lpar.c 19 KB

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