Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 2 | /* 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 Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 11 | #ifndef _PAGE_HWWRITE |
| 12 | #define _PAGE_HWWRITE 0 |
| 13 | #endif |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 14 | #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 Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 26 | #ifndef _PAGE_4K_PFN |
| 27 | #define _PAGE_4K_PFN 0 |
| 28 | #endif |
Benjamin Herrenschmidt | 57e2a99 | 2009-07-28 11:59:34 +1000 | [diff] [blame] | 29 | #ifndef _PAGE_SAO |
| 30 | #define _PAGE_SAO 0 |
| 31 | #endif |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 32 | #ifndef _PAGE_PSIZE |
| 33 | #define _PAGE_PSIZE 0 |
| 34 | #endif |
LEROY Christophe | a7b9f67 | 2015-01-19 17:04:38 +0100 | [diff] [blame] | 35 | /* _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.V | 6a119ea | 2015-12-01 09:06:54 +0530 | [diff] [blame] | 41 | |
| 42 | #ifndef _PAGE_PTE |
| 43 | #define _PAGE_PTE 0 |
| 44 | #endif |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 45 | /* 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 Leroy | 3517503 | 2018-01-12 13:45:29 +0100 | [diff] [blame] | 53 | #ifndef _PAGE_NA |
| 54 | #define _PAGE_NA 0 |
| 55 | #endif |
Christophe Leroy | de0f938 | 2018-01-12 13:45:31 +0100 | [diff] [blame] | 56 | #ifndef _PAGE_HUGE |
| 57 | #define _PAGE_HUGE 0 |
| 58 | #endif |
Aneesh Kumar K.V | 6a119ea | 2015-12-01 09:06:54 +0530 | [diff] [blame] | 59 | |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 60 | #ifndef _PMD_PRESENT_MASK |
| 61 | #define _PMD_PRESENT_MASK _PMD_PRESENT |
| 62 | #endif |
Christophe Leroy | de0f938 | 2018-01-12 13:45:31 +0100 | [diff] [blame] | 63 | #ifndef _PMD_USER |
| 64 | #define _PMD_USER 0 |
| 65 | #endif |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 66 | #ifndef _PAGE_KERNEL_RO |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 67 | #define _PAGE_KERNEL_RO (_PAGE_PRIVILEGED | _PAGE_RO) |
Benjamin Herrenschmidt | ea3cc33 | 2009-08-18 19:00:34 +0000 | [diff] [blame] | 68 | #endif |
| 69 | #ifndef _PAGE_KERNEL_ROX |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 70 | #define _PAGE_KERNEL_ROX (_PAGE_PRIVILEGED | _PAGE_RO | _PAGE_EXEC) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 71 | #endif |
| 72 | #ifndef _PAGE_KERNEL_RW |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 73 | #define _PAGE_KERNEL_RW (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | \ |
| 74 | _PAGE_HWWRITE) |
Benjamin Herrenschmidt | ea3cc33 | 2009-08-18 19:00:34 +0000 | [diff] [blame] | 75 | #endif |
| 76 | #ifndef _PAGE_KERNEL_RWX |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 77 | #define _PAGE_KERNEL_RWX (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | \ |
| 78 | _PAGE_HWWRITE | _PAGE_EXEC) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 79 | #endif |
| 80 | #ifndef _PAGE_HPTEFLAGS |
| 81 | #define _PAGE_HPTEFLAGS _PAGE_HASHPTE |
| 82 | #endif |
| 83 | #ifndef _PTE_NONE_MASK |
| 84 | #define _PTE_NONE_MASK _PAGE_HPTEFLAGS |
| 85 | #endif |
| 86 | |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 87 | #ifndef __ASSEMBLY__ |
Michael Ellerman | 7e1e63c | 2016-04-29 23:25:32 +1000 | [diff] [blame] | 88 | |
| 89 | /* |
| 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. |
| 93 | */ |
| 94 | static inline bool pte_user(pte_t pte) |
| 95 | { |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 96 | return (pte_val(pte) & (_PAGE_USER | _PAGE_PRIVILEGED)) == _PAGE_USER; |
Michael Ellerman | 7e1e63c | 2016-04-29 23:25:32 +1000 | [diff] [blame] | 97 | } |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 98 | #endif /* __ASSEMBLY__ */ |
| 99 | |
| 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 |
| 103 | */ |
| 104 | #ifndef PTE_RPN_SHIFT |
| 105 | #define PTE_RPN_SHIFT (PAGE_SHIFT) |
| 106 | #endif |
| 107 | |
Michael Ellerman | 027dfac | 2016-06-01 16:34:37 +1000 | [diff] [blame] | 108 | /* The mask covered by the RPN must be a ULL on 32-bit platforms with |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 109 | * 64-bit PTEs |
| 110 | */ |
| 111 | #if defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 112 | #define PTE_RPN_MASK (~((1ULL<<PTE_RPN_SHIFT)-1)) |
| 113 | #else |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 114 | #define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1)) |
| 115 | #endif |
| 116 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 117 | /* _PAGE_CHG_MASK masks of bits that are to be preserved across |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 118 | * pgprot changes |
| 119 | */ |
| 120 | #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ |
| 121 | _PAGE_ACCESSED | _PAGE_SPECIAL) |
| 122 | |
| 123 | /* Mask of bits returned by pte_pgprot() */ |
| 124 | #define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \ |
| 125 | _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \ |
Christophe Leroy | 3517503 | 2018-01-12 13:45:29 +0100 | [diff] [blame] | 126 | _PAGE_USER | _PAGE_ACCESSED | _PAGE_RO | _PAGE_NA | \ |
Christophe Leroy | 812fadc | 2018-01-12 13:45:27 +0100 | [diff] [blame] | 127 | _PAGE_PRIVILEGED | \ |
Benjamin Herrenschmidt | ea3cc33 | 2009-08-18 19:00:34 +0000 | [diff] [blame] | 128 | _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * We define 2 sets of base prot bits, one for basic pages (ie, |
| 132 | * cacheable kernel and user pages) and one for non cacheable |
| 133 | * pages. We always set _PAGE_COHERENT when SMP is enabled or |
| 134 | * the processor might need it for DMA coherency. |
| 135 | */ |
| 136 | #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE) |
Scott Wood | c602320 | 2015-07-18 14:24:58 -0500 | [diff] [blame] | 137 | #if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU) || \ |
| 138 | defined(CONFIG_PPC_E500MC) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 139 | #define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT) |
| 140 | #else |
| 141 | #define _PAGE_BASE (_PAGE_BASE_NC) |
| 142 | #endif |
| 143 | |
| 144 | /* Permission masks used to generate the __P and __S table, |
| 145 | * |
| 146 | * Note:__pgprot is defined in arch/powerpc/include/asm/page.h |
| 147 | * |
| 148 | * Write permissions imply read permissions for now (we could make write-only |
| 149 | * pages on BookE but we don't bother for now). Execute permission control is |
| 150 | * possible on platforms that define _PAGE_EXEC |
| 151 | * |
| 152 | * Note due to the way vm flags are laid out, the bits are XWR |
| 153 | */ |
Christophe Leroy | 3517503 | 2018-01-12 13:45:29 +0100 | [diff] [blame] | 154 | #define PAGE_NONE __pgprot(_PAGE_BASE | _PAGE_NA) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 155 | #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) |
LEROY Christophe | a7b9f67 | 2015-01-19 17:04:38 +0100 | [diff] [blame] | 156 | #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \ |
| 157 | _PAGE_EXEC) |
| 158 | #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO) |
| 159 | #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \ |
| 160 | _PAGE_EXEC) |
| 161 | #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO) |
| 162 | #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \ |
| 163 | _PAGE_EXEC) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 164 | |
| 165 | #define __P000 PAGE_NONE |
| 166 | #define __P001 PAGE_READONLY |
| 167 | #define __P010 PAGE_COPY |
| 168 | #define __P011 PAGE_COPY |
| 169 | #define __P100 PAGE_READONLY_X |
| 170 | #define __P101 PAGE_READONLY_X |
| 171 | #define __P110 PAGE_COPY_X |
| 172 | #define __P111 PAGE_COPY_X |
| 173 | |
| 174 | #define __S000 PAGE_NONE |
| 175 | #define __S001 PAGE_READONLY |
| 176 | #define __S010 PAGE_SHARED |
| 177 | #define __S011 PAGE_SHARED |
| 178 | #define __S100 PAGE_READONLY_X |
| 179 | #define __S101 PAGE_READONLY_X |
| 180 | #define __S110 PAGE_SHARED_X |
| 181 | #define __S111 PAGE_SHARED_X |
| 182 | |
| 183 | /* Permission masks used for kernel mappings */ |
| 184 | #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW) |
| 185 | #define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ |
| 186 | _PAGE_NO_CACHE) |
| 187 | #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ |
| 188 | _PAGE_NO_CACHE | _PAGE_GUARDED) |
Benjamin Herrenschmidt | ea3cc33 | 2009-08-18 19:00:34 +0000 | [diff] [blame] | 189 | #define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 190 | #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO) |
Benjamin Herrenschmidt | ea3cc33 | 2009-08-18 19:00:34 +0000 | [diff] [blame] | 191 | #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 192 | |
| 193 | /* Protection used for kernel text. We want the debuggers to be able to |
| 194 | * set breakpoints anywhere, so don't write protect the kernel text |
| 195 | * on platforms where such control is possible. |
| 196 | */ |
| 197 | #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\ |
Stefan Roese | 09597cf | 2011-04-14 23:49:53 +0000 | [diff] [blame] | 198 | defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) |
Benjamin Herrenschmidt | 7108700 | 2009-03-19 19:34:09 +0000 | [diff] [blame] | 199 | #define PAGE_KERNEL_TEXT PAGE_KERNEL_X |
| 200 | #else |
| 201 | #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX |
| 202 | #endif |
| 203 | |
| 204 | /* Make modules code happy. We don't set RO yet */ |
| 205 | #define PAGE_KERNEL_EXEC PAGE_KERNEL_X |
| 206 | |
| 207 | /* Advertise special mapping type for AGP */ |
| 208 | #define PAGE_AGP (PAGE_KERNEL_NC) |
| 209 | #define HAVE_PAGE_AGP |
| 210 | |
Aneesh Kumar K.V | c7d5484 | 2016-04-29 23:25:30 +1000 | [diff] [blame] | 211 | #ifndef _PAGE_READ |
| 212 | /* if not defined, we should not find _PAGE_WRITE too */ |
| 213 | #define _PAGE_READ 0 |
| 214 | #define _PAGE_WRITE _PAGE_RW |
| 215 | #endif |
Aneesh Kumar K.V | 945537d | 2016-04-29 23:25:45 +1000 | [diff] [blame] | 216 | |
| 217 | #ifndef H_PAGE_4K_PFN |
| 218 | #define H_PAGE_4K_PFN 0 |
| 219 | #endif |