Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <asm-generic/4level-fixup.h> |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/swap.h> |
| 16 | #include <asm/types.h> |
| 17 | #ifdef CONFIG_SUN4 |
| 18 | #include <asm/pgtsun4.h> |
| 19 | #else |
| 20 | #include <asm/pgtsun4c.h> |
| 21 | #endif |
| 22 | #include <asm/pgtsrmmu.h> |
| 23 | #include <asm/vac-ops.h> |
| 24 | #include <asm/oplib.h> |
| 25 | #include <asm/btfixup.h> |
| 26 | #include <asm/system.h> |
| 27 | |
| 28 | #ifndef __ASSEMBLY__ |
| 29 | |
| 30 | struct vm_area_struct; |
| 31 | struct page; |
| 32 | |
| 33 | extern void load_mmu(void); |
| 34 | extern unsigned long calc_highpages(void); |
| 35 | |
| 36 | BTFIXUPDEF_SIMM13(pgdir_shift) |
| 37 | BTFIXUPDEF_SETHI(pgdir_size) |
| 38 | BTFIXUPDEF_SETHI(pgdir_mask) |
| 39 | |
| 40 | BTFIXUPDEF_SIMM13(ptrs_per_pmd) |
| 41 | BTFIXUPDEF_SIMM13(ptrs_per_pgd) |
| 42 | BTFIXUPDEF_SIMM13(user_ptrs_per_pgd) |
| 43 | |
| 44 | #define pte_ERROR(e) __builtin_trap() |
| 45 | #define pmd_ERROR(e) __builtin_trap() |
| 46 | #define pgd_ERROR(e) __builtin_trap() |
| 47 | |
| 48 | BTFIXUPDEF_INT(page_none) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Hugh Dickins | d455a36 | 2005-04-19 13:29:23 -0700 | [diff] [blame] | 64 | #define FIRST_USER_ADDRESS 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define PTE_SIZE (PTRS_PER_PTE*4) |
| 66 | |
| 67 | #define PAGE_NONE __pgprot(BTFIXUP_INT(page_none)) |
Al Viro | 378e515 | 2007-07-21 19:20:34 -0700 | [diff] [blame] | 68 | extern pgprot_t PAGE_SHARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David S. Miller | 801ab3c | 2005-09-28 21:31:25 -0700 | [diff] [blame] | 83 | extern void paging_init(void); |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* Page table for 0-4MB for everybody, on the Sparc this |
| 86 | * holds the same as on the i386. |
| 87 | */ |
| 88 | extern pte_t pg0[1024]; |
| 89 | extern pte_t pg1[1024]; |
| 90 | extern pte_t pg2[1024]; |
| 91 | extern pte_t pg3[1024]; |
| 92 | |
| 93 | extern unsigned long ptr_in_current_pgd; |
| 94 | |
| 95 | /* Here is a trick, since mmap.c need the initializer elements for |
| 96 | * protection_map[] to be constant at compile time, I set the following |
| 97 | * to all zeros. I set it to the real values after I link in the |
| 98 | * appropriate MMU page table routines at boot time. |
| 99 | */ |
| 100 | #define __P000 __pgprot(0) |
| 101 | #define __P001 __pgprot(0) |
| 102 | #define __P010 __pgprot(0) |
| 103 | #define __P011 __pgprot(0) |
| 104 | #define __P100 __pgprot(0) |
| 105 | #define __P101 __pgprot(0) |
| 106 | #define __P110 __pgprot(0) |
| 107 | #define __P111 __pgprot(0) |
| 108 | |
| 109 | #define __S000 __pgprot(0) |
| 110 | #define __S001 __pgprot(0) |
| 111 | #define __S010 __pgprot(0) |
| 112 | #define __S011 __pgprot(0) |
| 113 | #define __S100 __pgprot(0) |
| 114 | #define __S101 __pgprot(0) |
| 115 | #define __S110 __pgprot(0) |
| 116 | #define __S111 __pgprot(0) |
| 117 | |
| 118 | extern int num_contexts; |
| 119 | |
| 120 | /* First physical page can be anywhere, the following is needed so that |
| 121 | * va-->pa and vice versa conversions work properly without performance |
| 122 | * hit for all __pa()/__va() operations. |
| 123 | */ |
| 124 | extern unsigned long phys_base; |
| 125 | extern unsigned long pfn_base; |
| 126 | |
| 127 | /* |
| 128 | * BAD_PAGETABLE is used when we need a bogus page-table, while |
| 129 | * BAD_PAGE is used for a bogus page. |
| 130 | * |
| 131 | * ZERO_PAGE is a global shared page that is always zero: used |
| 132 | * for zero-mapped memory areas etc.. |
| 133 | */ |
| 134 | extern pte_t * __bad_pagetable(void); |
| 135 | extern pte_t __bad_page(void); |
| 136 | extern unsigned long empty_zero_page; |
| 137 | |
| 138 | #define BAD_PAGETABLE __bad_pagetable() |
| 139 | #define BAD_PAGE __bad_page() |
| 140 | #define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page)) |
| 141 | |
| 142 | /* |
| 143 | */ |
| 144 | BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t) |
Dave McCracken | 46a82b2 | 2006-09-25 23:31:48 -0700 | [diff] [blame] | 145 | BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page_vaddr, pgd_t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | #define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd) |
Dave McCracken | 46a82b2 | 2006-09-25 23:31:48 -0700 | [diff] [blame] | 148 | #define pgd_page_vaddr(pgd) BTFIXUP_CALL(pgd_page_vaddr)(pgd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | BTFIXUPDEF_SETHI(none_mask) |
| 151 | BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t) |
| 152 | BTFIXUPDEF_CALL(void, pte_clear, pte_t *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 154 | static inline int pte_none(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
| 156 | return !(pte_val(pte) & ~BTFIXUP_SETHI(none_mask)); |
| 157 | } |
| 158 | |
| 159 | #define pte_present(pte) BTFIXUP_CALL(pte_present)(pte) |
| 160 | #define pte_clear(mm,addr,pte) BTFIXUP_CALL(pte_clear)(pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t) |
| 163 | BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t) |
| 164 | BTFIXUPDEF_CALL(void, pmd_clear, pmd_t *) |
| 165 | |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 166 | static inline int pmd_none(pmd_t pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
| 168 | return !(pmd_val(pmd) & ~BTFIXUP_SETHI(none_mask)); |
| 169 | } |
| 170 | |
| 171 | #define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd) |
| 172 | #define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd) |
| 173 | #define pmd_clear(pmd) BTFIXUP_CALL(pmd_clear)(pmd) |
| 174 | |
| 175 | BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t) |
| 176 | BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t) |
| 177 | BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t) |
| 178 | BTFIXUPDEF_CALL(void, pgd_clear, pgd_t *) |
| 179 | |
| 180 | #define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd) |
| 181 | #define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd) |
| 182 | #define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd) |
| 183 | #define pgd_clear(pgd) BTFIXUP_CALL(pgd_clear)(pgd) |
| 184 | |
| 185 | /* |
| 186 | * The following only work if pte_present() is true. |
| 187 | * Undefined behaviour if not.. |
| 188 | */ |
| 189 | BTFIXUPDEF_HALF(pte_writei) |
| 190 | BTFIXUPDEF_HALF(pte_dirtyi) |
| 191 | BTFIXUPDEF_HALF(pte_youngi) |
| 192 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 193 | static int pte_write(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 194 | static inline int pte_write(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | return pte_val(pte) & BTFIXUP_HALF(pte_writei); |
| 197 | } |
| 198 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 199 | static int pte_dirty(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 200 | static inline int pte_dirty(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi); |
| 203 | } |
| 204 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 205 | static int pte_young(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 206 | static inline int pte_young(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | return pte_val(pte) & BTFIXUP_HALF(pte_youngi); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * The following only work if pte_present() is not true. |
| 213 | */ |
| 214 | BTFIXUPDEF_HALF(pte_filei) |
| 215 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 216 | static int pte_file(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 217 | static inline int pte_file(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
| 219 | return pte_val(pte) & BTFIXUP_HALF(pte_filei); |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | */ |
| 224 | BTFIXUPDEF_HALF(pte_wrprotecti) |
| 225 | BTFIXUPDEF_HALF(pte_mkcleani) |
| 226 | BTFIXUPDEF_HALF(pte_mkoldi) |
| 227 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 228 | static pte_t pte_wrprotect(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 229 | static inline pte_t pte_wrprotect(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
| 231 | return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti)); |
| 232 | } |
| 233 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 234 | static pte_t pte_mkclean(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 235 | static inline pte_t pte_mkclean(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani)); |
| 238 | } |
| 239 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 240 | static pte_t pte_mkold(pte_t pte) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 241 | static inline pte_t pte_mkold(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi)); |
| 244 | } |
| 245 | |
| 246 | BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t) |
| 247 | BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t) |
| 248 | BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t) |
| 249 | |
| 250 | #define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte) |
| 251 | #define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte) |
| 252 | #define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte) |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
David S. Miller | 14778d9 | 2006-03-21 02:29:39 -0800 | [diff] [blame] | 268 | BTFIXUPDEF_CALL_CONST(pgprot_t, pgprot_noncached, pgprot_t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | #define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot) |
| 271 | #define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot) |
| 272 | #define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space) |
| 273 | |
David S. Miller | 14778d9 | 2006-03-21 02:29:39 -0800 | [diff] [blame] | 274 | #define pgprot_noncached(pgprot) BTFIXUP_CALL(pgprot_noncached)(pgprot) |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | BTFIXUPDEF_INT(pte_modify_mask) |
| 277 | |
Al Viro | 329d4dd | 2005-10-05 08:36:02 +0100 | [diff] [blame] | 278 | static pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__; |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 279 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
| 281 | return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) | |
| 282 | pgprot_val(newprot)); |
| 283 | } |
| 284 | |
| 285 | #define pgd_index(address) ((address) >> PGDIR_SHIFT) |
| 286 | |
| 287 | /* to find an entry in a page-table-directory */ |
| 288 | #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) |
| 289 | |
| 290 | /* to find an entry in a kernel page-table-directory */ |
| 291 | #define pgd_offset_k(address) pgd_offset(&init_mm, address) |
| 292 | |
| 293 | /* Find an entry in the second-level page table.. */ |
| 294 | BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long) |
| 295 | #define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr) |
| 296 | |
| 297 | /* Find an entry in the third-level page table.. */ |
| 298 | BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long) |
| 299 | #define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr) |
| 300 | |
| 301 | /* |
| 302 | * This shortcut works on sun4m (and sun4d) because the nocache area is static, |
| 303 | * and sun4c is guaranteed to have no highmem anyway. |
| 304 | */ |
| 305 | #define pte_offset_map(d, a) pte_offset_kernel(d,a) |
| 306 | #define pte_offset_map_nested(d, a) pte_offset_kernel(d,a) |
| 307 | |
| 308 | #define pte_unmap(pte) do{}while(0) |
| 309 | #define pte_unmap_nested(pte) do{}while(0) |
| 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) |
| 320 | |
| 321 | struct seq_file; |
| 322 | BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *) |
| 323 | |
| 324 | #define mmu_info(p) BTFIXUP_CALL(mmu_info)(p) |
| 325 | |
| 326 | /* Fault handler stuff... */ |
| 327 | #define FAULT_CODE_PROT 0x1 |
| 328 | #define FAULT_CODE_WRITE 0x2 |
| 329 | #define FAULT_CODE_USER 0x4 |
| 330 | |
| 331 | BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t) |
| 332 | |
| 333 | #define update_mmu_cache(vma,addr,pte) BTFIXUP_CALL(update_mmu_cache)(vma,addr,pte) |
| 334 | |
| 335 | BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long, |
| 336 | unsigned long, unsigned int) |
| 337 | BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int) |
| 338 | #define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len) |
| 339 | #define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len) |
| 340 | |
| 341 | extern int invalid_segment; |
| 342 | |
| 343 | /* Encode and de-code a swap entry */ |
| 344 | BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t) |
| 345 | BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t) |
| 346 | BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long) |
| 347 | |
| 348 | #define __swp_type(__x) BTFIXUP_CALL(__swp_type)(__x) |
| 349 | #define __swp_offset(__x) BTFIXUP_CALL(__swp_offset)(__x) |
| 350 | #define __swp_entry(__type,__off) BTFIXUP_CALL(__swp_entry)(__type,__off) |
| 351 | |
| 352 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) |
| 353 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) |
| 354 | |
| 355 | /* file-offset-in-pte helpers */ |
| 356 | BTFIXUPDEF_CALL(unsigned long, pte_to_pgoff, pte_t pte); |
| 357 | BTFIXUPDEF_CALL(pte_t, pgoff_to_pte, unsigned long pgoff); |
| 358 | |
| 359 | #define pte_to_pgoff(pte) BTFIXUP_CALL(pte_to_pgoff)(pte) |
| 360 | #define pgoff_to_pte(off) BTFIXUP_CALL(pgoff_to_pte)(off) |
| 361 | |
| 362 | /* |
| 363 | * This is made a constant because mm/fremap.c required a constant. |
| 364 | * Note that layout of these bits is different between sun4c.c and srmmu.c. |
| 365 | */ |
| 366 | #define PTE_FILE_MAX_BITS 24 |
| 367 | |
| 368 | /* |
| 369 | */ |
| 370 | struct ctx_list { |
| 371 | struct ctx_list *next; |
| 372 | struct ctx_list *prev; |
| 373 | unsigned int ctx_number; |
| 374 | struct mm_struct *ctx_mm; |
| 375 | }; |
| 376 | |
| 377 | extern struct ctx_list *ctx_list_pool; /* Dynamically allocated */ |
| 378 | extern struct ctx_list ctx_free; /* Head of free list */ |
| 379 | extern struct ctx_list ctx_used; /* Head of used contexts list */ |
| 380 | |
| 381 | #define NO_CONTEXT -1 |
| 382 | |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 383 | static inline void remove_from_ctx_list(struct ctx_list *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
| 385 | entry->next->prev = entry->prev; |
| 386 | entry->prev->next = entry->next; |
| 387 | } |
| 388 | |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 389 | static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
| 391 | entry->next = head; |
| 392 | (entry->prev = head->prev)->next = entry; |
| 393 | head->prev = entry; |
| 394 | } |
| 395 | #define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry) |
| 396 | #define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry) |
| 397 | |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 398 | static inline unsigned long |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | __get_phys (unsigned long addr) |
| 400 | { |
| 401 | switch (sparc_cpu_model){ |
| 402 | case sun4: |
| 403 | case sun4c: |
| 404 | return sun4c_get_pte (addr) << PAGE_SHIFT; |
| 405 | case sun4m: |
| 406 | case sun4d: |
| 407 | return ((srmmu_get_pte (addr) & 0xffffff00) << 4); |
| 408 | default: |
| 409 | return 0; |
| 410 | } |
| 411 | } |
| 412 | |
Adrian Bunk | 3115624 | 2005-10-03 17:37:02 -0700 | [diff] [blame] | 413 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | __get_iospace (unsigned long addr) |
| 415 | { |
| 416 | switch (sparc_cpu_model){ |
| 417 | case sun4: |
| 418 | case sun4c: |
| 419 | return -1; /* Don't check iospace on sun4c */ |
| 420 | case sun4m: |
| 421 | case sun4d: |
| 422 | return (srmmu_get_pte (addr) >> 28); |
| 423 | default: |
| 424 | return -1; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | extern unsigned long *sparc_valid_addr_bitmap; |
| 429 | |
| 430 | /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */ |
| 431 | #define kern_addr_valid(addr) \ |
| 432 | (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap)) |
| 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | extern int io_remap_pfn_range(struct vm_area_struct *vma, |
| 435 | unsigned long from, unsigned long pfn, |
| 436 | unsigned long size, pgprot_t prot); |
| 437 | |
| 438 | /* |
| 439 | * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in |
| 440 | * its high 4 bits. These macros/functions put it there or get it from there. |
| 441 | */ |
| 442 | #define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4))) |
| 443 | #define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4)) |
| 444 | #define GET_PFN(pfn) (pfn & 0x0fffffffUL) |
| 445 | |
Benjamin Herrenschmidt | 8dab524 | 2007-06-16 10:16:12 -0700 | [diff] [blame] | 446 | #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS |
| 447 | #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \ |
| 448 | ({ \ |
| 449 | int __changed = !pte_same(*(__ptep), __entry); \ |
| 450 | if (__changed) { \ |
| 451 | set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \ |
| 452 | flush_tlb_page(__vma, __address); \ |
| 453 | } \ |
| 454 | (sparc_cpu_model == sun4c) || __changed; \ |
| 455 | }) |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | #include <asm-generic/pgtable.h> |
| 458 | |
| 459 | #endif /* !(__ASSEMBLY__) */ |
| 460 | |
| 461 | /* We provide our own get_unmapped_area to cope with VA holes for userland */ |
| 462 | #define HAVE_ARCH_UNMAPPED_AREA |
| 463 | |
| 464 | /* |
| 465 | * No page table caches to initialise |
| 466 | */ |
| 467 | #define pgtable_cache_init() do { } while (0) |
| 468 | |
| 469 | #endif /* !(_SPARC_PGTABLE_H) */ |