blob: f6de4f49b1b2d4b8596604e337c7e4af6884b7ce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Minyard5bbea362013-04-08 16:06:35 +020011#include <linux/mm_types.h>
Ralf Baechle970d0322012-10-18 13:54:15 +020012#include <linux/mmzone.h>
Ralf Baechle875d43e2005-09-03 15:56:16 -070013#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/pgtable-32.h>
15#endif
Ralf Baechle875d43e2005-09-03 15:56:16 -070016#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/pgtable-64.h>
18#endif
19
Pete Popovf10fae02005-07-14 00:17:05 +000020#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/pgtable-bits.h>
22
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080023struct mm_struct;
24struct vm_area_struct;
25
Paul Burton780602d2016-04-19 09:25:03 +010026#define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_NO_READ | \
27 _CACHE_CACHABLE_NONCOHERENT)
28#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_WRITE | \
Chris Dearman35133692007-09-19 00:58:24 +010029 _page_cachable_default)
Paul Burton780602d2016-04-19 09:25:03 +010030#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_NO_EXEC | \
Steven J. Hillbe0c37c2015-02-26 18:16:37 -060031 _page_cachable_default)
Paul Burton780602d2016-04-19 09:25:03 +010032#define PAGE_READONLY __pgprot(_PAGE_PRESENT | \
Chris Dearman35133692007-09-19 00:58:24 +010033 _page_cachable_default)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
Chris Dearman35133692007-09-19 00:58:24 +010035 _PAGE_GLOBAL | _page_cachable_default)
Paul Burtone2a9e5a2014-03-03 12:08:40 +000036#define PAGE_KERNEL_NC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
37 _PAGE_GLOBAL | _CACHE_CACHABLE_NONCOHERENT)
Paul Burton780602d2016-04-19 09:25:03 +010038#define PAGE_USERIO __pgprot(_PAGE_PRESENT | _PAGE_WRITE | \
Chris Dearman35133692007-09-19 00:58:24 +010039 _page_cachable_default)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
41 __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
42
43/*
David Daney6dd93442010-02-10 15:12:47 -080044 * 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 Torvalds1da177e2005-04-16 15:20:36 -070048 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Chris Dearman35133692007-09-19 00:58:24 +010050/*
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
72extern unsigned long _page_cachable_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * ZERO_PAGE is a global shared page that is always zero; used
76 * for zero-mapped memory areas etc..
77 */
78
79extern unsigned long empty_zero_page;
80extern unsigned long zero_page_mask;
81
82#define ZERO_PAGE(vaddr) \
Franck Bui-Huu99e3b942006-10-19 13:19:59 +020083 (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
Kirill A. Shutemov816422a2012-12-12 13:52:36 -080084#define __HAVE_COLOR_ZERO_PAGE
Hugh Dickins62eede62009-09-21 17:03:34 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086extern 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-Huuc9d06962007-03-19 17:36:42 +010092#define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
Ralf Baechle970d0322012-10-18 13:54:15 +020093
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 McCracken46a82b22006-09-25 23:31:48 -070099#define pmd_page_vaddr(pmd) pmd_val(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Markos Chandrasf1014d12014-07-14 12:47:09 +0100101#define htw_stop() \
102do { \
Markos Chandrased4cbc82015-01-26 13:04:33 +0000103 unsigned long flags; \
104 \
Markos Chandras461d15972015-01-26 09:40:34 +0000105 if (cpu_has_htw) { \
Markos Chandrased4cbc82015-01-26 13:04:33 +0000106 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 Chandras461d15972015-01-26 09:40:34 +0000113 } \
Markos Chandrasf1014d12014-07-14 12:47:09 +0100114} while(0)
115
116#define htw_start() \
117do { \
Markos Chandrased4cbc82015-01-26 13:04:33 +0000118 unsigned long flags; \
119 \
Markos Chandrasf1014d12014-07-14 12:47:09 +0100120 if (cpu_has_htw) { \
Markos Chandrased4cbc82015-01-26 13:04:33 +0000121 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 Chandrasf1014d12014-07-14 12:47:09 +0100128 } \
129} while(0)
130
Paul Burton37d22a0d2016-03-01 02:37:59 +0000131static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
132 pte_t *ptep, pte_t pteval);
133
Ralf Baechle34adb282014-11-22 00:16:48 +0100134#if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400135
Steven J. Hillc5b36782015-02-26 18:16:38 -0600136#define pte_none(pte) (!(((pte).pte_high) & ~_PAGE_GLOBAL))
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400137#define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
Paul Burton37d22a0d2016-03-01 02:37:59 +0000138#define pte_no_exec(pte) ((pte).pte_low & _PAGE_NO_EXEC)
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static inline void set_pte(pte_t *ptep, pte_t pte)
141{
142 ptep->pte_high = pte.pte_high;
143 smp_wmb();
144 ptep->pte_low = pte.pte_low;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Steven J. Hillc5b36782015-02-26 18:16:38 -0600146 if (pte.pte_high & _PAGE_GLOBAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 pte_t *buddy = ptep_buddy(ptep);
148 /*
149 * Make sure the buddy is global too (if it's !none,
150 * it better already be global)
151 */
Steven J. Hillc5b36782015-02-26 18:16:38 -0600152 if (pte_none(*buddy))
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400153 buddy->pte_high |= _PAGE_GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
158{
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400159 pte_t null = __pte(0);
160
Markos Chandrasfde35382015-01-26 09:40:36 +0000161 htw_stop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* Preserve global status for the pair */
Steven J. Hillc5b36782015-02-26 18:16:38 -0600163 if (ptep_buddy(ptep)->pte_high & _PAGE_GLOBAL)
164 null.pte_high = _PAGE_GLOBAL;
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400165
166 set_pte_at(mm, addr, ptep, null);
Markos Chandrasfde35382015-01-26 09:40:36 +0000167 htw_start();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169#else
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400170
171#define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
172#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
Paul Burton37d22a0d2016-03-01 02:37:59 +0000173#define pte_no_exec(pte) (pte_val(pte) & _PAGE_NO_EXEC)
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/*
176 * Certain architectures need to do special things when pte's
177 * within a page table are directly modified. Thus, the following
178 * hook is made available.
179 */
180static inline void set_pte(pte_t *ptep, pte_t pteval)
181{
182 *ptep = pteval;
183#if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
184 if (pte_val(pteval) & _PAGE_GLOBAL) {
185 pte_t *buddy = ptep_buddy(ptep);
186 /*
187 * Make sure the buddy is global too (if it's !none,
188 * it better already be global)
189 */
David Daney46011e62015-08-03 17:48:43 -0700190#ifdef CONFIG_SMP
191 /*
192 * For SMP, multiple CPUs can race, so we need to do
193 * this atomically.
194 */
David Daney46011e62015-08-03 17:48:43 -0700195 unsigned long page_global = _PAGE_GLOBAL;
196 unsigned long tmp;
197
Joshua Kinard12863932015-09-07 06:42:30 -0400198 if (kernel_uses_llsc && R10000_LLSC_WAR) {
199 __asm__ __volatile__ (
200 " .set arch=r4000 \n"
201 " .set push \n"
202 " .set noreorder \n"
203 "1:" __LL "%[tmp], %[buddy] \n"
204 " bnez %[tmp], 2f \n"
205 " or %[tmp], %[tmp], %[global] \n"
206 __SC "%[tmp], %[buddy] \n"
207 " beqzl %[tmp], 1b \n"
208 " nop \n"
209 "2: \n"
210 " .set pop \n"
211 " .set mips0 \n"
212 : [buddy] "+m" (buddy->pte), [tmp] "=&r" (tmp)
David Daney46011e62015-08-03 17:48:43 -0700213 : [global] "r" (page_global));
Joshua Kinard12863932015-09-07 06:42:30 -0400214 } else if (kernel_uses_llsc) {
215 __asm__ __volatile__ (
216 " .set "MIPS_ISA_ARCH_LEVEL" \n"
217 " .set push \n"
218 " .set noreorder \n"
219 "1:" __LL "%[tmp], %[buddy] \n"
220 " bnez %[tmp], 2f \n"
221 " or %[tmp], %[tmp], %[global] \n"
222 __SC "%[tmp], %[buddy] \n"
223 " beqz %[tmp], 1b \n"
224 " nop \n"
225 "2: \n"
226 " .set pop \n"
227 " .set mips0 \n"
228 : [buddy] "+m" (buddy->pte), [tmp] "=&r" (tmp)
229 : [global] "r" (page_global));
230 }
David Daney46011e62015-08-03 17:48:43 -0700231#else /* !CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 if (pte_none(*buddy))
233 pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
David Daney46011e62015-08-03 17:48:43 -0700234#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
236#endif
237}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
240{
Markos Chandrasfde35382015-01-26 09:40:36 +0000241 htw_stop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
243 /* Preserve global status for the pair */
244 if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
245 set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
246 else
247#endif
248 set_pte_at(mm, addr, ptep, __pte(0));
Markos Chandrasfde35382015-01-26 09:40:36 +0000249 htw_start();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251#endif
252
Paul Burton37d22a0d2016-03-01 02:37:59 +0000253static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
254 pte_t *ptep, pte_t pteval)
255{
256 extern void __update_cache(unsigned long address, pte_t pte);
257
258 if (!pte_present(pteval))
259 goto cache_sync_done;
260
261 if (pte_present(*ptep) && (pte_pfn(*ptep) == pte_pfn(pteval)))
262 goto cache_sync_done;
263
264 __update_cache(addr, pteval);
265cache_sync_done:
266 set_pte(ptep, pteval);
267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269/*
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000270 * (pmds are folded into puds so this doesn't get actually called,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 * but the define is needed for a generic inline function.)
272 */
273#define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000274
David Daney325f8a02009-12-04 13:52:36 -0800275#ifndef __PAGETABLE_PMD_FOLDED
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000276/*
277 * (puds are folded into pgds so this doesn't get actually called,
278 * but the define is needed for a generic inline function.)
279 */
280#define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
281#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Ralf Baechle5ff97472007-08-01 15:25:28 +0100283#define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
284#define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
285#define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Ralf Baechle9975e772007-08-13 12:44:41 +0100287/*
288 * We used to declare this array with size but gcc 3.3 and older are not able
289 * to find that this expression is a constant, so the size is dropped.
290 */
291extern pgd_t swapper_pg_dir[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293/*
294 * The following only work if pte_present() is true.
295 * Undefined behaviour if not..
296 */
Ralf Baechle34adb282014-11-22 00:16:48 +0100297#if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400298static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; }
299static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; }
300static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; }
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302static inline pte_t pte_wrprotect(pte_t pte)
303{
Steven J. Hillc5b36782015-02-26 18:16:38 -0600304 pte.pte_low &= ~_PAGE_WRITE;
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400305 pte.pte_high &= ~_PAGE_SILENT_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 return pte;
307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309static inline pte_t pte_mkclean(pte_t pte)
310{
Steven J. Hillc5b36782015-02-26 18:16:38 -0600311 pte.pte_low &= ~_PAGE_MODIFIED;
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400312 pte.pte_high &= ~_PAGE_SILENT_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return pte;
314}
315
316static inline pte_t pte_mkold(pte_t pte)
317{
Steven J. Hillc5b36782015-02-26 18:16:38 -0600318 pte.pte_low &= ~_PAGE_ACCESSED;
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400319 pte.pte_high &= ~_PAGE_SILENT_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return pte;
321}
322
323static inline pte_t pte_mkwrite(pte_t pte)
324{
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400325 pte.pte_low |= _PAGE_WRITE;
Steven J. Hillc5b36782015-02-26 18:16:38 -0600326 if (pte.pte_low & _PAGE_MODIFIED)
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400327 pte.pte_high |= _PAGE_SILENT_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return pte;
329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331static inline pte_t pte_mkdirty(pte_t pte)
332{
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400333 pte.pte_low |= _PAGE_MODIFIED;
Steven J. Hillc5b36782015-02-26 18:16:38 -0600334 if (pte.pte_low & _PAGE_WRITE)
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400335 pte.pte_high |= _PAGE_SILENT_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return pte;
337}
338
339static inline pte_t pte_mkyoung(pte_t pte)
340{
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400341 pte.pte_low |= _PAGE_ACCESSED;
Paul Burton780602d2016-04-19 09:25:03 +0100342 if (!(pte.pte_low & _PAGE_NO_READ))
Sergei Shtylyov6e953892006-04-16 23:27:21 +0400343 pte.pte_high |= _PAGE_SILENT_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return pte;
345}
346#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
348static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
349static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351static inline pte_t pte_wrprotect(pte_t pte)
352{
353 pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
354 return pte;
355}
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357static inline pte_t pte_mkclean(pte_t pte)
358{
Steven J. Hill77a5c592014-11-13 09:52:01 -0600359 pte_val(pte) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return pte;
361}
362
363static inline pte_t pte_mkold(pte_t pte)
364{
Steven J. Hill77a5c592014-11-13 09:52:01 -0600365 pte_val(pte) &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return pte;
367}
368
369static inline pte_t pte_mkwrite(pte_t pte)
370{
371 pte_val(pte) |= _PAGE_WRITE;
372 if (pte_val(pte) & _PAGE_MODIFIED)
373 pte_val(pte) |= _PAGE_SILENT_WRITE;
374 return pte;
375}
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377static inline pte_t pte_mkdirty(pte_t pte)
378{
379 pte_val(pte) |= _PAGE_MODIFIED;
380 if (pte_val(pte) & _PAGE_WRITE)
381 pte_val(pte) |= _PAGE_SILENT_WRITE;
382 return pte;
383}
384
385static inline pte_t pte_mkyoung(pte_t pte)
386{
387 pte_val(pte) |= _PAGE_ACCESSED;
Steven J. Hillbe0c37c2015-02-26 18:16:37 -0600388 if (!(pte_val(pte) & _PAGE_NO_READ))
389 pte_val(pte) |= _PAGE_SILENT_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return pte;
391}
David Daneydd794392009-05-27 17:47:43 -0700392
Steven J. Hill05f98832015-02-19 10:18:50 -0600393#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
David Daneydd794392009-05-27 17:47:43 -0700394static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
395
396static inline pte_t pte_mkhuge(pte_t pte)
397{
398 pte_val(pte) |= _PAGE_HUGE;
399 return pte;
400}
Steven J. Hill05f98832015-02-19 10:18:50 -0600401#endif /* CONFIG_MIPS_HUGE_TLB_SUPPORT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#endif
Nick Piggin7e675132008-04-28 02:13:00 -0700403static inline int pte_special(pte_t pte) { return 0; }
404static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406/*
Ralf Baechle70342282013-01-22 12:59:30 +0100407 * Macro to make mark a page protection value as "uncacheable". Note
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 * that "protection" is really a misnomer here as the protection value
409 * contains the memory attribute bits, dirty bits, and various other
410 * bits as well.
411 */
412#define pgprot_noncached pgprot_noncached
413
414static inline pgprot_t pgprot_noncached(pgprot_t _prot)
415{
416 unsigned long prot = pgprot_val(_prot);
417
418 prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
419
420 return __pgprot(prot);
421}
422
Alex Smithc4687b12015-07-24 16:16:10 +0100423#define pgprot_writecombine pgprot_writecombine
424
Markos Chandras4b050ba2014-07-18 10:51:33 +0100425static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
426{
427 unsigned long prot = pgprot_val(_prot);
428
429 /* cpu_data[0].writecombine is already shifted by _CACHE_SHIFT */
430 prot = (prot & ~_CACHE_MASK) | cpu_data[0].writecombine;
431
432 return __pgprot(prot);
433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435/*
436 * Conversion functions: convert a page and protection to a page entry,
437 * and a page entry and page directory to the page they refer to.
438 */
439#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
440
Ralf Baechle34adb282014-11-22 00:16:48 +0100441#if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
443{
Steven J. Hillc5b36782015-02-26 18:16:38 -0600444 pte.pte_low &= (_PAGE_MODIFIED | _PAGE_ACCESSED | _PFNX_MASK);
Steven J. Hill77a5c592014-11-13 09:52:01 -0600445 pte.pte_high &= (_PFN_MASK | _CACHE_MASK);
Steven J. Hillc5b36782015-02-26 18:16:38 -0600446 pte.pte_low |= pgprot_val(newprot) & ~_PFNX_MASK;
447 pte.pte_high |= pgprot_val(newprot) & ~_PFN_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return pte;
449}
450#else
451static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
452{
453 return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
454}
455#endif
456
457
458extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
459 pte_t pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461static inline void update_mmu_cache(struct vm_area_struct *vma,
Russell King4b3073e2009-12-18 16:40:18 +0000462 unsigned long address, pte_t *ptep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Russell King4b3073e2009-12-18 16:40:18 +0000464 pte_t pte = *ptep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 __update_tlb(vma, address, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
Ralf Baechle970d0322012-10-18 13:54:15 +0200468static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
469 unsigned long address, pmd_t *pmdp)
470{
471 pte_t pte = *(pte_t *)pmdp;
472
473 __update_tlb(vma, address, pte);
474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define kern_addr_valid(addr) (1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Ralf Baechle34adb282014-11-22 00:16:48 +0100478#ifdef CONFIG_PHYS_ADDR_T_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot);
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481static inline int io_remap_pfn_range(struct vm_area_struct *vma,
482 unsigned long vaddr,
483 unsigned long pfn,
484 unsigned long size,
485 pgprot_t prot)
486{
Ralf Baechle15d45cc2014-11-22 00:22:09 +0100487 phys_addr_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size);
Thiemo Seuferac5d8c02005-04-11 12:24:16 +0000488 return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
Al Viro40d158e2013-05-11 12:13:10 -0400490#define io_remap_pfn_range io_remap_pfn_range
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#endif
492
Ralf Baechle970d0322012-10-18 13:54:15 +0200493#ifdef CONFIG_TRANSPARENT_HUGEPAGE
494
495extern int has_transparent_hugepage(void);
496
497static inline int pmd_trans_huge(pmd_t pmd)
498{
499 return !!(pmd_val(pmd) & _PAGE_HUGE);
500}
501
502static inline pmd_t pmd_mkhuge(pmd_t pmd)
503{
504 pmd_val(pmd) |= _PAGE_HUGE;
505
506 return pmd;
507}
508
Ralf Baechle970d0322012-10-18 13:54:15 +0200509extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
510 pmd_t *pmdp, pmd_t pmd);
511
Ralf Baechle970d0322012-10-18 13:54:15 +0200512#define __HAVE_ARCH_PMD_WRITE
513static inline int pmd_write(pmd_t pmd)
514{
515 return !!(pmd_val(pmd) & _PAGE_WRITE);
516}
517
518static inline pmd_t pmd_wrprotect(pmd_t pmd)
519{
520 pmd_val(pmd) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
521 return pmd;
522}
523
524static inline pmd_t pmd_mkwrite(pmd_t pmd)
525{
526 pmd_val(pmd) |= _PAGE_WRITE;
527 if (pmd_val(pmd) & _PAGE_MODIFIED)
528 pmd_val(pmd) |= _PAGE_SILENT_WRITE;
529
530 return pmd;
531}
532
533static inline int pmd_dirty(pmd_t pmd)
534{
535 return !!(pmd_val(pmd) & _PAGE_MODIFIED);
536}
537
538static inline pmd_t pmd_mkclean(pmd_t pmd)
539{
540 pmd_val(pmd) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
541 return pmd;
542}
543
544static inline pmd_t pmd_mkdirty(pmd_t pmd)
545{
546 pmd_val(pmd) |= _PAGE_MODIFIED;
547 if (pmd_val(pmd) & _PAGE_WRITE)
548 pmd_val(pmd) |= _PAGE_SILENT_WRITE;
549
550 return pmd;
551}
552
553static inline int pmd_young(pmd_t pmd)
554{
555 return !!(pmd_val(pmd) & _PAGE_ACCESSED);
556}
557
558static inline pmd_t pmd_mkold(pmd_t pmd)
559{
560 pmd_val(pmd) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
561
562 return pmd;
563}
564
565static inline pmd_t pmd_mkyoung(pmd_t pmd)
566{
567 pmd_val(pmd) |= _PAGE_ACCESSED;
568
Steven J. Hillbe0c37c2015-02-26 18:16:37 -0600569 if (!(pmd_val(pmd) & _PAGE_NO_READ))
570 pmd_val(pmd) |= _PAGE_SILENT_READ;
Ralf Baechle970d0322012-10-18 13:54:15 +0200571
572 return pmd;
573}
574
575/* Extern to avoid header file madness */
576extern pmd_t mk_pmd(struct page *page, pgprot_t prot);
577
578static inline unsigned long pmd_pfn(pmd_t pmd)
579{
580 return pmd_val(pmd) >> _PFN_SHIFT;
581}
582
583static inline struct page *pmd_page(pmd_t pmd)
584{
585 if (pmd_trans_huge(pmd))
586 return pfn_to_page(pmd_pfn(pmd));
587
588 return pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT);
589}
590
591static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
592{
593 pmd_val(pmd) = (pmd_val(pmd) & _PAGE_CHG_MASK) | pgprot_val(newprot);
594 return pmd;
595}
596
597static inline pmd_t pmd_mknotpresent(pmd_t pmd)
598{
599 pmd_val(pmd) &= ~(_PAGE_PRESENT | _PAGE_VALID | _PAGE_DIRTY);
600
601 return pmd;
602}
603
604/*
Aneesh Kumar K.V8809aa22015-06-24 16:57:44 -0700605 * The generic version pmdp_huge_get_and_clear uses a version of pmd_clear() with a
Ralf Baechle970d0322012-10-18 13:54:15 +0200606 * different prototype.
607 */
Aneesh Kumar K.V8809aa22015-06-24 16:57:44 -0700608#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
609static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
610 unsigned long address, pmd_t *pmdp)
Ralf Baechle970d0322012-10-18 13:54:15 +0200611{
612 pmd_t old = *pmdp;
613
614 pmd_clear(pmdp);
615
616 return old;
617}
618
619#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#include <asm-generic/pgtable.h>
622
623/*
Wu Zhangjin22f1fdf2009-11-11 13:59:23 +0800624 * uncached accelerated TLB map for video memory access
625 */
626#ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
627#define __HAVE_PHYS_MEM_ACCESS_PROT
628
629struct file;
630pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
631 unsigned long size, pgprot_t vma_prot);
632int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
633 unsigned long size, pgprot_t *vma_prot);
634#endif
635
636/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 * We provide our own get_unmapped area to cope with the virtual aliasing
638 * constraints placed on us by the cache architecture.
639 */
640#define HAVE_ARCH_UNMAPPED_AREA
Jian Pengd0be89f2011-05-17 12:27:49 -0700641#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643/*
644 * No page table caches to initialise
645 */
646#define pgtable_cache_init() do { } while (0)
647
648#endif /* _ASM_PGTABLE_H */