efi: move screen_info into efi init code
authorArnd Bergmann <arnd@arndb.de>
Tue, 17 Oct 2023 09:39:46 +0000 (11:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Oct 2023 14:33:39 +0000 (16:33 +0200)
After the vga console no longer relies on global screen_info, there are
only two remaining use cases:

 - on the x86 architecture, it is used for multiple boot methods
   (bzImage, EFI, Xen, kexec) to commucate the initial VGA or framebuffer
   settings to a number of device drivers.

 - on other architectures, it is only used as part of the EFI stub,
   and only for the three sysfb framebuffers (simpledrm, simplefb, efifb).

Remove the duplicate data structure definitions by moving it into the
efi-init.c file that sets it up initially for the EFI case, leaving x86
as an exception that retains its own definition for non-EFI boots.

The added #ifdefs here are optional, I added them to further limit the
reach of screen_info to configurations that have at least one of the
users enabled.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Acked-by: Helge Deller <deller@gmx.de>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20231017093947.3627976-1-arnd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/kernel/efi.c
arch/arm64/kernel/image-vars.h
arch/loongarch/kernel/efi.c
arch/loongarch/kernel/image-vars.h
arch/loongarch/kernel/setup.c
arch/riscv/kernel/image-vars.h
arch/riscv/kernel/setup.c
drivers/firmware/efi/efi-init.c
drivers/firmware/efi/libstub/efi-stub-entry.c

index 2b478ca356b00f1f71c11d40e6bb6eb66cf9b173..52089f111c8db25cb08efb3a48235a4ad36e0f72 100644 (file)
@@ -71,10 +71,6 @@ static __init pteval_t create_mapping_protection(efi_memory_desc_t *md)
        return pgprot_val(PAGE_KERNEL_EXEC);
 }
 
