acpiphp: Execute ACPI _REG method for hotadded devices
[linux/fpc-iii.git] / arch / arm / kernel / smp.c
blob57162af53dc982cc0911e09537915eb1eddc1cbb
1 /*
2 * linux/arch/arm/kernel/smp.c
4 * Copyright (C) 2002 ARM Limited, All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10 #include <linux/module.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/sched.h>
15 #include <linux/interrupt.h>
16 #include <linux/cache.h>
17 #include <linux/profile.h>
18 #include <linux/errno.h>
19 #include <linux/mm.h>
20 #include <linux/err.h>
21 #include <linux/cpu.h>
22 #include <linux/smp.h>
23 #include <linux/seq_file.h>
24 #include <linux/irq.h>
25 #include <linux/percpu.h>
26 #include <linux/clockchips.h>
28 #include <asm/atomic.h>
29 #include <asm/cacheflush.h>
30 #include <asm/cpu.h>
31 #include <asm/cputype.h>
32 #include <asm/mmu_context.h>
33 #include <asm/pgtable.h>
34 #include <asm/pgalloc.h>
35 #include <asm/processor.h>
36 #include <asm/tlbflush.h>
37 #include <asm/ptrace.h>
38 #include <asm/localtimer.h>
39 #include <asm/smp_plat.h>
42 * as from 2.5, kernels no longer have an init_tasks structure
43 * so we need some other way of telling a new secondary core
44 * where to place its SVC stack
46 struct secondary_data secondary_data;
49 * structures for inter-processor calls
50 * - A collection of single bit ipi messages.
52 struct ipi_data {
53 spinlock_t lock;
54 unsigned long ipi_count;
55 unsigned long bits;
58 static DEFINE_PER_CPU(struct ipi_data, ipi_data) = {
59 .lock = SPIN_LOCK_UNLOCKED,
62 enum ipi_msg_type {
63 IPI_TIMER,
64 IPI_RESCHEDULE,
65 IPI_CALL_FUNC,
66 IPI_CALL_FUNC_SINGLE,
67 IPI_CPU_STOP,
70 int __cpuinit __cpu_up(unsigned int cpu)
72 struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
73 struct task_struct *idle = ci->idle;
74 pgd_t *pgd;
75 pmd_t *pmd;
76 int ret;
79 * Spawn a new process manually, if not already done.
80 * Grab a pointer to its task struct so we can mess with it
82 if (!idle) {
83 idle = fork_idle(cpu);
84 if (IS_ERR(idle)) {
85 printk(KERN_ERR "CPU%u: fork() failed\n", cpu);
86 return PTR_ERR(idle);
88 ci->idle = idle;
92 * Allocate initial page tables to allow the new CPU to
93 * enable the MMU safely. This essentially means a set
94 * of our "standard" page tables, with the addition of
95 * a 1:1 mapping for the physical address of the kernel.
97 pgd = pgd_alloc(&init_mm);
98 pmd = pmd_offset(pgd + pgd_index(PHYS_OFFSET), PHYS_OFFSET);
99 *pmd = __pmd((PHYS_OFFSET & PGDIR_MASK) |
100 PMD_TYPE_SECT | PMD_SECT_AP_WRITE);
101 flush_pmd_entry(pmd);
104 * We need to tell the secondary core where to find
105 * its stack and the page tables.
107 secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
108 secondary_data.pgdir = virt_to_phys(pgd);
109 wmb();
112 * Now bring the CPU into our world.
114 ret = boot_secondary(cpu, idle);
115 if (ret == 0) {
116 unsigned long timeout;
119 * CPU was successfully started, wait for it
120 * to come online or time out.
122 timeout = jiffies + HZ;
123 while (time_before(jiffies, timeout)) {
124 if (cpu_online(cpu))
125 break;
127 udelay(10);
128 barrier();
131 if (!cpu_online(cpu))
132 ret = -EIO;
135 secondary_data.stack = NULL;
136 secondary_data.pgdir = 0;
138 *pmd = __pmd(0);
139 clean_pmd_entry(pmd);
140 pgd_free(&init_mm, pgd);
142 if (ret) {
143 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
146 * FIXME: We need to clean up the new idle thread. --rmk
150 return ret;
153 #ifdef CONFIG_HOTPLUG_CPU
155 * __cpu_disable runs on the processor to be shutdown.
157 int __cpu_disable(void)
159 unsigned int cpu = smp_processor_id();
160 struct task_struct *p;
161 int ret;
163 ret = mach_cpu_disable(cpu);
164 if (ret)
165 return ret;
168 * Take this CPU offline. Once we clear this, we can't return,
169 * and we must not schedule until we're ready to give up the cpu.
171 set_cpu_online(cpu, false);
174 * OK - migrate IRQs away from this CPU
176 migrate_irqs();
179 * Stop the local timer for this CPU.
181 local_timer_stop();
184 * Flush user cache and TLB mappings, and then remove this CPU
185 * from the vm mask set of all processes.
187 flush_cache_all();
188 local_flush_tlb_all();
190 read_lock(&tasklist_lock);
191 for_each_process(p) {
192 if (p->mm)
193 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
195 read_unlock(&tasklist_lock);
197 return 0;
201 * called on the thread which is asking for a CPU to be shutdown -
202 * waits until shutdown has completed, or it is timed out.
204 void __cpu_die(unsigned int cpu)
206 if (!platform_cpu_kill(cpu))
207 printk("CPU%u: unable to kill\n", cpu);
211 * Called from the idle thread for the CPU which has been shutdown.
213 * Note that we disable IRQs here, but do not re-enable them
214 * before returning to the caller. This is also the behaviour
215 * of the other hotplug-cpu capable cores, so presumably coming
216 * out of idle fixes this.
218 void __ref cpu_die(void)
220 unsigned int cpu = smp_processor_id();
222 local_irq_disable();
223 idle_task_exit();
226 * actual CPU shutdown procedure is at least platform (if not
227 * CPU) specific
229 platform_cpu_die(cpu);
232 * Do not return to the idle loop - jump back to the secondary
233 * cpu initialisation. There's some initialisation which needs
234 * to be repeated to undo the effects of taking the CPU offline.
236 __asm__("mov sp, %0\n"
237 " b secondary_start_kernel"
239 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
241 #endif /* CONFIG_HOTPLUG_CPU */
244 * This is the secondary CPU boot entry. We're using this CPUs
245 * idle thread stack, but a set of temporary page tables.
247 asmlinkage void __cpuinit secondary_start_kernel(void)
249 struct mm_struct *mm = &init_mm;
250 unsigned int cpu = smp_processor_id();
252 printk("CPU%u: Booted secondary processor\n", cpu);
255 * All kernel threads share the same mm context; grab a
256 * reference and switch to it.
258 atomic_inc(&mm->mm_users);
259 atomic_inc(&mm->mm_count);
260 current->active_mm = mm;
261 cpumask_set_cpu(cpu, mm_cpumask(mm));
262 cpu_switch_mm(mm->pgd, mm);
263 enter_lazy_tlb(mm, current);
264 local_flush_tlb_all();
266 cpu_init();
267 preempt_disable();
270 * Give the platform a chance to do its own initialisation.
272 platform_secondary_init(cpu);
275 * Enable local interrupts.
277 notify_cpu_starting(cpu);
278 local_irq_enable();
279 local_fiq_enable();
282 * Setup the percpu timer for this CPU.
284 percpu_timer_setup();
286 calibrate_delay();
288 smp_store_cpu_info(cpu);
291 * OK, now it's safe to let the boot CPU continue
293 set_cpu_online(cpu, true);
296 * OK, it's off to the idle thread for us
298 cpu_idle();
302 * Called by both boot and secondaries to move global data into
303 * per-processor storage.
305 void __cpuinit smp_store_cpu_info(unsigned int cpuid)
307 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
309 cpu_info->loops_per_jiffy = loops_per_jiffy;
312 void __init smp_cpus_done(unsigned int max_cpus)
314 int cpu;
315 unsigned long bogosum = 0;
317 for_each_online_cpu(cpu)
318 bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
320 printk(KERN_INFO "SMP: Total of %d processors activated "
321 "(%lu.%02lu BogoMIPS).\n",
322 num_online_cpus(),
323 bogosum / (500000/HZ),
324 (bogosum / (5000/HZ)) % 100);
327 void __init smp_prepare_boot_cpu(void)
329 unsigned int cpu = smp_processor_id();
331 per_cpu(cpu_data, cpu).idle = current;
334 static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg)
336 unsigned long flags;
337 unsigned int cpu;
339 local_irq_save(flags);
341 for_each_cpu(cpu, mask) {
342 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
344 spin_lock(&ipi->lock);
345 ipi->bits |= 1 << msg;
346 spin_unlock(&ipi->lock);
350 * Call the platform specific cross-CPU call function.
352 smp_cross_call(mask);
354 local_irq_restore(flags);
357 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
359 send_ipi_message(mask, IPI_CALL_FUNC);
362 void arch_send_call_function_single_ipi(int cpu)
364 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
367 void show_ipi_list(struct seq_file *p)
369 unsigned int cpu;
371 seq_puts(p, "IPI:");
373 for_each_present_cpu(cpu)
374 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
376 seq_putc(p, '\n');
379 void show_local_irqs(struct seq_file *p)
381 unsigned int cpu;
383 seq_printf(p, "LOC: ");
385 for_each_present_cpu(cpu)
386 seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs);
388 seq_putc(p, '\n');
392 * Timer (local or broadcast) support
394 static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
396 static void ipi_timer(void)
398 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
399 irq_enter();
400 evt->event_handler(evt);
401 irq_exit();
404 #ifdef CONFIG_LOCAL_TIMERS
405 asmlinkage void __exception do_local_timer(struct pt_regs *regs)
407 struct pt_regs *old_regs = set_irq_regs(regs);
408 int cpu = smp_processor_id();
410 if (local_timer_ack()) {
411 irq_stat[cpu].local_timer_irqs++;
412 ipi_timer();
415 set_irq_regs(old_regs);
417 #endif
419 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
420 static void smp_timer_broadcast(const struct cpumask *mask)
422 send_ipi_message(mask, IPI_TIMER);
425 static void broadcast_timer_set_mode(enum clock_event_mode mode,
426 struct clock_event_device *evt)
430 static void local_timer_setup(struct clock_event_device *evt)
432 evt->name = "dummy_timer";
433 evt->features = CLOCK_EVT_FEAT_ONESHOT |
434 CLOCK_EVT_FEAT_PERIODIC |
435 CLOCK_EVT_FEAT_DUMMY;
436 evt->rating = 400;
437 evt->mult = 1;
438 evt->set_mode = broadcast_timer_set_mode;
439 evt->broadcast = smp_timer_broadcast;
441 clockevents_register_device(evt);
443 #endif
445 void __cpuinit percpu_timer_setup(void)
447 unsigned int cpu = smp_processor_id();
448 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
450 evt->cpumask = cpumask_of(cpu);
452 local_timer_setup(evt);
455 static DEFINE_SPINLOCK(stop_lock);
458 * ipi_cpu_stop - handle IPI from smp_send_stop()
460 static void ipi_cpu_stop(unsigned int cpu)
462 spin_lock(&stop_lock);
463 printk(KERN_CRIT "CPU%u: stopping\n", cpu);
464 dump_stack();
465 spin_unlock(&stop_lock);
467 set_cpu_online(cpu, false);
469 local_fiq_disable();
470 local_irq_disable();
472 while (1)
473 cpu_relax();
477 * Main handler for inter-processor interrupts
479 * For ARM, the ipimask now only identifies a single
480 * category of IPI (Bit 1 IPIs have been replaced by a
481 * different mechanism):
483 * Bit 0 - Inter-processor function call
485 asmlinkage void __exception do_IPI(struct pt_regs *regs)
487 unsigned int cpu = smp_processor_id();
488 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
489 struct pt_regs *old_regs = set_irq_regs(regs);
491 ipi->ipi_count++;
493 for (;;) {
494 unsigned long msgs;
496 spin_lock(&ipi->lock);
497 msgs = ipi->bits;
498 ipi->bits = 0;
499 spin_unlock(&ipi->lock);
501 if (!msgs)
502 break;
504 do {
505 unsigned nextmsg;
507 nextmsg = msgs & -msgs;
508 msgs &= ~nextmsg;
509 nextmsg = ffz(~nextmsg);
511 switch (nextmsg) {
512 case IPI_TIMER:
513 ipi_timer();
514 break;
516 case IPI_RESCHEDULE:
518 * nothing more to do - eveything is
519 * done on the interrupt return path
521 break;
523 case IPI_CALL_FUNC:
524 generic_smp_call_function_interrupt();
525 break;
527 case IPI_CALL_FUNC_SINGLE:
528 generic_smp_call_function_single_interrupt();
529 break;
531 case IPI_CPU_STOP:
532 ipi_cpu_stop(cpu);
533 break;
535 default:
536 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
537 cpu, nextmsg);
538 break;
540 } while (msgs);
543 set_irq_regs(old_regs);
546 void smp_send_reschedule(int cpu)
548 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
551 void smp_send_stop(void)
553 cpumask_t mask = cpu_online_map;
554 cpu_clear(smp_processor_id(), mask);
555 send_ipi_message(&mask, IPI_CPU_STOP);
559 * not supported here
561 int setup_profiling_timer(unsigned int multiplier)
563 return -EINVAL;
566 static void
567 on_each_cpu_mask(void (*func)(void *), void *info, int wait,
568 const struct cpumask *mask)
570 preempt_disable();
572 smp_call_function_many(mask, func, info, wait);
573 if (cpumask_test_cpu(smp_processor_id(), mask))
574 func(info);
576 preempt_enable();
579 /**********************************************************************/
582 * TLB operations
584 struct tlb_args {
585 struct vm_area_struct *ta_vma;
586 unsigned long ta_start;
587 unsigned long ta_end;
590 static inline void ipi_flush_tlb_all(void *ignored)
592 local_flush_tlb_all();
595 static inline void ipi_flush_tlb_mm(void *arg)
597 struct mm_struct *mm = (struct mm_struct *)arg;
599 local_flush_tlb_mm(mm);
602 static inline void ipi_flush_tlb_page(void *arg)
604 struct tlb_args *ta = (struct tlb_args *)arg;
606 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
609 static inline void ipi_flush_tlb_kernel_page(void *arg)
611 struct tlb_args *ta = (struct tlb_args *)arg;
613 local_flush_tlb_kernel_page(ta->ta_start);
616 static inline void ipi_flush_tlb_range(void *arg)
618 struct tlb_args *ta = (struct tlb_args *)arg;
620 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
623 static inline void ipi_flush_tlb_kernel_range(void *arg)
625 struct tlb_args *ta = (struct tlb_args *)arg;
627 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
630 void flush_tlb_all(void)
632 if (tlb_ops_need_broadcast())
633 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
634 else
635 local_flush_tlb_all();
638 void flush_tlb_mm(struct mm_struct *mm)
640 if (tlb_ops_need_broadcast())
641 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm));
642 else
643 local_flush_tlb_mm(mm);
646 void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
648 if (tlb_ops_need_broadcast()) {
649 struct tlb_args ta;
650 ta.ta_vma = vma;
651 ta.ta_start = uaddr;
652 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm));
653 } else
654 local_flush_tlb_page(vma, uaddr);
657 void flush_tlb_kernel_page(unsigned long kaddr)
659 if (tlb_ops_need_broadcast()) {
660 struct tlb_args ta;
661 ta.ta_start = kaddr;
662 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
663 } else
664 local_flush_tlb_kernel_page(kaddr);
667 void flush_tlb_range(struct vm_area_struct *vma,
668 unsigned long start, unsigned long end)
670 if (tlb_ops_need_broadcast()) {
671 struct tlb_args ta;
672 ta.ta_vma = vma;
673 ta.ta_start = start;
674 ta.ta_end = end;
675 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm));
676 } else
677 local_flush_tlb_range(vma, start, end);
680 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
682 if (tlb_ops_need_broadcast()) {
683 struct tlb_args ta;
684 ta.ta_start = start;
685 ta.ta_end = end;
686 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
687 } else
688 local_flush_tlb_kernel_range(start, end);