hash_utils_64.c 31 KB

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