blob: c4a72c7a8c831749faa89b7be71cad1573b218c9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +00002/* Included from asm/pgtable-*.h only ! */
3
4/*
5 * Some bits are only used on some cpu families... Make sure that all
6 * the undefined gets a sensible default
7 */
8#ifndef _PAGE_HASHPTE
9#define _PAGE_HASHPTE 0
10#endif
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000011#ifndef _PAGE_HWWRITE
12#define _PAGE_HWWRITE 0
13#endif
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000014#ifndef _PAGE_EXEC
15#define _PAGE_EXEC 0
16#endif
17#ifndef _PAGE_ENDIAN
18#define _PAGE_ENDIAN 0
19#endif
20#ifndef _PAGE_COHERENT
21#define _PAGE_COHERENT 0
22#endif
23#ifndef _PAGE_WRITETHRU
24#define _PAGE_WRITETHRU 0
25#endif
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000026#ifndef _PAGE_4K_PFN
27#define _PAGE_4K_PFN 0
28#endif
Benjamin Herrenschmidt57e2a992009-07-28 11:59:34 +100029#ifndef _PAGE_SAO
30#define _PAGE_SAO 0
31#endif
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000032#ifndef _PAGE_PSIZE
33#define _PAGE_PSIZE 0
34#endif
LEROY Christophea7b9f672015-01-19 17:04:38 +010035/* _PAGE_RO and _PAGE_RW shall not be defined at the same time */
36#ifndef _PAGE_RO
37#define _PAGE_RO 0
38#else
39#define _PAGE_RW 0
40#endif
Aneesh Kumar K.V6a119ea2015-12-01 09:06:54 +053041
42#ifndef _PAGE_PTE
43#define _PAGE_PTE 0
44#endif
Christophe Leroy812fadc2018-01-12 13:45:27 +010045/* At least one of _PAGE_PRIVILEGED or _PAGE_USER must be defined */
46#ifndef _PAGE_PRIVILEGED
47#define _PAGE_PRIVILEGED 0
48#else
49#ifndef _PAGE_USER
50#define _PAGE_USER 0
51#endif
52#endif
Christophe Leroy35175032018-01-12 13:45:29 +010053#ifndef _PAGE_NA
54#define _PAGE_NA 0
55#endif
Christophe Leroyde0f9382018-01-12 13:45:31 +010056#ifndef _PAGE_HUGE
57#define _PAGE_HUGE 0
58#endif
Aneesh Kumar K.V6a119ea2015-12-01 09:06:54 +053059
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000060#ifndef _PMD_PRESENT_MASK
61#define _PMD_PRESENT_MASK _PMD_PRESENT
62#endif
63#ifndef _PMD_SIZE
64#define _PMD_SIZE 0
65#define PMD_PAGE_SIZE(pmd) bad_call_to_PMD_PAGE_SIZE()
66#endif
Christophe Leroyde0f9382018-01-12 13:45:31 +010067#ifndef _PMD_USER
68#define _PMD_USER 0
69#endif
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000070#ifndef _PAGE_KERNEL_RO
Christophe Leroy812fadc2018-01-12 13:45:27 +010071#define _PAGE_KERNEL_RO (_PAGE_PRIVILEGED | _PAGE_RO)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +000072#endif
73#ifndef _PAGE_KERNEL_ROX
Christophe Leroy812fadc2018-01-12 13:45:27 +010074#define _PAGE_KERNEL_ROX (_PAGE_PRIVILEGED | _PAGE_RO | _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000075#endif
76#ifndef _PAGE_KERNEL_RW
Christophe Leroy812fadc2018-01-12 13:45:27 +010077#define _PAGE_KERNEL_RW (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | \
78 _PAGE_HWWRITE)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +000079#endif
80#ifndef _PAGE_KERNEL_RWX
Christophe Leroy812fadc2018-01-12 13:45:27 +010081#define _PAGE_KERNEL_RWX (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | \
82 _PAGE_HWWRITE | _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000083#endif
84#ifndef _PAGE_HPTEFLAGS
85#define _PAGE_HPTEFLAGS _PAGE_HASHPTE
86#endif
87#ifndef _PTE_NONE_MASK
88#define _PTE_NONE_MASK _PAGE_HPTEFLAGS
89#endif
90
91/* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
92 * kernel without large page PMD support
93 */
94#ifndef __ASSEMBLY__
95extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
Michael Ellerman7e1e63c2016-04-29 23:25:32 +100096
97/*
98 * Don't just check for any non zero bits in __PAGE_USER, since for book3e
99 * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
100 * _PAGE_USER. Need to explicitly match _PAGE_BAP_UR bit in that case too.
101 */
102static inline bool pte_user(pte_t pte)
103{
Christophe Leroy812fadc2018-01-12 13:45:27 +0100104 return (pte_val(pte) & (_PAGE_USER | _PAGE_PRIVILEGED)) == _PAGE_USER;
Michael Ellerman7e1e63c2016-04-29 23:25:32 +1000105}
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000106#endif /* __ASSEMBLY__ */
107
108/* Location of the PFN in the PTE. Most 32-bit platforms use the same
109 * as _PAGE_SHIFT here (ie, naturally aligned).
110 * Platform who don't just pre-define the value so we don't override it here
111 */
112#ifndef PTE_RPN_SHIFT
113#define PTE_RPN_SHIFT (PAGE_SHIFT)
114#endif
115
Michael Ellerman027dfac2016-06-01 16:34:37 +1000116/* The mask covered by the RPN must be a ULL on 32-bit platforms with
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000117 * 64-bit PTEs
118 */
119#if defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000120#define PTE_RPN_MASK (~((1ULL<<PTE_RPN_SHIFT)-1))
121#else
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000122#define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1))
123#endif
124
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300125/* _PAGE_CHG_MASK masks of bits that are to be preserved across
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000126 * pgprot changes
127 */
128#define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
129 _PAGE_ACCESSED | _PAGE_SPECIAL)
130
131/* Mask of bits returned by pte_pgprot() */
132#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \
133 _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \
Christophe Leroy35175032018-01-12 13:45:29 +0100134 _PAGE_USER | _PAGE_ACCESSED | _PAGE_RO | _PAGE_NA | \
Christophe Leroy812fadc2018-01-12 13:45:27 +0100135 _PAGE_PRIVILEGED | \
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000136 _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000137
138/*
139 * We define 2 sets of base prot bits, one for basic pages (ie,
140 * cacheable kernel and user pages) and one for non cacheable
141 * pages. We always set _PAGE_COHERENT when SMP is enabled or
142 * the processor might need it for DMA coherency.
143 */
144#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
Scott Woodc6023202015-07-18 14:24:58 -0500145#if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU) || \
146 defined(CONFIG_PPC_E500MC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000147#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
148#else
149#define _PAGE_BASE (_PAGE_BASE_NC)
150#endif
151
152/* Permission masks used to generate the __P and __S table,
153 *
154 * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
155 *
156 * Write permissions imply read permissions for now (we could make write-only
157 * pages on BookE but we don't bother for now). Execute permission control is
158 * possible on platforms that define _PAGE_EXEC
159 *
160 * Note due to the way vm flags are laid out, the bits are XWR
161 */
Christophe Leroy35175032018-01-12 13:45:29 +0100162#define PAGE_NONE __pgprot(_PAGE_BASE | _PAGE_NA)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000163#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
LEROY Christophea7b9f672015-01-19 17:04:38 +0100164#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \
165 _PAGE_EXEC)
166#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
167#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
168 _PAGE_EXEC)
169#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
170#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
171 _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000172
173#define __P000 PAGE_NONE
174#define __P001 PAGE_READONLY
175#define __P010 PAGE_COPY
176#define __P011 PAGE_COPY
177#define __P100 PAGE_READONLY_X
178#define __P101 PAGE_READONLY_X
179#define __P110 PAGE_COPY_X
180#define __P111 PAGE_COPY_X
181
182#define __S000 PAGE_NONE
183#define __S001 PAGE_READONLY
184#define __S010 PAGE_SHARED
185#define __S011 PAGE_SHARED
186#define __S100 PAGE_READONLY_X
187#define __S101 PAGE_READONLY_X
188#define __S110 PAGE_SHARED_X
189#define __S111 PAGE_SHARED_X
190
191/* Permission masks used for kernel mappings */
192#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
193#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
194 _PAGE_NO_CACHE)
195#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
196 _PAGE_NO_CACHE | _PAGE_GUARDED)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000197#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000198#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000199#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000200
201/* Protection used for kernel text. We want the debuggers to be able to
202 * set breakpoints anywhere, so don't write protect the kernel text
203 * on platforms where such control is possible.
204 */
205#if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
Stefan Roese09597cf2011-04-14 23:49:53 +0000206 defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000207#define PAGE_KERNEL_TEXT PAGE_KERNEL_X
208#else
209#define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
210#endif
211
212/* Make modules code happy. We don't set RO yet */
213#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
214
215/* Advertise special mapping type for AGP */
216#define PAGE_AGP (PAGE_KERNEL_NC)
217#define HAVE_PAGE_AGP
218
219/* Advertise support for _PAGE_SPECIAL */
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000220#define __HAVE_ARCH_PTE_SPECIAL
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000221
Aneesh Kumar K.Vc7d54842016-04-29 23:25:30 +1000222#ifndef _PAGE_READ
223/* if not defined, we should not find _PAGE_WRITE too */
224#define _PAGE_READ 0
225#define _PAGE_WRITE _PAGE_RW
226#endif
Aneesh Kumar K.V945537d2016-04-29 23:25:45 +1000227
228#ifndef H_PAGE_4K_PFN
229#define H_PAGE_4K_PFN 0
230#endif