/* linux/arch/arm/mach-exynos4/platsmp.c1*2* Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.3* http://www.samsung.com4*5* Cloned from linux/arch/arm/mach-vexpress/platsmp.c6*7* Copyright (C) 2002 ARM Ltd.8* All Rights Reserved9*10* This program is free software; you can redistribute it and/or modify11* it under the terms of the GNU General Public License version 2 as12* published by the Free Software Foundation.13*/1415#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>21#include <linux/io.h>2223#include <asm/cacheflush.h>24#include <asm/hardware/gic.h>25#include <asm/smp_scu.h>26#include <asm/unified.h>2728#include <mach/hardware.h>29#include <mach/regs-clock.h>3031extern void exynos4_secondary_startup(void);3233/*34* control for which core is the next to come out of the secondary35* boot "holding pen"36*/3738volatile int __cpuinitdata pen_release = -1;3940/*41* Write pen_release in a way that is guaranteed to be visible to all42* observers, irrespective of whether they're taking part in coherency43* or not. This is necessary for the hotplug code to work reliably.44*/45static void write_pen_release(int val)46{47pen_release = val;48smp_wmb();49__cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));50outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));51}5253static void __iomem *scu_base_addr(void)54{55return (void __iomem *)(S5P_VA_SCU);56}5758static DEFINE_SPINLOCK(boot_lock);5960void __cpuinit platform_secondary_init(unsigned int cpu)61{62/*63* if any interrupts are already enabled for the primary64* core (e.g. timer irq), then they will not have been enabled65* for us: do so66*/67gic_secondary_init(0);6869/*70* let the primary processor know we're out of the71* pen, then head off into the C entry point72*/73write_pen_release(-1);7475/*76* Synchronise with the boot thread.77*/78spin_lock(&boot_lock);79spin_unlock(&boot_lock);80}8182int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)83{84unsigned long timeout;8586/*87* Set synchronisation state between this boot processor88* and the secondary one89*/90spin_lock(&boot_lock);9192/*93* The secondary processor is waiting to be released from94* the holding pen - release it, then wait for it to flag95* that it has been released by resetting pen_release.96*97* Note that "pen_release" is the hardware CPU ID, whereas98* "cpu" is Linux's internal ID.99*/100write_pen_release(cpu);101102/*103* Send the secondary CPU a soft interrupt, thereby causing104* the boot monitor to read the system wide flags register,105* and branch to the address found there.106*/107gic_raise_softirq(cpumask_of(cpu), 1);108109timeout = jiffies + (1 * HZ);110while (time_before(jiffies, timeout)) {111smp_rmb();112if (pen_release == -1)113break;114115udelay(10);116}117118/*119* now the secondary core is starting up let it run its120* calibrations, then wait for it to finish121*/122spin_unlock(&boot_lock);123124return pen_release != -1 ? -ENOSYS : 0;125}126127/*128* Initialise the CPU possible map early - this describes the CPUs129* which may be present or become present in the system.130*/131132void __init smp_init_cpus(void)133{134void __iomem *scu_base = scu_base_addr();135unsigned int i, ncores;136137ncores = scu_base ? scu_get_core_count(scu_base) : 1;138139/* sanity check */140if (ncores > NR_CPUS) {141printk(KERN_WARNING142"EXYNOS4: no. of cores (%d) greater than configured "143"maximum of %d - clipping\n",144ncores, NR_CPUS);145ncores = NR_CPUS;146}147148for (i = 0; i < ncores; i++)149set_cpu_possible(i, true);150151set_smp_cross_call(gic_raise_softirq);152}153154void __init platform_smp_prepare_cpus(unsigned int max_cpus)155{156int i;157158/*159* Initialise the present map, which describes the set of CPUs160* actually populated at the present time.161*/162for (i = 0; i < max_cpus; i++)163set_cpu_present(i, true);164165scu_enable(scu_base_addr());166167/*168* Write the address of secondary startup into the169* system-wide flags register. The boot monitor waits170* until it receives a soft interrupt, and then the171* secondary CPU branches to this address.172*/173__raw_writel(BSYM(virt_to_phys(exynos4_secondary_startup)), S5P_VA_SYSRAM);174}175176177