Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  ARM64 Specific Low-Level ACPI Boot Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2013-2014, Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Author: Al Stone <al.stone@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Author: Graeme Gregory <graeme.gregory@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Author: Hanjun Guo <hanjun.guo@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	Author: Tomasz Nowicki <tomasz.nowicki@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	Author: Naresh Bhat <naresh.bhat@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define pr_fmt(fmt) "ACPI: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/efi-bgrt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/irqdomain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/irq_work.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/serial_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <acpi/ghes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/cputype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/cpu_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/daifflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/smp_plat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) int acpi_noirq = 1;		/* skip ACPI IRQ initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) int acpi_disabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) EXPORT_SYMBOL(acpi_disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) int acpi_pci_disabled = 1;	/* skip ACPI PCI scan and IRQ initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) EXPORT_SYMBOL(acpi_pci_disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static bool param_acpi_off __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static bool param_acpi_on __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static bool param_acpi_force __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static int __init parse_acpi(char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* "acpi=off" disables both ACPI table parsing and interpreter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (strcmp(arg, "off") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		param_acpi_off = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	else if (strcmp(arg, "on") == 0) /* prefer ACPI over DT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		param_acpi_on = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	else if (strcmp(arg, "force") == 0) /* force ACPI to be enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		param_acpi_force = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return -EINVAL;	/* Core will print when we return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) early_param("acpi", parse_acpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int __init dt_scan_depth1_nodes(unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				       const char *uname, int depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				       void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * Ignore anything not directly under the root node; we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * catch its parent instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (depth != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (strcmp(uname, "chosen") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (strcmp(uname, "hypervisor") == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	    of_flat_dt_is_compatible(node, "xen,xen"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * This node at depth 1 is neither a chosen node nor a xen node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * which we do not expect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * __acpi_map_table() will be called before page_init(), so early_ioremap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * or early_memremap() should be called here to for ACPI table mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return early_memremap(phys, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (!map || !size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	early_memunmap(map, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) bool __init acpi_psci_present(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Whether HVC must be used instead of SMC as the PSCI conduit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) bool acpi_psci_use_hvc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *			      checks on it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * Return 0 on success,  <0 on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int __init acpi_fadt_sanity_check(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct acpi_table_header *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct acpi_table_fadt *fadt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 * FADT is required on arm64; retrieve it to check its presence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * and carry out revision and ACPI HW reduced compliancy tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	status = acpi_get_table(ACPI_SIG_FADT, 0, &table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		const char *msg = acpi_format_exception(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		pr_err("Failed to get FADT table, %s\n", msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	fadt = (struct acpi_table_fadt *)table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * Revision in table header is the FADT Major revision, and there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * is a minor revision of FADT which was introduced by ACPI 5.1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * we only deal with ACPI 5.1 or newer revision to get GIC and SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * boot protocol configuration data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (table->revision < 5 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	   (table->revision == 5 && fadt->minor_revision < 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		pr_err(FW_BUG "Unsupported FADT revision %d.%d, should be 5.1+\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		       table->revision, fadt->minor_revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		if (!fadt->arm_boot_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		pr_err("FADT has ARM boot flags set, assuming 5.1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		pr_err("FADT not ACPI hardware reduced compliant\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * acpi_get_table() creates FADT table mapping that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * should be released after parsing and before resuming boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	acpi_put_table(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * acpi_boot_table_init() called from setup_arch(), always.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *	1. find RSDP and get its address, and then find XSDT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *	2. extract all tables and checksums them all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *	3. check ACPI FADT revision
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  *	4. check ACPI FADT HW reduced flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * We can parse ACPI boot-time tables such as MADT after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * this function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * On return ACPI is enabled if either:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * - ACPI tables are initialized and sanity checks passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * - acpi=force was passed in the command line and ACPI was not disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *   explicitly through acpi=off command line parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * ACPI is disabled on function return otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) void __init acpi_boot_table_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * Enable ACPI instead of device tree unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * - ACPI has been disabled explicitly (acpi=off), or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 * - the device tree is not empty (it has more than just a /chosen node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	 *   and a /hypervisor node when running on Xen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 *   and ACPI has not been [force] enabled (acpi=on|force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (param_acpi_off ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	    (!param_acpi_on && !param_acpi_force &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	     of_scan_flat_dt(dt_scan_depth1_nodes, NULL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	 * ACPI is disabled at this point. Enable it in order to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 * the ACPI tables and carry out sanity checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	enable_acpi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 * If ACPI tables are initialized and FADT sanity checks passed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * leave ACPI enabled and carry on booting; otherwise disable ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * on initialization error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * If acpi=force was passed on the command line it forces ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * to be enabled even if its initialization failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (acpi_table_init() || acpi_fadt_sanity_check()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		pr_err("Failed to init ACPI tables\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (!param_acpi_force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			disable_acpi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (acpi_disabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (earlycon_acpi_spcr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			early_init_dt_scan_chosen_stdout();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		acpi_parse_spcr(earlycon_acpi_spcr_enable, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		if (IS_ENABLED(CONFIG_ACPI_BGRT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) pgprot_t __acpi_get_mem_attribute(phys_addr_t addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * According to "Table 8 Map: EFI memory types to AArch64 memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * types" of UEFI 2.5 section 2.3.6.1, each EFI memory type is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * mapped to a corresponding MAIR attribute encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * The EFI memory attribute advises all possible capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * of a memory region. We use the most efficient capability.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	u64 attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	attr = efi_mem_attributes(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (attr & EFI_MEMORY_WB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return PAGE_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (attr & EFI_MEMORY_WT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return __pgprot(PROT_NORMAL_WT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (attr & EFI_MEMORY_WC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return __pgprot(PROT_NORMAL_NC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return __pgprot(PROT_DEVICE_nGnRnE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	efi_memory_desc_t *md, *region = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	pgprot_t prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (WARN_ON_ONCE(!efi_enabled(EFI_MEMMAP)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	for_each_efi_memory_desc(md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		if (phys < md->phys_addr || phys >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		if (phys + size > end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			pr_warn(FW_BUG "requested region covers multiple EFI memory regions\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		region = md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 * It is fine for AML to remap regions that are not represented in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	 * EFI memory map at all, as it only describes normal memory, and MMIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * regions that require a virtual mapping to make them accessible to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * the EFI runtime services.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	prot = __pgprot(PROT_DEVICE_nGnRnE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (region) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		switch (region->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		case EFI_LOADER_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		case EFI_LOADER_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		case EFI_BOOT_SERVICES_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		case EFI_BOOT_SERVICES_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		case EFI_CONVENTIONAL_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		case EFI_PERSISTENT_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			if (memblock_is_map_memory(phys) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			    !memblock_is_region_memory(phys, size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				pr_warn(FW_BUG "requested region covers kernel memory @ %pa\n", &phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			 * Mapping kernel memory is permitted if the region in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			 * question is covered by a single memblock with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			 * NOMAP attribute set: this enables the use of ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			 * table overrides passed via initramfs, which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			 * reserved in memory using arch_reserve_mem_area()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			 * below. As this particular use case only requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			 * read access, fall through to the R/O mapping case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		case EFI_RUNTIME_SERVICES_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			 * This would be unusual, but not problematic per se,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			 * as long as we take care not to create a writable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			 * mapping for executable code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			prot = PAGE_KERNEL_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		case EFI_ACPI_RECLAIM_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			 * ACPI reclaim memory is used to pass firmware tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			 * and other data that is intended for consumption by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			 * the OS only, which may decide it wants to reclaim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			 * that memory and use it for something else. We never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			 * do that, but we usually add it to the linear map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			 * anyway, in which case we should use the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			 * mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			if (memblock_is_map_memory(phys))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 				return (void __iomem *)__phys_to_virt(phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			if (region->attribute & EFI_MEMORY_WB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				prot = PAGE_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			else if (region->attribute & EFI_MEMORY_WT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				prot = __pgprot(PROT_NORMAL_WT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			else if (region->attribute & EFI_MEMORY_WC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 				prot = __pgprot(PROT_NORMAL_NC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return __ioremap(phys, size, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * Claim Synchronous External Aborts as a firmware first notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * Used by KVM and the arch do_sea handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * @regs may be NULL when called from process context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int apei_claim_sea(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	int err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	bool return_to_irqs_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	unsigned long current_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	current_flags = local_daif_save_flags();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* current_flags isn't useful here as daif doesn't tell us about pNMI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return_to_irqs_enabled = !irqs_disabled_flags(arch_local_save_flags());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	if (regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		return_to_irqs_enabled = interrupts_enabled(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * SEA can interrupt SError, mask it and describe this as an NMI so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * that APEI defers the handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	local_daif_restore(DAIF_ERRCTX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	nmi_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	err = ghes_notify_sea();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	nmi_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	 * APEI NMI-like notifications are deferred to irq_work. Unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 * we interrupted irqs-masked code, we can do that now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		if (return_to_irqs_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			local_daif_restore(DAIF_PROCCTX_NOIRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			__irq_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			irq_work_run();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			__irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			pr_warn_ratelimited("APEI work queued but not completed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			err = -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	local_daif_restore(current_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) void arch_reserve_mem_area(acpi_physical_address addr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	memblock_mark_nomap(addr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }