2 * Copyright (C) 2002 ARM Ltd.
3 * Copyright (C) 2008 STMicroelctronics.
4 * Copyright (C) 2009 ST-Ericsson.
5 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
7 * This file is based on arm realview platform
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 #include <linux/init.h>
14 #include <linux/errno.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/smp.h>
20 #include <asm/cacheflush.h>
21 #include <asm/localtimer.h>
22 #include <asm/smp_scu.h>
23 #include <mach/hardware.h>
26 * control for which core is the next to come out of the secondary
29 volatile int __cpuinitdata pen_release = -1;
31 static unsigned int __init get_core_count(void)
33 return scu_get_core_count(__io_address(UX500_SCU_BASE));
36 static DEFINE_SPINLOCK(boot_lock);
38 void __cpuinit platform_secondary_init(unsigned int cpu)
43 * if any interrupts are already enabled for the primary
44 * core (e.g. timer irq), then they will not have been enabled
47 gic_cpu_init(0, __io_address(UX500_GIC_CPU_BASE));
50 * let the primary processor know we're out of the
51 * pen, then head off into the C entry point
56 * Synchronise with the boot thread.
58 spin_lock(&boot_lock);
59 spin_unlock(&boot_lock);
62 int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
64 unsigned long timeout;
67 * set synchronisation state between this boot processor
68 * and the secondary one
70 spin_lock(&boot_lock);
73 * The secondary processor is waiting to be released from
74 * the holding pen - release it, then wait for it to flag
75 * that it has been released by resetting pen_release.
78 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
79 outer_clean_range(__pa(&pen_release), __pa(&pen_release) + 1);
81 smp_cross_call(cpumask_of(cpu));
83 timeout = jiffies + (1 * HZ);
84 while (time_before(jiffies, timeout)) {
85 if (pen_release == -1)
90 * now the secondary core is starting up let it run its
91 * calibrations, then wait for it to finish
93 spin_unlock(&boot_lock);
95 return pen_release != -1 ? -ENOSYS : 0;
98 static void __init wakeup_secondary(void)
100 /* nobody is to be released from the pen yet */
104 * write the address of secondary startup into the backup ram register
105 * at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
106 * backup ram register at offset 0x1FF0, which is what boot rom code
107 * is waiting for. This would wake up the secondary core from WFE
109 #define U8500_CPU1_JUMPADDR_OFFSET 0x1FF4
110 __raw_writel(virt_to_phys(u8500_secondary_startup),
111 __io_address(UX500_BACKUPRAM0_BASE) +
112 U8500_CPU1_JUMPADDR_OFFSET);
114 #define U8500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
115 __raw_writel(0xA1FEED01,
116 __io_address(UX500_BACKUPRAM0_BASE) +
117 U8500_CPU1_WAKEMAGIC_OFFSET);
119 /* make sure write buffer is drained */
124 * Initialise the CPU possible map early - this describes the CPUs
125 * which may be present or become present in the system.
127 void __init smp_init_cpus(void)
129 unsigned int i, ncores = get_core_count();
131 for (i = 0; i < ncores; i++)
132 set_cpu_possible(i, true);
135 void __init smp_prepare_cpus(unsigned int max_cpus)
137 unsigned int ncores = get_core_count();
138 unsigned int cpu = smp_processor_id();
144 "U8500: strange CM count of 0? Default to 1\n");
148 if (ncores > num_possible_cpus()) {
150 "U8500: no. of cores (%d) greater than configured "
151 "maximum of %d - clipping\n",
152 ncores, num_possible_cpus());
153 ncores = num_possible_cpus();
156 smp_store_cpu_info(cpu);
159 * are we trying to boot more cores than exist?
161 if (max_cpus > ncores)
165 * Initialise the present map, which describes the set of CPUs
166 * actually populated at the present time.
168 for (i = 0; i < max_cpus; i++)
169 set_cpu_present(i, true);
173 * Enable the local timer or broadcast device for the
174 * boot CPU, but only if we have more than one CPU.
176 percpu_timer_setup();
177 scu_enable(__io_address(UX500_SCU_BASE));