Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 6 | #include <command.h> |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 7 | #include <display_options.h> |
Heinrich Schuchardt | 910590d | 2023-12-16 09:11:59 +0100 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 9 | #include <mapmem.h> |
| 10 | #include <acpi/acpi_table.h> |
| 11 | #include <asm/acpi_table.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 13 | #include <linux/errno.h> |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 14 | #include <dm/acpi.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | /** |
| 19 | * dump_hdr() - Dump an ACPI header |
| 20 | * |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 21 | * Except for the Firmware ACPI Control Structure (FACS) |
| 22 | * additionally show the revision information. |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 23 | * |
| 24 | * @hdr: ACPI header to dump |
| 25 | */ |
| 26 | static void dump_hdr(struct acpi_table_header *hdr) |
| 27 | { |
| 28 | bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN); |
| 29 | |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 30 | printf("%.*s %16lx %5x", ACPI_NAME_LEN, hdr->signature, |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 31 | (ulong)map_to_sysmem(hdr), hdr->length); |
| 32 | if (has_hdr) { |
Simon Glass | eb025f3 | 2021-12-01 09:03:06 -0700 | [diff] [blame] | 33 | printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision, |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 34 | hdr->oem_id, hdr->oem_table_id, hdr->oem_revision, |
Heinrich Schuchardt | 10de8a8 | 2024-01-21 12:52:48 +0100 | [diff] [blame] | 35 | hdr->creator_id, hdr->creator_revision); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 36 | } else { |
| 37 | printf("\n"); |
| 38 | } |
| 39 | } |
| 40 | |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 41 | static int dump_table_name(const char *sig) |
| 42 | { |
| 43 | struct acpi_table_header *hdr; |
| 44 | |
Simon Glass | 7ae6976 | 2023-05-04 16:54:58 -0600 | [diff] [blame] | 45 | hdr = acpi_find_table(sig); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 46 | if (!hdr) |
| 47 | return -ENOENT; |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 48 | printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature, |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 49 | (ulong)nomap_to_sysmem(hdr)); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 50 | print_buffer(0, hdr, 1, hdr->length, 0); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static void list_fadt(struct acpi_fadt *fadt) |
| 56 | { |
Heinrich Schuchardt | 9f8e062 | 2023-12-16 09:11:58 +0100 | [diff] [blame] | 57 | if (fadt->header.revision >= 3 && fadt->x_dsdt) |
| 58 | dump_hdr(nomap_sysmem(fadt->x_dsdt, 0)); |
| 59 | else if (fadt->dsdt) |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 60 | dump_hdr(nomap_sysmem(fadt->dsdt, 0)); |
Heinrich Schuchardt | 910590d | 2023-12-16 09:11:59 +0100 | [diff] [blame] | 61 | if (!IS_ENABLED(CONFIG_X86) && |
| 62 | !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) |
| 63 | log_err("FADT not ACPI-hardware-reduced-compliant\n"); |
Heinrich Schuchardt | 9f8e062 | 2023-12-16 09:11:58 +0100 | [diff] [blame] | 64 | if (fadt->header.revision >= 3 && fadt->x_firmware_ctrl) |
| 65 | dump_hdr(nomap_sysmem(fadt->x_firmware_ctrl, 0)); |
| 66 | else if (fadt->firmware_ctrl) |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 67 | dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0)); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 68 | } |
| 69 | |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 70 | static void list_rsdt(struct acpi_rsdp *rsdp) |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 71 | { |
| 72 | int len, i, count; |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 73 | struct acpi_rsdt *rsdt; |
| 74 | struct acpi_xsdt *xsdt; |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 75 | |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 76 | if (rsdp->rsdt_address) { |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 77 | rsdt = nomap_sysmem(rsdp->rsdt_address, 0); |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 78 | dump_hdr(&rsdt->header); |
| 79 | } |
| 80 | if (rsdp->xsdt_address) { |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 81 | xsdt = nomap_sysmem(rsdp->xsdt_address, 0); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 82 | dump_hdr(&xsdt->header); |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 83 | len = xsdt->header.length - sizeof(xsdt->header); |
| 84 | count = len / sizeof(u64); |
| 85 | } else if (rsdp->rsdt_address) { |
| 86 | len = rsdt->header.length - sizeof(rsdt->header); |
| 87 | count = len / sizeof(u32); |
| 88 | } else { |
| 89 | return; |
| 90 | } |
| 91 | |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 92 | for (i = 0; i < count; i++) { |
| 93 | struct acpi_table_header *hdr; |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 94 | u64 entry; |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 95 | |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 96 | if (rsdp->xsdt_address) |
| 97 | entry = xsdt->entry[i]; |
| 98 | else |
| 99 | entry = rsdt->entry[i]; |
| 100 | if (!entry) |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 101 | break; |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 102 | hdr = nomap_sysmem(entry, 0); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 103 | dump_hdr(hdr); |
| 104 | if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) |
| 105 | list_fadt((struct acpi_fadt *)hdr); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 106 | } |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 109 | static void list_rsdp(struct acpi_rsdp *rsdp) |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 110 | { |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 111 | printf("RSDP %16lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp), |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 112 | rsdp->length, rsdp->revision, rsdp->oem_id); |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 113 | list_rsdt(rsdp); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 114 | } |
| 115 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 116 | static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 117 | char *const argv[]) |
| 118 | { |
| 119 | struct acpi_rsdp *rsdp; |
| 120 | |
Simon Glass | b33f2f9 | 2021-12-01 09:02:37 -0700 | [diff] [blame] | 121 | rsdp = map_sysmem(gd_acpi_start(), 0); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 122 | if (!rsdp) { |
| 123 | printf("No ACPI tables present\n"); |
| 124 | return 0; |
| 125 | } |
Heinrich Schuchardt | 27e9ebb | 2023-11-21 15:41:28 +0100 | [diff] [blame] | 126 | printf("Name Base Size Detail\n" |
| 127 | "---- ---------------- ----- ----------------------------\n"); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 128 | list_rsdp(rsdp); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Simon Glass | 2b94342 | 2023-07-15 21:38:45 -0600 | [diff] [blame] | 133 | static int do_acpi_set(struct cmd_tbl *cmdtp, int flag, int argc, |
| 134 | char *const argv[]) |
| 135 | { |
| 136 | ulong val; |
| 137 | |
| 138 | if (argc < 2) { |
| 139 | printf("ACPI pointer: %lx\n", gd_acpi_start()); |
| 140 | } else { |
| 141 | val = hextoul(argv[1], NULL); |
| 142 | printf("Setting ACPI pointer to %lx\n", val); |
| 143 | gd_set_acpi_start(val); |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Simon Glass | 64bbc0d | 2020-07-07 13:12:12 -0600 | [diff] [blame] | 149 | static int do_acpi_items(struct cmd_tbl *cmdtp, int flag, int argc, |
| 150 | char *const argv[]) |
| 151 | { |
| 152 | bool dump_contents; |
| 153 | |
| 154 | dump_contents = argc >= 2 && !strcmp("-d", argv[1]); |
Simon Glass | e264be4 | 2023-05-04 16:54:57 -0600 | [diff] [blame] | 155 | if (!IS_ENABLED(CONFIG_ACPIGEN)) { |
| 156 | printf("Not supported (enable ACPIGEN)\n"); |
| 157 | return CMD_RET_FAILURE; |
| 158 | } |
Simon Glass | 64bbc0d | 2020-07-07 13:12:12 -0600 | [diff] [blame] | 159 | acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 164 | static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 165 | char *const argv[]) |
| 166 | { |
| 167 | const char *name; |
| 168 | char sig[ACPI_NAME_LEN]; |
| 169 | int ret; |
| 170 | |
Heinrich Schuchardt | 28a54ae | 2023-12-09 18:05:36 +0100 | [diff] [blame] | 171 | if (argc < 2) |
| 172 | return CMD_RET_USAGE; |
| 173 | |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 174 | name = argv[1]; |
| 175 | if (strlen(name) != ACPI_NAME_LEN) { |
| 176 | printf("Table name '%s' must be four characters\n", name); |
| 177 | return CMD_RET_FAILURE; |
| 178 | } |
Andrew Scull | 3189cd1 | 2022-04-03 10:39:09 +0000 | [diff] [blame] | 179 | str_to_upper(name, sig, ACPI_NAME_LEN); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 180 | ret = dump_table_name(sig); |
| 181 | if (ret) { |
| 182 | printf("Table '%.*s' not found\n", ACPI_NAME_LEN, sig); |
| 183 | return CMD_RET_FAILURE; |
| 184 | } |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 189 | U_BOOT_LONGHELP(acpi, |
Simon Glass | 2b94342 | 2023-07-15 21:38:45 -0600 | [diff] [blame] | 190 | "list - list ACPI tables\n" |
| 191 | "acpi items [-d] - List/dump each piece of ACPI data from devices\n" |
| 192 | "acpi set [<addr>] - Set or show address of ACPI tables\n" |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 193 | "acpi dump <name> - Dump ACPI table"); |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 194 | |
| 195 | U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text, |
| 196 | U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list), |
Simon Glass | 64bbc0d | 2020-07-07 13:12:12 -0600 | [diff] [blame] | 197 | U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items), |
Simon Glass | 2b94342 | 2023-07-15 21:38:45 -0600 | [diff] [blame] | 198 | U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set), |
Simon Glass | faf08c7 | 2020-04-26 09:19:53 -0600 | [diff] [blame] | 199 | U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump)); |