4 * SMP support for the SuperH processors.
6 * Copyright (C) 2002 - 2010 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 struct plat_smp_ops
*mp_ops
= NULL
;
36 /* State of each CPU */
37 DEFINE_PER_CPU(int, cpu_state
) = { 0 };
39 void __cpuinit
register_smp_ops(struct plat_smp_ops
*ops
)
42 printk(KERN_WARNING
"Overriding previously set SMP ops\n");
47 static inline void __init
smp_store_cpu_info(unsigned int cpu
)
49 struct sh_cpuinfo
*c
= cpu_data
+ cpu
;
51 memcpy(c
, &boot_cpu_data
, sizeof(struct sh_cpuinfo
));
53 c
->loops_per_jiffy
= loops_per_jiffy
;
56 void __init
smp_prepare_cpus(unsigned int max_cpus
)
58 unsigned int cpu
= smp_processor_id();
60 init_new_context(current
, &init_mm
);
61 current_thread_info()->cpu
= cpu
;
62 mp_ops
->prepare_cpus(max_cpus
);
64 #ifndef CONFIG_HOTPLUG_CPU
65 init_cpu_present(&cpu_possible_map
);
69 void __devinit
smp_prepare_boot_cpu(void)
71 unsigned int cpu
= smp_processor_id();
73 __cpu_number_map
[0] = cpu
;
74 __cpu_logical_map
[0] = cpu
;
76 set_cpu_online(cpu
, true);
77 set_cpu_possible(cpu
, true);
79 per_cpu(cpu_state
, cpu
) = CPU_ONLINE
;
82 asmlinkage
void __cpuinit
start_secondary(void)
84 unsigned int cpu
= smp_processor_id();
85 struct mm_struct
*mm
= &init_mm
;
88 atomic_inc(&mm
->mm_count
);
89 atomic_inc(&mm
->mm_users
);
90 current
->active_mm
= mm
;
92 enter_lazy_tlb(mm
, current
);
98 notify_cpu_starting(cpu
);
102 /* Enable local timers */
103 local_timer_setup(cpu
);
106 smp_store_cpu_info(cpu
);
108 set_cpu_online(cpu
, true);
109 per_cpu(cpu_state
, cpu
) = CPU_ONLINE
;
116 unsigned long bss_start
;
117 unsigned long bss_end
;
118 void *start_kernel_fn
;
123 int __cpuinit
__cpu_up(unsigned int cpu
)
125 struct task_struct
*tsk
;
126 unsigned long timeout
;
128 tsk
= fork_idle(cpu
);
130 printk(KERN_ERR
"Failed forking idle task for cpu %d\n", cpu
);
134 per_cpu(cpu_state
, cpu
) = CPU_UP_PREPARE
;
136 /* Fill in data in head.S for secondary cpus */
137 stack_start
.sp
= tsk
->thread
.sp
;
138 stack_start
.thread_info
= tsk
->stack
;
139 stack_start
.bss_start
= 0; /* don't clear bss for secondary cpus */
140 stack_start
.start_kernel_fn
= start_secondary
;
142 flush_icache_range((unsigned long)&stack_start
,
143 (unsigned long)&stack_start
+ sizeof(stack_start
));
146 mp_ops
->start_cpu(cpu
, (unsigned long)_stext
);
148 timeout
= jiffies
+ HZ
;
149 while (time_before(jiffies
, timeout
)) {
162 void __init
smp_cpus_done(unsigned int max_cpus
)
164 unsigned long bogosum
= 0;
167 for_each_online_cpu(cpu
)
168 bogosum
+= cpu_data
[cpu
].loops_per_jiffy
;
170 printk(KERN_INFO
"SMP: Total of %d processors activated "
171 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
172 bogosum
/ (500000/HZ
),
173 (bogosum
/ (5000/HZ
)) % 100);
176 void smp_send_reschedule(int cpu
)
178 mp_ops
->send_ipi(cpu
, SMP_MSG_RESCHEDULE
);
181 void smp_send_stop(void)
183 smp_call_function(stop_this_cpu
, 0, 0);
186 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
190 for_each_cpu(cpu
, mask
)
191 mp_ops
->send_ipi(cpu
, SMP_MSG_FUNCTION
);
194 void arch_send_call_function_single_ipi(int cpu
)
196 mp_ops
->send_ipi(cpu
, SMP_MSG_FUNCTION_SINGLE
);
199 void smp_timer_broadcast(const struct cpumask
*mask
)
203 for_each_cpu(cpu
, mask
)
204 mp_ops
->send_ipi(cpu
, SMP_MSG_TIMER
);
207 static void ipi_timer(void)
210 local_timer_interrupt();
214 void smp_message_recv(unsigned int msg
)
217 case SMP_MSG_FUNCTION
:
218 generic_smp_call_function_interrupt();
220 case SMP_MSG_RESCHEDULE
:
222 case SMP_MSG_FUNCTION_SINGLE
:
223 generic_smp_call_function_single_interrupt();
229 printk(KERN_WARNING
"SMP %d: %s(): unknown IPI %d\n",
230 smp_processor_id(), __func__
, msg
);
235 /* Not really SMP stuff ... */
236 int setup_profiling_timer(unsigned int multiplier
)
241 static void flush_tlb_all_ipi(void *info
)
243 local_flush_tlb_all();
246 void flush_tlb_all(void)
248 on_each_cpu(flush_tlb_all_ipi
, 0, 1);
251 static void flush_tlb_mm_ipi(void *mm
)
253 local_flush_tlb_mm((struct mm_struct
*)mm
);
257 * The following tlb flush calls are invoked when old translations are
258 * being torn down, or pte attributes are changing. For single threaded
259 * address spaces, a new context is obtained on the current cpu, and tlb
260 * context on other cpus are invalidated to force a new context allocation
261 * at switch_mm time, should the mm ever be used on other cpus. For
262 * multithreaded address spaces, intercpu interrupts have to be sent.
263 * Another case where intercpu interrupts are required is when the target
264 * mm might be active on another cpu (eg debuggers doing the flushes on
265 * behalf of debugees, kswapd stealing pages from another process etc).
269 void flush_tlb_mm(struct mm_struct
*mm
)
273 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
274 smp_call_function(flush_tlb_mm_ipi
, (void *)mm
, 1);
277 for (i
= 0; i
< num_online_cpus(); i
++)
278 if (smp_processor_id() != i
)
279 cpu_context(i
, mm
) = 0;
281 local_flush_tlb_mm(mm
);
286 struct flush_tlb_data
{
287 struct vm_area_struct
*vma
;
292 static void flush_tlb_range_ipi(void *info
)
294 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
296 local_flush_tlb_range(fd
->vma
, fd
->addr1
, fd
->addr2
);
299 void flush_tlb_range(struct vm_area_struct
*vma
,
300 unsigned long start
, unsigned long end
)
302 struct mm_struct
*mm
= vma
->vm_mm
;
305 if ((atomic_read(&mm
->mm_users
) != 1) || (current
->mm
!= mm
)) {
306 struct flush_tlb_data fd
;
311 smp_call_function(flush_tlb_range_ipi
, (void *)&fd
, 1);
314 for (i
= 0; i
< num_online_cpus(); i
++)
315 if (smp_processor_id() != i
)
316 cpu_context(i
, mm
) = 0;
318 local_flush_tlb_range(vma
, start
, end
);
322 static void flush_tlb_kernel_range_ipi(void *info
)
324 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
326 local_flush_tlb_kernel_range(fd
->addr1
, fd
->addr2
);
329 void flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
331 struct flush_tlb_data fd
;
335 on_each_cpu(flush_tlb_kernel_range_ipi
, (void *)&fd
, 1);
338 static void flush_tlb_page_ipi(void *info
)
340 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
342 local_flush_tlb_page(fd
->vma
, fd
->addr1
);
345 void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
348 if ((atomic_read(&vma
->vm_mm
->mm_users
) != 1) ||
349 (current
->mm
!= vma
->vm_mm
)) {
350 struct flush_tlb_data fd
;
354 smp_call_function(flush_tlb_page_ipi
, (void *)&fd
, 1);
357 for (i
= 0; i
< num_online_cpus(); i
++)
358 if (smp_processor_id() != i
)
359 cpu_context(i
, vma
->vm_mm
) = 0;
361 local_flush_tlb_page(vma
, page
);
365 static void flush_tlb_one_ipi(void *info
)
367 struct flush_tlb_data
*fd
= (struct flush_tlb_data
*)info
;
368 local_flush_tlb_one(fd
->addr1
, fd
->addr2
);
371 void flush_tlb_one(unsigned long asid
, unsigned long vaddr
)
373 struct flush_tlb_data fd
;
378 smp_call_function(flush_tlb_one_ipi
, (void *)&fd
, 1);
379 local_flush_tlb_one(asid
, vaddr
);