1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_PGTABLE_H 3 #define _ASM_POWERPC_PGTABLE_H 4 5 #ifndef __ASSEMBLER__ 6 #include <linux/mmdebug.h> 7 #include <linux/mmzone.h> 8 #include <asm/processor.h> /* For TASK_SIZE */ 9 #include <asm/mmu.h> 10 #include <asm/page.h> 11 #include <asm/tlbflush.h> 12 13 struct mm_struct; 14 15 #endif /* !__ASSEMBLER__ */ 16 17 #ifdef CONFIG_PPC_BOOK3S 18 #include <asm/book3s/pgtable.h> 19 #else 20 #include <asm/nohash/pgtable.h> 21 #endif /* !CONFIG_PPC_BOOK3S */ 22 23 /* Make modules code happy. We don't set RO yet */ 24 #define PAGE_KERNEL_EXEC PAGE_KERNEL_X 25 26 /* Advertise special mapping type for AGP */ 27 #define PAGE_AGP (PAGE_KERNEL_NC) 28 #define HAVE_PAGE_AGP 29 30 #ifndef __ASSEMBLER__ 31 32 #define PFN_PTE_SHIFT PTE_RPN_SHIFT 33 34 void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, 35 pte_t pte, unsigned int nr); 36 #define set_ptes set_ptes 37 void set_pte_at_unchecked(struct mm_struct *mm, unsigned long addr, 38 pte_t *ptep, pte_t pte); 39 #define update_mmu_cache(vma, addr, ptep) \ 40 update_mmu_cache_range(NULL, vma, addr, ptep, 1) 41 42 #ifndef MAX_PTRS_PER_PGD 43 #define MAX_PTRS_PER_PGD PTRS_PER_PGD 44 #endif 45 46 /* Keep this as a macro to avoid include dependency mess */ 47 #define pte_page(x) pfn_to_page(pte_pfn(x)) 48 49 static inline unsigned long pte_pfn(pte_t pte) 50 { 51 return (pte_val(pte) & PTE_RPN_MASK) >> PTE_RPN_SHIFT; 52 } 53 54 /* 55 * Select all bits except the pfn 56 */ 57 #define pte_pgprot pte_pgprot 58 static inline pgprot_t pte_pgprot(pte_t pte) 59 { 60 unsigned long pte_flags; 61 62 pte_flags = pte_val(pte) & ~PTE_RPN_MASK; 63 return __pgprot(pte_flags); 64 } 65 66 static inline pgprot_t pgprot_nx(pgprot_t prot) 67 { 68 return pte_pgprot(pte_exprotect(__pte(pgprot_val(prot)))); 69 } 70 #define pgprot_nx pgprot_nx 71 72 #ifndef pmd_page_vaddr 73 static inline const void *pmd_page_vaddr(pmd_t pmd) 74 { 75 return __va(pmd_val(pmd) & ~PMD_MASKED_BITS); 76 } 77 #define pmd_page_vaddr pmd_page_vaddr 78 #endif 79 80 extern pgd_t swapper_pg_dir[]; 81 82 extern void paging_init(void); 83 void poking_init(void); 84 85 extern unsigned long ioremap_bot; 86 extern const pgprot_t protection_map[16]; 87 88 /* can we use this in kvm */ 89 unsigned long vmalloc_to_phys(void *vmalloc_addr); 90 91 void pgtable_cache_add(unsigned int shift); 92 93 #ifdef CONFIG_PPC32 94 void __init *early_alloc_pgtable(unsigned long size); 95 #endif 96 pte_t *early_pte_alloc_kernel(pmd_t *pmdp, unsigned long va); 97 98 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_PPC32) 99 void mark_initmem_nx(void); 100 #else 101 static inline void mark_initmem_nx(void) { } 102 #endif 103 104 #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS 105 int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, 106 pte_t *ptep, pte_t entry, int dirty); 107 108 pgprot_t __phys_mem_access_prot(unsigned long pfn, unsigned long size, 109 pgprot_t vma_prot); 110 111 struct file; 112 static inline pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 113 unsigned long size, pgprot_t vma_prot) 114 { 115 return __phys_mem_access_prot(pfn, size, vma_prot); 116 } 117 #define __HAVE_PHYS_MEM_ACCESS_PROT 118 119 void __update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep); 120 121 /* 122 * This gets called at the end of handling a page fault, when 123 * the kernel has put a new PTE into the page table for the process. 124 * We use it to ensure coherency between the i-cache and d-cache 125 * for the page which has just been mapped in. 126 * On machines which use an MMU hash table, we use this to put a 127 * corresponding HPTE into the hash table ahead of time, instead of 128 * waiting for the inevitable extra hash-table miss exception. 129 */ 130 static inline void update_mmu_cache_range(struct vm_fault *vmf, 131 struct vm_area_struct *vma, unsigned long address, 132 pte_t *ptep, unsigned int nr) 133 { 134 if ((mmu_has_feature(MMU_FTR_HPTE_TABLE) && !radix_enabled()) || 135 (IS_ENABLED(CONFIG_PPC_E500) && IS_ENABLED(CONFIG_HUGETLB_PAGE))) 136 __update_mmu_cache(vma, address, ptep); 137 } 138 139 /* 140 * When used, PTE_FRAG_NR is defined in subarch pgtable.h 141 * so we are sure it is included when arriving here. 142 */ 143 #ifdef PTE_FRAG_NR 144 static inline void *pte_frag_get(mm_context_t *ctx) 145 { 146 return ctx->pte_frag; 147 } 148 149 static inline void pte_frag_set(mm_context_t *ctx, void *p) 150 { 151 ctx->pte_frag = p; 152 } 153 #else 154 #define PTE_FRAG_NR 1 155 #define PTE_FRAG_SIZE_SHIFT PAGE_SHIFT 156 #define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT) 157 158 static inline void *pte_frag_get(mm_context_t *ctx) 159 { 160 return NULL; 161 } 162 163 static inline void pte_frag_set(mm_context_t *ctx, void *p) 164 { 165 } 166 #endif 167 168 #define pmd_pgtable pmd_pgtable 169 static inline pgtable_t pmd_pgtable(pmd_t pmd) 170 { 171 return (pgtable_t)pmd_page_vaddr(pmd); 172 } 173 174 #ifdef CONFIG_PPC64 175 int __meminit vmemmap_populated(unsigned long vmemmap_addr, int vmemmap_map_size); 176 bool altmap_cross_boundary(struct vmem_altmap *altmap, unsigned long start, 177 unsigned long page_size); 178 /* 179 * mm/memory_hotplug.c:mhp_supports_memmap_on_memory goes into details 180 * some of the restrictions. We don't check for PMD_SIZE because our 181 * vmemmap allocation code can fallback correctly. The pageblock 182 * alignment requirement is met using altmap->reserve blocks. 183 */ 184 #define arch_supports_memmap_on_memory arch_supports_memmap_on_memory 185 static inline bool arch_supports_memmap_on_memory(unsigned long vmemmap_size) 186 { 187 if (!radix_enabled()) 188 return false; 189 /* 190 * With 4K page size and 2M PMD_SIZE, we can align 191 * things better with memory block size value 192 * starting from 128MB. Hence align things with PMD_SIZE. 193 */ 194 if (IS_ENABLED(CONFIG_PPC_4K_PAGES)) 195 return IS_ALIGNED(vmemmap_size, PMD_SIZE); 196 return true; 197 } 198 199 #endif /* CONFIG_PPC64 */ 200 201 #ifndef pmd_user_accessible_page 202 #define pmd_user_accessible_page(pmd, addr) false 203 #endif 204 205 #ifndef pud_user_accessible_page 206 #define pud_user_accessible_page(pud, addr) false 207 #endif 208 209 #endif /* __ASSEMBLER__ */ 210 211 #endif /* _ASM_POWERPC_PGTABLE_H */ 212