interrupt.c 19 KB

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