blob: 2aef9b7a0eb2afc8635c4d658ae0bd32ae8c463a [file] [log] [blame]
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +00001/* 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
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000016#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
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000028#ifndef _PAGE_4K_PFN
29#define _PAGE_4K_PFN 0
30#endif
Benjamin Herrenschmidt57e2a992009-07-28 11:59:34 +100031#ifndef _PAGE_SAO
32#define _PAGE_SAO 0
33#endif
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000034#ifndef _PAGE_PSIZE
35#define _PAGE_PSIZE 0
36#endif
LEROY Christophea7b9f672015-01-19 17:04:38 +010037/* _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
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000043#ifndef _PMD_PRESENT_MASK
44#define _PMD_PRESENT_MASK _PMD_PRESENT
45#endif
46#ifndef _PMD_SIZE
47#define _PMD_SIZE 0
48#define PMD_PAGE_SIZE(pmd) bad_call_to_PMD_PAGE_SIZE()
49#endif
50#ifndef _PAGE_KERNEL_RO
LEROY Christophea7b9f672015-01-19 17:04:38 +010051#define _PAGE_KERNEL_RO (_PAGE_RO)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +000052#endif
53#ifndef _PAGE_KERNEL_ROX
LEROY Christophea7b9f672015-01-19 17:04:38 +010054#define _PAGE_KERNEL_ROX (_PAGE_EXEC | _PAGE_RO)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000055#endif
56#ifndef _PAGE_KERNEL_RW
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +000057#define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE)
58#endif
59#ifndef _PAGE_KERNEL_RWX
60#define _PAGE_KERNEL_RWX (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE | _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000061#endif
62#ifndef _PAGE_HPTEFLAGS
63#define _PAGE_HPTEFLAGS _PAGE_HASHPTE
64#endif
65#ifndef _PTE_NONE_MASK
66#define _PTE_NONE_MASK _PAGE_HPTEFLAGS
67#endif
68
69/* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
70 * kernel without large page PMD support
71 */
72#ifndef __ASSEMBLY__
73extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
74#endif /* __ASSEMBLY__ */
75
76/* Location of the PFN in the PTE. Most 32-bit platforms use the same
77 * as _PAGE_SHIFT here (ie, naturally aligned).
78 * Platform who don't just pre-define the value so we don't override it here
79 */
80#ifndef PTE_RPN_SHIFT
81#define PTE_RPN_SHIFT (PAGE_SHIFT)
82#endif
83
84/* The mask convered by the RPN must be a ULL on 32-bit platforms with
85 * 64-bit PTEs
86 */
87#if defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
88#define PTE_RPN_MAX (1ULL << (64 - PTE_RPN_SHIFT))
89#define PTE_RPN_MASK (~((1ULL<<PTE_RPN_SHIFT)-1))
90#else
91#define PTE_RPN_MAX (1UL << (32 - PTE_RPN_SHIFT))
92#define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1))
93#endif
94
Lucas De Marchi25985ed2011-03-30 22:57:33 -030095/* _PAGE_CHG_MASK masks of bits that are to be preserved across
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +000096 * pgprot changes
97 */
98#define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
99 _PAGE_ACCESSED | _PAGE_SPECIAL)
100
101/* Mask of bits returned by pte_pgprot() */
102#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \
103 _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \
LEROY Christophea7b9f672015-01-19 17:04:38 +0100104 _PAGE_USER | _PAGE_ACCESSED | _PAGE_RO | \
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000105 _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000106
Mel Gorman6a339792014-10-09 15:26:33 -0700107#ifdef CONFIG_NUMA_BALANCING
108/* Mask of bits that distinguish present and numa ptes */
109#define _PAGE_NUMA_MASK (_PAGE_NUMA|_PAGE_PRESENT)
110#endif
111
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000112/*
113 * We define 2 sets of base prot bits, one for basic pages (ie,
114 * cacheable kernel and user pages) and one for non cacheable
115 * pages. We always set _PAGE_COHERENT when SMP is enabled or
116 * the processor might need it for DMA coherency.
117 */
118#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
119#if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU)
120#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
121#else
122#define _PAGE_BASE (_PAGE_BASE_NC)
123#endif
124
125/* Permission masks used to generate the __P and __S table,
126 *
127 * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
128 *
129 * Write permissions imply read permissions for now (we could make write-only
130 * pages on BookE but we don't bother for now). Execute permission control is
131 * possible on platforms that define _PAGE_EXEC
132 *
133 * Note due to the way vm flags are laid out, the bits are XWR
134 */
135#define PAGE_NONE __pgprot(_PAGE_BASE)
136#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
LEROY Christophea7b9f672015-01-19 17:04:38 +0100137#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \
138 _PAGE_EXEC)
139#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
140#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
141 _PAGE_EXEC)
142#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
143#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
144 _PAGE_EXEC)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000145
146#define __P000 PAGE_NONE
147#define __P001 PAGE_READONLY
148#define __P010 PAGE_COPY
149#define __P011 PAGE_COPY
150#define __P100 PAGE_READONLY_X
151#define __P101 PAGE_READONLY_X
152#define __P110 PAGE_COPY_X
153#define __P111 PAGE_COPY_X
154
155#define __S000 PAGE_NONE
156#define __S001 PAGE_READONLY
157#define __S010 PAGE_SHARED
158#define __S011 PAGE_SHARED
159#define __S100 PAGE_READONLY_X
160#define __S101 PAGE_READONLY_X
161#define __S110 PAGE_SHARED_X
162#define __S111 PAGE_SHARED_X
163
164/* Permission masks used for kernel mappings */
165#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
166#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
167 _PAGE_NO_CACHE)
168#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
169 _PAGE_NO_CACHE | _PAGE_GUARDED)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000170#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000171#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000172#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000173
174/* Protection used for kernel text. We want the debuggers to be able to
175 * set breakpoints anywhere, so don't write protect the kernel text
176 * on platforms where such control is possible.
177 */
178#if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
Stefan Roese09597cf2011-04-14 23:49:53 +0000179 defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000180#define PAGE_KERNEL_TEXT PAGE_KERNEL_X
181#else
182#define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
183#endif
184
185/* Make modules code happy. We don't set RO yet */
186#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
187
Paul Gortmaker92437d42010-09-24 12:44:52 -0400188/*
189 * Don't just check for any non zero bits in __PAGE_USER, since for book3e
190 * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300191 * _PAGE_USER. Need to explicitly match _PAGE_BAP_UR bit in that case too.
Paul Gortmaker92437d42010-09-24 12:44:52 -0400192 */
193#define pte_user(val) ((val & _PAGE_USER) == _PAGE_USER)
194
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000195/* Advertise special mapping type for AGP */
196#define PAGE_AGP (PAGE_KERNEL_NC)
197#define HAVE_PAGE_AGP
198
199/* Advertise support for _PAGE_SPECIAL */
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000200#define __HAVE_ARCH_PTE_SPECIAL
Benjamin Herrenschmidt71087002009-03-19 19:34:09 +0000201