VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-mips / pgtable.h
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
11 #include <linux/config.h>
12 #ifdef CONFIG_MIPS32
13 #include <asm/pgtable-32.h>
14 #endif
15 #ifdef CONFIG_MIPS64
16 #include <asm/pgtable-64.h>
17 #endif
18
19 #include <asm/pgtable-bits.h>
20
21 #define PAGE_NONE       __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT)
22 #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
23                         PAGE_CACHABLE_DEFAULT)
24 #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_READ | \
25                         PAGE_CACHABLE_DEFAULT)
26 #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_READ | \
27                         PAGE_CACHABLE_DEFAULT)
28 #define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
29                         _PAGE_GLOBAL | PAGE_CACHABLE_DEFAULT)
30 #define PAGE_USERIO     __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
31                         PAGE_CACHABLE_DEFAULT)
32 #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
33                         __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
34
35 /*
36  * MIPS can't do page protection for execute, and considers that the same like
37  * read. Also, write permissions imply read permissions. This is the closest
38  * we can get by reasonable means..
39  */
40 #define __P000  PAGE_NONE
41 #define __P001  PAGE_READONLY
42 #define __P010  PAGE_COPY
43 #define __P011  PAGE_COPY
44 #define __P100  PAGE_READONLY
45 #define __P101  PAGE_READONLY
46 #define __P110  PAGE_COPY
47 #define __P111  PAGE_COPY
48
49 #define __S000  PAGE_NONE
50 #define __S001  PAGE_READONLY
51 #define __S010  PAGE_SHARED
52 #define __S011  PAGE_SHARED
53 #define __S100  PAGE_READONLY
54 #define __S101  PAGE_READONLY
55 #define __S110  PAGE_SHARED
56 #define __S111  PAGE_SHARED
57
58 /*
59  * ZERO_PAGE is a global shared page that is always zero; used
60  * for zero-mapped memory areas etc..
61  */
62
63 extern unsigned long empty_zero_page;
64 extern unsigned long zero_page_mask;
65
66 #define ZERO_PAGE(vaddr) \
67         (virt_to_page(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask)))
68
69 extern void paging_init(void);
70
71 /*
72  * Conversion functions: convert a page and protection to a page entry,
73  * and a page entry and page directory to the page they refer to.
74  */
75 #define page_pte(page)          page_pte_prot(page, __pgprot(0))
76 #define pmd_phys(pmd)           (pmd_val(pmd) - PAGE_OFFSET)
77 #define pmd_page(pmd)           (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
78 #define pmd_page_kernel(pmd)    pmd_val(pmd)
79
80 #define pte_none(pte)           (!(pte_val(pte) & ~_PAGE_GLOBAL))
81 #define pte_present(pte)        (pte_val(pte) & _PAGE_PRESENT)
82
83 /*
84  * Certain architectures need to do special things when pte's
85  * within a page table are directly modified.  Thus, the following
86  * hook is made available.
87  */
88 static inline void set_pte(pte_t *ptep, pte_t pteval)
89 {
90         *ptep = pteval;
91 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
92         if (pte_val(pteval) & _PAGE_GLOBAL) {
93                 pte_t *buddy = ptep_buddy(ptep);
94                 /*
95                  * Make sure the buddy is global too (if it's !none,
96                  * it better already be global)
97                  */
98                 if (pte_none(*buddy))
99                         pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
100         }
101 #endif
102 }
103
104 static inline void pte_clear(pte_t *ptep)
105 {
106 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
107         /* Preserve global status for the pair */
108         if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
109                 set_pte(ptep, __pte(_PAGE_GLOBAL));
110         else
111 #endif
112                 set_pte(ptep, __pte(0));
113 }
114
115 /*
116  * (pmds are folded into pgds so this doesn't get actually called,
117  * but the define is needed for a generic inline function.)
118  */
119 #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
120 #define set_pgd(pgdptr, pgdval) do { *(pgdptr) = (pgdval); } while(0)
121
122 #define PGD_T_LOG2      ffz(~sizeof(pgd_t))
123 #define PMD_T_LOG2      ffz(~sizeof(pmd_t))
124 #define PTE_T_LOG2      ffz(~sizeof(pte_t))
125
126 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
127
128 /*
129  * The following only work if pte_present() is true.
130  * Undefined behaviour if not..
131  */
132 static inline int pte_user(pte_t pte)   { BUG(); return 0; }
133 static inline int pte_read(pte_t pte)   { return pte_val(pte) & _PAGE_READ; }
134 static inline int pte_write(pte_t pte)  { return pte_val(pte) & _PAGE_WRITE; }
135 static inline int pte_dirty(pte_t pte)  { return pte_val(pte) & _PAGE_MODIFIED; }
136 static inline int pte_young(pte_t pte)  { return pte_val(pte) & _PAGE_ACCESSED; }
137 static inline int pte_file(pte_t pte)   { return pte_val(pte) & _PAGE_FILE; }
138
139 static inline pte_t pte_wrprotect(pte_t pte)
140 {
141         pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
142         return pte;
143 }
144
145 static inline pte_t pte_rdprotect(pte_t pte)
146 {
147         pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
148         return pte;
149 }
150
151 static inline pte_t pte_mkclean(pte_t pte)
152 {
153         pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
154         return pte;
155 }
156
157 static inline pte_t pte_mkold(pte_t pte)
158 {
159         pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
160         return pte;
161 }
162
163 static inline pte_t pte_mkwrite(pte_t pte)
164 {
165         pte_val(pte) |= _PAGE_WRITE;
166         if (pte_val(pte) & _PAGE_MODIFIED)
167                 pte_val(pte) |= _PAGE_SILENT_WRITE;
168         return pte;
169 }
170
171 static inline pte_t pte_mkread(pte_t pte)
172 {
173         pte_val(pte) |= _PAGE_READ;
174         if (pte_val(pte) & _PAGE_ACCESSED)
175                 pte_val(pte) |= _PAGE_SILENT_READ;
176         return pte;
177 }
178
179 static inline pte_t pte_mkdirty(pte_t pte)
180 {
181         pte_val(pte) |= _PAGE_MODIFIED;
182         if (pte_val(pte) & _PAGE_WRITE)
183                 pte_val(pte) |= _PAGE_SILENT_WRITE;
184         return pte;
185 }
186
187 static inline pte_t pte_mkyoung(pte_t pte)
188 {
189         pte_val(pte) |= _PAGE_ACCESSED;
190         if (pte_val(pte) & _PAGE_READ)
191                 pte_val(pte) |= _PAGE_SILENT_READ;
192         return pte;
193 }
194
195 /*
196  * Macro to make mark a page protection value as "uncacheable".  Note
197  * that "protection" is really a misnomer here as the protection value
198  * contains the memory attribute bits, dirty bits, and various other
199  * bits as well.
200  */
201 #define pgprot_noncached pgprot_noncached
202
203 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
204 {
205         unsigned long prot = pgprot_val(_prot);
206
207         prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
208
209         return __pgprot(prot);
210 }
211
212 /*
213  * Conversion functions: convert a page and protection to a page entry,
214  * and a page entry and page directory to the page they refer to.
215  */
216 #define mk_pte(page, pgprot)    pfn_pte(page_to_pfn(page), (pgprot))
217
218 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
219 {
220         return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
221 }
222
223
224 extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
225         pte_t pte);
226 extern void __update_cache(struct vm_area_struct *vma, unsigned long address,
227         pte_t pte);
228
229 static inline void update_mmu_cache(struct vm_area_struct *vma,
230         unsigned long address, pte_t pte)
231 {
232         __update_tlb(vma, address, pte);
233         __update_cache(vma, address, pte);
234 }
235
236 #ifndef CONFIG_DISCONTIGMEM
237 #define kern_addr_valid(addr)   (1)
238 #endif
239
240 #include <asm-generic/pgtable.h>
241
242 /*
243  * We provide our own get_unmapped area to cope with the virtual aliasing
244  * constraints placed on us by the cache architecture.
245  */
246 #define HAVE_ARCH_UNMAPPED_AREA
247
248 #define io_remap_page_range remap_page_range
249
250 /*
251  * No page table caches to initialise
252  */
253 #define pgtable_cache_init()    do { } while (0)
254
255 #endif /* _ASM_PGTABLE_H */