2 * ARM64 Specific Low-Level ACPI Boot Support
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>
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.
16 #define pr_fmt(fmt) "ACPI: " fmt
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>
25 #include <linux/of_fdt.h>
26 #include <linux/smp.h>
28 #include <asm/cputype.h>
29 #include <asm/cpu_ops.h>
30 #include <asm/smp_plat.h>
32 int acpi_noirq
= 1; /* skip ACPI IRQ initialization */
33 int acpi_disabled
= 1;
34 EXPORT_SYMBOL(acpi_disabled
);
36 int acpi_pci_disabled
= 1; /* skip ACPI PCI scan and IRQ initialization */
37 EXPORT_SYMBOL(acpi_pci_disabled
);
39 static bool param_acpi_off __initdata
;
40 static bool param_acpi_force __initdata
;
42 static int __init
parse_acpi(char *arg
)
47 /* "acpi=off" disables both ACPI table parsing and interpreter */
48 if (strcmp(arg
, "off") == 0)
49 param_acpi_off
= true;
50 else if (strcmp(arg
, "force") == 0) /* force ACPI to be enabled */
51 param_acpi_force
= true;
53 return -EINVAL
; /* Core will print when we return error */
57 early_param("acpi", parse_acpi
);
59 static int __init
dt_scan_depth1_nodes(unsigned long node
,
60 const char *uname
, int depth
,
64 * Return 1 as soon as we encounter a node at depth 1 that is
65 * not the /chosen node.
67 if (depth
== 1 && (strcmp(uname
, "chosen") != 0))
73 * __acpi_map_table() will be called before page_init(), so early_ioremap()
74 * or early_memremap() should be called here to for ACPI table mapping.
76 char *__init
__acpi_map_table(unsigned long phys
, unsigned long size
)
81 return early_memremap(phys
, size
);
84 void __init
__acpi_unmap_table(char *map
, unsigned long size
)
89 early_memunmap(map
, size
);
92 bool __init
acpi_psci_present(void)
94 return acpi_gbl_FADT
.arm_boot_flags
& ACPI_FADT_PSCI_COMPLIANT
;
97 /* Whether HVC must be used instead of SMC as the PSCI conduit */
98 bool __init
acpi_psci_use_hvc(void)
100 return acpi_gbl_FADT
.arm_boot_flags
& ACPI_FADT_PSCI_USE_HVC
;
104 * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity
107 * Return 0 on success, <0 on failure
109 static int __init
acpi_fadt_sanity_check(void)
111 struct acpi_table_header
*table
;
112 struct acpi_table_fadt
*fadt
;
118 * FADT is required on arm64; retrieve it to check its presence
119 * and carry out revision and ACPI HW reduced compliancy tests
121 status
= acpi_get_table_with_size(ACPI_SIG_FADT
, 0, &table
, &tbl_size
);
122 if (ACPI_FAILURE(status
)) {
123 const char *msg
= acpi_format_exception(status
);
125 pr_err("Failed to get FADT table, %s\n", msg
);
129 fadt
= (struct acpi_table_fadt
*)table
;
132 * Revision in table header is the FADT Major revision, and there
133 * is a minor revision of FADT which was introduced by ACPI 5.1,
134 * we only deal with ACPI 5.1 or newer revision to get GIC and SMP
135 * boot protocol configuration data.
137 if (table
->revision
< 5 ||
138 (table
->revision
== 5 && fadt
->minor_revision
< 1)) {
139 pr_err("Unsupported FADT revision %d.%d, should be 5.1+\n",
140 table
->revision
, fadt
->minor_revision
);
145 if (!(fadt
->flags
& ACPI_FADT_HW_REDUCED
)) {
146 pr_err("FADT not ACPI hardware reduced compliant\n");
152 * acpi_get_table_with_size() creates FADT table mapping that
153 * should be released after parsing and before resuming boot
155 early_acpi_os_unmap_memory(table
, tbl_size
);
160 * acpi_boot_table_init() called from setup_arch(), always.
161 * 1. find RSDP and get its address, and then find XSDT
162 * 2. extract all tables and checksums them all
163 * 3. check ACPI FADT revision
164 * 4. check ACPI FADT HW reduced flag
166 * We can parse ACPI boot-time tables such as MADT after
167 * this function is called.
169 * On return ACPI is enabled if either:
171 * - ACPI tables are initialized and sanity checks passed
172 * - acpi=force was passed in the command line and ACPI was not disabled
173 * explicitly through acpi=off command line parameter
175 * ACPI is disabled on function return otherwise
177 void __init
acpi_boot_table_init(void)
180 * Enable ACPI instead of device tree unless
181 * - ACPI has been disabled explicitly (acpi=off), or
182 * - the device tree is not empty (it has more than just a /chosen node)
183 * and ACPI has not been force enabled (acpi=force)
185 if (param_acpi_off
||
186 (!param_acpi_force
&& of_scan_flat_dt(dt_scan_depth1_nodes
, NULL
)))
190 * ACPI is disabled at this point. Enable it in order to parse
191 * the ACPI tables and carry out sanity checks
196 * If ACPI tables are initialized and FADT sanity checks passed,
197 * leave ACPI enabled and carry on booting; otherwise disable ACPI
198 * on initialization error.
199 * If acpi=force was passed on the command line it forces ACPI
200 * to be enabled even if its initialization failed.
202 if (acpi_table_init() || acpi_fadt_sanity_check()) {
203 pr_err("Failed to init ACPI tables\n");
204 if (!param_acpi_force
)
209 void __init
acpi_gic_init(void)
211 struct acpi_table_header
*table
;
219 status
= acpi_get_table_with_size(ACPI_SIG_MADT
, 0, &table
, &tbl_size
);
220 if (ACPI_FAILURE(status
)) {
221 const char *msg
= acpi_format_exception(status
);
223 pr_err("Failed to get MADT table, %s\n", msg
);
227 err
= gic_v2_acpi_init(table
);
229 pr_err("Failed to initialize GIC IRQ controller");
231 early_acpi_os_unmap_memory((char *)table
, tbl_size
);