1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
7 #include <asm/acpi_table.h>
9 #include <asm/tables.h>
11 static struct acpi_rsdp *acpi_valid_rsdp(struct acpi_rsdp *rsdp)
13 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
16 debug("Looking on %p for valid checksum\n", rsdp);
18 if (table_compute_checksum((void *)rsdp, 20) != 0)
20 debug("acpi rsdp checksum 1 passed\n");
22 if ((rsdp->revision > 1) &&
23 (table_compute_checksum((void *)rsdp, rsdp->length) != 0))
25 debug("acpi rsdp checksum 2 passed\n");
30 struct acpi_fadt *acpi_find_fadt(void)
33 struct acpi_rsdp *rsdp = NULL;
34 struct acpi_rsdt *rsdt;
35 struct acpi_fadt *fadt = NULL;
39 for (p = (char *)ROM_TABLE_ADDR; p < (char *)ROM_TABLE_END; p += 16) {
40 rsdp = acpi_valid_rsdp((struct acpi_rsdp *)p);
48 debug("RSDP found at %p\n", rsdp);
49 rsdt = (struct acpi_rsdt *)(uintptr_t)rsdp->rsdt_address;
51 end = (char *)rsdt + rsdt->header.length;
52 debug("RSDT found at %p ends at %p\n", rsdt, end);
54 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
55 fadt = (struct acpi_fadt *)(uintptr_t)rsdt->entry[i];
56 if (strncmp((char *)fadt, "FACP", 4) == 0)
64 debug("FADT found at %p\n", fadt);
68 void *acpi_find_wakeup_vector(struct acpi_fadt *fadt)
70 struct acpi_facs *facs;
73 debug("Trying to find the wakeup vector...\n");
75 facs = (struct acpi_facs *)(uintptr_t)fadt->firmware_ctrl;
78 debug("No FACS found, wake up from S3 not possible.\n");
82 debug("FACS found at %p\n", facs);
83 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
84 debug("OS waking vector is %p\n", wake_vec);
89 void enter_acpi_mode(int pm1_cnt)
91 u16 val = inw(pm1_cnt);
94 * PM1_CNT register bit0 selects the power management event to be
95 * either an SCI or SMI interrupt. When this bit is set, then power
96 * management events will generate an SCI interrupt. When this bit
97 * is reset power management events will generate an SMI interrupt.
99 * Per ACPI spec, it is the responsibility of the hardware to set
100 * or reset this bit. OSPM always preserves this bit position.
102 * U-Boot does not support SMI. And we don't have plan to support
103 * anything running in SMM within U-Boot. To create a legacy-free
104 * system, and expose ourselves to OSPM as working under ACPI mode
105 * already, turn this bit on.
107 outw(val | PM1_CNT_SCI_EN, pm1_cnt);