[PATCH] firmware: coreboot: Don't register a pdev if screen_info data is available
From: Javier Martinez Canillas
Date: Thu Sep 12 2024 - 12:31:55 EST
On Coreboot platforms, a system framebuffer may be provided to the Linux
kernel by filling a LB_TAG_FRAMEBUFFER entry in the Coreboot table. But
a Coreboot payload (e.g: SeaBIOS) could also provide this information to
the Linux kernel.
If that the case, early arch x86 boot code will fill the global struct
screen_info data and that data used by the Generic System Framebuffers
(sysfb) framework to add a platform device with platform data about the
system framebuffer.
But later then the framebuffer_coreboot driver will try to do the same
framebuffer (using the information from the Coreboot table), which will
lead to an error due a simple-framebuffer.0 device already registered:
sysfs: cannot create duplicate filename '/bus/platform/devices/simple-framebuffer.0'
...
coreboot: could not register framebuffer
framebuffer coreboot8: probe with driver framebuffer failed with error -17
To prevent the issue, make the framebuffer_core driver to not register a
platform device if the global struct screen_info data has been filled.
Reported-by: Brian Norris <briannorris@xxxxxxxxxxxx>
Link: https://lore.kernel.org/all/ZuCG-DggNThuF4pj@b20ea791c01f/T/#ma7fb65acbc1a56042258adac910992bb225a20d2
Suggested-by: Julius Werner <jwerner@xxxxxxxxxxxx>
Signed-off-by: Javier Martinez Canillas <javierm@xxxxxxxxxx>
---
drivers/firmware/google/framebuffer-coreboot.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/firmware/google/framebuffer-coreboot.c b/drivers/firmware/google/framebuffer-coreboot.c
index daadd71d8ddd..4e50da17cd7e 100644
--- a/drivers/firmware/google/framebuffer-coreboot.c
+++ b/drivers/firmware/google/framebuffer-coreboot.c
@@ -15,6 +15,7 @@
#include <linux/module.h>
#include <linux/platform_data/simplefb.h>
#include <linux/platform_device.h>
+#include <linux/screen_info.h>
#include "coreboot_table.h"
@@ -27,6 +28,7 @@ static int framebuffer_probe(struct coreboot_device *dev)
int i;
u32 length;
struct lb_framebuffer *fb = &dev->framebuffer;
+ struct screen_info *si = &screen_info;
struct platform_device *pdev;
struct resource res;
struct simplefb_platform_data pdata = {
@@ -36,6 +38,20 @@ static int framebuffer_probe(struct coreboot_device *dev)
.format = NULL,
};
+ /*
+ * If the global screen_info data has been filled, the Generic
+ * System Framebuffers (sysfb) will already register a platform
+ * and pass the screen_info as platform_data to a driver that
+ * could scan-out using the system provided framebuffer.
+ *
+ * On Coreboot systems, the advertise LB_TAG_FRAMEBUFFER entry
+ * in the Coreboot table should only be used if the payload did
+ * not set video mode info and passed it to the Linux kernel.
+ */
+ if (si->orig_video_isVGA == VIDEO_TYPE_VLFB ||
+ si->orig_video_isVGA == VIDEO_TYPE_EFI)
+ return -EINVAL;
+
if (!fb->physical_address)
return -ENODEV;
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat