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> 2383014579SKukjin Kim 2483014579SKukjin Kim #include <asm/cacheflush.h> 2583014579SKukjin Kim #include <asm/hardware/gic.h> 2683014579SKukjin Kim #include <asm/smp_scu.h> 2783014579SKukjin Kim 2883014579SKukjin Kim #include <mach/hardware.h> 2983014579SKukjin Kim #include <mach/regs-clock.h> 3083014579SKukjin Kim #include <mach/regs-pmu.h> 3183014579SKukjin Kim 3283014579SKukjin Kim #include <plat/cpu.h> 3383014579SKukjin Kim 3483014579SKukjin Kim extern unsigned int gic_bank_offset; 3583014579SKukjin Kim extern void exynos4_secondary_startup(void); 3683014579SKukjin Kim 3783014579SKukjin Kim #define CPU1_BOOT_REG (samsung_rev() == EXYNOS4210_REV_1_1 ? \ 3883014579SKukjin Kim S5P_INFORM5 : S5P_VA_SYSRAM) 3983014579SKukjin Kim 4083014579SKukjin Kim /* 4183014579SKukjin Kim * control for which core is the next to come out of the secondary 4283014579SKukjin Kim * boot "holding pen" 4383014579SKukjin Kim */ 4483014579SKukjin Kim 4583014579SKukjin Kim volatile int __cpuinitdata pen_release = -1; 4683014579SKukjin Kim 4783014579SKukjin Kim /* 4883014579SKukjin Kim * Write pen_release in a way that is guaranteed to be visible to all 4983014579SKukjin Kim * observers, irrespective of whether they're taking part in coherency 5083014579SKukjin Kim * or not. This is necessary for the hotplug code to work reliably. 5183014579SKukjin Kim */ 5283014579SKukjin Kim static void write_pen_release(int val) 5383014579SKukjin Kim { 5483014579SKukjin Kim pen_release = val; 5583014579SKukjin Kim smp_wmb(); 5683014579SKukjin Kim __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release)); 5783014579SKukjin Kim outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1)); 5883014579SKukjin Kim } 5983014579SKukjin Kim 6083014579SKukjin Kim static void __iomem *scu_base_addr(void) 6183014579SKukjin Kim { 6283014579SKukjin Kim return (void __iomem *)(S5P_VA_SCU); 6383014579SKukjin Kim } 6483014579SKukjin Kim 6583014579SKukjin Kim static DEFINE_SPINLOCK(boot_lock); 6683014579SKukjin Kim 6783014579SKukjin Kim static void __cpuinit exynos4_gic_secondary_init(void) 6883014579SKukjin Kim { 6983014579SKukjin Kim void __iomem *dist_base = S5P_VA_GIC_DIST + 7083014579SKukjin Kim (gic_bank_offset * smp_processor_id()); 7183014579SKukjin Kim void __iomem *cpu_base = S5P_VA_GIC_CPU + 7283014579SKukjin Kim (gic_bank_offset * smp_processor_id()); 7383014579SKukjin Kim int i; 7483014579SKukjin Kim 7583014579SKukjin Kim /* 7683014579SKukjin Kim * Deal with the banked PPI and SGI interrupts - disable all 7783014579SKukjin Kim * PPI interrupts, ensure all SGI interrupts are enabled. 7883014579SKukjin Kim */ 7983014579SKukjin Kim __raw_writel(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR); 8083014579SKukjin Kim __raw_writel(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET); 8183014579SKukjin Kim 8283014579SKukjin Kim /* 8383014579SKukjin Kim * Set priority on PPI and SGI interrupts 8483014579SKukjin Kim */ 8583014579SKukjin Kim for (i = 0; i < 32; i += 4) 8683014579SKukjin Kim __raw_writel(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4); 8783014579SKukjin Kim 8883014579SKukjin Kim __raw_writel(0xf0, cpu_base + GIC_CPU_PRIMASK); 8983014579SKukjin Kim __raw_writel(1, cpu_base + GIC_CPU_CTRL); 9083014579SKukjin Kim } 9183014579SKukjin Kim 9283014579SKukjin Kim void __cpuinit platform_secondary_init(unsigned int cpu) 9383014579SKukjin Kim { 9483014579SKukjin Kim /* 9583014579SKukjin Kim * if any interrupts are already enabled for the primary 9683014579SKukjin Kim * core (e.g. timer irq), then they will not have been enabled 9783014579SKukjin Kim * for us: do so 9883014579SKukjin Kim */ 9983014579SKukjin Kim exynos4_gic_secondary_init(); 10083014579SKukjin Kim 10183014579SKukjin Kim /* 10283014579SKukjin Kim * let the primary processor know we're out of the 10383014579SKukjin Kim * pen, then head off into the C entry point 10483014579SKukjin Kim */ 10583014579SKukjin Kim write_pen_release(-1); 10683014579SKukjin Kim 10783014579SKukjin Kim /* 10883014579SKukjin Kim * Synchronise with the boot thread. 10983014579SKukjin Kim */ 11083014579SKukjin Kim spin_lock(&boot_lock); 11183014579SKukjin Kim spin_unlock(&boot_lock); 11283014579SKukjin Kim } 11383014579SKukjin Kim 11483014579SKukjin Kim int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) 11583014579SKukjin Kim { 11683014579SKukjin Kim unsigned long timeout; 11783014579SKukjin Kim 11883014579SKukjin Kim /* 11983014579SKukjin Kim * Set synchronisation state between this boot processor 12083014579SKukjin Kim * and the secondary one 12183014579SKukjin Kim */ 12283014579SKukjin Kim spin_lock(&boot_lock); 12383014579SKukjin Kim 12483014579SKukjin Kim /* 12583014579SKukjin Kim * The secondary processor is waiting to be released from 12683014579SKukjin Kim * the holding pen - release it, then wait for it to flag 12783014579SKukjin Kim * that it has been released by resetting pen_release. 12883014579SKukjin Kim * 12983014579SKukjin Kim * Note that "pen_release" is the hardware CPU ID, whereas 13083014579SKukjin Kim * "cpu" is Linux's internal ID. 13183014579SKukjin Kim */ 13283014579SKukjin Kim write_pen_release(cpu_logical_map(cpu)); 13383014579SKukjin Kim 13483014579SKukjin Kim if (!(__raw_readl(S5P_ARM_CORE1_STATUS) & S5P_CORE_LOCAL_PWR_EN)) { 13583014579SKukjin Kim __raw_writel(S5P_CORE_LOCAL_PWR_EN, 13683014579SKukjin Kim S5P_ARM_CORE1_CONFIGURATION); 13783014579SKukjin Kim 13883014579SKukjin Kim timeout = 10; 13983014579SKukjin Kim 14083014579SKukjin Kim /* wait max 10 ms until cpu1 is on */ 14183014579SKukjin Kim while ((__raw_readl(S5P_ARM_CORE1_STATUS) 14283014579SKukjin Kim & S5P_CORE_LOCAL_PWR_EN) != S5P_CORE_LOCAL_PWR_EN) { 14383014579SKukjin Kim if (timeout-- == 0) 14483014579SKukjin Kim break; 14583014579SKukjin Kim 14683014579SKukjin Kim mdelay(1); 14783014579SKukjin Kim } 14883014579SKukjin Kim 14983014579SKukjin Kim if (timeout == 0) { 15083014579SKukjin Kim printk(KERN_ERR "cpu1 power enable failed"); 15183014579SKukjin Kim spin_unlock(&boot_lock); 15283014579SKukjin Kim return -ETIMEDOUT; 15383014579SKukjin Kim } 15483014579SKukjin Kim } 15583014579SKukjin Kim /* 15683014579SKukjin Kim * Send the secondary CPU a soft interrupt, thereby causing 15783014579SKukjin Kim * the boot monitor to read the system wide flags register, 15883014579SKukjin Kim * and branch to the address found there. 15983014579SKukjin Kim */ 16083014579SKukjin Kim 16183014579SKukjin Kim timeout = jiffies + (1 * HZ); 16283014579SKukjin Kim while (time_before(jiffies, timeout)) { 16383014579SKukjin Kim smp_rmb(); 16483014579SKukjin Kim 165*f7597c02SRob Herring __raw_writel(virt_to_phys(exynos4_secondary_startup), 16683014579SKukjin Kim CPU1_BOOT_REG); 16783014579SKukjin Kim gic_raise_softirq(cpumask_of(cpu), 1); 16883014579SKukjin Kim 16983014579SKukjin Kim if (pen_release == -1) 17083014579SKukjin Kim break; 17183014579SKukjin Kim 17283014579SKukjin Kim udelay(10); 17383014579SKukjin Kim } 17483014579SKukjin Kim 17583014579SKukjin Kim /* 17683014579SKukjin Kim * now the secondary core is starting up let it run its 17783014579SKukjin Kim * calibrations, then wait for it to finish 17883014579SKukjin Kim */ 17983014579SKukjin Kim spin_unlock(&boot_lock); 18083014579SKukjin Kim 18183014579SKukjin Kim return pen_release != -1 ? -ENOSYS : 0; 18283014579SKukjin Kim } 18383014579SKukjin Kim 18483014579SKukjin Kim /* 18583014579SKukjin Kim * Initialise the CPU possible map early - this describes the CPUs 18683014579SKukjin Kim * which may be present or become present in the system. 18783014579SKukjin Kim */ 18883014579SKukjin Kim 18983014579SKukjin Kim void __init smp_init_cpus(void) 19083014579SKukjin Kim { 19183014579SKukjin Kim void __iomem *scu_base = scu_base_addr(); 19283014579SKukjin Kim unsigned int i, ncores; 19383014579SKukjin Kim 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 set_smp_cross_call(gic_raise_softirq); 20783014579SKukjin Kim } 20883014579SKukjin Kim 20983014579SKukjin Kim void __init platform_smp_prepare_cpus(unsigned int max_cpus) 21083014579SKukjin Kim { 21183014579SKukjin Kim 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. 21983014579SKukjin Kim */ 220*f7597c02SRob Herring __raw_writel(virt_to_phys(exynos4_secondary_startup), 22183014579SKukjin Kim CPU1_BOOT_REG); 22283014579SKukjin Kim } 223