blob: 002cc612deef5ce9c93499e8a2ea4043050eb189 [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 Mundt173a44d2008-08-06 18:02:48 +09006 * Copyright (C) 2002 - 2008 Paul Mundt
Paul Mundtaba10302007-09-21 18:32:32 +09007 * 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 Mundtb56050a2008-10-21 12:39:24 +090021#include <linux/cpu.h>
Paul Mundtaba10302007-09-21 18:32:32 +090022#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/atomic.h>
24#include <asm/processor.h>
25#include <asm/system.h>
26#include <asm/mmu_context.h>
27#include <asm/smp.h>
Paul Mundtaba10302007-09-21 18:32:32 +090028#include <asm/cacheflush.h>
29#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Paul Mundtaba10302007-09-21 18:32:32 +090031int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
32int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static inline void __init smp_store_cpu_info(unsigned int cpu)
35{
Paul Mundtaba10302007-09-21 18:32:32 +090036 struct sh_cpuinfo *c = cpu_data + cpu;
37
Paul Mundta66c2ed2009-10-14 14:14:30 +090038 memcpy(c, &boot_cpu_data, sizeof(struct sh_cpuinfo));
39
Paul Mundtaba10302007-09-21 18:32:32 +090040 c->loops_per_jiffy = loops_per_jiffy;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
43void __init smp_prepare_cpus(unsigned int max_cpus)
44{
45 unsigned int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Paul Mundtaba10302007-09-21 18:32:32 +090047 init_new_context(current, &init_mm);
48 current_thread_info()->cpu = cpu;
49 plat_prepare_cpus(max_cpus);
50
51#ifndef CONFIG_HOTPLUG_CPU
Rusty Russelle09377b2009-06-12 22:33:14 +093052 init_cpu_present(&cpu_possible_map);
Paul Mundtaba10302007-09-21 18:32:32 +090053#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
56void __devinit smp_prepare_boot_cpu(void)
57{
58 unsigned int cpu = smp_processor_id();
59
Paul Mundtaba10302007-09-21 18:32:32 +090060 __cpu_number_map[0] = cpu;
61 __cpu_logical_map[0] = cpu;
62
Rusty Russelle09377b2009-06-12 22:33:14 +093063 set_cpu_online(cpu, true);
64 set_cpu_possible(cpu, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Paul Mundtaba10302007-09-21 18:32:32 +090067asmlinkage void __cpuinit start_secondary(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Paul Mundtaba10302007-09-21 18:32:32 +090069 unsigned int cpu;
70 struct mm_struct *mm = &init_mm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Matt Fleming4bea3412010-03-28 20:08:25 +000072 enable_mmu();
Paul Mundtaba10302007-09-21 18:32:32 +090073 atomic_inc(&mm->mm_count);
74 atomic_inc(&mm->mm_users);
75 current->active_mm = mm;
76 BUG_ON(current->mm);
77 enter_lazy_tlb(mm, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Paul Mundtaba10302007-09-21 18:32:32 +090079 per_cpu_trap_init();
80
81 preempt_disable();
82
Manfred Spraule545a612008-09-07 16:57:22 +020083 notify_cpu_starting(smp_processor_id());
84
Paul Mundtaba10302007-09-21 18:32:32 +090085 local_irq_enable();
86
Paul Mundt8c245942008-08-06 18:37:07 +090087 cpu = smp_processor_id();
88
89 /* Enable local timers */
90 local_timer_setup(cpu);
Paul Mundtaba10302007-09-21 18:32:32 +090091 calibrate_delay();
92
Paul Mundtaba10302007-09-21 18:32:32 +090093 smp_store_cpu_info(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 cpu_set(cpu, cpu_online_map);
96
Paul Mundtaba10302007-09-21 18:32:32 +090097 cpu_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Paul Mundtaba10302007-09-21 18:32:32 +0900100extern struct {
101 unsigned long sp;
102 unsigned long bss_start;
103 unsigned long bss_end;
104 void *start_kernel_fn;
105 void *cpu_init_fn;
106 void *thread_info;
107} stack_start;
108
109int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Paul Mundtaba10302007-09-21 18:32:32 +0900111 struct task_struct *tsk;
112 unsigned long timeout;
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800113
Paul Mundtaba10302007-09-21 18:32:32 +0900114 tsk = fork_idle(cpu);
115 if (IS_ERR(tsk)) {
116 printk(KERN_ERR "Failed forking idle task for cpu %d\n", cpu);
117 return PTR_ERR(tsk);
118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Paul Mundtaba10302007-09-21 18:32:32 +0900120 /* Fill in data in head.S for secondary cpus */
121 stack_start.sp = tsk->thread.sp;
122 stack_start.thread_info = tsk->stack;
123 stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
124 stack_start.start_kernel_fn = start_secondary;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Paul Mundtd7806132009-10-14 11:51:28 +0900126 flush_icache_range((unsigned long)&stack_start,
127 (unsigned long)&stack_start + sizeof(stack_start));
128 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Paul Mundtaba10302007-09-21 18:32:32 +0900130 plat_start_cpu(cpu, (unsigned long)_stext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Paul Mundtaba10302007-09-21 18:32:32 +0900132 timeout = jiffies + HZ;
133 while (time_before(jiffies, timeout)) {
134 if (cpu_online(cpu))
135 break;
136
137 udelay(10);
138 }
139
140 if (cpu_online(cpu))
141 return 0;
142
143 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
146void __init smp_cpus_done(unsigned int max_cpus)
147{
Paul Mundtaba10302007-09-21 18:32:32 +0900148 unsigned long bogosum = 0;
149 int cpu;
150
151 for_each_online_cpu(cpu)
152 bogosum += cpu_data[cpu].loops_per_jiffy;
153
154 printk(KERN_INFO "SMP: Total of %d processors activated "
155 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
156 bogosum / (500000/HZ),
157 (bogosum / (5000/HZ)) % 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160void smp_send_reschedule(int cpu)
161{
Paul Mundtaba10302007-09-21 18:32:32 +0900162 plat_send_ipi(cpu, SMP_MSG_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165void smp_send_stop(void)
166{
Jens Axboe8691e5a2008-06-06 11:18:06 +0200167 smp_call_function(stop_this_cpu, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Rusty Russell819807d2009-06-12 22:32:35 +0930170void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Jens Axboe490f5de2008-06-10 20:52:59 +0200172 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Rusty Russell819807d2009-06-12 22:32:35 +0930174 for_each_cpu(cpu, mask)
Jens Axboe490f5de2008-06-10 20:52:59 +0200175 plat_send_ipi(cpu, SMP_MSG_FUNCTION);
176}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Jens Axboe490f5de2008-06-10 20:52:59 +0200178void arch_send_call_function_single_ipi(int cpu)
179{
180 plat_send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Rusty Russell320ab2b2008-12-13 21:20:26 +1030183void smp_timer_broadcast(const struct cpumask *mask)
Paul Mundt6f527072008-08-06 18:21:03 +0900184{
185 int cpu;
186
Rusty Russell320ab2b2008-12-13 21:20:26 +1030187 for_each_cpu(cpu, mask)
Paul Mundt6f527072008-08-06 18:21:03 +0900188 plat_send_ipi(cpu, SMP_MSG_TIMER);
189}
190
191static void ipi_timer(void)
192{
193 irq_enter();
Paul Mundt8c245942008-08-06 18:37:07 +0900194 local_timer_interrupt();
Paul Mundt6f527072008-08-06 18:21:03 +0900195 irq_exit();
196}
197
Paul Mundt173a44d2008-08-06 18:02:48 +0900198void smp_message_recv(unsigned int msg)
199{
200 switch (msg) {
201 case SMP_MSG_FUNCTION:
202 generic_smp_call_function_interrupt();
203 break;
204 case SMP_MSG_RESCHEDULE:
205 break;
206 case SMP_MSG_FUNCTION_SINGLE:
207 generic_smp_call_function_single_interrupt();
208 break;
Paul Mundt6f527072008-08-06 18:21:03 +0900209 case SMP_MSG_TIMER:
210 ipi_timer();
211 break;
Paul Mundt173a44d2008-08-06 18:02:48 +0900212 default:
213 printk(KERN_WARNING "SMP %d: %s(): unknown IPI %d\n",
214 smp_processor_id(), __func__, msg);
215 break;
216 }
217}
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/* Not really SMP stuff ... */
220int setup_profiling_timer(unsigned int multiplier)
221{
222 return 0;
223}
224
Paul Mundt9964fa82007-09-21 18:09:55 +0900225static void flush_tlb_all_ipi(void *info)
226{
227 local_flush_tlb_all();
228}
229
230void flush_tlb_all(void)
231{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200232 on_each_cpu(flush_tlb_all_ipi, 0, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900233}
234
235static void flush_tlb_mm_ipi(void *mm)
236{
237 local_flush_tlb_mm((struct mm_struct *)mm);
238}
239
240/*
241 * The following tlb flush calls are invoked when old translations are
242 * being torn down, or pte attributes are changing. For single threaded
243 * address spaces, a new context is obtained on the current cpu, and tlb
244 * context on other cpus are invalidated to force a new context allocation
245 * at switch_mm time, should the mm ever be used on other cpus. For
246 * multithreaded address spaces, intercpu interrupts have to be sent.
247 * Another case where intercpu interrupts are required is when the target
248 * mm might be active on another cpu (eg debuggers doing the flushes on
249 * behalf of debugees, kswapd stealing pages from another process etc).
250 * Kanoj 07/00.
251 */
252
253void flush_tlb_mm(struct mm_struct *mm)
254{
255 preempt_disable();
256
257 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
Jens Axboe8691e5a2008-06-06 11:18:06 +0200258 smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900259 } else {
260 int i;
261 for (i = 0; i < num_online_cpus(); i++)
262 if (smp_processor_id() != i)
263 cpu_context(i, mm) = 0;
264 }
265 local_flush_tlb_mm(mm);
266
267 preempt_enable();
268}
269
270struct flush_tlb_data {
271 struct vm_area_struct *vma;
272 unsigned long addr1;
273 unsigned long addr2;
274};
275
276static void flush_tlb_range_ipi(void *info)
277{
278 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
279
280 local_flush_tlb_range(fd->vma, fd->addr1, fd->addr2);
281}
282
283void flush_tlb_range(struct vm_area_struct *vma,
284 unsigned long start, unsigned long end)
285{
286 struct mm_struct *mm = vma->vm_mm;
287
288 preempt_disable();
289 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
290 struct flush_tlb_data fd;
291
292 fd.vma = vma;
293 fd.addr1 = start;
294 fd.addr2 = end;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200295 smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900296 } else {
297 int i;
298 for (i = 0; i < num_online_cpus(); i++)
299 if (smp_processor_id() != i)
300 cpu_context(i, mm) = 0;
301 }
302 local_flush_tlb_range(vma, start, end);
303 preempt_enable();
304}
305
306static void flush_tlb_kernel_range_ipi(void *info)
307{
308 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
309
310 local_flush_tlb_kernel_range(fd->addr1, fd->addr2);
311}
312
313void flush_tlb_kernel_range(unsigned long start, unsigned long end)
314{
315 struct flush_tlb_data fd;
316
317 fd.addr1 = start;
318 fd.addr2 = end;
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200319 on_each_cpu(flush_tlb_kernel_range_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900320}
321
322static void flush_tlb_page_ipi(void *info)
323{
324 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
325
326 local_flush_tlb_page(fd->vma, fd->addr1);
327}
328
329void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
330{
331 preempt_disable();
332 if ((atomic_read(&vma->vm_mm->mm_users) != 1) ||
333 (current->mm != vma->vm_mm)) {
334 struct flush_tlb_data fd;
335
336 fd.vma = vma;
337 fd.addr1 = page;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200338 smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900339 } else {
340 int i;
341 for (i = 0; i < num_online_cpus(); i++)
342 if (smp_processor_id() != i)
343 cpu_context(i, vma->vm_mm) = 0;
344 }
345 local_flush_tlb_page(vma, page);
346 preempt_enable();
347}
348
349static void flush_tlb_one_ipi(void *info)
350{
351 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
352 local_flush_tlb_one(fd->addr1, fd->addr2);
353}
354
355void flush_tlb_one(unsigned long asid, unsigned long vaddr)
356{
357 struct flush_tlb_data fd;
358
359 fd.addr1 = asid;
360 fd.addr2 = vaddr;
361
Jens Axboe8691e5a2008-06-06 11:18:06 +0200362 smp_call_function(flush_tlb_one_ipi, (void *)&fd, 1);
Paul Mundt9964fa82007-09-21 18:09:55 +0900363 local_flush_tlb_one(asid, vaddr);
364}