1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Included from asm/pgtable-*.h only ! */
5 * Some bits are only used on some cpu families... Make sure that all
6 * the undefined gets a sensible default
9 #define _PAGE_HASHPTE 0
12 #define _PAGE_HWWRITE 0
18 #define _PAGE_ENDIAN 0
20 #ifndef _PAGE_COHERENT
21 #define _PAGE_COHERENT 0
23 #ifndef _PAGE_WRITETHRU
24 #define _PAGE_WRITETHRU 0
27 #define _PAGE_4K_PFN 0
35 /* _PAGE_RO and _PAGE_RW shall not be defined at the same time */
45 /* At least one of _PAGE_PRIVILEGED or _PAGE_USER must be defined */
46 #ifndef _PAGE_PRIVILEGED
47 #define _PAGE_PRIVILEGED 0
60 #ifndef _PMD_PRESENT_MASK
61 #define _PMD_PRESENT_MASK _PMD_PRESENT
66 #ifndef _PAGE_KERNEL_RO
67 #define _PAGE_KERNEL_RO (_PAGE_PRIVILEGED | _PAGE_RO)
69 #ifndef _PAGE_KERNEL_ROX
70 #define _PAGE_KERNEL_ROX (_PAGE_PRIVILEGED | _PAGE_RO | _PAGE_EXEC)
72 #ifndef _PAGE_KERNEL_RW
73 #define _PAGE_KERNEL_RW (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | \
76 #ifndef _PAGE_KERNEL_RWX
77 #define _PAGE_KERNEL_RWX (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | \
78 _PAGE_HWWRITE | _PAGE_EXEC)
80 #ifndef _PAGE_HPTEFLAGS
81 #define _PAGE_HPTEFLAGS _PAGE_HASHPTE
83 #ifndef _PTE_NONE_MASK
84 #define _PTE_NONE_MASK _PAGE_HPTEFLAGS
90 * Don't just check for any non zero bits in __PAGE_USER, since for book3e
91 * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
92 * _PAGE_USER. Need to explicitly match _PAGE_BAP_UR bit in that case too.
94 static inline bool pte_user(pte_t pte)
96 return (pte_val(pte) & (_PAGE_USER | _PAGE_PRIVILEGED)) == _PAGE_USER;
98 #endif /* __ASSEMBLY__ */
100 /* Location of the PFN in the PTE. Most 32-bit platforms use the same
101 * as _PAGE_SHIFT here (ie, naturally aligned).
102 * Platform who don't just pre-define the value so we don't override it here
104 #ifndef PTE_RPN_SHIFT
105 #define PTE_RPN_SHIFT (PAGE_SHIFT)
108 /* The mask covered by the RPN must be a ULL on 32-bit platforms with
111 #if defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
112 #define PTE_RPN_MASK (~((1ULL<<PTE_RPN_SHIFT)-1))
113 #define MAX_POSSIBLE_PHYSMEM_BITS 36
115 #define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1))
116 #define MAX_POSSIBLE_PHYSMEM_BITS 32
119 /* _PAGE_CHG_MASK masks of bits that are to be preserved across
122 #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
123 _PAGE_ACCESSED | _PAGE_SPECIAL)
125 /* Mask of bits returned by pte_pgprot() */
126 #define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \
127 _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \
128 _PAGE_USER | _PAGE_ACCESSED | _PAGE_RO | _PAGE_NA | \
130 _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC)
133 * We define 2 sets of base prot bits, one for basic pages (ie,
134 * cacheable kernel and user pages) and one for non cacheable
135 * pages. We always set _PAGE_COHERENT when SMP is enabled or
136 * the processor might need it for DMA coherency.
138 #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
139 #if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU) || \
140 defined(CONFIG_PPC_E500MC)
141 #define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
143 #define _PAGE_BASE (_PAGE_BASE_NC)
146 /* Permission masks used to generate the __P and __S table,
148 * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
150 * Write permissions imply read permissions for now (we could make write-only
151 * pages on BookE but we don't bother for now). Execute permission control is
152 * possible on platforms that define _PAGE_EXEC
154 * Note due to the way vm flags are laid out, the bits are XWR
156 #define PAGE_NONE __pgprot(_PAGE_BASE | _PAGE_NA)
157 #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
158 #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \
160 #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
161 #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
163 #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
164 #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
167 #define __P000 PAGE_NONE
168 #define __P001 PAGE_READONLY
169 #define __P010 PAGE_COPY
170 #define __P011 PAGE_COPY
171 #define __P100 PAGE_READONLY_X
172 #define __P101 PAGE_READONLY_X
173 #define __P110 PAGE_COPY_X
174 #define __P111 PAGE_COPY_X
176 #define __S000 PAGE_NONE
177 #define __S001 PAGE_READONLY
178 #define __S010 PAGE_SHARED
179 #define __S011 PAGE_SHARED
180 #define __S100 PAGE_READONLY_X
181 #define __S101 PAGE_READONLY_X
182 #define __S110 PAGE_SHARED_X
183 #define __S111 PAGE_SHARED_X
185 /* Permission masks used for kernel mappings */
186 #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
187 #define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
189 #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
190 _PAGE_NO_CACHE | _PAGE_GUARDED)
191 #define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
192 #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
193 #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
195 /* Protection used for kernel text. We want the debuggers to be able to
196 * set breakpoints anywhere, so don't write protect the kernel text
197 * on platforms where such control is possible.
199 #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
200 defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
201 #define PAGE_KERNEL_TEXT PAGE_KERNEL_X
203 #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
206 /* Make modules code happy. We don't set RO yet */
207 #define PAGE_KERNEL_EXEC PAGE_KERNEL_X
209 /* Advertise special mapping type for AGP */
210 #define PAGE_AGP (PAGE_KERNEL_NC)
211 #define HAVE_PAGE_AGP
214 /* if not defined, we should not find _PAGE_WRITE too */
216 #define _PAGE_WRITE _PAGE_RW
219 #ifndef H_PAGE_4K_PFN
220 #define H_PAGE_4K_PFN 0