blob: 14070549e0512fdbc890866ecf97e170a0337e62 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/kernel/smp.c
3 *
4 * Copyright (C) 2002 ARM Limited, All Rights Reserved.
5 *
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 */
Russell Kingc97d4862006-10-25 13:59:16 +010010#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040020#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/cpu.h>
22#include <linux/smp.h>
23#include <linux/seq_file.h>
Russell Kingc97d4862006-10-25 13:59:16 +010024#include <linux/irq.h>
Russell Kingbc282482009-05-17 18:58:34 +010025#include <linux/percpu.h>
26#include <linux/clockchips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/atomic.h>
29#include <asm/cacheflush.h>
30#include <asm/cpu.h>
Russell King42578c82009-06-11 15:35:00 +010031#include <asm/cputype.h>
Russell Kinge65f38e2005-06-18 09:33:31 +010032#include <asm/mmu_context.h>
33#include <asm/pgtable.h>
34#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/processor.h>
Russell King37b05b62010-10-01 15:38:24 +010036#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/tlbflush.h>
38#include <asm/ptrace.h>
Russell Kingbc282482009-05-17 18:58:34 +010039#include <asm/localtimer.h>
Russell Kinge616c592009-09-27 20:55:43 +010040#include <asm/smp_plat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/*
Russell Kinge65f38e2005-06-18 09:33:31 +010043 * as from 2.5, kernels no longer have an init_tasks structure
44 * so we need some other way of telling a new secondary core
45 * where to place its SVC stack
46 */
47struct secondary_data secondary_data;
48
49/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * structures for inter-processor calls
51 * - A collection of single bit ipi messages.
52 */
53struct ipi_data {
54 spinlock_t lock;
55 unsigned long ipi_count;
56 unsigned long bits;
57};
58
59static DEFINE_PER_CPU(struct ipi_data, ipi_data) = {
60 .lock = SPIN_LOCK_UNLOCKED,
61};
62
63enum ipi_msg_type {
64 IPI_TIMER,
65 IPI_RESCHEDULE,
66 IPI_CALL_FUNC,
Jens Axboef6dd9fa52008-06-10 20:48:30 +020067 IPI_CALL_FUNC_SINGLE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 IPI_CPU_STOP,
69};
70
Russell King37b05b62010-10-01 15:38:24 +010071static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
72 unsigned long end)
73{
74 unsigned long addr, prot;
75 pmd_t *pmd;
76
77 prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
78 if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
79 prot |= PMD_BIT4;
80
81 for (addr = start & PGDIR_MASK; addr < end;) {
82 pmd = pmd_offset(pgd + pgd_index(addr), addr);
83 pmd[0] = __pmd(addr | prot);
84 addr += SECTION_SIZE;
85 pmd[1] = __pmd(addr | prot);
86 addr += SECTION_SIZE;
87 flush_pmd_entry(pmd);
88 outer_clean_range(__pa(pmd), __pa(pmd + 1));
89 }
90}
91
92static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
93 unsigned long end)
94{
95 unsigned long addr;
96 pmd_t *pmd;
97
98 for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
99 pmd = pmd_offset(pgd + pgd_index(addr), addr);
100 pmd[0] = __pmd(0);
101 pmd[1] = __pmd(0);
102 clean_pmd_entry(pmd);
103 outer_clean_range(__pa(pmd), __pa(pmd + 1));
104 }
105}
106
Russell Kingbd6f68a2005-07-17 21:35:41 +0100107int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Russell King71f512e2005-11-02 21:51:40 +0000109 struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
110 struct task_struct *idle = ci->idle;
Russell Kinge65f38e2005-06-18 09:33:31 +0100111 pgd_t *pgd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 int ret;
113
114 /*
Russell King71f512e2005-11-02 21:51:40 +0000115 * Spawn a new process manually, if not already done.
116 * Grab a pointer to its task struct so we can mess with it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 */
Russell King71f512e2005-11-02 21:51:40 +0000118 if (!idle) {
119 idle = fork_idle(cpu);
120 if (IS_ERR(idle)) {
121 printk(KERN_ERR "CPU%u: fork() failed\n", cpu);
122 return PTR_ERR(idle);
123 }
124 ci->idle = idle;
Santosh Shilimkar13ea9cc2010-04-30 06:51:20 +0100125 } else {
126 /*
127 * Since this idle thread is being re-used, call
128 * init_idle() to reinitialize the thread structure.
129 */
130 init_idle(idle, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
133 /*
Russell Kinge65f38e2005-06-18 09:33:31 +0100134 * Allocate initial page tables to allow the new CPU to
135 * enable the MMU safely. This essentially means a set
136 * of our "standard" page tables, with the addition of
137 * a 1:1 mapping for the physical address of the kernel.
138 */
139 pgd = pgd_alloc(&init_mm);
Russell King37b05b62010-10-01 15:38:24 +0100140 if (!pgd)
141 return -ENOMEM;
142
143 if (PHYS_OFFSET != PAGE_OFFSET) {
144#ifndef CONFIG_HOTPLUG_CPU
145 identity_mapping_add(pgd, __pa(__init_begin), __pa(__init_end));
146#endif
147 identity_mapping_add(pgd, __pa(_stext), __pa(_etext));
148 identity_mapping_add(pgd, __pa(_sdata), __pa(_edata));
149 }
Russell Kinge65f38e2005-06-18 09:33:31 +0100150
151 /*
152 * We need to tell the secondary core where to find
153 * its stack and the page tables.
154 */
Al Viro32d39a92006-01-12 01:05:58 -0800155 secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
Russell Kinge65f38e2005-06-18 09:33:31 +0100156 secondary_data.pgdir = virt_to_phys(pgd);
Russell King10272472010-02-12 14:36:24 +0000157 __cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data));
158 outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1));
Russell Kinge65f38e2005-06-18 09:33:31 +0100159
160 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 * Now bring the CPU into our world.
162 */
163 ret = boot_secondary(cpu, idle);
Russell Kinge65f38e2005-06-18 09:33:31 +0100164 if (ret == 0) {
165 unsigned long timeout;
166
167 /*
168 * CPU was successfully started, wait for it
169 * to come online or time out.
170 */
171 timeout = jiffies + HZ;
172 while (time_before(jiffies, timeout)) {
173 if (cpu_online(cpu))
174 break;
175
176 udelay(10);
177 barrier();
178 }
179
180 if (!cpu_online(cpu))
181 ret = -EIO;
182 }
183
Russell King5d430452005-11-08 10:44:46 +0000184 secondary_data.stack = NULL;
Russell Kinge65f38e2005-06-18 09:33:31 +0100185 secondary_data.pgdir = 0;
186
Russell King37b05b62010-10-01 15:38:24 +0100187 if (PHYS_OFFSET != PAGE_OFFSET) {
188#ifndef CONFIG_HOTPLUG_CPU
189 identity_mapping_del(pgd, __pa(__init_begin), __pa(__init_end));
190#endif
191 identity_mapping_del(pgd, __pa(_stext), __pa(_etext));
192 identity_mapping_del(pgd, __pa(_sdata), __pa(_edata));
193 }
194
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800195 pgd_free(&init_mm, pgd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (ret) {
Russell King0908db22005-06-19 19:48:16 +0100198 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 /*
201 * FIXME: We need to clean up the new idle thread. --rmk
202 */
203 }
204
205 return ret;
206}
207
Russell Kinga054a812005-11-02 22:24:33 +0000208#ifdef CONFIG_HOTPLUG_CPU
209/*
210 * __cpu_disable runs on the processor to be shutdown.
211 */
Russell King90140c32009-09-27 21:04:48 +0100212int __cpu_disable(void)
Russell Kinga054a812005-11-02 22:24:33 +0000213{
214 unsigned int cpu = smp_processor_id();
215 struct task_struct *p;
216 int ret;
217
Russell King8e2a43f2010-05-15 10:18:05 +0100218 ret = platform_cpu_disable(cpu);
Russell Kinga054a812005-11-02 22:24:33 +0000219 if (ret)
220 return ret;
221
222 /*
223 * Take this CPU offline. Once we clear this, we can't return,
224 * and we must not schedule until we're ready to give up the cpu.
225 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100226 set_cpu_online(cpu, false);
Russell Kinga054a812005-11-02 22:24:33 +0000227
228 /*
229 * OK - migrate IRQs away from this CPU
230 */
231 migrate_irqs();
232
233 /*
Russell King37ee16a2005-11-08 19:08:05 +0000234 * Stop the local timer for this CPU.
235 */
Catalin Marinasebac6542008-12-01 14:54:57 +0000236 local_timer_stop();
Russell King37ee16a2005-11-08 19:08:05 +0000237
238 /*
Russell Kinga054a812005-11-02 22:24:33 +0000239 * Flush user cache and TLB mappings, and then remove this CPU
240 * from the vm mask set of all processes.
241 */
242 flush_cache_all();
243 local_flush_tlb_all();
244
245 read_lock(&tasklist_lock);
246 for_each_process(p) {
247 if (p->mm)
Rusty Russell56f8ba82009-09-24 09:34:49 -0600248 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
Russell Kinga054a812005-11-02 22:24:33 +0000249 }
250 read_unlock(&tasklist_lock);
251
252 return 0;
253}
254
255/*
256 * called on the thread which is asking for a CPU to be shutdown -
257 * waits until shutdown has completed, or it is timed out.
258 */
Russell King90140c32009-09-27 21:04:48 +0100259void __cpu_die(unsigned int cpu)
Russell Kinga054a812005-11-02 22:24:33 +0000260{
261 if (!platform_cpu_kill(cpu))
262 printk("CPU%u: unable to kill\n", cpu);
263}
264
265/*
266 * Called from the idle thread for the CPU which has been shutdown.
267 *
268 * Note that we disable IRQs here, but do not re-enable them
269 * before returning to the caller. This is also the behaviour
270 * of the other hotplug-cpu capable cores, so presumably coming
271 * out of idle fixes this.
272 */
Russell King90140c32009-09-27 21:04:48 +0100273void __ref cpu_die(void)
Russell Kinga054a812005-11-02 22:24:33 +0000274{
275 unsigned int cpu = smp_processor_id();
276
277 local_irq_disable();
278 idle_task_exit();
279
280 /*
281 * actual CPU shutdown procedure is at least platform (if not
282 * CPU) specific
283 */
284 platform_cpu_die(cpu);
285
286 /*
287 * Do not return to the idle loop - jump back to the secondary
288 * cpu initialisation. There's some initialisation which needs
289 * to be repeated to undo the effects of taking the CPU offline.
290 */
291 __asm__("mov sp, %0\n"
292 " b secondary_start_kernel"
293 :
Al Viro32d39a92006-01-12 01:05:58 -0800294 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
Russell Kinga054a812005-11-02 22:24:33 +0000295}
296#endif /* CONFIG_HOTPLUG_CPU */
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298/*
Russell Kinge65f38e2005-06-18 09:33:31 +0100299 * This is the secondary CPU boot entry. We're using this CPUs
300 * idle thread stack, but a set of temporary page tables.
301 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100302asmlinkage void __cpuinit secondary_start_kernel(void)
Russell Kinge65f38e2005-06-18 09:33:31 +0100303{
304 struct mm_struct *mm = &init_mm;
Russell Kingda2660d2005-11-12 17:21:47 +0000305 unsigned int cpu = smp_processor_id();
Russell Kinge65f38e2005-06-18 09:33:31 +0100306
307 printk("CPU%u: Booted secondary processor\n", cpu);
308
309 /*
310 * All kernel threads share the same mm context; grab a
311 * reference and switch to it.
312 */
313 atomic_inc(&mm->mm_users);
314 atomic_inc(&mm->mm_count);
315 current->active_mm = mm;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600316 cpumask_set_cpu(cpu, mm_cpumask(mm));
Russell Kinge65f38e2005-06-18 09:33:31 +0100317 cpu_switch_mm(mm->pgd, mm);
318 enter_lazy_tlb(mm, current);
Russell King505d7b12005-07-28 20:32:47 +0100319 local_flush_tlb_all();
Russell Kinge65f38e2005-06-18 09:33:31 +0100320
321 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800322 preempt_disable();
Russell Kinge65f38e2005-06-18 09:33:31 +0100323
324 /*
325 * Give the platform a chance to do its own initialisation.
326 */
327 platform_secondary_init(cpu);
328
329 /*
330 * Enable local interrupts.
331 */
Manfred Spraule545a612008-09-07 16:57:22 +0200332 notify_cpu_starting(cpu);
Russell Kinge65f38e2005-06-18 09:33:31 +0100333 local_irq_enable();
334 local_fiq_enable();
335
Catalin Marinasa8655e82008-02-04 17:30:57 +0100336 /*
Russell Kingbc282482009-05-17 18:58:34 +0100337 * Setup the percpu timer for this CPU.
Catalin Marinasa8655e82008-02-04 17:30:57 +0100338 */
Russell Kingbc282482009-05-17 18:58:34 +0100339 percpu_timer_setup();
Catalin Marinasa8655e82008-02-04 17:30:57 +0100340
Russell Kinge65f38e2005-06-18 09:33:31 +0100341 calibrate_delay();
342
343 smp_store_cpu_info(cpu);
344
345 /*
346 * OK, now it's safe to let the boot CPU continue
347 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100348 set_cpu_online(cpu, true);
Russell Kinge65f38e2005-06-18 09:33:31 +0100349
350 /*
351 * OK, it's off to the idle thread for us
352 */
353 cpu_idle();
354}
355
356/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 * Called by both boot and secondaries to move global data into
358 * per-processor storage.
359 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100360void __cpuinit smp_store_cpu_info(unsigned int cpuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
362 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
363
364 cpu_info->loops_per_jiffy = loops_per_jiffy;
365}
366
367void __init smp_cpus_done(unsigned int max_cpus)
368{
369 int cpu;
370 unsigned long bogosum = 0;
371
372 for_each_online_cpu(cpu)
373 bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
374
375 printk(KERN_INFO "SMP: Total of %d processors activated "
376 "(%lu.%02lu BogoMIPS).\n",
377 num_online_cpus(),
378 bogosum / (500000/HZ),
379 (bogosum / (5000/HZ)) % 100);
380}
381
382void __init smp_prepare_boot_cpu(void)
383{
384 unsigned int cpu = smp_processor_id();
385
Russell King71f512e2005-11-02 21:51:40 +0000386 per_cpu(cpu_data, cpu).idle = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Russell King82668102009-05-17 16:20:18 +0100389static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
391 unsigned long flags;
392 unsigned int cpu;
393
394 local_irq_save(flags);
395
Russell King82668102009-05-17 16:20:18 +0100396 for_each_cpu(cpu, mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
398
399 spin_lock(&ipi->lock);
400 ipi->bits |= 1 << msg;
401 spin_unlock(&ipi->lock);
402 }
403
404 /*
405 * Call the platform specific cross-CPU call function.
406 */
Russell King82668102009-05-17 16:20:18 +0100407 smp_cross_call(mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 local_irq_restore(flags);
410}
411
Russell King82668102009-05-17 16:20:18 +0100412void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Jens Axboef6dd9fa52008-06-10 20:48:30 +0200414 send_ipi_message(mask, IPI_CALL_FUNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Jens Axboef6dd9fa52008-06-10 20:48:30 +0200417void arch_send_call_function_single_ipi(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Russell King82668102009-05-17 16:20:18 +0100419 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
Catalin Marinas3e459992008-02-04 17:28:56 +0100421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422void show_ipi_list(struct seq_file *p)
423{
424 unsigned int cpu;
425
426 seq_puts(p, "IPI:");
427
Russell Kinge11b2232005-07-11 19:26:31 +0100428 for_each_present_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
430
431 seq_putc(p, '\n');
432}
433
Russell King37ee16a2005-11-08 19:08:05 +0000434void show_local_irqs(struct seq_file *p)
435{
436 unsigned int cpu;
437
438 seq_printf(p, "LOC: ");
439
440 for_each_present_cpu(cpu)
441 seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs);
442
443 seq_putc(p, '\n');
444}
445
Russell Kingbc282482009-05-17 18:58:34 +0100446/*
447 * Timer (local or broadcast) support
448 */
449static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
450
Russell Kingc97d4862006-10-25 13:59:16 +0100451static void ipi_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
Russell Kingbc282482009-05-17 18:58:34 +0100453 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 irq_enter();
Russell Kingbc282482009-05-17 18:58:34 +0100455 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 irq_exit();
457}
458
Russell King37ee16a2005-11-08 19:08:05 +0000459#ifdef CONFIG_LOCAL_TIMERS
Russell Kingb9811d72007-05-08 11:31:07 +0100460asmlinkage void __exception do_local_timer(struct pt_regs *regs)
Russell King37ee16a2005-11-08 19:08:05 +0000461{
Russell Kingc97d4862006-10-25 13:59:16 +0100462 struct pt_regs *old_regs = set_irq_regs(regs);
Russell King37ee16a2005-11-08 19:08:05 +0000463 int cpu = smp_processor_id();
464
465 if (local_timer_ack()) {
466 irq_stat[cpu].local_timer_irqs++;
Russell Kingc97d4862006-10-25 13:59:16 +0100467 ipi_timer();
Russell King37ee16a2005-11-08 19:08:05 +0000468 }
Russell Kingc97d4862006-10-25 13:59:16 +0100469
470 set_irq_regs(old_regs);
Russell King37ee16a2005-11-08 19:08:05 +0000471}
472#endif
473
Russell Kingbc282482009-05-17 18:58:34 +0100474#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
475static void smp_timer_broadcast(const struct cpumask *mask)
476{
477 send_ipi_message(mask, IPI_TIMER);
478}
Russell King5388a6b2010-07-26 13:19:43 +0100479#else
480#define smp_timer_broadcast NULL
481#endif
Russell Kingbc282482009-05-17 18:58:34 +0100482
Russell King5388a6b2010-07-26 13:19:43 +0100483#ifndef CONFIG_LOCAL_TIMERS
Russell Kingbc282482009-05-17 18:58:34 +0100484static void broadcast_timer_set_mode(enum clock_event_mode mode,
485 struct clock_event_device *evt)
486{
487}
488
489static void local_timer_setup(struct clock_event_device *evt)
490{
491 evt->name = "dummy_timer";
492 evt->features = CLOCK_EVT_FEAT_ONESHOT |
493 CLOCK_EVT_FEAT_PERIODIC |
494 CLOCK_EVT_FEAT_DUMMY;
495 evt->rating = 400;
496 evt->mult = 1;
497 evt->set_mode = broadcast_timer_set_mode;
Russell Kingbc282482009-05-17 18:58:34 +0100498
499 clockevents_register_device(evt);
500}
501#endif
502
503void __cpuinit percpu_timer_setup(void)
504{
505 unsigned int cpu = smp_processor_id();
506 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
507
508 evt->cpumask = cpumask_of(cpu);
Russell King5388a6b2010-07-26 13:19:43 +0100509 evt->broadcast = smp_timer_broadcast;
Russell Kingbc282482009-05-17 18:58:34 +0100510
511 local_timer_setup(evt);
512}
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514static DEFINE_SPINLOCK(stop_lock);
515
516/*
517 * ipi_cpu_stop - handle IPI from smp_send_stop()
518 */
519static void ipi_cpu_stop(unsigned int cpu)
520{
Russell King3d3f78d2010-07-26 13:31:27 +0100521 if (system_state == SYSTEM_BOOTING ||
522 system_state == SYSTEM_RUNNING) {
523 spin_lock(&stop_lock);
524 printk(KERN_CRIT "CPU%u: stopping\n", cpu);
525 dump_stack();
526 spin_unlock(&stop_lock);
527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Russell Kinge03cdad2009-05-28 14:16:52 +0100529 set_cpu_online(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 local_fiq_disable();
532 local_irq_disable();
533
534 while (1)
535 cpu_relax();
536}
537
538/*
539 * Main handler for inter-processor interrupts
540 *
541 * For ARM, the ipimask now only identifies a single
542 * category of IPI (Bit 1 IPIs have been replaced by a
543 * different mechanism):
544 *
545 * Bit 0 - Inter-processor function call
546 */
Russell Kingb9811d72007-05-08 11:31:07 +0100547asmlinkage void __exception do_IPI(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
549 unsigned int cpu = smp_processor_id();
550 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
Russell Kingc97d4862006-10-25 13:59:16 +0100551 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 ipi->ipi_count++;
554
555 for (;;) {
556 unsigned long msgs;
557
558 spin_lock(&ipi->lock);
559 msgs = ipi->bits;
560 ipi->bits = 0;
561 spin_unlock(&ipi->lock);
562
563 if (!msgs)
564 break;
565
566 do {
567 unsigned nextmsg;
568
569 nextmsg = msgs & -msgs;
570 msgs &= ~nextmsg;
571 nextmsg = ffz(~nextmsg);
572
573 switch (nextmsg) {
574 case IPI_TIMER:
Russell Kingc97d4862006-10-25 13:59:16 +0100575 ipi_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 break;
577
578 case IPI_RESCHEDULE:
579 /*
580 * nothing more to do - eveything is
581 * done on the interrupt return path
582 */
583 break;
584
585 case IPI_CALL_FUNC:
Jens Axboef6dd9fa52008-06-10 20:48:30 +0200586 generic_smp_call_function_interrupt();
587 break;
588
589 case IPI_CALL_FUNC_SINGLE:
590 generic_smp_call_function_single_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 break;
592
593 case IPI_CPU_STOP:
594 ipi_cpu_stop(cpu);
595 break;
596
597 default:
598 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
599 cpu, nextmsg);
600 break;
601 }
602 } while (msgs);
603 }
Russell Kingc97d4862006-10-25 13:59:16 +0100604
605 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
608void smp_send_reschedule(int cpu)
609{
Russell King82668102009-05-17 16:20:18 +0100610 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613void smp_send_stop(void)
614{
615 cpumask_t mask = cpu_online_map;
616 cpu_clear(smp_processor_id(), mask);
Russell King82668102009-05-17 16:20:18 +0100617 send_ipi_message(&mask, IPI_CPU_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
619
620/*
621 * not supported here
622 */
Russell King5048bcb2007-07-23 12:59:46 +0100623int setup_profiling_timer(unsigned int multiplier)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
625 return -EINVAL;
626}
Russell King4b0ef3b2005-06-28 13:49:16 +0100627
Russell King82668102009-05-17 16:20:18 +0100628static void
629on_each_cpu_mask(void (*func)(void *), void *info, int wait,
630 const struct cpumask *mask)
Russell King4b0ef3b2005-06-28 13:49:16 +0100631{
Russell King4b0ef3b2005-06-28 13:49:16 +0100632 preempt_disable();
633
Russell King82668102009-05-17 16:20:18 +0100634 smp_call_function_many(mask, func, info, wait);
635 if (cpumask_test_cpu(smp_processor_id(), mask))
Russell King4b0ef3b2005-06-28 13:49:16 +0100636 func(info);
637
638 preempt_enable();
Russell King4b0ef3b2005-06-28 13:49:16 +0100639}
640
641/**********************************************************************/
642
643/*
644 * TLB operations
645 */
646struct tlb_args {
647 struct vm_area_struct *ta_vma;
648 unsigned long ta_start;
649 unsigned long ta_end;
650};
651
652static inline void ipi_flush_tlb_all(void *ignored)
653{
654 local_flush_tlb_all();
655}
656
657static inline void ipi_flush_tlb_mm(void *arg)
658{
659 struct mm_struct *mm = (struct mm_struct *)arg;
660
661 local_flush_tlb_mm(mm);
662}
663
664static inline void ipi_flush_tlb_page(void *arg)
665{
666 struct tlb_args *ta = (struct tlb_args *)arg;
667
668 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
669}
670
671static inline void ipi_flush_tlb_kernel_page(void *arg)
672{
673 struct tlb_args *ta = (struct tlb_args *)arg;
674
675 local_flush_tlb_kernel_page(ta->ta_start);
676}
677
678static inline void ipi_flush_tlb_range(void *arg)
679{
680 struct tlb_args *ta = (struct tlb_args *)arg;
681
682 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
683}
684
685static inline void ipi_flush_tlb_kernel_range(void *arg)
686{
687 struct tlb_args *ta = (struct tlb_args *)arg;
688
689 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
690}
691
692void flush_tlb_all(void)
693{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100694 if (tlb_ops_need_broadcast())
695 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
696 else
697 local_flush_tlb_all();
Russell King4b0ef3b2005-06-28 13:49:16 +0100698}
699
700void flush_tlb_mm(struct mm_struct *mm)
701{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100702 if (tlb_ops_need_broadcast())
Rusty Russell56f8ba82009-09-24 09:34:49 -0600703 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100704 else
705 local_flush_tlb_mm(mm);
Russell King4b0ef3b2005-06-28 13:49:16 +0100706}
707
708void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
709{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100710 if (tlb_ops_need_broadcast()) {
711 struct tlb_args ta;
712 ta.ta_vma = vma;
713 ta.ta_start = uaddr;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600714 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100715 } else
716 local_flush_tlb_page(vma, uaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100717}
718
719void flush_tlb_kernel_page(unsigned long kaddr)
720{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100721 if (tlb_ops_need_broadcast()) {
722 struct tlb_args ta;
723 ta.ta_start = kaddr;
724 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
725 } else
726 local_flush_tlb_kernel_page(kaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100727}
728
729void flush_tlb_range(struct vm_area_struct *vma,
730 unsigned long start, unsigned long end)
731{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100732 if (tlb_ops_need_broadcast()) {
733 struct tlb_args ta;
734 ta.ta_vma = vma;
735 ta.ta_start = start;
736 ta.ta_end = end;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600737 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100738 } else
739 local_flush_tlb_range(vma, start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100740}
741
742void flush_tlb_kernel_range(unsigned long start, unsigned long end)
743{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100744 if (tlb_ops_need_broadcast()) {
745 struct tlb_args ta;
746 ta.ta_start = start;
747 ta.ta_end = end;
748 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
749 } else
750 local_flush_tlb_kernel_range(start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100751}