lpar.c 20 KB

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