spapr.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. /*
  288. * No chip-id for the sPAPR backend. This has an impact how we
  289. * pick a target. See xive_pick_irq_target().
  290. */
  291. data->src_chip = XIVE_INVALID_CHIP_ID;
  292. data->eoi_mmio = ioremap(data->eoi_page, 1u << data->esb_shift);
  293. if (!data->eoi_mmio) {
  294. pr_err("Failed to map EOI page for irq 0x%x\n", hw_irq);
  295. return -ENOMEM;
  296. }
  297. data->hw_irq = hw_irq;
  298. /* Full function page supports trigger */
  299. if (flags & XIVE_SRC_TRIGGER) {
  300. data->trig_mmio = data->eoi_mmio;
  301. return 0;
  302. }
  303. data->trig_mmio = ioremap(data->trig_page, 1u << data->esb_shift);
  304. if (!data->trig_mmio) {
  305. pr_err("Failed to map trigger page for irq 0x%x\n", hw_irq);
  306. return -ENOMEM;
  307. }
  308. return 0;
  309. }
  310. static int xive_spapr_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq)
  311. {
  312. long rc;
  313. rc = plpar_int_set_source_config(XIVE_SRC_SET_EISN, hw_irq, target,
  314. prio, sw_irq);
  315. return rc == 0 ? 0 : -ENXIO;
  316. }
  317. /* This can be called multiple time to change a queue configuration */
  318. static int xive_spapr_configure_queue(u32 target, struct xive_q *q, u8 prio,
  319. __be32 *qpage, u32 order)
  320. {
  321. s64 rc = 0;
  322. unsigned long esn_page;
  323. unsigned long esn_size;
  324. u64 flags, qpage_phys;
  325. /* If there's an actual queue page, clean it */
  326. if (order) {
  327. if (WARN_ON(!qpage))
  328. return -EINVAL;
  329. qpage_phys = __pa(qpage);
  330. } else {
  331. qpage_phys = 0;
  332. }
  333. /* Initialize the rest of the fields */
  334. q->msk = order ? ((1u << (order - 2)) - 1) : 0;
  335. q->idx = 0;
  336. q->toggle = 0;
  337. rc = plpar_int_get_queue_info(0, target, prio, &esn_page, &esn_size);
  338. if (rc) {
  339. pr_err("Error %lld getting queue info CPU %d prio %d\n", rc,
  340. target, prio);
  341. rc = -EIO;
  342. goto fail;
  343. }
  344. /* TODO: add support for the notification page */
  345. q->eoi_phys = esn_page;
  346. /* Default is to always notify */
  347. flags = XIVE_EQ_ALWAYS_NOTIFY;
  348. /* Configure and enable the queue in HW */
  349. rc = plpar_int_set_queue_config(flags, target, prio, qpage_phys, order);
  350. if (rc) {
  351. pr_err("Error %lld setting queue for CPU %d prio %d\n", rc,
  352. target, prio);
  353. rc = -EIO;
  354. } else {
  355. q->qpage = qpage;
  356. }
  357. fail:
  358. return rc;
  359. }
  360. static int xive_spapr_setup_queue(unsigned int cpu, struct xive_cpu *xc,
  361. u8 prio)
  362. {
  363. struct xive_q *q = &xc->queue[prio];
  364. __be32 *qpage;
  365. qpage = xive_queue_page_alloc(cpu, xive_queue_shift);
  366. if (IS_ERR(qpage))
  367. return PTR_ERR(qpage);
  368. return xive_spapr_configure_queue(get_hard_smp_processor_id(cpu),
  369. q, prio, qpage, xive_queue_shift);
  370. }
  371. static void xive_spapr_cleanup_queue(unsigned int cpu, struct xive_cpu *xc,
  372. u8 prio)
  373. {
  374. struct xive_q *q = &xc->queue[prio];
  375. unsigned int alloc_order;
  376. long rc;
  377. int hw_cpu = get_hard_smp_processor_id(cpu);
  378. rc = plpar_int_set_queue_config(0, hw_cpu, prio, 0, 0);
  379. if (rc)
  380. pr_err("Error %ld setting queue for CPU %d prio %d\n", rc,
  381. hw_cpu, prio);
  382. alloc_order = xive_alloc_order(xive_queue_shift);
  383. free_pages((unsigned long)q->qpage, alloc_order);
  384. q->qpage = NULL;
  385. }
  386. static bool xive_spapr_match(struct device_node *node)
  387. {
  388. /* Ignore cascaded controllers for the moment */
  389. return 1;
  390. }
  391. #ifdef CONFIG_SMP
  392. static int xive_spapr_get_ipi(unsigned int cpu, struct xive_cpu *xc)
  393. {
  394. int irq = xive_irq_bitmap_alloc();
  395. if (irq < 0) {
  396. pr_err("Failed to allocate IPI on CPU %d\n", cpu);
  397. return -ENXIO;
  398. }
  399. xc->hw_ipi = irq;
  400. return 0;
  401. }
  402. static void xive_spapr_put_ipi(unsigned int cpu, struct xive_cpu *xc)
  403. {
  404. if (!xc->hw_ipi)
  405. return;
  406. xive_irq_bitmap_free(xc->hw_ipi);
  407. xc->hw_ipi = 0;
  408. }
  409. #endif /* CONFIG_SMP */
  410. static void xive_spapr_shutdown(void)
  411. {
  412. plpar_int_reset(0);
  413. }
  414. /*
  415. * Perform an "ack" cycle on the current thread. Grab the pending
  416. * active priorities and update the CPPR to the most favored one.
  417. */
  418. static void xive_spapr_update_pending(struct xive_cpu *xc)
  419. {
  420. u8 nsr, cppr;
  421. u16 ack;
  422. /*
  423. * Perform the "Acknowledge O/S to Register" cycle.
  424. *
  425. * Let's speedup the access to the TIMA using the raw I/O
  426. * accessor as we don't need the synchronisation routine of
  427. * the higher level ones
  428. */
  429. ack = be16_to_cpu(__raw_readw(xive_tima + TM_SPC_ACK_OS_REG));
  430. /* Synchronize subsequent queue accesses */
  431. mb();
  432. /*
  433. * Grab the CPPR and the "NSR" field which indicates the source
  434. * of the interrupt (if any)
  435. */
  436. cppr = ack & 0xff;
  437. nsr = ack >> 8;
  438. if (nsr & TM_QW1_NSR_EO) {
  439. if (cppr == 0xff)
  440. return;
  441. /* Mark the priority pending */
  442. xc->pending_prio |= 1 << cppr;
  443. /*
  444. * A new interrupt should never have a CPPR less favored
  445. * than our current one.
  446. */
  447. if (cppr >= xc->cppr)
  448. pr_err("CPU %d odd ack CPPR, got %d at %d\n",
  449. smp_processor_id(), cppr, xc->cppr);
  450. /* Update our idea of what the CPPR is */
  451. xc->cppr = cppr;
  452. }
  453. }
  454. static void xive_spapr_eoi(u32 hw_irq)
  455. {
  456. /* Not used */;
  457. }
  458. static void xive_spapr_setup_cpu(unsigned int cpu, struct xive_cpu *xc)
  459. {
  460. /* Only some debug on the TIMA settings */
  461. pr_debug("(HW value: %08x %08x %08x)\n",
  462. in_be32(xive_tima + TM_QW1_OS + TM_WORD0),
  463. in_be32(xive_tima + TM_QW1_OS + TM_WORD1),
  464. in_be32(xive_tima + TM_QW1_OS + TM_WORD2));
  465. }
  466. static void xive_spapr_teardown_cpu(unsigned int cpu, struct xive_cpu *xc)
  467. {
  468. /* Nothing to do */;
  469. }
  470. static void xive_spapr_sync_source(u32 hw_irq)
  471. {
  472. /* Specs are unclear on what this is doing */
  473. plpar_int_sync(0, hw_irq);
  474. }
  475. static const struct xive_ops xive_spapr_ops = {
  476. .populate_irq_data = xive_spapr_populate_irq_data,
  477. .configure_irq = xive_spapr_configure_irq,
  478. .setup_queue = xive_spapr_setup_queue,
  479. .cleanup_queue = xive_spapr_cleanup_queue,
  480. .match = xive_spapr_match,
  481. .shutdown = xive_spapr_shutdown,
  482. .update_pending = xive_spapr_update_pending,
  483. .eoi = xive_spapr_eoi,
  484. .setup_cpu = xive_spapr_setup_cpu,
  485. .teardown_cpu = xive_spapr_teardown_cpu,
  486. .sync_source = xive_spapr_sync_source,
  487. .esb_rw = xive_spapr_esb_rw,
  488. #ifdef CONFIG_SMP
  489. .get_ipi = xive_spapr_get_ipi,
  490. .put_ipi = xive_spapr_put_ipi,
  491. #endif /* CONFIG_SMP */
  492. .name = "spapr",
  493. };
  494. /*
  495. * get max priority from "/ibm,plat-res-int-priorities"
  496. */
  497. static bool xive_get_max_prio(u8 *max_prio)
  498. {
  499. struct device_node *rootdn;
  500. const __be32 *reg;
  501. u32 len;
  502. int prio, found;
  503. rootdn = of_find_node_by_path("/");
  504. if (!rootdn) {
  505. pr_err("not root node found !\n");
  506. return false;
  507. }
  508. reg = of_get_property(rootdn, "ibm,plat-res-int-priorities", &len);
  509. if (!reg) {
  510. pr_err("Failed to read 'ibm,plat-res-int-priorities' property\n");
  511. return false;
  512. }
  513. if (len % (2 * sizeof(u32)) != 0) {
  514. pr_err("invalid 'ibm,plat-res-int-priorities' property\n");
  515. return false;
  516. }
  517. /* HW supports priorities in the range [0-7] and 0xFF is a
  518. * wildcard priority used to mask. We scan the ranges reserved
  519. * by the hypervisor to find the lowest priority we can use.
  520. */
  521. found = 0xFF;
  522. for (prio = 0; prio < 8; prio++) {
  523. int reserved = 0;
  524. int i;
  525. for (i = 0; i < len / (2 * sizeof(u32)); i++) {
  526. int base = be32_to_cpu(reg[2 * i]);
  527. int range = be32_to_cpu(reg[2 * i + 1]);
  528. if (prio >= base && prio < base + range)
  529. reserved++;
  530. }
  531. if (!reserved)
  532. found = prio;
  533. }
  534. if (found == 0xFF) {
  535. pr_err("no valid priority found in 'ibm,plat-res-int-priorities'\n");
  536. return false;
  537. }
  538. *max_prio = found;
  539. return true;
  540. }
  541. bool __init xive_spapr_init(void)
  542. {
  543. struct device_node *np;
  544. struct resource r;
  545. void __iomem *tima;
  546. struct property *prop;
  547. u8 max_prio;
  548. u32 val;
  549. u32 len;
  550. const __be32 *reg;
  551. int i;
  552. if (xive_cmdline_disabled)
  553. return false;
  554. pr_devel("%s()\n", __func__);
  555. np = of_find_compatible_node(NULL, NULL, "ibm,power-ivpe");
  556. if (!np) {
  557. pr_devel("not found !\n");
  558. return false;
  559. }
  560. pr_devel("Found %s\n", np->full_name);
  561. /* Resource 1 is the OS ring TIMA */
  562. if (of_address_to_resource(np, 1, &r)) {
  563. pr_err("Failed to get thread mgmnt area resource\n");
  564. return false;
  565. }
  566. tima = ioremap(r.start, resource_size(&r));
  567. if (!tima) {
  568. pr_err("Failed to map thread mgmnt area\n");
  569. return false;
  570. }
  571. if (!xive_get_max_prio(&max_prio))
  572. return false;
  573. /* Feed the IRQ number allocator with the ranges given in the DT */
  574. reg = of_get_property(np, "ibm,xive-lisn-ranges", &len);
  575. if (!reg) {
  576. pr_err("Failed to read 'ibm,xive-lisn-ranges' property\n");
  577. return false;
  578. }
  579. if (len % (2 * sizeof(u32)) != 0) {
  580. pr_err("invalid 'ibm,xive-lisn-ranges' property\n");
  581. return false;
  582. }
  583. for (i = 0; i < len / (2 * sizeof(u32)); i++, reg += 2)
  584. xive_irq_bitmap_add(be32_to_cpu(reg[0]),
  585. be32_to_cpu(reg[1]));
  586. /* Iterate the EQ sizes and pick one */
  587. of_property_for_each_u32(np, "ibm,xive-eq-sizes", prop, reg, val) {
  588. xive_queue_shift = val;
  589. if (val == PAGE_SHIFT)
  590. break;
  591. }
  592. /* Initialize XIVE core with our backend */
  593. if (!xive_core_init(&xive_spapr_ops, tima, TM_QW1_OS, max_prio))
  594. return false;
  595. pr_info("Using %dkB queues\n", 1 << (xive_queue_shift - 10));
  596. return true;
  597. }