Aneesh Kumar K.V | 26b6a3d | 2015-12-01 09:06:26 +0530 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_BOOK3S_64_HASH_H |
| 2 | #define _ASM_POWERPC_BOOK3S_64_HASH_H |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 3 | #ifdef __KERNEL__ |
| 4 | |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame^] | 5 | /* |
| 6 | * Common bits between 4K and 64K pages in a linux-style PTE. |
| 7 | * These match the bits in the (hardware-defined) PowerPC PTE as closely |
| 8 | * as possible. Additional bits may be defined in pgtable-hash64-*.h |
| 9 | * |
| 10 | * Note: We only support user read/write permissions. Supervisor always |
| 11 | * have full read/write to pages above PAGE_OFFSET (pages below that |
| 12 | * always use the user access permissions). |
| 13 | * |
| 14 | * We could create separate kernel read-only if we used the 3 PP bits |
| 15 | * combinations that newer processors provide but we currently don't. |
| 16 | */ |
| 17 | #define _PAGE_PRESENT 0x00001 /* software: pte contains a translation */ |
| 18 | #define _PAGE_USER 0x00002 /* matches one of the PP bits */ |
| 19 | #define _PAGE_BIT_SWAP_TYPE 2 |
| 20 | #define _PAGE_EXEC 0x00004 /* No execute on POWER4 and newer (we invert) */ |
| 21 | #define _PAGE_GUARDED 0x00008 |
| 22 | /* We can derive Memory coherence from _PAGE_NO_CACHE */ |
| 23 | #define _PAGE_COHERENT 0x0 |
| 24 | #define _PAGE_NO_CACHE 0x00020 /* I: cache inhibit */ |
| 25 | #define _PAGE_WRITETHRU 0x00040 /* W: cache write-through */ |
| 26 | #define _PAGE_DIRTY 0x00080 /* C: page changed */ |
| 27 | #define _PAGE_ACCESSED 0x00100 /* R: page referenced */ |
| 28 | #define _PAGE_RW 0x00200 /* software: user write access allowed */ |
| 29 | #define _PAGE_HASHPTE 0x00400 /* software: pte has an associated HPTE */ |
| 30 | #define _PAGE_BUSY 0x00800 /* software: PTE & hash are busy */ |
| 31 | #define _PAGE_F_GIX 0x07000 /* full page: hidx bits */ |
| 32 | #define _PAGE_F_GIX_SHIFT 12 |
| 33 | #define _PAGE_F_SECOND 0x08000 /* Whether to use secondary hash or not */ |
| 34 | #define _PAGE_SPECIAL 0x10000 /* software: special page */ |
| 35 | |
| 36 | /* |
| 37 | * THP pages can't be special. So use the _PAGE_SPECIAL |
| 38 | */ |
| 39 | #define _PAGE_SPLITTING _PAGE_SPECIAL |
| 40 | |
| 41 | /* |
| 42 | * We need to differentiate between explicit huge page and THP huge |
| 43 | * page, since THP huge page also need to track real subpage details |
| 44 | */ |
| 45 | #define _PAGE_THP_HUGE _PAGE_4K_PFN |
| 46 | |
| 47 | /* |
| 48 | * set of bits not changed in pmd_modify. |
| 49 | */ |
| 50 | #define _HPAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | \ |
| 51 | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_SPLITTING | \ |
| 52 | _PAGE_THP_HUGE) |
| 53 | |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 54 | #ifdef CONFIG_PPC_64K_PAGES |
| 55 | #include <asm/book3s/64/hash-64k.h> |
| 56 | #else |
| 57 | #include <asm/book3s/64/hash-4k.h> |
| 58 | #endif |
| 59 | |
| 60 | /* |
| 61 | * Size of EA range mapped by our pagetables. |
| 62 | */ |
| 63 | #define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \ |
| 64 | PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT) |
| 65 | #define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE) |
| 66 | |
| 67 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 68 | #define PMD_CACHE_INDEX (PMD_INDEX_SIZE + 1) |
| 69 | #else |
| 70 | #define PMD_CACHE_INDEX PMD_INDEX_SIZE |
| 71 | #endif |
| 72 | /* |
| 73 | * Define the address range of the kernel non-linear virtual area |
| 74 | */ |
| 75 | #define KERN_VIRT_START ASM_CONST(0xD000000000000000) |
| 76 | #define KERN_VIRT_SIZE ASM_CONST(0x0000100000000000) |
| 77 | |
| 78 | /* |
| 79 | * The vmalloc space starts at the beginning of that region, and |
| 80 | * occupies half of it on hash CPUs and a quarter of it on Book3E |
| 81 | * (we keep a quarter for the virtual memmap) |
| 82 | */ |
| 83 | #define VMALLOC_START KERN_VIRT_START |
| 84 | #define VMALLOC_SIZE (KERN_VIRT_SIZE >> 1) |
| 85 | #define VMALLOC_END (VMALLOC_START + VMALLOC_SIZE) |
| 86 | |
| 87 | /* |
| 88 | * Region IDs |
| 89 | */ |
| 90 | #define REGION_SHIFT 60UL |
| 91 | #define REGION_MASK (0xfUL << REGION_SHIFT) |
| 92 | #define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT) |
| 93 | |
| 94 | #define VMALLOC_REGION_ID (REGION_ID(VMALLOC_START)) |
| 95 | #define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET)) |
| 96 | #define VMEMMAP_REGION_ID (0xfUL) /* Server only */ |
| 97 | #define USER_REGION_ID (0UL) |
| 98 | |
| 99 | /* |
| 100 | * Defines the address of the vmemap area, in its own region on |
| 101 | * hash table CPUs. |
| 102 | */ |
| 103 | #define VMEMMAP_BASE (VMEMMAP_REGION_ID << REGION_SHIFT) |
| 104 | |
| 105 | #ifdef CONFIG_PPC_MM_SLICES |
| 106 | #define HAVE_ARCH_UNMAPPED_AREA |
| 107 | #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN |
| 108 | #endif /* CONFIG_PPC_MM_SLICES */ |
Benjamin Herrenschmidt | 8d1cf34 | 2009-03-19 19:34:08 +0000 | [diff] [blame] | 109 | |
| 110 | /* No separate kernel read-only */ |
| 111 | #define _PAGE_KERNEL_RW (_PAGE_RW | _PAGE_DIRTY) /* user access blocked by key */ |
| 112 | #define _PAGE_KERNEL_RO _PAGE_KERNEL_RW |
Aneesh Kumar K.V | b0412ea | 2015-12-01 09:06:33 +0530 | [diff] [blame] | 113 | #define _PAGE_KERNEL_RWX (_PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC) |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 114 | |
| 115 | /* Strong Access Ordering */ |
Benjamin Herrenschmidt | 8d1cf34 | 2009-03-19 19:34:08 +0000 | [diff] [blame] | 116 | #define _PAGE_SAO (_PAGE_WRITETHRU | _PAGE_NO_CACHE | _PAGE_COHERENT) |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 117 | |
Benjamin Herrenschmidt | 8d1cf34 | 2009-03-19 19:34:08 +0000 | [diff] [blame] | 118 | /* No page size encoding in the linux PTE */ |
| 119 | #define _PAGE_PSIZE 0 |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 120 | |
| 121 | /* PTEIDX nibble */ |
| 122 | #define _PTEIDX_SECONDARY 0x8 |
| 123 | #define _PTEIDX_GROUP_IX 0x7 |
| 124 | |
Benjamin Herrenschmidt | a033a48 | 2009-03-19 19:34:15 +0000 | [diff] [blame] | 125 | /* Hash table based platforms need atomic updates of the linux PTE */ |
| 126 | #define PTE_ATOMIC_UPDATES 1 |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 127 | #define _PTE_NONE_MASK _PAGE_HPTEFLAGS |
| 128 | /* |
| 129 | * The mask convered by the RPN must be a ULL on 32-bit platforms with |
| 130 | * 64-bit PTEs |
| 131 | */ |
| 132 | #define PTE_RPN_MASK (~((1UL << PTE_RPN_SHIFT) - 1)) |
| 133 | /* |
| 134 | * _PAGE_CHG_MASK masks of bits that are to be preserved across |
| 135 | * pgprot changes |
| 136 | */ |
| 137 | #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ |
| 138 | _PAGE_ACCESSED | _PAGE_SPECIAL) |
| 139 | /* |
| 140 | * Mask of bits returned by pte_pgprot() |
| 141 | */ |
| 142 | #define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \ |
| 143 | _PAGE_WRITETHRU | _PAGE_4K_PFN | \ |
| 144 | _PAGE_USER | _PAGE_ACCESSED | \ |
| 145 | _PAGE_RW | _PAGE_DIRTY | _PAGE_EXEC) |
| 146 | /* |
| 147 | * We define 2 sets of base prot bits, one for basic pages (ie, |
| 148 | * cacheable kernel and user pages) and one for non cacheable |
| 149 | * pages. We always set _PAGE_COHERENT when SMP is enabled or |
| 150 | * the processor might need it for DMA coherency. |
| 151 | */ |
| 152 | #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE) |
| 153 | #define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT) |
| 154 | |
| 155 | /* Permission masks used to generate the __P and __S table, |
| 156 | * |
| 157 | * Note:__pgprot is defined in arch/powerpc/include/asm/page.h |
| 158 | * |
| 159 | * Write permissions imply read permissions for now (we could make write-only |
| 160 | * pages on BookE but we don't bother for now). Execute permission control is |
| 161 | * possible on platforms that define _PAGE_EXEC |
| 162 | * |
| 163 | * Note due to the way vm flags are laid out, the bits are XWR |
| 164 | */ |
| 165 | #define PAGE_NONE __pgprot(_PAGE_BASE) |
| 166 | #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) |
| 167 | #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \ |
| 168 | _PAGE_EXEC) |
| 169 | #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER ) |
| 170 | #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) |
| 171 | #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER ) |
| 172 | #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) |
| 173 | |
| 174 | #define __P000 PAGE_NONE |
| 175 | #define __P001 PAGE_READONLY |
| 176 | #define __P010 PAGE_COPY |
| 177 | #define __P011 PAGE_COPY |
| 178 | #define __P100 PAGE_READONLY_X |
| 179 | #define __P101 PAGE_READONLY_X |
| 180 | #define __P110 PAGE_COPY_X |
| 181 | #define __P111 PAGE_COPY_X |
| 182 | |
| 183 | #define __S000 PAGE_NONE |
| 184 | #define __S001 PAGE_READONLY |
| 185 | #define __S010 PAGE_SHARED |
| 186 | #define __S011 PAGE_SHARED |
| 187 | #define __S100 PAGE_READONLY_X |
| 188 | #define __S101 PAGE_READONLY_X |
| 189 | #define __S110 PAGE_SHARED_X |
| 190 | #define __S111 PAGE_SHARED_X |
| 191 | |
| 192 | /* Permission masks used for kernel mappings */ |
| 193 | #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW) |
| 194 | #define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ |
| 195 | _PAGE_NO_CACHE) |
| 196 | #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ |
| 197 | _PAGE_NO_CACHE | _PAGE_GUARDED) |
| 198 | #define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX) |
| 199 | #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO) |
| 200 | #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX) |
| 201 | |
| 202 | /* Protection used for kernel text. We want the debuggers to be able to |
| 203 | * set breakpoints anywhere, so don't write protect the kernel text |
| 204 | * on platforms where such control is possible. |
| 205 | */ |
| 206 | #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\ |
| 207 | defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) |
| 208 | #define PAGE_KERNEL_TEXT PAGE_KERNEL_X |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 209 | #else |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 210 | #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 211 | #endif |
| 212 | |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 213 | /* Make modules code happy. We don't set RO yet */ |
| 214 | #define PAGE_KERNEL_EXEC PAGE_KERNEL_X |
| 215 | #define PAGE_AGP (PAGE_KERNEL_NC) |
| 216 | |
| 217 | #define PMD_BAD_BITS (PTE_TABLE_SIZE-1) |
| 218 | #define PUD_BAD_BITS (PMD_TABLE_SIZE-1) |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 219 | |
| 220 | #ifndef __ASSEMBLY__ |
| 221 | #define pmd_bad(pmd) (!is_kernel_addr(pmd_val(pmd)) \ |
| 222 | || (pmd_val(pmd) & PMD_BAD_BITS)) |
| 223 | #define pmd_page_vaddr(pmd) (pmd_val(pmd) & ~PMD_MASKED_BITS) |
| 224 | |
| 225 | #define pud_bad(pud) (!is_kernel_addr(pud_val(pud)) \ |
| 226 | || (pud_val(pud) & PUD_BAD_BITS)) |
| 227 | #define pud_page_vaddr(pud) (pud_val(pud) & ~PUD_MASKED_BITS) |
| 228 | |
| 229 | #define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & (PTRS_PER_PGD - 1)) |
| 230 | #define pmd_index(address) (((address) >> (PMD_SHIFT)) & (PTRS_PER_PMD - 1)) |
| 231 | #define pte_index(address) (((address) >> (PAGE_SHIFT)) & (PTRS_PER_PTE - 1)) |
| 232 | |
| 233 | extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr, |
| 234 | pte_t *ptep, unsigned long pte, int huge); |
Aneesh Kumar K.V | c6a3c49 | 2015-12-01 09:06:50 +0530 | [diff] [blame] | 235 | extern unsigned long htab_convert_pte_flags(unsigned long pteflags); |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 236 | /* Atomic PTE updates */ |
| 237 | static inline unsigned long pte_update(struct mm_struct *mm, |
| 238 | unsigned long addr, |
| 239 | pte_t *ptep, unsigned long clr, |
| 240 | unsigned long set, |
| 241 | int huge) |
| 242 | { |
| 243 | unsigned long old, tmp; |
| 244 | |
| 245 | __asm__ __volatile__( |
| 246 | "1: ldarx %0,0,%3 # pte_update\n\ |
| 247 | andi. %1,%0,%6\n\ |
| 248 | bne- 1b \n\ |
| 249 | andc %1,%0,%4 \n\ |
| 250 | or %1,%1,%7\n\ |
| 251 | stdcx. %1,0,%3 \n\ |
| 252 | bne- 1b" |
| 253 | : "=&r" (old), "=&r" (tmp), "=m" (*ptep) |
| 254 | : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY), "r" (set) |
| 255 | : "cc" ); |
| 256 | /* huge pages use the old page table lock */ |
| 257 | if (!huge) |
| 258 | assert_pte_locked(mm, addr); |
| 259 | |
| 260 | if (old & _PAGE_HASHPTE) |
| 261 | hpte_need_flush(mm, addr, ptep, old, huge); |
| 262 | |
| 263 | return old; |
| 264 | } |
| 265 | |
| 266 | static inline int __ptep_test_and_clear_young(struct mm_struct *mm, |
| 267 | unsigned long addr, pte_t *ptep) |
| 268 | { |
| 269 | unsigned long old; |
| 270 | |
| 271 | if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0) |
| 272 | return 0; |
| 273 | old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0); |
| 274 | return (old & _PAGE_ACCESSED) != 0; |
| 275 | } |
| 276 | #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG |
| 277 | #define ptep_test_and_clear_young(__vma, __addr, __ptep) \ |
| 278 | ({ \ |
| 279 | int __r; \ |
| 280 | __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \ |
| 281 | __r; \ |
| 282 | }) |
| 283 | |
| 284 | #define __HAVE_ARCH_PTEP_SET_WRPROTECT |
| 285 | static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, |
| 286 | pte_t *ptep) |
| 287 | { |
| 288 | |
| 289 | if ((pte_val(*ptep) & _PAGE_RW) == 0) |
| 290 | return; |
| 291 | |
| 292 | pte_update(mm, addr, ptep, _PAGE_RW, 0, 0); |
| 293 | } |
| 294 | |
| 295 | static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, |
| 296 | unsigned long addr, pte_t *ptep) |
| 297 | { |
| 298 | if ((pte_val(*ptep) & _PAGE_RW) == 0) |
| 299 | return; |
| 300 | |
| 301 | pte_update(mm, addr, ptep, _PAGE_RW, 0, 1); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * We currently remove entries from the hashtable regardless of whether |
| 306 | * the entry was young or dirty. The generic routines only flush if the |
| 307 | * entry was young or dirty which is not good enough. |
| 308 | * |
| 309 | * We should be more intelligent about this but for the moment we override |
| 310 | * these functions and force a tlb flush unconditionally |
| 311 | */ |
| 312 | #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH |
| 313 | #define ptep_clear_flush_young(__vma, __address, __ptep) \ |
| 314 | ({ \ |
| 315 | int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \ |
| 316 | __ptep); \ |
| 317 | __young; \ |
| 318 | }) |
| 319 | |
| 320 | #define __HAVE_ARCH_PTEP_GET_AND_CLEAR |
| 321 | static inline pte_t ptep_get_and_clear(struct mm_struct *mm, |
| 322 | unsigned long addr, pte_t *ptep) |
| 323 | { |
| 324 | unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0); |
| 325 | return __pte(old); |
| 326 | } |
| 327 | |
| 328 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, |
| 329 | pte_t * ptep) |
| 330 | { |
| 331 | pte_update(mm, addr, ptep, ~0UL, 0, 0); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | /* Set the dirty and/or accessed bits atomically in a linux PTE, this |
| 336 | * function doesn't need to flush the hash entry |
| 337 | */ |
| 338 | static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry) |
| 339 | { |
| 340 | unsigned long bits = pte_val(entry) & |
| 341 | (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC); |
| 342 | |
| 343 | unsigned long old, tmp; |
| 344 | |
| 345 | __asm__ __volatile__( |
| 346 | "1: ldarx %0,0,%4\n\ |
| 347 | andi. %1,%0,%6\n\ |
| 348 | bne- 1b \n\ |
| 349 | or %0,%3,%0\n\ |
| 350 | stdcx. %0,0,%4\n\ |
| 351 | bne- 1b" |
| 352 | :"=&r" (old), "=&r" (tmp), "=m" (*ptep) |
| 353 | :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY) |
| 354 | :"cc"); |
| 355 | } |
| 356 | |
| 357 | #define __HAVE_ARCH_PTE_SAME |
| 358 | #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0) |
| 359 | |
Aneesh Kumar K.V | 1ca7212 | 2015-12-01 09:06:37 +0530 | [diff] [blame] | 360 | /* Generic accessors to PTE bits */ |
| 361 | static inline int pte_write(pte_t pte) { return !!(pte_val(pte) & _PAGE_RW);} |
| 362 | static inline int pte_dirty(pte_t pte) { return !!(pte_val(pte) & _PAGE_DIRTY); } |
| 363 | static inline int pte_young(pte_t pte) { return !!(pte_val(pte) & _PAGE_ACCESSED); } |
| 364 | static inline int pte_special(pte_t pte) { return !!(pte_val(pte) & _PAGE_SPECIAL); } |
| 365 | static inline int pte_none(pte_t pte) { return (pte_val(pte) & ~_PTE_NONE_MASK) == 0; } |
| 366 | static inline pgprot_t pte_pgprot(pte_t pte) { return __pgprot(pte_val(pte) & PAGE_PROT_BITS); } |
| 367 | |
| 368 | #ifdef CONFIG_NUMA_BALANCING |
| 369 | /* |
| 370 | * These work without NUMA balancing but the kernel does not care. See the |
| 371 | * comment in include/asm-generic/pgtable.h . On powerpc, this will only |
| 372 | * work for user pages and always return true for kernel pages. |
| 373 | */ |
| 374 | static inline int pte_protnone(pte_t pte) |
| 375 | { |
| 376 | return (pte_val(pte) & |
| 377 | (_PAGE_PRESENT | _PAGE_USER)) == _PAGE_PRESENT; |
| 378 | } |
| 379 | #endif /* CONFIG_NUMA_BALANCING */ |
| 380 | |
| 381 | static inline int pte_present(pte_t pte) |
| 382 | { |
| 383 | return pte_val(pte) & _PAGE_PRESENT; |
| 384 | } |
| 385 | |
| 386 | /* Conversion functions: convert a page and protection to a page entry, |
| 387 | * and a page entry and page directory to the page they refer to. |
| 388 | * |
| 389 | * Even if PTEs can be unsigned long long, a PFN is always an unsigned |
| 390 | * long for now. |
| 391 | */ |
| 392 | static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) |
| 393 | { |
| 394 | return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) | |
| 395 | pgprot_val(pgprot)); |
| 396 | } |
| 397 | |
| 398 | static inline unsigned long pte_pfn(pte_t pte) |
| 399 | { |
| 400 | return pte_val(pte) >> PTE_RPN_SHIFT; |
| 401 | } |
| 402 | |
| 403 | /* Generic modifiers for PTE bits */ |
| 404 | static inline pte_t pte_wrprotect(pte_t pte) |
| 405 | { |
| 406 | return __pte(pte_val(pte) & ~_PAGE_RW); |
| 407 | } |
| 408 | |
| 409 | static inline pte_t pte_mkclean(pte_t pte) |
| 410 | { |
| 411 | return __pte(pte_val(pte) & ~_PAGE_DIRTY); |
| 412 | } |
| 413 | |
| 414 | static inline pte_t pte_mkold(pte_t pte) |
| 415 | { |
| 416 | return __pte(pte_val(pte) & ~_PAGE_ACCESSED); |
| 417 | } |
| 418 | |
| 419 | static inline pte_t pte_mkwrite(pte_t pte) |
| 420 | { |
| 421 | return __pte(pte_val(pte) | _PAGE_RW); |
| 422 | } |
| 423 | |
| 424 | static inline pte_t pte_mkdirty(pte_t pte) |
| 425 | { |
| 426 | return __pte(pte_val(pte) | _PAGE_DIRTY); |
| 427 | } |
| 428 | |
| 429 | static inline pte_t pte_mkyoung(pte_t pte) |
| 430 | { |
| 431 | return __pte(pte_val(pte) | _PAGE_ACCESSED); |
| 432 | } |
| 433 | |
| 434 | static inline pte_t pte_mkspecial(pte_t pte) |
| 435 | { |
| 436 | return __pte(pte_val(pte) | _PAGE_SPECIAL); |
| 437 | } |
| 438 | |
| 439 | static inline pte_t pte_mkhuge(pte_t pte) |
| 440 | { |
| 441 | return pte; |
| 442 | } |
| 443 | |
| 444 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 445 | { |
| 446 | return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)); |
| 447 | } |
| 448 | |
| 449 | /* This low level function performs the actual PTE insertion |
| 450 | * Setting the PTE depends on the MMU type and other factors. It's |
| 451 | * an horrible mess that I'm not going to try to clean up now but |
| 452 | * I'm keeping it in one place rather than spread around |
| 453 | */ |
| 454 | static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 455 | pte_t *ptep, pte_t pte, int percpu) |
| 456 | { |
| 457 | /* |
| 458 | * Anything else just stores the PTE normally. That covers all 64-bit |
| 459 | * cases, and 32-bit non-hash with 32-bit PTEs. |
| 460 | */ |
| 461 | *ptep = pte; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Macro to mark a page protection value as "uncacheable". |
| 466 | */ |
| 467 | |
| 468 | #define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \ |
| 469 | _PAGE_WRITETHRU) |
| 470 | |
| 471 | #define pgprot_noncached pgprot_noncached |
| 472 | static inline pgprot_t pgprot_noncached(pgprot_t prot) |
| 473 | { |
| 474 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | |
| 475 | _PAGE_NO_CACHE | _PAGE_GUARDED); |
| 476 | } |
| 477 | |
| 478 | #define pgprot_noncached_wc pgprot_noncached_wc |
| 479 | static inline pgprot_t pgprot_noncached_wc(pgprot_t prot) |
| 480 | { |
| 481 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | |
| 482 | _PAGE_NO_CACHE); |
| 483 | } |
| 484 | |
| 485 | #define pgprot_cached pgprot_cached |
| 486 | static inline pgprot_t pgprot_cached(pgprot_t prot) |
| 487 | { |
| 488 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | |
| 489 | _PAGE_COHERENT); |
| 490 | } |
| 491 | |
| 492 | #define pgprot_cached_wthru pgprot_cached_wthru |
| 493 | static inline pgprot_t pgprot_cached_wthru(pgprot_t prot) |
| 494 | { |
| 495 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | |
| 496 | _PAGE_COHERENT | _PAGE_WRITETHRU); |
| 497 | } |
| 498 | |
| 499 | #define pgprot_cached_noncoherent pgprot_cached_noncoherent |
| 500 | static inline pgprot_t pgprot_cached_noncoherent(pgprot_t prot) |
| 501 | { |
| 502 | return __pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL); |
| 503 | } |
| 504 | |
| 505 | #define pgprot_writecombine pgprot_writecombine |
| 506 | static inline pgprot_t pgprot_writecombine(pgprot_t prot) |
| 507 | { |
| 508 | return pgprot_noncached_wc(prot); |
| 509 | } |
| 510 | |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 511 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 512 | extern void hpte_do_hugepage_flush(struct mm_struct *mm, unsigned long addr, |
| 513 | pmd_t *pmdp, unsigned long old_pmd); |
| 514 | #else |
| 515 | static inline void hpte_do_hugepage_flush(struct mm_struct *mm, |
| 516 | unsigned long addr, pmd_t *pmdp, |
| 517 | unsigned long old_pmd) |
| 518 | { |
| 519 | WARN(1, "%s called with THP disabled\n", __func__); |
| 520 | } |
| 521 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 522 | |
| 523 | #endif /* !__ASSEMBLY__ */ |
Benjamin Herrenschmidt | c605782 | 2009-03-10 17:53:29 +0000 | [diff] [blame] | 524 | #endif /* __KERNEL__ */ |
Aneesh Kumar K.V | 26b6a3d | 2015-12-01 09:06:26 +0530 | [diff] [blame] | 525 | #endif /* _ASM_POWERPC_BOOK3S_64_HASH_H */ |