upgrade to linux 2.6.10-1.12_FC2
[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 #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
84 static inline void set_pte(pte_t *ptep, pte_t pte)
85 {
86         ptep->pte_high = pte.pte_high;
87         smp_wmb();
88         ptep->pte_low = pte.pte_low;
89         //printk("pte_high %x pte_low %x\n", ptep->pte_high, ptep->pte_low);
90
91         if (pte_val(pte) & _PAGE_GLOBAL) {
92                 pte_t *buddy = ptep_buddy(ptep);
93                 /*
94                  * Make sure the buddy is global too (if it's !none,
95                  * it better already be global)
96                  */
97                 if (pte_none(*buddy))
98                         buddy->pte_low |= _PAGE_GLOBAL;
99         }
100 }
101
102 static inline void pte_clear(pte_t *ptep)
103 {
104         /* Preserve global status for the pair */
105         if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
106                 set_pte(ptep, __pte(_PAGE_GLOBAL));
107         else
108                 set_pte(ptep, __pte(0));
109 }
110 #else
111 /*
112  * Certain architectures need to do special things when pte's
113  * within a page table are directly modified.  Thus, the following
114  * hook is made available.
115  */
116 static inline void set_pte(pte_t *ptep, pte_t pteval)
117 {
118         *ptep = pteval;
119 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
120         if (pte_val(pteval) & _PAGE_GLOBAL) {
121                 pte_t *buddy = ptep_buddy(ptep);
122                 /*
123                  * Make sure the buddy is global too (if it's !none,
124                  * it better already be global)
125                  */
126                 if (pte_none(*buddy))
127                         pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
128         }
129 #endif
130 }
131
132 static inline void pte_clear(pte_t *ptep)
133 {
134 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
135         /* Preserve global status for the pair */
136         if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
137                 set_pte(ptep, __pte(_PAGE_GLOBAL));
138         else
139 #endif
140                 set_pte(ptep, __pte(0));
141 }
142 #endif
143
144 /*
145  * (pmds are folded into pgds so this doesn't get actually called,
146  * but the define is needed for a generic inline function.)
147  */
148 #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
149 #define set_pgd(pgdptr, pgdval) do { *(pgdptr) = (pgdval); } while(0)
150
151 #define PGD_T_LOG2      ffz(~sizeof(pgd_t))
152 #define PMD_T_LOG2      ffz(~sizeof(pmd_t))
153 #define PTE_T_LOG2      ffz(~sizeof(pte_t))
154
155 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
156
157 /*
158  * The following only work if pte_present() is true.
159  * Undefined behaviour if not..
160  */
161 static inline int pte_user(pte_t pte)   { BUG(); return 0; }
162 #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
163 static inline int pte_read(pte_t pte)   { return (pte).pte_low & _PAGE_READ; }
164 static inline int pte_write(pte_t pte)  { return (pte).pte_low & _PAGE_WRITE; }
165 static inline int pte_dirty(pte_t pte)  { return (pte).pte_low & _PAGE_MODIFIED; }
166 static inline int pte_young(pte_t pte)  { return (pte).pte_low & _PAGE_ACCESSED; }
167 static inline int pte_file(pte_t pte)   { return (pte).pte_low & _PAGE_FILE; }
168 static inline pte_t pte_wrprotect(pte_t pte)
169 {
170         (pte).pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
171         (pte).pte_high &= ~_PAGE_SILENT_WRITE;
172         return pte;
173 }
174
175 static inline pte_t pte_rdprotect(pte_t pte)
176 {
177         (pte).pte_low &= ~(_PAGE_READ | _PAGE_SILENT_READ);
178         (pte).pte_high &= ~_PAGE_SILENT_READ;
179         return pte;
180 }
181
182 static inline pte_t pte_mkclean(pte_t pte)
183 {
184         (pte).pte_low &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
185         (pte).pte_high &= ~_PAGE_SILENT_WRITE;
186         return pte;
187 }
188
189 static inline pte_t pte_mkold(pte_t pte)
190 {
191         (pte).pte_low &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
192         (pte).pte_high &= ~_PAGE_SILENT_READ;
193         return pte;
194 }
195
196 static inline pte_t pte_mkwrite(pte_t pte)
197 {
198         (pte).pte_low |= _PAGE_WRITE;
199         if ((pte).pte_low & _PAGE_MODIFIED) {
200                 (pte).pte_low |= _PAGE_SILENT_WRITE;
201                 (pte).pte_high |= _PAGE_SILENT_WRITE;
202         }
203         return pte;
204 }
205
206 static inline pte_t pte_mkread(pte_t pte)
207 {
208         (pte).pte_low |= _PAGE_READ;
209         if ((pte).pte_low & _PAGE_ACCESSED) {
210                 (pte).pte_low |= _PAGE_SILENT_READ;
211                 (pte).pte_high |= _PAGE_SILENT_READ;
212         }
213         return pte;
214 }
215
216 static inline pte_t pte_mkdirty(pte_t pte)
217 {
218         (pte).pte_low |= _PAGE_MODIFIED;
219         if ((pte).pte_low & _PAGE_WRITE) {
220                 (pte).pte_low |= _PAGE_SILENT_WRITE;
221                 (pte).pte_high |= _PAGE_SILENT_WRITE;
222         }
223         return pte;
224 }
225
226 static inline pte_t pte_mkyoung(pte_t pte)
227 {
228         (pte).pte_low |= _PAGE_ACCESSED;
229         if ((pte).pte_low & _PAGE_READ)
230                 (pte).pte_low |= _PAGE_SILENT_READ;
231                 (pte).pte_high |= _PAGE_SILENT_READ;
232         return pte;
233 }
234 #else
235 static inline int pte_read(pte_t pte)   { return pte_val(pte) & _PAGE_READ; }
236 static inline int pte_write(pte_t pte)  { return pte_val(pte) & _PAGE_WRITE; }
237 static inline int pte_dirty(pte_t pte)  { return pte_val(pte) & _PAGE_MODIFIED; }
238 static inline int pte_young(pte_t pte)  { return pte_val(pte) & _PAGE_ACCESSED; }
239 static inline int pte_file(pte_t pte)   { return pte_val(pte) & _PAGE_FILE; }
240
241 static inline pte_t pte_wrprotect(pte_t pte)
242 {
243         pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
244         return pte;
245 }
246
247 static inline pte_t pte_rdprotect(pte_t pte)
248 {
249         pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
250         return pte;
251 }
252
253 static inline pte_t pte_mkclean(pte_t pte)
254 {
255         pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
256         return pte;
257 }
258
259 static inline pte_t pte_mkold(pte_t pte)
260 {
261         pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
262         return pte;
263 }
264
265 static inline pte_t pte_mkwrite(pte_t pte)
266 {
267         pte_val(pte) |= _PAGE_WRITE;
268         if (pte_val(pte) & _PAGE_MODIFIED)
269                 pte_val(pte) |= _PAGE_SILENT_WRITE;
270         return pte;
271 }
272
273 static inline pte_t pte_mkread(pte_t pte)
274 {
275         pte_val(pte) |= _PAGE_READ;
276         if (pte_val(pte) & _PAGE_ACCESSED)
277                 pte_val(pte) |= _PAGE_SILENT_READ;
278         return pte;
279 }
280
281 static inline pte_t pte_mkdirty(pte_t pte)
282 {
283         pte_val(pte) |= _PAGE_MODIFIED;
284         if (pte_val(pte) & _PAGE_WRITE)
285                 pte_val(pte) |= _PAGE_SILENT_WRITE;
286         return pte;
287 }
288
289 static inline pte_t pte_mkyoung(pte_t pte)
290 {
291         pte_val(pte) |= _PAGE_ACCESSED;
292         if (pte_val(pte) & _PAGE_READ)
293                 pte_val(pte) |= _PAGE_SILENT_READ;
294         return pte;
295 }
296 #endif
297
298 /*
299  * Macro to make mark a page protection value as "uncacheable".  Note
300  * that "protection" is really a misnomer here as the protection value
301  * contains the memory attribute bits, dirty bits, and various other
302  * bits as well.
303  */
304 #define pgprot_noncached pgprot_noncached
305
306 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
307 {
308         unsigned long prot = pgprot_val(_prot);
309
310         prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
311
312         return __pgprot(prot);
313 }
314
315 /*
316  * Conversion functions: convert a page and protection to a page entry,
317  * and a page entry and page directory to the page they refer to.
318  */
319 #define mk_pte(page, pgprot)    pfn_pte(page_to_pfn(page), (pgprot))
320
321 #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
322 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
323 {
324         pte.pte_low &= _PAGE_CHG_MASK;
325         pte.pte_low |= pgprot_val(newprot);
326         pte.pte_high |= pgprot_val(newprot) & 0x3f;
327         return pte;
328 }
329 #else
330 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
331 {
332         return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
333 }
334 #endif
335
336
337 extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
338         pte_t pte);
339 extern void __update_cache(struct vm_area_struct *vma, unsigned long address,
340         pte_t pte);
341
342 static inline void update_mmu_cache(struct vm_area_struct *vma,
343         unsigned long address, pte_t pte)
344 {
345         __update_tlb(vma, address, pte);
346         __update_cache(vma, address, pte);
347 }
348
349 #ifndef CONFIG_DISCONTIGMEM
350 #define kern_addr_valid(addr)   (1)
351 #endif
352
353 #ifdef CONFIG_64BIT_PHYS_ADDR
354 extern phys_t fixup_bigphys_addr(phys_t phys_addr, phys_t size);
355 extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot);
356
357 static inline int io_remap_page_range(struct vm_area_struct *vma,
358                 unsigned long vaddr,
359                 unsigned long paddr,
360                 unsigned long size,
361                 pgprot_t prot)
362 {
363         phys_t phys_addr_high = fixup_bigphys_addr(paddr, size);
364         return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot);
365 }
366 #else
367 #define io_remap_page_range(vma, vaddr, paddr, size, prot)              \
368         remap_pfn_range(vma, vaddr, (paddr) >> PAGE_SHIFT, size, prot)
369 #endif
370
371 #include <asm-generic/pgtable.h>
372
373 /*
374  * We provide our own get_unmapped area to cope with the virtual aliasing
375  * constraints placed on us by the cache architecture.
376  */
377 #define HAVE_ARCH_UNMAPPED_AREA
378
379 /*
380  * No page table caches to initialise
381  */
382 #define pgtable_cache_init()    do { } while (0)
383
384 #endif /* _ASM_PGTABLE_H */