blob: 7a3cc0266934015525c85a9ba390b3e9dabcf433 [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 Axboef6dd9fa2008-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 King71f512e82005-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 King71f512e82005-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 King71f512e82005-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 King10272472010-02-12 14:36:24 +0000102 outer_clean_range(__pa(pmd), __pa(pmd + 1));
Russell Kinge65f38e2005-06-18 09:33:31 +0100103
104 /*
105 * We need to tell the secondary core where to find
106 * its stack and the page tables.
107 */
Al Viro32d39a92006-01-12 01:05:58 -0800108 secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
Russell Kinge65f38e2005-06-18 09:33:31 +0100109 secondary_data.pgdir = virt_to_phys(pgd);
Russell King10272472010-02-12 14:36:24 +0000110 __cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data));
111 outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1));
Russell Kinge65f38e2005-06-18 09:33:31 +0100112
113 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 * Now bring the CPU into our world.
115 */
116 ret = boot_secondary(cpu, idle);
Russell Kinge65f38e2005-06-18 09:33:31 +0100117 if (ret == 0) {
118 unsigned long timeout;
119
120 /*
121 * CPU was successfully started, wait for it
122 * to come online or time out.
123 */
124 timeout = jiffies + HZ;
125 while (time_before(jiffies, timeout)) {
126 if (cpu_online(cpu))
127 break;
128
129 udelay(10);
130 barrier();
131 }
132
133 if (!cpu_online(cpu))
134 ret = -EIO;
135 }
136
Russell King5d430452005-11-08 10:44:46 +0000137 secondary_data.stack = NULL;
Russell Kinge65f38e2005-06-18 09:33:31 +0100138 secondary_data.pgdir = 0;
139
Russell King058ddee2008-08-07 22:36:59 +0100140 *pmd = __pmd(0);
Catalin Marinase9fc7822009-02-11 13:14:57 +0100141 clean_pmd_entry(pmd);
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800142 pgd_free(&init_mm, pgd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 if (ret) {
Russell King0908db22005-06-19 19:48:16 +0100145 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 /*
148 * FIXME: We need to clean up the new idle thread. --rmk
149 */
150 }
151
152 return ret;
153}
154
Russell Kinga054a812005-11-02 22:24:33 +0000155#ifdef CONFIG_HOTPLUG_CPU
156/*
157 * __cpu_disable runs on the processor to be shutdown.
158 */
Russell King90140c32009-09-27 21:04:48 +0100159int __cpu_disable(void)
Russell Kinga054a812005-11-02 22:24:33 +0000160{
161 unsigned int cpu = smp_processor_id();
162 struct task_struct *p;
163 int ret;
164
Russell King8e2a43f2010-05-15 10:18:05 +0100165 ret = platform_cpu_disable(cpu);
Russell Kinga054a812005-11-02 22:24:33 +0000166 if (ret)
167 return ret;
168
169 /*
170 * Take this CPU offline. Once we clear this, we can't return,
171 * and we must not schedule until we're ready to give up the cpu.
172 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100173 set_cpu_online(cpu, false);
Russell Kinga054a812005-11-02 22:24:33 +0000174
175 /*
176 * OK - migrate IRQs away from this CPU
177 */
178 migrate_irqs();
179
180 /*
Russell King37ee16a2005-11-08 19:08:05 +0000181 * Stop the local timer for this CPU.
182 */
Catalin Marinasebac6542008-12-01 14:54:57 +0000183 local_timer_stop();
Russell King37ee16a2005-11-08 19:08:05 +0000184
185 /*
Russell Kinga054a812005-11-02 22:24:33 +0000186 * Flush user cache and TLB mappings, and then remove this CPU
187 * from the vm mask set of all processes.
188 */
189 flush_cache_all();
190 local_flush_tlb_all();
191
192 read_lock(&tasklist_lock);
193 for_each_process(p) {
194 if (p->mm)
Rusty Russell56f8ba82009-09-24 09:34:49 -0600195 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
Russell Kinga054a812005-11-02 22:24:33 +0000196 }
197 read_unlock(&tasklist_lock);
198
199 return 0;
200}
201
202/*
203 * called on the thread which is asking for a CPU to be shutdown -
204 * waits until shutdown has completed, or it is timed out.
205 */
Russell King90140c32009-09-27 21:04:48 +0100206void __cpu_die(unsigned int cpu)
Russell Kinga054a812005-11-02 22:24:33 +0000207{
208 if (!platform_cpu_kill(cpu))
209 printk("CPU%u: unable to kill\n", cpu);
210}
211
212/*
213 * Called from the idle thread for the CPU which has been shutdown.
214 *
215 * Note that we disable IRQs here, but do not re-enable them
216 * before returning to the caller. This is also the behaviour
217 * of the other hotplug-cpu capable cores, so presumably coming
218 * out of idle fixes this.
219 */
Russell King90140c32009-09-27 21:04:48 +0100220void __ref cpu_die(void)
Russell Kinga054a812005-11-02 22:24:33 +0000221{
222 unsigned int cpu = smp_processor_id();
223
224 local_irq_disable();
225 idle_task_exit();
226
227 /*
228 * actual CPU shutdown procedure is at least platform (if not
229 * CPU) specific
230 */
231 platform_cpu_die(cpu);
232
233 /*
234 * Do not return to the idle loop - jump back to the secondary
235 * cpu initialisation. There's some initialisation which needs
236 * to be repeated to undo the effects of taking the CPU offline.
237 */
238 __asm__("mov sp, %0\n"
239 " b secondary_start_kernel"
240 :
Al Viro32d39a92006-01-12 01:05:58 -0800241 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
Russell Kinga054a812005-11-02 22:24:33 +0000242}
243#endif /* CONFIG_HOTPLUG_CPU */
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/*
Russell Kinge65f38e2005-06-18 09:33:31 +0100246 * This is the secondary CPU boot entry. We're using this CPUs
247 * idle thread stack, but a set of temporary page tables.
248 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100249asmlinkage void __cpuinit secondary_start_kernel(void)
Russell Kinge65f38e2005-06-18 09:33:31 +0100250{
251 struct mm_struct *mm = &init_mm;
Russell Kingda2660d2005-11-12 17:21:47 +0000252 unsigned int cpu = smp_processor_id();
Russell Kinge65f38e2005-06-18 09:33:31 +0100253
254 printk("CPU%u: Booted secondary processor\n", cpu);
255
256 /*
257 * All kernel threads share the same mm context; grab a
258 * reference and switch to it.
259 */
260 atomic_inc(&mm->mm_users);
261 atomic_inc(&mm->mm_count);
262 current->active_mm = mm;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600263 cpumask_set_cpu(cpu, mm_cpumask(mm));
Russell Kinge65f38e2005-06-18 09:33:31 +0100264 cpu_switch_mm(mm->pgd, mm);
265 enter_lazy_tlb(mm, current);
Russell King505d7b12005-07-28 20:32:47 +0100266 local_flush_tlb_all();
Russell Kinge65f38e2005-06-18 09:33:31 +0100267
268 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800269 preempt_disable();
Russell Kinge65f38e2005-06-18 09:33:31 +0100270
271 /*
272 * Give the platform a chance to do its own initialisation.
273 */
274 platform_secondary_init(cpu);
275
276 /*
277 * Enable local interrupts.
278 */
Manfred Spraule545a612008-09-07 16:57:22 +0200279 notify_cpu_starting(cpu);
Russell Kinge65f38e2005-06-18 09:33:31 +0100280 local_irq_enable();
281 local_fiq_enable();
282
Catalin Marinasa8655e82008-02-04 17:30:57 +0100283 /*
Russell Kingbc282482009-05-17 18:58:34 +0100284 * Setup the percpu timer for this CPU.
Catalin Marinasa8655e82008-02-04 17:30:57 +0100285 */
Russell Kingbc282482009-05-17 18:58:34 +0100286 percpu_timer_setup();
Catalin Marinasa8655e82008-02-04 17:30:57 +0100287
Russell Kinge65f38e2005-06-18 09:33:31 +0100288 calibrate_delay();
289
290 smp_store_cpu_info(cpu);
291
292 /*
293 * OK, now it's safe to let the boot CPU continue
294 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100295 set_cpu_online(cpu, true);
Russell Kinge65f38e2005-06-18 09:33:31 +0100296
297 /*
298 * OK, it's off to the idle thread for us
299 */
300 cpu_idle();
301}
302
303/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 * Called by both boot and secondaries to move global data into
305 * per-processor storage.
306 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100307void __cpuinit smp_store_cpu_info(unsigned int cpuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
310
311 cpu_info->loops_per_jiffy = loops_per_jiffy;
312}
313
314void __init smp_cpus_done(unsigned int max_cpus)
315{
316 int cpu;
317 unsigned long bogosum = 0;
318
319 for_each_online_cpu(cpu)
320 bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
321
322 printk(KERN_INFO "SMP: Total of %d processors activated "
323 "(%lu.%02lu BogoMIPS).\n",
324 num_online_cpus(),
325 bogosum / (500000/HZ),
326 (bogosum / (5000/HZ)) % 100);
327}
328
329void __init smp_prepare_boot_cpu(void)
330{
331 unsigned int cpu = smp_processor_id();
332
Russell King71f512e82005-11-02 21:51:40 +0000333 per_cpu(cpu_data, cpu).idle = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
335
Russell King82668102009-05-17 16:20:18 +0100336static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 unsigned long flags;
339 unsigned int cpu;
340
341 local_irq_save(flags);
342
Russell King82668102009-05-17 16:20:18 +0100343 for_each_cpu(cpu, mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
345
346 spin_lock(&ipi->lock);
347 ipi->bits |= 1 << msg;
348 spin_unlock(&ipi->lock);
349 }
350
351 /*
352 * Call the platform specific cross-CPU call function.
353 */
Russell King82668102009-05-17 16:20:18 +0100354 smp_cross_call(mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 local_irq_restore(flags);
357}
358
Russell King82668102009-05-17 16:20:18 +0100359void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200361 send_ipi_message(mask, IPI_CALL_FUNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200364void arch_send_call_function_single_ipi(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Russell King82668102009-05-17 16:20:18 +0100366 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
Catalin Marinas3e459992008-02-04 17:28:56 +0100368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369void show_ipi_list(struct seq_file *p)
370{
371 unsigned int cpu;
372
373 seq_puts(p, "IPI:");
374
Russell Kinge11b2232005-07-11 19:26:31 +0100375 for_each_present_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
377
378 seq_putc(p, '\n');
379}
380
Russell King37ee16a2005-11-08 19:08:05 +0000381void show_local_irqs(struct seq_file *p)
382{
383 unsigned int cpu;
384
385 seq_printf(p, "LOC: ");
386
387 for_each_present_cpu(cpu)
388 seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs);
389
390 seq_putc(p, '\n');
391}
392
Russell Kingbc282482009-05-17 18:58:34 +0100393/*
394 * Timer (local or broadcast) support
395 */
396static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
397
Russell Kingc97d4862006-10-25 13:59:16 +0100398static void ipi_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Russell Kingbc282482009-05-17 18:58:34 +0100400 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 irq_enter();
Russell Kingbc282482009-05-17 18:58:34 +0100402 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 irq_exit();
404}
405
Russell King37ee16a2005-11-08 19:08:05 +0000406#ifdef CONFIG_LOCAL_TIMERS
Russell Kingb9811d72007-05-08 11:31:07 +0100407asmlinkage void __exception do_local_timer(struct pt_regs *regs)
Russell King37ee16a2005-11-08 19:08:05 +0000408{
Russell Kingc97d4862006-10-25 13:59:16 +0100409 struct pt_regs *old_regs = set_irq_regs(regs);
Russell King37ee16a2005-11-08 19:08:05 +0000410 int cpu = smp_processor_id();
411
412 if (local_timer_ack()) {
413 irq_stat[cpu].local_timer_irqs++;
Russell Kingc97d4862006-10-25 13:59:16 +0100414 ipi_timer();
Russell King37ee16a2005-11-08 19:08:05 +0000415 }
Russell Kingc97d4862006-10-25 13:59:16 +0100416
417 set_irq_regs(old_regs);
Russell King37ee16a2005-11-08 19:08:05 +0000418}
419#endif
420
Russell Kingbc282482009-05-17 18:58:34 +0100421#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
422static void smp_timer_broadcast(const struct cpumask *mask)
423{
424 send_ipi_message(mask, IPI_TIMER);
425}
426
427static void broadcast_timer_set_mode(enum clock_event_mode mode,
428 struct clock_event_device *evt)
429{
430}
431
432static void local_timer_setup(struct clock_event_device *evt)
433{
434 evt->name = "dummy_timer";
435 evt->features = CLOCK_EVT_FEAT_ONESHOT |
436 CLOCK_EVT_FEAT_PERIODIC |
437 CLOCK_EVT_FEAT_DUMMY;
438 evt->rating = 400;
439 evt->mult = 1;
440 evt->set_mode = broadcast_timer_set_mode;
441 evt->broadcast = smp_timer_broadcast;
442
443 clockevents_register_device(evt);
444}
445#endif
446
447void __cpuinit percpu_timer_setup(void)
448{
449 unsigned int cpu = smp_processor_id();
450 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
451
452 evt->cpumask = cpumask_of(cpu);
453
454 local_timer_setup(evt);
455}
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457static DEFINE_SPINLOCK(stop_lock);
458
459/*
460 * ipi_cpu_stop - handle IPI from smp_send_stop()
461 */
462static void ipi_cpu_stop(unsigned int cpu)
463{
464 spin_lock(&stop_lock);
465 printk(KERN_CRIT "CPU%u: stopping\n", cpu);
466 dump_stack();
467 spin_unlock(&stop_lock);
468
Russell Kinge03cdad2009-05-28 14:16:52 +0100469 set_cpu_online(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 local_fiq_disable();
472 local_irq_disable();
473
474 while (1)
475 cpu_relax();
476}
477
478/*
479 * Main handler for inter-processor interrupts
480 *
481 * For ARM, the ipimask now only identifies a single
482 * category of IPI (Bit 1 IPIs have been replaced by a
483 * different mechanism):
484 *
485 * Bit 0 - Inter-processor function call
486 */
Russell Kingb9811d72007-05-08 11:31:07 +0100487asmlinkage void __exception do_IPI(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 unsigned int cpu = smp_processor_id();
490 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
Russell Kingc97d4862006-10-25 13:59:16 +0100491 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 ipi->ipi_count++;
494
495 for (;;) {
496 unsigned long msgs;
497
498 spin_lock(&ipi->lock);
499 msgs = ipi->bits;
500 ipi->bits = 0;
501 spin_unlock(&ipi->lock);
502
503 if (!msgs)
504 break;
505
506 do {
507 unsigned nextmsg;
508
509 nextmsg = msgs & -msgs;
510 msgs &= ~nextmsg;
511 nextmsg = ffz(~nextmsg);
512
513 switch (nextmsg) {
514 case IPI_TIMER:
Russell Kingc97d4862006-10-25 13:59:16 +0100515 ipi_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 break;
517
518 case IPI_RESCHEDULE:
519 /*
520 * nothing more to do - eveything is
521 * done on the interrupt return path
522 */
523 break;
524
525 case IPI_CALL_FUNC:
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200526 generic_smp_call_function_interrupt();
527 break;
528
529 case IPI_CALL_FUNC_SINGLE:
530 generic_smp_call_function_single_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 break;
532
533 case IPI_CPU_STOP:
534 ipi_cpu_stop(cpu);
535 break;
536
537 default:
538 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
539 cpu, nextmsg);
540 break;
541 }
542 } while (msgs);
543 }
Russell Kingc97d4862006-10-25 13:59:16 +0100544
545 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
548void smp_send_reschedule(int cpu)
549{
Russell King82668102009-05-17 16:20:18 +0100550 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553void smp_send_stop(void)
554{
555 cpumask_t mask = cpu_online_map;
556 cpu_clear(smp_processor_id(), mask);
Russell King82668102009-05-17 16:20:18 +0100557 send_ipi_message(&mask, IPI_CPU_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
560/*
561 * not supported here
562 */
Russell King5048bcb2007-07-23 12:59:46 +0100563int setup_profiling_timer(unsigned int multiplier)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
565 return -EINVAL;
566}
Russell King4b0ef3b2005-06-28 13:49:16 +0100567
Russell King82668102009-05-17 16:20:18 +0100568static void
569on_each_cpu_mask(void (*func)(void *), void *info, int wait,
570 const struct cpumask *mask)
Russell King4b0ef3b2005-06-28 13:49:16 +0100571{
Russell King4b0ef3b2005-06-28 13:49:16 +0100572 preempt_disable();
573
Russell King82668102009-05-17 16:20:18 +0100574 smp_call_function_many(mask, func, info, wait);
575 if (cpumask_test_cpu(smp_processor_id(), mask))
Russell King4b0ef3b2005-06-28 13:49:16 +0100576 func(info);
577
578 preempt_enable();
Russell King4b0ef3b2005-06-28 13:49:16 +0100579}
580
581/**********************************************************************/
582
583/*
584 * TLB operations
585 */
586struct tlb_args {
587 struct vm_area_struct *ta_vma;
588 unsigned long ta_start;
589 unsigned long ta_end;
590};
591
592static inline void ipi_flush_tlb_all(void *ignored)
593{
594 local_flush_tlb_all();
595}
596
597static inline void ipi_flush_tlb_mm(void *arg)
598{
599 struct mm_struct *mm = (struct mm_struct *)arg;
600
601 local_flush_tlb_mm(mm);
602}
603
604static inline void ipi_flush_tlb_page(void *arg)
605{
606 struct tlb_args *ta = (struct tlb_args *)arg;
607
608 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
609}
610
611static inline void ipi_flush_tlb_kernel_page(void *arg)
612{
613 struct tlb_args *ta = (struct tlb_args *)arg;
614
615 local_flush_tlb_kernel_page(ta->ta_start);
616}
617
618static inline void ipi_flush_tlb_range(void *arg)
619{
620 struct tlb_args *ta = (struct tlb_args *)arg;
621
622 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
623}
624
625static inline void ipi_flush_tlb_kernel_range(void *arg)
626{
627 struct tlb_args *ta = (struct tlb_args *)arg;
628
629 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
630}
631
632void flush_tlb_all(void)
633{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100634 if (tlb_ops_need_broadcast())
635 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
636 else
637 local_flush_tlb_all();
Russell King4b0ef3b2005-06-28 13:49:16 +0100638}
639
640void flush_tlb_mm(struct mm_struct *mm)
641{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100642 if (tlb_ops_need_broadcast())
Rusty Russell56f8ba82009-09-24 09:34:49 -0600643 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100644 else
645 local_flush_tlb_mm(mm);
Russell King4b0ef3b2005-06-28 13:49:16 +0100646}
647
648void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
649{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100650 if (tlb_ops_need_broadcast()) {
651 struct tlb_args ta;
652 ta.ta_vma = vma;
653 ta.ta_start = uaddr;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600654 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100655 } else
656 local_flush_tlb_page(vma, uaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100657}
658
659void flush_tlb_kernel_page(unsigned long kaddr)
660{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100661 if (tlb_ops_need_broadcast()) {
662 struct tlb_args ta;
663 ta.ta_start = kaddr;
664 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
665 } else
666 local_flush_tlb_kernel_page(kaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100667}
668
669void flush_tlb_range(struct vm_area_struct *vma,
670 unsigned long start, unsigned long end)
671{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100672 if (tlb_ops_need_broadcast()) {
673 struct tlb_args ta;
674 ta.ta_vma = vma;
675 ta.ta_start = start;
676 ta.ta_end = end;
Rusty Russell56f8ba82009-09-24 09:34:49 -0600677 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm));
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100678 } else
679 local_flush_tlb_range(vma, start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100680}
681
682void flush_tlb_kernel_range(unsigned long start, unsigned long end)
683{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100684 if (tlb_ops_need_broadcast()) {
685 struct tlb_args ta;
686 ta.ta_start = start;
687 ta.ta_end = end;
688 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
689 } else
690 local_flush_tlb_kernel_range(start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100691}