interrupt.c 18 KB

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