blob: dc1ace55d5578bdcb96930fa7dabde0bb692ddd9 [file] [log] [blame]
Russell King59ac59f2010-02-11 21:56:07 +00001/*
2 * linux/arch/arm/mach-vexpress/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>
Russell King59ac59f2010-02-11 21:56:07 +000013#include <linux/smp.h>
14#include <linux/io.h>
Pawel Moll95d59742012-02-24 09:18:14 +000015#include <linux/of_fdt.h>
Pawel Moll38669e02012-10-09 12:56:36 +010016#include <linux/vexpress.h>
Pawel Moll95d59742012-02-24 09:18:14 +000017
18#include <asm/smp_scu.h>
Pawel Moll95d59742012-02-24 09:18:14 +000019#include <asm/mach/map.h>
Russell King59ac59f2010-02-11 21:56:07 +000020
Russell King59ac59f2010-02-11 21:56:07 +000021#include <mach/motherboard.h>
Russell King59ac59f2010-02-11 21:56:07 +000022
Marc Zyngier3695adc2011-09-08 13:15:22 +010023#include <plat/platsmp.h>
Russell King59ac59f2010-02-11 21:56:07 +000024
Marc Zyngier3695adc2011-09-08 13:15:22 +010025#include "core.h"
Russell King3705ff62010-12-18 10:53:12 +000026
Pawel Moll95d59742012-02-24 09:18:14 +000027#if defined(CONFIG_OF)
28
29static enum {
30 GENERIC_SCU,
31 CORTEX_A9_SCU,
32} vexpress_dt_scu __initdata = GENERIC_SCU;
33
34static struct map_desc vexpress_dt_cortex_a9_scu_map __initdata = {
35 .virtual = V2T_PERIPH,
36 /* .pfn set in vexpress_dt_init_cortex_a9_scu() */
37 .length = SZ_128,
38 .type = MT_DEVICE,
39};
40
41static void *vexpress_dt_cortex_a9_scu_base __initdata;
42
43const static char *vexpress_dt_cortex_a9_match[] __initconst = {
44 "arm,cortex-a5-scu",
45 "arm,cortex-a9-scu",
46 NULL
47};
48
49static int __init vexpress_dt_find_scu(unsigned long node,
50 const char *uname, int depth, void *data)
51{
52 if (of_flat_dt_match(node, vexpress_dt_cortex_a9_match)) {
53 phys_addr_t phys_addr;
54 __be32 *reg = of_get_flat_dt_prop(node, "reg", NULL);
55
56 if (WARN_ON(!reg))
57 return -EINVAL;
58
59 phys_addr = be32_to_cpup(reg);
60 vexpress_dt_scu = CORTEX_A9_SCU;
61
62 vexpress_dt_cortex_a9_scu_map.pfn = __phys_to_pfn(phys_addr);
63 iotable_init(&vexpress_dt_cortex_a9_scu_map, 1);
64 vexpress_dt_cortex_a9_scu_base = ioremap(phys_addr, SZ_256);
65 if (WARN_ON(!vexpress_dt_cortex_a9_scu_base))
66 return -EFAULT;
67 }
68
69 return 0;
70}
71
72void __init vexpress_dt_smp_map_io(void)
73{
74 if (initial_boot_params)
75 WARN_ON(of_scan_flat_dt(vexpress_dt_find_scu, NULL));
76}
77
78static int __init vexpress_dt_cpus_num(unsigned long node, const char *uname,
79 int depth, void *data)
80{
81 static int prev_depth = -1;
82 static int nr_cpus = -1;
83
84 if (prev_depth > depth && nr_cpus > 0)
85 return nr_cpus;
86
87 if (nr_cpus < 0 && strcmp(uname, "cpus") == 0)
88 nr_cpus = 0;
89
90 if (nr_cpus >= 0) {
91 const char *device_type = of_get_flat_dt_prop(node,
92 "device_type", NULL);
93
94 if (device_type && strcmp(device_type, "cpu") == 0)
95 nr_cpus++;
96 }
97
98 prev_depth = depth;
99
100 return 0;
101}
102
103static void __init vexpress_dt_smp_init_cpus(void)
104{
105 int ncores = 0, i;
106
107 switch (vexpress_dt_scu) {
108 case GENERIC_SCU:
109 ncores = of_scan_flat_dt(vexpress_dt_cpus_num, NULL);
110 break;
111 case CORTEX_A9_SCU:
112 ncores = scu_get_core_count(vexpress_dt_cortex_a9_scu_base);
113 break;
114 default:
115 WARN_ON(1);
116 break;
117 }
118
119 if (ncores < 2)
120 return;
121
122 if (ncores > nr_cpu_ids) {
123 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
124 ncores, nr_cpu_ids);
125 ncores = nr_cpu_ids;
126 }
127
128 for (i = 0; i < ncores; ++i)
129 set_cpu_possible(i, true);
Pawel Moll95d59742012-02-24 09:18:14 +0000130}
131
132static void __init vexpress_dt_smp_prepare_cpus(unsigned int max_cpus)
133{
134 int i;
135
136 switch (vexpress_dt_scu) {
137 case GENERIC_SCU:
138 for (i = 0; i < max_cpus; i++)
139 set_cpu_present(i, true);
140 break;
141 case CORTEX_A9_SCU:
142 scu_enable(vexpress_dt_cortex_a9_scu_base);
143 break;
144 default:
145 WARN_ON(1);
146 break;
147 }
148}
149
150#else
151
152static void __init vexpress_dt_smp_init_cpus(void)
153{
154 WARN_ON(1);
155}
156
157void __init vexpress_dt_smp_prepare_cpus(unsigned int max_cpus)
158{
159 WARN_ON(1);
160}
161
162#endif
163
Russell King59ac59f2010-02-11 21:56:07 +0000164/*
165 * Initialise the CPU possible map early - this describes the CPUs
166 * which may be present or become present in the system.
167 */
Marc Zyngier3695adc2011-09-08 13:15:22 +0100168static void __init vexpress_smp_init_cpus(void)
Russell King59ac59f2010-02-11 21:56:07 +0000169{
Pawel Moll95d59742012-02-24 09:18:14 +0000170 if (ct_desc)
171 ct_desc->init_cpu_map();
172 else
173 vexpress_dt_smp_init_cpus();
174
Russell King59ac59f2010-02-11 21:56:07 +0000175}
176
Marc Zyngier3695adc2011-09-08 13:15:22 +0100177static void __init vexpress_smp_prepare_cpus(unsigned int max_cpus)
Russell King59ac59f2010-02-11 21:56:07 +0000178{
Russell King59ac59f2010-02-11 21:56:07 +0000179 /*
180 * Initialise the present map, which describes the set of CPUs
181 * actually populated at the present time.
182 */
Pawel Moll95d59742012-02-24 09:18:14 +0000183 if (ct_desc)
184 ct_desc->smp_enable(max_cpus);
185 else
186 vexpress_dt_smp_prepare_cpus(max_cpus);
Russell King05c74a62010-12-03 11:09:48 +0000187
Russell King59ac59f2010-02-11 21:56:07 +0000188 /*
Russell King05c74a62010-12-03 11:09:48 +0000189 * Write the address of secondary startup into the
190 * system-wide flags register. The boot monitor waits
191 * until it receives a soft interrupt, and then the
192 * secondary CPU branches to this address.
Russell King59ac59f2010-02-11 21:56:07 +0000193 */
Pawel Moll38669e02012-10-09 12:56:36 +0100194 vexpress_flags_set(virt_to_phys(versatile_secondary_startup));
Russell King59ac59f2010-02-11 21:56:07 +0000195}
Marc Zyngier3695adc2011-09-08 13:15:22 +0100196
197struct smp_operations __initdata vexpress_smp_ops = {
198 .smp_init_cpus = vexpress_smp_init_cpus,
199 .smp_prepare_cpus = vexpress_smp_prepare_cpus,
200 .smp_secondary_init = versatile_secondary_init,
201 .smp_boot_secondary = versatile_boot_secondary,
202#ifdef CONFIG_HOTPLUG_CPU
203 .cpu_die = vexpress_cpu_die,
204#endif
205};