1 From 6f7a129e59721f6d97a0f06f7078d06f19ade69e Mon Sep 17 00:00:00 2001
2 From: Yutang Jiang <yutang.jiang@nxp.com>
3 Date: Thu, 21 Jul 2016 19:37:42 +0800
4 Subject: [PATCH 70/70] Revert "arm64: use fixmap region for permanent FDT
7 Signed-off-by: Yutang Jiang <yutang.jiang@nxp.com>
9 Documentation/arm64/booting.txt | 10 +++----
10 arch/arm64/include/asm/boot.h | 14 ----------
11 arch/arm64/include/asm/fixmap.h | 15 -----------
12 arch/arm64/include/asm/mmu.h | 1 -
13 arch/arm64/kernel/head.S | 39 ++++++++++++++++++++++++++-
14 arch/arm64/kernel/setup.c | 29 +++++++++++++-------
15 arch/arm64/mm/init.c | 1 +
16 arch/arm64/mm/mmu.c | 57 ---------------------------------------
17 8 files changed, 62 insertions(+), 104 deletions(-)
18 delete mode 100644 arch/arm64/include/asm/boot.h
20 --- a/Documentation/arm64/booting.txt
21 +++ b/Documentation/arm64/booting.txt
22 @@ -45,13 +45,11 @@ sees fit.)
24 Requirement: MANDATORY
26 -The device tree blob (dtb) must be placed on an 8-byte boundary and must
27 -not exceed 2 megabytes in size. Since the dtb will be mapped cacheable
28 -using blocks of up to 2 megabytes in size, it must not be placed within
29 -any 2M region which must be mapped with any specific attributes.
30 +The device tree blob (dtb) must be placed on an 8-byte boundary within
31 +the first 512 megabytes from the start of the kernel image and must not
32 +cross a 2-megabyte boundary. This is to allow the kernel to map the
33 +blob using a single section mapping in the initial page tables.
35 -NOTE: versions prior to v4.2 also require that the DTB be placed within
36 -the 512 MB region starting at text_offset bytes below the kernel Image.
38 3. Decompress the kernel image
39 ------------------------------
40 --- a/arch/arm64/include/asm/boot.h
47 -#include <asm/sizes.h>
50 - * arm64 requires the DTB to be 8 byte aligned and
51 - * not exceed 2MB in size.
53 -#define MIN_FDT_ALIGN 8
54 -#define MAX_FDT_SIZE SZ_2M
57 --- a/arch/arm64/include/asm/fixmap.h
58 +++ b/arch/arm64/include/asm/fixmap.h
61 #include <linux/kernel.h>
62 #include <linux/sizes.h>
63 -#include <asm/boot.h>
69 enum fixed_addresses {
73 - * Reserve a virtual window for the FDT that is 2 MB larger than the
74 - * maximum supported size, and put it at the top of the fixmap region.
75 - * The additional space ensures that any FDT that does not exceed
76 - * MAX_FDT_SIZE can be mapped regardless of whether it crosses any
77 - * 2 MB alignment boundaries.
79 - * Keep this at the top so it remains 2 MB aligned.
81 -#define FIX_FDT_SIZE (MAX_FDT_SIZE + SZ_2M)
83 - FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1,
85 FIX_EARLYCON_MEM_BASE,
87 __end_of_permanent_fixed_addresses,
88 --- a/arch/arm64/include/asm/mmu.h
89 +++ b/arch/arm64/include/asm/mmu.h
90 @@ -34,6 +34,5 @@ extern void init_mem_pgprot(void);
91 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
92 unsigned long virt, phys_addr_t size,
94 -extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
97 --- a/arch/arm64/kernel/head.S
98 +++ b/arch/arm64/kernel/head.S
99 @@ -212,6 +212,8 @@ ENTRY(stext)
100 bl el2_setup // Drop to EL1, w20=cpu_boot_mode
101 adrp x24, __PHYS_OFFSET
102 bl set_cpu_boot_mode_flag
105 bl __create_page_tables // x25=TTBR0, x26=TTBR1
107 * The following calls CPU setup code, see arch/arm64/mm/proc.S for
108 @@ -243,6 +245,24 @@ preserve_boot_args:
109 ENDPROC(preserve_boot_args)
112 + * Determine validity of the x21 FDT pointer.
113 + * The dtb must be 8-byte aligned and live in the first 512M of memory.
130 * Macro to create a table entry to the next page.
132 * tbl: page table address
133 @@ -306,7 +326,8 @@ ENDPROC(preserve_boot_args)
134 * required to get the kernel running. The following sections are required:
135 * - identity mapping to enable the MMU (low address, TTBR0)
136 * - first few MB of the kernel linear mapping to jump to once the MMU has
138 + * been enabled, including the FDT blob (TTBR1)
139 + * - pgd entry for fixed mappings (TTBR1)
141 __create_page_tables:
142 adrp x25, idmap_pg_dir
143 @@ -396,6 +417,22 @@ __create_page_tables:
144 create_block_map x0, x7, x3, x5, x6
147 + * Map the FDT blob (maximum 2MB; must be within 512MB of
150 + mov x3, x21 // FDT phys address
151 + and x3, x3, #~((1 << 21) - 1) // 2MB aligned
152 + mov x6, #PAGE_OFFSET
153 + sub x5, x3, x24 // subtract PHYS_OFFSET
154 + tst x5, #~((1 << 29) - 1) // within 512MB?
155 + csel x21, xzr, x21, ne // zero the FDT pointer
157 + add x5, x5, x6 // __va(FDT blob)
158 + add x6, x5, #1 << 21 // 2MB for the FDT blob
159 + sub x6, x6, #1 // inclusive range
160 + create_block_map x0, x7, x3, x5, x6
163 * Since the page tables have been populated with non-cacheable
164 * accesses (MMU disabled), invalidate the idmap and swapper page
165 * tables again to remove any speculatively loaded cache lines.
166 --- a/arch/arm64/kernel/setup.c
167 +++ b/arch/arm64/kernel/setup.c
168 @@ -87,6 +87,18 @@ static struct resource mem_res[] = {
169 #define kernel_code mem_res[0]
170 #define kernel_data mem_res[1]
172 +void __init early_print(const char *str, ...)
178 + vsnprintf(buf, sizeof(buf), str, ap);
185 * The recorded values of x0 .. x3 upon kernel entry.
187 @@ -180,14 +192,12 @@ static void __init smp_build_mpidr_hash(
189 static void __init setup_machine_fdt(phys_addr_t dt_phys)
191 - void *dt_virt = fixmap_remap_fdt(dt_phys);
193 - if (!dt_virt || !early_init_dt_scan(dt_virt)) {
195 - "Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n"
196 - "The dtb must be 8-byte aligned and must not exceed 2 MB in size\n"
197 - "\nPlease check your bootloader.",
198 - &dt_phys, dt_virt);
199 + if (!dt_phys || !early_init_dt_scan(phys_to_virt(dt_phys))) {
201 + "Error: invalid device tree blob at physical address 0x%p (virtual address 0x%p)\n"
202 + "The dtb must be 8-byte aligned and passed in the first 512MB of memory\n"
203 + "\nPlease check your bootloader.\n",
204 + dt_phys, phys_to_virt(dt_phys));
208 @@ -294,6 +304,7 @@ void __init setup_arch(char **cmdline_p)
209 pr_info("Boot CPU: AArch64 Processor [%08x]\n", read_cpuid_id());
211 sprintf(init_utsname()->machine, ELF_PLATFORM);
212 + setup_machine_fdt(__fdt_pointer);
213 init_mm.start_code = (unsigned long) _text;
214 init_mm.end_code = (unsigned long) _etext;
215 init_mm.end_data = (unsigned long) _edata;
216 @@ -304,8 +315,6 @@ void __init setup_arch(char **cmdline_p)
218 early_ioremap_init();
220 - setup_machine_fdt(__fdt_pointer);
225 --- a/arch/arm64/mm/init.c
226 +++ b/arch/arm64/mm/init.c
227 @@ -171,6 +171,7 @@ void __init arm64_memblock_init(void)
228 memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
231 + early_init_fdt_reserve_self();
232 early_init_fdt_scan_reserved_mem();
234 /* 4GB maximum for 32-bit only capable devices */
235 --- a/arch/arm64/mm/mmu.c
236 +++ b/arch/arm64/mm/mmu.c
238 #include <linux/kernel.h>
239 #include <linux/errno.h>
240 #include <linux/init.h>
241 -#include <linux/libfdt.h>
242 #include <linux/mman.h>
243 #include <linux/nodemask.h>
244 #include <linux/memblock.h>
245 @@ -641,59 +640,3 @@ void __set_fixmap(enum fixed_addresses i
246 flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
250 -void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
252 - const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
253 - pgprot_t prot = PAGE_KERNEL_RO;
258 - * Check whether the physical FDT address is set and meets the minimum
259 - * alignment requirement. Since we are relying on MIN_FDT_ALIGN to be
260 - * at least 8 bytes so that we can always access the magic and size
261 - * fields of the FDT header after mapping the first chunk, double check
262 - * here if that is indeed the case.
264 - BUILD_BUG_ON(MIN_FDT_ALIGN < 8);
265 - if (!dt_phys || dt_phys % MIN_FDT_ALIGN)
269 - * Make sure that the FDT region can be mapped without the need to
270 - * allocate additional translation table pages, so that it is safe
271 - * to call create_mapping() this early.
273 - * On 64k pages, the FDT will be mapped using PTEs, so we need to
274 - * be in the same PMD as the rest of the fixmap.
275 - * On 4k pages, we'll use section mappings for the FDT so we only
276 - * have to be in the same PUD.
278 - BUILD_BUG_ON(dt_virt_base % SZ_2M);
280 - BUILD_BUG_ON(__fix_to_virt(FIX_FDT_END) >> SWAPPER_TABLE_SHIFT !=
281 - __fix_to_virt(FIX_BTMAP_BEGIN) >> SWAPPER_TABLE_SHIFT);
283 - offset = dt_phys % SWAPPER_BLOCK_SIZE;
284 - dt_virt = (void *)dt_virt_base + offset;
286 - /* map the first chunk so we can read the size from the header */
287 - create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
288 - SWAPPER_BLOCK_SIZE, prot);
290 - if (fdt_magic(dt_virt) != FDT_MAGIC)
293 - size = fdt_totalsize(dt_virt);
294 - if (size > MAX_FDT_SIZE)
297 - if (offset + size > SWAPPER_BLOCK_SIZE)
298 - create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
299 - round_up(offset + size, SWAPPER_BLOCK_SIZE), prot);
301 - memblock_reserve(dt_phys, size);