Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI/VGA: Fix boot device detection after framebuffer relocation
@ 2026-10-28  9:46 wuqianhai
  2026-10-28 10:11 ` sashiko-bot
                   ` (4 more replies)
  0 siblings, 5 replies; 34+ messages in thread
From: wuqianhai @ 2026-10-28  9:46 UTC (permalink / raw)
  To: bhelgaas
  Cc: wuqianhai, linux-pci, linux-kernel, tzimmermann, javierm,
	dri-devel

From: wuqianhai <wuqianhai@loongson.cn>

PCI resource assignment can relocate the firmware framebuffer BAR, which
leaves the base address in screen_info stale.  The VGA arbiter then calls
screen_info_pci_dev() from vga_is_firmware_default(), which fails to match
the framebuffer against any PCI device's BARs.  As a result, the boot VGA
device is not recognized and the arbiter may select the wrong default
device.

Fix this by calling screen_info_apply_fixups() in vga_arb_device_init()
before adding the VGA devices.  This relocates lfb_base to the assigned
BAR address so that vga_is_firmware_default() matches the boot device
again.

Tested on a LoongArch platform, with vga_is_firmware_default()
additionally enabled for CONFIG_LOONGARCH via local changes.

Fixes: 337bf13aa9ddab8ae47f2677ab75cf69ae33437b ("PCI/VGA: Replace vga_is_firmware_default() with a screen info check")
Signed-off-by: wuqianhai <wuqianhai@loongson.cn>
---
 drivers/pci/vgaarb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c
index 3e58b2c05c85..aca594651f58 100644
--- a/drivers/pci/vgaarb.c
+++ b/drivers/pci/vgaarb.c
@@ -1527,6 +1527,14 @@ static int __init vga_arb_device_init(void)
 	int rc;
 	struct pci_dev *pdev;
 
+	/*
+	 * PCI resource assignment may have relocated the firmware
+	 * framebuffer BAR. Update screen_info's lfb_base so that
+	 * vga_is_firmware_default() can match it against the boot
+	 * device's relocated resource.
+	 */
+	screen_info_apply_fixups();
+
 	rc = misc_register(&vga_arb_device);
 	if (rc < 0)
 		pr_err("error %d registering device\n", rc);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread
* [PATCH v3 4/6] LoongArch: video: Implement primary framebuffer device detection
@ 2026-11-10  8:57 wuqianhai
  2026-11-10  8:57 ` [PATCH v3 6/6] PCI/VGA: Enable firmware default device detection on LoongArch wuqianhai
  0 siblings, 1 reply; 34+ messages in thread
From: wuqianhai @ 2026-11-10  8:57 UTC (permalink / raw)
  To: chenhuacai, kernel, tzimmermann, deller, bhelgaas
  Cc: ardb, ilias.apalodimas, javierm, loongarch, linux-pci, linux-efi,
	dri-devel, linux-fbdev, linux-kernel, wuqianhai

From: wuqianhai <wuqianhai@loongson.cn>

The LoongArch port does not implement video_is_primary_device(), so it
falls back to the generic stub that always returns false.  As a result,
with CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y the framebuffer console
cannot map itself to the primary display device and instead binds to the
first registered framebuffer, which is not necessarily the one the
firmware used for the boot console.

Implement video_is_primary_device() by returning whether the device is
the VGA default device.  This reuses the VGA arbiter's choice instead of
matching the firmware framebuffer by address, so it is stable across BAR
resizing: the default device is fixed before any driver runs.

Signed-off-by: wuqianhai <wuqianhai@loongson.cn>
---
 arch/loongarch/Makefile             |  3 +++
 arch/loongarch/include/asm/video.h  |  7 +++++++
 arch/loongarch/video/Makefile       |  3 +++
 arch/loongarch/video/video-common.c | 29 +++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 arch/loongarch/video/Makefile
 create mode 100644 arch/loongarch/video/video-common.c

diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index 4b22f95aaafb..7fca93298cef 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -166,6 +166,9 @@ bootvars-y	= VMLINUX_LOAD_ADDRESS=$(load-y)
 
 drivers-$(CONFIG_PCI)		+= arch/loongarch/pci/
 
+# framebuffer console primary device detection
+drivers-$(CONFIG_VIDEO)		+= arch/loongarch/video/
+
 KBUILD_AFLAGS	+= $(cflags-y)
 KBUILD_CFLAGS	+= $(cflags-y)
 KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y)
diff --git a/arch/loongarch/include/asm/video.h b/arch/loongarch/include/asm/video.h
index 9f76845f2d4f..7b38881ea1d6 100644
--- a/arch/loongarch/include/asm/video.h
+++ b/arch/loongarch/include/asm/video.h
@@ -8,6 +8,13 @@
 #include <linux/compiler.h>
 #include <linux/string.h>
 
+struct device;
+
+#ifdef CONFIG_VIDEO
+bool video_is_primary_device(struct device *dev);
+#define video_is_primary_device video_is_primary_device
+#endif
+
 static inline void fb_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n)
 {
 	memcpy(to, (void __force *)from, n);
diff --git a/arch/loongarch/video/Makefile b/arch/loongarch/video/Makefile
new file mode 100644
index 000000000000..f1b2a7e54033
--- /dev/null
+++ b/arch/loongarch/video/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_VIDEO)		+= video-common.o
diff --git a/arch/loongarch/video/video-common.c b/arch/loongarch/video/video-common.c
new file mode 100644
index 000000000000..6fea46661cb6
--- /dev/null
+++ b/arch/loongarch/video/video-common.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Loongson Technology Corporation Limited
+ */
+
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/vgaarb.h>
+
+#include <asm/video.h>
+
+bool video_is_primary_device(struct device *dev)
+{
+	struct pci_dev *pdev;
+
+	if (!dev_is_pci(dev))
+		return false;
+
+	pdev = to_pci_dev(dev);
+
+	if (!pci_is_display(pdev))
+		return false;
+
+	return pdev == vga_default_device();
+}
+EXPORT_SYMBOL(video_is_primary_device);
+
+MODULE_DESCRIPTION("LoongArch video helpers");
+MODULE_LICENSE("GPL");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2026-11-10 16:25 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28  9:46 [PATCH] PCI/VGA: Fix boot device detection after framebuffer relocation wuqianhai
2026-10-28 10:11 ` sashiko-bot
2026-10-28 23:15 ` Bjorn Helgaas
2026-10-29  3:39   ` wuqianhai
2026-10-29 20:03     ` Bjorn Helgaas
2026-10-29  7:54   ` Thomas Zimmermann
2026-10-29  3:34 ` [PATCH v2] PCI/VGA: Enable firmware default device detection on LoongArch wuqianhai
2026-10-29  3:58   ` sashiko-bot
2026-10-29  8:10   ` Thomas Zimmermann
2026-11-10  8:56   ` [PATCH v3 0/6] LoongArch: Identify the firmware/boot display device wuqianhai
2026-11-10  8:56     ` [PATCH v3 1/6] LoongArch: efi: Provide sysfb_primary_display for screen_info users wuqianhai
2026-11-10 14:34       ` Thomas Zimmermann
2026-11-10 14:39       ` Thomas Zimmermann
2026-11-10 16:25       ` Thomas Zimmermann
2026-11-10  8:56     ` [PATCH v3 2/6] LoongArch/PCI: Refresh screen_info after resource assignment wuqianhai
2026-11-10 14:46       ` Thomas Zimmermann
2026-11-10  8:56     ` [PATCH v3 3/6] LoongArch/PCI: Remove vga default device override wuqianhai
2026-11-10  9:01   ` [PATCH v3 0/6] LoongArch: Identify the firmware/boot display device wuqianhai
2026-11-10  9:01     ` [PATCH v3 1/6] LoongArch: efi: Provide sysfb_primary_display for screen_info users wuqianhai
2026-11-10  9:38       ` sashiko-bot
2026-11-10  9:01     ` [PATCH v3 2/6] LoongArch/PCI: Refresh screen_info after resource assignment wuqianhai
2026-11-10  9:52       ` sashiko-bot
2026-11-10  9:02     ` [PATCH v3 3/6] LoongArch/PCI: Remove vga default device override wuqianhai
2026-11-10  9:41       ` sashiko-bot
2026-11-10  9:24     ` [PATCH v3 4/6] LoongArch: video: Implement primary framebuffer device detection wuqianhai
2026-11-10  9:58       ` sashiko-bot
2026-11-10  9:24     ` [PATCH v3 5/6] efi/libstub: Enable direct sysfb_primary_display access on LoongArch wuqianhai
2026-11-10  9:35       ` sashiko-bot
2026-11-10  9:24     ` [PATCH v3 6/6] PCI/VGA: Enable firmware default device detection " wuqianhai
2026-11-10  9:49       ` sashiko-bot
2026-11-10 10:00     ` [PATCH v3 0/6] LoongArch: Identify the firmware/boot display device Huacai Chen
2026-10-29  7:00 ` [PATCH] PCI/VGA: Fix boot device detection after framebuffer relocation kernel test robot
2026-10-29 13:30 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-10  8:57 [PATCH v3 4/6] LoongArch: video: Implement primary framebuffer device detection wuqianhai
2026-11-10  8:57 ` [PATCH v3 6/6] PCI/VGA: Enable firmware default device detection on LoongArch wuqianhai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox