blob: 60154d08debf115ad70270dbc44d4e3a0f0d4432 [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
Milton Millerf1072932011-05-10 19:29:10 +000042static void ps3_smp_message_pass(int cpu, int msg)
Geoff Levandf58a9d12006-11-23 00:46:51 +010043{
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
Milton Millerf1072932011-05-10 19:29:10 +000052 virq = per_cpu(ps3_ipi_virqs, cpu)[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"
Milton Millerf1072932011-05-10 19:29:10 +000057 " (%d)\n", __func__, __LINE__, cpu, msg, result);
Geoff Levandf58a9d12006-11-23 00:46:51 +010058}
59
Michael Ellermana7f4ee12015-04-04 19:28:50 +110060static void __init ps3_smp_probe(void)
Geoff Levandf58a9d12006-11-23 00:46:51 +010061{
Geoff Levand7eaf09e2011-11-08 12:38:21 +000062 int cpu;
Geoff Levandf58a9d12006-11-23 00:46:51 +010063
Geoff Levand7eaf09e2011-11-08 12:38:21 +000064 for (cpu = 0; cpu < 2; cpu++) {
65 int result;
66 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
67 int i;
Geoff Levandf58a9d12006-11-23 00:46:51 +010068
Geoff Levand7eaf09e2011-11-08 12:38:21 +000069 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
Geoff Levandf58a9d12006-11-23 00:46:51 +010070
Geoff Levand7eaf09e2011-11-08 12:38:21 +000071 /*
72 * Check assumptions on ps3_ipi_virqs[] indexing. If this
73 * check fails, then a different mapping of PPC_MSG_
74 * to index needs to be setup.
75 */
Geoff Levandf58a9d12006-11-23 00:46:51 +010076
Geoff Levand7eaf09e2011-11-08 12:38:21 +000077 BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
78 BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
Srivatsa S. Bhat1b67bee2014-02-26 05:37:43 +053079 BUILD_BUG_ON(PPC_MSG_TICK_BROADCAST != 2);
Geoff Levand7eaf09e2011-11-08 12:38:21 +000080 BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
Geoff Levandf58a9d12006-11-23 00:46:51 +010081
Geoff Levand7eaf09e2011-11-08 12:38:21 +000082 for (i = 0; i < MSG_COUNT; i++) {
83 result = ps3_event_receive_port_setup(cpu, &virqs[i]);
Geoff Levandf58a9d12006-11-23 00:46:51 +010084
Geoff Levand7eaf09e2011-11-08 12:38:21 +000085 if (result)
86 continue;
Geoff Levandf58a9d12006-11-23 00:46:51 +010087
Geoff Levand7eaf09e2011-11-08 12:38:21 +000088 DBG("%s:%d: (%d, %d) => virq %u\n",
89 __func__, __LINE__, cpu, i, virqs[i]);
Geoff Levandf58a9d12006-11-23 00:46:51 +010090
Geoff Levand7eaf09e2011-11-08 12:38:21 +000091 result = smp_request_message_ipi(virqs[i], i);
Geoff Levandf58a9d12006-11-23 00:46:51 +010092
Geoff Levand7eaf09e2011-11-08 12:38:21 +000093 if (result)
Michael Ellermanef24ba72016-09-06 21:53:24 +100094 virqs[i] = 0;
Geoff Levand7eaf09e2011-11-08 12:38:21 +000095 else
96 ps3_register_ipi_irq(cpu, virqs[i]);
97 }
98
99 ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
100
101 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100102 }
Geoff Levandf58a9d12006-11-23 00:46:51 +0100103}
104
105void ps3_smp_cleanup_cpu(int cpu)
106{
Geoff Levand7961f202007-06-16 07:17:42 +1000107 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100108 int i;
109
110 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000111
Geoff Levandf58a9d12006-11-23 00:46:51 +0100112 for (i = 0; i < MSG_COUNT; i++) {
Geoff Levand9263e852007-06-16 07:19:32 +1000113 /* Can't call free_irq from interrupt context. */
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000114 ps3_event_receive_port_destroy(virqs[i]);
Michael Ellermanef24ba72016-09-06 21:53:24 +1000115 virqs[i] = 0;
Geoff Levandf58a9d12006-11-23 00:46:51 +0100116 }
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000117
Geoff Levandf58a9d12006-11-23 00:46:51 +0100118 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
119}
120
121static struct smp_ops_t ps3_smp_ops = {
122 .probe = ps3_smp_probe,
123 .message_pass = ps3_smp_message_pass,
124 .kick_cpu = smp_generic_kick_cpu,
Geoff Levandf58a9d12006-11-23 00:46:51 +0100125};
126
127void smp_init_ps3(void)
128{
129 DBG(" -> %s\n", __func__);
130 smp_ops = &ps3_smp_ops;
131 DBG(" <- %s\n", __func__);
132}