Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 10 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 20 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/cpu.h> |
| 22 | #include <linux/smp.h> |
| 23 | #include <linux/seq_file.h> |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 24 | #include <linux/irq.h> |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 25 | #include <linux/percpu.h> |
| 26 | #include <linux/clockchips.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include <asm/atomic.h> |
| 29 | #include <asm/cacheflush.h> |
| 30 | #include <asm/cpu.h> |
Russell King | 42578c8 | 2009-06-11 15:35:00 +0100 | [diff] [blame] | 31 | #include <asm/cputype.h> |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 32 | #include <asm/mmu_context.h> |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/processor.h> |
| 36 | #include <asm/tlbflush.h> |
| 37 | #include <asm/ptrace.h> |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 38 | #include <asm/localtimer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 41 | * 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 | */ |
| 45 | struct secondary_data secondary_data; |
| 46 | |
| 47 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | * structures for inter-processor calls |
| 49 | * - A collection of single bit ipi messages. |
| 50 | */ |
| 51 | struct ipi_data { |
| 52 | spinlock_t lock; |
| 53 | unsigned long ipi_count; |
| 54 | unsigned long bits; |
| 55 | }; |
| 56 | |
| 57 | static DEFINE_PER_CPU(struct ipi_data, ipi_data) = { |
| 58 | .lock = SPIN_LOCK_UNLOCKED, |
| 59 | }; |
| 60 | |
| 61 | enum ipi_msg_type { |
| 62 | IPI_TIMER, |
| 63 | IPI_RESCHEDULE, |
| 64 | IPI_CALL_FUNC, |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 65 | IPI_CALL_FUNC_SINGLE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | IPI_CPU_STOP, |
| 67 | }; |
| 68 | |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 69 | int __cpuinit __cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 71 | struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu); |
| 72 | struct task_struct *idle = ci->idle; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 73 | pgd_t *pgd; |
| 74 | pmd_t *pmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | int ret; |
| 76 | |
| 77 | /* |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 78 | * Spawn a new process manually, if not already done. |
| 79 | * Grab a pointer to its task struct so we can mess with it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | */ |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 81 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 91 | * 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 King | 058ddee | 2008-08-07 22:36:59 +0100 | [diff] [blame] | 97 | pmd = pmd_offset(pgd + pgd_index(PHYS_OFFSET), PHYS_OFFSET); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 98 | *pmd = __pmd((PHYS_OFFSET & PGDIR_MASK) | |
| 99 | PMD_TYPE_SECT | PMD_SECT_AP_WRITE); |
Catalin Marinas | e9fc782 | 2009-02-11 13:14:57 +0100 | [diff] [blame] | 100 | flush_pmd_entry(pmd); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * We need to tell the secondary core where to find |
| 104 | * its stack and the page tables. |
| 105 | */ |
Al Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 106 | secondary_data.stack = task_stack_page(idle) + THREAD_START_SP; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 107 | secondary_data.pgdir = virt_to_phys(pgd); |
| 108 | wmb(); |
| 109 | |
| 110 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * Now bring the CPU into our world. |
| 112 | */ |
| 113 | ret = boot_secondary(cpu, idle); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 114 | 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 King | 5d43045 | 2005-11-08 10:44:46 +0000 | [diff] [blame] | 134 | secondary_data.stack = NULL; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 135 | secondary_data.pgdir = 0; |
| 136 | |
Russell King | 058ddee | 2008-08-07 22:36:59 +0100 | [diff] [blame] | 137 | *pmd = __pmd(0); |
Catalin Marinas | e9fc782 | 2009-02-11 13:14:57 +0100 | [diff] [blame] | 138 | clean_pmd_entry(pmd); |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 139 | pgd_free(&init_mm, pgd); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (ret) { |
Russell King | 0908db2 | 2005-06-19 19:48:16 +0100 | [diff] [blame] | 142 | printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu); |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* |
| 145 | * FIXME: We need to clean up the new idle thread. --rmk |
| 146 | */ |
| 147 | } |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 152 | #ifdef CONFIG_HOTPLUG_CPU |
| 153 | /* |
| 154 | * __cpu_disable runs on the processor to be shutdown. |
| 155 | */ |
| 156 | int __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 King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 170 | set_cpu_online(cpu, false); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * OK - migrate IRQs away from this CPU |
| 174 | */ |
| 175 | migrate_irqs(); |
| 176 | |
| 177 | /* |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 178 | * Stop the local timer for this CPU. |
| 179 | */ |
Catalin Marinas | ebac654 | 2008-12-01 14:54:57 +0000 | [diff] [blame] | 180 | local_timer_stop(); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 181 | |
| 182 | /* |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 183 | * 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 | */ |
| 203 | void __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 | */ |
| 217 | void __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 Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 238 | : "r" (task_stack_page(current) + THREAD_SIZE - 8)); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 239 | } |
| 240 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 243 | * 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 King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 246 | asmlinkage void __cpuinit secondary_start_kernel(void) |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 247 | { |
| 248 | struct mm_struct *mm = &init_mm; |
Russell King | da2660d | 2005-11-12 17:21:47 +0000 | [diff] [blame] | 249 | unsigned int cpu = smp_processor_id(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 250 | |
| 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 King | 505d7b1 | 2005-07-28 20:32:47 +0100 | [diff] [blame] | 263 | local_flush_tlb_all(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 264 | |
| 265 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 266 | preempt_disable(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 267 | |
| 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 Spraul | e545a61 | 2008-09-07 16:57:22 +0200 | [diff] [blame] | 276 | notify_cpu_starting(cpu); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 277 | local_irq_enable(); |
| 278 | local_fiq_enable(); |
| 279 | |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 280 | /* |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 281 | * Setup the percpu timer for this CPU. |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 282 | */ |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 283 | percpu_timer_setup(); |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 284 | |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 285 | 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 King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 292 | set_cpu_online(cpu, true); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * OK, it's off to the idle thread for us |
| 296 | */ |
| 297 | cpu_idle(); |
| 298 | } |
| 299 | |
| 300 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | * Called by both boot and secondaries to move global data into |
| 302 | * per-processor storage. |
| 303 | */ |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 304 | void __cpuinit smp_store_cpu_info(unsigned int cpuid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid); |
| 307 | |
| 308 | cpu_info->loops_per_jiffy = loops_per_jiffy; |
| 309 | } |
| 310 | |
| 311 | void __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 | |
| 326 | void __init smp_prepare_boot_cpu(void) |
| 327 | { |
| 328 | unsigned int cpu = smp_processor_id(); |
| 329 | |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 330 | per_cpu(cpu_data, cpu).idle = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 333 | static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | unsigned long flags; |
| 336 | unsigned int cpu; |
| 337 | |
| 338 | local_irq_save(flags); |
| 339 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 340 | for_each_cpu(cpu, mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | 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 King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 351 | smp_cross_call(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | local_irq_restore(flags); |
| 354 | } |
| 355 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 356 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 358 | send_ipi_message(mask, IPI_CALL_FUNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 361 | void arch_send_call_function_single_ipi(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 363 | send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
Catalin Marinas | 3e45999 | 2008-02-04 17:28:56 +0100 | [diff] [blame] | 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | void show_ipi_list(struct seq_file *p) |
| 367 | { |
| 368 | unsigned int cpu; |
| 369 | |
| 370 | seq_puts(p, "IPI:"); |
| 371 | |
Russell King | e11b223 | 2005-07-11 19:26:31 +0100 | [diff] [blame] | 372 | for_each_present_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count); |
| 374 | |
| 375 | seq_putc(p, '\n'); |
| 376 | } |
| 377 | |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 378 | void 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 King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 390 | /* |
| 391 | * Timer (local or broadcast) support |
| 392 | */ |
| 393 | static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent); |
| 394 | |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 395 | static void ipi_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 397 | struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | irq_enter(); |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 399 | evt->event_handler(evt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | irq_exit(); |
| 401 | } |
| 402 | |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 403 | #ifdef CONFIG_LOCAL_TIMERS |
Russell King | b9811d7 | 2007-05-08 11:31:07 +0100 | [diff] [blame] | 404 | asmlinkage void __exception do_local_timer(struct pt_regs *regs) |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 405 | { |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 406 | struct pt_regs *old_regs = set_irq_regs(regs); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 407 | int cpu = smp_processor_id(); |
| 408 | |
| 409 | if (local_timer_ack()) { |
| 410 | irq_stat[cpu].local_timer_irqs++; |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 411 | ipi_timer(); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 412 | } |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 413 | |
| 414 | set_irq_regs(old_regs); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 415 | } |
| 416 | #endif |
| 417 | |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 418 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 419 | static void smp_timer_broadcast(const struct cpumask *mask) |
| 420 | { |
| 421 | send_ipi_message(mask, IPI_TIMER); |
| 422 | } |
| 423 | |
| 424 | static void broadcast_timer_set_mode(enum clock_event_mode mode, |
| 425 | struct clock_event_device *evt) |
| 426 | { |
| 427 | } |
| 428 | |
| 429 | static 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 | |
| 444 | void __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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | static DEFINE_SPINLOCK(stop_lock); |
| 455 | |
| 456 | /* |
| 457 | * ipi_cpu_stop - handle IPI from smp_send_stop() |
| 458 | */ |
| 459 | static 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 King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 466 | set_cpu_online(cpu, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 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 King | b9811d7 | 2007-05-08 11:31:07 +0100 | [diff] [blame] | 484 | asmlinkage void __exception do_IPI(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
| 486 | unsigned int cpu = smp_processor_id(); |
| 487 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 488 | struct pt_regs *old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 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 King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 512 | ipi_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 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 Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 523 | generic_smp_call_function_interrupt(); |
| 524 | break; |
| 525 | |
| 526 | case IPI_CALL_FUNC_SINGLE: |
| 527 | generic_smp_call_function_single_interrupt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | 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 King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 541 | |
| 542 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void smp_send_reschedule(int cpu) |
| 546 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 547 | send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | void smp_send_stop(void) |
| 551 | { |
| 552 | cpumask_t mask = cpu_online_map; |
| 553 | cpu_clear(smp_processor_id(), mask); |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 554 | send_ipi_message(&mask, IPI_CPU_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* |
| 558 | * not supported here |
| 559 | */ |
Russell King | 5048bcb | 2007-07-23 12:59:46 +0100 | [diff] [blame] | 560 | int setup_profiling_timer(unsigned int multiplier) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
| 562 | return -EINVAL; |
| 563 | } |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 564 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 565 | static void |
| 566 | on_each_cpu_mask(void (*func)(void *), void *info, int wait, |
| 567 | const struct cpumask *mask) |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 568 | { |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 569 | preempt_disable(); |
| 570 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 571 | smp_call_function_many(mask, func, info, wait); |
| 572 | if (cpumask_test_cpu(smp_processor_id(), mask)) |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 573 | func(info); |
| 574 | |
| 575 | preempt_enable(); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /**********************************************************************/ |
| 579 | |
| 580 | /* |
| 581 | * TLB operations |
| 582 | */ |
| 583 | struct tlb_args { |
| 584 | struct vm_area_struct *ta_vma; |
| 585 | unsigned long ta_start; |
| 586 | unsigned long ta_end; |
| 587 | }; |
| 588 | |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 589 | /* all SMP configurations have the extended CPUID registers */ |
| 590 | static inline int tlb_ops_need_broadcast(void) |
| 591 | { |
| 592 | return ((read_cpuid_ext(CPUID_EXT_MMFR3) >> 12) & 0xf) < 2; |
| 593 | } |
| 594 | |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 595 | static inline void ipi_flush_tlb_all(void *ignored) |
| 596 | { |
| 597 | local_flush_tlb_all(); |
| 598 | } |
| 599 | |
| 600 | static 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 | |
| 607 | static 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 | |
| 614 | static 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 | |
| 621 | static 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 | |
| 628 | static 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 | |
| 635 | void flush_tlb_all(void) |
| 636 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 637 | if (tlb_ops_need_broadcast()) |
| 638 | on_each_cpu(ipi_flush_tlb_all, NULL, 1); |
| 639 | else |
| 640 | local_flush_tlb_all(); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | void flush_tlb_mm(struct mm_struct *mm) |
| 644 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 645 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) |
| 652 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 653 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | void flush_tlb_kernel_page(unsigned long kaddr) |
| 663 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 664 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | void flush_tlb_range(struct vm_area_struct *vma, |
| 673 | unsigned long start, unsigned long end) |
| 674 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 675 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) |
| 686 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 687 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 694 | } |