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 memcpy(c
, &boot_cpu_data
, sizeof(struct sh_cpuinfo
));
40 c
->loops_per_jiffy
= loops_per_jiffy
;
43 void __init
smp_prepare_cpus(unsigned int max_cpus
)
45 unsigned int cpu
= smp_processor_id();
47 init_new_context(current
, &init_mm
);
48 current_thread_info()->cpu
= cpu
;
49 plat_prepare_cpus(max_cpus
);
51 #ifndef CONFIG_HOTPLUG_CPU
52 init_cpu_present(&cpu_possible_map
);
56 void __devinit
smp_prepare_boot_cpu(void)
58 unsigned int cpu
= smp_processor_id();
60 __cpu_number_map
[0] = cpu
;
61 __cpu_logical_map
[0] = cpu
;
63 set_cpu_online(cpu
, true);
64 set_cpu_possible(cpu
, true);
67 asmlinkage
void __cpuinit
start_secondary(void)
70 struct mm_struct
*mm
= &init_mm
;
73 atomic_inc(&mm
->mm_count
);
74 atomic_inc(&mm
->mm_users
);
75 current
->active_mm
= mm
;
77 enter_lazy_tlb(mm
, current
);
83 notify_cpu_starting(smp_processor_id());
87 cpu
= smp_processor_id();
89 /* Enable local timers */
90 local_timer_setup(cpu
);
93 smp_store_cpu_info(cpu
);
95 cpu_set(cpu
, cpu_online_map
);
102 unsigned long bss_start
;
103 unsigned long bss_end
;
104 void *start_kernel_fn
;
109 int __cpuinit
__cpu_up(unsigned int cpu
)
111 struct task_struct
*tsk
;
112 unsigned long timeout
;
114 tsk
= fork_idle(cpu
);
116 printk(KERN_ERR
"Failed forking idle task for cpu %d\n", cpu
);
120 /* 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
;
128 plat_start_cpu(cpu
, (unsigned long)_stext
);
130 timeout
= jiffies
+ HZ
;
131 while (time_before(jiffies
, timeout
)) {
144 void __init
smp_cpus_done(unsigned int max_cpus
)
146 unsigned long bogosum
= 0;
149 for_each_online_cpu(cpu
)
150 bogosum
+= cpu_data
[cpu
].loops_per_jiffy
;
152 printk(KERN_INFO
"SMP: Total of %d processors activated "
153 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
154 bogosum
/ (500000/HZ
),
155 (bogosum
/ (5000/HZ
)) % 100);
158 void smp_send_reschedule(int cpu
)
160 plat_send_ipi(cpu
, SMP_MSG_RESCHEDULE
);
163 static void stop_this_cpu(void *unused
)
165 cpu_clear(smp_processor_id(), cpu_online_map
);
172 void smp_send_stop(void)
174 smp_call_function(stop_this_cpu
, 0, 0);
177 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
181 for_each_cpu(cpu
, mask
)
182 plat_send_ipi(cpu
, SMP_MSG_FUNCTION
);
185 void arch_send_call_function_single_ipi(int cpu
)
187 plat_send_ipi(cpu
, SMP_MSG_FUNCTION_SINGLE
);
190 void smp_timer_broadcast(const struct cpumask
*mask
)
194 for_each_cpu(cpu
, mask
)
195 plat_send_ipi(cpu
, SMP_MSG_TIMER
);
198 static void ipi_timer(void)
201 local_timer_interrupt();
205 void smp_message_recv(unsigned int msg
)
208 case SMP_MSG_FUNCTION
:
209 generic_smp_call_function_interrupt();
211 case SMP_MSG_RESCHEDULE
:
213 case SMP_MSG_FUNCTION_SINGLE
:
214 generic_smp_call_function_single_interrupt();
220 printk(KERN_WARNING
"SMP %d: %s(): unknown IPI %d\n",
221 smp_processor_id(), __func__
, msg
);
226 /* Not really SMP stuff ... */
227 int setup_profiling_timer(unsigned int multiplier
)
232 static void flush_tlb_all_ipi(void *info
)
234 local_flush_tlb_all();
237 void flush_tlb_all(void)
239 on_each_cpu(flush_tlb_all_ipi
, 0, 1);
242 static void flush_tlb_mm_ipi(void *mm
)
244 local_flush_tlb_mm((struct mm_struct
*)mm
);
248 * The following tlb flush calls are invoked when old translations are
249 * being torn down, or pte attributes are changing. For single threaded
250 * address spaces, a new context is obtained on the current cpu, and tlb
251 * context on other cpus are invalidated to force a new context allocation
252 * at switch_mm time, should the mm ever be used on other cpus. For
253 * multithreaded address spaces, intercpu interrupts have to be sent.
254 * Another case where intercpu interrupts are required is when the target
255 * mm might be active on another cpu (eg debuggers doing the flushes on
256 * behalf of debugees, kswapd stealing pages from another process etc).
260 void flush_tlb_mm(struct mm_struct
*mm
)
264 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
265 smp_call_function(flush_tlb_mm_ipi
, (void *)mm
, 1);
268 for (i
= 0; i
< num_online_cpus(); i
++)
269 if (smp_processor_id() != i
)
270 cpu_context(i
, mm
) = 0;
272 local_flush_tlb_mm(mm
);
277 struct flush_tlb_data
{
278 struct vm_area_struct
*vma
;
283 static void flush_tlb_range_ipi(void *info
)
285 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
287 local_flush_tlb_range(fd
->vma
, fd
->addr1
, fd
->addr2
);
290 void flush_tlb_range(struct vm_area_struct
*vma
,
291 unsigned long start
, unsigned long end
)
293 struct mm_struct
*mm
= vma
->vm_mm
;
296 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
297 struct flush_tlb_data fd
;
302 smp_call_function(flush_tlb_range_ipi
, (void *)&fd
, 1);
305 for (i
= 0; i
< num_online_cpus(); i
++)
306 if (smp_processor_id() != i
)
307 cpu_context(i
, mm
) = 0;
309 local_flush_tlb_range(vma
, start
, end
);
313 static void flush_tlb_kernel_range_ipi(void *info
)
315 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
317 local_flush_tlb_kernel_range(fd
->addr1
, fd
->addr2
);
320 void flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
322 struct flush_tlb_data fd
;
326 on_each_cpu(flush_tlb_kernel_range_ipi
, (void *)&fd
, 1);
329 static void flush_tlb_page_ipi(void *info
)
331 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
333 local_flush_tlb_page(fd
->vma
, fd
->addr1
);
336 void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
339 if ((atomic_read(&vma
->vm_mm
->mm_users
) != 1) ||
340 (current
->mm
!= vma
->vm_mm
)) {
341 struct flush_tlb_data fd
;
345 smp_call_function(flush_tlb_page_ipi
, (void *)&fd
, 1);
348 for (i
= 0; i
< num_online_cpus(); i
++)
349 if (smp_processor_id() != i
)
350 cpu_context(i
, vma
->vm_mm
) = 0;
352 local_flush_tlb_page(vma
, page
);
356 static void flush_tlb_one_ipi(void *info
)
358 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
359 local_flush_tlb_one(fd
->addr1
, fd
->addr2
);
362 void flush_tlb_one(unsigned long asid
, unsigned long vaddr
)
364 struct flush_tlb_data fd
;
369 smp_call_function(flush_tlb_one_ipi
, (void *)&fd
, 1);
370 local_flush_tlb_one(asid
, vaddr
);