smp.c 4.1 KB
Newer Older
1
/*
2 3
 * Copyright 2007-2009 Analog Devices Inc.
 *               Philippe Gerum <rpm@xenomai.org>
4
 *
5
 * Licensed under the GPL-2 or later.
6 7 8 9 10 11 12 13
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <asm/smp.h>
#include <asm/dma.h>
14
#include <asm/time.h>
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

static DEFINE_SPINLOCK(boot_lock);

/*
 * platform_init_cpus() - Tell the world about how many cores we
 * have. This is called while setting up the architecture support
 * (setup_arch()), so don't be too demanding here with respect to
 * available kernel services.
 */

void __init platform_init_cpus(void)
{
	cpu_set(0, cpu_possible_map); /* CoreA */
	cpu_set(1, cpu_possible_map); /* CoreB */
}

void __init platform_prepare_cpus(unsigned int max_cpus)
{
33
	bfin_relocate_coreb_l1_mem();
34 35 36 37 38 39 40 41 42 43 44 45 46 47

	/* Both cores ought to be present on a bf561! */
	cpu_set(0, cpu_present_map); /* CoreA */
	cpu_set(1, cpu_present_map); /* CoreB */
}

int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
{
	return -EINVAL;
}

void __cpuinit platform_secondary_init(unsigned int cpu)
{
	/* Clone setup for peripheral interrupt sources from CoreA. */
48 49
	bfin_write_SICB_IMASK0(bfin_read_SIC_IMASK0());
	bfin_write_SICB_IMASK1(bfin_read_SIC_IMASK1());
50 51 52
	SSYNC();

	/* Clone setup for IARs from CoreA. */
53 54 55 56 57 58 59 60
	bfin_write_SICB_IAR0(bfin_read_SIC_IAR0());
	bfin_write_SICB_IAR1(bfin_read_SIC_IAR1());
	bfin_write_SICB_IAR2(bfin_read_SIC_IAR2());
	bfin_write_SICB_IAR3(bfin_read_SIC_IAR3());
	bfin_write_SICB_IAR4(bfin_read_SIC_IAR4());
	bfin_write_SICB_IAR5(bfin_read_SIC_IAR5());
	bfin_write_SICB_IAR6(bfin_read_SIC_IAR6());
	bfin_write_SICB_IAR7(bfin_read_SIC_IAR7());
61 62
	bfin_write_SICB_IWR0(IWR_DISABLE_ALL);
	bfin_write_SICB_IWR1(IWR_DISABLE_ALL);
63 64 65 66 67 68
	SSYNC();

	/* Store CPU-private information to the cpu_data array. */
	bfin_setup_cpudata(cpu);

	/* We are done with local CPU inits, unblock the boot CPU. */
69
	set_cpu_online(cpu, true);
70 71 72 73 74 75 76 77 78 79 80 81
	spin_lock(&boot_lock);
	spin_unlock(&boot_lock);
}

int __cpuinit platform_boot_secondary(unsigned int cpu, struct task_struct *idle)
{
	unsigned long timeout;

	printk(KERN_INFO "Booting Core B.\n");

	spin_lock(&boot_lock);

82
	if ((bfin_read_SYSCR() & COREB_SRAM_INIT) == 0) {
83 84 85 86
		/* CoreB already running, sending ipi to wakeup it */
		platform_send_ipi_cpu(cpu, IRQ_SUPPLE_0);
	} else {
		/* Kick CoreB, which should start execution from CORE_SRAM_BASE. */
87
		bfin_write_SYSCR(bfin_read_SYSCR() & ~COREB_SRAM_INIT);
88 89
		SSYNC();
	}
90 91 92

	timeout = jiffies + 1 * HZ;
	while (time_before(jiffies, timeout)) {
93
		if (cpu_online(cpu))
94 95 96 97 98
			break;
		udelay(100);
		barrier();
	}

99
	if (cpu_online(cpu)) {
100 101 102 103 104
		/* release the lock and let coreb run */
		spin_unlock(&boot_lock);
		return 0;
	} else
		panic("CPU%u: processor failed to boot\n", cpu);
105 106
}

107 108 109
static const char supple0[] = "IRQ_SUPPLE_0";
static const char supple1[] = "IRQ_SUPPLE_1";
void __init platform_request_ipi(int irq, void *handler)
110 111
{
	int ret;
112
	const char *name = (irq == IRQ_SUPPLE_0) ? supple0 : supple1;
113

114
	ret = request_irq(irq, handler, IRQF_DISABLED | IRQF_PERCPU, name, handler);
115
	if (ret)
116
		panic("Cannot request %s for IPI service", name);
117 118
}

119
void platform_send_ipi(cpumask_t callmap, int irq)
120 121
{
	unsigned int cpu;
122
	int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8;
123 124 125 126

	for_each_cpu_mask(cpu, callmap) {
		BUG_ON(cpu >= 2);
		SSYNC();
127
		bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
128 129 130 131
		SSYNC();
	}
}

132
void platform_send_ipi_cpu(unsigned int cpu, int irq)
133
{
134
	int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8;
135 136
	BUG_ON(cpu >= 2);
	SSYNC();
137
	bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
138 139 140
	SSYNC();
}

141
void platform_clear_ipi(unsigned int cpu, int irq)
142
{
143
	int offset = (irq == IRQ_SUPPLE_0) ? 10 : 12;
144 145
	BUG_ON(cpu >= 2);
	SSYNC();
146
	bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
147 148
	SSYNC();
}
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

/*
 * Setup core B's local core timer.
 * In SMP, core timer is used for clock event device.
 */
void __cpuinit bfin_local_timer_setup(void)
{
#if defined(CONFIG_TICKSOURCE_CORETMR)
	bfin_coretmr_init();
	bfin_coretmr_clockevent_init();
	get_irq_chip(IRQ_CORETMR)->unmask(IRQ_CORETMR);
#else
	/* Power down the core timer, just to play safe. */
	bfin_write_TCNTL(0);
#endif

}