Michal Simek | 6a3cece | 2009-03-27 14:25:37 +0100 | [diff] [blame] | 1 | /* |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 2 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> |
| 3 | * Copyright (C) 2008-2009 PetaLogix |
Michal Simek | 6a3cece | 2009-03-27 14:25:37 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006 Atmark Techno, Inc. |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #ifndef _ASM_MICROBLAZE_PGTABLE_H |
| 12 | #define _ASM_MICROBLAZE_PGTABLE_H |
| 13 | |
| 14 | #include <asm/setup.h> |
| 15 | |
| 16 | #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ |
| 17 | remap_pfn_range(vma, vaddr, pfn, size, prot) |
| 18 | |
Michal Simek | 79bf3a1 | 2010-01-20 15:17:08 +0100 | [diff] [blame] | 19 | #ifndef __ASSEMBLY__ |
| 20 | extern int mem_init_done; |
| 21 | #endif |
| 22 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 23 | #ifndef CONFIG_MMU |
| 24 | |
Michal Simek | 6a3cece | 2009-03-27 14:25:37 +0100 | [diff] [blame] | 25 | #define pgd_present(pgd) (1) /* pages are always present on non MMU */ |
| 26 | #define pgd_none(pgd) (0) |
| 27 | #define pgd_bad(pgd) (0) |
| 28 | #define pgd_clear(pgdp) |
| 29 | #define kern_addr_valid(addr) (1) |
| 30 | #define pmd_offset(a, b) ((void *) 0) |
| 31 | |
| 32 | #define PAGE_NONE __pgprot(0) /* these mean nothing to non MMU */ |
| 33 | #define PAGE_SHARED __pgprot(0) /* these mean nothing to non MMU */ |
| 34 | #define PAGE_COPY __pgprot(0) /* these mean nothing to non MMU */ |
| 35 | #define PAGE_READONLY __pgprot(0) /* these mean nothing to non MMU */ |
| 36 | #define PAGE_KERNEL __pgprot(0) /* these mean nothing to non MMU */ |
| 37 | |
Arnd Bergmann | 0c60155 | 2009-05-01 21:44:51 +0000 | [diff] [blame] | 38 | #define pgprot_noncached(x) (x) |
| 39 | |
Michal Simek | 6a3cece | 2009-03-27 14:25:37 +0100 | [diff] [blame] | 40 | #define __swp_type(x) (0) |
| 41 | #define __swp_offset(x) (0) |
| 42 | #define __swp_entry(typ, off) ((swp_entry_t) { ((typ) | ((off) << 7)) }) |
| 43 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) |
| 44 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) |
| 45 | |
| 46 | #ifndef __ASSEMBLY__ |
| 47 | static inline int pte_file(pte_t pte) { return 0; } |
| 48 | #endif /* __ASSEMBLY__ */ |
| 49 | |
| 50 | #define ZERO_PAGE(vaddr) ({ BUG(); NULL; }) |
| 51 | |
| 52 | #define swapper_pg_dir ((pgd_t *) NULL) |
| 53 | |
| 54 | #define pgtable_cache_init() do {} while (0) |
| 55 | |
| 56 | #define arch_enter_lazy_cpu_mode() do {} while (0) |
| 57 | |
Michal Simek | 79bf3a1 | 2010-01-20 15:17:08 +0100 | [diff] [blame] | 58 | #define pgprot_noncached_wc(prot) prot |
| 59 | |
Michal Simek | 099a2f4 | 2010-09-10 12:43:42 +0200 | [diff] [blame] | 60 | /* |
| 61 | * All 32bit addresses are effectively valid for vmalloc... |
| 62 | * Sort of meaningless for non-VM targets. |
| 63 | */ |
| 64 | #define VMALLOC_START 0 |
| 65 | #define VMALLOC_END 0xffffffff |
| 66 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 67 | #else /* CONFIG_MMU */ |
| 68 | |
| 69 | #include <asm-generic/4level-fixup.h> |
| 70 | |
| 71 | #ifdef __KERNEL__ |
| 72 | #ifndef __ASSEMBLY__ |
| 73 | |
| 74 | #include <linux/sched.h> |
| 75 | #include <linux/threads.h> |
| 76 | #include <asm/processor.h> /* For TASK_SIZE */ |
| 77 | #include <asm/mmu.h> |
| 78 | #include <asm/page.h> |
| 79 | |
| 80 | #define FIRST_USER_ADDRESS 0 |
| 81 | |
| 82 | extern unsigned long va_to_phys(unsigned long address); |
| 83 | extern pte_t *va_to_pte(unsigned long address); |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * The following only work if pte_present() is true. |
| 87 | * Undefined behaviour if not.. |
| 88 | */ |
| 89 | |
| 90 | static inline int pte_special(pte_t pte) { return 0; } |
| 91 | |
| 92 | static inline pte_t pte_mkspecial(pte_t pte) { return pte; } |
| 93 | |
| 94 | /* Start and end of the vmalloc area. */ |
| 95 | /* Make sure to map the vmalloc area above the pinned kernel memory area |
| 96 | of 32Mb. */ |
Michal Simek | 83a9252 | 2011-12-19 13:46:35 +0100 | [diff] [blame] | 97 | #define VMALLOC_START (CONFIG_KERNEL_START + CONFIG_LOWMEM_SIZE) |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 98 | #define VMALLOC_END ioremap_bot |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 99 | |
| 100 | #endif /* __ASSEMBLY__ */ |
| 101 | |
| 102 | /* |
Michal Simek | a6475c1 | 2010-01-18 15:27:10 +0100 | [diff] [blame] | 103 | * Macro to mark a page protection value as "uncacheable". |
| 104 | */ |
| 105 | |
| 106 | #define _PAGE_CACHE_CTL (_PAGE_GUARDED | _PAGE_NO_CACHE | \ |
| 107 | _PAGE_WRITETHRU) |
| 108 | |
| 109 | #define pgprot_noncached(prot) \ |
| 110 | (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ |
| 111 | _PAGE_NO_CACHE | _PAGE_GUARDED)) |
| 112 | |
| 113 | #define pgprot_noncached_wc(prot) \ |
| 114 | (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ |
| 115 | _PAGE_NO_CACHE)) |
| 116 | |
| 117 | /* |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 118 | * The MicroBlaze MMU is identical to the PPC-40x MMU, and uses a hash |
| 119 | * table containing PTEs, together with a set of 16 segment registers, to |
| 120 | * define the virtual to physical address mapping. |
| 121 | * |
| 122 | * We use the hash table as an extended TLB, i.e. a cache of currently |
| 123 | * active mappings. We maintain a two-level page table tree, much |
| 124 | * like that used by the i386, for the sake of the Linux memory |
| 125 | * management code. Low-level assembler code in hashtable.S |
| 126 | * (procedure hash_page) is responsible for extracting ptes from the |
| 127 | * tree and putting them into the hash table when necessary, and |
| 128 | * updating the accessed and modified bits in the page table tree. |
| 129 | */ |
| 130 | |
| 131 | /* |
| 132 | * The MicroBlaze processor has a TLB architecture identical to PPC-40x. The |
| 133 | * instruction and data sides share a unified, 64-entry, semi-associative |
| 134 | * TLB which is maintained totally under software control. In addition, the |
| 135 | * instruction side has a hardware-managed, 2,4, or 8-entry, fully-associative |
| 136 | * TLB which serves as a first level to the shared TLB. These two TLBs are |
| 137 | * known as the UTLB and ITLB, respectively (see "mmu.h" for definitions). |
| 138 | */ |
| 139 | |
| 140 | /* |
| 141 | * The normal case is that PTEs are 32-bits and we have a 1-page |
| 142 | * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus |
| 143 | * |
| 144 | */ |
| 145 | |
| 146 | /* PMD_SHIFT determines the size of the area mapped by the PTE pages */ |
| 147 | #define PMD_SHIFT (PAGE_SHIFT + PTE_SHIFT) |
| 148 | #define PMD_SIZE (1UL << PMD_SHIFT) |
| 149 | #define PMD_MASK (~(PMD_SIZE-1)) |
| 150 | |
| 151 | /* PGDIR_SHIFT determines what a top-level page table entry can map */ |
| 152 | #define PGDIR_SHIFT PMD_SHIFT |
| 153 | #define PGDIR_SIZE (1UL << PGDIR_SHIFT) |
| 154 | #define PGDIR_MASK (~(PGDIR_SIZE-1)) |
| 155 | |
| 156 | /* |
| 157 | * entries per page directory level: our page-table tree is two-level, so |
| 158 | * we don't really have any PMD directory. |
| 159 | */ |
| 160 | #define PTRS_PER_PTE (1 << PTE_SHIFT) |
| 161 | #define PTRS_PER_PMD 1 |
| 162 | #define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT)) |
| 163 | |
| 164 | #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) |
| 165 | #define FIRST_USER_PGD_NR 0 |
| 166 | |
| 167 | #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT) |
| 168 | #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS) |
| 169 | |
| 170 | #define pte_ERROR(e) \ |
| 171 | printk(KERN_ERR "%s:%d: bad pte "PTE_FMT".\n", \ |
| 172 | __FILE__, __LINE__, pte_val(e)) |
| 173 | #define pmd_ERROR(e) \ |
| 174 | printk(KERN_ERR "%s:%d: bad pmd %08lx.\n", \ |
| 175 | __FILE__, __LINE__, pmd_val(e)) |
| 176 | #define pgd_ERROR(e) \ |
| 177 | printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \ |
| 178 | __FILE__, __LINE__, pgd_val(e)) |
| 179 | |
| 180 | /* |
| 181 | * Bits in a linux-style PTE. These match the bits in the |
| 182 | * (hardware-defined) PTE as closely as possible. |
| 183 | */ |
| 184 | |
| 185 | /* There are several potential gotchas here. The hardware TLBLO |
| 186 | * field looks like this: |
| 187 | * |
| 188 | * 0 1 2 3 4 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
| 189 | * RPN..................... 0 0 EX WR ZSEL....... W I M G |
| 190 | * |
| 191 | * Where possible we make the Linux PTE bits match up with this |
| 192 | * |
| 193 | * - bits 20 and 21 must be cleared, because we use 4k pages (4xx can |
| 194 | * support down to 1k pages), this is done in the TLBMiss exception |
| 195 | * handler. |
| 196 | * - We use only zones 0 (for kernel pages) and 1 (for user pages) |
| 197 | * of the 16 available. Bit 24-26 of the TLB are cleared in the TLB |
| 198 | * miss handler. Bit 27 is PAGE_USER, thus selecting the correct |
| 199 | * zone. |
| 200 | * - PRESENT *must* be in the bottom two bits because swap cache |
| 201 | * entries use the top 30 bits. Because 4xx doesn't support SMP |
| 202 | * anyway, M is irrelevant so we borrow it for PAGE_PRESENT. Bit 30 |
| 203 | * is cleared in the TLB miss handler before the TLB entry is loaded. |
| 204 | * - All other bits of the PTE are loaded into TLBLO without |
| 205 | * * modification, leaving us only the bits 20, 21, 24, 25, 26, 30 for |
| 206 | * software PTE bits. We actually use use bits 21, 24, 25, and |
| 207 | * 30 respectively for the software bits: ACCESSED, DIRTY, RW, and |
| 208 | * PRESENT. |
| 209 | */ |
| 210 | |
| 211 | /* Definitions for MicroBlaze. */ |
| 212 | #define _PAGE_GUARDED 0x001 /* G: page is guarded from prefetch */ |
Michal Simek | f14d6f7 | 2009-07-15 13:39:35 +0200 | [diff] [blame] | 213 | #define _PAGE_FILE 0x001 /* when !present: nonlinear file mapping */ |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 214 | #define _PAGE_PRESENT 0x002 /* software: PTE contains a translation */ |
| 215 | #define _PAGE_NO_CACHE 0x004 /* I: caching is inhibited */ |
| 216 | #define _PAGE_WRITETHRU 0x008 /* W: caching is write-through */ |
| 217 | #define _PAGE_USER 0x010 /* matches one of the zone permission bits */ |
| 218 | #define _PAGE_RW 0x040 /* software: Writes permitted */ |
| 219 | #define _PAGE_DIRTY 0x080 /* software: dirty page */ |
| 220 | #define _PAGE_HWWRITE 0x100 /* hardware: Dirty & RW, set in exception */ |
| 221 | #define _PAGE_HWEXEC 0x200 /* hardware: EX permission */ |
| 222 | #define _PAGE_ACCESSED 0x400 /* software: R: page referenced */ |
| 223 | #define _PMD_PRESENT PAGE_MASK |
| 224 | |
| 225 | /* |
| 226 | * Some bits are unused... |
| 227 | */ |
| 228 | #ifndef _PAGE_HASHPTE |
| 229 | #define _PAGE_HASHPTE 0 |
| 230 | #endif |
| 231 | #ifndef _PTE_NONE_MASK |
| 232 | #define _PTE_NONE_MASK 0 |
| 233 | #endif |
| 234 | #ifndef _PAGE_SHARED |
| 235 | #define _PAGE_SHARED 0 |
| 236 | #endif |
| 237 | #ifndef _PAGE_HWWRITE |
| 238 | #define _PAGE_HWWRITE 0 |
| 239 | #endif |
| 240 | #ifndef _PAGE_HWEXEC |
| 241 | #define _PAGE_HWEXEC 0 |
| 242 | #endif |
| 243 | #ifndef _PAGE_EXEC |
| 244 | #define _PAGE_EXEC 0 |
| 245 | #endif |
| 246 | |
| 247 | #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) |
| 248 | |
| 249 | /* |
| 250 | * Note: the _PAGE_COHERENT bit automatically gets set in the hardware |
| 251 | * PTE if CONFIG_SMP is defined (hash_page does this); there is no need |
| 252 | * to have it in the Linux PTE, and in fact the bit could be reused for |
| 253 | * another purpose. -- paulus. |
| 254 | */ |
| 255 | #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED) |
| 256 | #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE) |
| 257 | |
| 258 | #define _PAGE_KERNEL \ |
| 259 | (_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED | _PAGE_HWEXEC) |
| 260 | |
| 261 | #define _PAGE_IO (_PAGE_KERNEL | _PAGE_NO_CACHE | _PAGE_GUARDED) |
| 262 | |
| 263 | #define PAGE_NONE __pgprot(_PAGE_BASE) |
| 264 | #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER) |
| 265 | #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) |
| 266 | #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) |
| 267 | #define PAGE_SHARED_X \ |
| 268 | __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC) |
| 269 | #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER) |
| 270 | #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) |
| 271 | |
| 272 | #define PAGE_KERNEL __pgprot(_PAGE_KERNEL) |
| 273 | #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_SHARED) |
| 274 | #define PAGE_KERNEL_CI __pgprot(_PAGE_IO) |
| 275 | |
| 276 | /* |
| 277 | * We consider execute permission the same as read. |
| 278 | * Also, write permissions imply read permissions. |
| 279 | */ |
| 280 | #define __P000 PAGE_NONE |
| 281 | #define __P001 PAGE_READONLY_X |
| 282 | #define __P010 PAGE_COPY |
| 283 | #define __P011 PAGE_COPY_X |
| 284 | #define __P100 PAGE_READONLY |
| 285 | #define __P101 PAGE_READONLY_X |
| 286 | #define __P110 PAGE_COPY |
| 287 | #define __P111 PAGE_COPY_X |
| 288 | |
| 289 | #define __S000 PAGE_NONE |
| 290 | #define __S001 PAGE_READONLY_X |
| 291 | #define __S010 PAGE_SHARED |
| 292 | #define __S011 PAGE_SHARED_X |
| 293 | #define __S100 PAGE_READONLY |
| 294 | #define __S101 PAGE_READONLY_X |
| 295 | #define __S110 PAGE_SHARED |
| 296 | #define __S111 PAGE_SHARED_X |
| 297 | |
| 298 | #ifndef __ASSEMBLY__ |
| 299 | /* |
| 300 | * ZERO_PAGE is a global shared page that is always zero: used |
| 301 | * for zero-mapped memory areas etc.. |
| 302 | */ |
| 303 | extern unsigned long empty_zero_page[1024]; |
| 304 | #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) |
| 305 | |
| 306 | #endif /* __ASSEMBLY__ */ |
| 307 | |
| 308 | #define pte_none(pte) ((pte_val(pte) & ~_PTE_NONE_MASK) == 0) |
| 309 | #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT) |
| 310 | #define pte_clear(mm, addr, ptep) \ |
| 311 | do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0) |
| 312 | |
| 313 | #define pmd_none(pmd) (!pmd_val(pmd)) |
| 314 | #define pmd_bad(pmd) ((pmd_val(pmd) & _PMD_PRESENT) == 0) |
| 315 | #define pmd_present(pmd) ((pmd_val(pmd) & _PMD_PRESENT) != 0) |
| 316 | #define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0) |
| 317 | |
| 318 | #define pte_page(x) (mem_map + (unsigned long) \ |
| 319 | ((pte_val(x) - memory_start) >> PAGE_SHIFT)) |
| 320 | #define PFN_SHIFT_OFFSET (PAGE_SHIFT) |
| 321 | |
| 322 | #define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET) |
| 323 | |
| 324 | #define pfn_pte(pfn, prot) \ |
| 325 | __pte(((pte_basic_t)(pfn) << PFN_SHIFT_OFFSET) | pgprot_val(prot)) |
| 326 | |
| 327 | #ifndef __ASSEMBLY__ |
| 328 | /* |
| 329 | * The "pgd_xxx()" functions here are trivial for a folded two-level |
| 330 | * setup: the pgd is never bad, and a pmd always exists (as it's folded |
| 331 | * into the pgd entry) |
| 332 | */ |
| 333 | static inline int pgd_none(pgd_t pgd) { return 0; } |
| 334 | static inline int pgd_bad(pgd_t pgd) { return 0; } |
| 335 | static inline int pgd_present(pgd_t pgd) { return 1; } |
| 336 | #define pgd_clear(xp) do { } while (0) |
| 337 | #define pgd_page(pgd) \ |
| 338 | ((unsigned long) __va(pgd_val(pgd) & PAGE_MASK)) |
| 339 | |
| 340 | /* |
| 341 | * The following only work if pte_present() is true. |
| 342 | * Undefined behaviour if not.. |
| 343 | */ |
| 344 | static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; } |
| 345 | static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; } |
| 346 | static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; } |
| 347 | static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } |
| 348 | static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } |
Michal Simek | f14d6f7 | 2009-07-15 13:39:35 +0200 | [diff] [blame] | 349 | static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 350 | |
| 351 | static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; } |
| 352 | static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; } |
| 353 | |
| 354 | static inline pte_t pte_rdprotect(pte_t pte) \ |
| 355 | { pte_val(pte) &= ~_PAGE_USER; return pte; } |
| 356 | static inline pte_t pte_wrprotect(pte_t pte) \ |
| 357 | { pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; } |
| 358 | static inline pte_t pte_exprotect(pte_t pte) \ |
| 359 | { pte_val(pte) &= ~_PAGE_EXEC; return pte; } |
| 360 | static inline pte_t pte_mkclean(pte_t pte) \ |
| 361 | { pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; } |
| 362 | static inline pte_t pte_mkold(pte_t pte) \ |
| 363 | { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; } |
| 364 | |
| 365 | static inline pte_t pte_mkread(pte_t pte) \ |
| 366 | { pte_val(pte) |= _PAGE_USER; return pte; } |
| 367 | static inline pte_t pte_mkexec(pte_t pte) \ |
| 368 | { pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; } |
| 369 | static inline pte_t pte_mkwrite(pte_t pte) \ |
| 370 | { pte_val(pte) |= _PAGE_RW; return pte; } |
| 371 | static inline pte_t pte_mkdirty(pte_t pte) \ |
| 372 | { pte_val(pte) |= _PAGE_DIRTY; return pte; } |
| 373 | static inline pte_t pte_mkyoung(pte_t pte) \ |
| 374 | { pte_val(pte) |= _PAGE_ACCESSED; return pte; } |
| 375 | |
| 376 | /* |
| 377 | * Conversion functions: convert a page and protection to a page entry, |
| 378 | * and a page entry and page directory to the page they refer to. |
| 379 | */ |
| 380 | |
| 381 | static inline pte_t mk_pte_phys(phys_addr_t physpage, pgprot_t pgprot) |
| 382 | { |
| 383 | pte_t pte; |
| 384 | pte_val(pte) = physpage | pgprot_val(pgprot); |
| 385 | return pte; |
| 386 | } |
| 387 | |
| 388 | #define mk_pte(page, pgprot) \ |
| 389 | ({ \ |
| 390 | pte_t pte; \ |
| 391 | pte_val(pte) = (((page - mem_map) << PAGE_SHIFT) + memory_start) | \ |
| 392 | pgprot_val(pgprot); \ |
| 393 | pte; \ |
| 394 | }) |
| 395 | |
| 396 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 397 | { |
| 398 | pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); |
| 399 | return pte; |
| 400 | } |
| 401 | |
| 402 | /* |
| 403 | * Atomic PTE updates. |
| 404 | * |
| 405 | * pte_update clears and sets bit atomically, and returns |
| 406 | * the old pte value. |
| 407 | * The ((unsigned long)(p+1) - 4) hack is to get to the least-significant |
| 408 | * 32 bits of the PTE regardless of whether PTEs are 32 or 64 bits. |
| 409 | */ |
| 410 | static inline unsigned long pte_update(pte_t *p, unsigned long clr, |
| 411 | unsigned long set) |
| 412 | { |
Michal Simek | 1f80a67 | 2011-02-07 18:51:54 +0100 | [diff] [blame] | 413 | unsigned long flags, old, tmp; |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 414 | |
Michal Simek | 1f80a67 | 2011-02-07 18:51:54 +0100 | [diff] [blame] | 415 | raw_local_irq_save(flags); |
| 416 | |
| 417 | __asm__ __volatile__( "lw %0, %2, r0 \n" |
| 418 | "andn %1, %0, %3 \n" |
| 419 | "or %1, %1, %4 \n" |
| 420 | "sw %1, %2, r0 \n" |
| 421 | : "=&r" (old), "=&r" (tmp) |
| 422 | : "r" ((unsigned long)(p + 1) - 4), "r" (clr), "r" (set) |
| 423 | : "cc"); |
| 424 | |
| 425 | raw_local_irq_restore(flags); |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 426 | |
| 427 | return old; |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * set_pte stores a linux PTE into the linux page table. |
| 432 | */ |
| 433 | static inline void set_pte(struct mm_struct *mm, unsigned long addr, |
| 434 | pte_t *ptep, pte_t pte) |
| 435 | { |
| 436 | *ptep = pte; |
| 437 | } |
| 438 | |
| 439 | static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 440 | pte_t *ptep, pte_t pte) |
| 441 | { |
| 442 | *ptep = pte; |
| 443 | } |
| 444 | |
Michal Simek | 658b368 | 2011-01-16 13:56:53 +0100 | [diff] [blame] | 445 | #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG |
| 446 | static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, |
| 447 | unsigned long address, pte_t *ptep) |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 448 | { |
| 449 | return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0; |
| 450 | } |
| 451 | |
| 452 | static inline int ptep_test_and_clear_dirty(struct mm_struct *mm, |
| 453 | unsigned long addr, pte_t *ptep) |
| 454 | { |
| 455 | return (pte_update(ptep, \ |
| 456 | (_PAGE_DIRTY | _PAGE_HWWRITE), 0) & _PAGE_DIRTY) != 0; |
| 457 | } |
| 458 | |
Michal Simek | 658b368 | 2011-01-16 13:56:53 +0100 | [diff] [blame] | 459 | #define __HAVE_ARCH_PTEP_GET_AND_CLEAR |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 460 | static inline pte_t ptep_get_and_clear(struct mm_struct *mm, |
| 461 | unsigned long addr, pte_t *ptep) |
| 462 | { |
| 463 | return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0)); |
| 464 | } |
| 465 | |
| 466 | /*static inline void ptep_set_wrprotect(struct mm_struct *mm, |
| 467 | unsigned long addr, pte_t *ptep) |
| 468 | { |
| 469 | pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0); |
| 470 | }*/ |
| 471 | |
| 472 | static inline void ptep_mkdirty(struct mm_struct *mm, |
| 473 | unsigned long addr, pte_t *ptep) |
| 474 | { |
| 475 | pte_update(ptep, 0, _PAGE_DIRTY); |
| 476 | } |
| 477 | |
| 478 | /*#define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)*/ |
| 479 | |
| 480 | /* Convert pmd entry to page */ |
| 481 | /* our pmd entry is an effective address of pte table*/ |
| 482 | /* returns effective address of the pmd entry*/ |
| 483 | #define pmd_page_kernel(pmd) ((unsigned long) (pmd_val(pmd) & PAGE_MASK)) |
| 484 | |
| 485 | /* returns struct *page of the pmd entry*/ |
| 486 | #define pmd_page(pmd) (pfn_to_page(__pa(pmd_val(pmd)) >> PAGE_SHIFT)) |
| 487 | |
| 488 | /* to find an entry in a kernel page-table-directory */ |
| 489 | #define pgd_offset_k(address) pgd_offset(&init_mm, address) |
| 490 | |
| 491 | /* to find an entry in a page-table-directory */ |
| 492 | #define pgd_index(address) ((address) >> PGDIR_SHIFT) |
| 493 | #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) |
| 494 | |
| 495 | /* Find an entry in the second-level page table.. */ |
| 496 | static inline pmd_t *pmd_offset(pgd_t *dir, unsigned long address) |
| 497 | { |
| 498 | return (pmd_t *) dir; |
| 499 | } |
| 500 | |
| 501 | /* Find an entry in the third-level page table.. */ |
| 502 | #define pte_index(address) \ |
| 503 | (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) |
| 504 | #define pte_offset_kernel(dir, addr) \ |
| 505 | ((pte_t *) pmd_page_kernel(*(dir)) + pte_index(addr)) |
| 506 | #define pte_offset_map(dir, addr) \ |
Peter Zijlstra | ece0e2b | 2010-10-26 14:21:52 -0700 | [diff] [blame] | 507 | ((pte_t *) kmap_atomic(pmd_page(*(dir))) + pte_index(addr)) |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 508 | |
Peter Zijlstra | ece0e2b | 2010-10-26 14:21:52 -0700 | [diff] [blame] | 509 | #define pte_unmap(pte) kunmap_atomic(pte) |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 510 | |
| 511 | /* Encode and decode a nonlinear file mapping entry */ |
| 512 | #define PTE_FILE_MAX_BITS 29 |
| 513 | #define pte_to_pgoff(pte) (pte_val(pte) >> 3) |
Michal Simek | f14d6f7 | 2009-07-15 13:39:35 +0200 | [diff] [blame] | 514 | #define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE }) |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 515 | |
| 516 | extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; |
| 517 | |
| 518 | /* |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 519 | * Encode and decode a swap entry. |
| 520 | * Note that the bits we use in a PTE for representing a swap entry |
| 521 | * must not include the _PAGE_PRESENT bit, or the _PAGE_HASHPTE bit |
| 522 | * (if used). -- paulus |
| 523 | */ |
| 524 | #define __swp_type(entry) ((entry).val & 0x3f) |
| 525 | #define __swp_offset(entry) ((entry).val >> 6) |
| 526 | #define __swp_entry(type, offset) \ |
| 527 | ((swp_entry_t) { (type) | ((offset) << 6) }) |
| 528 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 2 }) |
| 529 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 2 }) |
| 530 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 531 | extern unsigned long iopa(unsigned long addr); |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 532 | |
| 533 | /* Values for nocacheflag and cmode */ |
| 534 | /* These are not used by the APUS kernel_map, but prevents |
| 535 | * compilation errors. |
| 536 | */ |
| 537 | #define IOMAP_FULL_CACHING 0 |
| 538 | #define IOMAP_NOCACHE_SER 1 |
| 539 | #define IOMAP_NOCACHE_NONSER 2 |
| 540 | #define IOMAP_NO_COPYBACK 3 |
| 541 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 542 | /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */ |
| 543 | #define kern_addr_valid(addr) (1) |
| 544 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 545 | /* |
| 546 | * No page table caches to initialise |
| 547 | */ |
| 548 | #define pgtable_cache_init() do { } while (0) |
| 549 | |
| 550 | void do_page_fault(struct pt_regs *regs, unsigned long address, |
| 551 | unsigned long error_code); |
| 552 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 553 | void mapin_ram(void); |
| 554 | int map_page(unsigned long va, phys_addr_t pa, int flags); |
| 555 | |
| 556 | extern int mem_init_done; |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 557 | |
| 558 | asmlinkage void __init mmu_init(void); |
| 559 | |
| 560 | void __init *early_get_page(void); |
| 561 | |
Michal Simek | 15902bf | 2009-05-26 16:30:15 +0200 | [diff] [blame] | 562 | #endif /* __ASSEMBLY__ */ |
| 563 | #endif /* __KERNEL__ */ |
| 564 | |
| 565 | #endif /* CONFIG_MMU */ |
| 566 | |
Michal Simek | 6a3cece | 2009-03-27 14:25:37 +0100 | [diff] [blame] | 567 | #ifndef __ASSEMBLY__ |
| 568 | #include <asm-generic/pgtable.h> |
| 569 | |
Michal Simek | ae8ee15 | 2010-02-22 12:09:02 +0100 | [diff] [blame] | 570 | extern unsigned long ioremap_bot, ioremap_base; |
| 571 | |
Michal Simek | cd44da1 | 2011-02-07 11:42:37 +0100 | [diff] [blame] | 572 | void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle); |
Michal Simek | f152576 | 2010-04-10 17:34:06 +0200 | [diff] [blame] | 573 | void consistent_free(size_t size, void *vaddr); |
Michal Simek | ae8ee15 | 2010-02-22 12:09:02 +0100 | [diff] [blame] | 574 | void consistent_sync(void *vaddr, size_t size, int direction); |
| 575 | void consistent_sync_page(struct page *page, unsigned long offset, |
| 576 | size_t size, int direction); |
| 577 | |
Michal Simek | 6a3cece | 2009-03-27 14:25:37 +0100 | [diff] [blame] | 578 | void setup_memory(void); |
| 579 | #endif /* __ASSEMBLY__ */ |
| 580 | |
| 581 | #endif /* _ASM_MICROBLAZE_PGTABLE_H */ |