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