Skip to content

Commit 69e377b

Browse files
committed
efi/arm: libstub: move ARM specific code out of generic routines
Move some code that is only reachable when IS_ENABLED(CONFIG_ARM) into the ARM EFI arch code. Cc: Russell King <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 71c7adc commit 69e377b

File tree

4 files changed

+84
-61
lines changed

4 files changed

+84
-61
lines changed

arch/arm/include/asm/efi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#ifdef CONFIG_EFI
1919
void efi_init(void);
20+
void arm_efi_init(void);
2021

2122
int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
2223
int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
@@ -37,7 +38,7 @@ void efi_virtmap_load(void);
3738
void efi_virtmap_unload(void);
3839

3940
#else
40-
#define efi_init()
41+
#define arm_efi_init()
4142
#endif /* CONFIG_EFI */
4243

4344
/* arch specific definitions used by the stub code */

arch/arm/kernel/efi.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/efi.h>
7+
#include <linux/memblock.h>
78
#include <asm/efi.h>
89
#include <asm/mach/map.h>
910
#include <asm/mmu_context.h>
@@ -73,3 +74,81 @@ int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
7374
return efi_set_mapping_permissions(mm, md);
7475
return 0;
7576
}
77+
78+
static unsigned long __initdata screen_info_table = EFI_INVALID_TABLE_ADDR;
79+
static unsigned long __initdata cpu_state_table = EFI_INVALID_TABLE_ADDR;
80+
81+
const efi_config_table_type_t efi_arch_tables[] __initconst = {
82+
{LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, &screen_info_table},
83+
{LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
84+
{}
85+
};
86+
87+
static void __init load_screen_info_table(void)
88+
{
89+
struct screen_info *si;
90+
91+
if (screen_info_table != EFI_INVALID_TABLE_ADDR) {
92+
si = early_memremap_ro(screen_info_table, sizeof(*si));
93+
if (!si) {
94+
pr_err("Could not map screen_info config table\n");
95+
return;
96+
}
97+
screen_info = *si;
98+
early_memunmap(si, sizeof(*si));
99+
100+
/* dummycon on ARM needs non-zero values for columns/lines */
101+
screen_info.orig_video_cols = 80;
102+
screen_info.orig_video_lines = 25;
103+
104+
if (memblock_is_map_memory(screen_info.lfb_base))
105+
memblock_mark_nomap(screen_info.lfb_base,
106+
screen_info.lfb_size);
107+
}
108+
}
109+
110+
static void __init load_cpu_state_table(void)
111+
{
112+
if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
113+
struct efi_arm_entry_state *state;
114+
bool dump_state = true;
115+
116+
state = early_memremap_ro(cpu_state_table,
117+
sizeof(struct efi_arm_entry_state));
118+
if (state == NULL) {
119+
pr_warn("Unable to map CPU entry state table.\n");
120+
return;
121+
}
122+
123+
if ((state->sctlr_before_ebs & 1) == 0)
124+
pr_warn(FW_BUG "EFI stub was entered with MMU and Dcache disabled, please fix your firmware!\n");
125+
else if ((state->sctlr_after_ebs & 1) == 0)
126+
pr_warn(FW_BUG "ExitBootServices() returned with MMU and Dcache disabled, please fix your firmware!\n");
127+
else
128+
dump_state = false;
129+
130+
if (dump_state || efi_enabled(EFI_DBG)) {
131+
pr_info("CPSR at EFI stub entry : 0x%08x\n",
132+
state->cpsr_before_ebs);
133+
pr_info("SCTLR at EFI stub entry : 0x%08x\n",
134+
state->sctlr_before_ebs);
135+
pr_info("CPSR after ExitBootServices() : 0x%08x\n",
136+
state->cpsr_after_ebs);
137+
pr_info("SCTLR after ExitBootServices(): 0x%08x\n",
138+
state->sctlr_after_ebs);
139+
}
140+
early_memunmap(state, sizeof(struct efi_arm_entry_state));
141+
}
142+
}
143+
144+
void __init arm_efi_init(void)
145+
{
146+
efi_init();
147+
148+
load_screen_info_table();
149+
150+
/* ARM does not permit early mappings to persist across paging_init() */
151+
efi_memmap_unmap();
152+
153+
load_cpu_state_table();
154+
}

