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