[PATCH 3/3] video: aperture: hand off EFI earlycon on aperture ackquisition
From: Mikhail Rudenko
Date: Wed Nov 25 2026 - 12:04:08 EST
With keep_bootcon, EFI earlycon can keep writing to the firmware
framebuffer while a graphics driver takes over. Add a handoff option
that unregisters it after framebuffer/drm device successfully acquires
its aperture or when a conflicting-device removal helper is
called. The option opt-in, default behavior is preserved.
When handoff option is effective, unregister the EFI earlycon when a
graphics device driver ackquires aperture (unless it was unregistered
earlier).
Signed-off-by: Mikhail Rudenko <xyzzy@xxxxxxxxxxxxxx>
---
Documentation/admin-guide/kernel-parameters.txt | 5 +++-
drivers/firmware/efi/earlycon.c | 37 ++++++++++++++++++++++++-
drivers/video/aperture.c | 13 ++++++++-
include/linux/efi.h | 7 +++++
4 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 0b3c140babd94..829bb01cc10d0 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1532,7 +1532,10 @@ Kernel parameters
memory mapped framebuffer (if available). On cache
coherent non-x86 systems that use system memory for
the framebuffer, pass the 'ram' option so that it is
- mapped with the correct attributes.
+ mapped with the correct attributes. Pass 'handoff' with
+ keep_bootcon to retain EFI earlycon until a graphics
+ driver acquires a firmware framebuffer aperture. Options
+ may be combined, e.g. earlycon=efifb,ram,handoff.
linflex,<addr>
Use early console provided by Freescale LINFlexD UART
diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c
index 3a6eaf5481f40..9d65777d225e1 100644
--- a/drivers/firmware/efi/earlycon.c
+++ b/drivers/firmware/efi/earlycon.c
@@ -21,8 +21,20 @@ static u32 efi_x_array[1024];
static u32 efi_x, efi_y;
static u64 fb_base;
static bool fb_wb;
+static bool fb_handoff;
static void *efi_fb;
+void efi_earlycon_unregister(void)
+{
+ struct console *con = READ_ONCE(earlycon_console);
+
+ if (!con || !fb_handoff)
+ return;
+
+ if (console_is_registered(con))
+ unregister_console(con);
+}
+
/*
* EFI earlycon needs to use early_memremap() to map the framebuffer.
* But early_memremap() is not usable for 'earlycon=efifb keep_bootcon',
@@ -219,6 +231,29 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
static bool __initdata fb_probed;
+static void __init efi_earlycon_parse_options(const char *opt)
+{
+ /* Reprobe has no options; retain those parsed on the first attempt. */
+ if (!opt)
+ return;
+
+ fb_wb = false;
+ fb_handoff = false;
+
+ while (*opt) {
+ size_t len = strcspn(opt, ",");
+
+ if (len == 3 && !strncmp(opt, "ram", len))
+ fb_wb = true;
+ else if (len == 7 && !strncmp(opt, "handoff", len))
+ fb_handoff = true;
+
+ opt += len;
+ if (*opt)
+ opt++;
+ }
+}
+
void __init efi_earlycon_reprobe(void)
{
if (fb_probed)
@@ -232,7 +267,7 @@ static int __init efi_earlycon_setup(struct earlycon_device *device,
u16 xres, yres;
u32 i;
- fb_wb = opt && !strcmp(opt, "ram");
+ efi_earlycon_parse_options(opt);
if (si->orig_video_isVGA != VIDEO_TYPE_EFI) {
fb_probed = true;
diff --git a/drivers/video/aperture.c b/drivers/video/aperture.c
index 2b5a1e666e9b2..249b037562103 100644
--- a/drivers/video/aperture.c
+++ b/drivers/video/aperture.c
@@ -2,6 +2,7 @@
#include <linux/aperture.h>
#include <linux/device.h>
+#include <linux/efi.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/pci.h>
@@ -240,7 +241,13 @@ int devm_aperture_acquire_for_platform_device(struct platform_device *pdev,
resource_size_t base,
resource_size_t size)
{
- return devm_aperture_acquire(&pdev->dev, base, size, aperture_detach_platform_device);
+ int ret;
+
+ ret = devm_aperture_acquire(&pdev->dev, base, size, aperture_detach_platform_device);
+ if (!ret)
+ efi_earlycon_unregister();
+
+ return ret;
}
EXPORT_SYMBOL(devm_aperture_acquire_for_platform_device);
@@ -284,6 +291,8 @@ static void aperture_detach_devices(resource_size_t base, resource_size_t size)
int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
const char *name)
{
+ efi_earlycon_unregister();
+
/*
* If a driver asked to unregister a platform device registered by
* sysfb, then can be assumed that this is a driver for a display
@@ -349,6 +358,8 @@ int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *na
resource_size_t base, size;
int bar, ret = 0;
+ efi_earlycon_unregister();
+
sysfb_disable(&pdev->dev);
for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
diff --git a/include/linux/efi.h b/include/linux/efi.h
index cc1df1577d5fb..44cff6fe53f90 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -720,6 +720,13 @@ efi_guid_to_str(const efi_guid_t *guid, char *out)
extern void efi_init (void);
extern void efi_earlycon_reprobe(void);
+#ifdef CONFIG_EFI_EARLYCON
+void efi_earlycon_unregister(void);
+#else
+static inline void efi_earlycon_unregister(void)
+{
+}
+#endif
#ifdef CONFIG_EFI
extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
#else
--
2.56.1