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 static inline void __init
smp_store_cpu_info(unsigned int cpu
)
36 struct sh_cpuinfo
*c
= cpu_data
+ cpu
;
38 c
->loops_per_jiffy
= loops_per_jiffy
;
41 void __init
smp_prepare_cpus(unsigned int max_cpus
)
43 unsigned int cpu
= smp_processor_id();
45 init_new_context(current
, &init_mm
);
46 current_thread_info()->cpu
= cpu
;
47 plat_prepare_cpus(max_cpus
);
49 #ifndef CONFIG_HOTPLUG_CPU
50 cpu_present_map
= cpu_possible_map
;
54 void __devinit
smp_prepare_boot_cpu(void)
56 unsigned int cpu
= smp_processor_id();
58 __cpu_number_map
[0] = cpu
;
59 __cpu_logical_map
[0] = cpu
;
61 cpu_set(cpu
, cpu_online_map
);
62 cpu_set(cpu
, cpu_possible_map
);
65 asmlinkage
void __cpuinit
start_secondary(void)
68 struct mm_struct
*mm
= &init_mm
;
70 atomic_inc(&mm
->mm_count
);
71 atomic_inc(&mm
->mm_users
);
72 current
->active_mm
= mm
;
74 enter_lazy_tlb(mm
, current
);
80 notify_cpu_starting(smp_processor_id());
84 cpu
= smp_processor_id();
86 /* Enable local timers */
87 local_timer_setup(cpu
);
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 void smp_timer_broadcast(const struct cpumask
*mask
)
191 for_each_cpu(cpu
, mask
)
192 plat_send_ipi(cpu
, SMP_MSG_TIMER
);
195 static void ipi_timer(void)
198 local_timer_interrupt();
202 void smp_message_recv(unsigned int msg
)
205 case SMP_MSG_FUNCTION
:
206 generic_smp_call_function_interrupt();
208 case SMP_MSG_RESCHEDULE
:
210 case SMP_MSG_FUNCTION_SINGLE
:
211 generic_smp_call_function_single_interrupt();
217 printk(KERN_WARNING
"SMP %d: %s(): unknown IPI %d\n",
218 smp_processor_id(), __func__
, msg
);
223 /* Not really SMP stuff ... */
224 int setup_profiling_timer(unsigned int multiplier
)
229 static void flush_tlb_all_ipi(void *info
)
231 local_flush_tlb_all();
234 void flush_tlb_all(void)
236 on_each_cpu(flush_tlb_all_ipi
, 0, 1);
239 static void flush_tlb_mm_ipi(void *mm
)
241 local_flush_tlb_mm((struct mm_struct
*)mm
);
245 * The following tlb flush calls are invoked when old translations are
246 * being torn down, or pte attributes are changing. For single threaded
247 * address spaces, a new context is obtained on the current cpu, and tlb
248 * context on other cpus are invalidated to force a new context allocation
249 * at switch_mm time, should the mm ever be used on other cpus. For
250 * multithreaded address spaces, intercpu interrupts have to be sent.
251 * Another case where intercpu interrupts are required is when the target
252 * mm might be active on another cpu (eg debuggers doing the flushes on
253 * behalf of debugees, kswapd stealing pages from another process etc).
257 void flush_tlb_mm(struct mm_struct
*mm
)
261 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
262 smp_call_function(flush_tlb_mm_ipi
, (void *)mm
, 1);
265 for (i
= 0; i
< num_online_cpus(); i
++)
266 if (smp_processor_id() != i
)
267 cpu_context(i
, mm
) = 0;
269 local_flush_tlb_mm(mm
);
274 struct flush_tlb_data
{
275 struct vm_area_struct
*vma
;
280 static void flush_tlb_range_ipi(void *info
)
282 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
284 local_flush_tlb_range(fd
->vma
, fd
->addr1
, fd
->addr2
);
287 void flush_tlb_range(struct vm_area_struct
*vma
,
288 unsigned long start
, unsigned long end
)
290 struct mm_struct
*mm
= vma
->vm_mm
;
293 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
294 struct flush_tlb_data fd
;
299 smp_call_function(flush_tlb_range_ipi
, (void *)&fd
, 1);
302 for (i
= 0; i
< num_online_cpus(); i
++)
303 if (smp_processor_id() != i
)
304 cpu_context(i
, mm
) = 0;
306 local_flush_tlb_range(vma
, start
, end
);
310 static void flush_tlb_kernel_range_ipi(void *info
)
312 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
314 local_flush_tlb_kernel_range(fd
->addr1
, fd
->addr2
);
317 void flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
319 struct flush_tlb_data fd
;
323 on_each_cpu(flush_tlb_kernel_range_ipi
, (void *)&fd
, 1);
326 static void flush_tlb_page_ipi(void *info
)
328 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
330 local_flush_tlb_page(fd
->vma
, fd
->addr1
);
333 void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
336 if ((atomic_read(&vma
->vm_mm
->mm_users
) != 1) ||
337 (current
->mm
!= vma
->vm_mm
)) {
338 struct flush_tlb_data fd
;
342 smp_call_function(flush_tlb_page_ipi
, (void *)&fd
, 1);
345 for (i
= 0; i
< num_online_cpus(); i
++)
346 if (smp_processor_id() != i
)
347 cpu_context(i
, vma
->vm_mm
) = 0;
349 local_flush_tlb_page(vma
, page
);
353 static void flush_tlb_one_ipi(void *info
)
355 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
356 local_flush_tlb_one(fd
->addr1
, fd
->addr2
);
359 void flush_tlb_one(unsigned long asid
, unsigned long vaddr
)
361 struct flush_tlb_data fd
;
366 smp_call_function(flush_tlb_one_ipi
, (void *)&fd
, 1);
367 local_flush_tlb_one(asid
, vaddr
);