Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * PowerPC version |
| 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 4 | * |
| 5 | * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) |
| 6 | * and Cort Dougan (PReP) (cort@cs.nmt.edu) |
| 7 | * Copyright (C) 1996 Paul Mackerras |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 8 | * |
| 9 | * Derived from "arch/i386/mm/init.c" |
| 10 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds |
| 11 | * |
| 12 | * Dave Engebretsen <engebret@us.ibm.com> |
| 13 | * Rework for PPC64 port. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | * |
| 20 | */ |
| 21 | |
Benjamin Herrenschmidt | cec08e7 | 2008-04-30 15:41:48 +1000 | [diff] [blame] | 22 | #undef DEBUG |
| 23 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 24 | #include <linux/signal.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/mman.h> |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/swap.h> |
| 33 | #include <linux/stddef.h> |
| 34 | #include <linux/vmalloc.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/delay.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 37 | #include <linux/highmem.h> |
| 38 | #include <linux/idr.h> |
| 39 | #include <linux/nodemask.h> |
| 40 | #include <linux/module.h> |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 41 | #include <linux/poison.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 42 | #include <linux/memblock.h> |
David Gibson | a4fe3ce | 2009-10-26 19:24:31 +0000 | [diff] [blame] | 43 | #include <linux/hugetlb.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 45 | #include <linux/of_fdt.h> |
| 46 | #include <linux/libfdt.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 47 | |
| 48 | #include <asm/pgalloc.h> |
| 49 | #include <asm/page.h> |
| 50 | #include <asm/prom.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 51 | #include <asm/rtas.h> |
| 52 | #include <asm/io.h> |
| 53 | #include <asm/mmu_context.h> |
| 54 | #include <asm/pgtable.h> |
| 55 | #include <asm/mmu.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 56 | #include <linux/uaccess.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 57 | #include <asm/smp.h> |
| 58 | #include <asm/machdep.h> |
| 59 | #include <asm/tlb.h> |
| 60 | #include <asm/eeh.h> |
| 61 | #include <asm/processor.h> |
| 62 | #include <asm/mmzone.h> |
| 63 | #include <asm/cputable.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 64 | #include <asm/sections.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 65 | #include <asm/iommu.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 66 | #include <asm/vdso.h> |
David Gibson | 800fc3e | 2005-11-16 15:43:48 +1100 | [diff] [blame] | 67 | |
| 68 | #include "mmu_decl.h" |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 69 | |
Benjamin Herrenschmidt | 9449168 | 2009-06-02 21:17:45 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_PPC_STD_MMU_64 |
Aneesh Kumar K.V | dd1842a | 2016-04-29 23:25:49 +1000 | [diff] [blame] | 71 | #if H_PGTABLE_RANGE > USER_VSID_RANGE |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 72 | #warning Limited user VSID range means pagetable space is wasted |
| 73 | #endif |
Benjamin Herrenschmidt | 9449168 | 2009-06-02 21:17:45 +0000 | [diff] [blame] | 74 | #endif /* CONFIG_PPC_STD_MMU_64 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 75 | |
Kumar Gala | 37dd2ba | 2008-04-22 04:22:34 +1000 | [diff] [blame] | 76 | phys_addr_t memstart_addr = ~0; |
Sonny Rao | 79c3095 | 2010-08-19 18:08:09 +0000 | [diff] [blame] | 77 | EXPORT_SYMBOL_GPL(memstart_addr); |
Kumar Gala | 37dd2ba | 2008-04-22 04:22:34 +1000 | [diff] [blame] | 78 | phys_addr_t kernstart_addr; |
Sonny Rao | 79c3095 | 2010-08-19 18:08:09 +0000 | [diff] [blame] | 79 | EXPORT_SYMBOL_GPL(kernstart_addr); |
Kumar Gala | d7917ba | 2008-04-16 05:52:22 +1000 | [diff] [blame] | 80 | |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 81 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
| 82 | /* |
| 83 | * Given an address within the vmemmap, determine the pfn of the page that |
| 84 | * represents the start of the section it is within. Note that we have to |
| 85 | * do this by hand as the proffered address may not be correctly aligned. |
| 86 | * Subtraction of non-aligned pointers produces undefined results. |
| 87 | */ |
Michael Ellerman | 09de9ff | 2008-05-08 14:27:07 +1000 | [diff] [blame] | 88 | static unsigned long __meminit vmemmap_section_start(unsigned long page) |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 89 | { |
| 90 | unsigned long offset = page - ((unsigned long)(vmemmap)); |
| 91 | |
| 92 | /* Return the pfn of the start of the section. */ |
| 93 | return (offset / sizeof(struct page)) & PAGE_SECTION_MASK; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Check if this vmemmap page is already initialised. If any section |
| 98 | * which overlaps this vmemmap page is initialised then this page is |
| 99 | * initialised already. |
| 100 | */ |
Michael Ellerman | 09de9ff | 2008-05-08 14:27:07 +1000 | [diff] [blame] | 101 | static int __meminit vmemmap_populated(unsigned long start, int page_size) |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 102 | { |
| 103 | unsigned long end = start + page_size; |
Li Zhong | 16a05bf | 2014-06-11 16:23:39 +0800 | [diff] [blame] | 104 | start = (unsigned long)(pfn_to_page(vmemmap_section_start(start))); |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 105 | |
| 106 | for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page))) |
Li Zhong | 16a05bf | 2014-06-11 16:23:39 +0800 | [diff] [blame] | 107 | if (pfn_valid(page_to_pfn((struct page *)start))) |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 108 | return 1; |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Anshuman Khandual | 39e4675 | 2017-04-06 19:44:50 +0530 | [diff] [blame^] | 113 | /* |
| 114 | * vmemmap virtual address space management does not have a traditonal page |
| 115 | * table to track which virtual struct pages are backed by physical mapping. |
| 116 | * The virtual to physical mappings are tracked in a simple linked list |
| 117 | * format. 'vmemmap_list' maintains the entire vmemmap physical mapping at |
| 118 | * all times where as the 'next' list maintains the available |
| 119 | * vmemmap_backing structures which have been deleted from the |
| 120 | * 'vmemmap_global' list during system runtime (memory hotplug remove |
| 121 | * operation). The freed 'vmemmap_backing' structures are reused later when |
| 122 | * new requests come in without allocating fresh memory. This pointer also |
| 123 | * tracks the allocated 'vmemmap_backing' structures as we allocate one |
| 124 | * full page memory at a time when we dont have any. |
| 125 | */ |
Mark Nelson | 91eea67 | 2010-04-21 16:21:03 +0000 | [diff] [blame] | 126 | struct vmemmap_backing *vmemmap_list; |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 127 | static struct vmemmap_backing *next; |
Anshuman Khandual | 39e4675 | 2017-04-06 19:44:50 +0530 | [diff] [blame^] | 128 | |
| 129 | /* |
| 130 | * The same pointer 'next' tracks individual chunks inside the allocated |
| 131 | * full page during the boot time and again tracks the freeed nodes during |
| 132 | * runtime. It is racy but it does not happen as they are separated by the |
| 133 | * boot process. Will create problem if some how we have memory hotplug |
| 134 | * operation during boot !! |
| 135 | */ |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 136 | static int num_left; |
| 137 | static int num_freed; |
Mark Nelson | 91eea67 | 2010-04-21 16:21:03 +0000 | [diff] [blame] | 138 | |
| 139 | static __meminit struct vmemmap_backing * vmemmap_list_alloc(int node) |
| 140 | { |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 141 | struct vmemmap_backing *vmem_back; |
| 142 | /* get from freed entries first */ |
| 143 | if (num_freed) { |
| 144 | num_freed--; |
| 145 | vmem_back = next; |
| 146 | next = next->list; |
| 147 | |
| 148 | return vmem_back; |
| 149 | } |
Mark Nelson | 91eea67 | 2010-04-21 16:21:03 +0000 | [diff] [blame] | 150 | |
| 151 | /* allocate a page when required and hand out chunks */ |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 152 | if (!num_left) { |
Mark Nelson | 91eea67 | 2010-04-21 16:21:03 +0000 | [diff] [blame] | 153 | next = vmemmap_alloc_block(PAGE_SIZE, node); |
| 154 | if (unlikely(!next)) { |
| 155 | WARN_ON(1); |
| 156 | return NULL; |
| 157 | } |
| 158 | num_left = PAGE_SIZE / sizeof(struct vmemmap_backing); |
| 159 | } |
| 160 | |
| 161 | num_left--; |
| 162 | |
| 163 | return next++; |
| 164 | } |
| 165 | |
| 166 | static __meminit void vmemmap_list_populate(unsigned long phys, |
| 167 | unsigned long start, |
| 168 | int node) |
| 169 | { |
| 170 | struct vmemmap_backing *vmem_back; |
| 171 | |
| 172 | vmem_back = vmemmap_list_alloc(node); |
| 173 | if (unlikely(!vmem_back)) { |
| 174 | WARN_ON(1); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | vmem_back->phys = phys; |
| 179 | vmem_back->virt_addr = start; |
| 180 | vmem_back->list = vmemmap_list; |
| 181 | |
| 182 | vmemmap_list = vmem_back; |
| 183 | } |
| 184 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 185 | int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node) |
| 186 | { |
| 187 | unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift; |
| 188 | |
| 189 | /* Align to the page size of the linear mapping. */ |
| 190 | start = _ALIGN_DOWN(start, page_size); |
| 191 | |
| 192 | pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node); |
| 193 | |
| 194 | for (; start < end; start += page_size) { |
| 195 | void *p; |
David Gibson | 1dace6c | 2016-02-09 13:32:42 +1000 | [diff] [blame] | 196 | int rc; |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 197 | |
| 198 | if (vmemmap_populated(start, page_size)) |
| 199 | continue; |
| 200 | |
| 201 | p = vmemmap_alloc_block(page_size, node); |
| 202 | if (!p) |
| 203 | return -ENOMEM; |
| 204 | |
| 205 | vmemmap_list_populate(__pa(p), start, node); |
| 206 | |
| 207 | pr_debug(" * %016lx..%016lx allocated at %p\n", |
| 208 | start, start + page_size, p); |
| 209 | |
David Gibson | 1dace6c | 2016-02-09 13:32:42 +1000 | [diff] [blame] | 210 | rc = vmemmap_create_mapping(start, page_size, __pa(p)); |
| 211 | if (rc < 0) { |
| 212 | pr_warning( |
| 213 | "vmemmap_populate: Unable to create vmemmap mapping: %d\n", |
| 214 | rc); |
| 215 | return -EFAULT; |
| 216 | } |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | #ifdef CONFIG_MEMORY_HOTPLUG |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 223 | static unsigned long vmemmap_list_free(unsigned long start) |
| 224 | { |
| 225 | struct vmemmap_backing *vmem_back, *vmem_back_prev; |
| 226 | |
| 227 | vmem_back_prev = vmem_back = vmemmap_list; |
| 228 | |
| 229 | /* look for it with prev pointer recorded */ |
| 230 | for (; vmem_back; vmem_back = vmem_back->list) { |
| 231 | if (vmem_back->virt_addr == start) |
| 232 | break; |
| 233 | vmem_back_prev = vmem_back; |
| 234 | } |
| 235 | |
| 236 | if (unlikely(!vmem_back)) { |
| 237 | WARN_ON(1); |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /* remove it from vmemmap_list */ |
| 242 | if (vmem_back == vmemmap_list) /* remove head */ |
| 243 | vmemmap_list = vmem_back->list; |
| 244 | else |
| 245 | vmem_back_prev->list = vmem_back->list; |
| 246 | |
| 247 | /* next point to this freed entry */ |
| 248 | vmem_back->list = next; |
| 249 | next = vmem_back; |
| 250 | num_freed++; |
| 251 | |
| 252 | return vmem_back->phys; |
| 253 | } |
| 254 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 255 | void __ref vmemmap_free(unsigned long start, unsigned long end) |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 256 | { |
Benjamin Herrenschmidt | cec08e7 | 2008-04-30 15:41:48 +1000 | [diff] [blame] | 257 | unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift; |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 258 | |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 259 | start = _ALIGN_DOWN(start, page_size); |
| 260 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 261 | pr_debug("vmemmap_free %lx...%lx\n", start, end); |
Benjamin Herrenschmidt | 32a7494 | 2009-07-23 23:15:58 +0000 | [diff] [blame] | 262 | |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 263 | for (; start < end; start += page_size) { |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 264 | unsigned long addr; |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 265 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 266 | /* |
| 267 | * the section has already be marked as invalid, so |
| 268 | * vmemmap_populated() true means some other sections still |
| 269 | * in this page, so skip it. |
| 270 | */ |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 271 | if (vmemmap_populated(start, page_size)) |
| 272 | continue; |
| 273 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 274 | addr = vmemmap_list_free(start); |
| 275 | if (addr) { |
| 276 | struct page *page = pfn_to_page(addr >> PAGE_SHIFT); |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 277 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 278 | if (PageReserved(page)) { |
| 279 | /* allocated from bootmem */ |
| 280 | if (page_size < PAGE_SIZE) { |
| 281 | /* |
| 282 | * this shouldn't happen, but if it is |
| 283 | * the case, leave the memory there |
| 284 | */ |
| 285 | WARN_ON_ONCE(1); |
| 286 | } else { |
| 287 | unsigned int nr_pages = |
| 288 | 1 << get_order(page_size); |
| 289 | while (nr_pages--) |
| 290 | free_reserved_page(page++); |
| 291 | } |
| 292 | } else |
| 293 | free_pages((unsigned long)(__va(addr)), |
| 294 | get_order(page_size)); |
Mark Nelson | 91eea67 | 2010-04-21 16:21:03 +0000 | [diff] [blame] | 295 | |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 296 | vmemmap_remove_mapping(start, page_size); |
| 297 | } |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 298 | } |
Andy Whitcroft | d29eff7bc | 2007-10-16 01:24:17 -0700 | [diff] [blame] | 299 | } |
Li Zhong | 71b0bfe | 2014-06-11 16:23:38 +0800 | [diff] [blame] | 300 | #endif |
Nathan Fontenot | f7e3334 | 2013-09-27 10:18:09 -0500 | [diff] [blame] | 301 | void register_page_bootmem_memmap(unsigned long section_nr, |
| 302 | struct page *start_page, unsigned long size) |
| 303 | { |
| 304 | } |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 305 | |
Alexey Kardashevskiy | 8e0861fa | 2013-08-28 18:37:42 +1000 | [diff] [blame] | 306 | /* |
| 307 | * We do not have access to the sparsemem vmemmap, so we fallback to |
| 308 | * walking the list of sparsemem blocks which we already maintain for |
| 309 | * the sake of crashdump. In the long run, we might want to maintain |
| 310 | * a tree if performance of that linear walk becomes a problem. |
| 311 | * |
| 312 | * realmode_pfn_to_page functions can fail due to: |
| 313 | * 1) As real sparsemem blocks do not lay in RAM continously (they |
| 314 | * are in virtual address space which is not available in the real mode), |
| 315 | * the requested page struct can be split between blocks so get_page/put_page |
| 316 | * may fail. |
| 317 | * 2) When huge pages are used, the get_page/put_page API will fail |
| 318 | * in real mode as the linked addresses in the page struct are virtual |
| 319 | * too. |
| 320 | */ |
| 321 | struct page *realmode_pfn_to_page(unsigned long pfn) |
| 322 | { |
| 323 | struct vmemmap_backing *vmem_back; |
| 324 | struct page *page; |
| 325 | unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift; |
| 326 | unsigned long pg_va = (unsigned long) pfn_to_page(pfn); |
| 327 | |
| 328 | for (vmem_back = vmemmap_list; vmem_back; vmem_back = vmem_back->list) { |
| 329 | if (pg_va < vmem_back->virt_addr) |
| 330 | continue; |
| 331 | |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 332 | /* After vmemmap_list entry free is possible, need check all */ |
| 333 | if ((pg_va + sizeof(struct page)) <= |
| 334 | (vmem_back->virt_addr + page_size)) { |
| 335 | page = (struct page *) (vmem_back->phys + pg_va - |
Alexey Kardashevskiy | 8e0861fa | 2013-08-28 18:37:42 +1000 | [diff] [blame] | 336 | vmem_back->virt_addr); |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 337 | return page; |
| 338 | } |
Alexey Kardashevskiy | 8e0861fa | 2013-08-28 18:37:42 +1000 | [diff] [blame] | 339 | } |
| 340 | |
Li Zhong | bd8cb03 | 2014-06-11 16:23:36 +0800 | [diff] [blame] | 341 | /* Probably that page struct is split between real pages */ |
Alexey Kardashevskiy | 8e0861fa | 2013-08-28 18:37:42 +1000 | [diff] [blame] | 342 | return NULL; |
| 343 | } |
| 344 | EXPORT_SYMBOL_GPL(realmode_pfn_to_page); |
| 345 | |
| 346 | #elif defined(CONFIG_FLATMEM) |
| 347 | |
| 348 | struct page *realmode_pfn_to_page(unsigned long pfn) |
| 349 | { |
| 350 | struct page *page = pfn_to_page(pfn); |
| 351 | return page; |
| 352 | } |
| 353 | EXPORT_SYMBOL_GPL(realmode_pfn_to_page); |
| 354 | |
| 355 | #endif /* CONFIG_SPARSEMEM_VMEMMAP/CONFIG_FLATMEM */ |
Michael Ellerman | 1a01dc8 | 2016-07-26 20:09:30 +1000 | [diff] [blame] | 356 | |
| 357 | #ifdef CONFIG_PPC_STD_MMU_64 |
Michael Ellerman | c610ec6 | 2016-07-26 21:29:30 +1000 | [diff] [blame] | 358 | static bool disable_radix; |
| 359 | static int __init parse_disable_radix(char *p) |
| 360 | { |
| 361 | disable_radix = true; |
| 362 | return 0; |
| 363 | } |
| 364 | early_param("disable_radix", parse_disable_radix); |
| 365 | |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 366 | /* |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 367 | * If we're running under a hypervisor, we need to check the contents of |
| 368 | * /chosen/ibm,architecture-vec-5 to see if the hypervisor is willing to do |
| 369 | * radix. If not, we clear the radix feature bit so we fall back to hash. |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 370 | */ |
| 371 | static void early_check_vec5(void) |
| 372 | { |
| 373 | unsigned long root, chosen; |
| 374 | int size; |
| 375 | const u8 *vec5; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 376 | u8 mmu_supported; |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 377 | |
| 378 | root = of_get_flat_dt_root(); |
| 379 | chosen = of_get_flat_dt_subnode_by_name(root, "chosen"); |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 380 | if (chosen == -FDT_ERR_NOTFOUND) { |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 381 | cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 382 | return; |
| 383 | } |
| 384 | vec5 = of_get_flat_dt_prop(chosen, "ibm,architecture-vec-5", &size); |
| 385 | if (!vec5) { |
| 386 | cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; |
| 387 | return; |
| 388 | } |
| 389 | if (size <= OV5_INDX(OV5_MMU_SUPPORT)) { |
| 390 | cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | /* Check for supported configuration */ |
| 395 | mmu_supported = vec5[OV5_INDX(OV5_MMU_SUPPORT)] & |
| 396 | OV5_FEAT(OV5_MMU_SUPPORT); |
| 397 | if (mmu_supported == OV5_FEAT(OV5_MMU_RADIX)) { |
| 398 | /* Hypervisor only supports radix - check enabled && GTSE */ |
| 399 | if (!early_radix_enabled()) { |
| 400 | pr_warn("WARNING: Ignoring cmdline option disable_radix\n"); |
| 401 | } |
| 402 | if (!(vec5[OV5_INDX(OV5_RADIX_GTSE)] & |
| 403 | OV5_FEAT(OV5_RADIX_GTSE))) { |
| 404 | pr_warn("WARNING: Hypervisor doesn't support RADIX with GTSE\n"); |
| 405 | } |
| 406 | /* Do radix anyway - the hypervisor said we had to */ |
| 407 | cur_cpu_spec->mmu_features |= MMU_FTR_TYPE_RADIX; |
| 408 | } else if (mmu_supported == OV5_FEAT(OV5_MMU_HASH)) { |
| 409 | /* Hypervisor only supports hash - disable radix */ |
| 410 | cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; |
| 411 | } |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 412 | } |
| 413 | |
Michael Ellerman | 1a01dc8 | 2016-07-26 20:09:30 +1000 | [diff] [blame] | 414 | void __init mmu_early_init_devtree(void) |
| 415 | { |
Michael Ellerman | c610ec6 | 2016-07-26 21:29:30 +1000 | [diff] [blame] | 416 | /* Disable radix mode based on kernel command line. */ |
Paul Mackerras | fc36a90 | 2017-03-21 12:38:02 +1100 | [diff] [blame] | 417 | if (disable_radix) |
Aneesh Kumar K.V | 5a25b6f | 2016-07-27 13:19:01 +1000 | [diff] [blame] | 418 | cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; |
Michael Ellerman | bacf9cf | 2016-07-26 21:31:59 +1000 | [diff] [blame] | 419 | |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 420 | /* |
| 421 | * Check /chosen/ibm,architecture-vec-5 if running as a guest. |
| 422 | * When running bare-metal, we can use radix if we like |
| 423 | * even though the ibm,architecture-vec-5 property created by |
| 424 | * skiboot doesn't have the necessary bits set. |
| 425 | */ |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 426 | if (!(mfmsr() & MSR_HV)) |
Paul Mackerras | 18569c1 | 2017-01-30 21:21:34 +1100 | [diff] [blame] | 427 | early_check_vec5(); |
| 428 | |
Aneesh Kumar K.V | b8f1b4f | 2016-07-23 14:42:35 +0530 | [diff] [blame] | 429 | if (early_radix_enabled()) |
Michael Ellerman | 2537b09 | 2016-07-26 21:55:27 +1000 | [diff] [blame] | 430 | radix__early_init_devtree(); |
| 431 | else |
Michael Ellerman | bacf9cf | 2016-07-26 21:31:59 +1000 | [diff] [blame] | 432 | hash__early_init_devtree(); |
Michael Ellerman | 1a01dc8 | 2016-07-26 20:09:30 +1000 | [diff] [blame] | 433 | } |
| 434 | #endif /* CONFIG_PPC_STD_MMU_64 */ |