Linux-2.6.12-rc2
[linux-2.6/next.git] / arch / sh / kernel / smp.c
blob56a39d69e080dae1b12fade6656ea18c6d5479a2
1 /*
2 * arch/sh/kernel/smp.c
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>
26 #include <asm/atomic.h>
27 #include <asm/processor.h>
28 #include <asm/system.h>
29 #include <asm/mmu_context.h>
30 #include <asm/smp.h>
33 * This was written with the Sega Saturn (SMP SH-2 7604) in mind,
34 * but is designed to be usable regardless if there's an MMU
35 * present or not.
37 struct sh_cpuinfo cpu_data[NR_CPUS];
39 extern void per_cpu_trap_init(void);
41 cpumask_t cpu_possible_map;
42 cpumask_t cpu_online_map;
43 static atomic_t cpus_booted = ATOMIC_INIT(0);
45 /* These are defined by the board-specific code. */
48 * Cause the function described by call_data to be executed on the passed
49 * cpu. When the function has finished, increment the finished field of
50 * call_data.
52 void __smp_send_ipi(unsigned int cpu, unsigned int action);
55 * Find the number of available processors
57 unsigned int __smp_probe_cpus(void);
60 * Start a particular processor
62 void __smp_slave_init(unsigned int cpu);
65 * Run specified function on a particular processor.
67 void __smp_call_function(unsigned int cpu);
69 static inline void __init smp_store_cpu_info(unsigned int cpu)
71 cpu_data[cpu].loops_per_jiffy = loops_per_jiffy;
74 void __init smp_prepare_cpus(unsigned int max_cpus)
76 unsigned int cpu = smp_processor_id();
77 int i;
79 atomic_set(&cpus_booted, 1);
80 smp_store_cpu_info(cpu);
82 for (i = 0; i < __smp_probe_cpus(); i++)
83 cpu_set(i, cpu_possible_map);
86 void __devinit smp_prepare_boot_cpu(void)
88 unsigned int cpu = smp_processor_id();
90 cpu_set(cpu, cpu_online_map);
91 cpu_set(cpu, cpu_possible_map);
94 int __cpu_up(unsigned int cpu)
96 struct task_struct *tsk;
98 tsk = fork_idle(cpu);
100 if (IS_ERR(tsk))
101 panic("Failed forking idle task for cpu %d\n", cpu);
103 tsk->thread_info->cpu = cpu;
105 cpu_set(cpu, cpu_online_map);
107 return 0;
110 int start_secondary(void *unused)
112 unsigned int cpu = smp_processor_id();
114 atomic_inc(&init_mm.mm_count);
115 current->active_mm = &init_mm;
117 smp_store_cpu_info(cpu);
119 __smp_slave_init(cpu);
120 per_cpu_trap_init();
122 atomic_inc(&cpus_booted);
124 cpu_idle();
125 return 0;
128 void __init smp_cpus_done(unsigned int max_cpus)
130 smp_mb();
133 void smp_send_reschedule(int cpu)
135 __smp_send_ipi(cpu, SMP_MSG_RESCHEDULE);
138 static void stop_this_cpu(void *unused)
140 cpu_clear(smp_processor_id(), cpu_online_map);
141 local_irq_disable();
143 for (;;)
144 cpu_relax();
147 void smp_send_stop(void)
149 smp_call_function(stop_this_cpu, 0, 1, 0);
153 struct smp_fn_call_struct smp_fn_call = {
154 .lock = SPIN_LOCK_UNLOCKED,
155 .finished = ATOMIC_INIT(0),
159 * The caller of this wants the passed function to run on every cpu. If wait
160 * is set, wait until all cpus have finished the function before returning.
161 * The lock is here to protect the call structure.
162 * You must not call this function with disabled interrupts or from a
163 * hardware interrupt handler or from a bottom half handler.
165 int smp_call_function(void (*func)(void *info), void *info, int retry, int wait)
167 unsigned int nr_cpus = atomic_read(&cpus_booted);
168 int i;
170 if (nr_cpus < 2)
171 return 0;
173 /* Can deadlock when called with interrupts disabled */
174 WARN_ON(irqs_disabled());
176 spin_lock(&smp_fn_call.lock);
178 atomic_set(&smp_fn_call.finished, 0);
179 smp_fn_call.fn = func;
180 smp_fn_call.data = info;
182 for (i = 0; i < nr_cpus; i++)
183 if (i != smp_processor_id())
184 __smp_call_function(i);
186 if (wait)
187 while (atomic_read(&smp_fn_call.finished) != (nr_cpus - 1));
189 spin_unlock(&smp_fn_call.lock);
191 return 0;
194 /* Not really SMP stuff ... */
195 int setup_profiling_timer(unsigned int multiplier)
197 return 0;