Merge tag 'dm-4.8-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
[deliverable/linux.git] / arch / powerpc / platforms / ps3 / smp.c
CommitLineData
f58a9d17
GL
1/*
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>
f58a9d17
GL
26
27#include "platform.h"
28
29#if defined(DEBUG)
83bb643d 30#define DBG udbg_printf
f58a9d17 31#else
83bb643d 32#define DBG pr_debug
f58a9d17
GL
33#endif
34
f58a9d17 35/**
7961f20c 36 * ps3_ipi_virqs - a per cpu array of virqs for ipi use
f58a9d17
GL
37 */
38
39#define MSG_COUNT 4
204fba4a 40static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs);
f58a9d17 41
f1072939 42static void ps3_smp_message_pass(int cpu, int msg)
f58a9d17
GL
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
f1072939 52 virq = per_cpu(ps3_ipi_virqs, cpu)[msg];
f58a9d17
GL
53 result = ps3_send_event_locally(virq);
54
55 if (result)
56 DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
f1072939 57 " (%d)\n", __func__, __LINE__, cpu, msg, result);
f58a9d17
GL
58}
59
a7f4ee1f 60static void __init ps3_smp_probe(void)
f58a9d17 61{
7eaf09ee 62 int cpu;
f58a9d17 63
7eaf09ee
GL
64 for (cpu = 0; cpu < 2; cpu++) {
65 int result;
66 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
67 int i;
f58a9d17 68
7eaf09ee 69 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
f58a9d17 70
7eaf09ee
GL
71 /*
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 */
f58a9d17 76
7eaf09ee
GL
77 BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
78 BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
1b67bee1 79 BUILD_BUG_ON(PPC_MSG_TICK_BROADCAST != 2);
7eaf09ee 80 BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
f58a9d17 81
7eaf09ee
GL
82 for (i = 0; i < MSG_COUNT; i++) {
83 result = ps3_event_receive_port_setup(cpu, &virqs[i]);
f58a9d17 84
7eaf09ee
GL
85 if (result)
86 continue;
f58a9d17 87
7eaf09ee
GL
88 DBG("%s:%d: (%d, %d) => virq %u\n",
89 __func__, __LINE__, cpu, i, virqs[i]);
f58a9d17 90
7eaf09ee 91 result = smp_request_message_ipi(virqs[i], i);
f58a9d17 92
7eaf09ee
GL
93 if (result)
94 virqs[i] = NO_IRQ;
95 else
96 ps3_register_ipi_irq(cpu, virqs[i]);
97 }
f58a9d17 98
7eaf09ee 99 ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
f58a9d17 100
7eaf09ee
GL
101 DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
102 }
f58a9d17
GL
103}
104
105void ps3_smp_cleanup_cpu(int cpu)
106{
7961f20c 107 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
f58a9d17
GL
108 int i;
109
110 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
dc4f60c2 111
f58a9d17 112 for (i = 0; i < MSG_COUNT; i++) {
9263e85a 113 /* Can't call free_irq from interrupt context. */
dc4f60c2 114 ps3_event_receive_port_destroy(virqs[i]);
f58a9d17
GL
115 virqs[i] = NO_IRQ;
116 }
dc4f60c2 117
f58a9d17
GL
118 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,
f58a9d17
GL
125};
126
127void smp_init_ps3(void)
128{
129 DBG(" -> %s\n", __func__);
130 smp_ops = &ps3_smp_ops;
131 DBG(" <- %s\n", __func__);
132}
This page took 0.609047 seconds and 5 git commands to generate.