blob: 24131264ec2c62cd9236098f72728fc561b6ea97 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 */
52struct ipi_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 unsigned long ipi_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
Russell King24480d92010-11-15 09:54:18 +000056static DEFINE_PER_CPU(struct ipi_data, ipi_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58enum ipi_msg_type {
Russell King24480d92010-11-15 09:54:18 +000059 IPI_TIMER = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 IPI_RESCHEDULE,
61 IPI_CALL_FUNC,
Jens Axboef6dd9fa2008-06-10 20:48:30 +020062 IPI_CALL_FUNC_SINGLE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 IPI_CPU_STOP,
64};
65
Russell King37b05b62010-10-01 15:38:24 +010066static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
67 unsigned long end)
68{
69 unsigned long addr, prot;
70 pmd_t *pmd;
71
72 prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
73 if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
74 prot |= PMD_BIT4;
75
76 for (addr = start & PGDIR_MASK; addr < end;) {
77 pmd = pmd_offset(pgd + pgd_index(addr), addr);
78 pmd[0] = __pmd(addr | prot);
79 addr += SECTION_SIZE;
80 pmd[1] = __pmd(addr | prot);
81 addr += SECTION_SIZE;
82 flush_pmd_entry(pmd);
83 outer_clean_range(__pa(pmd), __pa(pmd + 1));
84 }
85}
86
87static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
88 unsigned long end)
89{
90 unsigned long addr;
91 pmd_t *pmd;
92
93 for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
94 pmd = pmd_offset(pgd + pgd_index(addr), addr);
95 pmd[0] = __pmd(0);
96 pmd[1] = __pmd(0);
97 clean_pmd_entry(pmd);
98 outer_clean_range(__pa(pmd), __pa(pmd + 1));
99 }
100}
101
Russell Kingbd6f68a2005-07-17 21:35:41 +0100102int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Russell King71f512e82005-11-02 21:51:40 +0000104 struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
105 struct task_struct *idle = ci->idle;
Russell Kinge65f38e2005-06-18 09:33:31 +0100106 pgd_t *pgd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 int ret;
108
109 /*
Russell King71f512e82005-11-02 21:51:40 +0000110 * Spawn a new process manually, if not already done.
111 * Grab a pointer to its task struct so we can mess with it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
Russell King71f512e82005-11-02 21:51:40 +0000113 if (!idle) {
114 idle = fork_idle(cpu);
115 if (IS_ERR(idle)) {
116 printk(KERN_ERR "CPU%u: fork() failed\n", cpu);
117 return PTR_ERR(idle);
118 }
119 ci->idle = idle;
Santosh Shilimkar13ea9cc2010-04-30 06:51:20 +0100120 } else {
121 /*
122 * Since this idle thread is being re-used, call
123 * init_idle() to reinitialize the thread structure.
124 */
125 init_idle(idle, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
128 /*
Russell Kinge65f38e2005-06-18 09:33:31 +0100129 * Allocate initial page tables to allow the new CPU to
130 * enable the MMU safely. This essentially means a set
131 * of our "standard" page tables, with the addition of
132 * a 1:1 mapping for the physical address of the kernel.
133 */
134 pgd = pgd_alloc(&init_mm);
Russell King37b05b62010-10-01 15:38:24 +0100135 if (!pgd)
136 return -ENOMEM;
137
138 if (PHYS_OFFSET != PAGE_OFFSET) {
139#ifndef CONFIG_HOTPLUG_CPU
140 identity_mapping_add(pgd, __pa(__init_begin), __pa(__init_end));
141#endif
142 identity_mapping_add(pgd, __pa(_stext), __pa(_etext));
143 identity_mapping_add(pgd, __pa(_sdata), __pa(_edata));
144 }
Russell Kinge65f38e2005-06-18 09:33:31 +0100145
146 /*
147 * We need to tell the secondary core where to find
148 * its stack and the page tables.
149 */
Al Viro32d39a92006-01-12 01:05:58 -0800150 secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
Russell Kinge65f38e2005-06-18 09:33:31 +0100151 secondary_data.pgdir = virt_to_phys(pgd);
Russell King10272472010-02-12 14:36:24 +0000152 __cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data));
153 outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1));
Russell Kinge65f38e2005-06-18 09:33:31 +0100154
155 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 * Now bring the CPU into our world.
157 */
158 ret = boot_secondary(cpu, idle);
Russell Kinge65f38e2005-06-18 09:33:31 +0100159 if (ret == 0) {
160 unsigned long timeout;
161
162 /*
163 * CPU was successfully started, wait for it
164 * to come online or time out.
165 */
166 timeout = jiffies + HZ;
167 while (time_before(jiffies, timeout)) {
168 if (cpu_online(cpu))
169 break;
170
171 udelay(10);
172 barrier();
173 }
174
175 if (!cpu_online(cpu))
176 ret = -EIO;
177 }
178
Russell King5d430452005-11-08 10:44:46 +0000179 secondary_data.stack = NULL;
Russell Kinge65f38e2005-06-18 09:33:31 +0100180 secondary_data.pgdir = 0;
181
Russell King37b05b62010-10-01 15:38:24 +0100182 if (PHYS_OFFSET != PAGE_OFFSET) {
183#ifndef CONFIG_HOTPLUG_CPU
184 identity_mapping_del(pgd, __pa(__init_begin), __pa(__init_end));
185#endif
186 identity_mapping_del(pgd, __pa(_stext), __pa(_etext));
187 identity_mapping_del(pgd, __pa(_sdata), __pa(_edata));
188 }
189
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800190 pgd_free(&init_mm, pgd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 if (ret) {
Russell King0908db22005-06-19 19:48:16 +0100193 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 /*
196 * FIXME: We need to clean up the new idle thread. --rmk
197 */
198 }
199
200 return ret;
201}
202
Russell Kinga054a812005-11-02 22:24:33 +0000203#ifdef CONFIG_HOTPLUG_CPU
204/*
205 * __cpu_disable runs on the processor to be shutdown.
206 */
Russell King90140c32009-09-27 21:04:48 +0100207int __cpu_disable(void)
Russell Kinga054a812005-11-02 22:24:33 +0000208{
209 unsigned int cpu = smp_processor_id();
210 struct task_struct *p;
211 int ret;
212
Russell King8e2a43f2010-05-15 10:18:05 +0100213 ret = platform_cpu_disable(cpu);
Russell Kinga054a812005-11-02 22:24:33 +0000214 if (ret)
215 return ret;
216
217 /*
218 * Take this CPU offline. Once we clear this, we can't return,
219 * and we must not schedule until we're ready to give up the cpu.
220 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100221 set_cpu_online(cpu, false);
Russell Kinga054a812005-11-02 22:24:33 +0000222
223 /*
224 * OK - migrate IRQs away from this CPU
225 */
226 migrate_irqs();
227
228 /*
Russell King37ee16a2005-11-08 19:08:05 +0000229 * Stop the local timer for this CPU.
230 */
Catalin Marinasebac6542008-12-01 14:54:57 +0000231 local_timer_stop();
Russell King37ee16a2005-11-08 19:08:05 +0000232
233 /*
Russell Kinga054a812005-11-02 22:24:33 +0000234 * Flush user cache and TLB mappings, and then remove this CPU
235 * from the vm mask set of all processes.
236 */
237 flush_cache_all();
238 local_flush_tlb_all();
239
240 read_lock(&tasklist_lock);
241 for_each_process(p) {
242 if (p->mm)
Rusty Russell56f8ba82009-09-24 09:34:49 -0600243 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
Russell Kinga054a812005-11-02 22:24:33 +0000244 }
245 read_unlock(&tasklist_lock);
246
247 return 0;
248}
249
250/*
251 * called on the thread which is asking for a CPU to be shutdown -
252 * waits until shutdown has completed, or it is timed out.
253 */
Russell King90140c32009-09-27 21:04:48 +0100254void __cpu_die(unsigned int cpu)
Russell Kinga054a812005-11-02 22:24:33 +0000255{
256 if (!platform_cpu_kill(cpu))
257 printk("CPU%u: unable to kill\n", cpu);
258}
259
260/*
261 * Called from the idle thread for the CPU which has been shutdown.
262 *
263 * Note that we disable IRQs here, but do not re-enable them
264 * before returning to the caller. This is also the behaviour
265 * of the other hotplug-cpu capable cores, so presumably coming
266 * out of idle fixes this.
267 */
Russell King90140c32009-09-27 21:04:48 +0100268void __ref cpu_die(void)
Russell Kinga054a812005-11-02 22:24:33 +0000269{
270 unsigned int cpu = smp_processor_id();
271
272 local_irq_disable();
273 idle_task_exit();
274
275 /*
276 * actual CPU shutdown procedure is at least platform (if not
277 * CPU) specific
278 */
279 platform_cpu_die(cpu);
280
281 /*
282 * Do not return to the idle loop - jump back to the secondary
283 * cpu initialisation. There's some initialisation which needs
284 * to be repeated to undo the effects of taking the CPU offline.
285 */
286 __asm__("mov sp, %0\n"
287 " b secondary_start_kernel"
288 :
Al Viro32d39a92006-01-12 01:05:58 -0800289 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
Russell Kinga054a812005-11-02 22:24:33 +0000290}
291#endif /* CONFIG_HOTPLUG_CPU */
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293/*
Russell Kinge65f38e2005-06-18 09:33:31 +0100294 * This is the secondary CPU boot entry. We're using this CPUs
295 * idle thread stack, but a set of temporary page tables.
296 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100297asmlinkage void __cpuinit secondary_start_kernel(void)
Russell Kinge65f38e2005-06-18 09:33:31 +0100298{
299 struct mm_struct *mm = &init_mm;
Russell Kingda2660d2005-11-12 17:21:47 +0000300 unsigned int cpu = smp_processor_id();
Russell Kinge65f38e2005-06-18 09:33:31 +0100301
302 printk("CPU%u: Booted secondary processor\n", cpu);
303
304 /*
305 * All kernel threads share the same mm context; grab a
306 * reference and switch to it.
307 */
308 atomic_inc(&mm->mm_users);
309 atomic_inc(&mm->mm_count);
310 current->active_mm = mm;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600311 cpumask_set_cpu(cpu, mm_cpumask(mm));
Russell Kinge65f38e2005-06-18 09:33:31 +0100312 cpu_switch_mm(mm->pgd, mm);
313 enter_lazy_tlb(mm, current);
Russell King505d7b12005-07-28 20:32:47 +0100314 local_flush_tlb_all();
Russell Kinge65f38e2005-06-18 09:33:31 +0100315
316 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800317 preempt_disable();
Russell Kinge65f38e2005-06-18 09:33:31 +0100318
319 /*
320 * Give the platform a chance to do its own initialisation.
321 */
322 platform_secondary_init(cpu);
323
324 /*
325 * Enable local interrupts.
326 */
Manfred Spraule545a612008-09-07 16:57:22 +0200327 notify_cpu_starting(cpu);
Russell Kinge65f38e2005-06-18 09:33:31 +0100328 local_irq_enable();
329 local_fiq_enable();
330
Catalin Marinasa8655e82008-02-04 17:30:57 +0100331 /*
Russell Kingbc282482009-05-17 18:58:34 +0100332 * Setup the percpu timer for this CPU.
Catalin Marinasa8655e82008-02-04 17:30:57 +0100333 */
Russell Kingbc282482009-05-17 18:58:34 +0100334 percpu_timer_setup();
Catalin Marinasa8655e82008-02-04 17:30:57 +0100335
Russell Kinge65f38e2005-06-18 09:33:31 +0100336 calibrate_delay();
337
338 smp_store_cpu_info(cpu);
339
340 /*
341 * OK, now it's safe to let the boot CPU continue
342 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100343 set_cpu_online(cpu, true);
Russell Kinge65f38e2005-06-18 09:33:31 +0100344
345 /*
346 * OK, it's off to the idle thread for us
347 */
348 cpu_idle();
349}
350
351/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 * Called by both boot and secondaries to move global data into
353 * per-processor storage.
354 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100355void __cpuinit smp_store_cpu_info(unsigned int cpuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
358
359 cpu_info->loops_per_jiffy = loops_per_jiffy;
360}
361
362void __init smp_cpus_done(unsigned int max_cpus)
363{
364 int cpu;
365 unsigned long bogosum = 0;
366
367 for_each_online_cpu(cpu)
368 bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
369
370 printk(KERN_INFO "SMP: Total of %d processors activated "
371 "(%lu.%02lu BogoMIPS).\n",
372 num_online_cpus(),
373 bogosum / (500000/HZ),
374 (bogosum / (5000/HZ)) % 100);
375}
376
377void __init smp_prepare_boot_cpu(void)
378{
379 unsigned int cpu = smp_processor_id();
380
Russell King71f512e82005-11-02 21:51:40 +0000381 per_cpu(cpu_data, cpu).idle = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Russell King82668102009-05-17 16:20:18 +0100384void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Russell Kinge3fbb082010-12-20 14:47:19 +0000386 smp_cross_call(mask, IPI_CALL_FUNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200389void arch_send_call_function_single_ipi(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Russell Kinge3fbb082010-12-20 14:47:19 +0000391 smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
Catalin Marinas3e459992008-02-04 17:28:56 +0100393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394void show_ipi_list(struct seq_file *p)
395{
396 unsigned int cpu;
397
398 seq_puts(p, "IPI:");
399
Russell Kinge11b2232005-07-11 19:26:31 +0100400 for_each_present_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
402
403 seq_putc(p, '\n');
404}
405
Russell Kingbc282482009-05-17 18:58:34 +0100406/*
407 * Timer (local or broadcast) support
408 */
409static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
410
Russell Kingc97d4862006-10-25 13:59:16 +0100411static void ipi_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Russell Kingbc282482009-05-17 18:58:34 +0100413 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 irq_enter();
Russell Kingbc282482009-05-17 18:58:34 +0100415 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 irq_exit();
417}
418
Russell King37ee16a2005-11-08 19:08:05 +0000419#ifdef CONFIG_LOCAL_TIMERS
Russell Kingb9811d72007-05-08 11:31:07 +0100420asmlinkage void __exception do_local_timer(struct pt_regs *regs)
Russell King37ee16a2005-11-08 19:08:05 +0000421{
Russell Kingc97d4862006-10-25 13:59:16 +0100422 struct pt_regs *old_regs = set_irq_regs(regs);
Russell King37ee16a2005-11-08 19:08:05 +0000423 int cpu = smp_processor_id();
424
425 if (local_timer_ack()) {
Russell King46c48f22010-11-15 14:15:03 +0000426 __inc_irq_stat(cpu, local_timer_irqs);
Russell Kingc97d4862006-10-25 13:59:16 +0100427 ipi_timer();
Russell King37ee16a2005-11-08 19:08:05 +0000428 }
Russell Kingc97d4862006-10-25 13:59:16 +0100429
430 set_irq_regs(old_regs);
Russell King37ee16a2005-11-08 19:08:05 +0000431}
Russell Kingec405ea2010-11-15 13:38:06 +0000432
433void show_local_irqs(struct seq_file *p)
434{
435 unsigned int cpu;
436
437 seq_printf(p, "LOC: ");
438
439 for_each_present_cpu(cpu)
Russell King46c48f22010-11-15 14:15:03 +0000440 seq_printf(p, "%10u ", __get_irq_stat(cpu, local_timer_irqs));
Russell Kingec405ea2010-11-15 13:38:06 +0000441
442 seq_putc(p, '\n');
443}
Russell King37ee16a2005-11-08 19:08:05 +0000444#endif
445
Russell Kingbc282482009-05-17 18:58:34 +0100446#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
447static void smp_timer_broadcast(const struct cpumask *mask)
448{
Russell Kinge3fbb082010-12-20 14:47:19 +0000449 smp_cross_call(mask, IPI_TIMER);
Russell Kingbc282482009-05-17 18:58:34 +0100450}
Russell King5388a6b2010-07-26 13:19:43 +0100451#else
452#define smp_timer_broadcast NULL
453#endif
Russell Kingbc282482009-05-17 18:58:34 +0100454
Russell King5388a6b2010-07-26 13:19:43 +0100455#ifndef CONFIG_LOCAL_TIMERS
Russell Kingbc282482009-05-17 18:58:34 +0100456static void broadcast_timer_set_mode(enum clock_event_mode mode,
457 struct clock_event_device *evt)
458{
459}
460
461static void local_timer_setup(struct clock_event_device *evt)
462{
463 evt->name = "dummy_timer";
464 evt->features = CLOCK_EVT_FEAT_ONESHOT |
465 CLOCK_EVT_FEAT_PERIODIC |
466 CLOCK_EVT_FEAT_DUMMY;
467 evt->rating = 400;
468 evt->mult = 1;
469 evt->set_mode = broadcast_timer_set_mode;
Russell Kingbc282482009-05-17 18:58:34 +0100470
471 clockevents_register_device(evt);
472}
473#endif
474
475void __cpuinit percpu_timer_setup(void)
476{
477 unsigned int cpu = smp_processor_id();
478 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
479
480 evt->cpumask = cpumask_of(cpu);
Russell King5388a6b2010-07-26 13:19:43 +0100481 evt->broadcast = smp_timer_broadcast;
Russell Kingbc282482009-05-17 18:58:34 +0100482
483 local_timer_setup(evt);
484}
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486static DEFINE_SPINLOCK(stop_lock);
487
488/*
489 * ipi_cpu_stop - handle IPI from smp_send_stop()
490 */
491static void ipi_cpu_stop(unsigned int cpu)
492{
Russell King3d3f78d2010-07-26 13:31:27 +0100493 if (system_state == SYSTEM_BOOTING ||
494 system_state == SYSTEM_RUNNING) {
495 spin_lock(&stop_lock);
496 printk(KERN_CRIT "CPU%u: stopping\n", cpu);
497 dump_stack();
498 spin_unlock(&stop_lock);
499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Russell Kinge03cdad2009-05-28 14:16:52 +0100501 set_cpu_online(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 local_fiq_disable();
504 local_irq_disable();
505
506 while (1)
507 cpu_relax();
508}
509
510/*
511 * Main handler for inter-processor interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 */
Russell Kingad3b6992010-11-15 09:42:08 +0000513asmlinkage void __exception do_IPI(int ipinr, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
515 unsigned int cpu = smp_processor_id();
516 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
Russell Kingc97d4862006-10-25 13:59:16 +0100517 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 ipi->ipi_count++;
520
Russell King24480d92010-11-15 09:54:18 +0000521 switch (ipinr) {
522 case IPI_TIMER:
523 ipi_timer();
524 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Russell King24480d92010-11-15 09:54:18 +0000526 case IPI_RESCHEDULE:
527 /*
528 * nothing more to do - eveything is
529 * done on the interrupt return path
530 */
531 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Russell King24480d92010-11-15 09:54:18 +0000533 case IPI_CALL_FUNC:
534 generic_smp_call_function_interrupt();
535 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Russell King24480d92010-11-15 09:54:18 +0000537 case IPI_CALL_FUNC_SINGLE:
538 generic_smp_call_function_single_interrupt();
539 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Russell King24480d92010-11-15 09:54:18 +0000541 case IPI_CPU_STOP:
542 ipi_cpu_stop(cpu);
543 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Russell King24480d92010-11-15 09:54:18 +0000545 default:
546 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
547 cpu, ipinr);
548 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 }
Russell Kingc97d4862006-10-25 13:59:16 +0100550 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553void smp_send_reschedule(int cpu)
554{
Russell Kinge3fbb082010-12-20 14:47:19 +0000555 smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558void smp_send_stop(void)
559{
560 cpumask_t mask = cpu_online_map;
561 cpu_clear(smp_processor_id(), mask);
Tony Lindgrenf9e417e2010-09-21 00:43:19 +0100562 if (!cpus_empty(mask))
Russell Kinge3fbb082010-12-20 14:47:19 +0000563 smp_cross_call(&mask, IPI_CPU_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566/*
567 * not supported here
568 */
Russell King5048bcb2007-07-23 12:59:46 +0100569int setup_profiling_timer(unsigned int multiplier)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
571 return -EINVAL;
572}
Russell King4b0ef3b2005-06-28 13:49:16 +0100573
Russell King82668102009-05-17 16:20:18 +0100574static void
575on_each_cpu_mask(void (*func)(void *), void *info, int wait,
576 const struct cpumask *mask)
Russell King4b0ef3b2005-06-28 13:49:16 +0100577{
Russell King4b0ef3b2005-06-28 13:49:16 +0100578 preempt_disable();
579
Russell King82668102009-05-17 16:20:18 +0100580 smp_call_function_many(mask, func, info, wait);
581 if (cpumask_test_cpu(smp_processor_id(), mask))
Russell King4b0ef3b2005-06-28 13:49:16 +0100582 func(info);
583
584 preempt_enable();
Russell King4b0ef3b2005-06-28 13:49:16 +0100585}
586
587/**********************************************************************/
588
589/*
590 * TLB operations
591 */
592struct tlb_args {
593 struct vm_area_struct *ta_vma;
594 unsigned long ta_start;
595 unsigned long ta_end;
596};
597
598static inline void ipi_flush_tlb_all(void *ignored)
599{
600 local_flush_tlb_all();
601}
602
603static inline void ipi_flush_tlb_mm(void *arg)
604{
605 struct mm_struct *mm = (struct mm_struct *)arg;
606
607 local_flush_tlb_mm(mm);
608}
609
610static inline void ipi_flush_tlb_page(void *arg)
611{
612 struct tlb_args *ta = (struct tlb_args *)arg;
613
614 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
615}
616
617static inline void ipi_flush_tlb_kernel_page(void *arg)
618{
619 struct tlb_args *ta = (struct tlb_args *)arg;
620
621 local_flush_tlb_kernel_page(ta->ta_start);
622}
623
624static inline void ipi_flush_tlb_range(void *arg)
625{
626 struct tlb_args *ta = (struct tlb_args *)arg;
627
628 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
629}
630
631static inline void ipi_flush_tlb_kernel_range(void *arg)
632{
633 struct tlb_args *ta = (struct tlb_args *)arg;
634
635 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
636}
637
638void flush_tlb_all(void)
639{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100640 if (tlb_ops_need_broadcast())
641 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
642 else
643 local_flush_tlb_all();
Russell King4b0ef3b2005-06-28 13:49:16 +0100644}
645
646void flush_tlb_mm(struct mm_struct *mm)
647{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100648 if (tlb_ops_need_broadcast())
Rusty Russell56f8ba82009-09-24 09:34:49 -0600649 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100650 else
651 local_flush_tlb_mm(mm);
Russell King4b0ef3b2005-06-28 13:49:16 +0100652}
653
654void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
655{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100656 if (tlb_ops_need_broadcast()) {
657 struct tlb_args ta;
658 ta.ta_vma = vma;
659 ta.ta_start = uaddr;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600660 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100661 } else
662 local_flush_tlb_page(vma, uaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100663}
664
665void flush_tlb_kernel_page(unsigned long kaddr)
666{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100667 if (tlb_ops_need_broadcast()) {
668 struct tlb_args ta;
669 ta.ta_start = kaddr;
670 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
671 } else
672 local_flush_tlb_kernel_page(kaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100673}
674
675void flush_tlb_range(struct vm_area_struct *vma,
676 unsigned long start, unsigned long end)
677{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100678 if (tlb_ops_need_broadcast()) {
679 struct tlb_args ta;
680 ta.ta_vma = vma;
681 ta.ta_start = start;
682 ta.ta_end = end;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600683 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100684 } else
685 local_flush_tlb_range(vma, start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100686}
687
688void flush_tlb_kernel_range(unsigned long start, unsigned long end)
689{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100690 if (tlb_ops_need_broadcast()) {
691 struct tlb_args ta;
692 ta.ta_start = start;
693 ta.ta_end = end;
694 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
695 } else
696 local_flush_tlb_kernel_range(start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100697}