blob: 90369429ee664d05c3a18bbffe48b689e194ae4f [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{
33 int len;
34
35 len = &coreb_trampoline_end - &coreb_trampoline_start + 1;
Graf Yangdbc895f2009-01-07 23:14:39 +080036 BUG_ON(len > L1_CODE_LENGTH);
Graf Yangc51b4482009-01-07 23:14:39 +080037
Graf Yangdbc895f2009-01-07 23:14:39 +080038 dma_memcpy((void *)COREB_L1_CODE_START, &coreb_trampoline_start, len);
Graf Yangc51b4482009-01-07 23:14:39 +080039
40 /* Both cores ought to be present on a bf561! */
41 cpu_set(0, cpu_present_map); /* CoreA */
42 cpu_set(1, cpu_present_map); /* CoreB */
43
Graf Yangdbc895f2009-01-07 23:14:39 +080044 printk(KERN_INFO "CoreB bootstrap code to SRAM %p via DMA.\n", (void *)COREB_L1_CODE_START);
Graf Yangc51b4482009-01-07 23:14:39 +080045}
46
47int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
48{
49 return -EINVAL;
50}
51
52void __cpuinit platform_secondary_init(unsigned int cpu)
53{
Graf Yangc51b4482009-01-07 23:14:39 +080054 /* Clone setup for peripheral interrupt sources from CoreA. */
55 bfin_write_SICB_IMASK0(bfin_read_SICA_IMASK0());
56 bfin_write_SICB_IMASK1(bfin_read_SICA_IMASK1());
57 SSYNC();
58
59 /* Clone setup for IARs from CoreA. */
60 bfin_write_SICB_IAR0(bfin_read_SICA_IAR0());
61 bfin_write_SICB_IAR1(bfin_read_SICA_IAR1());
62 bfin_write_SICB_IAR2(bfin_read_SICA_IAR2());
63 bfin_write_SICB_IAR3(bfin_read_SICA_IAR3());
64 bfin_write_SICB_IAR4(bfin_read_SICA_IAR4());
65 bfin_write_SICB_IAR5(bfin_read_SICA_IAR5());
66 bfin_write_SICB_IAR6(bfin_read_SICA_IAR6());
67 bfin_write_SICB_IAR7(bfin_read_SICA_IAR7());
68 SSYNC();
69
Graf Yangc51b4482009-01-07 23:14:39 +080070 /* Store CPU-private information to the cpu_data array. */
71 bfin_setup_cpudata(cpu);
72
73 /* We are done with local CPU inits, unblock the boot CPU. */
Graf Yang682f5dc2009-12-28 09:27:27 +000074 set_cpu_online(cpu, true);
Graf Yangc51b4482009-01-07 23:14:39 +080075 spin_lock(&boot_lock);
76 spin_unlock(&boot_lock);
77}
78
79int __cpuinit platform_boot_secondary(unsigned int cpu, struct task_struct *idle)
80{
81 unsigned long timeout;
82
83 /* CoreB already running?! */
84 BUG_ON((bfin_read_SICA_SYSCR() & COREB_SRAM_INIT) == 0);
85
86 printk(KERN_INFO "Booting Core B.\n");
87
88 spin_lock(&boot_lock);
89
90 /* Kick CoreB, which should start execution from CORE_SRAM_BASE. */
91 SSYNC();
92 bfin_write_SICA_SYSCR(bfin_read_SICA_SYSCR() & ~COREB_SRAM_INIT);
93 SSYNC();
94
95 timeout = jiffies + 1 * HZ;
96 while (time_before(jiffies, timeout)) {
Graf Yang682f5dc2009-12-28 09:27:27 +000097 if (cpu_online(cpu))
Graf Yangc51b4482009-01-07 23:14:39 +080098 break;
99 udelay(100);
100 barrier();
101 }
102
Graf Yang682f5dc2009-12-28 09:27:27 +0000103 if (cpu_online(cpu)) {
Yi Li578d36f2009-12-02 07:58:12 +0000104 /* release the lock and let coreb run */
105 spin_unlock(&boot_lock);
106 return 0;
107 } else
108 panic("CPU%u: processor failed to boot\n", cpu);
Graf Yangc51b4482009-01-07 23:14:39 +0800109}
110
111void __init platform_request_ipi(irq_handler_t handler)
112{
113 int ret;
114
115 ret = request_irq(IRQ_SUPPLE_0, handler, IRQF_DISABLED,
Graf Yang1fa9be72009-05-15 11:01:59 +0000116 "Supplemental Interrupt0", handler);
Graf Yangc51b4482009-01-07 23:14:39 +0800117 if (ret)
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000118 panic("Cannot request supplemental interrupt 0 for IPI service");
Graf Yangc51b4482009-01-07 23:14:39 +0800119}
120
121void platform_send_ipi(cpumask_t callmap)
122{
123 unsigned int cpu;
124
125 for_each_cpu_mask(cpu, callmap) {
126 BUG_ON(cpu >= 2);
127 SSYNC();
128 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (6 + cpu)));
129 SSYNC();
130 }
131}
132
133void platform_send_ipi_cpu(unsigned int cpu)
134{
135 BUG_ON(cpu >= 2);
136 SSYNC();
137 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (6 + cpu)));
138 SSYNC();
139}
140
141void platform_clear_ipi(unsigned int cpu)
142{
143 BUG_ON(cpu >= 2);
144 SSYNC();
145 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (10 + cpu)));
146 SSYNC();
147}
Yi Li0d152c22009-12-28 10:21:49 +0000148
149/*
150 * Setup core B's local core timer.
151 * In SMP, core timer is used for clock event device.
152 */
153void __cpuinit bfin_local_timer_setup(void)
154{
155#if defined(CONFIG_TICKSOURCE_CORETMR)
156 bfin_coretmr_init();
157 bfin_coretmr_clockevent_init();
158 get_irq_chip(IRQ_CORETMR)->unmask(IRQ_CORETMR);
159#else
160 /* Power down the core timer, just to play safe. */
161 bfin_write_TCNTL(0);
162#endif
163
164}