Simon Glass | 7ae6976 | 2023-05-04 16:54:58 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Utility functions for ACPI |
| 4 | * |
| 5 | * Copyright 2023 Google LLC |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mapmem.h> |
| 10 | #include <acpi/acpi_table.h> |
| 11 | #include <asm/global_data.h> |
| 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | struct acpi_table_header *acpi_find_table(const char *sig) |
| 16 | { |
| 17 | struct acpi_rsdp *rsdp; |
| 18 | struct acpi_rsdt *rsdt; |
Heinrich Schuchardt | 23c14e1 | 2023-11-18 22:57:26 +0100 | [diff] [blame] | 19 | struct acpi_xsdt *xsdt; |
Simon Glass | 7ae6976 | 2023-05-04 16:54:58 -0600 | [diff] [blame] | 20 | int len, i, count; |
| 21 | |
| 22 | rsdp = map_sysmem(gd_acpi_start(), 0); |
| 23 | if (!rsdp) |
| 24 | return NULL; |
Heinrich Schuchardt | 23c14e1 | 2023-11-18 22:57:26 +0100 | [diff] [blame] | 25 | if (rsdp->xsdt_address) { |
| 26 | xsdt = map_sysmem(rsdp->xsdt_address, 0); |
| 27 | len = xsdt->header.length - sizeof(xsdt->header); |
| 28 | count = len / sizeof(u64); |
| 29 | } else { |
| 30 | if (!rsdp->rsdt_address) |
| 31 | return NULL; |
| 32 | rsdt = map_sysmem(rsdp->rsdt_address, 0); |
| 33 | len = rsdt->header.length - sizeof(rsdt->header); |
| 34 | count = len / sizeof(u32); |
| 35 | } |
Simon Glass | 7ae6976 | 2023-05-04 16:54:58 -0600 | [diff] [blame] | 36 | for (i = 0; i < count; i++) { |
| 37 | struct acpi_table_header *hdr; |
| 38 | |
Heinrich Schuchardt | 23c14e1 | 2023-11-18 22:57:26 +0100 | [diff] [blame] | 39 | if (rsdp->xsdt_address) |
| 40 | hdr = map_sysmem(xsdt->entry[i], 0); |
| 41 | else |
| 42 | hdr = map_sysmem(rsdt->entry[i], 0); |
Simon Glass | 7ae6976 | 2023-05-04 16:54:58 -0600 | [diff] [blame] | 43 | if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) |
| 44 | return hdr; |
| 45 | if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) { |
| 46 | struct acpi_fadt *fadt = (struct acpi_fadt *)hdr; |
| 47 | |
| 48 | if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt) |
| 49 | return map_sysmem(fadt->dsdt, 0); |
| 50 | if (!memcmp(sig, "FACS", ACPI_NAME_LEN) && |
| 51 | fadt->firmware_ctrl) |
| 52 | return map_sysmem(fadt->firmware_ctrl, 0); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return NULL; |
| 57 | } |