1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
8 #include <acpi/acpi_table.h>
10 #include <asm/tables.h>
12 static struct acpi_rsdp *acpi_valid_rsdp(struct acpi_rsdp *rsdp)
14 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
17 debug("Looking on %p for valid checksum\n", rsdp);
19 if (table_compute_checksum((void *)rsdp, 20) != 0)
21 debug("acpi rsdp checksum 1 passed\n");
23 if ((rsdp->revision > 1) &&
24 (table_compute_checksum((void *)rsdp, rsdp->length) != 0))
26 debug("acpi rsdp checksum 2 passed\n");
31 struct acpi_fadt *acpi_find_fadt(void)
34 struct acpi_rsdp *rsdp = NULL;
35 struct acpi_rsdt *rsdt;
36 struct acpi_fadt *fadt = NULL;
40 for (p = (char *)ROM_TABLE_ADDR; p < (char *)ROM_TABLE_END; p += 16) {
41 rsdp = acpi_valid_rsdp((struct acpi_rsdp *)p);
49 debug("RSDP found at %p\n", rsdp);
50 rsdt = (struct acpi_rsdt *)(uintptr_t)rsdp->rsdt_address;
52 end = (char *)rsdt + rsdt->header.length;
53 debug("RSDT found at %p ends at %p\n", rsdt, end);
55 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
56 fadt = (struct acpi_fadt *)(uintptr_t)rsdt->entry[i];
57 if (strncmp((char *)fadt, "FACP", 4) == 0)
65 debug("FADT found at %p\n", fadt);
69 void *acpi_find_wakeup_vector(struct acpi_fadt *fadt)
71 struct acpi_facs *facs;
74 debug("Trying to find the wakeup vector...\n");
76 facs = (struct acpi_facs *)(uintptr_t)fadt->firmware_ctrl;
79 debug("No FACS found, wake up from S3 not possible.\n");
83 debug("FACS found at %p\n", facs);
84 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
85 debug("OS waking vector is %p\n", wake_vec);
90 void enter_acpi_mode(int pm1_cnt)
92 u16 val = inw(pm1_cnt);
95 * PM1_CNT register bit0 selects the power management event to be
96 * either an SCI or SMI interrupt. When this bit is set, then power
97 * management events will generate an SCI interrupt. When this bit
98 * is reset power management events will generate an SMI interrupt.
100 * Per ACPI spec, it is the responsibility of the hardware to set
101 * or reset this bit. OSPM always preserves this bit position.
103 * U-Boot does not support SMI. And we don't have plan to support
104 * anything running in SMM within U-Boot. To create a legacy-free
105 * system, and expose ourselves to OSPM as working under ACPI mode
106 * already, turn this bit on.
108 outw(val | PM1_CNT_SCI_EN, pm1_cnt);