Skip to content

Commit 2f66294

Browse files
andy-shevkelmously
authored andcommitted
efi/earlycon: Remap entire framebuffer after page initialization
BugLink: https://bugs.launchpad.net/bugs/1861929 [ Upstream commit b418d66 ] When commit: 69c1f39 ("efi/x86: Convert x86 EFI earlyprintk into generic earlycon implementation") moved the x86 specific EFI earlyprintk implementation to a shared location, it also tweaked the behaviour. In particular, it dropped a trick with full framebuffer remapping after page initialization, leading to two regressions: 1) very slow scrolling after page initialization, 2) kernel hang when the 'keep_bootcon' command line argument is passed. Putting the tweak back fixes #2 and mitigates #1, i.e., it limits the slow behavior to the early boot stages, presumably due to eliminating heavy map()/unmap() operations per each pixel line on the screen. [ ardb: ensure efifb is unmapped again unless keep_bootcon is in effect. ] [ mingo: speling fixes. ] Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Cc: Arvind Sankar <nivedita@alum.mit.edu> Cc: Bhupesh Sharma <bhsharma@redhat.com> Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> Cc: linux-efi@vger.kernel.org Fixes: 69c1f39 ("efi/x86: Convert x86 EFI earlyprintk into generic earlycon implementation") Link: https://lkml.kernel.org/r/20191206165542.31469-7-ardb@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
1 parent 425f493 commit 2f66294

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

drivers/firmware/efi/earlycon.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,57 @@
1313

1414
#include <asm/early_ioremap.h>
1515

16+
static const struct console *earlycon_console __initdata;
1617
static const struct font_desc *font;
1718
static u32 efi_x, efi_y;
1819
static u64 fb_base;
1920
static pgprot_t fb_prot;
21+
static void *efi_fb;
22+
23+
/*
24+
* EFI earlycon needs to use early_memremap() to map the framebuffer.
25+
* But early_memremap() is not usable for 'earlycon=efifb keep_bootcon',
26+
* memremap() should be used instead. memremap() will be available after
27+
* paging_init() which is earlier than initcall callbacks. Thus adding this
28+
* early initcall function early_efi_map_fb() to map the whole EFI framebuffer.
29+
*/
30+
static int __init efi_earlycon_remap_fb(void)
31+
{
32+
/* bail if there is no bootconsole or it has been disabled already */
33+
if (!earlycon_console || !(earlycon_console->flags & CON_ENABLED))
34+
return 0;
35+
36+
if (pgprot_val(fb_prot) == pgprot_val(PAGE_KERNEL))
37+
efi_fb = memremap(fb_base, screen_info.lfb_size, MEMREMAP_WB);
38+
else
39+
efi_fb = memremap(fb_base, screen_info.lfb_size, MEMREMAP_WC);
40+
41+
return efi_fb ? 0 : -ENOMEM;
42+
}
43+
early_initcall(efi_earlycon_remap_fb);
44+
45+
static int __init efi_earlycon_unmap_fb(void)
46+
{
47+
/* unmap the bootconsole fb unless keep_bootcon has left it enabled */
48+
if (efi_fb && !(earlycon_console->flags & CON_ENABLED))
49+
memunmap(efi_fb);
50+
return 0;
51+
}
52+
late_initcall(efi_earlycon_unmap_fb);
2053

2154
static __ref void *efi_earlycon_map(unsigned long start, unsigned long len)
2255
{
56+
if (efi_fb)
57+
return efi_fb + start;
58+
2359
return early_memremap_prot(fb_base + start, len, pgprot_val(fb_prot));
2460
}
2561

2662
static __ref void efi_earlycon_unmap(void *addr, unsigned long len)
2763
{
64+
if (efi_fb)
65+
return;
66+
2867
early_memunmap(addr, len);
2968
}
3069

@@ -201,6 +240,7 @@ static int __init efi_earlycon_setup(struct earlycon_device *device,
201240
efi_earlycon_scroll_up();
202241

203242
device->con->write = efi_earlycon_write;
243+
earlycon_console = device->con;
204244
return 0;
205245
}
206246
EARLYCON_DECLARE(efifb, efi_earlycon_setup);

0 commit comments

Comments
 (0)