2 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
5 * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
7 * Copyright (C) 2002 ARM Ltd.
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.
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>
22 #include <linux/of_address.h>
24 #include <asm/cacheflush.h>
25 #include <asm/smp_plat.h>
26 #include <asm/smp_scu.h>
27 #include <asm/firmware.h>
32 extern void exynos4_secondary_startup(void);
34 static inline void __iomem
*cpu_boot_reg_base(void)
36 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1
)
38 return sysram_base_addr
;
41 static inline void __iomem
*cpu_boot_reg(int cpu
)
43 void __iomem
*boot_reg
;
45 boot_reg
= cpu_boot_reg_base();
47 return ERR_PTR(-ENODEV
);
48 if (soc_is_exynos4412())
50 else if (soc_is_exynos5420() || soc_is_exynos5800())
56 * Write pen_release in a way that is guaranteed to be visible to all
57 * observers, irrespective of whether they're taking part in coherency
58 * or not. This is necessary for the hotplug code to work reliably.
60 static void write_pen_release(int val
)
64 sync_cache_w(&pen_release
);
67 static void __iomem
*scu_base_addr(void)
69 return (void __iomem
*)(S5P_VA_SCU
);
72 static DEFINE_SPINLOCK(boot_lock
);
74 static void exynos_secondary_init(unsigned int cpu
)
77 * let the primary processor know we're out of the
78 * pen, then head off into the C entry point
80 write_pen_release(-1);
83 * Synchronise with the boot thread.
85 spin_lock(&boot_lock
);
86 spin_unlock(&boot_lock
);
89 static int exynos_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
91 unsigned long timeout
;
92 unsigned long phys_cpu
= cpu_logical_map(cpu
);
96 * Set synchronisation state between this boot processor
97 * and the secondary one
99 spin_lock(&boot_lock
);
102 * The secondary processor is waiting to be released from
103 * the holding pen - release it, then wait for it to flag
104 * that it has been released by resetting pen_release.
106 * Note that "pen_release" is the hardware CPU ID, whereas
107 * "cpu" is Linux's internal ID.
109 write_pen_release(phys_cpu
);
111 if (!exynos_cpu_power_state(cpu
)) {
112 exynos_cpu_power_up(cpu
);
115 /* wait max 10 ms until cpu1 is on */
116 while (exynos_cpu_power_state(cpu
) != S5P_CORE_LOCAL_PWR_EN
) {
124 printk(KERN_ERR
"cpu1 power enable failed");
125 spin_unlock(&boot_lock
);
130 * Send the secondary CPU a soft interrupt, thereby causing
131 * the boot monitor to read the system wide flags register,
132 * and branch to the address found there.
135 timeout
= jiffies
+ (1 * HZ
);
136 while (time_before(jiffies
, timeout
)) {
137 unsigned long boot_addr
;
141 boot_addr
= virt_to_phys(exynos4_secondary_startup
);
144 * Try to set boot address using firmware first
145 * and fall back to boot register if it fails.
147 ret
= call_firmware_op(set_cpu_boot_addr
, phys_cpu
, boot_addr
);
148 if (ret
&& ret
!= -ENOSYS
)
150 if (ret
== -ENOSYS
) {
151 void __iomem
*boot_reg
= cpu_boot_reg(phys_cpu
);
153 if (IS_ERR(boot_reg
)) {
154 ret
= PTR_ERR(boot_reg
);
157 __raw_writel(boot_addr
, cpu_boot_reg(phys_cpu
));
160 call_firmware_op(cpu_boot
, phys_cpu
);
162 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
164 if (pen_release
== -1)
171 * now the secondary core is starting up let it run its
172 * calibrations, then wait for it to finish
175 spin_unlock(&boot_lock
);
177 return pen_release
!= -1 ? ret
: 0;
181 * Initialise the CPU possible map early - this describes the CPUs
182 * which may be present or become present in the system.
185 static void __init
exynos_smp_init_cpus(void)
187 void __iomem
*scu_base
= scu_base_addr();
188 unsigned int i
, ncores
;
190 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9
)
191 ncores
= scu_base
? scu_get_core_count(scu_base
) : 1;
194 * CPU Nodes are passed thru DT and set_cpu_possible
195 * is set by "arm_dt_init_cpu_maps".
200 if (ncores
> nr_cpu_ids
) {
201 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
206 for (i
= 0; i
< ncores
; i
++)
207 set_cpu_possible(i
, true);
210 static void __init
exynos_smp_prepare_cpus(unsigned int max_cpus
)
214 exynos_sysram_init();
216 if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9
)
217 scu_enable(scu_base_addr());
220 * Write the address of secondary startup into the
221 * system-wide flags register. The boot monitor waits
222 * until it receives a soft interrupt, and then the
223 * secondary CPU branches to this address.
225 * Try using firmware operation first and fall back to
226 * boot register if it fails.
228 for (i
= 1; i
< max_cpus
; ++i
) {
229 unsigned long phys_cpu
;
230 unsigned long boot_addr
;
233 phys_cpu
= cpu_logical_map(i
);
234 boot_addr
= virt_to_phys(exynos4_secondary_startup
);
236 ret
= call_firmware_op(set_cpu_boot_addr
, phys_cpu
, boot_addr
);
237 if (ret
&& ret
!= -ENOSYS
)
239 if (ret
== -ENOSYS
) {
240 void __iomem
*boot_reg
= cpu_boot_reg(phys_cpu
);
242 if (IS_ERR(boot_reg
))
244 __raw_writel(boot_addr
, cpu_boot_reg(phys_cpu
));
249 struct smp_operations exynos_smp_ops __initdata
= {
250 .smp_init_cpus
= exynos_smp_init_cpus
,
251 .smp_prepare_cpus
= exynos_smp_prepare_cpus
,
252 .smp_secondary_init
= exynos_secondary_init
,
253 .smp_boot_secondary
= exynos_boot_secondary
,
254 #ifdef CONFIG_HOTPLUG_CPU
255 .cpu_die
= exynos_cpu_die
,