Skip to content

Commit dbf9527

Browse files
committed
Merge branch 'pci/vga'
- Add pci_is_vga() helper, which checks for both PCI_CLASS_DISPLAY_VGA and PCI_CLASS_NOT_DEFINED_VGA (which catches ancient devices built before Class Codes were defined) (Sui Jingfeng) - Use the new pci_is_vga() to identify devices for the VGA arbiter, the sysfs "boot_vga" attribute, and the virtio and qxl drivers (SUi Jingfeng) * pci/vga: drm/qxl: Use pci_is_vga() to identify VGA devices drm/virtio: Use pci_is_vga() to identify VGA devices PCI/sysfs: Enable 'boot_vga' attribute via pci_is_vga() PCI/VGA: Select VGA devices earlier PCI/VGA: Use pci_is_vga() to identify VGA devices PCI: Add pci_is_vga() helper
2 parents 79a8394 + 94cfada commit dbf9527

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

drivers/gpu/drm/qxl/qxl_drv.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);
6868
static struct drm_driver qxl_driver;
6969
static struct pci_driver qxl_pci_driver;
7070

71-
static bool is_vga(struct pci_dev *pdev)
72-
{
73-
return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
74-
}
75-
7671
static int
7772
qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7873
{
@@ -100,7 +95,7 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10095
if (ret)
10196
goto disable_pci;
10297

103-
if (is_vga(pdev) && pdev->revision < 5) {
98+
if (pci_is_vga(pdev) && pdev->revision < 5) {
10499
ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
105100
if (ret) {
106101
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)
131126
unload:
132127
qxl_device_fini(qdev);
133128
put_vga:
134-
if (is_vga(pdev) && pdev->revision < 5)
129+
if (pci_is_vga(pdev) && pdev->revision < 5)
135130
vga_put(pdev, VGA_RSRC_LEGACY_IO);
136131
disable_pci:
137132
pci_disable_device(pdev);
@@ -159,7 +154,7 @@ qxl_pci_remove(struct pci_dev *pdev)
159154

160155
drm_dev_unregister(dev);
161156
drm_atomic_helper_shutdown(dev);
162-
if (is_vga(pdev) && pdev->revision < 5)
157+
if (pci_is_vga(pdev) && pdev->revision < 5)
163158
vga_put(pdev, VGA_RSRC_LEGACY_IO);
164159
}
165160

drivers/gpu/drm/virtio/virtgpu_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int virtio_gpu_pci_quirk(struct drm_device *dev)
5151
{
5252
struct pci_dev *pdev = to_pci_dev(dev->dev);
5353
const char *pname = dev_name(&pdev->dev);
54-
bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
54+
bool vga = pci_is_vga(pdev);
5555
int ret;
5656

5757
DRM_INFO("pci: %s detected at %s\n",

drivers/pci/pci-sysfs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,11 +1548,10 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
15481548
struct device *dev = kobj_to_dev(kobj);
15491549
struct pci_dev *pdev = to_pci_dev(dev);
15501550

1551-
if (a == &dev_attr_boot_vga.attr)
1552-
if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1553-
return 0;
1551+
if (a == &dev_attr_boot_vga.attr && pci_is_vga(pdev))
1552+
return a->mode;
15541553

1555-
return a->mode;
1554+
return 0;
15561555
}
15571556

15581557
static struct attribute *pci_dev_hp_attrs[] = {

drivers/pci/vgaarb.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,6 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
764764
struct pci_dev *bridge;
765765
u16 cmd;
766766

767-
/* Only deal with VGA class devices */
768-
if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
769-
return false;
770-
771767
/* Allocate structure */
772768
vgadev = kzalloc(sizeof(struct vga_device), GFP_KERNEL);
773769
if (vgadev == NULL) {
@@ -1503,6 +1499,10 @@ static int pci_notify(struct notifier_block *nb, unsigned long action,
15031499

15041500
vgaarb_dbg(dev, "%s\n", __func__);
15051501

1502+
/* Only deal with VGA class devices */
1503+
if (!pci_is_vga(pdev))
1504+
return 0;
1505+
15061506
/*
15071507
* For now, we're only interested in devices added and removed.
15081508
* I didn't test this thing here, so someone needs to double check
@@ -1550,8 +1550,10 @@ static int __init vga_arb_device_init(void)
15501550
pdev = NULL;
15511551
while ((pdev =
15521552
pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
1553-
PCI_ANY_ID, pdev)) != NULL)
1554-
vga_arbiter_add_pci_device(pdev);
1553+
PCI_ANY_ID, pdev)) != NULL) {
1554+
if (pci_is_vga(pdev))
1555+
vga_arbiter_add_pci_device(pdev);
1556+
}
15551557

15561558
pr_info("loaded\n");
15571559
return rc;

include/linux/pci.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,30 @@ static inline bool pci_is_bridge(struct pci_dev *dev)
713713
dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
714714
}
715715

716+
/**
717+
* pci_is_vga - check if the PCI device is a VGA device
718+
*
719+
* The PCI Code and ID Assignment spec, r1.15, secs 1.4 and 1.1, define
720+
* VGA Base Class and Sub-Classes:
721+
*
722+
* 03 00 PCI_CLASS_DISPLAY_VGA VGA-compatible or 8514-compatible
723+
* 00 01 PCI_CLASS_NOT_DEFINED_VGA VGA-compatible (before Class Code)
724+
*
725+
* Return true if the PCI device is a VGA device and uses the legacy VGA
726+
* resources ([mem 0xa0000-0xbffff], [io 0x3b0-0x3bb], [io 0x3c0-0x3df] and
727+
* aliases).
728+
*/
729+
static inline bool pci_is_vga(struct pci_dev *pdev)
730+
{
731+
if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
732+
return true;
733+
734+
if ((pdev->class >> 8) == PCI_CLASS_NOT_DEFINED_VGA)
735+
return true;
736+
737+
return false;
738+
}
739+
716740
#define for_each_pci_bridge(dev, bus) \
717741
list_for_each_entry(dev, &bus->devices, bus_list) \
718742
if (!pci_is_bridge(dev)) {} else

0 commit comments

Comments
 (0)