]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | */ | |
c97d4869 | 10 | #include <linux/module.h> |
1da177e4 LT |
11 | #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> | |
4e950f6f | 20 | #include <linux/err.h> |
1da177e4 LT |
21 | #include <linux/cpu.h> |
22 | #include <linux/smp.h> | |
23 | #include <linux/seq_file.h> | |
c97d4869 | 24 | #include <linux/irq.h> |
bc28248e RK |
25 | #include <linux/percpu.h> |
26 | #include <linux/clockchips.h> | |
1da177e4 LT |
27 | |
28 | #include <asm/atomic.h> | |
29 | #include <asm/cacheflush.h> | |
30 | #include <asm/cpu.h> | |
42578c82 | 31 | #include <asm/cputype.h> |
e65f38ed RK |
32 | #include <asm/mmu_context.h> |
33 | #include <asm/pgtable.h> | |
34 | #include <asm/pgalloc.h> | |
1da177e4 | 35 | #include <asm/processor.h> |
37b05b63 | 36 | #include <asm/sections.h> |
1da177e4 LT |
37 | #include <asm/tlbflush.h> |
38 | #include <asm/ptrace.h> | |
bc28248e | 39 | #include <asm/localtimer.h> |
e616c591 | 40 | #include <asm/smp_plat.h> |
1da177e4 | 41 | |
e65f38ed RK |
42 | /* |
43 | * 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 | */ | |
47 | struct secondary_data secondary_data; | |
48 | ||
1da177e4 LT |
49 | /* |
50 | * structures for inter-processor calls | |
1da177e4 LT |
51 | */ |
52 | struct ipi_data { | |
1da177e4 | 53 | unsigned long ipi_count; |
1da177e4 LT |
54 | }; |
55 | ||
24480d98 | 56 | static DEFINE_PER_CPU(struct ipi_data, ipi_data); |
1da177e4 LT |
57 | |
58 | enum ipi_msg_type { | |
24480d98 | 59 | IPI_TIMER = 2, |
1da177e4 LT |
60 | IPI_RESCHEDULE, |
61 | IPI_CALL_FUNC, | |
f6dd9fa5 | 62 | IPI_CALL_FUNC_SINGLE, |
1da177e4 LT |
63 | IPI_CPU_STOP, |
64 | }; | |
65 | ||
37b05b63 RK |
66 | static 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 | ||
87 | static 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 | ||
bd6f68af | 102 | int __cpuinit __cpu_up(unsigned int cpu) |
1da177e4 | 103 | { |
71f512e8 RK |
104 | struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu); |
105 | struct task_struct *idle = ci->idle; | |
e65f38ed | 106 | pgd_t *pgd; |
1da177e4 LT |
107 | int ret; |
108 | ||
109 | /* | |
71f512e8 RK |
110 | * Spawn a new process manually, if not already done. |
111 | * Grab a pointer to its task struct so we can mess with it | |
1da177e4 | 112 | */ |
71f512e8 RK |
113 | 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; | |
13ea9cc8 SS |
120 | } 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); | |
1da177e4 LT |
126 | } |
127 | ||
e65f38ed RK |
128 | /* |
129 | * 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); | |
37b05b63 RK |
135 | 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 | } | |
e65f38ed RK |
145 | |
146 | /* | |
147 | * We need to tell the secondary core where to find | |
148 | * its stack and the page tables. | |
149 | */ | |
32d39a93 | 150 | secondary_data.stack = task_stack_page(idle) + THREAD_START_SP; |
e65f38ed | 151 | secondary_data.pgdir = virt_to_phys(pgd); |
1027247f RK |
152 | __cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data)); |
153 | outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1)); | |
e65f38ed | 154 | |
1da177e4 LT |
155 | /* |
156 | * Now bring the CPU into our world. | |
157 | */ | |
158 | ret = boot_secondary(cpu, idle); | |
e65f38ed RK |
159 | 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 | ||
5d43045b | 179 | secondary_data.stack = NULL; |
e65f38ed RK |
180 | secondary_data.pgdir = 0; |
181 | ||
37b05b63 RK |
182 | 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 | ||
5e541973 | 190 | pgd_free(&init_mm, pgd); |
e65f38ed | 191 | |
1da177e4 | 192 | if (ret) { |
0908db22 RK |
193 | printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu); |
194 | ||
1da177e4 LT |
195 | /* |
196 | * FIXME: We need to clean up the new idle thread. --rmk | |
197 | */ | |
198 | } | |
199 | ||
200 | return ret; | |
201 | } | |
202 | ||
a054a811 RK |
203 | #ifdef CONFIG_HOTPLUG_CPU |
204 | /* | |
205 | * __cpu_disable runs on the processor to be shutdown. | |
206 | */ | |
90140c30 | 207 | int __cpu_disable(void) |
a054a811 RK |
208 | { |
209 | unsigned int cpu = smp_processor_id(); | |
210 | struct task_struct *p; | |
211 | int ret; | |
212 | ||
8e2a43f5 | 213 | ret = platform_cpu_disable(cpu); |
a054a811 RK |
214 | 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 | */ | |
e03cdade | 221 | set_cpu_online(cpu, false); |
a054a811 RK |
222 | |
223 | /* | |
224 | * OK - migrate IRQs away from this CPU | |
225 | */ | |
226 | migrate_irqs(); | |
227 | ||
37ee16ae RK |
228 | /* |
229 | * Stop the local timer for this CPU. | |
230 | */ | |
ebac6546 | 231 | local_timer_stop(); |
37ee16ae | 232 | |
a054a811 RK |
233 | /* |
234 | * 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) | |
56f8ba83 | 243 | cpumask_clear_cpu(cpu, mm_cpumask(p->mm)); |
a054a811 RK |
244 | } |
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 | */ | |
90140c30 | 254 | void __cpu_die(unsigned int cpu) |
a054a811 RK |
255 | { |
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 | */ | |
90140c30 | 268 | void __ref cpu_die(void) |
a054a811 RK |
269 | { |
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 | : | |
32d39a93 | 289 | : "r" (task_stack_page(current) + THREAD_SIZE - 8)); |
a054a811 RK |
290 | } |
291 | #endif /* CONFIG_HOTPLUG_CPU */ | |
292 | ||
e65f38ed RK |
293 | /* |
294 | * This is the secondary CPU boot entry. We're using this CPUs | |
295 | * idle thread stack, but a set of temporary page tables. | |
296 | */ | |
bd6f68af | 297 | asmlinkage void __cpuinit secondary_start_kernel(void) |
e65f38ed RK |
298 | { |
299 | struct mm_struct *mm = &init_mm; | |
da2660d2 | 300 | unsigned int cpu = smp_processor_id(); |
e65f38ed RK |
301 | |
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; | |
56f8ba83 | 311 | cpumask_set_cpu(cpu, mm_cpumask(mm)); |
e65f38ed RK |
312 | cpu_switch_mm(mm->pgd, mm); |
313 | enter_lazy_tlb(mm, current); | |
505d7b19 | 314 | local_flush_tlb_all(); |
e65f38ed RK |
315 | |
316 | cpu_init(); | |
5bfb5d69 | 317 | preempt_disable(); |
e65f38ed RK |
318 | |
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 | */ | |
e545a614 | 327 | notify_cpu_starting(cpu); |
e65f38ed RK |
328 | local_irq_enable(); |
329 | local_fiq_enable(); | |
330 | ||
a8655e83 | 331 | /* |
bc28248e | 332 | * Setup the percpu timer for this CPU. |
a8655e83 | 333 | */ |
bc28248e | 334 | percpu_timer_setup(); |
a8655e83 | 335 | |
e65f38ed RK |
336 | calibrate_delay(); |
337 | ||
338 | smp_store_cpu_info(cpu); | |
339 | ||
340 | /* | |
341 | * OK, now it's safe to let the boot CPU continue | |
342 | */ | |
e03cdade | 343 | set_cpu_online(cpu, true); |
e65f38ed RK |
344 | |
345 | /* | |
346 | * OK, it's off to the idle thread for us | |
347 | */ | |
348 | cpu_idle(); | |
349 | } | |
350 | ||
1da177e4 LT |
351 | /* |
352 | * Called by both boot and secondaries to move global data into | |
353 | * per-processor storage. | |
354 | */ | |
bd6f68af | 355 | void __cpuinit smp_store_cpu_info(unsigned int cpuid) |
1da177e4 LT |
356 | { |
357 | struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid); | |
358 | ||
359 | cpu_info->loops_per_jiffy = loops_per_jiffy; | |
360 | } | |
361 | ||
362 | void __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 | ||
377 | void __init smp_prepare_boot_cpu(void) | |
378 | { | |
379 | unsigned int cpu = smp_processor_id(); | |
380 | ||
71f512e8 | 381 | per_cpu(cpu_data, cpu).idle = current; |
1da177e4 LT |
382 | } |
383 | ||
82668104 | 384 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
1da177e4 | 385 | { |
e3fbb087 | 386 | smp_cross_call(mask, IPI_CALL_FUNC); |
1da177e4 LT |
387 | } |
388 | ||
f6dd9fa5 | 389 | void arch_send_call_function_single_ipi(int cpu) |
3e459990 | 390 | { |
e3fbb087 | 391 | smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE); |
3e459990 | 392 | } |
3e459990 | 393 | |
1da177e4 LT |
394 | void show_ipi_list(struct seq_file *p) |
395 | { | |
396 | unsigned int cpu; | |
397 | ||
398 | seq_puts(p, "IPI:"); | |
399 | ||
e11b2236 | 400 | for_each_present_cpu(cpu) |
1da177e4 LT |
401 | seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count); |
402 | ||
403 | seq_putc(p, '\n'); | |
404 | } | |
405 | ||
37ee16ae RK |
406 | void show_local_irqs(struct seq_file *p) |
407 | { | |
408 | unsigned int cpu; | |
409 | ||
410 | seq_printf(p, "LOC: "); | |
411 | ||
412 | for_each_present_cpu(cpu) | |
413 | seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs); | |
414 | ||
415 | seq_putc(p, '\n'); | |
416 | } | |
417 | ||
bc28248e RK |
418 | /* |
419 | * Timer (local or broadcast) support | |
420 | */ | |
421 | static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent); | |
422 | ||
c97d4869 | 423 | static void ipi_timer(void) |
1da177e4 | 424 | { |
bc28248e | 425 | struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent); |
1da177e4 | 426 | irq_enter(); |
bc28248e | 427 | evt->event_handler(evt); |
1da177e4 LT |
428 | irq_exit(); |
429 | } | |
430 | ||
37ee16ae | 431 | #ifdef CONFIG_LOCAL_TIMERS |
b9811d7f | 432 | asmlinkage void __exception do_local_timer(struct pt_regs *regs) |
37ee16ae | 433 | { |
c97d4869 | 434 | struct pt_regs *old_regs = set_irq_regs(regs); |
37ee16ae RK |
435 | int cpu = smp_processor_id(); |
436 | ||
437 | if (local_timer_ack()) { | |
438 | irq_stat[cpu].local_timer_irqs++; | |
c97d4869 | 439 | ipi_timer(); |
37ee16ae | 440 | } |
c97d4869 RK |
441 | |
442 | set_irq_regs(old_regs); | |
37ee16ae RK |
443 | } |
444 | #endif | |
445 | ||
bc28248e RK |
446 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
447 | static void smp_timer_broadcast(const struct cpumask *mask) | |
448 | { | |
e3fbb087 | 449 | smp_cross_call(mask, IPI_TIMER); |
bc28248e | 450 | } |
5388a6b2 RK |
451 | #else |
452 | #define smp_timer_broadcast NULL | |
453 | #endif | |
bc28248e | 454 | |
5388a6b2 | 455 | #ifndef CONFIG_LOCAL_TIMERS |
bc28248e RK |
456 | static void broadcast_timer_set_mode(enum clock_event_mode mode, |
457 | struct clock_event_device *evt) | |
458 | { | |
459 | } | |
460 | ||
461 | static 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; | |
bc28248e RK |
470 | |
471 | clockevents_register_device(evt); | |
472 | } | |
473 | #endif | |
474 | ||
475 | void __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); | |
5388a6b2 | 481 | evt->broadcast = smp_timer_broadcast; |
bc28248e RK |
482 | |
483 | local_timer_setup(evt); | |
484 | } | |
485 | ||
1da177e4 LT |
486 | static DEFINE_SPINLOCK(stop_lock); |
487 | ||
488 | /* | |
489 | * ipi_cpu_stop - handle IPI from smp_send_stop() | |
490 | */ | |
491 | static void ipi_cpu_stop(unsigned int cpu) | |
492 | { | |
3d3f78d7 RK |
493 | 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 | } | |
1da177e4 | 500 | |
e03cdade | 501 | set_cpu_online(cpu, false); |
1da177e4 LT |
502 | |
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 | |
1da177e4 | 512 | */ |
ad3b6993 | 513 | asmlinkage void __exception do_IPI(int ipinr, struct pt_regs *regs) |
1da177e4 LT |
514 | { |
515 | unsigned int cpu = smp_processor_id(); | |
516 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); | |
c97d4869 | 517 | struct pt_regs *old_regs = set_irq_regs(regs); |
1da177e4 LT |
518 | |
519 | ipi->ipi_count++; | |
520 | ||
24480d98 RK |
521 | switch (ipinr) { |
522 | case IPI_TIMER: | |
523 | ipi_timer(); | |
524 | break; | |
1da177e4 | 525 | |
24480d98 RK |
526 | case IPI_RESCHEDULE: |
527 | /* | |
528 | * nothing more to do - eveything is | |
529 | * done on the interrupt return path | |
530 | */ | |
531 | break; | |
1da177e4 | 532 | |
24480d98 RK |
533 | case IPI_CALL_FUNC: |
534 | generic_smp_call_function_interrupt(); | |
535 | break; | |
f6dd9fa5 | 536 | |
24480d98 RK |
537 | case IPI_CALL_FUNC_SINGLE: |
538 | generic_smp_call_function_single_interrupt(); | |
539 | break; | |
1da177e4 | 540 | |
24480d98 RK |
541 | case IPI_CPU_STOP: |
542 | ipi_cpu_stop(cpu); | |
543 | break; | |
1da177e4 | 544 | |
24480d98 RK |
545 | default: |
546 | printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n", | |
547 | cpu, ipinr); | |
548 | break; | |
1da177e4 | 549 | } |
c97d4869 | 550 | set_irq_regs(old_regs); |
1da177e4 LT |
551 | } |
552 | ||
553 | void smp_send_reschedule(int cpu) | |
554 | { | |
e3fbb087 | 555 | smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE); |
1da177e4 LT |
556 | } |
557 | ||
1da177e4 LT |
558 | void smp_send_stop(void) |
559 | { | |
560 | cpumask_t mask = cpu_online_map; | |
561 | cpu_clear(smp_processor_id(), mask); | |
f9e417e9 | 562 | if (!cpus_empty(mask)) |
e3fbb087 | 563 | smp_cross_call(&mask, IPI_CPU_STOP); |
1da177e4 LT |
564 | } |
565 | ||
566 | /* | |
567 | * not supported here | |
568 | */ | |
5048bcba | 569 | int setup_profiling_timer(unsigned int multiplier) |
1da177e4 LT |
570 | { |
571 | return -EINVAL; | |
572 | } | |
4b0ef3b1 | 573 | |
82668104 RK |
574 | static void |
575 | on_each_cpu_mask(void (*func)(void *), void *info, int wait, | |
576 | const struct cpumask *mask) | |
4b0ef3b1 | 577 | { |
4b0ef3b1 RK |
578 | preempt_disable(); |
579 | ||
82668104 RK |
580 | smp_call_function_many(mask, func, info, wait); |
581 | if (cpumask_test_cpu(smp_processor_id(), mask)) | |
4b0ef3b1 RK |
582 | func(info); |
583 | ||
584 | preempt_enable(); | |
4b0ef3b1 RK |
585 | } |
586 | ||
587 | /**********************************************************************/ | |
588 | ||
589 | /* | |
590 | * TLB operations | |
591 | */ | |
592 | struct tlb_args { | |
593 | struct vm_area_struct *ta_vma; | |
594 | unsigned long ta_start; | |
595 | unsigned long ta_end; | |
596 | }; | |
597 | ||
598 | static inline void ipi_flush_tlb_all(void *ignored) | |
599 | { | |
600 | local_flush_tlb_all(); | |
601 | } | |
602 | ||
603 | static 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 | ||
610 | static 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 | ||
617 | static 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 | ||
624 | static 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 | ||
631 | static 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 | ||
638 | void flush_tlb_all(void) | |
639 | { | |
faa7bc51 CM |
640 | if (tlb_ops_need_broadcast()) |
641 | on_each_cpu(ipi_flush_tlb_all, NULL, 1); | |
642 | else | |
643 | local_flush_tlb_all(); | |
4b0ef3b1 RK |
644 | } |
645 | ||
646 | void flush_tlb_mm(struct mm_struct *mm) | |
647 | { | |
faa7bc51 | 648 | if (tlb_ops_need_broadcast()) |
56f8ba83 | 649 | on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm)); |
faa7bc51 CM |
650 | else |
651 | local_flush_tlb_mm(mm); | |
4b0ef3b1 RK |
652 | } |
653 | ||
654 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) | |
655 | { | |
faa7bc51 CM |
656 | if (tlb_ops_need_broadcast()) { |
657 | struct tlb_args ta; | |
658 | ta.ta_vma = vma; | |
659 | ta.ta_start = uaddr; | |
56f8ba83 | 660 | on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm)); |
faa7bc51 CM |
661 | } else |
662 | local_flush_tlb_page(vma, uaddr); | |
4b0ef3b1 RK |
663 | } |
664 | ||
665 | void flush_tlb_kernel_page(unsigned long kaddr) | |
666 | { | |
faa7bc51 CM |
667 | 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); | |
4b0ef3b1 RK |
673 | } |
674 | ||
675 | void flush_tlb_range(struct vm_area_struct *vma, | |
676 | unsigned long start, unsigned long end) | |
677 | { | |
faa7bc51 CM |
678 | 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; | |
56f8ba83 | 683 | on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm)); |
faa7bc51 CM |
684 | } else |
685 | local_flush_tlb_range(vma, start, end); | |
4b0ef3b1 RK |
686 | } |
687 | ||
688 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) | |
689 | { | |
faa7bc51 CM |
690 | 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); | |
4b0ef3b1 | 697 | } |