Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2003 Ralf Baechle |
| 7 | */ |
| 8 | #ifndef _ASM_PGTABLE_H |
| 9 | #define _ASM_PGTABLE_H |
| 10 | |
Corey Minyard | 5bbea36 | 2013-04-08 16:06:35 +0200 | [diff] [blame] | 11 | #include <linux/mm_types.h> |
Ralf Baechle | 970d032 | 2012-10-18 13:54:15 +0200 | [diff] [blame] | 12 | #include <linux/mmzone.h> |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 13 | #ifdef CONFIG_32BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/pgtable-32.h> |
| 15 | #endif |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/pgtable-64.h> |
| 18 | #endif |
| 19 | |
Pete Popov | f10fae0 | 2005-07-14 00:17:05 +0000 | [diff] [blame] | 20 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/pgtable-bits.h> |
| 22 | |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 23 | struct mm_struct; |
| 24 | struct vm_area_struct; |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT) |
Steven J. Hill | 05857c6 | 2012-09-13 16:51:46 -0500 | [diff] [blame] | 27 | #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_WRITE | (cpu_has_rixi ? 0 : _PAGE_READ) | \ |
Chris Dearman | 3513369 | 2007-09-19 00:58:24 +0100 | [diff] [blame] | 28 | _page_cachable_default) |
Steven J. Hill | 05857c6 | 2012-09-13 16:51:46 -0500 | [diff] [blame] | 29 | #define PAGE_COPY __pgprot(_PAGE_PRESENT | (cpu_has_rixi ? 0 : _PAGE_READ) | \ |
| 30 | (cpu_has_rixi ? _PAGE_NO_EXEC : 0) | _page_cachable_default) |
| 31 | #define PAGE_READONLY __pgprot(_PAGE_PRESENT | (cpu_has_rixi ? 0 : _PAGE_READ) | \ |
Chris Dearman | 3513369 | 2007-09-19 00:58:24 +0100 | [diff] [blame] | 32 | _page_cachable_default) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \ |
Chris Dearman | 3513369 | 2007-09-19 00:58:24 +0100 | [diff] [blame] | 34 | _PAGE_GLOBAL | _page_cachable_default) |
Paul Burton | e2a9e5a | 2014-03-03 12:08:40 +0000 | [diff] [blame] | 35 | #define PAGE_KERNEL_NC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \ |
| 36 | _PAGE_GLOBAL | _CACHE_CACHABLE_NONCOHERENT) |
Steven J. Hill | 05857c6 | 2012-09-13 16:51:46 -0500 | [diff] [blame] | 37 | #define PAGE_USERIO __pgprot(_PAGE_PRESENT | (cpu_has_rixi ? 0 : _PAGE_READ) | _PAGE_WRITE | \ |
Chris Dearman | 3513369 | 2007-09-19 00:58:24 +0100 | [diff] [blame] | 38 | _page_cachable_default) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \ |
| 40 | __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED) |
| 41 | |
| 42 | /* |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 43 | * If _PAGE_NO_EXEC is not defined, we can't do page protection for |
| 44 | * execute, and consider it to be the same as read. Also, write |
| 45 | * permissions imply read permissions. This is the closest we can get |
| 46 | * by reasonable means.. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Chris Dearman | 3513369 | 2007-09-19 00:58:24 +0100 | [diff] [blame] | 49 | /* |
| 50 | * Dummy values to fill the table in mmap.c |
| 51 | * The real values will be generated at runtime |
| 52 | */ |
| 53 | #define __P000 __pgprot(0) |
| 54 | #define __P001 __pgprot(0) |
| 55 | #define __P010 __pgprot(0) |
| 56 | #define __P011 __pgprot(0) |
| 57 | #define __P100 __pgprot(0) |
| 58 | #define __P101 __pgprot(0) |
| 59 | #define __P110 __pgprot(0) |
| 60 | #define __P111 __pgprot(0) |
| 61 | |
| 62 | #define __S000 __pgprot(0) |
| 63 | #define __S001 __pgprot(0) |
| 64 | #define __S010 __pgprot(0) |
| 65 | #define __S011 __pgprot(0) |
| 66 | #define __S100 __pgprot(0) |
| 67 | #define __S101 __pgprot(0) |
| 68 | #define __S110 __pgprot(0) |
| 69 | #define __S111 __pgprot(0) |
| 70 | |
| 71 | extern unsigned long _page_cachable_default; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * ZERO_PAGE is a global shared page that is always zero; used |
| 75 | * for zero-mapped memory areas etc.. |
| 76 | */ |
| 77 | |
| 78 | extern unsigned long empty_zero_page; |
| 79 | extern unsigned long zero_page_mask; |
| 80 | |
| 81 | #define ZERO_PAGE(vaddr) \ |
Franck Bui-Huu | 99e3b94 | 2006-10-19 13:19:59 +0200 | [diff] [blame] | 82 | (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask)))) |
Kirill A. Shutemov | 816422a | 2012-12-12 13:52:36 -0800 | [diff] [blame] | 83 | #define __HAVE_COLOR_ZERO_PAGE |
Hugh Dickins | 62eede6 | 2009-09-21 17:03:34 -0700 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | extern void paging_init(void); |
| 86 | |
| 87 | /* |
| 88 | * Conversion functions: convert a page and protection to a page entry, |
| 89 | * and a page entry and page directory to the page they refer to. |
| 90 | */ |
Franck Bui-Huu | c9d0696 | 2007-03-19 17:36:42 +0100 | [diff] [blame] | 91 | #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd)) |
Ralf Baechle | 970d032 | 2012-10-18 13:54:15 +0200 | [diff] [blame] | 92 | |
| 93 | #define __pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT)) |
| 94 | #ifndef CONFIG_TRANSPARENT_HUGEPAGE |
| 95 | #define pmd_page(pmd) __pmd_page(pmd) |
| 96 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 97 | |
Dave McCracken | 46a82b2 | 2006-09-25 23:31:48 -0700 | [diff] [blame] | 98 | #define pmd_page_vaddr(pmd) pmd_val(pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Markos Chandras | f1014d1 | 2014-07-14 12:47:09 +0100 | [diff] [blame] | 100 | #define htw_stop() \ |
| 101 | do { \ |
| 102 | if (cpu_has_htw) \ |
| 103 | write_c0_pwctl(read_c0_pwctl() & \ |
| 104 | ~(1 << MIPS_PWCTL_PWEN_SHIFT)); \ |
| 105 | } while(0) |
| 106 | |
| 107 | #define htw_start() \ |
| 108 | do { \ |
| 109 | if (cpu_has_htw) \ |
| 110 | write_c0_pwctl(read_c0_pwctl() | \ |
| 111 | (1 << MIPS_PWCTL_PWEN_SHIFT)); \ |
| 112 | } while(0) |
| 113 | |
| 114 | |
| 115 | #define htw_reset() \ |
| 116 | do { \ |
| 117 | if (cpu_has_htw) { \ |
| 118 | htw_stop(); \ |
| 119 | back_to_back_c0_hazard(); \ |
| 120 | htw_start(); \ |
| 121 | back_to_back_c0_hazard(); \ |
| 122 | } \ |
| 123 | } while(0) |
| 124 | |
Lars Persson | 2a4a8b1 | 2014-08-08 15:47:48 +0200 | [diff] [blame] | 125 | extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, |
| 126 | pte_t pteval); |
| 127 | |
Ralf Baechle | 34adb28 | 2014-11-22 00:16:48 +0100 | [diff] [blame] | 128 | #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 129 | |
| 130 | #define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL)) |
| 131 | #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT) |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static inline void set_pte(pte_t *ptep, pte_t pte) |
| 134 | { |
| 135 | ptep->pte_high = pte.pte_high; |
| 136 | smp_wmb(); |
| 137 | ptep->pte_low = pte.pte_low; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 139 | if (pte.pte_low & _PAGE_GLOBAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | pte_t *buddy = ptep_buddy(ptep); |
| 141 | /* |
| 142 | * Make sure the buddy is global too (if it's !none, |
| 143 | * it better already be global) |
| 144 | */ |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 145 | if (pte_none(*buddy)) { |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 146 | buddy->pte_low |= _PAGE_GLOBAL; |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 147 | buddy->pte_high |= _PAGE_GLOBAL; |
| 148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 153 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 154 | pte_t null = __pte(0); |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Preserve global status for the pair */ |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 157 | if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL) |
| 158 | null.pte_low = null.pte_high = _PAGE_GLOBAL; |
| 159 | |
| 160 | set_pte_at(mm, addr, ptep, null); |
Markos Chandras | f1014d1 | 2014-07-14 12:47:09 +0100 | [diff] [blame] | 161 | htw_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | #else |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 164 | |
| 165 | #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL)) |
| 166 | #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT) |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
| 169 | * Certain architectures need to do special things when pte's |
| 170 | * within a page table are directly modified. Thus, the following |
| 171 | * hook is made available. |
| 172 | */ |
| 173 | static inline void set_pte(pte_t *ptep, pte_t pteval) |
| 174 | { |
| 175 | *ptep = pteval; |
| 176 | #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX) |
| 177 | if (pte_val(pteval) & _PAGE_GLOBAL) { |
| 178 | pte_t *buddy = ptep_buddy(ptep); |
| 179 | /* |
| 180 | * Make sure the buddy is global too (if it's !none, |
| 181 | * it better already be global) |
| 182 | */ |
| 183 | if (pte_none(*buddy)) |
| 184 | pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL; |
| 185 | } |
| 186 | #endif |
| 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 190 | { |
| 191 | #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX) |
| 192 | /* Preserve global status for the pair */ |
| 193 | if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL) |
| 194 | set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL)); |
| 195 | else |
| 196 | #endif |
| 197 | set_pte_at(mm, addr, ptep, __pte(0)); |
Markos Chandras | f1014d1 | 2014-07-14 12:47:09 +0100 | [diff] [blame] | 198 | htw_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | #endif |
| 201 | |
| 202 | /* |
Ralf Baechle | c6e8b58 | 2005-02-10 12:19:59 +0000 | [diff] [blame] | 203 | * (pmds are folded into puds so this doesn't get actually called, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | * but the define is needed for a generic inline function.) |
| 205 | */ |
| 206 | #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0) |
Ralf Baechle | c6e8b58 | 2005-02-10 12:19:59 +0000 | [diff] [blame] | 207 | |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 208 | #ifndef __PAGETABLE_PMD_FOLDED |
Ralf Baechle | c6e8b58 | 2005-02-10 12:19:59 +0000 | [diff] [blame] | 209 | /* |
| 210 | * (puds are folded into pgds so this doesn't get actually called, |
| 211 | * but the define is needed for a generic inline function.) |
| 212 | */ |
| 213 | #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0) |
| 214 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Ralf Baechle | 5ff9747 | 2007-08-01 15:25:28 +0100 | [diff] [blame] | 216 | #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1) |
| 217 | #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1) |
| 218 | #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Ralf Baechle | 9975e77 | 2007-08-13 12:44:41 +0100 | [diff] [blame] | 220 | /* |
| 221 | * We used to declare this array with size but gcc 3.3 and older are not able |
| 222 | * to find that this expression is a constant, so the size is dropped. |
| 223 | */ |
| 224 | extern pgd_t swapper_pg_dir[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * The following only work if pte_present() is true. |
| 228 | * Undefined behaviour if not.. |
| 229 | */ |
Ralf Baechle | 34adb28 | 2014-11-22 00:16:48 +0100 | [diff] [blame] | 230 | #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 231 | static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; } |
| 232 | static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; } |
| 233 | static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; } |
| 234 | static inline int pte_file(pte_t pte) { return pte.pte_low & _PAGE_FILE; } |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | static inline pte_t pte_wrprotect(pte_t pte) |
| 237 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 238 | pte.pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE); |
| 239 | pte.pte_high &= ~_PAGE_SILENT_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | return pte; |
| 241 | } |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | static inline pte_t pte_mkclean(pte_t pte) |
| 244 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 245 | pte.pte_low &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE); |
| 246 | pte.pte_high &= ~_PAGE_SILENT_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return pte; |
| 248 | } |
| 249 | |
| 250 | static inline pte_t pte_mkold(pte_t pte) |
| 251 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 252 | pte.pte_low &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ); |
| 253 | pte.pte_high &= ~_PAGE_SILENT_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return pte; |
| 255 | } |
| 256 | |
| 257 | static inline pte_t pte_mkwrite(pte_t pte) |
| 258 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 259 | pte.pte_low |= _PAGE_WRITE; |
| 260 | if (pte.pte_low & _PAGE_MODIFIED) { |
| 261 | pte.pte_low |= _PAGE_SILENT_WRITE; |
| 262 | pte.pte_high |= _PAGE_SILENT_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | return pte; |
| 265 | } |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | static inline pte_t pte_mkdirty(pte_t pte) |
| 268 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 269 | pte.pte_low |= _PAGE_MODIFIED; |
| 270 | if (pte.pte_low & _PAGE_WRITE) { |
| 271 | pte.pte_low |= _PAGE_SILENT_WRITE; |
| 272 | pte.pte_high |= _PAGE_SILENT_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } |
| 274 | return pte; |
| 275 | } |
| 276 | |
| 277 | static inline pte_t pte_mkyoung(pte_t pte) |
| 278 | { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 279 | pte.pte_low |= _PAGE_ACCESSED; |
Ilpo Järvinen | 057229f | 2008-05-02 14:08:20 +0300 | [diff] [blame] | 280 | if (pte.pte_low & _PAGE_READ) { |
Sergei Shtylyov | 6e95389 | 2006-04-16 23:27:21 +0400 | [diff] [blame] | 281 | pte.pte_low |= _PAGE_SILENT_READ; |
| 282 | pte.pte_high |= _PAGE_SILENT_READ; |
Ilpo Järvinen | 057229f | 2008-05-02 14:08:20 +0300 | [diff] [blame] | 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | return pte; |
| 285 | } |
| 286 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; } |
| 288 | static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; } |
| 289 | static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } |
| 290 | static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } |
| 291 | |
| 292 | static inline pte_t pte_wrprotect(pte_t pte) |
| 293 | { |
| 294 | pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE); |
| 295 | return pte; |
| 296 | } |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | static inline pte_t pte_mkclean(pte_t pte) |
| 299 | { |
| 300 | pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE); |
| 301 | return pte; |
| 302 | } |
| 303 | |
| 304 | static inline pte_t pte_mkold(pte_t pte) |
| 305 | { |
| 306 | pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ); |
| 307 | return pte; |
| 308 | } |
| 309 | |
| 310 | static inline pte_t pte_mkwrite(pte_t pte) |
| 311 | { |
| 312 | pte_val(pte) |= _PAGE_WRITE; |
| 313 | if (pte_val(pte) & _PAGE_MODIFIED) |
| 314 | pte_val(pte) |= _PAGE_SILENT_WRITE; |
| 315 | return pte; |
| 316 | } |
| 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | static inline pte_t pte_mkdirty(pte_t pte) |
| 319 | { |
| 320 | pte_val(pte) |= _PAGE_MODIFIED; |
| 321 | if (pte_val(pte) & _PAGE_WRITE) |
| 322 | pte_val(pte) |= _PAGE_SILENT_WRITE; |
| 323 | return pte; |
| 324 | } |
| 325 | |
| 326 | static inline pte_t pte_mkyoung(pte_t pte) |
| 327 | { |
| 328 | pte_val(pte) |= _PAGE_ACCESSED; |
Steven J. Hill | 05857c6 | 2012-09-13 16:51:46 -0500 | [diff] [blame] | 329 | if (cpu_has_rixi) { |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 330 | if (!(pte_val(pte) & _PAGE_NO_READ)) |
| 331 | pte_val(pte) |= _PAGE_SILENT_READ; |
| 332 | } else { |
| 333 | if (pte_val(pte) & _PAGE_READ) |
| 334 | pte_val(pte) |= _PAGE_SILENT_READ; |
| 335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return pte; |
| 337 | } |
David Daney | dd79439 | 2009-05-27 17:47:43 -0700 | [diff] [blame] | 338 | |
| 339 | #ifdef _PAGE_HUGE |
| 340 | static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; } |
| 341 | |
| 342 | static inline pte_t pte_mkhuge(pte_t pte) |
| 343 | { |
| 344 | pte_val(pte) |= _PAGE_HUGE; |
| 345 | return pte; |
| 346 | } |
| 347 | #endif /* _PAGE_HUGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | #endif |
Nick Piggin | 7e67513 | 2008-04-28 02:13:00 -0700 | [diff] [blame] | 349 | static inline int pte_special(pte_t pte) { return 0; } |
| 350 | static inline pte_t pte_mkspecial(pte_t pte) { return pte; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 353 | * Macro to make mark a page protection value as "uncacheable". Note |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | * that "protection" is really a misnomer here as the protection value |
| 355 | * contains the memory attribute bits, dirty bits, and various other |
| 356 | * bits as well. |
| 357 | */ |
| 358 | #define pgprot_noncached pgprot_noncached |
| 359 | |
| 360 | static inline pgprot_t pgprot_noncached(pgprot_t _prot) |
| 361 | { |
| 362 | unsigned long prot = pgprot_val(_prot); |
| 363 | |
| 364 | prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED; |
| 365 | |
| 366 | return __pgprot(prot); |
| 367 | } |
| 368 | |
Markos Chandras | 4b050ba | 2014-07-18 10:51:33 +0100 | [diff] [blame] | 369 | static inline pgprot_t pgprot_writecombine(pgprot_t _prot) |
| 370 | { |
| 371 | unsigned long prot = pgprot_val(_prot); |
| 372 | |
| 373 | /* cpu_data[0].writecombine is already shifted by _CACHE_SHIFT */ |
| 374 | prot = (prot & ~_CACHE_MASK) | cpu_data[0].writecombine; |
| 375 | |
| 376 | return __pgprot(prot); |
| 377 | } |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* |
| 380 | * Conversion functions: convert a page and protection to a page entry, |
| 381 | * and a page entry and page directory to the page they refer to. |
| 382 | */ |
| 383 | #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) |
| 384 | |
Ralf Baechle | 34adb28 | 2014-11-22 00:16:48 +0100 | [diff] [blame] | 385 | #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 387 | { |
Sergei Shtylyov | 79e0bc3 | 2006-05-03 22:56:43 +0400 | [diff] [blame] | 388 | pte.pte_low &= _PAGE_CHG_MASK; |
| 389 | pte.pte_high &= ~0x3f; |
| 390 | pte.pte_low |= pgprot_val(newprot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | pte.pte_high |= pgprot_val(newprot) & 0x3f; |
| 392 | return pte; |
| 393 | } |
| 394 | #else |
| 395 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 396 | { |
| 397 | return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)); |
| 398 | } |
| 399 | #endif |
| 400 | |
| 401 | |
| 402 | extern void __update_tlb(struct vm_area_struct *vma, unsigned long address, |
| 403 | pte_t pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | static inline void update_mmu_cache(struct vm_area_struct *vma, |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 406 | unsigned long address, pte_t *ptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 408 | pte_t pte = *ptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | __update_tlb(vma, address, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Ralf Baechle | 970d032 | 2012-10-18 13:54:15 +0200 | [diff] [blame] | 412 | static inline void update_mmu_cache_pmd(struct vm_area_struct *vma, |
| 413 | unsigned long address, pmd_t *pmdp) |
| 414 | { |
| 415 | pte_t pte = *(pte_t *)pmdp; |
| 416 | |
| 417 | __update_tlb(vma, address, pte); |
| 418 | } |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | #define kern_addr_valid(addr) (1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Ralf Baechle | 34adb28 | 2014-11-22 00:16:48 +0100 | [diff] [blame] | 422 | #ifdef CONFIG_PHYS_ADDR_T_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot); |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | static inline int io_remap_pfn_range(struct vm_area_struct *vma, |
| 426 | unsigned long vaddr, |
| 427 | unsigned long pfn, |
| 428 | unsigned long size, |
| 429 | pgprot_t prot) |
| 430 | { |
Ralf Baechle | 15d45cc | 2014-11-22 00:22:09 +0100 | [diff] [blame^] | 431 | phys_addr_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size); |
Thiemo Seufer | ac5d8c0 | 2005-04-11 12:24:16 +0000 | [diff] [blame] | 432 | return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
Al Viro | 40d158e | 2013-05-11 12:13:10 -0400 | [diff] [blame] | 434 | #define io_remap_pfn_range io_remap_pfn_range |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | #endif |
| 436 | |
Ralf Baechle | 970d032 | 2012-10-18 13:54:15 +0200 | [diff] [blame] | 437 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 438 | |
| 439 | extern int has_transparent_hugepage(void); |
| 440 | |
| 441 | static inline int pmd_trans_huge(pmd_t pmd) |
| 442 | { |
| 443 | return !!(pmd_val(pmd) & _PAGE_HUGE); |
| 444 | } |
| 445 | |
| 446 | static inline pmd_t pmd_mkhuge(pmd_t pmd) |
| 447 | { |
| 448 | pmd_val(pmd) |= _PAGE_HUGE; |
| 449 | |
| 450 | return pmd; |
| 451 | } |
| 452 | |
| 453 | static inline int pmd_trans_splitting(pmd_t pmd) |
| 454 | { |
| 455 | return !!(pmd_val(pmd) & _PAGE_SPLITTING); |
| 456 | } |
| 457 | |
| 458 | static inline pmd_t pmd_mksplitting(pmd_t pmd) |
| 459 | { |
| 460 | pmd_val(pmd) |= _PAGE_SPLITTING; |
| 461 | |
| 462 | return pmd; |
| 463 | } |
| 464 | |
| 465 | extern void set_pmd_at(struct mm_struct *mm, unsigned long addr, |
| 466 | pmd_t *pmdp, pmd_t pmd); |
| 467 | |
| 468 | #define __HAVE_ARCH_PMDP_SPLITTING_FLUSH |
| 469 | /* Extern to avoid header file madness */ |
| 470 | extern void pmdp_splitting_flush(struct vm_area_struct *vma, |
| 471 | unsigned long address, |
| 472 | pmd_t *pmdp); |
| 473 | |
| 474 | #define __HAVE_ARCH_PMD_WRITE |
| 475 | static inline int pmd_write(pmd_t pmd) |
| 476 | { |
| 477 | return !!(pmd_val(pmd) & _PAGE_WRITE); |
| 478 | } |
| 479 | |
| 480 | static inline pmd_t pmd_wrprotect(pmd_t pmd) |
| 481 | { |
| 482 | pmd_val(pmd) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE); |
| 483 | return pmd; |
| 484 | } |
| 485 | |
| 486 | static inline pmd_t pmd_mkwrite(pmd_t pmd) |
| 487 | { |
| 488 | pmd_val(pmd) |= _PAGE_WRITE; |
| 489 | if (pmd_val(pmd) & _PAGE_MODIFIED) |
| 490 | pmd_val(pmd) |= _PAGE_SILENT_WRITE; |
| 491 | |
| 492 | return pmd; |
| 493 | } |
| 494 | |
| 495 | static inline int pmd_dirty(pmd_t pmd) |
| 496 | { |
| 497 | return !!(pmd_val(pmd) & _PAGE_MODIFIED); |
| 498 | } |
| 499 | |
| 500 | static inline pmd_t pmd_mkclean(pmd_t pmd) |
| 501 | { |
| 502 | pmd_val(pmd) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE); |
| 503 | return pmd; |
| 504 | } |
| 505 | |
| 506 | static inline pmd_t pmd_mkdirty(pmd_t pmd) |
| 507 | { |
| 508 | pmd_val(pmd) |= _PAGE_MODIFIED; |
| 509 | if (pmd_val(pmd) & _PAGE_WRITE) |
| 510 | pmd_val(pmd) |= _PAGE_SILENT_WRITE; |
| 511 | |
| 512 | return pmd; |
| 513 | } |
| 514 | |
| 515 | static inline int pmd_young(pmd_t pmd) |
| 516 | { |
| 517 | return !!(pmd_val(pmd) & _PAGE_ACCESSED); |
| 518 | } |
| 519 | |
| 520 | static inline pmd_t pmd_mkold(pmd_t pmd) |
| 521 | { |
| 522 | pmd_val(pmd) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ); |
| 523 | |
| 524 | return pmd; |
| 525 | } |
| 526 | |
| 527 | static inline pmd_t pmd_mkyoung(pmd_t pmd) |
| 528 | { |
| 529 | pmd_val(pmd) |= _PAGE_ACCESSED; |
| 530 | |
| 531 | if (cpu_has_rixi) { |
| 532 | if (!(pmd_val(pmd) & _PAGE_NO_READ)) |
| 533 | pmd_val(pmd) |= _PAGE_SILENT_READ; |
| 534 | } else { |
| 535 | if (pmd_val(pmd) & _PAGE_READ) |
| 536 | pmd_val(pmd) |= _PAGE_SILENT_READ; |
| 537 | } |
| 538 | |
| 539 | return pmd; |
| 540 | } |
| 541 | |
| 542 | /* Extern to avoid header file madness */ |
| 543 | extern pmd_t mk_pmd(struct page *page, pgprot_t prot); |
| 544 | |
| 545 | static inline unsigned long pmd_pfn(pmd_t pmd) |
| 546 | { |
| 547 | return pmd_val(pmd) >> _PFN_SHIFT; |
| 548 | } |
| 549 | |
| 550 | static inline struct page *pmd_page(pmd_t pmd) |
| 551 | { |
| 552 | if (pmd_trans_huge(pmd)) |
| 553 | return pfn_to_page(pmd_pfn(pmd)); |
| 554 | |
| 555 | return pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT); |
| 556 | } |
| 557 | |
| 558 | static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) |
| 559 | { |
| 560 | pmd_val(pmd) = (pmd_val(pmd) & _PAGE_CHG_MASK) | pgprot_val(newprot); |
| 561 | return pmd; |
| 562 | } |
| 563 | |
| 564 | static inline pmd_t pmd_mknotpresent(pmd_t pmd) |
| 565 | { |
| 566 | pmd_val(pmd) &= ~(_PAGE_PRESENT | _PAGE_VALID | _PAGE_DIRTY); |
| 567 | |
| 568 | return pmd; |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * The generic version pmdp_get_and_clear uses a version of pmd_clear() with a |
| 573 | * different prototype. |
| 574 | */ |
| 575 | #define __HAVE_ARCH_PMDP_GET_AND_CLEAR |
| 576 | static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm, |
| 577 | unsigned long address, pmd_t *pmdp) |
| 578 | { |
| 579 | pmd_t old = *pmdp; |
| 580 | |
| 581 | pmd_clear(pmdp); |
| 582 | |
| 583 | return old; |
| 584 | } |
| 585 | |
| 586 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | #include <asm-generic/pgtable.h> |
| 589 | |
| 590 | /* |
Wu Zhangjin | 22f1fdf | 2009-11-11 13:59:23 +0800 | [diff] [blame] | 591 | * uncached accelerated TLB map for video memory access |
| 592 | */ |
| 593 | #ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED |
| 594 | #define __HAVE_PHYS_MEM_ACCESS_PROT |
| 595 | |
| 596 | struct file; |
| 597 | pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, |
| 598 | unsigned long size, pgprot_t vma_prot); |
| 599 | int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, |
| 600 | unsigned long size, pgprot_t *vma_prot); |
| 601 | #endif |
| 602 | |
| 603 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | * We provide our own get_unmapped area to cope with the virtual aliasing |
| 605 | * constraints placed on us by the cache architecture. |
| 606 | */ |
| 607 | #define HAVE_ARCH_UNMAPPED_AREA |
Jian Peng | d0be89f | 2011-05-17 12:27:49 -0700 | [diff] [blame] | 608 | #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | /* |
| 611 | * No page table caches to initialise |
| 612 | */ |
| 613 | #define pgtable_cache_init() do { } while (0) |
| 614 | |
| 615 | #endif /* _ASM_PGTABLE_H */ |