Skip to content

Commit 39ada88

Browse files
committed
efi/x86: Move 32-bit code into efi_32.c
Now that the old memmap code has been removed, some code that was left behind in arch/x86/platform/efi/efi.c is only used for 32-bit builds, which means it can live in efi_32.c as well. So move it over. Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 8a8a323 commit 39ada88

File tree

3 files changed

+37
-86
lines changed

3 files changed

+37
-86
lines changed

arch/x86/include/asm/efi.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ extern unsigned long efi_fw_vendor, efi_config_table;
8181
kernel_fpu_end(); \
8282
})
8383

84-
8584
#define arch_efi_call_virt(p, f, args...) p->f(args)
8685

87-
#define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
88-
8986
#else /* !CONFIG_X86_32 */
9087

9188
#define EFI_LOADER_SIGNATURE "EL64"
@@ -125,9 +122,6 @@ struct efi_scratch {
125122
kernel_fpu_end(); \
126123
})
127124

128-
extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
129-
u32 type, u64 attribute);
130-
131125
#ifdef CONFIG_KASAN
132126
/*
133127
* CONFIG_KASAN may redefine memset to __memset. __memset function is present
@@ -143,17 +137,13 @@ extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
143137
#endif /* CONFIG_X86_32 */
144138

145139
extern struct efi_scratch efi_scratch;
146-
extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable);
147140
extern int __init efi_memblock_x86_reserve_range(void);
148141
extern void __init efi_print_memmap(void);
149-
extern void __init efi_memory_uc(u64 addr, unsigned long size);
150142
extern void __init efi_map_region(efi_memory_desc_t *md);
151143
extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
152144
extern void efi_sync_low_kernel_mappings(void);
153145
extern int __init efi_alloc_page_tables(void);
154146
extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
155-
extern void __init old_map_region(efi_memory_desc_t *md);
156-
extern void __init runtime_code_page_mkexec(void);
157147
extern void __init efi_runtime_update_mappings(void);
158148
extern void __init efi_dump_pagetable(void);
159149
extern void __init efi_apply_memmap_quirks(void);

arch/x86/platform/efi/efi.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#include <asm/efi.h>
5050
#include <asm/e820/api.h>
5151
#include <asm/time.h>
52-
#include <asm/set_memory.h>
5352
#include <asm/tlbflush.h>
5453
#include <asm/x86_init.h>
5554
#include <asm/uv/uv.h>
@@ -496,74 +495,6 @@ void __init efi_init(void)
496495
efi_print_memmap();
497496
}
498497

499-
#if defined(CONFIG_X86_32)
500-
501-
void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
502-
{
503-
u64 addr, npages;
504-
505-
addr = md->virt_addr;
506-
npages = md->num_pages;
507-
508-
memrange_efi_to_native(&addr, &npages);
509-
510-
if (executable)
511-
set_memory_x(addr, npages);
512-
else
513-
set_memory_nx(addr, npages);
514-
}
515-
516-
void __init runtime_code_page_mkexec(void)
517-
{
518-
efi_memory_desc_t *md;
519-
520-
/* Make EFI runtime service code area executable */
521-
for_each_efi_memory_desc(md) {
522-
if (md->type != EFI_RUNTIME_SERVICES_CODE)
523-
continue;
524-
525-
efi_set_executable(md, true);
526-
}
527-
}
528-
529-
void __init efi_memory_uc(u64 addr, unsigned long size)
530-
{
531-
unsigned long page_shift = 1UL << EFI_PAGE_SHIFT;
532-
u64 npages;
533-
534-
npages = round_up(size, page_shift) / page_shift;
535-
memrange_efi_to_native(&addr, &npages);
536-
set_memory_uc(addr, npages);
537-
}
538-
539-
void __init old_map_region(efi_memory_desc_t *md)
540-
{
541-
u64 start_pfn, end_pfn, end;
542-
unsigned long size;
543-
void *va;
544-
545-
start_pfn = PFN_DOWN(md->phys_addr);
546-
size = md->num_pages << PAGE_SHIFT;
547-
end = md->phys_addr + size;
548-
end_pfn = PFN_UP(end);
549-
550-
if (pfn_range_is_mapped(start_pfn, end_pfn)) {
551-
va = __va(md->phys_addr);
552-
553-
if (!(md->attribute & EFI_MEMORY_WB))
554-
efi_memory_uc((u64)(unsigned long)va, size);
555-
} else
556-
va = efi_ioremap(md->phys_addr, size,
557-
md->type, md->attribute);
558-
559-
md->virt_addr = (u64) (unsigned long) va;
560-
if (!va)
561-
pr_err("ioremap of 0x%llX failed!\n",
562-
(unsigned long long)md->phys_addr);
563-
}
564-
565-
#endif
566-
567498
/* Merge contiguous regions of the same type and attribute */
568499
static void __init efi_merge_regions(void)
569500
{

arch/x86/platform/efi/efi_32.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,35 @@
2929
#include <asm/io.h>
3030
#include <asm/desc.h>
3131
#include <asm/page.h>
32+
#include <asm/set_memory.h>
3233
#include <asm/tlbflush.h>
3334
#include <asm/efi.h>
3435

36+
void __init efi_map_region(efi_memory_desc_t *md)
37+
{
38+
u64 start_pfn, end_pfn, end;
39+
unsigned long size;
40+
void *va;
41+
42+
start_pfn = PFN_DOWN(md->phys_addr);
43+
size = md->num_pages << PAGE_SHIFT;
44+
end = md->phys_addr + size;
45+
end_pfn = PFN_UP(end);
46+
47+
if (pfn_range_is_mapped(start_pfn, end_pfn)) {
48+
va = __va(md->phys_addr);
49+
50+
if (!(md->attribute & EFI_MEMORY_WB))
51+
set_memory_uc((unsigned long)va, md->num_pages);
52+
} else {
53+
va = ioremap_cache(md->phys_addr, size);
54+
}
55+
56+
md->virt_addr = (unsigned long)va;
57+
if (!va)
58+
pr_err("ioremap of 0x%llX failed!\n", md->phys_addr);
59+
}
60+
3561
/*
3662
* To make EFI call EFI runtime service in physical addressing mode we need
3763
* prolog/epilog before/after the invocation to claim the EFI runtime service
@@ -58,11 +84,6 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
5884
return 0;
5985
}
6086

61-
void __init efi_map_region(efi_memory_desc_t *md)
62-
{
63-
old_map_region(md);
64-
}
65-
6687
void __init efi_map_region_fixed(efi_memory_desc_t *md) {}
6788
void __init parse_efi_setup(u64 phys_addr, u32 data_len) {}
6889

@@ -107,6 +128,15 @@ efi_status_t __init efi_set_virtual_address_map(unsigned long memory_map_size,
107128

108129
void __init efi_runtime_update_mappings(void)
109130
{
110-
if (__supported_pte_mask & _PAGE_NX)
111-
runtime_code_page_mkexec();
131+
if (__supported_pte_mask & _PAGE_NX) {
132+
efi_memory_desc_t *md;
133+
134+
/* Make EFI runtime service code area executable */
135+
for_each_efi_memory_desc(md) {
136+
if (md->type != EFI_RUNTIME_SERVICES_CODE)
137+
continue;
138+
139+
set_memory_x(md->virt_addr, md->num_pages);
140+
}
141+
}
112142
}

0 commit comments

Comments
 (0)