Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp1492293ima; Sat, 2 Feb 2019 01:42:19 -0800 (PST) X-Google-Smtp-Source: AHgI3IbglvovA8kAXGSqPcQRdRGGwyxiX3RjCqaGucKVjXh3SVVbBdn/ndsKejYsJGajhWqyyWD9 X-Received: by 2002:a63:d10:: with SMTP id c16mr5616996pgl.382.1549100539006; Sat, 02 Feb 2019 01:42:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549100538; cv=none; d=google.com; s=arc-20160816; b=LOYhXTbMJCRMs7qkgc9LcoZxB7nI1M3ElGNAdH3U4l0FDVQULKxrj39WIbo8uxjfGr qrzHO0rkjpc9jWKNiuxA9FlMSuXpTw9DqCOlshUle+DzwFVB7z1um0qWU1kXtoHhr7Ly bKiNXdkSFFFMH2YW2KUpD0hEZUZrVsbuCnu5i8ObxLQa16G690uH0wLEvD+14wzrlrB7 HnHipZAU2NJPHyoyHEeHbOgDl/jyvZ2h9MC/Qj/+a9237ZNekfIPGt7iUdramlVi1eL+ afAoD19x8HFxhsBbZkwWRwjEJku3C5eKaHTttqsARozsFLH09DqvHNaEVkyzhytsQ8dz LqKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=mwg5Ah8nIeO+W6wCFX0pD1gr7HS/By0xQ7PGiMwrE2s=; b=KlVqrUKTMt4lni/9VMYijfEY8KuBM4OWcz6mLimytMSVf5sHndYE9gqIGzyHSn2aN4 2lA7B+RM59+5oMU5JNtmROg5G4gXbR+X86nDMS23e9BP47cc/HCf0pM5lwVfmSopHOX5 e7ucVeQKTeN0WEyYleulgngvsiXusI4tURXcDwTaFrLU5PFI7gTJZKTCGFJ7l4JkTlaN +apOtLsPOOk1Cn1MuZm4GlHTjHwThTHwCWqDFu+L9O/5uKVSgIlv5R4kOk+crdxGfyle VFoJV0UtSePBiJHkyC7rFBR0XrGB2aykVCYa613kpmqduwmurvJsI3c+xGUjAgeQCwD0 LUXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CE6Ftvng; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h20si9396832pgm.366.2019.02.02.01.42.03; Sat, 02 Feb 2019 01:42:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CE6Ftvng; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727814AbfBBJls (ORCPT + 99 others); Sat, 2 Feb 2019 04:41:48 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:45611 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727694AbfBBJlm (ORCPT ); Sat, 2 Feb 2019 04:41:42 -0500 Received: by mail-ed1-f65.google.com with SMTP id d39so7431581edb.12 for ; Sat, 02 Feb 2019 01:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mwg5Ah8nIeO+W6wCFX0pD1gr7HS/By0xQ7PGiMwrE2s=; b=CE6FtvngQ/Bk90WPH8q8dXWzZR+FGcM7FXzD34i3EMmRJQmixmgPeO4jH2QAdNePH/ /LJSL7e2cQZOrZxBhEp97axtCzh1JbCqV4PK7LZaRo/ieFSQAvGtuuuE/70ebSfHkk+x Sxlmholng5PLaqxZsC+QV+OnCHqBQUCkLUtJg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mwg5Ah8nIeO+W6wCFX0pD1gr7HS/By0xQ7PGiMwrE2s=; b=DAwOa6A1OOG9UZD7aSbn6Dskr9WjBhpRPZuwn9OhtlxKCN3e3GAYPrD6gw9S9XuARa zJYoJgbBoRIv3eaBDFUlSLrrUetbBVVGcsPH8eqe4B4wlAOaK/IE87JWmMfxxbv0XZCd EhhI1YcKD5348pwRuSIyB9Nv2jKL8avwK3AItvkZemL+XRihSVSjqN4kFguPD9H3/bKT qyIcD+33WzIgzfNyL3/HwTTo3tZZUXA/dLkVzPcad0A6Hpd84yR18uni5dDtqxDG3KQV vq+s7FxLu67Ca+f21tS+RNT3jwk8H4ASr8JGciPONbaAEUpyqTWn2N5yQq2/dBhCceIL v7Kw== X-Gm-Message-State: AJcUukcGWqUGxDQ2D7s6Fr6oFX7viNkXWGkkKvFOccuxirINABNN74T0 2zkzBRbH+IsrUZz9BGJHrL7a6w== X-Received: by 2002:a17:906:f110:: with SMTP id gv16mr22414567ejb.223.1549100500406; Sat, 02 Feb 2019 01:41:40 -0800 (PST) Received: from mba13.c.hoisthospitality.com ([109.236.135.164]) by smtp.gmail.com with ESMTPSA id l41sm2608824eda.83.2019.02.02.01.41.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 01:41:39 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, AKASHI Takahiro , Alexander Graf , Bjorn Andersson , Borislav Petkov , Heinrich Schuchardt , Jeffrey Hugo , Lee Jones , Leif Lindholm , Linus Torvalds , Peter Jones , Peter Zijlstra , Sai Praneeth Prakhya Subject: [PATCH 09/10] efi: x86: convert x86 EFI earlyprintk into generic earlycon implementation Date: Sat, 2 Feb 2019 10:41:18 +0100 Message-Id: <20190202094119.13230-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202094119.13230-1-ard.biesheuvel@linaro.org> References: <20190202094119.13230-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the x86 EFI earlyprintk implementation to a shared location under drivers/firmware and tweak it slightly so we can expose it as an earlycon implementation (which is generic) rather than earlyprintk (which is only implemented for a few architectures) This also involves switching to write-combine mappings by default (which is required on ARM since device mappings lack memory semantics, and so memcpy/memset may not be used on them), and adding support for shared memory framebuffers on cache coherent non-x86 systems (which do not tolerate mismatched attributes) Note that 32-bit ARM does not populate its struct screen_info early enough for earlycon=efifb to work, so it is disabled there. Reviewed-by: Alexander Graf Signed-off-by: Ard Biesheuvel --- .../admin-guide/kernel-parameters.txt | 8 +- arch/x86/Kconfig.debug | 10 -- arch/x86/include/asm/efi.h | 1 - arch/x86/kernel/early_printk.c | 4 - arch/x86/platform/efi/Makefile | 1 - drivers/firmware/efi/Kconfig | 6 + drivers/firmware/efi/Makefile | 1 + .../firmware/efi/earlycon.c | 134 +++++++----------- 8 files changed, 64 insertions(+), 101 deletions(-) rename arch/x86/platform/efi/early_printk.c => drivers/firmware/efi/earlycon.c (42%) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index b799bcf67d7b..76dd3baa31e0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1073,9 +1073,15 @@ specified address. The serial port must already be setup and configured. Options are not yet supported. + efifb,[options] + Start an early, unaccelerated console on the EFI + 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. + earlyprintk= [X86,SH,ARM,M68k,S390] earlyprintk=vga - earlyprintk=efi earlyprintk=sclp earlyprintk=xen earlyprintk=serial[,ttySn[,baudrate]] diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index 0723dff17e6c..15d0fbe27872 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -40,16 +40,6 @@ config EARLY_PRINTK_DBGP with klogd/syslogd or the X server. You should normally say N here, unless you want to debug such a crash. You need usb debug device. -config EARLY_PRINTK_EFI - bool "Early printk via the EFI framebuffer" - depends on EFI && EARLY_PRINTK - select FONT_SUPPORT - ---help--- - Write kernel log output directly into the EFI framebuffer. - - This is useful for kernel debugging when your machine crashes very - early before the console code is initialized. - config EARLY_PRINTK_USB_XDBC bool "Early printk via the xHCI debug port" depends on EARLY_PRINTK && PCI diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index a37378f986ec..08ebb2270d87 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -170,7 +170,6 @@ static inline bool efi_runtime_supported(void) return false; } -extern struct console early_efi_console; extern void parse_efi_setup(u64 phys_addr, u32 data_len); extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt); diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c index 374a52fa5296..9b33904251a9 100644 --- a/arch/x86/kernel/early_printk.c +++ b/arch/x86/kernel/early_printk.c @@ -388,10 +388,6 @@ static int __init setup_early_printk(char *buf) if (!strncmp(buf, "xen", 3)) early_console_register(&xenboot_console, keep); #endif -#ifdef CONFIG_EARLY_PRINTK_EFI - if (!strncmp(buf, "efi", 3)) - early_console_register(&early_efi_console, keep); -#endif #ifdef CONFIG_EARLY_PRINTK_USB_XDBC if (!strncmp(buf, "xdbc", 4)) early_xdbc_parse_parameter(buf + 4); diff --git a/arch/x86/platform/efi/Makefile b/arch/x86/platform/efi/Makefile index e4dc3862d423..fe29f3f5d384 100644 --- a/arch/x86/platform/efi/Makefile +++ b/arch/x86/platform/efi/Makefile @@ -3,5 +3,4 @@ OBJECT_FILES_NON_STANDARD_efi_thunk_$(BITS).o := y OBJECT_FILES_NON_STANDARD_efi_stub_$(BITS).o := y obj-$(CONFIG_EFI) += quirks.o efi.o efi_$(BITS).o efi_stub_$(BITS).o -obj-$(CONFIG_EARLY_PRINTK_EFI) += early_printk.o obj-$(CONFIG_EFI_MIXED) += efi_thunk_$(BITS).o diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 89110dfc7127..190be0b1d109 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -198,3 +198,9 @@ config EFI_DEV_PATH_PARSER bool depends on ACPI default n + +config EFI_EARLYCON + def_bool y + depends on SERIAL_EARLYCON && !ARM && !IA64 + select FONT_SUPPORT + select ARCH_USE_MEMREMAP_PROT diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index 5f9f5039de50..d2d0d2030620 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -30,5 +30,6 @@ arm-obj-$(CONFIG_EFI) := arm-init.o arm-runtime.o obj-$(CONFIG_ARM) += $(arm-obj-y) obj-$(CONFIG_ARM64) += $(arm-obj-y) obj-$(CONFIG_EFI_CAPSULE_LOADER) += capsule-loader.o +obj-$(CONFIG_EFI_EARLYCON) += earlycon.o obj-$(CONFIG_UEFI_CPER_ARM) += cper-arm.o obj-$(CONFIG_UEFI_CPER_X86) += cper-x86.o diff --git a/arch/x86/platform/efi/early_printk.c b/drivers/firmware/efi/earlycon.c similarity index 42% rename from arch/x86/platform/efi/early_printk.c rename to drivers/firmware/efi/earlycon.c index 7138bc7a265c..dc1ae14ea4cf 100644 --- a/arch/x86/platform/efi/early_printk.c +++ b/drivers/firmware/efi/earlycon.c @@ -1,8 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2013 Intel Corporation; author Matt Fleming - * - * This file is part of the Linux kernel, and is made available under - * the terms of the GNU General Public License version 2. */ #include @@ -10,104 +8,68 @@ #include #include #include -#include +#include +#include + +#include static const struct font_desc *font; static u32 efi_x, efi_y; -static void *efi_fb; -static bool early_efi_keep; - -/* - * efi earlyprintk need use early_ioremap to map the framebuffer. - * But early_ioremap is not usable for earlyprintk=efi,keep, ioremap should - * be used instead. ioremap will be available after paging_init() which is - * earlier than initcall callbacks. Thus adding this early initcall function - * early_efi_map_fb to map the whole efi framebuffer. - */ -static __init int early_efi_map_fb(void) -{ - u64 base, size; +static u64 fb_base; +static pgprot_t fb_prot; - if (!early_efi_keep) - return 0; - - base = boot_params.screen_info.lfb_base; - if (boot_params.screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) - base |= (u64)boot_params.screen_info.ext_lfb_base << 32; - size = boot_params.screen_info.lfb_size; - efi_fb = ioremap(base, size); - - return efi_fb ? 0 : -ENOMEM; -} -early_initcall(early_efi_map_fb); - -/* - * early_efi_map maps efi framebuffer region [start, start + len -1] - * In case earlyprintk=efi,keep we have the whole framebuffer mapped already - * so just return the offset efi_fb + start. - */ -static __ref void *early_efi_map(unsigned long start, unsigned long len) +static __ref void *efi_earlycon_map(unsigned long start, unsigned long len) { - u64 base; - - base = boot_params.screen_info.lfb_base; - if (boot_params.screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) - base |= (u64)boot_params.screen_info.ext_lfb_base << 32; - - if (efi_fb) - return (efi_fb + start); - else - return early_ioremap(base + start, len); + return early_memremap_prot(fb_base + start, len, pgprot_val(fb_prot)); } -static __ref void early_efi_unmap(void *addr, unsigned long len) +static __ref void efi_earlycon_unmap(void *addr, unsigned long len) { - if (!efi_fb) - early_iounmap(addr, len); + early_memunmap(addr, len); } -static void early_efi_clear_scanline(unsigned int y) +static void efi_earlycon_clear_scanline(unsigned int y) { unsigned long *dst; u16 len; - len = boot_params.screen_info.lfb_linelength; - dst = early_efi_map(y*len, len); + len = screen_info.lfb_linelength; + dst = efi_earlycon_map(y*len, len); if (!dst) return; memset(dst, 0, len); - early_efi_unmap(dst, len); + efi_earlycon_unmap(dst, len); } -static void early_efi_scroll_up(void) +static void efi_earlycon_scroll_up(void) { unsigned long *dst, *src; u16 len; u32 i, height; - len = boot_params.screen_info.lfb_linelength; - height = boot_params.screen_info.lfb_height; + len = screen_info.lfb_linelength; + height = screen_info.lfb_height; for (i = 0; i < height - font->height; i++) { - dst = early_efi_map(i*len, len); + dst = efi_earlycon_map(i*len, len); if (!dst) return; - src = early_efi_map((i + font->height) * len, len); + src = efi_earlycon_map((i + font->height) * len, len); if (!src) { - early_efi_unmap(dst, len); + efi_earlycon_unmap(dst, len); return; } memmove(dst, src, len); - early_efi_unmap(src, len); - early_efi_unmap(dst, len); + efi_earlycon_unmap(src, len); + efi_earlycon_unmap(dst, len); } } -static void early_efi_write_char(u32 *dst, unsigned char c, unsigned int h) +static void efi_earlycon_write_char(u32 *dst, unsigned char c, unsigned int h) { const u32 color_black = 0x00000000; const u32 color_white = 0x00ffffff; @@ -128,14 +90,14 @@ static void early_efi_write_char(u32 *dst, unsigned char c, unsigned int h) } static void -early_efi_write(struct console *con, const char *str, unsigned int num) +efi_earlycon_write(struct console *con, const char *str, unsigned int num) { struct screen_info *si; unsigned int len; const char *s; void *dst; - si = &boot_params.screen_info; + si = &screen_info; len = si->lfb_linelength; while (num) { @@ -155,7 +117,7 @@ early_efi_write(struct console *con, const char *str, unsigned int num) for (h = 0; h < font->height; h++) { unsigned int n, x; - dst = early_efi_map((efi_y + h) * len, len); + dst = efi_earlycon_map((efi_y + h) * len, len); if (!dst) return; @@ -164,12 +126,12 @@ early_efi_write(struct console *con, const char *str, unsigned int num) x = efi_x; while (n-- > 0) { - early_efi_write_char(dst + x*4, *s, h); + efi_earlycon_write_char(dst + x*4, *s, h); x += font->width; s++; } - early_efi_unmap(dst, len); + efi_earlycon_unmap(dst, len); } num -= count; @@ -192,26 +154,39 @@ early_efi_write(struct console *con, const char *str, unsigned int num) u32 i; efi_y -= font->height; - early_efi_scroll_up(); + efi_earlycon_scroll_up(); for (i = 0; i < font->height; i++) - early_efi_clear_scanline(efi_y + i); + efi_earlycon_clear_scanline(efi_y + i); } } } -static __init int early_efi_setup(struct console *con, char *options) +static int __init efi_earlycon_setup(struct earlycon_device *device, + const char *opt) { struct screen_info *si; u16 xres, yres; u32 i; - si = &boot_params.screen_info; + if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) + 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; + + if (opt && !strcmp(opt, "ram")) + fb_prot = PAGE_KERNEL; + else + fb_prot = pgprot_writecombine(PAGE_KERNEL); + + si = &screen_info; xres = si->lfb_width; yres = si->lfb_height; /* - * early_efi_write_char() implicitly assumes a framebuffer with + * efi_earlycon_write_char() implicitly assumes a framebuffer with * 32-bits per pixel. */ if (si->lfb_depth != 32) @@ -223,18 +198,9 @@ static __init int early_efi_setup(struct console *con, char *options) efi_y = rounddown(yres, font->height) - font->height; for (i = 0; i < (yres - efi_y) / font->height; i++) - early_efi_scroll_up(); + efi_earlycon_scroll_up(); - /* early_console_register will unset CON_BOOT in case ,keep */ - if (!(con->flags & CON_BOOT)) - early_efi_keep = true; + device->con->write = efi_earlycon_write; return 0; } - -struct console early_efi_console = { - .name = "earlyefi", - .write = early_efi_write, - .setup = early_efi_setup, - .flags = CON_PRINTBUFFER, - .index = -1, -}; +EARLYCON_DECLARE(efifb, efi_earlycon_setup); -- 2.17.1