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 | |
| 24 | #include <linux/config.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/sched.h> |
| 28 | #include <linux/proc_fs.h> |
| 29 | #include <linux/stat.h> |
| 30 | #include <linux/sysctl.h> |
| 31 | #include <linux/ctype.h> |
| 32 | #include <linux/cache.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/signal.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/processor.h> |
| 37 | #include <asm/pgtable.h> |
| 38 | #include <asm/mmu.h> |
| 39 | #include <asm/mmu_context.h> |
| 40 | #include <asm/page.h> |
| 41 | #include <asm/types.h> |
| 42 | #include <asm/system.h> |
| 43 | #include <asm/uaccess.h> |
| 44 | #include <asm/machdep.h> |
| 45 | #include <asm/lmb.h> |
| 46 | #include <asm/abs_addr.h> |
| 47 | #include <asm/tlbflush.h> |
| 48 | #include <asm/io.h> |
| 49 | #include <asm/eeh.h> |
| 50 | #include <asm/tlb.h> |
| 51 | #include <asm/cacheflush.h> |
| 52 | #include <asm/cputable.h> |
| 53 | #include <asm/abs_addr.h> |
| 54 | #include <asm/sections.h> |
| 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 | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 90 | hpte_t *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; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 97 | #ifdef CONFIG_HUGETLB_PAGE |
| 98 | int mmu_huge_psize = MMU_PAGE_16M; |
| 99 | unsigned int HPAGE_SHIFT; |
| 100 | #endif |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 101 | #ifdef CONFIG_PPC_64K_PAGES |
| 102 | int mmu_ci_restrictions; |
| 103 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 105 | /* There are definitions of page sizes arrays to be used when none |
| 106 | * is provided by the firmware. |
| 107 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 109 | /* Pre-POWER4 CPUs (4k pages only) |
| 110 | */ |
| 111 | struct mmu_psize_def mmu_psize_defaults_old[] = { |
| 112 | [MMU_PAGE_4K] = { |
| 113 | .shift = 12, |
| 114 | .sllp = 0, |
| 115 | .penc = 0, |
| 116 | .avpnm = 0, |
| 117 | .tlbiel = 0, |
| 118 | }, |
| 119 | }; |
| 120 | |
| 121 | /* POWER4, GPUL, POWER5 |
| 122 | * |
| 123 | * Support for 16Mb large pages |
| 124 | */ |
| 125 | struct mmu_psize_def mmu_psize_defaults_gp[] = { |
| 126 | [MMU_PAGE_4K] = { |
| 127 | .shift = 12, |
| 128 | .sllp = 0, |
| 129 | .penc = 0, |
| 130 | .avpnm = 0, |
| 131 | .tlbiel = 1, |
| 132 | }, |
| 133 | [MMU_PAGE_16M] = { |
| 134 | .shift = 24, |
| 135 | .sllp = SLB_VSID_L, |
| 136 | .penc = 0, |
| 137 | .avpnm = 0x1UL, |
| 138 | .tlbiel = 0, |
| 139 | }, |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | int htab_bolt_mapping(unsigned long vstart, unsigned long vend, |
| 144 | unsigned long pstart, unsigned long mode, int psize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 146 | unsigned long vaddr, paddr; |
| 147 | unsigned int step, shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | unsigned long tmp_mode; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 149 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 151 | shift = mmu_psize_defs[psize].shift; |
| 152 | step = 1 << shift; |
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 | for (vaddr = vstart, paddr = pstart; vaddr < vend; |
| 155 | vaddr += step, paddr += step) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | unsigned long vpn, hash, hpteg; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 157 | unsigned long vsid = get_kernel_vsid(vaddr); |
| 158 | unsigned long va = (vsid << 28) | (vaddr & 0x0fffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 160 | vpn = va >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | tmp_mode = mode; |
| 162 | |
| 163 | /* Make non-kernel text non-executable */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 164 | if (!in_kernel_text(vaddr)) |
| 165 | tmp_mode = mode | HPTE_R_N; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 167 | hash = hpt_hash(va, shift); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP); |
| 169 | |
Michael Ellerman | c30a4df | 2006-06-23 18:16:39 +1000 | [diff] [blame^] | 170 | DBG("htab_bolt_mapping: calling %p\n", ppc_md.hpte_insert); |
| 171 | |
| 172 | BUG_ON(!ppc_md.hpte_insert); |
| 173 | ret = ppc_md.hpte_insert(hpteg, va, paddr, |
| 174 | tmp_mode, HPTE_V_BOLTED, psize); |
| 175 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 176 | if (ret < 0) |
| 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 179 | return ret < 0 ? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 182 | static int __init htab_dt_scan_page_sizes(unsigned long node, |
| 183 | const char *uname, int depth, |
| 184 | void *data) |
| 185 | { |
| 186 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
| 187 | u32 *prop; |
| 188 | unsigned long size = 0; |
| 189 | |
| 190 | /* We are scanning "cpu" nodes only */ |
| 191 | if (type == NULL || strcmp(type, "cpu") != 0) |
| 192 | return 0; |
| 193 | |
| 194 | prop = (u32 *)of_get_flat_dt_prop(node, |
| 195 | "ibm,segment-page-sizes", &size); |
| 196 | if (prop != NULL) { |
| 197 | DBG("Page sizes from device-tree:\n"); |
| 198 | size /= 4; |
| 199 | cur_cpu_spec->cpu_features &= ~(CPU_FTR_16M_PAGE); |
| 200 | while(size > 0) { |
| 201 | unsigned int shift = prop[0]; |
| 202 | unsigned int slbenc = prop[1]; |
| 203 | unsigned int lpnum = prop[2]; |
| 204 | unsigned int lpenc = 0; |
| 205 | struct mmu_psize_def *def; |
| 206 | int idx = -1; |
| 207 | |
| 208 | size -= 3; prop += 3; |
| 209 | while(size > 0 && lpnum) { |
| 210 | if (prop[0] == shift) |
| 211 | lpenc = prop[1]; |
| 212 | prop += 2; size -= 2; |
| 213 | lpnum--; |
| 214 | } |
| 215 | switch(shift) { |
| 216 | case 0xc: |
| 217 | idx = MMU_PAGE_4K; |
| 218 | break; |
| 219 | case 0x10: |
| 220 | idx = MMU_PAGE_64K; |
| 221 | break; |
| 222 | case 0x14: |
| 223 | idx = MMU_PAGE_1M; |
| 224 | break; |
| 225 | case 0x18: |
| 226 | idx = MMU_PAGE_16M; |
| 227 | cur_cpu_spec->cpu_features |= CPU_FTR_16M_PAGE; |
| 228 | break; |
| 229 | case 0x22: |
| 230 | idx = MMU_PAGE_16G; |
| 231 | break; |
| 232 | } |
| 233 | if (idx < 0) |
| 234 | continue; |
| 235 | def = &mmu_psize_defs[idx]; |
| 236 | def->shift = shift; |
| 237 | if (shift <= 23) |
| 238 | def->avpnm = 0; |
| 239 | else |
| 240 | def->avpnm = (1 << (shift - 23)) - 1; |
| 241 | def->sllp = slbenc; |
| 242 | def->penc = lpenc; |
| 243 | /* We don't know for sure what's up with tlbiel, so |
| 244 | * for now we only set it for 4K and 64K pages |
| 245 | */ |
| 246 | if (idx == MMU_PAGE_4K || idx == MMU_PAGE_64K) |
| 247 | def->tlbiel = 1; |
| 248 | else |
| 249 | def->tlbiel = 0; |
| 250 | |
| 251 | DBG(" %d: shift=%02x, sllp=%04x, avpnm=%08x, " |
| 252 | "tlbiel=%d, penc=%d\n", |
| 253 | idx, shift, def->sllp, def->avpnm, def->tlbiel, |
| 254 | def->penc); |
| 255 | } |
| 256 | return 1; |
| 257 | } |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | static void __init htab_init_page_sizes(void) |
| 263 | { |
| 264 | int rc; |
| 265 | |
| 266 | /* Default to 4K pages only */ |
| 267 | memcpy(mmu_psize_defs, mmu_psize_defaults_old, |
| 268 | sizeof(mmu_psize_defaults_old)); |
| 269 | |
| 270 | /* |
| 271 | * Try to find the available page sizes in the device-tree |
| 272 | */ |
| 273 | rc = of_scan_flat_dt(htab_dt_scan_page_sizes, NULL); |
| 274 | if (rc != 0) /* Found */ |
| 275 | goto found; |
| 276 | |
| 277 | /* |
| 278 | * Not in the device-tree, let's fallback on known size |
| 279 | * list for 16M capable GP & GR |
| 280 | */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 281 | if (cpu_has_feature(CPU_FTR_16M_PAGE) && !machine_is(iseries)) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 282 | memcpy(mmu_psize_defs, mmu_psize_defaults_gp, |
| 283 | sizeof(mmu_psize_defaults_gp)); |
| 284 | found: |
| 285 | /* |
| 286 | * Pick a size for the linear mapping. Currently, we only support |
| 287 | * 16M, 1M and 4K which is the default |
| 288 | */ |
| 289 | if (mmu_psize_defs[MMU_PAGE_16M].shift) |
| 290 | mmu_linear_psize = MMU_PAGE_16M; |
| 291 | else if (mmu_psize_defs[MMU_PAGE_1M].shift) |
| 292 | mmu_linear_psize = MMU_PAGE_1M; |
| 293 | |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 294 | #ifdef CONFIG_PPC_64K_PAGES |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 295 | /* |
| 296 | * Pick a size for the ordinary pages. Default is 4K, we support |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 297 | * 64K for user mappings and vmalloc if supported by the processor. |
| 298 | * We only use 64k for ioremap if the processor |
| 299 | * (and firmware) support cache-inhibited large pages. |
| 300 | * If not, we use 4k and set mmu_ci_restrictions so that |
| 301 | * hash_page knows to switch processes that use cache-inhibited |
| 302 | * mappings to 4k pages. |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 303 | */ |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 304 | if (mmu_psize_defs[MMU_PAGE_64K].shift) { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 305 | mmu_virtual_psize = MMU_PAGE_64K; |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 306 | mmu_vmalloc_psize = MMU_PAGE_64K; |
| 307 | if (cpu_has_feature(CPU_FTR_CI_LARGE_PAGE)) |
| 308 | mmu_io_psize = MMU_PAGE_64K; |
| 309 | else |
| 310 | mmu_ci_restrictions = 1; |
| 311 | } |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 312 | #endif |
| 313 | |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 314 | printk(KERN_DEBUG "Page orders: linear mapping = %d, " |
| 315 | "virtual = %d, io = %d\n", |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 316 | mmu_psize_defs[mmu_linear_psize].shift, |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 317 | mmu_psize_defs[mmu_virtual_psize].shift, |
| 318 | mmu_psize_defs[mmu_io_psize].shift); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 319 | |
| 320 | #ifdef CONFIG_HUGETLB_PAGE |
| 321 | /* Init large page size. Currently, we pick 16M or 1M depending |
| 322 | * on what is available |
| 323 | */ |
| 324 | if (mmu_psize_defs[MMU_PAGE_16M].shift) |
| 325 | mmu_huge_psize = MMU_PAGE_16M; |
David Gibson | 7d24f0b | 2005-11-07 00:57:52 -0800 | [diff] [blame] | 326 | /* With 4k/4level pagetables, we can't (for now) cope with a |
| 327 | * huge page size < PMD_SIZE */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 328 | else if (mmu_psize_defs[MMU_PAGE_1M].shift) |
| 329 | mmu_huge_psize = MMU_PAGE_1M; |
| 330 | |
| 331 | /* Calculate HPAGE_SHIFT and sanity check it */ |
David Gibson | 7d24f0b | 2005-11-07 00:57:52 -0800 | [diff] [blame] | 332 | if (mmu_psize_defs[mmu_huge_psize].shift > MIN_HUGEPTE_SHIFT && |
| 333 | mmu_psize_defs[mmu_huge_psize].shift < SID_SHIFT) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 334 | HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift; |
| 335 | else |
| 336 | HPAGE_SHIFT = 0; /* No huge pages dude ! */ |
| 337 | #endif /* CONFIG_HUGETLB_PAGE */ |
| 338 | } |
| 339 | |
| 340 | static int __init htab_dt_scan_pftsize(unsigned long node, |
| 341 | const char *uname, int depth, |
| 342 | void *data) |
| 343 | { |
| 344 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
| 345 | u32 *prop; |
| 346 | |
| 347 | /* We are scanning "cpu" nodes only */ |
| 348 | if (type == NULL || strcmp(type, "cpu") != 0) |
| 349 | return 0; |
| 350 | |
| 351 | prop = (u32 *)of_get_flat_dt_prop(node, "ibm,pft-size", NULL); |
| 352 | if (prop != NULL) { |
| 353 | /* pft_size[0] is the NUMA CEC cookie */ |
| 354 | ppc64_pft_size = prop[1]; |
| 355 | return 1; |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static unsigned long __init htab_get_table_size(void) |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 361 | { |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 362 | unsigned long mem_size, rnd_mem_size, pteg_count; |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 363 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 364 | /* 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] | 365 | * 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] | 366 | * calculate it now based on the total RAM size |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 367 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 368 | if (ppc64_pft_size == 0) |
| 369 | of_scan_flat_dt(htab_dt_scan_pftsize, NULL); |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 370 | if (ppc64_pft_size) |
| 371 | return 1UL << ppc64_pft_size; |
| 372 | |
| 373 | /* round mem_size up to next power of 2 */ |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 374 | mem_size = lmb_phys_mem_size(); |
| 375 | rnd_mem_size = 1UL << __ilog2(mem_size); |
| 376 | if (rnd_mem_size < mem_size) |
Paul Mackerras | 3eac8c6 | 2005-10-12 16:58:53 +1000 | [diff] [blame] | 377 | rnd_mem_size <<= 1; |
| 378 | |
| 379 | /* # pages / 2 */ |
| 380 | pteg_count = max(rnd_mem_size >> (12 + 1), 1UL << 11); |
| 381 | |
| 382 | return pteg_count << 7; |
| 383 | } |
| 384 | |
Mike Kravetz | 54b7924 | 2005-11-07 16:25:48 -0800 | [diff] [blame] | 385 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 386 | void create_section_mapping(unsigned long start, unsigned long end) |
| 387 | { |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 388 | BUG_ON(htab_bolt_mapping(start, end, __pa(start), |
Mike Kravetz | 54b7924 | 2005-11-07 16:25:48 -0800 | [diff] [blame] | 389 | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX, |
| 390 | mmu_linear_psize)); |
| 391 | } |
| 392 | #endif /* CONFIG_MEMORY_HOTPLUG */ |
| 393 | |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 394 | static inline void make_bl(unsigned int *insn_addr, void *func) |
| 395 | { |
| 396 | unsigned long funcp = *((unsigned long *)func); |
| 397 | int offset = funcp - (unsigned long)insn_addr; |
| 398 | |
| 399 | *insn_addr = (unsigned int)(0x48000001 | (offset & 0x03fffffc)); |
| 400 | flush_icache_range((unsigned long)insn_addr, 4+ |
| 401 | (unsigned long)insn_addr); |
| 402 | } |
| 403 | |
| 404 | static void __init htab_finish_init(void) |
| 405 | { |
| 406 | extern unsigned int *htab_call_hpte_insert1; |
| 407 | extern unsigned int *htab_call_hpte_insert2; |
| 408 | extern unsigned int *htab_call_hpte_remove; |
| 409 | extern unsigned int *htab_call_hpte_updatepp; |
| 410 | |
| 411 | #ifdef CONFIG_PPC_64K_PAGES |
| 412 | extern unsigned int *ht64_call_hpte_insert1; |
| 413 | extern unsigned int *ht64_call_hpte_insert2; |
| 414 | extern unsigned int *ht64_call_hpte_remove; |
| 415 | extern unsigned int *ht64_call_hpte_updatepp; |
| 416 | |
| 417 | make_bl(ht64_call_hpte_insert1, ppc_md.hpte_insert); |
| 418 | make_bl(ht64_call_hpte_insert2, ppc_md.hpte_insert); |
| 419 | make_bl(ht64_call_hpte_remove, ppc_md.hpte_remove); |
| 420 | make_bl(ht64_call_hpte_updatepp, ppc_md.hpte_updatepp); |
| 421 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 422 | |
| 423 | make_bl(htab_call_hpte_insert1, ppc_md.hpte_insert); |
| 424 | make_bl(htab_call_hpte_insert2, ppc_md.hpte_insert); |
| 425 | make_bl(htab_call_hpte_remove, ppc_md.hpte_remove); |
| 426 | make_bl(htab_call_hpte_updatepp, ppc_md.hpte_updatepp); |
| 427 | } |
| 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | void __init htab_initialize(void) |
| 430 | { |
Michael Ellerman | 337a712 | 2006-02-21 17:22:55 +1100 | [diff] [blame] | 431 | unsigned long table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | unsigned long pteg_count; |
| 433 | unsigned long mode_rw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | unsigned long base = 0, size = 0; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 435 | int i; |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | extern unsigned long tce_alloc_start, tce_alloc_end; |
| 438 | |
| 439 | DBG(" -> htab_initialize()\n"); |
| 440 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 441 | /* Initialize page sizes */ |
| 442 | htab_init_page_sizes(); |
| 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | /* |
| 445 | * Calculate the required size of the htab. We want the number of |
| 446 | * PTEGs to equal one half the number of real pages. |
| 447 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 448 | htab_size_bytes = htab_get_table_size(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | pteg_count = htab_size_bytes >> 7; |
| 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | htab_hash_mask = pteg_count - 1; |
| 452 | |
Michael Ellerman | 57cfb81 | 2006-03-21 20:45:59 +1100 | [diff] [blame] | 453 | if (firmware_has_feature(FW_FEATURE_LPAR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | /* Using a hypervisor which owns the htab */ |
| 455 | htab_address = NULL; |
| 456 | _SDR1 = 0; |
| 457 | } else { |
| 458 | /* Find storage for the HPT. Must be contiguous in |
| 459 | * the absolute address space. |
| 460 | */ |
| 461 | table = lmb_alloc(htab_size_bytes, htab_size_bytes); |
| 462 | |
| 463 | DBG("Hash table allocated at %lx, size: %lx\n", table, |
| 464 | htab_size_bytes); |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | htab_address = abs_to_virt(table); |
| 467 | |
| 468 | /* htab absolute addr + encoded htabsize */ |
| 469 | _SDR1 = table + __ilog2(pteg_count) - 11; |
| 470 | |
| 471 | /* Initialize the HPT with no entries */ |
| 472 | memset((void *)table, 0, htab_size_bytes); |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 473 | |
| 474 | /* Set SDR1 */ |
| 475 | mtspr(SPRN_SDR1, _SDR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Anton Blanchard | 515bae9 | 2005-06-21 17:15:55 -0700 | [diff] [blame] | 478 | mode_rw = _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
| 480 | /* On U3 based machines, we need to reserve the DART area and |
| 481 | * _NOT_ map it to avoid cache paradoxes as it's remapped non |
| 482 | * cacheable later on |
| 483 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | /* create bolted the linear mapping in the hash table */ |
| 486 | for (i=0; i < lmb.memory.cnt; i++) { |
Michael Ellerman | b5666f7 | 2005-12-05 10:24:33 -0600 | [diff] [blame] | 487 | base = (unsigned long)__va(lmb.memory.region[i].base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | size = lmb.memory.region[i].size; |
| 489 | |
| 490 | DBG("creating mapping for region: %lx : %lx\n", base, size); |
| 491 | |
| 492 | #ifdef CONFIG_U3_DART |
| 493 | /* Do not map the DART space. Fortunately, it will be aligned |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 494 | * in such a way that it will not cross two lmb regions and |
| 495 | * will fit within a single 16Mb page. |
| 496 | * The DART space is assumed to be a full 16Mb region even if |
| 497 | * we only use 2Mb of that space. We will use more of it later |
| 498 | * for AGP GART. We have to use a full 16Mb large page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | */ |
| 500 | DBG("DART base: %lx\n", dart_tablebase); |
| 501 | |
| 502 | if (dart_tablebase != 0 && dart_tablebase >= base |
| 503 | && dart_tablebase < (base + size)) { |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 504 | unsigned long dart_table_end = dart_tablebase + 16 * MB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | if (base != dart_tablebase) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 506 | BUG_ON(htab_bolt_mapping(base, dart_tablebase, |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 507 | __pa(base), mode_rw, |
| 508 | mmu_linear_psize)); |
| 509 | if ((base + size) > dart_table_end) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 510 | BUG_ON(htab_bolt_mapping(dart_tablebase+16*MB, |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 511 | base + size, |
| 512 | __pa(dart_table_end), |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 513 | mode_rw, |
| 514 | mmu_linear_psize)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | continue; |
| 516 | } |
| 517 | #endif /* CONFIG_U3_DART */ |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 518 | BUG_ON(htab_bolt_mapping(base, base + size, __pa(base), |
| 519 | mode_rw, mmu_linear_psize)); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 520 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | /* |
| 523 | * If we have a memory_limit and we've allocated TCEs then we need to |
| 524 | * explicitly map the TCE area at the top of RAM. We also cope with the |
| 525 | * case that the TCEs start below memory_limit. |
| 526 | * tce_alloc_start/end are 16MB aligned so the mapping should work |
| 527 | * for either 4K or 16MB pages. |
| 528 | */ |
| 529 | if (tce_alloc_start) { |
Michael Ellerman | b5666f7 | 2005-12-05 10:24:33 -0600 | [diff] [blame] | 530 | tce_alloc_start = (unsigned long)__va(tce_alloc_start); |
| 531 | tce_alloc_end = (unsigned long)__va(tce_alloc_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | if (base + size >= tce_alloc_start) |
| 534 | tce_alloc_start = base + size + 1; |
| 535 | |
Michael Ellerman | caf80e5 | 2006-03-21 20:45:51 +1100 | [diff] [blame] | 536 | BUG_ON(htab_bolt_mapping(tce_alloc_start, tce_alloc_end, |
| 537 | __pa(tce_alloc_start), mode_rw, |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 538 | mmu_linear_psize)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 541 | htab_finish_init(); |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | DBG(" <- htab_initialize()\n"); |
| 544 | } |
| 545 | #undef KB |
| 546 | #undef MB |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Anton Blanchard | e597cb32 | 2005-12-29 10:46:29 +1100 | [diff] [blame] | 548 | void htab_initialize_secondary(void) |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 549 | { |
Michael Ellerman | 57cfb81 | 2006-03-21 20:45:59 +1100 | [diff] [blame] | 550 | if (!firmware_has_feature(FW_FEATURE_LPAR)) |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 551 | mtspr(SPRN_SDR1, _SDR1); |
| 552 | } |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | /* |
| 555 | * Called by asm hashtable.S for doing lazy icache flush |
| 556 | */ |
| 557 | unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap) |
| 558 | { |
| 559 | struct page *page; |
| 560 | |
Benjamin Herrenschmidt | 76c8e25 | 2005-11-08 11:21:05 +1100 | [diff] [blame] | 561 | if (!pfn_valid(pte_pfn(pte))) |
| 562 | return pp; |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | page = pte_page(pte); |
| 565 | |
| 566 | /* page is dirty */ |
| 567 | if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) { |
| 568 | if (trap == 0x400) { |
| 569 | __flush_dcache_icache(page_address(page)); |
| 570 | set_bit(PG_arch_1, &page->flags); |
| 571 | } else |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 572 | pp |= HPTE_R_N; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | return pp; |
| 575 | } |
| 576 | |
| 577 | /* Result code is: |
| 578 | * 0 - handled |
| 579 | * 1 - normal page fault |
| 580 | * -1 - critical hash insertion error |
| 581 | */ |
| 582 | int hash_page(unsigned long ea, unsigned long access, unsigned long trap) |
| 583 | { |
| 584 | void *pgdir; |
| 585 | unsigned long vsid; |
| 586 | struct mm_struct *mm; |
| 587 | pte_t *ptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | cpumask_t tmp; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 589 | int rc, user_region = 0, local = 0; |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 590 | int psize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 592 | DBG_LOW("hash_page(ea=%016lx, access=%lx, trap=%lx\n", |
| 593 | ea, access, trap); |
David Gibson | 1f8d419 | 2005-05-05 16:15:13 -0700 | [diff] [blame] | 594 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 595 | if ((ea & ~REGION_MASK) >= PGTABLE_RANGE) { |
| 596 | DBG_LOW(" out of pgtable range !\n"); |
| 597 | return 1; |
| 598 | } |
| 599 | |
| 600 | /* Get region & vsid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | switch (REGION_ID(ea)) { |
| 602 | case USER_REGION_ID: |
| 603 | user_region = 1; |
| 604 | mm = current->mm; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 605 | if (! mm) { |
| 606 | DBG_LOW(" user region with no mm !\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | return 1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | vsid = get_vsid(mm->context.id, ea); |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 610 | psize = mm->context.user_psize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | case VMALLOC_REGION_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | mm = &init_mm; |
| 614 | vsid = get_kernel_vsid(ea); |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 615 | if (ea < VMALLOC_END) |
| 616 | psize = mmu_vmalloc_psize; |
| 617 | else |
| 618 | psize = mmu_io_psize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | default: |
| 621 | /* Not a valid range |
| 622 | * Send the problem up to do_page_fault |
| 623 | */ |
| 624 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 626 | 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] | 627 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 628 | /* Get pgdir */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | pgdir = mm->pgd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (pgdir == NULL) |
| 631 | return 1; |
| 632 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 633 | /* Check CPU locality */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | tmp = cpumask_of_cpu(smp_processor_id()); |
| 635 | if (user_region && cpus_equal(mm->cpu_vm_mask, tmp)) |
| 636 | local = 1; |
| 637 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 638 | /* Handle hugepage regions */ |
| 639 | if (unlikely(in_hugepage_area(mm->context, ea))) { |
| 640 | DBG_LOW(" -> huge page !\n"); |
David Gibson | cbf52af | 2005-12-09 14:20:52 +1100 | [diff] [blame] | 641 | return hash_huge_page(mm, access, ea, vsid, local, trap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 644 | /* Get PTE and page size from page tables */ |
| 645 | ptep = find_linux_pte(pgdir, ea); |
| 646 | if (ptep == NULL || !pte_present(*ptep)) { |
| 647 | DBG_LOW(" no PTE !\n"); |
| 648 | return 1; |
| 649 | } |
| 650 | |
| 651 | #ifndef CONFIG_PPC_64K_PAGES |
| 652 | DBG_LOW(" i-pte: %016lx\n", pte_val(*ptep)); |
| 653 | #else |
| 654 | DBG_LOW(" i-pte: %016lx %016lx\n", pte_val(*ptep), |
| 655 | pte_val(*(ptep + PTRS_PER_PTE))); |
| 656 | #endif |
| 657 | /* Pre-check access permissions (will be re-checked atomically |
| 658 | * in __hash_page_XX but this pre-check is a fast path |
| 659 | */ |
| 660 | if (access & ~pte_val(*ptep)) { |
| 661 | DBG_LOW(" no access !\n"); |
| 662 | return 1; |
| 663 | } |
| 664 | |
| 665 | /* Do actual hashing */ |
| 666 | #ifndef CONFIG_PPC_64K_PAGES |
| 667 | rc = __hash_page_4K(ea, access, vsid, ptep, trap, local); |
| 668 | #else |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 669 | if (mmu_ci_restrictions) { |
| 670 | /* If this PTE is non-cacheable, switch to 4k */ |
| 671 | if (psize == MMU_PAGE_64K && |
| 672 | (pte_val(*ptep) & _PAGE_NO_CACHE)) { |
| 673 | if (user_region) { |
| 674 | psize = MMU_PAGE_4K; |
| 675 | mm->context.user_psize = MMU_PAGE_4K; |
| 676 | mm->context.sllp = SLB_VSID_USER | |
| 677 | mmu_psize_defs[MMU_PAGE_4K].sllp; |
| 678 | } else if (ea < VMALLOC_END) { |
| 679 | /* |
| 680 | * some driver did a non-cacheable mapping |
| 681 | * in vmalloc space, so switch vmalloc |
| 682 | * to 4k pages |
| 683 | */ |
| 684 | printk(KERN_ALERT "Reducing vmalloc segment " |
| 685 | "to 4kB pages because of " |
| 686 | "non-cacheable mapping\n"); |
| 687 | psize = mmu_vmalloc_psize = MMU_PAGE_4K; |
| 688 | } |
| 689 | } |
| 690 | if (user_region) { |
| 691 | if (psize != get_paca()->context.user_psize) { |
| 692 | get_paca()->context = mm->context; |
| 693 | slb_flush_and_rebolt(); |
| 694 | } |
| 695 | } else if (get_paca()->vmalloc_sllp != |
| 696 | mmu_psize_defs[mmu_vmalloc_psize].sllp) { |
| 697 | get_paca()->vmalloc_sllp = |
| 698 | mmu_psize_defs[mmu_vmalloc_psize].sllp; |
| 699 | slb_flush_and_rebolt(); |
| 700 | } |
| 701 | } |
| 702 | if (psize == MMU_PAGE_64K) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 703 | rc = __hash_page_64K(ea, access, vsid, ptep, trap, local); |
| 704 | else |
| 705 | rc = __hash_page_4K(ea, access, vsid, ptep, trap, local); |
| 706 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 707 | |
| 708 | #ifndef CONFIG_PPC_64K_PAGES |
| 709 | DBG_LOW(" o-pte: %016lx\n", pte_val(*ptep)); |
| 710 | #else |
| 711 | DBG_LOW(" o-pte: %016lx %016lx\n", pte_val(*ptep), |
| 712 | pte_val(*(ptep + PTRS_PER_PTE))); |
| 713 | #endif |
| 714 | DBG_LOW(" -> rc=%d\n", rc); |
| 715 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 717 | EXPORT_SYMBOL_GPL(hash_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 719 | void hash_preload(struct mm_struct *mm, unsigned long ea, |
| 720 | unsigned long access, unsigned long trap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 722 | unsigned long vsid; |
| 723 | void *pgdir; |
| 724 | pte_t *ptep; |
| 725 | cpumask_t mask; |
| 726 | unsigned long flags; |
| 727 | int local = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 729 | /* We don't want huge pages prefaulted for now |
| 730 | */ |
| 731 | if (unlikely(in_hugepage_area(mm->context, ea))) |
| 732 | return; |
| 733 | |
| 734 | DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx," |
| 735 | " trap=%lx\n", mm, mm->pgd, ea, access, trap); |
| 736 | |
| 737 | /* Get PTE, VSID, access mask */ |
| 738 | pgdir = mm->pgd; |
| 739 | if (pgdir == NULL) |
| 740 | return; |
| 741 | ptep = find_linux_pte(pgdir, ea); |
| 742 | if (!ptep) |
| 743 | return; |
| 744 | vsid = get_vsid(mm->context.id, ea); |
| 745 | |
| 746 | /* Hash it in */ |
| 747 | local_irq_save(flags); |
| 748 | mask = cpumask_of_cpu(smp_processor_id()); |
| 749 | if (cpus_equal(mm->cpu_vm_mask, mask)) |
| 750 | local = 1; |
| 751 | #ifndef CONFIG_PPC_64K_PAGES |
| 752 | __hash_page_4K(ea, access, vsid, ptep, trap, local); |
| 753 | #else |
Paul Mackerras | bf72aeb | 2006-06-15 10:45:18 +1000 | [diff] [blame] | 754 | if (mmu_ci_restrictions) { |
| 755 | /* If this PTE is non-cacheable, switch to 4k */ |
| 756 | if (mm->context.user_psize == MMU_PAGE_64K && |
| 757 | (pte_val(*ptep) & _PAGE_NO_CACHE)) { |
| 758 | mm->context.user_psize = MMU_PAGE_4K; |
| 759 | mm->context.sllp = SLB_VSID_USER | |
| 760 | mmu_psize_defs[MMU_PAGE_4K].sllp; |
| 761 | get_paca()->context = mm->context; |
| 762 | slb_flush_and_rebolt(); |
| 763 | } |
| 764 | } |
| 765 | if (mm->context.user_psize == MMU_PAGE_64K) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 766 | __hash_page_64K(ea, access, vsid, ptep, trap, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | else |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 768 | __hash_page_4K(ea, access, vsid, ptep, trap, local); |
| 769 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 770 | local_irq_restore(flags); |
| 771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 773 | void flush_hash_page(unsigned long va, real_pte_t pte, int psize, int local) |
| 774 | { |
| 775 | unsigned long hash, index, shift, hidx, slot; |
| 776 | |
| 777 | DBG_LOW("flush_hash_page(va=%016x)\n", va); |
| 778 | pte_iterate_hashed_subpages(pte, psize, va, index, shift) { |
| 779 | hash = hpt_hash(va, shift); |
| 780 | hidx = __rpte_to_hidx(pte, index); |
| 781 | if (hidx & _PTEIDX_SECONDARY) |
| 782 | hash = ~hash; |
| 783 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 784 | slot += hidx & _PTEIDX_GROUP_IX; |
| 785 | DBG_LOW(" sub %d: hash=%x, hidx=%x\n", index, slot, hidx); |
| 786 | ppc_md.hpte_invalidate(slot, va, psize, local); |
| 787 | } pte_iterate_hashed_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 790 | void flush_hash_range(unsigned long number, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 792 | if (ppc_md.flush_hash_range) |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 793 | ppc_md.flush_hash_range(number, local); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 794 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | int i; |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 796 | struct ppc64_tlb_batch *batch = |
| 797 | &__get_cpu_var(ppc64_tlb_batch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | for (i = 0; i < number; i++) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 800 | flush_hash_page(batch->vaddr[i], batch->pte[i], |
| 801 | batch->psize, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | /* |
| 806 | * low_hash_fault is called when we the low level hash code failed |
| 807 | * to instert a PTE due to an hypervisor error |
| 808 | */ |
| 809 | void low_hash_fault(struct pt_regs *regs, unsigned long address) |
| 810 | { |
| 811 | if (user_mode(regs)) { |
| 812 | siginfo_t info; |
| 813 | |
| 814 | info.si_signo = SIGBUS; |
| 815 | info.si_errno = 0; |
| 816 | info.si_code = BUS_ADRERR; |
| 817 | info.si_addr = (void __user *)address; |
| 818 | force_sig_info(SIGBUS, &info, current); |
| 819 | return; |
| 820 | } |
| 821 | bad_page_fault(regs, address, SIGBUS); |
| 822 | } |