Skip to content

Commit 60a9bac

Browse files
committed
PCI/VGA: Factor out vga_select_framebuffer_device()
On x86 and ia64, if a VGA device BARs include a framebuffer reported by platform firmware, we select the device as the default VGA device. Factor this code to a separate function. No functional change intended. Link: https://lore.kernel.org/r/20220224224753.297579-4-helgaas@kernel.org Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Bruno Prémont <bonbons@linux-vserver.org>
1 parent c1593dd commit 60a9bac

1 file changed

Lines changed: 53 additions & 46 deletions

File tree

drivers/pci/vgaarb.c

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,58 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc)
565565
}
566566
EXPORT_SYMBOL(vga_put);
567567

568+
static void __init vga_select_framebuffer_device(struct pci_dev *pdev)
569+
{
570+
#if defined(CONFIG_X86) || defined(CONFIG_IA64)
571+
struct device *dev = &pdev->dev;
572+
u64 base = screen_info.lfb_base;
573+
u64 size = screen_info.lfb_size;
574+
u64 limit;
575+
resource_size_t start, end;
576+
unsigned long flags;
577+
int i;
578+
579+
/* Select the device owning the boot framebuffer if there is one */
580+
581+
if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
582+
base |= (u64)screen_info.ext_lfb_base << 32;
583+
584+
limit = base + size;
585+
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+
595+
/* Does firmware framebuffer belong to us? */
596+
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
597+
flags = pci_resource_flags(pdev, i);
598+
599+
if ((flags & IORESOURCE_MEM) == 0)
600+
continue;
601+
602+
start = pci_resource_start(pdev, i);
603+
end = pci_resource_end(pdev, i);
604+
605+
if (!start || !end)
606+
continue;
607+
608+
if (base < start || limit >= end)
609+
continue;
610+
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);
616+
}
617+
#endif
618+
}
619+
568620
static bool vga_arb_integrated_gpu(struct device *dev)
569621
{
570622
#if defined(CONFIG_ACPI)
@@ -1446,54 +1498,9 @@ static void __init vga_arb_select_default_device(void)
14461498
struct pci_dev *pdev, *found = NULL;
14471499
struct vga_device *vgadev;
14481500

1449-
#if defined(CONFIG_X86) || defined(CONFIG_IA64)
1450-
u64 base = screen_info.lfb_base;
1451-
u64 size = screen_info.lfb_size;
1452-
u64 limit;
1453-
resource_size_t start, end;
1454-
unsigned long flags;
1455-
int i;
1456-
1457-
if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
1458-
base |= (u64)screen_info.ext_lfb_base << 32;
1459-
1460-
limit = base + size;
1461-
14621501
list_for_each_entry(vgadev, &vga_list, list) {
1463-
struct device *dev = &vgadev->pdev->dev;
1464-
/*
1465-
* Override vga_arbiter_add_pci_device()'s I/O based detection
1466-
* as it may take the wrong device (e.g. on Apple system under
1467-
* EFI).
1468-
*
1469-
* Select the device owning the boot framebuffer if there is
1470-
* one.
1471-
*/
1472-
1473-
/* Does firmware framebuffer belong to us? */
1474-
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
1475-
flags = pci_resource_flags(vgadev->pdev, i);
1476-
1477-
if ((flags & IORESOURCE_MEM) == 0)
1478-
continue;
1479-
1480-
start = pci_resource_start(vgadev->pdev, i);
1481-
end = pci_resource_end(vgadev->pdev, i);
1482-
1483-
if (!start || !end)
1484-
continue;
1485-
1486-
if (base < start || limit >= end)
1487-
continue;
1488-
1489-
if (!vga_default_device())
1490-
vgaarb_info(dev, "setting as boot device\n");
1491-
else if (vgadev->pdev != vga_default_device())
1492-
vgaarb_info(dev, "overriding boot device\n");
1493-
vga_set_default_device(vgadev->pdev);
1494-
}
1502+
vga_select_framebuffer_device(vgadev->pdev);
14951503
}
1496-
#endif
14971504

14981505
if (!vga_default_device()) {
14991506
list_for_each_entry_reverse(vgadev, &vga_list, list) {

0 commit comments

Comments
 (0)