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
6 * Copyright (C) 2003 Ralf Baechle
11 #include <linux/mm_types.h>
12 #include <linux/mmzone.h>
14 #include <asm/pgtable-32.h>
17 #include <asm/pgtable-64.h>
21 #include <asm/pgtable-bits.h>
24 struct vm_area_struct
;
26 #define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT)
27 #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | \
28 _page_cachable_default)
29 #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_NO_EXEC | \
30 _page_cachable_default)
31 #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | \
32 _page_cachable_default)
33 #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
34 _PAGE_GLOBAL | _page_cachable_default)
35 #define PAGE_KERNEL_NC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
36 _PAGE_GLOBAL | _CACHE_CACHABLE_NONCOHERENT)
37 #define PAGE_USERIO __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
38 _page_cachable_default)
39 #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
40 __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
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..
50 * Dummy values to fill the table in mmap.c
51 * The real values will be generated at runtime
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)
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)
71 extern unsigned long _page_cachable_default
;
74 * ZERO_PAGE is a global shared page that is always zero; used
75 * for zero-mapped memory areas etc..
78 extern unsigned long empty_zero_page
;
79 extern unsigned long zero_page_mask
;
81 #define ZERO_PAGE(vaddr) \
82 (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
83 #define __HAVE_COLOR_ZERO_PAGE
85 extern void paging_init(void);
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.
91 #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
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 */
98 #define pmd_page_vaddr(pmd) pmd_val(pmd)
102 unsigned long flags; \
105 local_irq_save(flags); \
106 if(!raw_current_cpu_data.htw_seq++) { \
107 write_c0_pwctl(read_c0_pwctl() & \
108 ~(1 << MIPS_PWCTL_PWEN_SHIFT)); \
109 back_to_back_c0_hazard(); \
111 local_irq_restore(flags); \
115 #define htw_start() \
117 unsigned long flags; \
120 local_irq_save(flags); \
121 if (!--raw_current_cpu_data.htw_seq) { \
122 write_c0_pwctl(read_c0_pwctl() | \
123 (1 << MIPS_PWCTL_PWEN_SHIFT)); \
124 back_to_back_c0_hazard(); \
126 local_irq_restore(flags); \
130 static inline void set_pte_at(struct mm_struct
*mm
, unsigned long addr
,
131 pte_t
*ptep
, pte_t pteval
);
133 #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
135 #define pte_none(pte) (!(((pte).pte_high) & ~_PAGE_GLOBAL))
136 #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
137 #define pte_no_exec(pte) ((pte).pte_low & _PAGE_NO_EXEC)
139 static inline void set_pte(pte_t
*ptep
, pte_t pte
)
141 ptep
->pte_high
= pte
.pte_high
;
143 ptep
->pte_low
= pte
.pte_low
;
145 if (pte
.pte_high
& _PAGE_GLOBAL
) {
146 pte_t
*buddy
= ptep_buddy(ptep
);
148 * Make sure the buddy is global too (if it's !none,
149 * it better already be global)
151 if (pte_none(*buddy
))
152 buddy
->pte_high
|= _PAGE_GLOBAL
;
156 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
158 pte_t null
= __pte(0);
161 /* Preserve global status for the pair */
162 if (ptep_buddy(ptep
)->pte_high
& _PAGE_GLOBAL
)
163 null
.pte_high
= _PAGE_GLOBAL
;
165 set_pte_at(mm
, addr
, ptep
, null
);
170 #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
171 #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
172 #define pte_no_exec(pte) (pte_val(pte) & _PAGE_NO_EXEC)
175 * Certain architectures need to do special things when pte's
176 * within a page table are directly modified. Thus, the following
177 * hook is made available.
179 static inline void set_pte(pte_t
*ptep
, pte_t pteval
)
182 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
183 if (pte_val(pteval
) & _PAGE_GLOBAL
) {
184 pte_t
*buddy
= ptep_buddy(ptep
);
186 * Make sure the buddy is global too (if it's !none,
187 * it better already be global)
191 * For SMP, multiple CPUs can race, so we need to do
195 #define LL_INSN "lld"
196 #define SC_INSN "scd"
197 #else /* CONFIG_32BIT */
201 unsigned long page_global
= _PAGE_GLOBAL
;
204 __asm__
__volatile__ (
207 "1: " LL_INSN
" %[tmp], %[buddy]\n"
209 " or %[tmp], %[tmp], %[global]\n"
210 " " SC_INSN
" %[tmp], %[buddy]\n"
215 : [buddy
] "+m" (buddy
->pte
),
217 : [global
] "r" (page_global
));
218 #else /* !CONFIG_SMP */
219 if (pte_none(*buddy
))
220 pte_val(*buddy
) = pte_val(*buddy
) | _PAGE_GLOBAL
;
221 #endif /* CONFIG_SMP */
226 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
229 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
230 /* Preserve global status for the pair */
231 if (pte_val(*ptep_buddy(ptep
)) & _PAGE_GLOBAL
)
232 set_pte_at(mm
, addr
, ptep
, __pte(_PAGE_GLOBAL
));
235 set_pte_at(mm
, addr
, ptep
, __pte(0));
240 static inline void set_pte_at(struct mm_struct
*mm
, unsigned long addr
,
241 pte_t
*ptep
, pte_t pteval
)
243 extern void __update_cache(unsigned long address
, pte_t pte
);
245 if (!pte_present(pteval
))
246 goto cache_sync_done
;
248 if (pte_present(*ptep
) && (pte_pfn(*ptep
) == pte_pfn(pteval
)))
249 goto cache_sync_done
;
251 __update_cache(addr
, pteval
);
253 set_pte(ptep
, pteval
);
257 * (pmds are folded into puds so this doesn't get actually called,
258 * but the define is needed for a generic inline function.)
260 #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
262 #ifndef __PAGETABLE_PMD_FOLDED
264 * (puds are folded into pgds so this doesn't get actually called,
265 * but the define is needed for a generic inline function.)
267 #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
270 #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
271 #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
272 #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
275 * We used to declare this array with size but gcc 3.3 and older are not able
276 * to find that this expression is a constant, so the size is dropped.
278 extern pgd_t swapper_pg_dir
[];
281 * The following only work if pte_present() is true.
282 * Undefined behaviour if not..
284 #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
285 static inline int pte_write(pte_t pte
) { return pte
.pte_low
& _PAGE_WRITE
; }
286 static inline int pte_dirty(pte_t pte
) { return pte
.pte_low
& _PAGE_MODIFIED
; }
287 static inline int pte_young(pte_t pte
) { return pte
.pte_low
& _PAGE_ACCESSED
; }
289 static inline pte_t
pte_wrprotect(pte_t pte
)
291 pte
.pte_low
&= ~_PAGE_WRITE
;
292 pte
.pte_high
&= ~_PAGE_SILENT_WRITE
;
296 static inline pte_t
pte_mkclean(pte_t pte
)
298 pte
.pte_low
&= ~_PAGE_MODIFIED
;
299 pte
.pte_high
&= ~_PAGE_SILENT_WRITE
;
303 static inline pte_t
pte_mkold(pte_t pte
)
305 pte
.pte_low
&= ~_PAGE_ACCESSED
;
306 pte
.pte_high
&= ~_PAGE_SILENT_READ
;
310 static inline pte_t
pte_mkwrite(pte_t pte
)
312 pte
.pte_low
|= _PAGE_WRITE
;
313 if (pte
.pte_low
& _PAGE_MODIFIED
)
314 pte
.pte_high
|= _PAGE_SILENT_WRITE
;
318 static inline pte_t
pte_mkdirty(pte_t pte
)
320 pte
.pte_low
|= _PAGE_MODIFIED
;
321 if (pte
.pte_low
& _PAGE_WRITE
)
322 pte
.pte_high
|= _PAGE_SILENT_WRITE
;
326 static inline pte_t
pte_mkyoung(pte_t pte
)
328 pte
.pte_low
|= _PAGE_ACCESSED
;
329 if (pte
.pte_low
& _PAGE_READ
)
330 pte
.pte_high
|= _PAGE_SILENT_READ
;
334 static inline int pte_write(pte_t pte
) { return pte_val(pte
) & _PAGE_WRITE
; }
335 static inline int pte_dirty(pte_t pte
) { return pte_val(pte
) & _PAGE_MODIFIED
; }
336 static inline int pte_young(pte_t pte
) { return pte_val(pte
) & _PAGE_ACCESSED
; }
338 static inline pte_t
pte_wrprotect(pte_t pte
)
340 pte_val(pte
) &= ~(_PAGE_WRITE
| _PAGE_SILENT_WRITE
);
344 static inline pte_t
pte_mkclean(pte_t pte
)
346 pte_val(pte
) &= ~(_PAGE_MODIFIED
| _PAGE_SILENT_WRITE
);
350 static inline pte_t
pte_mkold(pte_t pte
)
352 pte_val(pte
) &= ~(_PAGE_ACCESSED
| _PAGE_SILENT_READ
);
356 static inline pte_t
pte_mkwrite(pte_t pte
)
358 pte_val(pte
) |= _PAGE_WRITE
;
359 if (pte_val(pte
) & _PAGE_MODIFIED
)
360 pte_val(pte
) |= _PAGE_SILENT_WRITE
;
364 static inline pte_t
pte_mkdirty(pte_t pte
)
366 pte_val(pte
) |= _PAGE_MODIFIED
;
367 if (pte_val(pte
) & _PAGE_WRITE
)
368 pte_val(pte
) |= _PAGE_SILENT_WRITE
;
372 static inline pte_t
pte_mkyoung(pte_t pte
)
374 pte_val(pte
) |= _PAGE_ACCESSED
;
375 #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
376 if (!(pte_val(pte
) & _PAGE_NO_READ
))
377 pte_val(pte
) |= _PAGE_SILENT_READ
;
380 if (pte_val(pte
) & _PAGE_READ
)
381 pte_val(pte
) |= _PAGE_SILENT_READ
;
385 #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
386 static inline int pte_huge(pte_t pte
) { return pte_val(pte
) & _PAGE_HUGE
; }
388 static inline pte_t
pte_mkhuge(pte_t pte
)
390 pte_val(pte
) |= _PAGE_HUGE
;
393 #endif /* CONFIG_MIPS_HUGE_TLB_SUPPORT */
395 static inline int pte_special(pte_t pte
) { return 0; }
396 static inline pte_t
pte_mkspecial(pte_t pte
) { return pte
; }
399 * Macro to make mark a page protection value as "uncacheable". Note
400 * that "protection" is really a misnomer here as the protection value
401 * contains the memory attribute bits, dirty bits, and various other
404 #define pgprot_noncached pgprot_noncached
406 static inline pgprot_t
pgprot_noncached(pgprot_t _prot
)
408 unsigned long prot
= pgprot_val(_prot
);
410 prot
= (prot
& ~_CACHE_MASK
) | _CACHE_UNCACHED
;
412 return __pgprot(prot
);
415 static inline pgprot_t
pgprot_writecombine(pgprot_t _prot
)
417 unsigned long prot
= pgprot_val(_prot
);
419 /* cpu_data[0].writecombine is already shifted by _CACHE_SHIFT */
420 prot
= (prot
& ~_CACHE_MASK
) | cpu_data
[0].writecombine
;
422 return __pgprot(prot
);
426 * Conversion functions: convert a page and protection to a page entry,
427 * and a page entry and page directory to the page they refer to.
429 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
431 #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
432 static inline pte_t
pte_modify(pte_t pte
, pgprot_t newprot
)
434 pte
.pte_low
&= (_PAGE_MODIFIED
| _PAGE_ACCESSED
| _PFNX_MASK
);
435 pte
.pte_high
&= (_PFN_MASK
| _CACHE_MASK
);
436 pte
.pte_low
|= pgprot_val(newprot
) & ~_PFNX_MASK
;
437 pte
.pte_high
|= pgprot_val(newprot
) & ~_PFN_MASK
;
441 static inline pte_t
pte_modify(pte_t pte
, pgprot_t newprot
)
443 return __pte((pte_val(pte
) & _PAGE_CHG_MASK
) | pgprot_val(newprot
));
448 extern void __update_tlb(struct vm_area_struct
*vma
, unsigned long address
,
451 static inline void update_mmu_cache(struct vm_area_struct
*vma
,
452 unsigned long address
, pte_t
*ptep
)
455 __update_tlb(vma
, address
, pte
);
458 static inline void update_mmu_cache_pmd(struct vm_area_struct
*vma
,
459 unsigned long address
, pmd_t
*pmdp
)
461 pte_t pte
= *(pte_t
*)pmdp
;
463 __update_tlb(vma
, address
, pte
);
466 #define kern_addr_valid(addr) (1)
468 #ifdef CONFIG_PHYS_ADDR_T_64BIT
469 extern int remap_pfn_range(struct vm_area_struct
*vma
, unsigned long from
, unsigned long pfn
, unsigned long size
, pgprot_t prot
);
471 static inline int io_remap_pfn_range(struct vm_area_struct
*vma
,
477 phys_addr_t phys_addr_high
= fixup_bigphys_addr(pfn
<< PAGE_SHIFT
, size
);
478 return remap_pfn_range(vma
, vaddr
, phys_addr_high
>> PAGE_SHIFT
, size
, prot
);
480 #define io_remap_pfn_range io_remap_pfn_range
483 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
485 extern int has_transparent_hugepage(void);
487 static inline int pmd_trans_huge(pmd_t pmd
)
489 return !!(pmd_val(pmd
) & _PAGE_HUGE
);
492 static inline pmd_t
pmd_mkhuge(pmd_t pmd
)
494 pmd_val(pmd
) |= _PAGE_HUGE
;
499 static inline int pmd_trans_splitting(pmd_t pmd
)
501 return !!(pmd_val(pmd
) & _PAGE_SPLITTING
);
504 static inline pmd_t
pmd_mksplitting(pmd_t pmd
)
506 pmd_val(pmd
) |= _PAGE_SPLITTING
;
511 extern void set_pmd_at(struct mm_struct
*mm
, unsigned long addr
,
512 pmd_t
*pmdp
, pmd_t pmd
);
514 #define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
515 /* Extern to avoid header file madness */
516 extern void pmdp_splitting_flush(struct vm_area_struct
*vma
,
517 unsigned long address
,
520 #define __HAVE_ARCH_PMD_WRITE
521 static inline int pmd_write(pmd_t pmd
)
523 return !!(pmd_val(pmd
) & _PAGE_WRITE
);
526 static inline pmd_t
pmd_wrprotect(pmd_t pmd
)
528 pmd_val(pmd
) &= ~(_PAGE_WRITE
| _PAGE_SILENT_WRITE
);
532 static inline pmd_t
pmd_mkwrite(pmd_t pmd
)
534 pmd_val(pmd
) |= _PAGE_WRITE
;
535 if (pmd_val(pmd
) & _PAGE_MODIFIED
)
536 pmd_val(pmd
) |= _PAGE_SILENT_WRITE
;
541 static inline int pmd_dirty(pmd_t pmd
)
543 return !!(pmd_val(pmd
) & _PAGE_MODIFIED
);
546 static inline pmd_t
pmd_mkclean(pmd_t pmd
)
548 pmd_val(pmd
) &= ~(_PAGE_MODIFIED
| _PAGE_SILENT_WRITE
);
552 static inline pmd_t
pmd_mkdirty(pmd_t pmd
)
554 pmd_val(pmd
) |= _PAGE_MODIFIED
;
555 if (pmd_val(pmd
) & _PAGE_WRITE
)
556 pmd_val(pmd
) |= _PAGE_SILENT_WRITE
;
561 static inline int pmd_young(pmd_t pmd
)
563 return !!(pmd_val(pmd
) & _PAGE_ACCESSED
);
566 static inline pmd_t
pmd_mkold(pmd_t pmd
)
568 pmd_val(pmd
) &= ~(_PAGE_ACCESSED
|_PAGE_SILENT_READ
);
573 static inline pmd_t
pmd_mkyoung(pmd_t pmd
)
575 pmd_val(pmd
) |= _PAGE_ACCESSED
;
577 #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
578 if (!(pmd_val(pmd
) & _PAGE_NO_READ
))
579 pmd_val(pmd
) |= _PAGE_SILENT_READ
;
582 if (pmd_val(pmd
) & _PAGE_READ
)
583 pmd_val(pmd
) |= _PAGE_SILENT_READ
;
588 /* Extern to avoid header file madness */
589 extern pmd_t
mk_pmd(struct page
*page
, pgprot_t prot
);
591 static inline unsigned long pmd_pfn(pmd_t pmd
)
593 return pmd_val(pmd
) >> _PFN_SHIFT
;
596 static inline struct page
*pmd_page(pmd_t pmd
)
598 if (pmd_trans_huge(pmd
))
599 return pfn_to_page(pmd_pfn(pmd
));
601 return pfn_to_page(pmd_phys(pmd
) >> PAGE_SHIFT
);
604 static inline pmd_t
pmd_modify(pmd_t pmd
, pgprot_t newprot
)
606 pmd_val(pmd
) = (pmd_val(pmd
) & (_PAGE_CHG_MASK
| _PAGE_HUGE
)) |
607 (pgprot_val(newprot
) & ~_PAGE_CHG_MASK
);
611 static inline pmd_t
pmd_mknotpresent(pmd_t pmd
)
613 pmd_val(pmd
) &= ~(_PAGE_PRESENT
| _PAGE_VALID
| _PAGE_DIRTY
);
619 * The generic version pmdp_get_and_clear uses a version of pmd_clear() with a
620 * different prototype.
622 #define __HAVE_ARCH_PMDP_GET_AND_CLEAR
623 static inline pmd_t
pmdp_get_and_clear(struct mm_struct
*mm
,
624 unsigned long address
, pmd_t
*pmdp
)
633 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
635 #include <asm-generic/pgtable.h>
638 * uncached accelerated TLB map for video memory access
640 #ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
641 #define __HAVE_PHYS_MEM_ACCESS_PROT
644 pgprot_t
phys_mem_access_prot(struct file
*file
, unsigned long pfn
,
645 unsigned long size
, pgprot_t vma_prot
);
646 int phys_mem_access_prot_allowed(struct file
*file
, unsigned long pfn
,
647 unsigned long size
, pgprot_t
*vma_prot
);
651 * We provide our own get_unmapped area to cope with the virtual aliasing
652 * constraints placed on us by the cache architecture.
654 #define HAVE_ARCH_UNMAPPED_AREA
655 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
658 * No page table caches to initialise
660 #define pgtable_cache_init() do { } while (0)
662 #endif /* _ASM_PGTABLE_H */