Skip to contentSkip to conversation

efi: earlycon: Reprobe after parsing config tables

PATCH In review Ard Biesheuvel 2 participants 2 messages Mar 12, 2023 – Mar 13, 2023 EFI

lore
Share & tools
lore

Ard Biesheuvel

author maintainer
#0 lore raw

PATCH 1/1 efi: earlycon: Reprobe after parsing config tables

Commit 732ea9db9d8a ("efi: libstub: Move screen_info handling to common code") reorganized the earlycon handling so that all architectures pass the screen_info data via a EFI config table instead of populating struct screen_info directly, as the latter is only possible when the EFI stub is baked into the kernel (and not into the decompressor).

However, this means that struct screen_info may not have been populated yet by the time the earlycon probe takes place, and this results in a non-functional early console.

So let's probe again right after parsing the config tables and populating struct screen_info. Note that this means that earlycon output starts a bit later than before, and so it may fail to capture issues that occur while doing the early EFI initialization.

Cc Xuefeng Li <[email protected]>
Cc Xuerui Wang <[email protected]>
Cc Huacai Chen <[email protected]>
Fixes 732ea9db9d8a ("efi: libstub: Move screen_info handling to common code")
---
 drivers/firmware/efi/earlycon.c | 16 +++++++++++++---
 drivers/firmware/efi/efi-init.c |  2 ++
 include/linux/efi.h             |  1 +
 3 files changed, 16 insertions(+), 3 deletions(-)
drivers/firmware/efi/earlycon.c +13 -3
index f54e6fdf08e2bf4c..f80a9af3d16e94de 100644
@@ -215,6 +215,14 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
 	}
 }
 
+static bool __initdata fb_probed;
+
+void __init efi_earlycon_reprobe(void)
+{
+	if (fb_probed)
+		setup_earlycon("efifb");
+}
+
 static int __init efi_earlycon_setup(struct earlycon_device *device,
 				     const char *opt)
 {
@@ -222,15 +230,17 @@ static int __init efi_earlycon_setup(struct earlycon_device *device,
 	u16 xres, yres;
 	u32 i;
 
-	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
+	fb_wb = opt && !strcmp(opt, "ram");
+
+	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) {
+		fb_probed = true;
 		return -ENODEV;
+	}
 
 	fb_base = screen_info.lfb_base;
 	if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
 		fb_base |= (u64)screen_info.ext_lfb_base << 32;
 
-	fb_wb = opt && !strcmp(opt, "ram");
-
 	si = &screen_info;
 	xres = si->lfb_width;
 	yres = si->lfb_height;
drivers/firmware/efi/efi-init.c +2 -0
index 2c16080e1f71907c..e6deb3c3ebe67b9f 100644
@@ -72,6 +72,8 @@ static void __init init_screen_info(void)
 		if (memblock_is_map_memory(screen_info.lfb_base))
 			memblock_mark_nomap(screen_info.lfb_base,
 					    screen_info.lfb_size);
+
+		efi_earlycon_reprobe();
 	}
 }
 
include/linux/efi.h +1 -0
index 04a733f0ba956211..7aa62c92185f6467 100644
@@ -693,6 +693,7 @@ efi_guid_to_str(efi_guid_t *guid, char *out)
 }
 
 extern void efi_init (void);
+extern void efi_earlycon_reprobe(void);
 #ifdef CONFIG_EFI
 extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
 #else
Signature · 1 line
2.39.2
Tested-by on v1 1/1
#1 lore raw
Quoted 16 lines · Ard Biesheuvel

Commit 732ea9db9d8a ("efi: libstub: Move screen_info handling to common code") reorganized the earlycon handling so that all architectures pass the screen_info data via a EFI config table instead of populating struct screen_info directly, as the latter is only possible when the EFI stub is baked into the kernel (and not into the decompressor).

However, this means that struct screen_info may not have been populated yet by the time the earlycon probe takes place, and this results in a non-functional early console.

So let's probe again right after parsing the config tables and populating struct screen_info. Note that this means that earlycon output starts a bit later than before, and so it may fail to capture issues that occur while doing the early EFI initialization.

Quoted 6 lines
Cc Xuefeng Li <[email protected]>
Cc Xuerui Wang <[email protected]>
Cc Huacai Chen <[email protected]>
Fixes 732ea9db9d8a ("efi: libstub: Move screen_info handling to common code")

Thanks for the fix! On Snapdragon laptops: