Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'devel-stable' into for-linus

+985 -367
+20
arch/arm/Kconfig
··· 20 20 select GENERIC_ALLOCATOR 21 21 select GENERIC_ATOMIC64 if (CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI) 22 22 select GENERIC_CLOCKEVENTS_BROADCAST if SMP 23 + select GENERIC_EARLY_IOREMAP 23 24 select GENERIC_IDLE_POLL_SETUP 24 25 select GENERIC_IRQ_PROBE 25 26 select GENERIC_IRQ_SHOW ··· 2060 2059 will be determined at run-time by masking the current IP with 2061 2060 0xf8000000. This assumes the zImage being placed in the first 128MB 2062 2061 from start of memory. 2062 + 2063 + config EFI_STUB 2064 + bool 2065 + 2066 + config EFI 2067 + bool "UEFI runtime support" 2068 + depends on OF && !CPU_BIG_ENDIAN && MMU && AUTO_ZRELADDR && !XIP_KERNEL 2069 + select UCS2_STRING 2070 + select EFI_PARAMS_FROM_FDT 2071 + select EFI_STUB 2072 + select EFI_ARMSTUB 2073 + select EFI_RUNTIME_WRAPPERS 2074 + ---help--- 2075 + This option provides support for runtime services provided 2076 + by UEFI firmware (such as non-volatile variables, realtime 2077 + clock, and platform reset). A UEFI stub is also provided to 2078 + allow the kernel to be booted as an EFI application. This 2079 + is only useful for kernels that may run on systems that have 2080 + UEFI firmware. 2063 2081 2064 2082 endmenu 2065 2083
+3 -1
arch/arm/boot/compressed/Makefile
··· 167 167 false; \ 168 168 fi 169 169 170 + efi-obj-$(CONFIG_EFI_STUB) := $(objtree)/drivers/firmware/efi/libstub/lib.a 171 + 170 172 $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \ 171 173 $(addprefix $(obj)/, $(OBJS)) $(lib1funcs) $(ashldi3) \ 172 - $(bswapsdi2) FORCE 174 + $(bswapsdi2) $(efi-obj-y) FORCE 173 175 @$(check_for_multiple_zreladdr) 174 176 $(call if_changed,ld) 175 177 @$(check_for_bad_syms)
+130
arch/arm/boot/compressed/efi-header.S
··· 1 + /* 2 + * Copyright (C) 2013-2015 Linaro Ltd 3 + * Authors: Roy Franz <roy.franz@linaro.org> 4 + * Ard Biesheuvel <ard.biesheuvel@linaro.org> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + .macro __nop 12 + #ifdef CONFIG_EFI_STUB 13 + @ This is almost but not quite a NOP, since it does clobber the 14 + @ condition flags. But it is the best we can do for EFI, since 15 + @ PE/COFF expects the magic string "MZ" at offset 0, while the 16 + @ ARM/Linux boot protocol expects an executable instruction 17 + @ there. 18 + .inst 'M' | ('Z' << 8) | (0x1310 << 16) @ tstne r0, #0x4d000 19 + #else 20 + mov r0, r0 21 + #endif 22 + .endm 23 + 24 + .macro __EFI_HEADER 25 + #ifdef CONFIG_EFI_STUB 26 + b __efi_start 27 + 28 + .set start_offset, __efi_start - start 29 + .org start + 0x3c 30 + @ 31 + @ The PE header can be anywhere in the file, but for 32 + @ simplicity we keep it together with the MSDOS header 33 + @ The offset to the PE/COFF header needs to be at offset 34 + @ 0x3C in the MSDOS header. 35 + @ The only 2 fields of the MSDOS header that are used are this 36 + @ PE/COFF offset, and the "MZ" bytes at offset 0x0. 37 + @ 38 + .long pe_header - start @ Offset to the PE header. 39 + 40 + pe_header: 41 + .ascii "PE\0\0" 42 + 43 + coff_header: 44 + .short 0x01c2 @ ARM or Thumb 45 + .short 2 @ nr_sections 46 + .long 0 @ TimeDateStamp 47 + .long 0 @ PointerToSymbolTable 48 + .long 1 @ NumberOfSymbols 49 + .short section_table - optional_header 50 + @ SizeOfOptionalHeader 51 + .short 0x306 @ Characteristics. 52 + @ IMAGE_FILE_32BIT_MACHINE | 53 + @ IMAGE_FILE_DEBUG_STRIPPED | 54 + @ IMAGE_FILE_EXECUTABLE_IMAGE | 55 + @ IMAGE_FILE_LINE_NUMS_STRIPPED 56 + 57 + optional_header: 58 + .short 0x10b @ PE32 format 59 + .byte 0x02 @ MajorLinkerVersion 60 + .byte 0x14 @ MinorLinkerVersion 61 + .long _end - __efi_start @ SizeOfCode 62 + .long 0 @ SizeOfInitializedData 63 + .long 0 @ SizeOfUninitializedData 64 + .long efi_stub_entry - start @ AddressOfEntryPoint 65 + .long start_offset @ BaseOfCode 66 + .long 0 @ data 67 + 68 + extra_header_fields: 69 + .long 0 @ ImageBase 70 + .long 0x200 @ SectionAlignment 71 + .long 0x200 @ FileAlignment 72 + .short 0 @ MajorOperatingSystemVersion 73 + .short 0 @ MinorOperatingSystemVersion 74 + .short 0 @ MajorImageVersion 75 + .short 0 @ MinorImageVersion 76 + .short 0 @ MajorSubsystemVersion 77 + .short 0 @ MinorSubsystemVersion 78 + .long 0 @ Win32VersionValue 79 + 80 + .long _end - start @ SizeOfImage 81 + .long start_offset @ SizeOfHeaders 82 + .long 0 @ CheckSum 83 + .short 0xa @ Subsystem (EFI application) 84 + .short 0 @ DllCharacteristics 85 + .long 0 @ SizeOfStackReserve 86 + .long 0 @ SizeOfStackCommit 87 + .long 0 @ SizeOfHeapReserve 88 + .long 0 @ SizeOfHeapCommit 89 + .long 0 @ LoaderFlags 90 + .long 0x6 @ NumberOfRvaAndSizes 91 + 92 + .quad 0 @ ExportTable 93 + .quad 0 @ ImportTable 94 + .quad 0 @ ResourceTable 95 + .quad 0 @ ExceptionTable 96 + .quad 0 @ CertificationTable 97 + .quad 0 @ BaseRelocationTable 98 + 99 + section_table: 100 + @ 101 + @ The EFI application loader requires a relocation section 102 + @ because EFI applications must be relocatable. This is a 103 + @ dummy section as far as we are concerned. 104 + @ 105 + .ascii ".reloc\0\0" 106 + .long 0 @ VirtualSize 107 + .long 0 @ VirtualAddress 108 + .long 0 @ SizeOfRawData 109 + .long 0 @ PointerToRawData 110 + .long 0 @ PointerToRelocations 111 + .long 0 @ PointerToLineNumbers 112 + .short 0 @ NumberOfRelocations 113 + .short 0 @ NumberOfLineNumbers 114 + .long 0x42100040 @ Characteristics 115 + 116 + .ascii ".text\0\0\0" 117 + .long _end - __efi_start @ VirtualSize 118 + .long __efi_start @ VirtualAddress 119 + .long _edata - __efi_start @ SizeOfRawData 120 + .long __efi_start @ PointerToRawData 121 + .long 0 @ PointerToRelocations 122 + .long 0 @ PointerToLineNumbers 123 + .short 0 @ NumberOfRelocations 124 + .short 0 @ NumberOfLineNumbers 125 + .long 0xe0500020 @ Characteristics 126 + 127 + .align 9 128 + __efi_start: 129 + #endif 130 + .endm
+52 -2
arch/arm/boot/compressed/head.S
··· 12 12 #include <asm/assembler.h> 13 13 #include <asm/v7m.h> 14 14 15 + #include "efi-header.S" 16 + 15 17 AR_CLASS( .arch armv7-a ) 16 18 M_CLASS( .arch armv7-m ) 17 19 ··· 128 126 start: 129 127 .type start,#function 130 128 .rept 7 131 - mov r0, r0 129 + __nop 132 130 .endr 133 131 ARM( mov r0, r0 ) 134 132 ARM( b 1f ) ··· 141 139 .word 0x04030201 @ endianness flag 142 140 143 141 THUMB( .thumb ) 144 - 1: 142 + 1: __EFI_HEADER 143 + 145 144 ARM_BE8( setend be ) @ go BE8 if compiled for BE8 146 145 AR_CLASS( mrs r9, cpsr ) 147 146 #ifdef CONFIG_ARM_VIRT_EXT ··· 1355 1352 THUMB( bx r4 ) @ entry point is always ARM for A/R classes 1356 1353 1357 1354 reloc_code_end: 1355 + 1356 + #ifdef CONFIG_EFI_STUB 1357 + .align 2 1358 + _start: .long start - . 1359 + 1360 + ENTRY(efi_stub_entry) 1361 + @ allocate space on stack for passing current zImage address 1362 + @ and for the EFI stub to return of new entry point of 1363 + @ zImage, as EFI stub may copy the kernel. Pointer address 1364 + @ is passed in r2. r0 and r1 are passed through from the 1365 + @ EFI firmware to efi_entry 1366 + adr ip, _start 1367 + ldr r3, [ip] 1368 + add r3, r3, ip 1369 + stmfd sp!, {r3, lr} 1370 + mov r2, sp @ pass zImage address in r2 1371 + bl efi_entry 1372 + 1373 + @ Check for error return from EFI stub. r0 has FDT address 1374 + @ or error code. 1375 + cmn r0, #1 1376 + beq efi_load_fail 1377 + 1378 + @ Preserve return value of efi_entry() in r4 1379 + mov r4, r0 1380 + bl cache_clean_flush 1381 + bl cache_off 1382 + 1383 + @ Set parameters for booting zImage according to boot protocol 1384 + @ put FDT address in r2, it was returned by efi_entry() 1385 + @ r1 is the machine type, and r0 needs to be 0 1386 + mov r0, #0 1387 + mov r1, #0xFFFFFFFF 1388 + mov r2, r4 1389 + 1390 + @ Branch to (possibly) relocated zImage that is in [sp] 1391 + ldr lr, [sp] 1392 + ldr ip, =start_offset 1393 + add lr, lr, ip 1394 + mov pc, lr @ no mode switch 1395 + 1396 + efi_load_fail: 1397 + @ Return EFI_LOAD_ERROR to EFI firmware on error. 1398 + ldr r0, =0x80000001 1399 + ldmfd sp!, {ip, pc} 1400 + ENDPROC(efi_stub_entry) 1401 + #endif 1358 1402 1359 1403 .align 1360 1404 .section ".stack", "aw", %nobits
+7
arch/arm/boot/compressed/vmlinux.lds.S
··· 48 48 *(.rodata) 49 49 *(.rodata.*) 50 50 } 51 + .data : { 52 + /* 53 + * The EFI stub always executes from RAM, and runs strictly before the 54 + * decompressor, so we can make an exception for its r/w data, and keep it 55 + */ 56 + *(.data.efistub) 57 + } 51 58 .piggydata : { 52 59 *(.piggydata) 53 60 }
+1
arch/arm/include/asm/Kbuild
··· 3 3 generic-y += bitsperlong.h 4 4 generic-y += cputime.h 5 5 generic-y += current.h 6 + generic-y += early_ioremap.h 6 7 generic-y += emergency-restart.h 7 8 generic-y += errno.h 8 9 generic-y += exec.h
+83
arch/arm/include/asm/efi.h
··· 1 + /* 2 + * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + 9 + #ifndef __ASM_ARM_EFI_H 10 + #define __ASM_ARM_EFI_H 11 + 12 + #include <asm/cacheflush.h> 13 + #include <asm/cachetype.h> 14 + #include <asm/early_ioremap.h> 15 + #include <asm/fixmap.h> 16 + #include <asm/highmem.h> 17 + #include <asm/mach/map.h> 18 + #include <asm/mmu_context.h> 19 + #include <asm/pgtable.h> 20 + 21 + #ifdef CONFIG_EFI 22 + void efi_init(void); 23 + 24 + int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); 25 + 26 + #define efi_call_virt(f, ...) \ 27 + ({ \ 28 + efi_##f##_t *__f; \ 29 + efi_status_t __s; \ 30 + \ 31 + efi_virtmap_load(); \ 32 + __f = efi.systab->runtime->f; \ 33 + __s = __f(__VA_ARGS__); \ 34 + efi_virtmap_unload(); \ 35 + __s; \ 36 + }) 37 + 38 + #define __efi_call_virt(f, ...) \ 39 + ({ \ 40 + efi_##f##_t *__f; \ 41 + \ 42 + efi_virtmap_load(); \ 43 + __f = efi.systab->runtime->f; \ 44 + __f(__VA_ARGS__); \ 45 + efi_virtmap_unload(); \ 46 + }) 47 + 48 + static inline void efi_set_pgd(struct mm_struct *mm) 49 + { 50 + check_and_switch_context(mm, NULL); 51 + } 52 + 53 + void efi_virtmap_load(void); 54 + void efi_virtmap_unload(void); 55 + 56 + #else 57 + #define efi_init() 58 + #endif /* CONFIG_EFI */ 59 + 60 + /* arch specific definitions used by the stub code */ 61 + 62 + #define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) 63 + 64 + /* 65 + * A reasonable upper bound for the uncompressed kernel size is 32 MBytes, 66 + * so we will reserve that amount of memory. We have no easy way to tell what 67 + * the actuall size of code + data the uncompressed kernel will use. 68 + * If this is insufficient, the decompressor will relocate itself out of the 69 + * way before performing the decompression. 70 + */ 71 + #define MAX_UNCOMP_KERNEL_SIZE SZ_32M 72 + 73 + /* 74 + * The kernel zImage should preferably be located between 32 MB and 128 MB 75 + * from the base of DRAM. The min address leaves space for a maximal size 76 + * uncompressed image, and the max address is due to how the zImage decompressor 77 + * picks a destination address. 78 + */ 79 + #define ZIMAGE_OFFSET_LIMIT SZ_128M 80 + #define MIN_ZIMAGE_OFFSET MAX_UNCOMP_KERNEL_SIZE 81 + #define MAX_FDT_OFFSET ZIMAGE_OFFSET_LIMIT 82 + 83 + #endif /* _ASM_ARM_EFI_H */
+28 -1
arch/arm/include/asm/fixmap.h
··· 19 19 FIX_TEXT_POKE0, 20 20 FIX_TEXT_POKE1, 21 21 22 - __end_of_fixed_addresses 22 + __end_of_fixmap_region, 23 + 24 + /* 25 + * Share the kmap() region with early_ioremap(): this is guaranteed 26 + * not to clash since early_ioremap() is only available before 27 + * paging_init(), and kmap() only after. 28 + */ 29 + #define NR_FIX_BTMAPS 32 30 + #define FIX_BTMAPS_SLOTS 7 31 + #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS) 32 + 33 + FIX_BTMAP_END = __end_of_permanent_fixed_addresses, 34 + FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1, 35 + __end_of_early_ioremap_region 23 36 }; 37 + 38 + static const enum fixed_addresses __end_of_fixed_addresses = 39 + __end_of_fixmap_region > __end_of_early_ioremap_region ? 40 + __end_of_fixmap_region : __end_of_early_ioremap_region; 24 41 25 42 #define FIXMAP_PAGE_COMMON (L_PTE_YOUNG | L_PTE_PRESENT | L_PTE_XN | L_PTE_DIRTY) 26 43 27 44 #define FIXMAP_PAGE_NORMAL (FIXMAP_PAGE_COMMON | L_PTE_MT_WRITEBACK) 45 + #define FIXMAP_PAGE_RO (FIXMAP_PAGE_NORMAL | L_PTE_RDONLY) 28 46 29 47 /* Used by set_fixmap_(io|nocache), both meant for mapping a device */ 30 48 #define FIXMAP_PAGE_IO (FIXMAP_PAGE_COMMON | L_PTE_MT_DEV_SHARED | L_PTE_SHARED) 31 49 #define FIXMAP_PAGE_NOCACHE FIXMAP_PAGE_IO 50 + 51 + #define __early_set_fixmap __set_fixmap 52 + 53 + #ifdef CONFIG_MMU 32 54 33 55 void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot); 34 56 void __init early_fixmap_init(void); 35 57 36 58 #include <asm-generic/fixmap.h> 37 59 60 + #else 61 + 62 + static inline void early_fixmap_init(void) { } 63 + 64 + #endif 38 65 #endif
+2
arch/arm/include/asm/mach/map.h
··· 42 42 extern void iotable_init(struct map_desc *, int); 43 43 extern void vm_reserve_area_early(unsigned long addr, unsigned long size, 44 44 void *caller); 45 + extern void create_mapping_late(struct mm_struct *mm, struct map_desc *md, 46 + bool ng); 45 47 46 48 #ifdef CONFIG_DEBUG_LL 47 49 extern void debug_ll_addr(unsigned long *paddr, unsigned long *vaddr);
+1 -1
arch/arm/include/asm/mmu_context.h
··· 26 26 #ifdef CONFIG_CPU_HAS_ASID 27 27 28 28 void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk); 29 - #define init_new_context(tsk,mm) ({ atomic64_set(&mm->context.id, 0); 0; }) 29 + #define init_new_context(tsk,mm) ({ atomic64_set(&(mm)->context.id, 0); 0; }) 30 30 31 31 #ifdef CONFIG_ARM_ERRATA_798181 32 32 void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
+1
arch/arm/kernel/Makefile
··· 76 76 AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt 77 77 obj-$(CONFIG_ARM_CPU_TOPOLOGY) += topology.o 78 78 obj-$(CONFIG_VDSO) += vdso.o 79 + obj-$(CONFIG_EFI) += efi.o 79 80 80 81 ifneq ($(CONFIG_ARCH_EBSA110),y) 81 82 obj-y += io.o
+38
arch/arm/kernel/efi.c
··· 1 + /* 2 + * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + 9 + #include <linux/efi.h> 10 + #include <asm/efi.h> 11 + #include <asm/mach/map.h> 12 + #include <asm/mmu_context.h> 13 + 14 + int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md) 15 + { 16 + struct map_desc desc = { 17 + .virtual = md->virt_addr, 18 + .pfn = __phys_to_pfn(md->phys_addr), 19 + .length = md->num_pages * EFI_PAGE_SIZE, 20 + }; 21 + 22 + /* 23 + * Order is important here: memory regions may have all of the 24 + * bits below set (and usually do), so we check them in order of 25 + * preference. 26 + */ 27 + if (md->attribute & EFI_MEMORY_WB) 28 + desc.type = MT_MEMORY_RWX; 29 + else if (md->attribute & EFI_MEMORY_WT) 30 + desc.type = MT_MEMORY_RWX_NONCACHED; 31 + else if (md->attribute & EFI_MEMORY_WC) 32 + desc.type = MT_DEVICE_WC; 33 + else 34 + desc.type = MT_DEVICE; 35 + 36 + create_mapping_late(mm, &desc, true); 37 + return 0; 38 + }
+8 -2
arch/arm/kernel/setup.c
··· 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 9 */ 10 + #include <linux/efi.h> 10 11 #include <linux/export.h> 11 12 #include <linux/kernel.h> 12 13 #include <linux/stddef.h> ··· 38 37 #include <asm/cp15.h> 39 38 #include <asm/cpu.h> 40 39 #include <asm/cputype.h> 40 + #include <asm/efi.h> 41 41 #include <asm/elf.h> 42 + #include <asm/early_ioremap.h> 42 43 #include <asm/fixmap.h> 43 44 #include <asm/procinfo.h> 44 45 #include <asm/psci.h> ··· 1026 1023 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE); 1027 1024 *cmdline_p = cmd_line; 1028 1025 1029 - if (IS_ENABLED(CONFIG_FIX_EARLYCON_MEM)) 1030 - early_fixmap_init(); 1026 + early_fixmap_init(); 1027 + early_ioremap_init(); 1031 1028 1032 1029 parse_early_param(); 1033 1030 ··· 1035 1032 early_paging_init(mdesc); 1036 1033 #endif 1037 1034 setup_dma_zone(mdesc); 1035 + efi_init(); 1038 1036 sanity_check_meminfo(); 1039 1037 arm_memblock_init(mdesc); 1038 + 1039 + early_ioremap_reset(); 1040 1040 1041 1041 paging_init(mdesc); 1042 1042 request_standard_resources(mdesc);
+4 -1
arch/arm/mm/init.c
··· 192 192 #ifdef CONFIG_HAVE_ARCH_PFN_VALID 193 193 int pfn_valid(unsigned long pfn) 194 194 { 195 - return memblock_is_memory(__pfn_to_phys(pfn)); 195 + return memblock_is_map_memory(__pfn_to_phys(pfn)); 196 196 } 197 197 EXPORT_SYMBOL(pfn_valid); 198 198 #endif ··· 431 431 432 432 /* Ignore complete lowmem entries */ 433 433 if (end <= max_low) 434 + continue; 435 + 436 + if (memblock_is_nomap(mem)) 434 437 continue; 435 438 436 439 /* Truncate partial highmem entries */
+9
arch/arm/mm/ioremap.c
··· 30 30 #include <asm/cp15.h> 31 31 #include <asm/cputype.h> 32 32 #include <asm/cacheflush.h> 33 + #include <asm/early_ioremap.h> 33 34 #include <asm/mmu_context.h> 34 35 #include <asm/pgalloc.h> 35 36 #include <asm/tlbflush.h> ··· 470 469 } 471 470 EXPORT_SYMBOL_GPL(pci_ioremap_io); 472 471 #endif 472 + 473 + /* 474 + * Must be called after early_fixmap_init 475 + */ 476 + void __init early_ioremap_init(void) 477 + { 478 + early_ioremap_setup(); 479 + }
+87 -41
arch/arm/mm/mmu.c
··· 390 390 * The early fixmap range spans multiple pmds, for which 391 391 * we are not prepared: 392 392 */ 393 - BUILD_BUG_ON((__fix_to_virt(__end_of_permanent_fixed_addresses) >> PMD_SHIFT) 393 + BUILD_BUG_ON((__fix_to_virt(__end_of_early_ioremap_region) >> PMD_SHIFT) 394 394 != FIXADDR_TOP >> PMD_SHIFT); 395 395 396 396 pmd = fixmap_pmd(FIXADDR_TOP); ··· 724 724 return early_alloc_aligned(sz, sz); 725 725 } 726 726 727 - static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned long prot) 727 + static void *__init late_alloc(unsigned long sz) 728 + { 729 + void *ptr = (void *)__get_free_pages(PGALLOC_GFP, get_order(sz)); 730 + 731 + BUG_ON(!ptr); 732 + return ptr; 733 + } 734 + 735 + static pte_t * __init pte_alloc(pmd_t *pmd, unsigned long addr, 736 + unsigned long prot, 737 + void *(*alloc)(unsigned long sz)) 728 738 { 729 739 if (pmd_none(*pmd)) { 730 - pte_t *pte = early_alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE); 740 + pte_t *pte = alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE); 731 741 __pmd_populate(pmd, __pa(pte), prot); 732 742 } 733 743 BUG_ON(pmd_bad(*pmd)); 734 744 return pte_offset_kernel(pmd, addr); 735 745 } 736 746 747 + static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, 748 + unsigned long prot) 749 + { 750 + return pte_alloc(pmd, addr, prot, early_alloc); 751 + } 752 + 737 753 static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr, 738 754 unsigned long end, unsigned long pfn, 739 - const struct mem_type *type) 755 + const struct mem_type *type, 756 + void *(*alloc)(unsigned long sz), 757 + bool ng) 740 758 { 741 - pte_t *pte = early_pte_alloc(pmd, addr, type->prot_l1); 759 + pte_t *pte = pte_alloc(pmd, addr, type->prot_l1, alloc); 742 760 do { 743 - set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)), 0); 761 + set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)), 762 + ng ? PTE_EXT_NG : 0); 744 763 pfn++; 745 764 } while (pte++, addr += PAGE_SIZE, addr != end); 746 765 } 747 766 748 767 static void __init __map_init_section(pmd_t *pmd, unsigned long addr, 749 768 unsigned long end, phys_addr_t phys, 750 - const struct mem_type *type) 769 + const struct mem_type *type, bool ng) 751 770 { 752 771 pmd_t *p = pmd; 753 772 ··· 784 765 pmd++; 785 766 #endif 786 767 do { 787 - *pmd = __pmd(phys | type->prot_sect); 768 + *pmd = __pmd(phys | type->prot_sect | (ng ? PMD_SECT_nG : 0)); 788 769 phys += SECTION_SIZE; 789 770 } while (pmd++, addr += SECTION_SIZE, addr != end); 790 771 ··· 793 774 794 775 static void __init alloc_init_pmd(pud_t *pud, unsigned long addr, 795 776 unsigned long end, phys_addr_t phys, 796 - const struct mem_type *type) 777 + const struct mem_type *type, 778 + void *(*alloc)(unsigned long sz), bool ng) 797 779 { 798 780 pmd_t *pmd = pmd_offset(pud, addr); 799 781 unsigned long next; ··· 812 792 */ 813 793 if (type->prot_sect && 814 794 ((addr | next | phys) & ~SECTION_MASK) == 0) { 815 - __map_init_section(pmd, addr, next, phys, type); 795 + __map_init_section(pmd, addr, next, phys, type, ng); 816 796 } else { 817 797 alloc_init_pte(pmd, addr, next, 818 - __phys_to_pfn(phys), type); 798 + __phys_to_pfn(phys), type, alloc, ng); 819 799 } 820 800 821 801 phys += next - addr; ··· 825 805 826 806 static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr, 827 807 unsigned long end, phys_addr_t phys, 828 - const struct mem_type *type) 808 + const struct mem_type *type, 809 + void *(*alloc)(unsigned long sz), bool ng) 829 810 { 830 811 pud_t *pud = pud_offset(pgd, addr); 831 812 unsigned long next; 832 813 833 814 do { 834 815 next = pud_addr_end(addr, end); 835 - alloc_init_pmd(pud, addr, next, phys, type); 816 + alloc_init_pmd(pud, addr, next, phys, type, alloc, ng); 836 817 phys += next - addr; 837 818 } while (pud++, addr = next, addr != end); 838 819 } 839 820 840 821 #ifndef CONFIG_ARM_LPAE 841 - static void __init create_36bit_mapping(struct map_desc *md, 842 - const struct mem_type *type) 822 + static void __init create_36bit_mapping(struct mm_struct *mm, 823 + struct map_desc *md, 824 + const struct mem_type *type, 825 + bool ng) 843 826 { 844 827 unsigned long addr, length, end; 845 828 phys_addr_t phys; ··· 882 859 */ 883 860 phys |= (((md->pfn >> (32 - PAGE_SHIFT)) & 0xF) << 20); 884 861 885 - pgd = pgd_offset_k(addr); 862 + pgd = pgd_offset(mm, addr); 886 863 end = addr + length; 887 864 do { 888 865 pud_t *pud = pud_offset(pgd, addr); ··· 890 867 int i; 891 868 892 869 for (i = 0; i < 16; i++) 893 - *pmd++ = __pmd(phys | type->prot_sect | PMD_SECT_SUPER); 870 + *pmd++ = __pmd(phys | type->prot_sect | PMD_SECT_SUPER | 871 + (ng ? PMD_SECT_nG : 0)); 894 872 895 873 addr += SUPERSECTION_SIZE; 896 874 phys += SUPERSECTION_SIZE; ··· 900 876 } 901 877 #endif /* !CONFIG_ARM_LPAE */ 902 878 903 - /* 904 - * Create the page directory entries and any necessary 905 - * page tables for the mapping specified by `md'. We 906 - * are able to cope here with varying sizes and address 907 - * offsets, and we take full advantage of sections and 908 - * supersections. 909 - */ 910 - static void __init create_mapping(struct map_desc *md) 879 + static void __init __create_mapping(struct mm_struct *mm, struct map_desc *md, 880 + void *(*alloc)(unsigned long sz), 881 + bool ng) 911 882 { 912 883 unsigned long addr, length, end; 913 884 phys_addr_t phys; 914 885 const struct mem_type *type; 915 886 pgd_t *pgd; 916 - 917 - if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) { 918 - pr_warn("BUG: not creating mapping for 0x%08llx at 0x%08lx in user region\n", 919 - (long long)__pfn_to_phys((u64)md->pfn), md->virtual); 920 - return; 921 - } 922 - 923 - if ((md->type == MT_DEVICE || md->type == MT_ROM) && 924 - md->virtual >= PAGE_OFFSET && md->virtual < FIXADDR_START && 925 - (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) { 926 - pr_warn("BUG: mapping for 0x%08llx at 0x%08lx out of vmalloc space\n", 927 - (long long)__pfn_to_phys((u64)md->pfn), md->virtual); 928 - } 929 887 930 888 type = &mem_types[md->type]; 931 889 ··· 916 910 * Catch 36-bit addresses 917 911 */ 918 912 if (md->pfn >= 0x100000) { 919 - create_36bit_mapping(md, type); 913 + create_36bit_mapping(mm, md, type, ng); 920 914 return; 921 915 } 922 916 #endif ··· 931 925 return; 932 926 } 933 927 934 - pgd = pgd_offset_k(addr); 928 + pgd = pgd_offset(mm, addr); 935 929 end = addr + length; 936 930 do { 937 931 unsigned long next = pgd_addr_end(addr, end); 938 932 939 - alloc_init_pud(pgd, addr, next, phys, type); 933 + alloc_init_pud(pgd, addr, next, phys, type, alloc, ng); 940 934 941 935 phys += next - addr; 942 936 addr = next; 943 937 } while (pgd++, addr != end); 938 + } 939 + 940 + /* 941 + * Create the page directory entries and any necessary 942 + * page tables for the mapping specified by `md'. We 943 + * are able to cope here with varying sizes and address 944 + * offsets, and we take full advantage of sections and 945 + * supersections. 946 + */ 947 + static void __init create_mapping(struct map_desc *md) 948 + { 949 + if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) { 950 + pr_warn("BUG: not creating mapping for 0x%08llx at 0x%08lx in user region\n", 951 + (long long)__pfn_to_phys((u64)md->pfn), md->virtual); 952 + return; 953 + } 954 + 955 + if ((md->type == MT_DEVICE || md->type == MT_ROM) && 956 + md->virtual >= PAGE_OFFSET && md->virtual < FIXADDR_START && 957 + (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) { 958 + pr_warn("BUG: mapping for 0x%08llx at 0x%08lx out of vmalloc space\n", 959 + (long long)__pfn_to_phys((u64)md->pfn), md->virtual); 960 + } 961 + 962 + __create_mapping(&init_mm, md, early_alloc, false); 963 + } 964 + 965 + void __init create_mapping_late(struct mm_struct *mm, struct map_desc *md, 966 + bool ng) 967 + { 968 + #ifdef CONFIG_ARM_LPAE 969 + pud_t *pud = pud_alloc(mm, pgd_offset(mm, md->virtual), md->virtual); 970 + if (WARN_ON(!pud)) 971 + return; 972 + pmd_alloc(mm, pud, 0); 973 + #endif 974 + __create_mapping(mm, md, late_alloc, ng); 944 975 } 945 976 946 977 /* ··· 1434 1391 phys_addr_t start = reg->base; 1435 1392 phys_addr_t end = start + reg->size; 1436 1393 struct map_desc map; 1394 + 1395 + if (memblock_is_nomap(reg)) 1396 + continue; 1437 1397 1438 1398 if (end > arm_lowmem_limit) 1439 1399 end = arm_lowmem_limit;
+9
arch/arm64/include/asm/efi.h
··· 2 2 #define _ASM_EFI_H 3 3 4 4 #include <asm/io.h> 5 + #include <asm/mmu_context.h> 5 6 #include <asm/neon.h> 7 + #include <asm/tlbflush.h> 6 8 7 9 #ifdef CONFIG_EFI 8 10 extern void efi_init(void); 9 11 #else 10 12 #define efi_init() 11 13 #endif 14 + 15 + int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); 12 16 13 17 #define efi_call_virt(f, ...) \ 14 18 ({ \ ··· 66 62 * into a private set of page tables. If this all succeeds, the Runtime 67 63 * Services are enabled and the EFI_RUNTIME_SERVICES bit set. 68 64 */ 65 + 66 + static inline void efi_set_pgd(struct mm_struct *mm) 67 + { 68 + switch_mm(NULL, mm, NULL); 69 + } 69 70 70 71 void efi_virtmap_load(void); 71 72 void efi_virtmap_unload(void);
+16 -316
arch/arm64/kernel/efi.c
··· 11 11 * 12 12 */ 13 13 14 - #include <linux/atomic.h> 15 14 #include <linux/dmi.h> 16 15 #include <linux/efi.h> 17 - #include <linux/export.h> 18 - #include <linux/memblock.h> 19 - #include <linux/mm_types.h> 20 - #include <linux/bootmem.h> 21 - #include <linux/of.h> 22 - #include <linux/of_fdt.h> 23 - #include <linux/preempt.h> 24 - #include <linux/rbtree.h> 25 - #include <linux/rwsem.h> 26 - #include <linux/sched.h> 27 - #include <linux/slab.h> 28 - #include <linux/spinlock.h> 16 + #include <linux/init.h> 29 17 30 - #include <asm/cacheflush.h> 31 18 #include <asm/efi.h> 32 - #include <asm/tlbflush.h> 33 - #include <asm/mmu_context.h> 34 - #include <asm/mmu.h> 35 - #include <asm/pgtable.h> 36 19 37 - struct efi_memory_map memmap; 38 - 39 - static u64 efi_system_table; 40 - 41 - static pgd_t efi_pgd[PTRS_PER_PGD] __page_aligned_bss; 42 - 43 - static struct mm_struct efi_mm = { 44 - .mm_rb = RB_ROOT, 45 - .pgd = efi_pgd, 46 - .mm_users = ATOMIC_INIT(2), 47 - .mm_count = ATOMIC_INIT(1), 48 - .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), 49 - .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), 50 - .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), 51 - }; 52 - 53 - static int __init is_normal_ram(efi_memory_desc_t *md) 20 + int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md) 54 21 { 55 - if (md->attribute & EFI_MEMORY_WB) 56 - return 1; 57 - return 0; 58 - } 59 - 60 - /* 61 - * Translate a EFI virtual address into a physical address: this is necessary, 62 - * as some data members of the EFI system table are virtually remapped after 63 - * SetVirtualAddressMap() has been called. 64 - */ 65 - static phys_addr_t efi_to_phys(unsigned long addr) 66 - { 67 - efi_memory_desc_t *md; 68 - 69 - for_each_efi_memory_desc(&memmap, md) { 70 - if (!(md->attribute & EFI_MEMORY_RUNTIME)) 71 - continue; 72 - if (md->virt_addr == 0) 73 - /* no virtual mapping has been installed by the stub */ 74 - break; 75 - if (md->virt_addr <= addr && 76 - (addr - md->virt_addr) < (md->num_pages << EFI_PAGE_SHIFT)) 77 - return md->phys_addr + addr - md->virt_addr; 78 - } 79 - return addr; 80 - } 81 - 82 - static int __init uefi_init(void) 83 - { 84 - efi_char16_t *c16; 85 - void *config_tables; 86 - u64 table_size; 87 - char vendor[100] = "unknown"; 88 - int i, retval; 89 - 90 - efi.systab = early_memremap(efi_system_table, 91 - sizeof(efi_system_table_t)); 92 - if (efi.systab == NULL) { 93 - pr_warn("Unable to map EFI system table.\n"); 94 - return -ENOMEM; 95 - } 96 - 97 - set_bit(EFI_BOOT, &efi.flags); 98 - set_bit(EFI_64BIT, &efi.flags); 22 + pteval_t prot_val; 99 23 100 24 /* 101 - * Verify the EFI Table 25 + * Only regions of type EFI_RUNTIME_SERVICES_CODE need to be 26 + * executable, everything else can be mapped with the XN bits 27 + * set. 102 28 */ 103 - if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { 104 - pr_err("System table signature incorrect\n"); 105 - retval = -EINVAL; 106 - goto out; 107 - } 108 - if ((efi.systab->hdr.revision >> 16) < 2) 109 - pr_warn("Warning: EFI system table version %d.%02d, expected 2.00 or greater\n", 110 - efi.systab->hdr.revision >> 16, 111 - efi.systab->hdr.revision & 0xffff); 29 + if ((md->attribute & EFI_MEMORY_WB) == 0) 30 + prot_val = PROT_DEVICE_nGnRE; 31 + else if (md->type == EFI_RUNTIME_SERVICES_CODE || 32 + !PAGE_ALIGNED(md->phys_addr)) 33 + prot_val = pgprot_val(PAGE_KERNEL_EXEC); 34 + else 35 + prot_val = pgprot_val(PAGE_KERNEL); 112 36 113 - /* Show what we know for posterity */ 114 - c16 = early_memremap(efi_to_phys(efi.systab->fw_vendor), 115 - sizeof(vendor) * sizeof(efi_char16_t)); 116 - if (c16) { 117 - for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i) 118 - vendor[i] = c16[i]; 119 - vendor[i] = '\0'; 120 - early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t)); 121 - } 122 - 123 - pr_info("EFI v%u.%.02u by %s\n", 124 - efi.systab->hdr.revision >> 16, 125 - efi.systab->hdr.revision & 0xffff, vendor); 126 - 127 - table_size = sizeof(efi_config_table_64_t) * efi.systab->nr_tables; 128 - config_tables = early_memremap(efi_to_phys(efi.systab->tables), 129 - table_size); 130 - if (config_tables == NULL) { 131 - pr_warn("Unable to map EFI config table array.\n"); 132 - retval = -ENOMEM; 133 - goto out; 134 - } 135 - retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables, 136 - sizeof(efi_config_table_64_t), NULL); 137 - 138 - early_memunmap(config_tables, table_size); 139 - out: 140 - early_memunmap(efi.systab, sizeof(efi_system_table_t)); 141 - return retval; 142 - } 143 - 144 - /* 145 - * Return true for RAM regions we want to permanently reserve. 146 - */ 147 - static __init int is_reserve_region(efi_memory_desc_t *md) 148 - { 149 - switch (md->type) { 150 - case EFI_LOADER_CODE: 151 - case EFI_LOADER_DATA: 152 - case EFI_BOOT_SERVICES_CODE: 153 - case EFI_BOOT_SERVICES_DATA: 154 - case EFI_CONVENTIONAL_MEMORY: 155 - case EFI_PERSISTENT_MEMORY: 156 - return 0; 157 - default: 158 - break; 159 - } 160 - return is_normal_ram(md); 161 - } 162 - 163 - static __init void reserve_regions(void) 164 - { 165 - efi_memory_desc_t *md; 166 - u64 paddr, npages, size; 167 - 168 - if (efi_enabled(EFI_DBG)) 169 - pr_info("Processing EFI memory map:\n"); 170 - 171 - for_each_efi_memory_desc(&memmap, md) { 172 - paddr = md->phys_addr; 173 - npages = md->num_pages; 174 - 175 - if (efi_enabled(EFI_DBG)) { 176 - char buf[64]; 177 - 178 - pr_info(" 0x%012llx-0x%012llx %s", 179 - paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1, 180 - efi_md_typeattr_format(buf, sizeof(buf), md)); 181 - } 182 - 183 - memrange_efi_to_native(&paddr, &npages); 184 - size = npages << PAGE_SHIFT; 185 - 186 - if (is_normal_ram(md)) 187 - early_init_dt_add_memory_arch(paddr, size); 188 - 189 - if (is_reserve_region(md)) { 190 - memblock_reserve(paddr, size); 191 - if (efi_enabled(EFI_DBG)) 192 - pr_cont("*"); 193 - } 194 - 195 - if (efi_enabled(EFI_DBG)) 196 - pr_cont("\n"); 197 - } 198 - 199 - set_bit(EFI_MEMMAP, &efi.flags); 200 - } 201 - 202 - void __init efi_init(void) 203 - { 204 - struct efi_fdt_params params; 205 - 206 - /* Grab UEFI information placed in FDT by stub */ 207 - if (!efi_get_fdt_params(&params)) 208 - return; 209 - 210 - efi_system_table = params.system_table; 211 - 212 - memblock_reserve(params.mmap & PAGE_MASK, 213 - PAGE_ALIGN(params.mmap_size + (params.mmap & ~PAGE_MASK))); 214 - memmap.phys_map = params.mmap; 215 - memmap.map = early_memremap(params.mmap, params.mmap_size); 216 - if (memmap.map == NULL) { 217 - /* 218 - * If we are booting via UEFI, the UEFI memory map is the only 219 - * description of memory we have, so there is little point in 220 - * proceeding if we cannot access it. 221 - */ 222 - panic("Unable to map EFI memory map.\n"); 223 - } 224 - memmap.map_end = memmap.map + params.mmap_size; 225 - memmap.desc_size = params.desc_size; 226 - memmap.desc_version = params.desc_ver; 227 - 228 - if (uefi_init() < 0) 229 - return; 230 - 231 - reserve_regions(); 232 - early_memunmap(memmap.map, params.mmap_size); 233 - } 234 - 235 - static bool __init efi_virtmap_init(void) 236 - { 237 - efi_memory_desc_t *md; 238 - 239 - init_new_context(NULL, &efi_mm); 240 - 241 - for_each_efi_memory_desc(&memmap, md) { 242 - pgprot_t prot; 243 - 244 - if (!(md->attribute & EFI_MEMORY_RUNTIME)) 245 - continue; 246 - if (md->virt_addr == 0) 247 - return false; 248 - 249 - pr_info(" EFI remap 0x%016llx => %p\n", 250 - md->phys_addr, (void *)md->virt_addr); 251 - 252 - /* 253 - * Only regions of type EFI_RUNTIME_SERVICES_CODE need to be 254 - * executable, everything else can be mapped with the XN bits 255 - * set. 256 - */ 257 - if (!is_normal_ram(md)) 258 - prot = __pgprot(PROT_DEVICE_nGnRE); 259 - else if (md->type == EFI_RUNTIME_SERVICES_CODE || 260 - !PAGE_ALIGNED(md->phys_addr)) 261 - prot = PAGE_KERNEL_EXEC; 262 - else 263 - prot = PAGE_KERNEL; 264 - 265 - create_pgd_mapping(&efi_mm, md->phys_addr, md->virt_addr, 266 - md->num_pages << EFI_PAGE_SHIFT, 267 - __pgprot(pgprot_val(prot) | PTE_NG)); 268 - } 269 - return true; 270 - } 271 - 272 - /* 273 - * Enable the UEFI Runtime Services if all prerequisites are in place, i.e., 274 - * non-early mapping of the UEFI system table and virtual mappings for all 275 - * EFI_MEMORY_RUNTIME regions. 276 - */ 277 - static int __init arm64_enable_runtime_services(void) 278 - { 279 - u64 mapsize; 280 - 281 - if (!efi_enabled(EFI_BOOT)) { 282 - pr_info("EFI services will not be available.\n"); 283 - return 0; 284 - } 285 - 286 - if (efi_runtime_disabled()) { 287 - pr_info("EFI runtime services will be disabled.\n"); 288 - return 0; 289 - } 290 - 291 - pr_info("Remapping and enabling EFI services.\n"); 292 - 293 - mapsize = memmap.map_end - memmap.map; 294 - memmap.map = (__force void *)ioremap_cache(memmap.phys_map, 295 - mapsize); 296 - if (!memmap.map) { 297 - pr_err("Failed to remap EFI memory map\n"); 298 - return -ENOMEM; 299 - } 300 - memmap.map_end = memmap.map + mapsize; 301 - efi.memmap = &memmap; 302 - 303 - efi.systab = (__force void *)ioremap_cache(efi_system_table, 304 - sizeof(efi_system_table_t)); 305 - if (!efi.systab) { 306 - pr_err("Failed to remap EFI System Table\n"); 307 - return -ENOMEM; 308 - } 309 - set_bit(EFI_SYSTEM_TABLES, &efi.flags); 310 - 311 - if (!efi_virtmap_init()) { 312 - pr_err("No UEFI virtual mapping was installed -- runtime services will not be available\n"); 313 - return -ENOMEM; 314 - } 315 - 316 - /* Set up runtime services function pointers */ 317 - efi_native_runtime_setup(); 318 - set_bit(EFI_RUNTIME_SERVICES, &efi.flags); 319 - 320 - efi.runtime_version = efi.systab->hdr.revision; 321 - 37 + create_pgd_mapping(mm, md->phys_addr, md->virt_addr, 38 + md->num_pages << EFI_PAGE_SHIFT, 39 + __pgprot(prot_val | PTE_NG)); 322 40 return 0; 323 41 } 324 - early_initcall(arm64_enable_runtime_services); 325 42 326 43 static int __init arm64_dmi_init(void) 327 44 { ··· 53 336 return 0; 54 337 } 55 338 core_initcall(arm64_dmi_init); 56 - 57 - static void efi_set_pgd(struct mm_struct *mm) 58 - { 59 - switch_mm(NULL, mm, NULL); 60 - } 61 - 62 - void efi_virtmap_load(void) 63 - { 64 - preempt_disable(); 65 - efi_set_pgd(&efi_mm); 66 - } 67 - 68 - void efi_virtmap_unload(void) 69 - { 70 - efi_set_pgd(current->active_mm); 71 - preempt_enable(); 72 - } 73 339 74 340 /* 75 341 * UpdateCapsule() depends on the system being shutdown via
+1 -1
arch/arm64/mm/init.c
··· 120 120 #ifdef CONFIG_HAVE_ARCH_PFN_VALID 121 121 int pfn_valid(unsigned long pfn) 122 122 { 123 - return memblock_is_memory(pfn << PAGE_SHIFT); 123 + return memblock_is_map_memory(pfn << PAGE_SHIFT); 124 124 } 125 125 EXPORT_SYMBOL(pfn_valid); 126 126 #endif
+2
arch/arm64/mm/mmu.c
··· 372 372 373 373 if (start >= end) 374 374 break; 375 + if (memblock_is_nomap(reg)) 376 + continue; 375 377 376 378 if (ARM64_SWAPPER_USES_SECTION_MAPS) { 377 379 /*
+4
drivers/firmware/efi/Makefile
··· 18 18 obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o 19 19 obj-$(CONFIG_EFI_STUB) += libstub/ 20 20 obj-$(CONFIG_EFI_FAKE_MEMMAP) += fake_mem.o 21 + 22 + arm-obj-$(CONFIG_EFI) := arm-init.o arm-runtime.o 23 + obj-$(CONFIG_ARM) += $(arm-obj-y) 24 + obj-$(CONFIG_ARM64) += $(arm-obj-y)
+209
drivers/firmware/efi/arm-init.c
··· 1 + /* 2 + * Extensible Firmware Interface 3 + * 4 + * Based on Extensible Firmware Interface Specification version 2.4 5 + * 6 + * Copyright (C) 2013 - 2015 Linaro Ltd. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + * 12 + */ 13 + 14 + #include <linux/efi.h> 15 + #include <linux/init.h> 16 + #include <linux/memblock.h> 17 + #include <linux/mm_types.h> 18 + #include <linux/of.h> 19 + #include <linux/of_fdt.h> 20 + 21 + #include <asm/efi.h> 22 + 23 + struct efi_memory_map memmap; 24 + 25 + u64 efi_system_table; 26 + 27 + static int __init is_normal_ram(efi_memory_desc_t *md) 28 + { 29 + if (md->attribute & EFI_MEMORY_WB) 30 + return 1; 31 + return 0; 32 + } 33 + 34 + /* 35 + * Translate a EFI virtual address into a physical address: this is necessary, 36 + * as some data members of the EFI system table are virtually remapped after 37 + * SetVirtualAddressMap() has been called. 38 + */ 39 + static phys_addr_t efi_to_phys(unsigned long addr) 40 + { 41 + efi_memory_desc_t *md; 42 + 43 + for_each_efi_memory_desc(&memmap, md) { 44 + if (!(md->attribute & EFI_MEMORY_RUNTIME)) 45 + continue; 46 + if (md->virt_addr == 0) 47 + /* no virtual mapping has been installed by the stub */ 48 + break; 49 + if (md->virt_addr <= addr && 50 + (addr - md->virt_addr) < (md->num_pages << EFI_PAGE_SHIFT)) 51 + return md->phys_addr + addr - md->virt_addr; 52 + } 53 + return addr; 54 + } 55 + 56 + static int __init uefi_init(void) 57 + { 58 + efi_char16_t *c16; 59 + void *config_tables; 60 + size_t table_size; 61 + char vendor[100] = "unknown"; 62 + int i, retval; 63 + 64 + efi.systab = early_memremap(efi_system_table, 65 + sizeof(efi_system_table_t)); 66 + if (efi.systab == NULL) { 67 + pr_warn("Unable to map EFI system table.\n"); 68 + return -ENOMEM; 69 + } 70 + 71 + set_bit(EFI_BOOT, &efi.flags); 72 + if (IS_ENABLED(CONFIG_64BIT)) 73 + set_bit(EFI_64BIT, &efi.flags); 74 + 75 + /* 76 + * Verify the EFI Table 77 + */ 78 + if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { 79 + pr_err("System table signature incorrect\n"); 80 + retval = -EINVAL; 81 + goto out; 82 + } 83 + if ((efi.systab->hdr.revision >> 16) < 2) 84 + pr_warn("Warning: EFI system table version %d.%02d, expected 2.00 or greater\n", 85 + efi.systab->hdr.revision >> 16, 86 + efi.systab->hdr.revision & 0xffff); 87 + 88 + /* Show what we know for posterity */ 89 + c16 = early_memremap(efi_to_phys(efi.systab->fw_vendor), 90 + sizeof(vendor) * sizeof(efi_char16_t)); 91 + if (c16) { 92 + for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i) 93 + vendor[i] = c16[i]; 94 + vendor[i] = '\0'; 95 + early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t)); 96 + } 97 + 98 + pr_info("EFI v%u.%.02u by %s\n", 99 + efi.systab->hdr.revision >> 16, 100 + efi.systab->hdr.revision & 0xffff, vendor); 101 + 102 + table_size = sizeof(efi_config_table_64_t) * efi.systab->nr_tables; 103 + config_tables = early_memremap(efi_to_phys(efi.systab->tables), 104 + table_size); 105 + if (config_tables == NULL) { 106 + pr_warn("Unable to map EFI config table array.\n"); 107 + retval = -ENOMEM; 108 + goto out; 109 + } 110 + retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables, 111 + sizeof(efi_config_table_t), NULL); 112 + 113 + early_memunmap(config_tables, table_size); 114 + out: 115 + early_memunmap(efi.systab, sizeof(efi_system_table_t)); 116 + return retval; 117 + } 118 + 119 + /* 120 + * Return true for RAM regions we want to permanently reserve. 121 + */ 122 + static __init int is_reserve_region(efi_memory_desc_t *md) 123 + { 124 + switch (md->type) { 125 + case EFI_LOADER_CODE: 126 + case EFI_LOADER_DATA: 127 + case EFI_BOOT_SERVICES_CODE: 128 + case EFI_BOOT_SERVICES_DATA: 129 + case EFI_CONVENTIONAL_MEMORY: 130 + case EFI_PERSISTENT_MEMORY: 131 + return 0; 132 + default: 133 + break; 134 + } 135 + return is_normal_ram(md); 136 + } 137 + 138 + static __init void reserve_regions(void) 139 + { 140 + efi_memory_desc_t *md; 141 + u64 paddr, npages, size; 142 + 143 + if (efi_enabled(EFI_DBG)) 144 + pr_info("Processing EFI memory map:\n"); 145 + 146 + for_each_efi_memory_desc(&memmap, md) { 147 + paddr = md->phys_addr; 148 + npages = md->num_pages; 149 + 150 + if (efi_enabled(EFI_DBG)) { 151 + char buf[64]; 152 + 153 + pr_info(" 0x%012llx-0x%012llx %s", 154 + paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1, 155 + efi_md_typeattr_format(buf, sizeof(buf), md)); 156 + } 157 + 158 + memrange_efi_to_native(&paddr, &npages); 159 + size = npages << PAGE_SHIFT; 160 + 161 + if (is_normal_ram(md)) 162 + early_init_dt_add_memory_arch(paddr, size); 163 + 164 + if (is_reserve_region(md)) { 165 + memblock_mark_nomap(paddr, size); 166 + if (efi_enabled(EFI_DBG)) 167 + pr_cont("*"); 168 + } 169 + 170 + if (efi_enabled(EFI_DBG)) 171 + pr_cont("\n"); 172 + } 173 + 174 + set_bit(EFI_MEMMAP, &efi.flags); 175 + } 176 + 177 + void __init efi_init(void) 178 + { 179 + struct efi_fdt_params params; 180 + 181 + /* Grab UEFI information placed in FDT by stub */ 182 + if (!efi_get_fdt_params(&params)) 183 + return; 184 + 185 + efi_system_table = params.system_table; 186 + 187 + memmap.phys_map = params.mmap; 188 + memmap.map = early_memremap(params.mmap, params.mmap_size); 189 + if (memmap.map == NULL) { 190 + /* 191 + * If we are booting via UEFI, the UEFI memory map is the only 192 + * description of memory we have, so there is little point in 193 + * proceeding if we cannot access it. 194 + */ 195 + panic("Unable to map EFI memory map.\n"); 196 + } 197 + memmap.map_end = memmap.map + params.mmap_size; 198 + memmap.desc_size = params.desc_size; 199 + memmap.desc_version = params.desc_ver; 200 + 201 + if (uefi_init() < 0) 202 + return; 203 + 204 + reserve_regions(); 205 + early_memunmap(memmap.map, params.mmap_size); 206 + memblock_mark_nomap(params.mmap & PAGE_MASK, 207 + PAGE_ALIGN(params.mmap_size + 208 + (params.mmap & ~PAGE_MASK))); 209 + }
+135
drivers/firmware/efi/arm-runtime.c
··· 1 + /* 2 + * Extensible Firmware Interface 3 + * 4 + * Based on Extensible Firmware Interface Specification version 2.4 5 + * 6 + * Copyright (C) 2013, 2014 Linaro Ltd. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + * 12 + */ 13 + 14 + #include <linux/efi.h> 15 + #include <linux/io.h> 16 + #include <linux/memblock.h> 17 + #include <linux/mm_types.h> 18 + #include <linux/preempt.h> 19 + #include <linux/rbtree.h> 20 + #include <linux/rwsem.h> 21 + #include <linux/sched.h> 22 + #include <linux/slab.h> 23 + #include <linux/spinlock.h> 24 + 25 + #include <asm/cacheflush.h> 26 + #include <asm/efi.h> 27 + #include <asm/mmu.h> 28 + #include <asm/pgalloc.h> 29 + #include <asm/pgtable.h> 30 + 31 + extern u64 efi_system_table; 32 + 33 + static struct mm_struct efi_mm = { 34 + .mm_rb = RB_ROOT, 35 + .mm_users = ATOMIC_INIT(2), 36 + .mm_count = ATOMIC_INIT(1), 37 + .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), 38 + .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), 39 + .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), 40 + }; 41 + 42 + static bool __init efi_virtmap_init(void) 43 + { 44 + efi_memory_desc_t *md; 45 + 46 + efi_mm.pgd = pgd_alloc(&efi_mm); 47 + init_new_context(NULL, &efi_mm); 48 + 49 + for_each_efi_memory_desc(&memmap, md) { 50 + phys_addr_t phys = md->phys_addr; 51 + int ret; 52 + 53 + if (!(md->attribute & EFI_MEMORY_RUNTIME)) 54 + continue; 55 + if (md->virt_addr == 0) 56 + return false; 57 + 58 + ret = efi_create_mapping(&efi_mm, md); 59 + if (!ret) { 60 + pr_info(" EFI remap %pa => %p\n", 61 + &phys, (void *)(unsigned long)md->virt_addr); 62 + } else { 63 + pr_warn(" EFI remap %pa: failed to create mapping (%d)\n", 64 + &phys, ret); 65 + return false; 66 + } 67 + } 68 + return true; 69 + } 70 + 71 + /* 72 + * Enable the UEFI Runtime Services if all prerequisites are in place, i.e., 73 + * non-early mapping of the UEFI system table and virtual mappings for all 74 + * EFI_MEMORY_RUNTIME regions. 75 + */ 76 + static int __init arm_enable_runtime_services(void) 77 + { 78 + u64 mapsize; 79 + 80 + if (!efi_enabled(EFI_BOOT)) { 81 + pr_info("EFI services will not be available.\n"); 82 + return 0; 83 + } 84 + 85 + if (efi_runtime_disabled()) { 86 + pr_info("EFI runtime services will be disabled.\n"); 87 + return 0; 88 + } 89 + 90 + pr_info("Remapping and enabling EFI services.\n"); 91 + 92 + mapsize = memmap.map_end - memmap.map; 93 + memmap.map = (__force void *)ioremap_cache(memmap.phys_map, 94 + mapsize); 95 + if (!memmap.map) { 96 + pr_err("Failed to remap EFI memory map\n"); 97 + return -ENOMEM; 98 + } 99 + memmap.map_end = memmap.map + mapsize; 100 + efi.memmap = &memmap; 101 + 102 + efi.systab = (__force void *)ioremap_cache(efi_system_table, 103 + sizeof(efi_system_table_t)); 104 + if (!efi.systab) { 105 + pr_err("Failed to remap EFI System Table\n"); 106 + return -ENOMEM; 107 + } 108 + set_bit(EFI_SYSTEM_TABLES, &efi.flags); 109 + 110 + if (!efi_virtmap_init()) { 111 + pr_err("No UEFI virtual mapping was installed -- runtime services will not be available\n"); 112 + return -ENOMEM; 113 + } 114 + 115 + /* Set up runtime services function pointers */ 116 + efi_native_runtime_setup(); 117 + set_bit(EFI_RUNTIME_SERVICES, &efi.flags); 118 + 119 + efi.runtime_version = efi.systab->hdr.revision; 120 + 121 + return 0; 122 + } 123 + early_initcall(arm_enable_runtime_services); 124 + 125 + void efi_virtmap_load(void) 126 + { 127 + preempt_disable(); 128 + efi_set_pgd(&efi_mm); 129 + } 130 + 131 + void efi_virtmap_unload(void) 132 + { 133 + efi_set_pgd(current->active_mm); 134 + preempt_enable(); 135 + }
+2
drivers/firmware/efi/efi.c
··· 25 25 #include <linux/io.h> 26 26 #include <linux/platform_device.h> 27 27 28 + #include <asm/efi.h> 29 + 28 30 struct efi __read_mostly efi = { 29 31 .mps = EFI_INVALID_TABLE_ADDR, 30 32 .acpi = EFI_INVALID_TABLE_ADDR,
+9
drivers/firmware/efi/libstub/Makefile
··· 34 34 lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o \ 35 35 $(patsubst %.c,lib-%.o,$(arm-deps)) 36 36 37 + lib-$(CONFIG_ARM) += arm32-stub.o 37 38 lib-$(CONFIG_ARM64) += arm64-stub.o 38 39 CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 39 40 ··· 68 67 $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y) \ 69 68 && (echo >&2 "$@: absolute symbol references not allowed in the EFI stub"; \ 70 69 rm -f $@; /bin/false); else /bin/false; fi 70 + 71 + # 72 + # ARM discards the .data section because it disallows r/w data in the 73 + # decompressor. So move our .data to .data.efistub, which is preserved 74 + # explicitly by the decompressor linker script. 75 + # 76 + STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub 77 + STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS
+3 -1
drivers/firmware/efi/libstub/arm-stub.c
··· 303 303 * The value chosen is the largest non-zero power of 2 suitable for this purpose 304 304 * both on 32-bit and 64-bit ARM CPUs, to maximize the likelihood that it can 305 305 * be mapped efficiently. 306 + * Since 32-bit ARM could potentially execute with a 1G/3G user/kernel split, 307 + * map everything below 1 GB. 306 308 */ 307 - #define EFI_RT_VIRTUAL_BASE 0x40000000 309 + #define EFI_RT_VIRTUAL_BASE SZ_512M 308 310 309 311 static int cmp_mem_desc(const void *l, const void *r) 310 312 {
+85
drivers/firmware/efi/libstub/arm32-stub.c
··· 1 + /* 2 + * Copyright (C) 2013 Linaro Ltd; <roy.franz@linaro.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + */ 9 + #include <linux/efi.h> 10 + #include <asm/efi.h> 11 + 12 + efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 13 + unsigned long *image_addr, 14 + unsigned long *image_size, 15 + unsigned long *reserve_addr, 16 + unsigned long *reserve_size, 17 + unsigned long dram_base, 18 + efi_loaded_image_t *image) 19 + { 20 + unsigned long nr_pages; 21 + efi_status_t status; 22 + /* Use alloc_addr to tranlsate between types */ 23 + efi_physical_addr_t alloc_addr; 24 + 25 + /* 26 + * Verify that the DRAM base address is compatible with the ARM 27 + * boot protocol, which determines the base of DRAM by masking 28 + * off the low 27 bits of the address at which the zImage is 29 + * loaded. These assumptions are made by the decompressor, 30 + * before any memory map is available. 31 + */ 32 + dram_base = round_up(dram_base, SZ_128M); 33 + 34 + /* 35 + * Reserve memory for the uncompressed kernel image. This is 36 + * all that prevents any future allocations from conflicting 37 + * with the kernel. Since we can't tell from the compressed 38 + * image how much DRAM the kernel actually uses (due to BSS 39 + * size uncertainty) we allocate the maximum possible size. 40 + * Do this very early, as prints can cause memory allocations 41 + * that may conflict with this. 42 + */ 43 + alloc_addr = dram_base; 44 + *reserve_size = MAX_UNCOMP_KERNEL_SIZE; 45 + nr_pages = round_up(*reserve_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 46 + status = sys_table->boottime->allocate_pages(EFI_ALLOCATE_ADDRESS, 47 + EFI_LOADER_DATA, 48 + nr_pages, &alloc_addr); 49 + if (status != EFI_SUCCESS) { 50 + *reserve_size = 0; 51 + pr_efi_err(sys_table, "Unable to allocate memory for uncompressed kernel.\n"); 52 + return status; 53 + } 54 + *reserve_addr = alloc_addr; 55 + 56 + /* 57 + * Relocate the zImage, so that it appears in the lowest 128 MB 58 + * memory window. 59 + */ 60 + *image_size = image->image_size; 61 + status = efi_relocate_kernel(sys_table, image_addr, *image_size, 62 + *image_size, 63 + dram_base + MAX_UNCOMP_KERNEL_SIZE, 0); 64 + if (status != EFI_SUCCESS) { 65 + pr_efi_err(sys_table, "Failed to relocate kernel.\n"); 66 + efi_free(sys_table, *reserve_size, *reserve_addr); 67 + *reserve_size = 0; 68 + return status; 69 + } 70 + 71 + /* 72 + * Check to see if we were able to allocate memory low enough 73 + * in memory. The kernel determines the base of DRAM from the 74 + * address at which the zImage is loaded. 75 + */ 76 + if (*image_addr + *image_size > dram_base + ZIMAGE_OFFSET_LIMIT) { 77 + pr_efi_err(sys_table, "Failed to relocate kernel, no low memory available.\n"); 78 + efi_free(sys_table, *reserve_size, *reserve_addr); 79 + *reserve_size = 0; 80 + efi_free(sys_table, *image_size, *image_addr); 81 + *image_size = 0; 82 + return EFI_LOAD_ERROR; 83 + } 84 + return EFI_SUCCESS; 85 + }
+8
include/linux/memblock.h
··· 25 25 MEMBLOCK_NONE = 0x0, /* No special request */ 26 26 MEMBLOCK_HOTPLUG = 0x1, /* hotpluggable region */ 27 27 MEMBLOCK_MIRROR = 0x2, /* mirrored region */ 28 + MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ 28 29 }; 29 30 30 31 struct memblock_region { ··· 83 82 int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); 84 83 int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); 85 84 int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); 85 + int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); 86 86 ulong choose_memblock_flags(void); 87 87 88 88 /* Low level functions */ ··· 184 182 static inline bool memblock_is_mirror(struct memblock_region *m) 185 183 { 186 184 return m->flags & MEMBLOCK_MIRROR; 185 + } 186 + 187 + static inline bool memblock_is_nomap(struct memblock_region *m) 188 + { 189 + return m->flags & MEMBLOCK_NOMAP; 187 190 } 188 191 189 192 #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP ··· 326 319 phys_addr_t memblock_end_of_DRAM(void); 327 320 void memblock_enforce_memory_limit(phys_addr_t memory_limit); 328 321 int memblock_is_memory(phys_addr_t addr); 322 + int memblock_is_map_memory(phys_addr_t addr); 329 323 int memblock_is_region_memory(phys_addr_t base, phys_addr_t size); 330 324 int memblock_is_reserved(phys_addr_t addr); 331 325 bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size);
+28
mm/memblock.c
··· 822 822 return memblock_setclr_flag(base, size, 1, MEMBLOCK_MIRROR); 823 823 } 824 824 825 + /** 826 + * memblock_mark_nomap - Mark a memory region with flag MEMBLOCK_NOMAP. 827 + * @base: the base phys addr of the region 828 + * @size: the size of the region 829 + * 830 + * Return 0 on success, -errno on failure. 831 + */ 832 + int __init_memblock memblock_mark_nomap(phys_addr_t base, phys_addr_t size) 833 + { 834 + return memblock_setclr_flag(base, size, 1, MEMBLOCK_NOMAP); 835 + } 825 836 826 837 /** 827 838 * __next_reserved_mem_region - next function for for_each_reserved_region() ··· 922 911 923 912 /* if we want mirror memory skip non-mirror memory regions */ 924 913 if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m)) 914 + continue; 915 + 916 + /* skip nomap memory unless we were asked for it explicitly */ 917 + if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m)) 925 918 continue; 926 919 927 920 if (!type_b) { ··· 1035 1020 1036 1021 /* if we want mirror memory skip non-mirror memory regions */ 1037 1022 if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m)) 1023 + continue; 1024 + 1025 + /* skip nomap memory unless we were asked for it explicitly */ 1026 + if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m)) 1038 1027 continue; 1039 1028 1040 1029 if (!type_b) { ··· 1536 1517 int __init_memblock memblock_is_memory(phys_addr_t addr) 1537 1518 { 1538 1519 return memblock_search(&memblock.memory, addr) != -1; 1520 + } 1521 + 1522 + int __init_memblock memblock_is_map_memory(phys_addr_t addr) 1523 + { 1524 + int i = memblock_search(&memblock.memory, addr); 1525 + 1526 + if (i == -1) 1527 + return false; 1528 + return !memblock_is_nomap(&memblock.memory.regions[i]); 1539 1529 } 1540 1530 1541 1531 #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP