blob: 5d68bf613b0b9dbe0fde9e2e3055fe23c0375f63 [file] [log] [blame]
Graf Yangc51b4482009-01-07 23:14:39 +08001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Copyright 2007-2009 Analog Devices Inc.
3 * Philippe Gerum <rpm@xenomai.org>
Graf Yangc51b4482009-01-07 23:14:39 +08004 *
Robin Getz96f10502009-09-24 14:11:24 +00005 * Licensed under the GPL-2 or later.
Graf Yangc51b4482009-01-07 23:14:39 +08006 */
7
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/sched.h>
11#include <linux/delay.h>
12#include <asm/smp.h>
13#include <asm/dma.h>
Yi Li0d152c22009-12-28 10:21:49 +000014#include <asm/time.h>
Graf Yangc51b4482009-01-07 23:14:39 +080015
Graf Yangc51b4482009-01-07 23:14:39 +080016static DEFINE_SPINLOCK(boot_lock);
17
Graf Yangc51b4482009-01-07 23:14:39 +080018/*
19 * platform_init_cpus() - Tell the world about how many cores we
20 * have. This is called while setting up the architecture support
21 * (setup_arch()), so don't be too demanding here with respect to
22 * available kernel services.
23 */
24
25void __init platform_init_cpus(void)
26{
27 cpu_set(0, cpu_possible_map); /* CoreA */
28 cpu_set(1, cpu_possible_map); /* CoreB */
29}
30
31void __init platform_prepare_cpus(unsigned int max_cpus)
32{
Sonic Zhangc6345ab2010-08-05 07:49:26 +000033 bfin_relocate_coreb_l1_mem();
Graf Yangc51b4482009-01-07 23:14:39 +080034
35 /* Both cores ought to be present on a bf561! */
36 cpu_set(0, cpu_present_map); /* CoreA */
37 cpu_set(1, cpu_present_map); /* CoreB */
Graf Yangc51b4482009-01-07 23:14:39 +080038}
39
40int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
41{
42 return -EINVAL;
43}
44
45void __cpuinit platform_secondary_init(unsigned int cpu)
46{
Graf Yangc51b4482009-01-07 23:14:39 +080047 /* Clone setup for peripheral interrupt sources from CoreA. */
Mike Frysinger39c99962010-10-19 18:44:23 +000048 bfin_write_SICB_IMASK0(bfin_read_SIC_IMASK0());
49 bfin_write_SICB_IMASK1(bfin_read_SIC_IMASK1());
Graf Yangc51b4482009-01-07 23:14:39 +080050 SSYNC();
51
52 /* Clone setup for IARs from CoreA. */
Mike Frysinger39c99962010-10-19 18:44:23 +000053 bfin_write_SICB_IAR0(bfin_read_SIC_IAR0());
54 bfin_write_SICB_IAR1(bfin_read_SIC_IAR1());
55 bfin_write_SICB_IAR2(bfin_read_SIC_IAR2());
56 bfin_write_SICB_IAR3(bfin_read_SIC_IAR3());
57 bfin_write_SICB_IAR4(bfin_read_SIC_IAR4());
58 bfin_write_SICB_IAR5(bfin_read_SIC_IAR5());
59 bfin_write_SICB_IAR6(bfin_read_SIC_IAR6());
60 bfin_write_SICB_IAR7(bfin_read_SIC_IAR7());
Graf Yang0b39db22009-12-28 11:13:51 +000061 bfin_write_SICB_IWR0(IWR_DISABLE_ALL);
62 bfin_write_SICB_IWR1(IWR_DISABLE_ALL);
Graf Yangc51b4482009-01-07 23:14:39 +080063 SSYNC();
64
Graf Yangc51b4482009-01-07 23:14:39 +080065 /* Store CPU-private information to the cpu_data array. */
66 bfin_setup_cpudata(cpu);
67
68 /* We are done with local CPU inits, unblock the boot CPU. */
Graf Yang682f5dc2009-12-28 09:27:27 +000069 set_cpu_online(cpu, true);
Graf Yangc51b4482009-01-07 23:14:39 +080070 spin_lock(&boot_lock);
71 spin_unlock(&boot_lock);
72}
73
74int __cpuinit platform_boot_secondary(unsigned int cpu, struct task_struct *idle)
75{
76 unsigned long timeout;
77
Graf Yangc51b4482009-01-07 23:14:39 +080078 printk(KERN_INFO "Booting Core B.\n");
79
80 spin_lock(&boot_lock);
81
Mike Frysinger94a038c2010-10-27 10:06:32 -040082 if ((bfin_read_SYSCR() & COREB_SRAM_INIT) == 0) {
Graf Yang0b39db22009-12-28 11:13:51 +000083 /* CoreB already running, sending ipi to wakeup it */
84 platform_send_ipi_cpu(cpu, IRQ_SUPPLE_0);
85 } else {
86 /* Kick CoreB, which should start execution from CORE_SRAM_BASE. */
Mike Frysinger94a038c2010-10-27 10:06:32 -040087 bfin_write_SYSCR(bfin_read_SYSCR() & ~COREB_SRAM_INIT);
Graf Yang0b39db22009-12-28 11:13:51 +000088 SSYNC();
89 }
Graf Yangc51b4482009-01-07 23:14:39 +080090
91 timeout = jiffies + 1 * HZ;
92 while (time_before(jiffies, timeout)) {
Graf Yang682f5dc2009-12-28 09:27:27 +000093 if (cpu_online(cpu))
Graf Yangc51b4482009-01-07 23:14:39 +080094 break;
95 udelay(100);
96 barrier();
97 }
98
Graf Yang682f5dc2009-12-28 09:27:27 +000099 if (cpu_online(cpu)) {
Yi Li578d36f2009-12-02 07:58:12 +0000100 /* release the lock and let coreb run */
101 spin_unlock(&boot_lock);
102 return 0;
103 } else
104 panic("CPU%u: processor failed to boot\n", cpu);
Graf Yangc51b4482009-01-07 23:14:39 +0800105}
106
Yi Li73a40062009-12-17 08:20:32 +0000107static const char supple0[] = "IRQ_SUPPLE_0";
108static const char supple1[] = "IRQ_SUPPLE_1";
109void __init platform_request_ipi(int irq, void *handler)
Graf Yangc51b4482009-01-07 23:14:39 +0800110{
111 int ret;
Yi Li73a40062009-12-17 08:20:32 +0000112 const char *name = (irq == IRQ_SUPPLE_0) ? supple0 : supple1;
Graf Yangc51b4482009-01-07 23:14:39 +0800113
Yi Li73a40062009-12-17 08:20:32 +0000114 ret = request_irq(irq, handler, IRQF_DISABLED | IRQF_PERCPU, name, handler);
Graf Yangc51b4482009-01-07 23:14:39 +0800115 if (ret)
Yi Li73a40062009-12-17 08:20:32 +0000116 panic("Cannot request %s for IPI service", name);
Graf Yangc51b4482009-01-07 23:14:39 +0800117}
118
Yi Li73a40062009-12-17 08:20:32 +0000119void platform_send_ipi(cpumask_t callmap, int irq)
Graf Yangc51b4482009-01-07 23:14:39 +0800120{
121 unsigned int cpu;
Yi Li73a40062009-12-17 08:20:32 +0000122 int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8;
Graf Yangc51b4482009-01-07 23:14:39 +0800123
124 for_each_cpu_mask(cpu, callmap) {
125 BUG_ON(cpu >= 2);
126 SSYNC();
Yi Li73a40062009-12-17 08:20:32 +0000127 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
Graf Yangc51b4482009-01-07 23:14:39 +0800128 SSYNC();
129 }
130}
131
Yi Li73a40062009-12-17 08:20:32 +0000132void platform_send_ipi_cpu(unsigned int cpu, int irq)
Graf Yangc51b4482009-01-07 23:14:39 +0800133{
Yi Li73a40062009-12-17 08:20:32 +0000134 int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8;
Graf Yangc51b4482009-01-07 23:14:39 +0800135 BUG_ON(cpu >= 2);
136 SSYNC();
Yi Li73a40062009-12-17 08:20:32 +0000137 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
Graf Yangc51b4482009-01-07 23:14:39 +0800138 SSYNC();
139}
140
Yi Li73a40062009-12-17 08:20:32 +0000141void platform_clear_ipi(unsigned int cpu, int irq)
Graf Yangc51b4482009-01-07 23:14:39 +0800142{
Yi Li73a40062009-12-17 08:20:32 +0000143 int offset = (irq == IRQ_SUPPLE_0) ? 10 : 12;
Graf Yangc51b4482009-01-07 23:14:39 +0800144 BUG_ON(cpu >= 2);
145 SSYNC();
Yi Li73a40062009-12-17 08:20:32 +0000146 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
Graf Yangc51b4482009-01-07 23:14:39 +0800147 SSYNC();
148}
Yi Li0d152c22009-12-28 10:21:49 +0000149
150/*
151 * Setup core B's local core timer.
152 * In SMP, core timer is used for clock event device.
153 */
154void __cpuinit bfin_local_timer_setup(void)
155{
156#if defined(CONFIG_TICKSOURCE_CORETMR)
Mike Frysinger91796c22011-03-18 03:03:23 -0400157 struct irq_chip *chip = get_irq_chip(IRQ_CORETMR);
158 struct irq_desc *desc = irq_to_desc(IRQ_CORETMR);
159
Yi Li0d152c22009-12-28 10:21:49 +0000160 bfin_coretmr_init();
161 bfin_coretmr_clockevent_init();
Mike Frysinger91796c22011-03-18 03:03:23 -0400162
163 chip->irq_unmask(&desc->irq_data);
Yi Li0d152c22009-12-28 10:21:49 +0000164#else
165 /* Power down the core timer, just to play safe. */
166 bfin_write_TCNTL(0);
167#endif
168
169}