blob: 50b9aad5e27b729acc2aa060be4d604d866ef07b [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
Tomasz Figa1f054f52012-11-24 11:13:48 +090035static inline void __iomem *cpu_boot_reg_base(void)
36{
37 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
38 return S5P_INFORM5;
Sachin Kamatb3205de2014-05-13 07:13:44 +090039 return sysram_base_addr;
Tomasz Figa1f054f52012-11-24 11:13:48 +090040}
41
42static inline void __iomem *cpu_boot_reg(int cpu)
43{
44 void __iomem *boot_reg;
45
46 boot_reg = cpu_boot_reg_base();
Sachin Kamatb3205de2014-05-13 07:13:44 +090047 if (!boot_reg)
48 return ERR_PTR(-ENODEV);
Tomasz Figa1f054f52012-11-24 11:13:48 +090049 if (soc_is_exynos4412())
50 boot_reg += 4*cpu;
Arun Kumar K86c6f142014-05-26 04:16:11 +090051 else if (soc_is_exynos5420() || soc_is_exynos5800())
Chander Kashyap1580be32013-06-19 00:29:35 +090052 boot_reg += 4;
Tomasz Figa1f054f52012-11-24 11:13:48 +090053 return boot_reg;
54}
JungHi Min911c29b2011-07-16 13:39:09 +090055
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090056/*
Russell King3705ff62010-12-18 10:53:12 +000057 * Write pen_release in a way that is guaranteed to be visible to all
58 * observers, irrespective of whether they're taking part in coherency
59 * or not. This is necessary for the hotplug code to work reliably.
60 */
61static void write_pen_release(int val)
62{
63 pen_release = val;
64 smp_wmb();
Nicolas Pitref45913f2013-12-05 14:26:16 -050065 sync_cache_w(&pen_release);
Russell King3705ff62010-12-18 10:53:12 +000066}
67
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090068static void __iomem *scu_base_addr(void)
69{
70 return (void __iomem *)(S5P_VA_SCU);
71}
72
73static DEFINE_SPINLOCK(boot_lock);
74
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040075static void exynos_secondary_init(unsigned int cpu)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090076{
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090077 /*
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090078 * let the primary processor know we're out of the
79 * pen, then head off into the C entry point
80 */
Russell King3705ff62010-12-18 10:53:12 +000081 write_pen_release(-1);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090082
83 /*
84 * Synchronise with the boot thread.
85 */
86 spin_lock(&boot_lock);
87 spin_unlock(&boot_lock);
88}
89
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040090static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090091{
92 unsigned long timeout;
Tomasz Figa9637f302014-07-16 02:59:18 +090093 u32 mpidr = cpu_logical_map(cpu);
94 u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
Sachin Kamatb3205de2014-05-13 07:13:44 +090095 int ret = -ENOSYS;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +090096
97 /*
98 * Set synchronisation state between this boot processor
99 * and the secondary one
100 */
101 spin_lock(&boot_lock);
102
103 /*
104 * The secondary processor is waiting to be released from
105 * the holding pen - release it, then wait for it to flag
106 * that it has been released by resetting pen_release.
107 *
Tomasz Figa9637f302014-07-16 02:59:18 +0900108 * Note that "pen_release" is the hardware CPU core ID, whereas
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900109 * "cpu" is Linux's internal ID.
110 */
Tomasz Figa9637f302014-07-16 02:59:18 +0900111 write_pen_release(core_id);
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900112
Tomasz Figa9637f302014-07-16 02:59:18 +0900113 if (!exynos_cpu_power_state(core_id)) {
114 exynos_cpu_power_up(core_id);
JungHi Min911c29b2011-07-16 13:39:09 +0900115 timeout = 10;
116
117 /* wait max 10 ms until cpu1 is on */
Tomasz Figa9637f302014-07-16 02:59:18 +0900118 while (exynos_cpu_power_state(core_id)
119 != S5P_CORE_LOCAL_PWR_EN) {
JungHi Min911c29b2011-07-16 13:39:09 +0900120 if (timeout-- == 0)
121 break;
122
123 mdelay(1);
124 }
125
126 if (timeout == 0) {
127 printk(KERN_ERR "cpu1 power enable failed");
128 spin_unlock(&boot_lock);
129 return -ETIMEDOUT;
130 }
131 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900132 /*
133 * Send the secondary CPU a soft interrupt, thereby causing
134 * the boot monitor to read the system wide flags register,
135 * and branch to the address found there.
136 */
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900137
138 timeout = jiffies + (1 * HZ);
139 while (time_before(jiffies, timeout)) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900140 unsigned long boot_addr;
141
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900142 smp_rmb();
JungHi Min911c29b2011-07-16 13:39:09 +0900143
Tomasz Figabeddf632012-12-11 13:58:43 +0900144 boot_addr = virt_to_phys(exynos4_secondary_startup);
145
146 /*
147 * Try to set boot address using firmware first
148 * and fall back to boot register if it fails.
149 */
Tomasz Figa9637f302014-07-16 02:59:18 +0900150 ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900151 if (ret && ret != -ENOSYS)
152 goto fail;
153 if (ret == -ENOSYS) {
Tomasz Figa9637f302014-07-16 02:59:18 +0900154 void __iomem *boot_reg = cpu_boot_reg(core_id);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900155
156 if (IS_ERR(boot_reg)) {
157 ret = PTR_ERR(boot_reg);
158 goto fail;
159 }
Tomasz Figa9637f302014-07-16 02:59:18 +0900160 __raw_writel(boot_addr, cpu_boot_reg(core_id));
Sachin Kamatb3205de2014-05-13 07:13:44 +0900161 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900162
Tomasz Figa9637f302014-07-16 02:59:18 +0900163 call_firmware_op(cpu_boot, core_id);
Tomasz Figabeddf632012-12-11 13:58:43 +0900164
Rob Herringb1cffeb2012-11-26 15:05:48 -0600165 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
JungHi Min911c29b2011-07-16 13:39:09 +0900166
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900167 if (pen_release == -1)
168 break;
169
170 udelay(10);
171 }
172
173 /*
174 * now the secondary core is starting up let it run its
175 * calibrations, then wait for it to finish
176 */
Sachin Kamatb3205de2014-05-13 07:13:44 +0900177fail:
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900178 spin_unlock(&boot_lock);
179
Sachin Kamatb3205de2014-05-13 07:13:44 +0900180 return pen_release != -1 ? ret : 0;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900181}
182
183/*
184 * Initialise the CPU possible map early - this describes the CPUs
185 * which may be present or become present in the system.
186 */
187
Marc Zyngier06853ae2011-09-08 13:15:22 +0100188static void __init exynos_smp_init_cpus(void)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900189{
190 void __iomem *scu_base = scu_base_addr();
191 unsigned int i, ncores;
192
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900193 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900194 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
Chander Kashyap1897d2f2013-06-19 00:29:34 +0900195 else
196 /*
197 * CPU Nodes are passed thru DT and set_cpu_possible
198 * is set by "arm_dt_init_cpu_maps".
199 */
200 return;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900201
202 /* sanity check */
Russell Kinga06f9162011-10-20 22:04:18 +0100203 if (ncores > nr_cpu_ids) {
204 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
205 ncores, nr_cpu_ids);
206 ncores = nr_cpu_ids;
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900207 }
208
209 for (i = 0; i < ncores; i++)
210 set_cpu_possible(i, true);
211}
212
Marc Zyngier06853ae2011-09-08 13:15:22 +0100213static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900214{
Tomasz Figa1f054f52012-11-24 11:13:48 +0900215 int i;
216
Olof Johansson1754c422014-06-02 21:47:46 -0700217 exynos_sysram_init();
218
Leela Krishna Amudalab5f3c752013-06-10 18:28:04 +0900219 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
Kukjin Kime9bba612012-01-25 15:35:57 +0900220 scu_enable(scu_base_addr());
Russell King05c74a62010-12-03 11:09:48 +0000221
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900222 /*
Russell King05c74a62010-12-03 11:09:48 +0000223 * Write the address of secondary startup into the
224 * system-wide flags register. The boot monitor waits
225 * until it receives a soft interrupt, and then the
226 * secondary CPU branches to this address.
Tomasz Figabeddf632012-12-11 13:58:43 +0900227 *
228 * Try using firmware operation first and fall back to
229 * boot register if it fails.
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900230 */
Tomasz Figabeddf632012-12-11 13:58:43 +0900231 for (i = 1; i < max_cpus; ++i) {
Tomasz Figabeddf632012-12-11 13:58:43 +0900232 unsigned long boot_addr;
Tomasz Figa9637f302014-07-16 02:59:18 +0900233 u32 mpidr;
234 u32 core_id;
Sachin Kamatb3205de2014-05-13 07:13:44 +0900235 int ret;
Tomasz Figabeddf632012-12-11 13:58:43 +0900236
Tomasz Figa9637f302014-07-16 02:59:18 +0900237 mpidr = cpu_logical_map(i);
238 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
Tomasz Figabeddf632012-12-11 13:58:43 +0900239 boot_addr = virt_to_phys(exynos4_secondary_startup);
240
Tomasz Figa9637f302014-07-16 02:59:18 +0900241 ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900242 if (ret && ret != -ENOSYS)
243 break;
244 if (ret == -ENOSYS) {
Tomasz Figa9637f302014-07-16 02:59:18 +0900245 void __iomem *boot_reg = cpu_boot_reg(core_id);
Sachin Kamatb3205de2014-05-13 07:13:44 +0900246
247 if (IS_ERR(boot_reg))
248 break;
Tomasz Figa9637f302014-07-16 02:59:18 +0900249 __raw_writel(boot_addr, cpu_boot_reg(core_id));
Sachin Kamatb3205de2014-05-13 07:13:44 +0900250 }
Tomasz Figabeddf632012-12-11 13:58:43 +0900251 }
Changhwan Youn2b12b5c2010-07-26 21:08:52 +0900252}
Marc Zyngier06853ae2011-09-08 13:15:22 +0100253
254struct smp_operations exynos_smp_ops __initdata = {
255 .smp_init_cpus = exynos_smp_init_cpus,
256 .smp_prepare_cpus = exynos_smp_prepare_cpus,
257 .smp_secondary_init = exynos_secondary_init,
258 .smp_boot_secondary = exynos_boot_secondary,
259#ifdef CONFIG_HOTPLUG_CPU
260 .cpu_die = exynos_cpu_die,
261#endif
262};