183014579SKukjin Kim /* linux/arch/arm/mach-exynos4/platsmp.c 283014579SKukjin Kim * 383014579SKukjin Kim * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. 483014579SKukjin Kim * http://www.samsung.com 583014579SKukjin Kim * 683014579SKukjin Kim * Cloned from linux/arch/arm/mach-vexpress/platsmp.c 783014579SKukjin Kim * 883014579SKukjin Kim * Copyright (C) 2002 ARM Ltd. 983014579SKukjin Kim * All Rights Reserved 1083014579SKukjin Kim * 1183014579SKukjin Kim * This program is free software; you can redistribute it and/or modify 1283014579SKukjin Kim * it under the terms of the GNU General Public License version 2 as 1383014579SKukjin Kim * published by the Free Software Foundation. 1483014579SKukjin Kim */ 1583014579SKukjin Kim 1683014579SKukjin Kim #include <linux/init.h> 1783014579SKukjin Kim #include <linux/errno.h> 1883014579SKukjin Kim #include <linux/delay.h> 1983014579SKukjin Kim #include <linux/device.h> 2083014579SKukjin Kim #include <linux/jiffies.h> 2183014579SKukjin Kim #include <linux/smp.h> 2283014579SKukjin Kim #include <linux/io.h> 23520f7bd7SRob Herring #include <linux/irqchip/arm-gic.h> 2483014579SKukjin Kim 2583014579SKukjin Kim #include <asm/cacheflush.h> 26eb50439bSWill Deacon #include <asm/smp_plat.h> 2783014579SKukjin Kim #include <asm/smp_scu.h> 28*beddf63fSTomasz Figa #include <asm/firmware.h> 2983014579SKukjin Kim 3083014579SKukjin Kim #include <mach/hardware.h> 3183014579SKukjin Kim #include <mach/regs-clock.h> 3283014579SKukjin Kim #include <mach/regs-pmu.h> 3383014579SKukjin Kim 3483014579SKukjin Kim #include <plat/cpu.h> 3583014579SKukjin Kim 3606853ae4SMarc Zyngier #include "common.h" 3706853ae4SMarc Zyngier 3883014579SKukjin Kim extern void exynos4_secondary_startup(void); 3983014579SKukjin Kim 401f054f52STomasz Figa static inline void __iomem *cpu_boot_reg_base(void) 411f054f52STomasz Figa { 421f054f52STomasz Figa if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1) 431f054f52STomasz Figa return S5P_INFORM5; 441f054f52STomasz Figa return S5P_VA_SYSRAM; 451f054f52STomasz Figa } 461f054f52STomasz Figa 471f054f52STomasz Figa static inline void __iomem *cpu_boot_reg(int cpu) 481f054f52STomasz Figa { 491f054f52STomasz Figa void __iomem *boot_reg; 501f054f52STomasz Figa 511f054f52STomasz Figa boot_reg = cpu_boot_reg_base(); 521f054f52STomasz Figa if (soc_is_exynos4412()) 531f054f52STomasz Figa boot_reg += 4*cpu; 541f054f52STomasz Figa return boot_reg; 551f054f52STomasz Figa } 5683014579SKukjin Kim 5783014579SKukjin Kim /* 5883014579SKukjin Kim * Write pen_release in a way that is guaranteed to be visible to all 5983014579SKukjin Kim * observers, irrespective of whether they're taking part in coherency 6083014579SKukjin Kim * or not. This is necessary for the hotplug code to work reliably. 6183014579SKukjin Kim */ 6283014579SKukjin Kim static void write_pen_release(int val) 6383014579SKukjin Kim { 6483014579SKukjin Kim pen_release = val; 6583014579SKukjin Kim smp_wmb(); 6683014579SKukjin Kim __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release)); 6783014579SKukjin Kim outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1)); 6883014579SKukjin Kim } 6983014579SKukjin Kim 7083014579SKukjin Kim static void __iomem *scu_base_addr(void) 7183014579SKukjin Kim { 7283014579SKukjin Kim return (void __iomem *)(S5P_VA_SCU); 7383014579SKukjin Kim } 7483014579SKukjin Kim 7583014579SKukjin Kim static DEFINE_SPINLOCK(boot_lock); 7683014579SKukjin Kim 7706853ae4SMarc Zyngier static void __cpuinit exynos_secondary_init(unsigned int cpu) 7883014579SKukjin Kim { 7983014579SKukjin Kim /* 8083014579SKukjin Kim * if any interrupts are already enabled for the primary 8183014579SKukjin Kim * core (e.g. timer irq), then they will not have been enabled 8283014579SKukjin Kim * for us: do so 8383014579SKukjin Kim */ 84db0d4db2SMarc Zyngier gic_secondary_init(0); 8583014579SKukjin Kim 8683014579SKukjin Kim /* 8783014579SKukjin Kim * let the primary processor know we're out of the 8883014579SKukjin Kim * pen, then head off into the C entry point 8983014579SKukjin Kim */ 9083014579SKukjin Kim write_pen_release(-1); 9183014579SKukjin Kim 9283014579SKukjin Kim /* 9383014579SKukjin Kim * Synchronise with the boot thread. 9483014579SKukjin Kim */ 9583014579SKukjin Kim spin_lock(&boot_lock); 9683014579SKukjin Kim spin_unlock(&boot_lock); 9783014579SKukjin Kim } 9883014579SKukjin Kim 9906853ae4SMarc Zyngier static int __cpuinit exynos_boot_secondary(unsigned int cpu, struct task_struct *idle) 10083014579SKukjin Kim { 10183014579SKukjin Kim unsigned long timeout; 1021f054f52STomasz Figa unsigned long phys_cpu = cpu_logical_map(cpu); 10383014579SKukjin Kim 10483014579SKukjin Kim /* 10583014579SKukjin Kim * Set synchronisation state between this boot processor 10683014579SKukjin Kim * and the secondary one 10783014579SKukjin Kim */ 10883014579SKukjin Kim spin_lock(&boot_lock); 10983014579SKukjin Kim 11083014579SKukjin Kim /* 11183014579SKukjin Kim * The secondary processor is waiting to be released from 11283014579SKukjin Kim * the holding pen - release it, then wait for it to flag 11383014579SKukjin Kim * that it has been released by resetting pen_release. 11483014579SKukjin Kim * 11583014579SKukjin Kim * Note that "pen_release" is the hardware CPU ID, whereas 11683014579SKukjin Kim * "cpu" is Linux's internal ID. 11783014579SKukjin Kim */ 1181f054f52STomasz Figa write_pen_release(phys_cpu); 11983014579SKukjin Kim 12083014579SKukjin Kim if (!(__raw_readl(S5P_ARM_CORE1_STATUS) & S5P_CORE_LOCAL_PWR_EN)) { 12183014579SKukjin Kim __raw_writel(S5P_CORE_LOCAL_PWR_EN, 12283014579SKukjin Kim S5P_ARM_CORE1_CONFIGURATION); 12383014579SKukjin Kim 12483014579SKukjin Kim timeout = 10; 12583014579SKukjin Kim 12683014579SKukjin Kim /* wait max 10 ms until cpu1 is on */ 12783014579SKukjin Kim while ((__raw_readl(S5P_ARM_CORE1_STATUS) 12883014579SKukjin Kim & S5P_CORE_LOCAL_PWR_EN) != S5P_CORE_LOCAL_PWR_EN) { 12983014579SKukjin Kim if (timeout-- == 0) 13083014579SKukjin Kim break; 13183014579SKukjin Kim 13283014579SKukjin Kim mdelay(1); 13383014579SKukjin Kim } 13483014579SKukjin Kim 13583014579SKukjin Kim if (timeout == 0) { 13683014579SKukjin Kim printk(KERN_ERR "cpu1 power enable failed"); 13783014579SKukjin Kim spin_unlock(&boot_lock); 13883014579SKukjin Kim return -ETIMEDOUT; 13983014579SKukjin Kim } 14083014579SKukjin Kim } 14183014579SKukjin Kim /* 14283014579SKukjin Kim * Send the secondary CPU a soft interrupt, thereby causing 14383014579SKukjin Kim * the boot monitor to read the system wide flags register, 14483014579SKukjin Kim * and branch to the address found there. 14583014579SKukjin Kim */ 14683014579SKukjin Kim 14783014579SKukjin Kim timeout = jiffies + (1 * HZ); 14883014579SKukjin Kim while (time_before(jiffies, timeout)) { 149*beddf63fSTomasz Figa unsigned long boot_addr; 150*beddf63fSTomasz Figa 15183014579SKukjin Kim smp_rmb(); 15283014579SKukjin Kim 153*beddf63fSTomasz Figa boot_addr = virt_to_phys(exynos4_secondary_startup); 154*beddf63fSTomasz Figa 155*beddf63fSTomasz Figa /* 156*beddf63fSTomasz Figa * Try to set boot address using firmware first 157*beddf63fSTomasz Figa * and fall back to boot register if it fails. 158*beddf63fSTomasz Figa */ 159*beddf63fSTomasz Figa if (call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr)) 160*beddf63fSTomasz Figa __raw_writel(boot_addr, cpu_boot_reg(phys_cpu)); 161*beddf63fSTomasz Figa 162*beddf63fSTomasz Figa call_firmware_op(cpu_boot, phys_cpu); 163*beddf63fSTomasz Figa 164b1cffebfSRob Herring arch_send_wakeup_ipi_mask(cpumask_of(cpu)); 16583014579SKukjin Kim 16683014579SKukjin Kim if (pen_release == -1) 16783014579SKukjin Kim break; 16883014579SKukjin Kim 16983014579SKukjin Kim udelay(10); 17083014579SKukjin Kim } 17183014579SKukjin Kim 17283014579SKukjin Kim /* 17383014579SKukjin Kim * now the secondary core is starting up let it run its 17483014579SKukjin Kim * calibrations, then wait for it to finish 17583014579SKukjin Kim */ 17683014579SKukjin Kim spin_unlock(&boot_lock); 17783014579SKukjin Kim 17883014579SKukjin Kim return pen_release != -1 ? -ENOSYS : 0; 17983014579SKukjin Kim } 18083014579SKukjin Kim 18183014579SKukjin Kim /* 18283014579SKukjin Kim * Initialise the CPU possible map early - this describes the CPUs 18383014579SKukjin Kim * which may be present or become present in the system. 18483014579SKukjin Kim */ 18583014579SKukjin Kim 18606853ae4SMarc Zyngier static void __init exynos_smp_init_cpus(void) 18783014579SKukjin Kim { 18883014579SKukjin Kim void __iomem *scu_base = scu_base_addr(); 18983014579SKukjin Kim unsigned int i, ncores; 19083014579SKukjin Kim 191e9bba615SKukjin Kim if (soc_is_exynos5250()) 192e9bba615SKukjin Kim ncores = 2; 193e9bba615SKukjin Kim else 19483014579SKukjin Kim ncores = scu_base ? scu_get_core_count(scu_base) : 1; 19583014579SKukjin Kim 19683014579SKukjin Kim /* sanity check */ 19783014579SKukjin Kim if (ncores > nr_cpu_ids) { 19883014579SKukjin Kim pr_warn("SMP: %u cores greater than maximum (%u), clipping\n", 19983014579SKukjin Kim ncores, nr_cpu_ids); 20083014579SKukjin Kim ncores = nr_cpu_ids; 20183014579SKukjin Kim } 20283014579SKukjin Kim 20383014579SKukjin Kim for (i = 0; i < ncores; i++) 20483014579SKukjin Kim set_cpu_possible(i, true); 20583014579SKukjin Kim } 20683014579SKukjin Kim 20706853ae4SMarc Zyngier static void __init exynos_smp_prepare_cpus(unsigned int max_cpus) 20883014579SKukjin Kim { 2091f054f52STomasz Figa int i; 2101f054f52STomasz Figa 21183e877a3SKukjin Kim if (!(soc_is_exynos5250() || soc_is_exynos5440())) 21283014579SKukjin Kim scu_enable(scu_base_addr()); 21383014579SKukjin Kim 21483014579SKukjin Kim /* 21583014579SKukjin Kim * Write the address of secondary startup into the 21683014579SKukjin Kim * system-wide flags register. The boot monitor waits 21783014579SKukjin Kim * until it receives a soft interrupt, and then the 21883014579SKukjin Kim * secondary CPU branches to this address. 219*beddf63fSTomasz Figa * 220*beddf63fSTomasz Figa * Try using firmware operation first and fall back to 221*beddf63fSTomasz Figa * boot register if it fails. 22283014579SKukjin Kim */ 223*beddf63fSTomasz Figa for (i = 1; i < max_cpus; ++i) { 224*beddf63fSTomasz Figa unsigned long phys_cpu; 225*beddf63fSTomasz Figa unsigned long boot_addr; 226*beddf63fSTomasz Figa 227*beddf63fSTomasz Figa phys_cpu = cpu_logical_map(i); 228*beddf63fSTomasz Figa boot_addr = virt_to_phys(exynos4_secondary_startup); 229*beddf63fSTomasz Figa 230*beddf63fSTomasz Figa if (call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr)) 231*beddf63fSTomasz Figa __raw_writel(boot_addr, cpu_boot_reg(phys_cpu)); 232*beddf63fSTomasz Figa } 23383014579SKukjin Kim } 23406853ae4SMarc Zyngier 23506853ae4SMarc Zyngier struct smp_operations exynos_smp_ops __initdata = { 23606853ae4SMarc Zyngier .smp_init_cpus = exynos_smp_init_cpus, 23706853ae4SMarc Zyngier .smp_prepare_cpus = exynos_smp_prepare_cpus, 23806853ae4SMarc Zyngier .smp_secondary_init = exynos_secondary_init, 23906853ae4SMarc Zyngier .smp_boot_secondary = exynos_boot_secondary, 24006853ae4SMarc Zyngier #ifdef CONFIG_HOTPLUG_CPU 24106853ae4SMarc Zyngier .cpu_die = exynos_cpu_die, 24206853ae4SMarc Zyngier #endif 24306853ae4SMarc Zyngier }; 244