]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/powerpc/kernel/smp.c
powerpc: Change the doorbell IPI calling convention
[mirror_ubuntu-bionic-kernel.git] / arch / powerpc / kernel / smp.c
1 /*
2 * SMP support for ppc.
3 *
4 * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
5 * deal of code from the sparc and intel versions.
6 *
7 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
8 *
9 * PowerPC-64 Support added by Dave Engebretsen, Peter Bergner, and
10 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 */
17
18 #undef DEBUG
19
20 #include <linux/kernel.h>
21 #include <linux/export.h>
22 #include <linux/sched/mm.h>
23 #include <linux/sched/topology.h>
24 #include <linux/smp.h>
25 #include <linux/interrupt.h>
26 #include <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/spinlock.h>
29 #include <linux/cache.h>
30 #include <linux/err.h>
31 #include <linux/device.h>
32 #include <linux/cpu.h>
33 #include <linux/notifier.h>
34 #include <linux/topology.h>
35 #include <linux/profile.h>
36
37 #include <asm/ptrace.h>
38 #include <linux/atomic.h>
39 #include <asm/irq.h>
40 #include <asm/hw_irq.h>
41 #include <asm/kvm_ppc.h>
42 #include <asm/dbell.h>
43 #include <asm/page.h>
44 #include <asm/pgtable.h>
45 #include <asm/prom.h>
46 #include <asm/smp.h>
47 #include <asm/time.h>
48 #include <asm/machdep.h>
49 #include <asm/cputhreads.h>
50 #include <asm/cputable.h>
51 #include <asm/mpic.h>
52 #include <asm/vdso_datapage.h>
53 #ifdef CONFIG_PPC64
54 #include <asm/paca.h>
55 #endif
56 #include <asm/vdso.h>
57 #include <asm/debug.h>
58 #include <asm/kexec.h>
59 #include <asm/asm-prototypes.h>
60 #include <asm/cpu_has_feature.h>
61
62 #ifdef DEBUG
63 #include <asm/udbg.h>
64 #define DBG(fmt...) udbg_printf(fmt)
65 #else
66 #define DBG(fmt...)
67 #endif
68
69 #ifdef CONFIG_HOTPLUG_CPU
70 /* State of each CPU during hotplug phases */
71 static DEFINE_PER_CPU(int, cpu_state) = { 0 };
72 #endif
73
74 struct thread_info *secondary_ti;
75
76 DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
77 DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
78
79 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
80 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
81
82 /* SMP operations for this machine */
83 struct smp_ops_t *smp_ops;
84
85 /* Can't be static due to PowerMac hackery */
86 volatile unsigned int cpu_callin_map[NR_CPUS];
87
88 int smt_enabled_at_boot = 1;
89
90 static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL;
91
92 /*
93 * Returns 1 if the specified cpu should be brought up during boot.
94 * Used to inhibit booting threads if they've been disabled or
95 * limited on the command line
96 */
97 int smp_generic_cpu_bootable(unsigned int nr)
98 {
99 /* Special case - we inhibit secondary thread startup
100 * during boot if the user requests it.
101 */
102 if (system_state == SYSTEM_BOOTING && cpu_has_feature(CPU_FTR_SMT)) {
103 if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
104 return 0;
105 if (smt_enabled_at_boot
106 && cpu_thread_in_core(nr) >= smt_enabled_at_boot)
107 return 0;
108 }
109
110 return 1;
111 }
112
113
114 #ifdef CONFIG_PPC64
115 int smp_generic_kick_cpu(int nr)
116 {
117 BUG_ON(nr < 0 || nr >= NR_CPUS);
118
119 /*
120 * The processor is currently spinning, waiting for the
121 * cpu_start field to become non-zero After we set cpu_start,
122 * the processor will continue on to secondary_start
123 */
124 if (!paca[nr].cpu_start) {
125 paca[nr].cpu_start = 1;
126 smp_mb();
127 return 0;
128 }
129
130 #ifdef CONFIG_HOTPLUG_CPU
131 /*
132 * Ok it's not there, so it might be soft-unplugged, let's
133 * try to bring it back
134 */
135 generic_set_cpu_up(nr);
136 smp_wmb();
137 smp_send_reschedule(nr);
138 #endif /* CONFIG_HOTPLUG_CPU */
139
140 return 0;
141 }
142 #endif /* CONFIG_PPC64 */
143
144 static irqreturn_t call_function_action(int irq, void *data)
145 {
146 generic_smp_call_function_interrupt();
147 return IRQ_HANDLED;
148 }
149
150 static irqreturn_t reschedule_action(int irq, void *data)
151 {
152 scheduler_ipi();
153 return IRQ_HANDLED;
154 }
155
156 static irqreturn_t tick_broadcast_ipi_action(int irq, void *data)
157 {
158 tick_broadcast_ipi_handler();
159 return IRQ_HANDLED;
160 }
161
162 static irqreturn_t debug_ipi_action(int irq, void *data)
163 {
164 if (crash_ipi_function_ptr) {
165 crash_ipi_function_ptr(get_irq_regs());
166 return IRQ_HANDLED;
167 }
168
169 #ifdef CONFIG_DEBUGGER
170 debugger_ipi(get_irq_regs());
171 #endif /* CONFIG_DEBUGGER */
172
173 return IRQ_HANDLED;
174 }
175
176 static irq_handler_t smp_ipi_action[] = {
177 [PPC_MSG_CALL_FUNCTION] = call_function_action,
178 [PPC_MSG_RESCHEDULE] = reschedule_action,
179 [PPC_MSG_TICK_BROADCAST] = tick_broadcast_ipi_action,
180 [PPC_MSG_DEBUGGER_BREAK] = debug_ipi_action,
181 };
182
183 const char *smp_ipi_name[] = {
184 [PPC_MSG_CALL_FUNCTION] = "ipi call function",
185 [PPC_MSG_RESCHEDULE] = "ipi reschedule",
186 [PPC_MSG_TICK_BROADCAST] = "ipi tick-broadcast",
187 [PPC_MSG_DEBUGGER_BREAK] = "ipi debugger",
188 };
189
190 /* optional function to request ipi, for controllers with >= 4 ipis */
191 int smp_request_message_ipi(int virq, int msg)
192 {
193 int err;
194
195 if (msg < 0 || msg > PPC_MSG_DEBUGGER_BREAK) {
196 return -EINVAL;
197 }
198 #if !defined(CONFIG_DEBUGGER) && !defined(CONFIG_KEXEC_CORE)
199 if (msg == PPC_MSG_DEBUGGER_BREAK) {
200 return 1;
201 }
202 #endif
203 err = request_irq(virq, smp_ipi_action[msg],
204 IRQF_PERCPU | IRQF_NO_THREAD | IRQF_NO_SUSPEND,
205 smp_ipi_name[msg], NULL);
206 WARN(err < 0, "unable to request_irq %d for %s (rc %d)\n",
207 virq, smp_ipi_name[msg], err);
208
209 return err;
210 }
211
212 #ifdef CONFIG_PPC_SMP_MUXED_IPI
213 struct cpu_messages {
214 long messages; /* current messages */
215 };
216 static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
217
218 void smp_muxed_ipi_set_message(int cpu, int msg)
219 {
220 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
221 char *message = (char *)&info->messages;
222
223 /*
224 * Order previous accesses before accesses in the IPI handler.
225 */
226 smp_mb();
227 message[msg] = 1;
228 }
229
230 void smp_muxed_ipi_message_pass(int cpu, int msg)
231 {
232 smp_muxed_ipi_set_message(cpu, msg);
233
234 /*
235 * cause_ipi functions are required to include a full barrier
236 * before doing whatever causes the IPI.
237 */
238 smp_ops->cause_ipi(cpu);
239 }
240
241 #ifdef __BIG_ENDIAN__
242 #define IPI_MESSAGE(A) (1uL << ((BITS_PER_LONG - 8) - 8 * (A)))
243 #else
244 #define IPI_MESSAGE(A) (1uL << (8 * (A)))
245 #endif
246
247 irqreturn_t smp_ipi_demux(void)
248 {
249 struct cpu_messages *info;
250 unsigned long all;
251
252 mb(); /* order any irq clear */
253
254 info = this_cpu_ptr(&ipi_message);
255 do {
256 all = xchg(&info->messages, 0);
257 #if defined(CONFIG_KVM_XICS) && defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE)
258 /*
259 * Must check for PPC_MSG_RM_HOST_ACTION messages
260 * before PPC_MSG_CALL_FUNCTION messages because when
261 * a VM is destroyed, we call kick_all_cpus_sync()
262 * to ensure that any pending PPC_MSG_RM_HOST_ACTION
263 * messages have completed before we free any VCPUs.
264 */
265 if (all & IPI_MESSAGE(PPC_MSG_RM_HOST_ACTION))
266 kvmppc_xics_ipi_action();
267 #endif
268 if (all & IPI_MESSAGE(PPC_MSG_CALL_FUNCTION))
269 generic_smp_call_function_interrupt();
270 if (all & IPI_MESSAGE(PPC_MSG_RESCHEDULE))
271 scheduler_ipi();
272 if (all & IPI_MESSAGE(PPC_MSG_TICK_BROADCAST))
273 tick_broadcast_ipi_handler();
274 if (all & IPI_MESSAGE(PPC_MSG_DEBUGGER_BREAK))
275 debug_ipi_action(0, NULL);
276 } while (info->messages);
277
278 return IRQ_HANDLED;
279 }
280 #endif /* CONFIG_PPC_SMP_MUXED_IPI */
281
282 static inline void do_message_pass(int cpu, int msg)
283 {
284 if (smp_ops->message_pass)
285 smp_ops->message_pass(cpu, msg);
286 #ifdef CONFIG_PPC_SMP_MUXED_IPI
287 else
288 smp_muxed_ipi_message_pass(cpu, msg);
289 #endif
290 }
291
292 void smp_send_reschedule(int cpu)
293 {
294 if (likely(smp_ops))
295 do_message_pass(cpu, PPC_MSG_RESCHEDULE);
296 }
297 EXPORT_SYMBOL_GPL(smp_send_reschedule);
298
299 void arch_send_call_function_single_ipi(int cpu)
300 {
301 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
302 }
303
304 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
305 {
306 unsigned int cpu;
307
308 for_each_cpu(cpu, mask)
309 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
310 }
311
312 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
313 void tick_broadcast(const struct cpumask *mask)
314 {
315 unsigned int cpu;
316
317 for_each_cpu(cpu, mask)
318 do_message_pass(cpu, PPC_MSG_TICK_BROADCAST);
319 }
320 #endif
321
322 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE)
323 void smp_send_debugger_break(void)
324 {
325 int cpu;
326 int me = raw_smp_processor_id();
327
328 if (unlikely(!smp_ops))
329 return;
330
331 for_each_online_cpu(cpu)
332 if (cpu != me)
333 do_message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
334 }
335 #endif
336
337 #ifdef CONFIG_KEXEC_CORE
338 void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
339 {
340 crash_ipi_function_ptr = crash_ipi_callback;
341 if (crash_ipi_callback) {
342 mb();
343 smp_send_debugger_break();
344 }
345 }
346 #endif
347
348 static void stop_this_cpu(void *dummy)
349 {
350 /* Remove this CPU */
351 set_cpu_online(smp_processor_id(), false);
352
353 local_irq_disable();
354 while (1)
355 ;
356 }
357
358 void smp_send_stop(void)
359 {
360 smp_call_function(stop_this_cpu, NULL, 0);
361 }
362
363 struct thread_info *current_set[NR_CPUS];
364
365 static void smp_store_cpu_info(int id)
366 {
367 per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
368 #ifdef CONFIG_PPC_FSL_BOOK3E
369 per_cpu(next_tlbcam_idx, id)
370 = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
371 #endif
372 }
373
374 void __init smp_prepare_cpus(unsigned int max_cpus)
375 {
376 unsigned int cpu;
377
378 DBG("smp_prepare_cpus\n");
379
380 /*
381 * setup_cpu may need to be called on the boot cpu. We havent
382 * spun any cpus up but lets be paranoid.
383 */
384 BUG_ON(boot_cpuid != smp_processor_id());
385
386 /* Fixup boot cpu */
387 smp_store_cpu_info(boot_cpuid);
388 cpu_callin_map[boot_cpuid] = 1;
389
390 for_each_possible_cpu(cpu) {
391 zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu),
392 GFP_KERNEL, cpu_to_node(cpu));
393 zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
394 GFP_KERNEL, cpu_to_node(cpu));
395 /*
396 * numa_node_id() works after this.
397 */
398 if (cpu_present(cpu)) {
399 set_cpu_numa_node(cpu, numa_cpu_lookup_table[cpu]);
400 set_cpu_numa_mem(cpu,
401 local_memory_node(numa_cpu_lookup_table[cpu]));
402 }
403 }
404
405 cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
406 cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
407
408 if (smp_ops && smp_ops->probe)
409 smp_ops->probe();
410 }
411
412 void smp_prepare_boot_cpu(void)
413 {
414 BUG_ON(smp_processor_id() != boot_cpuid);
415 #ifdef CONFIG_PPC64
416 paca[boot_cpuid].__current = current;
417 #endif
418 set_numa_node(numa_cpu_lookup_table[boot_cpuid]);
419 current_set[boot_cpuid] = task_thread_info(current);
420 }
421
422 #ifdef CONFIG_HOTPLUG_CPU
423
424 int generic_cpu_disable(void)
425 {
426 unsigned int cpu = smp_processor_id();
427
428 if (cpu == boot_cpuid)
429 return -EBUSY;
430
431 set_cpu_online(cpu, false);
432 #ifdef CONFIG_PPC64
433 vdso_data->processorCount--;
434 #endif
435 /* Update affinity of all IRQs previously aimed at this CPU */
436 irq_migrate_all_off_this_cpu();
437
438 /* Give the CPU time to drain in-flight ones */
439 local_irq_enable();
440 mdelay(1);
441 local_irq_disable();
442
443 return 0;
444 }
445
446 void generic_cpu_die(unsigned int cpu)
447 {
448 int i;
449
450 for (i = 0; i < 100; i++) {
451 smp_rmb();
452 if (is_cpu_dead(cpu))
453 return;
454 msleep(100);
455 }
456 printk(KERN_ERR "CPU%d didn't die...\n", cpu);
457 }
458
459 void generic_set_cpu_dead(unsigned int cpu)
460 {
461 per_cpu(cpu_state, cpu) = CPU_DEAD;
462 }
463
464 /*
465 * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
466 * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
467 * which makes the delay in generic_cpu_die() not happen.
468 */
469 void generic_set_cpu_up(unsigned int cpu)
470 {
471 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
472 }
473
474 int generic_check_cpu_restart(unsigned int cpu)
475 {
476 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
477 }
478
479 int is_cpu_dead(unsigned int cpu)
480 {
481 return per_cpu(cpu_state, cpu) == CPU_DEAD;
482 }
483
484 static bool secondaries_inhibited(void)
485 {
486 return kvm_hv_mode_active();
487 }
488
489 #else /* HOTPLUG_CPU */
490
491 #define secondaries_inhibited() 0
492
493 #endif
494
495 static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
496 {
497 struct thread_info *ti = task_thread_info(idle);
498
499 #ifdef CONFIG_PPC64
500 paca[cpu].__current = idle;
501 paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
502 #endif
503 ti->cpu = cpu;
504 secondary_ti = current_set[cpu] = ti;
505 }
506
507 int __cpu_up(unsigned int cpu, struct task_struct *tidle)
508 {
509 int rc, c;
510
511 /*
512 * Don't allow secondary threads to come online if inhibited
513 */
514 if (threads_per_core > 1 && secondaries_inhibited() &&
515 cpu_thread_in_subcore(cpu))
516 return -EBUSY;
517
518 if (smp_ops == NULL ||
519 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
520 return -EINVAL;
521
522 cpu_idle_thread_init(cpu, tidle);
523
524 /*
525 * The platform might need to allocate resources prior to bringing
526 * up the CPU
527 */
528 if (smp_ops->prepare_cpu) {
529 rc = smp_ops->prepare_cpu(cpu);
530 if (rc)
531 return rc;
532 }
533
534 /* Make sure callin-map entry is 0 (can be leftover a CPU
535 * hotplug
536 */
537 cpu_callin_map[cpu] = 0;
538
539 /* The information for processor bringup must
540 * be written out to main store before we release
541 * the processor.
542 */
543 smp_mb();
544
545 /* wake up cpus */
546 DBG("smp: kicking cpu %d\n", cpu);
547 rc = smp_ops->kick_cpu(cpu);
548 if (rc) {
549 pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
550 return rc;
551 }
552
553 /*
554 * wait to see if the cpu made a callin (is actually up).
555 * use this value that I found through experimentation.
556 * -- Cort
557 */
558 if (system_state < SYSTEM_RUNNING)
559 for (c = 50000; c && !cpu_callin_map[cpu]; c--)
560 udelay(100);
561 #ifdef CONFIG_HOTPLUG_CPU
562 else
563 /*
564 * CPUs can take much longer to come up in the
565 * hotplug case. Wait five seconds.
566 */
567 for (c = 5000; c && !cpu_callin_map[cpu]; c--)
568 msleep(1);
569 #endif
570
571 if (!cpu_callin_map[cpu]) {
572 printk(KERN_ERR "Processor %u is stuck.\n", cpu);
573 return -ENOENT;
574 }
575
576 DBG("Processor %u found.\n", cpu);
577
578 if (smp_ops->give_timebase)
579 smp_ops->give_timebase();
580
581 /* Wait until cpu puts itself in the online & active maps */
582 while (!cpu_online(cpu))
583 cpu_relax();
584
585 return 0;
586 }
587
588 /* Return the value of the reg property corresponding to the given
589 * logical cpu.
590 */
591 int cpu_to_core_id(int cpu)
592 {
593 struct device_node *np;
594 const __be32 *reg;
595 int id = -1;
596
597 np = of_get_cpu_node(cpu, NULL);
598 if (!np)
599 goto out;
600
601 reg = of_get_property(np, "reg", NULL);
602 if (!reg)
603 goto out;
604
605 id = be32_to_cpup(reg);
606 out:
607 of_node_put(np);
608 return id;
609 }
610 EXPORT_SYMBOL_GPL(cpu_to_core_id);
611
612 /* Helper routines for cpu to core mapping */
613 int cpu_core_index_of_thread(int cpu)
614 {
615 return cpu >> threads_shift;
616 }
617 EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
618
619 int cpu_first_thread_of_core(int core)
620 {
621 return core << threads_shift;
622 }
623 EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
624
625 static void traverse_siblings_chip_id(int cpu, bool add, int chipid)
626 {
627 const struct cpumask *mask;
628 struct device_node *np;
629 int i, plen;
630 const __be32 *prop;
631
632 mask = add ? cpu_online_mask : cpu_present_mask;
633 for_each_cpu(i, mask) {
634 np = of_get_cpu_node(i, NULL);
635 if (!np)
636 continue;
637 prop = of_get_property(np, "ibm,chip-id", &plen);
638 if (prop && plen == sizeof(int) &&
639 of_read_number(prop, 1) == chipid) {
640 if (add) {
641 cpumask_set_cpu(cpu, cpu_core_mask(i));
642 cpumask_set_cpu(i, cpu_core_mask(cpu));
643 } else {
644 cpumask_clear_cpu(cpu, cpu_core_mask(i));
645 cpumask_clear_cpu(i, cpu_core_mask(cpu));
646 }
647 }
648 of_node_put(np);
649 }
650 }
651
652 /* Must be called when no change can occur to cpu_present_mask,
653 * i.e. during cpu online or offline.
654 */
655 static struct device_node *cpu_to_l2cache(int cpu)
656 {
657 struct device_node *np;
658 struct device_node *cache;
659
660 if (!cpu_present(cpu))
661 return NULL;
662
663 np = of_get_cpu_node(cpu, NULL);
664 if (np == NULL)
665 return NULL;
666
667 cache = of_find_next_cache_node(np);
668
669 of_node_put(np);
670
671 return cache;
672 }
673
674 static void traverse_core_siblings(int cpu, bool add)
675 {
676 struct device_node *l2_cache, *np;
677 const struct cpumask *mask;
678 int i, chip, plen;
679 const __be32 *prop;
680
681 /* First see if we have ibm,chip-id properties in cpu nodes */
682 np = of_get_cpu_node(cpu, NULL);
683 if (np) {
684 chip = -1;
685 prop = of_get_property(np, "ibm,chip-id", &plen);
686 if (prop && plen == sizeof(int))
687 chip = of_read_number(prop, 1);
688 of_node_put(np);
689 if (chip >= 0) {
690 traverse_siblings_chip_id(cpu, add, chip);
691 return;
692 }
693 }
694
695 l2_cache = cpu_to_l2cache(cpu);
696 mask = add ? cpu_online_mask : cpu_present_mask;
697 for_each_cpu(i, mask) {
698 np = cpu_to_l2cache(i);
699 if (!np)
700 continue;
701 if (np == l2_cache) {
702 if (add) {
703 cpumask_set_cpu(cpu, cpu_core_mask(i));
704 cpumask_set_cpu(i, cpu_core_mask(cpu));
705 } else {
706 cpumask_clear_cpu(cpu, cpu_core_mask(i));
707 cpumask_clear_cpu(i, cpu_core_mask(cpu));
708 }
709 }
710 of_node_put(np);
711 }
712 of_node_put(l2_cache);
713 }
714
715 /* Activate a secondary processor. */
716 void start_secondary(void *unused)
717 {
718 unsigned int cpu = smp_processor_id();
719 int i, base;
720
721 mmgrab(&init_mm);
722 current->active_mm = &init_mm;
723
724 smp_store_cpu_info(cpu);
725 set_dec(tb_ticks_per_jiffy);
726 preempt_disable();
727 cpu_callin_map[cpu] = 1;
728
729 if (smp_ops->setup_cpu)
730 smp_ops->setup_cpu(cpu);
731 if (smp_ops->take_timebase)
732 smp_ops->take_timebase();
733
734 secondary_cpu_time_init();
735
736 #ifdef CONFIG_PPC64
737 if (system_state == SYSTEM_RUNNING)
738 vdso_data->processorCount++;
739
740 vdso_getcpu_init();
741 #endif
742 /* Update sibling maps */
743 base = cpu_first_thread_sibling(cpu);
744 for (i = 0; i < threads_per_core; i++) {
745 if (cpu_is_offline(base + i) && (cpu != base + i))
746 continue;
747 cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
748 cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
749
750 /* cpu_core_map should be a superset of
751 * cpu_sibling_map even if we don't have cache
752 * information, so update the former here, too.
753 */
754 cpumask_set_cpu(cpu, cpu_core_mask(base + i));
755 cpumask_set_cpu(base + i, cpu_core_mask(cpu));
756 }
757 traverse_core_siblings(cpu, true);
758
759 set_numa_node(numa_cpu_lookup_table[cpu]);
760 set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
761
762 smp_wmb();
763 notify_cpu_starting(cpu);
764 set_cpu_online(cpu, true);
765
766 local_irq_enable();
767
768 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
769
770 BUG();
771 }
772
773 int setup_profiling_timer(unsigned int multiplier)
774 {
775 return 0;
776 }
777
778 #ifdef CONFIG_SCHED_SMT
779 /* cpumask of CPUs with asymetric SMT dependancy */
780 static int powerpc_smt_flags(void)
781 {
782 int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
783
784 if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
785 printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
786 flags |= SD_ASYM_PACKING;
787 }
788 return flags;
789 }
790 #endif
791
792 static struct sched_domain_topology_level powerpc_topology[] = {
793 #ifdef CONFIG_SCHED_SMT
794 { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
795 #endif
796 { cpu_cpu_mask, SD_INIT_NAME(DIE) },
797 { NULL, },
798 };
799
800 void __init smp_cpus_done(unsigned int max_cpus)
801 {
802 cpumask_var_t old_mask;
803
804 /* We want the setup_cpu() here to be called from CPU 0, but our
805 * init thread may have been "borrowed" by another CPU in the meantime
806 * se we pin us down to CPU 0 for a short while
807 */
808 alloc_cpumask_var(&old_mask, GFP_NOWAIT);
809 cpumask_copy(old_mask, &current->cpus_allowed);
810 set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid));
811
812 if (smp_ops && smp_ops->setup_cpu)
813 smp_ops->setup_cpu(boot_cpuid);
814
815 set_cpus_allowed_ptr(current, old_mask);
816
817 free_cpumask_var(old_mask);
818
819 if (smp_ops && smp_ops->bringup_done)
820 smp_ops->bringup_done();
821
822 dump_numa_cpu_topology();
823
824 set_sched_topology(powerpc_topology);
825
826 }
827
828 #ifdef CONFIG_HOTPLUG_CPU
829 int __cpu_disable(void)
830 {
831 int cpu = smp_processor_id();
832 int base, i;
833 int err;
834
835 if (!smp_ops->cpu_disable)
836 return -ENOSYS;
837
838 err = smp_ops->cpu_disable();
839 if (err)
840 return err;
841
842 /* Update sibling maps */
843 base = cpu_first_thread_sibling(cpu);
844 for (i = 0; i < threads_per_core && base + i < nr_cpu_ids; i++) {
845 cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
846 cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
847 cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
848 cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
849 }
850 traverse_core_siblings(cpu, false);
851
852 return 0;
853 }
854
855 void __cpu_die(unsigned int cpu)
856 {
857 if (smp_ops->cpu_die)
858 smp_ops->cpu_die(cpu);
859 }
860
861 void cpu_die(void)
862 {
863 if (ppc_md.cpu_die)
864 ppc_md.cpu_die();
865
866 /* If we return, we re-enter start_secondary */
867 start_secondary_resume();
868 }
869
870 #endif