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