4 * SMP support for the SuperH processors.
6 * Copyright (C) 2002 - 2008 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);
85 notify_cpu_starting(smp_processor_id());
89 cpu = smp_processor_id();
91 /* Enable local timers */
92 local_timer_setup(cpu);
95 smp_store_cpu_info(cpu);
97 cpu_set(cpu, cpu_online_map);
104 unsigned long bss_start;
105 unsigned long bss_end;
106 void *start_kernel_fn;
111 int __cpuinit __cpu_up(unsigned int cpu)
113 struct task_struct *tsk;
114 unsigned long timeout;
116 tsk = fork_idle(cpu);
118 printk(KERN_ERR "Failed forking idle task for cpu %d\n", cpu);
122 /* Fill in data in head.S for secondary cpus */
123 stack_start.sp = tsk->thread.sp;
124 stack_start.thread_info = tsk->stack;
125 stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
126 stack_start.start_kernel_fn = start_secondary;
130 plat_start_cpu(cpu, (unsigned long)_stext);
132 timeout = jiffies + HZ;
133 while (time_before(jiffies, timeout)) {
146 void __init smp_cpus_done(unsigned int max_cpus)
148 unsigned long bogosum = 0;
151 for_each_online_cpu(cpu)
152 bogosum += cpu_data[cpu].loops_per_jiffy;
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);
160 void smp_send_reschedule(int cpu)
162 plat_send_ipi(cpu, SMP_MSG_RESCHEDULE);
165 static void stop_this_cpu(void *unused)
167 cpu_clear(smp_processor_id(), cpu_online_map);
174 void smp_send_stop(void)
176 smp_call_function(stop_this_cpu, 0, 0);
179 void arch_send_call_function_ipi(cpumask_t mask)
183 for_each_cpu_mask(cpu, mask)
184 plat_send_ipi(cpu, SMP_MSG_FUNCTION);
187 void arch_send_call_function_single_ipi(int cpu)
189 plat_send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
192 void smp_timer_broadcast(cpumask_t mask)
196 for_each_cpu_mask(cpu, mask)
197 plat_send_ipi(cpu, SMP_MSG_TIMER);
200 static void ipi_timer(void)
203 local_timer_interrupt();
207 void smp_message_recv(unsigned int msg)
210 case SMP_MSG_FUNCTION:
211 generic_smp_call_function_interrupt();
213 case SMP_MSG_RESCHEDULE:
215 case SMP_MSG_FUNCTION_SINGLE:
216 generic_smp_call_function_single_interrupt();
222 printk(KERN_WARNING "SMP %d: %s(): unknown IPI %d\n",
223 smp_processor_id(), __func__, msg);
228 /* Not really SMP stuff ... */
229 int setup_profiling_timer(unsigned int multiplier)
234 static void flush_tlb_all_ipi(void *info)
236 local_flush_tlb_all();
239 void flush_tlb_all(void)
241 on_each_cpu(flush_tlb_all_ipi, 0, 1);
244 static void flush_tlb_mm_ipi(void *mm)
246 local_flush_tlb_mm((struct mm_struct *)mm);
250 * The following tlb flush calls are invoked when old translations are
251 * being torn down, or pte attributes are changing. For single threaded
252 * address spaces, a new context is obtained on the current cpu, and tlb
253 * context on other cpus are invalidated to force a new context allocation
254 * at switch_mm time, should the mm ever be used on other cpus. For
255 * multithreaded address spaces, intercpu interrupts have to be sent.
256 * Another case where intercpu interrupts are required is when the target
257 * mm might be active on another cpu (eg debuggers doing the flushes on
258 * behalf of debugees, kswapd stealing pages from another process etc).
262 void flush_tlb_mm(struct mm_struct *mm)
266 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
267 smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
270 for (i = 0; i < num_online_cpus(); i++)
271 if (smp_processor_id() != i)
272 cpu_context(i, mm) = 0;
274 local_flush_tlb_mm(mm);
279 struct flush_tlb_data {
280 struct vm_area_struct *vma;
285 static void flush_tlb_range_ipi(void *info)
287 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
289 local_flush_tlb_range(fd->vma, fd->addr1, fd->addr2);
292 void flush_tlb_range(struct vm_area_struct *vma,
293 unsigned long start, unsigned long end)
295 struct mm_struct *mm = vma->vm_mm;
298 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
299 struct flush_tlb_data fd;
304 smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
307 for (i = 0; i < num_online_cpus(); i++)
308 if (smp_processor_id() != i)
309 cpu_context(i, mm) = 0;
311 local_flush_tlb_range(vma, start, end);
315 static void flush_tlb_kernel_range_ipi(void *info)
317 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
319 local_flush_tlb_kernel_range(fd->addr1, fd->addr2);
322 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
324 struct flush_tlb_data fd;
328 on_each_cpu(flush_tlb_kernel_range_ipi, (void *)&fd, 1);
331 static void flush_tlb_page_ipi(void *info)
333 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
335 local_flush_tlb_page(fd->vma, fd->addr1);
338 void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
341 if ((atomic_read(&vma->vm_mm->mm_users) != 1) ||
342 (current->mm != vma->vm_mm)) {
343 struct flush_tlb_data fd;
347 smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
350 for (i = 0; i < num_online_cpus(); i++)
351 if (smp_processor_id() != i)
352 cpu_context(i, vma->vm_mm) = 0;
354 local_flush_tlb_page(vma, page);
358 static void flush_tlb_one_ipi(void *info)
360 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
361 local_flush_tlb_one(fd->addr1, fd->addr2);
364 void flush_tlb_one(unsigned long asid, unsigned long vaddr)
366 struct flush_tlb_data fd;
371 smp_call_function(flush_tlb_one_ipi, (void *)&fd, 1);
372 local_flush_tlb_one(asid, vaddr);