This source file includes following definitions.
- ps3_chip_mask
- ps3_chip_unmask
- ps3_chip_eoi
- ps3_virq_setup
- ps3_virq_destroy
- ps3_irq_plug_setup
- ps3_irq_plug_destroy
- ps3_event_receive_port_setup
- ps3_event_receive_port_destroy
- ps3_send_event_locally
- ps3_sb_event_receive_port_setup
- ps3_sb_event_receive_port_destroy
- ps3_io_irq_setup
- ps3_io_irq_destroy
- ps3_vuart_irq_setup
- ps3_vuart_irq_destroy
- ps3_spe_irq_setup
- ps3_spe_irq_destroy
- _dump_64_bmp
- _dump_256_bmp
- _dump_bmp
- _dump_mask
- dump_bmp
- ps3_host_map
- ps3_host_match
- ps3_register_ipi_debug_brk
- ps3_register_ipi_irq
- ps3_get_irq
- ps3_init_IRQ
- ps3_shutdown_IRQ
1
2
3
4
5
6
7
8
9 #include <linux/kernel.h>
10 #include <linux/export.h>
11 #include <linux/irq.h>
12
13 #include <asm/machdep.h>
14 #include <asm/udbg.h>
15 #include <asm/lv1call.h>
16 #include <asm/smp.h>
17
18 #include "platform.h"
19
20 #if defined(DEBUG)
21 #define DBG udbg_printf
22 #define FAIL udbg_printf
23 #else
24 #define DBG pr_devel
25 #define FAIL pr_debug
26 #endif
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 #define PS3_BMP_MINALIGN 64
56
57 struct ps3_bmp {
58 struct {
59 u64 status;
60 u64 unused_1[3];
61 unsigned long mask;
62 u64 unused_2[3];
63 };
64 };
65
66
67
68
69
70
71
72
73
74
75
76 struct ps3_private {
77 struct ps3_bmp bmp __attribute__ ((aligned (PS3_BMP_MINALIGN)));
78 spinlock_t bmp_lock;
79 u64 ppe_id;
80 u64 thread_id;
81 unsigned long ipi_debug_brk_mask;
82 unsigned long ipi_mask;
83 };
84
85 static DEFINE_PER_CPU(struct ps3_private, ps3_private);
86
87
88
89
90
91
92
93
94 static void ps3_chip_mask(struct irq_data *d)
95 {
96 struct ps3_private *pd = irq_data_get_irq_chip_data(d);
97 unsigned long flags;
98
99 DBG("%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__,
100 pd->thread_id, d->irq);
101
102 local_irq_save(flags);
103 clear_bit(63 - d->irq, &pd->bmp.mask);
104 lv1_did_update_interrupt_mask(pd->ppe_id, pd->thread_id);
105 local_irq_restore(flags);
106 }
107
108
109
110
111
112
113
114
115 static void ps3_chip_unmask(struct irq_data *d)
116 {
117 struct ps3_private *pd = irq_data_get_irq_chip_data(d);
118 unsigned long flags;
119
120 DBG("%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__,
121 pd->thread_id, d->irq);
122
123 local_irq_save(flags);
124 set_bit(63 - d->irq, &pd->bmp.mask);
125 lv1_did_update_interrupt_mask(pd->ppe_id, pd->thread_id);
126 local_irq_restore(flags);
127 }
128
129
130
131
132
133
134
135
136 static void ps3_chip_eoi(struct irq_data *d)
137 {
138 const struct ps3_private *pd = irq_data_get_irq_chip_data(d);
139
140
141
142 if (!test_bit(63 - d->irq, &pd->ipi_mask))
143 lv1_end_of_interrupt_ext(pd->ppe_id, pd->thread_id, d->irq);
144 }
145
146
147
148
149
150 static struct irq_chip ps3_irq_chip = {
151 .name = "ps3",
152 .irq_mask = ps3_chip_mask,
153 .irq_unmask = ps3_chip_unmask,
154 .irq_eoi = ps3_chip_eoi,
155 };
156
157
158
159
160
161
162
163
164
165
166
167
168 static int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
169 unsigned int *virq)
170 {
171 int result;
172 struct ps3_private *pd;
173
174
175
176 if (cpu == PS3_BINDING_CPU_ANY)
177 cpu = 0;
178
179 pd = &per_cpu(ps3_private, cpu);
180
181 *virq = irq_create_mapping(NULL, outlet);
182
183 if (!*virq) {
184 FAIL("%s:%d: irq_create_mapping failed: outlet %lu\n",
185 __func__, __LINE__, outlet);
186 result = -ENOMEM;
187 goto fail_create;
188 }
189
190 DBG("%s:%d: outlet %lu => cpu %u, virq %u\n", __func__, __LINE__,
191 outlet, cpu, *virq);
192
193 result = irq_set_chip_data(*virq, pd);
194
195 if (result) {
196 FAIL("%s:%d: irq_set_chip_data failed\n",
197 __func__, __LINE__);
198 goto fail_set;
199 }
200
201 ps3_chip_mask(irq_get_irq_data(*virq));
202
203 return result;
204
205 fail_set:
206 irq_dispose_mapping(*virq);
207 fail_create:
208 return result;
209 }
210
211
212
213
214
215
216
217
218 static int ps3_virq_destroy(unsigned int virq)
219 {
220 const struct ps3_private *pd = irq_get_chip_data(virq);
221
222 DBG("%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__,
223 __LINE__, pd->ppe_id, pd->thread_id, virq);
224
225 irq_set_chip_data(virq, NULL);
226 irq_dispose_mapping(virq);
227
228 DBG("%s:%d <-\n", __func__, __LINE__);
229 return 0;
230 }
231
232
233
234
235
236
237
238
239
240
241
242 int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
243 unsigned int *virq)
244 {
245 int result;
246 struct ps3_private *pd;
247
248 result = ps3_virq_setup(cpu, outlet, virq);
249
250 if (result) {
251 FAIL("%s:%d: ps3_virq_setup failed\n", __func__, __LINE__);
252 goto fail_setup;
253 }
254
255 pd = irq_get_chip_data(*virq);
256
257
258
259 result = lv1_connect_irq_plug_ext(pd->ppe_id, pd->thread_id, *virq,
260 outlet, 0);
261
262 if (result) {
263 FAIL("%s:%d: lv1_connect_irq_plug_ext failed: %s\n",
264 __func__, __LINE__, ps3_result(result));
265 result = -EPERM;
266 goto fail_connect;
267 }
268
269 return result;
270
271 fail_connect:
272 ps3_virq_destroy(*virq);
273 fail_setup:
274 return result;
275 }
276 EXPORT_SYMBOL_GPL(ps3_irq_plug_setup);
277
278
279
280
281
282
283
284
285
286
287 int ps3_irq_plug_destroy(unsigned int virq)
288 {
289 int result;
290 const struct ps3_private *pd = irq_get_chip_data(virq);
291
292 DBG("%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__,
293 __LINE__, pd->ppe_id, pd->thread_id, virq);
294
295 ps3_chip_mask(irq_get_irq_data(virq));
296
297 result = lv1_disconnect_irq_plug_ext(pd->ppe_id, pd->thread_id, virq);
298
299 if (result)
300 FAIL("%s:%d: lv1_disconnect_irq_plug_ext failed: %s\n",
301 __func__, __LINE__, ps3_result(result));
302
303 ps3_virq_destroy(virq);
304
305 return result;
306 }
307 EXPORT_SYMBOL_GPL(ps3_irq_plug_destroy);
308
309
310
311
312
313
314
315
316
317
318
319
320 int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq)
321 {
322 int result;
323 u64 outlet;
324
325 result = lv1_construct_event_receive_port(&outlet);
326
327 if (result) {
328 FAIL("%s:%d: lv1_construct_event_receive_port failed: %s\n",
329 __func__, __LINE__, ps3_result(result));
330 *virq = 0;
331 return result;
332 }
333
334 result = ps3_irq_plug_setup(cpu, outlet, virq);
335 BUG_ON(result);
336
337 return result;
338 }
339 EXPORT_SYMBOL_GPL(ps3_event_receive_port_setup);
340
341
342
343
344
345
346
347
348
349
350 int ps3_event_receive_port_destroy(unsigned int virq)
351 {
352 int result;
353
354 DBG(" -> %s:%d virq %u\n", __func__, __LINE__, virq);
355
356 ps3_chip_mask(irq_get_irq_data(virq));
357
358 result = lv1_destruct_event_receive_port(virq_to_hw(virq));
359
360 if (result)
361 FAIL("%s:%d: lv1_destruct_event_receive_port failed: %s\n",
362 __func__, __LINE__, ps3_result(result));
363
364
365
366
367
368
369 DBG(" <- %s:%d\n", __func__, __LINE__);
370 return result;
371 }
372
373 int ps3_send_event_locally(unsigned int virq)
374 {
375 return lv1_send_event_locally(virq_to_hw(virq));
376 }
377
378
379
380
381
382
383
384
385
386
387
388
389 int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev,
390 enum ps3_cpu_binding cpu, unsigned int *virq)
391 {
392
393
394 int result;
395
396 result = ps3_event_receive_port_setup(cpu, virq);
397
398 if (result)
399 return result;
400
401 result = lv1_connect_interrupt_event_receive_port(dev->bus_id,
402 dev->dev_id, virq_to_hw(*virq), dev->interrupt_id);
403
404 if (result) {
405 FAIL("%s:%d: lv1_connect_interrupt_event_receive_port"
406 " failed: %s\n", __func__, __LINE__,
407 ps3_result(result));
408 ps3_event_receive_port_destroy(*virq);
409 *virq = 0;
410 return result;
411 }
412
413 DBG("%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
414 dev->interrupt_id, *virq);
415
416 return 0;
417 }
418 EXPORT_SYMBOL(ps3_sb_event_receive_port_setup);
419
420 int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev,
421 unsigned int virq)
422 {
423
424
425 int result;
426
427 DBG(" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
428 dev->interrupt_id, virq);
429
430 result = lv1_disconnect_interrupt_event_receive_port(dev->bus_id,
431 dev->dev_id, virq_to_hw(virq), dev->interrupt_id);
432
433 if (result)
434 FAIL("%s:%d: lv1_disconnect_interrupt_event_receive_port"
435 " failed: %s\n", __func__, __LINE__,
436 ps3_result(result));
437
438 result = ps3_event_receive_port_destroy(virq);
439 BUG_ON(result);
440
441
442
443
444
445
446 result = ps3_virq_destroy(virq);
447 BUG_ON(result);
448
449 DBG(" <- %s:%d\n", __func__, __LINE__);
450 return result;
451 }
452 EXPORT_SYMBOL(ps3_sb_event_receive_port_destroy);
453
454
455
456
457
458
459
460
461
462
463
464
465 int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
466 unsigned int *virq)
467 {
468 int result;
469 u64 outlet;
470
471 result = lv1_construct_io_irq_outlet(interrupt_id, &outlet);
472
473 if (result) {
474 FAIL("%s:%d: lv1_construct_io_irq_outlet failed: %s\n",
475 __func__, __LINE__, ps3_result(result));
476 return result;
477 }
478
479 result = ps3_irq_plug_setup(cpu, outlet, virq);
480 BUG_ON(result);
481
482 return result;
483 }
484 EXPORT_SYMBOL_GPL(ps3_io_irq_setup);
485
486 int ps3_io_irq_destroy(unsigned int virq)
487 {
488 int result;
489 unsigned long outlet = virq_to_hw(virq);
490
491 ps3_chip_mask(irq_get_irq_data(virq));
492
493
494
495
496
497
498 result = ps3_irq_plug_destroy(virq);
499 BUG_ON(result);
500
501 result = lv1_destruct_io_irq_outlet(outlet);
502
503 if (result)
504 FAIL("%s:%d: lv1_destruct_io_irq_outlet failed: %s\n",
505 __func__, __LINE__, ps3_result(result));
506
507 return result;
508 }
509 EXPORT_SYMBOL_GPL(ps3_io_irq_destroy);
510
511
512
513
514
515
516
517
518
519
520
521
522 int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
523 unsigned int *virq)
524 {
525 int result;
526 u64 outlet;
527 u64 lpar_addr;
528
529 BUG_ON(!is_kernel_addr((u64)virt_addr_bmp));
530
531 lpar_addr = ps3_mm_phys_to_lpar(__pa(virt_addr_bmp));
532
533 result = lv1_configure_virtual_uart_irq(lpar_addr, &outlet);
534
535 if (result) {
536 FAIL("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
537 __func__, __LINE__, ps3_result(result));
538 return result;
539 }
540
541 result = ps3_irq_plug_setup(cpu, outlet, virq);
542 BUG_ON(result);
543
544 return result;
545 }
546 EXPORT_SYMBOL_GPL(ps3_vuart_irq_setup);
547
548 int ps3_vuart_irq_destroy(unsigned int virq)
549 {
550 int result;
551
552 ps3_chip_mask(irq_get_irq_data(virq));
553 result = lv1_deconfigure_virtual_uart_irq();
554
555 if (result) {
556 FAIL("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
557 __func__, __LINE__, ps3_result(result));
558 return result;
559 }
560
561 result = ps3_irq_plug_destroy(virq);
562 BUG_ON(result);
563
564 return result;
565 }
566 EXPORT_SYMBOL_GPL(ps3_vuart_irq_destroy);
567
568
569
570
571
572
573
574
575
576
577
578 int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
579 unsigned int class, unsigned int *virq)
580 {
581 int result;
582 u64 outlet;
583
584 BUG_ON(class > 2);
585
586 result = lv1_get_spe_irq_outlet(spe_id, class, &outlet);
587
588 if (result) {
589 FAIL("%s:%d: lv1_get_spe_irq_outlet failed: %s\n",
590 __func__, __LINE__, ps3_result(result));
591 return result;
592 }
593
594 result = ps3_irq_plug_setup(cpu, outlet, virq);
595 BUG_ON(result);
596
597 return result;
598 }
599
600 int ps3_spe_irq_destroy(unsigned int virq)
601 {
602 int result;
603
604 ps3_chip_mask(irq_get_irq_data(virq));
605
606 result = ps3_irq_plug_destroy(virq);
607 BUG_ON(result);
608
609 return result;
610 }
611
612
613 #define PS3_INVALID_OUTLET ((irq_hw_number_t)-1)
614 #define PS3_PLUG_MAX 63
615
616 #if defined(DEBUG)
617 static void _dump_64_bmp(const char *header, const u64 *p, unsigned cpu,
618 const char* func, int line)
619 {
620 pr_debug("%s:%d: %s %u {%04llx_%04llx_%04llx_%04llx}\n",
621 func, line, header, cpu,
622 *p >> 48, (*p >> 32) & 0xffff, (*p >> 16) & 0xffff,
623 *p & 0xffff);
624 }
625
626 static void __maybe_unused _dump_256_bmp(const char *header,
627 const u64 *p, unsigned cpu, const char* func, int line)
628 {
629 pr_debug("%s:%d: %s %u {%016llx:%016llx:%016llx:%016llx}\n",
630 func, line, header, cpu, p[0], p[1], p[2], p[3]);
631 }
632
633 #define dump_bmp(_x) _dump_bmp(_x, __func__, __LINE__)
634 static void _dump_bmp(struct ps3_private* pd, const char* func, int line)
635 {
636 unsigned long flags;
637
638 spin_lock_irqsave(&pd->bmp_lock, flags);
639 _dump_64_bmp("stat", &pd->bmp.status, pd->thread_id, func, line);
640 _dump_64_bmp("mask", (u64*)&pd->bmp.mask, pd->thread_id, func, line);
641 spin_unlock_irqrestore(&pd->bmp_lock, flags);
642 }
643
644 #define dump_mask(_x) _dump_mask(_x, __func__, __LINE__)
645 static void __maybe_unused _dump_mask(struct ps3_private *pd,
646 const char* func, int line)
647 {
648 unsigned long flags;
649
650 spin_lock_irqsave(&pd->bmp_lock, flags);
651 _dump_64_bmp("mask", (u64*)&pd->bmp.mask, pd->thread_id, func, line);
652 spin_unlock_irqrestore(&pd->bmp_lock, flags);
653 }
654 #else
655 static void dump_bmp(struct ps3_private* pd) {};
656 #endif
657
658 static int ps3_host_map(struct irq_domain *h, unsigned int virq,
659 irq_hw_number_t hwirq)
660 {
661 DBG("%s:%d: hwirq %lu, virq %u\n", __func__, __LINE__, hwirq,
662 virq);
663
664 irq_set_chip_and_handler(virq, &ps3_irq_chip, handle_fasteoi_irq);
665
666 return 0;
667 }
668
669 static int ps3_host_match(struct irq_domain *h, struct device_node *np,
670 enum irq_domain_bus_token bus_token)
671 {
672
673 return 1;
674 }
675
676 static const struct irq_domain_ops ps3_host_ops = {
677 .map = ps3_host_map,
678 .match = ps3_host_match,
679 };
680
681 void __init ps3_register_ipi_debug_brk(unsigned int cpu, unsigned int virq)
682 {
683 struct ps3_private *pd = &per_cpu(ps3_private, cpu);
684
685 set_bit(63 - virq, &pd->ipi_debug_brk_mask);
686
687 DBG("%s:%d: cpu %u, virq %u, mask %lxh\n", __func__, __LINE__,
688 cpu, virq, pd->ipi_debug_brk_mask);
689 }
690
691 void __init ps3_register_ipi_irq(unsigned int cpu, unsigned int virq)
692 {
693 struct ps3_private *pd = &per_cpu(ps3_private, cpu);
694
695 set_bit(63 - virq, &pd->ipi_mask);
696
697 DBG("%s:%d: cpu %u, virq %u, ipi_mask %lxh\n", __func__, __LINE__,
698 cpu, virq, pd->ipi_mask);
699 }
700
701 static unsigned int ps3_get_irq(void)
702 {
703 struct ps3_private *pd = this_cpu_ptr(&ps3_private);
704 u64 x = (pd->bmp.status & pd->bmp.mask);
705 unsigned int plug;
706
707
708
709 if (x & pd->ipi_debug_brk_mask)
710 x &= pd->ipi_debug_brk_mask;
711
712 asm volatile("cntlzd %0,%1" : "=r" (plug) : "r" (x));
713 plug &= 0x3f;
714
715 if (unlikely(!plug)) {
716 DBG("%s:%d: no plug found: thread_id %llu\n", __func__,
717 __LINE__, pd->thread_id);
718 dump_bmp(&per_cpu(ps3_private, 0));
719 dump_bmp(&per_cpu(ps3_private, 1));
720 return 0;
721 }
722
723 #if defined(DEBUG)
724 if (unlikely(plug < NUM_ISA_INTERRUPTS || plug > PS3_PLUG_MAX)) {
725 dump_bmp(&per_cpu(ps3_private, 0));
726 dump_bmp(&per_cpu(ps3_private, 1));
727 BUG();
728 }
729 #endif
730
731
732
733 if (test_bit(63 - plug, &pd->ipi_mask))
734 lv1_end_of_interrupt_ext(pd->ppe_id, pd->thread_id, plug);
735
736 return plug;
737 }
738
739 void __init ps3_init_IRQ(void)
740 {
741 int result;
742 unsigned cpu;
743 struct irq_domain *host;
744
745 host = irq_domain_add_nomap(NULL, PS3_PLUG_MAX + 1, &ps3_host_ops, NULL);
746 irq_set_default_host(host);
747
748 for_each_possible_cpu(cpu) {
749 struct ps3_private *pd = &per_cpu(ps3_private, cpu);
750
751 lv1_get_logical_ppe_id(&pd->ppe_id);
752 pd->thread_id = get_hard_smp_processor_id(cpu);
753 spin_lock_init(&pd->bmp_lock);
754
755 DBG("%s:%d: ppe_id %llu, thread_id %llu, bmp %lxh\n",
756 __func__, __LINE__, pd->ppe_id, pd->thread_id,
757 ps3_mm_phys_to_lpar(__pa(&pd->bmp)));
758
759 result = lv1_configure_irq_state_bitmap(pd->ppe_id,
760 pd->thread_id, ps3_mm_phys_to_lpar(__pa(&pd->bmp)));
761
762 if (result)
763 FAIL("%s:%d: lv1_configure_irq_state_bitmap failed:"
764 " %s\n", __func__, __LINE__,
765 ps3_result(result));
766 }
767
768 ppc_md.get_irq = ps3_get_irq;
769 }
770
771 void ps3_shutdown_IRQ(int cpu)
772 {
773 int result;
774 u64 ppe_id;
775 u64 thread_id = get_hard_smp_processor_id(cpu);
776
777 lv1_get_logical_ppe_id(&ppe_id);
778 result = lv1_configure_irq_state_bitmap(ppe_id, thread_id, 0);
779
780 DBG("%s:%d: lv1_configure_irq_state_bitmap (%llu:%llu/%d) %s\n", __func__,
781 __LINE__, ppe_id, thread_id, cpu, ps3_result(result));
782 }