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 | (cpu_has_rixi ? 0 : _PAGE_READ) | \
28 _page_cachable_default)
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) | \
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 | (cpu_has_rixi ? 0 : _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)
100 #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
102 #define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
103 #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
105 static inline void set_pte(pte_t
*ptep
, pte_t pte
)
107 ptep
->pte_high
= pte
.pte_high
;
109 ptep
->pte_low
= pte
.pte_low
;
111 if (pte
.pte_low
& _PAGE_GLOBAL
) {
112 pte_t
*buddy
= ptep_buddy(ptep
);
114 * Make sure the buddy is global too (if it's !none,
115 * it better already be global)
117 if (pte_none(*buddy
)) {
118 buddy
->pte_low
|= _PAGE_GLOBAL
;
119 buddy
->pte_high
|= _PAGE_GLOBAL
;
123 #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
125 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
127 pte_t null
= __pte(0);
129 /* Preserve global status for the pair */
130 if (ptep_buddy(ptep
)->pte_low
& _PAGE_GLOBAL
)
131 null
.pte_low
= null
.pte_high
= _PAGE_GLOBAL
;
133 set_pte_at(mm
, addr
, ptep
, null
);
137 #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
138 #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
141 * Certain architectures need to do special things when pte's
142 * within a page table are directly modified. Thus, the following
143 * hook is made available.
145 static inline void set_pte(pte_t
*ptep
, pte_t pteval
)
148 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
149 if (pte_val(pteval
) & _PAGE_GLOBAL
) {
150 pte_t
*buddy
= ptep_buddy(ptep
);
152 * Make sure the buddy is global too (if it's !none,
153 * it better already be global)
155 if (pte_none(*buddy
))
156 pte_val(*buddy
) = pte_val(*buddy
) | _PAGE_GLOBAL
;
160 #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
162 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
164 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
165 /* Preserve global status for the pair */
166 if (pte_val(*ptep_buddy(ptep
)) & _PAGE_GLOBAL
)
167 set_pte_at(mm
, addr
, ptep
, __pte(_PAGE_GLOBAL
));
170 set_pte_at(mm
, addr
, ptep
, __pte(0));
175 * (pmds are folded into puds so this doesn't get actually called,
176 * but the define is needed for a generic inline function.)
178 #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
180 #ifndef __PAGETABLE_PMD_FOLDED
182 * (puds are folded into pgds so this doesn't get actually called,
183 * but the define is needed for a generic inline function.)
185 #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
188 #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
189 #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
190 #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
193 * We used to declare this array with size but gcc 3.3 and older are not able
194 * to find that this expression is a constant, so the size is dropped.
196 extern pgd_t swapper_pg_dir
[];
199 * The following only work if pte_present() is true.
200 * Undefined behaviour if not..
202 #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
203 static inline int pte_write(pte_t pte
) { return pte
.pte_low
& _PAGE_WRITE
; }
204 static inline int pte_dirty(pte_t pte
) { return pte
.pte_low
& _PAGE_MODIFIED
; }
205 static inline int pte_young(pte_t pte
) { return pte
.pte_low
& _PAGE_ACCESSED
; }
206 static inline int pte_file(pte_t pte
) { return pte
.pte_low
& _PAGE_FILE
; }
208 static inline pte_t
pte_wrprotect(pte_t pte
)
210 pte
.pte_low
&= ~(_PAGE_WRITE
| _PAGE_SILENT_WRITE
);
211 pte
.pte_high
&= ~_PAGE_SILENT_WRITE
;
215 static inline pte_t
pte_mkclean(pte_t pte
)
217 pte
.pte_low
&= ~(_PAGE_MODIFIED
| _PAGE_SILENT_WRITE
);
218 pte
.pte_high
&= ~_PAGE_SILENT_WRITE
;
222 static inline pte_t
pte_mkold(pte_t pte
)
224 pte
.pte_low
&= ~(_PAGE_ACCESSED
| _PAGE_SILENT_READ
);
225 pte
.pte_high
&= ~_PAGE_SILENT_READ
;
229 static inline pte_t
pte_mkwrite(pte_t pte
)
231 pte
.pte_low
|= _PAGE_WRITE
;
232 if (pte
.pte_low
& _PAGE_MODIFIED
) {
233 pte
.pte_low
|= _PAGE_SILENT_WRITE
;
234 pte
.pte_high
|= _PAGE_SILENT_WRITE
;
239 static inline pte_t
pte_mkdirty(pte_t pte
)
241 pte
.pte_low
|= _PAGE_MODIFIED
;
242 if (pte
.pte_low
& _PAGE_WRITE
) {
243 pte
.pte_low
|= _PAGE_SILENT_WRITE
;
244 pte
.pte_high
|= _PAGE_SILENT_WRITE
;
249 static inline pte_t
pte_mkyoung(pte_t pte
)
251 pte
.pte_low
|= _PAGE_ACCESSED
;
252 if (pte
.pte_low
& _PAGE_READ
) {
253 pte
.pte_low
|= _PAGE_SILENT_READ
;
254 pte
.pte_high
|= _PAGE_SILENT_READ
;
259 static inline int pte_write(pte_t pte
) { return pte_val(pte
) & _PAGE_WRITE
; }
260 static inline int pte_dirty(pte_t pte
) { return pte_val(pte
) & _PAGE_MODIFIED
; }
261 static inline int pte_young(pte_t pte
) { return pte_val(pte
) & _PAGE_ACCESSED
; }
262 static inline int pte_file(pte_t pte
) { return pte_val(pte
) & _PAGE_FILE
; }
264 static inline pte_t
pte_wrprotect(pte_t pte
)
266 pte_val(pte
) &= ~(_PAGE_WRITE
| _PAGE_SILENT_WRITE
);
270 static inline pte_t
pte_mkclean(pte_t pte
)
272 pte_val(pte
) &= ~(_PAGE_MODIFIED
|_PAGE_SILENT_WRITE
);
276 static inline pte_t
pte_mkold(pte_t pte
)
278 pte_val(pte
) &= ~(_PAGE_ACCESSED
|_PAGE_SILENT_READ
);
282 static inline pte_t
pte_mkwrite(pte_t pte
)
284 pte_val(pte
) |= _PAGE_WRITE
;
285 if (pte_val(pte
) & _PAGE_MODIFIED
)
286 pte_val(pte
) |= _PAGE_SILENT_WRITE
;
290 static inline pte_t
pte_mkdirty(pte_t pte
)
292 pte_val(pte
) |= _PAGE_MODIFIED
;
293 if (pte_val(pte
) & _PAGE_WRITE
)
294 pte_val(pte
) |= _PAGE_SILENT_WRITE
;
298 static inline pte_t
pte_mkyoung(pte_t pte
)
300 pte_val(pte
) |= _PAGE_ACCESSED
;
302 if (!(pte_val(pte
) & _PAGE_NO_READ
))
303 pte_val(pte
) |= _PAGE_SILENT_READ
;
305 if (pte_val(pte
) & _PAGE_READ
)
306 pte_val(pte
) |= _PAGE_SILENT_READ
;
312 static inline int pte_huge(pte_t pte
) { return pte_val(pte
) & _PAGE_HUGE
; }
314 static inline pte_t
pte_mkhuge(pte_t pte
)
316 pte_val(pte
) |= _PAGE_HUGE
;
319 #endif /* _PAGE_HUGE */
321 static inline int pte_special(pte_t pte
) { return 0; }
322 static inline pte_t
pte_mkspecial(pte_t pte
) { return pte
; }
325 * Macro to make mark a page protection value as "uncacheable". Note
326 * that "protection" is really a misnomer here as the protection value
327 * contains the memory attribute bits, dirty bits, and various other
330 #define pgprot_noncached pgprot_noncached
332 static inline pgprot_t
pgprot_noncached(pgprot_t _prot
)
334 unsigned long prot
= pgprot_val(_prot
);
336 prot
= (prot
& ~_CACHE_MASK
) | _CACHE_UNCACHED
;
338 return __pgprot(prot
);
342 * Conversion functions: convert a page and protection to a page entry,
343 * and a page entry and page directory to the page they refer to.
345 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
347 #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
348 static inline pte_t
pte_modify(pte_t pte
, pgprot_t newprot
)
350 pte
.pte_low
&= _PAGE_CHG_MASK
;
351 pte
.pte_high
&= ~0x3f;
352 pte
.pte_low
|= pgprot_val(newprot
);
353 pte
.pte_high
|= pgprot_val(newprot
) & 0x3f;
357 static inline pte_t
pte_modify(pte_t pte
, pgprot_t newprot
)
359 return __pte((pte_val(pte
) & _PAGE_CHG_MASK
) | pgprot_val(newprot
));
364 extern void __update_tlb(struct vm_area_struct
*vma
, unsigned long address
,
366 extern void __update_cache(struct vm_area_struct
*vma
, unsigned long address
,
369 static inline void update_mmu_cache(struct vm_area_struct
*vma
,
370 unsigned long address
, pte_t
*ptep
)
373 __update_tlb(vma
, address
, pte
);
374 __update_cache(vma
, address
, pte
);
377 static inline void update_mmu_cache_pmd(struct vm_area_struct
*vma
,
378 unsigned long address
, pmd_t
*pmdp
)
380 pte_t pte
= *(pte_t
*)pmdp
;
382 __update_tlb(vma
, address
, pte
);
385 #define kern_addr_valid(addr) (1)
387 #ifdef CONFIG_64BIT_PHYS_ADDR
388 extern int remap_pfn_range(struct vm_area_struct
*vma
, unsigned long from
, unsigned long pfn
, unsigned long size
, pgprot_t prot
);
390 static inline int io_remap_pfn_range(struct vm_area_struct
*vma
,
396 phys_t phys_addr_high
= fixup_bigphys_addr(pfn
<< PAGE_SHIFT
, size
);
397 return remap_pfn_range(vma
, vaddr
, phys_addr_high
>> PAGE_SHIFT
, size
, prot
);
399 #define io_remap_pfn_range io_remap_pfn_range
402 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
404 extern int has_transparent_hugepage(void);
406 static inline int pmd_trans_huge(pmd_t pmd
)
408 return !!(pmd_val(pmd
) & _PAGE_HUGE
);
411 static inline pmd_t
pmd_mkhuge(pmd_t pmd
)
413 pmd_val(pmd
) |= _PAGE_HUGE
;
418 static inline int pmd_trans_splitting(pmd_t pmd
)
420 return !!(pmd_val(pmd
) & _PAGE_SPLITTING
);
423 static inline pmd_t
pmd_mksplitting(pmd_t pmd
)
425 pmd_val(pmd
) |= _PAGE_SPLITTING
;
430 extern void set_pmd_at(struct mm_struct
*mm
, unsigned long addr
,
431 pmd_t
*pmdp
, pmd_t pmd
);
433 #define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
434 /* Extern to avoid header file madness */
435 extern void pmdp_splitting_flush(struct vm_area_struct
*vma
,
436 unsigned long address
,
439 #define __HAVE_ARCH_PMD_WRITE
440 static inline int pmd_write(pmd_t pmd
)
442 return !!(pmd_val(pmd
) & _PAGE_WRITE
);
445 static inline pmd_t
pmd_wrprotect(pmd_t pmd
)
447 pmd_val(pmd
) &= ~(_PAGE_WRITE
| _PAGE_SILENT_WRITE
);
451 static inline pmd_t
pmd_mkwrite(pmd_t pmd
)
453 pmd_val(pmd
) |= _PAGE_WRITE
;
454 if (pmd_val(pmd
) & _PAGE_MODIFIED
)
455 pmd_val(pmd
) |= _PAGE_SILENT_WRITE
;
460 static inline int pmd_dirty(pmd_t pmd
)
462 return !!(pmd_val(pmd
) & _PAGE_MODIFIED
);
465 static inline pmd_t
pmd_mkclean(pmd_t pmd
)
467 pmd_val(pmd
) &= ~(_PAGE_MODIFIED
| _PAGE_SILENT_WRITE
);
471 static inline pmd_t
pmd_mkdirty(pmd_t pmd
)
473 pmd_val(pmd
) |= _PAGE_MODIFIED
;
474 if (pmd_val(pmd
) & _PAGE_WRITE
)
475 pmd_val(pmd
) |= _PAGE_SILENT_WRITE
;
480 static inline int pmd_young(pmd_t pmd
)
482 return !!(pmd_val(pmd
) & _PAGE_ACCESSED
);
485 static inline pmd_t
pmd_mkold(pmd_t pmd
)
487 pmd_val(pmd
) &= ~(_PAGE_ACCESSED
|_PAGE_SILENT_READ
);
492 static inline pmd_t
pmd_mkyoung(pmd_t pmd
)
494 pmd_val(pmd
) |= _PAGE_ACCESSED
;
497 if (!(pmd_val(pmd
) & _PAGE_NO_READ
))
498 pmd_val(pmd
) |= _PAGE_SILENT_READ
;
500 if (pmd_val(pmd
) & _PAGE_READ
)
501 pmd_val(pmd
) |= _PAGE_SILENT_READ
;
507 /* Extern to avoid header file madness */
508 extern pmd_t
mk_pmd(struct page
*page
, pgprot_t prot
);
510 static inline unsigned long pmd_pfn(pmd_t pmd
)
512 return pmd_val(pmd
) >> _PFN_SHIFT
;
515 static inline struct page
*pmd_page(pmd_t pmd
)
517 if (pmd_trans_huge(pmd
))
518 return pfn_to_page(pmd_pfn(pmd
));
520 return pfn_to_page(pmd_phys(pmd
) >> PAGE_SHIFT
);
523 static inline pmd_t
pmd_modify(pmd_t pmd
, pgprot_t newprot
)
525 pmd_val(pmd
) = (pmd_val(pmd
) & _PAGE_CHG_MASK
) | pgprot_val(newprot
);
529 static inline pmd_t
pmd_mknotpresent(pmd_t pmd
)
531 pmd_val(pmd
) &= ~(_PAGE_PRESENT
| _PAGE_VALID
| _PAGE_DIRTY
);
537 * The generic version pmdp_get_and_clear uses a version of pmd_clear() with a
538 * different prototype.
540 #define __HAVE_ARCH_PMDP_GET_AND_CLEAR
541 static inline pmd_t
pmdp_get_and_clear(struct mm_struct
*mm
,
542 unsigned long address
, pmd_t
*pmdp
)
551 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
553 #include <asm-generic/pgtable.h>
556 * uncached accelerated TLB map for video memory access
558 #ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
559 #define __HAVE_PHYS_MEM_ACCESS_PROT
562 pgprot_t
phys_mem_access_prot(struct file
*file
, unsigned long pfn
,
563 unsigned long size
, pgprot_t vma_prot
);
564 int phys_mem_access_prot_allowed(struct file
*file
, unsigned long pfn
,
565 unsigned long size
, pgprot_t
*vma_prot
);
569 * We provide our own get_unmapped area to cope with the virtual aliasing
570 * constraints placed on us by the cache architecture.
572 #define HAVE_ARCH_UNMAPPED_AREA
573 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
576 * No page table caches to initialise
578 #define pgtable_cache_init() do { } while (0)
580 #endif /* _ASM_PGTABLE_H */
This page took 0.057331 seconds and 5 git commands to generate.