From patchwork Wed Aug 30 11:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13370197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01C69C6FA8F for ; Wed, 30 Aug 2023 11:24:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5128110E4FA; Wed, 30 Aug 2023 11:24:35 +0000 (UTC) Received: from out-242.mta0.migadu.com (out-242.mta0.migadu.com [91.218.175.242]) by gabe.freedesktop.org (Postfix) with ESMTPS id E740A10E4F8 for ; Wed, 30 Aug 2023 11:24:31 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693394144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DLVdHbG85+44P7qsiRYYVxfolXMOcHBsopMctAcePck=; b=J59qCFT0OBGdEmbDi4JY96Y0g2lOm/hwpx206PWQver8wN02CSpISQoonof/5wEaRuSTR5 ouCPVB3GdJM3Uyt4LGtJGwvB4wkGB4hupMSzjpaR//dtI0uBmIqZbmOBuyKnZ/kB5JxLUi kgv1cwNYtl3n58wormShqGG2v91FWKM= From: Sui Jingfeng To: Bjorn Helgaas , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu Subject: [-next 1/5] PCI: Add the pci_is_vga() helper Date: Wed, 30 Aug 2023 19:15:28 +0800 Message-Id: <20230830111532.444535-2-sui.jingfeng@linux.dev> In-Reply-To: <20230830111532.444535-1-sui.jingfeng@linux.dev> References: <20230830111532.444535-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sui Jingfeng , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, "Maciej W. Rozycki" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng The PCI code and ID assignment specification defined four types of display controllers for the display base class(03h), and the devices with 0x00h sub-class code are VGA devices. VGA devices with programming interface 0x00 is VGA-compatible, VGA devices with programming interface 0x01 are 8514-compatible controllers. Besides, PCI_CLASS_NOT_DEFINED_VGA is defined to provide backward compatibility for devices that were built before the class code field was defined. Hence, introduce the pci_is_vga() helper, let it handle the details for us. It returns true if the PCI(e) device being tested belongs to the VGA devices category. Cc: "Maciej W. Rozycki" Signed-off-by: Sui Jingfeng --- include/linux/pci.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index cf6e0b057752..ace727001911 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -713,6 +713,33 @@ static inline bool pci_is_bridge(struct pci_dev *dev) dev->hdr_type == PCI_HEADER_TYPE_CARDBUS; } +/** + * The PCI code and ID assignment specification defined four types of + * display controllers for the display base class(03h), and the devices + * with 0x00h sub-class code are VGA devices. VGA devices with programming + * interface 0x00 is VGA-compatible, VGA devices with programming interface + * 0x01 are 8514-compatible controllers. Besides, PCI_CLASS_NOT_DEFINED_VGA + * is defined to provide backward compatibility for devices that were built + * before the class code field was defined. This means that it belong to the + * VGA devices category also. + * + * Returns: + * true if the PCI device is a VGA device, false otherwise. + */ +static inline bool pci_is_vga(struct pci_dev *pdev) +{ + if (!pdev) + return false; + + if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) + return true; + + if ((pdev->class >> 8) == PCI_CLASS_NOT_DEFINED_VGA) + return true; + + return false; +} + #define for_each_pci_bridge(dev, bus) \ list_for_each_entry(dev, &bus->devices, bus_list) \ if (!pci_is_bridge(dev)) {} else