kernel: bump 4.4 to 4.4.167
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 9070-Revert-arm64-use-fixmap-region-for-permanent-FDT-map.patch
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
5 mapping"
6
7 Signed-off-by: Yutang Jiang <yutang.jiang@nxp.com>
8 ---
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
19
20 --- a/Documentation/arm64/booting.txt
21 +++ b/Documentation/arm64/booting.txt
22 @@ -45,13 +45,11 @@ sees fit.)
23
24 Requirement: MANDATORY
25
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.
34
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.
37
38 3. Decompress the kernel image
39 ------------------------------
40 --- a/arch/arm64/include/asm/boot.h
41 +++ /dev/null
42 @@ -1,14 +0,0 @@
43 -
44 -#ifndef __ASM_BOOT_H
45 -#define __ASM_BOOT_H
46 -
47 -#include <asm/sizes.h>
48 -
49 -/*
50 - * arm64 requires the DTB to be 8 byte aligned and
51 - * not exceed 2MB in size.
52 - */
53 -#define MIN_FDT_ALIGN 8
54 -#define MAX_FDT_SIZE SZ_2M
55 -
56 -#endif
57 --- a/arch/arm64/include/asm/fixmap.h
58 +++ b/arch/arm64/include/asm/fixmap.h
59 @@ -18,7 +18,6 @@
60 #ifndef __ASSEMBLY__
61 #include <linux/kernel.h>
62 #include <linux/sizes.h>
63 -#include <asm/boot.h>
64 #include <asm/page.h>
65
66 /*
67 @@ -34,20 +33,6 @@
68 */
69 enum fixed_addresses {
70 FIX_HOLE,
71 -
72 - /*
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.
78 - *
79 - * Keep this at the top so it remains 2 MB aligned.
80 - */
81 -#define FIX_FDT_SIZE (MAX_FDT_SIZE + SZ_2M)
82 - FIX_FDT_END,
83 - FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1,
84 -
85 FIX_EARLYCON_MEM_BASE,
86 FIX_TEXT_POKE0,
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,
93 pgprot_t prot);
94 -extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
95
96 #endif
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
103 +
104 + bl __vet_fdt
105 bl __create_page_tables // x25=TTBR0, x26=TTBR1
106 /*
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)
110
111 /*
112 + * Determine validity of the x21 FDT pointer.
113 + * The dtb must be 8-byte aligned and live in the first 512M of memory.
114 + */
115 +__vet_fdt:
116 + tst x21, #0x7
117 + b.ne 1f
118 + cmp x21, x24
119 + b.lt 1f
120 + mov x0, #(1 << 29)
121 + add x0, x0, x24
122 + cmp x21, x0
123 + b.ge 1f
124 + ret
125 +1:
126 + mov x21, #0
127 + ret
128 +ENDPROC(__vet_fdt)
129 +/*
130 * Macro to create a table entry to the next page.
131 *
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
137 - * been enabled
138 + * been enabled, including the FDT blob (TTBR1)
139 + * - pgd entry for fixed mappings (TTBR1)
140 */
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
145
146 /*
147 + * Map the FDT blob (maximum 2MB; must be within 512MB of
148 + * PHYS_OFFSET).
149 + */
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
156 + b.ne 1f
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
161 +1:
162 + /*
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]
171
172 +void __init early_print(const char *str, ...)
173 +{
174 + char buf[256];
175 + va_list ap;
176 +
177 + va_start(ap, str);
178 + vsnprintf(buf, sizeof(buf), str, ap);
179 + va_end(ap);
180 +
181 + printk("%s", buf);
182 +}
183 +
184 /*
185 * The recorded values of x0 .. x3 upon kernel entry.
186 */
187 @@ -180,14 +192,12 @@ static void __init smp_build_mpidr_hash(
188
189 static void __init setup_machine_fdt(phys_addr_t dt_phys)
190 {
191 - void *dt_virt = fixmap_remap_fdt(dt_phys);
192 -
193 - if (!dt_virt || !early_init_dt_scan(dt_virt)) {
194 - pr_crit("\n"
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))) {
200 + early_print("\n"
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));
205
206 while (true)
207 cpu_relax();
208 @@ -294,6 +304,7 @@ void __init setup_arch(char **cmdline_p)
209 pr_info("Boot CPU: AArch64 Processor [%08x]\n", read_cpuid_id());
210
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)
217 early_fixmap_init();
218 early_ioremap_init();
219
220 - setup_machine_fdt(__fdt_pointer);
221 -
222 parse_early_param();
223
224 /*
225 --- a/arch/arm64/mm/init.c
226 +++ b/arch/arm64/mm/init.c
227 @@ -175,6 +175,7 @@ void __init arm64_memblock_init(void)
228 memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
229 #endif
230
231 + early_init_fdt_reserve_self();
232 early_init_fdt_scan_reserved_mem();
233
234 /* 4GB maximum for 32-bit only capable devices */
235 --- a/arch/arm64/mm/mmu.c
236 +++ b/arch/arm64/mm/mmu.c
237 @@ -21,7 +21,6 @@
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 @@ -642,62 +641,6 @@ void __set_fixmap(enum fixed_addresses i
246 }
247 }
248
249 -void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
250 -{
251 - const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
252 - pgprot_t prot = PAGE_KERNEL_RO;
253 - int size, offset;
254 - void *dt_virt;
255 -
256 - /*
257 - * Check whether the physical FDT address is set and meets the minimum
258 - * alignment requirement. Since we are relying on MIN_FDT_ALIGN to be
259 - * at least 8 bytes so that we can always access the magic and size
260 - * fields of the FDT header after mapping the first chunk, double check
261 - * here if that is indeed the case.
262 - */
263 - BUILD_BUG_ON(MIN_FDT_ALIGN < 8);
264 - if (!dt_phys || dt_phys % MIN_FDT_ALIGN)
265 - return NULL;
266 -
267 - /*
268 - * Make sure that the FDT region can be mapped without the need to
269 - * allocate additional translation table pages, so that it is safe
270 - * to call create_mapping() this early.
271 - *
272 - * On 64k pages, the FDT will be mapped using PTEs, so we need to
273 - * be in the same PMD as the rest of the fixmap.
274 - * On 4k pages, we'll use section mappings for the FDT so we only
275 - * have to be in the same PUD.
276 - */
277 - BUILD_BUG_ON(dt_virt_base % SZ_2M);
278 -
279 - BUILD_BUG_ON(__fix_to_virt(FIX_FDT_END) >> SWAPPER_TABLE_SHIFT !=
280 - __fix_to_virt(FIX_BTMAP_BEGIN) >> SWAPPER_TABLE_SHIFT);
281 -
282 - offset = dt_phys % SWAPPER_BLOCK_SIZE;
283 - dt_virt = (void *)dt_virt_base + offset;
284 -
285 - /* map the first chunk so we can read the size from the header */
286 - create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
287 - SWAPPER_BLOCK_SIZE, prot);
288 -
289 - if (fdt_magic(dt_virt) != FDT_MAGIC)
290 - return NULL;
291 -
292 - size = fdt_totalsize(dt_virt);
293 - if (size > MAX_FDT_SIZE)
294 - return NULL;
295 -
296 - if (offset + size > SWAPPER_BLOCK_SIZE)
297 - create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
298 - round_up(offset + size, SWAPPER_BLOCK_SIZE), prot);
299 -
300 - memblock_reserve(dt_phys, size);
301 -
302 - return dt_virt;
303 -}
304 -
305 #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
306 int pud_free_pmd_page(pud_t *pud, unsigned long addr)
307 {