hash_utils_64.c 31 KB

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