Commit | Line | Data |
---|---|---|
873e65bc | 1 | // SPDX-License-Identifier: GPL-2.0-only |
f58a9d17 GL |
2 | /* |
3 | * PS3 SMP routines. | |
4 | * | |
5 | * Copyright (C) 2006 Sony Computer Entertainment Inc. | |
6 | * Copyright 2006 Sony Corp. | |
f58a9d17 GL |
7 | */ |
8 | ||
9 | #include <linux/kernel.h> | |
10 | #include <linux/smp.h> | |
11 | ||
12 | #include <asm/machdep.h> | |
13 | #include <asm/udbg.h> | |
f58a9d17 GL |
14 | |
15 | #include "platform.h" | |
16 | ||
17 | #if defined(DEBUG) | |
83bb643d | 18 | #define DBG udbg_printf |
f58a9d17 | 19 | #else |
83bb643d | 20 | #define DBG pr_debug |
f58a9d17 GL |
21 | #endif |
22 | ||
f58a9d17 | 23 | /** |
7961f20c | 24 | * ps3_ipi_virqs - a per cpu array of virqs for ipi use |
f58a9d17 GL |
25 | */ |
26 | ||
27 | #define MSG_COUNT 4 | |
204fba4a | 28 | static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs); |
f58a9d17 | 29 | |
f1072939 | 30 | static void ps3_smp_message_pass(int cpu, int msg) |
f58a9d17 GL |
31 | { |
32 | int result; | |
33 | unsigned int virq; | |
34 | ||
35 | if (msg >= MSG_COUNT) { | |
36 | DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg); | |
37 | return; | |
38 | } | |
39 | ||
f1072939 | 40 | virq = per_cpu(ps3_ipi_virqs, cpu)[msg]; |
f58a9d17 GL |
41 | result = ps3_send_event_locally(virq); |
42 | ||
43 | if (result) | |
44 | DBG("%s:%d: ps3_send_event_locally(%d, %d) failed" | |
f1072939 | 45 | " (%d)\n", __func__, __LINE__, cpu, msg, result); |
f58a9d17 GL |
46 | } |
47 | ||
a7f4ee1f | 48 | static void __init ps3_smp_probe(void) |
f58a9d17 | 49 | { |
7eaf09ee | 50 | int cpu; |
f58a9d17 | 51 | |
7eaf09ee GL |
52 | for (cpu = 0; cpu < 2; cpu++) { |
53 | int result; | |
54 | unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu); | |
55 | int i; | |
f58a9d17 | 56 | |
7eaf09ee | 57 | DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); |
f58a9d17 | 58 | |
7eaf09ee GL |
59 | /* |
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. | |
63 | */ | |
f58a9d17 | 64 | |
7eaf09ee GL |
65 | BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0); |
66 | BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1); | |
1b67bee1 | 67 | BUILD_BUG_ON(PPC_MSG_TICK_BROADCAST != 2); |
ddd703ca | 68 | BUILD_BUG_ON(PPC_MSG_NMI_IPI != 3); |
f58a9d17 | 69 | |
7eaf09ee GL |
70 | for (i = 0; i < MSG_COUNT; i++) { |
71 | result = ps3_event_receive_port_setup(cpu, &virqs[i]); | |
f58a9d17 | 72 | |
7eaf09ee GL |
73 | if (result) |
74 | continue; | |
f58a9d17 | 75 | |
7eaf09ee GL |
76 | DBG("%s:%d: (%d, %d) => virq %u\n", |
77 | __func__, __LINE__, cpu, i, virqs[i]); | |
f58a9d17 | 78 | |
7eaf09ee | 79 | result = smp_request_message_ipi(virqs[i], i); |
f58a9d17 | 80 | |
7eaf09ee | 81 | if (result) |
ef24ba70 | 82 | virqs[i] = 0; |
7eaf09ee GL |
83 | else |
84 | ps3_register_ipi_irq(cpu, virqs[i]); | |
85 | } | |
f58a9d17 | 86 | |
ddd703ca | 87 | ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_NMI_IPI]); |
f58a9d17 | 88 | |
7eaf09ee GL |
89 | DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu); |
90 | } | |
f58a9d17 GL |
91 | } |
92 | ||
93 | void ps3_smp_cleanup_cpu(int cpu) | |
94 | { | |
7961f20c | 95 | unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu); |
f58a9d17 GL |
96 | int i; |
97 | ||
98 | DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); | |
dc4f60c2 | 99 | |
f58a9d17 | 100 | for (i = 0; i < MSG_COUNT; i++) { |
9263e85a | 101 | /* Can't call free_irq from interrupt context. */ |
dc4f60c2 | 102 | ps3_event_receive_port_destroy(virqs[i]); |
ef24ba70 | 103 | virqs[i] = 0; |
f58a9d17 | 104 | } |
dc4f60c2 | 105 | |
f58a9d17 GL |
106 | DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu); |
107 | } | |
108 | ||
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, | |
f58a9d17 GL |
113 | }; |
114 | ||
115 | void smp_init_ps3(void) | |
116 | { | |
117 | DBG(" -> %s\n", __func__); | |
118 | smp_ops = &ps3_smp_ops; | |
119 | DBG(" <- %s\n", __func__); | |
120 | } |