hash_utils_64.c 31 KB

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