]> git.baikalelectronics.ru Git - kernel.git/commitdiff
efi/arm: libstub: move ARM specific code out of generic routines
authorArd Biesheuvel <ardb@kernel.org>
Fri, 16 Sep 2022 08:04:57 +0000 (10:04 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 27 Sep 2022 11:26:16 +0000 (13:26 +0200)
Move some code that is only reachable when IS_ENABLED(CONFIG_ARM) into
the ARM EFI arch code.

Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/arm/include/asm/efi.h
arch/arm/kernel/efi.c
arch/arm/kernel/setup.c
drivers/firmware/efi/efi-init.c

index 3088ef72704e598b76f04df7b7c6773a594be5ef..4bdd930167c0f18c2d7dba832b0315a91264ff79 100644 (file)
@@ -17,6 +17,7 @@
 
 #ifdef CONFIG_EFI
 void efi_init(void);
+void arm_efi_init(void);
 
 int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
 int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
@@ -37,7 +38,7 @@ void efi_virtmap_load(void);
 void efi_virtmap_unload(void);
 
 #else
-#define efi_init()
+#define arm_efi_init()
 #endif /* CONFIG_EFI */
 
 /* arch specific definitions used by the stub code */
index e57dbcc89123e1ae515fe10557fc13d3f941338e..e50ad7eefc02a6eb08b2736644f4724fa3aad2ee 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/efi.h>
+#include <linux/memblock.h>
 #include <asm/efi.h>
 #include <asm/mach/map.h>
 #include <asm/mmu_context.h>
@@ -73,3 +74,81 @@ int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
                return efi_set_mapping_permissions(mm, md);
        return 0;
 }
+
+static unsigned long __initdata screen_info_table = EFI_INVALID_TABLE_ADDR;
+static unsigned long __initdata cpu_state_table = EFI_INVALID_TABLE_ADDR;
+
+const efi_config_table_type_t efi_arch_tables[] __initconst = {
+       {LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, &screen_info_table},
+       {LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
+       {}
+};
+
+static void __init load_screen_info_table(void)
+{
+       struct screen_info *si;
+
+       if (screen_info_table != EFI_INVALID_TABLE_ADDR) {
+               si = early_memremap_ro(screen_info_table, sizeof(*si));
+               if (!si) {
+                       pr_err("Could not map screen_info config table\n");
+                       return;
+               }
+               screen_info = *si;
+               early_memunmap(si, sizeof(*si));
+
+               /* dummycon on ARM needs non-zero values for columns/lines */
+               screen_info.orig_video_cols = 80;
+               screen_info.orig_video_lines = 25;
+
+               if (memblock_is_map_memory(screen_info.lfb_base))
+                       memblock_mark_nomap(screen_info.lfb_base,
+                                           screen_info.lfb_size);
+       }
+}
+
+static void __init load_cpu_state_table(void)
+{
+       if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
+               struct efi_arm_entry_state *state;
+               bool dump_state = true;
+
+               state = early_memremap_ro(cpu_state_table,
+                                         sizeof(struct efi_arm_entry_state));
+               if (state == NULL) {
+                       pr_warn("Unable to map CPU entry state table.\n");
+                       return;
+               }
+
+               if ((state->sctlr_before_ebs & 1) == 0)
+                       pr_warn(FW_BUG "EFI stub was entered with MMU and Dcache disabled, please fix your firmware!\n");
+               else if ((state->sctlr_after_ebs & 1) == 0)
+                       pr_warn(FW_BUG "ExitBootServices() returned with MMU and Dcache disabled, please fix your firmware!\n");
+               else
+                       dump_state = false;
+
+               if (dump_state || efi_enabled(EFI_DBG)) {
+                       pr_info("CPSR at EFI stub entry        : 0x%08x\n",
+                               state->cpsr_before_ebs);
+                       pr_info("SCTLR at EFI stub entry       : 0x%08x\n",
+                               state->sctlr_before_ebs);
+                       pr_info("CPSR after ExitBootServices() : 0x%08x\n",
+                               state->cpsr_after_ebs);
+                       pr_info("SCTLR after ExitBootServices(): 0x%08x\n",
+                               state->sctlr_after_ebs);
+               }
+               early_memunmap(state, sizeof(struct efi_arm_entry_state));
+       }
+}
+
+void __init arm_efi_init(void)
+{
+       efi_init();
+
+       load_screen_info_table();
+
+       /* ARM does not permit early mappings to persist across paging_init() */
+       efi_memmap_unmap();
+
+       load_cpu_state_table();
+}
index 1e8a50a97edf2e49dc2075b5b119a5d561010b86..cb88c6e69377319e1534776d8aeae35b979c56e4 100644 (file)
@@ -1141,7 +1141,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
        setup_dma_zone(mdesc);
        xen_early_init();
