Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <asm-generic/4level-fixup.h> |
| 12 | |
| 13 | #include <linux/config.h> |
| 14 | #ifdef CONFIG_MIPS32 |
| 15 | #include <asm/pgtable-32.h> |
| 16 | #endif |
| 17 | #ifdef CONFIG_MIPS64 |
| 18 | #include <asm/pgtable-64.h> |
| 19 | #endif |
| 20 | |
| 21 | #include <asm/pgtable-bits.h> |
| 22 | |
| 23 | #define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT) |
| 24 | #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \ |
| 25 | PAGE_CACHABLE_DEFAULT) |
| 26 | #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | \ |
| 27 | PAGE_CACHABLE_DEFAULT) |
| 28 | #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | \ |
| 29 | PAGE_CACHABLE_DEFAULT) |
| 30 | #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \ |
| 31 | _PAGE_GLOBAL | PAGE_CACHABLE_DEFAULT) |
| 32 | #define PAGE_USERIO __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \ |
| 33 | PAGE_CACHABLE_DEFAULT) |
| 34 | #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \ |
| 35 | __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED) |
| 36 | |
| 37 | /* |
| 38 | * MIPS can't do page protection for execute, and considers that the same like |
| 39 | * read. Also, write permissions imply read permissions. This is the closest |
| 40 | * we can get by reasonable means.. |
| 41 | */ |
| 42 | #define __P000 PAGE_NONE |
| 43 | #define __P001 PAGE_READONLY |
| 44 | #define __P010 PAGE_COPY |
| 45 | #define __P011 PAGE_COPY |
| 46 | #define __P100 PAGE_READONLY |
| 47 | #define __P101 PAGE_READONLY |
| 48 | #define __P110 PAGE_COPY |
| 49 | #define __P111 PAGE_COPY |
| 50 | |
| 51 | #define __S000 PAGE_NONE |
| 52 | #define __S001 PAGE_READONLY |
| 53 | #define __S010 PAGE_SHARED |
| 54 | #define __S011 PAGE_SHARED |
| 55 | #define __S100 PAGE_READONLY |
| 56 | #define __S101 PAGE_READONLY |
| 57 | #define __S110 PAGE_SHARED |
| 58 | #define __S111 PAGE_SHARED |
| 59 | |
| 60 | /* |
| 61 | * ZERO_PAGE is a global shared page that is always zero; used |
| 62 | * for zero-mapped memory areas etc.. |
| 63 | */ |
| 64 | |
| 65 | extern unsigned long empty_zero_page; |
| 66 | extern unsigned long zero_page_mask; |
| 67 | |
| 68 | #define ZERO_PAGE(vaddr) \ |
| 69 | (virt_to_page(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))) |
| 70 | |
| 71 | extern void paging_init(void); |
| 72 | |
| 73 | /* |
| 74 | * Conversion functions: convert a page and protection to a page entry, |
| 75 | * and a page entry and page directory to the page they refer to. |
| 76 | */ |
| 77 | #define page_pte(page) page_pte_prot(page, __pgprot(0)) |
| 78 | #define pmd_phys(pmd) (pmd_val(pmd) - PAGE_OFFSET) |
| 79 | #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT)) |
| 80 | #define pmd_page_kernel(pmd) pmd_val(pmd) |
| 81 | |
| 82 | #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL)) |
| 83 | #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT) |
| 84 | |
| 85 | #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32) |
| 86 | static inline void set_pte(pte_t *ptep, pte_t pte) |
| 87 | { |
| 88 | ptep->pte_high = pte.pte_high; |
| 89 | smp_wmb(); |
| 90 | ptep->pte_low = pte.pte_low; |
| 91 | //printk("pte_high %x pte_low %x\n", ptep->pte_high, ptep->pte_low); |
| 92 | |
| 93 | if (pte_val(pte) & _PAGE_GLOBAL) { |
| 94 | pte_t *buddy = ptep_buddy(ptep); |
| 95 | /* |
| 96 | * Make sure the buddy is global too (if it's !none, |
| 97 | * it better already be global) |
| 98 | */ |
| 99 | if (pte_none(*buddy)) |
| 100 | buddy->pte_low |= _PAGE_GLOBAL; |
| 101 | } |
| 102 | } |
| 103 | #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) |
| 104 | |
| 105 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 106 | { |
| 107 | /* Preserve global status for the pair */ |
| 108 | if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL) |
| 109 | set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL)); |
| 110 | else |
| 111 | set_pte_at(mm, addr, ptep, __pte(0)); |
| 112 | } |
| 113 | #else |
| 114 | /* |
| 115 | * Certain architectures need to do special things when pte's |
| 116 | * within a page table are directly modified. Thus, the following |
| 117 | * hook is made available. |
| 118 | */ |
| 119 | static inline void set_pte(pte_t *ptep, pte_t pteval) |
| 120 | { |
| 121 | *ptep = pteval; |
| 122 | #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX) |
| 123 | if (pte_val(pteval) & _PAGE_GLOBAL) { |
| 124 | pte_t *buddy = ptep_buddy(ptep); |
| 125 | /* |
| 126 | * Make sure the buddy is global too (if it's !none, |
| 127 | * it better already be global) |
| 128 | */ |
| 129 | if (pte_none(*buddy)) |
| 130 | pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL; |
| 131 | } |
| 132 | #endif |
| 133 | } |
| 134 | #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) |
| 135 | |
| 136 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 137 | { |
| 138 | #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX) |
| 139 | /* Preserve global status for the pair */ |
| 140 | if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL) |
| 141 | set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL)); |
| 142 | else |
| 143 | #endif |
| 144 | set_pte_at(mm, addr, ptep, __pte(0)); |
| 145 | } |
| 146 | #endif |
| 147 | |
| 148 | /* |
| 149 | * (pmds are folded into pgds so this doesn't get actually called, |
| 150 | * but the define is needed for a generic inline function.) |
| 151 | */ |
| 152 | #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0) |
| 153 | #define set_pgd(pgdptr, pgdval) do { *(pgdptr) = (pgdval); } while(0) |
| 154 | |
| 155 | #define PGD_T_LOG2 ffz(~sizeof(pgd_t)) |
| 156 | #define PMD_T_LOG2 ffz(~sizeof(pmd_t)) |
| 157 | #define PTE_T_LOG2 ffz(~sizeof(pte_t)) |
| 158 | |
| 159 | extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; |
| 160 | |
| 161 | /* |
| 162 | * The following only work if pte_present() is true. |
| 163 | * Undefined behaviour if not.. |
| 164 | */ |
| 165 | static inline int pte_user(pte_t pte) { BUG(); return 0; } |
| 166 | #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32) |
| 167 | static inline int pte_read(pte_t pte) { return (pte).pte_low & _PAGE_READ; } |
| 168 | static inline int pte_write(pte_t pte) { return (pte).pte_low & _PAGE_WRITE; } |
| 169 | static inline int pte_dirty(pte_t pte) { return (pte).pte_low & _PAGE_MODIFIED; } |
| 170 | static inline int pte_young(pte_t pte) { return (pte).pte_low & _PAGE_ACCESSED; } |
| 171 | static inline int pte_file(pte_t pte) { return (pte).pte_low & _PAGE_FILE; } |
| 172 | static inline pte_t pte_wrprotect(pte_t pte) |
| 173 | { |
| 174 | (pte).pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE); |
| 175 | (pte).pte_high &= ~_PAGE_SILENT_WRITE; |
| 176 | return pte; |
| 177 | } |
| 178 | |
| 179 | static inline pte_t pte_rdprotect(pte_t pte) |
| 180 | { |
| 181 | (pte).pte_low &= ~(_PAGE_READ | _PAGE_SILENT_READ); |
| 182 | (pte).pte_high &= ~_PAGE_SILENT_READ; |
| 183 | return pte; |
| 184 | } |
| 185 | |
| 186 | static inline pte_t pte_mkclean(pte_t pte) |
| 187 | { |
| 188 | (pte).pte_low &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE); |
| 189 | (pte).pte_high &= ~_PAGE_SILENT_WRITE; |
| 190 | return pte; |
| 191 | } |
| 192 | |
| 193 | static inline pte_t pte_mkold(pte_t pte) |
| 194 | { |
| 195 | (pte).pte_low &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ); |
| 196 | (pte).pte_high &= ~_PAGE_SILENT_READ; |
| 197 | return pte; |
| 198 | } |
| 199 | |
| 200 | static inline pte_t pte_mkwrite(pte_t pte) |
| 201 | { |
| 202 | (pte).pte_low |= _PAGE_WRITE; |
| 203 | if ((pte).pte_low & _PAGE_MODIFIED) { |
| 204 | (pte).pte_low |= _PAGE_SILENT_WRITE; |
| 205 | (pte).pte_high |= _PAGE_SILENT_WRITE; |
| 206 | } |
| 207 | return pte; |
| 208 | } |
| 209 | |
| 210 | static inline pte_t pte_mkread(pte_t pte) |
| 211 | { |
| 212 | (pte).pte_low |= _PAGE_READ; |
| 213 | if ((pte).pte_low & _PAGE_ACCESSED) { |
| 214 | (pte).pte_low |= _PAGE_SILENT_READ; |
| 215 | (pte).pte_high |= _PAGE_SILENT_READ; |
| 216 | } |
| 217 | return pte; |
| 218 | } |
| 219 | |
| 220 | static inline pte_t pte_mkdirty(pte_t pte) |
| 221 | { |
| 222 | (pte).pte_low |= _PAGE_MODIFIED; |
| 223 | if ((pte).pte_low & _PAGE_WRITE) { |
| 224 | (pte).pte_low |= _PAGE_SILENT_WRITE; |
| 225 | (pte).pte_high |= _PAGE_SILENT_WRITE; |
| 226 | } |
| 227 | return pte; |
| 228 | } |
| 229 | |
| 230 | static inline pte_t pte_mkyoung(pte_t pte) |
| 231 | { |
| 232 | (pte).pte_low |= _PAGE_ACCESSED; |
| 233 | if ((pte).pte_low & _PAGE_READ) |
| 234 | (pte).pte_low |= _PAGE_SILENT_READ; |
| 235 | (pte).pte_high |= _PAGE_SILENT_READ; |
| 236 | return pte; |
| 237 | } |
| 238 | #else |
| 239 | static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; } |
| 240 | static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; } |
| 241 | static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; } |
| 242 | static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } |
| 243 | static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } |
| 244 | |
| 245 | static inline pte_t pte_wrprotect(pte_t pte) |
| 246 | { |
| 247 | pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE); |
| 248 | return pte; |
| 249 | } |
| 250 | |
| 251 | static inline pte_t pte_rdprotect(pte_t pte) |
| 252 | { |
| 253 | pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ); |
| 254 | return pte; |
| 255 | } |
| 256 | |
| 257 | static inline pte_t pte_mkclean(pte_t pte) |
| 258 | { |
| 259 | pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE); |
| 260 | return pte; |
| 261 | } |
| 262 | |
| 263 | static inline pte_t pte_mkold(pte_t pte) |
| 264 | { |
| 265 | pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ); |
| 266 | return pte; |
| 267 | } |
| 268 | |
| 269 | static inline pte_t pte_mkwrite(pte_t pte) |
| 270 | { |
| 271 | pte_val(pte) |= _PAGE_WRITE; |
| 272 | if (pte_val(pte) & _PAGE_MODIFIED) |
| 273 | pte_val(pte) |= _PAGE_SILENT_WRITE; |
| 274 | return pte; |
| 275 | } |
| 276 | |
| 277 | static inline pte_t pte_mkread(pte_t pte) |
| 278 | { |
| 279 | pte_val(pte) |= _PAGE_READ; |
| 280 | if (pte_val(pte) & _PAGE_ACCESSED) |
| 281 | pte_val(pte) |= _PAGE_SILENT_READ; |
| 282 | return pte; |
| 283 | } |
| 284 | |
| 285 | static inline pte_t pte_mkdirty(pte_t pte) |
| 286 | { |
| 287 | pte_val(pte) |= _PAGE_MODIFIED; |
| 288 | if (pte_val(pte) & _PAGE_WRITE) |
| 289 | pte_val(pte) |= _PAGE_SILENT_WRITE; |
| 290 | return pte; |
| 291 | } |
| 292 | |
| 293 | static inline pte_t pte_mkyoung(pte_t pte) |
| 294 | { |
| 295 | pte_val(pte) |= _PAGE_ACCESSED; |
| 296 | if (pte_val(pte) & _PAGE_READ) |
| 297 | pte_val(pte) |= _PAGE_SILENT_READ; |
| 298 | return pte; |
| 299 | } |
| 300 | #endif |
| 301 | |
| 302 | /* |
| 303 | * Macro to make mark a page protection value as "uncacheable". Note |
| 304 | * that "protection" is really a misnomer here as the protection value |
| 305 | * contains the memory attribute bits, dirty bits, and various other |
| 306 | * bits as well. |
| 307 | */ |
| 308 | #define pgprot_noncached pgprot_noncached |
| 309 | |
| 310 | static inline pgprot_t pgprot_noncached(pgprot_t _prot) |
| 311 | { |
| 312 | unsigned long prot = pgprot_val(_prot); |
| 313 | |
| 314 | prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED; |
| 315 | |
| 316 | return __pgprot(prot); |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * Conversion functions: convert a page and protection to a page entry, |
| 321 | * and a page entry and page directory to the page they refer to. |
| 322 | */ |
| 323 | #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) |
| 324 | |
| 325 | #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32) |
| 326 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 327 | { |
| 328 | pte.pte_low &= _PAGE_CHG_MASK; |
| 329 | pte.pte_low |= pgprot_val(newprot); |
| 330 | pte.pte_high |= pgprot_val(newprot) & 0x3f; |
| 331 | return pte; |
| 332 | } |
| 333 | #else |
| 334 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 335 | { |
| 336 | return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)); |
| 337 | } |
| 338 | #endif |
| 339 | |
| 340 | |
| 341 | extern void __update_tlb(struct vm_area_struct *vma, unsigned long address, |
| 342 | pte_t pte); |
| 343 | extern void __update_cache(struct vm_area_struct *vma, unsigned long address, |
| 344 | pte_t pte); |
| 345 | |
| 346 | static inline void update_mmu_cache(struct vm_area_struct *vma, |
| 347 | unsigned long address, pte_t pte) |
| 348 | { |
| 349 | __update_tlb(vma, address, pte); |
| 350 | __update_cache(vma, address, pte); |
| 351 | } |
| 352 | |
Yoichi Yuasa | b4819b5 | 2005-06-25 14:54:31 -0700 | [diff] [blame] | 353 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | #define kern_addr_valid(addr) (1) |
| 355 | #endif |
| 356 | |
| 357 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 358 | extern phys_t fixup_bigphys_addr(phys_t phys_addr, phys_t size); |
| 359 | extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot); |
| 360 | |
| 361 | static inline int io_remap_page_range(struct vm_area_struct *vma, |
| 362 | unsigned long vaddr, |
| 363 | unsigned long paddr, |
| 364 | unsigned long size, |
| 365 | pgprot_t prot) |
| 366 | { |
| 367 | phys_t phys_addr_high = fixup_bigphys_addr(paddr, size); |
| 368 | return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot); |
| 369 | } |
| 370 | |
| 371 | static inline int io_remap_pfn_range(struct vm_area_struct *vma, |
| 372 | unsigned long vaddr, |
| 373 | unsigned long pfn, |
| 374 | unsigned long size, |
| 375 | pgprot_t prot) |
| 376 | { |
| 377 | phys_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size); |
| 378 | return remap_pfn_range(vma, vaddr, pfn, size, prot); |
| 379 | } |
| 380 | #else |
| 381 | #define io_remap_page_range(vma, vaddr, paddr, size, prot) \ |
| 382 | remap_pfn_range(vma, vaddr, (paddr) >> PAGE_SHIFT, size, prot) |
| 383 | #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ |
| 384 | remap_pfn_range(vma, vaddr, pfn, size, prot) |
| 385 | #endif |
| 386 | |
| 387 | #define MK_IOSPACE_PFN(space, pfn) (pfn) |
| 388 | #define GET_IOSPACE(pfn) 0 |
| 389 | #define GET_PFN(pfn) (pfn) |
| 390 | |
| 391 | #include <asm-generic/pgtable.h> |
| 392 | |
| 393 | /* |
| 394 | * We provide our own get_unmapped area to cope with the virtual aliasing |
| 395 | * constraints placed on us by the cache architecture. |
| 396 | */ |
| 397 | #define HAVE_ARCH_UNMAPPED_AREA |
| 398 | |
| 399 | /* |
| 400 | * No page table caches to initialise |
| 401 | */ |
| 402 | #define pgtable_cache_init() do { } while (0) |
| 403 | |
| 404 | #endif /* _ASM_PGTABLE_H */ |