WIP FPC-III support
[linux/fpc-iii.git] / arch / powerpc / platforms / ps3 / smp.c
blob93b1e73b35299951283ba9b913bda785034fbf33
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * PS3 SMP routines.
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
7 */
9 #include <linux/kernel.h>
10 #include <linux/smp.h>
12 #include <asm/machdep.h>
13 #include <asm/udbg.h>
15 #include "platform.h"
17 #if defined(DEBUG)
18 #define DBG udbg_printf
19 #else
20 #define DBG pr_debug
21 #endif
23 /**
24 * ps3_ipi_virqs - a per cpu array of virqs for ipi use
27 #define MSG_COUNT 4
28 static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs);
30 static void ps3_smp_message_pass(int cpu, int msg)
32 int result;
33 unsigned int virq;
35 if (msg >= MSG_COUNT) {
36 DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
37 return;
40 virq = per_cpu(ps3_ipi_virqs, cpu)[msg];
41 result = ps3_send_event_locally(virq);
43 if (result)
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)
50 int cpu;
52 for (cpu = 0; cpu < 2; cpu++) {
53 int result;
54 unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
55 int i;
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]);
73 if (result)
74 continue;
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);
81 if (result)
82 virqs[i] = 0;
83 else
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);
96 int i;
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]);
103 virqs[i] = 0;
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__);