blob: 57162af53dc982cc0911e09537915eb1eddc1cbb [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>
36#include <asm/tlbflush.h>
37#include <asm/ptrace.h>
Russell Kingbc282482009-05-17 18:58:34 +010038#include <asm/localtimer.h>
Russell Kinge616c592009-09-27 20:55:43 +010039#include <asm/smp_plat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/*
Russell Kinge65f38e2005-06-18 09:33:31 +010042 * 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
45 */
46struct secondary_data secondary_data;
47
48/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * structures for inter-processor calls
50 * - A collection of single bit ipi messages.
51 */
52struct ipi_data {
53 spinlock_t lock;
54 unsigned long ipi_count;
55 unsigned long bits;
56};
57
58static DEFINE_PER_CPU(struct ipi_data, ipi_data) = {
59 .lock = SPIN_LOCK_UNLOCKED,
60};
61
62enum ipi_msg_type {
63 IPI_TIMER,
64 IPI_RESCHEDULE,
65 IPI_CALL_FUNC,
Jens Axboef6dd9fa52008-06-10 20:48:30 +020066 IPI_CALL_FUNC_SINGLE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 IPI_CPU_STOP,
68};
69
Russell Kingbd6f68a2005-07-17 21:35:41 +010070int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Russell King71f512e2005-11-02 21:51:40 +000072 struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
73 struct task_struct *idle = ci->idle;
Russell Kinge65f38e2005-06-18 09:33:31 +010074 pgd_t *pgd;
75 pmd_t *pmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 int ret;
77
78 /*
Russell King71f512e2005-11-02 21:51:40 +000079 * Spawn a new process manually, if not already done.
80 * Grab a pointer to its task struct so we can mess with it
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 */
Russell King71f512e2005-11-02 21:51:40 +000082 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);
87 }
88 ci->idle = idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
91 /*
Russell Kinge65f38e2005-06-18 09:33:31 +010092 * 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.
96 */
97 pgd = pgd_alloc(&init_mm);
Russell King058ddee2008-08-07 22:36:59 +010098 pmd = pmd_offset(pgd + pgd_index(PHYS_OFFSET), PHYS_OFFSET);
Russell Kinge65f38e2005-06-18 09:33:31 +010099 *pmd = __pmd((PHYS_OFFSET & PGDIR_MASK) |
100 PMD_TYPE_SECT | PMD_SECT_AP_WRITE);
Catalin Marinase9fc7822009-02-11 13:14:57 +0100101 flush_pmd_entry(pmd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100102
103 /*
104 * We need to tell the secondary core where to find
105 * its stack and the page tables.
106 */
Al Viro32d39a92006-01-12 01:05:58 -0800107 secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
Russell Kinge65f38e2005-06-18 09:33:31 +0100108 secondary_data.pgdir = virt_to_phys(pgd);
109 wmb();
110
111 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * Now bring the CPU into our world.
113 */
114 ret = boot_secondary(cpu, idle);
Russell Kinge65f38e2005-06-18 09:33:31 +0100115 if (ret == 0) {
116 unsigned long timeout;
117
118 /*
119 * CPU was successfully started, wait for it
120 * to come online or time out.
121 */
122 timeout = jiffies + HZ;
123 while (time_before(jiffies, timeout)) {
124 if (cpu_online(cpu))
125 break;
126
127 udelay(10);
128 barrier();
129 }
130
131 if (!cpu_online(cpu))
132 ret = -EIO;
133 }
134
Russell King5d430452005-11-08 10:44:46 +0000135 secondary_data.stack = NULL;
Russell Kinge65f38e2005-06-18 09:33:31 +0100136 secondary_data.pgdir = 0;
137
Russell King058ddee2008-08-07 22:36:59 +0100138 *pmd = __pmd(0);
Catalin Marinase9fc7822009-02-11 13:14:57 +0100139 clean_pmd_entry(pmd);
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800140 pgd_free(&init_mm, pgd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (ret) {
Russell King0908db22005-06-19 19:48:16 +0100143 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /*
146 * FIXME: We need to clean up the new idle thread. --rmk
147 */
148 }
149
150 return ret;
151}
152
Russell Kinga054a812005-11-02 22:24:33 +0000153#ifdef CONFIG_HOTPLUG_CPU
154/*
155 * __cpu_disable runs on the processor to be shutdown.
156 */
Russell King90140c32009-09-27 21:04:48 +0100157int __cpu_disable(void)
Russell Kinga054a812005-11-02 22:24:33 +0000158{
159 unsigned int cpu = smp_processor_id();
160 struct task_struct *p;
161 int ret;
162
163 ret = mach_cpu_disable(cpu);
164 if (ret)
165 return ret;
166
167 /*
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.
170 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100171 set_cpu_online(cpu, false);
Russell Kinga054a812005-11-02 22:24:33 +0000172
173 /*
174 * OK - migrate IRQs away from this CPU
175 */
176 migrate_irqs();
177
178 /*
Russell King37ee16a2005-11-08 19:08:05 +0000179 * Stop the local timer for this CPU.
180 */
Catalin Marinasebac6542008-12-01 14:54:57 +0000181 local_timer_stop();
Russell King37ee16a2005-11-08 19:08:05 +0000182
183 /*
Russell Kinga054a812005-11-02 22:24:33 +0000184 * Flush user cache and TLB mappings, and then remove this CPU
185 * from the vm mask set of all processes.
186 */
187 flush_cache_all();
188 local_flush_tlb_all();
189
190 read_lock(&tasklist_lock);
191 for_each_process(p) {
192 if (p->mm)
Rusty Russell56f8ba82009-09-24 09:34:49 -0600193 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
Russell Kinga054a812005-11-02 22:24:33 +0000194 }
195 read_unlock(&tasklist_lock);
196
197 return 0;
198}
199
200/*
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.
203 */
Russell King90140c32009-09-27 21:04:48 +0100204void __cpu_die(unsigned int cpu)
Russell Kinga054a812005-11-02 22:24:33 +0000205{
206 if (!platform_cpu_kill(cpu))
207 printk("CPU%u: unable to kill\n", cpu);
208}
209
210/*
211 * Called from the idle thread for the CPU which has been shutdown.
212 *
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.
217 */
Russell King90140c32009-09-27 21:04:48 +0100218void __ref cpu_die(void)
Russell Kinga054a812005-11-02 22:24:33 +0000219{
220 unsigned int cpu = smp_processor_id();
221
222 local_irq_disable();
223 idle_task_exit();
224
225 /*
226 * actual CPU shutdown procedure is at least platform (if not
227 * CPU) specific
228 */
229 platform_cpu_die(cpu);
230
231 /*
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.
235 */
236 __asm__("mov sp, %0\n"
237 " b secondary_start_kernel"
238 :
Al Viro32d39a92006-01-12 01:05:58 -0800239 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
Russell Kinga054a812005-11-02 22:24:33 +0000240}
241#endif /* CONFIG_HOTPLUG_CPU */
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*
Russell Kinge65f38e2005-06-18 09:33:31 +0100244 * This is the secondary CPU boot entry. We're using this CPUs
245 * idle thread stack, but a set of temporary page tables.
246 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100247asmlinkage void __cpuinit secondary_start_kernel(void)
Russell Kinge65f38e2005-06-18 09:33:31 +0100248{
249 struct mm_struct *mm = &init_mm;
Russell Kingda2660d2005-11-12 17:21:47 +0000250 unsigned int cpu = smp_processor_id();
Russell Kinge65f38e2005-06-18 09:33:31 +0100251
252 printk("CPU%u: Booted secondary processor\n", cpu);
253
254 /*
255 * All kernel threads share the same mm context; grab a
256 * reference and switch to it.
257 */
258 atomic_inc(&mm->mm_users);
259 atomic_inc(&mm->mm_count);
260 current->active_mm = mm;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600261 cpumask_set_cpu(cpu, mm_cpumask(mm));
Russell Kinge65f38e2005-06-18 09:33:31 +0100262 cpu_switch_mm(mm->pgd, mm);
263 enter_lazy_tlb(mm, current);
Russell King505d7b12005-07-28 20:32:47 +0100264 local_flush_tlb_all();
Russell Kinge65f38e2005-06-18 09:33:31 +0100265
266 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800267 preempt_disable();
Russell Kinge65f38e2005-06-18 09:33:31 +0100268
269 /*
270 * Give the platform a chance to do its own initialisation.
271 */
272 platform_secondary_init(cpu);
273
274 /*
275 * Enable local interrupts.
276 */
Manfred Spraule545a612008-09-07 16:57:22 +0200277 notify_cpu_starting(cpu);
Russell Kinge65f38e2005-06-18 09:33:31 +0100278 local_irq_enable();
279 local_fiq_enable();
280
Catalin Marinasa8655e82008-02-04 17:30:57 +0100281 /*
Russell Kingbc282482009-05-17 18:58:34 +0100282 * Setup the percpu timer for this CPU.
Catalin Marinasa8655e82008-02-04 17:30:57 +0100283 */
Russell Kingbc282482009-05-17 18:58:34 +0100284 percpu_timer_setup();
Catalin Marinasa8655e82008-02-04 17:30:57 +0100285
Russell Kinge65f38e2005-06-18 09:33:31 +0100286 calibrate_delay();
287
288 smp_store_cpu_info(cpu);
289
290 /*
291 * OK, now it's safe to let the boot CPU continue
292 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100293 set_cpu_online(cpu, true);
Russell Kinge65f38e2005-06-18 09:33:31 +0100294
295 /*
296 * OK, it's off to the idle thread for us
297 */
298 cpu_idle();
299}
300
301/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * Called by both boot and secondaries to move global data into
303 * per-processor storage.
304 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100305void __cpuinit smp_store_cpu_info(unsigned int cpuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
307 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
308
309 cpu_info->loops_per_jiffy = loops_per_jiffy;
310}
311
312void __init smp_cpus_done(unsigned int max_cpus)
313{
314 int cpu;
315 unsigned long bogosum = 0;
316
317 for_each_online_cpu(cpu)
318 bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
319
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);
325}
326
327void __init smp_prepare_boot_cpu(void)
328{
329 unsigned int cpu = smp_processor_id();
330
Russell King71f512e2005-11-02 21:51:40 +0000331 per_cpu(cpu_data, cpu).idle = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Russell King82668102009-05-17 16:20:18 +0100334static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 unsigned long flags;
337 unsigned int cpu;
338
339 local_irq_save(flags);
340
Russell King82668102009-05-17 16:20:18 +0100341 for_each_cpu(cpu, mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
343
344 spin_lock(&ipi->lock);
345 ipi->bits |= 1 << msg;
346 spin_unlock(&ipi->lock);
347 }
348
349 /*
350 * Call the platform specific cross-CPU call function.
351 */
Russell King82668102009-05-17 16:20:18 +0100352 smp_cross_call(mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 local_irq_restore(flags);
355}
356
Russell King82668102009-05-17 16:20:18 +0100357void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Jens Axboef6dd9fa52008-06-10 20:48:30 +0200359 send_ipi_message(mask, IPI_CALL_FUNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
Jens Axboef6dd9fa52008-06-10 20:48:30 +0200362void arch_send_call_function_single_ipi(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Russell King82668102009-05-17 16:20:18 +0100364 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
Catalin Marinas3e459992008-02-04 17:28:56 +0100366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367void show_ipi_list(struct seq_file *p)
368{
369 unsigned int cpu;
370
371 seq_puts(p, "IPI:");
372
Russell Kinge11b2232005-07-11 19:26:31 +0100373 for_each_present_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
375
376 seq_putc(p, '\n');
377}
378
Russell King37ee16a2005-11-08 19:08:05 +0000379void show_local_irqs(struct seq_file *p)
380{
381 unsigned int cpu;
382
383 seq_printf(p, "LOC: ");
384
385 for_each_present_cpu(cpu)
386 seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs);
387
388 seq_putc(p, '\n');
389}
390
Russell Kingbc282482009-05-17 18:58:34 +0100391/*
392 * Timer (local or broadcast) support
393 */
394static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
395
Russell Kingc97d4862006-10-25 13:59:16 +0100396static void ipi_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Russell Kingbc282482009-05-17 18:58:34 +0100398 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 irq_enter();
Russell Kingbc282482009-05-17 18:58:34 +0100400 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 irq_exit();
402}
403
Russell King37ee16a2005-11-08 19:08:05 +0000404#ifdef CONFIG_LOCAL_TIMERS
Russell Kingb9811d72007-05-08 11:31:07 +0100405asmlinkage void __exception do_local_timer(struct pt_regs *regs)
Russell King37ee16a2005-11-08 19:08:05 +0000406{
Russell Kingc97d4862006-10-25 13:59:16 +0100407 struct pt_regs *old_regs = set_irq_regs(regs);
Russell King37ee16a2005-11-08 19:08:05 +0000408 int cpu = smp_processor_id();
409
410 if (local_timer_ack()) {
411 irq_stat[cpu].local_timer_irqs++;
Russell Kingc97d4862006-10-25 13:59:16 +0100412 ipi_timer();
Russell King37ee16a2005-11-08 19:08:05 +0000413 }
Russell Kingc97d4862006-10-25 13:59:16 +0100414
415 set_irq_regs(old_regs);
Russell King37ee16a2005-11-08 19:08:05 +0000416}
417#endif
418
Russell Kingbc282482009-05-17 18:58:34 +0100419#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
420static void smp_timer_broadcast(const struct cpumask *mask)
421{
422 send_ipi_message(mask, IPI_TIMER);
423}
424
425static void broadcast_timer_set_mode(enum clock_event_mode mode,
426 struct clock_event_device *evt)
427{
428}
429
430static void local_timer_setup(struct clock_event_device *evt)
431{
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;
440
441 clockevents_register_device(evt);
442}
443#endif
444
445void __cpuinit percpu_timer_setup(void)
446{
447 unsigned int cpu = smp_processor_id();
448 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
449
450 evt->cpumask = cpumask_of(cpu);
451
452 local_timer_setup(evt);
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455static DEFINE_SPINLOCK(stop_lock);
456
457/*
458 * ipi_cpu_stop - handle IPI from smp_send_stop()
459 */
460static void ipi_cpu_stop(unsigned int cpu)
461{
462 spin_lock(&stop_lock);
463 printk(KERN_CRIT "CPU%u: stopping\n", cpu);
464 dump_stack();
465 spin_unlock(&stop_lock);
466
Russell Kinge03cdad2009-05-28 14:16:52 +0100467 set_cpu_online(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 local_fiq_disable();
470 local_irq_disable();
471
472 while (1)
473 cpu_relax();
474}
475
476/*
477 * Main handler for inter-processor interrupts
478 *
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):
482 *
483 * Bit 0 - Inter-processor function call
484 */
Russell Kingb9811d72007-05-08 11:31:07 +0100485asmlinkage void __exception do_IPI(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
487 unsigned int cpu = smp_processor_id();
488 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
Russell Kingc97d4862006-10-25 13:59:16 +0100489 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 ipi->ipi_count++;
492
493 for (;;) {
494 unsigned long msgs;
495
496 spin_lock(&ipi->lock);
497 msgs = ipi->bits;
498 ipi->bits = 0;
499 spin_unlock(&ipi->lock);
500
501 if (!msgs)
502 break;
503
504 do {
505 unsigned nextmsg;
506
507 nextmsg = msgs & -msgs;
508 msgs &= ~nextmsg;
509 nextmsg = ffz(~nextmsg);
510
511 switch (nextmsg) {
512 case IPI_TIMER:
Russell Kingc97d4862006-10-25 13:59:16 +0100513 ipi_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 break;
515
516 case IPI_RESCHEDULE:
517 /*
518 * nothing more to do - eveything is
519 * done on the interrupt return path
520 */
521 break;
522
523 case IPI_CALL_FUNC:
Jens Axboef6dd9fa52008-06-10 20:48:30 +0200524 generic_smp_call_function_interrupt();
525 break;
526
527 case IPI_CALL_FUNC_SINGLE:
528 generic_smp_call_function_single_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 break;
530
531 case IPI_CPU_STOP:
532 ipi_cpu_stop(cpu);
533 break;
534
535 default:
536 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
537 cpu, nextmsg);
538 break;
539 }
540 } while (msgs);
541 }
Russell Kingc97d4862006-10-25 13:59:16 +0100542
543 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
546void smp_send_reschedule(int cpu)
547{
Russell King82668102009-05-17 16:20:18 +0100548 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551void smp_send_stop(void)
552{
553 cpumask_t mask = cpu_online_map;
554 cpu_clear(smp_processor_id(), mask);
Russell King82668102009-05-17 16:20:18 +0100555 send_ipi_message(&mask, IPI_CPU_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558/*
559 * not supported here
560 */
Russell King5048bcb2007-07-23 12:59:46 +0100561int setup_profiling_timer(unsigned int multiplier)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
563 return -EINVAL;
564}
Russell King4b0ef3b2005-06-28 13:49:16 +0100565
Russell King82668102009-05-17 16:20:18 +0100566static void
567on_each_cpu_mask(void (*func)(void *), void *info, int wait,
568 const struct cpumask *mask)
Russell King4b0ef3b2005-06-28 13:49:16 +0100569{
Russell King4b0ef3b2005-06-28 13:49:16 +0100570 preempt_disable();
571
Russell King82668102009-05-17 16:20:18 +0100572 smp_call_function_many(mask, func, info, wait);
573 if (cpumask_test_cpu(smp_processor_id(), mask))
Russell King4b0ef3b2005-06-28 13:49:16 +0100574 func(info);
575
576 preempt_enable();
Russell King4b0ef3b2005-06-28 13:49:16 +0100577}
578
579/**********************************************************************/
580
581/*
582 * TLB operations
583 */
584struct tlb_args {
585 struct vm_area_struct *ta_vma;
586 unsigned long ta_start;
587 unsigned long ta_end;
588};
589
590static inline void ipi_flush_tlb_all(void *ignored)
591{
592 local_flush_tlb_all();
593}
594
595static inline void ipi_flush_tlb_mm(void *arg)
596{
597 struct mm_struct *mm = (struct mm_struct *)arg;
598
599 local_flush_tlb_mm(mm);
600}
601
602static inline void ipi_flush_tlb_page(void *arg)
603{
604 struct tlb_args *ta = (struct tlb_args *)arg;
605
606 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
607}
608
609static inline void ipi_flush_tlb_kernel_page(void *arg)
610{
611 struct tlb_args *ta = (struct tlb_args *)arg;
612
613 local_flush_tlb_kernel_page(ta->ta_start);
614}
615
616static inline void ipi_flush_tlb_range(void *arg)
617{
618 struct tlb_args *ta = (struct tlb_args *)arg;
619
620 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
621}
622
623static inline void ipi_flush_tlb_kernel_range(void *arg)
624{
625 struct tlb_args *ta = (struct tlb_args *)arg;
626
627 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
628}
629
630void flush_tlb_all(void)
631{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100632 if (tlb_ops_need_broadcast())
633 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
634 else
635 local_flush_tlb_all();
Russell King4b0ef3b2005-06-28 13:49:16 +0100636}
637
638void flush_tlb_mm(struct mm_struct *mm)
639{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100640 if (tlb_ops_need_broadcast())
Rusty Russell56f8ba82009-09-24 09:34:49 -0600641 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100642 else
643 local_flush_tlb_mm(mm);
Russell King4b0ef3b2005-06-28 13:49:16 +0100644}
645
646void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
647{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100648 if (tlb_ops_need_broadcast()) {
649 struct tlb_args ta;
650 ta.ta_vma = vma;
651 ta.ta_start = uaddr;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600652 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100653 } else
654 local_flush_tlb_page(vma, uaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100655}
656
657void flush_tlb_kernel_page(unsigned long kaddr)
658{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100659 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);
Russell King4b0ef3b2005-06-28 13:49:16 +0100665}
666
667void flush_tlb_range(struct vm_area_struct *vma,
668 unsigned long start, unsigned long end)
669{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100670 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;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600675 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100676 } else
677 local_flush_tlb_range(vma, start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100678}
679
680void flush_tlb_kernel_range(unsigned long start, unsigned long end)
681{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100682 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);
Russell King4b0ef3b2005-06-28 13:49:16 +0100689}