hwrng: core - Don't use a stack buffer in add_early_randomness()
[linux/fpc-iii.git] / arch / powerpc / kernel / smp.c
blob9c6f3fd580597e5fdfcc5fc46031d9be0aaac74b
1 /*
2 * SMP support for ppc.
4 * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
5 * deal of code from the sparc and intel versions.
7 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
9 * PowerPC-64 Support added by Dave Engebretsen, Peter Bergner, and
10 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
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.
18 #undef DEBUG
20 #include <linux/kernel.h>
21 #include <linux/export.h>
22 #include <linux/sched.h>
23 #include <linux/smp.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/init.h>
27 #include <linux/spinlock.h>
28 #include <linux/cache.h>
29 #include <linux/err.h>
30 #include <linux/device.h>
31 #include <linux/cpu.h>
32 #include <linux/notifier.h>
33 #include <linux/topology.h>
34 #include <linux/profile.h>
36 #include <asm/ptrace.h>
37 #include <linux/atomic.h>
38 #include <asm/irq.h>
39 #include <asm/hw_irq.h>
40 #include <asm/kvm_ppc.h>
41 #include <asm/page.h>
42 #include <asm/pgtable.h>
43 #include <asm/prom.h>
44 #include <asm/smp.h>
45 #include <asm/time.h>
46 #include <asm/machdep.h>
47 #include <asm/cputhreads.h>
48 #include <asm/cputable.h>
49 #include <asm/mpic.h>
50 #include <asm/vdso_datapage.h>
51 #ifdef CONFIG_PPC64
52 #include <asm/paca.h>
53 #endif
54 #include <asm/vdso.h>
55 #include <asm/debug.h>
56 #include <asm/kexec.h>
57 #include <asm/asm-prototypes.h>
58 #include <asm/cpu_has_feature.h>
60 #ifdef DEBUG
61 #include <asm/udbg.h>
62 #define DBG(fmt...) udbg_printf(fmt)
63 #else
64 #define DBG(fmt...)
65 #endif
67 #ifdef CONFIG_HOTPLUG_CPU
68 /* State of each CPU during hotplug phases */
69 static DEFINE_PER_CPU(int, cpu_state) = { 0 };
70 #endif
72 struct thread_info *secondary_ti;
74 DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
75 DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
77 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
78 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
80 /* SMP operations for this machine */
81 struct smp_ops_t *smp_ops;
83 /* Can't be static due to PowerMac hackery */
84 volatile unsigned int cpu_callin_map[NR_CPUS];
86 int smt_enabled_at_boot = 1;
88 static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL;
91 * Returns 1 if the specified cpu should be brought up during boot.
92 * Used to inhibit booting threads if they've been disabled or
93 * limited on the command line
95 int smp_generic_cpu_bootable(unsigned int nr)
97 /* Special case - we inhibit secondary thread startup
98 * during boot if the user requests it.
100 if (system_state == SYSTEM_BOOTING && cpu_has_feature(CPU_FTR_SMT)) {
101 if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
102 return 0;
103 if (smt_enabled_at_boot
104 && cpu_thread_in_core(nr) >= smt_enabled_at_boot)
105 return 0;
108 return 1;
112 #ifdef CONFIG_PPC64
113 int smp_generic_kick_cpu(int nr)
115 BUG_ON(nr < 0 || nr >= NR_CPUS);
118 * The processor is currently spinning, waiting for the
119 * cpu_start field to become non-zero After we set cpu_start,
120 * the processor will continue on to secondary_start
122 if (!paca[nr].cpu_start) {
123 paca[nr].cpu_start = 1;
124 smp_mb();
125 return 0;
128 #ifdef CONFIG_HOTPLUG_CPU
130 * Ok it's not there, so it might be soft-unplugged, let's
131 * try to bring it back
133 generic_set_cpu_up(nr);
134 smp_wmb();
135 smp_send_reschedule(nr);
136 #endif /* CONFIG_HOTPLUG_CPU */
138 return 0;
140 #endif /* CONFIG_PPC64 */
142 static irqreturn_t call_function_action(int irq, void *data)
144 generic_smp_call_function_interrupt();
145 return IRQ_HANDLED;
148 static irqreturn_t reschedule_action(int irq, void *data)
150 scheduler_ipi();
151 return IRQ_HANDLED;
154 static irqreturn_t tick_broadcast_ipi_action(int irq, void *data)
156 tick_broadcast_ipi_handler();
157 return IRQ_HANDLED;
160 static irqreturn_t debug_ipi_action(int irq, void *data)
162 if (crash_ipi_function_ptr) {
163 crash_ipi_function_ptr(get_irq_regs());
164 return IRQ_HANDLED;
167 #ifdef CONFIG_DEBUGGER
168 debugger_ipi(get_irq_regs());
169 #endif /* CONFIG_DEBUGGER */
171 return IRQ_HANDLED;
174 static irq_handler_t smp_ipi_action[] = {
175 [PPC_MSG_CALL_FUNCTION] = call_function_action,
176 [PPC_MSG_RESCHEDULE] = reschedule_action,
177 [PPC_MSG_TICK_BROADCAST] = tick_broadcast_ipi_action,
178 [PPC_MSG_DEBUGGER_BREAK] = debug_ipi_action,
181 const char *smp_ipi_name[] = {
182 [PPC_MSG_CALL_FUNCTION] = "ipi call function",
183 [PPC_MSG_RESCHEDULE] = "ipi reschedule",
184 [PPC_MSG_TICK_BROADCAST] = "ipi tick-broadcast",
185 [PPC_MSG_DEBUGGER_BREAK] = "ipi debugger",
188 /* optional function to request ipi, for controllers with >= 4 ipis */
189 int smp_request_message_ipi(int virq, int msg)
191 int err;
193 if (msg < 0 || msg > PPC_MSG_DEBUGGER_BREAK) {
194 return -EINVAL;
196 #if !defined(CONFIG_DEBUGGER) && !defined(CONFIG_KEXEC)
197 if (msg == PPC_MSG_DEBUGGER_BREAK) {
198 return 1;
200 #endif
201 err = request_irq(virq, smp_ipi_action[msg],
202 IRQF_PERCPU | IRQF_NO_THREAD | IRQF_NO_SUSPEND,
203 smp_ipi_name[msg], NULL);
204 WARN(err < 0, "unable to request_irq %d for %s (rc %d)\n",
205 virq, smp_ipi_name[msg], err);
207 return err;
210 #ifdef CONFIG_PPC_SMP_MUXED_IPI
211 struct cpu_messages {
212 long messages; /* current messages */
213 unsigned long data; /* data for cause ipi */
215 static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
217 void smp_muxed_ipi_set_data(int cpu, unsigned long data)
219 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
221 info->data = data;
224 void smp_muxed_ipi_set_message(int cpu, int msg)
226 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
227 char *message = (char *)&info->messages;
230 * Order previous accesses before accesses in the IPI handler.
232 smp_mb();
233 message[msg] = 1;
236 void smp_muxed_ipi_message_pass(int cpu, int msg)
238 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
240 smp_muxed_ipi_set_message(cpu, msg);
242 * cause_ipi functions are required to include a full barrier
243 * before doing whatever causes the IPI.
245 smp_ops->cause_ipi(cpu, info->data);
248 #ifdef __BIG_ENDIAN__
249 #define IPI_MESSAGE(A) (1uL << ((BITS_PER_LONG - 8) - 8 * (A)))
250 #else
251 #define IPI_MESSAGE(A) (1uL << (8 * (A)))
252 #endif
254 irqreturn_t smp_ipi_demux(void)
256 struct cpu_messages *info = this_cpu_ptr(&ipi_message);
257 unsigned long all;
259 mb(); /* order any irq clear */
261 do {
262 all = xchg(&info->messages, 0);
263 #if defined(CONFIG_KVM_XICS) && defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE)
265 * Must check for PPC_MSG_RM_HOST_ACTION messages
266 * before PPC_MSG_CALL_FUNCTION messages because when
267 * a VM is destroyed, we call kick_all_cpus_sync()
268 * to ensure that any pending PPC_MSG_RM_HOST_ACTION
269 * messages have completed before we free any VCPUs.
271 if (all & IPI_MESSAGE(PPC_MSG_RM_HOST_ACTION))
272 kvmppc_xics_ipi_action();
273 #endif
274 if (all & IPI_MESSAGE(PPC_MSG_CALL_FUNCTION))
275 generic_smp_call_function_interrupt();
276 if (all & IPI_MESSAGE(PPC_MSG_RESCHEDULE))
277 scheduler_ipi();
278 if (all & IPI_MESSAGE(PPC_MSG_TICK_BROADCAST))
279 tick_broadcast_ipi_handler();
280 if (all & IPI_MESSAGE(PPC_MSG_DEBUGGER_BREAK))
281 debug_ipi_action(0, NULL);
282 } while (info->messages);
284 return IRQ_HANDLED;
286 #endif /* CONFIG_PPC_SMP_MUXED_IPI */
288 static inline void do_message_pass(int cpu, int msg)
290 if (smp_ops->message_pass)
291 smp_ops->message_pass(cpu, msg);
292 #ifdef CONFIG_PPC_SMP_MUXED_IPI
293 else
294 smp_muxed_ipi_message_pass(cpu, msg);
295 #endif
298 void smp_send_reschedule(int cpu)
300 if (likely(smp_ops))
301 do_message_pass(cpu, PPC_MSG_RESCHEDULE);
303 EXPORT_SYMBOL_GPL(smp_send_reschedule);
305 void arch_send_call_function_single_ipi(int cpu)
307 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
310 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
312 unsigned int cpu;
314 for_each_cpu(cpu, mask)
315 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
318 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
319 void tick_broadcast(const struct cpumask *mask)
321 unsigned int cpu;
323 for_each_cpu(cpu, mask)
324 do_message_pass(cpu, PPC_MSG_TICK_BROADCAST);
326 #endif
328 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
329 void smp_send_debugger_break(void)
331 int cpu;
332 int me = raw_smp_processor_id();
334 if (unlikely(!smp_ops))
335 return;
337 for_each_online_cpu(cpu)
338 if (cpu != me)
339 do_message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
341 #endif
343 #ifdef CONFIG_KEXEC
344 void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
346 crash_ipi_function_ptr = crash_ipi_callback;
347 if (crash_ipi_callback) {
348 mb();
349 smp_send_debugger_break();
352 #endif
354 static void stop_this_cpu(void *dummy)
356 /* Remove this CPU */
357 set_cpu_online(smp_processor_id(), false);
359 local_irq_disable();
360 while (1)
364 void smp_send_stop(void)
366 smp_call_function(stop_this_cpu, NULL, 0);
369 struct thread_info *current_set[NR_CPUS];
371 static void smp_store_cpu_info(int id)
373 per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
374 #ifdef CONFIG_PPC_FSL_BOOK3E
375 per_cpu(next_tlbcam_idx, id)
376 = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
377 #endif
380 void __init smp_prepare_cpus(unsigned int max_cpus)
382 unsigned int cpu;
384 DBG("smp_prepare_cpus\n");
387 * setup_cpu may need to be called on the boot cpu. We havent
388 * spun any cpus up but lets be paranoid.
390 BUG_ON(boot_cpuid != smp_processor_id());
392 /* Fixup boot cpu */
393 smp_store_cpu_info(boot_cpuid);
394 cpu_callin_map[boot_cpuid] = 1;
396 for_each_possible_cpu(cpu) {
397 zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu),
398 GFP_KERNEL, cpu_to_node(cpu));
399 zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
400 GFP_KERNEL, cpu_to_node(cpu));
402 * numa_node_id() works after this.
404 if (cpu_present(cpu)) {
405 set_cpu_numa_node(cpu, numa_cpu_lookup_table[cpu]);
406 set_cpu_numa_mem(cpu,
407 local_memory_node(numa_cpu_lookup_table[cpu]));
411 cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
412 cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
414 if (smp_ops && smp_ops->probe)
415 smp_ops->probe();
418 void smp_prepare_boot_cpu(void)
420 BUG_ON(smp_processor_id() != boot_cpuid);
421 #ifdef CONFIG_PPC64
422 paca[boot_cpuid].__current = current;
423 #endif
424 set_numa_node(numa_cpu_lookup_table[boot_cpuid]);
425 current_set[boot_cpuid] = task_thread_info(current);
428 #ifdef CONFIG_HOTPLUG_CPU
430 int generic_cpu_disable(void)
432 unsigned int cpu = smp_processor_id();
434 if (cpu == boot_cpuid)
435 return -EBUSY;
437 set_cpu_online(cpu, false);
438 #ifdef CONFIG_PPC64
439 vdso_data->processorCount--;
440 #endif
441 migrate_irqs();
442 return 0;
445 void generic_cpu_die(unsigned int cpu)
447 int i;
449 for (i = 0; i < 100; i++) {
450 smp_rmb();
451 if (is_cpu_dead(cpu))
452 return;
453 msleep(100);
455 printk(KERN_ERR "CPU%d didn't die...\n", cpu);
458 void generic_set_cpu_dead(unsigned int cpu)
460 per_cpu(cpu_state, cpu) = CPU_DEAD;
464 * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
465 * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
466 * which makes the delay in generic_cpu_die() not happen.
468 void generic_set_cpu_up(unsigned int cpu)
470 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
473 int generic_check_cpu_restart(unsigned int cpu)
475 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
478 int is_cpu_dead(unsigned int cpu)
480 return per_cpu(cpu_state, cpu) == CPU_DEAD;
483 static bool secondaries_inhibited(void)
485 return kvm_hv_mode_active();
488 #else /* HOTPLUG_CPU */
490 #define secondaries_inhibited() 0
492 #endif
494 static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
496 struct thread_info *ti = task_thread_info(idle);
498 #ifdef CONFIG_PPC64
499 paca[cpu].__current = idle;
500 paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
501 #endif
502 ti->cpu = cpu;
503 secondary_ti = current_set[cpu] = ti;
506 int __cpu_up(unsigned int cpu, struct task_struct *tidle)
508 int rc, c;
511 * Don't allow secondary threads to come online if inhibited
513 if (threads_per_core > 1 && secondaries_inhibited() &&
514 cpu_thread_in_subcore(cpu))
515 return -EBUSY;
517 if (smp_ops == NULL ||
518 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
519 return -EINVAL;
521 cpu_idle_thread_init(cpu, tidle);
523 /* Make sure callin-map entry is 0 (can be leftover a CPU
524 * hotplug
526 cpu_callin_map[cpu] = 0;
528 /* The information for processor bringup must
529 * be written out to main store before we release
530 * the processor.
532 smp_mb();
534 /* wake up cpus */
535 DBG("smp: kicking cpu %d\n", cpu);
536 rc = smp_ops->kick_cpu(cpu);
537 if (rc) {
538 pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
539 return rc;
543 * wait to see if the cpu made a callin (is actually up).
544 * use this value that I found through experimentation.
545 * -- Cort
547 if (system_state < SYSTEM_RUNNING)
548 for (c = 50000; c && !cpu_callin_map[cpu]; c--)
549 udelay(100);
550 #ifdef CONFIG_HOTPLUG_CPU
551 else
553 * CPUs can take much longer to come up in the
554 * hotplug case. Wait five seconds.
556 for (c = 5000; c && !cpu_callin_map[cpu]; c--)
557 msleep(1);
558 #endif
560 if (!cpu_callin_map[cpu]) {
561 printk(KERN_ERR "Processor %u is stuck.\n", cpu);
562 return -ENOENT;
565 DBG("Processor %u found.\n", cpu);
567 if (smp_ops->give_timebase)
568 smp_ops->give_timebase();
570 /* Wait until cpu puts itself in the online & active maps */
571 while (!cpu_online(cpu))
572 cpu_relax();
574 return 0;
577 /* Return the value of the reg property corresponding to the given
578 * logical cpu.
580 int cpu_to_core_id(int cpu)
582 struct device_node *np;
583 const __be32 *reg;
584 int id = -1;
586 np = of_get_cpu_node(cpu, NULL);
587 if (!np)
588 goto out;
590 reg = of_get_property(np, "reg", NULL);
591 if (!reg)
592 goto out;
594 id = be32_to_cpup(reg);
595 out:
596 of_node_put(np);
597 return id;
599 EXPORT_SYMBOL_GPL(cpu_to_core_id);
601 /* Helper routines for cpu to core mapping */
602 int cpu_core_index_of_thread(int cpu)
604 return cpu >> threads_shift;
606 EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
608 int cpu_first_thread_of_core(int core)
610 return core << threads_shift;
612 EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
614 static void traverse_siblings_chip_id(int cpu, bool add, int chipid)
616 const struct cpumask *mask;
617 struct device_node *np;
618 int i, plen;
619 const __be32 *prop;
621 mask = add ? cpu_online_mask : cpu_present_mask;
622 for_each_cpu(i, mask) {
623 np = of_get_cpu_node(i, NULL);
624 if (!np)
625 continue;
626 prop = of_get_property(np, "ibm,chip-id", &plen);
627 if (prop && plen == sizeof(int) &&
628 of_read_number(prop, 1) == chipid) {
629 if (add) {
630 cpumask_set_cpu(cpu, cpu_core_mask(i));
631 cpumask_set_cpu(i, cpu_core_mask(cpu));
632 } else {
633 cpumask_clear_cpu(cpu, cpu_core_mask(i));
634 cpumask_clear_cpu(i, cpu_core_mask(cpu));
637 of_node_put(np);
641 /* Must be called when no change can occur to cpu_present_mask,
642 * i.e. during cpu online or offline.
644 static struct device_node *cpu_to_l2cache(int cpu)
646 struct device_node *np;
647 struct device_node *cache;
649 if (!cpu_present(cpu))
650 return NULL;
652 np = of_get_cpu_node(cpu, NULL);
653 if (np == NULL)
654 return NULL;
656 cache = of_find_next_cache_node(np);
658 of_node_put(np);
660 return cache;
663 static void traverse_core_siblings(int cpu, bool add)
665 struct device_node *l2_cache, *np;
666 const struct cpumask *mask;
667 int i, chip, plen;
668 const __be32 *prop;
670 /* First see if we have ibm,chip-id properties in cpu nodes */
671 np = of_get_cpu_node(cpu, NULL);
672 if (np) {
673 chip = -1;
674 prop = of_get_property(np, "ibm,chip-id", &plen);
675 if (prop && plen == sizeof(int))
676 chip = of_read_number(prop, 1);
677 of_node_put(np);
678 if (chip >= 0) {
679 traverse_siblings_chip_id(cpu, add, chip);
680 return;
684 l2_cache = cpu_to_l2cache(cpu);
685 mask = add ? cpu_online_mask : cpu_present_mask;
686 for_each_cpu(i, mask) {
687 np = cpu_to_l2cache(i);
688 if (!np)
689 continue;
690 if (np == l2_cache) {
691 if (add) {
692 cpumask_set_cpu(cpu, cpu_core_mask(i));
693 cpumask_set_cpu(i, cpu_core_mask(cpu));
694 } else {
695 cpumask_clear_cpu(cpu, cpu_core_mask(i));
696 cpumask_clear_cpu(i, cpu_core_mask(cpu));
699 of_node_put(np);
701 of_node_put(l2_cache);
704 /* Activate a secondary processor. */
705 void start_secondary(void *unused)
707 unsigned int cpu = smp_processor_id();
708 int i, base;
710 atomic_inc(&init_mm.mm_count);
711 current->active_mm = &init_mm;
713 smp_store_cpu_info(cpu);
714 set_dec(tb_ticks_per_jiffy);
715 preempt_disable();
716 cpu_callin_map[cpu] = 1;
718 if (smp_ops->setup_cpu)
719 smp_ops->setup_cpu(cpu);
720 if (smp_ops->take_timebase)
721 smp_ops->take_timebase();
723 secondary_cpu_time_init();
725 #ifdef CONFIG_PPC64
726 if (system_state == SYSTEM_RUNNING)
727 vdso_data->processorCount++;
729 vdso_getcpu_init();
730 #endif
731 /* Update sibling maps */
732 base = cpu_first_thread_sibling(cpu);
733 for (i = 0; i < threads_per_core; i++) {
734 if (cpu_is_offline(base + i) && (cpu != base + i))
735 continue;
736 cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
737 cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
739 /* cpu_core_map should be a superset of
740 * cpu_sibling_map even if we don't have cache
741 * information, so update the former here, too.
743 cpumask_set_cpu(cpu, cpu_core_mask(base + i));
744 cpumask_set_cpu(base + i, cpu_core_mask(cpu));
746 traverse_core_siblings(cpu, true);
748 set_numa_node(numa_cpu_lookup_table[cpu]);
749 set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
751 smp_wmb();
752 notify_cpu_starting(cpu);
753 set_cpu_online(cpu, true);
755 local_irq_enable();
757 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
759 BUG();
762 int setup_profiling_timer(unsigned int multiplier)
764 return 0;
767 #ifdef CONFIG_SCHED_SMT
768 /* cpumask of CPUs with asymetric SMT dependancy */
769 static int powerpc_smt_flags(void)
771 int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
773 if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
774 printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
775 flags |= SD_ASYM_PACKING;
777 return flags;
779 #endif
781 static struct sched_domain_topology_level powerpc_topology[] = {
782 #ifdef CONFIG_SCHED_SMT
783 { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
784 #endif
785 { cpu_cpu_mask, SD_INIT_NAME(DIE) },
786 { NULL, },
789 void __init smp_cpus_done(unsigned int max_cpus)
791 cpumask_var_t old_mask;
793 /* We want the setup_cpu() here to be called from CPU 0, but our
794 * init thread may have been "borrowed" by another CPU in the meantime
795 * se we pin us down to CPU 0 for a short while
797 alloc_cpumask_var(&old_mask, GFP_NOWAIT);
798 cpumask_copy(old_mask, tsk_cpus_allowed(current));
799 set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid));
801 if (smp_ops && smp_ops->setup_cpu)
802 smp_ops->setup_cpu(boot_cpuid);
804 set_cpus_allowed_ptr(current, old_mask);
806 free_cpumask_var(old_mask);
808 if (smp_ops && smp_ops->bringup_done)
809 smp_ops->bringup_done();
811 dump_numa_cpu_topology();
813 set_sched_topology(powerpc_topology);
817 #ifdef CONFIG_HOTPLUG_CPU
818 int __cpu_disable(void)
820 int cpu = smp_processor_id();
821 int base, i;
822 int err;
824 if (!smp_ops->cpu_disable)
825 return -ENOSYS;
827 err = smp_ops->cpu_disable();
828 if (err)
829 return err;
831 /* Update sibling maps */
832 base = cpu_first_thread_sibling(cpu);
833 for (i = 0; i < threads_per_core && base + i < nr_cpu_ids; i++) {
834 cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
835 cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
836 cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
837 cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
839 traverse_core_siblings(cpu, false);
841 return 0;
844 void __cpu_die(unsigned int cpu)
846 if (smp_ops->cpu_die)
847 smp_ops->cpu_die(cpu);
850 void cpu_die(void)
852 if (ppc_md.cpu_die)
853 ppc_md.cpu_die();
855 /* If we return, we re-enter start_secondary */
856 start_secondary_resume();
859 #endif