-/* we will fill this structure from the stub, so don't put it in .bss */
-struct screen_info screen_info __section(".data");
-EXPORT_SYMBOL(screen_info);
-
 int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
 {
        pteval_t prot_val = create_mapping_protection(md);
index 35f3c795951373549faad3ed2d1bd30ad427eb78..5e4dc72ab1bdac5f51250a381ee53213ad106283 100644 (file)
@@ -27,7 +27,9 @@ PROVIDE(__efistub__text                       = _text);
 PROVIDE(__efistub__end                 = _end);
 PROVIDE(__efistub___inittext_end               = __inittext_end);
 PROVIDE(__efistub__edata               = _edata);
+#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
 PROVIDE(__efistub_screen_info          = screen_info);
+#endif
 PROVIDE(__efistub__ctype               = _ctype);
 
 PROVIDE(__pi___memcpy                  = __pi_memcpy);
index 9fc10cea21e10e387ef47f3fac85a9c3fc5fc66c..acb5d3385675c974d98a71b8b659ed1088914acd 100644 (file)
@@ -68,6 +68,11 @@ void __init efi_runtime_init(void)
 
 unsigned long __initdata screen_info_table = EFI_INVALID_TABLE_ADDR;
 
+#if defined(CONFIG_SYSFB) || defined(CONFIG_EFI_EARLYCON)
+struct screen_info screen_info __section(".data");
+EXPORT_SYMBOL_GPL(screen_info);
+#endif
+
 static void __init init_screen_info(void)
 {
        struct screen_info *si;
@@ -115,7 +120,8 @@ void __init efi_init(void)
 
        set_bit(EFI_CONFIG_TABLES, &efi.flags);
 
-       init_screen_info();
+       if (IS_ENABLED(CONFIG_EFI_EARLYCON) || IS_ENABLED(CONFIG_SYSFB))
+               init_screen_info();
 
        if (boot_memmap == EFI_INVALID_TABLE_ADDR)
                return;
index e561989d02de93c500b1a8b5d6ac44fb8ece75d8..5087416b9678d650d199ddc015628ec41de2625c 100644 (file)
@@ -12,7 +12,9 @@ __efistub_kernel_entry                = kernel_entry;
 __efistub_kernel_asize         = kernel_asize;
 __efistub_kernel_fsize         = kernel_fsize;
 __efistub_kernel_offset                = kernel_offset;
+#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
 __efistub_screen_info          = screen_info;
+#endif
 
 #endif
 
index 4ae0ad43c354ee39f8258242a51dd7519bb379fc..2bf1f6977d525869189ac3633efedb273a43a807 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/dmi.h>
 #include <linux/efi.h>
 #include <linux/export.h>
-#include <linux/screen_info.h>
 #include <linux/memblock.h>
 #include <linux/initrd.h>
 #include <linux/ioport.h>
 #define SMBIOS_CORE_PACKAGE_OFFSET     0x23
 #define LOONGSON_EFI_ENABLE            (1 << 3)
 
-#ifdef CONFIG_EFI
-struct screen_info screen_info __section(".data");
-#endif
-
 unsigned long fw_arg0, fw_arg1, fw_arg2;
 DEFINE_PER_CPU(unsigned long, kernelsp);
 struct cpuinfo_loongarch cpu_data[NR_CPUS] __read_mostly;
index ea1a10355ce908a0f75d7f76ba99c72bfc507a77..3df30dd1c458bafe7f38385d516499baf027154e 100644 (file)
@@ -28,7 +28,9 @@ __efistub__start_kernel               = _start_kernel;
 __efistub__end                 = _end;
 __efistub__edata               = _edata;
 __efistub___init_text_end      = __init_text_end;
+#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
 __efistub_screen_info          = screen_info;
+#endif
 
 #endif
 
index 0c466a50f1744e7f068d56c7caad845a39cf64eb..0624f44d43eca13ed1a0619fae0c4922fd52d384 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/memblock.h>
 #include <linux/sched.h>
 #include <linux/console.h>
-#include <linux/screen_info.h>
 #include <linux/of_fdt.h>
 #include <linux/sched/task.h>
 #include <linux/smp.h>
 
 #include "head.h"
 
-#if defined(CONFIG_EFI)
-struct screen_info screen_info __section(".data");
-#endif
-
 /*
  * The lucky hart to first increment this variable will boot the other cores.
  * This is used before the kernel initializes the BSS so it can't be in the
index ef0820f1a9246ede74aa4a7aec41938628d2c755..d4987d013080174bda0e462f029c03192897bebb 100644 (file)
@@ -55,6 +55,15 @@ static phys_addr_t __init efi_to_phys(unsigned long addr)
 
 extern __weak const efi_config_table_type_t efi_arch_tables[];
 
+/*
+ * x86 defines its own screen_info and uses it even without EFI,
+ * everything else can get it from here.
+ */
+#if !defined(CONFIG_X86) && (defined(CONFIG_SYSFB) || defined(CONFIG_EFI_EARLYCON))
+struct screen_info screen_info __section(".data");
+EXPORT_SYMBOL_GPL(screen_info);
+#endif
+
 static void __init init_screen_info(void)
 {
        struct screen_info *si;
@@ -240,5 +249,8 @@ void __init efi_init(void)
        memblock_reserve(data.phys_map & PAGE_MASK,
                         PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
 
-       init_screen_info();
+       if (IS_ENABLED(CONFIG_X86) ||
+           IS_ENABLED(CONFIG_SYSFB) ||
+           IS_ENABLED(CONFIG_EFI_EARLYCON))
+               init_screen_info();
 }
index 2f1902e5d407536bc4bd23a713fb12c77445d737..a6c0498351905cbf54b25498797c578dfa4688de 100644 (file)
@@ -13,7 +13,13 @@ struct screen_info *alloc_screen_info(void)
 {
        if (IS_ENABLED(CONFIG_ARM))
                return __alloc_screen_info();
-       return (void *)&screen_info + screen_info_offset;
+
+       if (IS_ENABLED(CONFIG_X86) ||
+           IS_ENABLED(CONFIG_EFI_EARLYCON) ||
+           IS_ENABLED(CONFIG_SYSFB))
+               return (void *)&screen_info + screen_info_offset;
+
+       return NULL;
 }
 
 /*