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