1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/memblock.h>
9 #include <asm/mach/map.h>
10 #include <asm/mmu_context.h>
12 static int __init set_permissions(pte_t *ptep, unsigned long addr, void *data)
14 efi_memory_desc_t *md = data;
17 if (md->attribute & EFI_MEMORY_RO)
18 pte = set_pte_bit(pte, __pgprot(L_PTE_RDONLY));
19 if (md->attribute & EFI_MEMORY_XP)
20 pte = set_pte_bit(pte, __pgprot(L_PTE_XN));
21 set_pte_ext(ptep, pte, PTE_EXT_NG);
25 int __init efi_set_mapping_permissions(struct mm_struct *mm,
26 efi_memory_desc_t *md)
28 unsigned long base, size;
31 size = md->num_pages << EFI_PAGE_SHIFT;
34 * We can only use apply_to_page_range() if we can guarantee that the
35 * entire region was mapped using pages. This should be the case if the
36 * region does not cover any naturally aligned SECTION_SIZE sized
39 if (round_down(base + size, SECTION_SIZE) <
40 round_up(base, SECTION_SIZE) + SECTION_SIZE)
41 return apply_to_page_range(mm, base, size, set_permissions, md);
46 int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
48 struct map_desc desc = {
49 .virtual = md->virt_addr,
50 .pfn = __phys_to_pfn(md->phys_addr),
51 .length = md->num_pages * EFI_PAGE_SIZE,
55 * Order is important here: memory regions may have all of the
56 * bits below set (and usually do), so we check them in order of
59 if (md->attribute & EFI_MEMORY_WB)
60 desc.type = MT_MEMORY_RWX;
61 else if (md->attribute & EFI_MEMORY_WT)
62 desc.type = MT_MEMORY_RWX_NONCACHED;
63 else if (md->attribute & EFI_MEMORY_WC)
64 desc.type = MT_DEVICE_WC;
66 desc.type = MT_DEVICE;
68 create_mapping_late(mm, &desc, true);
71 * If stricter permissions were specified, apply them now.
73 if (md->attribute & (EFI_MEMORY_RO | EFI_MEMORY_XP))
74 return efi_set_mapping_permissions(mm, md);
78 static unsigned long __initdata screen_info_table = EFI_INVALID_TABLE_ADDR;
79 static unsigned long __initdata cpu_state_table = EFI_INVALID_TABLE_ADDR;
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},
87 static void __init load_screen_info_table(void)
89 struct screen_info *si;
91 if (screen_info_table != EFI_INVALID_TABLE_ADDR) {
92 si = early_memremap_ro(screen_info_table, sizeof(*si));
94 pr_err("Could not map screen_info config table\n");
98 early_memunmap(si, sizeof(*si));
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;
104 if (memblock_is_map_memory(screen_info.lfb_base))
105 memblock_mark_nomap(screen_info.lfb_base,
106 screen_info.lfb_size);
110 static void __init load_cpu_state_table(void)
112 if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
113 struct efi_arm_entry_state *state;
114 bool dump_state = true;
116 state = early_memremap_ro(cpu_state_table,
117 sizeof(struct efi_arm_entry_state));
119 pr_warn("Unable to map CPU entry state table.\n");
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");
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);
140 early_memunmap(state, sizeof(struct efi_arm_entry_state));
144 void __init arm_efi_init(void)
148 load_screen_info_table();
150 /* ARM does not permit early mappings to persist across paging_init() */
153 load_cpu_state_table();