Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 1 | /* |
| 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 King | 934848d | 2009-01-08 09:58:51 +0000 | [diff] [blame] | 15 | #include <linux/jiffies.h> |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 16 | #include <linux/smp.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 17 | #include <linux/io.h> |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 18 | |
| 19 | #include <asm/cacheflush.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 20 | #include <mach/hardware.h> |
Catalin Marinas | 7dd19e7 | 2008-02-04 17:39:00 +0100 | [diff] [blame] | 21 | #include <asm/mach-types.h> |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 22 | #include <asm/localtimer.h> |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 23 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 24 | #include <mach/board-eb.h> |
| 25 | #include <mach/board-pb11mp.h> |
Russell King | 49613d4 | 2009-05-16 11:41:53 +0100 | [diff] [blame] | 26 | #include <asm/smp_scu.h> |
Catalin Marinas | b7b0ba9 | 2008-04-18 22:43:08 +0100 | [diff] [blame] | 27 | |
Catalin Marinas | 1bbdf63 | 2008-12-01 14:54:58 +0000 | [diff] [blame] | 28 | #include "core.h" |
| 29 | |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 30 | extern 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 | */ |
| 36 | volatile int __cpuinitdata pen_release = -1; |
| 37 | |
Catalin Marinas | 1bbdf63 | 2008-12-01 14:54:58 +0000 | [diff] [blame] | 38 | static 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 King | a8cbcd9 | 2009-05-16 11:51:14 +0100 | [diff] [blame^] | 48 | static inline unsigned int get_core_count(void) |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 49 | { |
Catalin Marinas | 1bbdf63 | 2008-12-01 14:54:58 +0000 | [diff] [blame] | 50 | void __iomem *scu_base = scu_base_addr(); |
Russell King | a8cbcd9 | 2009-05-16 11:51:14 +0100 | [diff] [blame^] | 51 | if (scu_base) |
| 52 | return scu_get_core_count(scu_base); |
| 53 | return 1; |
Catalin Marinas | b7b0ba9 | 2008-04-18 22:43:08 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 56 | static DEFINE_SPINLOCK(boot_lock); |
| 57 | |
| 58 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 59 | { |
Catalin Marinas | 08383ef | 2008-06-27 15:15:12 +0100 | [diff] [blame] | 60 | trace_hardirqs_off(); |
| 61 | |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 62 | /* |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 63 | * 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 Marinas | 1bbdf63 | 2008-12-01 14:54:58 +0000 | [diff] [blame] | 67 | gic_cpu_init(0, gic_cpu_base_addr); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 68 | |
| 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 Marinas | 0e0ba76 | 2007-02-15 19:05:29 +0100 | [diff] [blame] | 74 | smp_wmb(); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Synchronise with the boot thread. |
| 78 | */ |
| 79 | spin_lock(&boot_lock); |
| 80 | spin_unlock(&boot_lock); |
| 81 | } |
| 82 | |
| 83 | int __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 King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 114 | smp_cross_call(cpumask_of(cpu)); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 115 | |
| 116 | timeout = jiffies + (1 * HZ); |
| 117 | while (time_before(jiffies, timeout)) { |
Catalin Marinas | 0e0ba76 | 2007-02-15 19:05:29 +0100 | [diff] [blame] | 118 | smp_rmb(); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 119 | 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 | |
| 134 | static 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 King | 5d43045 | 2005-11-08 10:44:46 +0000 | [diff] [blame] | 149 | __io_address(REALVIEW_SYS_BASE) + |
| 150 | REALVIEW_SYS_FLAGSS_OFFSET); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 151 | #define REALVIEW_SYS_FLAGSC_OFFSET 0x34 |
| 152 | __raw_writel(3, |
Russell King | 5d43045 | 2005-11-08 10:44:46 +0000 | [diff] [blame] | 153 | __io_address(REALVIEW_SYS_BASE) + |
| 154 | REALVIEW_SYS_FLAGSC_OFFSET); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 155 | #endif |
| 156 | |
| 157 | mb(); |
| 158 | } |
| 159 | |
Russell King | 7bbb794 | 2006-02-16 11:08:09 +0000 | [diff] [blame] | 160 | /* |
| 161 | * Initialise the CPU possible map early - this describes the CPUs |
| 162 | * which may be present or become present in the system. |
| 163 | */ |
| 164 | void __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 King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 172 | void __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 King | 2a98beb | 2005-11-09 10:50:29 +0000 | [diff] [blame] | 202 | /* |
Russell King | 7bbb794 | 2006-02-16 11:08:09 +0000 | [diff] [blame] | 203 | * Initialise the present map, which describes the set of CPUs |
| 204 | * actually populated at the present time. |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 205 | */ |
Russell King | 7bbb794 | 2006-02-16 11:08:09 +0000 | [diff] [blame] | 206 | for (i = 0; i < max_cpus; i++) |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 207 | cpu_set(i, cpu_present_map); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 208 | |
| 209 | /* |
Catalin Marinas | b7b0ba9 | 2008-04-18 22:43:08 +0100 | [diff] [blame] | 210 | * 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 King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 215 | */ |
Catalin Marinas | b7b0ba9 | 2008-04-18 22:43:08 +0100 | [diff] [blame] | 216 | if (max_cpus > 1) { |
Russell King | bc28248 | 2009-05-17 18:58:34 +0100 | [diff] [blame] | 217 | /* |
| 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 King | a8cbcd9 | 2009-05-16 11:51:14 +0100 | [diff] [blame^] | 223 | scu_enable(scu_base_addr()); |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 224 | poke_milo(); |
Catalin Marinas | b7b0ba9 | 2008-04-18 22:43:08 +0100 | [diff] [blame] | 225 | } |
Russell King | 862184f | 2005-11-07 21:05:42 +0000 | [diff] [blame] | 226 | } |