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> |
Rabin Vincent | 61b5cb1 | 2010-10-07 20:51:58 +0530 | [diff] [blame^] | 19 | #include <linux/ftrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 21 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/cpu.h> |
| 23 | #include <linux/smp.h> |
| 24 | #include <linux/seq_file.h> |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 25 | #include <linux/irq.h> |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 26 | #include <linux/percpu.h> |
| 27 | #include <linux/clockchips.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #include <asm/atomic.h> |
| 30 | #include <asm/cacheflush.h> |
| 31 | #include <asm/cpu.h> |
Russell King | 42578c8 | 2009-06-11 15:35:00 +0100 | [diff] [blame] | 32 | #include <asm/cputype.h> |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 33 | #include <asm/mmu_context.h> |
| 34 | #include <asm/pgtable.h> |
| 35 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/processor.h> |
Russell King | 37b05b6 | 2010-10-01 15:38:24 +0100 | [diff] [blame] | 37 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/tlbflush.h> |
| 39 | #include <asm/ptrace.h> |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 40 | #include <asm/localtimer.h> |
Russell King | e616c59 | 2009-09-27 20:55:43 +0100 | [diff] [blame] | 41 | #include <asm/smp_plat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 44 | * as from 2.5, kernels no longer have an init_tasks structure |
| 45 | * so we need some other way of telling a new secondary core |
| 46 | * where to place its SVC stack |
| 47 | */ |
| 48 | struct secondary_data secondary_data; |
| 49 | |
| 50 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * structures for inter-processor calls |
| 52 | * - A collection of single bit ipi messages. |
| 53 | */ |
| 54 | struct ipi_data { |
| 55 | spinlock_t lock; |
| 56 | unsigned long ipi_count; |
| 57 | unsigned long bits; |
| 58 | }; |
| 59 | |
| 60 | static DEFINE_PER_CPU(struct ipi_data, ipi_data) = { |
| 61 | .lock = SPIN_LOCK_UNLOCKED, |
| 62 | }; |
| 63 | |
| 64 | enum ipi_msg_type { |
| 65 | IPI_TIMER, |
| 66 | IPI_RESCHEDULE, |
| 67 | IPI_CALL_FUNC, |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 68 | IPI_CALL_FUNC_SINGLE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | IPI_CPU_STOP, |
| 70 | }; |
| 71 | |
Russell King | 37b05b6 | 2010-10-01 15:38:24 +0100 | [diff] [blame] | 72 | static inline void identity_mapping_add(pgd_t *pgd, unsigned long start, |
| 73 | unsigned long end) |
| 74 | { |
| 75 | unsigned long addr, prot; |
| 76 | pmd_t *pmd; |
| 77 | |
| 78 | prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE; |
| 79 | if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale()) |
| 80 | prot |= PMD_BIT4; |
| 81 | |
| 82 | for (addr = start & PGDIR_MASK; addr < end;) { |
| 83 | pmd = pmd_offset(pgd + pgd_index(addr), addr); |
| 84 | pmd[0] = __pmd(addr | prot); |
| 85 | addr += SECTION_SIZE; |
| 86 | pmd[1] = __pmd(addr | prot); |
| 87 | addr += SECTION_SIZE; |
| 88 | flush_pmd_entry(pmd); |
| 89 | outer_clean_range(__pa(pmd), __pa(pmd + 1)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | static inline void identity_mapping_del(pgd_t *pgd, unsigned long start, |
| 94 | unsigned long end) |
| 95 | { |
| 96 | unsigned long addr; |
| 97 | pmd_t *pmd; |
| 98 | |
| 99 | for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) { |
| 100 | pmd = pmd_offset(pgd + pgd_index(addr), addr); |
| 101 | pmd[0] = __pmd(0); |
| 102 | pmd[1] = __pmd(0); |
| 103 | clean_pmd_entry(pmd); |
| 104 | outer_clean_range(__pa(pmd), __pa(pmd + 1)); |
| 105 | } |
| 106 | } |
| 107 | |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 108 | int __cpuinit __cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 110 | struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu); |
| 111 | struct task_struct *idle = ci->idle; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 112 | pgd_t *pgd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | int ret; |
| 114 | |
| 115 | /* |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 116 | * Spawn a new process manually, if not already done. |
| 117 | * 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] | 118 | */ |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 119 | if (!idle) { |
| 120 | idle = fork_idle(cpu); |
| 121 | if (IS_ERR(idle)) { |
| 122 | printk(KERN_ERR "CPU%u: fork() failed\n", cpu); |
| 123 | return PTR_ERR(idle); |
| 124 | } |
| 125 | ci->idle = idle; |
Santosh Shilimkar | 13ea9cc | 2010-04-30 06:51:20 +0100 | [diff] [blame] | 126 | } else { |
| 127 | /* |
| 128 | * Since this idle thread is being re-used, call |
| 129 | * init_idle() to reinitialize the thread structure. |
| 130 | */ |
| 131 | init_idle(idle, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 135 | * Allocate initial page tables to allow the new CPU to |
| 136 | * enable the MMU safely. This essentially means a set |
| 137 | * of our "standard" page tables, with the addition of |
| 138 | * a 1:1 mapping for the physical address of the kernel. |
| 139 | */ |
| 140 | pgd = pgd_alloc(&init_mm); |
Russell King | 37b05b6 | 2010-10-01 15:38:24 +0100 | [diff] [blame] | 141 | if (!pgd) |
| 142 | return -ENOMEM; |
| 143 | |
| 144 | if (PHYS_OFFSET != PAGE_OFFSET) { |
| 145 | #ifndef CONFIG_HOTPLUG_CPU |
| 146 | identity_mapping_add(pgd, __pa(__init_begin), __pa(__init_end)); |
| 147 | #endif |
| 148 | identity_mapping_add(pgd, __pa(_stext), __pa(_etext)); |
| 149 | identity_mapping_add(pgd, __pa(_sdata), __pa(_edata)); |
| 150 | } |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * We need to tell the secondary core where to find |
| 154 | * its stack and the page tables. |
| 155 | */ |
Al Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 156 | secondary_data.stack = task_stack_page(idle) + THREAD_START_SP; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 157 | secondary_data.pgdir = virt_to_phys(pgd); |
Russell King | 1027247 | 2010-02-12 14:36:24 +0000 | [diff] [blame] | 158 | __cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data)); |
| 159 | outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1)); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 160 | |
| 161 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | * Now bring the CPU into our world. |
| 163 | */ |
| 164 | ret = boot_secondary(cpu, idle); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 165 | if (ret == 0) { |
| 166 | unsigned long timeout; |
| 167 | |
| 168 | /* |
| 169 | * CPU was successfully started, wait for it |
| 170 | * to come online or time out. |
| 171 | */ |
| 172 | timeout = jiffies + HZ; |
| 173 | while (time_before(jiffies, timeout)) { |
| 174 | if (cpu_online(cpu)) |
| 175 | break; |
| 176 | |
| 177 | udelay(10); |
| 178 | barrier(); |
| 179 | } |
| 180 | |
| 181 | if (!cpu_online(cpu)) |
| 182 | ret = -EIO; |
| 183 | } |
| 184 | |
Russell King | 5d43045 | 2005-11-08 10:44:46 +0000 | [diff] [blame] | 185 | secondary_data.stack = NULL; |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 186 | secondary_data.pgdir = 0; |
| 187 | |
Russell King | 37b05b6 | 2010-10-01 15:38:24 +0100 | [diff] [blame] | 188 | if (PHYS_OFFSET != PAGE_OFFSET) { |
| 189 | #ifndef CONFIG_HOTPLUG_CPU |
| 190 | identity_mapping_del(pgd, __pa(__init_begin), __pa(__init_end)); |
| 191 | #endif |
| 192 | identity_mapping_del(pgd, __pa(_stext), __pa(_etext)); |
| 193 | identity_mapping_del(pgd, __pa(_sdata), __pa(_edata)); |
| 194 | } |
| 195 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 196 | pgd_free(&init_mm, pgd); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (ret) { |
Russell King | 0908db2 | 2005-06-19 19:48:16 +0100 | [diff] [blame] | 199 | printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu); |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* |
| 202 | * FIXME: We need to clean up the new idle thread. --rmk |
| 203 | */ |
| 204 | } |
| 205 | |
| 206 | return ret; |
| 207 | } |
| 208 | |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 209 | #ifdef CONFIG_HOTPLUG_CPU |
| 210 | /* |
| 211 | * __cpu_disable runs on the processor to be shutdown. |
| 212 | */ |
Russell King | 90140c3 | 2009-09-27 21:04:48 +0100 | [diff] [blame] | 213 | int __cpu_disable(void) |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 214 | { |
| 215 | unsigned int cpu = smp_processor_id(); |
| 216 | struct task_struct *p; |
| 217 | int ret; |
| 218 | |
Russell King | 8e2a43f | 2010-05-15 10:18:05 +0100 | [diff] [blame] | 219 | ret = platform_cpu_disable(cpu); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 220 | if (ret) |
| 221 | return ret; |
| 222 | |
| 223 | /* |
| 224 | * Take this CPU offline. Once we clear this, we can't return, |
| 225 | * and we must not schedule until we're ready to give up the cpu. |
| 226 | */ |
Russell King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 227 | set_cpu_online(cpu, false); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * OK - migrate IRQs away from this CPU |
| 231 | */ |
| 232 | migrate_irqs(); |
| 233 | |
| 234 | /* |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 235 | * Stop the local timer for this CPU. |
| 236 | */ |
Catalin Marinas | ebac654 | 2008-12-01 14:54:57 +0000 | [diff] [blame] | 237 | local_timer_stop(); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 238 | |
| 239 | /* |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 240 | * Flush user cache and TLB mappings, and then remove this CPU |
| 241 | * from the vm mask set of all processes. |
| 242 | */ |
| 243 | flush_cache_all(); |
| 244 | local_flush_tlb_all(); |
| 245 | |
| 246 | read_lock(&tasklist_lock); |
| 247 | for_each_process(p) { |
| 248 | if (p->mm) |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 249 | cpumask_clear_cpu(cpu, mm_cpumask(p->mm)); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 250 | } |
| 251 | read_unlock(&tasklist_lock); |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | * called on the thread which is asking for a CPU to be shutdown - |
| 258 | * waits until shutdown has completed, or it is timed out. |
| 259 | */ |
Russell King | 90140c3 | 2009-09-27 21:04:48 +0100 | [diff] [blame] | 260 | void __cpu_die(unsigned int cpu) |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 261 | { |
| 262 | if (!platform_cpu_kill(cpu)) |
| 263 | printk("CPU%u: unable to kill\n", cpu); |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Called from the idle thread for the CPU which has been shutdown. |
| 268 | * |
| 269 | * Note that we disable IRQs here, but do not re-enable them |
| 270 | * before returning to the caller. This is also the behaviour |
| 271 | * of the other hotplug-cpu capable cores, so presumably coming |
| 272 | * out of idle fixes this. |
| 273 | */ |
Russell King | 90140c3 | 2009-09-27 21:04:48 +0100 | [diff] [blame] | 274 | void __ref cpu_die(void) |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 275 | { |
| 276 | unsigned int cpu = smp_processor_id(); |
| 277 | |
| 278 | local_irq_disable(); |
| 279 | idle_task_exit(); |
| 280 | |
| 281 | /* |
| 282 | * actual CPU shutdown procedure is at least platform (if not |
| 283 | * CPU) specific |
| 284 | */ |
| 285 | platform_cpu_die(cpu); |
| 286 | |
| 287 | /* |
| 288 | * Do not return to the idle loop - jump back to the secondary |
| 289 | * cpu initialisation. There's some initialisation which needs |
| 290 | * to be repeated to undo the effects of taking the CPU offline. |
| 291 | */ |
| 292 | __asm__("mov sp, %0\n" |
| 293 | " b secondary_start_kernel" |
| 294 | : |
Al Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 295 | : "r" (task_stack_page(current) + THREAD_SIZE - 8)); |
Russell King | a054a81 | 2005-11-02 22:24:33 +0000 | [diff] [blame] | 296 | } |
| 297 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 300 | * This is the secondary CPU boot entry. We're using this CPUs |
| 301 | * idle thread stack, but a set of temporary page tables. |
| 302 | */ |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 303 | asmlinkage void __cpuinit secondary_start_kernel(void) |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 304 | { |
| 305 | struct mm_struct *mm = &init_mm; |
Russell King | da2660d | 2005-11-12 17:21:47 +0000 | [diff] [blame] | 306 | unsigned int cpu = smp_processor_id(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 307 | |
| 308 | printk("CPU%u: Booted secondary processor\n", cpu); |
| 309 | |
| 310 | /* |
| 311 | * All kernel threads share the same mm context; grab a |
| 312 | * reference and switch to it. |
| 313 | */ |
| 314 | atomic_inc(&mm->mm_users); |
| 315 | atomic_inc(&mm->mm_count); |
| 316 | current->active_mm = mm; |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 317 | cpumask_set_cpu(cpu, mm_cpumask(mm)); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 318 | cpu_switch_mm(mm->pgd, mm); |
| 319 | enter_lazy_tlb(mm, current); |
Russell King | 505d7b1 | 2005-07-28 20:32:47 +0100 | [diff] [blame] | 320 | local_flush_tlb_all(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 321 | |
| 322 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 323 | preempt_disable(); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | * Give the platform a chance to do its own initialisation. |
| 327 | */ |
| 328 | platform_secondary_init(cpu); |
| 329 | |
| 330 | /* |
| 331 | * Enable local interrupts. |
| 332 | */ |
Manfred Spraul | e545a61 | 2008-09-07 16:57:22 +0200 | [diff] [blame] | 333 | notify_cpu_starting(cpu); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 334 | local_irq_enable(); |
| 335 | local_fiq_enable(); |
| 336 | |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 337 | /* |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 338 | * Setup the percpu timer for this CPU. |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 339 | */ |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 340 | percpu_timer_setup(); |
Catalin Marinas | a8655e8 | 2008-02-04 17:30:57 +0100 | [diff] [blame] | 341 | |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 342 | calibrate_delay(); |
| 343 | |
| 344 | smp_store_cpu_info(cpu); |
| 345 | |
| 346 | /* |
| 347 | * OK, now it's safe to let the boot CPU continue |
| 348 | */ |
Russell King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 349 | set_cpu_online(cpu, true); |
Russell King | e65f38e | 2005-06-18 09:33:31 +0100 | [diff] [blame] | 350 | |
| 351 | /* |
| 352 | * OK, it's off to the idle thread for us |
| 353 | */ |
| 354 | cpu_idle(); |
| 355 | } |
| 356 | |
| 357 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | * Called by both boot and secondaries to move global data into |
| 359 | * per-processor storage. |
| 360 | */ |
Russell King | bd6f68a | 2005-07-17 21:35:41 +0100 | [diff] [blame] | 361 | void __cpuinit smp_store_cpu_info(unsigned int cpuid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
| 363 | struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid); |
| 364 | |
| 365 | cpu_info->loops_per_jiffy = loops_per_jiffy; |
| 366 | } |
| 367 | |
| 368 | void __init smp_cpus_done(unsigned int max_cpus) |
| 369 | { |
| 370 | int cpu; |
| 371 | unsigned long bogosum = 0; |
| 372 | |
| 373 | for_each_online_cpu(cpu) |
| 374 | bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy; |
| 375 | |
| 376 | printk(KERN_INFO "SMP: Total of %d processors activated " |
| 377 | "(%lu.%02lu BogoMIPS).\n", |
| 378 | num_online_cpus(), |
| 379 | bogosum / (500000/HZ), |
| 380 | (bogosum / (5000/HZ)) % 100); |
| 381 | } |
| 382 | |
| 383 | void __init smp_prepare_boot_cpu(void) |
| 384 | { |
| 385 | unsigned int cpu = smp_processor_id(); |
| 386 | |
Russell King | 71f512e8 | 2005-11-02 21:51:40 +0000 | [diff] [blame] | 387 | per_cpu(cpu_data, cpu).idle = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 390 | 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] | 391 | { |
| 392 | unsigned long flags; |
| 393 | unsigned int cpu; |
| 394 | |
| 395 | local_irq_save(flags); |
| 396 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 397 | for_each_cpu(cpu, mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); |
| 399 | |
| 400 | spin_lock(&ipi->lock); |
| 401 | ipi->bits |= 1 << msg; |
| 402 | spin_unlock(&ipi->lock); |
| 403 | } |
| 404 | |
| 405 | /* |
| 406 | * Call the platform specific cross-CPU call function. |
| 407 | */ |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 408 | smp_cross_call(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | local_irq_restore(flags); |
| 411 | } |
| 412 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 413 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 415 | send_ipi_message(mask, IPI_CALL_FUNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 418 | void arch_send_call_function_single_ipi(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 420 | send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
Catalin Marinas | 3e45999 | 2008-02-04 17:28:56 +0100 | [diff] [blame] | 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | void show_ipi_list(struct seq_file *p) |
| 424 | { |
| 425 | unsigned int cpu; |
| 426 | |
| 427 | seq_puts(p, "IPI:"); |
| 428 | |
Russell King | e11b223 | 2005-07-11 19:26:31 +0100 | [diff] [blame] | 429 | for_each_present_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count); |
| 431 | |
| 432 | seq_putc(p, '\n'); |
| 433 | } |
| 434 | |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 435 | void show_local_irqs(struct seq_file *p) |
| 436 | { |
| 437 | unsigned int cpu; |
| 438 | |
| 439 | seq_printf(p, "LOC: "); |
| 440 | |
| 441 | for_each_present_cpu(cpu) |
| 442 | seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs); |
| 443 | |
| 444 | seq_putc(p, '\n'); |
| 445 | } |
| 446 | |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 447 | /* |
| 448 | * Timer (local or broadcast) support |
| 449 | */ |
| 450 | static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent); |
| 451 | |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 452 | static void ipi_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 454 | struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | irq_enter(); |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 456 | evt->event_handler(evt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | irq_exit(); |
| 458 | } |
| 459 | |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 460 | #ifdef CONFIG_LOCAL_TIMERS |
Rabin Vincent | 61b5cb1 | 2010-10-07 20:51:58 +0530 | [diff] [blame^] | 461 | asmlinkage void __exception_irq_entry do_local_timer(struct pt_regs *regs) |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 462 | { |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 463 | struct pt_regs *old_regs = set_irq_regs(regs); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 464 | int cpu = smp_processor_id(); |
| 465 | |
| 466 | if (local_timer_ack()) { |
| 467 | irq_stat[cpu].local_timer_irqs++; |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 468 | ipi_timer(); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 469 | } |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 470 | |
| 471 | set_irq_regs(old_regs); |
Russell King | 37ee16a | 2005-11-08 19:08:05 +0000 | [diff] [blame] | 472 | } |
| 473 | #endif |
| 474 | |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 475 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 476 | static void smp_timer_broadcast(const struct cpumask *mask) |
| 477 | { |
| 478 | send_ipi_message(mask, IPI_TIMER); |
| 479 | } |
Russell King | 5388a6b | 2010-07-26 13:19:43 +0100 | [diff] [blame] | 480 | #else |
| 481 | #define smp_timer_broadcast NULL |
| 482 | #endif |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 483 | |
Russell King | 5388a6b | 2010-07-26 13:19:43 +0100 | [diff] [blame] | 484 | #ifndef CONFIG_LOCAL_TIMERS |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 485 | static void broadcast_timer_set_mode(enum clock_event_mode mode, |
| 486 | struct clock_event_device *evt) |
| 487 | { |
| 488 | } |
| 489 | |
| 490 | static void local_timer_setup(struct clock_event_device *evt) |
| 491 | { |
| 492 | evt->name = "dummy_timer"; |
| 493 | evt->features = CLOCK_EVT_FEAT_ONESHOT | |
| 494 | CLOCK_EVT_FEAT_PERIODIC | |
| 495 | CLOCK_EVT_FEAT_DUMMY; |
| 496 | evt->rating = 400; |
| 497 | evt->mult = 1; |
| 498 | evt->set_mode = broadcast_timer_set_mode; |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 499 | |
| 500 | clockevents_register_device(evt); |
| 501 | } |
| 502 | #endif |
| 503 | |
| 504 | void __cpuinit percpu_timer_setup(void) |
| 505 | { |
| 506 | unsigned int cpu = smp_processor_id(); |
| 507 | struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu); |
| 508 | |
| 509 | evt->cpumask = cpumask_of(cpu); |
Russell King | 5388a6b | 2010-07-26 13:19:43 +0100 | [diff] [blame] | 510 | evt->broadcast = smp_timer_broadcast; |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 511 | |
| 512 | local_timer_setup(evt); |
| 513 | } |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | static DEFINE_SPINLOCK(stop_lock); |
| 516 | |
| 517 | /* |
| 518 | * ipi_cpu_stop - handle IPI from smp_send_stop() |
| 519 | */ |
| 520 | static void ipi_cpu_stop(unsigned int cpu) |
| 521 | { |
Russell King | 3d3f78d | 2010-07-26 13:31:27 +0100 | [diff] [blame] | 522 | if (system_state == SYSTEM_BOOTING || |
| 523 | system_state == SYSTEM_RUNNING) { |
| 524 | spin_lock(&stop_lock); |
| 525 | printk(KERN_CRIT "CPU%u: stopping\n", cpu); |
| 526 | dump_stack(); |
| 527 | spin_unlock(&stop_lock); |
| 528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Russell King | e03cdad | 2009-05-28 14:16:52 +0100 | [diff] [blame] | 530 | set_cpu_online(cpu, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | local_fiq_disable(); |
| 533 | local_irq_disable(); |
| 534 | |
| 535 | while (1) |
| 536 | cpu_relax(); |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * Main handler for inter-processor interrupts |
| 541 | * |
| 542 | * For ARM, the ipimask now only identifies a single |
| 543 | * category of IPI (Bit 1 IPIs have been replaced by a |
| 544 | * different mechanism): |
| 545 | * |
| 546 | * Bit 0 - Inter-processor function call |
| 547 | */ |
Rabin Vincent | 61b5cb1 | 2010-10-07 20:51:58 +0530 | [diff] [blame^] | 548 | asmlinkage void __exception_irq_entry do_IPI(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
| 550 | unsigned int cpu = smp_processor_id(); |
| 551 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 552 | struct pt_regs *old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | ipi->ipi_count++; |
| 555 | |
| 556 | for (;;) { |
| 557 | unsigned long msgs; |
| 558 | |
| 559 | spin_lock(&ipi->lock); |
| 560 | msgs = ipi->bits; |
| 561 | ipi->bits = 0; |
| 562 | spin_unlock(&ipi->lock); |
| 563 | |
| 564 | if (!msgs) |
| 565 | break; |
| 566 | |
| 567 | do { |
| 568 | unsigned nextmsg; |
| 569 | |
| 570 | nextmsg = msgs & -msgs; |
| 571 | msgs &= ~nextmsg; |
| 572 | nextmsg = ffz(~nextmsg); |
| 573 | |
| 574 | switch (nextmsg) { |
| 575 | case IPI_TIMER: |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 576 | ipi_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | break; |
| 578 | |
| 579 | case IPI_RESCHEDULE: |
| 580 | /* |
| 581 | * nothing more to do - eveything is |
| 582 | * done on the interrupt return path |
| 583 | */ |
| 584 | break; |
| 585 | |
| 586 | case IPI_CALL_FUNC: |
Jens Axboe | f6dd9fa | 2008-06-10 20:48:30 +0200 | [diff] [blame] | 587 | generic_smp_call_function_interrupt(); |
| 588 | break; |
| 589 | |
| 590 | case IPI_CALL_FUNC_SINGLE: |
| 591 | generic_smp_call_function_single_interrupt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | break; |
| 593 | |
| 594 | case IPI_CPU_STOP: |
| 595 | ipi_cpu_stop(cpu); |
| 596 | break; |
| 597 | |
| 598 | default: |
| 599 | printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n", |
| 600 | cpu, nextmsg); |
| 601 | break; |
| 602 | } |
| 603 | } while (msgs); |
| 604 | } |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 605 | |
| 606 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | void smp_send_reschedule(int cpu) |
| 610 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 611 | send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | void smp_send_stop(void) |
| 615 | { |
| 616 | cpumask_t mask = cpu_online_map; |
| 617 | cpu_clear(smp_processor_id(), mask); |
Tony Lindgren | f9e417e | 2010-09-21 00:43:19 +0100 | [diff] [blame] | 618 | if (!cpus_empty(mask)) |
| 619 | send_ipi_message(&mask, IPI_CPU_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /* |
| 623 | * not supported here |
| 624 | */ |
Russell King | 5048bcb | 2007-07-23 12:59:46 +0100 | [diff] [blame] | 625 | int setup_profiling_timer(unsigned int multiplier) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | { |
| 627 | return -EINVAL; |
| 628 | } |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 629 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 630 | static void |
| 631 | on_each_cpu_mask(void (*func)(void *), void *info, int wait, |
| 632 | const struct cpumask *mask) |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 633 | { |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 634 | preempt_disable(); |
| 635 | |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 636 | smp_call_function_many(mask, func, info, wait); |
| 637 | if (cpumask_test_cpu(smp_processor_id(), mask)) |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 638 | func(info); |
| 639 | |
| 640 | preempt_enable(); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /**********************************************************************/ |
| 644 | |
| 645 | /* |
| 646 | * TLB operations |
| 647 | */ |
| 648 | struct tlb_args { |
| 649 | struct vm_area_struct *ta_vma; |
| 650 | unsigned long ta_start; |
| 651 | unsigned long ta_end; |
| 652 | }; |
| 653 | |
| 654 | static inline void ipi_flush_tlb_all(void *ignored) |
| 655 | { |
| 656 | local_flush_tlb_all(); |
| 657 | } |
| 658 | |
| 659 | static inline void ipi_flush_tlb_mm(void *arg) |
| 660 | { |
| 661 | struct mm_struct *mm = (struct mm_struct *)arg; |
| 662 | |
| 663 | local_flush_tlb_mm(mm); |
| 664 | } |
| 665 | |
| 666 | static inline void ipi_flush_tlb_page(void *arg) |
| 667 | { |
| 668 | struct tlb_args *ta = (struct tlb_args *)arg; |
| 669 | |
| 670 | local_flush_tlb_page(ta->ta_vma, ta->ta_start); |
| 671 | } |
| 672 | |
| 673 | static inline void ipi_flush_tlb_kernel_page(void *arg) |
| 674 | { |
| 675 | struct tlb_args *ta = (struct tlb_args *)arg; |
| 676 | |
| 677 | local_flush_tlb_kernel_page(ta->ta_start); |
| 678 | } |
| 679 | |
| 680 | static inline void ipi_flush_tlb_range(void *arg) |
| 681 | { |
| 682 | struct tlb_args *ta = (struct tlb_args *)arg; |
| 683 | |
| 684 | local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end); |
| 685 | } |
| 686 | |
| 687 | static inline void ipi_flush_tlb_kernel_range(void *arg) |
| 688 | { |
| 689 | struct tlb_args *ta = (struct tlb_args *)arg; |
| 690 | |
| 691 | local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end); |
| 692 | } |
| 693 | |
| 694 | void flush_tlb_all(void) |
| 695 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 696 | if (tlb_ops_need_broadcast()) |
| 697 | on_each_cpu(ipi_flush_tlb_all, NULL, 1); |
| 698 | else |
| 699 | local_flush_tlb_all(); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void flush_tlb_mm(struct mm_struct *mm) |
| 703 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 704 | if (tlb_ops_need_broadcast()) |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 705 | 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] | 706 | else |
| 707 | local_flush_tlb_mm(mm); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) |
| 711 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 712 | if (tlb_ops_need_broadcast()) { |
| 713 | struct tlb_args ta; |
| 714 | ta.ta_vma = vma; |
| 715 | ta.ta_start = uaddr; |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 716 | 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] | 717 | } else |
| 718 | local_flush_tlb_page(vma, uaddr); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void flush_tlb_kernel_page(unsigned long kaddr) |
| 722 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 723 | if (tlb_ops_need_broadcast()) { |
| 724 | struct tlb_args ta; |
| 725 | ta.ta_start = kaddr; |
| 726 | on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1); |
| 727 | } else |
| 728 | local_flush_tlb_kernel_page(kaddr); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void flush_tlb_range(struct vm_area_struct *vma, |
| 732 | unsigned long start, unsigned long end) |
| 733 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 734 | if (tlb_ops_need_broadcast()) { |
| 735 | struct tlb_args ta; |
| 736 | ta.ta_vma = vma; |
| 737 | ta.ta_start = start; |
| 738 | ta.ta_end = end; |
Rusty Russell | 56f8ba8 | 2009-09-24 09:34:49 -0600 | [diff] [blame] | 739 | 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] | 740 | } else |
| 741 | local_flush_tlb_range(vma, start, end); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) |
| 745 | { |
Catalin Marinas | faa7bc5 | 2009-05-30 14:00:14 +0100 | [diff] [blame] | 746 | if (tlb_ops_need_broadcast()) { |
| 747 | struct tlb_args ta; |
| 748 | ta.ta_start = start; |
| 749 | ta.ta_end = end; |
| 750 | on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1); |
| 751 | } else |
| 752 | local_flush_tlb_kernel_range(start, end); |
Russell King | 4b0ef3b | 2005-06-28 13:49:16 +0100 | [diff] [blame] | 753 | } |