native.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Copyright 2016,2017 IBM Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #define pr_fmt(fmt) "xive: " fmt
  10. #include <linux/types.h>
  11. #include <linux/irq.h>
  12. #include <linux/debugfs.h>
  13. #include <linux/smp.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/init.h>
  17. #include <linux/of.h>
  18. #include <linux/slab.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/delay.h>
  21. #include <linux/cpumask.h>
  22. #include <linux/mm.h>
  23. #include <asm/prom.h>
  24. #include <asm/io.h>
  25. #include <asm/smp.h>
  26. #include <asm/irq.h>
  27. #include <asm/errno.h>
  28. #include <asm/xive.h>
  29. #include <asm/xive-regs.h>
  30. #include <asm/opal.h>
  31. #include <asm/kvm_ppc.h>
  32. #include "xive-internal.h"
  33. static u32 xive_provision_size;
  34. static u32 *xive_provision_chips;
  35. static u32 xive_provision_chip_count;
  36. static u32 xive_queue_shift;
  37. static u32 xive_pool_vps = XIVE_INVALID_VP;
  38. static struct kmem_cache *xive_provision_cache;
  39. int xive_native_populate_irq_data(u32 hw_irq, struct xive_irq_data *data)
  40. {
  41. __be64 flags, eoi_page, trig_page;
  42. __be32 esb_shift, src_chip;
  43. u64 opal_flags;
  44. s64 rc;
  45. memset(data, 0, sizeof(*data));
  46. rc = opal_xive_get_irq_info(hw_irq, &flags, &eoi_page, &trig_page,
  47. &esb_shift, &src_chip);
  48. if (rc) {
  49. pr_err("opal_xive_get_irq_info(0x%x) returned %lld\n",
  50. hw_irq, rc);
  51. return -EINVAL;
  52. }
  53. opal_flags = be64_to_cpu(flags);
  54. if (opal_flags & OPAL_XIVE_IRQ_STORE_EOI)
  55. data->flags |= XIVE_IRQ_FLAG_STORE_EOI;
  56. if (opal_flags & OPAL_XIVE_IRQ_LSI)
  57. data->flags |= XIVE_IRQ_FLAG_LSI;
  58. if (opal_flags & OPAL_XIVE_IRQ_SHIFT_BUG)
  59. data->flags |= XIVE_IRQ_FLAG_SHIFT_BUG;
  60. if (opal_flags & OPAL_XIVE_IRQ_MASK_VIA_FW)
  61. data->flags |= XIVE_IRQ_FLAG_MASK_FW;
  62. if (opal_flags & OPAL_XIVE_IRQ_EOI_VIA_FW)
  63. data->flags |= XIVE_IRQ_FLAG_EOI_FW;
  64. data->eoi_page = be64_to_cpu(eoi_page);
  65. data->trig_page = be64_to_cpu(trig_page);
  66. data->esb_shift = be32_to_cpu(esb_shift);
  67. data->src_chip = be32_to_cpu(src_chip);
  68. data->eoi_mmio = ioremap(data->eoi_page, 1u << data->esb_shift);
  69. if (!data->eoi_mmio) {
  70. pr_err("Failed to map EOI page for irq 0x%x\n", hw_irq);
  71. return -ENOMEM;
  72. }
  73. data->hw_irq = hw_irq;
  74. if (!data->trig_page)
  75. return 0;
  76. if (data->trig_page == data->eoi_page) {
  77. data->trig_mmio = data->eoi_mmio;
  78. return 0;
  79. }
  80. data->trig_mmio = ioremap(data->trig_page, 1u << data->esb_shift);
  81. if (!data->trig_mmio) {
  82. pr_err("Failed to map trigger page for irq 0x%x\n", hw_irq);
  83. return -ENOMEM;
  84. }
  85. return 0;
  86. }
  87. EXPORT_SYMBOL_GPL(xive_native_populate_irq_data);
  88. int xive_native_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq)
  89. {
  90. s64 rc;
  91. for (;;) {
  92. rc = opal_xive_set_irq_config(hw_irq, target, prio, sw_irq);
  93. if (rc != OPAL_BUSY)
  94. break;
  95. msleep(1);
  96. }
  97. return rc == 0 ? 0 : -ENXIO;
  98. }
  99. EXPORT_SYMBOL_GPL(xive_native_configure_irq);
  100. /* This can be called multiple time to change a queue configuration */
  101. int xive_native_configure_queue(u32 vp_id, struct xive_q *q, u8 prio,
  102. __be32 *qpage, u32 order, bool can_escalate)
  103. {
  104. s64 rc = 0;
  105. __be64 qeoi_page_be;
  106. __be32 esc_irq_be;
  107. u64 flags, qpage_phys;
  108. /* If there's an actual queue page, clean it */
  109. if (order) {
  110. if (WARN_ON(!qpage))
  111. return -EINVAL;
  112. qpage_phys = __pa(qpage);
  113. } else
  114. qpage_phys = 0;
  115. /* Initialize the rest of the fields */
  116. q->msk = order ? ((1u << (order - 2)) - 1) : 0;
  117. q->idx = 0;
  118. q->toggle = 0;
  119. rc = opal_xive_get_queue_info(vp_id, prio, NULL, NULL,
  120. &qeoi_page_be,
  121. &esc_irq_be,
  122. NULL);
  123. if (rc) {
  124. pr_err("Error %lld getting queue info prio %d\n", rc, prio);
  125. rc = -EIO;
  126. goto fail;
  127. }
  128. q->eoi_phys = be64_to_cpu(qeoi_page_be);
  129. /* Default flags */
  130. flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY | OPAL_XIVE_EQ_ENABLED;
  131. /* Escalation needed ? */
  132. if (can_escalate) {
  133. q->esc_irq = be32_to_cpu(esc_irq_be);
  134. flags |= OPAL_XIVE_EQ_ESCALATE;
  135. }
  136. /* Configure and enable the queue in HW */
  137. for (;;) {
  138. rc = opal_xive_set_queue_info(vp_id, prio, qpage_phys, order, flags);
  139. if (rc != OPAL_BUSY)
  140. break;
  141. msleep(1);
  142. }
  143. if (rc) {
  144. pr_err("Error %lld setting queue for prio %d\n", rc, prio);
  145. rc = -EIO;
  146. } else {
  147. /*
  148. * KVM code requires all of the above to be visible before
  149. * q->qpage is set due to how it manages IPI EOIs
  150. */
  151. wmb();
  152. q->qpage = qpage;
  153. }
  154. fail:
  155. return rc;
  156. }
  157. EXPORT_SYMBOL_GPL(xive_native_configure_queue);
  158. static void __xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio)
  159. {
  160. s64 rc;
  161. /* Disable the queue in HW */
  162. for (;;) {
  163. rc = opal_xive_set_queue_info(vp_id, prio, 0, 0, 0);
  164. if (rc != OPAL_BUSY)
  165. break;
  166. msleep(1);
  167. }
  168. if (rc)
  169. pr_err("Error %lld disabling queue for prio %d\n", rc, prio);
  170. }
  171. void xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio)
  172. {
  173. __xive_native_disable_queue(vp_id, q, prio);
  174. }
  175. EXPORT_SYMBOL_GPL(xive_native_disable_queue);
  176. static int xive_native_setup_queue(unsigned int cpu, struct xive_cpu *xc, u8 prio)
  177. {
  178. struct xive_q *q = &xc->queue[prio];
  179. __be32 *qpage;
  180. qpage = xive_queue_page_alloc(cpu, xive_queue_shift);
  181. if (IS_ERR(qpage))
  182. return PTR_ERR(qpage);
  183. return xive_native_configure_queue(get_hard_smp_processor_id(cpu),
  184. q, prio, qpage, xive_queue_shift, false);
  185. }
  186. static void xive_native_cleanup_queue(unsigned int cpu, struct xive_cpu *xc, u8 prio)
  187. {
  188. struct xive_q *q = &xc->queue[prio];
  189. unsigned int alloc_order;
  190. /*
  191. * We use the variant with no iounmap as this is called on exec
  192. * from an IPI and iounmap isn't safe
  193. */
  194. __xive_native_disable_queue(get_hard_smp_processor_id(cpu), q, prio);
  195. alloc_order = xive_alloc_order(xive_queue_shift);
  196. free_pages((unsigned long)q->qpage, alloc_order);
  197. q->qpage = NULL;
  198. }
  199. static bool xive_native_match(struct device_node *node)
  200. {
  201. return of_device_is_compatible(node, "ibm,opal-xive-vc");
  202. }
  203. #ifdef CONFIG_SMP
  204. static int xive_native_get_ipi(unsigned int cpu, struct xive_cpu *xc)
  205. {
  206. struct device_node *np;
  207. unsigned int chip_id;
  208. s64 irq;
  209. /* Find the chip ID */
  210. np = of_get_cpu_node(cpu, NULL);
  211. if (np) {
  212. if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
  213. chip_id = 0;
  214. }
  215. /* Allocate an IPI and populate info about it */
  216. for (;;) {
  217. irq = opal_xive_allocate_irq(chip_id);
  218. if (irq == OPAL_BUSY) {
  219. msleep(1);
  220. continue;
  221. }
  222. if (irq < 0) {
  223. pr_err("Failed to allocate IPI on CPU %d\n", cpu);
  224. return -ENXIO;
  225. }
  226. xc->hw_ipi = irq;
  227. break;
  228. }
  229. return 0;
  230. }
  231. #endif /* CONFIG_SMP */
  232. u32 xive_native_alloc_irq(void)
  233. {
  234. s64 rc;
  235. for (;;) {
  236. rc = opal_xive_allocate_irq(OPAL_XIVE_ANY_CHIP);
  237. if (rc != OPAL_BUSY)
  238. break;
  239. msleep(1);
  240. }
  241. if (rc < 0)
  242. return 0;
  243. return rc;
  244. }
  245. EXPORT_SYMBOL_GPL(xive_native_alloc_irq);
  246. void xive_native_free_irq(u32 irq)
  247. {
  248. for (;;) {
  249. s64 rc = opal_xive_free_irq(irq);
  250. if (rc != OPAL_BUSY)
  251. break;
  252. msleep(1);
  253. }
  254. }
  255. EXPORT_SYMBOL_GPL(xive_native_free_irq);
  256. #ifdef CONFIG_SMP
  257. static void xive_native_put_ipi(unsigned int cpu, struct xive_cpu *xc)
  258. {
  259. s64 rc;
  260. /* Free the IPI */
  261. if (!xc->hw_ipi)
  262. return;
  263. for (;;) {
  264. rc = opal_xive_free_irq(xc->hw_ipi);
  265. if (rc == OPAL_BUSY) {
  266. msleep(1);
  267. continue;
  268. }
  269. xc->hw_ipi = 0;
  270. break;
  271. }
  272. }
  273. #endif /* CONFIG_SMP */
  274. static void xive_native_shutdown(void)
  275. {
  276. /* Switch the XIVE to emulation mode */
  277. opal_xive_reset(OPAL_XIVE_MODE_EMU);
  278. }
  279. /*
  280. * Perform an "ack" cycle on the current thread, thus
  281. * grabbing the pending active priorities and updating
  282. * the CPPR to the most favored one.
  283. */
  284. static void xive_native_update_pending(struct xive_cpu *xc)
  285. {
  286. u8 he, cppr;
  287. u16 ack;
  288. /* Perform the acknowledge hypervisor to register cycle */
  289. ack = be16_to_cpu(__raw_readw(xive_tima + TM_SPC_ACK_HV_REG));
  290. /* Synchronize subsequent queue accesses */
  291. mb();
  292. /*
  293. * Grab the CPPR and the "HE" field which indicates the source
  294. * of the hypervisor interrupt (if any)
  295. */
  296. cppr = ack & 0xff;
  297. he = GETFIELD(TM_QW3_NSR_HE, (ack >> 8));
  298. switch(he) {
  299. case TM_QW3_NSR_HE_NONE: /* Nothing to see here */
  300. break;
  301. case TM_QW3_NSR_HE_PHYS: /* Physical thread interrupt */
  302. if (cppr == 0xff)
  303. return;
  304. /* Mark the priority pending */
  305. xc->pending_prio |= 1 << cppr;
  306. /*
  307. * A new interrupt should never have a CPPR less favored
  308. * than our current one.
  309. */
  310. if (cppr >= xc->cppr)
  311. pr_err("CPU %d odd ack CPPR, got %d at %d\n",
  312. smp_processor_id(), cppr, xc->cppr);
  313. /* Update our idea of what the CPPR is */
  314. xc->cppr = cppr;
  315. break;
  316. case TM_QW3_NSR_HE_POOL: /* HV Pool interrupt (unused) */
  317. case TM_QW3_NSR_HE_LSI: /* Legacy FW LSI (unused) */
  318. pr_err("CPU %d got unexpected interrupt type HE=%d\n",
  319. smp_processor_id(), he);
  320. return;
  321. }
  322. }
  323. static void xive_native_eoi(u32 hw_irq)
  324. {
  325. /*
  326. * Not normally used except if specific interrupts need
  327. * a workaround on EOI.
  328. */
  329. opal_int_eoi(hw_irq);
  330. }
  331. static void xive_native_setup_cpu(unsigned int cpu, struct xive_cpu *xc)
  332. {
  333. s64 rc;
  334. u32 vp;
  335. __be64 vp_cam_be;
  336. u64 vp_cam;
  337. if (xive_pool_vps == XIVE_INVALID_VP)
  338. return;
  339. /* Enable the pool VP */
  340. vp = xive_pool_vps + cpu;
  341. pr_debug("CPU %d setting up pool VP 0x%x\n", cpu, vp);
  342. for (;;) {
  343. rc = opal_xive_set_vp_info(vp, OPAL_XIVE_VP_ENABLED, 0);
  344. if (rc != OPAL_BUSY)
  345. break;
  346. msleep(1);
  347. }
  348. if (rc) {
  349. pr_err("Failed to enable pool VP on CPU %d\n", cpu);
  350. return;
  351. }
  352. /* Grab it's CAM value */
  353. rc = opal_xive_get_vp_info(vp, NULL, &vp_cam_be, NULL, NULL);
  354. if (rc) {
  355. pr_err("Failed to get pool VP info CPU %d\n", cpu);
  356. return;
  357. }
  358. vp_cam = be64_to_cpu(vp_cam_be);
  359. pr_debug("VP CAM = %llx\n", vp_cam);
  360. /* Push it on the CPU (set LSMFB to 0xff to skip backlog scan) */
  361. pr_debug("(Old HW value: %08x)\n",
  362. in_be32(xive_tima + TM_QW2_HV_POOL + TM_WORD2));
  363. out_be32(xive_tima + TM_QW2_HV_POOL + TM_WORD0, 0xff);
  364. out_be32(xive_tima + TM_QW2_HV_POOL + TM_WORD2,
  365. TM_QW2W2_VP | vp_cam);
  366. pr_debug("(New HW value: %08x)\n",
  367. in_be32(xive_tima + TM_QW2_HV_POOL + TM_WORD2));
  368. }
  369. static void xive_native_teardown_cpu(unsigned int cpu, struct xive_cpu *xc)
  370. {
  371. s64 rc;
  372. u32 vp;
  373. if (xive_pool_vps == XIVE_INVALID_VP)
  374. return;
  375. /* Pull the pool VP from the CPU */
  376. in_be64(xive_tima + TM_SPC_PULL_POOL_CTX);
  377. /* Disable it */
  378. vp = xive_pool_vps + cpu;
  379. for (;;) {
  380. rc = opal_xive_set_vp_info(vp, 0, 0);
  381. if (rc != OPAL_BUSY)
  382. break;
  383. msleep(1);
  384. }
  385. }
  386. void xive_native_sync_source(u32 hw_irq)
  387. {
  388. opal_xive_sync(XIVE_SYNC_EAS, hw_irq);
  389. }
  390. EXPORT_SYMBOL_GPL(xive_native_sync_source);
  391. static const struct xive_ops xive_native_ops = {
  392. .populate_irq_data = xive_native_populate_irq_data,
  393. .configure_irq = xive_native_configure_irq,
  394. .setup_queue = xive_native_setup_queue,
  395. .cleanup_queue = xive_native_cleanup_queue,
  396. .match = xive_native_match,
  397. .shutdown = xive_native_shutdown,
  398. .update_pending = xive_native_update_pending,
  399. .eoi = xive_native_eoi,
  400. .setup_cpu = xive_native_setup_cpu,
  401. .teardown_cpu = xive_native_teardown_cpu,
  402. .sync_source = xive_native_sync_source,
  403. #ifdef CONFIG_SMP
  404. .get_ipi = xive_native_get_ipi,
  405. .put_ipi = xive_native_put_ipi,
  406. #endif /* CONFIG_SMP */
  407. .name = "native",
  408. };
  409. static bool xive_parse_provisioning(struct device_node *np)
  410. {
  411. int rc;
  412. if (of_property_read_u32(np, "ibm,xive-provision-page-size",
  413. &xive_provision_size) < 0)
  414. return true;
  415. rc = of_property_count_elems_of_size(np, "ibm,xive-provision-chips", 4);
  416. if (rc < 0) {
  417. pr_err("Error %d getting provision chips array\n", rc);
  418. return false;
  419. }
  420. xive_provision_chip_count = rc;
  421. if (rc == 0)
  422. return true;
  423. xive_provision_chips = kzalloc(4 * xive_provision_chip_count,
  424. GFP_KERNEL);
  425. if (WARN_ON(!xive_provision_chips))
  426. return false;
  427. rc = of_property_read_u32_array(np, "ibm,xive-provision-chips",
  428. xive_provision_chips,
  429. xive_provision_chip_count);
  430. if (rc < 0) {
  431. pr_err("Error %d reading provision chips array\n", rc);
  432. return false;
  433. }
  434. xive_provision_cache = kmem_cache_create("xive-provision",
  435. xive_provision_size,
  436. xive_provision_size,
  437. 0, NULL);
  438. if (!xive_provision_cache) {
  439. pr_err("Failed to allocate provision cache\n");
  440. return false;
  441. }
  442. return true;
  443. }
  444. static void xive_native_setup_pools(void)
  445. {
  446. /* Allocate a pool big enough */
  447. pr_debug("XIVE: Allocating VP block for pool size %u\n", nr_cpu_ids);
  448. xive_pool_vps = xive_native_alloc_vp_block(nr_cpu_ids);
  449. if (WARN_ON(xive_pool_vps == XIVE_INVALID_VP))
  450. pr_err("XIVE: Failed to allocate pool VP, KVM might not function\n");
  451. pr_debug("XIVE: Pool VPs allocated at 0x%x for %u max CPUs\n",
  452. xive_pool_vps, nr_cpu_ids);
  453. }
  454. u32 xive_native_default_eq_shift(void)
  455. {
  456. return xive_queue_shift;
  457. }
  458. EXPORT_SYMBOL_GPL(xive_native_default_eq_shift);
  459. bool __init xive_native_init(void)
  460. {
  461. struct device_node *np;
  462. struct resource r;
  463. void __iomem *tima;
  464. struct property *prop;
  465. u8 max_prio = 7;
  466. const __be32 *p;
  467. u32 val, cpu;
  468. s64 rc;
  469. if (xive_cmdline_disabled)
  470. return false;
  471. pr_devel("xive_native_init()\n");
  472. np = of_find_compatible_node(NULL, NULL, "ibm,opal-xive-pe");
  473. if (!np) {
  474. pr_devel("not found !\n");
  475. return false;
  476. }
  477. pr_devel("Found %pOF\n", np);
  478. /* Resource 1 is HV window */
  479. if (of_address_to_resource(np, 1, &r)) {
  480. pr_err("Failed to get thread mgmnt area resource\n");
  481. return false;
  482. }
  483. tima = ioremap(r.start, resource_size(&r));
  484. if (!tima) {
  485. pr_err("Failed to map thread mgmnt area\n");
  486. return false;
  487. }
  488. /* Read number of priorities */
  489. if (of_property_read_u32(np, "ibm,xive-#priorities", &val) == 0)
  490. max_prio = val - 1;
  491. /* Iterate the EQ sizes and pick one */
  492. of_property_for_each_u32(np, "ibm,xive-eq-sizes", prop, p, val) {
  493. xive_queue_shift = val;
  494. if (val == PAGE_SHIFT)
  495. break;
  496. }
  497. /* Configure Thread Management areas for KVM */
  498. for_each_possible_cpu(cpu)
  499. kvmppc_set_xive_tima(cpu, r.start, tima);
  500. /* Grab size of provisionning pages */
  501. xive_parse_provisioning(np);
  502. /* Switch the XIVE to exploitation mode */
  503. rc = opal_xive_reset(OPAL_XIVE_MODE_EXPL);
  504. if (rc) {
  505. pr_err("Switch to exploitation mode failed with error %lld\n", rc);
  506. return false;
  507. }
  508. /* Setup some dummy HV pool VPs */
  509. xive_native_setup_pools();
  510. /* Initialize XIVE core with our backend */
  511. if (!xive_core_init(&xive_native_ops, tima, TM_QW3_HV_PHYS,
  512. max_prio)) {
  513. opal_xive_reset(OPAL_XIVE_MODE_EMU);
  514. return false;
  515. }
  516. pr_info("Using %dkB queues\n", 1 << (xive_queue_shift - 10));
  517. return true;
  518. }
  519. static bool xive_native_provision_pages(void)
  520. {
  521. u32 i;
  522. void *p;
  523. for (i = 0; i < xive_provision_chip_count; i++) {
  524. u32 chip = xive_provision_chips[i];
  525. /*
  526. * XXX TODO: Try to make the allocation local to the node where
  527. * the chip resides.
  528. */
  529. p = kmem_cache_alloc(xive_provision_cache, GFP_KERNEL);
  530. if (!p) {
  531. pr_err("Failed to allocate provisioning page\n");
  532. return false;
  533. }
  534. opal_xive_donate_page(chip, __pa(p));
  535. }
  536. return true;
  537. }
  538. u32 xive_native_alloc_vp_block(u32 max_vcpus)
  539. {
  540. s64 rc;
  541. u32 order;
  542. order = fls(max_vcpus) - 1;
  543. if (max_vcpus > (1 << order))
  544. order++;
  545. pr_debug("VP block alloc, for max VCPUs %d use order %d\n",
  546. max_vcpus, order);
  547. for (;;) {
  548. rc = opal_xive_alloc_vp_block(order);
  549. switch (rc) {
  550. case OPAL_BUSY:
  551. msleep(1);
  552. break;
  553. case OPAL_XIVE_PROVISIONING:
  554. if (!xive_native_provision_pages())
  555. return XIVE_INVALID_VP;
  556. break;
  557. default:
  558. if (rc < 0) {
  559. pr_err("OPAL failed to allocate VCPUs order %d, err %lld\n",
  560. order, rc);
  561. return XIVE_INVALID_VP;
  562. }
  563. return rc;
  564. }
  565. }
  566. }
  567. EXPORT_SYMBOL_GPL(xive_native_alloc_vp_block);
  568. void xive_native_free_vp_block(u32 vp_base)
  569. {
  570. s64 rc;
  571. if (vp_base == XIVE_INVALID_VP)
  572. return;
  573. rc = opal_xive_free_vp_block(vp_base);
  574. if (rc < 0)
  575. pr_warn("OPAL error %lld freeing VP block\n", rc);
  576. }
  577. EXPORT_SYMBOL_GPL(xive_native_free_vp_block);
  578. int xive_native_enable_vp(u32 vp_id)
  579. {
  580. s64 rc;
  581. for (;;) {
  582. rc = opal_xive_set_vp_info(vp_id, OPAL_XIVE_VP_ENABLED, 0);
  583. if (rc != OPAL_BUSY)
  584. break;
  585. msleep(1);
  586. }
  587. return rc ? -EIO : 0;
  588. }
  589. EXPORT_SYMBOL_GPL(xive_native_enable_vp);
  590. int xive_native_disable_vp(u32 vp_id)
  591. {
  592. s64 rc;
  593. for (;;) {
  594. rc = opal_xive_set_vp_info(vp_id, 0, 0);
  595. if (rc != OPAL_BUSY)
  596. break;
  597. msleep(1);
  598. }
  599. return rc ? -EIO : 0;
  600. }
  601. EXPORT_SYMBOL_GPL(xive_native_disable_vp);
  602. int xive_native_get_vp_info(u32 vp_id, u32 *out_cam_id, u32 *out_chip_id)
  603. {
  604. __be64 vp_cam_be;
  605. __be32 vp_chip_id_be;
  606. s64 rc;
  607. rc = opal_xive_get_vp_info(vp_id, NULL, &vp_cam_be, NULL, &vp_chip_id_be);
  608. if (rc)
  609. return -EIO;
  610. *out_cam_id = be64_to_cpu(vp_cam_be) & 0xffffffffu;
  611. *out_chip_id = be32_to_cpu(vp_chip_id_be);
  612. return 0;
  613. }
  614. EXPORT_SYMBOL_GPL(xive_native_get_vp_info);