blob: de885fd256c519b220e6d48d86996e1f7027cd5d [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/*
Russell Kinge65f38e2005-06-18 09:33:31 +010041 * as from 2.5, kernels no longer have an init_tasks structure
42 * so we need some other way of telling a new secondary core
43 * where to place its SVC stack
44 */
45struct secondary_data secondary_data;
46
47/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 * structures for inter-processor calls
49 * - A collection of single bit ipi messages.
50 */
51struct ipi_data {
52 spinlock_t lock;
53 unsigned long ipi_count;
54 unsigned long bits;
55};
56
57static DEFINE_PER_CPU(struct ipi_data, ipi_data) = {
58 .lock = SPIN_LOCK_UNLOCKED,
59};
60
61enum ipi_msg_type {
62 IPI_TIMER,
63 IPI_RESCHEDULE,
64 IPI_CALL_FUNC,
Jens Axboef6dd9fa2008-06-10 20:48:30 +020065 IPI_CALL_FUNC_SINGLE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 IPI_CPU_STOP,
67};
68
Russell Kingbd6f68a2005-07-17 21:35:41 +010069int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Russell King71f512e82005-11-02 21:51:40 +000071 struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
72 struct task_struct *idle = ci->idle;
Russell Kinge65f38e2005-06-18 09:33:31 +010073 pgd_t *pgd;
74 pmd_t *pmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 int ret;
76
77 /*
Russell King71f512e82005-11-02 21:51:40 +000078 * Spawn a new process manually, if not already done.
79 * Grab a pointer to its task struct so we can mess with it
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
Russell King71f512e82005-11-02 21:51:40 +000081 if (!idle) {
82 idle = fork_idle(cpu);
83 if (IS_ERR(idle)) {
84 printk(KERN_ERR "CPU%u: fork() failed\n", cpu);
85 return PTR_ERR(idle);
86 }
87 ci->idle = idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
90 /*
Russell Kinge65f38e2005-06-18 09:33:31 +010091 * Allocate initial page tables to allow the new CPU to
92 * enable the MMU safely. This essentially means a set
93 * of our "standard" page tables, with the addition of
94 * a 1:1 mapping for the physical address of the kernel.
95 */
96 pgd = pgd_alloc(&init_mm);
Russell King058ddee2008-08-07 22:36:59 +010097 pmd = pmd_offset(pgd + pgd_index(PHYS_OFFSET), PHYS_OFFSET);
Russell Kinge65f38e2005-06-18 09:33:31 +010098 *pmd = __pmd((PHYS_OFFSET & PGDIR_MASK) |
99 PMD_TYPE_SECT | PMD_SECT_AP_WRITE);
Catalin Marinase9fc7822009-02-11 13:14:57 +0100100 flush_pmd_entry(pmd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100101
102 /*
103 * We need to tell the secondary core where to find
104 * its stack and the page tables.
105 */
Al Viro32d39a92006-01-12 01:05:58 -0800106 secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
Russell Kinge65f38e2005-06-18 09:33:31 +0100107 secondary_data.pgdir = virt_to_phys(pgd);
108 wmb();
109
110 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 * Now bring the CPU into our world.
112 */
113 ret = boot_secondary(cpu, idle);
Russell Kinge65f38e2005-06-18 09:33:31 +0100114 if (ret == 0) {
115 unsigned long timeout;
116
117 /*
118 * CPU was successfully started, wait for it
119 * to come online or time out.
120 */
121 timeout = jiffies + HZ;
122 while (time_before(jiffies, timeout)) {
123 if (cpu_online(cpu))
124 break;
125
126 udelay(10);
127 barrier();
128 }
129
130 if (!cpu_online(cpu))
131 ret = -EIO;
132 }
133
Russell King5d430452005-11-08 10:44:46 +0000134 secondary_data.stack = NULL;
Russell Kinge65f38e2005-06-18 09:33:31 +0100135 secondary_data.pgdir = 0;
136
Russell King058ddee2008-08-07 22:36:59 +0100137 *pmd = __pmd(0);
Catalin Marinase9fc7822009-02-11 13:14:57 +0100138 clean_pmd_entry(pmd);
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800139 pgd_free(&init_mm, pgd);
Russell Kinge65f38e2005-06-18 09:33:31 +0100140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (ret) {
Russell King0908db22005-06-19 19:48:16 +0100142 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /*
145 * FIXME: We need to clean up the new idle thread. --rmk
146 */
147 }
148
149 return ret;
150}
151
Russell Kinga054a812005-11-02 22:24:33 +0000152#ifdef CONFIG_HOTPLUG_CPU
153/*
154 * __cpu_disable runs on the processor to be shutdown.
155 */
156int __cpuexit __cpu_disable(void)
157{
158 unsigned int cpu = smp_processor_id();
159 struct task_struct *p;
160 int ret;
161
162 ret = mach_cpu_disable(cpu);
163 if (ret)
164 return ret;
165
166 /*
167 * Take this CPU offline. Once we clear this, we can't return,
168 * and we must not schedule until we're ready to give up the cpu.
169 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100170 set_cpu_online(cpu, false);
Russell Kinga054a812005-11-02 22:24:33 +0000171
172 /*
173 * OK - migrate IRQs away from this CPU
174 */
175 migrate_irqs();
176
177 /*
Russell King37ee16a2005-11-08 19:08:05 +0000178 * Stop the local timer for this CPU.
179 */
Catalin Marinasebac6542008-12-01 14:54:57 +0000180 local_timer_stop();
Russell King37ee16a2005-11-08 19:08:05 +0000181
182 /*
Russell Kinga054a812005-11-02 22:24:33 +0000183 * Flush user cache and TLB mappings, and then remove this CPU
184 * from the vm mask set of all processes.
185 */
186 flush_cache_all();
187 local_flush_tlb_all();
188
189 read_lock(&tasklist_lock);
190 for_each_process(p) {
191 if (p->mm)
192 cpu_clear(cpu, p->mm->cpu_vm_mask);
193 }
194 read_unlock(&tasklist_lock);
195
196 return 0;
197}
198
199/*
200 * called on the thread which is asking for a CPU to be shutdown -
201 * waits until shutdown has completed, or it is timed out.
202 */
203void __cpuexit __cpu_die(unsigned int cpu)
204{
205 if (!platform_cpu_kill(cpu))
206 printk("CPU%u: unable to kill\n", cpu);
207}
208
209/*
210 * Called from the idle thread for the CPU which has been shutdown.
211 *
212 * Note that we disable IRQs here, but do not re-enable them
213 * before returning to the caller. This is also the behaviour
214 * of the other hotplug-cpu capable cores, so presumably coming
215 * out of idle fixes this.
216 */
217void __cpuexit cpu_die(void)
218{
219 unsigned int cpu = smp_processor_id();
220
221 local_irq_disable();
222 idle_task_exit();
223
224 /*
225 * actual CPU shutdown procedure is at least platform (if not
226 * CPU) specific
227 */
228 platform_cpu_die(cpu);
229
230 /*
231 * Do not return to the idle loop - jump back to the secondary
232 * cpu initialisation. There's some initialisation which needs
233 * to be repeated to undo the effects of taking the CPU offline.
234 */
235 __asm__("mov sp, %0\n"
236 " b secondary_start_kernel"
237 :
Al Viro32d39a92006-01-12 01:05:58 -0800238 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
Russell Kinga054a812005-11-02 22:24:33 +0000239}
240#endif /* CONFIG_HOTPLUG_CPU */
241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242/*
Russell Kinge65f38e2005-06-18 09:33:31 +0100243 * This is the secondary CPU boot entry. We're using this CPUs
244 * idle thread stack, but a set of temporary page tables.
245 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100246asmlinkage void __cpuinit secondary_start_kernel(void)
Russell Kinge65f38e2005-06-18 09:33:31 +0100247{
248 struct mm_struct *mm = &init_mm;
Russell Kingda2660d2005-11-12 17:21:47 +0000249 unsigned int cpu = smp_processor_id();
Russell Kinge65f38e2005-06-18 09:33:31 +0100250
251 printk("CPU%u: Booted secondary processor\n", cpu);
252
253 /*
254 * All kernel threads share the same mm context; grab a
255 * reference and switch to it.
256 */
257 atomic_inc(&mm->mm_users);
258 atomic_inc(&mm->mm_count);
259 current->active_mm = mm;
260 cpu_set(cpu, mm->cpu_vm_mask);
261 cpu_switch_mm(mm->pgd, mm);
262 enter_lazy_tlb(mm, current);
Russell King505d7b12005-07-28 20:32:47 +0100263 local_flush_tlb_all();
Russell Kinge65f38e2005-06-18 09:33:31 +0100264
265 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800266 preempt_disable();
Russell Kinge65f38e2005-06-18 09:33:31 +0100267
268 /*
269 * Give the platform a chance to do its own initialisation.
270 */
271 platform_secondary_init(cpu);
272
273 /*
274 * Enable local interrupts.
275 */
Manfred Spraule545a612008-09-07 16:57:22 +0200276 notify_cpu_starting(cpu);
Russell Kinge65f38e2005-06-18 09:33:31 +0100277 local_irq_enable();
278 local_fiq_enable();
279
Catalin Marinasa8655e82008-02-04 17:30:57 +0100280 /*
Russell Kingbc282482009-05-17 18:58:34 +0100281 * Setup the percpu timer for this CPU.
Catalin Marinasa8655e82008-02-04 17:30:57 +0100282 */
Russell Kingbc282482009-05-17 18:58:34 +0100283 percpu_timer_setup();
Catalin Marinasa8655e82008-02-04 17:30:57 +0100284
Russell Kinge65f38e2005-06-18 09:33:31 +0100285 calibrate_delay();
286
287 smp_store_cpu_info(cpu);
288
289 /*
290 * OK, now it's safe to let the boot CPU continue
291 */
Russell Kinge03cdad2009-05-28 14:16:52 +0100292 set_cpu_online(cpu, true);
Russell Kinge65f38e2005-06-18 09:33:31 +0100293
294 /*
295 * OK, it's off to the idle thread for us
296 */
297 cpu_idle();
298}
299
300/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 * Called by both boot and secondaries to move global data into
302 * per-processor storage.
303 */
Russell Kingbd6f68a2005-07-17 21:35:41 +0100304void __cpuinit smp_store_cpu_info(unsigned int cpuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
306 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
307
308 cpu_info->loops_per_jiffy = loops_per_jiffy;
309}
310
311void __init smp_cpus_done(unsigned int max_cpus)
312{
313 int cpu;
314 unsigned long bogosum = 0;
315
316 for_each_online_cpu(cpu)
317 bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
318
319 printk(KERN_INFO "SMP: Total of %d processors activated "
320 "(%lu.%02lu BogoMIPS).\n",
321 num_online_cpus(),
322 bogosum / (500000/HZ),
323 (bogosum / (5000/HZ)) % 100);
324}
325
326void __init smp_prepare_boot_cpu(void)
327{
328 unsigned int cpu = smp_processor_id();
329
Russell King71f512e82005-11-02 21:51:40 +0000330 per_cpu(cpu_data, cpu).idle = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
Russell King82668102009-05-17 16:20:18 +0100333static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 unsigned long flags;
336 unsigned int cpu;
337
338 local_irq_save(flags);
339
Russell King82668102009-05-17 16:20:18 +0100340 for_each_cpu(cpu, mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
342
343 spin_lock(&ipi->lock);
344 ipi->bits |= 1 << msg;
345 spin_unlock(&ipi->lock);
346 }
347
348 /*
349 * Call the platform specific cross-CPU call function.
350 */
Russell King82668102009-05-17 16:20:18 +0100351 smp_cross_call(mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 local_irq_restore(flags);
354}
355
Russell King82668102009-05-17 16:20:18 +0100356void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200358 send_ipi_message(mask, IPI_CALL_FUNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200361void arch_send_call_function_single_ipi(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Russell King82668102009-05-17 16:20:18 +0100363 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
Catalin Marinas3e459992008-02-04 17:28:56 +0100365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366void show_ipi_list(struct seq_file *p)
367{
368 unsigned int cpu;
369
370 seq_puts(p, "IPI:");
371
Russell Kinge11b2232005-07-11 19:26:31 +0100372 for_each_present_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
374
375 seq_putc(p, '\n');
376}
377
Russell King37ee16a2005-11-08 19:08:05 +0000378void show_local_irqs(struct seq_file *p)
379{
380 unsigned int cpu;
381
382 seq_printf(p, "LOC: ");
383
384 for_each_present_cpu(cpu)
385 seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs);
386
387 seq_putc(p, '\n');
388}
389
Russell Kingbc282482009-05-17 18:58:34 +0100390/*
391 * Timer (local or broadcast) support
392 */
393static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
394
Russell Kingc97d4862006-10-25 13:59:16 +0100395static void ipi_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Russell Kingbc282482009-05-17 18:58:34 +0100397 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 irq_enter();
Russell Kingbc282482009-05-17 18:58:34 +0100399 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 irq_exit();
401}
402
Russell King37ee16a2005-11-08 19:08:05 +0000403#ifdef CONFIG_LOCAL_TIMERS
Russell Kingb9811d72007-05-08 11:31:07 +0100404asmlinkage void __exception do_local_timer(struct pt_regs *regs)
Russell King37ee16a2005-11-08 19:08:05 +0000405{
Russell Kingc97d4862006-10-25 13:59:16 +0100406 struct pt_regs *old_regs = set_irq_regs(regs);
Russell King37ee16a2005-11-08 19:08:05 +0000407 int cpu = smp_processor_id();
408
409 if (local_timer_ack()) {
410 irq_stat[cpu].local_timer_irqs++;
Russell Kingc97d4862006-10-25 13:59:16 +0100411 ipi_timer();
Russell King37ee16a2005-11-08 19:08:05 +0000412 }
Russell Kingc97d4862006-10-25 13:59:16 +0100413
414 set_irq_regs(old_regs);
Russell King37ee16a2005-11-08 19:08:05 +0000415}
416#endif
417
Russell Kingbc282482009-05-17 18:58:34 +0100418#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
419static void smp_timer_broadcast(const struct cpumask *mask)
420{
421 send_ipi_message(mask, IPI_TIMER);
422}
423
424static void broadcast_timer_set_mode(enum clock_event_mode mode,
425 struct clock_event_device *evt)
426{
427}
428
429static void local_timer_setup(struct clock_event_device *evt)
430{
431 evt->name = "dummy_timer";
432 evt->features = CLOCK_EVT_FEAT_ONESHOT |
433 CLOCK_EVT_FEAT_PERIODIC |
434 CLOCK_EVT_FEAT_DUMMY;
435 evt->rating = 400;
436 evt->mult = 1;
437 evt->set_mode = broadcast_timer_set_mode;
438 evt->broadcast = smp_timer_broadcast;
439
440 clockevents_register_device(evt);
441}
442#endif
443
444void __cpuinit percpu_timer_setup(void)
445{
446 unsigned int cpu = smp_processor_id();
447 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
448
449 evt->cpumask = cpumask_of(cpu);
450
451 local_timer_setup(evt);
452}
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454static DEFINE_SPINLOCK(stop_lock);
455
456/*
457 * ipi_cpu_stop - handle IPI from smp_send_stop()
458 */
459static void ipi_cpu_stop(unsigned int cpu)
460{
461 spin_lock(&stop_lock);
462 printk(KERN_CRIT "CPU%u: stopping\n", cpu);
463 dump_stack();
464 spin_unlock(&stop_lock);
465
Russell Kinge03cdad2009-05-28 14:16:52 +0100466 set_cpu_online(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 local_fiq_disable();
469 local_irq_disable();
470
471 while (1)
472 cpu_relax();
473}
474
475/*
476 * Main handler for inter-processor interrupts
477 *
478 * For ARM, the ipimask now only identifies a single
479 * category of IPI (Bit 1 IPIs have been replaced by a
480 * different mechanism):
481 *
482 * Bit 0 - Inter-processor function call
483 */
Russell Kingb9811d72007-05-08 11:31:07 +0100484asmlinkage void __exception do_IPI(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
486 unsigned int cpu = smp_processor_id();
487 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
Russell Kingc97d4862006-10-25 13:59:16 +0100488 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 ipi->ipi_count++;
491
492 for (;;) {
493 unsigned long msgs;
494
495 spin_lock(&ipi->lock);
496 msgs = ipi->bits;
497 ipi->bits = 0;
498 spin_unlock(&ipi->lock);
499
500 if (!msgs)
501 break;
502
503 do {
504 unsigned nextmsg;
505
506 nextmsg = msgs & -msgs;
507 msgs &= ~nextmsg;
508 nextmsg = ffz(~nextmsg);
509
510 switch (nextmsg) {
511 case IPI_TIMER:
Russell Kingc97d4862006-10-25 13:59:16 +0100512 ipi_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514
515 case IPI_RESCHEDULE:
516 /*
517 * nothing more to do - eveything is
518 * done on the interrupt return path
519 */
520 break;
521
522 case IPI_CALL_FUNC:
Jens Axboef6dd9fa2008-06-10 20:48:30 +0200523 generic_smp_call_function_interrupt();
524 break;
525
526 case IPI_CALL_FUNC_SINGLE:
527 generic_smp_call_function_single_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529
530 case IPI_CPU_STOP:
531 ipi_cpu_stop(cpu);
532 break;
533
534 default:
535 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
536 cpu, nextmsg);
537 break;
538 }
539 } while (msgs);
540 }
Russell Kingc97d4862006-10-25 13:59:16 +0100541
542 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545void smp_send_reschedule(int cpu)
546{
Russell King82668102009-05-17 16:20:18 +0100547 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550void smp_send_stop(void)
551{
552 cpumask_t mask = cpu_online_map;
553 cpu_clear(smp_processor_id(), mask);
Russell King82668102009-05-17 16:20:18 +0100554 send_ipi_message(&mask, IPI_CPU_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557/*
558 * not supported here
559 */
Russell King5048bcb2007-07-23 12:59:46 +0100560int setup_profiling_timer(unsigned int multiplier)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 return -EINVAL;
563}
Russell King4b0ef3b2005-06-28 13:49:16 +0100564
Russell King82668102009-05-17 16:20:18 +0100565static void
566on_each_cpu_mask(void (*func)(void *), void *info, int wait,
567 const struct cpumask *mask)
Russell King4b0ef3b2005-06-28 13:49:16 +0100568{
Russell King4b0ef3b2005-06-28 13:49:16 +0100569 preempt_disable();
570
Russell King82668102009-05-17 16:20:18 +0100571 smp_call_function_many(mask, func, info, wait);
572 if (cpumask_test_cpu(smp_processor_id(), mask))
Russell King4b0ef3b2005-06-28 13:49:16 +0100573 func(info);
574
575 preempt_enable();
Russell King4b0ef3b2005-06-28 13:49:16 +0100576}
577
578/**********************************************************************/
579
580/*
581 * TLB operations
582 */
583struct tlb_args {
584 struct vm_area_struct *ta_vma;
585 unsigned long ta_start;
586 unsigned long ta_end;
587};
588
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100589/* all SMP configurations have the extended CPUID registers */
590static inline int tlb_ops_need_broadcast(void)
591{
592 return ((read_cpuid_ext(CPUID_EXT_MMFR3) >> 12) & 0xf) < 2;
593}
594
Russell King4b0ef3b2005-06-28 13:49:16 +0100595static inline void ipi_flush_tlb_all(void *ignored)
596{
597 local_flush_tlb_all();
598}
599
600static inline void ipi_flush_tlb_mm(void *arg)
601{
602 struct mm_struct *mm = (struct mm_struct *)arg;
603
604 local_flush_tlb_mm(mm);
605}
606
607static inline void ipi_flush_tlb_page(void *arg)
608{
609 struct tlb_args *ta = (struct tlb_args *)arg;
610
611 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
612}
613
614static inline void ipi_flush_tlb_kernel_page(void *arg)
615{
616 struct tlb_args *ta = (struct tlb_args *)arg;
617
618 local_flush_tlb_kernel_page(ta->ta_start);
619}
620
621static inline void ipi_flush_tlb_range(void *arg)
622{
623 struct tlb_args *ta = (struct tlb_args *)arg;
624
625 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
626}
627
628static inline void ipi_flush_tlb_kernel_range(void *arg)
629{
630 struct tlb_args *ta = (struct tlb_args *)arg;
631
632 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
633}
634
635void flush_tlb_all(void)
636{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100637 if (tlb_ops_need_broadcast())
638 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
639 else
640 local_flush_tlb_all();
Russell King4b0ef3b2005-06-28 13:49:16 +0100641}
642
643void flush_tlb_mm(struct mm_struct *mm)
644{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100645 if (tlb_ops_need_broadcast())
646 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, &mm->cpu_vm_mask);
647 else
648 local_flush_tlb_mm(mm);
Russell King4b0ef3b2005-06-28 13:49:16 +0100649}
650
651void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
652{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100653 if (tlb_ops_need_broadcast()) {
654 struct tlb_args ta;
655 ta.ta_vma = vma;
656 ta.ta_start = uaddr;
657 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, &vma->vm_mm->cpu_vm_mask);
658 } else
659 local_flush_tlb_page(vma, uaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100660}
661
662void flush_tlb_kernel_page(unsigned long kaddr)
663{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100664 if (tlb_ops_need_broadcast()) {
665 struct tlb_args ta;
666 ta.ta_start = kaddr;
667 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
668 } else
669 local_flush_tlb_kernel_page(kaddr);
Russell King4b0ef3b2005-06-28 13:49:16 +0100670}
671
672void flush_tlb_range(struct vm_area_struct *vma,
673 unsigned long start, unsigned long end)
674{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100675 if (tlb_ops_need_broadcast()) {
676 struct tlb_args ta;
677 ta.ta_vma = vma;
678 ta.ta_start = start;
679 ta.ta_end = end;
680 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, &vma->vm_mm->cpu_vm_mask);
681 } else
682 local_flush_tlb_range(vma, start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100683}
684
685void flush_tlb_kernel_range(unsigned long start, unsigned long end)
686{
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100687 if (tlb_ops_need_broadcast()) {
688 struct tlb_args ta;
689 ta.ta_start = start;
690 ta.ta_end = end;
691 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
692 } else
693 local_flush_tlb_kernel_range(start, end);
Russell King4b0ef3b2005-06-28 13:49:16 +0100694}