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/jiffies.h>
19 #include <linux/smp.h>
21 #include <linux/of_address.h>
22 #include <linux/soc/samsung/exynos-regs-pmu.h>
24 #include <asm/cacheflush.h>
26 #include <asm/smp_plat.h>
27 #include <asm/smp_scu.h>
28 #include <asm/firmware.h>
34 extern void exynos4_secondary_startup(void);
36 #ifdef CONFIG_HOTPLUG_CPU
37 static inline void cpu_leave_lowpower(u32 core_id
)
42 "mrc p15, 0, %0, c1, c0, 0\n"
44 " mcr p15, 0, %0, c1, c0, 0\n"
45 " mrc p15, 0, %0, c1, c0, 1\n"
47 " mcr p15, 0, %0, c1, c0, 1\n"
49 : "Ir" (CR_C
), "Ir" (0x40)
53 static inline void platform_do_lowpower(unsigned int cpu
, int *spurious
)
55 u32 mpidr
= cpu_logical_map(cpu
);
56 u32 core_id
= MPIDR_AFFINITY_LEVEL(mpidr
, 0);
60 /* Turn the CPU off on next WFI instruction. */
61 exynos_cpu_power_down(core_id
);
65 if (pen_release
== core_id
) {
67 * OK, proper wakeup, we're done
73 * Getting here, means that we have come out of WFI without
74 * having been woken up - this shouldn't happen
76 * Just note it happening - when we're woken, we can report
82 #endif /* CONFIG_HOTPLUG_CPU */
85 * exynos_core_power_down : power down the specified cpu
86 * @cpu : the cpu to power down
88 * Power down the specified cpu. The sequence must be finished by a
89 * call to cpu_do_idle()
92 void exynos_cpu_power_down(int cpu
)
96 if (cpu
== 0 && (soc_is_exynos5420() || soc_is_exynos5800())) {
98 * Bypass power down for CPU0 during suspend. Check for
99 * the SYS_PWR_REG value to decide if we are suspending
102 int val
= pmu_raw_readl(EXYNOS5_ARM_CORE0_SYS_PWR_REG
);
104 if (!(val
& S5P_CORE_LOCAL_PWR_EN
))
108 core_conf
= pmu_raw_readl(EXYNOS_ARM_CORE_CONFIGURATION(cpu
));
109 core_conf
&= ~S5P_CORE_LOCAL_PWR_EN
;
110 pmu_raw_writel(core_conf
, EXYNOS_ARM_CORE_CONFIGURATION(cpu
));
114 * exynos_cpu_power_up : power up the specified cpu
115 * @cpu : the cpu to power up
117 * Power up the specified cpu
119 void exynos_cpu_power_up(int cpu
)
121 u32 core_conf
= S5P_CORE_LOCAL_PWR_EN
;
123 if (soc_is_exynos3250())
124 core_conf
|= S5P_CORE_AUTOWAKEUP_EN
;
126 pmu_raw_writel(core_conf
,
127 EXYNOS_ARM_CORE_CONFIGURATION(cpu
));
131 * exynos_cpu_power_state : returns the power state of the cpu
132 * @cpu : the cpu to retrieve the power state from
135 int exynos_cpu_power_state(int cpu
)
137 return (pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(cpu
)) &
138 S5P_CORE_LOCAL_PWR_EN
);
142 * exynos_cluster_power_down : power down the specified cluster
143 * @cluster : the cluster to power down
145 void exynos_cluster_power_down(int cluster
)
147 pmu_raw_writel(0, EXYNOS_COMMON_CONFIGURATION(cluster
));
151 * exynos_cluster_power_up : power up the specified cluster
152 * @cluster : the cluster to power up
154 void exynos_cluster_power_up(int cluster
)
156 pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN
,
157 EXYNOS_COMMON_CONFIGURATION(cluster
));
161 * exynos_cluster_power_state : returns the power state of the cluster
162 * @cluster : the cluster to retrieve the power state from
165 int exynos_cluster_power_state(int cluster
)
167 return (pmu_raw_readl(EXYNOS_COMMON_STATUS(cluster
)) &
168 S5P_CORE_LOCAL_PWR_EN
);
171 static void __iomem
*cpu_boot_reg_base(void)
173 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1
)
174 return pmu_base_addr
+ S5P_INFORM5
;
175 return sysram_base_addr
;
178 static inline void __iomem
*cpu_boot_reg(int cpu
)
180 void __iomem
*boot_reg
;
182 boot_reg
= cpu_boot_reg_base();
184 return IOMEM_ERR_PTR(-ENODEV
);
185 if (soc_is_exynos4412())
187 else if (soc_is_exynos5420() || soc_is_exynos5800())
193 * Set wake up by local power mode and execute software reset for given core.
195 * Currently this is needed only when booting secondary CPU on Exynos3250.
197 void exynos_core_restart(u32 core_id
)
201 if (!of_machine_is_compatible("samsung,exynos3250"))
204 while (!pmu_raw_readl(S5P_PMU_SPARE2
))
208 val
= pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(core_id
));
209 val
|= S5P_CORE_WAKEUP_FROM_LOCAL_CFG
;
210 pmu_raw_writel(val
, EXYNOS_ARM_CORE_STATUS(core_id
));
212 pmu_raw_writel(EXYNOS_CORE_PO_RESET(core_id
), EXYNOS_SWRESET
);
216 * Write pen_release in a way that is guaranteed to be visible to all
217 * observers, irrespective of whether they're taking part in coherency
218 * or not. This is necessary for the hotplug code to work reliably.
220 static void write_pen_release(int val
)
224 sync_cache_w(&pen_release
);
227 static void __iomem
*scu_base_addr(void)
229 return (void __iomem
*)(S5P_VA_SCU
);
232 static DEFINE_SPINLOCK(boot_lock
);
234 static void exynos_secondary_init(unsigned int cpu
)
237 * let the primary processor know we're out of the
238 * pen, then head off into the C entry point
240 write_pen_release(-1);
243 * Synchronise with the boot thread.
245 spin_lock(&boot_lock
);
246 spin_unlock(&boot_lock
);
249 int exynos_set_boot_addr(u32 core_id
, unsigned long boot_addr
)
254 * Try to set boot address using firmware first
255 * and fall back to boot register if it fails.
257 ret
= call_firmware_op(set_cpu_boot_addr
, core_id
, boot_addr
);
258 if (ret
&& ret
!= -ENOSYS
)
260 if (ret
== -ENOSYS
) {
261 void __iomem
*boot_reg
= cpu_boot_reg(core_id
);
263 if (IS_ERR(boot_reg
)) {
264 ret
= PTR_ERR(boot_reg
);
267 writel_relaxed(boot_addr
, boot_reg
);
274 int exynos_get_boot_addr(u32 core_id
, unsigned long *boot_addr
)
279 * Try to get boot address using firmware first
280 * and fall back to boot register if it fails.
282 ret
= call_firmware_op(get_cpu_boot_addr
, core_id
, boot_addr
);
283 if (ret
&& ret
!= -ENOSYS
)
285 if (ret
== -ENOSYS
) {
286 void __iomem
*boot_reg
= cpu_boot_reg(core_id
);
288 if (IS_ERR(boot_reg
)) {
289 ret
= PTR_ERR(boot_reg
);
292 *boot_addr
= readl_relaxed(boot_reg
);
299 static int exynos_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
301 unsigned long timeout
;
302 u32 mpidr
= cpu_logical_map(cpu
);
303 u32 core_id
= MPIDR_AFFINITY_LEVEL(mpidr
, 0);
307 * Set synchronisation state between this boot processor
308 * and the secondary one
310 spin_lock(&boot_lock
);
313 * The secondary processor is waiting to be released from
314 * the holding pen - release it, then wait for it to flag
315 * that it has been released by resetting pen_release.
317 * Note that "pen_release" is the hardware CPU core ID, whereas
318 * "cpu" is Linux's internal ID.
320 write_pen_release(core_id
);
322 if (!exynos_cpu_power_state(core_id
)) {
323 exynos_cpu_power_up(core_id
);
326 /* wait max 10 ms until cpu1 is on */
327 while (exynos_cpu_power_state(core_id
)
328 != S5P_CORE_LOCAL_PWR_EN
) {
336 printk(KERN_ERR
"cpu1 power enable failed");
337 spin_unlock(&boot_lock
);
342 exynos_core_restart(core_id
);
345 * Send the secondary CPU a soft interrupt, thereby causing
346 * the boot monitor to read the system wide flags register,
347 * and branch to the address found there.
350 timeout
= jiffies
+ (1 * HZ
);
351 while (time_before(jiffies
, timeout
)) {
352 unsigned long boot_addr
;
356 boot_addr
= virt_to_phys(exynos4_secondary_startup
);
358 ret
= exynos_set_boot_addr(core_id
, boot_addr
);
362 call_firmware_op(cpu_boot
, core_id
);
364 if (soc_is_exynos3250())
367 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
369 if (pen_release
== -1)
375 if (pen_release
!= -1)
379 * now the secondary core is starting up let it run its
380 * calibrations, then wait for it to finish
383 spin_unlock(&boot_lock
);
385 return pen_release
!= -1 ? ret
: 0;
389 * Initialise the CPU possible map early - this describes the CPUs
390 * which may be present or become present in the system.
393 static void __init
exynos_smp_init_cpus(void)
395 void __iomem
*scu_base
= scu_base_addr();
396 unsigned int i
, ncores
;
398 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9
)
399 ncores
= scu_base
? scu_get_core_count(scu_base
) : 1;
402 * CPU Nodes are passed thru DT and set_cpu_possible
403 * is set by "arm_dt_init_cpu_maps".
408 if (ncores
> nr_cpu_ids
) {
409 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
414 for (i
= 0; i
< ncores
; i
++)
415 set_cpu_possible(i
, true);
418 static void __init
exynos_smp_prepare_cpus(unsigned int max_cpus
)
422 exynos_sysram_init();
424 exynos_set_delayed_reset_assertion(true);
426 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9
)
427 scu_enable(scu_base_addr());
430 * Write the address of secondary startup into the
431 * system-wide flags register. The boot monitor waits
432 * until it receives a soft interrupt, and then the
433 * secondary CPU branches to this address.
435 * Try using firmware operation first and fall back to
436 * boot register if it fails.
438 for (i
= 1; i
< max_cpus
; ++i
) {
439 unsigned long boot_addr
;
444 mpidr
= cpu_logical_map(i
);
445 core_id
= MPIDR_AFFINITY_LEVEL(mpidr
, 0);
446 boot_addr
= virt_to_phys(exynos4_secondary_startup
);
448 ret
= exynos_set_boot_addr(core_id
, boot_addr
);
454 #ifdef CONFIG_HOTPLUG_CPU
456 * platform-specific code to shutdown a CPU
458 * Called with IRQs disabled
460 static void exynos_cpu_die(unsigned int cpu
)
463 u32 mpidr
= cpu_logical_map(cpu
);
464 u32 core_id
= MPIDR_AFFINITY_LEVEL(mpidr
, 0);
466 v7_exit_coherency_flush(louis
);
468 platform_do_lowpower(cpu
, &spurious
);
471 * bring this CPU back into the world of cache
472 * coherency, and then restore interrupts
474 cpu_leave_lowpower(core_id
);
477 pr_warn("CPU%u: %u spurious wakeup calls\n", cpu
, spurious
);
479 #endif /* CONFIG_HOTPLUG_CPU */
481 const struct smp_operations exynos_smp_ops __initconst
= {
482 .smp_init_cpus
= exynos_smp_init_cpus
,
483 .smp_prepare_cpus
= exynos_smp_prepare_cpus
,
484 .smp_secondary_init
= exynos_secondary_init
,
485 .smp_boot_secondary
= exynos_boot_secondary
,
486 #ifdef CONFIG_HOTPLUG_CPU
487 .cpu_die
= exynos_cpu_die
,