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