4 * SMP support for the SuperH processors.
6 * Copyright (C) 2002, 2003 Paul Mundt
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 #include <linux/config.h>
14 #include <linux/cache.h>
15 #include <linux/cpumask.h>
16 #include <linux/delay.h>
17 #include <linux/init.h>
18 #include <linux/interrupt.h>
19 #include <linux/spinlock.h>
20 #include <linux/threads.h>
21 #include <linux/module.h>
22 #include <linux/time.h>
23 #include <linux/timex.h>
24 #include <linux/sched.h>
25 #include <linux/module.h>
27 #include <asm/atomic.h>
28 #include <asm/processor.h>
29 #include <asm/system.h>
30 #include <asm/mmu_context.h>
34 * This was written with the Sega Saturn (SMP SH-2 7604) in mind,
35 * but is designed to be usable regardless if there's an MMU
38 struct sh_cpuinfo cpu_data[NR_CPUS];
40 extern void per_cpu_trap_init(void);
42 cpumask_t cpu_possible_map;
43 EXPORT_SYMBOL(cpu_possible_map);
45 cpumask_t cpu_online_map;
46 static atomic_t cpus_booted = ATOMIC_INIT(0);
48 /* These are defined by the board-specific code. */
51 * Cause the function described by call_data to be executed on the passed
52 * cpu. When the function has finished, increment the finished field of
55 void __smp_send_ipi(unsigned int cpu, unsigned int action);
58 * Find the number of available processors
60 unsigned int __smp_probe_cpus(void);
63 * Start a particular processor
65 void __smp_slave_init(unsigned int cpu);
68 * Run specified function on a particular processor.
70 void __smp_call_function(unsigned int cpu);
72 static inline void __init smp_store_cpu_info(unsigned int cpu)
74 cpu_data[cpu].loops_per_jiffy = loops_per_jiffy;
77 void __init smp_prepare_cpus(unsigned int max_cpus)
79 unsigned int cpu = smp_processor_id();
82 atomic_set(&cpus_booted, 1);
83 smp_store_cpu_info(cpu);
85 for (i = 0; i < __smp_probe_cpus(); i++)
86 cpu_set(i, cpu_possible_map);
89 void __devinit smp_prepare_boot_cpu(void)
91 unsigned int cpu = smp_processor_id();
93 cpu_set(cpu, cpu_online_map);
94 cpu_set(cpu, cpu_possible_map);
97 int __cpu_up(unsigned int cpu)
99 struct task_struct *tsk;
101 tsk = fork_idle(cpu);
104 panic("Failed forking idle task for cpu %d\n", cpu);
106 tsk->thread_info->cpu = cpu;
108 cpu_set(cpu, cpu_online_map);
113 int start_secondary(void *unused)
115 unsigned int cpu = smp_processor_id();
117 atomic_inc(&init_mm.mm_count);
118 current->active_mm = &init_mm;
120 smp_store_cpu_info(cpu);
122 __smp_slave_init(cpu);
125 atomic_inc(&cpus_booted);
131 void __init smp_cpus_done(unsigned int max_cpus)
136 void smp_send_reschedule(int cpu)
138 __smp_send_ipi(cpu, SMP_MSG_RESCHEDULE);
141 static void stop_this_cpu(void *unused)
143 cpu_clear(smp_processor_id(), cpu_online_map);
150 void smp_send_stop(void)
152 smp_call_function(stop_this_cpu, 0, 1, 0);
156 struct smp_fn_call_struct smp_fn_call = {
157 .lock = SPIN_LOCK_UNLOCKED,
158 .finished = ATOMIC_INIT(0),
162 * The caller of this wants the passed function to run on every cpu. If wait
163 * is set, wait until all cpus have finished the function before returning.
164 * The lock is here to protect the call structure.
165 * You must not call this function with disabled interrupts or from a
166 * hardware interrupt handler or from a bottom half handler.
168 int smp_call_function(void (*func)(void *info), void *info, int retry, int wait)
170 unsigned int nr_cpus = atomic_read(&cpus_booted);
176 /* Can deadlock when called with interrupts disabled */
177 WARN_ON(irqs_disabled());
179 spin_lock(&smp_fn_call.lock);
181 atomic_set(&smp_fn_call.finished, 0);
182 smp_fn_call.fn = func;
183 smp_fn_call.data = info;
185 for (i = 0; i < nr_cpus; i++)
186 if (i != smp_processor_id())
187 __smp_call_function(i);
190 while (atomic_read(&smp_fn_call.finished) != (nr_cpus - 1));
192 spin_unlock(&smp_fn_call.lock);
197 /* Not really SMP stuff ... */
198 int setup_profiling_timer(unsigned int multiplier)