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