1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
9 #include <linux/kernel.h>
10 #include <linux/smp.h>
12 #include <asm/machdep.h>
18 #define DBG udbg_printf
24 * ps3_ipi_virqs - a per cpu array of virqs for ipi use
28 static DEFINE_PER_CPU(unsigned int [MSG_COUNT
], ps3_ipi_virqs
);
30 static void ps3_smp_message_pass(int cpu
, int msg
)
35 if (msg
>= MSG_COUNT
) {
36 DBG("%s:%d: bad msg: %d\n", __func__
, __LINE__
, msg
);
40 virq
= per_cpu(ps3_ipi_virqs
, cpu
)[msg
];
41 result
= ps3_send_event_locally(virq
);
44 DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
45 " (%d)\n", __func__
, __LINE__
, cpu
, msg
, result
);
48 static void __init
ps3_smp_probe(void)
52 for (cpu
= 0; cpu
< 2; cpu
++) {
54 unsigned int *virqs
= per_cpu(ps3_ipi_virqs
, cpu
);
57 DBG(" -> %s:%d: (%d)\n", __func__
, __LINE__
, cpu
);
60 * Check assumptions on ps3_ipi_virqs[] indexing. If this
61 * check fails, then a different mapping of PPC_MSG_
62 * to index needs to be setup.
65 BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION
!= 0);
66 BUILD_BUG_ON(PPC_MSG_RESCHEDULE
!= 1);
67 BUILD_BUG_ON(PPC_MSG_TICK_BROADCAST
!= 2);
68 BUILD_BUG_ON(PPC_MSG_NMI_IPI
!= 3);
70 for (i
= 0; i
< MSG_COUNT
; i
++) {
71 result
= ps3_event_receive_port_setup(cpu
, &virqs
[i
]);
76 DBG("%s:%d: (%d, %d) => virq %u\n",
77 __func__
, __LINE__
, cpu
, i
, virqs
[i
]);
79 result
= smp_request_message_ipi(virqs
[i
], i
);
84 ps3_register_ipi_irq(cpu
, virqs
[i
]);
87 ps3_register_ipi_debug_brk(cpu
, virqs
[PPC_MSG_NMI_IPI
]);
89 DBG(" <- %s:%d: (%d)\n", __func__
, __LINE__
, cpu
);
93 void ps3_smp_cleanup_cpu(int cpu
)
95 unsigned int *virqs
= per_cpu(ps3_ipi_virqs
, cpu
);
98 DBG(" -> %s:%d: (%d)\n", __func__
, __LINE__
, cpu
);
100 for (i
= 0; i
< MSG_COUNT
; i
++) {
101 /* Can't call free_irq from interrupt context. */
102 ps3_event_receive_port_destroy(virqs
[i
]);
106 DBG(" <- %s:%d: (%d)\n", __func__
, __LINE__
, cpu
);
109 static struct smp_ops_t ps3_smp_ops
= {
110 .probe
= ps3_smp_probe
,
111 .message_pass
= ps3_smp_message_pass
,
112 .kick_cpu
= smp_generic_kick_cpu
,
115 void smp_init_ps3(void)
117 DBG(" -> %s\n", __func__
);
118 smp_ops
= &ps3_smp_ops
;
119 DBG(" <- %s\n", __func__
);