9070-Revert-arm64-use-fixmap-region-for-permanent-FDT-map.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. Signed-off-by: Yutang Jiang <yutang.jiang@nxp.com>
  7. ---
  8. Documentation/arm64/booting.txt | 10 +++----
  9. arch/arm64/include/asm/boot.h | 14 ----------
  10. arch/arm64/include/asm/fixmap.h | 15 -----------
  11. arch/arm64/include/asm/mmu.h | 1 -
  12. arch/arm64/kernel/head.S | 39 ++++++++++++++++++++++++++-
  13. arch/arm64/kernel/setup.c | 29 +++++++++++++-------
  14. arch/arm64/mm/init.c | 1 +
  15. arch/arm64/mm/mmu.c | 57 ---------------------------------------
  16. 8 files changed, 62 insertions(+), 104 deletions(-)
  17. delete mode 100644 arch/arm64/include/asm/boot.h
  18. --- a/Documentation/arm64/booting.txt
  19. +++ b/Documentation/arm64/booting.txt
  20. @@ -45,13 +45,11 @@ sees fit.)
  21. Requirement: MANDATORY
  22. -The device tree blob (dtb) must be placed on an 8-byte boundary and must
  23. -not exceed 2 megabytes in size. Since the dtb will be mapped cacheable
  24. -using blocks of up to 2 megabytes in size, it must not be placed within
  25. -any 2M region which must be mapped with any specific attributes.
  26. +The device tree blob (dtb) must be placed on an 8-byte boundary within
  27. +the first 512 megabytes from the start of the kernel image and must not
  28. +cross a 2-megabyte boundary. This is to allow the kernel to map the
  29. +blob using a single section mapping in the initial page tables.
  30. -NOTE: versions prior to v4.2 also require that the DTB be placed within
  31. -the 512 MB region starting at text_offset bytes below the kernel Image.
  32. 3. Decompress the kernel image
  33. ------------------------------
  34. --- a/arch/arm64/include/asm/boot.h
  35. +++ /dev/null
  36. @@ -1,14 +0,0 @@
  37. -
  38. -#ifndef __ASM_BOOT_H
  39. -#define __ASM_BOOT_H
  40. -
  41. -#include <asm/sizes.h>
  42. -
  43. -/*
  44. - * arm64 requires the DTB to be 8 byte aligned and
  45. - * not exceed 2MB in size.
  46. - */
  47. -#define MIN_FDT_ALIGN 8
  48. -#define MAX_FDT_SIZE SZ_2M
  49. -
  50. -#endif
  51. --- a/arch/arm64/include/asm/fixmap.h
  52. +++ b/arch/arm64/include/asm/fixmap.h
  53. @@ -18,7 +18,6 @@
  54. #ifndef __ASSEMBLY__
  55. #include <linux/kernel.h>
  56. #include <linux/sizes.h>
  57. -#include <asm/boot.h>
  58. #include <asm/page.h>
  59. /*
  60. @@ -34,20 +33,6 @@
  61. */
  62. enum fixed_addresses {
  63. FIX_HOLE,
  64. -
  65. - /*
  66. - * Reserve a virtual window for the FDT that is 2 MB larger than the
  67. - * maximum supported size, and put it at the top of the fixmap region.
  68. - * The additional space ensures that any FDT that does not exceed
  69. - * MAX_FDT_SIZE can be mapped regardless of whether it crosses any
  70. - * 2 MB alignment boundaries.
  71. - *
  72. - * Keep this at the top so it remains 2 MB aligned.
  73. - */
  74. -#define FIX_FDT_SIZE (MAX_FDT_SIZE + SZ_2M)
  75. - FIX_FDT_END,
  76. - FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1,
  77. -
  78. FIX_EARLYCON_MEM_BASE,
  79. FIX_TEXT_POKE0,
  80. __end_of_permanent_fixed_addresses,
  81. --- a/arch/arm64/include/asm/mmu.h
  82. +++ b/arch/arm64/include/asm/mmu.h
  83. @@ -34,6 +34,5 @@ extern void init_mem_pgprot(void);
  84. extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
  85. unsigned long virt, phys_addr_t size,
  86. pgprot_t prot);
  87. -extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
  88. #endif
  89. --- a/arch/arm64/kernel/head.S
  90. +++ b/arch/arm64/kernel/head.S
  91. @@ -213,6 +213,8 @@ ENTRY(stext)
  92. bl el2_setup // Drop to EL1, w20=cpu_boot_mode
  93. adrp x24, __PHYS_OFFSET
  94. bl set_cpu_boot_mode_flag
  95. +
  96. + bl __vet_fdt
  97. bl __create_page_tables // x25=TTBR0, x26=TTBR1
  98. /*
  99. * The following calls CPU setup code, see arch/arm64/mm/proc.S for
  100. @@ -244,6 +246,24 @@ preserve_boot_args:
  101. ENDPROC(preserve_boot_args)
  102. /*
  103. + * Determine validity of the x21 FDT pointer.
  104. + * The dtb must be 8-byte aligned and live in the first 512M of memory.
  105. + */
  106. +__vet_fdt:
  107. + tst x21, #0x7
  108. + b.ne 1f
  109. + cmp x21, x24
  110. + b.lt 1f
  111. + mov x0, #(1 << 29)
  112. + add x0, x0, x24
  113. + cmp x21, x0
  114. + b.ge 1f
  115. + ret
  116. +1:
  117. + mov x21, #0
  118. + ret
  119. +ENDPROC(__vet_fdt)
  120. +/*
  121. * Macro to create a table entry to the next page.
  122. *
  123. * tbl: page table address
  124. @@ -307,7 +327,8 @@ ENDPROC(preserve_boot_args)
  125. * required to get the kernel running. The following sections are required:
  126. * - identity mapping to enable the MMU (low address, TTBR0)
  127. * - first few MB of the kernel linear mapping to jump to once the MMU has
  128. - * been enabled
  129. + * been enabled, including the FDT blob (TTBR1)
  130. + * - pgd entry for fixed mappings (TTBR1)
  131. */
  132. __create_page_tables:
  133. adrp x25, idmap_pg_dir
  134. @@ -397,6 +418,22 @@ __create_page_tables:
  135. create_block_map x0, x7, x3, x5, x6
  136. /*
  137. + * Map the FDT blob (maximum 2MB; must be within 512MB of
  138. + * PHYS_OFFSET).
  139. + */
  140. + mov x3, x21 // FDT phys address
  141. + and x3, x3, #~((1 << 21) - 1) // 2MB aligned
  142. + mov x6, #PAGE_OFFSET
  143. + sub x5, x3, x24 // subtract PHYS_OFFSET
  144. + tst x5, #~((1 << 29) - 1) // within 512MB?
  145. + csel x21, xzr, x21, ne // zero the FDT pointer
  146. + b.ne 1f
  147. + add x5, x5, x6 // __va(FDT blob)
  148. + add x6, x5, #1 << 21 // 2MB for the FDT blob
  149. + sub x6, x6, #1 // inclusive range
  150. + create_block_map x0, x7, x3, x5, x6
  151. +1:
  152. + /*
  153. * Since the page tables have been populated with non-cacheable
  154. * accesses (MMU disabled), invalidate the idmap and swapper page
  155. * tables again to remove any speculatively loaded cache lines.
  156. --- a/arch/arm64/kernel/setup.c
  157. +++ b/arch/arm64/kernel/setup.c
  158. @@ -87,6 +87,18 @@ static struct resource mem_res[] = {
  159. #define kernel_code mem_res[0]
  160. #define kernel_data mem_res[1]
  161. +void __init early_print(const char *str, ...)
  162. +{
  163. + char buf[256];
  164. + va_list ap;
  165. +
  166. + va_start(ap, str);
  167. + vsnprintf(buf, sizeof(buf), str, ap);
  168. + va_end(ap);
  169. +
  170. + printk("%s", buf);
  171. +}
  172. +
  173. /*
  174. * The recorded values of x0 .. x3 upon kernel entry.
  175. */
  176. @@ -180,14 +192,12 @@ static void __init smp_build_mpidr_hash(
  177. static void __init setup_machine_fdt(phys_addr_t dt_phys)
  178. {
  179. - void *dt_virt = fixmap_remap_fdt(dt_phys);
  180. -
  181. - if (!dt_virt || !early_init_dt_scan(dt_virt)) {
  182. - pr_crit("\n"
  183. - "Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n"
  184. - "The dtb must be 8-byte aligned and must not exceed 2 MB in size\n"
  185. - "\nPlease check your bootloader.",
  186. - &dt_phys, dt_virt);
  187. + if (!dt_phys || !early_init_dt_scan(phys_to_virt(dt_phys))) {
  188. + early_print("\n"
  189. + "Error: invalid device tree blob at physical address 0x%p (virtual address 0x%p)\n"
  190. + "The dtb must be 8-byte aligned and passed in the first 512MB of memory\n"
  191. + "\nPlease check your bootloader.\n",
  192. + dt_phys, phys_to_virt(dt_phys));
  193. while (true)
  194. cpu_relax();
  195. @@ -294,6 +304,7 @@ void __init setup_arch(char **cmdline_p)
  196. pr_info("Boot CPU: AArch64 Processor [%08x]\n", read_cpuid_id());
  197. sprintf(init_utsname()->machine, ELF_PLATFORM);
  198. + setup_machine_fdt(__fdt_pointer);
  199. init_mm.start_code = (unsigned long) _text;
  200. init_mm.end_code = (unsigned long) _etext;
  201. init_mm.end_data = (unsigned long) _edata;
  202. @@ -304,8 +315,6 @@ void __init setup_arch(char **cmdline_p)
  203. early_fixmap_init();
  204. early_ioremap_init();
  205. - setup_machine_fdt(__fdt_pointer);
  206. -
  207. parse_early_param();
  208. /*
  209. --- a/arch/arm64/mm/init.c
  210. +++ b/arch/arm64/mm/init.c
  211. @@ -175,6 +175,7 @@ void __init arm64_memblock_init(void)
  212. memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
  213. #endif
  214. + early_init_fdt_reserve_self();
  215. early_init_fdt_scan_reserved_mem();
  216. /* 4GB maximum for 32-bit only capable devices */
  217. --- a/arch/arm64/mm/mmu.c
  218. +++ b/arch/arm64/mm/mmu.c
  219. @@ -21,7 +21,6 @@
  220. #include <linux/kernel.h>
  221. #include <linux/errno.h>
  222. #include <linux/init.h>
  223. -#include <linux/libfdt.h>
  224. #include <linux/mman.h>
  225. #include <linux/nodemask.h>
  226. #include <linux/memblock.h>
  227. @@ -642,62 +641,6 @@ void __set_fixmap(enum fixed_addresses i
  228. }
  229. }
  230. -void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
  231. -{
  232. - const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
  233. - pgprot_t prot = PAGE_KERNEL_RO;
  234. - int size, offset;
  235. - void *dt_virt;
  236. -
  237. - /*
  238. - * Check whether the physical FDT address is set and meets the minimum
  239. - * alignment requirement. Since we are relying on MIN_FDT_ALIGN to be
  240. - * at least 8 bytes so that we can always access the magic and size
  241. - * fields of the FDT header after mapping the first chunk, double check
  242. - * here if that is indeed the case.
  243. - */
  244. - BUILD_BUG_ON(MIN_FDT_ALIGN < 8);
  245. - if (!dt_phys || dt_phys % MIN_FDT_ALIGN)
  246. - return NULL;
  247. -
  248. - /*
  249. - * Make sure that the FDT region can be mapped without the need to
  250. - * allocate additional translation table pages, so that it is safe
  251. - * to call create_mapping() this early.
  252. - *
  253. - * On 64k pages, the FDT will be mapped using PTEs, so we need to
  254. - * be in the same PMD as the rest of the fixmap.
  255. - * On 4k pages, we'll use section mappings for the FDT so we only
  256. - * have to be in the same PUD.
  257. - */
  258. - BUILD_BUG_ON(dt_virt_base % SZ_2M);
  259. -
  260. - BUILD_BUG_ON(__fix_to_virt(FIX_FDT_END) >> SWAPPER_TABLE_SHIFT !=
  261. - __fix_to_virt(FIX_BTMAP_BEGIN) >> SWAPPER_TABLE_SHIFT);
  262. -
  263. - offset = dt_phys % SWAPPER_BLOCK_SIZE;
  264. - dt_virt = (void *)dt_virt_base + offset;
  265. -
  266. - /* map the first chunk so we can read the size from the header */
  267. - create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
  268. - SWAPPER_BLOCK_SIZE, prot);
  269. -
  270. - if (fdt_magic(dt_virt) != FDT_MAGIC)
  271. - return NULL;
  272. -
  273. - size = fdt_totalsize(dt_virt);
  274. - if (size > MAX_FDT_SIZE)
  275. - return NULL;
  276. -
  277. - if (offset + size > SWAPPER_BLOCK_SIZE)
  278. - create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
  279. - round_up(offset + size, SWAPPER_BLOCK_SIZE), prot);
  280. -
  281. - memblock_reserve(dt_phys, size);
  282. -
  283. - return dt_virt;
  284. -}
  285. -
  286. #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
  287. int pud_free_pmd_page(pud_t *pud, unsigned long addr)
  288. {