4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
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.
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.
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
21 #include <linux/kernel.h>
22 #include <linux/smp.h>
24 #include <asm/machdep.h>
30 #define DBG(fmt...) udbg_printf(fmt)
32 #define DBG(fmt...) do{if(0)printk(fmt);}while(0)
35 static irqreturn_t ipi_function_handler(int irq, void *msg)
37 smp_message_recv((int)(long)msg);
42 * virqs - a per cpu array of virqs for ipi use
46 static DEFINE_PER_CPU(unsigned int, virqs[MSG_COUNT]);
48 static const char *names[MSG_COUNT] = {
55 static void do_message_pass(int target, int msg)
60 if (msg >= MSG_COUNT) {
61 DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
65 virq = per_cpu(virqs, target)[msg];
66 result = ps3_send_event_locally(virq);
69 DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
70 " (%d)\n", __func__, __LINE__, target, msg, result);
73 static void ps3_smp_message_pass(int target, int msg)
78 do_message_pass(target, msg);
79 else if (target == MSG_ALL_BUT_SELF) {
80 for_each_online_cpu(cpu)
81 if (cpu != smp_processor_id())
82 do_message_pass(cpu, msg);
84 for_each_online_cpu(cpu)
85 do_message_pass(cpu, msg);
89 static int ps3_smp_probe(void)
94 static void __init ps3_smp_setup_cpu(int cpu)
97 unsigned int *virqs = per_cpu(virqs, cpu);
100 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
103 * Check assumptions on virqs[] indexing. If this
104 * check fails, then a different mapping of PPC_MSG_
105 * to index needs to be setup.
108 BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
109 BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
110 BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
112 for (i = 0; i < MSG_COUNT; i++) {
113 result = ps3_event_receive_port_setup(cpu, &virqs[i]);
118 DBG("%s:%d: (%d, %d) => virq %u\n",
119 __func__, __LINE__, cpu, i, virqs[i]);
121 result = request_irq(virqs[i], ipi_function_handler,
122 IRQF_DISABLED, names[i], (void*)(long)i);
128 ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
130 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
133 void ps3_smp_cleanup_cpu(int cpu)
135 unsigned int *virqs = per_cpu(virqs, cpu);
138 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
140 for (i = 0; i < MSG_COUNT; i++) {
141 free_irq(virqs[i], (void*)(long)i);
142 ps3_event_receive_port_destroy(virqs[i]);
146 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
149 static struct smp_ops_t ps3_smp_ops = {
150 .probe = ps3_smp_probe,
151 .message_pass = ps3_smp_message_pass,
152 .kick_cpu = smp_generic_kick_cpu,
153 .setup_cpu = ps3_smp_setup_cpu,
156 void smp_init_ps3(void)
158 DBG(" -> %s\n", __func__);
159 smp_ops = &ps3_smp_ops;
160 DBG(" <- %s\n", __func__);