Commit | Line | Data |
---|---|---|
37655163 AS |
1 | /* |
2 | * ARM64 Specific Low-Level ACPI Boot Support | |
3 | * | |
4 | * Copyright (C) 2013-2014, Linaro Ltd. | |
5 | * Author: Al Stone <al.stone@linaro.org> | |
6 | * Author: Graeme Gregory <graeme.gregory@linaro.org> | |
7 | * Author: Hanjun Guo <hanjun.guo@linaro.org> | |
8 | * Author: Tomasz Nowicki <tomasz.nowicki@linaro.org> | |
9 | * Author: Naresh Bhat <naresh.bhat@linaro.org> | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License version 2 as | |
13 | * published by the Free Software Foundation. | |
14 | */ | |
15 | ||
16 | #define pr_fmt(fmt) "ACPI: " fmt | |
17 | ||
18 | #include <linux/acpi.h> | |
19 | #include <linux/bootmem.h> | |
20 | #include <linux/cpumask.h> | |
21 | #include <linux/init.h> | |
22 | #include <linux/irq.h> | |
23 | #include <linux/irqdomain.h> | |
24 | #include <linux/memblock.h> | |
b10d79f7 | 25 | #include <linux/of_fdt.h> |
37655163 AS |
26 | #include <linux/smp.h> |
27 | ||
fccb9a81 HG |
28 | #include <asm/cputype.h> |
29 | #include <asm/cpu_ops.h> | |
30 | #include <asm/smp_plat.h> | |
31 | ||
b10d79f7 AS |
32 | int acpi_noirq = 1; /* skip ACPI IRQ initialization */ |
33 | int acpi_disabled = 1; | |
37655163 AS |
34 | EXPORT_SYMBOL(acpi_disabled); |
35 | ||
b10d79f7 | 36 | int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */ |
37655163 AS |
37 | EXPORT_SYMBOL(acpi_pci_disabled); |
38 | ||
fccb9a81 HG |
39 | /* Processors with enabled flag and sane MPIDR */ |
40 | static int enabled_cpus; | |
41 | ||
42 | /* Boot CPU is valid or not in MADT */ | |
43 | static bool bootcpu_valid __initdata; | |
44 | ||
b10d79f7 | 45 | static bool param_acpi_off __initdata; |
fb094eb1 | 46 | static bool param_acpi_force __initdata; |
b10d79f7 AS |
47 | |
48 | static int __init parse_acpi(char *arg) | |
49 | { | |
50 | if (!arg) | |
51 | return -EINVAL; | |
52 | ||
53 | /* "acpi=off" disables both ACPI table parsing and interpreter */ | |
54 | if (strcmp(arg, "off") == 0) | |
55 | param_acpi_off = true; | |
56 | else if (strcmp(arg, "force") == 0) /* force ACPI to be enabled */ | |
57 | param_acpi_force = true; | |
58 | else | |
59 | return -EINVAL; /* Core will print when we return error */ | |
60 | ||
61 | return 0; | |
62 | } | |
63 | early_param("acpi", parse_acpi); | |
64 | ||
65 | static int __init dt_scan_depth1_nodes(unsigned long node, | |
66 | const char *uname, int depth, | |
67 | void *data) | |
68 | { | |
69 | /* | |
70 | * Return 1 as soon as we encounter a node at depth 1 that is | |
71 | * not the /chosen node. | |
72 | */ | |
73 | if (depth == 1 && (strcmp(uname, "chosen") != 0)) | |
74 | return 1; | |
75 | return 0; | |
76 | } | |
77 | ||
37655163 AS |
78 | /* |
79 | * __acpi_map_table() will be called before page_init(), so early_ioremap() | |
80 | * or early_memremap() should be called here to for ACPI table mapping. | |
81 | */ | |
82 | char *__init __acpi_map_table(unsigned long phys, unsigned long size) | |
83 | { | |
84 | if (!size) | |
85 | return NULL; | |
86 | ||
87 | return early_memremap(phys, size); | |
88 | } | |
89 | ||
90 | void __init __acpi_unmap_table(char *map, unsigned long size) | |
91 | { | |
92 | if (!map || !size) | |
93 | return; | |
94 | ||
95 | early_memunmap(map, size); | |
96 | } | |
97 | ||
fccb9a81 HG |
98 | /** |
99 | * acpi_map_gic_cpu_interface - generates a logical cpu number | |
100 | * and map to MPIDR represented by GICC structure | |
101 | * @mpidr: CPU's hardware id to register, MPIDR represented in MADT | |
102 | * @enabled: this cpu is enabled or not | |
103 | * | |
104 | * Returns the logical cpu number which maps to MPIDR | |
105 | */ | |
8ef32031 WD |
106 | static int __init |
107 | acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor) | |
fccb9a81 HG |
108 | { |
109 | int i; | |
8ef32031 WD |
110 | u64 mpidr = processor->arm_mpidr & MPIDR_HWID_BITMASK; |
111 | bool enabled = !!(processor->flags & ACPI_MADT_ENABLED); | |
fccb9a81 HG |
112 | |
113 | if (mpidr == INVALID_HWID) { | |
114 | pr_info("Skip MADT cpu entry with invalid MPIDR\n"); | |
115 | return -EINVAL; | |
116 | } | |
117 | ||
118 | total_cpus++; | |
119 | if (!enabled) | |
120 | return -EINVAL; | |
121 | ||
122 | if (enabled_cpus >= NR_CPUS) { | |
123 | pr_warn("NR_CPUS limit of %d reached, Processor %d/0x%llx ignored.\n", | |
124 | NR_CPUS, total_cpus, mpidr); | |
125 | return -EINVAL; | |
126 | } | |
127 | ||
128 | /* Check if GICC structure of boot CPU is available in the MADT */ | |
129 | if (cpu_logical_map(0) == mpidr) { | |
130 | if (bootcpu_valid) { | |
131 | pr_err("Firmware bug, duplicate CPU MPIDR: 0x%llx in MADT\n", | |
132 | mpidr); | |
133 | return -EINVAL; | |
134 | } | |
135 | ||
136 | bootcpu_valid = true; | |
137 | } | |
138 | ||
139 | /* | |
140 | * Duplicate MPIDRs are a recipe for disaster. Scan | |
141 | * all initialized entries and check for | |
142 | * duplicates. If any is found just ignore the CPU. | |
143 | */ | |
144 | for (i = 1; i < enabled_cpus; i++) { | |
145 | if (cpu_logical_map(i) == mpidr) { | |
146 | pr_err("Firmware bug, duplicate CPU MPIDR: 0x%llx in MADT\n", | |
147 | mpidr); | |
148 | return -EINVAL; | |
149 | } | |
150 | } | |
151 | ||
152 | if (!acpi_psci_present()) | |
153 | return -EOPNOTSUPP; | |
154 | ||
155 | cpu_ops[enabled_cpus] = cpu_get_ops("psci"); | |
156 | /* CPU 0 was already initialized */ | |
157 | if (enabled_cpus) { | |
158 | if (!cpu_ops[enabled_cpus]) | |
159 | return -EINVAL; | |
160 | ||
161 | if (cpu_ops[enabled_cpus]->cpu_init(NULL, enabled_cpus)) | |
162 | return -EOPNOTSUPP; | |
163 | ||
164 | /* map the logical cpu id to cpu MPIDR */ | |
165 | cpu_logical_map(enabled_cpus) = mpidr; | |
166 | } | |
167 | ||
168 | enabled_cpus++; | |
169 | return enabled_cpus; | |
170 | } | |
171 | ||
172 | static int __init | |
173 | acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header, | |
174 | const unsigned long end) | |
175 | { | |
176 | struct acpi_madt_generic_interrupt *processor; | |
177 | ||
178 | processor = (struct acpi_madt_generic_interrupt *)header; | |
179 | ||
180 | if (BAD_MADT_ENTRY(processor, end)) | |
181 | return -EINVAL; | |
182 | ||
183 | acpi_table_print_madt_entry(header); | |
ec81ad4e HG |
184 | acpi_map_gic_cpu_interface(processor); |
185 | return 0; | |
fccb9a81 HG |
186 | } |
187 | ||
188 | /* Parse GIC cpu interface entries in MADT for SMP init */ | |
189 | void __init acpi_init_cpus(void) | |
190 | { | |
191 | int count, i; | |
192 | ||
193 | /* | |
194 | * do a partial walk of MADT to determine how many CPUs | |
195 | * we have including disabled CPUs, and get information | |
196 | * we need for SMP init | |
197 | */ | |
198 | count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, | |
199 | acpi_parse_gic_cpu_interface, 0); | |
200 | ||
201 | if (!count) { | |
202 | pr_err("No GIC CPU interface entries present\n"); | |
203 | return; | |
204 | } else if (count < 0) { | |
205 | pr_err("Error parsing GIC CPU interface entry\n"); | |
206 | return; | |
207 | } | |
208 | ||
209 | if (!bootcpu_valid) { | |
210 | pr_err("MADT missing boot CPU MPIDR, not enabling secondaries\n"); | |
211 | return; | |
212 | } | |
213 | ||
214 | for (i = 0; i < enabled_cpus; i++) | |
215 | set_cpu_possible(i, true); | |
216 | ||
217 | /* Make boot-up look pretty */ | |
218 | pr_info("%d CPUs enabled, %d CPUs total\n", enabled_cpus, total_cpus); | |
219 | } | |
220 | ||
54971e43 LP |
221 | /* |
222 | * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity | |
223 | * checks on it | |
224 | * | |
225 | * Return 0 on success, <0 on failure | |
226 | */ | |
227 | static int __init acpi_fadt_sanity_check(void) | |
37655163 | 228 | { |
54971e43 LP |
229 | struct acpi_table_header *table; |
230 | struct acpi_table_fadt *fadt; | |
231 | acpi_status status; | |
232 | acpi_size tbl_size; | |
233 | int ret = 0; | |
234 | ||
235 | /* | |
236 | * FADT is required on arm64; retrieve it to check its presence | |
237 | * and carry out revision and ACPI HW reduced compliancy tests | |
238 | */ | |
239 | status = acpi_get_table_with_size(ACPI_SIG_FADT, 0, &table, &tbl_size); | |
240 | if (ACPI_FAILURE(status)) { | |
241 | const char *msg = acpi_format_exception(status); | |
242 | ||
243 | pr_err("Failed to get FADT table, %s\n", msg); | |
244 | return -ENODEV; | |
245 | } | |
246 | ||
247 | fadt = (struct acpi_table_fadt *)table; | |
37655163 AS |
248 | |
249 | /* | |
250 | * Revision in table header is the FADT Major revision, and there | |
251 | * is a minor revision of FADT which was introduced by ACPI 5.1, | |
252 | * we only deal with ACPI 5.1 or newer revision to get GIC and SMP | |
54971e43 | 253 | * boot protocol configuration data. |
37655163 | 254 | */ |
54971e43 LP |
255 | if (table->revision < 5 || |
256 | (table->revision == 5 && fadt->minor_revision < 1)) { | |
257 | pr_err("Unsupported FADT revision %d.%d, should be 5.1+\n", | |
258 | table->revision, fadt->minor_revision); | |
259 | ret = -EINVAL; | |
260 | goto out; | |
fccb9a81 | 261 | } |
37655163 | 262 | |
54971e43 LP |
263 | if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) { |
264 | pr_err("FADT not ACPI hardware reduced compliant\n"); | |
265 | ret = -EINVAL; | |
266 | } | |
37655163 | 267 | |
54971e43 LP |
268 | out: |
269 | /* | |
270 | * acpi_get_table_with_size() creates FADT table mapping that | |
271 | * should be released after parsing and before resuming boot | |
272 | */ | |
273 | early_acpi_os_unmap_memory(table, tbl_size); | |
274 | return ret; | |
37655163 AS |
275 | } |
276 | ||
277 | /* | |
278 | * acpi_boot_table_init() called from setup_arch(), always. | |
279 | * 1. find RSDP and get its address, and then find XSDT | |
280 | * 2. extract all tables and checksums them all | |
281 | * 3. check ACPI FADT revision | |
54971e43 | 282 | * 4. check ACPI FADT HW reduced flag |
37655163 AS |
283 | * |
284 | * We can parse ACPI boot-time tables such as MADT after | |
285 | * this function is called. | |
54971e43 | 286 | * |
fb094eb1 LP |
287 | * On return ACPI is enabled if either: |
288 | * | |
289 | * - ACPI tables are initialized and sanity checks passed | |
290 | * - acpi=force was passed in the command line and ACPI was not disabled | |
291 | * explicitly through acpi=off command line parameter | |
292 | * | |
293 | * ACPI is disabled on function return otherwise | |
37655163 AS |
294 | */ |
295 | void __init acpi_boot_table_init(void) | |
296 | { | |
b10d79f7 AS |
297 | /* |
298 | * Enable ACPI instead of device tree unless | |
299 | * - ACPI has been disabled explicitly (acpi=off), or | |
300 | * - the device tree is not empty (it has more than just a /chosen node) | |
301 | * and ACPI has not been force enabled (acpi=force) | |
302 | */ | |
303 | if (param_acpi_off || | |
304 | (!param_acpi_force && of_scan_flat_dt(dt_scan_depth1_nodes, NULL))) | |
37655163 AS |
305 | return; |
306 | ||
54971e43 LP |
307 | /* |
308 | * ACPI is disabled at this point. Enable it in order to parse | |
309 | * the ACPI tables and carry out sanity checks | |
310 | */ | |
b10d79f7 AS |
311 | enable_acpi(); |
312 | ||
54971e43 LP |
313 | /* |
314 | * If ACPI tables are initialized and FADT sanity checks passed, | |
315 | * leave ACPI enabled and carry on booting; otherwise disable ACPI | |
316 | * on initialization error. | |
fb094eb1 LP |
317 | * If acpi=force was passed on the command line it forces ACPI |
318 | * to be enabled even if its initialization failed. | |
54971e43 LP |
319 | */ |
320 | if (acpi_table_init() || acpi_fadt_sanity_check()) { | |
321 | pr_err("Failed to init ACPI tables\n"); | |
fb094eb1 LP |
322 | if (!param_acpi_force) |
323 | disable_acpi(); | |
37655163 AS |
324 | } |
325 | } | |
d60fc389 TN |
326 | |
327 | void __init acpi_gic_init(void) | |
328 | { | |
329 | struct acpi_table_header *table; | |
330 | acpi_status status; | |
331 | acpi_size tbl_size; | |
332 | int err; | |
333 | ||
334 | if (acpi_disabled) | |
335 | return; | |
336 | ||
337 | status = acpi_get_table_with_size(ACPI_SIG_MADT, 0, &table, &tbl_size); | |
338 | if (ACPI_FAILURE(status)) { | |
339 | const char *msg = acpi_format_exception(status); | |
340 | ||
341 | pr_err("Failed to get MADT table, %s\n", msg); | |
342 | return; | |
343 | } | |
344 | ||
345 | err = gic_v2_acpi_init(table); | |
346 | if (err) | |
347 | pr_err("Failed to initialize GIC IRQ controller"); | |
348 | ||
349 | early_acpi_os_unmap_memory((char *)table, tbl_size); | |
350 | } |