lpar.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * pSeries_lpar.c
  3. * Copyright (C) 2001 Todd Inglett, IBM Corporation
  4. *
  5. * pSeries LPAR support.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* Enables debugging of low-level hash table routines - careful! */
  22. #undef DEBUG
  23. #include <linux/kernel.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/console.h>
  26. #include <linux/export.h>
  27. #include <asm/processor.h>
  28. #include <asm/mmu.h>
  29. #include <asm/page.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/machdep.h>
  32. #include <asm/mmu_context.h>
  33. #include <asm/iommu.h>
  34. #include <asm/tlbflush.h>
  35. #include <asm/tlb.h>
  36. #include <asm/prom.h>
  37. #include <asm/cputable.h>
  38. #include <asm/udbg.h>
  39. #include <asm/smp.h>
  40. #include <asm/trace.h>
  41. #include <asm/firmware.h>
  42. #include <asm/plpar_wrappers.h>
  43. #include "pseries.h"
  44. /* Flag bits for H_BULK_REMOVE */
  45. #define HBR_REQUEST 0x4000000000000000UL
  46. #define HBR_RESPONSE 0x8000000000000000UL
  47. #define HBR_END 0xc000000000000000UL
  48. #define HBR_AVPN 0x0200000000000000UL
  49. #define HBR_ANDCOND 0x0100000000000000UL
  50. /* in hvCall.S */
  51. EXPORT_SYMBOL(plpar_hcall);
  52. EXPORT_SYMBOL(plpar_hcall9);
  53. EXPORT_SYMBOL(plpar_hcall_norets);
  54. extern void pSeries_find_serial_port(void);
  55. void vpa_init(int cpu)
  56. {
  57. int hwcpu = get_hard_smp_processor_id(cpu);
  58. unsigned long addr;
  59. long ret;
  60. struct paca_struct *pp;
  61. struct dtl_entry *dtl;
  62. /*
  63. * The spec says it "may be problematic" if CPU x registers the VPA of
  64. * CPU y. We should never do that, but wail if we ever do.
  65. */
  66. WARN_ON(cpu != smp_processor_id());
  67. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  68. lppaca_of(cpu).vmxregs_in_use = 1;
  69. if (cpu_has_feature(CPU_FTR_ARCH_207S))
  70. lppaca_of(cpu).ebb_regs_in_use = 1;
  71. addr = __pa(&lppaca_of(cpu));
  72. ret = register_vpa(hwcpu, addr);
  73. if (ret) {
  74. pr_err("WARNING: VPA registration for cpu %d (hw %d) of area "
  75. "%lx failed with %ld\n", cpu, hwcpu, addr, ret);
  76. return;
  77. }
  78. /*
  79. * PAPR says this feature is SLB-Buffer but firmware never
  80. * reports that. All SPLPAR support SLB shadow buffer.
  81. */
  82. addr = __pa(&slb_shadow[cpu]);
  83. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  84. ret = register_slb_shadow(hwcpu, addr);
  85. if (ret)
  86. pr_err("WARNING: SLB shadow buffer registration for "
  87. "cpu %d (hw %d) of area %lx failed with %ld\n",
  88. cpu, hwcpu, addr, ret);
  89. }
  90. /*
  91. * Register dispatch trace log, if one has been allocated.
  92. */
  93. pp = &paca[cpu];
  94. dtl = pp->dispatch_log;
  95. if (dtl) {
  96. pp->dtl_ridx = 0;
  97. pp->dtl_curr = dtl;
  98. lppaca_of(cpu).dtl_idx = 0;
  99. /* hypervisor reads buffer length from this field */
  100. dtl->enqueue_to_dispatch_time = cpu_to_be32(DISPATCH_LOG_BYTES);
  101. ret = register_dtl(hwcpu, __pa(dtl));
  102. if (ret)
  103. pr_err("WARNING: DTL registration of cpu %d (hw %d) "
  104. "failed with %ld\n", smp_processor_id(),
  105. hwcpu, ret);
  106. lppaca_of(cpu).dtl_enable_mask = 2;
  107. }
  108. }
  109. static long pSeries_lpar_hpte_insert(unsigned long hpte_group,
  110. unsigned long vpn, unsigned long pa,
  111. unsigned long rflags, unsigned long vflags,
  112. int psize, int apsize, int ssize)
  113. {
  114. unsigned long lpar_rc;
  115. unsigned long flags;
  116. unsigned long slot;
  117. unsigned long hpte_v, hpte_r;
  118. if (!(vflags & HPTE_V_BOLTED))
  119. pr_devel("hpte_insert(group=%lx, vpn=%016lx, "
  120. "pa=%016lx, rflags=%lx, vflags=%lx, psize=%d)\n",
  121. hpte_group, vpn, pa, rflags, vflags, psize);
  122. hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID;
  123. hpte_r = hpte_encode_r(pa, psize, apsize) | rflags;
  124. if (!(vflags & HPTE_V_BOLTED))
  125. pr_devel(" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r);
  126. /* Now fill in the actual HPTE */
  127. /* Set CEC cookie to 0 */
  128. /* Zero page = 0 */
  129. /* I-cache Invalidate = 0 */
  130. /* I-cache synchronize = 0 */
  131. /* Exact = 0 */
  132. flags = 0;
  133. /* Make pHyp happy */
  134. if ((rflags & _PAGE_NO_CACHE) && !(rflags & _PAGE_WRITETHRU))
  135. hpte_r &= ~_PAGE_COHERENT;
  136. if (firmware_has_feature(FW_FEATURE_XCMO) && !(hpte_r & HPTE_R_N))
  137. flags |= H_COALESCE_CAND;
  138. lpar_rc = plpar_pte_enter(flags, hpte_group, hpte_v, hpte_r, &slot);
  139. if (unlikely(lpar_rc == H_PTEG_FULL)) {
  140. if (!(vflags & HPTE_V_BOLTED))
  141. pr_devel(" full\n");
  142. return -1;
  143. }
  144. /*
  145. * Since we try and ioremap PHBs we don't own, the pte insert
  146. * will fail. However we must catch the failure in hash_page
  147. * or we will loop forever, so return -2 in this case.
  148. */
  149. if (unlikely(lpar_rc != H_SUCCESS)) {
  150. if (!(vflags & HPTE_V_BOLTED))
  151. pr_devel(" lpar err %ld\n", lpar_rc);
  152. return -2;
  153. }
  154. if (!(vflags & HPTE_V_BOLTED))
  155. pr_devel(" -> slot: %lu\n", slot & 7);
  156. /* Because of iSeries, we have to pass down the secondary
  157. * bucket bit here as well
  158. */
  159. return (slot & 7) | (!!(vflags & HPTE_V_SECONDARY) << 3);
  160. }
  161. static DEFINE_SPINLOCK(pSeries_lpar_tlbie_lock);
  162. static long pSeries_lpar_hpte_remove(unsigned long hpte_group)
  163. {
  164. unsigned long slot_offset;
  165. unsigned long lpar_rc;
  166. int i;
  167. unsigned long dummy1, dummy2;
  168. /* pick a random slot to start at */
  169. slot_offset = mftb() & 0x7;
  170. for (i = 0; i < HPTES_PER_GROUP; i++) {
  171. /* don't remove a bolted entry */
  172. lpar_rc = plpar_pte_remove(H_ANDCOND, hpte_group + slot_offset,
  173. (0x1UL << 4), &dummy1, &dummy2);
  174. if (lpar_rc == H_SUCCESS)
  175. return i;
  176. /*
  177. * The test for adjunct partition is performed before the
  178. * ANDCOND test. H_RESOURCE may be returned, so we need to
  179. * check for that as well.
  180. */
  181. BUG_ON(lpar_rc != H_NOT_FOUND && lpar_rc != H_RESOURCE);
  182. slot_offset++;
  183. slot_offset &= 0x7;
  184. }
  185. return -1;
  186. }
  187. static void pSeries_lpar_hptab_clear(void)
  188. {
  189. unsigned long size_bytes = 1UL << ppc64_pft_size;
  190. unsigned long hpte_count = size_bytes >> 4;
  191. struct {
  192. unsigned long pteh;
  193. unsigned long ptel;
  194. } ptes[4];
  195. long lpar_rc;
  196. unsigned long i, j;
  197. /* Read in batches of 4,
  198. * invalidate only valid entries not in the VRMA
  199. * hpte_count will be a multiple of 4
  200. */
  201. for (i = 0; i < hpte_count; i += 4) {
  202. lpar_rc = plpar_pte_read_4_raw(0, i, (void *)ptes);
  203. if (lpar_rc != H_SUCCESS)
  204. continue;
  205. for (j = 0; j < 4; j++){
  206. if ((ptes[j].pteh & HPTE_V_VRMA_MASK) ==
  207. HPTE_V_VRMA_MASK)
  208. continue;
  209. if (ptes[j].pteh & HPTE_V_VALID)
  210. plpar_pte_remove_raw(0, i + j, 0,
  211. &(ptes[j].pteh), &(ptes[j].ptel));
  212. }
  213. }
  214. }
  215. /*
  216. * NOTE: for updatepp ops we are fortunate that the linux "newpp" bits and
  217. * the low 3 bits of flags happen to line up. So no transform is needed.
  218. * We can probably optimize here and assume the high bits of newpp are
  219. * already zero. For now I am paranoid.
  220. */
  221. static long pSeries_lpar_hpte_updatepp(unsigned long slot,
  222. unsigned long newpp,
  223. unsigned long vpn,
  224. int psize, int apsize,
  225. int ssize, int local)
  226. {
  227. unsigned long lpar_rc;
  228. unsigned long flags = (newpp & 7) | H_AVPN;
  229. unsigned long want_v;
  230. want_v = hpte_encode_avpn(vpn, psize, ssize);
  231. pr_devel(" update: avpnv=%016lx, hash=%016lx, f=%lx, psize: %d ...",
  232. want_v, slot, flags, psize);
  233. lpar_rc = plpar_pte_protect(flags, slot, want_v);
  234. if (lpar_rc == H_NOT_FOUND) {
  235. pr_devel("not found !\n");
  236. return -1;
  237. }
  238. pr_devel("ok\n");
  239. BUG_ON(lpar_rc != H_SUCCESS);
  240. return 0;
  241. }
  242. static unsigned long pSeries_lpar_hpte_getword0(unsigned long slot)
  243. {
  244. unsigned long dword0;
  245. unsigned long lpar_rc;
  246. unsigned long dummy_word1;
  247. unsigned long flags;
  248. /* Read 1 pte at a time */
  249. /* Do not need RPN to logical page translation */
  250. /* No cross CEC PFT access */
  251. flags = 0;
  252. lpar_rc = plpar_pte_read(flags, slot, &dword0, &dummy_word1);
  253. BUG_ON(lpar_rc != H_SUCCESS);
  254. return dword0;
  255. }
  256. static long pSeries_lpar_hpte_find(unsigned long vpn, int psize, int ssize)
  257. {
  258. unsigned long hash;
  259. unsigned long i;
  260. long slot;
  261. unsigned long want_v, hpte_v;
  262. hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize);
  263. want_v = hpte_encode_avpn(vpn, psize, ssize);
  264. /* Bolted entries are always in the primary group */
  265. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  266. for (i = 0; i < HPTES_PER_GROUP; i++) {
  267. hpte_v = pSeries_lpar_hpte_getword0(slot);
  268. if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID))
  269. /* HPTE matches */
  270. return slot;
  271. ++slot;
  272. }
  273. return -1;
  274. }
  275. static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp,
  276. unsigned long ea,
  277. int psize, int ssize)
  278. {
  279. unsigned long vpn;
  280. unsigned long lpar_rc, slot, vsid, flags;
  281. vsid = get_kernel_vsid(ea, ssize);
  282. vpn = hpt_vpn(ea, vsid, ssize);
  283. slot = pSeries_lpar_hpte_find(vpn, psize, ssize);
  284. BUG_ON(slot == -1);
  285. flags = newpp & 7;
  286. lpar_rc = plpar_pte_protect(flags, slot, 0);
  287. BUG_ON(lpar_rc != H_SUCCESS);
  288. }
  289. static void pSeries_lpar_hpte_invalidate(unsigned long slot, unsigned long vpn,
  290. int psize, int apsize,
  291. int ssize, int local)
  292. {
  293. unsigned long want_v;
  294. unsigned long lpar_rc;
  295. unsigned long dummy1, dummy2;
  296. pr_devel(" inval : slot=%lx, vpn=%016lx, psize: %d, local: %d\n",
  297. slot, vpn, psize, local);
  298. want_v = hpte_encode_avpn(vpn, psize, ssize);
  299. lpar_rc = plpar_pte_remove(H_AVPN, slot, want_v, &dummy1, &dummy2);
  300. if (lpar_rc == H_NOT_FOUND)
  301. return;
  302. BUG_ON(lpar_rc != H_SUCCESS);
  303. }
  304. /*
  305. * Limit iterations holding pSeries_lpar_tlbie_lock to 3. We also need
  306. * to make sure that we avoid bouncing the hypervisor tlbie lock.
  307. */
  308. #define PPC64_HUGE_HPTE_BATCH 12
  309. static void __pSeries_lpar_hugepage_invalidate(unsigned long *slot,
  310. unsigned long *vpn, int count,
  311. int psize, int ssize)
  312. {
  313. unsigned long param[8];
  314. int i = 0, pix = 0, rc;
  315. unsigned long flags = 0;
  316. int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
  317. if (lock_tlbie)
  318. spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags);
  319. for (i = 0; i < count; i++) {
  320. if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) {
  321. pSeries_lpar_hpte_invalidate(slot[i], vpn[i], psize, 0,
  322. ssize, 0);
  323. } else {
  324. param[pix] = HBR_REQUEST | HBR_AVPN | slot[i];
  325. param[pix+1] = hpte_encode_avpn(vpn[i], psize, ssize);
  326. pix += 2;
  327. if (pix == 8) {
  328. rc = plpar_hcall9(H_BULK_REMOVE, param,
  329. param[0], param[1], param[2],
  330. param[3], param[4], param[5],
  331. param[6], param[7]);
  332. BUG_ON(rc != H_SUCCESS);
  333. pix = 0;
  334. }
  335. }
  336. }
  337. if (pix) {
  338. param[pix] = HBR_END;
  339. rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1],
  340. param[2], param[3], param[4], param[5],
  341. param[6], param[7]);
  342. BUG_ON(rc != H_SUCCESS);
  343. }
  344. if (lock_tlbie)
  345. spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags);
  346. }
  347. static void pSeries_lpar_hugepage_invalidate(struct mm_struct *mm,
  348. unsigned char *hpte_slot_array,
  349. unsigned long addr, int psize)
  350. {
  351. int ssize = 0, i, index = 0;
  352. unsigned long s_addr = addr;
  353. unsigned int max_hpte_count, valid;
  354. unsigned long vpn_array[PPC64_HUGE_HPTE_BATCH];
  355. unsigned long slot_array[PPC64_HUGE_HPTE_BATCH];
  356. unsigned long shift, hidx, vpn = 0, vsid, hash, slot;
  357. shift = mmu_psize_defs[psize].shift;
  358. max_hpte_count = 1U << (PMD_SHIFT - shift);
  359. for (i = 0; i < max_hpte_count; i++) {
  360. valid = hpte_valid(hpte_slot_array, i);
  361. if (!valid)
  362. continue;
  363. hidx = hpte_hash_index(hpte_slot_array, i);
  364. /* get the vpn */
  365. addr = s_addr + (i * (1ul << shift));
  366. if (!is_kernel_addr(addr)) {
  367. ssize = user_segment_size(addr);
  368. vsid = get_vsid(mm->context.id, addr, ssize);
  369. WARN_ON(vsid == 0);
  370. } else {
  371. vsid = get_kernel_vsid(addr, mmu_kernel_ssize);
  372. ssize = mmu_kernel_ssize;
  373. }
  374. vpn = hpt_vpn(addr, vsid, ssize);
  375. hash = hpt_hash(vpn, shift, ssize);
  376. if (hidx & _PTEIDX_SECONDARY)
  377. hash = ~hash;
  378. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  379. slot += hidx & _PTEIDX_GROUP_IX;
  380. slot_array[index] = slot;
  381. vpn_array[index] = vpn;
  382. if (index == PPC64_HUGE_HPTE_BATCH - 1) {
  383. /*
  384. * Now do a bluk invalidate
  385. */
  386. __pSeries_lpar_hugepage_invalidate(slot_array,
  387. vpn_array,
  388. PPC64_HUGE_HPTE_BATCH,
  389. psize, ssize);
  390. index = 0;
  391. } else
  392. index++;
  393. }
  394. if (index)
  395. __pSeries_lpar_hugepage_invalidate(slot_array, vpn_array,
  396. index, psize, ssize);
  397. }
  398. static void pSeries_lpar_hpte_removebolted(unsigned long ea,
  399. int psize, int ssize)
  400. {
  401. unsigned long vpn;
  402. unsigned long slot, vsid;
  403. vsid = get_kernel_vsid(ea, ssize);
  404. vpn = hpt_vpn(ea, vsid, ssize);
  405. slot = pSeries_lpar_hpte_find(vpn, psize, ssize);
  406. BUG_ON(slot == -1);
  407. /*
  408. * lpar doesn't use the passed actual page size
  409. */
  410. pSeries_lpar_hpte_invalidate(slot, vpn, psize, 0, ssize, 0);
  411. }
  412. /*
  413. * Take a spinlock around flushes to avoid bouncing the hypervisor tlbie
  414. * lock.
  415. */
  416. static void pSeries_lpar_flush_hash_range(unsigned long number, int local)
  417. {
  418. unsigned long vpn;
  419. unsigned long i, pix, rc;
  420. unsigned long flags = 0;
  421. struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);
  422. int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
  423. unsigned long param[9];
  424. unsigned long hash, index, shift, hidx, slot;
  425. real_pte_t pte;
  426. int psize, ssize;
  427. if (lock_tlbie)
  428. spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags);
  429. psize = batch->psize;
  430. ssize = batch->ssize;
  431. pix = 0;
  432. for (i = 0; i < number; i++) {
  433. vpn = batch->vpn[i];
  434. pte = batch->pte[i];
  435. pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) {
  436. hash = hpt_hash(vpn, shift, ssize);
  437. hidx = __rpte_to_hidx(pte, index);
  438. if (hidx & _PTEIDX_SECONDARY)
  439. hash = ~hash;
  440. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  441. slot += hidx & _PTEIDX_GROUP_IX;
  442. if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) {
  443. /*
  444. * lpar doesn't use the passed actual page size
  445. */
  446. pSeries_lpar_hpte_invalidate(slot, vpn, psize,
  447. 0, ssize, local);
  448. } else {
  449. param[pix] = HBR_REQUEST | HBR_AVPN | slot;
  450. param[pix+1] = hpte_encode_avpn(vpn, psize,
  451. ssize);
  452. pix += 2;
  453. if (pix == 8) {
  454. rc = plpar_hcall9(H_BULK_REMOVE, param,
  455. param[0], param[1], param[2],
  456. param[3], param[4], param[5],
  457. param[6], param[7]);
  458. BUG_ON(rc != H_SUCCESS);
  459. pix = 0;
  460. }
  461. }
  462. } pte_iterate_hashed_end();
  463. }
  464. if (pix) {
  465. param[pix] = HBR_END;
  466. rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1],
  467. param[2], param[3], param[4], param[5],
  468. param[6], param[7]);
  469. BUG_ON(rc != H_SUCCESS);
  470. }
  471. if (lock_tlbie)
  472. spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags);
  473. }
  474. static int __init disable_bulk_remove(char *str)
  475. {
  476. if (strcmp(str, "off") == 0 &&
  477. firmware_has_feature(FW_FEATURE_BULK_REMOVE)) {
  478. printk(KERN_INFO "Disabling BULK_REMOVE firmware feature");
  479. powerpc_firmware_features &= ~FW_FEATURE_BULK_REMOVE;
  480. }
  481. return 1;
  482. }
  483. __setup("bulk_remove=", disable_bulk_remove);
  484. void __init hpte_init_lpar(void)
  485. {
  486. ppc_md.hpte_invalidate = pSeries_lpar_hpte_invalidate;
  487. ppc_md.hpte_updatepp = pSeries_lpar_hpte_updatepp;
  488. ppc_md.hpte_updateboltedpp = pSeries_lpar_hpte_updateboltedpp;
  489. ppc_md.hpte_insert = pSeries_lpar_hpte_insert;
  490. ppc_md.hpte_remove = pSeries_lpar_hpte_remove;
  491. ppc_md.hpte_removebolted = pSeries_lpar_hpte_removebolted;
  492. ppc_md.flush_hash_range = pSeries_lpar_flush_hash_range;
  493. ppc_md.hpte_clear_all = pSeries_lpar_hptab_clear;
  494. ppc_md.hugepage_invalidate = pSeries_lpar_hugepage_invalidate;
  495. }
  496. #ifdef CONFIG_PPC_SMLPAR
  497. #define CMO_FREE_HINT_DEFAULT 1
  498. static int cmo_free_hint_flag = CMO_FREE_HINT_DEFAULT;
  499. static int __init cmo_free_hint(char *str)
  500. {
  501. char *parm;
  502. parm = strstrip(str);
  503. if (strcasecmp(parm, "no") == 0 || strcasecmp(parm, "off") == 0) {
  504. printk(KERN_INFO "cmo_free_hint: CMO free page hinting is not active.\n");
  505. cmo_free_hint_flag = 0;
  506. return 1;
  507. }
  508. cmo_free_hint_flag = 1;
  509. printk(KERN_INFO "cmo_free_hint: CMO free page hinting is active.\n");
  510. if (strcasecmp(parm, "yes") == 0 || strcasecmp(parm, "on") == 0)
  511. return 1;
  512. return 0;
  513. }
  514. __setup("cmo_free_hint=", cmo_free_hint);
  515. static void pSeries_set_page_state(struct page *page, int order,
  516. unsigned long state)
  517. {
  518. int i, j;
  519. unsigned long cmo_page_sz, addr;
  520. cmo_page_sz = cmo_get_page_size();
  521. addr = __pa((unsigned long)page_address(page));
  522. for (i = 0; i < (1 << order); i++, addr += PAGE_SIZE) {
  523. for (j = 0; j < PAGE_SIZE; j += cmo_page_sz)
  524. plpar_hcall_norets(H_PAGE_INIT, state, addr + j, 0);
  525. }
  526. }
  527. void arch_free_page(struct page *page, int order)
  528. {
  529. if (!cmo_free_hint_flag || !firmware_has_feature(FW_FEATURE_CMO))
  530. return;
  531. pSeries_set_page_state(page, order, H_PAGE_SET_UNUSED);
  532. }
  533. EXPORT_SYMBOL(arch_free_page);
  534. #endif
  535. #ifdef CONFIG_TRACEPOINTS
  536. /*
  537. * We optimise our hcall path by placing hcall_tracepoint_refcount
  538. * directly in the TOC so we can check if the hcall tracepoints are
  539. * enabled via a single load.
  540. */
  541. /* NB: reg/unreg are called while guarded with the tracepoints_mutex */
  542. extern long hcall_tracepoint_refcount;
  543. /*
  544. * Since the tracing code might execute hcalls we need to guard against
  545. * recursion. One example of this are spinlocks calling H_YIELD on
  546. * shared processor partitions.
  547. */
  548. static DEFINE_PER_CPU(unsigned int, hcall_trace_depth);
  549. void hcall_tracepoint_regfunc(void)
  550. {
  551. hcall_tracepoint_refcount++;
  552. }
  553. void hcall_tracepoint_unregfunc(void)
  554. {
  555. hcall_tracepoint_refcount--;
  556. }
  557. void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
  558. {
  559. unsigned long flags;
  560. unsigned int *depth;
  561. /*
  562. * We cannot call tracepoints inside RCU idle regions which
  563. * means we must not trace H_CEDE.
  564. */
  565. if (opcode == H_CEDE)
  566. return;
  567. local_irq_save(flags);
  568. depth = &__get_cpu_var(hcall_trace_depth);
  569. if (*depth)
  570. goto out;
  571. (*depth)++;
  572. preempt_disable();
  573. trace_hcall_entry(opcode, args);
  574. (*depth)--;
  575. out:
  576. local_irq_restore(flags);
  577. }
  578. void __trace_hcall_exit(long opcode, unsigned long retval,
  579. unsigned long *retbuf)
  580. {
  581. unsigned long flags;
  582. unsigned int *depth;
  583. if (opcode == H_CEDE)
  584. return;
  585. local_irq_save(flags);
  586. depth = &__get_cpu_var(hcall_trace_depth);
  587. if (*depth)
  588. goto out;
  589. (*depth)++;
  590. trace_hcall_exit(opcode, retval, retbuf);
  591. preempt_enable();
  592. (*depth)--;
  593. out:
  594. local_irq_restore(flags);
  595. }
  596. #endif
  597. /**
  598. * h_get_mpp
  599. * H_GET_MPP hcall returns info in 7 parms
  600. */
  601. int h_get_mpp(struct hvcall_mpp_data *mpp_data)
  602. {
  603. int rc;
  604. unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
  605. rc = plpar_hcall9(H_GET_MPP, retbuf);
  606. mpp_data->entitled_mem = retbuf[0];
  607. mpp_data->mapped_mem = retbuf[1];
  608. mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
  609. mpp_data->pool_num = retbuf[2] & 0xffff;
  610. mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff;
  611. mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff;
  612. mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffffUL;
  613. mpp_data->pool_size = retbuf[4];
  614. mpp_data->loan_request = retbuf[5];
  615. mpp_data->backing_mem = retbuf[6];
  616. return rc;
  617. }
  618. EXPORT_SYMBOL(h_get_mpp);
  619. int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data)
  620. {
  621. int rc;
  622. unsigned long retbuf[PLPAR_HCALL9_BUFSIZE] = { 0 };
  623. rc = plpar_hcall9(H_GET_MPP_X, retbuf);
  624. mpp_x_data->coalesced_bytes = retbuf[0];
  625. mpp_x_data->pool_coalesced_bytes = retbuf[1];
  626. mpp_x_data->pool_purr_cycles = retbuf[2];
  627. mpp_x_data->pool_spurr_cycles = retbuf[3];
  628. return rc;
  629. }