blob: 094d9d4e85865ec30e4db6ba95e0b39abce4669d [file] [log] [blame]
Simon Glassfaf08c72020-04-26 09:19:53 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
Simon Glassfaf08c72020-04-26 09:19:53 -06006#include <command.h>
Simon Glass1ab16922022-07-31 12:28:48 -06007#include <display_options.h>
Heinrich Schuchardt910590d2023-12-16 09:11:59 +01008#include <log.h>
Simon Glassfaf08c72020-04-26 09:19:53 -06009#include <mapmem.h>
10#include <acpi/acpi_table.h>
11#include <asm/acpi_table.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Tom Rini5c1444f2024-04-27 08:10:59 -060013#include <linux/errno.h>
Simon Glassfaf08c72020-04-26 09:19:53 -060014#include <dm/acpi.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/**
19 * dump_hdr() - Dump an ACPI header
20 *
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010021 * Except for the Firmware ACPI Control Structure (FACS)
22 * additionally show the revision information.
Simon Glassfaf08c72020-04-26 09:19:53 -060023 *
24 * @hdr: ACPI header to dump
25 */
26static void dump_hdr(struct acpi_table_header *hdr)
27{
28 bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN);
29
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010030 printf("%.*s %16lx %5x", ACPI_NAME_LEN, hdr->signature,
Simon Glassfaf08c72020-04-26 09:19:53 -060031 (ulong)map_to_sysmem(hdr), hdr->length);
32 if (has_hdr) {
Simon Glasseb025f32021-12-01 09:03:06 -070033 printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
Simon Glassfaf08c72020-04-26 09:19:53 -060034 hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
Heinrich Schuchardt10de8a82024-01-21 12:52:48 +010035 hdr->creator_id, hdr->creator_revision);
Simon Glassfaf08c72020-04-26 09:19:53 -060036 } else {
37 printf("\n");
38 }
39}
40
Simon Glassfaf08c72020-04-26 09:19:53 -060041static int dump_table_name(const char *sig)
42{
43 struct acpi_table_header *hdr;
44
Simon Glass7ae69762023-05-04 16:54:58 -060045 hdr = acpi_find_table(sig);
Simon Glassfaf08c72020-04-26 09:19:53 -060046 if (!hdr)
47 return -ENOENT;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010048 printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature,
Simon Glass919f8352023-12-31 08:25:54 -070049 (ulong)nomap_to_sysmem(hdr));
Simon Glassfaf08c72020-04-26 09:19:53 -060050 print_buffer(0, hdr, 1, hdr->length, 0);
51
52 return 0;
53}
54
55static void list_fadt(struct acpi_fadt *fadt)
56{
Heinrich Schuchardt9f8e0622023-12-16 09:11:58 +010057 if (fadt->header.revision >= 3 && fadt->x_dsdt)
58 dump_hdr(nomap_sysmem(fadt->x_dsdt, 0));
59 else if (fadt->dsdt)
Simon Glass919f8352023-12-31 08:25:54 -070060 dump_hdr(nomap_sysmem(fadt->dsdt, 0));
Heinrich Schuchardt910590d2023-12-16 09:11:59 +010061 if (!IS_ENABLED(CONFIG_X86) &&
62 !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI))
63 log_err("FADT not ACPI-hardware-reduced-compliant\n");
Heinrich Schuchardt9f8e0622023-12-16 09:11:58 +010064 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 Glass919f8352023-12-31 08:25:54 -070067 dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0));
Simon Glassfaf08c72020-04-26 09:19:53 -060068}
69
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010070static void list_rsdt(struct acpi_rsdp *rsdp)
Simon Glassfaf08c72020-04-26 09:19:53 -060071{
72 int len, i, count;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010073 struct acpi_rsdt *rsdt;
74 struct acpi_xsdt *xsdt;
Simon Glassfaf08c72020-04-26 09:19:53 -060075
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010076 if (rsdp->rsdt_address) {
Simon Glass919f8352023-12-31 08:25:54 -070077 rsdt = nomap_sysmem(rsdp->rsdt_address, 0);
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010078 dump_hdr(&rsdt->header);
79 }
80 if (rsdp->xsdt_address) {
Simon Glass919f8352023-12-31 08:25:54 -070081 xsdt = nomap_sysmem(rsdp->xsdt_address, 0);
Simon Glassfaf08c72020-04-26 09:19:53 -060082 dump_hdr(&xsdt->header);
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010083 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 Glassfaf08c72020-04-26 09:19:53 -060092 for (i = 0; i < count; i++) {
93 struct acpi_table_header *hdr;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010094 u64 entry;
Simon Glassfaf08c72020-04-26 09:19:53 -060095
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010096 if (rsdp->xsdt_address)
97 entry = xsdt->entry[i];
98 else
99 entry = rsdt->entry[i];
100 if (!entry)
Simon Glassfaf08c72020-04-26 09:19:53 -0600101 break;
Simon Glass919f8352023-12-31 08:25:54 -0700102 hdr = nomap_sysmem(entry, 0);
Simon Glassfaf08c72020-04-26 09:19:53 -0600103 dump_hdr(hdr);
104 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
105 list_fadt((struct acpi_fadt *)hdr);
Simon Glassfaf08c72020-04-26 09:19:53 -0600106 }
Simon Glassfaf08c72020-04-26 09:19:53 -0600107}
108
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100109static void list_rsdp(struct acpi_rsdp *rsdp)
Simon Glassfaf08c72020-04-26 09:19:53 -0600110{
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100111 printf("RSDP %16lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
Simon Glassfaf08c72020-04-26 09:19:53 -0600112 rsdp->length, rsdp->revision, rsdp->oem_id);
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100113 list_rsdt(rsdp);
Simon Glassfaf08c72020-04-26 09:19:53 -0600114}
115
Simon Glassed38aef2020-05-10 11:40:03 -0600116static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassfaf08c72020-04-26 09:19:53 -0600117 char *const argv[])
118{
119 struct acpi_rsdp *rsdp;
120
Simon Glassb33f2f92021-12-01 09:02:37 -0700121 rsdp = map_sysmem(gd_acpi_start(), 0);
Simon Glassfaf08c72020-04-26 09:19:53 -0600122 if (!rsdp) {
123 printf("No ACPI tables present\n");
124 return 0;
125 }
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100126 printf("Name Base Size Detail\n"
127 "---- ---------------- ----- ----------------------------\n");
Simon Glassfaf08c72020-04-26 09:19:53 -0600128 list_rsdp(rsdp);
129
130 return 0;
131}
132
Simon Glass2b943422023-07-15 21:38:45 -0600133static 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 Glass64bbc0d2020-07-07 13:12:12 -0600149static 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 Glasse264be42023-05-04 16:54:57 -0600155 if (!IS_ENABLED(CONFIG_ACPIGEN)) {
156 printf("Not supported (enable ACPIGEN)\n");
157 return CMD_RET_FAILURE;
158 }
Simon Glass64bbc0d2020-07-07 13:12:12 -0600159 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
160
161 return 0;
162}
163
Simon Glassed38aef2020-05-10 11:40:03 -0600164static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassfaf08c72020-04-26 09:19:53 -0600165 char *const argv[])
166{
167 const char *name;
168 char sig[ACPI_NAME_LEN];
169 int ret;
170
Heinrich Schuchardt28a54ae2023-12-09 18:05:36 +0100171 if (argc < 2)
172 return CMD_RET_USAGE;
173
Simon Glassfaf08c72020-04-26 09:19:53 -0600174 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 Scull3189cd12022-04-03 10:39:09 +0000179 str_to_upper(name, sig, ACPI_NAME_LEN);
Simon Glassfaf08c72020-04-26 09:19:53 -0600180 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 Rini03f146c2023-10-07 15:13:08 -0400189U_BOOT_LONGHELP(acpi,
Simon Glass2b943422023-07-15 21:38:45 -0600190 "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 Rini03f146c2023-10-07 15:13:08 -0400193 "acpi dump <name> - Dump ACPI table");
Simon Glassfaf08c72020-04-26 09:19:53 -0600194
195U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text,
196 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list),
Simon Glass64bbc0d2020-07-07 13:12:12 -0600197 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
Simon Glass2b943422023-07-15 21:38:45 -0600198 U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set),
Simon Glassfaf08c72020-04-26 09:19:53 -0600199 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));