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