]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/mips/include/asm/pgtable.h
UBIFS: fix a horrid bug
[mirror_ubuntu-artful-kernel.git] / arch / mips / include / asm / pgtable.h
CommitLineData
1da177e4
LT
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
5bbea36a 11#include <linux/mm_types.h>
970d032f 12#include <linux/mmzone.h>
875d43e7 13#ifdef CONFIG_32BIT
1da177e4
LT
14#include <asm/pgtable-32.h>
15#endif
875d43e7 16#ifdef CONFIG_64BIT
1da177e4
LT
17#include <asm/pgtable-64.h>
18#endif
19
f10fae02 20#include <asm/io.h>
1da177e4
LT
21#include <asm/pgtable-bits.h>
22
8c65b4a6
TS
23struct mm_struct;
24struct vm_area_struct;
25
1da177e4 26#define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT)
05857c64 27#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_WRITE | (cpu_has_rixi ? 0 : _PAGE_READ) | \
35133692 28 _page_cachable_default)
05857c64
SH
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) | \
35133692 32 _page_cachable_default)
1da177e4 33#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
35133692 34 _PAGE_GLOBAL | _page_cachable_default)
05857c64 35#define PAGE_USERIO __pgprot(_PAGE_PRESENT | (cpu_has_rixi ? 0 : _PAGE_READ) | _PAGE_WRITE | \
35133692 36 _page_cachable_default)
1da177e4
LT
37#define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
38 __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
39
40/*
6dd9344c
DD
41 * If _PAGE_NO_EXEC is not defined, we can't do page protection for
42 * execute, and consider it to be the same as read. Also, write
43 * permissions imply read permissions. This is the closest we can get
44 * by reasonable means..
1da177e4 45 */
1da177e4 46
35133692
CD
47/*
48 * Dummy values to fill the table in mmap.c
49 * The real values will be generated at runtime
50 */
51#define __P000 __pgprot(0)
52#define __P001 __pgprot(0)
53#define __P010 __pgprot(0)
54#define __P011 __pgprot(0)
55#define __P100 __pgprot(0)
56#define __P101 __pgprot(0)
57#define __P110 __pgprot(0)
58#define __P111 __pgprot(0)
59
60#define __S000 __pgprot(0)
61#define __S001 __pgprot(0)
62#define __S010 __pgprot(0)
63#define __S011 __pgprot(0)
64#define __S100 __pgprot(0)
65#define __S101 __pgprot(0)
66#define __S110 __pgprot(0)
67#define __S111 __pgprot(0)
68
69extern unsigned long _page_cachable_default;
1da177e4
LT
70
71/*
72 * ZERO_PAGE is a global shared page that is always zero; used
73 * for zero-mapped memory areas etc..
74 */
75
76extern unsigned long empty_zero_page;
77extern unsigned long zero_page_mask;
78
79#define ZERO_PAGE(vaddr) \
99e3b942 80 (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
816422ad 81#define __HAVE_COLOR_ZERO_PAGE
62eede62 82
1da177e4
LT
83extern void paging_init(void);
84
85/*
86 * Conversion functions: convert a page and protection to a page entry,
87 * and a page entry and page directory to the page they refer to.
88 */
c9d06962 89#define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
970d032f
RB
90
91#define __pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
92#ifndef CONFIG_TRANSPARENT_HUGEPAGE
93#define pmd_page(pmd) __pmd_page(pmd)
94#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
95
46a82b2d 96#define pmd_page_vaddr(pmd) pmd_val(pmd)
1da177e4 97
962f480e 98#if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
6e953891
SS
99
100#define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
101#define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
102
1da177e4
LT
103static inline void set_pte(pte_t *ptep, pte_t pte)
104{
105 ptep->pte_high = pte.pte_high;
106 smp_wmb();
107 ptep->pte_low = pte.pte_low;
1da177e4 108
6e953891 109 if (pte.pte_low & _PAGE_GLOBAL) {
1da177e4
LT
110 pte_t *buddy = ptep_buddy(ptep);
111 /*
112 * Make sure the buddy is global too (if it's !none,
113 * it better already be global)
114 */
6e953891 115 if (pte_none(*buddy)) {
70342287 116 buddy->pte_low |= _PAGE_GLOBAL;
6e953891
SS
117 buddy->pte_high |= _PAGE_GLOBAL;
118 }
1da177e4
LT
119 }
120}
21a151d8 121#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
1da177e4
LT
122
123static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
124{
6e953891
SS
125 pte_t null = __pte(0);
126
1da177e4 127 /* Preserve global status for the pair */
6e953891
SS
128 if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL)
129 null.pte_low = null.pte_high = _PAGE_GLOBAL;
130
131 set_pte_at(mm, addr, ptep, null);
1da177e4
LT
132}
133#else
6e953891
SS
134
135#define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
136#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
137
1da177e4
LT
138/*
139 * Certain architectures need to do special things when pte's
140 * within a page table are directly modified. Thus, the following
141 * hook is made available.
142 */
143static inline void set_pte(pte_t *ptep, pte_t pteval)
144{
145 *ptep = pteval;
146#if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
147 if (pte_val(pteval) & _PAGE_GLOBAL) {
148 pte_t *buddy = ptep_buddy(ptep);
149 /*
150 * Make sure the buddy is global too (if it's !none,
151 * it better already be global)
152 */
153 if (pte_none(*buddy))
154 pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
155 }
156#endif
157}
21a151d8 158#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
1da177e4
LT
159
160static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
161{
162#if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
163 /* Preserve global status for the pair */
164 if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
165 set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
166 else
167#endif
168 set_pte_at(mm, addr, ptep, __pte(0));
169}
170#endif
171
172/*
c6e8b587 173 * (pmds are folded into puds so this doesn't get actually called,
1da177e4
LT
174 * but the define is needed for a generic inline function.)
175 */
176#define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
c6e8b587 177
325f8a0a 178#ifndef __PAGETABLE_PMD_FOLDED
c6e8b587
RB
179/*
180 * (puds are folded into pgds so this doesn't get actually called,
181 * but the define is needed for a generic inline function.)
182 */
183#define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
184#endif
1da177e4 185
5ff97472
RB
186#define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
187#define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
188#define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
1da177e4 189
9975e77d
RB
190/*
191 * We used to declare this array with size but gcc 3.3 and older are not able
192 * to find that this expression is a constant, so the size is dropped.
193 */
194extern pgd_t swapper_pg_dir[];
1da177e4
LT
195
196/*
197 * The following only work if pte_present() is true.
198 * Undefined behaviour if not..
199 */
962f480e 200#if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
6e953891
SS
201static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; }
202static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; }
203static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; }
204static inline int pte_file(pte_t pte) { return pte.pte_low & _PAGE_FILE; }
205
1da177e4
LT
206static inline pte_t pte_wrprotect(pte_t pte)
207{
6e953891
SS
208 pte.pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
209 pte.pte_high &= ~_PAGE_SILENT_WRITE;
1da177e4
LT
210 return pte;
211}
212
1da177e4
LT
213static inline pte_t pte_mkclean(pte_t pte)
214{
6e953891
SS
215 pte.pte_low &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
216 pte.pte_high &= ~_PAGE_SILENT_WRITE;
1da177e4
LT
217 return pte;
218}
219
220static inline pte_t pte_mkold(pte_t pte)
221{
6e953891
SS
222 pte.pte_low &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
223 pte.pte_high &= ~_PAGE_SILENT_READ;
1da177e4
LT
224 return pte;
225}
226
227static inline pte_t pte_mkwrite(pte_t pte)
228{
6e953891
SS
229 pte.pte_low |= _PAGE_WRITE;
230 if (pte.pte_low & _PAGE_MODIFIED) {
231 pte.pte_low |= _PAGE_SILENT_WRITE;
232 pte.pte_high |= _PAGE_SILENT_WRITE;
1da177e4
LT
233 }
234 return pte;
235}
236
1da177e4
LT
237static inline pte_t pte_mkdirty(pte_t pte)
238{
6e953891
SS
239 pte.pte_low |= _PAGE_MODIFIED;
240 if (pte.pte_low & _PAGE_WRITE) {
241 pte.pte_low |= _PAGE_SILENT_WRITE;
242 pte.pte_high |= _PAGE_SILENT_WRITE;
1da177e4
LT
243 }
244 return pte;
245}
246
247static inline pte_t pte_mkyoung(pte_t pte)
248{
6e953891 249 pte.pte_low |= _PAGE_ACCESSED;
057229f9 250 if (pte.pte_low & _PAGE_READ) {
6e953891
SS
251 pte.pte_low |= _PAGE_SILENT_READ;
252 pte.pte_high |= _PAGE_SILENT_READ;
057229f9 253 }
1da177e4
LT
254 return pte;
255}
256#else
1da177e4
LT
257static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
258static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
259static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
260static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
261
262static inline pte_t pte_wrprotect(pte_t pte)
263{
264 pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
265 return pte;
266}
267
1da177e4
LT
268static inline pte_t pte_mkclean(pte_t pte)
269{
270 pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
271 return pte;
272}
273
274static inline pte_t pte_mkold(pte_t pte)
275{
276 pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
277 return pte;
278}
279
280static inline pte_t pte_mkwrite(pte_t pte)
281{
282 pte_val(pte) |= _PAGE_WRITE;
283 if (pte_val(pte) & _PAGE_MODIFIED)
284 pte_val(pte) |= _PAGE_SILENT_WRITE;
285 return pte;
286}
287
1da177e4
LT
288static inline pte_t pte_mkdirty(pte_t pte)
289{
290 pte_val(pte) |= _PAGE_MODIFIED;
291 if (pte_val(pte) & _PAGE_WRITE)
292 pte_val(pte) |= _PAGE_SILENT_WRITE;
293 return pte;
294}
295
296static inline pte_t pte_mkyoung(pte_t pte)
297{
298 pte_val(pte) |= _PAGE_ACCESSED;
05857c64 299 if (cpu_has_rixi) {
6dd9344c
DD
300 if (!(pte_val(pte) & _PAGE_NO_READ))
301 pte_val(pte) |= _PAGE_SILENT_READ;
302 } else {
303 if (pte_val(pte) & _PAGE_READ)
304 pte_val(pte) |= _PAGE_SILENT_READ;
305 }
1da177e4
LT
306 return pte;
307}
dd794392
DD
308
309#ifdef _PAGE_HUGE
310static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
311
312static inline pte_t pte_mkhuge(pte_t pte)
313{
314 pte_val(pte) |= _PAGE_HUGE;
315 return pte;
316}
317#endif /* _PAGE_HUGE */
1da177e4 318#endif
7e675137
NP
319static inline int pte_special(pte_t pte) { return 0; }
320static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1da177e4
LT
321
322/*
70342287 323 * Macro to make mark a page protection value as "uncacheable". Note
1da177e4
LT
324 * that "protection" is really a misnomer here as the protection value
325 * contains the memory attribute bits, dirty bits, and various other
326 * bits as well.
327 */
328#define pgprot_noncached pgprot_noncached
329
330static inline pgprot_t pgprot_noncached(pgprot_t _prot)
331{
332 unsigned long prot = pgprot_val(_prot);
333
334 prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
335
336 return __pgprot(prot);
337}
338
339/*
340 * Conversion functions: convert a page and protection to a page entry,
341 * and a page entry and page directory to the page they refer to.
342 */
343#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
344
962f480e 345#if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
1da177e4
LT
346static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
347{
79e0bc37
SS
348 pte.pte_low &= _PAGE_CHG_MASK;
349 pte.pte_high &= ~0x3f;
350 pte.pte_low |= pgprot_val(newprot);
1da177e4
LT
351 pte.pte_high |= pgprot_val(newprot) & 0x3f;
352 return pte;
353}
354#else
355static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
356{
357 return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
358}
359#endif
360
361
362extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
363 pte_t pte);
364extern void __update_cache(struct vm_area_struct *vma, unsigned long address,
365 pte_t pte);
366
367static inline void update_mmu_cache(struct vm_area_struct *vma,
4b3073e1 368 unsigned long address, pte_t *ptep)
1da177e4 369{
4b3073e1 370 pte_t pte = *ptep;
1da177e4
LT
371 __update_tlb(vma, address, pte);
372 __update_cache(vma, address, pte);
373}
374
970d032f
RB
375static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
376 unsigned long address, pmd_t *pmdp)
377{
378 pte_t pte = *(pte_t *)pmdp;
379
380 __update_tlb(vma, address, pte);
381}
382
1da177e4 383#define kern_addr_valid(addr) (1)
1da177e4
LT
384
385#ifdef CONFIG_64BIT_PHYS_ADDR
1da177e4
LT
386extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot);
387
1da177e4
LT
388static inline int io_remap_pfn_range(struct vm_area_struct *vma,
389 unsigned long vaddr,
390 unsigned long pfn,
391 unsigned long size,
392 pgprot_t prot)
393{
394 phys_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size);
ac5d8c02 395 return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot);
1da177e4
LT
396}
397#else
1da177e4
LT
398#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
399 remap_pfn_range(vma, vaddr, pfn, size, prot)
400#endif
401
970d032f
RB
402#ifdef CONFIG_TRANSPARENT_HUGEPAGE
403
404extern int has_transparent_hugepage(void);
405
406static inline int pmd_trans_huge(pmd_t pmd)
407{
408 return !!(pmd_val(pmd) & _PAGE_HUGE);
409}
410
411static inline pmd_t pmd_mkhuge(pmd_t pmd)
412{
413 pmd_val(pmd) |= _PAGE_HUGE;
414
415 return pmd;
416}
417
418static inline int pmd_trans_splitting(pmd_t pmd)
419{
420 return !!(pmd_val(pmd) & _PAGE_SPLITTING);
421}
422
423static inline pmd_t pmd_mksplitting(pmd_t pmd)
424{
425 pmd_val(pmd) |= _PAGE_SPLITTING;
426
427 return pmd;
428}
429
430extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
431 pmd_t *pmdp, pmd_t pmd);
432
433#define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
434/* Extern to avoid header file madness */
435extern void pmdp_splitting_flush(struct vm_area_struct *vma,
436 unsigned long address,
437 pmd_t *pmdp);
438
439#define __HAVE_ARCH_PMD_WRITE
440static inline int pmd_write(pmd_t pmd)
441{
442 return !!(pmd_val(pmd) & _PAGE_WRITE);
443}
444
445static inline pmd_t pmd_wrprotect(pmd_t pmd)
446{
447 pmd_val(pmd) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
448 return pmd;
449}
450
451static inline pmd_t pmd_mkwrite(pmd_t pmd)
452{
453 pmd_val(pmd) |= _PAGE_WRITE;
454 if (pmd_val(pmd) & _PAGE_MODIFIED)
455 pmd_val(pmd) |= _PAGE_SILENT_WRITE;
456
457 return pmd;
458}
459
460static inline int pmd_dirty(pmd_t pmd)
461{
462 return !!(pmd_val(pmd) & _PAGE_MODIFIED);
463}
464
465static inline pmd_t pmd_mkclean(pmd_t pmd)
466{
467 pmd_val(pmd) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
468 return pmd;
469}
470
471static inline pmd_t pmd_mkdirty(pmd_t pmd)
472{
473 pmd_val(pmd) |= _PAGE_MODIFIED;
474 if (pmd_val(pmd) & _PAGE_WRITE)
475 pmd_val(pmd) |= _PAGE_SILENT_WRITE;
476
477 return pmd;
478}
479
480static inline int pmd_young(pmd_t pmd)
481{
482 return !!(pmd_val(pmd) & _PAGE_ACCESSED);
483}
484
485static inline pmd_t pmd_mkold(pmd_t pmd)
486{
487 pmd_val(pmd) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
488
489 return pmd;
490}
491
492static inline pmd_t pmd_mkyoung(pmd_t pmd)
493{
494 pmd_val(pmd) |= _PAGE_ACCESSED;
495
496 if (cpu_has_rixi) {
497 if (!(pmd_val(pmd) & _PAGE_NO_READ))
498 pmd_val(pmd) |= _PAGE_SILENT_READ;
499 } else {
500 if (pmd_val(pmd) & _PAGE_READ)
501 pmd_val(pmd) |= _PAGE_SILENT_READ;
502 }
503
504 return pmd;
505}
506
507/* Extern to avoid header file madness */
508extern pmd_t mk_pmd(struct page *page, pgprot_t prot);
509
510static inline unsigned long pmd_pfn(pmd_t pmd)
511{
512 return pmd_val(pmd) >> _PFN_SHIFT;
513}
514
515static inline struct page *pmd_page(pmd_t pmd)
516{
517 if (pmd_trans_huge(pmd))
518 return pfn_to_page(pmd_pfn(pmd));
519
520 return pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT);
521}
522
523static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
524{
525 pmd_val(pmd) = (pmd_val(pmd) & _PAGE_CHG_MASK) | pgprot_val(newprot);
526 return pmd;
527}
528
529static inline pmd_t pmd_mknotpresent(pmd_t pmd)
530{
531 pmd_val(pmd) &= ~(_PAGE_PRESENT | _PAGE_VALID | _PAGE_DIRTY);
532
533 return pmd;
534}
535
536/*
537 * The generic version pmdp_get_and_clear uses a version of pmd_clear() with a
538 * different prototype.
539 */
540#define __HAVE_ARCH_PMDP_GET_AND_CLEAR
541static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm,
542 unsigned long address, pmd_t *pmdp)
543{
544 pmd_t old = *pmdp;
545
546 pmd_clear(pmdp);
547
548 return old;
549}
550
551#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
552
1da177e4
LT
553#include <asm-generic/pgtable.h>
554
22f1fdfd
WZ
555/*
556 * uncached accelerated TLB map for video memory access
557 */
558#ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
559#define __HAVE_PHYS_MEM_ACCESS_PROT
560
561struct file;
562pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
563 unsigned long size, pgprot_t vma_prot);
564int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
565 unsigned long size, pgprot_t *vma_prot);
566#endif
567
1da177e4
LT
568/*
569 * We provide our own get_unmapped area to cope with the virtual aliasing
570 * constraints placed on us by the cache architecture.
571 */
572#define HAVE_ARCH_UNMAPPED_AREA
d0be89f6 573#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
1da177e4
LT
574
575/*
576 * No page table caches to initialise
577 */
578#define pgtable_cache_init() do { } while (0)
579
580#endif /* _ASM_PGTABLE_H */