Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI/VGA: Move disabled VGA device detection to ADD_DEVICE path

a37c0f48950b ("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>

authored by

Huacai Chen and committed by
Bjorn Helgaas
37114e4d e96902eb

+9 -18
+9 -18
drivers/pci/vgaarb.c
··· 656 656 * We use the first one we find, so if we've already found one, 657 657 * vgadev is no better. 658 658 */ 659 - if (boot_vga) 659 + if (boot_vga && 660 + (boot_vga->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK) 660 661 return false; 661 662 662 663 if ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK) ··· 693 692 } 694 693 return true; 695 694 } 695 + 696 + /* 697 + * vgadev has neither IO nor MEM enabled. If we haven't found any 698 + * other VGA devices, it is the best candidate so far. 699 + */ 700 + if (!boot_vga) 701 + return true; 696 702 697 703 return false; 698 704 } ··· 1567 1559 MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops 1568 1560 }; 1569 1561 1570 - static void __init vga_arb_select_default_device(void) 1571 - { 1572 - struct vga_device *vgadev; 1573 - 1574 - if (!vga_default_device()) { 1575 - vgadev = list_first_entry_or_null(&vga_list, 1576 - struct vga_device, list); 1577 - if (vgadev) { 1578 - struct device *dev = &vgadev->pdev->dev; 1579 - vgaarb_info(dev, "setting as boot device (VGA legacy resources not available)\n"); 1580 - vga_set_default_device(vgadev->pdev); 1581 - } 1582 - } 1583 - } 1584 - 1585 1562 static int __init vga_arb_device_init(void) 1586 1563 { 1587 1564 int rc; ··· 1595 1602 else 1596 1603 vgaarb_info(dev, "no bridge control possible\n"); 1597 1604 } 1598 - 1599 - vga_arb_select_default_device(); 1600 1605 1601 1606 pr_info("loaded\n"); 1602 1607 return rc;