lpar.c 20 KB

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