4 * SMP support for the SuperH processors.
6 * Copyright (C) 2002 - 2007 Paul Mundt
7 * Copyright (C) 2006 - 2007 Akio Idehara
9 * 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
13 #include <linux/err.h>
14 #include <linux/cache.h>
15 #include <linux/cpumask.h>
16 #include <linux/delay.h>
17 #include <linux/init.h>
18 #include <linux/spinlock.h>
20 #include <linux/module.h>
21 #include <linux/interrupt.h>
22 #include <asm/atomic.h>
23 #include <asm/processor.h>
24 #include <asm/system.h>
25 #include <asm/mmu_context.h>
27 #include <asm/cacheflush.h>
28 #include <asm/sections.h>
30 int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
31 int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
33 cpumask_t cpu_possible_map;
34 EXPORT_SYMBOL(cpu_possible_map);
36 cpumask_t cpu_online_map;
37 EXPORT_SYMBOL(cpu_online_map);
39 static inline void __init smp_store_cpu_info(unsigned int cpu)
41 struct sh_cpuinfo *c = cpu_data + cpu;
43 c->loops_per_jiffy = loops_per_jiffy;
46 void __init smp_prepare_cpus(unsigned int max_cpus)
48 unsigned int cpu = smp_processor_id();
50 init_new_context(current, &init_mm);
51 current_thread_info()->cpu = cpu;
52 plat_prepare_cpus(max_cpus);
54 #ifndef CONFIG_HOTPLUG_CPU
55 cpu_present_map = cpu_possible_map;
59 void __devinit smp_prepare_boot_cpu(void)
61 unsigned int cpu = smp_processor_id();
63 __cpu_number_map[0] = cpu;
64 __cpu_logical_map[0] = cpu;
66 cpu_set(cpu, cpu_online_map);
67 cpu_set(cpu, cpu_possible_map);
70 asmlinkage void __cpuinit start_secondary(void)
73 struct mm_struct *mm = &init_mm;
75 atomic_inc(&mm->mm_count);
76 atomic_inc(&mm->mm_users);
77 current->active_mm = mm;
79 enter_lazy_tlb(mm, current);
89 cpu = smp_processor_id();
90 smp_store_cpu_info(cpu);
92 cpu_set(cpu, cpu_online_map);
99 unsigned long bss_start;
100 unsigned long bss_end;
101 void *start_kernel_fn;
106 int __cpuinit __cpu_up(unsigned int cpu)
108 struct task_struct *tsk;
109 unsigned long timeout;
111 tsk = fork_idle(cpu);
113 printk(KERN_ERR "Failed forking idle task for cpu %d\n", cpu);
117 /* Fill in data in head.S for secondary cpus */
118 stack_start.sp = tsk->thread.sp;
119 stack_start.thread_info = tsk->stack;
120 stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
121 stack_start.start_kernel_fn = start_secondary;
125 plat_start_cpu(cpu, (unsigned long)_stext);
127 timeout = jiffies + HZ;
128 while (time_before(jiffies, timeout)) {
141 void __init smp_cpus_done(unsigned int max_cpus)
143 unsigned long bogosum = 0;
146 for_each_online_cpu(cpu)
147 bogosum += cpu_data[cpu].loops_per_jiffy;
149 printk(KERN_INFO "SMP: Total of %d processors activated "
150 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
151 bogosum / (500000/HZ),
152 (bogosum / (5000/HZ)) % 100);
155 void smp_send_reschedule(int cpu)
157 plat_send_ipi(cpu, SMP_MSG_RESCHEDULE);
160 static void stop_this_cpu(void *unused)
162 cpu_clear(smp_processor_id(), cpu_online_map);
169 void smp_send_stop(void)
171 smp_call_function(stop_this_cpu, 0, 0);
174 void arch_send_call_function_ipi(cpumask_t mask)
178 for_each_cpu_mask(cpu, mask)
179 plat_send_ipi(cpu, SMP_MSG_FUNCTION);
182 void arch_send_call_function_single_ipi(int cpu)
184 plat_send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
187 /* Not really SMP stuff ... */
188 int setup_profiling_timer(unsigned int multiplier)
193 static void flush_tlb_all_ipi(void *info)
195 local_flush_tlb_all();
198 void flush_tlb_all(void)
200 on_each_cpu(flush_tlb_all_ipi, 0, 1);
203 static void flush_tlb_mm_ipi(void *mm)
205 local_flush_tlb_mm((struct mm_struct *)mm);
209 * The following tlb flush calls are invoked when old translations are
210 * being torn down, or pte attributes are changing. For single threaded
211 * address spaces, a new context is obtained on the current cpu, and tlb
212 * context on other cpus are invalidated to force a new context allocation
213 * at switch_mm time, should the mm ever be used on other cpus. For
214 * multithreaded address spaces, intercpu interrupts have to be sent.
215 * Another case where intercpu interrupts are required is when the target
216 * mm might be active on another cpu (eg debuggers doing the flushes on
217 * behalf of debugees, kswapd stealing pages from another process etc).
221 void flush_tlb_mm(struct mm_struct *mm)
225 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
226 smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
229 for (i = 0; i < num_online_cpus(); i++)
230 if (smp_processor_id() != i)
231 cpu_context(i, mm) = 0;
233 local_flush_tlb_mm(mm);
238 struct flush_tlb_data {
239 struct vm_area_struct *vma;
244 static void flush_tlb_range_ipi(void *info)
246 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
248 local_flush_tlb_range(fd->vma, fd->addr1, fd->addr2);
251 void flush_tlb_range(struct vm_area_struct *vma,
252 unsigned long start, unsigned long end)
254 struct mm_struct *mm = vma->vm_mm;
257 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
258 struct flush_tlb_data fd;
263 smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
266 for (i = 0; i < num_online_cpus(); i++)
267 if (smp_processor_id() != i)
268 cpu_context(i, mm) = 0;
270 local_flush_tlb_range(vma, start, end);
274 static void flush_tlb_kernel_range_ipi(void *info)
276 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
278 local_flush_tlb_kernel_range(fd->addr1, fd->addr2);
281 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
283 struct flush_tlb_data fd;
287 on_each_cpu(flush_tlb_kernel_range_ipi, (void *)&fd, 1);
290 static void flush_tlb_page_ipi(void *info)
292 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
294 local_flush_tlb_page(fd->vma, fd->addr1);
297 void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
300 if ((atomic_read(&vma->vm_mm->mm_users) != 1) ||
301 (current->mm != vma->vm_mm)) {
302 struct flush_tlb_data fd;
306 smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
309 for (i = 0; i < num_online_cpus(); i++)
310 if (smp_processor_id() != i)
311 cpu_context(i, vma->vm_mm) = 0;
313 local_flush_tlb_page(vma, page);
317 static void flush_tlb_one_ipi(void *info)
319 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
320 local_flush_tlb_one(fd->addr1, fd->addr2);
323 void flush_tlb_one(unsigned long asid, unsigned long vaddr)
325 struct flush_tlb_data fd;
330 smp_call_function(flush_tlb_one_ipi, (void *)&fd, 1);
331 local_flush_tlb_one(asid, vaddr);