perf tools: Improve 'libbabel' feature check failure message
[linux/fpc-iii.git] / arch / sh / kernel / smp.c
blobfc5acfc93c92bf9cbce40bfd306331c3075b75d8
1 /*
2 * arch/sh/kernel/smp.c
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
11 * for more details.
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>
19 #include <linux/mm.h>
20 #include <linux/module.h>
21 #include <linux/cpu.h>
22 #include <linux/interrupt.h>
23 #include <linux/sched.h>
24 #include <linux/atomic.h>
25 #include <asm/processor.h>
26 #include <asm/mmu_context.h>
27 #include <asm/smp.h>
28 #include <asm/cacheflush.h>
29 #include <asm/sections.h>
30 #include <asm/setup.h>
32 int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
33 int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
35 struct plat_smp_ops *mp_ops = NULL;
37 /* State of each CPU */
38 DEFINE_PER_CPU(int, cpu_state) = { 0 };
40 void register_smp_ops(struct plat_smp_ops *ops)
42 if (mp_ops)
43 printk(KERN_WARNING "Overriding previously set SMP ops\n");
45 mp_ops = ops;
48 static inline void smp_store_cpu_info(unsigned int cpu)
50 struct sh_cpuinfo *c = cpu_data + cpu;
52 memcpy(c, &boot_cpu_data, sizeof(struct sh_cpuinfo));
54 c->loops_per_jiffy = loops_per_jiffy;
57 void __init smp_prepare_cpus(unsigned int max_cpus)
59 unsigned int cpu = smp_processor_id();
61 init_new_context(current, &init_mm);
62 current_thread_info()->cpu = cpu;
63 mp_ops->prepare_cpus(max_cpus);
65 #ifndef CONFIG_HOTPLUG_CPU
66 init_cpu_present(cpu_possible_mask);
67 #endif
70 void __init smp_prepare_boot_cpu(void)
72 unsigned int cpu = smp_processor_id();
74 __cpu_number_map[0] = cpu;
75 __cpu_logical_map[0] = cpu;
77 set_cpu_online(cpu, true);
78 set_cpu_possible(cpu, true);
80 per_cpu(cpu_state, cpu) = CPU_ONLINE;
83 #ifdef CONFIG_HOTPLUG_CPU
84 void native_cpu_die(unsigned int cpu)
86 unsigned int i;
88 for (i = 0; i < 10; i++) {
89 smp_rmb();
90 if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
91 if (system_state == SYSTEM_RUNNING)
92 pr_info("CPU %u is now offline\n", cpu);
94 return;
97 msleep(100);
100 pr_err("CPU %u didn't die...\n", cpu);
103 int native_cpu_disable(unsigned int cpu)
105 return cpu == 0 ? -EPERM : 0;
108 void play_dead_common(void)
110 idle_task_exit();
111 irq_ctx_exit(raw_smp_processor_id());
112 mb();
114 __this_cpu_write(cpu_state, CPU_DEAD);
115 local_irq_disable();
118 void native_play_dead(void)
120 play_dead_common();
123 int __cpu_disable(void)
125 unsigned int cpu = smp_processor_id();
126 int ret;
128 ret = mp_ops->cpu_disable(cpu);
129 if (ret)
130 return ret;
133 * Take this CPU offline. Once we clear this, we can't return,
134 * and we must not schedule until we're ready to give up the cpu.
136 set_cpu_online(cpu, false);
139 * OK - migrate IRQs away from this CPU
141 migrate_irqs();
144 * Stop the local timer for this CPU.
146 local_timer_stop(cpu);
149 * Flush user cache and TLB mappings, and then remove this CPU
150 * from the vm mask set of all processes.
152 flush_cache_all();
153 local_flush_tlb_all();
155 clear_tasks_mm_cpumask(cpu);
157 return 0;
159 #else /* ... !CONFIG_HOTPLUG_CPU */
160 int native_cpu_disable(unsigned int cpu)
162 return -ENOSYS;
165 void native_cpu_die(unsigned int cpu)
167 /* We said "no" in __cpu_disable */
168 BUG();
171 void native_play_dead(void)
173 BUG();
175 #endif
177 asmlinkage void start_secondary(void)
179 unsigned int cpu = smp_processor_id();
180 struct mm_struct *mm = &init_mm;
182 enable_mmu();
183 atomic_inc(&mm->mm_count);
184 atomic_inc(&mm->mm_users);
185 current->active_mm = mm;
186 enter_lazy_tlb(mm, current);
187 local_flush_tlb_all();
189 per_cpu_trap_init();
191 preempt_disable();
193 notify_cpu_starting(cpu);
195 local_irq_enable();
197 /* Enable local timers */
198 local_timer_setup(cpu);
199 calibrate_delay();
201 smp_store_cpu_info(cpu);
203 set_cpu_online(cpu, true);
204 per_cpu(cpu_state, cpu) = CPU_ONLINE;
206 cpu_startup_entry(CPUHP_ONLINE);
209 extern struct {
210 unsigned long sp;
211 unsigned long bss_start;
212 unsigned long bss_end;
213 void *start_kernel_fn;
214 void *cpu_init_fn;
215 void *thread_info;
216 } stack_start;
218 int __cpu_up(unsigned int cpu, struct task_struct *tsk)
220 unsigned long timeout;
222 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
224 /* Fill in data in head.S for secondary cpus */
225 stack_start.sp = tsk->thread.sp;
226 stack_start.thread_info = tsk->stack;
227 stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
228 stack_start.start_kernel_fn = start_secondary;
230 flush_icache_range((unsigned long)&stack_start,
231 (unsigned long)&stack_start + sizeof(stack_start));
232 wmb();
234 mp_ops->start_cpu(cpu, (unsigned long)_stext);
236 timeout = jiffies + HZ;
237 while (time_before(jiffies, timeout)) {
238 if (cpu_online(cpu))
239 break;
241 udelay(10);
242 barrier();
245 if (cpu_online(cpu))
246 return 0;
248 return -ENOENT;
251 void __init smp_cpus_done(unsigned int max_cpus)
253 unsigned long bogosum = 0;
254 int cpu;
256 for_each_online_cpu(cpu)
257 bogosum += cpu_data[cpu].loops_per_jiffy;
259 printk(KERN_INFO "SMP: Total of %d processors activated "
260 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
261 bogosum / (500000/HZ),
262 (bogosum / (5000/HZ)) % 100);
265 void smp_send_reschedule(int cpu)
267 mp_ops->send_ipi(cpu, SMP_MSG_RESCHEDULE);
270 void smp_send_stop(void)
272 smp_call_function(stop_this_cpu, 0, 0);
275 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
277 int cpu;
279 for_each_cpu(cpu, mask)
280 mp_ops->send_ipi(cpu, SMP_MSG_FUNCTION);
283 void arch_send_call_function_single_ipi(int cpu)
285 mp_ops->send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
288 void smp_timer_broadcast(const struct cpumask *mask)
290 int cpu;
292 for_each_cpu(cpu, mask)
293 mp_ops->send_ipi(cpu, SMP_MSG_TIMER);
296 static void ipi_timer(void)
298 irq_enter();
299 local_timer_interrupt();
300 irq_exit();
303 void smp_message_recv(unsigned int msg)
305 switch (msg) {
306 case SMP_MSG_FUNCTION:
307 generic_smp_call_function_interrupt();
308 break;
309 case SMP_MSG_RESCHEDULE:
310 scheduler_ipi();
311 break;
312 case SMP_MSG_FUNCTION_SINGLE:
313 generic_smp_call_function_single_interrupt();
314 break;
315 case SMP_MSG_TIMER:
316 ipi_timer();
317 break;
318 default:
319 printk(KERN_WARNING "SMP %d: %s(): unknown IPI %d\n",
320 smp_processor_id(), __func__, msg);
321 break;
325 /* Not really SMP stuff ... */
326 int setup_profiling_timer(unsigned int multiplier)
328 return 0;
331 static void flush_tlb_all_ipi(void *info)
333 local_flush_tlb_all();
336 void flush_tlb_all(void)
338 on_each_cpu(flush_tlb_all_ipi, 0, 1);
341 static void flush_tlb_mm_ipi(void *mm)
343 local_flush_tlb_mm((struct mm_struct *)mm);
347 * The following tlb flush calls are invoked when old translations are
348 * being torn down, or pte attributes are changing. For single threaded
349 * address spaces, a new context is obtained on the current cpu, and tlb
350 * context on other cpus are invalidated to force a new context allocation
351 * at switch_mm time, should the mm ever be used on other cpus. For
352 * multithreaded address spaces, intercpu interrupts have to be sent.
353 * Another case where intercpu interrupts are required is when the target
354 * mm might be active on another cpu (eg debuggers doing the flushes on
355 * behalf of debugees, kswapd stealing pages from another process etc).
356 * Kanoj 07/00.
358 void flush_tlb_mm(struct mm_struct *mm)
360 preempt_disable();
362 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
363 smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
364 } else {
365 int i;
366 for (i = 0; i < num_online_cpus(); i++)
367 if (smp_processor_id() != i)
368 cpu_context(i, mm) = 0;
370 local_flush_tlb_mm(mm);
372 preempt_enable();
375 struct flush_tlb_data {
376 struct vm_area_struct *vma;
377 unsigned long addr1;
378 unsigned long addr2;
381 static void flush_tlb_range_ipi(void *info)
383 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
385 local_flush_tlb_range(fd->vma, fd->addr1, fd->addr2);
388 void flush_tlb_range(struct vm_area_struct *vma,
389 unsigned long start, unsigned long end)
391 struct mm_struct *mm = vma->vm_mm;
393 preempt_disable();
394 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
395 struct flush_tlb_data fd;
397 fd.vma = vma;
398 fd.addr1 = start;
399 fd.addr2 = end;
400 smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
401 } else {
402 int i;
403 for (i = 0; i < num_online_cpus(); i++)
404 if (smp_processor_id() != i)
405 cpu_context(i, mm) = 0;
407 local_flush_tlb_range(vma, start, end);
408 preempt_enable();
411 static void flush_tlb_kernel_range_ipi(void *info)
413 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
415 local_flush_tlb_kernel_range(fd->addr1, fd->addr2);
418 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
420 struct flush_tlb_data fd;
422 fd.addr1 = start;
423 fd.addr2 = end;
424 on_each_cpu(flush_tlb_kernel_range_ipi, (void *)&fd, 1);
427 static void flush_tlb_page_ipi(void *info)
429 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
431 local_flush_tlb_page(fd->vma, fd->addr1);
434 void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
436 preempt_disable();
437 if ((atomic_read(&vma->vm_mm->mm_users) != 1) ||
438 (current->mm != vma->vm_mm)) {
439 struct flush_tlb_data fd;
441 fd.vma = vma;
442 fd.addr1 = page;
443 smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
444 } else {
445 int i;
446 for (i = 0; i < num_online_cpus(); i++)
447 if (smp_processor_id() != i)
448 cpu_context(i, vma->vm_mm) = 0;
450 local_flush_tlb_page(vma, page);
451 preempt_enable();
454 static void flush_tlb_one_ipi(void *info)
456 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
457 local_flush_tlb_one(fd->addr1, fd->addr2);
460 void flush_tlb_one(unsigned long asid, unsigned long vaddr)
462 struct flush_tlb_data fd;
464 fd.addr1 = asid;
465 fd.addr2 = vaddr;
467 smp_call_function(flush_tlb_one_ipi, (void *)&fd, 1);
468 local_flush_tlb_one(asid, vaddr);