blob: 7c829989859c2418a5f484c6324b3aba85585831 [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
Tomasz Figa1f054f52012-11-24 11:13:48 +090036static inline void __iomem *cpu_boot_reg_base(void)
37{
38 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
Pankaj Dubey2e94ac42014-07-19 03:43:22 +090039 return pmu_base_addr + S5P_INFORM5;
Sachin Kamatb3205de2014-05-13 07:13:44 +090040 return sysram_base_addr;
Tomasz Figa1f054f52012-11-24 11:13:48 +090041}
42
43static inline void __iomem *cpu_boot_reg(int cpu)
44{
45 void __iomem *boot_reg;
46
47 boot_reg = cpu_boot_reg_base();
Sachin Kamatb3205de2014-05-13 07:13:44 +090048 if (!boot_reg)
49 return ERR_PTR(-ENODEV);
Tomasz Figa1f054f52012-11-24 11:13:48 +090050 if (soc_is_exynos4412())
51 boot_reg += 4*cpu;
Arun Kumar K86c6f142014-05-26 04:16:11 +090052 else if (soc_is_exynos5420() || soc_is_exynos5800())
Chander Kashyap1580be32013-06-19 00:29:35 +090053 boot_reg += 4;
Tomasz Figa1f054f52012-11-24 11:13:48 +090054 return boot_reg;
55}
JungHi Min911c29b2011-07-16 13:39:09 +090056
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090057/*
Russell King3705ff62010-12-18 10:53:12 +000058 * Write pen_release in a way that is guaranteed to be visible to all
59 * observers, irrespective of whether they're taking part in coherency
60 * or not. This is necessary for the hotplug code to work reliably.
61 */
62static void write_pen_release(int val)
63{
64 pen_release = val;
65 smp_wmb();
Nicolas Pitref45913f2013-12-05 14:26:16 -050066 sync_cache_w(&pen_release);
Russell King3705ff62010-12-18 10:53:12 +000067}
68
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090069static void __iomem *scu_base_addr(void)
70{
71 return (void __iomem *)(S5P_VA_SCU);
72}
73
74static DEFINE_SPINLOCK(boot_lock);
75
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040076static void exynos_secondary_init(unsigned int cpu)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090077{
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090078 /*
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090079 * let the primary processor know we're out of the
80 * pen, then head off into the C entry point
81 */
Russell King3705ff62010-12-18 10:53:12 +000082 write_pen_release(-1);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090083
84 /*
85 * Synchronise with the boot thread.
86 */
87 spin_lock(&boot_lock);
88 spin_unlock(&boot_lock);
89}
90
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040091static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090092{
93 unsigned long timeout;
Tomasz Figa9637f302014-07-16 02:59:18 +090094 u32 mpidr = cpu_logical_map(cpu);
95 u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
Sachin Kamatb3205de2014-05-13 07:13:44 +090096 int ret = -ENOSYS;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090097
98 /*
99 * Set synchronisation state between this boot processor
100 * and the secondary one
101 */
102 spin_lock(&boot_lock);
103
104 /*
105 * The secondary processor is waiting to be released from
106 * the holding pen - release it, then wait for it to flag
107 * that it has been released by resetting pen_release.
108 *
Tomasz Figa9637f302014-07-16 02:59:18 +0900109 * Note that "pen_release" is the hardware CPU core ID, whereas
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900110 * "cpu" is Linux's internal ID.
111 */
Tomasz Figa9637f302014-07-16 02:59:18 +0900112 write_pen_release(core_id);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900113
Tomasz Figa9637f302014-07-16 02:59:18 +0900114 if (!exynos_cpu_power_state(core_id)) {
115 exynos_cpu_power_up(core_id);
JungHi Min911c29b2011-07-16 13:39:09 +0900116 timeout = 10;
117
118 /* wait max 10 ms until cpu1 is on */
Tomasz Figa9637f302014-07-16 02:59:18 +0900119 while (exynos_cpu_power_state(core_id)
120 != S5P_CORE_LOCAL_PWR_EN) {
JungHi Min911c29b2011-07-16 13:39:09 +0900121 if (timeout-- == 0)
122 break;
123
124 mdelay(1);
125 }
126
127 if (timeout == 0) {
128 printk(KERN_ERR "cpu1 power enable failed");
129 spin_unlock(&boot_lock);
130 return -ETIMEDOUT;
131 }
132 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900133 /*
134 * Send the secondary CPU a soft interrupt, thereby causing
135 * the boot monitor to read the system wide flags register,
136 * and branch to the address found there.
137 */
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900138
139 timeout = jiffies + (1 * HZ);
140 while (time_before(jiffies, timeout)) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900141 unsigned long boot_addr;
142
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900143 smp_rmb();
JungHi Min911c29b2011-07-16 13:39:09 +0900144
Tomasz Figabeddf632012-12-11 13:58:43 +0900145 boot_addr = virt_to_phys(exynos4_secondary_startup);
146
147 /*
148 * Try to set boot address using firmware first
149 * and fall back to boot register if it fails.
150 */
Tomasz Figa9637f302014-07-16 02:59:18 +0900151 ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900152 if (ret && ret != -ENOSYS)
153 goto fail;
154 if (ret == -ENOSYS) {
Tomasz Figa9637f302014-07-16 02:59:18 +0900155 void __iomem *boot_reg = cpu_boot_reg(core_id);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900156
157 if (IS_ERR(boot_reg)) {
158 ret = PTR_ERR(boot_reg);
159 goto fail;
160 }
Tomasz Figa9637f302014-07-16 02:59:18 +0900161 __raw_writel(boot_addr, cpu_boot_reg(core_id));
Sachin Kamatb3205de2014-05-13 07:13:44 +0900162 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900163
Tomasz Figa9637f302014-07-16 02:59:18 +0900164 call_firmware_op(cpu_boot, core_id);
Tomasz Figabeddf632012-12-11 13:58:43 +0900165
Rob Herringb1cffeb2012-11-26 15:05:48 -0600166 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
JungHi Min911c29b2011-07-16 13:39:09 +0900167
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900168 if (pen_release == -1)
169 break;
170
171 udelay(10);
172 }
173
174 /*
175 * now the secondary core is starting up let it run its
176 * calibrations, then wait for it to finish
177 */
Sachin Kamatb3205de2014-05-13 07:13:44 +0900178fail:
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900179 spin_unlock(&boot_lock);
180
Sachin Kamatb3205de2014-05-13 07:13:44 +0900181 return pen_release != -1 ? ret : 0;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900182}
183
184/*
185 * Initialise the CPU possible map early - this describes the CPUs
186 * which may be present or become present in the system.
187 */
188
Marc Zyngier06853ae2011-09-08 13:15:22 +0100189static void __init exynos_smp_init_cpus(void)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900190{
191 void __iomem *scu_base = scu_base_addr();
192 unsigned int i, ncores;
193
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900194 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900195 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900196 else
197 /*
198 * CPU Nodes are passed thru DT and set_cpu_possible
199 * is set by "arm_dt_init_cpu_maps".
200 */
201 return;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900202
203 /* sanity check */
Russell Kinga06f9162011-10-20 22:04:18 +0100204 if (ncores > nr_cpu_ids) {
205 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
206 ncores, nr_cpu_ids);
207 ncores = nr_cpu_ids;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900208 }
209
210 for (i = 0; i < ncores; i++)
211 set_cpu_possible(i, true);
212}
213
Marc Zyngier06853ae2011-09-08 13:15:22 +0100214static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900215{
Tomasz Figa1f054f52012-11-24 11:13:48 +0900216 int i;
217
Olof Johansson1754c422014-06-02 21:47:46 -0700218 exynos_sysram_init();
219
Leela Krishna Amudalab5f3c752013-06-10 18:28:04 +0900220 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900221 scu_enable(scu_base_addr());
Russell King05c74a62010-12-03 11:09:48 +0000222
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900223 /*
Russell King05c74a62010-12-03 11:09:48 +0000224 * Write the address of secondary startup into the
225 * system-wide flags register. The boot monitor waits
226 * until it receives a soft interrupt, and then the
227 * secondary CPU branches to this address.
Tomasz Figabeddf632012-12-11 13:58:43 +0900228 *
229 * Try using firmware operation first and fall back to
230 * boot register if it fails.
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900231 */
Tomasz Figabeddf632012-12-11 13:58:43 +0900232 for (i = 1; i < max_cpus; ++i) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900233 unsigned long boot_addr;
Tomasz Figa9637f302014-07-16 02:59:18 +0900234 u32 mpidr;
235 u32 core_id;
Sachin Kamatb3205de2014-05-13 07:13:44 +0900236 int ret;
Tomasz Figabeddf632012-12-11 13:58:43 +0900237
Tomasz Figa9637f302014-07-16 02:59:18 +0900238 mpidr = cpu_logical_map(i);
239 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
Tomasz Figabeddf632012-12-11 13:58:43 +0900240 boot_addr = virt_to_phys(exynos4_secondary_startup);
241
Tomasz Figa9637f302014-07-16 02:59:18 +0900242 ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900243 if (ret && ret != -ENOSYS)
244 break;
245 if (ret == -ENOSYS) {
Tomasz Figa9637f302014-07-16 02:59:18 +0900246 void __iomem *boot_reg = cpu_boot_reg(core_id);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900247
248 if (IS_ERR(boot_reg))
249 break;
Tomasz Figa9637f302014-07-16 02:59:18 +0900250 __raw_writel(boot_addr, cpu_boot_reg(core_id));
Sachin Kamatb3205de2014-05-13 07:13:44 +0900251 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900252 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900253}
Marc Zyngier06853ae2011-09-08 13:15:22 +0100254
255struct smp_operations exynos_smp_ops __initdata = {
256 .smp_init_cpus = exynos_smp_init_cpus,
257 .smp_prepare_cpus = exynos_smp_prepare_cpus,
258 .smp_secondary_init = exynos_secondary_init,
259 .smp_boot_secondary = exynos_boot_secondary,
260#ifdef CONFIG_HOTPLUG_CPU
261 .cpu_die = exynos_cpu_die,
262#endif
263};