blob: 51ffde40af2b7d5c9ba41fee997c4790073d8035 [file] [log] [blame]
Geoff Levandf58a9d12006-11-23 00:46:51 +01001/*
2 * PS3 SMP 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
21#include <linux/kernel.h>
22#include <linux/smp.h>
23
24#include <asm/machdep.h>
25#include <asm/udbg.h>
Geoff Levandf58a9d12006-11-23 00:46:51 +010026
27#include "platform.h"
28
29#if defined(DEBUG)
Geert Uytterhoeven83bb6432007-06-16 07:19:23 +100030#define DBG udbg_printf
Geoff Levandf58a9d12006-11-23 00:46:51 +010031#else
Geert Uytterhoeven83bb6432007-06-16 07:19:23 +100032#define DBG pr_debug
Geoff Levandf58a9d12006-11-23 00:46:51 +010033#endif
34
Geoff Levandf58a9d12006-11-23 00:46:51 +010035/**
Geoff Levand7961f202007-06-16 07:17:42 +100036 * ps3_ipi_virqs - a per cpu array of virqs for ipi use
Geoff Levandf58a9d12006-11-23 00:46:51 +010037 */
38
39#define MSG_COUNT 4
Tejun Heo204fba42009-06-24 15:13:45 +090040static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs);
Geoff Levandf58a9d12006-11-23 00:46:51 +010041
Geoff Levandf58a9d12006-11-23 00:46:51 +010042static void do_message_pass(int target, int msg)
43{
44 int result;
45 unsigned int virq;
46
47 if (msg >= MSG_COUNT) {
48 DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
49 return;
50 }
51
Geoff Levand7961f202007-06-16 07:17:42 +100052 virq = per_cpu(ps3_ipi_virqs, target)[msg];
Geoff Levandf58a9d12006-11-23 00:46:51 +010053 result = ps3_send_event_locally(virq);
54
55 if (result)
56 DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
57 " (%d)\n", __func__, __LINE__, target, msg, result);
58}
59
60static void ps3_smp_message_pass(int target, int msg)
61{
62 int cpu;
63
64 if (target < NR_CPUS)
65 do_message_pass(target, msg);
66 else if (target == MSG_ALL_BUT_SELF) {
67 for_each_online_cpu(cpu)
68 if (cpu != smp_processor_id())
69 do_message_pass(cpu, msg);
70 } else {
71 for_each_online_cpu(cpu)
72 do_message_pass(cpu, msg);
73 }
74}
75
76static int ps3_smp_probe(void)
77{
78 return 2;
79}
80
81static void __init ps3_smp_setup_cpu(int cpu)
82{
83 int result;
Geoff Levand7961f202007-06-16 07:17:42 +100084 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
Geoff Levandf58a9d12006-11-23 00:46:51 +010085 int i;
86
87 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
88
89 /*
Geoff Levand7961f202007-06-16 07:17:42 +100090 * Check assumptions on ps3_ipi_virqs[] indexing. If this
Geoff Levandf58a9d12006-11-23 00:46:51 +010091 * check fails, then a different mapping of PPC_MSG_
92 * to index needs to be setup.
93 */
94
Jens Axboeb7d7a242008-06-26 11:22:13 +020095 BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
96 BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
97 BUILD_BUG_ON(PPC_MSG_CALL_FUNC_SINGLE != 2);
98 BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
Geoff Levandf58a9d12006-11-23 00:46:51 +010099
100 for (i = 0; i < MSG_COUNT; i++) {
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000101 result = ps3_event_receive_port_setup(cpu, &virqs[i]);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100102
103 if (result)
104 continue;
105
106 DBG("%s:%d: (%d, %d) => virq %u\n",
107 __func__, __LINE__, cpu, i, virqs[i]);
108
Geoff Levandfb94fc22009-04-16 09:05:39 +0000109 result = smp_request_message_ipi(virqs[i], i);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100110
Geoff Levand28820d92007-05-12 03:41:59 +1000111 if (result)
112 virqs[i] = NO_IRQ;
Geoff Levandf58a9d12006-11-23 00:46:51 +0100113 }
114
115 ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
116
117 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
118}
119
120void ps3_smp_cleanup_cpu(int cpu)
121{
Geoff Levand7961f202007-06-16 07:17:42 +1000122 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100123 int i;
124
125 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000126
Geoff Levandf58a9d12006-11-23 00:46:51 +0100127 for (i = 0; i < MSG_COUNT; i++) {
Geoff Levand9263e852007-06-16 07:19:32 +1000128 /* Can't call free_irq from interrupt context. */
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000129 ps3_event_receive_port_destroy(virqs[i]);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100130 virqs[i] = NO_IRQ;
131 }
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000132
Geoff Levandf58a9d12006-11-23 00:46:51 +0100133 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
134}
135
136static struct smp_ops_t ps3_smp_ops = {
137 .probe = ps3_smp_probe,
138 .message_pass = ps3_smp_message_pass,
139 .kick_cpu = smp_generic_kick_cpu,
140 .setup_cpu = ps3_smp_setup_cpu,
141};
142
143void smp_init_ps3(void)
144{
145 DBG(" -> %s\n", __func__);
146 smp_ops = &ps3_smp_ops;
147 DBG(" <- %s\n", __func__);
148}