Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PowerPC64 port by Mike Corrigan and Dave Engebretsen |
| 3 | * {mikejc|engebret}@us.ibm.com |
| 4 | * |
| 5 | * Copyright (c) 2000 Mike Corrigan <mikejc@us.ibm.com> |
| 6 | * |
| 7 | * SMP scalability work: |
| 8 | * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM |
| 9 | * |
| 10 | * Module name: htab.c |
| 11 | * |
| 12 | * Description: |
| 13 | * PowerPC Hashed Page Table functions |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ |
| 20 | |
| 21 | #undef DEBUG |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 22 | #undef DEBUG_LOW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/errno.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/proc_fs.h> |
| 28 | #include <linux/stat.h> |
| 29 | #include <linux/sysctl.h> |
| 30 | #include <linux/ctype.h> |
| 31 | #include <linux/cache.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/signal.h> |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/processor.h> |
| 36 | #include <asm/pgtable.h> |
| 37 | #include <asm/mmu.h> |
| 38 | #include <asm/mmu_context.h> |
| 39 | #include <asm/page.h> |
| 40 | #include <asm/types.h> |
| 41 | #include <asm/system.h> |
| 42 | #include <asm/uaccess.h> |
| 43 | #include <asm/machdep.h> |
| 44 | #include <asm/lmb.h> |
| 45 | #include <asm/abs_addr.h> |
| 46 | #include <asm/tlbflush.h> |
| 47 | #include <asm/io.h> |
| 48 | #include <asm/eeh.h> |
| 49 | #include <asm/tlb.h> |
| 50 | #include <asm/cacheflush.h> |
| 51 | #include <asm/cputable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/sections.h> |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 53 | #include <asm/spu.h> |
will schmidt | aa39be0 | 2007-10-30 06:24:19 +1100 | [diff] [blame^] | 54 | #include <asm/udbg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #ifdef DEBUG |
| 57 | #define DBG(fmt...) udbg_printf(fmt) |
| 58 | #else |
| 59 | #define DBG(fmt...) |
| 60 | #endif |
| 61 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 62 | #ifdef DEBUG_LOW |
| 63 | #define DBG_LOW(fmt...) udbg_printf(fmt) |
| 64 | #else |
| 65 | #define DBG_LOW(fmt...) |
| 66 | #endif |
| 67 | |
| 68 | #define KB (1024) |
| 69 | #define MB (1024*KB) |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Note: pte --> Linux PTE |
| 73 | * HPTE --> PowerPC Hashed Page Table Entry |
| 74 | * |
| 75 | * Execution context: |
| 76 | * htab_initialize is called with the MMU off (of course), but |
| 77 | * the kernel has been copied down to zero so it can directly |
| 78 | * reference global data. At this point it is very difficult |
| 79 | * to print debug info. |
| 80 | * |
| 81 | */ |
| 82 | |
| 83 | #ifdef CONFIG_U3_DART |
| 84 | extern unsigned long dart_tablebase; |
| 85 | #endif /* CONFIG_U3_DART */ |
| 86 | |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 87 | static unsigned long _SDR1; |
| 88 | struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT]; |
| 89 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 90 | struct hash_pte *htab_address; |
Michael Ellerman | 337a712 | 2006-02-21 17:22:55 +1100 | [diff] [blame] | 91 | unsigned long htab_size_bytes; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 92 | unsigned long htab_hash_mask; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 93 | int mmu_linear_psize = MMU_PAGE_4K; |
| 94 | int mmu_virtual_psize = MMU_PAGE_4K; |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 95 | int mmu_vmalloc_psize = MMU_PAGE_4K; |
| 96 | int mmu_io_psize = MMU_PAGE_4K; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 97 | int mmu_kernel_ssize = MMU_SEGSIZE_256M; |
| 98 | int mmu_highuser_ssize = MMU_SEGSIZE_256M; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 99 | #ifdef CONFIG_HUGETLB_PAGE |
| 100 | int mmu_huge_psize = MMU_PAGE_16M; |
| 101 | unsigned int HPAGE_SHIFT; |
| 102 | #endif |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 103 | #ifdef CONFIG_PPC_64K_PAGES |
| 104 | int mmu_ci_restrictions; |
| 105 | #endif |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 106 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 107 | static u8 *linear_map_hash_slots; |
| 108 | static unsigned long linear_map_hash_count; |
Michael Ellerman | ed16669 | 2007-04-18 11:50:09 +1000 | [diff] [blame] | 109 | static DEFINE_SPINLOCK(linear_map_hash_lock); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 110 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 112 | /* There are definitions of page sizes arrays to be used when none |
| 113 | * is provided by the firmware. |
| 114 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 116 | /* Pre-POWER4 CPUs (4k pages only) |
| 117 | */ |
| 118 | struct mmu_psize_def mmu_psize_defaults_old[] = { |
| 119 | [MMU_PAGE_4K] = { |
| 120 | .shift = 12, |
| 121 | .sllp = 0, |
| 122 | .penc = 0, |
| 123 | .avpnm = 0, |
| 124 | .tlbiel = 0, |
| 125 | }, |
| 126 | }; |
| 127 | |
| 128 | /* POWER4, GPUL, POWER5 |
| 129 | * |
| 130 | * Support for 16Mb large pages |
| 131 | */ |
| 132 | struct mmu_psize_def mmu_psize_defaults_gp[] = { |
| 133 | [MMU_PAGE_4K] = { |
| 134 | .shift = 12, |
| 135 | .sllp = 0, |
| 136 | .penc = 0, |
| 137 | .avpnm = 0, |
| 138 | .tlbiel = 1, |
| 139 | }, |
| 140 | [MMU_PAGE_16M] = { |
| 141 | .shift = 24, |
| 142 | .sllp = SLB_VSID_L, |
| 143 | .penc = 0, |
| 144 | .avpnm = 0x1UL, |
| 145 | .tlbiel = 0, |
| 146 | }, |
| 147 | }; |
| 148 | |
| 149 | |
| 150 | int htab_bolt_mapping(unsigned long vstart, unsigned long vend, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 151 | unsigned long pstart, unsigned long mode, |
| 152 | int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 154 | unsigned long vaddr, paddr; |
| 155 | unsigned int step, shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | unsigned long tmp_mode; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 157 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 159 | shift = mmu_psize_defs[psize].shift; |
| 160 | step = 1 << shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 162 | for (vaddr = vstart, paddr = pstart; vaddr < vend; |
| 163 | vaddr += step, paddr += step) { |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 164 | unsigned long hash, hpteg; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 165 | unsigned long vsid = get_kernel_vsid(vaddr, ssize); |
| 166 | unsigned long va = hpt_va(vaddr, vsid, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | tmp_mode = mode; |
| 169 | |
| 170 | /* Make non-kernel text non-executable */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 171 | if (!in_kernel_text(vaddr)) |
| 172 | tmp_mode = mode | HPTE_R_N; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 174 | hash = hpt_hash(va, shift, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP); |
| 176 | |
Michael Ellerman | c30a4df | 2006-06-23 18:16:39 +1000 | [diff] [blame] | 177 | DBG("htab_bolt_mapping: calling %p\n", ppc_md.hpte_insert); |
| 178 | |
| 179 | BUG_ON(!ppc_md.hpte_insert); |
| 180 | ret = ppc_md.hpte_insert(hpteg, va, paddr, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 181 | tmp_mode, HPTE_V_BOLTED, psize, ssize); |
Michael Ellerman | c30a4df | 2006-06-23 18:16:39 +1000 | [diff] [blame] | 182 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 183 | if (ret < 0) |
| 184 | break; |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 185 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 186 | if ((paddr >> PAGE_SHIFT) < linear_map_hash_count) |
| 187 | linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80; |
| 188 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 190 | return ret < 0 ? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 193 | static int __init htab_dt_scan_seg_sizes(unsigned long node, |
| 194 | const char *uname, int depth, |
| 195 | void *data) |
| 196 | { |
| 197 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
| 198 | u32 *prop; |
| 199 | unsigned long size = 0; |
| 200 | |
| 201 | /* We are scanning "cpu" nodes only */ |
| 202 | if (type == NULL || strcmp(type, "cpu") != 0) |
| 203 | return 0; |
| 204 | |
| 205 | prop = (u32 *)of_get_flat_dt_prop(node, "ibm,processor-segment-sizes", |
| 206 | &size); |
| 207 | if (prop == NULL) |
| 208 | return 0; |
| 209 | for (; size >= 4; size -= 4, ++prop) { |
| 210 | if (prop[0] == 40) { |
| 211 | DBG("1T segment support detected\n"); |
| 212 | cur_cpu_spec->cpu_features |= CPU_FTR_1T_SEGMENT; |
Olof Johansson | f553400 | 2007-10-12 16:44:55 +1000 | [diff] [blame] | 213 | return 1; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 214 | } |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 215 | } |
Olof Johansson | f66bce5 | 2007-10-16 00:58:59 +1000 | [diff] [blame] | 216 | cur_cpu_spec->cpu_features &= ~CPU_FTR_NO_SLBIE_B; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static void __init htab_init_seg_sizes(void) |
| 221 | { |
| 222 | of_scan_flat_dt(htab_dt_scan_seg_sizes, NULL); |
| 223 | } |
| 224 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 225 | static int __init htab_dt_scan_page_sizes(unsigned long node, |
| 226 | const char *uname, int depth, |
| 227 | void *data) |
| 228 | { |
| 229 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
| 230 | u32 *prop; |
| 231 | unsigned long size = 0; |
| 232 | |
| 233 | /* We are scanning "cpu" nodes only */ |
| 234 | if (type == NULL || strcmp(type, "cpu") != 0) |
| 235 | return 0; |
| 236 | |
| 237 | prop = (u32 *)of_get_flat_dt_prop(node, |
| 238 | "ibm,segment-page-sizes", &size); |
| 239 | if (prop != NULL) { |
| 240 | DBG("Page sizes from device-tree:\n"); |
| 241 | size /= 4; |
| 242 | cur_cpu_spec->cpu_features &= ~(CPU_FTR_16M_PAGE); |
| 243 | while(size > 0) { |
| 244 | unsigned int shift = prop[0]; |
| 245 | unsigned int slbenc = prop[1]; |
| 246 | unsigned int lpnum = prop[2]; |
| 247 | unsigned int lpenc = 0; |
| 248 | struct mmu_psize_def *def; |
| 249 | int idx = -1; |
| 250 | |
| 251 | size -= 3; prop += 3; |
| 252 | while(size > 0 && lpnum) { |
| 253 | if (prop[0] == shift) |
| 254 | lpenc = prop[1]; |
| 255 | prop += 2; size -= 2; |
| 256 | lpnum--; |
| 257 | } |
| 258 | switch(shift) { |
| 259 | case 0xc: |
| 260 | idx = MMU_PAGE_4K; |
| 261 | break; |
| 262 | case 0x10: |
| 263 | idx = MMU_PAGE_64K; |
| 264 | break; |
| 265 | case 0x14: |
| 266 | idx = MMU_PAGE_1M; |
| 267 | break; |
| 268 | case 0x18: |
| 269 | idx = MMU_PAGE_16M; |
| 270 | cur_cpu_spec->cpu_features |= CPU_FTR_16M_PAGE; |
| 271 | break; |
| 272 | case 0x22: |
| 273 | idx = MMU_PAGE_16G; |
| 274 | break; |
| 275 | } |
| 276 | if (idx < 0) |
| 277 | continue; |
| 278 | def = &mmu_psize_defs[idx]; |
| 279 | def->shift = shift; |
| 280 | if (shift <= 23) |
| 281 | def->avpnm = 0; |
| 282 | else |
| 283 | def->avpnm = (1 << (shift - 23)) - 1; |
| 284 | def->sllp = slbenc; |
| 285 | def->penc = lpenc; |
| 286 | /* We don't know for sure what's up with tlbiel, so |
| 287 | * for now we only set it for 4K and 64K pages |
| 288 | */ |
| 289 | if (idx == MMU_PAGE_4K || idx == MMU_PAGE_64K) |
| 290 | def->tlbiel = 1; |
| 291 | else |
| 292 | def->tlbiel = 0; |
| 293 | |
| 294 | DBG(" %d: shift=%02x, sllp=%04x, avpnm=%08x, " |
| 295 | "tlbiel=%d, penc=%d\n", |
| 296 | idx, shift, def->sllp, def->avpnm, def->tlbiel, |
| 297 | def->penc); |
| 298 | } |
| 299 | return 1; |
| 300 | } |
| 301 | return 0; |
| 302 | } |
| 303 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 304 | static void __init htab_init_page_sizes(void) |
| 305 | { |
| 306 | int rc; |
| 307 | |
| 308 | /* Default to 4K pages only */ |
| 309 | memcpy(mmu_psize_defs, mmu_psize_defaults_old, |
| 310 | sizeof(mmu_psize_defaults_old)); |
| 311 | |
| 312 | /* |
| 313 | * Try to find the available page sizes in the device-tree |
| 314 | */ |
| 315 | rc = of_scan_flat_dt(htab_dt_scan_page_sizes, NULL); |
| 316 | if (rc != 0) /* Found */ |
| 317 | goto found; |
| 318 | |
| 319 | /* |
| 320 | * Not in the device-tree, let's fallback on known size |
| 321 | * list for 16M capable GP & GR |
| 322 | */ |
Stephen Rothwell | 0470466 | 2006-11-30 11:46:22 +1100 | [diff] [blame] | 323 | if (cpu_has_feature(CPU_FTR_16M_PAGE)) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 324 | memcpy(mmu_psize_defs, mmu_psize_defaults_gp, |
| 325 | sizeof(mmu_psize_defaults_gp)); |
| 326 | found: |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 327 | #ifndef CONFIG_DEBUG_PAGEALLOC |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 328 | /* |
| 329 | * Pick a size for the linear mapping. Currently, we only support |
| 330 | * 16M, 1M and 4K which is the default |
| 331 | */ |
| 332 | if (mmu_psize_defs[MMU_PAGE_16M].shift) |
| 333 | mmu_linear_psize = MMU_PAGE_16M; |
| 334 | else if (mmu_psize_defs[MMU_PAGE_1M].shift) |
| 335 | mmu_linear_psize = MMU_PAGE_1M; |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 336 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 337 | |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 338 | #ifdef CONFIG_PPC_64K_PAGES |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 339 | /* |
| 340 | * Pick a size for the ordinary pages. Default is 4K, we support |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 341 | * 64K for user mappings and vmalloc if supported by the processor. |
| 342 | * We only use 64k for ioremap if the processor |
| 343 | * (and firmware) support cache-inhibited large pages. |
| 344 | * If not, we use 4k and set mmu_ci_restrictions so that |
| 345 | * hash_page knows to switch processes that use cache-inhibited |
| 346 | * mappings to 4k pages. |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 347 | */ |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 348 | if (mmu_psize_defs[MMU_PAGE_64K].shift) { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 349 | mmu_virtual_psize = MMU_PAGE_64K; |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 350 | mmu_vmalloc_psize = MMU_PAGE_64K; |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 351 | if (mmu_linear_psize == MMU_PAGE_4K) |
| 352 | mmu_linear_psize = MMU_PAGE_64K; |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 353 | if (cpu_has_feature(CPU_FTR_CI_LARGE_PAGE)) |
| 354 | mmu_io_psize = MMU_PAGE_64K; |
| 355 | else |
| 356 | mmu_ci_restrictions = 1; |
| 357 | } |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 358 | #endif /* CONFIG_PPC_64K_PAGES */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 359 | |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 360 | printk(KERN_DEBUG "Page orders: linear mapping = %d, " |
| 361 | "virtual = %d, io = %d\n", |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 362 | mmu_psize_defs[mmu_linear_psize].shift, |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 363 | mmu_psize_defs[mmu_virtual_psize].shift, |
| 364 | mmu_psize_defs[mmu_io_psize].shift); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 365 | |
| 366 | #ifdef CONFIG_HUGETLB_PAGE |
| 367 | /* Init large page size. Currently, we pick 16M or 1M depending |
| 368 | * on what is available |
| 369 | */ |
| 370 | if (mmu_psize_defs[MMU_PAGE_16M].shift) |
| 371 | mmu_huge_psize = MMU_PAGE_16M; |
David Gibson | 7d24f0b | 2005-11-07 00:57:52 -0800 | [diff] [blame] | 372 | /* With 4k/4level pagetables, we can't (for now) cope with a |
| 373 | * huge page size < PMD_SIZE */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 374 | else if (mmu_psize_defs[MMU_PAGE_1M].shift) |
| 375 | mmu_huge_psize = MMU_PAGE_1M; |
| 376 | |
| 377 | /* Calculate HPAGE_SHIFT and sanity check it */ |
David Gibson | 7d24f0b | 2005-11-07 00:57:52 -0800 | [diff] [blame] | 378 | if (mmu_psize_defs[mmu_huge_psize].shift > MIN_HUGEPTE_SHIFT && |
| 379 | mmu_psize_defs[mmu_huge_psize].shift < SID_SHIFT) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 380 | HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift; |
| 381 | else |
| 382 | HPAGE_SHIFT = 0; /* No huge pages dude ! */ |
| 383 | #endif /* CONFIG_HUGETLB_PAGE */ |
| 384 | } |
| 385 | |
| 386 | static int __init htab_dt_scan_pftsize(unsigned long node, |
| 387 | const char *uname, int depth, |
| 388 | void *data) |
| 389 | { |
| 390 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
| 391 | u32 *prop; |
| 392 | |
| 393 | /* We are scanning "cpu" nodes only */ |
| 394 | if (type == NULL || strcmp(type, "cpu") != 0) |
| 395 | return 0; |
| 396 | |
| 397 | prop = (u32 *)of_get_flat_dt_prop(node, "ibm,pft-size", NULL); |
| 398 | if (prop != NULL) { |
| 399 | /* pft_size[0] is the NUMA CEC cookie */ |
| 400 | ppc64_pft_size = prop[1]; |
| 401 | return 1; |
| 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static unsigned long __init htab_get_table_size(void) |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 407 | { |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 408 | unsigned long mem_size, rnd_mem_size, pteg_count; |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 409 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 410 | /* If hash size isn't already provided by the platform, we try to |
Adrian Bunk | 943ffb5 | 2006-01-10 00:10:13 +0100 | [diff] [blame] | 411 | * retrieve it from the device-tree. If it's not there neither, we |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 412 | * calculate it now based on the total RAM size |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 413 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 414 | if (ppc64_pft_size == 0) |
| 415 | of_scan_flat_dt(htab_dt_scan_pftsize, NULL); |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 416 | if (ppc64_pft_size) |
| 417 | return 1UL << ppc64_pft_size; |
| 418 | |
| 419 | /* round mem_size up to next power of 2 */ |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 420 | mem_size = lmb_phys_mem_size(); |
| 421 | rnd_mem_size = 1UL << __ilog2(mem_size); |
| 422 | if (rnd_mem_size < mem_size) |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 423 | rnd_mem_size <<= 1; |
| 424 | |
| 425 | /* # pages / 2 */ |
| 426 | pteg_count = max(rnd_mem_size >> (12 + 1), 1UL << 11); |
| 427 | |
| 428 | return pteg_count << 7; |
| 429 | } |
| 430 | |
Mike Kravetz | 54b7924 | 2005-11-07 16:25:48 -0800 | [diff] [blame] | 431 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 432 | void create_section_mapping(unsigned long start, unsigned long end) |
| 433 | { |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 434 | BUG_ON(htab_bolt_mapping(start, end, __pa(start), |
Mike Kravetz | 54b7924 | 2005-11-07 16:25:48 -0800 | [diff] [blame] | 435 | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 436 | mmu_linear_psize, mmu_kernel_ssize)); |
Mike Kravetz | 54b7924 | 2005-11-07 16:25:48 -0800 | [diff] [blame] | 437 | } |
| 438 | #endif /* CONFIG_MEMORY_HOTPLUG */ |
| 439 | |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 440 | static inline void make_bl(unsigned int *insn_addr, void *func) |
| 441 | { |
| 442 | unsigned long funcp = *((unsigned long *)func); |
| 443 | int offset = funcp - (unsigned long)insn_addr; |
| 444 | |
| 445 | *insn_addr = (unsigned int)(0x48000001 | (offset & 0x03fffffc)); |
| 446 | flush_icache_range((unsigned long)insn_addr, 4+ |
| 447 | (unsigned long)insn_addr); |
| 448 | } |
| 449 | |
| 450 | static void __init htab_finish_init(void) |
| 451 | { |
| 452 | extern unsigned int *htab_call_hpte_insert1; |
| 453 | extern unsigned int *htab_call_hpte_insert2; |
| 454 | extern unsigned int *htab_call_hpte_remove; |
| 455 | extern unsigned int *htab_call_hpte_updatepp; |
| 456 | |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 457 | #ifdef CONFIG_PPC_HAS_HASH_64K |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 458 | extern unsigned int *ht64_call_hpte_insert1; |
| 459 | extern unsigned int *ht64_call_hpte_insert2; |
| 460 | extern unsigned int *ht64_call_hpte_remove; |
| 461 | extern unsigned int *ht64_call_hpte_updatepp; |
| 462 | |
| 463 | make_bl(ht64_call_hpte_insert1, ppc_md.hpte_insert); |
| 464 | make_bl(ht64_call_hpte_insert2, ppc_md.hpte_insert); |
| 465 | make_bl(ht64_call_hpte_remove, ppc_md.hpte_remove); |
| 466 | make_bl(ht64_call_hpte_updatepp, ppc_md.hpte_updatepp); |
Jon Tollefson | 5b82583 | 2007-05-17 04:43:02 +1000 | [diff] [blame] | 467 | #endif /* CONFIG_PPC_HAS_HASH_64K */ |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 468 | |
| 469 | make_bl(htab_call_hpte_insert1, ppc_md.hpte_insert); |
| 470 | make_bl(htab_call_hpte_insert2, ppc_md.hpte_insert); |
| 471 | make_bl(htab_call_hpte_remove, ppc_md.hpte_remove); |
| 472 | make_bl(htab_call_hpte_updatepp, ppc_md.hpte_updatepp); |
| 473 | } |
| 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | void __init htab_initialize(void) |
| 476 | { |
Michael Ellerman | 337a712 | 2006-02-21 17:22:55 +1100 | [diff] [blame] | 477 | unsigned long table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | unsigned long pteg_count; |
| 479 | unsigned long mode_rw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | unsigned long base = 0, size = 0; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 481 | int i; |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | extern unsigned long tce_alloc_start, tce_alloc_end; |
| 484 | |
| 485 | DBG(" -> htab_initialize()\n"); |
| 486 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 487 | /* Initialize segment sizes */ |
| 488 | htab_init_seg_sizes(); |
| 489 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 490 | /* Initialize page sizes */ |
| 491 | htab_init_page_sizes(); |
| 492 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 493 | if (cpu_has_feature(CPU_FTR_1T_SEGMENT)) { |
| 494 | mmu_kernel_ssize = MMU_SEGSIZE_1T; |
| 495 | mmu_highuser_ssize = MMU_SEGSIZE_1T; |
| 496 | printk(KERN_INFO "Using 1TB segments\n"); |
| 497 | } |
| 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | /* |
| 500 | * Calculate the required size of the htab. We want the number of |
| 501 | * PTEGs to equal one half the number of real pages. |
| 502 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 503 | htab_size_bytes = htab_get_table_size(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | pteg_count = htab_size_bytes >> 7; |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | htab_hash_mask = pteg_count - 1; |
| 507 | |
Michael Ellerman | 57cfb81 | 2006-03-21 20:45:59 +1100 | [diff] [blame] | 508 | if (firmware_has_feature(FW_FEATURE_LPAR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | /* Using a hypervisor which owns the htab */ |
| 510 | htab_address = NULL; |
| 511 | _SDR1 = 0; |
| 512 | } else { |
| 513 | /* Find storage for the HPT. Must be contiguous in |
| 514 | * the absolute address space. |
| 515 | */ |
| 516 | table = lmb_alloc(htab_size_bytes, htab_size_bytes); |
| 517 | |
| 518 | DBG("Hash table allocated at %lx, size: %lx\n", table, |
| 519 | htab_size_bytes); |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | htab_address = abs_to_virt(table); |
| 522 | |
| 523 | /* htab absolute addr + encoded htabsize */ |
| 524 | _SDR1 = table + __ilog2(pteg_count) - 11; |
| 525 | |
| 526 | /* Initialize the HPT with no entries */ |
| 527 | memset((void *)table, 0, htab_size_bytes); |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 528 | |
| 529 | /* Set SDR1 */ |
| 530 | mtspr(SPRN_SDR1, _SDR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Anton Blanchard | 515bae9c | 2005-06-21 17:15:55 -0700 | [diff] [blame] | 533 | mode_rw = _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 535 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 536 | linear_map_hash_count = lmb_end_of_DRAM() >> PAGE_SHIFT; |
| 537 | linear_map_hash_slots = __va(lmb_alloc_base(linear_map_hash_count, |
| 538 | 1, lmb.rmo_size)); |
| 539 | memset(linear_map_hash_slots, 0, linear_map_hash_count); |
| 540 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* On U3 based machines, we need to reserve the DART area and |
| 543 | * _NOT_ map it to avoid cache paradoxes as it's remapped non |
| 544 | * cacheable later on |
| 545 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* create bolted the linear mapping in the hash table */ |
| 548 | for (i=0; i < lmb.memory.cnt; i++) { |
Michael Ellerman | b5666f7 | 2005-12-05 10:24:33 -0600 | [diff] [blame] | 549 | base = (unsigned long)__va(lmb.memory.region[i].base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | size = lmb.memory.region[i].size; |
| 551 | |
| 552 | DBG("creating mapping for region: %lx : %lx\n", base, size); |
| 553 | |
| 554 | #ifdef CONFIG_U3_DART |
| 555 | /* Do not map the DART space. Fortunately, it will be aligned |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 556 | * in such a way that it will not cross two lmb regions and |
| 557 | * will fit within a single 16Mb page. |
| 558 | * The DART space is assumed to be a full 16Mb region even if |
| 559 | * we only use 2Mb of that space. We will use more of it later |
| 560 | * for AGP GART. We have to use a full 16Mb large page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | */ |
| 562 | DBG("DART base: %lx\n", dart_tablebase); |
| 563 | |
| 564 | if (dart_tablebase != 0 && dart_tablebase >= base |
| 565 | && dart_tablebase < (base + size)) { |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 566 | unsigned long dart_table_end = dart_tablebase + 16 * MB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | if (base != dart_tablebase) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 568 | BUG_ON(htab_bolt_mapping(base, dart_tablebase, |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 569 | __pa(base), mode_rw, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 570 | mmu_linear_psize, |
| 571 | mmu_kernel_ssize)); |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 572 | if ((base + size) > dart_table_end) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 573 | BUG_ON(htab_bolt_mapping(dart_tablebase+16*MB, |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 574 | base + size, |
| 575 | __pa(dart_table_end), |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 576 | mode_rw, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 577 | mmu_linear_psize, |
| 578 | mmu_kernel_ssize)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | continue; |
| 580 | } |
| 581 | #endif /* CONFIG_U3_DART */ |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 582 | BUG_ON(htab_bolt_mapping(base, base + size, __pa(base), |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 583 | mode_rw, mmu_linear_psize, mmu_kernel_ssize)); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
| 586 | /* |
| 587 | * If we have a memory_limit and we've allocated TCEs then we need to |
| 588 | * explicitly map the TCE area at the top of RAM. We also cope with the |
| 589 | * case that the TCEs start below memory_limit. |
| 590 | * tce_alloc_start/end are 16MB aligned so the mapping should work |
| 591 | * for either 4K or 16MB pages. |
| 592 | */ |
| 593 | if (tce_alloc_start) { |
Michael Ellerman | b5666f7 | 2005-12-05 10:24:33 -0600 | [diff] [blame] | 594 | tce_alloc_start = (unsigned long)__va(tce_alloc_start); |
| 595 | tce_alloc_end = (unsigned long)__va(tce_alloc_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | if (base + size >= tce_alloc_start) |
| 598 | tce_alloc_start = base + size + 1; |
| 599 | |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 600 | BUG_ON(htab_bolt_mapping(tce_alloc_start, tce_alloc_end, |
| 601 | __pa(tce_alloc_start), mode_rw, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 602 | mmu_linear_psize, mmu_kernel_ssize)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 605 | htab_finish_init(); |
| 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | DBG(" <- htab_initialize()\n"); |
| 608 | } |
| 609 | #undef KB |
| 610 | #undef MB |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Anton Blanchard | e597cb32 | 2005-12-29 10:46:29 +1100 | [diff] [blame] | 612 | void htab_initialize_secondary(void) |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 613 | { |
Michael Ellerman | 57cfb81 | 2006-03-21 20:45:59 +1100 | [diff] [blame] | 614 | if (!firmware_has_feature(FW_FEATURE_LPAR)) |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 615 | mtspr(SPRN_SDR1, _SDR1); |
| 616 | } |
| 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | /* |
| 619 | * Called by asm hashtable.S for doing lazy icache flush |
| 620 | */ |
| 621 | unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap) |
| 622 | { |
| 623 | struct page *page; |
| 624 | |
Benjamin Herrenschmidt | 76c8e25 | 2005-11-08 11:21:05 +1100 | [diff] [blame] | 625 | if (!pfn_valid(pte_pfn(pte))) |
| 626 | return pp; |
| 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | page = pte_page(pte); |
| 629 | |
| 630 | /* page is dirty */ |
| 631 | if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) { |
| 632 | if (trap == 0x400) { |
| 633 | __flush_dcache_icache(page_address(page)); |
| 634 | set_bit(PG_arch_1, &page->flags); |
| 635 | } else |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 636 | pp |= HPTE_R_N; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | return pp; |
| 639 | } |
| 640 | |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 641 | /* |
| 642 | * Demote a segment to using 4k pages. |
| 643 | * For now this makes the whole process use 4k pages. |
| 644 | */ |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 645 | #ifdef CONFIG_PPC_64K_PAGES |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 646 | static void demote_segment_4k(struct mm_struct *mm, unsigned long addr) |
| 647 | { |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 648 | if (mm->context.user_psize == MMU_PAGE_4K) |
| 649 | return; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 650 | slice_set_user_psize(mm, MMU_PAGE_4K); |
Geert Uytterhoeven | 1e57ba8 | 2007-07-17 02:35:38 +1000 | [diff] [blame] | 651 | #ifdef CONFIG_SPU_BASE |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 652 | spu_flush_all_slbs(mm); |
| 653 | #endif |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 654 | } |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 655 | #endif /* CONFIG_PPC_64K_PAGES */ |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* Result code is: |
| 658 | * 0 - handled |
| 659 | * 1 - normal page fault |
| 660 | * -1 - critical hash insertion error |
| 661 | */ |
| 662 | int hash_page(unsigned long ea, unsigned long access, unsigned long trap) |
| 663 | { |
| 664 | void *pgdir; |
| 665 | unsigned long vsid; |
| 666 | struct mm_struct *mm; |
| 667 | pte_t *ptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | cpumask_t tmp; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 669 | int rc, user_region = 0, local = 0; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 670 | int psize, ssize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 672 | DBG_LOW("hash_page(ea=%016lx, access=%lx, trap=%lx\n", |
| 673 | ea, access, trap); |
David Gibson | 1f8d419 | 2005-05-05 16:15:13 -0700 | [diff] [blame] | 674 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 675 | if ((ea & ~REGION_MASK) >= PGTABLE_RANGE) { |
| 676 | DBG_LOW(" out of pgtable range !\n"); |
| 677 | return 1; |
| 678 | } |
| 679 | |
| 680 | /* Get region & vsid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | switch (REGION_ID(ea)) { |
| 682 | case USER_REGION_ID: |
| 683 | user_region = 1; |
| 684 | mm = current->mm; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 685 | if (! mm) { |
| 686 | DBG_LOW(" user region with no mm !\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return 1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 688 | } |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 689 | #ifdef CONFIG_PPC_MM_SLICES |
| 690 | psize = get_slice_psize(mm, ea); |
| 691 | #else |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 692 | psize = mm->context.user_psize; |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 693 | #endif |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 694 | ssize = user_segment_size(ea); |
| 695 | vsid = get_vsid(mm->context.id, ea, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | case VMALLOC_REGION_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | mm = &init_mm; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 699 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 700 | if (ea < VMALLOC_END) |
| 701 | psize = mmu_vmalloc_psize; |
| 702 | else |
| 703 | psize = mmu_io_psize; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 704 | ssize = mmu_kernel_ssize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | default: |
| 707 | /* Not a valid range |
| 708 | * Send the problem up to do_page_fault |
| 709 | */ |
| 710 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 712 | DBG_LOW(" mm=%p, mm->pgdir=%p, vsid=%016lx\n", mm, mm->pgd, vsid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 714 | /* Get pgdir */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | pgdir = mm->pgd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | if (pgdir == NULL) |
| 717 | return 1; |
| 718 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 719 | /* Check CPU locality */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | tmp = cpumask_of_cpu(smp_processor_id()); |
| 721 | if (user_region && cpus_equal(mm->cpu_vm_mask, tmp)) |
| 722 | local = 1; |
| 723 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 724 | #ifdef CONFIG_HUGETLB_PAGE |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 725 | /* Handle hugepage regions */ |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 726 | if (HPAGE_SHIFT && psize == mmu_huge_psize) { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 727 | DBG_LOW(" -> huge page !\n"); |
David Gibson | cbf52af | 2005-12-09 14:20:52 +1100 | [diff] [blame] | 728 | return hash_huge_page(mm, access, ea, vsid, local, trap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 730 | #endif /* CONFIG_HUGETLB_PAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 732 | #ifndef CONFIG_PPC_64K_PAGES |
| 733 | /* If we use 4K pages and our psize is not 4K, then we are hitting |
| 734 | * a special driver mapping, we need to align the address before |
| 735 | * we fetch the PTE |
| 736 | */ |
| 737 | if (psize != MMU_PAGE_4K) |
| 738 | ea &= ~((1ul << mmu_psize_defs[psize].shift) - 1); |
| 739 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 740 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 741 | /* Get PTE and page size from page tables */ |
| 742 | ptep = find_linux_pte(pgdir, ea); |
| 743 | if (ptep == NULL || !pte_present(*ptep)) { |
| 744 | DBG_LOW(" no PTE !\n"); |
| 745 | return 1; |
| 746 | } |
| 747 | |
| 748 | #ifndef CONFIG_PPC_64K_PAGES |
| 749 | DBG_LOW(" i-pte: %016lx\n", pte_val(*ptep)); |
| 750 | #else |
| 751 | DBG_LOW(" i-pte: %016lx %016lx\n", pte_val(*ptep), |
| 752 | pte_val(*(ptep + PTRS_PER_PTE))); |
| 753 | #endif |
| 754 | /* Pre-check access permissions (will be re-checked atomically |
| 755 | * in __hash_page_XX but this pre-check is a fast path |
| 756 | */ |
| 757 | if (access & ~pte_val(*ptep)) { |
| 758 | DBG_LOW(" no access !\n"); |
| 759 | return 1; |
| 760 | } |
| 761 | |
| 762 | /* Do actual hashing */ |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 763 | #ifdef CONFIG_PPC_64K_PAGES |
Paul Mackerras | 721151d | 2007-04-03 21:24:02 +1000 | [diff] [blame] | 764 | /* If _PAGE_4K_PFN is set, make sure this is a 4k segment */ |
| 765 | if (pte_val(*ptep) & _PAGE_4K_PFN) { |
| 766 | demote_segment_4k(mm, ea); |
| 767 | psize = MMU_PAGE_4K; |
| 768 | } |
| 769 | |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 770 | /* If this PTE is non-cacheable and we have restrictions on |
| 771 | * using non cacheable large pages, then we switch to 4k |
| 772 | */ |
| 773 | if (mmu_ci_restrictions && psize == MMU_PAGE_64K && |
| 774 | (pte_val(*ptep) & _PAGE_NO_CACHE)) { |
| 775 | if (user_region) { |
| 776 | demote_segment_4k(mm, ea); |
| 777 | psize = MMU_PAGE_4K; |
| 778 | } else if (ea < VMALLOC_END) { |
| 779 | /* |
| 780 | * some driver did a non-cacheable mapping |
| 781 | * in vmalloc space, so switch vmalloc |
| 782 | * to 4k pages |
| 783 | */ |
| 784 | printk(KERN_ALERT "Reducing vmalloc segment " |
| 785 | "to 4kB pages because of " |
| 786 | "non-cacheable mapping\n"); |
| 787 | psize = mmu_vmalloc_psize = MMU_PAGE_4K; |
Geert Uytterhoeven | 1e57ba8 | 2007-07-17 02:35:38 +1000 | [diff] [blame] | 788 | #ifdef CONFIG_SPU_BASE |
Benjamin Herrenschmidt | 94b2a43 | 2007-03-10 00:05:37 +0100 | [diff] [blame] | 789 | spu_flush_all_slbs(mm); |
| 790 | #endif |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 791 | } |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 792 | } |
| 793 | if (user_region) { |
| 794 | if (psize != get_paca()->context.user_psize) { |
Benjamin Herrenschmidt | f6ab0b9 | 2007-10-29 12:05:18 +1100 | [diff] [blame] | 795 | get_paca()->context = mm->context; |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 796 | slb_flush_and_rebolt(); |
| 797 | } |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 798 | } else if (get_paca()->vmalloc_sllp != |
| 799 | mmu_psize_defs[mmu_vmalloc_psize].sllp) { |
| 800 | get_paca()->vmalloc_sllp = |
| 801 | mmu_psize_defs[mmu_vmalloc_psize].sllp; |
Michael Neuling | 67439b7 | 2007-08-03 11:55:39 +1000 | [diff] [blame] | 802 | slb_vmalloc_update(); |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 803 | } |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 804 | #endif /* CONFIG_PPC_64K_PAGES */ |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 805 | |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 806 | #ifdef CONFIG_PPC_HAS_HASH_64K |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 807 | if (psize == MMU_PAGE_64K) |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 808 | rc = __hash_page_64K(ea, access, vsid, ptep, trap, local, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 809 | else |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 810 | #endif /* CONFIG_PPC_HAS_HASH_64K */ |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 811 | rc = __hash_page_4K(ea, access, vsid, ptep, trap, local, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 812 | |
| 813 | #ifndef CONFIG_PPC_64K_PAGES |
| 814 | DBG_LOW(" o-pte: %016lx\n", pte_val(*ptep)); |
| 815 | #else |
| 816 | DBG_LOW(" o-pte: %016lx %016lx\n", pte_val(*ptep), |
| 817 | pte_val(*(ptep + PTRS_PER_PTE))); |
| 818 | #endif |
| 819 | DBG_LOW(" -> rc=%d\n", rc); |
| 820 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 822 | EXPORT_SYMBOL_GPL(hash_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 824 | void hash_preload(struct mm_struct *mm, unsigned long ea, |
| 825 | unsigned long access, unsigned long trap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 827 | unsigned long vsid; |
| 828 | void *pgdir; |
| 829 | pte_t *ptep; |
| 830 | cpumask_t mask; |
| 831 | unsigned long flags; |
| 832 | int local = 0; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 833 | int ssize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 835 | BUG_ON(REGION_ID(ea) != USER_REGION_ID); |
| 836 | |
| 837 | #ifdef CONFIG_PPC_MM_SLICES |
| 838 | /* We only prefault standard pages for now */ |
Ilpo Järvinen | 2b02d13 | 2007-08-16 08:03:35 +1000 | [diff] [blame] | 839 | if (unlikely(get_slice_psize(mm, ea) != mm->context.user_psize)) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 840 | return; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 841 | #endif |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 842 | |
| 843 | DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx," |
| 844 | " trap=%lx\n", mm, mm->pgd, ea, access, trap); |
| 845 | |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 846 | /* Get Linux PTE if available */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 847 | pgdir = mm->pgd; |
| 848 | if (pgdir == NULL) |
| 849 | return; |
| 850 | ptep = find_linux_pte(pgdir, ea); |
| 851 | if (!ptep) |
| 852 | return; |
Benjamin Herrenschmidt | 16f1c74 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 853 | |
| 854 | #ifdef CONFIG_PPC_64K_PAGES |
| 855 | /* If either _PAGE_4K_PFN or _PAGE_NO_CACHE is set (and we are on |
| 856 | * a 64K kernel), then we don't preload, hash_page() will take |
| 857 | * care of it once we actually try to access the page. |
| 858 | * That way we don't have to duplicate all of the logic for segment |
| 859 | * page size demotion here |
| 860 | */ |
| 861 | if (pte_val(*ptep) & (_PAGE_4K_PFN | _PAGE_NO_CACHE)) |
| 862 | return; |
| 863 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 864 | |
| 865 | /* Get VSID */ |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 866 | ssize = user_segment_size(ea); |
| 867 | vsid = get_vsid(mm->context.id, ea, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 868 | |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 869 | /* Hash doesn't like irqs */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 870 | local_irq_save(flags); |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 871 | |
| 872 | /* Is that local to this CPU ? */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 873 | mask = cpumask_of_cpu(smp_processor_id()); |
| 874 | if (cpus_equal(mm->cpu_vm_mask, mask)) |
| 875 | local = 1; |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 876 | |
| 877 | /* Hash it in */ |
| 878 | #ifdef CONFIG_PPC_HAS_HASH_64K |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 879 | if (mm->context.user_psize == MMU_PAGE_64K) |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 880 | __hash_page_64K(ea, access, vsid, ptep, trap, local, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | else |
Jon Tollefson | 5b82583 | 2007-05-17 04:43:02 +1000 | [diff] [blame] | 882 | #endif /* CONFIG_PPC_HAS_HASH_64K */ |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 883 | __hash_page_4K(ea, access, vsid, ptep, trap, local, ssize); |
Benjamin Herrenschmidt | 16c2d47 | 2007-05-08 16:27:28 +1000 | [diff] [blame] | 884 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 885 | local_irq_restore(flags); |
| 886 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
Benjamin Herrenschmidt | f6ab0b9 | 2007-10-29 12:05:18 +1100 | [diff] [blame] | 888 | /* WARNING: This is called from hash_low_64.S, if you change this prototype, |
| 889 | * do not forget to update the assembly call site ! |
| 890 | */ |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 891 | void flush_hash_page(unsigned long va, real_pte_t pte, int psize, int ssize, |
| 892 | int local) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 893 | { |
| 894 | unsigned long hash, index, shift, hidx, slot; |
| 895 | |
| 896 | DBG_LOW("flush_hash_page(va=%016x)\n", va); |
| 897 | pte_iterate_hashed_subpages(pte, psize, va, index, shift) { |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 898 | hash = hpt_hash(va, shift, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 899 | hidx = __rpte_to_hidx(pte, index); |
| 900 | if (hidx & _PTEIDX_SECONDARY) |
| 901 | hash = ~hash; |
| 902 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 903 | slot += hidx & _PTEIDX_GROUP_IX; |
| 904 | DBG_LOW(" sub %d: hash=%x, hidx=%x\n", index, slot, hidx); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 905 | ppc_md.hpte_invalidate(slot, va, psize, ssize, local); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 906 | } pte_iterate_hashed_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 909 | void flush_hash_range(unsigned long number, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 911 | if (ppc_md.flush_hash_range) |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 912 | ppc_md.flush_hash_range(number, local); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 913 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | int i; |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 915 | struct ppc64_tlb_batch *batch = |
| 916 | &__get_cpu_var(ppc64_tlb_batch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | for (i = 0; i < number; i++) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 919 | flush_hash_page(batch->vaddr[i], batch->pte[i], |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 920 | batch->psize, batch->ssize, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | /* |
| 925 | * low_hash_fault is called when we the low level hash code failed |
| 926 | * to instert a PTE due to an hypervisor error |
| 927 | */ |
| 928 | void low_hash_fault(struct pt_regs *regs, unsigned long address) |
| 929 | { |
| 930 | if (user_mode(regs)) { |
| 931 | siginfo_t info; |
| 932 | |
| 933 | info.si_signo = SIGBUS; |
| 934 | info.si_errno = 0; |
| 935 | info.si_code = BUS_ADRERR; |
| 936 | info.si_addr = (void __user *)address; |
| 937 | force_sig_info(SIGBUS, &info, current); |
| 938 | return; |
| 939 | } |
| 940 | bad_page_fault(regs, address, SIGBUS); |
| 941 | } |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 942 | |
| 943 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 944 | static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) |
| 945 | { |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 946 | unsigned long hash, hpteg; |
| 947 | unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); |
| 948 | unsigned long va = hpt_va(vaddr, vsid, mmu_kernel_ssize); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 949 | unsigned long mode = _PAGE_ACCESSED | _PAGE_DIRTY | |
| 950 | _PAGE_COHERENT | PP_RWXX | HPTE_R_N; |
| 951 | int ret; |
| 952 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 953 | hash = hpt_hash(va, PAGE_SHIFT, mmu_kernel_ssize); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 954 | hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP); |
| 955 | |
| 956 | ret = ppc_md.hpte_insert(hpteg, va, __pa(vaddr), |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 957 | mode, HPTE_V_BOLTED, |
| 958 | mmu_linear_psize, mmu_kernel_ssize); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 959 | BUG_ON (ret < 0); |
| 960 | spin_lock(&linear_map_hash_lock); |
| 961 | BUG_ON(linear_map_hash_slots[lmi] & 0x80); |
| 962 | linear_map_hash_slots[lmi] = ret | 0x80; |
| 963 | spin_unlock(&linear_map_hash_lock); |
| 964 | } |
| 965 | |
| 966 | static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) |
| 967 | { |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 968 | unsigned long hash, hidx, slot; |
| 969 | unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); |
| 970 | unsigned long va = hpt_va(vaddr, vsid, mmu_kernel_ssize); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 971 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 972 | hash = hpt_hash(va, PAGE_SHIFT, mmu_kernel_ssize); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 973 | spin_lock(&linear_map_hash_lock); |
| 974 | BUG_ON(!(linear_map_hash_slots[lmi] & 0x80)); |
| 975 | hidx = linear_map_hash_slots[lmi] & 0x7f; |
| 976 | linear_map_hash_slots[lmi] = 0; |
| 977 | spin_unlock(&linear_map_hash_lock); |
| 978 | if (hidx & _PTEIDX_SECONDARY) |
| 979 | hash = ~hash; |
| 980 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 981 | slot += hidx & _PTEIDX_GROUP_IX; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 982 | ppc_md.hpte_invalidate(slot, va, mmu_linear_psize, mmu_kernel_ssize, 0); |
Benjamin Herrenschmidt | 370a908 | 2007-04-12 15:30:23 +1000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | void kernel_map_pages(struct page *page, int numpages, int enable) |
| 986 | { |
| 987 | unsigned long flags, vaddr, lmi; |
| 988 | int i; |
| 989 | |
| 990 | local_irq_save(flags); |
| 991 | for (i = 0; i < numpages; i++, page++) { |
| 992 | vaddr = (unsigned long)page_address(page); |
| 993 | lmi = __pa(vaddr) >> PAGE_SHIFT; |
| 994 | if (lmi >= linear_map_hash_count) |
| 995 | continue; |
| 996 | if (enable) |
| 997 | kernel_map_linear_page(vaddr, lmi); |
| 998 | else |
| 999 | kernel_unmap_linear_page(vaddr, lmi); |
| 1000 | } |
| 1001 | local_irq_restore(flags); |
| 1002 | } |
| 1003 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |