lpar.c 20 KB

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