hash_utils_64.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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. #undef DEBUG
  21. #undef DEBUG_LOW
  22. #include <linux/spinlock.h>
  23. #include <linux/errno.h>
  24. #include <linux/sched.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/stat.h>
  27. #include <linux/sysctl.h>
  28. #include <linux/ctype.h>
  29. #include <linux/cache.h>
  30. #include <linux/init.h>
  31. #include <linux/signal.h>
  32. #include <linux/memblock.h>
  33. #include <asm/processor.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/mmu.h>
  36. #include <asm/mmu_context.h>
  37. #include <asm/page.h>
  38. #include <asm/types.h>
  39. #include <asm/system.h>
  40. #include <asm/uaccess.h>
  41. #include <asm/machdep.h>
  42. #include <asm/prom.h>
  43. #include <asm/abs_addr.h>
  44. #include <asm/tlbflush.h>
  45. #include <asm/io.h>
  46. #include <asm/eeh.h>
  47. #include <asm/tlb.h>
  48. #include <asm/cacheflush.h>
  49. #include <asm/cputable.h>
  50. #include <asm/sections.h>
  51. #include <asm/spu.h>
  52. #include <asm/udbg.h>
  53. #ifdef DEBUG
  54. #define DBG(fmt...) udbg_printf(fmt)
  55. #else
  56. #define DBG(fmt...)
  57. #endif
  58. #ifdef DEBUG_LOW
  59. #define DBG_LOW(fmt...) udbg_printf(fmt)
  60. #else
  61. #define DBG_LOW(fmt...)
  62. #endif
  63. #define KB (1024)
  64. #define MB (1024*KB)
  65. #define GB (1024L*MB)
  66. /*
  67. * Note: pte --> Linux PTE
  68. * HPTE --> PowerPC Hashed Page Table Entry
  69. *
  70. * Execution context:
  71. * htab_initialize is called with the MMU off (of course), but
  72. * the kernel has been copied down to zero so it can directly
  73. * reference global data. At this point it is very difficult
  74. * to print debug info.
  75. *
  76. */
  77. #ifdef CONFIG_U3_DART
  78. extern unsigned long dart_tablebase;
  79. #endif /* CONFIG_U3_DART */
  80. static unsigned long _SDR1;
  81. struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
  82. struct hash_pte *htab_address;
  83. unsigned long htab_size_bytes;
  84. unsigned long htab_hash_mask;
  85. EXPORT_SYMBOL_GPL(htab_hash_mask);
  86. int mmu_linear_psize = MMU_PAGE_4K;
  87. int mmu_virtual_psize = MMU_PAGE_4K;
  88. int mmu_vmalloc_psize = MMU_PAGE_4K;
  89. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  90. int mmu_vmemmap_psize = MMU_PAGE_4K;
  91. #endif
  92. int mmu_io_psize = MMU_PAGE_4K;
  93. int mmu_kernel_ssize = MMU_SEGSIZE_256M;
  94. int mmu_highuser_ssize = MMU_SEGSIZE_256M;
  95. u16 mmu_slb_size = 64;
  96. EXPORT_SYMBOL_GPL(mmu_slb_size);
  97. #ifdef CONFIG_HUGETLB_PAGE
  98. unsigned int HPAGE_SHIFT;
  99. #endif
  100. #ifdef CONFIG_PPC_64K_PAGES
  101. int mmu_ci_restrictions;
  102. #endif
  103. #ifdef CONFIG_DEBUG_PAGEALLOC
  104. static u8 *linear_map_hash_slots;
  105. static unsigned long linear_map_hash_count;
  106. static DEFINE_SPINLOCK(linear_map_hash_lock);
  107. #endif /* CONFIG_DEBUG_PAGEALLOC */
  108. /* There are definitions of page sizes arrays to be used when none
  109. * is provided by the firmware.
  110. */
  111. /* Pre-POWER4 CPUs (4k pages only)
  112. */
  113. static struct mmu_psize_def mmu_psize_defaults_old[] = {
  114. [MMU_PAGE_4K] = {
  115. .shift = 12,
  116. .sllp = 0,
  117. .penc = 0,
  118. .avpnm = 0,
  119. .tlbiel = 0,
  120. },
  121. };
  122. /* POWER4, GPUL, POWER5
  123. *
  124. * Support for 16Mb large pages
  125. */
  126. static struct mmu_psize_def mmu_psize_defaults_gp[] = {
  127. [MMU_PAGE_4K] = {
  128. .shift = 12,
  129. .sllp = 0,
  130. .penc = 0,
  131. .avpnm = 0,
  132. .tlbiel = 1,
  133. },
  134. [MMU_PAGE_16M] = {
  135. .shift = 24,
  136. .sllp = SLB_VSID_L,
  137. .penc = 0,
  138. .avpnm = 0x1UL,
  139. .tlbiel = 0,
  140. },
  141. };
  142. static unsigned long htab_convert_pte_flags(unsigned long pteflags)
  143. {
  144. unsigned long rflags = pteflags & 0x1fa;
  145. /* _PAGE_EXEC -> NOEXEC */
  146. if ((pteflags & _PAGE_EXEC) == 0)
  147. rflags |= HPTE_R_N;
  148. /* PP bits. PAGE_USER is already PP bit 0x2, so we only
  149. * need to add in 0x1 if it's a read-only user page
  150. */
  151. if ((pteflags & _PAGE_USER) && !((pteflags & _PAGE_RW) &&
  152. (pteflags & _PAGE_DIRTY)))
  153. rflags |= 1;
  154. /* Always add C */
  155. return rflags | HPTE_R_C;
  156. }
  157. int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
  158. unsigned long pstart, unsigned long prot,
  159. int psize, int ssize)
  160. {
  161. unsigned long vaddr, paddr;
  162. unsigned int step, shift;
  163. int ret = 0;
  164. shift = mmu_psize_defs[psize].shift;
  165. step = 1 << shift;
  166. prot = htab_convert_pte_flags(prot);
  167. DBG("htab_bolt_mapping(%lx..%lx -> %lx (%lx,%d,%d)\n",
  168. vstart, vend, pstart, prot, psize, ssize);
  169. for (vaddr = vstart, paddr = pstart; vaddr < vend;
  170. vaddr += step, paddr += step) {
  171. unsigned long hash, hpteg;
  172. unsigned long vsid = get_kernel_vsid(vaddr, ssize);
  173. unsigned long va = hpt_va(vaddr, vsid, ssize);
  174. unsigned long tprot = prot;
  175. /* Make kernel text executable */
  176. if (overlaps_kernel_text(vaddr, vaddr + step))
  177. tprot &= ~HPTE_R_N;
  178. hash = hpt_hash(va, shift, ssize);
  179. hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
  180. BUG_ON(!ppc_md.hpte_insert);
  181. ret = ppc_md.hpte_insert(hpteg, va, paddr, tprot,
  182. HPTE_V_BOLTED, psize, ssize);
  183. if (ret < 0)
  184. break;
  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 */
  189. }
  190. return ret < 0 ? ret : 0;
  191. }
  192. #ifdef CONFIG_MEMORY_HOTPLUG
  193. static int htab_remove_mapping(unsigned long vstart, unsigned long vend,
  194. int psize, int ssize)
  195. {
  196. unsigned long vaddr;
  197. unsigned int step, shift;
  198. shift = mmu_psize_defs[psize].shift;
  199. step = 1 << shift;
  200. if (!ppc_md.hpte_removebolted) {
  201. printk(KERN_WARNING "Platform doesn't implement "
  202. "hpte_removebolted\n");
  203. return -EINVAL;
  204. }
  205. for (vaddr = vstart; vaddr < vend; vaddr += step)
  206. ppc_md.hpte_removebolted(vaddr, psize, ssize);
  207. return 0;
  208. }
  209. #endif /* CONFIG_MEMORY_HOTPLUG */
  210. static int __init htab_dt_scan_seg_sizes(unsigned long node,
  211. const char *uname, int depth,
  212. void *data)
  213. {
  214. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  215. u32 *prop;
  216. unsigned long size = 0;
  217. /* We are scanning "cpu" nodes only */
  218. if (type == NULL || strcmp(type, "cpu") != 0)
  219. return 0;
  220. prop = (u32 *)of_get_flat_dt_prop(node, "ibm,processor-segment-sizes",
  221. &size);
  222. if (prop == NULL)
  223. return 0;
  224. for (; size >= 4; size -= 4, ++prop) {
  225. if (prop[0] == 40) {
  226. DBG("1T segment support detected\n");
  227. cur_cpu_spec->cpu_features |= CPU_FTR_1T_SEGMENT;
  228. return 1;
  229. }
  230. }
  231. cur_cpu_spec->cpu_features &= ~CPU_FTR_NO_SLBIE_B;
  232. return 0;
  233. }
  234. static void __init htab_init_seg_sizes(void)
  235. {
  236. of_scan_flat_dt(htab_dt_scan_seg_sizes, NULL);
  237. }
  238. static int __init htab_dt_scan_page_sizes(unsigned long node,
  239. const char *uname, int depth,
  240. void *data)
  241. {
  242. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  243. u32 *prop;
  244. unsigned long size = 0;
  245. /* We are scanning "cpu" nodes only */
  246. if (type == NULL || strcmp(type, "cpu") != 0)
  247. return 0;
  248. prop = (u32 *)of_get_flat_dt_prop(node,
  249. "ibm,segment-page-sizes", &size);
  250. if (prop != NULL) {
  251. DBG("Page sizes from device-tree:\n");
  252. size /= 4;
  253. cur_cpu_spec->cpu_features &= ~(CPU_FTR_16M_PAGE);
  254. while(size > 0) {
  255. unsigned int shift = prop[0];
  256. unsigned int slbenc = prop[1];
  257. unsigned int lpnum = prop[2];
  258. unsigned int lpenc = 0;
  259. struct mmu_psize_def *def;
  260. int idx = -1;
  261. size -= 3; prop += 3;
  262. while(size > 0 && lpnum) {
  263. if (prop[0] == shift)
  264. lpenc = prop[1];
  265. prop += 2; size -= 2;
  266. lpnum--;
  267. }
  268. switch(shift) {
  269. case 0xc:
  270. idx = MMU_PAGE_4K;
  271. break;
  272. case 0x10:
  273. idx = MMU_PAGE_64K;
  274. break;
  275. case 0x14:
  276. idx = MMU_PAGE_1M;
  277. break;
  278. case 0x18:
  279. idx = MMU_PAGE_16M;
  280. cur_cpu_spec->cpu_features |= CPU_FTR_16M_PAGE;
  281. break;
  282. case 0x22:
  283. idx = MMU_PAGE_16G;
  284. break;
  285. }
  286. if (idx < 0)
  287. continue;
  288. def = &mmu_psize_defs[idx];
  289. def->shift = shift;
  290. if (shift <= 23)
  291. def->avpnm = 0;
  292. else
  293. def->avpnm = (1 << (shift - 23)) - 1;
  294. def->sllp = slbenc;
  295. def->penc = lpenc;
  296. /* We don't know for sure what's up with tlbiel, so
  297. * for now we only set it for 4K and 64K pages
  298. */
  299. if (idx == MMU_PAGE_4K || idx == MMU_PAGE_64K)
  300. def->tlbiel = 1;
  301. else
  302. def->tlbiel = 0;
  303. DBG(" %d: shift=%02x, sllp=%04lx, avpnm=%08lx, "
  304. "tlbiel=%d, penc=%d\n",
  305. idx, shift, def->sllp, def->avpnm, def->tlbiel,
  306. def->penc);
  307. }
  308. return 1;
  309. }
  310. return 0;
  311. }
  312. #ifdef CONFIG_HUGETLB_PAGE
  313. /* Scan for 16G memory blocks that have been set aside for huge pages
  314. * and reserve those blocks for 16G huge pages.
  315. */
  316. static int __init htab_dt_scan_hugepage_blocks(unsigned long node,
  317. const char *uname, int depth,
  318. void *data) {
  319. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  320. unsigned long *addr_prop;
  321. u32 *page_count_prop;
  322. unsigned int expected_pages;
  323. long unsigned int phys_addr;
  324. long unsigned int block_size;
  325. /* We are scanning "memory" nodes only */
  326. if (type == NULL || strcmp(type, "memory") != 0)
  327. return 0;
  328. /* This property is the log base 2 of the number of virtual pages that
  329. * will represent this memory block. */
  330. page_count_prop = of_get_flat_dt_prop(node, "ibm,expected#pages", NULL);
  331. if (page_count_prop == NULL)
  332. return 0;
  333. expected_pages = (1 << page_count_prop[0]);
  334. addr_prop = of_get_flat_dt_prop(node, "reg", NULL);
  335. if (addr_prop == NULL)
  336. return 0;
  337. phys_addr = addr_prop[0];
  338. block_size = addr_prop[1];
  339. if (block_size != (16 * GB))
  340. return 0;
  341. printk(KERN_INFO "Huge page(16GB) memory: "
  342. "addr = 0x%lX size = 0x%lX pages = %d\n",
  343. phys_addr, block_size, expected_pages);
  344. if (phys_addr + (16 * GB) <= memblock_end_of_DRAM()) {
  345. memblock_reserve(phys_addr, block_size * expected_pages);
  346. add_gpage(phys_addr, block_size, expected_pages);
  347. }
  348. return 0;
  349. }
  350. #endif /* CONFIG_HUGETLB_PAGE */
  351. static void __init htab_init_page_sizes(void)
  352. {
  353. int rc;
  354. /* Default to 4K pages only */
  355. memcpy(mmu_psize_defs, mmu_psize_defaults_old,
  356. sizeof(mmu_psize_defaults_old));
  357. /*
  358. * Try to find the available page sizes in the device-tree
  359. */
  360. rc = of_scan_flat_dt(htab_dt_scan_page_sizes, NULL);
  361. if (rc != 0) /* Found */
  362. goto found;
  363. /*
  364. * Not in the device-tree, let's fallback on known size
  365. * list for 16M capable GP & GR
  366. */
  367. if (cpu_has_feature(CPU_FTR_16M_PAGE))
  368. memcpy(mmu_psize_defs, mmu_psize_defaults_gp,
  369. sizeof(mmu_psize_defaults_gp));
  370. found:
  371. #ifndef CONFIG_DEBUG_PAGEALLOC
  372. /*
  373. * Pick a size for the linear mapping. Currently, we only support
  374. * 16M, 1M and 4K which is the default
  375. */
  376. if (mmu_psize_defs[MMU_PAGE_16M].shift)
  377. mmu_linear_psize = MMU_PAGE_16M;
  378. else if (mmu_psize_defs[MMU_PAGE_1M].shift)
  379. mmu_linear_psize = MMU_PAGE_1M;
  380. #endif /* CONFIG_DEBUG_PAGEALLOC */
  381. #ifdef CONFIG_PPC_64K_PAGES
  382. /*
  383. * Pick a size for the ordinary pages. Default is 4K, we support
  384. * 64K for user mappings and vmalloc if supported by the processor.
  385. * We only use 64k for ioremap if the processor
  386. * (and firmware) support cache-inhibited large pages.
  387. * If not, we use 4k and set mmu_ci_restrictions so that
  388. * hash_page knows to switch processes that use cache-inhibited
  389. * mappings to 4k pages.
  390. */
  391. if (mmu_psize_defs[MMU_PAGE_64K].shift) {
  392. mmu_virtual_psize = MMU_PAGE_64K;
  393. mmu_vmalloc_psize = MMU_PAGE_64K;
  394. if (mmu_linear_psize == MMU_PAGE_4K)
  395. mmu_linear_psize = MMU_PAGE_64K;
  396. if (cpu_has_feature(CPU_FTR_CI_LARGE_PAGE)) {
  397. /*
  398. * Don't use 64k pages for ioremap on pSeries, since
  399. * that would stop us accessing the HEA ethernet.
  400. */
  401. if (!machine_is(pseries))
  402. mmu_io_psize = MMU_PAGE_64K;
  403. } else
  404. mmu_ci_restrictions = 1;
  405. }
  406. #endif /* CONFIG_PPC_64K_PAGES */
  407. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  408. /* We try to use 16M pages for vmemmap if that is supported
  409. * and we have at least 1G of RAM at boot
  410. */
  411. if (mmu_psize_defs[MMU_PAGE_16M].shift &&
  412. memblock_phys_mem_size() >= 0x40000000)
  413. mmu_vmemmap_psize = MMU_PAGE_16M;
  414. else if (mmu_psize_defs[MMU_PAGE_64K].shift)
  415. mmu_vmemmap_psize = MMU_PAGE_64K;
  416. else
  417. mmu_vmemmap_psize = MMU_PAGE_4K;
  418. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  419. printk(KERN_DEBUG "Page orders: linear mapping = %d, "
  420. "virtual = %d, io = %d"
  421. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  422. ", vmemmap = %d"
  423. #endif
  424. "\n",
  425. mmu_psize_defs[mmu_linear_psize].shift,
  426. mmu_psize_defs[mmu_virtual_psize].shift,
  427. mmu_psize_defs[mmu_io_psize].shift
  428. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  429. ,mmu_psize_defs[mmu_vmemmap_psize].shift
  430. #endif
  431. );
  432. #ifdef CONFIG_HUGETLB_PAGE
  433. /* Reserve 16G huge page memory sections for huge pages */
  434. of_scan_flat_dt(htab_dt_scan_hugepage_blocks, NULL);
  435. #endif /* CONFIG_HUGETLB_PAGE */
  436. }
  437. static int __init htab_dt_scan_pftsize(unsigned long node,
  438. const char *uname, int depth,
  439. void *data)
  440. {
  441. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  442. u32 *prop;
  443. /* We are scanning "cpu" nodes only */
  444. if (type == NULL || strcmp(type, "cpu") != 0)
  445. return 0;
  446. prop = (u32 *)of_get_flat_dt_prop(node, "ibm,pft-size", NULL);
  447. if (prop != NULL) {
  448. /* pft_size[0] is the NUMA CEC cookie */
  449. ppc64_pft_size = prop[1];
  450. return 1;
  451. }
  452. return 0;
  453. }
  454. static unsigned long __init htab_get_table_size(void)
  455. {
  456. unsigned long mem_size, rnd_mem_size, pteg_count, psize;
  457. /* If hash size isn't already provided by the platform, we try to
  458. * retrieve it from the device-tree. If it's not there neither, we
  459. * calculate it now based on the total RAM size
  460. */
  461. if (ppc64_pft_size == 0)
  462. of_scan_flat_dt(htab_dt_scan_pftsize, NULL);
  463. if (ppc64_pft_size)
  464. return 1UL << ppc64_pft_size;
  465. /* round mem_size up to next power of 2 */
  466. mem_size = memblock_phys_mem_size();
  467. rnd_mem_size = 1UL << __ilog2(mem_size);
  468. if (rnd_mem_size < mem_size)
  469. rnd_mem_size <<= 1;
  470. /* # pages / 2 */
  471. psize = mmu_psize_defs[mmu_virtual_psize].shift;
  472. pteg_count = max(rnd_mem_size >> (psize + 1), 1UL << 11);
  473. return pteg_count << 7;
  474. }
  475. #ifdef CONFIG_MEMORY_HOTPLUG
  476. void create_section_mapping(unsigned long start, unsigned long end)
  477. {
  478. BUG_ON(htab_bolt_mapping(start, end, __pa(start),
  479. pgprot_val(PAGE_KERNEL), mmu_linear_psize,
  480. mmu_kernel_ssize));
  481. }
  482. int remove_section_mapping(unsigned long start, unsigned long end)
  483. {
  484. return htab_remove_mapping(start, end, mmu_linear_psize,
  485. mmu_kernel_ssize);
  486. }
  487. #endif /* CONFIG_MEMORY_HOTPLUG */
  488. static inline void make_bl(unsigned int *insn_addr, void *func)
  489. {
  490. unsigned long funcp = *((unsigned long *)func);
  491. int offset = funcp - (unsigned long)insn_addr;
  492. *insn_addr = (unsigned int)(0x48000001 | (offset & 0x03fffffc));
  493. flush_icache_range((unsigned long)insn_addr, 4+
  494. (unsigned long)insn_addr);
  495. }
  496. static void __init htab_finish_init(void)
  497. {
  498. extern unsigned int *htab_call_hpte_insert1;
  499. extern unsigned int *htab_call_hpte_insert2;
  500. extern unsigned int *htab_call_hpte_remove;
  501. extern unsigned int *htab_call_hpte_updatepp;
  502. #ifdef CONFIG_PPC_HAS_HASH_64K
  503. extern unsigned int *ht64_call_hpte_insert1;
  504. extern unsigned int *ht64_call_hpte_insert2;
  505. extern unsigned int *ht64_call_hpte_remove;
  506. extern unsigned int *ht64_call_hpte_updatepp;
  507. make_bl(ht64_call_hpte_insert1, ppc_md.hpte_insert);
  508. make_bl(ht64_call_hpte_insert2, ppc_md.hpte_insert);
  509. make_bl(ht64_call_hpte_remove, ppc_md.hpte_remove);
  510. make_bl(ht64_call_hpte_updatepp, ppc_md.hpte_updatepp);
  511. #endif /* CONFIG_PPC_HAS_HASH_64K */
  512. make_bl(htab_call_hpte_insert1, ppc_md.hpte_insert);
  513. make_bl(htab_call_hpte_insert2, ppc_md.hpte_insert);
  514. make_bl(htab_call_hpte_remove, ppc_md.hpte_remove);
  515. make_bl(htab_call_hpte_updatepp, ppc_md.hpte_updatepp);
  516. }
  517. static void __init htab_initialize(void)
  518. {
  519. unsigned long table;
  520. unsigned long pteg_count;
  521. unsigned long prot;
  522. unsigned long base = 0, size = 0, limit;
  523. int i;
  524. DBG(" -> htab_initialize()\n");
  525. /* Initialize segment sizes */
  526. htab_init_seg_sizes();
  527. /* Initialize page sizes */
  528. htab_init_page_sizes();
  529. if (cpu_has_feature(CPU_FTR_1T_SEGMENT)) {
  530. mmu_kernel_ssize = MMU_SEGSIZE_1T;
  531. mmu_highuser_ssize = MMU_SEGSIZE_1T;
  532. printk(KERN_INFO "Using 1TB segments\n");
  533. }
  534. /*
  535. * Calculate the required size of the htab. We want the number of
  536. * PTEGs to equal one half the number of real pages.
  537. */
  538. htab_size_bytes = htab_get_table_size();
  539. pteg_count = htab_size_bytes >> 7;
  540. htab_hash_mask = pteg_count - 1;
  541. if (firmware_has_feature(FW_FEATURE_LPAR)) {
  542. /* Using a hypervisor which owns the htab */
  543. htab_address = NULL;
  544. _SDR1 = 0;
  545. } else {
  546. /* Find storage for the HPT. Must be contiguous in
  547. * the absolute address space. On cell we want it to be
  548. * in the first 2 Gig so we can use it for IOMMU hacks.
  549. */
  550. if (machine_is(cell))
  551. limit = 0x80000000;
  552. else
  553. limit = 0;
  554. table = memblock_alloc_base(htab_size_bytes, htab_size_bytes, limit);
  555. DBG("Hash table allocated at %lx, size: %lx\n", table,
  556. htab_size_bytes);
  557. htab_address = abs_to_virt(table);
  558. /* htab absolute addr + encoded htabsize */
  559. _SDR1 = table + __ilog2(pteg_count) - 11;
  560. /* Initialize the HPT with no entries */
  561. memset((void *)table, 0, htab_size_bytes);
  562. /* Set SDR1 */
  563. mtspr(SPRN_SDR1, _SDR1);
  564. }
  565. prot = pgprot_val(PAGE_KERNEL);
  566. #ifdef CONFIG_DEBUG_PAGEALLOC
  567. linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT;
  568. linear_map_hash_slots = __va(memblock_alloc_base(linear_map_hash_count,
  569. 1, memblock.rmo_size));
  570. memset(linear_map_hash_slots, 0, linear_map_hash_count);
  571. #endif /* CONFIG_DEBUG_PAGEALLOC */
  572. /* On U3 based machines, we need to reserve the DART area and
  573. * _NOT_ map it to avoid cache paradoxes as it's remapped non
  574. * cacheable later on
  575. */
  576. /* create bolted the linear mapping in the hash table */
  577. for (i=0; i < memblock.memory.cnt; i++) {
  578. base = (unsigned long)__va(memblock.memory.region[i].base);
  579. size = memblock.memory.region[i].size;
  580. DBG("creating mapping for region: %lx..%lx (prot: %lx)\n",
  581. base, size, prot);
  582. #ifdef CONFIG_U3_DART
  583. /* Do not map the DART space. Fortunately, it will be aligned
  584. * in such a way that it will not cross two memblock regions and
  585. * will fit within a single 16Mb page.
  586. * The DART space is assumed to be a full 16Mb region even if
  587. * we only use 2Mb of that space. We will use more of it later
  588. * for AGP GART. We have to use a full 16Mb large page.
  589. */
  590. DBG("DART base: %lx\n", dart_tablebase);
  591. if (dart_tablebase != 0 && dart_tablebase >= base
  592. && dart_tablebase < (base + size)) {
  593. unsigned long dart_table_end = dart_tablebase + 16 * MB;
  594. if (base != dart_tablebase)
  595. BUG_ON(htab_bolt_mapping(base, dart_tablebase,
  596. __pa(base), prot,
  597. mmu_linear_psize,
  598. mmu_kernel_ssize));
  599. if ((base + size) > dart_table_end)
  600. BUG_ON(htab_bolt_mapping(dart_tablebase+16*MB,
  601. base + size,
  602. __pa(dart_table_end),
  603. prot,
  604. mmu_linear_psize,
  605. mmu_kernel_ssize));
  606. continue;
  607. }
  608. #endif /* CONFIG_U3_DART */
  609. BUG_ON(htab_bolt_mapping(base, base + size, __pa(base),
  610. prot, mmu_linear_psize, mmu_kernel_ssize));
  611. }
  612. /*
  613. * If we have a memory_limit and we've allocated TCEs then we need to
  614. * explicitly map the TCE area at the top of RAM. We also cope with the
  615. * case that the TCEs start below memory_limit.
  616. * tce_alloc_start/end are 16MB aligned so the mapping should work
  617. * for either 4K or 16MB pages.
  618. */
  619. if (tce_alloc_start) {
  620. tce_alloc_start = (unsigned long)__va(tce_alloc_start);
  621. tce_alloc_end = (unsigned long)__va(tce_alloc_end);
  622. if (base + size >= tce_alloc_start)
  623. tce_alloc_start = base + size + 1;
  624. BUG_ON(htab_bolt_mapping(tce_alloc_start, tce_alloc_end,
  625. __pa(tce_alloc_start), prot,
  626. mmu_linear_psize, mmu_kernel_ssize));
  627. }
  628. htab_finish_init();
  629. DBG(" <- htab_initialize()\n");
  630. }
  631. #undef KB
  632. #undef MB
  633. void __init early_init_mmu(void)
  634. {
  635. /* Setup initial STAB address in the PACA */
  636. get_paca()->stab_real = __pa((u64)&initial_stab);
  637. get_paca()->stab_addr = (u64)&initial_stab;
  638. /* Initialize the MMU Hash table and create the linear mapping
  639. * of memory. Has to be done before stab/slb initialization as
  640. * this is currently where the page size encoding is obtained
  641. */
  642. htab_initialize();
  643. /* Initialize stab / SLB management except on iSeries
  644. */
  645. if (cpu_has_feature(CPU_FTR_SLB))
  646. slb_initialize();
  647. else if (!firmware_has_feature(FW_FEATURE_ISERIES))
  648. stab_initialize(get_paca()->stab_real);
  649. }
  650. #ifdef CONFIG_SMP
  651. void __cpuinit early_init_mmu_secondary(void)
  652. {
  653. /* Initialize hash table for that CPU */
  654. if (!firmware_has_feature(FW_FEATURE_LPAR))
  655. mtspr(SPRN_SDR1, _SDR1);
  656. /* Initialize STAB/SLB. We use a virtual address as it works
  657. * in real mode on pSeries and we want a virutal address on
  658. * iSeries anyway
  659. */
  660. if (cpu_has_feature(CPU_FTR_SLB))
  661. slb_initialize();
  662. else
  663. stab_initialize(get_paca()->stab_addr);
  664. }
  665. #endif /* CONFIG_SMP */
  666. /*
  667. * Called by asm hashtable.S for doing lazy icache flush
  668. */
  669. unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap)
  670. {
  671. struct page *page;
  672. if (!pfn_valid(pte_pfn(pte)))
  673. return pp;
  674. page = pte_page(pte);
  675. /* page is dirty */
  676. if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) {
  677. if (trap == 0x400) {
  678. flush_dcache_icache_page(page);
  679. set_bit(PG_arch_1, &page->flags);
  680. } else
  681. pp |= HPTE_R_N;
  682. }
  683. return pp;
  684. }
  685. #ifdef CONFIG_PPC_MM_SLICES
  686. unsigned int get_paca_psize(unsigned long addr)
  687. {
  688. unsigned long index, slices;
  689. if (addr < SLICE_LOW_TOP) {
  690. slices = get_paca()->context.low_slices_psize;
  691. index = GET_LOW_SLICE_INDEX(addr);
  692. } else {
  693. slices = get_paca()->context.high_slices_psize;
  694. index = GET_HIGH_SLICE_INDEX(addr);
  695. }
  696. return (slices >> (index * 4)) & 0xF;
  697. }
  698. #else
  699. unsigned int get_paca_psize(unsigned long addr)
  700. {
  701. return get_paca()->context.user_psize;
  702. }
  703. #endif
  704. /*
  705. * Demote a segment to using 4k pages.
  706. * For now this makes the whole process use 4k pages.
  707. */
  708. #ifdef CONFIG_PPC_64K_PAGES
  709. void demote_segment_4k(struct mm_struct *mm, unsigned long addr)
  710. {
  711. if (get_slice_psize(mm, addr) == MMU_PAGE_4K)
  712. return;
  713. slice_set_range_psize(mm, addr, 1, MMU_PAGE_4K);
  714. #ifdef CONFIG_SPU_BASE
  715. spu_flush_all_slbs(mm);
  716. #endif
  717. if (get_paca_psize(addr) != MMU_PAGE_4K) {
  718. get_paca()->context = mm->context;
  719. slb_flush_and_rebolt();
  720. }
  721. }
  722. #endif /* CONFIG_PPC_64K_PAGES */
  723. #ifdef CONFIG_PPC_SUBPAGE_PROT
  724. /*
  725. * This looks up a 2-bit protection code for a 4k subpage of a 64k page.
  726. * Userspace sets the subpage permissions using the subpage_prot system call.
  727. *
  728. * Result is 0: full permissions, _PAGE_RW: read-only,
  729. * _PAGE_USER or _PAGE_USER|_PAGE_RW: no access.
  730. */
  731. static int subpage_protection(struct mm_struct *mm, unsigned long ea)
  732. {
  733. struct subpage_prot_table *spt = &mm->context.spt;
  734. u32 spp = 0;
  735. u32 **sbpm, *sbpp;
  736. if (ea >= spt->maxaddr)
  737. return 0;
  738. if (ea < 0x100000000) {
  739. /* addresses below 4GB use spt->low_prot */
  740. sbpm = spt->low_prot;
  741. } else {
  742. sbpm = spt->protptrs[ea >> SBP_L3_SHIFT];
  743. if (!sbpm)
  744. return 0;
  745. }
  746. sbpp = sbpm[(ea >> SBP_L2_SHIFT) & (SBP_L2_COUNT - 1)];
  747. if (!sbpp)
  748. return 0;
  749. spp = sbpp[(ea >> PAGE_SHIFT) & (SBP_L1_COUNT - 1)];
  750. /* extract 2-bit bitfield for this 4k subpage */
  751. spp >>= 30 - 2 * ((ea >> 12) & 0xf);
  752. /* turn 0,1,2,3 into combination of _PAGE_USER and _PAGE_RW */
  753. spp = ((spp & 2) ? _PAGE_USER : 0) | ((spp & 1) ? _PAGE_RW : 0);
  754. return spp;
  755. }
  756. #else /* CONFIG_PPC_SUBPAGE_PROT */
  757. static inline int subpage_protection(struct mm_struct *mm, unsigned long ea)
  758. {
  759. return 0;
  760. }
  761. #endif
  762. void hash_failure_debug(unsigned long ea, unsigned long access,
  763. unsigned long vsid, unsigned long trap,
  764. int ssize, int psize, unsigned long pte)
  765. {
  766. if (!printk_ratelimit())
  767. return;
  768. pr_info("mm: Hashing failure ! EA=0x%lx access=0x%lx current=%s\n",
  769. ea, access, current->comm);
  770. pr_info(" trap=0x%lx vsid=0x%lx ssize=%d psize=%d pte=0x%lx\n",
  771. trap, vsid, ssize, psize, pte);
  772. }
  773. /* Result code is:
  774. * 0 - handled
  775. * 1 - normal page fault
  776. * -1 - critical hash insertion error
  777. * -2 - access not permitted by subpage protection mechanism
  778. */
  779. int hash_page(unsigned long ea, unsigned long access, unsigned long trap)
  780. {
  781. pgd_t *pgdir;
  782. unsigned long vsid;
  783. struct mm_struct *mm;
  784. pte_t *ptep;
  785. unsigned hugeshift;
  786. const struct cpumask *tmp;
  787. int rc, user_region = 0, local = 0;
  788. int psize, ssize;
  789. DBG_LOW("hash_page(ea=%016lx, access=%lx, trap=%lx\n",
  790. ea, access, trap);
  791. if ((ea & ~REGION_MASK) >= PGTABLE_RANGE) {
  792. DBG_LOW(" out of pgtable range !\n");
  793. return 1;
  794. }
  795. /* Get region & vsid */
  796. switch (REGION_ID(ea)) {
  797. case USER_REGION_ID:
  798. user_region = 1;
  799. mm = current->mm;
  800. if (! mm) {
  801. DBG_LOW(" user region with no mm !\n");
  802. return 1;
  803. }
  804. psize = get_slice_psize(mm, ea);
  805. ssize = user_segment_size(ea);
  806. vsid = get_vsid(mm->context.id, ea, ssize);
  807. break;
  808. case VMALLOC_REGION_ID:
  809. mm = &init_mm;
  810. vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
  811. if (ea < VMALLOC_END)
  812. psize = mmu_vmalloc_psize;
  813. else
  814. psize = mmu_io_psize;
  815. ssize = mmu_kernel_ssize;
  816. break;
  817. default:
  818. /* Not a valid range
  819. * Send the problem up to do_page_fault
  820. */
  821. return 1;
  822. }
  823. DBG_LOW(" mm=%p, mm->pgdir=%p, vsid=%016lx\n", mm, mm->pgd, vsid);
  824. /* Get pgdir */
  825. pgdir = mm->pgd;
  826. if (pgdir == NULL)
  827. return 1;
  828. /* Check CPU locality */
  829. tmp = cpumask_of(smp_processor_id());
  830. if (user_region && cpumask_equal(mm_cpumask(mm), tmp))
  831. local = 1;
  832. #ifndef CONFIG_PPC_64K_PAGES
  833. /* If we use 4K pages and our psize is not 4K, then we might
  834. * be hitting a special driver mapping, and need to align the
  835. * address before we fetch the PTE.
  836. *
  837. * It could also be a hugepage mapping, in which case this is
  838. * not necessary, but it's not harmful, either.
  839. */
  840. if (psize != MMU_PAGE_4K)
  841. ea &= ~((1ul << mmu_psize_defs[psize].shift) - 1);
  842. #endif /* CONFIG_PPC_64K_PAGES */
  843. /* Get PTE and page size from page tables */
  844. ptep = find_linux_pte_or_hugepte(pgdir, ea, &hugeshift);
  845. if (ptep == NULL || !pte_present(*ptep)) {
  846. DBG_LOW(" no PTE !\n");
  847. return 1;
  848. }
  849. /* Add _PAGE_PRESENT to the required access perm */
  850. access |= _PAGE_PRESENT;
  851. /* Pre-check access permissions (will be re-checked atomically
  852. * in __hash_page_XX but this pre-check is a fast path
  853. */
  854. if (access & ~pte_val(*ptep)) {
  855. DBG_LOW(" no access !\n");
  856. return 1;
  857. }
  858. #ifdef CONFIG_HUGETLB_PAGE
  859. if (hugeshift)
  860. return __hash_page_huge(ea, access, vsid, ptep, trap, local,
  861. ssize, hugeshift, psize);
  862. #endif /* CONFIG_HUGETLB_PAGE */
  863. #ifndef CONFIG_PPC_64K_PAGES
  864. DBG_LOW(" i-pte: %016lx\n", pte_val(*ptep));
  865. #else
  866. DBG_LOW(" i-pte: %016lx %016lx\n", pte_val(*ptep),
  867. pte_val(*(ptep + PTRS_PER_PTE)));
  868. #endif
  869. /* Do actual hashing */
  870. #ifdef CONFIG_PPC_64K_PAGES
  871. /* If _PAGE_4K_PFN is set, make sure this is a 4k segment */
  872. if ((pte_val(*ptep) & _PAGE_4K_PFN) && psize == MMU_PAGE_64K) {
  873. demote_segment_4k(mm, ea);
  874. psize = MMU_PAGE_4K;
  875. }
  876. /* If this PTE is non-cacheable and we have restrictions on
  877. * using non cacheable large pages, then we switch to 4k
  878. */
  879. if (mmu_ci_restrictions && psize == MMU_PAGE_64K &&
  880. (pte_val(*ptep) & _PAGE_NO_CACHE)) {
  881. if (user_region) {
  882. demote_segment_4k(mm, ea);
  883. psize = MMU_PAGE_4K;
  884. } else if (ea < VMALLOC_END) {
  885. /*
  886. * some driver did a non-cacheable mapping
  887. * in vmalloc space, so switch vmalloc
  888. * to 4k pages
  889. */
  890. printk(KERN_ALERT "Reducing vmalloc segment "
  891. "to 4kB pages because of "
  892. "non-cacheable mapping\n");
  893. psize = mmu_vmalloc_psize = MMU_PAGE_4K;
  894. #ifdef CONFIG_SPU_BASE
  895. spu_flush_all_slbs(mm);
  896. #endif
  897. }
  898. }
  899. if (user_region) {
  900. if (psize != get_paca_psize(ea)) {
  901. get_paca()->context = mm->context;
  902. slb_flush_and_rebolt();
  903. }
  904. } else if (get_paca()->vmalloc_sllp !=
  905. mmu_psize_defs[mmu_vmalloc_psize].sllp) {
  906. get_paca()->vmalloc_sllp =
  907. mmu_psize_defs[mmu_vmalloc_psize].sllp;
  908. slb_vmalloc_update();
  909. }
  910. #endif /* CONFIG_PPC_64K_PAGES */
  911. #ifdef CONFIG_PPC_HAS_HASH_64K
  912. if (psize == MMU_PAGE_64K)
  913. rc = __hash_page_64K(ea, access, vsid, ptep, trap, local, ssize);
  914. else
  915. #endif /* CONFIG_PPC_HAS_HASH_64K */
  916. {
  917. int spp = subpage_protection(mm, ea);
  918. if (access & spp)
  919. rc = -2;
  920. else
  921. rc = __hash_page_4K(ea, access, vsid, ptep, trap,
  922. local, ssize, spp);
  923. }
  924. /* Dump some info in case of hash insertion failure, they should
  925. * never happen so it is really useful to know if/when they do
  926. */
  927. if (rc == -1)
  928. hash_failure_debug(ea, access, vsid, trap, ssize, psize,
  929. pte_val(*ptep));
  930. #ifndef CONFIG_PPC_64K_PAGES
  931. DBG_LOW(" o-pte: %016lx\n", pte_val(*ptep));
  932. #else
  933. DBG_LOW(" o-pte: %016lx %016lx\n", pte_val(*ptep),
  934. pte_val(*(ptep + PTRS_PER_PTE)));
  935. #endif
  936. DBG_LOW(" -> rc=%d\n", rc);
  937. return rc;
  938. }
  939. EXPORT_SYMBOL_GPL(hash_page);
  940. void hash_preload(struct mm_struct *mm, unsigned long ea,
  941. unsigned long access, unsigned long trap)
  942. {
  943. unsigned long vsid;
  944. void *pgdir;
  945. pte_t *ptep;
  946. unsigned long flags;
  947. int rc, ssize, local = 0;
  948. BUG_ON(REGION_ID(ea) != USER_REGION_ID);
  949. #ifdef CONFIG_PPC_MM_SLICES
  950. /* We only prefault standard pages for now */
  951. if (unlikely(get_slice_psize(mm, ea) != mm->context.user_psize))
  952. return;
  953. #endif
  954. DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx,"
  955. " trap=%lx\n", mm, mm->pgd, ea, access, trap);
  956. /* Get Linux PTE if available */
  957. pgdir = mm->pgd;
  958. if (pgdir == NULL)
  959. return;
  960. ptep = find_linux_pte(pgdir, ea);
  961. if (!ptep)
  962. return;
  963. #ifdef CONFIG_PPC_64K_PAGES
  964. /* If either _PAGE_4K_PFN or _PAGE_NO_CACHE is set (and we are on
  965. * a 64K kernel), then we don't preload, hash_page() will take
  966. * care of it once we actually try to access the page.
  967. * That way we don't have to duplicate all of the logic for segment
  968. * page size demotion here
  969. */
  970. if (pte_val(*ptep) & (_PAGE_4K_PFN | _PAGE_NO_CACHE))
  971. return;
  972. #endif /* CONFIG_PPC_64K_PAGES */
  973. /* Get VSID */
  974. ssize = user_segment_size(ea);
  975. vsid = get_vsid(mm->context.id, ea, ssize);
  976. /* Hash doesn't like irqs */
  977. local_irq_save(flags);
  978. /* Is that local to this CPU ? */
  979. if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id())))
  980. local = 1;
  981. /* Hash it in */
  982. #ifdef CONFIG_PPC_HAS_HASH_64K
  983. if (mm->context.user_psize == MMU_PAGE_64K)
  984. rc = __hash_page_64K(ea, access, vsid, ptep, trap, local, ssize);
  985. else
  986. #endif /* CONFIG_PPC_HAS_HASH_64K */
  987. rc = __hash_page_4K(ea, access, vsid, ptep, trap, local, ssize,
  988. subpage_protection(pgdir, ea));
  989. /* Dump some info in case of hash insertion failure, they should
  990. * never happen so it is really useful to know if/when they do
  991. */
  992. if (rc == -1)
  993. hash_failure_debug(ea, access, vsid, trap, ssize,
  994. mm->context.user_psize, pte_val(*ptep));
  995. local_irq_restore(flags);
  996. }
  997. /* WARNING: This is called from hash_low_64.S, if you change this prototype,
  998. * do not forget to update the assembly call site !
  999. */
  1000. void flush_hash_page(unsigned long va, real_pte_t pte, int psize, int ssize,
  1001. int local)
  1002. {
  1003. unsigned long hash, index, shift, hidx, slot;
  1004. DBG_LOW("flush_hash_page(va=%016lx)\n", va);
  1005. pte_iterate_hashed_subpages(pte, psize, va, index, shift) {
  1006. hash = hpt_hash(va, shift, ssize);
  1007. hidx = __rpte_to_hidx(pte, index);
  1008. if (hidx & _PTEIDX_SECONDARY)
  1009. hash = ~hash;
  1010. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  1011. slot += hidx & _PTEIDX_GROUP_IX;
  1012. DBG_LOW(" sub %ld: hash=%lx, hidx=%lx\n", index, slot, hidx);
  1013. ppc_md.hpte_invalidate(slot, va, psize, ssize, local);
  1014. } pte_iterate_hashed_end();
  1015. }
  1016. void flush_hash_range(unsigned long number, int local)
  1017. {
  1018. if (ppc_md.flush_hash_range)
  1019. ppc_md.flush_hash_range(number, local);
  1020. else {
  1021. int i;
  1022. struct ppc64_tlb_batch *batch =
  1023. &__get_cpu_var(ppc64_tlb_batch);
  1024. for (i = 0; i < number; i++)
  1025. flush_hash_page(batch->vaddr[i], batch->pte[i],
  1026. batch->psize, batch->ssize, local);
  1027. }
  1028. }
  1029. /*
  1030. * low_hash_fault is called when we the low level hash code failed
  1031. * to instert a PTE due to an hypervisor error
  1032. */
  1033. void low_hash_fault(struct pt_regs *regs, unsigned long address, int rc)
  1034. {
  1035. if (user_mode(regs)) {
  1036. #ifdef CONFIG_PPC_SUBPAGE_PROT
  1037. if (rc == -2)
  1038. _exception(SIGSEGV, regs, SEGV_ACCERR, address);
  1039. else
  1040. #endif
  1041. _exception(SIGBUS, regs, BUS_ADRERR, address);
  1042. } else
  1043. bad_page_fault(regs, address, SIGBUS);
  1044. }
  1045. #ifdef CONFIG_DEBUG_PAGEALLOC
  1046. static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi)
  1047. {
  1048. unsigned long hash, hpteg;
  1049. unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize);
  1050. unsigned long va = hpt_va(vaddr, vsid, mmu_kernel_ssize);
  1051. unsigned long mode = htab_convert_pte_flags(PAGE_KERNEL);
  1052. int ret;
  1053. hash = hpt_hash(va, PAGE_SHIFT, mmu_kernel_ssize);
  1054. hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
  1055. ret = ppc_md.hpte_insert(hpteg, va, __pa(vaddr),
  1056. mode, HPTE_V_BOLTED,
  1057. mmu_linear_psize, mmu_kernel_ssize);
  1058. BUG_ON (ret < 0);
  1059. spin_lock(&linear_map_hash_lock);
  1060. BUG_ON(linear_map_hash_slots[lmi] & 0x80);
  1061. linear_map_hash_slots[lmi] = ret | 0x80;
  1062. spin_unlock(&linear_map_hash_lock);
  1063. }
  1064. static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi)
  1065. {
  1066. unsigned long hash, hidx, slot;
  1067. unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize);
  1068. unsigned long va = hpt_va(vaddr, vsid, mmu_kernel_ssize);
  1069. hash = hpt_hash(va, PAGE_SHIFT, mmu_kernel_ssize);
  1070. spin_lock(&linear_map_hash_lock);
  1071. BUG_ON(!(linear_map_hash_slots[lmi] & 0x80));
  1072. hidx = linear_map_hash_slots[lmi] & 0x7f;
  1073. linear_map_hash_slots[lmi] = 0;
  1074. spin_unlock(&linear_map_hash_lock);
  1075. if (hidx & _PTEIDX_SECONDARY)
  1076. hash = ~hash;
  1077. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  1078. slot += hidx & _PTEIDX_GROUP_IX;
  1079. ppc_md.hpte_invalidate(slot, va, mmu_linear_psize, mmu_kernel_ssize, 0);
  1080. }
  1081. void kernel_map_pages(struct page *page, int numpages, int enable)
  1082. {
  1083. unsigned long flags, vaddr, lmi;
  1084. int i;
  1085. local_irq_save(flags);
  1086. for (i = 0; i < numpages; i++, page++) {
  1087. vaddr = (unsigned long)page_address(page);
  1088. lmi = __pa(vaddr) >> PAGE_SHIFT;
  1089. if (lmi >= linear_map_hash_count)
  1090. continue;
  1091. if (enable)
  1092. kernel_map_linear_page(vaddr, lmi);
  1093. else
  1094. kernel_unmap_linear_page(vaddr, lmi);
  1095. }
  1096. local_irq_restore(flags);
  1097. }
  1098. #endif /* CONFIG_DEBUG_PAGEALLOC */