blob: 41ae28d69e6f7e2012fe86d006e6d8151f26927d [file] [log] [blame]
Pankaj Dubey45523862014-07-08 07:54:13 +09001 /*
Kukjin Kim7d30e8b2011-02-14 16:33:10 +09002 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
Changhwan Youn2b12b5c2010-07-26 21:08:52 +09004 *
5 * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
6 *
7 * Copyright (C) 2002 ARM Ltd.
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
15#include <linux/init.h>
16#include <linux/errno.h>
17#include <linux/delay.h>
18#include <linux/device.h>
19#include <linux/jiffies.h>
20#include <linux/smp.h>
21#include <linux/io.h>
Sachin Kamatb3205de2014-05-13 07:13:44 +090022#include <linux/of_address.h>
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090023
24#include <asm/cacheflush.h>
Will Deaconeb504392012-01-20 12:01:12 +010025#include <asm/smp_plat.h>
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090026#include <asm/smp_scu.h>
Tomasz Figabeddf632012-12-11 13:58:43 +090027#include <asm/firmware.h>
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090028
Pankaj Dubey2e94ac42014-07-19 03:43:22 +090029#include <mach/map.h>
30
Marc Zyngier06853ae2011-09-08 13:15:22 +010031#include "common.h"
Kukjin Kim65c9a852013-12-19 04:06:56 +090032#include "regs-pmu.h"
Marc Zyngier06853ae2011-09-08 13:15:22 +010033
Kukjin Kim7d30e8b2011-02-14 16:33:10 +090034extern void exynos4_secondary_startup(void);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090035
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +090036/**
37 * exynos_core_power_down : power down the specified cpu
38 * @cpu : the cpu to power down
39 *
40 * Power down the specified cpu. The sequence must be finished by a
41 * call to cpu_do_idle()
42 *
43 */
44void exynos_cpu_power_down(int cpu)
45{
Arnd Bergmann944483d2014-07-26 17:54:21 +020046 pmu_raw_writel(0, EXYNOS_ARM_CORE_CONFIGURATION(cpu));
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +090047}
48
49/**
50 * exynos_cpu_power_up : power up the specified cpu
51 * @cpu : the cpu to power up
52 *
53 * Power up the specified cpu
54 */
55void exynos_cpu_power_up(int cpu)
56{
Arnd Bergmann944483d2014-07-26 17:54:21 +020057 pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN,
58 EXYNOS_ARM_CORE_CONFIGURATION(cpu));
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +090059}
60
61/**
62 * exynos_cpu_power_state : returns the power state of the cpu
63 * @cpu : the cpu to retrieve the power state from
64 *
65 */
66int exynos_cpu_power_state(int cpu)
67{
Arnd Bergmann944483d2014-07-26 17:54:21 +020068 return (pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(cpu)) &
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +090069 S5P_CORE_LOCAL_PWR_EN);
70}
71
72/**
73 * exynos_cluster_power_down : power down the specified cluster
74 * @cluster : the cluster to power down
75 */
76void exynos_cluster_power_down(int cluster)
77{
Arnd Bergmann944483d2014-07-26 17:54:21 +020078 pmu_raw_writel(0, EXYNOS_COMMON_CONFIGURATION(cluster));
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +090079}
80
81/**
82 * exynos_cluster_power_up : power up the specified cluster
83 * @cluster : the cluster to power up
84 */
85void exynos_cluster_power_up(int cluster)
86{
Arnd Bergmann944483d2014-07-26 17:54:21 +020087 pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN,
88 EXYNOS_COMMON_CONFIGURATION(cluster));
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +090089}
90
91/**
92 * exynos_cluster_power_state : returns the power state of the cluster
93 * @cluster : the cluster to retrieve the power state from
94 *
95 */
96int exynos_cluster_power_state(int cluster)
97{
Arnd Bergmann944483d2014-07-26 17:54:21 +020098 return (pmu_raw_readl(EXYNOS_COMMON_STATUS(cluster)) &
99 S5P_CORE_LOCAL_PWR_EN);
Krzysztof Kozlowski7310d992014-07-19 04:45:02 +0900100}
101
Tomasz Figa1f054f52012-11-24 11:13:48 +0900102static inline void __iomem *cpu_boot_reg_base(void)
103{
104 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
Pankaj Dubey2e94ac42014-07-19 03:43:22 +0900105 return pmu_base_addr + S5P_INFORM5;
Sachin Kamatb3205de2014-05-13 07:13:44 +0900106 return sysram_base_addr;
Tomasz Figa1f054f52012-11-24 11:13:48 +0900107}
108
109static inline void __iomem *cpu_boot_reg(int cpu)
110{
111 void __iomem *boot_reg;
112
113 boot_reg = cpu_boot_reg_base();
Sachin Kamatb3205de2014-05-13 07:13:44 +0900114 if (!boot_reg)
115 return ERR_PTR(-ENODEV);
Tomasz Figa1f054f52012-11-24 11:13:48 +0900116 if (soc_is_exynos4412())
117 boot_reg += 4*cpu;
Arun Kumar K86c6f142014-05-26 04:16:11 +0900118 else if (soc_is_exynos5420() || soc_is_exynos5800())
Chander Kashyap1580be32013-06-19 00:29:35 +0900119 boot_reg += 4;
Tomasz Figa1f054f52012-11-24 11:13:48 +0900120 return boot_reg;
121}
JungHi Min911c29b2011-07-16 13:39:09 +0900122
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900123/*
Russell King3705ff62010-12-18 10:53:12 +0000124 * Write pen_release in a way that is guaranteed to be visible to all
125 * observers, irrespective of whether they're taking part in coherency
126 * or not. This is necessary for the hotplug code to work reliably.
127 */
128static void write_pen_release(int val)
129{
130 pen_release = val;
131 smp_wmb();
Nicolas Pitref45913f2013-12-05 14:26:16 -0500132 sync_cache_w(&pen_release);
Russell King3705ff62010-12-18 10:53:12 +0000133}
134
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900135static void __iomem *scu_base_addr(void)
136{
137 return (void __iomem *)(S5P_VA_SCU);
138}
139
140static DEFINE_SPINLOCK(boot_lock);
141
Paul Gortmaker8bd26e32013-06-17 15:43:14 -0400142static void exynos_secondary_init(unsigned int cpu)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900143{
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900144 /*
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900145 * let the primary processor know we're out of the
146 * pen, then head off into the C entry point
147 */
Russell King3705ff62010-12-18 10:53:12 +0000148 write_pen_release(-1);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900149
150 /*
151 * Synchronise with the boot thread.
152 */
153 spin_lock(&boot_lock);
154 spin_unlock(&boot_lock);
155}
156
Paul Gortmaker8bd26e32013-06-17 15:43:14 -0400157static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900158{
159 unsigned long timeout;
Tomasz Figa9637f302014-07-16 02:59:18 +0900160 u32 mpidr = cpu_logical_map(cpu);
161 u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900162 int ret = -ENOSYS;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900163
164 /*
165 * Set synchronisation state between this boot processor
166 * and the secondary one
167 */
168 spin_lock(&boot_lock);
169
170 /*
171 * The secondary processor is waiting to be released from
172 * the holding pen - release it, then wait for it to flag
173 * that it has been released by resetting pen_release.
174 *
Tomasz Figa9637f302014-07-16 02:59:18 +0900175 * Note that "pen_release" is the hardware CPU core ID, whereas
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900176 * "cpu" is Linux's internal ID.
177 */
Tomasz Figa9637f302014-07-16 02:59:18 +0900178 write_pen_release(core_id);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900179
Tomasz Figa9637f302014-07-16 02:59:18 +0900180 if (!exynos_cpu_power_state(core_id)) {
181 exynos_cpu_power_up(core_id);
JungHi Min911c29b2011-07-16 13:39:09 +0900182 timeout = 10;
183
184 /* wait max 10 ms until cpu1 is on */
Tomasz Figa9637f302014-07-16 02:59:18 +0900185 while (exynos_cpu_power_state(core_id)
186 != S5P_CORE_LOCAL_PWR_EN) {
JungHi Min911c29b2011-07-16 13:39:09 +0900187 if (timeout-- == 0)
188 break;
189
190 mdelay(1);
191 }
192
193 if (timeout == 0) {
194 printk(KERN_ERR "cpu1 power enable failed");
195 spin_unlock(&boot_lock);
196 return -ETIMEDOUT;
197 }
198 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900199 /*
200 * Send the secondary CPU a soft interrupt, thereby causing
201 * the boot monitor to read the system wide flags register,
202 * and branch to the address found there.
203 */
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900204
205 timeout = jiffies + (1 * HZ);
206 while (time_before(jiffies, timeout)) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900207 unsigned long boot_addr;
208
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900209 smp_rmb();
JungHi Min911c29b2011-07-16 13:39:09 +0900210
Tomasz Figabeddf632012-12-11 13:58:43 +0900211 boot_addr = virt_to_phys(exynos4_secondary_startup);
212
213 /*
214 * Try to set boot address using firmware first
215 * and fall back to boot register if it fails.
216 */
Tomasz Figa9637f302014-07-16 02:59:18 +0900217 ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900218 if (ret && ret != -ENOSYS)
219 goto fail;
220 if (ret == -ENOSYS) {
Tomasz Figa9637f302014-07-16 02:59:18 +0900221 void __iomem *boot_reg = cpu_boot_reg(core_id);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900222
223 if (IS_ERR(boot_reg)) {
224 ret = PTR_ERR(boot_reg);
225 goto fail;
226 }
Krzysztof Kozlowski68ba9472014-09-14 02:31:19 +0900227 __raw_writel(boot_addr, boot_reg);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900228 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900229
Tomasz Figa9637f302014-07-16 02:59:18 +0900230 call_firmware_op(cpu_boot, core_id);
Tomasz Figabeddf632012-12-11 13:58:43 +0900231
Rob Herringb1cffeb2012-11-26 15:05:48 -0600232 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
JungHi Min911c29b2011-07-16 13:39:09 +0900233
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900234 if (pen_release == -1)
235 break;
236
237 udelay(10);
238 }
239
240 /*
241 * now the secondary core is starting up let it run its
242 * calibrations, then wait for it to finish
243 */
Sachin Kamatb3205de2014-05-13 07:13:44 +0900244fail:
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900245 spin_unlock(&boot_lock);
246
Sachin Kamatb3205de2014-05-13 07:13:44 +0900247 return pen_release != -1 ? ret : 0;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900248}
249
250/*
251 * Initialise the CPU possible map early - this describes the CPUs
252 * which may be present or become present in the system.
253 */
254
Marc Zyngier06853ae2011-09-08 13:15:22 +0100255static void __init exynos_smp_init_cpus(void)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900256{
257 void __iomem *scu_base = scu_base_addr();
258 unsigned int i, ncores;
259
Russell Kingaf040ff2014-06-24 19:43:15 +0100260 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900261 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900262 else
263 /*
264 * CPU Nodes are passed thru DT and set_cpu_possible
265 * is set by "arm_dt_init_cpu_maps".
266 */
267 return;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900268
269 /* sanity check */
Russell Kinga06f9162011-10-20 22:04:18 +0100270 if (ncores > nr_cpu_ids) {
271 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
272 ncores, nr_cpu_ids);
273 ncores = nr_cpu_ids;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900274 }
275
276 for (i = 0; i < ncores; i++)
277 set_cpu_possible(i, true);
278}
279
Marc Zyngier06853ae2011-09-08 13:15:22 +0100280static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900281{
Tomasz Figa1f054f52012-11-24 11:13:48 +0900282 int i;
283
Olof Johansson1754c422014-06-02 21:47:46 -0700284 exynos_sysram_init();
285
Russell Kingaf040ff2014-06-24 19:43:15 +0100286 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900287 scu_enable(scu_base_addr());
Russell King05c74a62010-12-03 11:09:48 +0000288
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900289 /*
Russell King05c74a62010-12-03 11:09:48 +0000290 * Write the address of secondary startup into the
291 * system-wide flags register. The boot monitor waits
292 * until it receives a soft interrupt, and then the
293 * secondary CPU branches to this address.
Tomasz Figabeddf632012-12-11 13:58:43 +0900294 *
295 * Try using firmware operation first and fall back to
296 * boot register if it fails.
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900297 */
Tomasz Figabeddf632012-12-11 13:58:43 +0900298 for (i = 1; i < max_cpus; ++i) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900299 unsigned long boot_addr;
Tomasz Figa9637f302014-07-16 02:59:18 +0900300 u32 mpidr;
301 u32 core_id;
Sachin Kamatb3205de2014-05-13 07:13:44 +0900302 int ret;
Tomasz Figabeddf632012-12-11 13:58:43 +0900303
Tomasz Figa9637f302014-07-16 02:59:18 +0900304 mpidr = cpu_logical_map(i);
305 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
Tomasz Figabeddf632012-12-11 13:58:43 +0900306 boot_addr = virt_to_phys(exynos4_secondary_startup);
307
Tomasz Figa9637f302014-07-16 02:59:18 +0900308 ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900309 if (ret && ret != -ENOSYS)
310 break;
311 if (ret == -ENOSYS) {
Tomasz Figa9637f302014-07-16 02:59:18 +0900312 void __iomem *boot_reg = cpu_boot_reg(core_id);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900313
314 if (IS_ERR(boot_reg))
315 break;
Krzysztof Kozlowski68ba9472014-09-14 02:31:19 +0900316 __raw_writel(boot_addr, boot_reg);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900317 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900318 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900319}
Marc Zyngier06853ae2011-09-08 13:15:22 +0100320
321struct smp_operations exynos_smp_ops __initdata = {
322 .smp_init_cpus = exynos_smp_init_cpus,
323 .smp_prepare_cpus = exynos_smp_prepare_cpus,
324 .smp_secondary_init = exynos_secondary_init,
325 .smp_boot_secondary = exynos_boot_secondary,
326#ifdef CONFIG_HOTPLUG_CPU
327 .cpu_die = exynos_cpu_die,
328#endif
329};