omap-smp.c 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * OMAP4 SMP source file. It contains platform specific fucntions
 * needed for the linux smp kernel.
 *
 * Copyright (C) 2009 Texas Instruments, Inc.
 *
 * Author:
 *      Santosh Shilimkar <santosh.shilimkar@ti.com>
 *
 * Platform file needed for the OMAP4 SMP. This file is based on arm
 * realview smp platform.
 * * Copyright (c) 2002 ARM Limited.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/init.h>
#include <linux/device.h>
#include <linux/smp.h>
#include <linux/io.h>
22
#include <linux/irqchip/arm-gic.h>
23 24

#include <asm/smp_scu.h>
25

26
#include "omap-secure.h"
27
#include "omap-wakeupgen.h"
28
#include <asm/cputype.h>
29

30
#include "soc.h"
31
#include "iomap.h"
32
#include "common.h"
33
#include "clockdomain.h"
34
#include "pm.h"
35

S
Santosh Shilimkar 已提交
36 37 38 39 40 41
#define CPU_MASK		0xff0ffff0
#define CPU_CORTEX_A9		0x410FC090
#define CPU_CORTEX_A15		0x410FC0F0

#define OMAP5_CORE_COUNT	0x2

42 43
u16 pm44xx_errata;

44
/* SCU base address */
45
static void __iomem *scu_base;
46 47 48

static DEFINE_SPINLOCK(boot_lock);

49 50 51 52 53
void __iomem *omap4_get_scu_base(void)
{
	return scu_base;
}

54
static void __cpuinit omap4_secondary_init(unsigned int cpu)
55
{
56 57 58 59 60 61 62 63 64 65 66 67
	/*
	 * Configure ACTRL and enable NS SMP bit access on CPU1 on HS device.
	 * OMAP44XX EMU/HS devices - CPU0 SMP bit access is enabled in PPA
	 * init and for CPU1, a secure PPA API provided. CPU0 must be ON
	 * while executing NS_SMP API on CPU1 and PPA version must be 1.4.0+.
	 * OMAP443X GP devices- SMP bit isn't accessible.
	 * OMAP446X GP devices - SMP bit access is enabled on both CPUs.
	 */
	if (cpu_is_omap443x() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
		omap_secure_dispatcher(OMAP4_PPA_CPU_ACTRL_SMP_INDEX,
							4, 0, 0, 0, 0, 0);

68 69 70 71 72
	/*
	 * If any interrupts are already enabled for the primary
	 * core (e.g. timer irq), then they will not have been enabled
	 * for us: do so
	 */
73
	gic_secondary_init(0);
74 75 76 77 78 79 80 81

	/*
	 * Synchronise with the boot thread.
	 */
	spin_lock(&boot_lock);
	spin_unlock(&boot_lock);
}

82
static int __cpuinit omap4_boot_secondary(unsigned int cpu, struct task_struct *idle)
83
{
84 85
	static struct clockdomain *cpu1_clkdm;
	static bool booted;
86 87
	void __iomem *base = omap_get_wakeupgen_base();

88 89 90 91 92 93 94
	/*
	 * Set synchronisation state between this boot processor
	 * and the secondary one
	 */
	spin_lock(&boot_lock);

	/*
95
	 * Update the AuxCoreBoot0 with boot state for secondary core.
96 97 98 99
	 * omap_secondary_startup() routine will hold the secondary core till
	 * the AuxCoreBoot1 register is updated with cpu state
	 * A barrier is added to ensure that write buffer is drained
	 */
100 101 102 103 104
	if (omap_secure_apis_support())
		omap_modify_auxcoreboot0(0x200, 0xfffffdff);
	else
		__raw_writel(0x20, base + OMAP_AUX_CORE_BOOT_0);

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
	if (!cpu1_clkdm)
		cpu1_clkdm = clkdm_lookup("mpu1_clkdm");

	/*
	 * The SGI(Software Generated Interrupts) are not wakeup capable
	 * from low power states. This is known limitation on OMAP4 and
	 * needs to be worked around by using software forced clockdomain
	 * wake-up. To wakeup CPU1, CPU0 forces the CPU1 clockdomain to
	 * software force wakeup. The clockdomain is then put back to
	 * hardware supervised mode.
	 * More details can be found in OMAP4430 TRM - Version J
	 * Section :
	 *	4.3.4.2 Power States of CPU0 and CPU1
	 */
	if (booted) {
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
		/*
		 * GIC distributor control register has changed between
		 * CortexA9 r1pX and r2pX. The Control Register secure
		 * banked version is now composed of 2 bits:
		 * bit 0 == Secure Enable
		 * bit 1 == Non-Secure Enable
		 * The Non-Secure banked register has not changed
		 * Because the ROM Code is based on the r1pX GIC, the CPU1
		 * GIC restoration will cause a problem to CPU0 Non-Secure SW.
		 * The workaround must be:
		 * 1) Before doing the CPU1 wakeup, CPU0 must disable
		 * the GIC distributor
		 * 2) CPU1 must re-enable the GIC distributor on
		 * it's wakeup path.
		 */
135 136
		if (IS_PM44XX_ERRATUM(PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD)) {
			local_irq_disable();
137
			gic_dist_disable();
138
		}
139

140 141
		clkdm_wakeup(cpu1_clkdm);
		clkdm_allow_idle(cpu1_clkdm);
142 143 144 145 146 147 148 149 150

		if (IS_PM44XX_ERRATUM(PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD)) {
			while (gic_dist_disabled()) {
				udelay(1);
				cpu_relax();
			}
			gic_timer_retrigger();
			local_irq_enable();
		}
151 152 153 154 155
	} else {
		dsb_sev();
		booted = true;
	}

156
	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
157 158 159 160 161 162 163 164 165 166 167 168 169 170

	/*
	 * Now the secondary core is starting up let it run its
	 * calibrations, then wait for it to finish
	 */
	spin_unlock(&boot_lock);

	return 0;
}

/*
 * Initialise the CPU possible map early - this describes the CPUs
 * which may be present or become present in the system.
 */
171
static void __init omap4_smp_init_cpus(void)
172
{
S
Santosh Shilimkar 已提交
173 174 175 176 177 178 179 180 181
	unsigned int i = 0, ncores = 1, cpu_id;

	/* Use ARM cpuid check here, as SoC detection will not work so early */
	cpu_id = read_cpuid(CPUID_ID) & CPU_MASK;
	if (cpu_id == CPU_CORTEX_A9) {
		/*
		 * Currently we can't call ioremap here because
		 * SoC detection won't work until after init_early.
		 */
182
		scu_base =  OMAP2_L4_IO_ADDRESS(scu_a9_get_base());
S
Santosh Shilimkar 已提交
183 184 185 186 187
		BUG_ON(!scu_base);
		ncores = scu_get_core_count(scu_base);
	} else if (cpu_id == CPU_CORTEX_A15) {
		ncores = OMAP5_CORE_COUNT;
	}
188 189

	/* sanity check */
190 191 192 193
	if (ncores > nr_cpu_ids) {
		pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
			ncores, nr_cpu_ids);
		ncores = nr_cpu_ids;
194 195
	}

196 197 198 199
	for (i = 0; i < ncores; i++)
		set_cpu_possible(i, true);
}

