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; |
| 19 | int len, i, count; |
| 20 | |
| 21 | rsdp = map_sysmem(gd_acpi_start(), 0); |
| 22 | if (!rsdp) |
| 23 | return NULL; |
| 24 | rsdt = map_sysmem(rsdp->rsdt_address, 0); |
| 25 | len = rsdt->header.length - sizeof(rsdt->header); |
| 26 | count = len / sizeof(u32); |
| 27 | for (i = 0; i < count; i++) { |
| 28 | struct acpi_table_header *hdr; |
| 29 | |
| 30 | hdr = map_sysmem(rsdt->entry[i], 0); |
| 31 | if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) |
| 32 | return hdr; |
| 33 | if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) { |
| 34 | struct acpi_fadt *fadt = (struct acpi_fadt *)hdr; |
| 35 | |
| 36 | if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt) |
| 37 | return map_sysmem(fadt->dsdt, 0); |
| 38 | if (!memcmp(sig, "FACS", ACPI_NAME_LEN) && |
| 39 | fadt->firmware_ctrl) |
| 40 | return map_sysmem(fadt->firmware_ctrl, 0); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return NULL; |
| 45 | } |