170d64ceaSPaul Mackerras /* 270d64ceaSPaul Mackerras * PowerPC version 370d64ceaSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 470d64ceaSPaul Mackerras * 570d64ceaSPaul Mackerras * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) 670d64ceaSPaul Mackerras * and Cort Dougan (PReP) (cort@cs.nmt.edu) 770d64ceaSPaul Mackerras * Copyright (C) 1996 Paul Mackerras 870d64ceaSPaul Mackerras * 970d64ceaSPaul Mackerras * Derived from "arch/i386/mm/init.c" 1070d64ceaSPaul Mackerras * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds 1170d64ceaSPaul Mackerras * 1270d64ceaSPaul Mackerras * Dave Engebretsen <engebret@us.ibm.com> 1370d64ceaSPaul Mackerras * Rework for PPC64 port. 1470d64ceaSPaul Mackerras * 1570d64ceaSPaul Mackerras * This program is free software; you can redistribute it and/or 1670d64ceaSPaul Mackerras * modify it under the terms of the GNU General Public License 1770d64ceaSPaul Mackerras * as published by the Free Software Foundation; either version 1870d64ceaSPaul Mackerras * 2 of the License, or (at your option) any later version. 1970d64ceaSPaul Mackerras * 2070d64ceaSPaul Mackerras */ 2170d64ceaSPaul Mackerras 22cec08e7aSBenjamin Herrenschmidt #undef DEBUG 23cec08e7aSBenjamin Herrenschmidt 2470d64ceaSPaul Mackerras #include <linux/signal.h> 2570d64ceaSPaul Mackerras #include <linux/sched.h> 2670d64ceaSPaul Mackerras #include <linux/kernel.h> 2770d64ceaSPaul Mackerras #include <linux/errno.h> 2870d64ceaSPaul Mackerras #include <linux/string.h> 2970d64ceaSPaul Mackerras #include <linux/types.h> 3070d64ceaSPaul Mackerras #include <linux/mman.h> 3170d64ceaSPaul Mackerras #include <linux/mm.h> 3270d64ceaSPaul Mackerras #include <linux/swap.h> 3370d64ceaSPaul Mackerras #include <linux/stddef.h> 3470d64ceaSPaul Mackerras #include <linux/vmalloc.h> 3570d64ceaSPaul Mackerras #include <linux/init.h> 3670d64ceaSPaul Mackerras #include <linux/delay.h> 3770d64ceaSPaul Mackerras #include <linux/highmem.h> 3870d64ceaSPaul Mackerras #include <linux/idr.h> 3970d64ceaSPaul Mackerras #include <linux/nodemask.h> 4070d64ceaSPaul Mackerras #include <linux/module.h> 41c9cf5528SRandy Dunlap #include <linux/poison.h> 4295f72d1eSYinghai Lu #include <linux/memblock.h> 43a4fe3ce7SDavid Gibson #include <linux/hugetlb.h> 445a0e3ad6STejun Heo #include <linux/slab.h> 4570d64ceaSPaul Mackerras 4670d64ceaSPaul Mackerras #include <asm/pgalloc.h> 4770d64ceaSPaul Mackerras #include <asm/page.h> 4870d64ceaSPaul Mackerras #include <asm/prom.h> 4970d64ceaSPaul Mackerras #include <asm/rtas.h> 5070d64ceaSPaul Mackerras #include <asm/io.h> 5170d64ceaSPaul Mackerras #include <asm/mmu_context.h> 5270d64ceaSPaul Mackerras #include <asm/pgtable.h> 5370d64ceaSPaul Mackerras #include <asm/mmu.h> 5470d64ceaSPaul Mackerras #include <asm/uaccess.h> 5570d64ceaSPaul Mackerras #include <asm/smp.h> 5670d64ceaSPaul Mackerras #include <asm/machdep.h> 5770d64ceaSPaul Mackerras #include <asm/tlb.h> 5870d64ceaSPaul Mackerras #include <asm/eeh.h> 5970d64ceaSPaul Mackerras #include <asm/processor.h> 6070d64ceaSPaul Mackerras #include <asm/mmzone.h> 6170d64ceaSPaul Mackerras #include <asm/cputable.h> 6270d64ceaSPaul Mackerras #include <asm/sections.h> 6370d64ceaSPaul Mackerras #include <asm/iommu.h> 6470d64ceaSPaul Mackerras #include <asm/vdso.h> 65800fc3eeSDavid Gibson 66800fc3eeSDavid Gibson #include "mmu_decl.h" 6770d64ceaSPaul Mackerras 6894491685SBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64 69dd1842a2SAneesh Kumar K.V #if H_PGTABLE_RANGE > USER_VSID_RANGE 7070d64ceaSPaul Mackerras #warning Limited user VSID range means pagetable space is wasted 7170d64ceaSPaul Mackerras #endif 7270d64ceaSPaul Mackerras 73dd1842a2SAneesh Kumar K.V #if (TASK_SIZE_USER64 < H_PGTABLE_RANGE) && (TASK_SIZE_USER64 < USER_VSID_RANGE) 7470d64ceaSPaul Mackerras #warning TASK_SIZE is smaller than it needs to be. 7570d64ceaSPaul Mackerras #endif 7694491685SBenjamin Herrenschmidt #endif /* CONFIG_PPC_STD_MMU_64 */ 7770d64ceaSPaul Mackerras 7837dd2badSKumar Gala phys_addr_t memstart_addr = ~0; 7979c3095fSSonny Rao EXPORT_SYMBOL_GPL(memstart_addr); 8037dd2badSKumar Gala phys_addr_t kernstart_addr; 8179c3095fSSonny Rao EXPORT_SYMBOL_GPL(kernstart_addr); 82d7917ba7SKumar Gala 8351cc5068SAlexey Dobriyan static void pgd_ctor(void *addr) 8470d64ceaSPaul Mackerras { 8551cc5068SAlexey Dobriyan memset(addr, 0, PGD_TABLE_SIZE); 8651cc5068SAlexey Dobriyan } 8751cc5068SAlexey Dobriyan 88368ced78SAneesh Kumar K.V static void pud_ctor(void *addr) 89368ced78SAneesh Kumar K.V { 90368ced78SAneesh Kumar K.V memset(addr, 0, PUD_TABLE_SIZE); 91368ced78SAneesh Kumar K.V } 92368ced78SAneesh Kumar K.V 9351cc5068SAlexey Dobriyan static void pmd_ctor(void *addr) 9451cc5068SAlexey Dobriyan { 9551cc5068SAlexey Dobriyan memset(addr, 0, PMD_TABLE_SIZE); 9670d64ceaSPaul Mackerras } 9770d64ceaSPaul Mackerras 98a0668cdcSDavid Gibson struct kmem_cache *pgtable_cache[MAX_PGTABLE_INDEX_SIZE]; 9970d64ceaSPaul Mackerras 100a0668cdcSDavid Gibson /* 101a0668cdcSDavid Gibson * Create a kmem_cache() for pagetables. This is not used for PTE 102a0668cdcSDavid Gibson * pages - they're linked to struct page, come from the normal free 103a0668cdcSDavid Gibson * pages pool and have a different entry size (see real_pte_t) to 104a0668cdcSDavid Gibson * everything else. Caches created by this function are used for all 105a0668cdcSDavid Gibson * the higher level pagetables, and for hugepage pagetables. 106a0668cdcSDavid Gibson */ 107a0668cdcSDavid Gibson void pgtable_cache_add(unsigned shift, void (*ctor)(void *)) 108a0668cdcSDavid Gibson { 109a0668cdcSDavid Gibson char *name; 110a0668cdcSDavid Gibson unsigned long table_size = sizeof(void *) << shift; 111a0668cdcSDavid Gibson unsigned long align = table_size; 112a0668cdcSDavid Gibson 113a0668cdcSDavid Gibson /* When batching pgtable pointers for RCU freeing, we store 114a0668cdcSDavid Gibson * the index size in the low bits. Table alignment must be 115a4fe3ce7SDavid Gibson * big enough to fit it. 116a4fe3ce7SDavid Gibson * 117a4fe3ce7SDavid Gibson * Likewise, hugeapge pagetable pointers contain a (different) 118a4fe3ce7SDavid Gibson * shift value in the low bits. All tables must be aligned so 119a4fe3ce7SDavid Gibson * as to leave enough 0 bits in the address to contain it. */ 120a4fe3ce7SDavid Gibson unsigned long minalign = max(MAX_PGTABLE_INDEX_SIZE + 1, 121a4fe3ce7SDavid Gibson HUGEPD_SHIFT_MASK + 1); 122a0668cdcSDavid Gibson struct kmem_cache *new; 123a0668cdcSDavid Gibson 124a0668cdcSDavid Gibson /* It would be nice if this was a BUILD_BUG_ON(), but at the 125a0668cdcSDavid Gibson * moment, gcc doesn't seem to recognize is_power_of_2 as a 126a0668cdcSDavid Gibson * constant expression, so so much for that. */ 127a0668cdcSDavid Gibson BUG_ON(!is_power_of_2(minalign)); 128a0668cdcSDavid Gibson BUG_ON((shift < 1) || (shift > MAX_PGTABLE_INDEX_SIZE)); 129a0668cdcSDavid Gibson 130a0668cdcSDavid Gibson if (PGT_CACHE(shift)) 131a0668cdcSDavid Gibson return; /* Already have a cache of this size */ 132a0668cdcSDavid Gibson 133a0668cdcSDavid Gibson align = max_t(unsigned long, align, minalign); 134a0668cdcSDavid Gibson name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift); 135a0668cdcSDavid Gibson new = kmem_cache_create(name, table_size, align, 0, ctor); 136e77553cbSYanjiang Jin kfree(name); 137cf9427b8SAneesh Kumar K.V pgtable_cache[shift - 1] = new; 138a0668cdcSDavid Gibson pr_debug("Allocated pgtable cache for order %d\n", shift); 139a0668cdcSDavid Gibson } 140a0668cdcSDavid Gibson 14170d64ceaSPaul Mackerras 14270d64ceaSPaul Mackerras void pgtable_cache_init(void) 14370d64ceaSPaul Mackerras { 144a0668cdcSDavid Gibson pgtable_cache_add(PGD_INDEX_SIZE, pgd_ctor); 145f940f528SAneesh Kumar K.V pgtable_cache_add(PMD_CACHE_INDEX, pmd_ctor); 146368ced78SAneesh Kumar K.V /* 147368ced78SAneesh Kumar K.V * In all current configs, when the PUD index exists it's the 148368ced78SAneesh Kumar K.V * same size as either the pgd or pmd index except with THP enabled 149368ced78SAneesh Kumar K.V * on book3s 64 150368ced78SAneesh Kumar K.V */ 151368ced78SAneesh Kumar K.V if (PUD_INDEX_SIZE && !PGT_CACHE(PUD_INDEX_SIZE)) 152368ced78SAneesh Kumar K.V pgtable_cache_add(PUD_INDEX_SIZE, pud_ctor); 153368ced78SAneesh Kumar K.V 154f940f528SAneesh Kumar K.V if (!PGT_CACHE(PGD_INDEX_SIZE) || !PGT_CACHE(PMD_CACHE_INDEX)) 155a0668cdcSDavid Gibson panic("Couldn't allocate pgtable caches"); 156368ced78SAneesh Kumar K.V if (PUD_INDEX_SIZE && !PGT_CACHE(PUD_INDEX_SIZE)) 157368ced78SAneesh Kumar K.V panic("Couldn't allocate pud pgtable caches"); 15870d64ceaSPaul Mackerras } 159d29eff7bSAndy Whitcroft 160d29eff7bSAndy Whitcroft #ifdef CONFIG_SPARSEMEM_VMEMMAP 161d29eff7bSAndy Whitcroft /* 162d29eff7bSAndy Whitcroft * Given an address within the vmemmap, determine the pfn of the page that 163d29eff7bSAndy Whitcroft * represents the start of the section it is within. Note that we have to 164d29eff7bSAndy Whitcroft * do this by hand as the proffered address may not be correctly aligned. 165d29eff7bSAndy Whitcroft * Subtraction of non-aligned pointers produces undefined results. 166d29eff7bSAndy Whitcroft */ 16709de9ff8SMichael Ellerman static unsigned long __meminit vmemmap_section_start(unsigned long page) 168d29eff7bSAndy Whitcroft { 169d29eff7bSAndy Whitcroft unsigned long offset = page - ((unsigned long)(vmemmap)); 170d29eff7bSAndy Whitcroft 171d29eff7bSAndy Whitcroft /* Return the pfn of the start of the section. */ 172d29eff7bSAndy Whitcroft return (offset / sizeof(struct page)) & PAGE_SECTION_MASK; 173d29eff7bSAndy Whitcroft } 174d29eff7bSAndy Whitcroft 175d29eff7bSAndy Whitcroft /* 176d29eff7bSAndy Whitcroft * Check if this vmemmap page is already initialised. If any section 177d29eff7bSAndy Whitcroft * which overlaps this vmemmap page is initialised then this page is 178d29eff7bSAndy Whitcroft * initialised already. 179d29eff7bSAndy Whitcroft */ 18009de9ff8SMichael Ellerman static int __meminit vmemmap_populated(unsigned long start, int page_size) 181d29eff7bSAndy Whitcroft { 182d29eff7bSAndy Whitcroft unsigned long end = start + page_size; 18316a05bffSLi Zhong start = (unsigned long)(pfn_to_page(vmemmap_section_start(start))); 184d29eff7bSAndy Whitcroft 185d29eff7bSAndy Whitcroft for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page))) 18616a05bffSLi Zhong if (pfn_valid(page_to_pfn((struct page *)start))) 187d29eff7bSAndy Whitcroft return 1; 188d29eff7bSAndy Whitcroft 189d29eff7bSAndy Whitcroft return 0; 190d29eff7bSAndy Whitcroft } 191d29eff7bSAndy Whitcroft 19291eea67cSMark Nelson struct vmemmap_backing *vmemmap_list; 193bd8cb03dSLi Zhong static struct vmemmap_backing *next; 194bd8cb03dSLi Zhong static int num_left; 195bd8cb03dSLi Zhong static int num_freed; 19691eea67cSMark Nelson 19791eea67cSMark Nelson static __meminit struct vmemmap_backing * vmemmap_list_alloc(int node) 19891eea67cSMark Nelson { 199bd8cb03dSLi Zhong struct vmemmap_backing *vmem_back; 200bd8cb03dSLi Zhong /* get from freed entries first */ 201bd8cb03dSLi Zhong if (num_freed) { 202bd8cb03dSLi Zhong num_freed--; 203bd8cb03dSLi Zhong vmem_back = next; 204bd8cb03dSLi Zhong next = next->list; 205bd8cb03dSLi Zhong 206bd8cb03dSLi Zhong return vmem_back; 207bd8cb03dSLi Zhong } 20891eea67cSMark Nelson 20991eea67cSMark Nelson /* allocate a page when required and hand out chunks */ 210bd8cb03dSLi Zhong if (!num_left) { 21191eea67cSMark Nelson next = vmemmap_alloc_block(PAGE_SIZE, node); 21291eea67cSMark Nelson if (unlikely(!next)) { 21391eea67cSMark Nelson WARN_ON(1); 21491eea67cSMark Nelson return NULL; 21591eea67cSMark Nelson } 21691eea67cSMark Nelson num_left = PAGE_SIZE / sizeof(struct vmemmap_backing); 21791eea67cSMark Nelson } 21891eea67cSMark Nelson 21991eea67cSMark Nelson num_left--; 22091eea67cSMark Nelson 22191eea67cSMark Nelson return next++; 22291eea67cSMark Nelson } 22391eea67cSMark Nelson 22491eea67cSMark Nelson static __meminit void vmemmap_list_populate(unsigned long phys, 22591eea67cSMark Nelson unsigned long start, 22691eea67cSMark Nelson int node) 22791eea67cSMark Nelson { 22891eea67cSMark Nelson struct vmemmap_backing *vmem_back; 22991eea67cSMark Nelson 23091eea67cSMark Nelson vmem_back = vmemmap_list_alloc(node); 23191eea67cSMark Nelson if (unlikely(!vmem_back)) { 23291eea67cSMark Nelson WARN_ON(1); 23391eea67cSMark Nelson return; 23491eea67cSMark Nelson } 23591eea67cSMark Nelson 23691eea67cSMark Nelson vmem_back->phys = phys; 23791eea67cSMark Nelson vmem_back->virt_addr = start; 23891eea67cSMark Nelson vmem_back->list = vmemmap_list; 23991eea67cSMark Nelson 24091eea67cSMark Nelson vmemmap_list = vmem_back; 24191eea67cSMark Nelson } 24291eea67cSMark Nelson 24371b0bfe4SLi Zhong int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node) 24471b0bfe4SLi Zhong { 24571b0bfe4SLi Zhong unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift; 24671b0bfe4SLi Zhong 24771b0bfe4SLi Zhong /* Align to the page size of the linear mapping. */ 24871b0bfe4SLi Zhong start = _ALIGN_DOWN(start, page_size); 24971b0bfe4SLi Zhong 25071b0bfe4SLi Zhong pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node); 25171b0bfe4SLi Zhong 25271b0bfe4SLi Zhong for (; start < end; start += page_size) { 25371b0bfe4SLi Zhong void *p; 2541dace6c6SDavid Gibson int rc; 25571b0bfe4SLi Zhong 25671b0bfe4SLi Zhong if (vmemmap_populated(start, page_size)) 25771b0bfe4SLi Zhong continue; 25871b0bfe4SLi Zhong 25971b0bfe4SLi Zhong p = vmemmap_alloc_block(page_size, node); 26071b0bfe4SLi Zhong if (!p) 26171b0bfe4SLi Zhong return -ENOMEM; 26271b0bfe4SLi Zhong 26371b0bfe4SLi Zhong vmemmap_list_populate(__pa(p), start, node); 26471b0bfe4SLi Zhong 26571b0bfe4SLi Zhong pr_debug(" * %016lx..%016lx allocated at %p\n", 26671b0bfe4SLi Zhong start, start + page_size, p); 26771b0bfe4SLi Zhong 2681dace6c6SDavid Gibson rc = vmemmap_create_mapping(start, page_size, __pa(p)); 2691dace6c6SDavid Gibson if (rc < 0) { 2701dace6c6SDavid Gibson pr_warning( 2711dace6c6SDavid Gibson "vmemmap_populate: Unable to create vmemmap mapping: %d\n", 2721dace6c6SDavid Gibson rc); 2731dace6c6SDavid Gibson return -EFAULT; 2741dace6c6SDavid Gibson } 27571b0bfe4SLi Zhong } 27671b0bfe4SLi Zhong 27771b0bfe4SLi Zhong return 0; 27871b0bfe4SLi Zhong } 27971b0bfe4SLi Zhong 28071b0bfe4SLi Zhong #ifdef CONFIG_MEMORY_HOTPLUG 281bd8cb03dSLi Zhong static unsigned long vmemmap_list_free(unsigned long start) 282bd8cb03dSLi Zhong { 283bd8cb03dSLi Zhong struct vmemmap_backing *vmem_back, *vmem_back_prev; 284bd8cb03dSLi Zhong 285bd8cb03dSLi Zhong vmem_back_prev = vmem_back = vmemmap_list; 286bd8cb03dSLi Zhong 287bd8cb03dSLi Zhong /* look for it with prev pointer recorded */ 288bd8cb03dSLi Zhong for (; vmem_back; vmem_back = vmem_back->list) { 289bd8cb03dSLi Zhong if (vmem_back->virt_addr == start) 290bd8cb03dSLi Zhong break; 291bd8cb03dSLi Zhong vmem_back_prev = vmem_back; 292bd8cb03dSLi Zhong } 293bd8cb03dSLi Zhong 294bd8cb03dSLi Zhong if (unlikely(!vmem_back)) { 295bd8cb03dSLi Zhong WARN_ON(1); 296bd8cb03dSLi Zhong return 0; 297bd8cb03dSLi Zhong } 298bd8cb03dSLi Zhong 299bd8cb03dSLi Zhong /* remove it from vmemmap_list */ 300bd8cb03dSLi Zhong if (vmem_back == vmemmap_list) /* remove head */ 301bd8cb03dSLi Zhong vmemmap_list = vmem_back->list; 302bd8cb03dSLi Zhong else 303bd8cb03dSLi Zhong vmem_back_prev->list = vmem_back->list; 304bd8cb03dSLi Zhong 305bd8cb03dSLi Zhong /* next point to this freed entry */ 306bd8cb03dSLi Zhong vmem_back->list = next; 307bd8cb03dSLi Zhong next = vmem_back; 308bd8cb03dSLi Zhong num_freed++; 309bd8cb03dSLi Zhong 310bd8cb03dSLi Zhong return vmem_back->phys; 311bd8cb03dSLi Zhong } 312bd8cb03dSLi Zhong 31371b0bfe4SLi Zhong void __ref vmemmap_free(unsigned long start, unsigned long end) 314d29eff7bSAndy Whitcroft { 315cec08e7aSBenjamin Herrenschmidt unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift; 316d29eff7bSAndy Whitcroft 317d29eff7bSAndy Whitcroft start = _ALIGN_DOWN(start, page_size); 318d29eff7bSAndy Whitcroft 31971b0bfe4SLi Zhong pr_debug("vmemmap_free %lx...%lx\n", start, end); 32032a74949SBenjamin Herrenschmidt 321d29eff7bSAndy Whitcroft for (; start < end; start += page_size) { 32271b0bfe4SLi Zhong unsigned long addr; 323d29eff7bSAndy Whitcroft 32471b0bfe4SLi Zhong /* 32571b0bfe4SLi Zhong * the section has already be marked as invalid, so 32671b0bfe4SLi Zhong * vmemmap_populated() true means some other sections still 32771b0bfe4SLi Zhong * in this page, so skip it. 32871b0bfe4SLi Zhong */ 329d29eff7bSAndy Whitcroft if (vmemmap_populated(start, page_size)) 330d29eff7bSAndy Whitcroft continue; 331d29eff7bSAndy Whitcroft 33271b0bfe4SLi Zhong addr = vmemmap_list_free(start); 33371b0bfe4SLi Zhong if (addr) { 33471b0bfe4SLi Zhong struct page *page = pfn_to_page(addr >> PAGE_SHIFT); 335d29eff7bSAndy Whitcroft 33671b0bfe4SLi Zhong if (PageReserved(page)) { 33771b0bfe4SLi Zhong /* allocated from bootmem */ 33871b0bfe4SLi Zhong if (page_size < PAGE_SIZE) { 33971b0bfe4SLi Zhong /* 34071b0bfe4SLi Zhong * this shouldn't happen, but if it is 34171b0bfe4SLi Zhong * the case, leave the memory there 34271b0bfe4SLi Zhong */ 34371b0bfe4SLi Zhong WARN_ON_ONCE(1); 34471b0bfe4SLi Zhong } else { 34571b0bfe4SLi Zhong unsigned int nr_pages = 34671b0bfe4SLi Zhong 1 << get_order(page_size); 34771b0bfe4SLi Zhong while (nr_pages--) 34871b0bfe4SLi Zhong free_reserved_page(page++); 349d29eff7bSAndy Whitcroft } 35071b0bfe4SLi Zhong } else 35171b0bfe4SLi Zhong free_pages((unsigned long)(__va(addr)), 35271b0bfe4SLi Zhong get_order(page_size)); 353d29eff7bSAndy Whitcroft 35471b0bfe4SLi Zhong vmemmap_remove_mapping(start, page_size); 355d29eff7bSAndy Whitcroft } 3560197518cSTang Chen } 35771b0bfe4SLi Zhong } 35871b0bfe4SLi Zhong #endif 359f7e3334aSNathan Fontenot void register_page_bootmem_memmap(unsigned long section_nr, 360f7e3334aSNathan Fontenot struct page *start_page, unsigned long size) 361f7e3334aSNathan Fontenot { 362f7e3334aSNathan Fontenot } 363cd3db0c4SBenjamin Herrenschmidt 3648e0861faSAlexey Kardashevskiy /* 3658e0861faSAlexey Kardashevskiy * We do not have access to the sparsemem vmemmap, so we fallback to 3668e0861faSAlexey Kardashevskiy * walking the list of sparsemem blocks which we already maintain for 3678e0861faSAlexey Kardashevskiy * the sake of crashdump. In the long run, we might want to maintain 3688e0861faSAlexey Kardashevskiy * a tree if performance of that linear walk becomes a problem. 3698e0861faSAlexey Kardashevskiy * 3708e0861faSAlexey Kardashevskiy * realmode_pfn_to_page functions can fail due to: 3718e0861faSAlexey Kardashevskiy * 1) As real sparsemem blocks do not lay in RAM continously (they 3728e0861faSAlexey Kardashevskiy * are in virtual address space which is not available in the real mode), 3738e0861faSAlexey Kardashevskiy * the requested page struct can be split between blocks so get_page/put_page 3748e0861faSAlexey Kardashevskiy * may fail. 3758e0861faSAlexey Kardashevskiy * 2) When huge pages are used, the get_page/put_page API will fail 3768e0861faSAlexey Kardashevskiy * in real mode as the linked addresses in the page struct are virtual 3778e0861faSAlexey Kardashevskiy * too. 3788e0861faSAlexey Kardashevskiy */ 3798e0861faSAlexey Kardashevskiy struct page *realmode_pfn_to_page(unsigned long pfn) 3808e0861faSAlexey Kardashevskiy { 3818e0861faSAlexey Kardashevskiy struct vmemmap_backing *vmem_back; 3828e0861faSAlexey Kardashevskiy struct page *page; 3838e0861faSAlexey Kardashevskiy unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift; 3848e0861faSAlexey Kardashevskiy unsigned long pg_va = (unsigned long) pfn_to_page(pfn); 3858e0861faSAlexey Kardashevskiy 3868e0861faSAlexey Kardashevskiy for (vmem_back = vmemmap_list; vmem_back; vmem_back = vmem_back->list) { 3878e0861faSAlexey Kardashevskiy if (pg_va < vmem_back->virt_addr) 3888e0861faSAlexey Kardashevskiy continue; 3898e0861faSAlexey Kardashevskiy 390bd8cb03dSLi Zhong /* After vmemmap_list entry free is possible, need check all */ 391bd8cb03dSLi Zhong if ((pg_va + sizeof(struct page)) <= 392bd8cb03dSLi Zhong (vmem_back->virt_addr + page_size)) { 3938e0861faSAlexey Kardashevskiy page = (struct page *) (vmem_back->phys + pg_va - 3948e0861faSAlexey Kardashevskiy vmem_back->virt_addr); 3958e0861faSAlexey Kardashevskiy return page; 3968e0861faSAlexey Kardashevskiy } 397bd8cb03dSLi Zhong } 3988e0861faSAlexey Kardashevskiy 399bd8cb03dSLi Zhong /* Probably that page struct is split between real pages */ 4008e0861faSAlexey Kardashevskiy return NULL; 4018e0861faSAlexey Kardashevskiy } 4028e0861faSAlexey Kardashevskiy EXPORT_SYMBOL_GPL(realmode_pfn_to_page); 4038e0861faSAlexey Kardashevskiy 4048e0861faSAlexey Kardashevskiy #elif defined(CONFIG_FLATMEM) 4058e0861faSAlexey Kardashevskiy 4068e0861faSAlexey Kardashevskiy struct page *realmode_pfn_to_page(unsigned long pfn) 4078e0861faSAlexey Kardashevskiy { 4088e0861faSAlexey Kardashevskiy struct page *page = pfn_to_page(pfn); 4098e0861faSAlexey Kardashevskiy return page; 4108e0861faSAlexey Kardashevskiy } 4118e0861faSAlexey Kardashevskiy EXPORT_SYMBOL_GPL(realmode_pfn_to_page); 4128e0861faSAlexey Kardashevskiy 4138e0861faSAlexey Kardashevskiy #endif /* CONFIG_SPARSEMEM_VMEMMAP/CONFIG_FLATMEM */ 414*1a01dc87SMichael Ellerman 415*1a01dc87SMichael Ellerman #ifdef CONFIG_PPC_STD_MMU_64 416*1a01dc87SMichael Ellerman void __init mmu_early_init_devtree(void) 417*1a01dc87SMichael Ellerman { 418*1a01dc87SMichael Ellerman } 419*1a01dc87SMichael Ellerman #endif /* CONFIG_PPC_STD_MMU_64 */ 420