blob: 00bbe672b3b308433445d39461637f3a0d396573 [file] [log] [blame]
Graf Yang6b3087c2009-01-07 23:14:39 +08001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * IPI management based on arch/arm/kernel/smp.c (Copyright 2002 ARM Limited)
Graf Yang6b3087c2009-01-07 23:14:39 +08003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Copyright 2007-2009 Analog Devices Inc.
5 * Philippe Gerum <rpm@xenomai.org>
Graf Yang6b3087c2009-01-07 23:14:39 +08006 *
Robin Getz96f10502009-09-24 14:11:24 +00007 * Licensed under the GPL-2.
Graf Yang6b3087c2009-01-07 23:14:39 +08008 */
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 Liud0014be2011-12-12 11:04:05 +080017#include <linux/clockchips.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080018#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 Yang9c199b52009-09-21 11:51:31 +000023#include <linux/cpumask.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080024#include <linux/seq_file.h>
25#include <linux/irq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Arun Sharma600634972011-07-26 16:09:06 -070027#include <linux/atomic.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080028#include <asm/cacheflush.h>
Mike Frysinger6327a572011-04-15 03:06:59 -040029#include <asm/irq_handler.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080030#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 Yang1fa9be72009-05-15 11:01:59 +000036#include <asm/time.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080037#include <linux/err.h>
38
Graf Yang555487b2009-05-06 10:38:07 +000039/*
40 * Anomaly notes:
41 * 05000120 - we always define corelock as 32-bit integer in L2
42 */
Graf Yang6b3087c2009-01-07 23:14:39 +080043struct corelock_slot corelock __attribute__ ((__section__(".l2.bss")));
44
Sonic Zhangc6345ab2010-08-05 07:49:26 +000045#ifdef CONFIG_ICACHE_FLUSH_L1
46unsigned long blackfin_iflush_l1_entry[NR_CPUS];
47#endif
48
Mike Frysingerfb1d9be2011-05-29 23:12:51 -040049struct blackfin_initial_pda __cpuinitdata initial_pda_coreb;
Graf Yang6b3087c2009-01-07 23:14:39 +080050
Bob Liud0014be2011-12-12 11:04:05 +080051#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 Yang6b3087c2009-01-07 23:14:39 +080055
56struct blackfin_flush_data {
57 unsigned long start;
58 unsigned long end;
59};
60
61void *secondary_stack;
62
63
64struct smp_call_struct {
65 void (*func)(void *info);
66 void *info;
67 int wait;
Yi Li73a40062009-12-17 08:20:32 +000068 cpumask_t *waitmask;
Graf Yang6b3087c2009-01-07 23:14:39 +080069};
70
71static struct blackfin_flush_data smp_flush_data;
72
73static DEFINE_SPINLOCK(stop_lock);
74
75struct ipi_message {
Graf Yang6b3087c2009-01-07 23:14:39 +080076 unsigned long type;
77 struct smp_call_struct call_struct;
78};
79
Yi Li73a40062009-12-17 08:20:32 +000080/* 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 Yang6b3087c2009-01-07 23:14:39 +080084struct ipi_message_queue {
Graf Yang6b3087c2009-01-07 23:14:39 +080085 spinlock_t lock;
86 unsigned long count;
Yi Li73a40062009-12-17 08:20:32 +000087 unsigned long head; /* head of the queue */
88 struct ipi_message ipi_message[BFIN_IPI_MSGQ_LEN];
Graf Yang6b3087c2009-01-07 23:14:39 +080089};
90
91static DEFINE_PER_CPU(struct ipi_message_queue, ipi_msg_queue);
92
93static 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 Motohirofecedc802011-04-26 10:57:27 +0900100 set_cpu_online(cpu, false);
Graf Yang6b3087c2009-01-07 23:14:39 +0800101
102 local_irq_disable();
103
104 while (1)
105 SSYNC();
106}
107
108static 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 Zhang8d50de92011-04-12 08:16:04 +0000113 blackfin_dcache_invalidate_range((unsigned long)fdata,
114 (unsigned long)fdata + sizeof(*fdata));
Graf Yang6b3087c2009-01-07 23:14:39 +0800115
Sonic Zhang8d50de92011-04-12 08:16:04 +0000116 /* 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 Yang6b3087c2009-01-07 23:14:39 +0800130}
131
132static 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 Yang6b3087c2009-01-07 23:14:39 +0800140 func(info);
Yi Lic9784eb2009-12-04 06:56:21 +0000141 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 Motohirofecedc802011-04-26 10:57:27 +0900150 cpumask_clear_cpu(cpu, msg->call_struct.waitmask);
Yi Li73a40062009-12-17 08:20:32 +0000151 }
Graf Yang6b3087c2009-01-07 23:14:39 +0800152}
153
Yi Li73a40062009-12-17 08:20:32 +0000154/* Use IRQ_SUPPLE_0 to request reschedule.
155 * When returning from interrupt to user space,
156 * there is chance to reschedule */
157static 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 Liud0014be2011-12-12 11:04:05 +0800165DECLARE_PER_CPU(struct clock_event_device, coretmr_events);
166void 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 Li73a40062009-12-17 08:20:32 +0000173static irqreturn_t ipi_handler_int1(int irq, void *dev_instance)
Graf Yang6b3087c2009-01-07 23:14:39 +0800174{
Sonic Zhang86f20082009-06-10 08:42:41 +0000175 struct ipi_message *msg;
Graf Yang6b3087c2009-01-07 23:14:39 +0800176 struct ipi_message_queue *msg_queue;
177 unsigned int cpu = smp_processor_id();
Yi Li73a40062009-12-17 08:20:32 +0000178 unsigned long flags;
Graf Yang6b3087c2009-01-07 23:14:39 +0800179
Yi Li73a40062009-12-17 08:20:32 +0000180 platform_clear_ipi(cpu, IRQ_SUPPLE_1);
Graf Yang6b3087c2009-01-07 23:14:39 +0800181
182 msg_queue = &__get_cpu_var(ipi_msg_queue);
Graf Yang6b3087c2009-01-07 23:14:39 +0800183
Yi Li73a40062009-12-17 08:20:32 +0000184 spin_lock_irqsave(&msg_queue->lock, flags);
185
186 while (msg_queue->count) {
187 msg = &msg_queue->ipi_message[msg_queue->head];
Graf Yang6b3087c2009-01-07 23:14:39 +0800188 switch (msg->type) {
Bob Liud0014be2011-12-12 11:04:05 +0800189 case BFIN_IPI_TIMER:
190 ipi_timer();
191 break;
Peter Zijlstra184748c2011-04-05 17:23:39 +0200192 case BFIN_IPI_RESCHEDULE:
193 scheduler_ipi();
194 break;
Graf Yang6b3087c2009-01-07 23:14:39 +0800195 case BFIN_IPI_CALL_FUNC:
196 ipi_call_function(cpu, msg);
197 break;
198 case BFIN_IPI_CPU_STOP:
199 ipi_cpu_stop(cpu);
Graf Yang6b3087c2009-01-07 23:14:39 +0800200 break;
201 default:
Joe Perchesdb52ecc2010-03-26 19:27:51 -0700202 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%lx\n",
203 cpu, msg->type);
Graf Yang6b3087c2009-01-07 23:14:39 +0800204 break;
205 }
Yi Li73a40062009-12-17 08:20:32 +0000206 msg_queue->head++;
207 msg_queue->head %= BFIN_IPI_MSGQ_LEN;
208 msg_queue->count--;
Graf Yang6b3087c2009-01-07 23:14:39 +0800209 }
Yi Li73a40062009-12-17 08:20:32 +0000210 spin_unlock_irqrestore(&msg_queue->lock, flags);
Graf Yang6b3087c2009-01-07 23:14:39 +0800211 return IRQ_HANDLED;
212}
213
214static void ipi_queue_init(void)
215{
216 unsigned int cpu;
217 struct ipi_message_queue *msg_queue;
218 for_each_possible_cpu(cpu) {
219 msg_queue = &per_cpu(ipi_msg_queue, cpu);
Graf Yang6b3087c2009-01-07 23:14:39 +0800220 spin_lock_init(&msg_queue->lock);
221 msg_queue->count = 0;
Yi Li73a40062009-12-17 08:20:32 +0000222 msg_queue->head = 0;
Graf Yang6b3087c2009-01-07 23:14:39 +0800223 }
224}
225
Yi Li73a40062009-12-17 08:20:32 +0000226static inline void smp_send_message(cpumask_t callmap, unsigned long type,
227 void (*func) (void *info), void *info, int wait)
Graf Yang6b3087c2009-01-07 23:14:39 +0800228{
229 unsigned int cpu;
Graf Yang6b3087c2009-01-07 23:14:39 +0800230 struct ipi_message_queue *msg_queue;
231 struct ipi_message *msg;
Yi Li73a40062009-12-17 08:20:32 +0000232 unsigned long flags, next_msg;
KOSAKI Motohirofecedc802011-04-26 10:57:27 +0900233 cpumask_t waitmask; /* waitmask is shared by all cpus */
Graf Yang6b3087c2009-01-07 23:14:39 +0800234
KOSAKI Motohirofecedc802011-04-26 10:57:27 +0900235 cpumask_copy(&waitmask, &callmap);
236 for_each_cpu(cpu, &callmap) {
Graf Yang6b3087c2009-01-07 23:14:39 +0800237 msg_queue = &per_cpu(ipi_msg_queue, cpu);
238 spin_lock_irqsave(&msg_queue->lock, flags);
Yi Li73a40062009-12-17 08:20:32 +0000239 if (msg_queue->count < BFIN_IPI_MSGQ_LEN) {
240 next_msg = (msg_queue->head + msg_queue->count)
241 % BFIN_IPI_MSGQ_LEN;
242 msg = &msg_queue->ipi_message[next_msg];
243 msg->type = type;
244 if (type == BFIN_IPI_CALL_FUNC) {
245 msg->call_struct.func = func;
246 msg->call_struct.info = info;
247 msg->call_struct.wait = wait;
248 msg->call_struct.waitmask = &waitmask;
249 }
250 msg_queue->count++;
251 } else
252 panic("IPI message queue overflow\n");
Graf Yang6b3087c2009-01-07 23:14:39 +0800253 spin_unlock_irqrestore(&msg_queue->lock, flags);
Yi Li73a40062009-12-17 08:20:32 +0000254 platform_send_ipi_cpu(cpu, IRQ_SUPPLE_1);
Graf Yang6b3087c2009-01-07 23:14:39 +0800255 }
Yi Li73a40062009-12-17 08:20:32 +0000256
Graf Yang6b3087c2009-01-07 23:14:39 +0800257 if (wait) {
KOSAKI Motohirofecedc802011-04-26 10:57:27 +0900258 while (!cpumask_empty(&waitmask))
Graf Yang6b3087c2009-01-07 23:14:39 +0800259 blackfin_dcache_invalidate_range(
Yi Li73a40062009-12-17 08:20:32 +0000260 (unsigned long)(&waitmask),
261 (unsigned long)(&waitmask));
Yi Lic9784eb2009-12-04 06:56:21 +0000262#ifdef __ARCH_SYNC_CORE_DCACHE
263 /*
264 * Invalidate D cache in case shared data was changed by
265 * other processors to ensure cache coherence.
266 */
267 resync_core_dcache();
268#endif
Graf Yang6b3087c2009-01-07 23:14:39 +0800269 }
Yi Li73a40062009-12-17 08:20:32 +0000270}
271
272int smp_call_function(void (*func)(void *info), void *info, int wait)
273{
274 cpumask_t callmap;
275
Sonic Zhang567ebfc2010-06-25 05:55:16 +0000276 preempt_disable();
KOSAKI Motohirofecedc802011-04-26 10:57:27 +0900277 cpumask_copy(&callmap, cpu_online_mask);
278 cpumask_clear_cpu(smp_processor_id(), &callmap);
279 if (!cpumask_empty(&callmap))
Sonic Zhang567ebfc2010-06-25 05:55:16 +0000280 smp_send_message(callmap, BFIN_IPI_CALL_FUNC, func, info, wait);
Yi Li73a40062009-12-17 08:20:32 +0000281
Sonic Zhang567ebfc2010-06-25 05:55:16 +0000282 preempt_enable();
Yi Li73a40062009-12-17 08:20:32 +0000283
Graf Yang6b3087c2009-01-07 23:14:39 +0800284 return 0;
285}
286EXPORT_SYMBOL_GPL(smp_call_function);
287
288int smp_call_function_single(int cpuid, void (*func) (void *info), void *info,
289 int wait)
290{
291 unsigned int cpu = cpuid;
292 cpumask_t callmap;
Graf Yang6b3087c2009-01-07 23:14:39 +0800293
294 if (cpu_is_offline(cpu))
295 return 0;
KOSAKI Motohirofecedc802011-04-26 10:57:27 +0900296 cpumask_clear(&callmap);
297 cpumask_set_cpu(cpu, &callmap);
Graf Yang6b3087c2009-01-07 23:14:39 +0800298
Yi Li73a40062009-12-17 08:20:32 +0000299 smp_send_message(callmap, BFIN_IPI_CALL_FUNC, func, info, wait);
Graf Yang6b3087c2009-01-07 23:14:39 +0800300
Graf Yang6b3087c2009-01-07 23:14:39 +0800301 return 0;
302}
303EXPORT_SYMBOL_GPL(smp_call_function_single);
304
305void smp_send_reschedule(int cpu)
306{
Steven Miao0b2b06e2011-08-02 17:50:41 +0800307 cpumask_t callmap;
Yi Li73a40062009-12-17 08:20:32 +0000308 /* simply trigger an ipi */
Steven Miao0b2b06e2011-08-02 17:50:41 +0800309
310 cpumask_clear(&callmap);
311 cpumask_set_cpu(cpu, &callmap);
312
313 smp_send_message(callmap, BFIN_IPI_RESCHEDULE, NULL, NULL, 0);
Graf Yang6b3087c2009-01-07 23:14:39 +0800314
315 return;
316}
317
Bob Liud0014be2011-12-12 11:04:05 +0800318void smp_send_msg(const struct cpumask *mask, unsigned long type)
319{
320 smp_send_message(*mask, type, NULL, NULL, 0);
321}
322
323void smp_timer_broadcast(const struct cpumask *mask)
324{
325 smp_send_msg(mask, BFIN_IPI_TIMER);
326}
327
Graf Yang6b3087c2009-01-07 23:14:39 +0800328void smp_send_stop(void)
329{
Graf Yang6b3087c2009-01-07 23:14:39 +0800330 cpumask_t callmap;
Graf Yang6b3087c2009-01-07 23:14:39 +0800331
Sonic Zhang567ebfc2010-06-25 05:55:16 +0000332 preempt_disable();
KOSAKI Motohirofecedc802011-04-26 10:57:27 +0900333 cpumask_copy(&callmap, cpu_online_mask);
334 cpumask_clear_cpu(smp_processor_id(), &callmap);
335 if (!cpumask_empty(&callmap))
Sonic Zhang567ebfc2010-06-25 05:55:16 +0000336 smp_send_message(callmap, BFIN_IPI_CPU_STOP, NULL, NULL, 0);
Graf Yang6b3087c2009-01-07 23:14:39 +0800337
Sonic Zhang567ebfc2010-06-25 05:55:16 +0000338 preempt_enable();
Graf Yang6b3087c2009-01-07 23:14:39 +0800339
Graf Yang6b3087c2009-01-07 23:14:39 +0800340 return;
341}
342
Thomas Gleixner6bba2682012-04-20 13:05:53 +0000343int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *idle)
Graf Yang6b3087c2009-01-07 23:14:39 +0800344{
Graf Yang6b3087c2009-01-07 23:14:39 +0800345 int ret;
Graf Yang0b39db22009-12-28 11:13:51 +0000346
Graf Yang6b3087c2009-01-07 23:14:39 +0800347 secondary_stack = task_stack_page(idle) + THREAD_SIZE;
Graf Yang6b3087c2009-01-07 23:14:39 +0800348
349 ret = platform_boot_secondary(cpu, idle);
350
Graf Yang6b3087c2009-01-07 23:14:39 +0800351 secondary_stack = NULL;
352
353 return ret;
354}
355
356static void __cpuinit setup_secondary(unsigned int cpu)
357{
Graf Yang6b3087c2009-01-07 23:14:39 +0800358 unsigned long ilat;
359
360 bfin_write_IMASK(0);
361 CSYNC();
362 ilat = bfin_read_ILAT();
363 CSYNC();
364 bfin_write_ILAT(ilat);
365 CSYNC();
366
Graf Yang6b3087c2009-01-07 23:14:39 +0800367 /* Enable interrupt levels IVG7-15. IARs have been already
368 * programmed by the boot CPU. */
Mike Frysinger40059782008-11-18 17:48:22 +0800369 bfin_irq_flags |= IMASK_IVG15 |
Graf Yang6b3087c2009-01-07 23:14:39 +0800370 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
371 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Graf Yang6b3087c2009-01-07 23:14:39 +0800372}
373
374void __cpuinit secondary_start_kernel(void)
375{
376 unsigned int cpu = smp_processor_id();
377 struct mm_struct *mm = &init_mm;
378
379 if (_bfin_swrst & SWRST_DBL_FAULT_B) {
380 printk(KERN_EMERG "CoreB Recovering from DOUBLE FAULT event\n");
381#ifdef CONFIG_DEBUG_DOUBLEFAULT
Mike Frysingerfb1d9be2011-05-29 23:12:51 -0400382 printk(KERN_EMERG " While handling exception (EXCAUSE = %#x) at %pF\n",
383 initial_pda_coreb.seqstat_doublefault & SEQSTAT_EXCAUSE,
384 initial_pda_coreb.retx_doublefault);
385 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n",
386 initial_pda_coreb.dcplb_doublefault_addr);
387 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n",
388 initial_pda_coreb.icplb_doublefault_addr);
Graf Yang6b3087c2009-01-07 23:14:39 +0800389#endif
390 printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
Mike Frysingerfb1d9be2011-05-29 23:12:51 -0400391 initial_pda_coreb.retx);
Graf Yang6b3087c2009-01-07 23:14:39 +0800392 }
393
394 /*
395 * We want the D-cache to be enabled early, in case the atomic
396 * support code emulates cache coherence (see
397 * __ARCH_SYNC_CORE_DCACHE).
398 */
399 init_exception_vectors();
400
Graf Yang6b3087c2009-01-07 23:14:39 +0800401 local_irq_disable();
402
403 /* Attach the new idle task to the global mm. */
404 atomic_inc(&mm->mm_users);
405 atomic_inc(&mm->mm_count);
406 current->active_mm = mm;
Graf Yang6b3087c2009-01-07 23:14:39 +0800407
408 preempt_disable();
409
410 setup_secondary(cpu);
411
Yi Li578d36f2009-12-02 07:58:12 +0000412 platform_secondary_init(cpu);
413
Yi Li0d152c22009-12-28 10:21:49 +0000414 /* setup local core timer */
415 bfin_local_timer_setup();
416
Graf Yang6b3087c2009-01-07 23:14:39 +0800417 local_irq_enable();
418
steven miaoab61d2a2010-09-07 10:08:36 +0000419 bfin_setup_caches(cpu);
420
Bob Liud0014be2011-12-12 11:04:05 +0800421 notify_cpu_starting(cpu);
Yi Li578d36f2009-12-02 07:58:12 +0000422 /*
423 * Calibrate loops per jiffy value.
424 * IRQs need to be enabled here - D-cache can be invalidated
425 * in timer irq handler, so core B can read correct jiffies.
426 */
427 calibrate_delay();
Graf Yang6b3087c2009-01-07 23:14:39 +0800428
429 cpu_idle();
430}
431
432void __init smp_prepare_boot_cpu(void)
433{
434}
435
436void __init smp_prepare_cpus(unsigned int max_cpus)
437{
438 platform_prepare_cpus(max_cpus);
439 ipi_queue_init();
Yi Li73a40062009-12-17 08:20:32 +0000440 platform_request_ipi(IRQ_SUPPLE_0, ipi_handler_int0);
441 platform_request_ipi(IRQ_SUPPLE_1, ipi_handler_int1);
Graf Yang6b3087c2009-01-07 23:14:39 +0800442}
443
444void __init smp_cpus_done(unsigned int max_cpus)
445{
446 unsigned long bogosum = 0;
447 unsigned int cpu;
448
449 for_each_online_cpu(cpu)
Michael Hennerichc70c7542009-07-09 09:58:52 +0000450 bogosum += loops_per_jiffy;
Graf Yang6b3087c2009-01-07 23:14:39 +0800451
452 printk(KERN_INFO "SMP: Total of %d processors activated "
453 "(%lu.%02lu BogoMIPS).\n",
454 num_online_cpus(),
455 bogosum / (500000/HZ),
456 (bogosum / (5000/HZ)) % 100);
457}
458
459void smp_icache_flush_range_others(unsigned long start, unsigned long end)
460{
461 smp_flush_data.start = start;
462 smp_flush_data.end = end;
463
Steven Miaoa2eff9d2011-11-25 14:25:30 +0800464 preempt_disable();
465 if (smp_call_function(&ipi_flush_icache, &smp_flush_data, 1))
Graf Yang6b3087c2009-01-07 23:14:39 +0800466 printk(KERN_WARNING "SMP: failed to run I-cache flush request on other CPUs\n");
Steven Miaoa2eff9d2011-11-25 14:25:30 +0800467 preempt_enable();
Graf Yang6b3087c2009-01-07 23:14:39 +0800468}
469EXPORT_SYMBOL_GPL(smp_icache_flush_range_others);
470
Sonic Zhang47e9ded2009-06-10 08:57:08 +0000471#ifdef __ARCH_SYNC_CORE_ICACHE
Graf Yang718340f2010-02-01 06:07:50 +0000472unsigned long icache_invld_count[NR_CPUS];
Sonic Zhang47e9ded2009-06-10 08:57:08 +0000473void resync_core_icache(void)
474{
475 unsigned int cpu = get_cpu();
476 blackfin_invalidate_entire_icache();
Graf Yang718340f2010-02-01 06:07:50 +0000477 icache_invld_count[cpu]++;
Sonic Zhang47e9ded2009-06-10 08:57:08 +0000478 put_cpu();
479}
480EXPORT_SYMBOL(resync_core_icache);
481#endif
482
Graf Yang6b3087c2009-01-07 23:14:39 +0800483#ifdef __ARCH_SYNC_CORE_DCACHE
Graf Yang718340f2010-02-01 06:07:50 +0000484unsigned long dcache_invld_count[NR_CPUS];
Graf Yang6b3087c2009-01-07 23:14:39 +0800485unsigned long barrier_mask __attribute__ ((__section__(".l2.bss")));
486
487void resync_core_dcache(void)
488{
489 unsigned int cpu = get_cpu();
490 blackfin_invalidate_entire_dcache();
Graf Yang718340f2010-02-01 06:07:50 +0000491 dcache_invld_count[cpu]++;
Graf Yang6b3087c2009-01-07 23:14:39 +0800492 put_cpu();
493}
494EXPORT_SYMBOL(resync_core_dcache);
495#endif
Graf Yang0b39db22009-12-28 11:13:51 +0000496
497#ifdef CONFIG_HOTPLUG_CPU
498int __cpuexit __cpu_disable(void)
499{
500 unsigned int cpu = smp_processor_id();
501
502 if (cpu == 0)
503 return -EPERM;
504
505 set_cpu_online(cpu, false);
506 return 0;
507}
508
509static DECLARE_COMPLETION(cpu_killed);
510
511int __cpuexit __cpu_die(unsigned int cpu)
512{
513 return wait_for_completion_timeout(&cpu_killed, 5000);
514}
515
516void cpu_die(void)
517{
518 complete(&cpu_killed);
519
520 atomic_dec(&init_mm.mm_users);
521 atomic_dec(&init_mm.mm_count);
522
523 local_irq_disable();
524 platform_cpu_die();
525}
526#endif