spapr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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/smp.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/init.h>
  15. #include <linux/of.h>
  16. #include <linux/slab.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/mm.h>
  20. #include <linux/delay.h>
  21. #include <asm/prom.h>
  22. #include <asm/io.h>
  23. #include <asm/smp.h>
  24. #include <asm/irq.h>
  25. #include <asm/errno.h>
  26. #include <asm/xive.h>
  27. #include <asm/xive-regs.h>
  28. #include <asm/hvcall.h>
  29. #include "xive-internal.h"
  30. static u32 xive_queue_shift;
  31. struct xive_irq_bitmap {
  32. unsigned long *bitmap;
  33. unsigned int base;
  34. unsigned int count;
  35. spinlock_t lock;
  36. struct list_head list;
  37. };
  38. static LIST_HEAD(xive_irq_bitmaps);
  39. static int xive_irq_bitmap_add(int base, int count)
  40. {
  41. struct xive_irq_bitmap *xibm;
  42. xibm = kzalloc(sizeof(*xibm), GFP_ATOMIC);
  43. if (!xibm)
  44. return -ENOMEM;
  45. spin_lock_init(&xibm->lock);
  46. xibm->base = base;
  47. xibm->count = count;
  48. xibm->bitmap = kzalloc(xibm->count, GFP_KERNEL);
  49. list_add(&xibm->list, &xive_irq_bitmaps);
  50. pr_info("Using IRQ range [%x-%x]", xibm->base,
  51. xibm->base + xibm->count - 1);
  52. return 0;
  53. }
  54. static int __xive_irq_bitmap_alloc(struct xive_irq_bitmap *xibm)
  55. {
  56. int irq;
  57. irq = find_first_zero_bit(xibm->bitmap, xibm->count);
  58. if (irq != xibm->count) {
  59. set_bit(irq, xibm->bitmap);
  60. irq += xibm->base;
  61. } else {
  62. irq = -ENOMEM;
  63. }
  64. return irq;
  65. }
  66. static int xive_irq_bitmap_alloc(void)
  67. {
  68. struct xive_irq_bitmap *xibm;
  69. unsigned long flags;
  70. int irq = -ENOENT;
  71. list_for_each_entry(xibm, &xive_irq_bitmaps, list) {
  72. spin_lock_irqsave(&xibm->lock, flags);
  73. irq = __xive_irq_bitmap_alloc(xibm);
  74. spin_unlock_irqrestore(&xibm->lock, flags);
  75. if (irq >= 0)
  76. break;
  77. }
  78. return irq;
  79. }
  80. static void xive_irq_bitmap_free(int irq)
  81. {
  82. unsigned long flags;
  83. struct xive_irq_bitmap *xibm;
  84. list_for_each_entry(xibm, &xive_irq_bitmaps, list) {
  85. if ((irq >= xibm->base) && (irq < xibm->base + xibm->count)) {
  86. spin_lock_irqsave(&xibm->lock, flags);
  87. clear_bit(irq - xibm->base, xibm->bitmap);
  88. spin_unlock_irqrestore(&xibm->lock, flags);
  89. break;
  90. }
  91. }
  92. }
  93. /* Based on the similar routines in RTAS */
  94. static unsigned int plpar_busy_delay_time(long rc)
  95. {
  96. unsigned int ms = 0;
  97. if (H_IS_LONG_BUSY(rc)) {
  98. ms = get_longbusy_msecs(rc);
  99. } else if (rc == H_BUSY) {
  100. ms = 10; /* seems appropriate for XIVE hcalls */
  101. }
  102. return ms;
  103. }
  104. static unsigned int plpar_busy_delay(int rc)
  105. {
  106. unsigned int ms;
  107. ms = plpar_busy_delay_time(rc);
  108. if (ms)
  109. mdelay(ms);
  110. return ms;
  111. }
  112. /*
  113. * Note: this call has a partition wide scope and can take a while to
  114. * complete. If it returns H_LONG_BUSY_* it should be retried
  115. * periodically.
  116. */
  117. static long plpar_int_reset(unsigned long flags)
  118. {
  119. long rc;
  120. do {
  121. rc = plpar_hcall_norets(H_INT_RESET, flags);
  122. } while (plpar_busy_delay(rc));
  123. if (rc)
  124. pr_err("H_INT_RESET failed %ld\n", rc);
  125. return rc;
  126. }
  127. static long plpar_int_get_source_info(unsigned long flags,
  128. unsigned long lisn,
  129. unsigned long *src_flags,
  130. unsigned long *eoi_page,
  131. unsigned long *trig_page,
  132. unsigned long *esb_shift)
  133. {
  134. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  135. long rc;
  136. do {
  137. rc = plpar_hcall(H_INT_GET_SOURCE_INFO, retbuf, flags, lisn);
  138. } while (plpar_busy_delay(rc));
  139. if (rc) {
  140. pr_err("H_INT_GET_SOURCE_INFO lisn=%ld failed %ld\n", lisn, rc);
  141. return rc;
  142. }
  143. *src_flags = retbuf[0];
  144. *eoi_page = retbuf[1];
  145. *trig_page = retbuf[2];
  146. *esb_shift = retbuf[3];
  147. pr_devel("H_INT_GET_SOURCE_INFO flags=%lx eoi=%lx trig=%lx shift=%lx\n",
  148. retbuf[0], retbuf[1], retbuf[2], retbuf[3]);
  149. return 0;
  150. }
  151. #define XIVE_SRC_SET_EISN (1ull << (63 - 62))
  152. #define XIVE_SRC_MASK (1ull << (63 - 63)) /* unused */
  153. static long plpar_int_set_source_config(unsigned long flags,
  154. unsigned long lisn,
  155. unsigned long target,
  156. unsigned long prio,
  157. unsigned long sw_irq)
  158. {
  159. long rc;
  160. pr_devel("H_INT_SET_SOURCE_CONFIG flags=%lx lisn=%lx target=%lx prio=%lx sw_irq=%lx\n",
  161. flags, lisn, target, prio, sw_irq);
  162. do {
  163. rc = plpar_hcall_norets(H_INT_SET_SOURCE_CONFIG, flags, lisn,
  164. target, prio, sw_irq);
  165. } while (plpar_busy_delay(rc));
  166. if (rc) {
  167. pr_err("H_INT_SET_SOURCE_CONFIG lisn=%ld target=%lx prio=%lx failed %ld\n",
  168. lisn, target, prio, rc);
  169. return rc;
  170. }
  171. return 0;
  172. }
  173. static long plpar_int_get_queue_info(unsigned long flags,
  174. unsigned long target,
  175. unsigned long priority,
  176. unsigned long *esn_page,
  177. unsigned long *esn_size)
  178. {
  179. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  180. long rc;
  181. do {
  182. rc = plpar_hcall(H_INT_GET_QUEUE_INFO, retbuf, flags, target,
  183. priority);
  184. } while (plpar_busy_delay(rc));
  185. if (rc) {
  186. pr_err("H_INT_GET_QUEUE_INFO cpu=%ld prio=%ld failed %ld\n",
  187. target, priority, rc);
  188. return rc;
  189. }
  190. *esn_page = retbuf[0];
  191. *esn_size = retbuf[1];
  192. pr_devel("H_INT_GET_QUEUE_INFO page=%lx size=%lx\n",
  193. retbuf[0], retbuf[1]);
  194. return 0;
  195. }
  196. #define XIVE_EQ_ALWAYS_NOTIFY (1ull << (63 - 63))
  197. static long plpar_int_set_queue_config(unsigned long flags,
  198. unsigned long target,
  199. unsigned long priority,
  200. unsigned long qpage,
  201. unsigned long qsize)
  202. {
  203. long rc;
  204. pr_devel("H_INT_SET_QUEUE_CONFIG flags=%lx target=%lx priority=%lx qpage=%lx qsize=%lx\n",
  205. flags, target, priority, qpage, qsize);
  206. do {
  207. rc = plpar_hcall_norets(H_INT_SET_QUEUE_CONFIG, flags, target,
  208. priority, qpage, qsize);
  209. } while (plpar_busy_delay(rc));
  210. if (rc) {
  211. pr_err("H_INT_SET_QUEUE_CONFIG cpu=%ld prio=%ld qpage=%lx returned %ld\n",
  212. target, priority, qpage, rc);
  213. return rc;
  214. }
  215. return 0;
  216. }
  217. static long plpar_int_sync(unsigned long flags, unsigned long lisn)
  218. {
  219. long rc;
  220. do {
  221. rc = plpar_hcall_norets(H_INT_SYNC, flags, lisn);
  222. } while (plpar_busy_delay(rc));
  223. if (rc) {
  224. pr_err("H_INT_SYNC lisn=%ld returned %ld\n", lisn, rc);
  225. return rc;
  226. }
  227. return 0;
  228. }
  229. #define XIVE_ESB_FLAG_STORE (1ull << (63 - 63))
  230. static long plpar_int_esb(unsigned long flags,
  231. unsigned long lisn,
  232. unsigned long offset,
  233. unsigned long in_data,
  234. unsigned long *out_data)
  235. {
  236. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  237. long rc;
  238. pr_devel("H_INT_ESB flags=%lx lisn=%lx offset=%lx in=%lx\n",
  239. flags, lisn, offset, in_data);
  240. do {
  241. rc = plpar_hcall(H_INT_ESB, retbuf, flags, lisn, offset,
  242. in_data);
  243. } while (plpar_busy_delay(rc));
  244. if (rc) {
  245. pr_err("H_INT_ESB lisn=%ld offset=%ld returned %ld\n",
  246. lisn, offset, rc);
  247. return rc;
  248. }
  249. *out_data = retbuf[0];
  250. return 0;
  251. }
  252. static u64 xive_spapr_esb_rw(u32 lisn, u32 offset, u64 data, bool write)
  253. {
  254. unsigned long read_data;
  255. long rc;
  256. rc = plpar_int_esb(write ? XIVE_ESB_FLAG_STORE : 0,
  257. lisn, offset, data, &read_data);
  258. if (rc)
  259. return -1;
  260. return write ? 0 : read_data;
  261. }
  262. #define XIVE_SRC_H_INT_ESB (1ull << (63 - 60))
  263. #define XIVE_SRC_LSI (1ull << (63 - 61))
  264. #define XIVE_SRC_TRIGGER (1ull << (63 - 62))
  265. #define XIVE_SRC_STORE_EOI (1ull << (63 - 63))
  266. static int xive_spapr_populate_irq_data(u32 hw_irq, struct xive_irq_data *data)
  267. {
  268. long rc;
  269. unsigned long flags;
  270. unsigned long eoi_page;
  271. unsigned long trig_page;
  272. unsigned long esb_shift;
  273. memset(data, 0, sizeof(*data));
  274. rc = plpar_int_get_source_info(0, hw_irq, &flags, &eoi_page, &trig_page,
  275. &esb_shift);
  276. if (rc)
  277. return -EINVAL;
  278. if (flags & XIVE_SRC_H_INT_ESB)
  279. data->flags |= XIVE_IRQ_FLAG_H_INT_ESB;
  280. if (flags & XIVE_SRC_STORE_EOI)
  281. data->flags |= XIVE_IRQ_FLAG_STORE_EOI;
  282. if (flags & XIVE_SRC_LSI)
  283. data->flags |= XIVE_IRQ_FLAG_LSI;
  284. data->eoi_page = eoi_page;
  285. data->esb_shift = esb_shift;
  286. data->trig_page = trig_page;
  287. data->hw_irq = hw_irq;
  288. /*
  289. * No chip-id for the sPAPR backend. This has an impact how we
  290. * pick a target. See xive_pick_irq_target().
  291. */
  292. data->src_chip = XIVE_INVALID_CHIP_ID;
  293. /*
  294. * When the H_INT_ESB flag is set, the H_INT_ESB hcall should
  295. * be used for interrupt management. Skip the remapping of the
  296. * ESB pages which are not available.
  297. */
  298. if (data->flags & XIVE_IRQ_FLAG_H_INT_ESB)
  299. return 0;
  300. data->eoi_mmio = ioremap(data->eoi_page, 1u << data->esb_shift);
  301. if (!data->eoi_mmio) {
  302. pr_err("Failed to map EOI page for irq 0x%x\n", hw_irq);
  303. return -ENOMEM;
  304. }
  305. /* Full function page supports trigger */
  306. if (flags & XIVE_SRC_TRIGGER) {
  307. data->trig_mmio = data->eoi_mmio;
  308. return 0;
  309. }
  310. data->trig_mmio = ioremap(data->trig_page, 1u << data->esb_shift);
  311. if (!data->trig_mmio) {
  312. pr_err("Failed to map trigger page for irq 0x%x\n", hw_irq);
  313. return -ENOMEM;
  314. }
  315. return 0;
  316. }
  317. static int xive_spapr_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq)
  318. {
  319. long rc;
  320. rc = plpar_int_set_source_config(XIVE_SRC_SET_EISN, hw_irq, target,
  321. prio, sw_irq);
  322. return rc == 0 ? 0 : -ENXIO;
  323. }
  324. /* This can be called multiple time to change a queue configuration */
  325. static int xive_spapr_configure_queue(u32 target, struct xive_q *q, u8 prio,
  326. __be32 *qpage, u32 order)
  327. {
  328. s64 rc = 0;
  329. unsigned long esn_page;
  330. unsigned long esn_size;
  331. u64 flags, qpage_phys;
  332. /* If there's an actual queue page, clean it */
  333. if (order) {
  334. if (WARN_ON(!qpage))
  335. return -EINVAL;
  336. qpage_phys = __pa(qpage);
  337. } else {
  338. qpage_phys = 0;
  339. }
  340. /* Initialize the rest of the fields */
  341. q->msk = order ? ((1u << (order - 2)) - 1) : 0;
  342. q->idx = 0;
  343. q->toggle = 0;
  344. rc = plpar_int_get_queue_info(0, target, prio, &esn_page, &esn_size);
  345. if (rc) {
  346. pr_err("Error %lld getting queue info CPU %d prio %d\n", rc,
  347. target, prio);
  348. rc = -EIO;
  349. goto fail;
  350. }
  351. /* TODO: add support for the notification page */
  352. q->eoi_phys = esn_page;
  353. /* Default is to always notify */
  354. flags = XIVE_EQ_ALWAYS_NOTIFY;
  355. /* Configure and enable the queue in HW */
  356. rc = plpar_int_set_queue_config(flags, target, prio, qpage_phys, order);
  357. if (rc) {
  358. pr_err("Error %lld setting queue for CPU %d prio %d\n", rc,
  359. target, prio);
  360. rc = -EIO;
  361. } else {
  362. q->qpage = qpage;
  363. }
  364. fail:
  365. return rc;
  366. }
  367. static int xive_spapr_setup_queue(unsigned int cpu, struct xive_cpu *xc,
  368. u8 prio)
  369. {
  370. struct xive_q *q = &xc->queue[prio];
  371. __be32 *qpage;
  372. qpage = xive_queue_page_alloc(cpu, xive_queue_shift);
  373. if (IS_ERR(qpage))
  374. return PTR_ERR(qpage);
  375. return xive_spapr_configure_queue(get_hard_smp_processor_id(cpu),
  376. q, prio, qpage, xive_queue_shift);
  377. }
  378. static void xive_spapr_cleanup_queue(unsigned int cpu, struct xive_cpu *xc,
  379. u8 prio)
  380. {
  381. struct xive_q *q = &xc->queue[prio];
  382. unsigned int alloc_order;
  383. long rc;
  384. int hw_cpu = get_hard_smp_processor_id(cpu);
  385. rc = plpar_int_set_queue_config(0, hw_cpu, prio, 0, 0);
  386. if (rc)
  387. pr_err("Error %ld setting queue for CPU %d prio %d\n", rc,
  388. hw_cpu, prio);
  389. alloc_order = xive_alloc_order(xive_queue_shift);
  390. free_pages((unsigned long)q->qpage, alloc_order);
  391. q->qpage = NULL;
  392. }
  393. static bool xive_spapr_match(struct device_node *node)
  394. {
  395. /* Ignore cascaded controllers for the moment */
  396. return 1;
  397. }
  398. #ifdef CONFIG_SMP
  399. static int xive_spapr_get_ipi(unsigned int cpu, struct xive_cpu *xc)
  400. {
  401. int irq = xive_irq_bitmap_alloc();
  402. if (irq < 0) {
  403. pr_err("Failed to allocate IPI on CPU %d\n", cpu);
  404. return -ENXIO;
  405. }
  406. xc->hw_ipi = irq;
  407. return 0;
  408. }
  409. static void xive_spapr_put_ipi(unsigned int cpu, struct xive_cpu *xc)
  410. {
  411. if (xc->hw_ipi == XIVE_BAD_IRQ)
  412. return;
  413. xive_irq_bitmap_free(xc->hw_ipi);
  414. xc->hw_ipi = XIVE_BAD_IRQ;
  415. }
  416. #endif /* CONFIG_SMP */
  417. static void xive_spapr_shutdown(void)
  418. {
  419. plpar_int_reset(0);
  420. }
  421. /*
  422. * Perform an "ack" cycle on the current thread. Grab the pending
  423. * active priorities and update the CPPR to the most favored one.
  424. */
  425. static void xive_spapr_update_pending(struct xive_cpu *xc)
  426. {
  427. u8 nsr, cppr;
  428. u16 ack;
  429. /*
  430. * Perform the "Acknowledge O/S to Register" cycle.
  431. *
  432. * Let's speedup the access to the TIMA using the raw I/O
  433. * accessor as we don't need the synchronisation routine of
  434. * the higher level ones
  435. */
  436. ack = be16_to_cpu(__raw_readw(xive_tima + TM_SPC_ACK_OS_REG));
  437. /* Synchronize subsequent queue accesses */
  438. mb();
  439. /*
  440. * Grab the CPPR and the "NSR" field which indicates the source
  441. * of the interrupt (if any)
  442. */
  443. cppr = ack & 0xff;
  444. nsr = ack >> 8;
  445. if (nsr & TM_QW1_NSR_EO) {
  446. if (cppr == 0xff)
  447. return;
  448. /* Mark the priority pending */
  449. xc->pending_prio |= 1 << cppr;
  450. /*
  451. * A new interrupt should never have a CPPR less favored
  452. * than our current one.
  453. */
  454. if (cppr >= xc->cppr)
  455. pr_err("CPU %d odd ack CPPR, got %d at %d\n",
  456. smp_processor_id(), cppr, xc->cppr);
  457. /* Update our idea of what the CPPR is */
  458. xc->cppr = cppr;
  459. }
  460. }
  461. static void xive_spapr_eoi(u32 hw_irq)
  462. {
  463. /* Not used */;
  464. }
  465. static void xive_spapr_setup_cpu(unsigned int cpu, struct xive_cpu *xc)
  466. {
  467. /* Only some debug on the TIMA settings */
  468. pr_debug("(HW value: %08x %08x %08x)\n",
  469. in_be32(xive_tima + TM_QW1_OS + TM_WORD0),
  470. in_be32(xive_tima + TM_QW1_OS + TM_WORD1),
  471. in_be32(xive_tima + TM_QW1_OS + TM_WORD2));
  472. }
  473. static void xive_spapr_teardown_cpu(unsigned int cpu, struct xive_cpu *xc)
  474. {
  475. /* Nothing to do */;
  476. }
  477. static void xive_spapr_sync_source(u32 hw_irq)
  478. {
  479. /* Specs are unclear on what this is doing */
  480. plpar_int_sync(0, hw_irq);
  481. }
  482. static const struct xive_ops xive_spapr_ops = {
  483. .populate_irq_data = xive_spapr_populate_irq_data,
  484. .configure_irq = xive_spapr_configure_irq,
  485. .setup_queue = xive_spapr_setup_queue,
  486. .cleanup_queue = xive_spapr_cleanup_queue,
  487. .match = xive_spapr_match,
  488. .shutdown = xive_spapr_shutdown,
  489. .update_pending = xive_spapr_update_pending,
  490. .eoi = xive_spapr_eoi,
  491. .setup_cpu = xive_spapr_setup_cpu,
  492. .teardown_cpu = xive_spapr_teardown_cpu,
  493. .sync_source = xive_spapr_sync_source,
  494. .esb_rw = xive_spapr_esb_rw,
  495. #ifdef CONFIG_SMP
  496. .get_ipi = xive_spapr_get_ipi,
  497. .put_ipi = xive_spapr_put_ipi,
  498. #endif /* CONFIG_SMP */
  499. .name = "spapr",
  500. };
  501. /*
  502. * get max priority from "/ibm,plat-res-int-priorities"
  503. */
  504. static bool xive_get_max_prio(u8 *max_prio)
  505. {
  506. struct device_node *rootdn;
  507. const __be32 *reg;
  508. u32 len;
  509. int prio, found;
  510. rootdn = of_find_node_by_path("/");
  511. if (!rootdn) {
  512. pr_err("not root node found !\n");
  513. return false;
  514. }
  515. reg = of_get_property(rootdn, "ibm,plat-res-int-priorities", &len);
  516. if (!reg) {
  517. pr_err("Failed to read 'ibm,plat-res-int-priorities' property\n");
  518. return false;
  519. }
  520. if (len % (2 * sizeof(u32)) != 0) {
  521. pr_err("invalid 'ibm,plat-res-int-priorities' property\n");
  522. return false;
  523. }
  524. /* HW supports priorities in the range [0-7] and 0xFF is a
  525. * wildcard priority used to mask. We scan the ranges reserved
  526. * by the hypervisor to find the lowest priority we can use.
  527. */
  528. found = 0xFF;
  529. for (prio = 0; prio < 8; prio++) {
  530. int reserved = 0;
  531. int i;
  532. for (i = 0; i < len / (2 * sizeof(u32)); i++) {
  533. int base = be32_to_cpu(reg[2 * i]);
  534. int range = be32_to_cpu(reg[2 * i + 1]);
  535. if (prio >= base && prio < base + range)
  536. reserved++;
  537. }
  538. if (!reserved)
  539. found = prio;
  540. }
  541. if (found == 0xFF) {
  542. pr_err("no valid priority found in 'ibm,plat-res-int-priorities'\n");
  543. return false;
  544. }
  545. *max_prio = found;
  546. return true;
  547. }
  548. bool __init xive_spapr_init(void)
  549. {
  550. struct device_node *np;
  551. struct resource r;
  552. void __iomem *tima;
  553. struct property *prop;
  554. u8 max_prio;
  555. u32 val;
  556. u32 len;
  557. const __be32 *reg;
  558. int i;
  559. if (xive_cmdline_disabled)
  560. return false;
  561. pr_devel("%s()\n", __func__);
  562. np = of_find_compatible_node(NULL, NULL, "ibm,power-ivpe");
  563. if (!np) {
  564. pr_devel("not found !\n");
  565. return false;
  566. }
  567. pr_devel("Found %s\n", np->full_name);
  568. /* Resource 1 is the OS ring TIMA */
  569. if (of_address_to_resource(np, 1, &r)) {
  570. pr_err("Failed to get thread mgmnt area resource\n");
  571. return false;
  572. }
  573. tima = ioremap(r.start, resource_size(&r));
  574. if (!tima) {
  575. pr_err("Failed to map thread mgmnt area\n");
  576. return false;
  577. }
  578. if (!xive_get_max_prio(&max_prio))
  579. return false;
  580. /* Feed the IRQ number allocator with the ranges given in the DT */
  581. reg = of_get_property(np, "ibm,xive-lisn-ranges", &len);
  582. if (!reg) {
  583. pr_err("Failed to read 'ibm,xive-lisn-ranges' property\n");
  584. return false;
  585. }
  586. if (len % (2 * sizeof(u32)) != 0) {
  587. pr_err("invalid 'ibm,xive-lisn-ranges' property\n");
  588. return false;
  589. }
  590. for (i = 0; i < len / (2 * sizeof(u32)); i++, reg += 2)
  591. xive_irq_bitmap_add(be32_to_cpu(reg[0]),
  592. be32_to_cpu(reg[1]));
  593. /* Iterate the EQ sizes and pick one */
  594. of_property_for_each_u32(np, "ibm,xive-eq-sizes", prop, reg, val) {
  595. xive_queue_shift = val;
  596. if (val == PAGE_SHIFT)
  597. break;
  598. }
  599. /* Initialize XIVE core with our backend */
  600. if (!xive_core_init(&xive_spapr_ops, tima, TM_QW1_OS, max_prio))
  601. return false;
  602. pr_info("Using %dkB queues\n", 1 << (xive_queue_shift - 10));
  603. return true;
  604. }