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