hash_utils_64.c 31 KB

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