hash_utils_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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/config.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/errno.h>
  25. #include <linux/sched.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/stat.h>
  28. #include <linux/sysctl.h>
  29. #include <linux/ctype.h>
  30. #include <linux/cache.h>
  31. #include <linux/init.h>
  32. #include <linux/signal.h>
  33. #include <asm/ppcdebug.h>
  34. #include <asm/processor.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/mmu.h>
  37. #include <asm/mmu_context.h>
  38. #include <asm/page.h>
  39. #include <asm/types.h>
  40. #include <asm/system.h>
  41. #include <asm/uaccess.h>
  42. #include <asm/machdep.h>
  43. #include <asm/lmb.h>
  44. #include <asm/abs_addr.h>
  45. #include <asm/tlbflush.h>
  46. #include <asm/io.h>
  47. #include <asm/eeh.h>
  48. #include <asm/tlb.h>
  49. #include <asm/cacheflush.h>
  50. #include <asm/cputable.h>
  51. #include <asm/abs_addr.h>
  52. #include <asm/sections.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. /*
  66. * Note: pte --> Linux PTE
  67. * HPTE --> PowerPC Hashed Page Table Entry
  68. *
  69. * Execution context:
  70. * htab_initialize is called with the MMU off (of course), but
  71. * the kernel has been copied down to zero so it can directly
  72. * reference global data. At this point it is very difficult
  73. * to print debug info.
  74. *
  75. */
  76. #ifdef CONFIG_U3_DART
  77. extern unsigned long dart_tablebase;
  78. #endif /* CONFIG_U3_DART */
  79. hpte_t *htab_address;
  80. unsigned long htab_hash_mask;
  81. unsigned long _SDR1;
  82. struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
  83. int mmu_linear_psize = MMU_PAGE_4K;
  84. int mmu_virtual_psize = MMU_PAGE_4K;
  85. #ifdef CONFIG_HUGETLB_PAGE
  86. int mmu_huge_psize = MMU_PAGE_16M;
  87. unsigned int HPAGE_SHIFT;
  88. #endif
  89. /* There are definitions of page sizes arrays to be used when none
  90. * is provided by the firmware.
  91. */
  92. /* Pre-POWER4 CPUs (4k pages only)
  93. */
  94. struct mmu_psize_def mmu_psize_defaults_old[] = {
  95. [MMU_PAGE_4K] = {
  96. .shift = 12,
  97. .sllp = 0,
  98. .penc = 0,
  99. .avpnm = 0,
  100. .tlbiel = 0,
  101. },
  102. };
  103. /* POWER4, GPUL, POWER5
  104. *
  105. * Support for 16Mb large pages
  106. */
  107. struct mmu_psize_def mmu_psize_defaults_gp[] = {
  108. [MMU_PAGE_4K] = {
  109. .shift = 12,
  110. .sllp = 0,
  111. .penc = 0,
  112. .avpnm = 0,
  113. .tlbiel = 1,
  114. },
  115. [MMU_PAGE_16M] = {
  116. .shift = 24,
  117. .sllp = SLB_VSID_L,
  118. .penc = 0,
  119. .avpnm = 0x1UL,
  120. .tlbiel = 0,
  121. },
  122. };
  123. int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
  124. unsigned long pstart, unsigned long mode, int psize)
  125. {
  126. unsigned long vaddr, paddr;
  127. unsigned int step, shift;
  128. unsigned long tmp_mode;
  129. int ret = 0;
  130. shift = mmu_psize_defs[psize].shift;
  131. step = 1 << shift;
  132. for (vaddr = vstart, paddr = pstart; vaddr < vend;
  133. vaddr += step, paddr += step) {
  134. unsigned long vpn, hash, hpteg;
  135. unsigned long vsid = get_kernel_vsid(vaddr);
  136. unsigned long va = (vsid << 28) | (vaddr & 0x0fffffff);
  137. vpn = va >> shift;
  138. tmp_mode = mode;
  139. /* Make non-kernel text non-executable */
  140. if (!in_kernel_text(vaddr))
  141. tmp_mode = mode | HPTE_R_N;
  142. hash = hpt_hash(va, shift);
  143. hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
  144. /* The crap below can be cleaned once ppd_md.probe() can
  145. * set up the hash callbacks, thus we can just used the
  146. * normal insert callback here.
  147. */
  148. #ifdef CONFIG_PPC_ISERIES
  149. if (systemcfg->platform == PLATFORM_ISERIES_LPAR)
  150. ret = iSeries_hpte_insert(hpteg, va,
  151. virt_to_abs(paddr),
  152. tmp_mode,
  153. HPTE_V_BOLTED,
  154. psize);
  155. else
  156. #endif
  157. #ifdef CONFIG_PPC_PSERIES
  158. if (systemcfg->platform & PLATFORM_LPAR)
  159. ret = pSeries_lpar_hpte_insert(hpteg, va,
  160. virt_to_abs(paddr),
  161. tmp_mode,
  162. HPTE_V_BOLTED,
  163. psize);
  164. else
  165. #endif
  166. #ifdef CONFIG_PPC_MULTIPLATFORM
  167. ret = native_hpte_insert(hpteg, va,
  168. virt_to_abs(paddr),
  169. tmp_mode, HPTE_V_BOLTED,
  170. psize);
  171. #endif
  172. if (ret < 0)
  173. break;
  174. }
  175. return ret < 0 ? ret : 0;
  176. }
  177. static int __init htab_dt_scan_page_sizes(unsigned long node,
  178. const char *uname, int depth,
  179. void *data)
  180. {
  181. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  182. u32 *prop;
  183. unsigned long size = 0;
  184. /* We are scanning "cpu" nodes only */
  185. if (type == NULL || strcmp(type, "cpu") != 0)
  186. return 0;
  187. prop = (u32 *)of_get_flat_dt_prop(node,
  188. "ibm,segment-page-sizes", &size);
  189. if (prop != NULL) {
  190. DBG("Page sizes from device-tree:\n");
  191. size /= 4;
  192. cur_cpu_spec->cpu_features &= ~(CPU_FTR_16M_PAGE);
  193. while(size > 0) {
  194. unsigned int shift = prop[0];
  195. unsigned int slbenc = prop[1];
  196. unsigned int lpnum = prop[2];
  197. unsigned int lpenc = 0;
  198. struct mmu_psize_def *def;
  199. int idx = -1;
  200. size -= 3; prop += 3;
  201. while(size > 0 && lpnum) {
  202. if (prop[0] == shift)
  203. lpenc = prop[1];
  204. prop += 2; size -= 2;
  205. lpnum--;
  206. }
  207. switch(shift) {
  208. case 0xc:
  209. idx = MMU_PAGE_4K;
  210. break;
  211. case 0x10:
  212. idx = MMU_PAGE_64K;
  213. break;
  214. case 0x14:
  215. idx = MMU_PAGE_1M;
  216. break;
  217. case 0x18:
  218. idx = MMU_PAGE_16M;
  219. cur_cpu_spec->cpu_features |= CPU_FTR_16M_PAGE;
  220. break;
  221. case 0x22:
  222. idx = MMU_PAGE_16G;
  223. break;
  224. }
  225. if (idx < 0)
  226. continue;
  227. def = &mmu_psize_defs[idx];
  228. def->shift = shift;
  229. if (shift <= 23)
  230. def->avpnm = 0;
  231. else
  232. def->avpnm = (1 << (shift - 23)) - 1;
  233. def->sllp = slbenc;
  234. def->penc = lpenc;
  235. /* We don't know for sure what's up with tlbiel, so
  236. * for now we only set it for 4K and 64K pages
  237. */
  238. if (idx == MMU_PAGE_4K || idx == MMU_PAGE_64K)
  239. def->tlbiel = 1;
  240. else
  241. def->tlbiel = 0;
  242. DBG(" %d: shift=%02x, sllp=%04x, avpnm=%08x, "
  243. "tlbiel=%d, penc=%d\n",
  244. idx, shift, def->sllp, def->avpnm, def->tlbiel,
  245. def->penc);
  246. }
  247. return 1;
  248. }
  249. return 0;
  250. }
  251. static void __init htab_init_page_sizes(void)
  252. {
  253. int rc;
  254. /* Default to 4K pages only */
  255. memcpy(mmu_psize_defs, mmu_psize_defaults_old,
  256. sizeof(mmu_psize_defaults_old));
  257. /*
  258. * Try to find the available page sizes in the device-tree
  259. */
  260. rc = of_scan_flat_dt(htab_dt_scan_page_sizes, NULL);
  261. if (rc != 0) /* Found */
  262. goto found;
  263. /*
  264. * Not in the device-tree, let's fallback on known size
  265. * list for 16M capable GP & GR
  266. */
  267. if ((systemcfg->platform != PLATFORM_ISERIES_LPAR) &&
  268. cpu_has_feature(CPU_FTR_16M_PAGE))
  269. memcpy(mmu_psize_defs, mmu_psize_defaults_gp,
  270. sizeof(mmu_psize_defaults_gp));
  271. found:
  272. /*
  273. * Pick a size for the linear mapping. Currently, we only support
  274. * 16M, 1M and 4K which is the default
  275. */
  276. if (mmu_psize_defs[MMU_PAGE_16M].shift)
  277. mmu_linear_psize = MMU_PAGE_16M;
  278. else if (mmu_psize_defs[MMU_PAGE_1M].shift)
  279. mmu_linear_psize = MMU_PAGE_1M;
  280. /*
  281. * Pick a size for the ordinary pages. Default is 4K, we support
  282. * 64K if cache inhibited large pages are supported by the
  283. * processor
  284. */
  285. #ifdef CONFIG_PPC_64K_PAGES
  286. if (mmu_psize_defs[MMU_PAGE_64K].shift &&
  287. cpu_has_feature(CPU_FTR_CI_LARGE_PAGE))
  288. mmu_virtual_psize = MMU_PAGE_64K;
  289. #endif
  290. printk(KERN_INFO "Page orders: linear mapping = %d, others = %d\n",
  291. mmu_psize_defs[mmu_linear_psize].shift,
  292. mmu_psize_defs[mmu_virtual_psize].shift);
  293. #ifdef CONFIG_HUGETLB_PAGE
  294. /* Init large page size. Currently, we pick 16M or 1M depending
  295. * on what is available
  296. */
  297. if (mmu_psize_defs[MMU_PAGE_16M].shift)
  298. mmu_huge_psize = MMU_PAGE_16M;
  299. /* With 4k/4level pagetables, we can't (for now) cope with a
  300. * huge page size < PMD_SIZE */
  301. else if (mmu_psize_defs[MMU_PAGE_1M].shift)
  302. mmu_huge_psize = MMU_PAGE_1M;
  303. /* Calculate HPAGE_SHIFT and sanity check it */
  304. if (mmu_psize_defs[mmu_huge_psize].shift > MIN_HUGEPTE_SHIFT &&
  305. mmu_psize_defs[mmu_huge_psize].shift < SID_SHIFT)
  306. HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift;
  307. else
  308. HPAGE_SHIFT = 0; /* No huge pages dude ! */
  309. #endif /* CONFIG_HUGETLB_PAGE */
  310. }
  311. static int __init htab_dt_scan_pftsize(unsigned long node,
  312. const char *uname, int depth,
  313. void *data)
  314. {
  315. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  316. u32 *prop;
  317. /* We are scanning "cpu" nodes only */
  318. if (type == NULL || strcmp(type, "cpu") != 0)
  319. return 0;
  320. prop = (u32 *)of_get_flat_dt_prop(node, "ibm,pft-size", NULL);
  321. if (prop != NULL) {
  322. /* pft_size[0] is the NUMA CEC cookie */
  323. ppc64_pft_size = prop[1];
  324. return 1;
  325. }
  326. return 0;
  327. }
  328. static unsigned long __init htab_get_table_size(void)
  329. {
  330. unsigned long rnd_mem_size, pteg_count;
  331. /* If hash size isn't already provided by the platform, we try to
  332. * retreive it from the device-tree. If it's not there neither, we
  333. * calculate it now based on the total RAM size
  334. */
  335. if (ppc64_pft_size == 0)
  336. of_scan_flat_dt(htab_dt_scan_pftsize, NULL);
  337. if (ppc64_pft_size)
  338. return 1UL << ppc64_pft_size;
  339. /* round mem_size up to next power of 2 */
  340. rnd_mem_size = 1UL << __ilog2(systemcfg->physicalMemorySize);
  341. if (rnd_mem_size < systemcfg->physicalMemorySize)
  342. rnd_mem_size <<= 1;
  343. /* # pages / 2 */
  344. pteg_count = max(rnd_mem_size >> (12 + 1), 1UL << 11);
  345. return pteg_count << 7;
  346. }
  347. void __init htab_initialize(void)
  348. {
  349. unsigned long table, htab_size_bytes;
  350. unsigned long pteg_count;
  351. unsigned long mode_rw;
  352. unsigned long base = 0, size = 0;
  353. int i;
  354. extern unsigned long tce_alloc_start, tce_alloc_end;
  355. DBG(" -> htab_initialize()\n");
  356. /* Initialize page sizes */
  357. htab_init_page_sizes();
  358. /*
  359. * Calculate the required size of the htab. We want the number of
  360. * PTEGs to equal one half the number of real pages.
  361. */
  362. htab_size_bytes = htab_get_table_size();
  363. pteg_count = htab_size_bytes >> 7;
  364. /* For debug, make the HTAB 1/8 as big as it normally would be. */
  365. ifppcdebug(PPCDBG_HTABSIZE) {
  366. pteg_count >>= 3;
  367. htab_size_bytes = pteg_count << 7;
  368. }
  369. htab_hash_mask = pteg_count - 1;
  370. if (systemcfg->platform & PLATFORM_LPAR) {
  371. /* Using a hypervisor which owns the htab */
  372. htab_address = NULL;
  373. _SDR1 = 0;
  374. } else {
  375. /* Find storage for the HPT. Must be contiguous in
  376. * the absolute address space.
  377. */
  378. table = lmb_alloc(htab_size_bytes, htab_size_bytes);
  379. BUG_ON(table == 0);
  380. DBG("Hash table allocated at %lx, size: %lx\n", table,
  381. htab_size_bytes);
  382. htab_address = abs_to_virt(table);
  383. /* htab absolute addr + encoded htabsize */
  384. _SDR1 = table + __ilog2(pteg_count) - 11;
  385. /* Initialize the HPT with no entries */
  386. memset((void *)table, 0, htab_size_bytes);
  387. }
  388. mode_rw = _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX;
  389. /* On U3 based machines, we need to reserve the DART area and
  390. * _NOT_ map it to avoid cache paradoxes as it's remapped non
  391. * cacheable later on
  392. */
  393. /* create bolted the linear mapping in the hash table */
  394. for (i=0; i < lmb.memory.cnt; i++) {
  395. base = lmb.memory.region[i].base + KERNELBASE;
  396. size = lmb.memory.region[i].size;
  397. DBG("creating mapping for region: %lx : %lx\n", base, size);
  398. #ifdef CONFIG_U3_DART
  399. /* Do not map the DART space. Fortunately, it will be aligned
  400. * in such a way that it will not cross two lmb regions and
  401. * will fit within a single 16Mb page.
  402. * The DART space is assumed to be a full 16Mb region even if
  403. * we only use 2Mb of that space. We will use more of it later
  404. * for AGP GART. We have to use a full 16Mb large page.
  405. */
  406. DBG("DART base: %lx\n", dart_tablebase);
  407. if (dart_tablebase != 0 && dart_tablebase >= base
  408. && dart_tablebase < (base + size)) {
  409. if (base != dart_tablebase)
  410. BUG_ON(htab_bolt_mapping(base, dart_tablebase,
  411. base, mode_rw,
  412. mmu_linear_psize));
  413. if ((base + size) > (dart_tablebase + 16*MB))
  414. BUG_ON(htab_bolt_mapping(dart_tablebase+16*MB,
  415. base + size,
  416. dart_tablebase+16*MB,
  417. mode_rw,
  418. mmu_linear_psize));
  419. continue;
  420. }
  421. #endif /* CONFIG_U3_DART */
  422. BUG_ON(htab_bolt_mapping(base, base + size, base,
  423. mode_rw, mmu_linear_psize));
  424. }
  425. /*
  426. * If we have a memory_limit and we've allocated TCEs then we need to
  427. * explicitly map the TCE area at the top of RAM. We also cope with the
  428. * case that the TCEs start below memory_limit.
  429. * tce_alloc_start/end are 16MB aligned so the mapping should work
  430. * for either 4K or 16MB pages.
  431. */
  432. if (tce_alloc_start) {
  433. tce_alloc_start += KERNELBASE;
  434. tce_alloc_end += KERNELBASE;
  435. if (base + size >= tce_alloc_start)
  436. tce_alloc_start = base + size + 1;
  437. BUG_ON(htab_bolt_mapping(tce_alloc_start, tce_alloc_end,
  438. tce_alloc_start, mode_rw,
  439. mmu_linear_psize));
  440. }
  441. DBG(" <- htab_initialize()\n");
  442. }
  443. #undef KB
  444. #undef MB
  445. /*
  446. * Called by asm hashtable.S for doing lazy icache flush
  447. */
  448. unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap)
  449. {
  450. struct page *page;
  451. page = pte_page(pte);
  452. /* page is dirty */
  453. if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) {
  454. if (trap == 0x400) {
  455. __flush_dcache_icache(page_address(page));
  456. set_bit(PG_arch_1, &page->flags);
  457. } else
  458. pp |= HPTE_R_N;
  459. }
  460. return pp;
  461. }
  462. /* Result code is:
  463. * 0 - handled
  464. * 1 - normal page fault
  465. * -1 - critical hash insertion error
  466. */
  467. int hash_page(unsigned long ea, unsigned long access, unsigned long trap)
  468. {
  469. void *pgdir;
  470. unsigned long vsid;
  471. struct mm_struct *mm;
  472. pte_t *ptep;
  473. cpumask_t tmp;
  474. int rc, user_region = 0, local = 0;
  475. DBG_LOW("hash_page(ea=%016lx, access=%lx, trap=%lx\n",
  476. ea, access, trap);
  477. if ((ea & ~REGION_MASK) >= PGTABLE_RANGE) {
  478. DBG_LOW(" out of pgtable range !\n");
  479. return 1;
  480. }
  481. /* Get region & vsid */
  482. switch (REGION_ID(ea)) {
  483. case USER_REGION_ID:
  484. user_region = 1;
  485. mm = current->mm;
  486. if (! mm) {
  487. DBG_LOW(" user region with no mm !\n");
  488. return 1;
  489. }
  490. vsid = get_vsid(mm->context.id, ea);
  491. break;
  492. case VMALLOC_REGION_ID:
  493. mm = &init_mm;
  494. vsid = get_kernel_vsid(ea);
  495. break;
  496. default:
  497. /* Not a valid range
  498. * Send the problem up to do_page_fault
  499. */
  500. return 1;
  501. }
  502. DBG_LOW(" mm=%p, mm->pgdir=%p, vsid=%016lx\n", mm, mm->pgd, vsid);
  503. /* Get pgdir */
  504. pgdir = mm->pgd;
  505. if (pgdir == NULL)
  506. return 1;
  507. /* Check CPU locality */
  508. tmp = cpumask_of_cpu(smp_processor_id());
  509. if (user_region && cpus_equal(mm->cpu_vm_mask, tmp))
  510. local = 1;
  511. /* Handle hugepage regions */
  512. if (unlikely(in_hugepage_area(mm->context, ea))) {
  513. DBG_LOW(" -> huge page !\n");
  514. return hash_huge_page(mm, access, ea, vsid, local);
  515. }
  516. /* Get PTE and page size from page tables */
  517. ptep = find_linux_pte(pgdir, ea);
  518. if (ptep == NULL || !pte_present(*ptep)) {
  519. DBG_LOW(" no PTE !\n");
  520. return 1;
  521. }
  522. #ifndef CONFIG_PPC_64K_PAGES
  523. DBG_LOW(" i-pte: %016lx\n", pte_val(*ptep));
  524. #else
  525. DBG_LOW(" i-pte: %016lx %016lx\n", pte_val(*ptep),
  526. pte_val(*(ptep + PTRS_PER_PTE)));
  527. #endif
  528. /* Pre-check access permissions (will be re-checked atomically
  529. * in __hash_page_XX but this pre-check is a fast path
  530. */
  531. if (access & ~pte_val(*ptep)) {
  532. DBG_LOW(" no access !\n");
  533. return 1;
  534. }
  535. /* Do actual hashing */
  536. #ifndef CONFIG_PPC_64K_PAGES
  537. rc = __hash_page_4K(ea, access, vsid, ptep, trap, local);
  538. #else
  539. if (mmu_virtual_psize == MMU_PAGE_64K)
  540. rc = __hash_page_64K(ea, access, vsid, ptep, trap, local);
  541. else
  542. rc = __hash_page_4K(ea, access, vsid, ptep, trap, local);
  543. #endif /* CONFIG_PPC_64K_PAGES */
  544. #ifndef CONFIG_PPC_64K_PAGES
  545. DBG_LOW(" o-pte: %016lx\n", pte_val(*ptep));
  546. #else
  547. DBG_LOW(" o-pte: %016lx %016lx\n", pte_val(*ptep),
  548. pte_val(*(ptep + PTRS_PER_PTE)));
  549. #endif
  550. DBG_LOW(" -> rc=%d\n", rc);
  551. return rc;
  552. }
  553. void hash_preload(struct mm_struct *mm, unsigned long ea,
  554. unsigned long access, unsigned long trap)
  555. {
  556. unsigned long vsid;
  557. void *pgdir;
  558. pte_t *ptep;
  559. cpumask_t mask;
  560. unsigned long flags;
  561. int local = 0;
  562. /* We don't want huge pages prefaulted for now
  563. */
  564. if (unlikely(in_hugepage_area(mm->context, ea)))
  565. return;
  566. DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx,"
  567. " trap=%lx\n", mm, mm->pgd, ea, access, trap);
  568. /* Get PTE, VSID, access mask */
  569. pgdir = mm->pgd;
  570. if (pgdir == NULL)
  571. return;
  572. ptep = find_linux_pte(pgdir, ea);
  573. if (!ptep)
  574. return;
  575. vsid = get_vsid(mm->context.id, ea);
  576. /* Hash it in */
  577. local_irq_save(flags);
  578. mask = cpumask_of_cpu(smp_processor_id());
  579. if (cpus_equal(mm->cpu_vm_mask, mask))
  580. local = 1;
  581. #ifndef CONFIG_PPC_64K_PAGES
  582. __hash_page_4K(ea, access, vsid, ptep, trap, local);
  583. #else
  584. if (mmu_virtual_psize == MMU_PAGE_64K)
  585. __hash_page_64K(ea, access, vsid, ptep, trap, local);
  586. else
  587. __hash_page_4K(ea, access, vsid, ptep, trap, local);
  588. #endif /* CONFIG_PPC_64K_PAGES */
  589. local_irq_restore(flags);
  590. }
  591. void flush_hash_page(unsigned long va, real_pte_t pte, int psize, int local)
  592. {
  593. unsigned long hash, index, shift, hidx, slot;
  594. DBG_LOW("flush_hash_page(va=%016x)\n", va);
  595. pte_iterate_hashed_subpages(pte, psize, va, index, shift) {
  596. hash = hpt_hash(va, shift);
  597. hidx = __rpte_to_hidx(pte, index);
  598. if (hidx & _PTEIDX_SECONDARY)
  599. hash = ~hash;
  600. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  601. slot += hidx & _PTEIDX_GROUP_IX;
  602. DBG_LOW(" sub %d: hash=%x, hidx=%x\n", index, slot, hidx);
  603. ppc_md.hpte_invalidate(slot, va, psize, local);
  604. } pte_iterate_hashed_end();
  605. }
  606. void flush_hash_range(unsigned long number, int local)
  607. {
  608. if (ppc_md.flush_hash_range)
  609. ppc_md.flush_hash_range(number, local);
  610. else {
  611. int i;
  612. struct ppc64_tlb_batch *batch =
  613. &__get_cpu_var(ppc64_tlb_batch);
  614. for (i = 0; i < number; i++)
  615. flush_hash_page(batch->vaddr[i], batch->pte[i],
  616. batch->psize, local);
  617. }
  618. }
  619. static inline void make_bl(unsigned int *insn_addr, void *func)
  620. {
  621. unsigned long funcp = *((unsigned long *)func);
  622. int offset = funcp - (unsigned long)insn_addr;
  623. *insn_addr = (unsigned int)(0x48000001 | (offset & 0x03fffffc));
  624. flush_icache_range((unsigned long)insn_addr, 4+
  625. (unsigned long)insn_addr);
  626. }
  627. /*
  628. * low_hash_fault is called when we the low level hash code failed
  629. * to instert a PTE due to an hypervisor error
  630. */
  631. void low_hash_fault(struct pt_regs *regs, unsigned long address)
  632. {
  633. if (user_mode(regs)) {
  634. siginfo_t info;
  635. info.si_signo = SIGBUS;
  636. info.si_errno = 0;
  637. info.si_code = BUS_ADRERR;
  638. info.si_addr = (void __user *)address;
  639. force_sig_info(SIGBUS, &info, current);
  640. return;
  641. }
  642. bad_page_fault(regs, address, SIGBUS);
  643. }
  644. void __init htab_finish_init(void)
  645. {
  646. extern unsigned int *htab_call_hpte_insert1;
  647. extern unsigned int *htab_call_hpte_insert2;
  648. extern unsigned int *htab_call_hpte_remove;
  649. extern unsigned int *htab_call_hpte_updatepp;
  650. #ifdef CONFIG_PPC_64K_PAGES
  651. extern unsigned int *ht64_call_hpte_insert1;
  652. extern unsigned int *ht64_call_hpte_insert2;
  653. extern unsigned int *ht64_call_hpte_remove;
  654. extern unsigned int *ht64_call_hpte_updatepp;
  655. make_bl(ht64_call_hpte_insert1, ppc_md.hpte_insert);
  656. make_bl(ht64_call_hpte_insert2, ppc_md.hpte_insert);
  657. make_bl(ht64_call_hpte_remove, ppc_md.hpte_remove);
  658. make_bl(ht64_call_hpte_updatepp, ppc_md.hpte_updatepp);
  659. #endif /* CONFIG_PPC_64K_PAGES */
  660. make_bl(htab_call_hpte_insert1, ppc_md.hpte_insert);
  661. make_bl(htab_call_hpte_insert2, ppc_md.hpte_insert);
  662. make_bl(htab_call_hpte_remove, ppc_md.hpte_remove);
  663. make_bl(htab_call_hpte_updatepp, ppc_md.hpte_updatepp);
  664. }