init_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PowerPC version
  4. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  5. *
  6. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  7. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  8. * Copyright (C) 1996 Paul Mackerras
  9. *
  10. * Derived from "arch/i386/mm/init.c"
  11. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  12. *
  13. * Dave Engebretsen <engebret@us.ibm.com>
  14. * Rework for PPC64 port.
  15. */
  16. #undef DEBUG
  17. #include <linux/signal.h>
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/string.h>
  22. #include <linux/types.h>
  23. #include <linux/mman.h>
  24. #include <linux/mm.h>
  25. #include <linux/swap.h>
  26. #include <linux/stddef.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/init.h>
  29. #include <linux/delay.h>
  30. #include <linux/highmem.h>
  31. #include <linux/idr.h>
  32. #include <linux/nodemask.h>
  33. #include <linux/module.h>
  34. #include <linux/poison.h>
  35. #include <linux/memblock.h>
  36. #include <linux/hugetlb.h>
  37. #include <linux/slab.h>
  38. #include <linux/of_fdt.h>
  39. #include <linux/libfdt.h>
  40. #include <linux/memremap.h>
  41. #include <linux/memory.h>
  42. #include <asm/pgalloc.h>
  43. #include <asm/page.h>
  44. #include <asm/prom.h>
  45. #include <asm/rtas.h>
  46. #include <asm/io.h>
  47. #include <asm/mmu_context.h>
  48. #include <asm/mmu.h>
  49. #include <linux/uaccess.h>
  50. #include <asm/smp.h>
  51. #include <asm/machdep.h>
  52. #include <asm/tlb.h>
  53. #include <asm/eeh.h>
  54. #include <asm/processor.h>
  55. #include <asm/mmzone.h>
  56. #include <asm/cputable.h>
  57. #include <asm/sections.h>
  58. #include <asm/iommu.h>
  59. #include <asm/vdso.h>
  60. #include <asm/hugetlb.h>
  61. #include <mm/mmu_decl.h>
  62. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  63. /*
  64. * Given an address within the vmemmap, determine the page that
  65. * represents the start of the subsection it is within. Note that we have to
  66. * do this by hand as the proffered address may not be correctly aligned.
  67. * Subtraction of non-aligned pointers produces undefined results.
  68. */
  69. static struct page * __meminit vmemmap_subsection_start(unsigned long vmemmap_addr)
  70. {
  71. unsigned long start_pfn;
  72. unsigned long offset = vmemmap_addr - ((unsigned long)(vmemmap));
  73. /* Return the pfn of the start of the section. */
  74. start_pfn = (offset / sizeof(struct page)) & PAGE_SUBSECTION_MASK;
  75. return pfn_to_page(start_pfn);
  76. }
  77. /*
  78. * Since memory is added in sub-section chunks, before creating a new vmemmap
  79. * mapping, the kernel should check whether there is an existing memmap mapping
  80. * covering the new subsection added. This is needed because kernel can map
  81. * vmemmap area using 16MB pages which will cover a memory range of 16G. Such
  82. * a range covers multiple subsections (2M)
  83. *
  84. * If any subsection in the 16G range mapped by vmemmap is valid we consider the
  85. * vmemmap populated (There is a page table entry already present). We can't do
  86. * a page table lookup here because with the hash translation we don't keep
  87. * vmemmap details in linux page table.
  88. */
  89. int __meminit vmemmap_populated(unsigned long vmemmap_addr, int vmemmap_map_size)
  90. {
  91. struct page *start;
  92. unsigned long vmemmap_end = vmemmap_addr + vmemmap_map_size;
  93. start = vmemmap_subsection_start(vmemmap_addr);
  94. for (; (unsigned long)start < vmemmap_end; start += PAGES_PER_SUBSECTION)
  95. /*
  96. * pfn valid check here is intended to really check
  97. * whether we have any subsection already initialized
  98. * in this range.
  99. */
  100. if (pfn_valid(page_to_pfn(start)))
  101. return 1;
  102. return 0;
  103. }
  104. /*
  105. * vmemmap virtual address space management does not have a traditional page
  106. * table to track which virtual struct pages are backed by physical mapping.
  107. * The virtual to physical mappings are tracked in a simple linked list
  108. * format. 'vmemmap_list' maintains the entire vmemmap physical mapping at
  109. * all times where as the 'next' list maintains the available
  110. * vmemmap_backing structures which have been deleted from the
  111. * 'vmemmap_global' list during system runtime (memory hotplug remove
  112. * operation). The freed 'vmemmap_backing' structures are reused later when
  113. * new requests come in without allocating fresh memory. This pointer also
  114. * tracks the allocated 'vmemmap_backing' structures as we allocate one
  115. * full page memory at a time when we dont have any.
  116. */
  117. struct vmemmap_backing *vmemmap_list;
  118. static struct vmemmap_backing *next;
  119. /*
  120. * The same pointer 'next' tracks individual chunks inside the allocated
  121. * full page during the boot time and again tracks the freed nodes during
  122. * runtime. It is racy but it does not happen as they are separated by the
  123. * boot process. Will create problem if some how we have memory hotplug
  124. * operation during boot !!
  125. */
  126. static int num_left;
  127. static int num_freed;
  128. static __meminit struct vmemmap_backing * vmemmap_list_alloc(int node)
  129. {
  130. struct vmemmap_backing *vmem_back;
  131. /* get from freed entries first */
  132. if (num_freed) {
  133. num_freed--;
  134. vmem_back = next;
  135. next = next->list;
  136. return vmem_back;
  137. }
  138. /* allocate a page when required and hand out chunks */
  139. if (!num_left) {
  140. next = vmemmap_alloc_block(PAGE_SIZE, node);
  141. if (unlikely(!next)) {
  142. WARN_ON(1);
  143. return NULL;
  144. }
  145. num_left = PAGE_SIZE / sizeof(struct vmemmap_backing);
  146. }
  147. num_left--;
  148. return next++;
  149. }
  150. static __meminit int vmemmap_list_populate(unsigned long phys,
  151. unsigned long start,
  152. int node)
  153. {
  154. struct vmemmap_backing *vmem_back;
  155. vmem_back = vmemmap_list_alloc(node);
  156. if (unlikely(!vmem_back)) {
  157. pr_debug("vmemap list allocation failed\n");
  158. return -ENOMEM;
  159. }
  160. vmem_back->phys = phys;
  161. vmem_back->virt_addr = start;
  162. vmem_back->list = vmemmap_list;
  163. vmemmap_list = vmem_back;
  164. return 0;
  165. }
  166. bool altmap_cross_boundary(struct vmem_altmap *altmap, unsigned long start,
  167. unsigned long page_size)
  168. {
  169. unsigned long nr_pfn = page_size / sizeof(struct page);
  170. unsigned long start_pfn = page_to_pfn((struct page *)start);
  171. if ((start_pfn + nr_pfn - 1) > altmap->end_pfn)
  172. return true;
  173. if (start_pfn < altmap->base_pfn)
  174. return true;
  175. return false;
  176. }
  177. static int __meminit __vmemmap_populate(unsigned long start, unsigned long end, int node,
  178. struct vmem_altmap *altmap)
  179. {
  180. bool altmap_alloc;
  181. unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
  182. /* Align to the page size of the linear mapping. */
  183. start = ALIGN_DOWN(start, page_size);
  184. pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node);
  185. for (; start < end; start += page_size) {
  186. void *p = NULL;
  187. int rc;
  188. /*
  189. * This vmemmap range is backing different subsections. If any
  190. * of that subsection is marked valid, that means we already
  191. * have initialized a page table covering this range and hence
  192. * the vmemmap range is populated.
  193. */
  194. if (vmemmap_populated(start, page_size))
  195. continue;
  196. /*
  197. * Allocate from the altmap first if we have one. This may
  198. * fail due to alignment issues when using 16MB hugepages, so
  199. * fall back to system memory if the altmap allocation fail.
  200. */
  201. if (altmap && !altmap_cross_boundary(altmap, start, page_size)) {
  202. p = vmemmap_alloc_block_buf(page_size, node, altmap);
  203. if (!p)
  204. pr_debug("altmap block allocation failed, falling back to system memory");
  205. else
  206. altmap_alloc = true;
  207. }
  208. if (!p) {
  209. p = vmemmap_alloc_block_buf(page_size, node, NULL);
  210. altmap_alloc = false;
  211. }
  212. if (!p)
  213. return -ENOMEM;
  214. if (vmemmap_list_populate(__pa(p), start, node)) {
  215. /*
  216. * If we don't populate vmemap list, we don't have
  217. * the ability to free the allocated vmemmap
  218. * pages in section_deactivate. Hence free them
  219. * here.
  220. */
  221. int nr_pfns = page_size >> PAGE_SHIFT;
  222. unsigned long page_order = get_order(page_size);
  223. if (altmap_alloc)
  224. vmem_altmap_free(altmap, nr_pfns);
  225. else
  226. free_pages((unsigned long)p, page_order);
  227. return -ENOMEM;
  228. }
  229. pr_debug(" * %016lx..%016lx allocated at %p\n",
  230. start, start + page_size, p);
  231. rc = vmemmap_create_mapping(start, page_size, __pa(p));
  232. if (rc < 0) {
  233. pr_warn("%s: Unable to create vmemmap mapping: %d\n",
  234. __func__, rc);
  235. return -EFAULT;
  236. }
  237. }
  238. return 0;
  239. }
  240. int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
  241. struct vmem_altmap *altmap)
  242. {
  243. #ifdef CONFIG_PPC_BOOK3S_64
  244. if (radix_enabled())
  245. return radix__vmemmap_populate(start, end, node, altmap);
  246. #endif
  247. return __vmemmap_populate(start, end, node, altmap);
  248. }
  249. #ifdef CONFIG_MEMORY_HOTPLUG
  250. static unsigned long vmemmap_list_free(unsigned long start)
  251. {
  252. struct vmemmap_backing *vmem_back, *vmem_back_prev;
  253. vmem_back_prev = vmem_back = vmemmap_list;
  254. /* look for it with prev pointer recorded */
  255. for (; vmem_back; vmem_back = vmem_back->list) {
  256. if (vmem_back->virt_addr == start)
  257. break;
  258. vmem_back_prev = vmem_back;
  259. }
  260. if (unlikely(!vmem_back))
  261. return 0;
  262. /* remove it from vmemmap_list */
  263. if (vmem_back == vmemmap_list) /* remove head */
  264. vmemmap_list = vmem_back->list;
  265. else
  266. vmem_back_prev->list = vmem_back->list;
  267. /* next point to this freed entry */
  268. vmem_back->list = next;
  269. next = vmem_back;
  270. num_freed++;
  271. return vmem_back->phys;
  272. }
  273. static void __ref __vmemmap_free(unsigned long start, unsigned long end,
  274. struct vmem_altmap *altmap)
  275. {
  276. unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
  277. unsigned long page_order = get_order(page_size);
  278. unsigned long alt_start = ~0, alt_end = ~0;
  279. unsigned long base_pfn;
  280. start = ALIGN_DOWN(start, page_size);
  281. if (altmap) {
  282. alt_start = altmap->base_pfn;
  283. alt_end = altmap->base_pfn + altmap->reserve + altmap->free;
  284. }
  285. pr_debug("vmemmap_free %lx...%lx\n", start, end);
  286. for (; start < end; start += page_size) {
  287. unsigned long nr_pages, addr;
  288. struct page *page;
  289. /*
  290. * We have already marked the subsection we are trying to remove
  291. * invalid. So if we want to remove the vmemmap range, we
  292. * need to make sure there is no subsection marked valid
  293. * in this range.
  294. */
  295. if (vmemmap_populated(start, page_size))
  296. continue;
  297. addr = vmemmap_list_free(start);
  298. if (!addr)
  299. continue;
  300. page = pfn_to_page(addr >> PAGE_SHIFT);
  301. nr_pages = 1 << page_order;
  302. base_pfn = PHYS_PFN(addr);
  303. if (base_pfn >= alt_start && base_pfn < alt_end) {
  304. vmem_altmap_free(altmap, nr_pages);
  305. } else if (PageReserved(page)) {
  306. /* allocated from bootmem */
  307. if (page_size < PAGE_SIZE) {
  308. /*
  309. * this shouldn't happen, but if it is
  310. * the case, leave the memory there
  311. */
  312. WARN_ON_ONCE(1);
  313. } else {
  314. while (nr_pages--)
  315. free_reserved_page(page++);
  316. }
  317. } else {
  318. free_pages((unsigned long)(__va(addr)), page_order);
  319. }
  320. vmemmap_remove_mapping(start, page_size);
  321. }
  322. }
  323. void __ref vmemmap_free(unsigned long start, unsigned long end,
  324. struct vmem_altmap *altmap)
  325. {
  326. #ifdef CONFIG_PPC_BOOK3S_64
  327. if (radix_enabled())
  328. return radix__vmemmap_free(start, end, altmap);
  329. #endif
  330. return __vmemmap_free(start, end, altmap);
  331. }
  332. #endif
  333. void register_page_bootmem_memmap(unsigned long section_nr,
  334. struct page *start_page, unsigned long size)
  335. {
  336. }
  337. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  338. #ifdef CONFIG_PPC_BOOK3S_64
  339. unsigned int mmu_lpid_bits;
  340. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  341. EXPORT_SYMBOL_GPL(mmu_lpid_bits);
  342. #endif
  343. unsigned int mmu_pid_bits;
  344. static bool disable_radix = !IS_ENABLED(CONFIG_PPC_RADIX_MMU_DEFAULT);
  345. static int __init parse_disable_radix(char *p)
  346. {
  347. bool val;
  348. if (!p)
  349. val = true;
  350. else if (kstrtobool(p, &val))
  351. return -EINVAL;
  352. disable_radix = val;
  353. return 0;
  354. }
  355. early_param("disable_radix", parse_disable_radix);
  356. /*
  357. * If we're running under a hypervisor, we need to check the contents of
  358. * /chosen/ibm,architecture-vec-5 to see if the hypervisor is willing to do
  359. * radix. If not, we clear the radix feature bit so we fall back to hash.
  360. */
  361. static void __init early_check_vec5(void)
  362. {
  363. unsigned long root, chosen;
  364. int size;
  365. const u8 *vec5;
  366. u8 mmu_supported;
  367. root = of_get_flat_dt_root();
  368. chosen = of_get_flat_dt_subnode_by_name(root, "chosen");
  369. if (chosen == -FDT_ERR_NOTFOUND) {
  370. cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
  371. return;
  372. }
  373. vec5 = of_get_flat_dt_prop(chosen, "ibm,architecture-vec-5", &size);
  374. if (!vec5) {
  375. cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
  376. return;
  377. }
  378. if (size <= OV5_INDX(OV5_MMU_SUPPORT)) {
  379. cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
  380. return;
  381. }
  382. /* Check for supported configuration */
  383. mmu_supported = vec5[OV5_INDX(OV5_MMU_SUPPORT)] &
  384. OV5_FEAT(OV5_MMU_SUPPORT);
  385. if (mmu_supported == OV5_FEAT(OV5_MMU_RADIX)) {
  386. /* Hypervisor only supports radix - check enabled && GTSE */
  387. if (!early_radix_enabled()) {
  388. pr_warn("WARNING: Ignoring cmdline option disable_radix\n");
  389. }
  390. if (!(vec5[OV5_INDX(OV5_RADIX_GTSE)] &
  391. OV5_FEAT(OV5_RADIX_GTSE))) {
  392. cur_cpu_spec->mmu_features &= ~MMU_FTR_GTSE;
  393. } else
  394. cur_cpu_spec->mmu_features |= MMU_FTR_GTSE;
  395. /* Do radix anyway - the hypervisor said we had to */
  396. cur_cpu_spec->mmu_features |= MMU_FTR_TYPE_RADIX;
  397. } else if (mmu_supported == OV5_FEAT(OV5_MMU_HASH)) {
  398. /* Hypervisor only supports hash - disable radix */
  399. cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
  400. cur_cpu_spec->mmu_features &= ~MMU_FTR_GTSE;
  401. }
  402. }
  403. static int __init dt_scan_mmu_pid_width(unsigned long node,
  404. const char *uname, int depth,
  405. void *data)
  406. {
  407. int size = 0;
  408. const __be32 *prop;
  409. const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  410. /* We are scanning "cpu" nodes only */
  411. if (type == NULL || strcmp(type, "cpu") != 0)
  412. return 0;
  413. /* Find MMU LPID, PID register size */
  414. prop = of_get_flat_dt_prop(node, "ibm,mmu-lpid-bits", &size);
  415. if (prop && size == 4)
  416. mmu_lpid_bits = be32_to_cpup(prop);
  417. prop = of_get_flat_dt_prop(node, "ibm,mmu-pid-bits", &size);
  418. if (prop && size == 4)
  419. mmu_pid_bits = be32_to_cpup(prop);
  420. if (!mmu_pid_bits && !mmu_lpid_bits)
  421. return 0;
  422. return 1;
  423. }
  424. /*
  425. * Outside hotplug the kernel uses this value to map the kernel direct map
  426. * with radix. To be compatible with older kernels, let's keep this value
  427. * as 16M which is also SECTION_SIZE with SPARSEMEM. We can ideally map
  428. * things with 1GB size in the case where we don't support hotplug.
  429. */
  430. #ifndef CONFIG_MEMORY_HOTPLUG
  431. #define DEFAULT_MEMORY_BLOCK_SIZE SZ_16M
  432. #else
  433. #define DEFAULT_MEMORY_BLOCK_SIZE MIN_MEMORY_BLOCK_SIZE
  434. #endif
  435. static void update_memory_block_size(unsigned long *block_size, unsigned long mem_size)
  436. {
  437. unsigned long min_memory_block_size = DEFAULT_MEMORY_BLOCK_SIZE;
  438. for (; *block_size > min_memory_block_size; *block_size >>= 2) {
  439. if ((mem_size & *block_size) == 0)
  440. break;
  441. }
  442. }
  443. static int __init probe_memory_block_size(unsigned long node, const char *uname, int
  444. depth, void *data)
  445. {
  446. const char *type;
  447. unsigned long *block_size = (unsigned long *)data;
  448. const __be32 *reg, *endp;
  449. int l;
  450. if (depth != 1)
  451. return 0;
  452. /*
  453. * If we have dynamic-reconfiguration-memory node, use the
  454. * lmb value.
  455. */
  456. if (strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
  457. const __be32 *prop;
  458. prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
  459. if (!prop || l < dt_root_size_cells * sizeof(__be32))
  460. /*
  461. * Nothing in the device tree
  462. */
  463. *block_size = DEFAULT_MEMORY_BLOCK_SIZE;
  464. else
  465. *block_size = of_read_number(prop, dt_root_size_cells);
  466. /*
  467. * We have found the final value. Don't probe further.
  468. */
  469. return 1;
  470. }
  471. /*
  472. * Find all the device tree nodes of memory type and make sure
  473. * the area can be mapped using the memory block size value
  474. * we end up using. We start with 1G value and keep reducing
  475. * it such that we can map the entire area using memory_block_size.
  476. * This will be used on powernv and older pseries that don't
  477. * have ibm,lmb-size node.
  478. * For ex: with P5 we can end up with
  479. * memory@0 -> 128MB
  480. * memory@128M -> 64M
  481. * This will end up using 64MB memory block size value.
  482. */
  483. type = of_get_flat_dt_prop(node, "device_type", NULL);
  484. if (type == NULL || strcmp(type, "memory") != 0)
  485. return 0;
  486. reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
  487. if (!reg)
  488. reg = of_get_flat_dt_prop(node, "reg", &l);
  489. if (!reg)
  490. return 0;
  491. endp = reg + (l / sizeof(__be32));
  492. while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
  493. const char *compatible;
  494. u64 size;
  495. dt_mem_next_cell(dt_root_addr_cells, &reg);
  496. size = dt_mem_next_cell(dt_root_size_cells, &reg);
  497. if (size) {
  498. update_memory_block_size(block_size, size);
  499. continue;
  500. }
  501. /*
  502. * ibm,coherent-device-memory with linux,usable-memory = 0
  503. * Force 256MiB block size. Work around for GPUs on P9 PowerNV
  504. * linux,usable-memory == 0 implies driver managed memory and
  505. * we can't use large memory block size due to hotplug/unplug
  506. * limitations.
  507. */
  508. compatible = of_get_flat_dt_prop(node, "compatible", NULL);
  509. if (compatible && !strcmp(compatible, "ibm,coherent-device-memory")) {
  510. if (*block_size > SZ_256M)
  511. *block_size = SZ_256M;
  512. /*
  513. * We keep 256M as the upper limit with GPU present.
  514. */
  515. return 0;
  516. }
  517. }
  518. /* continue looking for other memory device types */
  519. return 0;
  520. }
  521. /*
  522. * start with 1G memory block size. Early init will
  523. * fix this with correct value.
  524. */
  525. unsigned long memory_block_size __ro_after_init = 1UL << 30;
  526. static void __init early_init_memory_block_size(void)
  527. {
  528. /*
  529. * We need to do memory_block_size probe early so that
  530. * radix__early_init_mmu() can use this as limit for
  531. * mapping page size.
  532. */
  533. of_scan_flat_dt(probe_memory_block_size, &memory_block_size);
  534. }
  535. void __init mmu_early_init_devtree(void)
  536. {
  537. bool hvmode = !!(mfmsr() & MSR_HV);
  538. /* Disable radix mode based on kernel command line. */
  539. if (disable_radix) {
  540. if (IS_ENABLED(CONFIG_PPC_64S_HASH_MMU))
  541. cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
  542. else
  543. pr_warn("WARNING: Ignoring cmdline option disable_radix\n");
  544. }
  545. of_scan_flat_dt(dt_scan_mmu_pid_width, NULL);
  546. if (hvmode && !mmu_lpid_bits) {
  547. if (early_cpu_has_feature(CPU_FTR_ARCH_207S))
  548. mmu_lpid_bits = 12; /* POWER8-10 */
  549. else
  550. mmu_lpid_bits = 10; /* POWER7 */
  551. }
  552. if (!mmu_pid_bits) {
  553. if (early_cpu_has_feature(CPU_FTR_ARCH_300))
  554. mmu_pid_bits = 20; /* POWER9-10 */
  555. }
  556. /*
  557. * Check /chosen/ibm,architecture-vec-5 if running as a guest.
  558. * When running bare-metal, we can use radix if we like
  559. * even though the ibm,architecture-vec-5 property created by
  560. * skiboot doesn't have the necessary bits set.
  561. */
  562. if (!hvmode)
  563. early_check_vec5();
  564. early_init_memory_block_size();
  565. if (early_radix_enabled()) {
  566. radix__early_init_devtree();
  567. /*
  568. * We have finalized the translation we are going to use by now.
  569. * Radix mode is not limited by RMA / VRMA addressing.
  570. * Hence don't limit memblock allocations.
  571. */
  572. ppc64_rma_size = ULONG_MAX;
  573. memblock_set_current_limit(MEMBLOCK_ALLOC_ANYWHERE);
  574. } else
  575. hash__early_init_devtree();
  576. if (IS_ENABLED(CONFIG_HUGETLB_PAGE_SIZE_VARIABLE))
  577. hugetlbpage_init_defaultsize();
  578. if (!(cur_cpu_spec->mmu_features & MMU_FTR_HPTE_TABLE) &&
  579. !(cur_cpu_spec->mmu_features & MMU_FTR_TYPE_RADIX))
  580. panic("kernel does not support any MMU type offered by platform");
  581. }
  582. #endif /* CONFIG_PPC_BOOK3S_64 */