1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_PGTABLE_H
3 #define _ASM_POWERPC_PGTABLE_H
6 #include <linux/mmdebug.h>
7 #include <linux/mmzone.h>
8 #include <asm/processor.h> /* For TASK_SIZE */
11 #include <asm/tlbflush.h>
15 #endif /* !__ASSEMBLY__ */
17 #ifdef CONFIG_PPC_BOOK3S
18 #include <asm/book3s/pgtable.h>
20 #include <asm/nohash/pgtable.h>
21 #endif /* !CONFIG_PPC_BOOK3S */
24 * Protection used for kernel text. We want the debuggers to be able to
25 * set breakpoints anywhere, so don't write protect the kernel text
26 * on platforms where such control is possible.
28 #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) || \
29 defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
30 #define PAGE_KERNEL_TEXT PAGE_KERNEL_X
32 #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
35 /* Make modules code happy. We don't set RO yet */
36 #define PAGE_KERNEL_EXEC PAGE_KERNEL_X
38 /* Advertise special mapping type for AGP */
39 #define PAGE_AGP (PAGE_KERNEL_NC)
44 #ifndef MAX_PTRS_PER_PGD
45 #define MAX_PTRS_PER_PGD PTRS_PER_PGD
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))
52 * Select all bits except the pfn
54 static inline pgprot_t pte_pgprot(pte_t pte)
56 unsigned long pte_flags;
58 pte_flags = pte_val(pte) & ~PTE_RPN_MASK;
59 return __pgprot(pte_flags);
62 #ifndef pmd_page_vaddr
63 static inline unsigned long pmd_page_vaddr(pmd_t pmd)
65 return ((unsigned long)__va(pmd_val(pmd) & ~PMD_MASKED_BITS));
67 #define pmd_page_vaddr pmd_page_vaddr
70 * ZERO_PAGE is a global shared page that is always zero: used
71 * for zero-mapped memory areas etc..
73 extern unsigned long empty_zero_page[];
74 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
76 extern pgd_t swapper_pg_dir[];
78 extern void paging_init(void);
79 void poking_init(void);
81 extern unsigned long ioremap_bot;
82 extern const pgprot_t protection_map[16];
85 * kern_addr_valid is intended to indicate whether an address is a valid
86 * kernel address. Most 32-bit archs define it as always true (like this)
87 * but most 64-bit archs actually perform a test. What should we do here?
89 #define kern_addr_valid(addr) (1)
91 #ifndef CONFIG_TRANSPARENT_HUGEPAGE
92 #define pmd_large(pmd) 0
95 /* can we use this in kvm */
96 unsigned long vmalloc_to_phys(void *vmalloc_addr);
98 void pgtable_cache_add(unsigned int shift);
100 pte_t *early_pte_alloc_kernel(pmd_t *pmdp, unsigned long va);
102 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_PPC32)
103 void mark_initmem_nx(void);
105 static inline void mark_initmem_nx(void) { }
109 * When used, PTE_FRAG_NR is defined in subarch pgtable.h
110 * so we are sure it is included when arriving here.
113 static inline void *pte_frag_get(mm_context_t *ctx)
115 return ctx->pte_frag;
118 static inline void pte_frag_set(mm_context_t *ctx, void *p)
123 #define PTE_FRAG_NR 1
124 #define PTE_FRAG_SIZE_SHIFT PAGE_SHIFT
125 #define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT)
127 static inline void *pte_frag_get(mm_context_t *ctx)
132 static inline void pte_frag_set(mm_context_t *ctx, void *p)
138 #define pmd_is_leaf pmd_is_leaf
139 static inline bool pmd_is_leaf(pmd_t pmd)
146 #define pud_is_leaf pud_is_leaf
147 static inline bool pud_is_leaf(pud_t pud)
154 #define p4d_is_leaf p4d_is_leaf
155 static inline bool p4d_is_leaf(p4d_t p4d)
161 #define pmd_pgtable pmd_pgtable
162 static inline pgtable_t pmd_pgtable(pmd_t pmd)
164 return (pgtable_t)pmd_page_vaddr(pmd);
168 #define is_ioremap_addr is_ioremap_addr
169 static inline bool is_ioremap_addr(const void *x)
171 unsigned long addr = (unsigned long)x;
173 return addr >= IOREMAP_BASE && addr < IOREMAP_END;
177 void arch_report_meminfo(struct seq_file *m);
178 #endif /* CONFIG_PPC64 */
180 #endif /* __ASSEMBLY__ */
182 #endif /* _ASM_POWERPC_PGTABLE_H */