hash_utils_64.c 31 KB

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