Skip to content

Commit 37114e4

Browse files
chenhuacaibjorn-helgaas
authored andcommitted
PCI/VGA: Move disabled VGA device detection to ADD_DEVICE path
a37c0f4 ("vgaarb: Select a default VGA device even if there's no legacy VGA") extended the vga_arb_device_init() subsys_initcall so that if there are no other eligible devices, it could select a disabled VGA device as the default. Move this detection from vga_arb_select_default_device() to vga_arbiter_add_pci_device() so every device, even those hot-added or enumerated after vga_arb_device_init() is eligible for selection as the default VGA device. [bhelgaas: commit log, restructure] Link: https://lore.kernel.org/r/20211015061512.2941859-5-chenhuacai@loongson.cn Link: https://lore.kernel.org/r/20220224224753.297579-8-helgaas@kernel.org Signed-off-by: Huacai Chen <chenhuacai@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Daniel Axtens <dja@axtens.net> Cc: Zhou Wang <wangzhou1@hisilicon.com>
1 parent e96902e commit 37114e4

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

drivers/pci/vgaarb.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ static bool vga_is_boot_device(struct vga_device *vgadev)
656656
* We use the first one we find, so if we've already found one,
657657
* vgadev is no better.
658658
*/
659-
if (boot_vga)
659+
if (boot_vga &&
660+
(boot_vga->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)
660661
return false;
661662

662663
if ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)
@@ -693,6 +694,13 @@ static bool vga_is_boot_device(struct vga_device *vgadev)
693694
return true;
694695
}
695696

697+
/*
698+
* vgadev has neither IO nor MEM enabled. If we haven't found any
699+
* other VGA devices, it is the best candidate so far.
700+
*/
701+
if (!boot_vga)
702+
return true;
703+
696704
return false;
697705
}
698706

@@ -1559,21 +1567,6 @@ static struct miscdevice vga_arb_device = {
15591567
MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops
15601568
};
15611569

1562-
static void __init vga_arb_select_default_device(void)
1563-
{
1564-
struct vga_device *vgadev;
1565-
1566-
if (!vga_default_device()) {
1567-
vgadev = list_first_entry_or_null(&vga_list,
1568-
struct vga_device, list);
1569-
if (vgadev) {
1570-
struct device *dev = &vgadev->pdev->dev;
1571-
vgaarb_info(dev, "setting as boot device (VGA legacy resources not available)\n");
1572-
vga_set_default_device(vgadev->pdev);
1573-
}
1574-
}
1575-
}
1576-
15771570
static int __init vga_arb_device_init(void)
15781571
{
15791572
int rc;
@@ -1603,8 +1596,6 @@ static int __init vga_arb_device_init(void)
16031596
vgaarb_info(dev, "no bridge control possible\n");
16041597
}
16051598

1606-
vga_arb_select_default_device();
1607-
16081599
pr_info("loaded\n");
16091600
return rc;
16101601
}

0 commit comments

Comments
 (0)