Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * IPI management based on arch/arm/kernel/smp.c (Copyright 2002 ARM Limited) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 3 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 4 | * Copyright 2007-2009 Analog Devices Inc. |
| 5 | * Philippe Gerum <rpm@xenomai.org> |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 6 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 7 | * Licensed under the GPL-2. |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 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> |
| 20 | #include <linux/cpu.h> |
| 21 | #include <linux/smp.h> |
Graf Yang | 9c199b5 | 2009-09-21 11:51:31 +0000 | [diff] [blame^] | 22 | #include <linux/cpumask.h> |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
| 24 | #include <linux/irq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 26 | #include <asm/atomic.h> |
| 27 | #include <asm/cacheflush.h> |
| 28 | #include <asm/mmu_context.h> |
| 29 | #include <asm/pgtable.h> |
| 30 | #include <asm/pgalloc.h> |
| 31 | #include <asm/processor.h> |
| 32 | #include <asm/ptrace.h> |
| 33 | #include <asm/cpu.h> |
Graf Yang | 1fa9be7 | 2009-05-15 11:01:59 +0000 | [diff] [blame] | 34 | #include <asm/time.h> |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 35 | #include <linux/err.h> |
| 36 | |
Graf Yang | 555487b | 2009-05-06 10:38:07 +0000 | [diff] [blame] | 37 | /* |
| 38 | * Anomaly notes: |
| 39 | * 05000120 - we always define corelock as 32-bit integer in L2 |
| 40 | */ |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 41 | struct corelock_slot corelock __attribute__ ((__section__(".l2.bss"))); |
| 42 | |
| 43 | void __cpuinitdata *init_retx_coreb, *init_saved_retx_coreb, |
| 44 | *init_saved_seqstat_coreb, *init_saved_icplb_fault_addr_coreb, |
| 45 | *init_saved_dcplb_fault_addr_coreb; |
| 46 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 47 | #define BFIN_IPI_RESCHEDULE 0 |
| 48 | #define BFIN_IPI_CALL_FUNC 1 |
| 49 | #define BFIN_IPI_CPU_STOP 2 |
| 50 | |
| 51 | struct blackfin_flush_data { |
| 52 | unsigned long start; |
| 53 | unsigned long end; |
| 54 | }; |
| 55 | |
| 56 | void *secondary_stack; |
| 57 | |
| 58 | |
| 59 | struct smp_call_struct { |
| 60 | void (*func)(void *info); |
| 61 | void *info; |
| 62 | int wait; |
| 63 | cpumask_t pending; |
| 64 | cpumask_t waitmask; |
| 65 | }; |
| 66 | |
| 67 | static struct blackfin_flush_data smp_flush_data; |
| 68 | |
| 69 | static DEFINE_SPINLOCK(stop_lock); |
| 70 | |
| 71 | struct ipi_message { |
| 72 | struct list_head list; |
| 73 | unsigned long type; |
| 74 | struct smp_call_struct call_struct; |
| 75 | }; |
| 76 | |
| 77 | struct ipi_message_queue { |
| 78 | struct list_head head; |
| 79 | spinlock_t lock; |
| 80 | unsigned long count; |
| 81 | }; |
| 82 | |
| 83 | static DEFINE_PER_CPU(struct ipi_message_queue, ipi_msg_queue); |
| 84 | |
| 85 | static void ipi_cpu_stop(unsigned int cpu) |
| 86 | { |
| 87 | spin_lock(&stop_lock); |
| 88 | printk(KERN_CRIT "CPU%u: stopping\n", cpu); |
| 89 | dump_stack(); |
| 90 | spin_unlock(&stop_lock); |
| 91 | |
| 92 | cpu_clear(cpu, cpu_online_map); |
| 93 | |
| 94 | local_irq_disable(); |
| 95 | |
| 96 | while (1) |
| 97 | SSYNC(); |
| 98 | } |
| 99 | |
| 100 | static void ipi_flush_icache(void *info) |
| 101 | { |
| 102 | struct blackfin_flush_data *fdata = info; |
| 103 | |
| 104 | /* Invalidate the memory holding the bounds of the flushed region. */ |
| 105 | blackfin_dcache_invalidate_range((unsigned long)fdata, |
| 106 | (unsigned long)fdata + sizeof(*fdata)); |
| 107 | |
| 108 | blackfin_icache_flush_range(fdata->start, fdata->end); |
| 109 | } |
| 110 | |
| 111 | static void ipi_call_function(unsigned int cpu, struct ipi_message *msg) |
| 112 | { |
| 113 | int wait; |
| 114 | void (*func)(void *info); |
| 115 | void *info; |
| 116 | func = msg->call_struct.func; |
| 117 | info = msg->call_struct.info; |
| 118 | wait = msg->call_struct.wait; |
| 119 | cpu_clear(cpu, msg->call_struct.pending); |
| 120 | func(info); |
Yi Li | c9784eb | 2009-12-04 06:56:21 +0000 | [diff] [blame] | 121 | if (wait) { |
| 122 | #ifdef __ARCH_SYNC_CORE_DCACHE |
| 123 | /* |
| 124 | * 'wait' usually means synchronization between CPUs. |
| 125 | * Invalidate D cache in case shared data was changed |
| 126 | * by func() to ensure cache coherence. |
| 127 | */ |
| 128 | resync_core_dcache(); |
| 129 | #endif |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 130 | cpu_clear(cpu, msg->call_struct.waitmask); |
Yi Li | c9784eb | 2009-12-04 06:56:21 +0000 | [diff] [blame] | 131 | } else |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 132 | kfree(msg); |
| 133 | } |
| 134 | |
| 135 | static irqreturn_t ipi_handler(int irq, void *dev_instance) |
| 136 | { |
Sonic Zhang | 86f2008 | 2009-06-10 08:42:41 +0000 | [diff] [blame] | 137 | struct ipi_message *msg; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 138 | struct ipi_message_queue *msg_queue; |
| 139 | unsigned int cpu = smp_processor_id(); |
| 140 | |
| 141 | platform_clear_ipi(cpu); |
| 142 | |
| 143 | msg_queue = &__get_cpu_var(ipi_msg_queue); |
| 144 | msg_queue->count++; |
| 145 | |
| 146 | spin_lock(&msg_queue->lock); |
Sonic Zhang | 86f2008 | 2009-06-10 08:42:41 +0000 | [diff] [blame] | 147 | while (!list_empty(&msg_queue->head)) { |
| 148 | msg = list_entry(msg_queue->head.next, typeof(*msg), list); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 149 | list_del(&msg->list); |
| 150 | switch (msg->type) { |
| 151 | case BFIN_IPI_RESCHEDULE: |
| 152 | /* That's the easiest one; leave it to |
| 153 | * return_from_int. */ |
| 154 | kfree(msg); |
| 155 | break; |
| 156 | case BFIN_IPI_CALL_FUNC: |
Sonic Zhang | 0bf3d93 | 2009-03-05 16:44:53 +0800 | [diff] [blame] | 157 | spin_unlock(&msg_queue->lock); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 158 | ipi_call_function(cpu, msg); |
Sonic Zhang | 0bf3d93 | 2009-03-05 16:44:53 +0800 | [diff] [blame] | 159 | spin_lock(&msg_queue->lock); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 160 | break; |
| 161 | case BFIN_IPI_CPU_STOP: |
Sonic Zhang | 0bf3d93 | 2009-03-05 16:44:53 +0800 | [diff] [blame] | 162 | spin_unlock(&msg_queue->lock); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 163 | ipi_cpu_stop(cpu); |
Sonic Zhang | 0bf3d93 | 2009-03-05 16:44:53 +0800 | [diff] [blame] | 164 | spin_lock(&msg_queue->lock); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 165 | kfree(msg); |
| 166 | break; |
| 167 | default: |
Joe Perches | db52ecc | 2010-03-26 19:27:51 -0700 | [diff] [blame] | 168 | printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%lx\n", |
| 169 | cpu, msg->type); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 170 | kfree(msg); |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | spin_unlock(&msg_queue->lock); |
| 175 | return IRQ_HANDLED; |
| 176 | } |
| 177 | |
| 178 | static void ipi_queue_init(void) |
| 179 | { |
| 180 | unsigned int cpu; |
| 181 | struct ipi_message_queue *msg_queue; |
| 182 | for_each_possible_cpu(cpu) { |
| 183 | msg_queue = &per_cpu(ipi_msg_queue, cpu); |
| 184 | INIT_LIST_HEAD(&msg_queue->head); |
| 185 | spin_lock_init(&msg_queue->lock); |
| 186 | msg_queue->count = 0; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | int smp_call_function(void (*func)(void *info), void *info, int wait) |
| 191 | { |
| 192 | unsigned int cpu; |
| 193 | cpumask_t callmap; |
| 194 | unsigned long flags; |
| 195 | struct ipi_message_queue *msg_queue; |
| 196 | struct ipi_message *msg; |
| 197 | |
| 198 | callmap = cpu_online_map; |
| 199 | cpu_clear(smp_processor_id(), callmap); |
| 200 | if (cpus_empty(callmap)) |
| 201 | return 0; |
| 202 | |
| 203 | msg = kmalloc(sizeof(*msg), GFP_ATOMIC); |
Julia Lawall | 994e9a2 | 2009-07-14 03:15:19 +0000 | [diff] [blame] | 204 | if (!msg) |
| 205 | return -ENOMEM; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 206 | INIT_LIST_HEAD(&msg->list); |
| 207 | msg->call_struct.func = func; |
| 208 | msg->call_struct.info = info; |
| 209 | msg->call_struct.wait = wait; |
| 210 | msg->call_struct.pending = callmap; |
| 211 | msg->call_struct.waitmask = callmap; |
| 212 | msg->type = BFIN_IPI_CALL_FUNC; |
| 213 | |
| 214 | for_each_cpu_mask(cpu, callmap) { |
| 215 | msg_queue = &per_cpu(ipi_msg_queue, cpu); |
| 216 | spin_lock_irqsave(&msg_queue->lock, flags); |
Sonic Zhang | 86f2008 | 2009-06-10 08:42:41 +0000 | [diff] [blame] | 217 | list_add_tail(&msg->list, &msg_queue->head); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 218 | spin_unlock_irqrestore(&msg_queue->lock, flags); |
| 219 | platform_send_ipi_cpu(cpu); |
| 220 | } |
| 221 | if (wait) { |
| 222 | while (!cpus_empty(msg->call_struct.waitmask)) |
| 223 | blackfin_dcache_invalidate_range( |
| 224 | (unsigned long)(&msg->call_struct.waitmask), |
| 225 | (unsigned long)(&msg->call_struct.waitmask)); |
Yi Li | c9784eb | 2009-12-04 06:56:21 +0000 | [diff] [blame] | 226 | #ifdef __ARCH_SYNC_CORE_DCACHE |
| 227 | /* |
| 228 | * Invalidate D cache in case shared data was changed by |
| 229 | * other processors to ensure cache coherence. |
| 230 | */ |
| 231 | resync_core_dcache(); |
| 232 | #endif |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 233 | kfree(msg); |
| 234 | } |
| 235 | return 0; |
| 236 | } |
| 237 | EXPORT_SYMBOL_GPL(smp_call_function); |
| 238 | |
| 239 | int smp_call_function_single(int cpuid, void (*func) (void *info), void *info, |
| 240 | int wait) |
| 241 | { |
| 242 | unsigned int cpu = cpuid; |
| 243 | cpumask_t callmap; |
| 244 | unsigned long flags; |
| 245 | struct ipi_message_queue *msg_queue; |
| 246 | struct ipi_message *msg; |
| 247 | |
| 248 | if (cpu_is_offline(cpu)) |
| 249 | return 0; |
| 250 | cpus_clear(callmap); |
| 251 | cpu_set(cpu, callmap); |
| 252 | |
| 253 | msg = kmalloc(sizeof(*msg), GFP_ATOMIC); |
Julia Lawall | 994e9a2 | 2009-07-14 03:15:19 +0000 | [diff] [blame] | 254 | if (!msg) |
| 255 | return -ENOMEM; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 256 | INIT_LIST_HEAD(&msg->list); |
| 257 | msg->call_struct.func = func; |
| 258 | msg->call_struct.info = info; |
| 259 | msg->call_struct.wait = wait; |
| 260 | msg->call_struct.pending = callmap; |
| 261 | msg->call_struct.waitmask = callmap; |
| 262 | msg->type = BFIN_IPI_CALL_FUNC; |
| 263 | |
| 264 | msg_queue = &per_cpu(ipi_msg_queue, cpu); |
| 265 | spin_lock_irqsave(&msg_queue->lock, flags); |
Sonic Zhang | 86f2008 | 2009-06-10 08:42:41 +0000 | [diff] [blame] | 266 | list_add_tail(&msg->list, &msg_queue->head); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 267 | spin_unlock_irqrestore(&msg_queue->lock, flags); |
| 268 | platform_send_ipi_cpu(cpu); |
| 269 | |
| 270 | if (wait) { |
| 271 | while (!cpus_empty(msg->call_struct.waitmask)) |
| 272 | blackfin_dcache_invalidate_range( |
| 273 | (unsigned long)(&msg->call_struct.waitmask), |
| 274 | (unsigned long)(&msg->call_struct.waitmask)); |
Yi Li | c9784eb | 2009-12-04 06:56:21 +0000 | [diff] [blame] | 275 | #ifdef __ARCH_SYNC_CORE_DCACHE |
| 276 | /* |
| 277 | * Invalidate D cache in case shared data was changed by |
| 278 | * other processors to ensure cache coherence. |
| 279 | */ |
| 280 | resync_core_dcache(); |
| 281 | #endif |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 282 | kfree(msg); |
| 283 | } |
| 284 | return 0; |
| 285 | } |
| 286 | EXPORT_SYMBOL_GPL(smp_call_function_single); |
| 287 | |
| 288 | void smp_send_reschedule(int cpu) |
| 289 | { |
| 290 | unsigned long flags; |
| 291 | struct ipi_message_queue *msg_queue; |
| 292 | struct ipi_message *msg; |
| 293 | |
| 294 | if (cpu_is_offline(cpu)) |
| 295 | return; |
| 296 | |
Roel Kluin | 05bad36 | 2009-11-21 19:35:58 +0100 | [diff] [blame] | 297 | msg = kzalloc(sizeof(*msg), GFP_ATOMIC); |
Julia Lawall | 994e9a2 | 2009-07-14 03:15:19 +0000 | [diff] [blame] | 298 | if (!msg) |
| 299 | return; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 300 | INIT_LIST_HEAD(&msg->list); |
| 301 | msg->type = BFIN_IPI_RESCHEDULE; |
| 302 | |
| 303 | msg_queue = &per_cpu(ipi_msg_queue, cpu); |
| 304 | spin_lock_irqsave(&msg_queue->lock, flags); |
Sonic Zhang | 86f2008 | 2009-06-10 08:42:41 +0000 | [diff] [blame] | 305 | list_add_tail(&msg->list, &msg_queue->head); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 306 | spin_unlock_irqrestore(&msg_queue->lock, flags); |
| 307 | platform_send_ipi_cpu(cpu); |
| 308 | |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | void smp_send_stop(void) |
| 313 | { |
| 314 | unsigned int cpu; |
| 315 | cpumask_t callmap; |
| 316 | unsigned long flags; |
| 317 | struct ipi_message_queue *msg_queue; |
| 318 | struct ipi_message *msg; |
| 319 | |
| 320 | callmap = cpu_online_map; |
| 321 | cpu_clear(smp_processor_id(), callmap); |
| 322 | if (cpus_empty(callmap)) |
| 323 | return; |
| 324 | |
Roel Kluin | 05bad36 | 2009-11-21 19:35:58 +0100 | [diff] [blame] | 325 | msg = kzalloc(sizeof(*msg), GFP_ATOMIC); |
Julia Lawall | 994e9a2 | 2009-07-14 03:15:19 +0000 | [diff] [blame] | 326 | if (!msg) |
| 327 | return; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 328 | INIT_LIST_HEAD(&msg->list); |
| 329 | msg->type = BFIN_IPI_CPU_STOP; |
| 330 | |
| 331 | for_each_cpu_mask(cpu, callmap) { |
| 332 | msg_queue = &per_cpu(ipi_msg_queue, cpu); |
| 333 | spin_lock_irqsave(&msg_queue->lock, flags); |
Sonic Zhang | 86f2008 | 2009-06-10 08:42:41 +0000 | [diff] [blame] | 334 | list_add_tail(&msg->list, &msg_queue->head); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 335 | spin_unlock_irqrestore(&msg_queue->lock, flags); |
| 336 | platform_send_ipi_cpu(cpu); |
| 337 | } |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | int __cpuinit __cpu_up(unsigned int cpu) |
| 342 | { |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 343 | int ret; |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 344 | static struct task_struct *idle; |
| 345 | |
| 346 | if (idle) |
| 347 | free_task(idle); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 348 | |
| 349 | idle = fork_idle(cpu); |
| 350 | if (IS_ERR(idle)) { |
| 351 | printk(KERN_ERR "CPU%u: fork() failed\n", cpu); |
| 352 | return PTR_ERR(idle); |
| 353 | } |
| 354 | |
| 355 | secondary_stack = task_stack_page(idle) + THREAD_SIZE; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 356 | |
| 357 | ret = platform_boot_secondary(cpu, idle); |
| 358 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 359 | secondary_stack = NULL; |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | static void __cpuinit setup_secondary(unsigned int cpu) |
| 365 | { |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 366 | unsigned long ilat; |
| 367 | |
| 368 | bfin_write_IMASK(0); |
| 369 | CSYNC(); |
| 370 | ilat = bfin_read_ILAT(); |
| 371 | CSYNC(); |
| 372 | bfin_write_ILAT(ilat); |
| 373 | CSYNC(); |
| 374 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 375 | /* Enable interrupt levels IVG7-15. IARs have been already |
| 376 | * programmed by the boot CPU. */ |
Mike Frysinger | 4005978 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 377 | bfin_irq_flags |= IMASK_IVG15 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 378 | IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 | |
| 379 | IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void __cpuinit secondary_start_kernel(void) |
| 383 | { |
| 384 | unsigned int cpu = smp_processor_id(); |
| 385 | struct mm_struct *mm = &init_mm; |
| 386 | |
| 387 | if (_bfin_swrst & SWRST_DBL_FAULT_B) { |
| 388 | printk(KERN_EMERG "CoreB Recovering from DOUBLE FAULT event\n"); |
| 389 | #ifdef CONFIG_DEBUG_DOUBLEFAULT |
| 390 | printk(KERN_EMERG " While handling exception (EXCAUSE = 0x%x) at %pF\n", |
| 391 | (int)init_saved_seqstat_coreb & SEQSTAT_EXCAUSE, init_saved_retx_coreb); |
| 392 | printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr_coreb); |
| 393 | printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr_coreb); |
| 394 | #endif |
| 395 | printk(KERN_NOTICE " The instruction at %pF caused a double exception\n", |
| 396 | init_retx_coreb); |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * We want the D-cache to be enabled early, in case the atomic |
| 401 | * support code emulates cache coherence (see |
| 402 | * __ARCH_SYNC_CORE_DCACHE). |
| 403 | */ |
| 404 | init_exception_vectors(); |
| 405 | |
| 406 | bfin_setup_caches(cpu); |
| 407 | |
| 408 | local_irq_disable(); |
| 409 | |
| 410 | /* Attach the new idle task to the global mm. */ |
| 411 | atomic_inc(&mm->mm_users); |
| 412 | atomic_inc(&mm->mm_count); |
| 413 | current->active_mm = mm; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 414 | |
| 415 | preempt_disable(); |
| 416 | |
| 417 | setup_secondary(cpu); |
| 418 | |
Yi Li | 578d36f | 2009-12-02 07:58:12 +0000 | [diff] [blame] | 419 | platform_secondary_init(cpu); |
| 420 | |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 421 | /* setup local core timer */ |
| 422 | bfin_local_timer_setup(); |
| 423 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 424 | local_irq_enable(); |
| 425 | |
Yi Li | 578d36f | 2009-12-02 07:58:12 +0000 | [diff] [blame] | 426 | /* |
| 427 | * Calibrate loops per jiffy value. |
| 428 | * IRQs need to be enabled here - D-cache can be invalidated |
| 429 | * in timer irq handler, so core B can read correct jiffies. |
| 430 | */ |
| 431 | calibrate_delay(); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 432 | |
| 433 | cpu_idle(); |
| 434 | } |
| 435 | |
| 436 | void __init smp_prepare_boot_cpu(void) |
| 437 | { |
| 438 | } |
| 439 | |
| 440 | void __init smp_prepare_cpus(unsigned int max_cpus) |
| 441 | { |
| 442 | platform_prepare_cpus(max_cpus); |
| 443 | ipi_queue_init(); |
| 444 | platform_request_ipi(&ipi_handler); |
| 445 | } |
| 446 | |
| 447 | void __init smp_cpus_done(unsigned int max_cpus) |
| 448 | { |
| 449 | unsigned long bogosum = 0; |
| 450 | unsigned int cpu; |
| 451 | |
| 452 | for_each_online_cpu(cpu) |
Michael Hennerich | c70c754 | 2009-07-09 09:58:52 +0000 | [diff] [blame] | 453 | bogosum += loops_per_jiffy; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 454 | |
| 455 | printk(KERN_INFO "SMP: Total of %d processors activated " |
| 456 | "(%lu.%02lu BogoMIPS).\n", |
| 457 | num_online_cpus(), |
| 458 | bogosum / (500000/HZ), |
| 459 | (bogosum / (5000/HZ)) % 100); |
| 460 | } |
| 461 | |
| 462 | void smp_icache_flush_range_others(unsigned long start, unsigned long end) |
| 463 | { |
| 464 | smp_flush_data.start = start; |
| 465 | smp_flush_data.end = end; |
| 466 | |
Sonic Zhang | 0bf3d93 | 2009-03-05 16:44:53 +0800 | [diff] [blame] | 467 | if (smp_call_function(&ipi_flush_icache, &smp_flush_data, 0)) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 468 | printk(KERN_WARNING "SMP: failed to run I-cache flush request on other CPUs\n"); |
| 469 | } |
| 470 | EXPORT_SYMBOL_GPL(smp_icache_flush_range_others); |
| 471 | |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 472 | #ifdef __ARCH_SYNC_CORE_ICACHE |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 473 | unsigned long icache_invld_count[NR_CPUS]; |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 474 | void resync_core_icache(void) |
| 475 | { |
| 476 | unsigned int cpu = get_cpu(); |
| 477 | blackfin_invalidate_entire_icache(); |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 478 | icache_invld_count[cpu]++; |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 479 | put_cpu(); |
| 480 | } |
| 481 | EXPORT_SYMBOL(resync_core_icache); |
| 482 | #endif |
| 483 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 484 | #ifdef __ARCH_SYNC_CORE_DCACHE |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 485 | unsigned long dcache_invld_count[NR_CPUS]; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 486 | unsigned long barrier_mask __attribute__ ((__section__(".l2.bss"))); |
| 487 | |
| 488 | void resync_core_dcache(void) |
| 489 | { |
| 490 | unsigned int cpu = get_cpu(); |
| 491 | blackfin_invalidate_entire_dcache(); |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 492 | dcache_invld_count[cpu]++; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 493 | put_cpu(); |
| 494 | } |
| 495 | EXPORT_SYMBOL(resync_core_dcache); |
| 496 | #endif |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 497 | |
| 498 | #ifdef CONFIG_HOTPLUG_CPU |
| 499 | int __cpuexit __cpu_disable(void) |
| 500 | { |
| 501 | unsigned int cpu = smp_processor_id(); |
| 502 | |
| 503 | if (cpu == 0) |
| 504 | return -EPERM; |
| 505 | |
| 506 | set_cpu_online(cpu, false); |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static DECLARE_COMPLETION(cpu_killed); |
| 511 | |
| 512 | int __cpuexit __cpu_die(unsigned int cpu) |
| 513 | { |
| 514 | return wait_for_completion_timeout(&cpu_killed, 5000); |
| 515 | } |
| 516 | |
| 517 | void cpu_die(void) |
| 518 | { |
| 519 | complete(&cpu_killed); |
| 520 | |
| 521 | atomic_dec(&init_mm.mm_users); |
| 522 | atomic_dec(&init_mm.mm_count); |
| 523 | |
| 524 | local_irq_disable(); |
| 525 | platform_cpu_die(); |
| 526 | } |
| 527 | #endif |