init_64.c 19 KB

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