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