interrupt.c 19 KB

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