interrupt.c 20 KB

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