This source file includes following definitions.
- pnv_smp_setup_cpu
- pnv_smp_kick_cpu
- pnv_smp_cpu_disable
- pnv_flush_interrupts
- pnv_smp_cpu_kill_self
- pnv_cpu_bootable
- pnv_smp_prepare_cpu
- pnv_cause_ipi
- pnv_smp_probe
- pnv_system_reset_exception
- pnv_cause_nmi_ipi
- pnv_smp_init
1
2
3
4
5
6
7
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/sched.h>
11 #include <linux/sched/hotplug.h>
12 #include <linux/smp.h>
13 #include <linux/interrupt.h>
14 #include <linux/delay.h>
15 #include <linux/init.h>
16 #include <linux/spinlock.h>
17 #include <linux/cpu.h>
18
19 #include <asm/irq.h>
20 #include <asm/smp.h>
21 #include <asm/paca.h>
22 #include <asm/machdep.h>
23 #include <asm/cputable.h>
24 #include <asm/firmware.h>
25 #include <asm/vdso_datapage.h>
26 #include <asm/cputhreads.h>
27 #include <asm/xics.h>
28 #include <asm/xive.h>
29 #include <asm/opal.h>
30 #include <asm/runlatch.h>
31 #include <asm/code-patching.h>
32 #include <asm/dbell.h>
33 #include <asm/kvm_ppc.h>
34 #include <asm/ppc-opcode.h>
35 #include <asm/cpuidle.h>
36 #include <asm/kexec.h>
37 #include <asm/reg.h>
38 #include <asm/powernv.h>
39
40 #include "powernv.h"
41
42 #ifdef DEBUG
43 #include <asm/udbg.h>
44 #define DBG(fmt...) udbg_printf(fmt)
45 #else
46 #define DBG(fmt...)
47 #endif
48
49 static void pnv_smp_setup_cpu(int cpu)
50 {
51
52
53
54
55 if (pvr_version_is(PVR_POWER9))
56 mtspr(SPRN_HMEER, mfspr(SPRN_HMEER) | PPC_BIT(17));
57
58 if (xive_enabled())
59 xive_smp_setup_cpu();
60 else if (cpu != boot_cpuid)
61 xics_setup_cpu();
62 }
63
64 static int pnv_smp_kick_cpu(int nr)
65 {
66 unsigned int pcpu;
67 unsigned long start_here =
68 __pa(ppc_function_entry(generic_secondary_smp_init));
69 long rc;
70 uint8_t status;
71
72 if (nr < 0 || nr >= nr_cpu_ids)
73 return -EINVAL;
74
75 pcpu = get_hard_smp_processor_id(nr);
76
77
78
79
80 if (paca_ptrs[nr]->cpu_start || !firmware_has_feature(FW_FEATURE_OPAL))
81 goto kick;
82
83
84
85
86
87
88
89 rc = opal_query_cpu_status(pcpu, &status);
90 if (rc != OPAL_SUCCESS) {
91 pr_warn("OPAL Error %ld querying CPU %d state\n", rc, nr);
92 return -ENODEV;
93 }
94
95
96
97
98
99 if (status == OPAL_THREAD_STARTED)
100 goto kick;
101
102
103
104
105 if (status == OPAL_THREAD_INACTIVE) {
106 pr_devel("OPAL: Starting CPU %d (HW 0x%x)...\n", nr, pcpu);
107 rc = opal_start_cpu(pcpu, start_here);
108 if (rc != OPAL_SUCCESS) {
109 pr_warn("OPAL Error %ld starting CPU %d\n", rc, nr);
110 return -ENODEV;
111 }
112 } else {
113
114
115
116
117
118
119 pr_devel("OPAL: CPU %d (HW 0x%x) is unavailable"
120 " (status %d)...\n", nr, pcpu, status);
121 return -ENODEV;
122 }
123
124 kick:
125 return smp_generic_kick_cpu(nr);
126 }
127
128 #ifdef CONFIG_HOTPLUG_CPU
129
130 static int pnv_smp_cpu_disable(void)
131 {
132 int cpu = smp_processor_id();
133
134
135
136
137
138 set_cpu_online(cpu, false);
139 vdso_data->processorCount--;
140 if (cpu == boot_cpuid)
141 boot_cpuid = cpumask_any(cpu_online_mask);
142 if (xive_enabled())
143 xive_smp_disable_cpu();
144 else
145 xics_migrate_irqs_away();
146 return 0;
147 }
148
149 static void pnv_flush_interrupts(void)
150 {
151 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
152 if (xive_enabled())
153 xive_flush_interrupt();
154 else
155 icp_opal_flush_interrupt();
156 } else {
157 icp_native_flush_interrupt();
158 }
159 }
160
161 static void pnv_smp_cpu_kill_self(void)
162 {
163 unsigned long srr1, unexpected_mask, wmask;
164 unsigned int cpu;
165 u64 lpcr_val;
166
167
168
169 idle_task_exit();
170 current->active_mm = NULL;
171 cpu = smp_processor_id();
172 DBG("CPU%d offline\n", cpu);
173 generic_set_cpu_dead(cpu);
174 smp_wmb();
175
176 wmask = SRR1_WAKEMASK;
177 if (cpu_has_feature(CPU_FTR_ARCH_207S))
178 wmask = SRR1_WAKEMASK_P8;
179
180
181
182
183
184
185
186
187
188 hard_irq_disable();
189 if (generic_check_cpu_restart(cpu))
190 goto out;
191
192 unexpected_mask = ~(PACA_IRQ_DEC | PACA_IRQ_HMI | PACA_IRQ_HARD_DIS);
193 if (local_paca->irq_happened & unexpected_mask) {
194 if (local_paca->irq_happened & PACA_IRQ_EE)
195 pnv_flush_interrupts();
196 DBG("CPU%d Unexpected exit while offline irq_happened=%lx!\n",
197 cpu, local_paca->irq_happened);
198 }
199 local_paca->irq_happened = PACA_IRQ_HARD_DIS;
200
201
202
203
204
205
206
207
208
209
210
211 lpcr_val = mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1;
212 pnv_program_cpu_hotplug_lpcr(cpu, lpcr_val);
213
214 while (!generic_check_cpu_restart(cpu)) {
215
216
217
218
219
220
221
222 kvmppc_clear_host_ipi(cpu);
223
224 srr1 = pnv_cpu_offline(cpu);
225
226 WARN_ON_ONCE(!irqs_disabled());
227 WARN_ON(lazy_irq_pending());
228
229
230
231
232
233
234
235
236
237
238
239
240 if (((srr1 & wmask) == SRR1_WAKEEE) ||
241 ((srr1 & wmask) == SRR1_WAKEHVI)) {
242 pnv_flush_interrupts();
243 } else if ((srr1 & wmask) == SRR1_WAKEHDBELL) {
244 unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
245 asm volatile(PPC_MSGCLR(%0) : : "r" (msg));
246 } else if ((srr1 & wmask) == SRR1_WAKERESET) {
247 irq_set_pending_from_srr1(srr1);
248
249 }
250
251 smp_mb();
252
253
254
255
256
257 if (kdump_in_progress()) {
258
259
260
261
262
263
264
265 struct pt_regs regs;
266
267 ppc_save_regs(®s);
268 crash_ipi_callback(®s);
269
270 }
271
272 if (cpu_core_split_required())
273 continue;
274
275 if (srr1 && !generic_check_cpu_restart(cpu))
276 DBG("CPU%d Unexpected exit while offline srr1=%lx!\n",
277 cpu, srr1);
278
279 }
280
281
282
283
284
285
286
287
288 lpcr_val = mfspr(SPRN_LPCR) | (u64)LPCR_PECE1;
289 pnv_program_cpu_hotplug_lpcr(cpu, lpcr_val);
290 out:
291 DBG("CPU%d coming online...\n", cpu);
292 }
293
294 #endif
295
296 static int pnv_cpu_bootable(unsigned int nr)
297 {
298
299
300
301
302
303
304 if (cpu_has_feature(CPU_FTR_ARCH_207S))
305 return 1;
306
307 return smp_generic_cpu_bootable(nr);
308 }
309
310 static int pnv_smp_prepare_cpu(int cpu)
311 {
312 if (xive_enabled())
313 return xive_smp_prepare_cpu(cpu);
314 return 0;
315 }
316
317
318 static void (*ic_cause_ipi)(int cpu);
319
320 static void pnv_cause_ipi(int cpu)
321 {
322 if (doorbell_try_core_ipi(cpu))
323 return;
324
325 ic_cause_ipi(cpu);
326 }
327
328 static void __init pnv_smp_probe(void)
329 {
330 if (xive_enabled())
331 xive_smp_probe();
332 else
333 xics_smp_probe();
334
335 if (cpu_has_feature(CPU_FTR_DBELL)) {
336 ic_cause_ipi = smp_ops->cause_ipi;
337 WARN_ON(!ic_cause_ipi);
338
339 if (cpu_has_feature(CPU_FTR_ARCH_300))
340 smp_ops->cause_ipi = doorbell_global_ipi;
341 else
342 smp_ops->cause_ipi = pnv_cause_ipi;
343 }
344 }
345
346 static int pnv_system_reset_exception(struct pt_regs *regs)
347 {
348 if (smp_handle_nmi_ipi(regs))
349 return 1;
350 return 0;
351 }
352
353 static int pnv_cause_nmi_ipi(int cpu)
354 {
355 int64_t rc;
356
357 if (cpu >= 0) {
358 int h = get_hard_smp_processor_id(cpu);
359
360 if (opal_check_token(OPAL_QUIESCE))
361 opal_quiesce(QUIESCE_HOLD, h);
362
363 rc = opal_signal_system_reset(h);
364
365 if (opal_check_token(OPAL_QUIESCE))
366 opal_quiesce(QUIESCE_RESUME, h);
367
368 if (rc != OPAL_SUCCESS)
369 return 0;
370 return 1;
371
372 } else if (cpu == NMI_IPI_ALL_OTHERS) {
373 bool success = true;
374 int c;
375
376 if (opal_check_token(OPAL_QUIESCE))
377 opal_quiesce(QUIESCE_HOLD, -1);
378
379
380
381
382
383
384 for_each_online_cpu(c) {
385 if (c == smp_processor_id())
386 continue;
387
388 rc = opal_signal_system_reset(
389 get_hard_smp_processor_id(c));
390 if (rc != OPAL_SUCCESS)
391 success = false;
392 }
393
394 if (opal_check_token(OPAL_QUIESCE))
395 opal_quiesce(QUIESCE_RESUME, -1);
396
397 if (success)
398 return 1;
399
400
401
402
403
404 }
405
406 return 0;
407 }
408
409 static struct smp_ops_t pnv_smp_ops = {
410 .message_pass = NULL,
411 .cause_ipi = NULL,
412 .cause_nmi_ipi = NULL,
413 .probe = pnv_smp_probe,
414 .prepare_cpu = pnv_smp_prepare_cpu,
415 .kick_cpu = pnv_smp_kick_cpu,
416 .setup_cpu = pnv_smp_setup_cpu,
417 .cpu_bootable = pnv_cpu_bootable,
418 #ifdef CONFIG_HOTPLUG_CPU
419 .cpu_disable = pnv_smp_cpu_disable,
420 .cpu_die = generic_cpu_die,
421 #endif
422 };
423
424
425 void __init pnv_smp_init(void)
426 {
427 if (opal_check_token(OPAL_SIGNAL_SYSTEM_RESET)) {
428 ppc_md.system_reset_exception = pnv_system_reset_exception;
429 pnv_smp_ops.cause_nmi_ipi = pnv_cause_nmi_ipi;
430 }
431 smp_ops = &pnv_smp_ops;
432
433 #ifdef CONFIG_HOTPLUG_CPU
434 ppc_md.cpu_die = pnv_smp_cpu_kill_self;
435 #ifdef CONFIG_KEXEC_CORE
436 crash_wake_offline = 1;
437 #endif
438 #endif
439 }