hash_utils_64.c 31 KB

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