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/cpu.h>
22 #include <linux/interrupt.h>
23 #include <asm/atomic.h>
24 #include <asm/processor.h>
25 #include <asm/system.h>
26 #include <asm/mmu_context.h>
28 #include <asm/cacheflush.h>
29 #include <asm/sections.h>
31 int __cpu_number_map
[NR_CPUS
]; /* Map physical to logical */
32 int __cpu_logical_map
[NR_CPUS
]; /* Map logical to physical */
34 cpumask_t cpu_possible_map
;
35 EXPORT_SYMBOL(cpu_possible_map
);
37 cpumask_t cpu_online_map
;
38 EXPORT_SYMBOL(cpu_online_map
);
40 static inline void __init
smp_store_cpu_info(unsigned int cpu
)
42 struct sh_cpuinfo
*c
= cpu_data
+ cpu
;
44 c
->loops_per_jiffy
= loops_per_jiffy
;
47 void __init
smp_prepare_cpus(unsigned int max_cpus
)
49 unsigned int cpu
= smp_processor_id();
51 init_new_context(current
, &init_mm
);
52 current_thread_info()->cpu
= cpu
;
53 plat_prepare_cpus(max_cpus
);
55 #ifndef CONFIG_HOTPLUG_CPU
56 cpu_present_map
= cpu_possible_map
;
60 void __devinit
smp_prepare_boot_cpu(void)
62 unsigned int cpu
= smp_processor_id();
64 __cpu_number_map
[0] = cpu
;
65 __cpu_logical_map
[0] = cpu
;
67 cpu_set(cpu
, cpu_online_map
);
68 cpu_set(cpu
, cpu_possible_map
);
71 asmlinkage
void __cpuinit
start_secondary(void)
74 struct mm_struct
*mm
= &init_mm
;
76 atomic_inc(&mm
->mm_count
);
77 atomic_inc(&mm
->mm_users
);
78 current
->active_mm
= mm
;
80 enter_lazy_tlb(mm
, current
);
86 notify_cpu_starting(smp_processor_id());
90 cpu
= smp_processor_id();
92 /* Enable local timers */
93 local_timer_setup(cpu
);
96 smp_store_cpu_info(cpu
);
98 cpu_set(cpu
, cpu_online_map
);
105 unsigned long bss_start
;
106 unsigned long bss_end
;
107 void *start_kernel_fn
;
112 int __cpuinit
__cpu_up(unsigned int cpu
)
114 struct task_struct
*tsk
;
115 unsigned long timeout
;
117 tsk
= fork_idle(cpu
);
119 printk(KERN_ERR
"Failed forking idle task for cpu %d\n", cpu
);
123 /* Fill in data in head.S for secondary cpus */
124 stack_start
.sp
= tsk
->thread
.sp
;
125 stack_start
.thread_info
= tsk
->stack
;
126 stack_start
.bss_start
= 0; /* don't clear bss for secondary cpus */
127 stack_start
.start_kernel_fn
= start_secondary
;
131 plat_start_cpu(cpu
, (unsigned long)_stext
);
133 timeout
= jiffies
+ HZ
;
134 while (time_before(jiffies
, timeout
)) {
147 void __init
smp_cpus_done(unsigned int max_cpus
)
149 unsigned long bogosum
= 0;
152 for_each_online_cpu(cpu
)
153 bogosum
+= cpu_data
[cpu
].loops_per_jiffy
;
155 printk(KERN_INFO
"SMP: Total of %d processors activated "
156 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
157 bogosum
/ (500000/HZ
),
158 (bogosum
/ (5000/HZ
)) % 100);
161 void smp_send_reschedule(int cpu
)
163 plat_send_ipi(cpu
, SMP_MSG_RESCHEDULE
);
166 static void stop_this_cpu(void *unused
)
168 cpu_clear(smp_processor_id(), cpu_online_map
);
175 void smp_send_stop(void)
177 smp_call_function(stop_this_cpu
, 0, 0);
180 void arch_send_call_function_ipi(cpumask_t mask
)
184 for_each_cpu_mask(cpu
, mask
)
185 plat_send_ipi(cpu
, SMP_MSG_FUNCTION
);
188 void arch_send_call_function_single_ipi(int cpu
)
190 plat_send_ipi(cpu
, SMP_MSG_FUNCTION_SINGLE
);
193 void smp_timer_broadcast(cpumask_t mask
)
197 for_each_cpu_mask(cpu
, mask
)
198 plat_send_ipi(cpu
, SMP_MSG_TIMER
);
201 static void ipi_timer(void)
204 local_timer_interrupt();
208 void smp_message_recv(unsigned int msg
)
211 case SMP_MSG_FUNCTION
:
212 generic_smp_call_function_interrupt();
214 case SMP_MSG_RESCHEDULE
:
216 case SMP_MSG_FUNCTION_SINGLE
:
217 generic_smp_call_function_single_interrupt();
223 printk(KERN_WARNING
"SMP %d: %s(): unknown IPI %d\n",
224 smp_processor_id(), __func__
, msg
);
229 /* Not really SMP stuff ... */
230 int setup_profiling_timer(unsigned int multiplier
)
235 static void flush_tlb_all_ipi(void *info
)
237 local_flush_tlb_all();
240 void flush_tlb_all(void)
242 on_each_cpu(flush_tlb_all_ipi
, 0, 1);
245 static void flush_tlb_mm_ipi(void *mm
)
247 local_flush_tlb_mm((struct mm_struct
*)mm
);
251 * The following tlb flush calls are invoked when old translations are
252 * being torn down, or pte attributes are changing. For single threaded
253 * address spaces, a new context is obtained on the current cpu, and tlb
254 * context on other cpus are invalidated to force a new context allocation
255 * at switch_mm time, should the mm ever be used on other cpus. For
256 * multithreaded address spaces, intercpu interrupts have to be sent.
257 * Another case where intercpu interrupts are required is when the target
258 * mm might be active on another cpu (eg debuggers doing the flushes on
259 * behalf of debugees, kswapd stealing pages from another process etc).
263 void flush_tlb_mm(struct mm_struct
*mm
)
267 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
268 smp_call_function(flush_tlb_mm_ipi
, (void *)mm
, 1);
271 for (i
= 0; i
< num_online_cpus(); i
++)
272 if (smp_processor_id() != i
)
273 cpu_context(i
, mm
) = 0;
275 local_flush_tlb_mm(mm
);
280 struct flush_tlb_data
{
281 struct vm_area_struct
*vma
;
286 static void flush_tlb_range_ipi(void *info
)
288 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
290 local_flush_tlb_range(fd
->vma
, fd
->addr1
, fd
->addr2
);
293 void flush_tlb_range(struct vm_area_struct
*vma
,
294 unsigned long start
, unsigned long end
)
296 struct mm_struct
*mm
= vma
->vm_mm
;
299 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
300 struct flush_tlb_data fd
;
305 smp_call_function(flush_tlb_range_ipi
, (void *)&fd
, 1);
308 for (i
= 0; i
< num_online_cpus(); i
++)
309 if (smp_processor_id() != i
)
310 cpu_context(i
, mm
) = 0;
312 local_flush_tlb_range(vma
, start
, end
);
316 static void flush_tlb_kernel_range_ipi(void *info
)
318 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
320 local_flush_tlb_kernel_range(fd
->addr1
, fd
->addr2
);
323 void flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
325 struct flush_tlb_data fd
;
329 on_each_cpu(flush_tlb_kernel_range_ipi
, (void *)&fd
, 1);
332 static void flush_tlb_page_ipi(void *info
)
334 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
336 local_flush_tlb_page(fd
->vma
, fd
->addr1
);
339 void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
342 if ((atomic_read(&vma
->vm_mm
->mm_users
) != 1) ||
343 (current
->mm
!= vma
->vm_mm
)) {
344 struct flush_tlb_data fd
;
348 smp_call_function(flush_tlb_page_ipi
, (void *)&fd
, 1);
351 for (i
= 0; i
< num_online_cpus(); i
++)
352 if (smp_processor_id() != i
)
353 cpu_context(i
, vma
->vm_mm
) = 0;
355 local_flush_tlb_page(vma
, page
);
359 static void flush_tlb_one_ipi(void *info
)
361 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
362 local_flush_tlb_one(fd
->addr1
, fd
->addr2
);
365 void flush_tlb_one(unsigned long asid
, unsigned long vaddr
)
367 struct flush_tlb_data fd
;
372 smp_call_function(flush_tlb_one_ipi
, (void *)&fd
, 1);
373 local_flush_tlb_one(asid
, vaddr
);