Paul Mundt | 26ff6c1 | 2006-09-27 15:13:36 +0900 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the functions and defines necessary to modify and |
| 3 | * use the SuperH page table tree. |
| 4 | * |
| 5 | * Copyright (C) 1999 Niibe Yutaka |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 6 | * Copyright (C) 2002 - 2007 Paul Mundt |
Paul Mundt | 26ff6c1 | 2006-09-27 15:13:36 +0900 | [diff] [blame] | 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General |
| 9 | * Public License. See the file "COPYING" in the main directory of this |
| 10 | * archive for more details. |
| 11 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #ifndef __ASM_SH_PGTABLE_H |
| 13 | #define __ASM_SH_PGTABLE_H |
| 14 | |
Matt Fleming | b73c806 | 2009-11-25 22:00:08 +0000 | [diff] [blame^] | 15 | #include <asm/pgtable_nopmd.h> |
Paul Mundt | 26ff6c1 | 2006-09-27 15:13:36 +0900 | [diff] [blame] | 16 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #ifndef __ASSEMBLY__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/addrspace.h> |
| 20 | #include <asm/fixmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * ZERO_PAGE is a global shared page that is always zero: used |
| 24 | * for zero-mapped memory areas etc.. |
| 25 | */ |
Paul Mundt | 26ff6c1 | 2006-09-27 15:13:36 +0900 | [diff] [blame] | 26 | extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) |
| 28 | |
| 29 | #endif /* !__ASSEMBLY__ */ |
| 30 | |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 31 | /* |
Paul Mundt | 36bcd39 | 2007-11-10 19:16:55 +0900 | [diff] [blame] | 32 | * Effective and physical address definitions, to aid with sign |
| 33 | * extension. |
| 34 | */ |
| 35 | #define NEFF 32 |
| 36 | #define NEFF_SIGN (1LL << (NEFF - 1)) |
| 37 | #define NEFF_MASK (-1LL << NEFF) |
| 38 | |
Paul Mundt | c791483 | 2009-08-04 17:14:39 +0900 | [diff] [blame] | 39 | static inline unsigned long long neff_sign_extend(unsigned long val) |
| 40 | { |
| 41 | unsigned long long extended = val; |
| 42 | return (extended & NEFF_SIGN) ? (extended | NEFF_MASK) : extended; |
| 43 | } |
| 44 | |
Paul Mundt | 36bcd39 | 2007-11-10 19:16:55 +0900 | [diff] [blame] | 45 | #ifdef CONFIG_29BIT |
| 46 | #define NPHYS 29 |
| 47 | #else |
| 48 | #define NPHYS 32 |
| 49 | #endif |
| 50 | |
| 51 | #define NPHYS_SIGN (1LL << (NPHYS - 1)) |
| 52 | #define NPHYS_MASK (-1LL << NPHYS) |
| 53 | |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 54 | #define PGDIR_SIZE (1UL << PGDIR_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define PGDIR_MASK (~(PGDIR_SIZE-1)) |
| 56 | |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 57 | /* Entries per level */ |
Paul Mundt | 7a847f8 | 2006-12-26 15:29:19 +0900 | [diff] [blame] | 58 | #define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE)) |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 59 | |
Hugh Dickins | d455a36 | 2005-04-19 13:29:23 -0700 | [diff] [blame] | 60 | #define FIRST_USER_ADDRESS 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Matt Fleming | 1f69b6a | 2009-10-06 21:22:25 +0000 | [diff] [blame] | 62 | #define PHYS_ADDR_MASK29 0x1fffffff |
| 63 | #define PHYS_ADDR_MASK32 0xffffffff |
| 64 | |
| 65 | #ifdef CONFIG_PMB |
| 66 | static inline unsigned long phys_addr_mask(void) |
| 67 | { |
| 68 | /* Is the MMU in 29bit mode? */ |
| 69 | if (__in_29bit_mode()) |
| 70 | return PHYS_ADDR_MASK29; |
| 71 | |
| 72 | return PHYS_ADDR_MASK32; |
| 73 | } |
Paul Mundt | 2a8bc92 | 2009-10-10 22:24:55 +0900 | [diff] [blame] | 74 | #elif defined(CONFIG_32BIT) |
Matt Fleming | 1f69b6a | 2009-10-06 21:22:25 +0000 | [diff] [blame] | 75 | static inline unsigned long phys_addr_mask(void) |
| 76 | { |
| 77 | return PHYS_ADDR_MASK32; |
| 78 | } |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 79 | #else |
Matt Fleming | 1f69b6a | 2009-10-06 21:22:25 +0000 | [diff] [blame] | 80 | static inline unsigned long phys_addr_mask(void) |
| 81 | { |
| 82 | return PHYS_ADDR_MASK29; |
| 83 | } |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 84 | #endif |
| 85 | |
Matt Fleming | 1f69b6a | 2009-10-06 21:22:25 +0000 | [diff] [blame] | 86 | #define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK) |
Paul Mundt | cb700aa | 2008-09-12 20:41:05 +0900 | [diff] [blame] | 87 | #define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Paul Mundt | 0468b4b | 2007-11-10 20:39:06 +0900 | [diff] [blame] | 89 | #ifdef CONFIG_SUPERH32 |
Paul Mundt | f0b859e | 2007-07-25 10:43:47 +0900 | [diff] [blame] | 90 | #define VMALLOC_START (P3SEG) |
Paul Mundt | 0468b4b | 2007-11-10 20:39:06 +0900 | [diff] [blame] | 91 | #else |
| 92 | #define VMALLOC_START (0xf0000000) |
| 93 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE) |
| 95 | |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 96 | #if defined(CONFIG_SUPERH32) |
| 97 | #include <asm/pgtable_32.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #else |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 99 | #include <asm/pgtable_64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /* |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 103 | * SH-X and lower (legacy) SuperH parts (SH-3, SH-4, some SH-4A) can't do page |
| 104 | * protection for execute, and considers it the same as a read. Also, write |
| 105 | * permission implies read permission. This is the closest we can get.. |
| 106 | * |
| 107 | * SH-X2 (SH7785) and later parts take this to the opposite end of the extreme, |
| 108 | * not only supporting separate execute, read, and write bits, but having |
| 109 | * completely separate permission bits for user and kernel space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | */ |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 111 | /*xwr*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define __P000 PAGE_NONE |
| 113 | #define __P001 PAGE_READONLY |
| 114 | #define __P010 PAGE_COPY |
| 115 | #define __P011 PAGE_COPY |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 116 | #define __P100 PAGE_EXECREAD |
| 117 | #define __P101 PAGE_EXECREAD |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define __P110 PAGE_COPY |
| 119 | #define __P111 PAGE_COPY |
| 120 | |
| 121 | #define __S000 PAGE_NONE |
| 122 | #define __S001 PAGE_READONLY |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 123 | #define __S010 PAGE_WRITEONLY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #define __S011 PAGE_SHARED |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 125 | #define __S100 PAGE_EXECREAD |
| 126 | #define __S101 PAGE_EXECREAD |
| 127 | #define __S110 PAGE_RWX |
| 128 | #define __S111 PAGE_RWX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | typedef pte_t *pte_addr_t; |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define kern_addr_valid(addr) (1) |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ |
| 135 | remap_pfn_range(vma, vaddr, pfn, size, prot) |
| 136 | |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 137 | #define pte_pfn(x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT))) |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* |
| 140 | * No page table caches to initialise |
| 141 | */ |
| 142 | #define pgtable_cache_init() do { } while (0) |
| 143 | |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 144 | struct vm_area_struct; |
Paul Mundt | 9cef749 | 2009-07-29 00:12:17 +0900 | [diff] [blame] | 145 | |
| 146 | extern void __update_cache(struct vm_area_struct *vma, |
| 147 | unsigned long address, pte_t pte); |
| 148 | extern void __update_tlb(struct vm_area_struct *vma, |
| 149 | unsigned long address, pte_t pte); |
| 150 | |
| 151 | static inline void |
| 152 | update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte) |
| 153 | { |
| 154 | __update_cache(vma, address, pte); |
| 155 | __update_tlb(vma, address, pte); |
| 156 | } |
| 157 | |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 158 | extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; |
| 159 | extern void paging_init(void); |
Paul Mundt | 9acb98f | 2007-12-17 10:52:11 +0900 | [diff] [blame] | 160 | extern void page_table_range_init(unsigned long start, unsigned long end, |
| 161 | pgd_t *pgd); |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 162 | |
Paul Mundt | ee1acbf | 2009-05-07 16:38:16 +0900 | [diff] [blame] | 163 | /* arch/sh/mm/mmap.c */ |
| 164 | #define HAVE_ARCH_UNMAPPED_AREA |
| 165 | #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | #include <asm-generic/pgtable.h> |
| 168 | |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 169 | #endif /* __ASM_SH_PGTABLE_H */ |