From: wuqianhai <[email protected]>

On LoongArch, PCI resource assignment completes during subsys_initcall
(acpi_init), before vga_arb_device_init() runs.  By that time the
firmware framebuffer BAR may already have been relocated, leaving
screen_info's lfb_base stale.  Enable vga_is_firmware_default() for
LoongArch and refresh screen_info in vga_arb_device_init() before the
boot device is matched.

Unlike x86, sysfb_primary_display is only defined when CONFIG_SYSFB is
enabled on LoongArch, so have VGA_ARB select SYSFB there.

Signed-off-by: wuqianhai <[email protected]>
---
Changes in v2:
- Add VGA_ARB's select of SYSFB for LoongArch to avoid an undefined
  reference when CONFIG_SCREEN_INFO is not set.
- Restrict the screen_info_apply_fixups() call to CONFIG_LOONGARCH so
  x86 and other architectures are unaffected.
- Enable vga_is_firmware_default() for LoongArch.
---
 drivers/pci/Kconfig  |  1 +
 drivers/pci/vgaarb.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 0c7408509ba2..55cc60f5d312 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -256,6 +256,7 @@ config VGA_ARB
        default y
        depends on !S390
        select SCREEN_INFO if X86
+       select SYSFB if LOONGARCH
        help
          Some "legacy" VGA devices implemented on PCI typically have the same
          hard-decoded addresses as they did on ISA. When multiple PCI devices
diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c
index 3e58b2c05c85..1b7e915629f9 100644
--- a/drivers/pci/vgaarb.c
+++ b/drivers/pci/vgaarb.c
@@ -566,7 +566,7 @@ EXPORT_SYMBOL(vga_put);
 
 static bool vga_is_firmware_default(struct pci_dev *pdev)
 {
-#if defined CONFIG_X86
+#if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH)
        return pdev == screen_info_pci_dev(&sysfb_primary_display.screen);
 #else
        return false;
@@ -1527,6 +1527,16 @@ static int __init vga_arb_device_init(void)
        int rc;
        struct pci_dev *pdev;
 
+#if defined(CONFIG_LOONGARCH)
+       /*
+        * On LoongArch, PCI resource assignment completes during
+        * subsys_initcall (acpi_init), before the VGA arbiter runs.  Refresh
+        * screen_info so vga_is_firmware_default() can match the relocated
+        * BAR.
+        */
+       screen_info_apply_fixups();
+#endif
+
        rc = misc_register(&vga_arb_device);
        if (rc < 0)
                pr_err("error %d registering device\n", rc);
-- 
2.34.1

Reply via email to