GNU Linux-libre 4.9.297-gnu1
[releases.git] / arch / powerpc / include / asm / pte-common.h
1 /* Included from asm/pgtable-*.h only ! */
2
3 /*
4  * Some bits are only used on some cpu families... Make sure that all
5  * the undefined gets a sensible default
6  */
7 #ifndef _PAGE_HASHPTE
8 #define _PAGE_HASHPTE   0
9 #endif
10 #ifndef _PAGE_SHARED
11 #define _PAGE_SHARED    0
12 #endif
13 #ifndef _PAGE_HWWRITE
14 #define _PAGE_HWWRITE   0
15 #endif
16 #ifndef _PAGE_EXEC
17 #define _PAGE_EXEC      0
18 #endif
19 #ifndef _PAGE_ENDIAN
20 #define _PAGE_ENDIAN    0
21 #endif
22 #ifndef _PAGE_COHERENT
23 #define _PAGE_COHERENT  0
24 #endif
25 #ifndef _PAGE_WRITETHRU
26 #define _PAGE_WRITETHRU 0
27 #endif
28 #ifndef _PAGE_4K_PFN
29 #define _PAGE_4K_PFN            0
30 #endif
31 #ifndef _PAGE_SAO
32 #define _PAGE_SAO       0
33 #endif
34 #ifndef _PAGE_PSIZE
35 #define _PAGE_PSIZE             0
36 #endif
37 /* _PAGE_RO and _PAGE_RW shall not be defined at the same time */
38 #ifndef _PAGE_RO
39 #define _PAGE_RO 0
40 #else
41 #define _PAGE_RW 0
42 #endif
43
44 #ifndef _PAGE_PTE
45 #define _PAGE_PTE 0
46 #endif
47
48 #ifndef _PMD_PRESENT_MASK
49 #define _PMD_PRESENT_MASK       _PMD_PRESENT
50 #endif
51 #ifndef _PMD_SIZE
52 #define _PMD_SIZE       0
53 #define PMD_PAGE_SIZE(pmd)      bad_call_to_PMD_PAGE_SIZE()
54 #endif
55 #ifndef _PAGE_KERNEL_RO
56 #define _PAGE_KERNEL_RO         (_PAGE_RO)
57 #endif
58 #ifndef _PAGE_KERNEL_ROX
59 #define _PAGE_KERNEL_ROX        (_PAGE_EXEC | _PAGE_RO)
60 #endif
61 #ifndef _PAGE_KERNEL_RW
62 #define _PAGE_KERNEL_RW         (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE)
63 #endif
64 #ifndef _PAGE_KERNEL_RWX
65 #define _PAGE_KERNEL_RWX        (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE | _PAGE_EXEC)
66 #endif
67 #ifndef _PAGE_HPTEFLAGS
68 #define _PAGE_HPTEFLAGS _PAGE_HASHPTE
69 #endif
70 #ifndef _PTE_NONE_MASK
71 #define _PTE_NONE_MASK  _PAGE_HPTEFLAGS
72 #endif
73
74 /* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
75  * kernel without large page PMD support
76  */
77 #ifndef __ASSEMBLY__
78 extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
79
80 /*
81  * Don't just check for any non zero bits in __PAGE_USER, since for book3e
82  * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
83  * _PAGE_USER.  Need to explicitly match _PAGE_BAP_UR bit in that case too.
84  */
85 static inline bool pte_user(pte_t pte)
86 {
87         return (pte_val(pte) & _PAGE_USER) == _PAGE_USER;
88 }
89 #endif /* __ASSEMBLY__ */
90
91 /* Location of the PFN in the PTE. Most 32-bit platforms use the same
92  * as _PAGE_SHIFT here (ie, naturally aligned).
93  * Platform who don't just pre-define the value so we don't override it here
94  */
95 #ifndef PTE_RPN_SHIFT
96 #define PTE_RPN_SHIFT   (PAGE_SHIFT)
97 #endif
98
99 /* The mask covered by the RPN must be a ULL on 32-bit platforms with
100  * 64-bit PTEs
101  */
102 #if defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
103 #define PTE_RPN_MASK    (~((1ULL<<PTE_RPN_SHIFT)-1))
104 #define MAX_POSSIBLE_PHYSMEM_BITS 36
105 #else
106 #define PTE_RPN_MASK    (~((1UL<<PTE_RPN_SHIFT)-1))
107 #define MAX_POSSIBLE_PHYSMEM_BITS 32
108 #endif
109
110 /* _PAGE_CHG_MASK masks of bits that are to be preserved across
111  * pgprot changes
112  */
113 #define _PAGE_CHG_MASK  (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
114                          _PAGE_ACCESSED | _PAGE_SPECIAL)
115
116 /* Mask of bits returned by pte_pgprot() */
117 #define PAGE_PROT_BITS  (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \
118                          _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \
119                          _PAGE_USER | _PAGE_ACCESSED | _PAGE_RO | \
120                          _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC)
121
122 /*
123  * We define 2 sets of base prot bits, one for basic pages (ie,
124  * cacheable kernel and user pages) and one for non cacheable
125  * pages. We always set _PAGE_COHERENT when SMP is enabled or
126  * the processor might need it for DMA coherency.
127  */
128 #define _PAGE_BASE_NC   (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
129 #if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU) || \
130         defined(CONFIG_PPC_E500MC)
131 #define _PAGE_BASE      (_PAGE_BASE_NC | _PAGE_COHERENT)
132 #else
133 #define _PAGE_BASE      (_PAGE_BASE_NC)
134 #endif
135
136 /* Permission masks used to generate the __P and __S table,
137  *
138  * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
139  *
140  * Write permissions imply read permissions for now (we could make write-only
141  * pages on BookE but we don't bother for now). Execute permission control is
142  * possible on platforms that define _PAGE_EXEC
143  *
144  * Note due to the way vm flags are laid out, the bits are XWR
145  */
146 #define PAGE_NONE       __pgprot(_PAGE_BASE)
147 #define PAGE_SHARED     __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
148 #define PAGE_SHARED_X   __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \
149                                  _PAGE_EXEC)
150 #define PAGE_COPY       __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
151 #define PAGE_COPY_X     __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
152                                  _PAGE_EXEC)
153 #define PAGE_READONLY   __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
154 #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
155                                  _PAGE_EXEC)
156
157 #define __P000  PAGE_NONE
158 #define __P001  PAGE_READONLY
159 #define __P010  PAGE_COPY
160 #define __P011  PAGE_COPY
161 #define __P100  PAGE_READONLY_X
162 #define __P101  PAGE_READONLY_X
163 #define __P110  PAGE_COPY_X
164 #define __P111  PAGE_COPY_X
165
166 #define __S000  PAGE_NONE
167 #define __S001  PAGE_READONLY
168 #define __S010  PAGE_SHARED
169 #define __S011  PAGE_SHARED
170 #define __S100  PAGE_READONLY_X
171 #define __S101  PAGE_READONLY_X
172 #define __S110  PAGE_SHARED_X
173 #define __S111  PAGE_SHARED_X
174
175 /* Permission masks used for kernel mappings */
176 #define PAGE_KERNEL     __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
177 #define PAGE_KERNEL_NC  __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
178                                  _PAGE_NO_CACHE)
179 #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
180                                  _PAGE_NO_CACHE | _PAGE_GUARDED)
181 #define PAGE_KERNEL_X   __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
182 #define PAGE_KERNEL_RO  __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
183 #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
184
185 /* Protection used for kernel text. We want the debuggers to be able to
186  * set breakpoints anywhere, so don't write protect the kernel text
187  * on platforms where such control is possible.
188  */
189 #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
190         defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
191 #define PAGE_KERNEL_TEXT        PAGE_KERNEL_X
192 #else
193 #define PAGE_KERNEL_TEXT        PAGE_KERNEL_ROX
194 #endif
195
196 /* Make modules code happy. We don't set RO yet */
197 #define PAGE_KERNEL_EXEC        PAGE_KERNEL_X
198
199 /* Advertise special mapping type for AGP */
200 #define PAGE_AGP                (PAGE_KERNEL_NC)
201 #define HAVE_PAGE_AGP
202
203 /* Advertise support for _PAGE_SPECIAL */
204 #define __HAVE_ARCH_PTE_SPECIAL
205
206 #ifndef _PAGE_READ
207 /* if not defined, we should not find _PAGE_WRITE too */
208 #define _PAGE_READ 0
209 #define _PAGE_WRITE _PAGE_RW
210 #endif
211
212 #ifndef H_PAGE_4K_PFN
213 #define H_PAGE_4K_PFN 0
214 #endif