blob: c862ce19587e320039f2c8de35a833ee8ed85331 [file] [log] [blame]
Russell King862184f2005-11-07 21:05:42 +00001/*
2 * linux/arch/arm/mach-realview/platsmp.c
3 *
4 * Copyright (C) 2002 ARM Ltd.
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/init.h>
12#include <linux/errno.h>
13#include <linux/delay.h>
14#include <linux/device.h>
Russell King934848d2009-01-08 09:58:51 +000015#include <linux/jiffies.h>
Russell King862184f2005-11-07 21:05:42 +000016#include <linux/smp.h>
Russell Kingfced80c2008-09-06 12:10:45 +010017#include <linux/io.h>
Russell King862184f2005-11-07 21:05:42 +000018
19#include <asm/cacheflush.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/hardware.h>
Catalin Marinas7dd19e72008-02-04 17:39:00 +010021#include <asm/mach-types.h>
Russell Kingbc282482009-05-17 18:58:34 +010022#include <asm/localtimer.h>
Russell King862184f2005-11-07 21:05:42 +000023
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/board-eb.h>
25#include <mach/board-pb11mp.h>
Russell King49613d42009-05-16 11:41:53 +010026#include <asm/smp_scu.h>
Catalin Marinasb7b0ba92008-04-18 22:43:08 +010027
Catalin Marinas1bbdf632008-12-01 14:54:58 +000028#include "core.h"
29
Russell King862184f2005-11-07 21:05:42 +000030extern void realview_secondary_startup(void);
31
32/*
33 * control for which core is the next to come out of the secondary
34 * boot "holding pen"
35 */
36volatile int __cpuinitdata pen_release = -1;
37
Catalin Marinas1bbdf632008-12-01 14:54:58 +000038static void __iomem *scu_base_addr(void)
39{
40 if (machine_is_realview_eb_mp())
41 return __io_address(REALVIEW_EB11MP_SCU_BASE);
42 else if (machine_is_realview_pb11mp())
43 return __io_address(REALVIEW_TC11MP_SCU_BASE);
44 else
45 return (void __iomem *)0;
46}
47
Russell Kinga8cbcd92009-05-16 11:51:14 +010048static inline unsigned int get_core_count(void)
Russell King862184f2005-11-07 21:05:42 +000049{
Catalin Marinas1bbdf632008-12-01 14:54:58 +000050 void __iomem *scu_base = scu_base_addr();
Russell Kinga8cbcd92009-05-16 11:51:14 +010051 if (scu_base)
52 return scu_get_core_count(scu_base);
53 return 1;
Catalin Marinasb7b0ba92008-04-18 22:43:08 +010054}
55
Russell King862184f2005-11-07 21:05:42 +000056static DEFINE_SPINLOCK(boot_lock);
57
58void __cpuinit platform_secondary_init(unsigned int cpu)
59{
Catalin Marinas08383ef2008-06-27 15:15:12 +010060 trace_hardirqs_off();
61
Russell King862184f2005-11-07 21:05:42 +000062 /*
Russell King862184f2005-11-07 21:05:42 +000063 * if any interrupts are already enabled for the primary
64 * core (e.g. timer irq), then they will not have been enabled
65 * for us: do so
66 */
Catalin Marinas1bbdf632008-12-01 14:54:58 +000067 gic_cpu_init(0, gic_cpu_base_addr);
Russell King862184f2005-11-07 21:05:42 +000068
69 /*
70 * let the primary processor know we're out of the
71 * pen, then head off into the C entry point
72 */
73 pen_release = -1;
Catalin Marinas0e0ba762007-02-15 19:05:29 +010074 smp_wmb();
Russell King862184f2005-11-07 21:05:42 +000075
76 /*
77 * Synchronise with the boot thread.
78 */
79 spin_lock(&boot_lock);
80 spin_unlock(&boot_lock);
81}
82
83int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
84{
85 unsigned long timeout;
86
87 /*
88 * set synchronisation state between this boot processor
89 * and the secondary one
90 */
91 spin_lock(&boot_lock);
92
93 /*
94 * The secondary processor is waiting to be released from
95 * the holding pen - release it, then wait for it to flag
96 * that it has been released by resetting pen_release.
97 *
98 * Note that "pen_release" is the hardware CPU ID, whereas
99 * "cpu" is Linux's internal ID.
100 */
101 pen_release = cpu;
102 flush_cache_all();
103
104 /*
105 * XXX
106 *
107 * This is a later addition to the booting protocol: the
108 * bootMonitor now puts secondary cores into WFI, so
109 * poke_milo() no longer gets the cores moving; we need
110 * to send a soft interrupt to wake the secondary core.
111 * Use smp_cross_call() for this, since there's little
112 * point duplicating the code here
113 */
Russell King82668102009-05-17 16:20:18 +0100114 smp_cross_call(cpumask_of(cpu));
Russell King862184f2005-11-07 21:05:42 +0000115
116 timeout = jiffies + (1 * HZ);
117 while (time_before(jiffies, timeout)) {
Catalin Marinas0e0ba762007-02-15 19:05:29 +0100118 smp_rmb();
Russell King862184f2005-11-07 21:05:42 +0000119 if (pen_release == -1)
120 break;
121
122 udelay(10);
123 }
124
125 /*
126 * now the secondary core is starting up let it run its
127 * calibrations, then wait for it to finish
128 */
129 spin_unlock(&boot_lock);
130
131 return pen_release != -1 ? -ENOSYS : 0;
132}
133
134static void __init poke_milo(void)
135{
136 extern void secondary_startup(void);
137
138 /* nobody is to be released from the pen yet */
139 pen_release = -1;
140
141 /*
142 * write the address of secondary startup into the system-wide
143 * flags register, then clear the bottom two bits, which is what
144 * BootMonitor is waiting for
145 */
146#if 1
147#define REALVIEW_SYS_FLAGSS_OFFSET 0x30
148 __raw_writel(virt_to_phys(realview_secondary_startup),
Russell King5d430452005-11-08 10:44:46 +0000149 __io_address(REALVIEW_SYS_BASE) +
150 REALVIEW_SYS_FLAGSS_OFFSET);
Russell King862184f2005-11-07 21:05:42 +0000151#define REALVIEW_SYS_FLAGSC_OFFSET 0x34
152 __raw_writel(3,
Russell King5d430452005-11-08 10:44:46 +0000153 __io_address(REALVIEW_SYS_BASE) +
154 REALVIEW_SYS_FLAGSC_OFFSET);
Russell King862184f2005-11-07 21:05:42 +0000155#endif
156
157 mb();
158}
159
Russell King7bbb7942006-02-16 11:08:09 +0000160/*
161 * Initialise the CPU possible map early - this describes the CPUs
162 * which may be present or become present in the system.
163 */
164void __init smp_init_cpus(void)
165{
166 unsigned int i, ncores = get_core_count();
167
168 for (i = 0; i < ncores; i++)
169 cpu_set(i, cpu_possible_map);
170}
171
Russell King862184f2005-11-07 21:05:42 +0000172void __init smp_prepare_cpus(unsigned int max_cpus)
173{
174 unsigned int ncores = get_core_count();
175 unsigned int cpu = smp_processor_id();
176 int i;
177
178 /* sanity check */
179 if (ncores == 0) {
180 printk(KERN_ERR
181 "Realview: strange CM count of 0? Default to 1\n");
182
183 ncores = 1;
184 }
185
186 if (ncores > NR_CPUS) {
187 printk(KERN_WARNING
188 "Realview: no. of cores (%d) greater than configured "
189 "maximum of %d - clipping\n",
190 ncores, NR_CPUS);
191 ncores = NR_CPUS;
192 }
193
194 smp_store_cpu_info(cpu);
195
196 /*
197 * are we trying to boot more cores than exist?
198 */
199 if (max_cpus > ncores)
200 max_cpus = ncores;
201
Russell King2a98beb2005-11-09 10:50:29 +0000202 /*
Russell King7bbb7942006-02-16 11:08:09 +0000203 * Initialise the present map, which describes the set of CPUs
204 * actually populated at the present time.
Russell King862184f2005-11-07 21:05:42 +0000205 */
Russell King7bbb7942006-02-16 11:08:09 +0000206 for (i = 0; i < max_cpus; i++)
Russell King862184f2005-11-07 21:05:42 +0000207 cpu_set(i, cpu_present_map);
Russell King862184f2005-11-07 21:05:42 +0000208
209 /*
Catalin Marinasb7b0ba92008-04-18 22:43:08 +0100210 * Initialise the SCU if there are more than one CPU and let
211 * them know where to start. Note that, on modern versions of
212 * MILO, the "poke" doesn't actually do anything until each
213 * individual core is sent a soft interrupt to get it out of
214 * WFI
Russell King862184f2005-11-07 21:05:42 +0000215 */
Catalin Marinasb7b0ba92008-04-18 22:43:08 +0100216 if (max_cpus > 1) {
Russell Kingbc282482009-05-17 18:58:34 +0100217 /*
218 * Enable the local timer or broadcast device for the
219 * boot CPU, but only if we have more than one CPU.
220 */
221 percpu_timer_setup();
222
Russell Kinga8cbcd92009-05-16 11:51:14 +0100223 scu_enable(scu_base_addr());
Russell King862184f2005-11-07 21:05:42 +0000224 poke_milo();
Catalin Marinasb7b0ba92008-04-18 22:43:08 +0100225 }
Russell King862184f2005-11-07 21:05:42 +0000226}