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> |
Russell King | e616c59 | 2009-09-27 20:55:43 +0100 | [diff] [blame] | 39 | #include <asm/smp_plat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 42 | * 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 | */ |
| 46 | struct secondary_data secondary_data; |
| 47 | |
| 48 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * structures for inter-processor calls |
| 50 | * - A collection of single bit ipi messages. |
| 51 | */ |
| 52 | struct ipi_data { |
| 53 | spinlock_t lock; |
| 54 | unsigned long ipi_count; |
| 55 | unsigned long bits; |
| 56 | }; |
| 57 | |
| 58 | static DEFINE_PER_CPU(struct ipi_data, ipi_data) = { |
| 59 | .lock = SPIN_LOCK_UNLOCKED, |
| 60 | }; |
| 61 | |
| 62 | enum ipi_msg_type { |
| 63 | IPI_TIMER, |
| 64 | IPI_RESCHEDULE, |
| 65 | IPI_CALL_FUNC, |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 66 | IPI_CALL_FUNC_SINGLE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | IPI_CPU_STOP, |
| 68 | }; |
| 69 | |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 70 | int __cpuinit __cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 72 | struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu); |
| 73 | struct task_struct *idle = ci->idle; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 74 | pgd_t *pgd; |
| 75 | pmd_t *pmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | int ret; |
| 77 | |
| 78 | /* |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 79 | * Spawn a new process manually, if not already done. |
| 80 | * 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] | 81 | */ |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 82 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 92 | * 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 King | 058ddee | 2008-08-07 22:36:59 +0100 | [diff] [blame] | 98 | pmd = pmd_offset(pgd + pgd_index(PHYS_OFFSET), PHYS_OFFSET); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 99 | *pmd = __pmd((PHYS_OFFSET & PGDIR_MASK) | |
| 100 | PMD_TYPE_SECT | PMD_SECT_AP_WRITE); |
Catalin Marinas | e9fc782 | 2009-02-11 13:14:57 +0100 | [diff] [blame] | 101 | flush_pmd_entry(pmd); |
Russell King | 1027247 | 2010-02-12 14:36:24 +0000 | [diff] [blame] | 102 | outer_clean_range(__pa(pmd), __pa(pmd + 1)); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * We need to tell the secondary core where to find |
| 106 | * its stack and the page tables. |
| 107 | */ |
Al Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 108 | secondary_data.stack = task_stack_page(idle) + THREAD_START_SP; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 109 | secondary_data.pgdir = virt_to_phys(pgd); |
Russell King | 1027247 | 2010-02-12 14:36:24 +0000 | [diff] [blame] | 110 | __cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data)); |
| 111 | outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1)); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 112 | |
| 113 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | * Now bring the CPU into our world. |
| 115 | */ |
| 116 | ret = boot_secondary(cpu, idle); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 117 | 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 King | 5d43045 | 2005-11-08 10:44:46 +0000 | [diff] [blame] | 137 | secondary_data.stack = NULL; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 138 | secondary_data.pgdir = 0; |
| 139 | |
Russell King | 058ddee | 2008-08-07 22:36:59 +0100 | [diff] [blame] | 140 | *pmd = __pmd(0); |
Catalin Marinas | e9fc782 | 2009-02-11 13:14:57 +0100 | [diff] [blame] | 141 | clean_pmd_entry(pmd); |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 142 | pgd_free(&init_mm, pgd); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (ret) { |
Russell King | 0908db2 | 2005-06-19 19:48:16 +0100 | [diff] [blame] | 145 | printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu); |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* |
| 148 | * FIXME: We need to clean up the new idle thread. --rmk |
| 149 | */ |
| 150 | } |
| 151 | |
| 152 | return ret; |
| 153 | } |
| 154 | |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 155 | #ifdef CONFIG_HOTPLUG_CPU |
| 156 | /* |
| 157 | * __cpu_disable runs on the processor to be shutdown. |
| 158 | */ |
Russell King | 90140c3 | 2009-09-27 21:04:48 +0100 | [diff] [blame] | 159 | int __cpu_disable(void) |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 160 | { |
| 161 | unsigned int cpu = smp_processor_id(); |
| 162 | struct task_struct *p; |
| 163 | int ret; |
| 164 | |
Russell King | 8e2a43f | 2010-05-15 10:18:05 +0100 | [diff] [blame^] | 165 | ret = platform_cpu_disable(cpu); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 166 | 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 King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 173 | set_cpu_online(cpu, false); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * OK - migrate IRQs away from this CPU |
| 177 | */ |
| 178 | migrate_irqs(); |
| 179 | |
| 180 | /* |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 181 | * Stop the local timer for this CPU. |
| 182 | */ |
Catalin Marinas | ebac654 | 2008-12-01 14:54:57 +0000 | [diff] [blame] | 183 | local_timer_stop(); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 184 | |
| 185 | /* |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 186 | * 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 Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 195 | cpumask_clear_cpu(cpu, mm_cpumask(p->mm)); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 196 | } |
| 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 King | 90140c3 | 2009-09-27 21:04:48 +0100 | [diff] [blame] | 206 | void __cpu_die(unsigned int cpu) |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 207 | { |
| 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 King | 90140c3 | 2009-09-27 21:04:48 +0100 | [diff] [blame] | 220 | void __ref cpu_die(void) |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 221 | { |
| 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 Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 241 | : "r" (task_stack_page(current) + THREAD_SIZE - 8)); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 242 | } |
| 243 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 246 | * 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 King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 249 | asmlinkage void __cpuinit secondary_start_kernel(void) |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 250 | { |
| 251 | struct mm_struct *mm = &init_mm; |
Russell King | da2660d | 2005-11-12 17:21:47 +0000 | [diff] [blame] | 252 | unsigned int cpu = smp_processor_id(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 253 | |
| 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 Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 263 | cpumask_set_cpu(cpu, mm_cpumask(mm)); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 264 | cpu_switch_mm(mm->pgd, mm); |
| 265 | enter_lazy_tlb(mm, current); |
Russell King | 505d7b1 | 2005-07-28 20:32:47 +0100 | [diff] [blame] | 266 | local_flush_tlb_all(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 267 | |
| 268 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 269 | preempt_disable(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 270 | |
| 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 Spraul | e545a61 | 2008-09-07 16:57:22 +0200 | [diff] [blame] | 279 | notify_cpu_starting(cpu); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 280 | local_irq_enable(); |
| 281 | local_fiq_enable(); |
| 282 | |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 283 | /* |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 284 | * Setup the percpu timer for this CPU. |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 285 | */ |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 286 | percpu_timer_setup(); |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 287 | |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 288 | 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 King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 295 | set_cpu_online(cpu, true); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 296 | |
| 297 | /* |
| 298 | * OK, it's off to the idle thread for us |
| 299 | */ |
| 300 | cpu_idle(); |
| 301 | } |
| 302 | |
| 303 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | * Called by both boot and secondaries to move global data into |
| 305 | * per-processor storage. |
| 306 | */ |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 307 | void __cpuinit smp_store_cpu_info(unsigned int cpuid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid); |
| 310 | |
| 311 | cpu_info->loops_per_jiffy = loops_per_jiffy; |
| 312 | } |
| 313 | |
| 314 | void __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 | |
| 329 | void __init smp_prepare_boot_cpu(void) |
| 330 | { |
| 331 | unsigned int cpu = smp_processor_id(); |
| 332 | |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 333 | per_cpu(cpu_data, cpu).idle = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 336 | 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] | 337 | { |
| 338 | unsigned long flags; |
| 339 | unsigned int cpu; |
| 340 | |
| 341 | local_irq_save(flags); |
| 342 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 343 | for_each_cpu(cpu, mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | 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 King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 354 | smp_cross_call(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | local_irq_restore(flags); |
| 357 | } |
| 358 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 359 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 361 | send_ipi_message(mask, IPI_CALL_FUNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 364 | void arch_send_call_function_single_ipi(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 366 | send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
Catalin Marinas | 3e45999 | 2008-02-04 17:28:56 +0100 | [diff] [blame] | 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | void show_ipi_list(struct seq_file *p) |
| 370 | { |
| 371 | unsigned int cpu; |
| 372 | |
| 373 | seq_puts(p, "IPI:"); |
| 374 | |
Russell King | e11b223 | 2005-07-11 19:26:31 +0100 | [diff] [blame] | 375 | for_each_present_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count); |
| 377 | |
| 378 | seq_putc(p, '\n'); |
| 379 | } |
| 380 | |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 381 | void 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 King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 393 | /* |
| 394 | * Timer (local or broadcast) support |
| 395 | */ |
| 396 | static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent); |
| 397 | |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 398 | static void ipi_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 400 | struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | irq_enter(); |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 402 | evt->event_handler(evt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | irq_exit(); |
| 404 | } |
| 405 | |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 406 | #ifdef CONFIG_LOCAL_TIMERS |
Russell King | b9811d7 | 2007-05-08 11:31:07 +0100 | [diff] [blame] | 407 | asmlinkage void __exception do_local_timer(struct pt_regs *regs) |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 408 | { |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 409 | struct pt_regs *old_regs = set_irq_regs(regs); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 410 | int cpu = smp_processor_id(); |
| 411 | |
| 412 | if (local_timer_ack()) { |
| 413 | irq_stat[cpu].local_timer_irqs++; |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 414 | ipi_timer(); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 415 | } |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 416 | |
| 417 | set_irq_regs(old_regs); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 418 | } |
| 419 | #endif |
| 420 | |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 421 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 422 | static void smp_timer_broadcast(const struct cpumask *mask) |
| 423 | { |
| 424 | send_ipi_message(mask, IPI_TIMER); |
| 425 | } |
| 426 | |
| 427 | static void broadcast_timer_set_mode(enum clock_event_mode mode, |
| 428 | struct clock_event_device *evt) |
| 429 | { |
| 430 | } |
| 431 | |
| 432 | static 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 | |
| 447 | void __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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | static DEFINE_SPINLOCK(stop_lock); |
| 458 | |
| 459 | /* |
| 460 | * ipi_cpu_stop - handle IPI from smp_send_stop() |
| 461 | */ |
| 462 | static 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 King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 469 | set_cpu_online(cpu, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 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 King | b9811d7 | 2007-05-08 11:31:07 +0100 | [diff] [blame] | 487 | asmlinkage void __exception do_IPI(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
| 489 | unsigned int cpu = smp_processor_id(); |
| 490 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 491 | struct pt_regs *old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 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 King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 515 | ipi_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | 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 Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 526 | generic_smp_call_function_interrupt(); |
| 527 | break; |
| 528 | |
| 529 | case IPI_CALL_FUNC_SINGLE: |
| 530 | generic_smp_call_function_single_interrupt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | 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 King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 544 | |
| 545 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void smp_send_reschedule(int cpu) |
| 549 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 550 | send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | void smp_send_stop(void) |
| 554 | { |
| 555 | cpumask_t mask = cpu_online_map; |
| 556 | cpu_clear(smp_processor_id(), mask); |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 557 | send_ipi_message(&mask, IPI_CPU_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* |
| 561 | * not supported here |
| 562 | */ |
Russell King | 5048bcb | 2007-07-23 12:59:46 +0100 | [diff] [blame] | 563 | int setup_profiling_timer(unsigned int multiplier) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
| 565 | return -EINVAL; |
| 566 | } |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 567 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 568 | static void |
| 569 | on_each_cpu_mask(void (*func)(void *), void *info, int wait, |
| 570 | const struct cpumask *mask) |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 571 | { |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 572 | preempt_disable(); |
| 573 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 574 | smp_call_function_many(mask, func, info, wait); |
| 575 | if (cpumask_test_cpu(smp_processor_id(), mask)) |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 576 | func(info); |
| 577 | |
| 578 | preempt_enable(); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /**********************************************************************/ |
| 582 | |
| 583 | /* |
| 584 | * TLB operations |
| 585 | */ |
| 586 | struct tlb_args { |
| 587 | struct vm_area_struct *ta_vma; |
| 588 | unsigned long ta_start; |
| 589 | unsigned long ta_end; |
| 590 | }; |
| 591 | |
| 592 | static inline void ipi_flush_tlb_all(void *ignored) |
| 593 | { |
| 594 | local_flush_tlb_all(); |
| 595 | } |
| 596 | |
| 597 | static 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 | |
| 604 | static 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 | |
| 611 | static 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 | |
| 618 | static 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 | |
| 625 | static 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 | |
| 632 | void flush_tlb_all(void) |
| 633 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 634 | if (tlb_ops_need_broadcast()) |
| 635 | on_each_cpu(ipi_flush_tlb_all, NULL, 1); |
| 636 | else |
| 637 | local_flush_tlb_all(); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | void flush_tlb_mm(struct mm_struct *mm) |
| 641 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 642 | if (tlb_ops_need_broadcast()) |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 643 | on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm)); |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 644 | else |
| 645 | local_flush_tlb_mm(mm); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) |
| 649 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 650 | if (tlb_ops_need_broadcast()) { |
| 651 | struct tlb_args ta; |
| 652 | ta.ta_vma = vma; |
| 653 | ta.ta_start = uaddr; |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 654 | on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm)); |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 655 | } else |
| 656 | local_flush_tlb_page(vma, uaddr); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | void flush_tlb_kernel_page(unsigned long kaddr) |
| 660 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 661 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | void flush_tlb_range(struct vm_area_struct *vma, |
| 670 | unsigned long start, unsigned long end) |
| 671 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 672 | 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 Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 677 | on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm)); |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 678 | } else |
| 679 | local_flush_tlb_range(vma, start, end); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) |
| 683 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 684 | 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 King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 691 | } |