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