21 #include <linux/kernel.h>
22 #include <linux/export.h>
25 #include <asm/machdep.h>
33 #define DBG udbg_printf
34 #define FAIL udbg_printf
67 #define PS3_BMP_MINALIGN 64
89 struct ps3_bmp bmp __attribute__ ((aligned (PS3_BMP_MINALIGN)));
106 static void ps3_chip_mask(
struct irq_data *
d)
111 DBG(
"%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__,
127 static void ps3_chip_unmask(
struct irq_data *
d)
132 DBG(
"%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__,
148 static void ps3_chip_eoi(
struct irq_data *
d)
150 const struct ps3_private *
pd = irq_data_get_irq_chip_data(d);
162 static struct irq_chip ps3_irq_chip = {
164 .irq_mask = ps3_chip_mask,
165 .irq_unmask = ps3_chip_unmask,
166 .irq_eoi = ps3_chip_eoi,
196 FAIL(
"%s:%d: irq_create_mapping failed: outlet %lu\n",
197 __func__, __LINE__, outlet);
202 DBG(
"%s:%d: outlet %lu => cpu %u, virq %u\n", __func__, __LINE__,
208 FAIL(
"%s:%d: irq_set_chip_data failed\n",
230 static int ps3_virq_destroy(
unsigned int virq)
232 const struct ps3_private *pd = irq_get_chip_data(virq);
234 DBG(
"%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__,
240 DBG(
"%s:%d <-\n", __func__, __LINE__);
260 result = ps3_virq_setup(cpu, outlet, virq);
263 FAIL(
"%s:%d: ps3_virq_setup failed\n", __func__, __LINE__);
267 pd = irq_get_chip_data(*virq);
275 FAIL(
"%s:%d: lv1_connect_irq_plug_ext failed: %s\n",
276 __func__, __LINE__, ps3_result(result));
284 ps3_virq_destroy(*virq);
302 const struct ps3_private *pd = irq_get_chip_data(virq);
304 DBG(
"%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__,
312 FAIL(
"%s:%d: lv1_disconnect_irq_plug_ext failed: %s\n",
313 __func__, __LINE__, ps3_result(result));
315 ps3_virq_destroy(virq);
337 result = lv1_construct_event_receive_port(&outlet);
340 FAIL(
"%s:%d: lv1_construct_event_receive_port failed: %s\n",
341 __func__, __LINE__, ps3_result(result));
366 DBG(
" -> %s:%d virq %u\n", __func__, __LINE__, virq);
370 result = lv1_destruct_event_receive_port(
virq_to_hw(virq));
373 FAIL(
"%s:%d: lv1_destruct_event_receive_port failed: %s\n",
374 __func__, __LINE__, ps3_result(result));
381 DBG(
" <- %s:%d\n", __func__, __LINE__);
387 return lv1_send_event_locally(
virq_to_hw(virq));
413 result = lv1_connect_interrupt_event_receive_port(dev->
bus_id,
417 FAIL(
"%s:%d: lv1_connect_interrupt_event_receive_port"
418 " failed: %s\n", __func__, __LINE__,
425 DBG(
"%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
439 DBG(
" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
442 result = lv1_disconnect_interrupt_event_receive_port(dev->
bus_id,
446 FAIL(
"%s:%d: lv1_disconnect_interrupt_event_receive_port"
447 " failed: %s\n", __func__, __LINE__,
458 result = ps3_virq_destroy(virq);
461 DBG(
" <- %s:%d\n", __func__, __LINE__);
483 result = lv1_construct_io_irq_outlet(interrupt_id, &outlet);
486 FAIL(
"%s:%d: lv1_construct_io_irq_outlet failed: %s\n",
487 __func__, __LINE__, ps3_result(result));
513 result = lv1_destruct_io_irq_outlet(outlet);
516 FAIL(
"%s:%d: lv1_destruct_io_irq_outlet failed: %s\n",
517 __func__, __LINE__, ps3_result(result));
545 result = lv1_configure_virtual_uart_irq(lpar_addr, &outlet);
548 FAIL(
"%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
549 __func__, __LINE__, ps3_result(result));
565 result = lv1_deconfigure_virtual_uart_irq();
568 FAIL(
"%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
569 __func__, __LINE__, ps3_result(result));
591 unsigned int class,
unsigned int *virq)
598 result = lv1_get_spe_irq_outlet(spe_id,
class, &outlet);
601 FAIL(
"%s:%d: lv1_get_spe_irq_outlet failed: %s\n",
602 __func__, __LINE__, ps3_result(result));
625 #define PS3_INVALID_OUTLET ((irq_hw_number_t)-1)
626 #define PS3_PLUG_MAX 63
629 static void _dump_64_bmp(
const char *
header,
const u64 *
p,
unsigned cpu,
632 pr_debug(
"%s:%d: %s %u {%04llx_%04llx_%04llx_%04llx}\n",
633 func, line, header, cpu,
634 *p >> 48, (*p >> 32) & 0xffff, (*p >> 16) & 0xffff,
641 pr_debug(
"%s:%d: %s %u {%016llx:%016llx:%016llx:%016llx}\n",
642 func, line, header, cpu, p[0], p[1], p[2], p[3]);
645 #define dump_bmp(_x) _dump_bmp(_x, __func__, __LINE__)
651 _dump_64_bmp(
"stat", &pd->bmp.status, pd->
thread_id, func, line);
652 _dump_64_bmp(
"mask", (
u64*)&pd->bmp.mask, pd->
thread_id, func, line);
653 spin_unlock_irqrestore(&pd->
bmp_lock, flags);
656 #define dump_mask(_x) _dump_mask(_x, __func__, __LINE__)
658 const char* func,
int line)
663 _dump_64_bmp(
"mask", (
u64*)&pd->bmp.mask, pd->
thread_id, func, line);
664 spin_unlock_irqrestore(&pd->
bmp_lock, flags);
670 static int ps3_host_map(
struct irq_domain *
h,
unsigned int virq,
673 DBG(
"%s:%d: hwirq %lu, virq %u\n", __func__, __LINE__, hwirq,
689 .match = ps3_host_match,
698 DBG(
"%s:%d: cpu %u, virq %u, mask %lxh\n", __func__, __LINE__,
708 DBG(
"%s:%d: cpu %u, virq %u, ipi_mask %lxh\n", __func__, __LINE__,
712 static unsigned int ps3_get_irq(
void)
715 u64 x = (pd->bmp.status & pd->bmp.mask);
723 asm volatile(
"cntlzd %0,%1" :
"=r" (plug) :
"r" (x));
727 DBG(
"%s:%d: no plug found: thread_id %llu\n", __func__,
763 pd->
thread_id = get_hard_smp_processor_id(cpu);
766 DBG(
"%s:%d: ppe_id %llu, thread_id %llu, bmp %lxh\n",
770 result = lv1_configure_irq_state_bitmap(pd->
ppe_id,
774 FAIL(
"%s:%d: lv1_configure_irq_state_bitmap failed:"
775 " %s\n", __func__, __LINE__,
779 ppc_md.get_irq = ps3_get_irq;
789 result = lv1_configure_irq_state_bitmap(ppe_id, thread_id, 0);
791 DBG(
"%s:%d: lv1_configure_irq_state_bitmap (%llu:%llu/%d) %s\n", __func__,
792 __LINE__, ppe_id, thread_id, cpu, ps3_result(result));