blob: b66a0c2d990d21df75c1411ce6a4dbe94a90d3ee [file] [log] [blame]
Colin Cross1cea7322010-02-21 17:46:23 -08001/*
2 * linux/arch/arm/mach-tegra/platsmp.c
3 *
4 * Copyright (C) 2002 ARM Ltd.
5 * All Rights Reserved
6 *
7 * Copyright (C) 2009 Palm
8 * All Rights Reserved
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/jiffies.h>
19#include <linux/smp.h>
20#include <linux/io.h>
21
22#include <asm/cacheflush.h>
23#include <mach/hardware.h>
24#include <asm/mach-types.h>
Colin Cross1cea7322010-02-21 17:46:23 -080025#include <asm/smp_scu.h>
26
27#include <mach/iomap.h>
28
29extern void tegra_secondary_startup(void);
30
31static DEFINE_SPINLOCK(boot_lock);
32static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
33
34#define EVP_CPU_RESET_VECTOR \
35 (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
36#define CLK_RST_CONTROLLER_CLK_CPU_CMPLX \
37 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x4c)
38#define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \
39 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344)
40
41void __cpuinit platform_secondary_init(unsigned int cpu)
42{
43 trace_hardirqs_off();
44
45 /*
46 * if any interrupts are already enabled for the primary
47 * core (e.g. timer irq), then they will not have been enabled
48 * for us: do so
49 */
50 gic_cpu_init(0, IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x100);
51
52 /*
53 * Synchronise with the boot thread.
54 */
55 spin_lock(&boot_lock);
56 spin_unlock(&boot_lock);
57}
58
59int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
60{
61 unsigned long old_boot_vector;
62 unsigned long boot_vector;
63 unsigned long timeout;
64 u32 reg;
65
66 /*
67 * set synchronisation state between this boot processor
68 * and the secondary one
69 */
70 spin_lock(&boot_lock);
71
72
73 /* set the reset vector to point to the secondary_startup routine */
74
75 boot_vector = virt_to_phys(tegra_secondary_startup);
76 old_boot_vector = readl(EVP_CPU_RESET_VECTOR);
77 writel(boot_vector, EVP_CPU_RESET_VECTOR);
78
79 /* enable cpu clock on cpu1 */
80 reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
81 writel(reg & ~(1<<9), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
82
83 reg = (1<<13) | (1<<9) | (1<<5) | (1<<1);
84 writel(reg, CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
85
86 smp_wmb();
87 flush_cache_all();
88
89 /* unhalt the cpu */
90 writel(0, IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + 0x14);
91
92 timeout = jiffies + (1 * HZ);
93 while (time_before(jiffies, timeout)) {
94 if (readl(EVP_CPU_RESET_VECTOR) != boot_vector)
95 break;
96 udelay(10);
97 }
98
99 /* put the old boot vector back */
100 writel(old_boot_vector, EVP_CPU_RESET_VECTOR);
101
102 /*
103 * now the secondary core is starting up let it run its
104 * calibrations, then wait for it to finish
105 */
106 spin_unlock(&boot_lock);
107
108 return 0;
109}
110
111/*
112 * Initialise the CPU possible map early - this describes the CPUs
113 * which may be present or become present in the system.
114 */
115void __init smp_init_cpus(void)
116{
117 unsigned int i, ncores = scu_get_core_count(scu_base);
118
Russell King8975b6c2010-12-03 19:29:53 +0000119 if (ncores > NR_CPUS) {
120 printk(KERN_ERR "Tegra: no. of cores (%u) greater than configured (%u), clipping\n",
121 ncores, NR_CPUS);
122 ncores = NR_CPUS;
123 }
124
Colin Cross1cea7322010-02-21 17:46:23 -0800125 for (i = 0; i < ncores; i++)
126 cpu_set(i, cpu_possible_map);
127}
128
Russell King05c74a62010-12-03 11:09:48 +0000129void __init platform_smp_prepare_cpus(unsigned int max_cpus)
Colin Cross1cea7322010-02-21 17:46:23 -0800130{
Colin Cross1cea7322010-02-21 17:46:23 -0800131 int i;
132
Colin Cross1cea7322010-02-21 17:46:23 -0800133 /*
134 * Initialise the present map, which describes the set of CPUs
135 * actually populated at the present time.
136 */
137 for (i = 0; i < max_cpus; i++)
138 set_cpu_present(i, true);
139
Russell King05c74a62010-12-03 11:09:48 +0000140 scu_enable(scu_base);
Colin Cross1cea7322010-02-21 17:46:23 -0800141}