-       efi_init();
+       arm_efi_init();
        /*
         * Make sure the calculation for lowmem/highmem is set appropriately
         * before reserving/allocating any memory
index 3928dbff76d0410a0744d355227f5f6596115f70..2fd770b499a35301f2c0c04f09cd379fa11dcf30 100644 (file)
@@ -51,34 +51,10 @@ static phys_addr_t __init efi_to_phys(unsigned long addr)
        return addr;
 }
 
-static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR;
-static __initdata unsigned long cpu_state_table = EFI_INVALID_TABLE_ADDR;
-
-static const efi_config_table_type_t arch_tables[] __initconst = {
-       {LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, &screen_info_table},
-       {LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
-       {}
-};
+extern __weak const efi_config_table_type_t efi_arch_tables[];
 
 static void __init init_screen_info(void)
 {
-       struct screen_info *si;
-
-       if (IS_ENABLED(CONFIG_ARM) &&
-           screen_info_table != EFI_INVALID_TABLE_ADDR) {
-               si = early_memremap_ro(screen_info_table, sizeof(*si));
-               if (!si) {
-                       pr_err("Could not map screen_info config table\n");
-                       return;
-               }
-               screen_info = *si;
-               early_memunmap(si, sizeof(*si));
-
-               /* dummycon on ARM needs non-zero values for columns/lines */
-               screen_info.orig_video_cols = 80;
-               screen_info.orig_video_lines = 25;
-       }
-
        if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI &&
            memblock_is_map_memory(screen_info.lfb_base))
                memblock_mark_nomap(screen_info.lfb_base, screen_info.lfb_size);
@@ -119,8 +95,7 @@ static int __init uefi_init(u64 efi_system_table)
                goto out;
        }
        retval = efi_config_parse_tables(config_tables, systab->nr_tables,
-                                        IS_ENABLED(CONFIG_ARM) ? arch_tables
-                                                               : NULL);
+                                        efi_arch_tables);
 
        early_memunmap(config_tables, table_size);
 out:
@@ -248,36 +223,4 @@ void __init efi_init(void)
                         PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
 
        init_screen_info();
-
-#ifdef CONFIG_ARM
-       /* ARM does not permit early mappings to persist across paging_init() */
-       efi_memmap_unmap();
-
-       if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
-               struct efi_arm_entry_state *state;
-               bool dump_state = true;
-
-               state = early_memremap_ro(cpu_state_table,
-                                         sizeof(struct efi_arm_entry_state));
-               if (state == NULL) {
-                       pr_warn("Unable to map CPU entry state table.\n");
-                       return;
-               }
-
-               if ((state->sctlr_before_ebs & 1) == 0)
-                       pr_warn(FW_BUG "EFI stub was entered with MMU and Dcache disabled, please fix your firmware!\n");
-               else if ((state->sctlr_after_ebs & 1) == 0)
-                       pr_warn(FW_BUG "ExitBootServices() returned with MMU and Dcache disabled, please fix your firmware!\n");
-               else
-                       dump_state = false;
-
-               if (dump_state || efi_enabled(EFI_DBG)) {
-                       pr_info("CPSR at EFI stub entry        : 0x%08x\n", state->cpsr_before_ebs);
-                       pr_info("SCTLR at EFI stub entry       : 0x%08x\n", state->sctlr_before_ebs);
-                       pr_info("CPSR after ExitBootServices() : 0x%08x\n", state->cpsr_after_ebs);
-                       pr_info("SCTLR after ExitBootServices(): 0x%08x\n", state->sctlr_after_ebs);
-               }
-               early_memunmap(state, sizeof(struct efi_arm_entry_state));
-       }
-#endif
 }