200
static void __init omap4_smp_prepare_cpus(unsigned int max_cpus)
201
{
202 203
	void *startup_addr = omap_secondary_startup;
	void __iomem *base = omap_get_wakeupgen_base();
204

205 206 207 208
	/*
	 * Initialise the SCU and wake up the secondary core using
	 * wakeup_secondary().
	 */
S
Santosh Shilimkar 已提交
209 210
	if (scu_base)
		scu_enable(scu_base);
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

	if (cpu_is_omap446x()) {
		startup_addr = omap_secondary_startup_4460;
		pm44xx_errata |= PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD;
	}

	/*
	 * Write the address of secondary startup routine into the
	 * AuxCoreBoot1 where ROM code will jump and start executing
	 * on secondary core once out of WFE
	 * A barrier is added to ensure that write buffer is drained
	 */
	if (omap_secure_apis_support())
		omap_auxcoreboot_addr(virt_to_phys(startup_addr));
	else
		__raw_writel(virt_to_phys(omap5_secondary_startup),
						base + OMAP_AUX_CORE_BOOT_1);

229
}
230 231 232 233 234 235 236 237 238 239

struct smp_operations omap4_smp_ops __initdata = {
	.smp_init_cpus		= omap4_smp_init_cpus,
	.smp_prepare_cpus	= omap4_smp_prepare_cpus,
	.smp_secondary_init	= omap4_secondary_init,
	.smp_boot_secondary	= omap4_boot_secondary,
#ifdef CONFIG_HOTPLUG_CPU
	.cpu_die		= omap4_cpu_die,
#endif
};