blob: ec02422e84993d4bb8f813e5976ffd9fe3b3bdeb [file] [log] [blame]
Kukjin Kim7d30e8b2011-02-14 16:33:10 +09001/* linux/arch/arm/mach-exynos4/platsmp.c
Changhwan Youn2b12b5c2010-07-26 21:08:52 +09002 *
Kukjin Kim7d30e8b2011-02-14 16:33:10 +09003 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
Changhwan Youn2b12b5c2010-07-26 21:08:52 +09005 *
6 * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
7 *
8 * Copyright (C) 2002 ARM Ltd.
9 * All Rights Reserved
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14*/
15
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/delay.h>
19#include <linux/device.h>
20#include <linux/jiffies.h>
21#include <linux/smp.h>
22#include <linux/io.h>
Sachin Kamatb3205de2014-05-13 07:13:44 +090023#include <linux/of_address.h>
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090024
25#include <asm/cacheflush.h>
Will Deaconeb504392012-01-20 12:01:12 +010026#include <asm/smp_plat.h>
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090027#include <asm/smp_scu.h>
Tomasz Figabeddf632012-12-11 13:58:43 +090028#include <asm/firmware.h>
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090029
Marc Zyngier06853ae2011-09-08 13:15:22 +010030#include "common.h"
Kukjin Kim65c9a852013-12-19 04:06:56 +090031#include "regs-pmu.h"
Marc Zyngier06853ae2011-09-08 13:15:22 +010032
Kukjin Kim7d30e8b2011-02-14 16:33:10 +090033extern void exynos4_secondary_startup(void);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090034
Daniel Lezcanocd245f52014-05-26 04:50:34 +090035void __iomem *sysram_base_addr;
Sachin Kamatb3205de2014-05-13 07:13:44 +090036void __iomem *sysram_ns_base_addr;
37
38static void __init exynos_smp_prepare_sysram(void)
39{
40 struct device_node *node;
41
42 for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram") {
43 if (!of_device_is_available(node))
44 continue;
45 sysram_base_addr = of_iomap(node, 0);
46 break;
47 }
48
49 for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram-ns") {
50 if (!of_device_is_available(node))
51 continue;
52 sysram_ns_base_addr = of_iomap(node, 0);
53 break;
54 }
55}
56
Tomasz Figa1f054f52012-11-24 11:13:48 +090057static inline void __iomem *cpu_boot_reg_base(void)
58{
59 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
60 return S5P_INFORM5;
Sachin Kamatb3205de2014-05-13 07:13:44 +090061 return sysram_base_addr;
Tomasz Figa1f054f52012-11-24 11:13:48 +090062}
63
64static inline void __iomem *cpu_boot_reg(int cpu)
65{
66 void __iomem *boot_reg;
67
68 boot_reg = cpu_boot_reg_base();
Sachin Kamatb3205de2014-05-13 07:13:44 +090069 if (!boot_reg)
70 return ERR_PTR(-ENODEV);
Tomasz Figa1f054f52012-11-24 11:13:48 +090071 if (soc_is_exynos4412())
72 boot_reg += 4*cpu;
Arun Kumar K86c6f142014-05-26 04:16:11 +090073 else if (soc_is_exynos5420() || soc_is_exynos5800())
Chander Kashyap1580be32013-06-19 00:29:35 +090074 boot_reg += 4;
Tomasz Figa1f054f52012-11-24 11:13:48 +090075 return boot_reg;
76}
JungHi Min911c29b2011-07-16 13:39:09 +090077
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090078/*
Russell King3705ff62010-12-18 10:53:12 +000079 * Write pen_release in a way that is guaranteed to be visible to all
80 * observers, irrespective of whether they're taking part in coherency
81 * or not. This is necessary for the hotplug code to work reliably.
82 */
83static void write_pen_release(int val)
84{
85 pen_release = val;
86 smp_wmb();
Nicolas Pitref45913f2013-12-05 14:26:16 -050087 sync_cache_w(&pen_release);
Russell King3705ff62010-12-18 10:53:12 +000088}
89
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090090static void __iomem *scu_base_addr(void)
91{
92 return (void __iomem *)(S5P_VA_SCU);
93}
94
95static DEFINE_SPINLOCK(boot_lock);
96
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040097static void exynos_secondary_init(unsigned int cpu)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090098{
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090099 /*
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900100 * let the primary processor know we're out of the
101 * pen, then head off into the C entry point
102 */
Russell King3705ff62010-12-18 10:53:12 +0000103 write_pen_release(-1);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900104
105 /*
106 * Synchronise with the boot thread.
107 */
108 spin_lock(&boot_lock);
109 spin_unlock(&boot_lock);
110}
111
Paul Gortmaker8bd26e32013-06-17 15:43:14 -0400112static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900113{
114 unsigned long timeout;
Tomasz Figa1f054f52012-11-24 11:13:48 +0900115 unsigned long phys_cpu = cpu_logical_map(cpu);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900116 int ret = -ENOSYS;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900117
118 /*
119 * Set synchronisation state between this boot processor
120 * and the secondary one
121 */
122 spin_lock(&boot_lock);
123
124 /*
125 * The secondary processor is waiting to be released from
126 * the holding pen - release it, then wait for it to flag
127 * that it has been released by resetting pen_release.
128 *
129 * Note that "pen_release" is the hardware CPU ID, whereas
130 * "cpu" is Linux's internal ID.
131 */
Tomasz Figa1f054f52012-11-24 11:13:48 +0900132 write_pen_release(phys_cpu);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900133
Leela Krishna Amudala664ba442014-05-16 04:23:25 +0900134 if (!exynos_cpu_power_state(cpu)) {
135 exynos_cpu_power_up(cpu);
JungHi Min911c29b2011-07-16 13:39:09 +0900136 timeout = 10;
137
138 /* wait max 10 ms until cpu1 is on */
Leela Krishna Amudala664ba442014-05-16 04:23:25 +0900139 while (exynos_cpu_power_state(cpu) != S5P_CORE_LOCAL_PWR_EN) {
JungHi Min911c29b2011-07-16 13:39:09 +0900140 if (timeout-- == 0)
141 break;
142
143 mdelay(1);
144 }
145
146 if (timeout == 0) {
147 printk(KERN_ERR "cpu1 power enable failed");
148 spin_unlock(&boot_lock);
149 return -ETIMEDOUT;
150 }
151 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900152 /*
153 * Send the secondary CPU a soft interrupt, thereby causing
154 * the boot monitor to read the system wide flags register,
155 * and branch to the address found there.
156 */
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900157
158 timeout = jiffies + (1 * HZ);
159 while (time_before(jiffies, timeout)) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900160 unsigned long boot_addr;
161
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900162 smp_rmb();
JungHi Min911c29b2011-07-16 13:39:09 +0900163
Tomasz Figabeddf632012-12-11 13:58:43 +0900164 boot_addr = virt_to_phys(exynos4_secondary_startup);
165
166 /*
167 * Try to set boot address using firmware first
168 * and fall back to boot register if it fails.
169 */
Sachin Kamatb3205de2014-05-13 07:13:44 +0900170 ret = call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr);
171 if (ret && ret != -ENOSYS)
172 goto fail;
173 if (ret == -ENOSYS) {
174 void __iomem *boot_reg = cpu_boot_reg(phys_cpu);
175
176 if (IS_ERR(boot_reg)) {
177 ret = PTR_ERR(boot_reg);
178 goto fail;
179 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900180 __raw_writel(boot_addr, cpu_boot_reg(phys_cpu));
Sachin Kamatb3205de2014-05-13 07:13:44 +0900181 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900182
183 call_firmware_op(cpu_boot, phys_cpu);
184
Rob Herringb1cffeb2012-11-26 15:05:48 -0600185 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
JungHi Min911c29b2011-07-16 13:39:09 +0900186
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900187 if (pen_release == -1)
188 break;
189
190 udelay(10);
191 }
192
193 /*
194 * now the secondary core is starting up let it run its
195 * calibrations, then wait for it to finish
196 */
Sachin Kamatb3205de2014-05-13 07:13:44 +0900197fail:
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900198 spin_unlock(&boot_lock);
199
Sachin Kamatb3205de2014-05-13 07:13:44 +0900200 return pen_release != -1 ? ret : 0;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900201}
202
203/*
204 * Initialise the CPU possible map early - this describes the CPUs
205 * which may be present or become present in the system.
206 */
207
Marc Zyngier06853ae2011-09-08 13:15:22 +0100208static void __init exynos_smp_init_cpus(void)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900209{
210 void __iomem *scu_base = scu_base_addr();
211 unsigned int i, ncores;
212
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900213 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900214 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900215 else
216 /*
217 * CPU Nodes are passed thru DT and set_cpu_possible
218 * is set by "arm_dt_init_cpu_maps".
219 */
220 return;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900221
222 /* sanity check */
Russell Kinga06f9162011-10-20 22:04:18 +0100223 if (ncores > nr_cpu_ids) {
224 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
225 ncores, nr_cpu_ids);
226 ncores = nr_cpu_ids;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900227 }
228
229 for (i = 0; i < ncores; i++)
230 set_cpu_possible(i, true);
231}
232
Marc Zyngier06853ae2011-09-08 13:15:22 +0100233static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900234{
Tomasz Figa1f054f52012-11-24 11:13:48 +0900235 int i;
236
Leela Krishna Amudalab5f3c752013-06-10 18:28:04 +0900237 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900238 scu_enable(scu_base_addr());
Russell King05c74a62010-12-03 11:09:48 +0000239
Sachin Kamatb3205de2014-05-13 07:13:44 +0900240 exynos_smp_prepare_sysram();
241
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900242 /*
Russell King05c74a62010-12-03 11:09:48 +0000243 * Write the address of secondary startup into the
244 * system-wide flags register. The boot monitor waits
245 * until it receives a soft interrupt, and then the
246 * secondary CPU branches to this address.
Tomasz Figabeddf632012-12-11 13:58:43 +0900247 *
248 * Try using firmware operation first and fall back to
249 * boot register if it fails.
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900250 */
Tomasz Figabeddf632012-12-11 13:58:43 +0900251 for (i = 1; i < max_cpus; ++i) {
252 unsigned long phys_cpu;
253 unsigned long boot_addr;
Sachin Kamatb3205de2014-05-13 07:13:44 +0900254 int ret;
Tomasz Figabeddf632012-12-11 13:58:43 +0900255
256 phys_cpu = cpu_logical_map(i);
257 boot_addr = virt_to_phys(exynos4_secondary_startup);
258
Sachin Kamatb3205de2014-05-13 07:13:44 +0900259 ret = call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr);
260 if (ret && ret != -ENOSYS)
261 break;
262 if (ret == -ENOSYS) {
263 void __iomem *boot_reg = cpu_boot_reg(phys_cpu);
264
265 if (IS_ERR(boot_reg))
266 break;
Tomasz Figabeddf632012-12-11 13:58:43 +0900267 __raw_writel(boot_addr, cpu_boot_reg(phys_cpu));
Sachin Kamatb3205de2014-05-13 07:13:44 +0900268 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900269 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900270}
Marc Zyngier06853ae2011-09-08 13:15:22 +0100271
272struct smp_operations exynos_smp_ops __initdata = {
273 .smp_init_cpus = exynos_smp_init_cpus,
274 .smp_prepare_cpus = exynos_smp_prepare_cpus,
275 .smp_secondary_init = exynos_secondary_init,
276 .smp_boot_secondary = exynos_boot_secondary,
277#ifdef CONFIG_HOTPLUG_CPU
278 .cpu_die = exynos_cpu_die,
279#endif
280};