Add the pci_is_vga() helper and use it
Subsystems (6)
cover Add the pci_is_vga() helper and use it
From: Sui Jingfeng <[email protected]>
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. Thus, PCI(e) device with the PCI_CLASS_NOT_DEFINED_VGA class code should also be handled as the normal VGA-compatible devices.
Compared with the "if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)" code, the newly implemented pci_is_vga() is shorter and straightforward. So it is more easy to use. It is designed as a inline function, the more common case "if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA))" is put before the less common case "if ((pdev->class >> 8) == PCI_CLASS_NOT_DEFINED_VGA)", so there should no performance penalty.
Sui Jingfeng (5):
PCI: Add the pci_is_vga() helper
PCI/VGA: Deal with VGA devices
PCI/sysfs: Use pci_is_vga() helper
drm/virgpu: Switch to pci_is_vga()
drm/qxl: Switch to pci_is_vga()
drivers/gpu/drm/qxl/qxl_drv.c | 11 +++-------- drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +- drivers/pci/pci-sysfs.c | 6 +++--- drivers/pci/vgaarb.c | 19 +++++++++---------- include/linux/pci.h | 27 +++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 22 deletions(-)
base-commit: 43cc31da9146f9ce60e4a03d96ef0807c2cdac94
Signature · 1 line
2.34.1
PATCH 1/5 PCI: Add the pci_is_vga() helper
From: Sui Jingfeng <[email protected]>
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.
--- include/linux/pci.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
include/linux/pci.h +27 -0
@@ -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
Signature · 1 line
2.34.1
Re: [-next 1/5] PCI: Add the pci_is_vga() helper
Quoted 5 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
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
I can update this with the spec details (PCI Code and Assignment spec r1.15, secs 1.1 and 1.4).
Quoted 34 lines
interface
0x00is VGA-compatible, VGA devices with programming interface0x01are 8514-compatible controllers. Besides,PCI_CLASS_NOT_DEFINED_VGAis defined to provide backward compatibility for devices that were built before the class code field was defined. Hence, introduce thepci_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" <[email protected]>Signed-off-by Sui Jingfeng <[email protected]>--- include/linux/pci.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)include/linux/pci.h +13
-0@@ -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. +*/
include/linux/pci.h static inline bool pci_is_bridge(struct pci_dev *dev) · line 738
Quoted 10 lines
include/linux/pci.h +10
-0+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;
Are you seeing a problem that will be fixed by this series, i.e., a PCI_CLASS_NOT_DEFINED_VGA device that we currently don't handle correctly?
I think this makes sense per the spec, but there's always a risk of breaking something, so it's nice if the change actually *fixes* something to make that risk worthwhile.
Quoted 9 lines
include/linux/pci.h +3
-0+return false; +} +#define for_each_pci_bridge (dev, bus) \ list_for_each_entry(dev, &bus->devices, bus_list) \ if (!pci_is_bridge(dev)) {} elseSignature · 1 line
2.34.1
Re: [-next 1/5] PCI: Add the pci_is_vga() helper
Hi,
Quoted 48 lines · Bjorn Helgaas
Quoted 5 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
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
I can update this with the spec details (PCI Code and Assignment spec r1.15, secs 1.1 and 1.4).
Quoted 39 lines
interface
0x00is VGA-compatible, VGA devices with programming interface0x01are 8514-compatible controllers. Besides,PCI_CLASS_NOT_DEFINED_VGAis defined to provide backward compatibility for devices that were built before the class code field was defined. Hence, introduce thepci_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" <[email protected]>Signed-off-by Sui Jingfeng <[email protected]>--- include/linux/pci.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)include/linux/pci.h +18
-0@@ -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; +
Quoted 8 lines
include/linux/pci.h static inline bool pci_is_bridge(struct pci_dev *dev) · line 738
Quoted 5 lines
include/linux/pci.h +5
-0+if ((pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ) +return true; + +if ((pdev->class >>8 ) ==PCI_CLASS_NOT_DEFINED_VGA ) +return true;Are you seeing a problem that will be fixed by this series, i.e., a
PCI_CLASS_NOT_DEFINED_VGAdevice that we currently don't handle correctly?
No, I write it according to the spec.
But I'm sure that the boot_vga will not be shown at sysfs for a PCI_CLASS_NOT_DEFINED_VGA device.
Quoted 3 lines
I think this makes sense per the spec, but there's always a risk of breaking something, so it's nice if the change actually *fixes* something to make that risk worthwhile.
Maciej mentioned that PCI_CLASS_NOT_DEFINED_VGA device should also be handled in the past. see [1]. But if no one interested in PCI_CLASS_NOT_DEFINED_VGA nowaday, then I guess the gains of this patch may not deserve the time and risk. But I don't mind if someone would like pick it up for other purpose.
Thanks for the reviewing. :-)
[1] https://lkml.org/lkml/2023/6/18/315
Quoted 9 lines
Quoted 9 lines
include/linux/pci.h +3
-0+return false; +} +#define for_each_pci_bridge (dev, bus) \ list_for_each_entry(dev, &bus->devices, bus_list) \ if (!pci_is_bridge(dev)) {} elseSignature · 1 line
2.34.1
Re: [-next 1/5] PCI: Add the pci_is_vga() helper
Quoted 5 lines · Sui Jingfeng
Quoted 3 lines
I think this makes sense per the spec, but there's always a risk of breaking something, so it's nice if the change actually *fixes* something to make that risk worthwhile.
Quoted 7 lines
Maciej mentioned that PCI_CLASS_NOT_DEFINED_VGA device should also be handled in the past.
see [1]. But if no one interested inPCI_CLASS_NOT_DEFINED_VGAnowaday, then I guess
the gains of this patch may not deserve the time and risk. But I don't mind if someone
would like pick it up for other purpose.
Well, if we need to determine for whatever purpose whether a PCI/e device
presents a VGA programming interface, then I think we ought to do this in a complete manner. I'm not sure offhand what could possibly break if we write our code according to specs and include PCI_CLASS_NOT_DEFINED_VGA devices in the class.
Yes, I'm aware they won't be the latest and greatest, but they may still
be there out there in service. For one I continue using my 30 years old Trident 8900C ISA VGA adapter with the most recent Linux kernel. The card serves its purpose, mostly as a glass TTY, so why should I replace it?
Of course there are broken devices out there regardless, which won't work
as we expect without special handling or sometimes at all even. It does not mean we should refrain from making the best effort for good compliant devices and assume in advance that something will break even if we write our code according to the relevant specs. I'd say do write according to specs and only try to sort out the situation somehow if something actually does break.
In any case if we actually do choose to ignore PCI_CLASS_NOT_DEFINED_VGA
devices, then I wanted to make sure we do it deliberately rather than from the lack of awareness of the existence of such devices.
Maciej
PATCH 2/5 PCI/VGA: Deal with VGA devices
In reply to Sui JingfengFrom: Sui Jingfeng <[email protected]>
VGAARB only cares about PCI(e) VGA devices, thus filtering out unqualified devices as early as possible. This also means that deleting a non-VGA device snooped won't unnecessarily call into vga_arbiter_del_pci_device() function. By using the newly implemented pci_is_vga(),
PCI(e) with PCI_CLASS_NOT_DEFINED_VGA class code will also be handled.
--- drivers/pci/vgaarb.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/pci/vgaarb.c +9 -10
@@ -764,10 +764,6 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)struct pci_dev *bridge;u16 cmd; -/* Only deal with VGA class devices */ -if ((pdev->class >>8 ) !=PCI_CLASS_DISPLAY_VGA ) -return false; -/* Allocate structure */ vgadev =kzalloc (sizeof (struct vga_device ),GFP_KERNEL );if (vgadev ==NULL ) {
@@ -1503,6 +1499,9 @@ static int pci_notify(struct notifier_block *nb, unsigned long action,vgaarb_dbg (dev,"%s\n" , __func__); +if (!pci_is_vga (pdev)) +return 0 ; +/* * For now, we're only interested in devices added and removed. * I didn't test this thing here, so someone needs to double check
@@ -1537,8 +1536,8 @@ static struct miscdevice vga_arb_device = {static int __init vga_arb_device_init (void ) { +struct pci_dev *pdev =NULL ;int rc; -struct pci_dev *pdev; rc =misc_register (&vga_arb_device);if (rc <0 )
@@ -1547,11 +1546,11 @@ static int __init vga_arb_device_init(void)bus_register_notifier (&pci_bus_type, &pci_notifier);/* Add all VGA class PCI devices by default */ - pdev =NULL ; -while ((pdev = -pci_get_subsys (PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID , -PCI_ANY_ID , pdev)) !=NULL ) -vga_arbiter_add_pci_device (pdev); +do { + pdev =pci_get_subsys (PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID , pdev); +if (pci_is_vga (pdev)) +vga_arbiter_add_pci_device (pdev); + }while (pdev);pr_info ("loaded\n" );return rc;
Signature · 1 line
2.34.1
PATCH 3/5 PCI/sysfs: Use pci_is_vga() helper
In reply to Sui JingfengFrom: Sui Jingfeng <[email protected]>
Instead of accessing the PCI_CLASS_DISPLAY_VGA and pdev->class directly. The PCI_CLASS_NOT_DEFINED_VGA is defined to provide backward compatibility for devices that were built before the class code field was defined. It should be visiable via sysfs(boot_vga) as the normal VGA-compatible devices.
--- drivers/pci/pci-sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/pci-sysfs.c +3 -3
@@ -1552,10 +1552,10 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,struct pci_dev *pdev =to_pci_dev (dev);if (a == &dev_attr_boot_vga.attr) -if ((pdev->class >>8 ) !=PCI_CLASS_DISPLAY_VGA ) -return 0 ; +if (pci_is_vga (pdev)) +return a->mode; -return a->mode; +return 0 ; }static struct attribute *pci_dev_hp_attrs[] = {
Signature · 1 line
2.34.1
PATCH 4/5 drm/virgpu: Switch to pci_is_vga()
In reply to Sui JingfengFrom: Sui Jingfeng <[email protected]>
Should be no functional change, just for cleanup purpose.
--- drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +1 -1
@@ -51,7 +51,7 @@ static int virtio_gpu_pci_quirk(struct drm_device *dev) {struct pci_dev *pdev =to_pci_dev (dev->dev);const char *pname =dev_name (&pdev->dev); -bool vga = (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; +bool vga =pci_is_vga (pdev);int ret; DRM_INFO("pci: %s detected at %s\n",
Signature · 1 line
2.34.1
Re: [-next 4/5] drm/virgpu: Switch to pci_is_vga()
In subject: "drm/virtio" to match previous history.
Quoted 19 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
Should be no functional change, just for cleanup purpose.
Cc David Airlie <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Gurchetan Singh <[email protected]>Cc Chia-I Wu <[email protected]>Cc Daniel Vetter <[email protected]>Signed-off-by Sui Jingfeng <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_drv.c +0
-0
drivers/gpu/drm/virtio/virtgpu_drv.c static int virtio_gpu_pci_quirk(struct drm_device *dev) · line 54
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-1@@ -51,7 +51,7 @@ static int virtio_gpu_pci_quirk(struct drm_device *dev) {struct pci_dev *pdev =to_pci_dev (dev->dev);const char *pname =dev_name (&pdev->dev); -bool vga = (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; +bool vga =pci_is_vga (pdev);
This *is* a functional change: Previously "vga" was only true for PCI_CLASS_DISPLAY_VGA (0x0300). Now it will be true for both PCI_CLASS_DISPLAY_VGA (0x0300) and PCI_CLASS_DISPLAY_OTHER (0x0380).
Is that desirable? I can't tell. Maybe the GPU folks will chime in.
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +0
-0int ret; DRM_INFO("pci: %s detected at %s\n",Signature · 1 line
2.34.1
Re: [-next 4/5] drm/virgpu: Switch to pci_is_vga()
Quoted 17 lines · Bjorn Helgaas
In subject: "drm/virtio" to match previous history.
Quoted 14 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
Should be no functional change, just for cleanup purpose.
Cc David Airlie <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Gurchetan Singh <[email protected]>Cc Chia-I Wu <[email protected]>Cc Daniel Vetter <[email protected]>Signed-off-by Sui Jingfeng <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
drivers/gpu/drm/virtio/virtgpu_drv.c static int virtio_gpu_pci_quirk(struct drm_device *dev) · line 54
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-1@@ -51,7 +51,7 @@ static int virtio_gpu_pci_quirk(struct drm_device *dev) {struct pci_dev *pdev =to_pci_dev (dev->dev);const char *pname =dev_name (&pdev->dev); -bool vga = (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; +bool vga =pci_is_vga (pdev);This *is* a functional change: Previously "vga" was only true for
PCI_CLASS_DISPLAY_VGA(0x0300). Now it will be true for bothPCI_CLASS_DISPLAY_VGA(0x0300) andPCI_CLASS_DISPLAY_OTHER(0x0380).
Oops, sorry, my mistake here. I meant PCI_CLASS_NOT_DEFINED_VGA, not PCI_CLASS_DISPLAY_OTHER. pci_is_vga() is true for either of:
PCI_CLASS_DISPLAY_VGA 0x0300
PCI_CLASS_NOT_DEFINED_VGA 0x0001
(PCI_CLASS_NOT_DEFINED_VGA is defined in the PCI Code and Assignment spec r1.15, sec 1.1; PCI_CLASS_DISPLAY_VGA is sec 1.4.)
Quoted 8 lines
Is that desirable? I can't tell. Maybe the GPU folks will chime in.
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +0
-0int ret; DRM_INFO("pci: %s detected at %s\n",Signature · 1 line
2.34.1
Re: [-next 4/5] drm/virgpu: Switch to pci_is_vga()
In reply to Bjorn HelgaasHi,
Quoted 31 lines · Bjorn Helgaas
In subject: "drm/virtio" to match previous history.
Quoted 19 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
Should be no functional change, just for cleanup purpose.
Cc David Airlie <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Gurchetan Singh <[email protected]>Cc Chia-I Wu <[email protected]>Cc Daniel Vetter <[email protected]>Signed-off-by Sui Jingfeng <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_drv.c +0
-0drivers/gpu/drm/virtio/virtgpu_drv.c static int virtio_gpu_pci_quirk(struct drm_device *dev) · line 54
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-1@@ -51,7 +51,7 @@ static int virtio_gpu_pci_quirk(struct drm_device *dev) {struct pci_dev *pdev =to_pci_dev (dev->dev);const char *pname =dev_name (&pdev->dev); -bool vga = (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; +bool vga =pci_is_vga (pdev);This *is* a functional change: Previously "vga" was only true for
PCI_CLASS_DISPLAY_VGA(0x0300). Now it will be true for bothPCI_CLASS_DISPLAY_VGA(0x0300) andPCI_CLASS_DISPLAY_OTHER(0x0380).
Quoted 2 lines
Is that desirable? I can't tell. Maybe the GPU folks will chime in.
Yes, the vga variable still will be "true" for the PCI_CLASS_DISPLAY_VGA (0x0300) class code, and this is the major case. But the devices with PCI_CLASS_NOT_DEFINED_VGA class code are quite uncommon, and virtio gpu is virtual GPU driver, It is unlikely that the QEMU to emulate a old device with PCI_CLASS_NOT_DEFINED_VGA class code. I means that there no reason to do so. Am I correct? Is there anyone know more?
For virtio virtual GPU driver, I would like to drop this patch, if no one response.
We probably only need to consider PCI_CLASS_NOT_DEFINED_VGA case for the real (probably old) hardware device. It do exists, as Maciej mention at [1].
[1] https://lkml.org/lkml/2023/6/18/315
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +0
-0int ret; DRM_INFO("pci: %s detected at %s\n",Signature · 1 line
2.34.1
PATCH 5/5 drm/qxl: Switch to pci_is_vga()
In reply to Sui JingfengFrom: Sui Jingfeng <[email protected]>
Should be no functional change, just for cleanup purpose.
--- drivers/gpu/drm/qxl/qxl_drv.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +3 -8
@@ -68,11 +68,6 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);static struct drm_driver qxl_driver;static struct pci_driver qxl_pci_driver; -static bool is_vga (struct pci_dev *pdev) -{ -return pdev->class ==PCI_CLASS_DISPLAY_VGA <<8 ; -} -static int qxl_pci_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -100,7 +95,7 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (ret) goto disable_pci; -if (is_vga (pdev) && pdev->revision <5 ) { +if (pci_is_vga (pdev) && pdev->revision <5 ) { ret =vga_get_interruptible (pdev,VGA_RSRC_LEGACY_IO );if (ret) {DRM_ERROR ("can't get legacy vga ioports\n" );
@@ -131,7 +126,7 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) unload:qxl_device_fini (qdev); put_vga: -if (is_vga (pdev) && pdev->revision <5 ) +if (pci_is_vga (pdev) && pdev->revision <5 )vga_put (pdev,VGA_RSRC_LEGACY_IO ); disable_pci:pci_disable_device (pdev);
@@ -159,7 +154,7 @@ qxl_pci_remove(struct pci_dev *pdev)drm_dev_unregister (dev);drm_atomic_helper_shutdown (dev); -if (is_vga (pdev) && pdev->revision <5 ) +if (pci_is_vga (pdev) && pdev->revision <5 )vga_put (pdev,VGA_RSRC_LEGACY_IO ); }
Signature · 1 line
2.34.1
Bjorn Helgaas
AppliedQuoted 26 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
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
0x00is VGA-compatible, VGA devices with programming interface0x01are 8514-compatible controllers. Besides,PCI_CLASS_NOT_DEFINED_VGAis defined to provide backward compatibility for devices that were built before the class code field was defined. Thus, PCI(e) device with thePCI_CLASS_NOT_DEFINED_VGAclass code should also be handled as the normal VGA-compatible devices.Compared with the "if ((
pdev->class>> 8) !=PCI_CLASS_DISPLAY_VGA)" code, the newly implementedpci_is_vga()is shorter and straightforward. So it is more easy to use. It is designed as a inline function, the more common case "if ((pdev->class>> 8) ==PCI_CLASS_DISPLAY_VGA))" is put before the less common case "if ((pdev->class>> 8) ==PCI_CLASS_NOT_DEFINED_VGA)", so there should no performance penalty.Sui Jingfeng (5):
PCI: Add thepci_is_vga()helper
PCI/VGA: Deal with VGA devices
PCI/sysfs: Usepci_is_vga()helper
drm/virgpu: Switch topci_is_vga()
drm/qxl: Switch topci_is_vga()
Quoted 6 lines
drivers/gpu/drm/qxl/qxl_drv.c | 11 +++-------- drivers/gpu/drm/virtio/virtgpu_drv.c | 2 +- drivers/pci/pci-sysfs.c | 6 +++--- drivers/pci/vgaarb.c | 19 +++++++++---------- include/linux/pci.h | 27 +++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 22 deletions(-)
I applied these on pci/vga for v6.7, thanks!
Please take a look at
https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/log/?h=vga
and let me know if I broke anything because I changed a few things; interdiff below:
drivers/pci/pci-sysfs.c +2 -3
@@ -1551,9 +1551,8 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,struct device *dev =kobj_to_dev (kobj);struct pci_dev *pdev =to_pci_dev (dev); -if (a == &dev_attr_boot_vga.attr) -if (pci_is_vga (pdev)) -return a->mode; +if (a == &dev_attr_boot_vga.attr &&pci_is_vga (pdev)) +return a->mode;return 0 ; }
drivers/pci/vgaarb.c +7 -4
@@ -1499,6 +1499,7 @@ static int pci_notify(struct notifier_block *nb, unsigned long action,vgaarb_dbg (dev,"%s\n" , __func__); +/* Only deal with VGA class devices */ if (!pci_is_vga (pdev))return 0 ;
@@ -1536,8 +1537,8 @@ static struct miscdevice vga_arb_device = {static int __init vga_arb_device_init (void ) { -struct pci_dev *pdev =NULL ;int rc; +struct pci_dev *pdev; rc =misc_register (&vga_arb_device);if (rc <0 )
@@ -1546,11 +1547,13 @@ static int __init vga_arb_device_init(void)bus_register_notifier (&pci_bus_type, &pci_notifier);/* Add all VGA class PCI devices by default */ -do { - pdev =pci_get_subsys (PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID , pdev); + pdev =NULL ; +while ((pdev = +pci_get_subsys (PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID , +PCI_ANY_ID , pdev)) !=NULL ) {if (pci_is_vga (pdev))vga_arbiter_add_pci_device (pdev); - }while (pdev); + }pr_info ("loaded\n" );return rc;
include/linux/pci.h +10 -13
@@ -714,23 +714,20 @@ static inline bool pci_is_bridge(struct pci_dev *dev) }/** -* 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. +* pci_is_vga - check if the PCI device is a VGA device * -* Returns: -* true if the PCI device is a VGA device, false otherwise. +* The PCI Code and ID Assignment spec, r1.15, secs 1.4 and 1.1, define +* VGA Base Class and Sub-Classes: +* +* 03 00 PCI_CLASS_DISPLAY_VGA VGA-compatible or 8514-compatible +* 00 01 PCI_CLASS_NOT_DEFINED_VGA VGA-compatible (before Class Code) +* +* Return true if the PCI device is a VGA device and uses the legacy VGA +* resources ([mem 0xa0000-0xbffff], [io 0x3b0-0x3bb], [io 0x3c0-0x3df] and +* aliases). */ static inline bool pci_is_vga (struct pci_dev *pdev) { -if (!pdev) -return false; -if ((pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )return true;