blob: 001778f9adaf83eee6cb3766866809516d346bc0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/kernel/smp.c
3 *
4 * SMP support for the SuperH processors.
5 *
Paul Mundtaba10302007-09-21 18:32:32 +09006 * Copyright (C) 2002 - 2007 Paul Mundt
7 * Copyright (C) 2006 - 2007 Akio Idehara
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Paul Mundtaba10302007-09-21 18:32:32 +09009 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
Evgeniy Polyakov66c52272007-05-31 13:46:21 +090013#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/cache.h>
15#include <linux/cpumask.h>
16#include <linux/delay.h>
17#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/spinlock.h>
Paul Mundtaba10302007-09-21 18:32:32 +090019#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
Paul Mundtaba10302007-09-21 18:32:32 +090021#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/atomic.h>
23#include <asm/processor.h>
24#include <asm/system.h>
25#include <asm/mmu_context.h>
26#include <asm/smp.h>
Paul Mundtaba10302007-09-21 18:32:32 +090027#include <asm/cacheflush.h>
28#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Paul Mundtaba10302007-09-21 18:32:32 +090030int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
31int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33cpumask_t cpu_possible_map;
David S. Millerc8923c62005-10-13 14:41:23 -070034EXPORT_SYMBOL(cpu_possible_map);
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036cpumask_t cpu_online_map;
Greg Bankse16b38f2006-10-02 02:17:40 -070037EXPORT_SYMBOL(cpu_online_map);
Paul Mundtaba10302007-09-21 18:32:32 +090038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static inline void __init smp_store_cpu_info(unsigned int cpu)
40{
Paul Mundtaba10302007-09-21 18:32:32 +090041 struct sh_cpuinfo *c = cpu_data + cpu;
42
43 c->loops_per_jiffy = loops_per_jiffy;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46void __init smp_prepare_cpus(unsigned int max_cpus)
47{
48 unsigned int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Paul Mundtaba10302007-09-21 18:32:32 +090050 init_new_context(current, &init_mm);
51 current_thread_info()->cpu = cpu;
52 plat_prepare_cpus(max_cpus);
53
54#ifndef CONFIG_HOTPLUG_CPU
55 cpu_present_map = cpu_possible_map;
56#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
59void __devinit smp_prepare_boot_cpu(void)
60{
61 unsigned int cpu = smp_processor_id();
62
Paul Mundtaba10302007-09-21 18:32:32 +090063 __cpu_number_map[0] = cpu;
64 __cpu_logical_map[0] = cpu;
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 cpu_set(cpu, cpu_online_map);
67 cpu_set(cpu, cpu_possible_map);
68}
69
Paul Mundtaba10302007-09-21 18:32:32 +090070asmlinkage void __cpuinit start_secondary(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Paul Mundtaba10302007-09-21 18:32:32 +090072 unsigned int cpu;
73 struct mm_struct *mm = &init_mm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Paul Mundtaba10302007-09-21 18:32:32 +090075 atomic_inc(&mm->mm_count);
76 atomic_inc(&mm->mm_users);
77 current->active_mm = mm;
78 BUG_ON(current->mm);
79 enter_lazy_tlb(mm, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Paul Mundtaba10302007-09-21 18:32:32 +090081 per_cpu_trap_init();
82
83 preempt_disable();
84
Manfred Spraule545a612008-09-07 16:57:22 +020085 notify_cpu_starting(smp_processor_id());
86
Paul Mundtaba10302007-09-21 18:32:32 +090087 local_irq_enable();
88
89 calibrate_delay();
90
91 cpu = smp_processor_id();
92 smp_store_cpu_info(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 cpu_set(cpu, cpu_online_map);
95
Paul Mundtaba10302007-09-21 18:32:32 +090096 cpu_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Paul Mundtaba10302007-09-21 18:32:32 +090099extern struct {
100 unsigned long sp;
101 unsigned long bss_start;
102 unsigned long bss_end;
103 void *start_kernel_fn;
104 void *cpu_init_fn;
105 void *thread_info;
106} stack_start;
107
108int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Paul Mundtaba10302007-09-21 18:32:32 +0900110 struct task_struct *tsk;
111 unsigned long timeout;
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800112
Paul Mundtaba10302007-09-21 18:32:32 +0900113 tsk = fork_idle(cpu);
114 if (IS_ERR(tsk)) {
115 printk(KERN_ERR "Failed forking idle task for cpu %d\n", cpu);
116 return PTR_ERR(tsk);
117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Paul Mundtaba10302007-09-21 18:32:32 +0900119 /* Fill in data in head.S for secondary cpus */
120 stack_start.sp = tsk->thread.sp;
121 stack_start.thread_info = tsk->stack;
122 stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
123 stack_start.start_kernel_fn = start_secondary;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Paul Mundtaba10302007-09-21 18:32:32 +0900125 flush_cache_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Paul Mundtaba10302007-09-21 18:32:32 +0900127 plat_start_cpu(cpu, (unsigned long)_stext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Paul Mundtaba10302007-09-21 18:32:32 +0900129 timeout = jiffies + HZ;
130 while (time_before(jiffies, timeout)) {
131 if (cpu_online(cpu))
132 break;
133
134 udelay(10);
135 }
136
137 if (cpu_online(cpu))
138 return 0;
139
140 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
143void __init smp_cpus_done(unsigned int max_cpus)
144{
Paul Mundtaba10302007-09-21 18:32:32 +0900145 unsigned long bogosum = 0;
146 int cpu;
147
148 for_each_online_cpu(cpu)
149 bogosum += cpu_data[cpu].loops_per_jiffy;
150
151 printk(KERN_INFO "SMP: Total of %d processors activated "
152 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
153 bogosum / (500000/HZ),
154 (bogosum / (5000/HZ)) % 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
157void smp_send_reschedule(int cpu)
158{
Paul Mundtaba10302007-09-21 18:32:32 +0900159 plat_send_ipi(cpu, SMP_MSG_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
162static void stop_this_cpu(void *unused)
163{
164 cpu_clear(smp_processor_id(), cpu_online_map);
165 local_irq_disable();
166
167 for (;;)
168 cpu_relax();
169}
170
171void smp_send_stop(void)
172{
Jens Axboe8691e5a2008-06-06 11:18:06 +0200173 smp_call_function(stop_this_cpu, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Jens Axboe490f5de2008-06-10 20:52:59 +0200176void arch_send_call_function_ipi(cpumask_t mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Jens Axboe490f5de2008-06-10 20:52:59 +0200178 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Jens Axboe490f5de2008-06-10 20:52:59 +0200180 for_each_cpu_mask(cpu, mask)
181 plat_send_ipi(cpu, SMP_MSG_FUNCTION);
182}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Jens Axboe490f5de2008-06-10 20:52:59 +0200184void arch_send_call_function_single_ipi(int cpu)
185{
186 plat_send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
189/* Not really SMP stuff ... */
190int setup_profiling_timer(unsigned int multiplier)
191{
192 return 0;
193}
194
Paul Mundt9964fa82007-09-21 18:09:55 +0900195static void flush_tlb_all_ipi(void *info)
196{
197 local_flush_tlb_all();
198}
199
200void flush_tlb_all(void)
201{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200202 on_each_cpu(flush_tlb_all_ipi, 0, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900203}
204
205static void flush_tlb_mm_ipi(void *mm)
206{
207 local_flush_tlb_mm((struct mm_struct *)mm);
208}
209
210/*
211 * The following tlb flush calls are invoked when old translations are
212 * being torn down, or pte attributes are changing. For single threaded
213 * address spaces, a new context is obtained on the current cpu, and tlb
214 * context on other cpus are invalidated to force a new context allocation
215 * at switch_mm time, should the mm ever be used on other cpus. For
216 * multithreaded address spaces, intercpu interrupts have to be sent.
217 * Another case where intercpu interrupts are required is when the target
218 * mm might be active on another cpu (eg debuggers doing the flushes on
219 * behalf of debugees, kswapd stealing pages from another process etc).
220 * Kanoj 07/00.
221 */
222
223void flush_tlb_mm(struct mm_struct *mm)
224{
225 preempt_disable();
226
227 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
Jens Axboe8691e5a2008-06-06 11:18:06 +0200228 smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900229 } else {
230 int i;
231 for (i = 0; i < num_online_cpus(); i++)
232 if (smp_processor_id() != i)
233 cpu_context(i, mm) = 0;
234 }
235 local_flush_tlb_mm(mm);
236
237 preempt_enable();
238}
239
240struct flush_tlb_data {
241 struct vm_area_struct *vma;
242 unsigned long addr1;
243 unsigned long addr2;
244};
245
246static void flush_tlb_range_ipi(void *info)
247{
248 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
249
250 local_flush_tlb_range(fd->vma, fd->addr1, fd->addr2);
251}
252
253void flush_tlb_range(struct vm_area_struct *vma,
254 unsigned long start, unsigned long end)
255{
256 struct mm_struct *mm = vma->vm_mm;
257
258 preempt_disable();
259 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
260 struct flush_tlb_data fd;
261
262 fd.vma = vma;
263 fd.addr1 = start;
264 fd.addr2 = end;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200265 smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900266 } else {
267 int i;
268 for (i = 0; i < num_online_cpus(); i++)
269 if (smp_processor_id() != i)
270 cpu_context(i, mm) = 0;
271 }
272 local_flush_tlb_range(vma, start, end);
273 preempt_enable();
274}
275
276static void flush_tlb_kernel_range_ipi(void *info)
277{
278 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
279
280 local_flush_tlb_kernel_range(fd->addr1, fd->addr2);
281}
282
283void flush_tlb_kernel_range(unsigned long start, unsigned long end)
284{
285 struct flush_tlb_data fd;
286
287 fd.addr1 = start;
288 fd.addr2 = end;
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200289 on_each_cpu(flush_tlb_kernel_range_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900290}
291
292static void flush_tlb_page_ipi(void *info)
293{
294 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
295
296 local_flush_tlb_page(fd->vma, fd->addr1);
297}
298
299void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
300{
301 preempt_disable();
302 if ((atomic_read(&vma->vm_mm->mm_users) != 1) ||
303 (current->mm != vma->vm_mm)) {
304 struct flush_tlb_data fd;
305
306 fd.vma = vma;
307 fd.addr1 = page;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200308 smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900309 } else {
310 int i;
311 for (i = 0; i < num_online_cpus(); i++)
312 if (smp_processor_id() != i)
313 cpu_context(i, vma->vm_mm) = 0;
314 }
315 local_flush_tlb_page(vma, page);
316 preempt_enable();
317}
318
319static void flush_tlb_one_ipi(void *info)
320{
321 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
322 local_flush_tlb_one(fd->addr1, fd->addr2);
323}
324
325void flush_tlb_one(unsigned long asid, unsigned long vaddr)
326{
327 struct flush_tlb_data fd;
328
329 fd.addr1 = asid;
330 fd.addr2 = vaddr;
331
Jens Axboe8691e5a2008-06-06 11:18:06 +0200332 smp_call_function(flush_tlb_one_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900333 local_flush_tlb_one(asid, vaddr);
334}