1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_PGTABLE_H 3 #define _ASM_POWERPC_PGTABLE_H 4 5 #ifndef __ASSEMBLY__ 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 /* !__ASSEMBLY__ */ 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 /* Note due to the way vm flags are laid out, the bits are XWR */ 24 #define __P000 PAGE_NONE 25 #define __P001 PAGE_READONLY 26 #define __P010 PAGE_COPY 27 #define __P011 PAGE_COPY 28 #define __P100 PAGE_READONLY_X 29 #define __P101 PAGE_READONLY_X 30 #define __P110 PAGE_COPY_X 31 #define __P111 PAGE_COPY_X 32 33 #define __S000 PAGE_NONE 34 #define __S001 PAGE_READONLY 35 #define __S010 PAGE_SHARED 36 #define __S011 PAGE_SHARED 37 #define __S100 PAGE_READONLY_X 38 #define __S101 PAGE_READONLY_X 39 #define __S110 PAGE_SHARED_X 40 #define __S111 PAGE_SHARED_X 41 42 #ifndef __ASSEMBLY__ 43 44 #ifndef MAX_PTRS_PER_PGD 45 #define MAX_PTRS_PER_PGD PTRS_PER_PGD 46 #endif 47 48 /* Keep these as a macros to avoid include dependency mess */ 49 #define pte_page(x) pfn_to_page(pte_pfn(x)) 50 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) 51 /* 52 * Select all bits except the pfn 53 */ 54 static inline pgprot_t pte_pgprot(pte_t pte) 55 { 56 unsigned long pte_flags; 57 58 pte_flags = pte_val(pte) & ~PTE_RPN_MASK; 59 return __pgprot(pte_flags); 60 } 61 62 #ifndef pmd_page_vaddr 63 static inline unsigned long pmd_page_vaddr(pmd_t pmd) 64 { 65 return ((unsigned long)__va(pmd_val(pmd) & ~PMD_MASKED_BITS)); 66 } 67 #define pmd_page_vaddr pmd_page_vaddr 68 #endif 69 /* 70 * ZERO_PAGE is a global shared page that is always zero: used 71 * for zero-mapped memory areas etc.. 72 */ 73 extern unsigned long empty_zero_page[]; 74 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) 75 76 extern pgd_t swapper_pg_dir[]; 77 78 extern void paging_init(void); 79 void poking_init(void); 80 81 extern unsigned long ioremap_bot; 82 83 /* 84 * kern_addr_valid is intended to indicate whether an address is a valid 85 * kernel address. Most 32-bit archs define it as always true (like this) 86 * but most 64-bit archs actually perform a test. What should we do here? 87 */ 88 #define kern_addr_valid(addr) (1) 89 90 #ifndef CONFIG_TRANSPARENT_HUGEPAGE 91 #define pmd_large(pmd) 0 92 #endif 93 94 /* can we use this in kvm */ 95 unsigned long vmalloc_to_phys(void *vmalloc_addr); 96 97 void pgtable_cache_add(unsigned int shift); 98 99 pte_t *early_pte_alloc_kernel(pmd_t *pmdp, unsigned long va); 100 101 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_PPC32) 102 void mark_initmem_nx(void); 103 #else 104 static inline void mark_initmem_nx(void) { } 105 #endif 106 107 /* 108 * When used, PTE_FRAG_NR is defined in subarch pgtable.h 109 * so we are sure it is included when arriving here. 110 */ 111 #ifdef PTE_FRAG_NR 112 static inline void *pte_frag_get(mm_context_t *ctx) 113 { 114 return ctx->pte_frag; 115 } 116 117 static inline void pte_frag_set(mm_context_t *ctx, void *p) 118 { 119 ctx->pte_frag = p; 120 } 121 #else 122 #define PTE_FRAG_NR 1 123 #define PTE_FRAG_SIZE_SHIFT PAGE_SHIFT 124 #define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT) 125 126 static inline void *pte_frag_get(mm_context_t *ctx) 127 { 128 return NULL; 129 } 130 131 static inline void pte_frag_set(mm_context_t *ctx, void *p) 132 { 133 } 134 #endif 135 136 #ifndef pmd_is_leaf 137 #define pmd_is_leaf pmd_is_leaf 138 static inline bool pmd_is_leaf(pmd_t pmd) 139 { 140 return false; 141 } 142 #endif 143 144 #ifndef pud_is_leaf 145 #define pud_is_leaf pud_is_leaf 146 static inline bool pud_is_leaf(pud_t pud) 147 { 148 return false; 149 } 150 #endif 151 152 #ifndef p4d_is_leaf 153 #define p4d_is_leaf p4d_is_leaf 154 static inline bool p4d_is_leaf(p4d_t p4d) 155 { 156 return false; 157 } 158 #endif 159 160 #ifdef CONFIG_PPC64 161 #define is_ioremap_addr is_ioremap_addr 162 static inline bool is_ioremap_addr(const void *x) 163 { 164 unsigned long addr = (unsigned long)x; 165 166 return addr >= IOREMAP_BASE && addr < IOREMAP_END; 167 } 168 169 struct seq_file; 170 void arch_report_meminfo(struct seq_file *m); 171 #endif /* CONFIG_PPC64 */ 172 173 #endif /* __ASSEMBLY__ */ 174 175 #endif /* _ASM_POWERPC_PGTABLE_H */ 176