blob: fd40fa175913c838d0a2f1770372f113dc64a160 [file] [log] [blame]
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +01001/*
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>
6 *
7 * This file is based on arm realview platform
8 *
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.
12 */
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>
18#include <linux/io.h>
19
20#include <asm/cacheflush.h>
21#include <asm/localtimer.h>
22#include <asm/smp_scu.h>
23#include <mach/hardware.h>
24
25/*
26 * control for which core is the next to come out of the secondary
27 * boot "holding pen"
28 */
29volatile int __cpuinitdata pen_release = -1;
30
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010031static DEFINE_SPINLOCK(boot_lock);
32
33void __cpuinit platform_secondary_init(unsigned int cpu)
34{
35 trace_hardirqs_off();
36
37 /*
38 * if any interrupts are already enabled for the primary
39 * core (e.g. timer irq), then they will not have been enabled
40 * for us: do so
41 */
Rabin Vincent817412d2010-05-03 08:31:35 +010042 gic_cpu_init(0, __io_address(UX500_GIC_CPU_BASE));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010043
44 /*
45 * let the primary processor know we're out of the
46 * pen, then head off into the C entry point
47 */
48 pen_release = -1;
49
50 /*
51 * Synchronise with the boot thread.
52 */
53 spin_lock(&boot_lock);
54 spin_unlock(&boot_lock);
55}
56
57int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
58{
59 unsigned long timeout;
60
61 /*
62 * set synchronisation state between this boot processor
63 * and the secondary one
64 */
65 spin_lock(&boot_lock);
66
67 /*
68 * The secondary processor is waiting to be released from
69 * the holding pen - release it, then wait for it to flag
70 * that it has been released by resetting pen_release.
71 */
72 pen_release = cpu;
Srinidhi Kasagar8e797a72010-04-03 19:10:45 +010073 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
74 outer_clean_range(__pa(&pen_release), __pa(&pen_release) + 1);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010075
Russell Kingad3b6992010-11-15 09:42:08 +000076 smp_cross_call(cpumask_of(cpu), 1);
Sundar Iyer9d704c02010-09-15 10:45:51 +010077
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010078 timeout = jiffies + (1 * HZ);
79 while (time_before(jiffies, timeout)) {
80 if (pen_release == -1)
81 break;
82 }
83
84 /*
85 * now the secondary core is starting up let it run its
86 * calibrations, then wait for it to finish
87 */
88 spin_unlock(&boot_lock);
89
90 return pen_release != -1 ? -ENOSYS : 0;
91}
92
93static void __init wakeup_secondary(void)
94{
95 /* nobody is to be released from the pen yet */
96 pen_release = -1;
97
98 /*
99 * write the address of secondary startup into the backup ram register
100 * at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
101 * backup ram register at offset 0x1FF0, which is what boot rom code
102 * is waiting for. This would wake up the secondary core from WFE
103 */
104#define U8500_CPU1_JUMPADDR_OFFSET 0x1FF4
105 __raw_writel(virt_to_phys(u8500_secondary_startup),
Rabin Vincent817412d2010-05-03 08:31:35 +0100106 __io_address(UX500_BACKUPRAM0_BASE) +
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100107 U8500_CPU1_JUMPADDR_OFFSET);
108
109#define U8500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
110 __raw_writel(0xA1FEED01,
Rabin Vincent817412d2010-05-03 08:31:35 +0100111 __io_address(UX500_BACKUPRAM0_BASE) +
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100112 U8500_CPU1_WAKEMAGIC_OFFSET);
113
114 /* make sure write buffer is drained */
115 mb();
116}
117
118/*
119 * Initialise the CPU possible map early - this describes the CPUs
120 * which may be present or become present in the system.
121 */
122void __init smp_init_cpus(void)
123{
Russell Kingfd778f02010-12-02 18:09:37 +0000124 unsigned int i, ncores;
125
126 ncores = scu_get_core_count(__io_address(UX500_SCU_BASE));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100127
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100128 /* sanity check */
Russell Kingbbc3d142010-12-03 10:42:58 +0000129 if (ncores > NR_CPUS) {
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100130 printk(KERN_WARNING
131 "U8500: no. of cores (%d) greater than configured "
132 "maximum of %d - clipping\n",
Russell Kingbbc3d142010-12-03 10:42:58 +0000133 ncores, NR_CPUS);
134 ncores = NR_CPUS;
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100135 }
136
Russell Kingbbc3d142010-12-03 10:42:58 +0000137 for (i = 0; i < ncores; i++)
138 set_cpu_possible(i, true);
139}
140
141void __init smp_prepare_cpus(unsigned int max_cpus)
142{
143 unsigned int ncores = num_possible_cpus();
144 unsigned int cpu = smp_processor_id();
145 int i;
146
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100147 smp_store_cpu_info(cpu);
148
149 /*
150 * are we trying to boot more cores than exist?
151 */
152 if (max_cpus > ncores)
153 max_cpus = ncores;
154
155 /*
156 * Initialise the present map, which describes the set of CPUs
157 * actually populated at the present time.
158 */
159 for (i = 0; i < max_cpus; i++)
160 set_cpu_present(i, true);
161
162 if (max_cpus > 1) {
163 /*
164 * Enable the local timer or broadcast device for the
165 * boot CPU, but only if we have more than one CPU.
166 */
167 percpu_timer_setup();
Rabin Vincent817412d2010-05-03 08:31:35 +0100168 scu_enable(__io_address(UX500_SCU_BASE));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100169 wakeup_secondary();
170 }
171}