interrupt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * PS3 interrupt routines.
  4. *
  5. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  6. * Copyright 2006 Sony Corp.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/export.h>
  10. #include <linux/irq.h>
  11. #include <linux/irqdomain.h>
  12. #include <asm/machdep.h>
  13. #include <asm/udbg.h>
  14. #include <asm/lv1call.h>
  15. #include <asm/smp.h>
  16. #include "platform.h"
  17. #if defined(DEBUG)
  18. #define DBG udbg_printf
  19. #define FAIL udbg_printf
  20. #else
  21. #define DBG pr_devel
  22. #define FAIL pr_debug
  23. #endif
  24. /**
  25. * struct ps3_bmp - a per cpu irq status and mask bitmap structure
  26. * @status: 256 bit status bitmap indexed by plug
  27. * @unused_1: Alignment
  28. * @mask: 256 bit mask bitmap indexed by plug
  29. * @unused_2: Alignment
  30. *
  31. * The HV maintains per SMT thread mappings of HV outlet to HV plug on
  32. * behalf of the guest. These mappings are implemented as 256 bit guest
  33. * supplied bitmaps indexed by plug number. The addresses of the bitmaps
  34. * are registered with the HV through lv1_configure_irq_state_bitmap().
  35. * The HV requires that the 512 bits of status + mask not cross a page
  36. * boundary. PS3_BMP_MINALIGN is used to define this minimal 64 byte
  37. * alignment.
  38. *
  39. * The HV supports 256 plugs per thread, assigned as {0..255}, for a total
  40. * of 512 plugs supported on a processor. To simplify the logic this
  41. * implementation equates HV plug value to Linux virq value, constrains each
  42. * interrupt to have a system wide unique plug number, and limits the range
  43. * of the plug values to map into the first dword of the bitmaps. This
  44. * gives a usable range of plug values of {NR_IRQS_LEGACY..63}. Note
  45. * that there is no constraint on how many in this set an individual thread
  46. * can acquire.
  47. *
  48. * The mask is declared as unsigned long so we can use set/clear_bit on it.
  49. */
  50. #define PS3_BMP_MINALIGN 64
  51. struct ps3_bmp {
  52. struct {
  53. u64 status;
  54. u64 unused_1[3];
  55. unsigned long mask;
  56. u64 unused_2[3];
  57. };
  58. };
  59. /**
  60. * struct ps3_private - a per cpu data structure
  61. * @bmp: ps3_bmp structure
  62. * @bmp_lock: Synchronize access to bmp.
  63. * @ipi_debug_brk_mask: Mask for debug break IPIs
  64. * @ppe_id: HV logical_ppe_id
  65. * @thread_id: HV thread_id
  66. * @ipi_mask: Mask of IPI virqs
  67. */
  68. struct ps3_private {
  69. struct ps3_bmp bmp __attribute__ ((aligned (PS3_BMP_MINALIGN)));
  70. spinlock_t bmp_lock;
  71. u64 ppe_id;
  72. u64 thread_id;
  73. unsigned long ipi_debug_brk_mask;
  74. unsigned long ipi_mask;
  75. };
  76. static DEFINE_PER_CPU(struct ps3_private, ps3_private);
  77. /**
  78. * ps3_chip_mask - Set an interrupt mask bit in ps3_bmp.
  79. * @virq: The assigned Linux virq.
  80. *
  81. * Sets ps3_bmp.mask and calls lv1_did_update_interrupt_mask().
  82. */
  83. static void ps3_chip_mask(struct irq_data *d)
  84. {
  85. struct ps3_private *pd = irq_data_get_irq_chip_data(d);
  86. unsigned long flags;
  87. DBG("%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__,
  88. pd->thread_id, d->irq);
  89. local_irq_save(flags);
  90. clear_bit(63 - d->irq, &pd->bmp.mask);
  91. lv1_did_update_interrupt_mask(pd->ppe_id, pd->thread_id);
  92. local_irq_restore(flags);
  93. }
  94. /**
  95. * ps3_chip_unmask - Clear an interrupt mask bit in ps3_bmp.
  96. * @virq: The assigned Linux virq.
  97. *
  98. * Clears ps3_bmp.mask and calls lv1_did_update_interrupt_mask().
  99. */
  100. static void ps3_chip_unmask(struct irq_data *d)
  101. {
  102. struct ps3_private *pd = irq_data_get_irq_chip_data(d);
  103. unsigned long flags;
  104. DBG("%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__,
  105. pd->thread_id, d->irq);
  106. local_irq_save(flags);
  107. set_bit(63 - d->irq, &pd->bmp.mask);
  108. lv1_did_update_interrupt_mask(pd->ppe_id, pd->thread_id);
  109. local_irq_restore(flags);
  110. }
  111. /**
  112. * ps3_chip_eoi - HV end-of-interrupt.
  113. * @virq: The assigned Linux virq.
  114. *
  115. * Calls lv1_end_of_interrupt_ext().
  116. */
  117. static void ps3_chip_eoi(struct irq_data *d)
  118. {
  119. const struct ps3_private *pd = irq_data_get_irq_chip_data(d);
  120. /* non-IPIs are EOIed here. */
  121. if (!test_bit(63 - d->irq, &pd->ipi_mask))
  122. lv1_end_of_interrupt_ext(pd->ppe_id, pd->thread_id, d->irq);
  123. }
  124. /**
  125. * ps3_irq_chip - Represents the ps3_bmp as a Linux struct irq_chip.
  126. */
  127. static struct irq_chip ps3_irq_chip = {
  128. .name = "ps3",
  129. .irq_mask = ps3_chip_mask,
  130. .irq_unmask = ps3_chip_unmask,
  131. .irq_eoi = ps3_chip_eoi,
  132. };
  133. /**
  134. * ps3_virq_setup - virq related setup.
  135. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  136. * serviced on.
  137. * @outlet: The HV outlet from the various create outlet routines.
  138. * @virq: The assigned Linux virq.
  139. *
  140. * Calls irq_create_mapping() to get a virq and sets the chip data to
  141. * ps3_private data.
  142. */
  143. static int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  144. unsigned int *virq)
  145. {
  146. int result;
  147. struct ps3_private *pd;
  148. /* This defines the default interrupt distribution policy. */
  149. if (cpu == PS3_BINDING_CPU_ANY)
  150. cpu = 0;
  151. pd = &per_cpu(ps3_private, cpu);
  152. *virq = irq_create_mapping(NULL, outlet);
  153. if (!*virq) {
  154. FAIL("%s:%d: irq_create_mapping failed: outlet %lu\n",
  155. __func__, __LINE__, outlet);
  156. result = -ENOMEM;
  157. goto fail_create;
  158. }
  159. DBG("%s:%d: outlet %lu => cpu %u, virq %u\n", __func__, __LINE__,
  160. outlet, cpu, *virq);
  161. result = irq_set_chip_data(*virq, pd);
  162. if (result) {
  163. FAIL("%s:%d: irq_set_chip_data failed\n",
  164. __func__, __LINE__);
  165. goto fail_set;
  166. }
  167. ps3_chip_mask(irq_get_irq_data(*virq));
  168. return result;
  169. fail_set:
  170. irq_dispose_mapping(*virq);
  171. fail_create:
  172. return result;
  173. }
  174. /**
  175. * ps3_virq_destroy - virq related teardown.
  176. * @virq: The assigned Linux virq.
  177. *
  178. * Clears chip data and calls irq_dispose_mapping() for the virq.
  179. */
  180. static int ps3_virq_destroy(unsigned int virq)
  181. {
  182. const struct ps3_private *pd = irq_get_chip_data(virq);
  183. DBG("%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__,
  184. __LINE__, pd->ppe_id, pd->thread_id, virq);
  185. irq_set_chip_data(virq, NULL);
  186. irq_dispose_mapping(virq);
  187. DBG("%s:%d <-\n", __func__, __LINE__);
  188. return 0;
  189. }
  190. /**
  191. * ps3_irq_plug_setup - Generic outlet and virq related setup.
  192. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  193. * serviced on.
  194. * @outlet: The HV outlet from the various create outlet routines.
  195. * @virq: The assigned Linux virq.
  196. *
  197. * Sets up virq and connects the irq plug.
  198. */
  199. int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  200. unsigned int *virq)
  201. {
  202. int result;
  203. struct ps3_private *pd;
  204. result = ps3_virq_setup(cpu, outlet, virq);
  205. if (result) {
  206. FAIL("%s:%d: ps3_virq_setup failed\n", __func__, __LINE__);
  207. goto fail_setup;
  208. }
  209. pd = irq_get_chip_data(*virq);
  210. /* Binds outlet to cpu + virq. */
  211. result = lv1_connect_irq_plug_ext(pd->ppe_id, pd->thread_id, *virq,
  212. outlet, 0);
  213. if (result) {
  214. FAIL("%s:%d: lv1_connect_irq_plug_ext failed: %s\n",
  215. __func__, __LINE__, ps3_result(result));
  216. result = -EPERM;
  217. goto fail_connect;
  218. }
  219. return result;
  220. fail_connect:
  221. ps3_virq_destroy(*virq);
  222. fail_setup:
  223. return result;
  224. }
  225. EXPORT_SYMBOL_GPL(ps3_irq_plug_setup);
  226. /**
  227. * ps3_irq_plug_destroy - Generic outlet and virq related teardown.
  228. * @virq: The assigned Linux virq.
  229. *
  230. * Disconnects the irq plug and tears down virq.
  231. * Do not call for system bus event interrupts setup with
  232. * ps3_sb_event_receive_port_setup().
  233. */
  234. int ps3_irq_plug_destroy(unsigned int virq)
  235. {
  236. int result;
  237. const struct ps3_private *pd = irq_get_chip_data(virq);
  238. DBG("%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__,
  239. __LINE__, pd->ppe_id, pd->thread_id, virq);
  240. ps3_chip_mask(irq_get_irq_data(virq));
  241. result = lv1_disconnect_irq_plug_ext(pd->ppe_id, pd->thread_id, virq);
  242. if (result)
  243. FAIL("%s:%d: lv1_disconnect_irq_plug_ext failed: %s\n",
  244. __func__, __LINE__, ps3_result(result));
  245. ps3_virq_destroy(virq);
  246. return result;
  247. }
  248. EXPORT_SYMBOL_GPL(ps3_irq_plug_destroy);
  249. /**
  250. * ps3_event_receive_port_setup - Setup an event receive port.
  251. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  252. * serviced on.
  253. * @virq: The assigned Linux virq.
  254. *
  255. * The virq can be used with lv1_connect_interrupt_event_receive_port() to
  256. * arrange to receive interrupts from system-bus devices, or with
  257. * ps3_send_event_locally() to signal events.
  258. */
  259. int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq)
  260. {
  261. int result;
  262. u64 outlet;
  263. result = lv1_construct_event_receive_port(&outlet);
  264. if (result) {
  265. FAIL("%s:%d: lv1_construct_event_receive_port failed: %s\n",
  266. __func__, __LINE__, ps3_result(result));
  267. *virq = 0;
  268. return result;
  269. }
  270. result = ps3_irq_plug_setup(cpu, outlet, virq);
  271. BUG_ON(result);
  272. return result;
  273. }
  274. EXPORT_SYMBOL_GPL(ps3_event_receive_port_setup);
  275. /**
  276. * ps3_event_receive_port_destroy - Destroy an event receive port.
  277. * @virq: The assigned Linux virq.
  278. *
  279. * Since ps3_event_receive_port_destroy destroys the receive port outlet,
  280. * SB devices need to call disconnect_interrupt_event_receive_port() before
  281. * this.
  282. */
  283. int ps3_event_receive_port_destroy(unsigned int virq)
  284. {
  285. int result;
  286. DBG(" -> %s:%d virq %u\n", __func__, __LINE__, virq);
  287. ps3_chip_mask(irq_get_irq_data(virq));
  288. result = lv1_destruct_event_receive_port(virq_to_hw(virq));
  289. if (result)
  290. FAIL("%s:%d: lv1_destruct_event_receive_port failed: %s\n",
  291. __func__, __LINE__, ps3_result(result));
  292. /*
  293. * Don't call ps3_virq_destroy() here since ps3_smp_cleanup_cpu()
  294. * calls from interrupt context (smp_call_function) when kexecing.
  295. */
  296. DBG(" <- %s:%d\n", __func__, __LINE__);
  297. return result;
  298. }
  299. int ps3_send_event_locally(unsigned int virq)
  300. {
  301. return lv1_send_event_locally(virq_to_hw(virq));
  302. }
  303. /**
  304. * ps3_sb_event_receive_port_setup - Setup a system bus event receive port.
  305. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  306. * serviced on.
  307. * @dev: The system bus device instance.
  308. * @virq: The assigned Linux virq.
  309. *
  310. * An event irq represents a virtual device interrupt. The interrupt_id
  311. * coresponds to the software interrupt number.
  312. */
  313. int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev,
  314. enum ps3_cpu_binding cpu, unsigned int *virq)
  315. {
  316. /* this should go in system-bus.c */
  317. int result;
  318. result = ps3_event_receive_port_setup(cpu, virq);
  319. if (result)
  320. return result;
  321. result = lv1_connect_interrupt_event_receive_port(dev->bus_id,
  322. dev->dev_id, virq_to_hw(*virq), dev->interrupt_id);
  323. if (result) {
  324. FAIL("%s:%d: lv1_connect_interrupt_event_receive_port"
  325. " failed: %s\n", __func__, __LINE__,
  326. ps3_result(result));
  327. ps3_event_receive_port_destroy(*virq);
  328. *virq = 0;
  329. return result;
  330. }
  331. DBG("%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
  332. dev->interrupt_id, *virq);
  333. return 0;
  334. }
  335. EXPORT_SYMBOL(ps3_sb_event_receive_port_setup);
  336. int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev,
  337. unsigned int virq)
  338. {
  339. /* this should go in system-bus.c */
  340. int result;
  341. DBG(" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
  342. dev->interrupt_id, virq);
  343. result = lv1_disconnect_interrupt_event_receive_port(dev->bus_id,
  344. dev->dev_id, virq_to_hw(virq), dev->interrupt_id);
  345. if (result)
  346. FAIL("%s:%d: lv1_disconnect_interrupt_event_receive_port"
  347. " failed: %s\n", __func__, __LINE__,
  348. ps3_result(result));
  349. result = ps3_event_receive_port_destroy(virq);
  350. BUG_ON(result);
  351. /*
  352. * ps3_event_receive_port_destroy() destroys the IRQ plug,
  353. * so don't call ps3_irq_plug_destroy() here.
  354. */
  355. result = ps3_virq_destroy(virq);
  356. BUG_ON(result);
  357. DBG(" <- %s:%d\n", __func__, __LINE__);
  358. return result;
  359. }
  360. EXPORT_SYMBOL(ps3_sb_event_receive_port_destroy);
  361. /**
  362. * ps3_io_irq_setup - Setup a system bus io irq.
  363. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  364. * serviced on.
  365. * @interrupt_id: The device interrupt id read from the system repository.
  366. * @virq: The assigned Linux virq.
  367. *
  368. * An io irq represents a non-virtualized device interrupt. interrupt_id
  369. * coresponds to the interrupt number of the interrupt controller.
  370. */
  371. int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
  372. unsigned int *virq)
  373. {
  374. int result;
  375. u64 outlet;
  376. result = lv1_construct_io_irq_outlet(interrupt_id, &outlet);
  377. if (result) {
  378. FAIL("%s:%d: lv1_construct_io_irq_outlet failed: %s\n",
  379. __func__, __LINE__, ps3_result(result));
  380. return result;
  381. }
  382. result = ps3_irq_plug_setup(cpu, outlet, virq);
  383. BUG_ON(result);
  384. return result;
  385. }
  386. EXPORT_SYMBOL_GPL(ps3_io_irq_setup);
  387. int ps3_io_irq_destroy(unsigned int virq)
  388. {
  389. int result;
  390. unsigned long outlet = virq_to_hw(virq);
  391. ps3_chip_mask(irq_get_irq_data(virq));
  392. /*
  393. * lv1_destruct_io_irq_outlet() will destroy the IRQ plug,
  394. * so call ps3_irq_plug_destroy() first.
  395. */
  396. result = ps3_irq_plug_destroy(virq);
  397. BUG_ON(result);
  398. result = lv1_destruct_io_irq_outlet(outlet);
  399. if (result)
  400. FAIL("%s:%d: lv1_destruct_io_irq_outlet failed: %s\n",
  401. __func__, __LINE__, ps3_result(result));
  402. return result;
  403. }
  404. EXPORT_SYMBOL_GPL(ps3_io_irq_destroy);
  405. /**
  406. * ps3_vuart_irq_setup - Setup the system virtual uart virq.
  407. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  408. * serviced on.
  409. * @virt_addr_bmp: The caller supplied virtual uart interrupt bitmap.
  410. * @virq: The assigned Linux virq.
  411. *
  412. * The system supports only a single virtual uart, so multiple calls without
  413. * freeing the interrupt will return a wrong state error.
  414. */
  415. int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
  416. unsigned int *virq)
  417. {
  418. int result;
  419. u64 outlet;
  420. u64 lpar_addr;
  421. BUG_ON(!is_kernel_addr((u64)virt_addr_bmp));
  422. lpar_addr = ps3_mm_phys_to_lpar(__pa(virt_addr_bmp));
  423. result = lv1_configure_virtual_uart_irq(lpar_addr, &outlet);
  424. if (result) {
  425. FAIL("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
  426. __func__, __LINE__, ps3_result(result));
  427. return result;
  428. }
  429. result = ps3_irq_plug_setup(cpu, outlet, virq);
  430. BUG_ON(result);
  431. return result;
  432. }
  433. EXPORT_SYMBOL_GPL(ps3_vuart_irq_setup);
  434. int ps3_vuart_irq_destroy(unsigned int virq)
  435. {
  436. int result;
  437. ps3_chip_mask(irq_get_irq_data(virq));
  438. result = lv1_deconfigure_virtual_uart_irq();
  439. if (result) {
  440. FAIL("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
  441. __func__, __LINE__, ps3_result(result));
  442. return result;
  443. }
  444. result = ps3_irq_plug_destroy(virq);
  445. BUG_ON(result);
  446. return result;
  447. }
  448. EXPORT_SYMBOL_GPL(ps3_vuart_irq_destroy);
  449. /**
  450. * ps3_spe_irq_setup - Setup an spe virq.
  451. * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
  452. * serviced on.
  453. * @spe_id: The spe_id returned from lv1_construct_logical_spe().
  454. * @class: The spe interrupt class {0,1,2}.
  455. * @virq: The assigned Linux virq.
  456. *
  457. */
  458. int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
  459. unsigned int class, unsigned int *virq)
  460. {
  461. int result;
  462. u64 outlet;
  463. BUG_ON(class > 2);
  464. result = lv1_get_spe_irq_outlet(spe_id, class, &outlet);
  465. if (result) {
  466. FAIL("%s:%d: lv1_get_spe_irq_outlet failed: %s\n",
  467. __func__, __LINE__, ps3_result(result));
  468. return result;
  469. }
  470. result = ps3_irq_plug_setup(cpu, outlet, virq);
  471. BUG_ON(result);
  472. return result;
  473. }
  474. int ps3_spe_irq_destroy(unsigned int virq)
  475. {
  476. int result;
  477. ps3_chip_mask(irq_get_irq_data(virq));
  478. result = ps3_irq_plug_destroy(virq);
  479. BUG_ON(result);
  480. return result;
  481. }
  482. #define PS3_INVALID_OUTLET ((irq_hw_number_t)-1)
  483. #define PS3_PLUG_MAX 63
  484. #if defined(DEBUG)
  485. static void _dump_64_bmp(const char *header, const u64 *p, unsigned cpu,
  486. const char* func, int line)
  487. {
  488. pr_debug("%s:%d: %s %u {%04llx_%04llx_%04llx_%04llx}\n",
  489. func, line, header, cpu,
  490. *p >> 48, (*p >> 32) & 0xffff, (*p >> 16) & 0xffff,
  491. *p & 0xffff);
  492. }
  493. static void __maybe_unused _dump_256_bmp(const char *header,
  494. const u64 *p, unsigned cpu, const char* func, int line)
  495. {
  496. pr_debug("%s:%d: %s %u {%016llx:%016llx:%016llx:%016llx}\n",
  497. func, line, header, cpu, p[0], p[1], p[2], p[3]);
  498. }
  499. #define dump_bmp(_x) _dump_bmp(_x, __func__, __LINE__)
  500. static void _dump_bmp(struct ps3_private* pd, const char* func, int line)
  501. {
  502. unsigned long flags;
  503. spin_lock_irqsave(&pd->bmp_lock, flags);
  504. _dump_64_bmp("stat", &pd->bmp.status, pd->thread_id, func, line);
  505. _dump_64_bmp("mask", (u64*)&pd->bmp.mask, pd->thread_id, func, line);
  506. spin_unlock_irqrestore(&pd->bmp_lock, flags);
  507. }
  508. #define dump_mask(_x) _dump_mask(_x, __func__, __LINE__)
  509. static void __maybe_unused _dump_mask(struct ps3_private *pd,
  510. const char* func, int line)
  511. {
  512. unsigned long flags;
  513. spin_lock_irqsave(&pd->bmp_lock, flags);
  514. _dump_64_bmp("mask", (u64*)&pd->bmp.mask, pd->thread_id, func, line);
  515. spin_unlock_irqrestore(&pd->bmp_lock, flags);
  516. }
  517. #else
  518. static void dump_bmp(struct ps3_private* pd) {};
  519. #endif /* defined(DEBUG) */
  520. static int ps3_host_map(struct irq_domain *h, unsigned int virq,
  521. irq_hw_number_t hwirq)
  522. {
  523. DBG("%s:%d: hwirq %lu, virq %u\n", __func__, __LINE__, hwirq,
  524. virq);
  525. irq_set_chip_and_handler(virq, &ps3_irq_chip, handle_fasteoi_irq);
  526. return 0;
  527. }
  528. static int ps3_host_match(struct irq_domain *h, struct device_node *np,
  529. enum irq_domain_bus_token bus_token)
  530. {
  531. /* Match all */
  532. return 1;
  533. }
  534. static const struct irq_domain_ops ps3_host_ops = {
  535. .map = ps3_host_map,
  536. .match = ps3_host_match,
  537. };
  538. void __init ps3_register_ipi_debug_brk(unsigned int cpu, unsigned int virq)
  539. {
  540. struct ps3_private *pd = &per_cpu(ps3_private, cpu);
  541. set_bit(63 - virq, &pd->ipi_debug_brk_mask);
  542. DBG("%s:%d: cpu %u, virq %u, mask %lxh\n", __func__, __LINE__,
  543. cpu, virq, pd->ipi_debug_brk_mask);
  544. }
  545. void __init ps3_register_ipi_irq(unsigned int cpu, unsigned int virq)
  546. {
  547. struct ps3_private *pd = &per_cpu(ps3_private, cpu);
  548. set_bit(63 - virq, &pd->ipi_mask);
  549. DBG("%s:%d: cpu %u, virq %u, ipi_mask %lxh\n", __func__, __LINE__,
  550. cpu, virq, pd->ipi_mask);
  551. }
  552. static unsigned int ps3_get_irq(void)
  553. {
  554. struct ps3_private *pd = this_cpu_ptr(&ps3_private);
  555. u64 x = (pd->bmp.status & pd->bmp.mask);
  556. unsigned int plug;
  557. /* check for ipi break first to stop this cpu ASAP */
  558. if (x & pd->ipi_debug_brk_mask)
  559. x &= pd->ipi_debug_brk_mask;
  560. asm volatile("cntlzd %0,%1" : "=r" (plug) : "r" (x));
  561. plug &= 0x3f;
  562. if (unlikely(!plug)) {
  563. DBG("%s:%d: no plug found: thread_id %llu\n", __func__,
  564. __LINE__, pd->thread_id);
  565. dump_bmp(&per_cpu(ps3_private, 0));
  566. dump_bmp(&per_cpu(ps3_private, 1));
  567. return 0;
  568. }
  569. #if defined(DEBUG)
  570. if (unlikely(plug < NR_IRQS_LEGACY || plug > PS3_PLUG_MAX)) {
  571. dump_bmp(&per_cpu(ps3_private, 0));
  572. dump_bmp(&per_cpu(ps3_private, 1));
  573. BUG();
  574. }
  575. #endif
  576. /* IPIs are EOIed here. */
  577. if (test_bit(63 - plug, &pd->ipi_mask))
  578. lv1_end_of_interrupt_ext(pd->ppe_id, pd->thread_id, plug);
  579. return plug;
  580. }
  581. void __init ps3_init_IRQ(void)
  582. {
  583. int result;
  584. unsigned cpu;
  585. struct irq_domain *host;
  586. host = irq_domain_add_nomap(NULL, PS3_PLUG_MAX + 1, &ps3_host_ops, NULL);
  587. irq_set_default_host(host);
  588. for_each_possible_cpu(cpu) {
  589. struct ps3_private *pd = &per_cpu(ps3_private, cpu);
  590. lv1_get_logical_ppe_id(&pd->ppe_id);
  591. pd->thread_id = get_hard_smp_processor_id(cpu);
  592. spin_lock_init(&pd->bmp_lock);
  593. DBG("%s:%d: ppe_id %llu, thread_id %llu, bmp %lxh\n",
  594. __func__, __LINE__, pd->ppe_id, pd->thread_id,
  595. ps3_mm_phys_to_lpar(__pa(&pd->bmp)));
  596. result = lv1_configure_irq_state_bitmap(pd->ppe_id,
  597. pd->thread_id, ps3_mm_phys_to_lpar(__pa(&pd->bmp)));
  598. if (result)
  599. FAIL("%s:%d: lv1_configure_irq_state_bitmap failed:"
  600. " %s\n", __func__, __LINE__,
  601. ps3_result(result));
  602. }
  603. ppc_md.get_irq = ps3_get_irq;
  604. }
  605. void ps3_shutdown_IRQ(int cpu)
  606. {
  607. int result;
  608. u64 ppe_id;
  609. u64 thread_id = get_hard_smp_processor_id(cpu);
  610. lv1_get_logical_ppe_id(&ppe_id);
  611. result = lv1_configure_irq_state_bitmap(ppe_id, thread_id, 0);
  612. DBG("%s:%d: lv1_configure_irq_state_bitmap (%llu:%llu/%d) %s\n", __func__,
  613. __LINE__, ppe_id, thread_id, cpu, ps3_result(result));
  614. }