1 #ifndef _SPARC_PGTABLE_H
2 #define _SPARC_PGTABLE_H
4 /* asm/pgtable.h: Defines and functions used to work
5 * with Sparc page tables.
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
11 #include <linux/const.h>
14 #include <asm-generic/4level-fixup.h>
16 #include <linux/spinlock.h>
17 #include <linux/swap.h>
18 #include <asm/types.h>
19 #include <asm/pgtsrmmu.h>
20 #include <asm/oplib.h>
21 #include <asm/btfixup.h>
22 #include <asm/cpu_type.h>
25 struct vm_area_struct;
28 extern void load_mmu(void);
29 extern unsigned long calc_highpages(void);
31 #define pte_ERROR(e) __builtin_trap()
32 #define pmd_ERROR(e) __builtin_trap()
33 #define pgd_ERROR(e) __builtin_trap()
35 BTFIXUPDEF_INT(page_none)
36 BTFIXUPDEF_INT(page_copy)
37 BTFIXUPDEF_INT(page_readonly)
38 BTFIXUPDEF_INT(page_kernel)
41 #define PMD_SIZE (1UL << PMD_SHIFT)
42 #define PMD_MASK (~(PMD_SIZE-1))
43 #define PMD_ALIGN(__addr) (((__addr) + ~PMD_MASK) & PMD_MASK)
44 #define PGDIR_SHIFT SRMMU_PGDIR_SHIFT
45 #define PGDIR_SIZE SRMMU_PGDIR_SIZE
46 #define PGDIR_MASK SRMMU_PGDIR_MASK
47 #define PTRS_PER_PTE 1024
48 #define PTRS_PER_PMD SRMMU_PTRS_PER_PMD
49 #define PTRS_PER_PGD SRMMU_PTRS_PER_PGD
50 #define USER_PTRS_PER_PGD PAGE_OFFSET / SRMMU_PGDIR_SIZE
51 #define FIRST_USER_ADDRESS 0
52 #define PTE_SIZE (PTRS_PER_PTE*4)
54 #define PAGE_NONE __pgprot(BTFIXUP_INT(page_none))
55 extern pgprot_t PAGE_SHARED;
56 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
57 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
59 extern unsigned long page_kernel;
62 #define PAGE_KERNEL page_kernel
64 #define PAGE_KERNEL __pgprot(BTFIXUP_INT(page_kernel))
67 /* Top-level page directory */
68 extern pgd_t swapper_pg_dir[1024];
70 extern void paging_init(void);
72 extern unsigned long ptr_in_current_pgd;
74 /* Here is a trick, since mmap.c need the initializer elements for
75 * protection_map[] to be constant at compile time, I set the following
76 * to all zeros. I set it to the real values after I link in the
77 * appropriate MMU page table routines at boot time.
79 #define __P000 __pgprot(0)
80 #define __P001 __pgprot(0)
81 #define __P010 __pgprot(0)
82 #define __P011 __pgprot(0)
83 #define __P100 __pgprot(0)
84 #define __P101 __pgprot(0)
85 #define __P110 __pgprot(0)
86 #define __P111 __pgprot(0)
88 #define __S000 __pgprot(0)
89 #define __S001 __pgprot(0)
90 #define __S010 __pgprot(0)
91 #define __S011 __pgprot(0)
92 #define __S100 __pgprot(0)
93 #define __S101 __pgprot(0)
94 #define __S110 __pgprot(0)
95 #define __S111 __pgprot(0)
97 extern int num_contexts;
99 /* First physical page can be anywhere, the following is needed so that
100 * va-->pa and vice versa conversions work properly without performance
101 * hit for all __pa()/__va() operations.
103 extern unsigned long phys_base;
104 extern unsigned long pfn_base;
107 * BAD_PAGETABLE is used when we need a bogus page-table, while
108 * BAD_PAGE is used for a bogus page.
110 * ZERO_PAGE is a global shared page that is always zero: used
111 * for zero-mapped memory areas etc..
113 extern pte_t * __bad_pagetable(void);
114 extern pte_t __bad_page(void);
115 extern unsigned long empty_zero_page;
117 #define BAD_PAGETABLE __bad_pagetable()
118 #define BAD_PAGE __bad_page()
119 #define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
122 * In general all page table modifications should use the V8 atomic
123 * swap instruction. This insures the mmu and the cpu are in sync
124 * with respect to ref/mod bits in the page tables.
126 static inline unsigned long srmmu_swap(unsigned long *addr, unsigned long value)
128 __asm__ __volatile__("swap [%2], %0" : "=&r" (value) : "0" (value), "r" (addr));
132 static inline void srmmu_set_pte(pte_t *ptep, pte_t pteval)
134 srmmu_swap((unsigned long *)ptep, pte_val(pteval));
139 BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t)
140 BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page_vaddr, pgd_t)
142 #define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd)
143 #define pgd_page_vaddr(pgd) BTFIXUP_CALL(pgd_page_vaddr)(pgd)
145 BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t)
147 static inline int pte_none(pte_t pte)
149 return !pte_val(pte);
152 #define pte_present(pte) BTFIXUP_CALL(pte_present)(pte)
154 static inline void __pte_clear(pte_t *ptep)
156 srmmu_set_pte(ptep, __pte(0));
159 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
164 BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t)
165 BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t)
167 static inline int pmd_none(pmd_t pmd)
169 return !pmd_val(pmd);
172 #define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd)
173 #define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd)
175 static inline void pmd_clear(pmd_t *pmdp)
178 for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++)
179 srmmu_set_pte((pte_t *)&pmdp->pmdv[i], __pte(0));
182 BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t)
183 BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t)
184 BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t)
186 #define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd)
187 #define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd)
188 #define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd)
190 static inline void pgd_clear(pgd_t *pgdp)
192 srmmu_set_pte((pte_t *)pgdp, __pte(0));
196 * The following only work if pte_present() is true.
197 * Undefined behaviour if not..
199 BTFIXUPDEF_HALF(pte_writei)
200 BTFIXUPDEF_HALF(pte_dirtyi)
201 BTFIXUPDEF_HALF(pte_youngi)
203 static int pte_write(pte_t pte) __attribute_const__;
204 static inline int pte_write(pte_t pte)
206 return pte_val(pte) & BTFIXUP_HALF(pte_writei);
209 static int pte_dirty(pte_t pte) __attribute_const__;
210 static inline int pte_dirty(pte_t pte)
212 return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi);
215 static int pte_young(pte_t pte) __attribute_const__;
216 static inline int pte_young(pte_t pte)
218 return pte_val(pte) & BTFIXUP_HALF(pte_youngi);
222 * The following only work if pte_present() is not true.
224 BTFIXUPDEF_HALF(pte_filei)
226 static int pte_file(pte_t pte) __attribute_const__;
227 static inline int pte_file(pte_t pte)
229 return pte_val(pte) & BTFIXUP_HALF(pte_filei);
232 static inline int pte_special(pte_t pte)
239 BTFIXUPDEF_HALF(pte_wrprotecti)
240 BTFIXUPDEF_HALF(pte_mkcleani)
241 BTFIXUPDEF_HALF(pte_mkoldi)
243 static pte_t pte_wrprotect(pte_t pte) __attribute_const__;
244 static inline pte_t pte_wrprotect(pte_t pte)
246 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti));
249 static pte_t pte_mkclean(pte_t pte) __attribute_const__;
250 static inline pte_t pte_mkclean(pte_t pte)
252 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani));
255 static pte_t pte_mkold(pte_t pte) __attribute_const__;
256 static inline pte_t pte_mkold(pte_t pte)
258 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi));
261 BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t)
262 BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t)
263 BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t)
265 #define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte)
266 #define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte)
267 #define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte)
269 #define pte_mkspecial(pte) (pte)
271 #define pfn_pte(pfn, prot) mk_pte(pfn_to_page(pfn), prot)
273 BTFIXUPDEF_CALL(unsigned long, pte_pfn, pte_t)
274 #define pte_pfn(pte) BTFIXUP_CALL(pte_pfn)(pte)
275 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
278 * Conversion functions: convert a page and protection to a page entry,
279 * and a page entry and page directory to the page they refer to.
281 BTFIXUPDEF_CALL_CONST(pte_t, mk_pte, struct page *, pgprot_t)
283 BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_phys, unsigned long, pgprot_t)
284 BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_io, unsigned long, pgprot_t, int)
286 #define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot)
287 #define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot)
288 #define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space)
290 #define pgprot_noncached pgprot_noncached
291 static inline pgprot_t pgprot_noncached(pgprot_t prot)
293 prot &= ~__pgprot(SRMMU_CACHE);
297 BTFIXUPDEF_INT(pte_modify_mask)
299 static pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__;
300 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
302 return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) |
303 pgprot_val(newprot));
306 #define pgd_index(address) ((address) >> PGDIR_SHIFT)
308 /* to find an entry in a page-table-directory */
309 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
311 /* to find an entry in a kernel page-table-directory */
312 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
314 /* Find an entry in the second-level page table.. */
315 BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long)
316 #define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr)
318 /* Find an entry in the third-level page table.. */
319 BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long)
320 #define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr)
323 * This shortcut works on sun4m (and sun4d) because the nocache area is static.
325 #define pte_offset_map(d, a) pte_offset_kernel(d,a)
326 #define pte_unmap(pte) do{}while(0)
328 /* Certain architectures need to do special things when pte's
329 * within a page table are directly modified. Thus, the following
330 * hook is made available.
333 BTFIXUPDEF_CALL(void, set_pte, pte_t *, pte_t)
335 #define set_pte(ptep,pteval) BTFIXUP_CALL(set_pte)(ptep,pteval)
336 #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
339 BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *)
341 #define mmu_info(p) BTFIXUP_CALL(mmu_info)(p)
343 /* Fault handler stuff... */
344 #define FAULT_CODE_PROT 0x1
345 #define FAULT_CODE_WRITE 0x2
346 #define FAULT_CODE_USER 0x4
348 BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t *)
350 #define update_mmu_cache(vma,addr,ptep) BTFIXUP_CALL(update_mmu_cache)(vma,addr,ptep)
352 BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long,
353 unsigned long, unsigned int)
354 BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int)
355 #define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len)
356 #define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len)
358 extern int invalid_segment;
360 /* Encode and de-code a swap entry */
361 BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t)
362 BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t)
363 BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long)
365 #define __swp_type(__x) BTFIXUP_CALL(__swp_type)(__x)
366 #define __swp_offset(__x) BTFIXUP_CALL(__swp_offset)(__x)
367 #define __swp_entry(__type,__off) BTFIXUP_CALL(__swp_entry)(__type,__off)
369 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
370 #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
372 /* file-offset-in-pte helpers */
373 static inline unsigned long pte_to_pgoff(pte_t pte)
375 return pte_val(pte) >> SRMMU_PTE_FILE_SHIFT;
378 static inline pte_t pgoff_to_pte(unsigned long pgoff)
380 return __pte((pgoff << SRMMU_PTE_FILE_SHIFT) | SRMMU_FILE);
384 * This is made a constant because mm/fremap.c required a constant.
386 #define PTE_FILE_MAX_BITS 24
391 struct ctx_list *next;
392 struct ctx_list *prev;
393 unsigned int ctx_number;
394 struct mm_struct *ctx_mm;
397 extern struct ctx_list *ctx_list_pool; /* Dynamically allocated */
398 extern struct ctx_list ctx_free; /* Head of free list */
399 extern struct ctx_list ctx_used; /* Head of used contexts list */
401 #define NO_CONTEXT -1
403 static inline void remove_from_ctx_list(struct ctx_list *entry)
405 entry->next->prev = entry->prev;
406 entry->prev->next = entry->next;
409 static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
412 (entry->prev = head->prev)->next = entry;
415 #define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
416 #define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
418 static inline unsigned long
419 __get_phys (unsigned long addr)
421 switch (sparc_cpu_model){
424 return ((srmmu_get_pte (addr) & 0xffffff00) << 4);
431 __get_iospace (unsigned long addr)
433 switch (sparc_cpu_model){
436 return (srmmu_get_pte (addr) >> 28);
442 extern unsigned long *sparc_valid_addr_bitmap;
444 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
445 #define kern_addr_valid(addr) \
446 (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap))
449 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
450 * its high 4 bits. These macros/functions put it there or get it from there.
452 #define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
453 #define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
454 #define GET_PFN(pfn) (pfn & 0x0fffffffUL)
456 extern int remap_pfn_range(struct vm_area_struct *, unsigned long, unsigned long,
457 unsigned long, pgprot_t);
459 static inline int io_remap_pfn_range(struct vm_area_struct *vma,
460 unsigned long from, unsigned long pfn,
461 unsigned long size, pgprot_t prot)
463 unsigned long long offset, space, phys_base;
465 offset = ((unsigned long long) GET_PFN(pfn)) << PAGE_SHIFT;
466 space = GET_IOSPACE(pfn);
467 phys_base = offset | (space << 32ULL);
469 return remap_pfn_range(vma, from, phys_base >> PAGE_SHIFT, size, prot);
472 #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
473 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
475 int __changed = !pte_same(*(__ptep), __entry); \
477 set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
478 flush_tlb_page(__vma, __address); \
483 #include <asm-generic/pgtable.h>
485 #endif /* !(__ASSEMBLY__) */
487 #define VMALLOC_START _AC(0xfe600000,UL)
488 #define VMALLOC_END _AC(0xffc00000,UL)
490 /* We provide our own get_unmapped_area to cope with VA holes for userland */
491 #define HAVE_ARCH_UNMAPPED_AREA
494 * No page table caches to initialise
496 #define pgtable_cache_init() do { } while (0)
498 #endif /* !(_SPARC_PGTABLE_H) */