Skip to content

Commit f8d81df

Browse files
chenhuacaibjorn-helgaas
authored andcommitted
PCI/VGA: Move firmware default device detection to ADD_DEVICE path
Previously we selected the firmware default device, i.e., one that owns the boot framebuffer, as the default device in vga_arb_select_default_device(). This was only done in the vga_arb_device_init() subsys_initcall, so devices enumerated later, e.g., by pcibios_init(), were not eligible. Fix this by moving the firmware default device selection from vga_arb_select_default_device() to vga_arbiter_add_pci_device(), which is called after every PCI device is enumerated, either by the vga_arb_device_init() subsys_initcall or as an ADD_DEVICE notifier. Note that if vga_arb_select_default_device() previously found a device owning the boot framebuffer, it unconditionally set it to be the default VGA device, and no subsequent device could replace it. [bhelgaas: commit log, restructure slightly] Link: https://lore.kernel.org/r/20211015061512.2941859-7-chenhuacai@loongson.cn Link: https://lore.kernel.org/r/20220224224753.297579-6-helgaas@kernel.org Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Bruno Prémont <bonbons@linux-vserver.org>
1 parent dfe3da8 commit f8d81df

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

drivers/pci/vgaarb.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct vga_device {
7272
unsigned int io_norm_cnt; /* normal IO count */
7373
unsigned int mem_norm_cnt; /* normal MEM count */
7474
bool bridge_has_one_vga;
75+
bool is_firmware_default; /* device selected by firmware */
7576
unsigned int (*set_decode)(struct pci_dev *pdev, bool decode);
7677
};
7778

@@ -565,10 +566,9 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc)
565566
}
566567
EXPORT_SYMBOL(vga_put);
567568

568-
static void __init vga_select_framebuffer_device(struct pci_dev *pdev)
569+
static bool vga_is_firmware_default(struct pci_dev *pdev)
569570
{
570571
#if defined(CONFIG_X86) || defined(CONFIG_IA64)
571-
struct device *dev = &pdev->dev;
572572
u64 base = screen_info.lfb_base;
573573
u64 size = screen_info.lfb_size;
574574
u64 limit;
@@ -583,15 +583,6 @@ static void __init vga_select_framebuffer_device(struct pci_dev *pdev)
583583

584584
limit = base + size;
585585

586-
/*
587-
* Override vga_arbiter_add_pci_device()'s I/O based detection
588-
* as it may take the wrong device (e.g. on Apple system under
589-
* EFI).
590-
*
591-
* Select the device owning the boot framebuffer if there is
592-
* one.
593-
*/
594-
595586
/* Does firmware framebuffer belong to us? */
596587
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
597588
flags = pci_resource_flags(pdev, i);
@@ -608,13 +599,10 @@ static void __init vga_select_framebuffer_device(struct pci_dev *pdev)
608599
if (base < start || limit >= end)
609600
continue;
610601

611-
if (!vga_default_device())
612-
vgaarb_info(dev, "setting as boot device\n");
613-
else if (pdev != vga_default_device())
614-
vgaarb_info(dev, "overriding boot device\n");
615-
vga_set_default_device(pdev);
602+
return true;
616603
}
617604
#endif
605+
return false;
618606
}
619607

620608
static bool vga_arb_integrated_gpu(struct device *dev)
@@ -635,6 +623,7 @@ static bool vga_arb_integrated_gpu(struct device *dev)
635623
static bool vga_is_boot_device(struct vga_device *vgadev)
636624
{
637625
struct vga_device *boot_vga = vgadev_find(vga_default_device());
626+
struct pci_dev *pdev = vgadev->pdev;
638627

639628
/*
640629
* We select the default VGA device in this order:
@@ -645,6 +634,18 @@ static bool vga_is_boot_device(struct vga_device *vgadev)
645634
* Other device (see vga_arb_select_default_device())
646635
*/
647636

637+
/*
638+
* We always prefer a firmware default device, so if we've already
639+
* found one, there's no need to consider vgadev.
640+
*/
641+
if (boot_vga && boot_vga->is_firmware_default)
642+
return false;
643+
644+
if (vga_is_firmware_default(pdev)) {
645+
vgadev->is_firmware_default = true;
646+
return true;
647+
}
648+
648649
/*
649650
* A legacy VGA device has MEM and IO enabled and any bridges
650651
* leading to it have PCI_BRIDGE_CTL_VGA enabled so the legacy
@@ -1531,10 +1532,6 @@ static void __init vga_arb_select_default_device(void)
15311532
struct pci_dev *pdev, *found = NULL;
15321533
struct vga_device *vgadev;
15331534

1534-
list_for_each_entry(vgadev, &vga_list, list) {
1535-
vga_select_framebuffer_device(vgadev->pdev);
1536-
}
1537-
15381535
if (!vga_default_device()) {
15391536
list_for_each_entry_reverse(vgadev, &vga_list, list) {
15401537
struct device *dev = &vgadev->pdev->dev;

0 commit comments

Comments
 (0)