blob: 0886cbccddee4ed475fb122d997ac9b7c80d037e [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>
Russell King0f7b3322011-04-03 13:01:30 +010023#include <asm/hardware/gic.h>
Colin Cross1cea7322010-02-21 17:46:23 -080024#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{
Colin Cross1cea7322010-02-21 17:46:23 -080043 /*
44 * if any interrupts are already enabled for the primary
45 * core (e.g. timer irq), then they will not have been enabled
46 * for us: do so
47 */
Russell King38489532010-12-04 16:01:03 +000048 gic_secondary_init(0);
Colin Cross1cea7322010-02-21 17:46:23 -080049
50 /*
51 * Synchronise with the boot thread.
52 */
53 spin_lock(&boot_lock);
54 spin_unlock(&boot_lock);
55}
56
57int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
58{
59 unsigned long old_boot_vector;
60 unsigned long boot_vector;
61 unsigned long timeout;
62 u32 reg;
63
64 /*
65 * set synchronisation state between this boot processor
66 * and the secondary one
67 */
68 spin_lock(&boot_lock);
69
70
71 /* set the reset vector to point to the secondary_startup routine */
72
73 boot_vector = virt_to_phys(tegra_secondary_startup);
74 old_boot_vector = readl(EVP_CPU_RESET_VECTOR);
75 writel(boot_vector, EVP_CPU_RESET_VECTOR);
76
77 /* enable cpu clock on cpu1 */
78 reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
79 writel(reg & ~(1<<9), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
80
81 reg = (1<<13) | (1<<9) | (1<<5) | (1<<1);
82 writel(reg, CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
83
84 smp_wmb();
85 flush_cache_all();
86
87 /* unhalt the cpu */
88 writel(0, IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + 0x14);
89
90 timeout = jiffies + (1 * HZ);
91 while (time_before(jiffies, timeout)) {
92 if (readl(EVP_CPU_RESET_VECTOR) != boot_vector)
93 break;
94 udelay(10);
95 }
96
97 /* put the old boot vector back */
98 writel(old_boot_vector, EVP_CPU_RESET_VECTOR);
99
100 /*
101 * now the secondary core is starting up let it run its
102 * calibrations, then wait for it to finish
103 */
104 spin_unlock(&boot_lock);
105
106 return 0;
107}
108
109/*
110 * Initialise the CPU possible map early - this describes the CPUs
111 * which may be present or become present in the system.
112 */
113void __init smp_init_cpus(void)
114{
115 unsigned int i, ncores = scu_get_core_count(scu_base);
116
Russell King8975b6c2010-12-03 19:29:53 +0000117 if (ncores > NR_CPUS) {
118 printk(KERN_ERR "Tegra: no. of cores (%u) greater than configured (%u), clipping\n",
119 ncores, NR_CPUS);
120 ncores = NR_CPUS;
121 }
122
Colin Cross1cea7322010-02-21 17:46:23 -0800123 for (i = 0; i < ncores; i++)
KOSAKI Motohiro24fe4322011-06-23 17:28:28 +0900124 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100125
126 set_smp_cross_call(gic_raise_softirq);
Colin Cross1cea7322010-02-21 17:46:23 -0800127}
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
Russell King05c74a62010-12-03 11:09:48 +0000132 scu_enable(scu_base);
Colin Cross1cea7322010-02-21 17:46:23 -0800133}