VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-sparc / pgtable.h
1 /* $Id: pgtable.h,v 1.110 2001/12/21 04:56:17 davem Exp $ */
2 #ifndef _SPARC_PGTABLE_H
3 #define _SPARC_PGTABLE_H
4
5 /*  asm-sparc/pgtable.h:  Defines and functions used to work
6  *                        with Sparc page tables.
7  *
8  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
9  *  Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
10  */
11
12 #include <linux/config.h>
13 #include <linux/spinlock.h>
14 #include <linux/swap.h>
15 #include <asm/types.h>
16 #ifdef CONFIG_SUN4
17 #include <asm/pgtsun4.h>
18 #else
19 #include <asm/pgtsun4c.h>
20 #endif
21 #include <asm/pgtsrmmu.h>
22 #include <asm/vac-ops.h>
23 #include <asm/oplib.h>
24 #include <asm/btfixup.h>
25 #include <asm/system.h>
26
27 #ifndef __ASSEMBLY__
28
29 struct vm_area_struct;
30 struct page;
31
32 extern void load_mmu(void);
33 extern unsigned long calc_highpages(void);
34
35 BTFIXUPDEF_SIMM13(pgdir_shift)
36 BTFIXUPDEF_SETHI(pgdir_size)
37 BTFIXUPDEF_SETHI(pgdir_mask)
38
39 BTFIXUPDEF_SIMM13(ptrs_per_pmd)
40 BTFIXUPDEF_SIMM13(ptrs_per_pgd)
41 BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
42
43 #define pte_ERROR(e)   __builtin_trap()
44 #define pmd_ERROR(e)   __builtin_trap()
45 #define pgd_ERROR(e)   __builtin_trap()
46
47 BTFIXUPDEF_INT(page_none)
48 BTFIXUPDEF_INT(page_shared)
49 BTFIXUPDEF_INT(page_copy)
50 BTFIXUPDEF_INT(page_readonly)
51 BTFIXUPDEF_INT(page_kernel)
52
53 #define PMD_SHIFT               SUN4C_PMD_SHIFT
54 #define PMD_SIZE                (1UL << PMD_SHIFT)
55 #define PMD_MASK                (~(PMD_SIZE-1))
56 #define PMD_ALIGN(__addr)       (((__addr) + ~PMD_MASK) & PMD_MASK)
57 #define PGDIR_SHIFT             BTFIXUP_SIMM13(pgdir_shift)
58 #define PGDIR_SIZE              BTFIXUP_SETHI(pgdir_size)
59 #define PGDIR_MASK              BTFIXUP_SETHI(pgdir_mask)
60 #define PTRS_PER_PTE            1024
61 #define PTRS_PER_PMD            BTFIXUP_SIMM13(ptrs_per_pmd)
62 #define PTRS_PER_PGD            BTFIXUP_SIMM13(ptrs_per_pgd)
63 #define USER_PTRS_PER_PGD       BTFIXUP_SIMM13(user_ptrs_per_pgd)
64 #define FIRST_USER_PGD_NR       0
65 #define PTE_SIZE                (PTRS_PER_PTE*4)
66
67 #define PAGE_NONE      __pgprot(BTFIXUP_INT(page_none))
68 #define PAGE_SHARED    __pgprot(BTFIXUP_INT(page_shared))
69 #define PAGE_COPY      __pgprot(BTFIXUP_INT(page_copy))
70 #define PAGE_READONLY  __pgprot(BTFIXUP_INT(page_readonly))
71
72 extern unsigned long page_kernel;
73
74 #ifdef MODULE
75 #define PAGE_KERNEL     page_kernel
76 #else
77 #define PAGE_KERNEL    __pgprot(BTFIXUP_INT(page_kernel))
78 #endif
79
80 /* Top-level page directory */
81 extern pgd_t swapper_pg_dir[1024];
82
83 /* Page table for 0-4MB for everybody, on the Sparc this
84  * holds the same as on the i386.
85  */
86 extern pte_t pg0[1024];
87 extern pte_t pg1[1024];
88 extern pte_t pg2[1024];
89 extern pte_t pg3[1024];
90
91 extern unsigned long ptr_in_current_pgd;
92
93 /* Here is a trick, since mmap.c need the initializer elements for
94  * protection_map[] to be constant at compile time, I set the following
95  * to all zeros.  I set it to the real values after I link in the
96  * appropriate MMU page table routines at boot time.
97  */
98 #define __P000  __pgprot(0)
99 #define __P001  __pgprot(0)
100 #define __P010  __pgprot(0)
101 #define __P011  __pgprot(0)
102 #define __P100  __pgprot(0)
103 #define __P101  __pgprot(0)
104 #define __P110  __pgprot(0)
105 #define __P111  __pgprot(0)
106
107 #define __S000  __pgprot(0)
108 #define __S001  __pgprot(0)
109 #define __S010  __pgprot(0)
110 #define __S011  __pgprot(0)
111 #define __S100  __pgprot(0)
112 #define __S101  __pgprot(0)
113 #define __S110  __pgprot(0)
114 #define __S111  __pgprot(0)
115
116 extern int num_contexts;
117
118 /* First physical page can be anywhere, the following is needed so that
119  * va-->pa and vice versa conversions work properly without performance
120  * hit for all __pa()/__va() operations.
121  */
122 extern unsigned long phys_base;
123 extern unsigned long pfn_base;
124
125 /*
126  * BAD_PAGETABLE is used when we need a bogus page-table, while
127  * BAD_PAGE is used for a bogus page.
128  *
129  * ZERO_PAGE is a global shared page that is always zero: used
130  * for zero-mapped memory areas etc..
131  */
132 extern pte_t * __bad_pagetable(void);
133 extern pte_t __bad_page(void);
134 extern unsigned long empty_zero_page;
135
136 #define BAD_PAGETABLE __bad_pagetable()
137 #define BAD_PAGE __bad_page()
138 #define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
139
140 /*
141  */
142 BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t)
143 BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page, pgd_t)
144
145 #define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd)
146 #define pgd_page(pgd) BTFIXUP_CALL(pgd_page)(pgd)
147
148 BTFIXUPDEF_SETHI(none_mask)
149 BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t)
150 BTFIXUPDEF_CALL(void, pte_clear, pte_t *)
151
152 extern __inline__ int pte_none(pte_t pte)
153 {
154         return !(pte_val(pte) & ~BTFIXUP_SETHI(none_mask));
155 }
156
157 #define pte_present(pte) BTFIXUP_CALL(pte_present)(pte)
158 #define pte_clear(pte) BTFIXUP_CALL(pte_clear)(pte)
159
160 BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t)
161 BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t)
162 BTFIXUPDEF_CALL(void, pmd_clear, pmd_t *)
163
164 extern __inline__ int pmd_none(pmd_t pmd)
165 {
166         return !(pmd_val(pmd) & ~BTFIXUP_SETHI(none_mask));
167 }
168
169 #define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd)
170 #define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd)
171 #define pmd_clear(pmd) BTFIXUP_CALL(pmd_clear)(pmd)
172
173 BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t)
174 BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t)
175 BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t)
176 BTFIXUPDEF_CALL(void, pgd_clear, pgd_t *)
177
178 #define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd)
179 #define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd)
180 #define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd)
181 #define pgd_clear(pgd) BTFIXUP_CALL(pgd_clear)(pgd)
182
183 /*
184  * The following only work if pte_present() is true.
185  * Undefined behaviour if not..
186  */
187 BTFIXUPDEF_HALF(pte_writei)
188 BTFIXUPDEF_HALF(pte_dirtyi)
189 BTFIXUPDEF_HALF(pte_youngi)
190
191 extern int pte_write(pte_t pte) __attribute_const__;
192 extern __inline__ int pte_write(pte_t pte)
193 {
194         return pte_val(pte) & BTFIXUP_HALF(pte_writei);
195 }
196
197 extern int pte_dirty(pte_t pte) __attribute_const__;
198 extern __inline__ int pte_dirty(pte_t pte)
199 {
200         return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi);
201 }
202
203 extern int pte_young(pte_t pte) __attribute_const__;
204 extern __inline__ int pte_young(pte_t pte)
205 {
206         return pte_val(pte) & BTFIXUP_HALF(pte_youngi);
207 }
208
209 /*
210  * The following only work if pte_present() is not true.
211  */
212 BTFIXUPDEF_HALF(pte_filei)
213
214 extern int pte_file(pte_t pte) __attribute_const__;
215 extern __inline__ int pte_file(pte_t pte)
216 {
217         return pte_val(pte) & BTFIXUP_HALF(pte_filei);
218 }
219
220 /*
221  */
222 BTFIXUPDEF_HALF(pte_wrprotecti)
223 BTFIXUPDEF_HALF(pte_mkcleani)
224 BTFIXUPDEF_HALF(pte_mkoldi)
225
226 extern pte_t pte_wrprotect(pte_t pte) __attribute_const__;
227 extern __inline__ pte_t pte_wrprotect(pte_t pte)
228 {
229         return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti));
230 }
231
232 extern pte_t pte_mkclean(pte_t pte) __attribute_const__;
233 extern __inline__ pte_t pte_mkclean(pte_t pte)
234 {
235         return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani));
236 }
237
238 extern pte_t pte_mkold(pte_t pte) __attribute_const__;
239 extern __inline__ pte_t pte_mkold(pte_t pte)
240 {
241         return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi));
242 }
243
244 BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t)
245 BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t)
246 BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t)
247
248 #define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte)
249 #define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte)
250 #define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte)
251
252 #define page_pte_prot(page, prot)       mk_pte(page, prot)
253 #define page_pte(page)                  mk_pte(page, __pgprot(0))
254 #define pfn_pte(pfn, prot)              mk_pte(pfn_to_page(pfn), prot)
255
256 BTFIXUPDEF_CALL(unsigned long,   pte_pfn, pte_t)
257 #define pte_pfn(pte) BTFIXUP_CALL(pte_pfn)(pte)
258 #define pte_page(pte)   pfn_to_page(pte_pfn(pte))
259
260 /*
261  * Conversion functions: convert a page and protection to a page entry,
262  * and a page entry and page directory to the page they refer to.
263  */
264 BTFIXUPDEF_CALL_CONST(pte_t, mk_pte, struct page *, pgprot_t)
265
266 BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_phys, unsigned long, pgprot_t)
267 BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_io, unsigned long, pgprot_t, int)
268
269 #define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot)
270 #define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot)
271 #define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space)
272
273 BTFIXUPDEF_INT(pte_modify_mask)
274
275 extern pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__;
276 extern __inline__ pte_t pte_modify(pte_t pte, pgprot_t newprot)
277 {
278         return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) |
279                 pgprot_val(newprot));
280 }
281
282 #define pgd_index(address) ((address) >> PGDIR_SHIFT)
283
284 /* to find an entry in a page-table-directory */
285 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
286
287 /* to find an entry in a kernel page-table-directory */
288 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
289
290 /* Find an entry in the second-level page table.. */
291 BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long)
292 #define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr)
293
294 /* Find an entry in the third-level page table.. */ 
295 BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long)
296 #define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr)
297
298 /*
299  * This shortcut works on sun4m (and sun4d) because the nocache area is static,
300  * and sun4c is guaranteed to have no highmem anyway.
301  */
302 #define pte_offset_map(d, a)            pte_offset_kernel(d,a)
303 #define pte_offset_map_nested(d, a)     pte_offset_kernel(d,a)
304
305 #define pte_unmap(pte)          do{}while(0)
306 #define pte_unmap_nested(pte)   do{}while(0)
307
308 /* The permissions for pgprot_val to make a page mapped on the obio space */
309 extern unsigned int pg_iobits;
310
311 /* Certain architectures need to do special things when pte's
312  * within a page table are directly modified.  Thus, the following
313  * hook is made available.
314  */
315
316 BTFIXUPDEF_CALL(void, set_pte, pte_t *, pte_t)
317
318 #define set_pte(ptep,pteval) BTFIXUP_CALL(set_pte)(ptep,pteval)
319
320 struct seq_file;
321 BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *)
322
323 #define mmu_info(p) BTFIXUP_CALL(mmu_info)(p)
324
325 /* Fault handler stuff... */
326 #define FAULT_CODE_PROT     0x1
327 #define FAULT_CODE_WRITE    0x2
328 #define FAULT_CODE_USER     0x4
329
330 BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t)
331
332 #define update_mmu_cache(vma,addr,pte) BTFIXUP_CALL(update_mmu_cache)(vma,addr,pte)
333
334 BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long,
335     unsigned long, unsigned int)
336 BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int)
337 #define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len)
338 #define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len)
339
340 extern int invalid_segment;
341
342 /* Encode and de-code a swap entry */
343 BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t)
344 BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t)
345 BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long)
346
347 #define __swp_type(__x)                 BTFIXUP_CALL(__swp_type)(__x)
348 #define __swp_offset(__x)               BTFIXUP_CALL(__swp_offset)(__x)
349 #define __swp_entry(__type,__off)       BTFIXUP_CALL(__swp_entry)(__type,__off)
350
351 #define __pte_to_swp_entry(pte)         ((swp_entry_t) { pte_val(pte) })
352 #define __swp_entry_to_pte(x)           ((pte_t) { (x).val })
353
354 /* file-offset-in-pte helpers */
355 BTFIXUPDEF_CALL(unsigned long, pte_to_pgoff, pte_t pte);
356 BTFIXUPDEF_CALL(pte_t, pgoff_to_pte, unsigned long pgoff);
357
358 #define pte_to_pgoff(pte) BTFIXUP_CALL(pte_to_pgoff)(pte)
359 #define pgoff_to_pte(off) BTFIXUP_CALL(pgoff_to_pte)(off)
360
361 /*
362  * This is made a constant because mm/fremap.c required a constant.
363  * Note that layout of these bits is different between sun4c.c and srmmu.c.
364  */
365 #define PTE_FILE_MAX_BITS 24
366
367 /*
368  */
369 struct ctx_list {
370         struct ctx_list *next;
371         struct ctx_list *prev;
372         unsigned int ctx_number;
373         struct mm_struct *ctx_mm;
374 };
375
376 extern struct ctx_list *ctx_list_pool;  /* Dynamically allocated */
377 extern struct ctx_list ctx_free;        /* Head of free list */
378 extern struct ctx_list ctx_used;        /* Head of used contexts list */
379
380 #define NO_CONTEXT     -1
381
382 extern __inline__ void remove_from_ctx_list(struct ctx_list *entry)
383 {
384         entry->next->prev = entry->prev;
385         entry->prev->next = entry->next;
386 }
387
388 extern __inline__ void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
389 {
390         entry->next = head;
391         (entry->prev = head->prev)->next = entry;
392         head->prev = entry;
393 }
394 #define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
395 #define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
396
397 extern __inline__ unsigned long
398 __get_phys (unsigned long addr)
399 {
400         switch (sparc_cpu_model){
401         case sun4:
402         case sun4c:
403                 return sun4c_get_pte (addr) << PAGE_SHIFT;
404         case sun4m:
405         case sun4d:
406                 return ((srmmu_get_pte (addr) & 0xffffff00) << 4);
407         default:
408                 return 0;
409         }
410 }
411
412 extern __inline__ int
413 __get_iospace (unsigned long addr)
414 {
415         switch (sparc_cpu_model){
416         case sun4:
417         case sun4c:
418                 return -1; /* Don't check iospace on sun4c */
419         case sun4m:
420         case sun4d:
421                 return (srmmu_get_pte (addr) >> 28);
422         default:
423                 return -1;
424         }
425 }
426
427 extern unsigned long *sparc_valid_addr_bitmap;
428
429 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
430 #define kern_addr_valid(addr) \
431         (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap))
432
433 extern int io_remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long to,
434                                unsigned long size, pgprot_t prot, int space);
435
436 #include <asm-generic/pgtable.h>
437
438 #endif /* !(__ASSEMBLY__) */
439
440 /* We provide our own get_unmapped_area to cope with VA holes for userland */
441 #define HAVE_ARCH_UNMAPPED_AREA
442
443 /*
444  * No page table caches to initialise
445  */
446 #define pgtable_cache_init()    do { } while (0)
447
448 #endif /* !(_SPARC_PGTABLE_H) */