interrupt.c 19 KB

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