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