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/cache.h>
14 #include <linux/cpumask.h>
15 #include <linux/delay.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/spinlock.h>
19 #include <linux/threads.h>
20 #include <linux/module.h>
21 #include <linux/time.h>
22 #include <linux/timex.h>
23 #include <linux/sched.h>
24 #include <linux/module.h>
26 #include <asm/atomic.h>
27 #include <asm/processor.h>
28 #include <asm/system.h>
29 #include <asm/mmu_context.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
37 struct sh_cpuinfo cpu_data
[NR_CPUS
];
39 extern void per_cpu_trap_init(void);
41 cpumask_t cpu_possible_map
;
42 EXPORT_SYMBOL(cpu_possible_map
);
44 cpumask_t cpu_online_map
;
45 static atomic_t cpus_booted
= ATOMIC_INIT(0);
47 /* These are defined by the board-specific code. */
50 * Cause the function described by call_data to be executed on the passed
51 * cpu. When the function has finished, increment the finished field of
54 void __smp_send_ipi(unsigned int cpu
, unsigned int action
);
57 * Find the number of available processors
59 unsigned int __smp_probe_cpus(void);
62 * Start a particular processor
64 void __smp_slave_init(unsigned int cpu
);
67 * Run specified function on a particular processor.
69 void __smp_call_function(unsigned int cpu
);
71 static inline void __init
smp_store_cpu_info(unsigned int cpu
)
73 cpu_data
[cpu
].loops_per_jiffy
= loops_per_jiffy
;
76 void __init
smp_prepare_cpus(unsigned int max_cpus
)
78 unsigned int cpu
= smp_processor_id();
81 atomic_set(&cpus_booted
, 1);
82 smp_store_cpu_info(cpu
);
84 for (i
= 0; i
< __smp_probe_cpus(); i
++)
85 cpu_set(i
, cpu_possible_map
);
88 void __devinit
smp_prepare_boot_cpu(void)
90 unsigned int cpu
= smp_processor_id();
92 cpu_set(cpu
, cpu_online_map
);
93 cpu_set(cpu
, cpu_possible_map
);
96 int __cpu_up(unsigned int cpu
)
98 struct task_struct
*tsk
;
100 tsk
= fork_idle(cpu
);
103 panic("Failed forking idle task for cpu %d\n", cpu
);
105 task_thread_info(tsk
)->cpu
= cpu
;
107 cpu_set(cpu
, cpu_online_map
);
112 int start_secondary(void *unused
)
116 cpu
= smp_processor_id();
118 atomic_inc(&init_mm
.mm_count
);
119 current
->active_mm
= &init_mm
;
121 smp_store_cpu_info(cpu
);
123 __smp_slave_init(cpu
);
127 atomic_inc(&cpus_booted
);
133 void __init
smp_cpus_done(unsigned int max_cpus
)
138 void smp_send_reschedule(int cpu
)
140 __smp_send_ipi(cpu
, SMP_MSG_RESCHEDULE
);
143 static void stop_this_cpu(void *unused
)
145 cpu_clear(smp_processor_id(), cpu_online_map
);
152 void smp_send_stop(void)
154 smp_call_function(stop_this_cpu
, 0, 1, 0);
158 struct smp_fn_call_struct smp_fn_call
= {
159 .lock
= SPIN_LOCK_UNLOCKED
,
160 .finished
= ATOMIC_INIT(0),
164 * The caller of this wants the passed function to run on every cpu. If wait
165 * is set, wait until all cpus have finished the function before returning.
166 * The lock is here to protect the call structure.
167 * You must not call this function with disabled interrupts or from a
168 * hardware interrupt handler or from a bottom half handler.
170 int smp_call_function(void (*func
)(void *info
), void *info
, int retry
, int wait
)
172 unsigned int nr_cpus
= atomic_read(&cpus_booted
);
178 /* Can deadlock when called with interrupts disabled */
179 WARN_ON(irqs_disabled());
181 spin_lock(&smp_fn_call
.lock
);
183 atomic_set(&smp_fn_call
.finished
, 0);
184 smp_fn_call
.fn
= func
;
185 smp_fn_call
.data
= info
;
187 for (i
= 0; i
< nr_cpus
; i
++)
188 if (i
!= smp_processor_id())
189 __smp_call_function(i
);
192 while (atomic_read(&smp_fn_call
.finished
) != (nr_cpus
- 1));
194 spin_unlock(&smp_fn_call
.lock
);
199 /* Not really SMP stuff ... */
200 int setup_profiling_timer(unsigned int multiplier
)