arch/arm/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ void __init setup_arch(char **cmdline_p)
11411141
#endif
11421142
setup_dma_zone(mdesc);
11431143
xen_early_init();
1144-
efi_init();
1144+
arm_efi_init();
11451145
/*
11461146
* Make sure the calculation for lowmem/highmem is set appropriately
11471147
* before reserving/allocating any memory

drivers/firmware/efi/efi-init.c

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,10 @@ static phys_addr_t __init efi_to_phys(unsigned long addr)
5151
return addr;
5252
}
5353

54-
static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR;
55-
static __initdata unsigned long cpu_state_table = EFI_INVALID_TABLE_ADDR;
56-
57-
static const efi_config_table_type_t arch_tables[] __initconst = {
58-
{LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, &screen_info_table},
59-
{LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
60-
{}
61-
};
54+
extern __weak const efi_config_table_type_t efi_arch_tables[];
6255

6356
static void __init init_screen_info(void)
6457
{
65-
struct screen_info *si;
66-
67-
if (IS_ENABLED(CONFIG_ARM) &&
68-
screen_info_table != EFI_INVALID_TABLE_ADDR) {
69-
si = early_memremap_ro(screen_info_table, sizeof(*si));
70-
if (!si) {
71-
pr_err("Could not map screen_info config table\n");
72-
return;
73-
}
74-
screen_info = *si;
75-
early_memunmap(si, sizeof(*si));
76-
77-
/* dummycon on ARM needs non-zero values for columns/lines */
78-
screen_info.orig_video_cols = 80;
79-
screen_info.orig_video_lines = 25;
80-
}
81-
8258
if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI &&
8359
memblock_is_map_memory(screen_info.lfb_base))
8460
memblock_mark_nomap(screen_info.lfb_base, screen_info.lfb_size);
@@ -119,8 +95,7 @@ static int __init uefi_init(u64 efi_system_table)
11995
goto out;
12096
}
12197
retval = efi_config_parse_tables(config_tables, systab->nr_tables,
122-
IS_ENABLED(CONFIG_ARM) ? arch_tables
123-
: NULL);
98+
efi_arch_tables);
12499

125100
early_memunmap(config_tables, table_size);
126101
out:
@@ -248,36 +223,4 @@ void __init efi_init(void)
248223
PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
249224

250225
init_screen_info();
251-
252-
#ifdef CONFIG_ARM
253-
/* ARM does not permit early mappings to persist across paging_init() */
254-
efi_memmap_unmap();
255-
256-
if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
257-
struct efi_arm_entry_state *state;
258-
bool dump_state = true;
259-
260-
state = early_memremap_ro(cpu_state_table,
261-
sizeof(struct efi_arm_entry_state));
262-
if (state == NULL) {
263-
pr_warn("Unable to map CPU entry state table.\n");
264-
return;
265-
}
266-
267-
if ((state->sctlr_before_ebs & 1) == 0)
268-
pr_warn(FW_BUG "EFI stub was entered with MMU and Dcache disabled, please fix your firmware!\n");
269-
else if ((state->sctlr_after_ebs & 1) == 0)
270-
pr_warn(FW_BUG "ExitBootServices() returned with MMU and Dcache disabled, please fix your firmware!\n");
271-
else
272-
dump_state = false;
273-
274-
if (dump_state || efi_enabled(EFI_DBG)) {
275-
pr_info("CPSR at EFI stub entry : 0x%08x\n", state->cpsr_before_ebs);
276-
pr_info("SCTLR at EFI stub entry : 0x%08x\n", state->sctlr_before_ebs);
277-
pr_info("CPSR after ExitBootServices() : 0x%08x\n", state->cpsr_after_ebs);
278-
pr_info("SCTLR after ExitBootServices(): 0x%08x\n", state->sctlr_after_ebs);
279-
}
280-
early_memunmap(state, sizeof(struct efi_arm_entry_state));
281-
}
282-
#endif
283226
}

0 commit comments

Comments
 (0)