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 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 49 | struct blackfin_initial_pda initial_pda_coreb; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 50 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 51 | enum ipi_message_type { |
Steven Miao | 150382a | 2013-07-09 15:39:53 +0800 | [diff] [blame] | 52 | BFIN_IPI_NONE, |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 53 | BFIN_IPI_TIMER, |
| 54 | BFIN_IPI_RESCHEDULE, |
| 55 | BFIN_IPI_CALL_FUNC, |
| 56 | BFIN_IPI_CALL_FUNC_SINGLE, |
| 57 | BFIN_IPI_CPU_STOP, |
| 58 | }; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 59 | |
| 60 | struct blackfin_flush_data { |
| 61 | unsigned long start; |
| 62 | unsigned long end; |
| 63 | }; |
| 64 | |
| 65 | void *secondary_stack; |
| 66 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 67 | static struct blackfin_flush_data smp_flush_data; |
| 68 | |
| 69 | static DEFINE_SPINLOCK(stop_lock); |
| 70 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 71 | /* A magic number - stress test shows this is safe for common cases */ |
| 72 | #define BFIN_IPI_MSGQ_LEN 5 |
| 73 | |
| 74 | /* Simple FIFO buffer, overflow leads to panic */ |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 75 | struct ipi_data { |
Steven Miao | 150382a | 2013-07-09 15:39:53 +0800 | [diff] [blame] | 76 | atomic_t count; |
| 77 | atomic_t bits; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 78 | }; |
| 79 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 80 | static DEFINE_PER_CPU(struct ipi_data, bfin_ipi); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 81 | |
| 82 | static void ipi_cpu_stop(unsigned int cpu) |
| 83 | { |
| 84 | spin_lock(&stop_lock); |
| 85 | printk(KERN_CRIT "CPU%u: stopping\n", cpu); |
| 86 | dump_stack(); |
| 87 | spin_unlock(&stop_lock); |
| 88 | |
KOSAKI Motohiro | fecedc80 | 2011-04-26 10:57:27 +0900 | [diff] [blame] | 89 | set_cpu_online(cpu, false); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 90 | |
| 91 | local_irq_disable(); |
| 92 | |
| 93 | while (1) |
| 94 | SSYNC(); |
| 95 | } |
| 96 | |
| 97 | static void ipi_flush_icache(void *info) |
| 98 | { |
| 99 | struct blackfin_flush_data *fdata = info; |
| 100 | |
| 101 | /* Invalidate the memory holding the bounds of the flushed region. */ |
Sonic Zhang | 8d50de9 | 2011-04-12 08:16:04 +0000 | [diff] [blame] | 102 | blackfin_dcache_invalidate_range((unsigned long)fdata, |
| 103 | (unsigned long)fdata + sizeof(*fdata)); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 104 | |
Sonic Zhang | 8d50de9 | 2011-04-12 08:16:04 +0000 | [diff] [blame] | 105 | /* Make sure all write buffers in the data side of the core |
| 106 | * are flushed before trying to invalidate the icache. This |
| 107 | * needs to be after the data flush and before the icache |
| 108 | * flush so that the SSYNC does the right thing in preventing |
| 109 | * the instruction prefetcher from hitting things in cached |
| 110 | * memory at the wrong time -- it runs much further ahead than |
| 111 | * the pipeline. |
| 112 | */ |
| 113 | SSYNC(); |
| 114 | |
| 115 | /* ipi_flaush_icache is invoked by generic flush_icache_range, |
| 116 | * so call blackfin arch icache flush directly here. |
| 117 | */ |
| 118 | blackfin_icache_flush_range(fdata->start, fdata->end); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 119 | } |
| 120 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 121 | /* Use IRQ_SUPPLE_0 to request reschedule. |
| 122 | * When returning from interrupt to user space, |
| 123 | * there is chance to reschedule */ |
| 124 | static irqreturn_t ipi_handler_int0(int irq, void *dev_instance) |
| 125 | { |
| 126 | unsigned int cpu = smp_processor_id(); |
| 127 | |
| 128 | platform_clear_ipi(cpu, IRQ_SUPPLE_0); |
| 129 | return IRQ_HANDLED; |
| 130 | } |
| 131 | |
Bob Liu | d0014be | 2011-12-12 11:04:05 +0800 | [diff] [blame] | 132 | DECLARE_PER_CPU(struct clock_event_device, coretmr_events); |
| 133 | void ipi_timer(void) |
| 134 | { |
| 135 | int cpu = smp_processor_id(); |
| 136 | struct clock_event_device *evt = &per_cpu(coretmr_events, cpu); |
| 137 | evt->event_handler(evt); |
| 138 | } |
| 139 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 140 | static irqreturn_t ipi_handler_int1(int irq, void *dev_instance) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 141 | { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 142 | struct ipi_data *bfin_ipi_data; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 143 | unsigned int cpu = smp_processor_id(); |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 144 | unsigned long pending; |
| 145 | unsigned long msg; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 146 | |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 147 | platform_clear_ipi(cpu, IRQ_SUPPLE_1); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 148 | |
Steven Miao | 177a48f | 2013-11-15 15:41:35 +0800 | [diff] [blame] | 149 | smp_rmb(); |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 150 | bfin_ipi_data = &__get_cpu_var(bfin_ipi); |
Steven Miao | 16fc5bc | 2013-07-16 13:25:21 +0800 | [diff] [blame] | 151 | while ((pending = atomic_xchg(&bfin_ipi_data->bits, 0)) != 0) { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 152 | msg = 0; |
| 153 | do { |
| 154 | msg = find_next_bit(&pending, BITS_PER_LONG, msg + 1); |
| 155 | switch (msg) { |
| 156 | case BFIN_IPI_TIMER: |
| 157 | ipi_timer(); |
| 158 | break; |
| 159 | case BFIN_IPI_RESCHEDULE: |
| 160 | scheduler_ipi(); |
| 161 | break; |
| 162 | case BFIN_IPI_CALL_FUNC: |
| 163 | generic_smp_call_function_interrupt(); |
| 164 | break; |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 165 | case BFIN_IPI_CALL_FUNC_SINGLE: |
| 166 | generic_smp_call_function_single_interrupt(); |
| 167 | break; |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 168 | case BFIN_IPI_CPU_STOP: |
| 169 | ipi_cpu_stop(cpu); |
| 170 | break; |
Steven Miao | 177a48f | 2013-11-15 15:41:35 +0800 | [diff] [blame] | 171 | default: |
| 172 | goto out; |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 173 | } |
Steven Miao | 150382a | 2013-07-09 15:39:53 +0800 | [diff] [blame] | 174 | atomic_dec(&bfin_ipi_data->count); |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 175 | } while (msg < BITS_PER_LONG); |
Steven Miao | 177a48f | 2013-11-15 15:41:35 +0800 | [diff] [blame] | 176 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 177 | } |
Steven Miao | 177a48f | 2013-11-15 15:41:35 +0800 | [diff] [blame] | 178 | out: |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 179 | return IRQ_HANDLED; |
| 180 | } |
| 181 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 182 | static void bfin_ipi_init(void) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 183 | { |
| 184 | unsigned int cpu; |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 185 | struct ipi_data *bfin_ipi_data; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 186 | for_each_possible_cpu(cpu) { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 187 | bfin_ipi_data = &per_cpu(bfin_ipi, cpu); |
Steven Miao | 16fc5bc | 2013-07-16 13:25:21 +0800 | [diff] [blame] | 188 | atomic_set(&bfin_ipi_data->bits, 0); |
| 189 | atomic_set(&bfin_ipi_data->count, 0); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 193 | void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 194 | { |
| 195 | unsigned int cpu; |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 196 | struct ipi_data *bfin_ipi_data; |
| 197 | unsigned long flags; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 198 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 199 | local_irq_save(flags); |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 200 | for_each_cpu(cpu, cpumask) { |
| 201 | bfin_ipi_data = &per_cpu(bfin_ipi, cpu); |
Steven Miao | 150382a | 2013-07-09 15:39:53 +0800 | [diff] [blame] | 202 | atomic_set_mask((1 << msg), &bfin_ipi_data->bits); |
| 203 | atomic_inc(&bfin_ipi_data->count); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 204 | } |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 205 | local_irq_restore(flags); |
Steven Miao | 177a48f | 2013-11-15 15:41:35 +0800 | [diff] [blame] | 206 | smp_wmb(); |
| 207 | for_each_cpu(cpu, cpumask) |
| 208 | platform_send_ipi_cpu(cpu, IRQ_SUPPLE_1); |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 211 | void arch_send_call_function_single_ipi(int cpu) |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 212 | { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 213 | send_ipi(cpumask_of(cpu), BFIN_IPI_CALL_FUNC_SINGLE); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 214 | } |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 215 | |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 216 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 217 | { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 218 | send_ipi(mask, BFIN_IPI_CALL_FUNC); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 219 | } |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 220 | |
| 221 | void smp_send_reschedule(int cpu) |
| 222 | { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 223 | send_ipi(cpumask_of(cpu), BFIN_IPI_RESCHEDULE); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 224 | |
| 225 | return; |
| 226 | } |
| 227 | |
Bob Liu | d0014be | 2011-12-12 11:04:05 +0800 | [diff] [blame] | 228 | void smp_send_msg(const struct cpumask *mask, unsigned long type) |
| 229 | { |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 230 | send_ipi(mask, type); |
Bob Liu | d0014be | 2011-12-12 11:04:05 +0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void smp_timer_broadcast(const struct cpumask *mask) |
| 234 | { |
| 235 | smp_send_msg(mask, BFIN_IPI_TIMER); |
| 236 | } |
| 237 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 238 | void smp_send_stop(void) |
| 239 | { |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 240 | cpumask_t callmap; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 241 | |
Sonic Zhang | 567ebfc | 2010-06-25 05:55:16 +0000 | [diff] [blame] | 242 | preempt_disable(); |
KOSAKI Motohiro | fecedc80 | 2011-04-26 10:57:27 +0900 | [diff] [blame] | 243 | cpumask_copy(&callmap, cpu_online_mask); |
| 244 | cpumask_clear_cpu(smp_processor_id(), &callmap); |
| 245 | if (!cpumask_empty(&callmap)) |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 246 | send_ipi(&callmap, BFIN_IPI_CPU_STOP); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 247 | |
Sonic Zhang | 567ebfc | 2010-06-25 05:55:16 +0000 | [diff] [blame] | 248 | preempt_enable(); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 249 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 253 | int __cpu_up(unsigned int cpu, struct task_struct *idle) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 254 | { |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 255 | int ret; |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 256 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 257 | secondary_stack = task_stack_page(idle) + THREAD_SIZE; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 258 | |
| 259 | ret = platform_boot_secondary(cpu, idle); |
| 260 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 261 | secondary_stack = NULL; |
| 262 | |
| 263 | return ret; |
| 264 | } |
| 265 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 266 | static void setup_secondary(unsigned int cpu) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 267 | { |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 268 | unsigned long ilat; |
| 269 | |
| 270 | bfin_write_IMASK(0); |
| 271 | CSYNC(); |
| 272 | ilat = bfin_read_ILAT(); |
| 273 | CSYNC(); |
| 274 | bfin_write_ILAT(ilat); |
| 275 | CSYNC(); |
| 276 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 277 | /* Enable interrupt levels IVG7-15. IARs have been already |
| 278 | * programmed by the boot CPU. */ |
Mike Frysinger | 4005978 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 279 | bfin_irq_flags |= IMASK_IVG15 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 280 | IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 | |
| 281 | IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 282 | } |
| 283 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 284 | void secondary_start_kernel(void) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 285 | { |
| 286 | unsigned int cpu = smp_processor_id(); |
| 287 | struct mm_struct *mm = &init_mm; |
| 288 | |
| 289 | if (_bfin_swrst & SWRST_DBL_FAULT_B) { |
| 290 | printk(KERN_EMERG "CoreB Recovering from DOUBLE FAULT event\n"); |
| 291 | #ifdef CONFIG_DEBUG_DOUBLEFAULT |
Mike Frysinger | fb1d9be | 2011-05-29 23:12:51 -0400 | [diff] [blame] | 292 | printk(KERN_EMERG " While handling exception (EXCAUSE = %#x) at %pF\n", |
| 293 | initial_pda_coreb.seqstat_doublefault & SEQSTAT_EXCAUSE, |
| 294 | initial_pda_coreb.retx_doublefault); |
| 295 | printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n", |
| 296 | initial_pda_coreb.dcplb_doublefault_addr); |
| 297 | printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n", |
| 298 | initial_pda_coreb.icplb_doublefault_addr); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 299 | #endif |
| 300 | printk(KERN_NOTICE " The instruction at %pF caused a double exception\n", |
Mike Frysinger | fb1d9be | 2011-05-29 23:12:51 -0400 | [diff] [blame] | 301 | initial_pda_coreb.retx); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* |
| 305 | * We want the D-cache to be enabled early, in case the atomic |
| 306 | * support code emulates cache coherence (see |
| 307 | * __ARCH_SYNC_CORE_DCACHE). |
| 308 | */ |
| 309 | init_exception_vectors(); |
| 310 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 311 | local_irq_disable(); |
| 312 | |
| 313 | /* Attach the new idle task to the global mm. */ |
| 314 | atomic_inc(&mm->mm_users); |
| 315 | atomic_inc(&mm->mm_count); |
| 316 | current->active_mm = mm; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 317 | |
| 318 | preempt_disable(); |
| 319 | |
| 320 | setup_secondary(cpu); |
| 321 | |
Yi Li | 578d36f | 2009-12-02 07:58:12 +0000 | [diff] [blame] | 322 | platform_secondary_init(cpu); |
Yi Li | 0d152c2 | 2009-12-28 10:21:49 +0000 | [diff] [blame] | 323 | /* setup local core timer */ |
| 324 | bfin_local_timer_setup(); |
| 325 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 326 | local_irq_enable(); |
| 327 | |
steven miao | ab61d2a | 2010-09-07 10:08:36 +0000 | [diff] [blame] | 328 | bfin_setup_caches(cpu); |
| 329 | |
Bob Liu | d0014be | 2011-12-12 11:04:05 +0800 | [diff] [blame] | 330 | notify_cpu_starting(cpu); |
Yi Li | 578d36f | 2009-12-02 07:58:12 +0000 | [diff] [blame] | 331 | /* |
| 332 | * Calibrate loops per jiffy value. |
| 333 | * IRQs need to be enabled here - D-cache can be invalidated |
| 334 | * in timer irq handler, so core B can read correct jiffies. |
| 335 | */ |
| 336 | calibrate_delay(); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 337 | |
Steven Miao | 150382a | 2013-07-09 15:39:53 +0800 | [diff] [blame] | 338 | /* We are done with local CPU inits, unblock the boot CPU. */ |
| 339 | set_cpu_online(cpu, true); |
Thomas Gleixner | 25d67f8 | 2013-03-21 22:49:41 +0100 | [diff] [blame] | 340 | cpu_startup_entry(CPUHP_ONLINE); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void __init smp_prepare_boot_cpu(void) |
| 344 | { |
| 345 | } |
| 346 | |
| 347 | void __init smp_prepare_cpus(unsigned int max_cpus) |
| 348 | { |
| 349 | platform_prepare_cpus(max_cpus); |
Steven Miao | 5088846 | 2012-07-31 17:28:10 +0800 | [diff] [blame] | 350 | bfin_ipi_init(); |
Yi Li | 73a4006 | 2009-12-17 08:20:32 +0000 | [diff] [blame] | 351 | platform_request_ipi(IRQ_SUPPLE_0, ipi_handler_int0); |
| 352 | platform_request_ipi(IRQ_SUPPLE_1, ipi_handler_int1); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void __init smp_cpus_done(unsigned int max_cpus) |
| 356 | { |
| 357 | unsigned long bogosum = 0; |
| 358 | unsigned int cpu; |
| 359 | |
| 360 | for_each_online_cpu(cpu) |
Michael Hennerich | c70c754 | 2009-07-09 09:58:52 +0000 | [diff] [blame] | 361 | bogosum += loops_per_jiffy; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 362 | |
| 363 | printk(KERN_INFO "SMP: Total of %d processors activated " |
| 364 | "(%lu.%02lu BogoMIPS).\n", |
| 365 | num_online_cpus(), |
| 366 | bogosum / (500000/HZ), |
| 367 | (bogosum / (5000/HZ)) % 100); |
| 368 | } |
| 369 | |
| 370 | void smp_icache_flush_range_others(unsigned long start, unsigned long end) |
| 371 | { |
| 372 | smp_flush_data.start = start; |
| 373 | smp_flush_data.end = end; |
| 374 | |
Steven Miao | a2eff9d | 2011-11-25 14:25:30 +0800 | [diff] [blame] | 375 | preempt_disable(); |
| 376 | if (smp_call_function(&ipi_flush_icache, &smp_flush_data, 1)) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 377 | printk(KERN_WARNING "SMP: failed to run I-cache flush request on other CPUs\n"); |
Steven Miao | a2eff9d | 2011-11-25 14:25:30 +0800 | [diff] [blame] | 378 | preempt_enable(); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 379 | } |
| 380 | EXPORT_SYMBOL_GPL(smp_icache_flush_range_others); |
| 381 | |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 382 | #ifdef __ARCH_SYNC_CORE_ICACHE |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 383 | unsigned long icache_invld_count[NR_CPUS]; |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 384 | void resync_core_icache(void) |
| 385 | { |
| 386 | unsigned int cpu = get_cpu(); |
| 387 | blackfin_invalidate_entire_icache(); |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 388 | icache_invld_count[cpu]++; |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 389 | put_cpu(); |
| 390 | } |
| 391 | EXPORT_SYMBOL(resync_core_icache); |
| 392 | #endif |
| 393 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 394 | #ifdef __ARCH_SYNC_CORE_DCACHE |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 395 | unsigned long dcache_invld_count[NR_CPUS]; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 396 | unsigned long barrier_mask __attribute__ ((__section__(".l2.bss"))); |
| 397 | |
| 398 | void resync_core_dcache(void) |
| 399 | { |
| 400 | unsigned int cpu = get_cpu(); |
| 401 | blackfin_invalidate_entire_dcache(); |
Graf Yang | 718340f | 2010-02-01 06:07:50 +0000 | [diff] [blame] | 402 | dcache_invld_count[cpu]++; |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 403 | put_cpu(); |
| 404 | } |
| 405 | EXPORT_SYMBOL(resync_core_dcache); |
| 406 | #endif |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 407 | |
| 408 | #ifdef CONFIG_HOTPLUG_CPU |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 409 | int __cpu_disable(void) |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 410 | { |
| 411 | unsigned int cpu = smp_processor_id(); |
| 412 | |
| 413 | if (cpu == 0) |
| 414 | return -EPERM; |
| 415 | |
| 416 | set_cpu_online(cpu, false); |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static DECLARE_COMPLETION(cpu_killed); |
| 421 | |
Paul Gortmaker | 13dff62 | 2013-06-18 16:56:21 -0400 | [diff] [blame] | 422 | int __cpu_die(unsigned int cpu) |
Graf Yang | 0b39db2 | 2009-12-28 11:13:51 +0000 | [diff] [blame] | 423 | { |
| 424 | return wait_for_completion_timeout(&cpu_killed, 5000); |
| 425 | } |
| 426 | |
| 427 | void cpu_die(void) |
| 428 | { |
| 429 | complete(&cpu_killed); |
| 430 | |
| 431 | atomic_dec(&init_mm.mm_users); |
| 432 | atomic_dec(&init_mm.mm_count); |
| 433 | |
| 434 | local_irq_disable(); |
| 435 | platform_cpu_die(); |
| 436 | } |
| 437 | #endif |