xref: /openbmc/linux/arch/arm/mach-exynos/platsmp.c (revision 1225ad72866b440574a22372b9edceb035632f2b)
14552386aSPankaj Dubey  /*
283014579SKukjin Kim  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
383014579SKukjin Kim  *		http://www.samsung.com
483014579SKukjin Kim  *
583014579SKukjin Kim  * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
683014579SKukjin Kim  *
783014579SKukjin Kim  *  Copyright (C) 2002 ARM Ltd.
883014579SKukjin Kim  *  All Rights Reserved
983014579SKukjin Kim  *
1083014579SKukjin Kim  * This program is free software; you can redistribute it and/or modify
1183014579SKukjin Kim  * it under the terms of the GNU General Public License version 2 as
1283014579SKukjin Kim  * published by the Free Software Foundation.
1383014579SKukjin Kim */
1483014579SKukjin Kim 
1583014579SKukjin Kim #include <linux/init.h>
1683014579SKukjin Kim #include <linux/errno.h>
1783014579SKukjin Kim #include <linux/delay.h>
1883014579SKukjin Kim #include <linux/device.h>
1983014579SKukjin Kim #include <linux/jiffies.h>
2083014579SKukjin Kim #include <linux/smp.h>
2183014579SKukjin Kim #include <linux/io.h>
22b3205deaSSachin Kamat #include <linux/of_address.h>
2383014579SKukjin Kim 
2483014579SKukjin Kim #include <asm/cacheflush.h>
256f0b7c0cSKrzysztof Kozlowski #include <asm/cp15.h>
26eb50439bSWill Deacon #include <asm/smp_plat.h>
2783014579SKukjin Kim #include <asm/smp_scu.h>
28beddf63fSTomasz Figa #include <asm/firmware.h>
2983014579SKukjin Kim 
302e94ac42SPankaj Dubey #include <mach/map.h>
312e94ac42SPankaj Dubey 
3206853ae4SMarc Zyngier #include "common.h"
3365c9a853SKukjin Kim #include "regs-pmu.h"
3406853ae4SMarc Zyngier 
3583014579SKukjin Kim extern void exynos4_secondary_startup(void);
3683014579SKukjin Kim 
376f0b7c0cSKrzysztof Kozlowski #ifdef CONFIG_HOTPLUG_CPU
3813cfa6c4SKrzysztof Kozlowski static inline void cpu_leave_lowpower(u32 core_id)
396f0b7c0cSKrzysztof Kozlowski {
406f0b7c0cSKrzysztof Kozlowski 	unsigned int v;
416f0b7c0cSKrzysztof Kozlowski 
426f0b7c0cSKrzysztof Kozlowski 	asm volatile(
436f0b7c0cSKrzysztof Kozlowski 	"mrc	p15, 0, %0, c1, c0, 0\n"
446f0b7c0cSKrzysztof Kozlowski 	"	orr	%0, %0, %1\n"
456f0b7c0cSKrzysztof Kozlowski 	"	mcr	p15, 0, %0, c1, c0, 0\n"
466f0b7c0cSKrzysztof Kozlowski 	"	mrc	p15, 0, %0, c1, c0, 1\n"
476f0b7c0cSKrzysztof Kozlowski 	"	orr	%0, %0, %2\n"
486f0b7c0cSKrzysztof Kozlowski 	"	mcr	p15, 0, %0, c1, c0, 1\n"
496f0b7c0cSKrzysztof Kozlowski 	  : "=&r" (v)
506f0b7c0cSKrzysztof Kozlowski 	  : "Ir" (CR_C), "Ir" (0x40)
516f0b7c0cSKrzysztof Kozlowski 	  : "cc");
526f0b7c0cSKrzysztof Kozlowski }
536f0b7c0cSKrzysztof Kozlowski 
546f0b7c0cSKrzysztof Kozlowski static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
556f0b7c0cSKrzysztof Kozlowski {
566f0b7c0cSKrzysztof Kozlowski 	u32 mpidr = cpu_logical_map(cpu);
576f0b7c0cSKrzysztof Kozlowski 	u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
586f0b7c0cSKrzysztof Kozlowski 
596f0b7c0cSKrzysztof Kozlowski 	for (;;) {
606f0b7c0cSKrzysztof Kozlowski 
616f0b7c0cSKrzysztof Kozlowski 		/* Turn the CPU off on next WFI instruction. */
626f0b7c0cSKrzysztof Kozlowski 		exynos_cpu_power_down(core_id);
636f0b7c0cSKrzysztof Kozlowski 
646f0b7c0cSKrzysztof Kozlowski 		wfi();
656f0b7c0cSKrzysztof Kozlowski 
666f0b7c0cSKrzysztof Kozlowski 		if (pen_release == core_id) {
676f0b7c0cSKrzysztof Kozlowski 			/*
686f0b7c0cSKrzysztof Kozlowski 			 * OK, proper wakeup, we're done
696f0b7c0cSKrzysztof Kozlowski 			 */
706f0b7c0cSKrzysztof Kozlowski 			break;
716f0b7c0cSKrzysztof Kozlowski 		}
726f0b7c0cSKrzysztof Kozlowski 
736f0b7c0cSKrzysztof Kozlowski 		/*
746f0b7c0cSKrzysztof Kozlowski 		 * Getting here, means that we have come out of WFI without
756f0b7c0cSKrzysztof Kozlowski 		 * having been woken up - this shouldn't happen
766f0b7c0cSKrzysztof Kozlowski 		 *
776f0b7c0cSKrzysztof Kozlowski 		 * Just note it happening - when we're woken, we can report
786f0b7c0cSKrzysztof Kozlowski 		 * its occurrence.
796f0b7c0cSKrzysztof Kozlowski 		 */
806f0b7c0cSKrzysztof Kozlowski 		(*spurious)++;
816f0b7c0cSKrzysztof Kozlowski 	}
826f0b7c0cSKrzysztof Kozlowski }
836f0b7c0cSKrzysztof Kozlowski #endif /* CONFIG_HOTPLUG_CPU */
846f0b7c0cSKrzysztof Kozlowski 
857310d99fSKrzysztof Kozlowski /**
867310d99fSKrzysztof Kozlowski  * exynos_core_power_down : power down the specified cpu
877310d99fSKrzysztof Kozlowski  * @cpu : the cpu to power down
887310d99fSKrzysztof Kozlowski  *
897310d99fSKrzysztof Kozlowski  * Power down the specified cpu. The sequence must be finished by a
907310d99fSKrzysztof Kozlowski  * call to cpu_do_idle()
917310d99fSKrzysztof Kozlowski  *
927310d99fSKrzysztof Kozlowski  */
937310d99fSKrzysztof Kozlowski void exynos_cpu_power_down(int cpu)
947310d99fSKrzysztof Kozlowski {
95497ab3b3SBartlomiej Zolnierkiewicz 	u32 core_conf;
96497ab3b3SBartlomiej Zolnierkiewicz 
97ca489c58SKrzysztof Kozlowski 	if (cpu == 0 && (soc_is_exynos5420() || soc_is_exynos5800())) {
98adc548d7SAbhilash Kesavan 		/*
99adc548d7SAbhilash Kesavan 		 * Bypass power down for CPU0 during suspend. Check for
100adc548d7SAbhilash Kesavan 		 * the SYS_PWR_REG value to decide if we are suspending
101adc548d7SAbhilash Kesavan 		 * the system.
102adc548d7SAbhilash Kesavan 		 */
103adc548d7SAbhilash Kesavan 		int val = pmu_raw_readl(EXYNOS5_ARM_CORE0_SYS_PWR_REG);
104adc548d7SAbhilash Kesavan 
105adc548d7SAbhilash Kesavan 		if (!(val & S5P_CORE_LOCAL_PWR_EN))
106adc548d7SAbhilash Kesavan 			return;
107adc548d7SAbhilash Kesavan 	}
108497ab3b3SBartlomiej Zolnierkiewicz 
109497ab3b3SBartlomiej Zolnierkiewicz 	core_conf = pmu_raw_readl(EXYNOS_ARM_CORE_CONFIGURATION(cpu));
110497ab3b3SBartlomiej Zolnierkiewicz 	core_conf &= ~S5P_CORE_LOCAL_PWR_EN;
111497ab3b3SBartlomiej Zolnierkiewicz 	pmu_raw_writel(core_conf, EXYNOS_ARM_CORE_CONFIGURATION(cpu));
1127310d99fSKrzysztof Kozlowski }
1137310d99fSKrzysztof Kozlowski 
1147310d99fSKrzysztof Kozlowski /**
1157310d99fSKrzysztof Kozlowski  * exynos_cpu_power_up : power up the specified cpu
1167310d99fSKrzysztof Kozlowski  * @cpu : the cpu to power up
1177310d99fSKrzysztof Kozlowski  *
1187310d99fSKrzysztof Kozlowski  * Power up the specified cpu
1197310d99fSKrzysztof Kozlowski  */
1207310d99fSKrzysztof Kozlowski void exynos_cpu_power_up(int cpu)
1217310d99fSKrzysztof Kozlowski {
122497ab3b3SBartlomiej Zolnierkiewicz 	u32 core_conf = S5P_CORE_LOCAL_PWR_EN;
123497ab3b3SBartlomiej Zolnierkiewicz 
124497ab3b3SBartlomiej Zolnierkiewicz 	if (soc_is_exynos3250())
125497ab3b3SBartlomiej Zolnierkiewicz 		core_conf |= S5P_CORE_AUTOWAKEUP_EN;
126497ab3b3SBartlomiej Zolnierkiewicz 
127497ab3b3SBartlomiej Zolnierkiewicz 	pmu_raw_writel(core_conf,
1287310d99fSKrzysztof Kozlowski 			EXYNOS_ARM_CORE_CONFIGURATION(cpu));
1297310d99fSKrzysztof Kozlowski }
1307310d99fSKrzysztof Kozlowski 
1317310d99fSKrzysztof Kozlowski /**
1327310d99fSKrzysztof Kozlowski  * exynos_cpu_power_state : returns the power state of the cpu
1337310d99fSKrzysztof Kozlowski  * @cpu : the cpu to retrieve the power state from
1347310d99fSKrzysztof Kozlowski  *
1357310d99fSKrzysztof Kozlowski  */
1367310d99fSKrzysztof Kozlowski int exynos_cpu_power_state(int cpu)
1377310d99fSKrzysztof Kozlowski {
138944483d0SArnd Bergmann 	return (pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(cpu)) &
1397310d99fSKrzysztof Kozlowski 			S5P_CORE_LOCAL_PWR_EN);
1407310d99fSKrzysztof Kozlowski }
1417310d99fSKrzysztof Kozlowski 
1427310d99fSKrzysztof Kozlowski /**
1437310d99fSKrzysztof Kozlowski  * exynos_cluster_power_down : power down the specified cluster
1447310d99fSKrzysztof Kozlowski  * @cluster : the cluster to power down
1457310d99fSKrzysztof Kozlowski  */
1467310d99fSKrzysztof Kozlowski void exynos_cluster_power_down(int cluster)
1477310d99fSKrzysztof Kozlowski {
148944483d0SArnd Bergmann 	pmu_raw_writel(0, EXYNOS_COMMON_CONFIGURATION(cluster));
1497310d99fSKrzysztof Kozlowski }
1507310d99fSKrzysztof Kozlowski 
1517310d99fSKrzysztof Kozlowski /**
1527310d99fSKrzysztof Kozlowski  * exynos_cluster_power_up : power up the specified cluster
1537310d99fSKrzysztof Kozlowski  * @cluster : the cluster to power up
1547310d99fSKrzysztof Kozlowski  */
1557310d99fSKrzysztof Kozlowski void exynos_cluster_power_up(int cluster)
1567310d99fSKrzysztof Kozlowski {
157944483d0SArnd Bergmann 	pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN,
1587310d99fSKrzysztof Kozlowski 			EXYNOS_COMMON_CONFIGURATION(cluster));
1597310d99fSKrzysztof Kozlowski }
1607310d99fSKrzysztof Kozlowski 
1617310d99fSKrzysztof Kozlowski /**
1627310d99fSKrzysztof Kozlowski  * exynos_cluster_power_state : returns the power state of the cluster
1637310d99fSKrzysztof Kozlowski  * @cluster : the cluster to retrieve the power state from
1647310d99fSKrzysztof Kozlowski  *
1657310d99fSKrzysztof Kozlowski  */
1667310d99fSKrzysztof Kozlowski int exynos_cluster_power_state(int cluster)
1677310d99fSKrzysztof Kozlowski {
168944483d0SArnd Bergmann 	return (pmu_raw_readl(EXYNOS_COMMON_STATUS(cluster)) &
1697310d99fSKrzysztof Kozlowski 		S5P_CORE_LOCAL_PWR_EN);
1707310d99fSKrzysztof Kozlowski }
1717310d99fSKrzysztof Kozlowski 
172712eddf7SBartlomiej Zolnierkiewicz void __iomem *cpu_boot_reg_base(void)
1731f054f52STomasz Figa {
1741f054f52STomasz Figa 	if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
1752e94ac42SPankaj Dubey 		return pmu_base_addr + S5P_INFORM5;
176b3205deaSSachin Kamat 	return sysram_base_addr;
1771f054f52STomasz Figa }
1781f054f52STomasz Figa 
1791f054f52STomasz Figa static inline void __iomem *cpu_boot_reg(int cpu)
1801f054f52STomasz Figa {
1811f054f52STomasz Figa 	void __iomem *boot_reg;
1821f054f52STomasz Figa 
1831f054f52STomasz Figa 	boot_reg = cpu_boot_reg_base();
184b3205deaSSachin Kamat 	if (!boot_reg)
185b3205deaSSachin Kamat 		return ERR_PTR(-ENODEV);
1861f054f52STomasz Figa 	if (soc_is_exynos4412())
1871f054f52STomasz Figa 		boot_reg += 4*cpu;
18886c6f148SArun Kumar K 	else if (soc_is_exynos5420() || soc_is_exynos5800())
1891580be3dSChander Kashyap 		boot_reg += 4;
1901f054f52STomasz Figa 	return boot_reg;
1911f054f52STomasz Figa }
19283014579SKukjin Kim 
19383014579SKukjin Kim /*
194b588aaecSKrzysztof Kozlowski  * Set wake up by local power mode and execute software reset for given core.
195b588aaecSKrzysztof Kozlowski  *
196b588aaecSKrzysztof Kozlowski  * Currently this is needed only when booting secondary CPU on Exynos3250.
197b588aaecSKrzysztof Kozlowski  */
198b588aaecSKrzysztof Kozlowski static void exynos_core_restart(u32 core_id)
199b588aaecSKrzysztof Kozlowski {
200b588aaecSKrzysztof Kozlowski 	u32 val;
201b588aaecSKrzysztof Kozlowski 
202b588aaecSKrzysztof Kozlowski 	if (!of_machine_is_compatible("samsung,exynos3250"))
203b588aaecSKrzysztof Kozlowski 		return;
204b588aaecSKrzysztof Kozlowski 
205497ab3b3SBartlomiej Zolnierkiewicz 	while (!pmu_raw_readl(S5P_PMU_SPARE2))
206497ab3b3SBartlomiej Zolnierkiewicz 		udelay(10);
207497ab3b3SBartlomiej Zolnierkiewicz 	udelay(10);
208497ab3b3SBartlomiej Zolnierkiewicz 
209b588aaecSKrzysztof Kozlowski 	val = pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(core_id));
210b588aaecSKrzysztof Kozlowski 	val |= S5P_CORE_WAKEUP_FROM_LOCAL_CFG;
211b588aaecSKrzysztof Kozlowski 	pmu_raw_writel(val, EXYNOS_ARM_CORE_STATUS(core_id));
212b588aaecSKrzysztof Kozlowski 
213b588aaecSKrzysztof Kozlowski 	pmu_raw_writel(EXYNOS_CORE_PO_RESET(core_id), EXYNOS_SWRESET);
214b588aaecSKrzysztof Kozlowski }
215b588aaecSKrzysztof Kozlowski 
216b588aaecSKrzysztof Kozlowski /*
21783014579SKukjin Kim  * Write pen_release in a way that is guaranteed to be visible to all
21883014579SKukjin Kim  * observers, irrespective of whether they're taking part in coherency
21983014579SKukjin Kim  * or not.  This is necessary for the hotplug code to work reliably.
22083014579SKukjin Kim  */
22183014579SKukjin Kim static void write_pen_release(int val)
22283014579SKukjin Kim {
22383014579SKukjin Kim 	pen_release = val;
22483014579SKukjin Kim 	smp_wmb();
225f45913fdSNicolas Pitre 	sync_cache_w(&pen_release);
22683014579SKukjin Kim }
22783014579SKukjin Kim 
22883014579SKukjin Kim static void __iomem *scu_base_addr(void)
22983014579SKukjin Kim {
23083014579SKukjin Kim 	return (void __iomem *)(S5P_VA_SCU);
23183014579SKukjin Kim }
23283014579SKukjin Kim 
23383014579SKukjin Kim static DEFINE_SPINLOCK(boot_lock);
23483014579SKukjin Kim 
2358bd26e3aSPaul Gortmaker static void exynos_secondary_init(unsigned int cpu)
23683014579SKukjin Kim {
23783014579SKukjin Kim 	/*
23883014579SKukjin Kim 	 * let the primary processor know we're out of the
23983014579SKukjin Kim 	 * pen, then head off into the C entry point
24083014579SKukjin Kim 	 */
24183014579SKukjin Kim 	write_pen_release(-1);
24283014579SKukjin Kim 
24383014579SKukjin Kim 	/*
24483014579SKukjin Kim 	 * Synchronise with the boot thread.
24583014579SKukjin Kim 	 */
24683014579SKukjin Kim 	spin_lock(&boot_lock);
24783014579SKukjin Kim 	spin_unlock(&boot_lock);
24883014579SKukjin Kim }
24983014579SKukjin Kim 
250955d4cf8SBartlomiej Zolnierkiewicz static int exynos_set_boot_addr(u32 core_id, unsigned long boot_addr)
251955d4cf8SBartlomiej Zolnierkiewicz {
252955d4cf8SBartlomiej Zolnierkiewicz 	int ret;
253955d4cf8SBartlomiej Zolnierkiewicz 
254955d4cf8SBartlomiej Zolnierkiewicz 	/*
255955d4cf8SBartlomiej Zolnierkiewicz 	 * Try to set boot address using firmware first
256955d4cf8SBartlomiej Zolnierkiewicz 	 * and fall back to boot register if it fails.
257955d4cf8SBartlomiej Zolnierkiewicz 	 */
258955d4cf8SBartlomiej Zolnierkiewicz 	ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
259955d4cf8SBartlomiej Zolnierkiewicz 	if (ret && ret != -ENOSYS)
260955d4cf8SBartlomiej Zolnierkiewicz 		goto fail;
261955d4cf8SBartlomiej Zolnierkiewicz 	if (ret == -ENOSYS) {
262955d4cf8SBartlomiej Zolnierkiewicz 		void __iomem *boot_reg = cpu_boot_reg(core_id);
263955d4cf8SBartlomiej Zolnierkiewicz 
264955d4cf8SBartlomiej Zolnierkiewicz 		if (IS_ERR(boot_reg)) {
265955d4cf8SBartlomiej Zolnierkiewicz 			ret = PTR_ERR(boot_reg);
266955d4cf8SBartlomiej Zolnierkiewicz 			goto fail;
267955d4cf8SBartlomiej Zolnierkiewicz 		}
268955d4cf8SBartlomiej Zolnierkiewicz 		__raw_writel(boot_addr, boot_reg);
269955d4cf8SBartlomiej Zolnierkiewicz 		ret = 0;
270955d4cf8SBartlomiej Zolnierkiewicz 	}
271955d4cf8SBartlomiej Zolnierkiewicz fail:
272955d4cf8SBartlomiej Zolnierkiewicz 	return ret;
273955d4cf8SBartlomiej Zolnierkiewicz }
274955d4cf8SBartlomiej Zolnierkiewicz 
275*1225ad72SBartlomiej Zolnierkiewicz static int exynos_get_boot_addr(u32 core_id, unsigned long *boot_addr)
276*1225ad72SBartlomiej Zolnierkiewicz {
277*1225ad72SBartlomiej Zolnierkiewicz 	int ret;
278*1225ad72SBartlomiej Zolnierkiewicz 
279*1225ad72SBartlomiej Zolnierkiewicz 	/*
280*1225ad72SBartlomiej Zolnierkiewicz 	 * Try to get boot address using firmware first
281*1225ad72SBartlomiej Zolnierkiewicz 	 * and fall back to boot register if it fails.
282*1225ad72SBartlomiej Zolnierkiewicz 	 */
283*1225ad72SBartlomiej Zolnierkiewicz 	ret = call_firmware_op(get_cpu_boot_addr, core_id, boot_addr);
284*1225ad72SBartlomiej Zolnierkiewicz 	if (ret && ret != -ENOSYS)
285*1225ad72SBartlomiej Zolnierkiewicz 		goto fail;
286*1225ad72SBartlomiej Zolnierkiewicz 	if (ret == -ENOSYS) {
287*1225ad72SBartlomiej Zolnierkiewicz 		void __iomem *boot_reg = cpu_boot_reg(core_id);
288*1225ad72SBartlomiej Zolnierkiewicz 
289*1225ad72SBartlomiej Zolnierkiewicz 		if (IS_ERR(boot_reg)) {
290*1225ad72SBartlomiej Zolnierkiewicz 			ret = PTR_ERR(boot_reg);
291*1225ad72SBartlomiej Zolnierkiewicz 			goto fail;
292*1225ad72SBartlomiej Zolnierkiewicz 		}
293*1225ad72SBartlomiej Zolnierkiewicz 		*boot_addr = __raw_readl(boot_reg);
294*1225ad72SBartlomiej Zolnierkiewicz 		ret = 0;
295*1225ad72SBartlomiej Zolnierkiewicz 	}
296*1225ad72SBartlomiej Zolnierkiewicz fail:
297*1225ad72SBartlomiej Zolnierkiewicz 	return ret;
298*1225ad72SBartlomiej Zolnierkiewicz }
299*1225ad72SBartlomiej Zolnierkiewicz 
3008bd26e3aSPaul Gortmaker static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
30183014579SKukjin Kim {
30283014579SKukjin Kim 	unsigned long timeout;
3039637f30eSTomasz Figa 	u32 mpidr = cpu_logical_map(cpu);
3049637f30eSTomasz Figa 	u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
305b3205deaSSachin Kamat 	int ret = -ENOSYS;
30683014579SKukjin Kim 
30783014579SKukjin Kim 	/*
30883014579SKukjin Kim 	 * Set synchronisation state between this boot processor
30983014579SKukjin Kim 	 * and the secondary one
31083014579SKukjin Kim 	 */
31183014579SKukjin Kim 	spin_lock(&boot_lock);
31283014579SKukjin Kim 
31383014579SKukjin Kim 	/*
31483014579SKukjin Kim 	 * The secondary processor is waiting to be released from
31583014579SKukjin Kim 	 * the holding pen - release it, then wait for it to flag
31683014579SKukjin Kim 	 * that it has been released by resetting pen_release.
31783014579SKukjin Kim 	 *
3189637f30eSTomasz Figa 	 * Note that "pen_release" is the hardware CPU core ID, whereas
31983014579SKukjin Kim 	 * "cpu" is Linux's internal ID.
32083014579SKukjin Kim 	 */
3219637f30eSTomasz Figa 	write_pen_release(core_id);
32283014579SKukjin Kim 
3239637f30eSTomasz Figa 	if (!exynos_cpu_power_state(core_id)) {
3249637f30eSTomasz Figa 		exynos_cpu_power_up(core_id);
32583014579SKukjin Kim 		timeout = 10;
32683014579SKukjin Kim 
32783014579SKukjin Kim 		/* wait max 10 ms until cpu1 is on */
3289637f30eSTomasz Figa 		while (exynos_cpu_power_state(core_id)
3299637f30eSTomasz Figa 		       != S5P_CORE_LOCAL_PWR_EN) {
33083014579SKukjin Kim 			if (timeout-- == 0)
33183014579SKukjin Kim 				break;
33283014579SKukjin Kim 
33383014579SKukjin Kim 			mdelay(1);
33483014579SKukjin Kim 		}
33583014579SKukjin Kim 
33683014579SKukjin Kim 		if (timeout == 0) {
33783014579SKukjin Kim 			printk(KERN_ERR "cpu1 power enable failed");
33883014579SKukjin Kim 			spin_unlock(&boot_lock);
33983014579SKukjin Kim 			return -ETIMEDOUT;
34083014579SKukjin Kim 		}
34183014579SKukjin Kim 	}
342b588aaecSKrzysztof Kozlowski 
343b588aaecSKrzysztof Kozlowski 	exynos_core_restart(core_id);
344b588aaecSKrzysztof Kozlowski 
34583014579SKukjin Kim 	/*
34683014579SKukjin Kim 	 * Send the secondary CPU a soft interrupt, thereby causing
34783014579SKukjin Kim 	 * the boot monitor to read the system wide flags register,
34883014579SKukjin Kim 	 * and branch to the address found there.
34983014579SKukjin Kim 	 */
35083014579SKukjin Kim 
35183014579SKukjin Kim 	timeout = jiffies + (1 * HZ);
35283014579SKukjin Kim 	while (time_before(jiffies, timeout)) {
353beddf63fSTomasz Figa 		unsigned long boot_addr;
354beddf63fSTomasz Figa 
35583014579SKukjin Kim 		smp_rmb();
35683014579SKukjin Kim 
357beddf63fSTomasz Figa 		boot_addr = virt_to_phys(exynos4_secondary_startup);
358beddf63fSTomasz Figa 
359955d4cf8SBartlomiej Zolnierkiewicz 		ret = exynos_set_boot_addr(core_id, boot_addr);
360955d4cf8SBartlomiej Zolnierkiewicz 		if (ret)
361b3205deaSSachin Kamat 			goto fail;
362beddf63fSTomasz Figa 
3639637f30eSTomasz Figa 		call_firmware_op(cpu_boot, core_id);
364beddf63fSTomasz Figa 
365497ab3b3SBartlomiej Zolnierkiewicz 		if (soc_is_exynos3250())
366497ab3b3SBartlomiej Zolnierkiewicz 			dsb_sev();
367497ab3b3SBartlomiej Zolnierkiewicz 		else
368b1cffebfSRob Herring 			arch_send_wakeup_ipi_mask(cpumask_of(cpu));
36983014579SKukjin Kim 
37083014579SKukjin Kim 		if (pen_release == -1)
37183014579SKukjin Kim 			break;
37283014579SKukjin Kim 
37383014579SKukjin Kim 		udelay(10);
37483014579SKukjin Kim 	}
37583014579SKukjin Kim 
3769f294c17SBartlomiej Zolnierkiewicz 	if (pen_release != -1)
3779f294c17SBartlomiej Zolnierkiewicz 		ret = -ETIMEDOUT;
3789f294c17SBartlomiej Zolnierkiewicz 
37983014579SKukjin Kim 	/*
38083014579SKukjin Kim 	 * now the secondary core is starting up let it run its
38183014579SKukjin Kim 	 * calibrations, then wait for it to finish
38283014579SKukjin Kim 	 */
383b3205deaSSachin Kamat fail:
38483014579SKukjin Kim 	spin_unlock(&boot_lock);
38583014579SKukjin Kim 
386b3205deaSSachin Kamat 	return pen_release != -1 ? ret : 0;
38783014579SKukjin Kim }
38883014579SKukjin Kim 
38983014579SKukjin Kim /*
39083014579SKukjin Kim  * Initialise the CPU possible map early - this describes the CPUs
39183014579SKukjin Kim  * which may be present or become present in the system.
39283014579SKukjin Kim  */
39383014579SKukjin Kim 
39406853ae4SMarc Zyngier static void __init exynos_smp_init_cpus(void)
39583014579SKukjin Kim {
39683014579SKukjin Kim 	void __iomem *scu_base = scu_base_addr();
39783014579SKukjin Kim 	unsigned int i, ncores;
39883014579SKukjin Kim 
399af040ffcSRussell King 	if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
40083014579SKukjin Kim 		ncores = scu_base ? scu_get_core_count(scu_base) : 1;
4011897d2f3SChander Kashyap 	else
4021897d2f3SChander Kashyap 		/*
4031897d2f3SChander Kashyap 		 * CPU Nodes are passed thru DT and set_cpu_possible
4041897d2f3SChander Kashyap 		 * is set by "arm_dt_init_cpu_maps".
4051897d2f3SChander Kashyap 		 */
4061897d2f3SChander Kashyap 		return;
40783014579SKukjin Kim 
40883014579SKukjin Kim 	/* sanity check */
40983014579SKukjin Kim 	if (ncores > nr_cpu_ids) {
41083014579SKukjin Kim 		pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
41183014579SKukjin Kim 			ncores, nr_cpu_ids);
41283014579SKukjin Kim 		ncores = nr_cpu_ids;
41383014579SKukjin Kim 	}
41483014579SKukjin Kim 
41583014579SKukjin Kim 	for (i = 0; i < ncores; i++)
41683014579SKukjin Kim 		set_cpu_possible(i, true);
41783014579SKukjin Kim }
41883014579SKukjin Kim 
41906853ae4SMarc Zyngier static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
42083014579SKukjin Kim {
4211f054f52STomasz Figa 	int i;
4221f054f52STomasz Figa 
4231754c42eSOlof Johansson 	exynos_sysram_init();
4241754c42eSOlof Johansson 
4256f024978SKrzysztof Kozlowski 	exynos_set_delayed_reset_assertion(true);
4266f024978SKrzysztof Kozlowski 
427af040ffcSRussell King 	if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
42883014579SKukjin Kim 		scu_enable(scu_base_addr());
42983014579SKukjin Kim 
43083014579SKukjin Kim 	/*
43183014579SKukjin Kim 	 * Write the address of secondary startup into the
43283014579SKukjin Kim 	 * system-wide flags register. The boot monitor waits
43383014579SKukjin Kim 	 * until it receives a soft interrupt, and then the
43483014579SKukjin Kim 	 * secondary CPU branches to this address.
435beddf63fSTomasz Figa 	 *
436beddf63fSTomasz Figa 	 * Try using firmware operation first and fall back to
437beddf63fSTomasz Figa 	 * boot register if it fails.
43883014579SKukjin Kim 	 */
439beddf63fSTomasz Figa 	for (i = 1; i < max_cpus; ++i) {
440beddf63fSTomasz Figa 		unsigned long boot_addr;
4419637f30eSTomasz Figa 		u32 mpidr;
4429637f30eSTomasz Figa 		u32 core_id;
443b3205deaSSachin Kamat 		int ret;
444beddf63fSTomasz Figa 
4459637f30eSTomasz Figa 		mpidr = cpu_logical_map(i);
4469637f30eSTomasz Figa 		core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
447beddf63fSTomasz Figa 		boot_addr = virt_to_phys(exynos4_secondary_startup);
448beddf63fSTomasz Figa 
449955d4cf8SBartlomiej Zolnierkiewicz 		ret = exynos_set_boot_addr(core_id, boot_addr);
450955d4cf8SBartlomiej Zolnierkiewicz 		if (ret)
451b3205deaSSachin Kamat 			break;
45283014579SKukjin Kim 	}
453b3205deaSSachin Kamat }
45406853ae4SMarc Zyngier 
4556f0b7c0cSKrzysztof Kozlowski #ifdef CONFIG_HOTPLUG_CPU
4566f0b7c0cSKrzysztof Kozlowski /*
4576f0b7c0cSKrzysztof Kozlowski  * platform-specific code to shutdown a CPU
4586f0b7c0cSKrzysztof Kozlowski  *
4596f0b7c0cSKrzysztof Kozlowski  * Called with IRQs disabled
4606f0b7c0cSKrzysztof Kozlowski  */
46127b9ee85SKrzysztof Kozlowski static void exynos_cpu_die(unsigned int cpu)
4626f0b7c0cSKrzysztof Kozlowski {
4636f0b7c0cSKrzysztof Kozlowski 	int spurious = 0;
46413cfa6c4SKrzysztof Kozlowski 	u32 mpidr = cpu_logical_map(cpu);
46513cfa6c4SKrzysztof Kozlowski 	u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
4666f0b7c0cSKrzysztof Kozlowski 
4676f0b7c0cSKrzysztof Kozlowski 	v7_exit_coherency_flush(louis);
4686f0b7c0cSKrzysztof Kozlowski 
4696f0b7c0cSKrzysztof Kozlowski 	platform_do_lowpower(cpu, &spurious);
4706f0b7c0cSKrzysztof Kozlowski 
4716f0b7c0cSKrzysztof Kozlowski 	/*
4726f0b7c0cSKrzysztof Kozlowski 	 * bring this CPU back into the world of cache
4736f0b7c0cSKrzysztof Kozlowski 	 * coherency, and then restore interrupts
4746f0b7c0cSKrzysztof Kozlowski 	 */
47513cfa6c4SKrzysztof Kozlowski 	cpu_leave_lowpower(core_id);
4766f0b7c0cSKrzysztof Kozlowski 
4776f0b7c0cSKrzysztof Kozlowski 	if (spurious)
4786f0b7c0cSKrzysztof Kozlowski 		pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
4796f0b7c0cSKrzysztof Kozlowski }
4806f0b7c0cSKrzysztof Kozlowski #endif /* CONFIG_HOTPLUG_CPU */
4816f0b7c0cSKrzysztof Kozlowski 
48206853ae4SMarc Zyngier struct smp_operations exynos_smp_ops __initdata = {
48306853ae4SMarc Zyngier 	.smp_init_cpus		= exynos_smp_init_cpus,
48406853ae4SMarc Zyngier 	.smp_prepare_cpus	= exynos_smp_prepare_cpus,
48506853ae4SMarc Zyngier 	.smp_secondary_init	= exynos_secondary_init,
48606853ae4SMarc Zyngier 	.smp_boot_secondary	= exynos_boot_secondary,
48706853ae4SMarc Zyngier #ifdef CONFIG_HOTPLUG_CPU
48806853ae4SMarc Zyngier 	.cpu_die		= exynos_cpu_die,
48906853ae4SMarc Zyngier #endif
49006853ae4SMarc Zyngier };
491