lpar.c 20 KB

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