blob: 094d9d4e85865ec30e4db6ba95e0b39abce4669d [file] [log] [blame]
Simon Glass0b885bc2020-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 Glass0b885bc2020-04-26 09:19:53 -06006#include <command.h>
Simon Glass4e4bf942022-07-31 12:28:48 -06007#include <display_options.h>
Heinrich Schuchardtc95ade82023-12-16 09:11:59 +01008#include <log.h>
Simon Glass0b885bc2020-04-26 09:19:53 -06009#include <mapmem.h>
10#include <acpi/acpi_table.h>
11#include <asm/acpi_table.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Tom Rini03de3052024-05-20 13:35:03 -060013#include <linux/errno.h>
Simon Glass0b885bc2020-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 Schuchardt36e3a1e2023-11-21 15:41:28 +010021 * Except for the Firmware ACPI Control Structure (FACS)
22 * additionally show the revision information.
Simon Glass0b885bc2020-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 Schuchardt36e3a1e2023-11-21 15:41:28 +010030 printf("%.*s %16lx %5x", ACPI_NAME_LEN, hdr->signature,
Simon Glass0b885bc2020-04-26 09:19:53 -060031 (ulong)map_to_sysmem(hdr), hdr->length);
32 if (has_hdr) {
Simon Glass06f6f3d2021-12-01 09:03:06 -070033 printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
Simon Glass0b885bc2020-04-26 09:19:53 -060034 hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
Heinrich Schuchardt4735d032024-01-21 12:52:48 +010035 hdr->creator_id, hdr->creator_revision);
Simon Glass0b885bc2020-04-26 09:19:53 -060036 } else {
37 printf("\n");
38 }
39}
40
Simon Glass0b885bc2020-04-26 09:19:53 -060041static int dump_table_name(const char *sig)
42{
43 struct acpi_table_header *hdr;
44
Simon Glass37bf4402023-05-04 16:54:58 -060045 hdr = acpi_find_table(sig);
Simon Glass0b885bc2020-04-26 09:19:53 -060046 if (!hdr)
47 return -ENOENT;
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010048 printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature,
Simon Glassa8efebe2023-12-31 08:25:54 -070049 (ulong)nomap_to_sysmem(hdr));
Simon Glass0b885bc2020-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 Schuchardtc5924b12023-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 Glassa8efebe2023-12-31 08:25:54 -070060 dump_hdr(nomap_sysmem(fadt->dsdt, 0));
Heinrich Schuchardtc95ade82023-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 Schuchardtc5924b12023-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 Glassa8efebe2023-12-31 08:25:54 -070067 dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0));
Simon Glass0b885bc2020-04-26 09:19:53 -060068}
69
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010070static void list_rsdt(struct acpi_rsdp *rsdp)
Simon Glass0b885bc2020-04-26 09:19:53 -060071{
72 int len, i, count;
Simon Glass0b885bc2020-04-26 09:19:53 -060073 struct acpi_rsdt *rsdt;
74 struct acpi_xsdt *xsdt;
75
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010076 if (rsdp->rsdt_address) {
Simon Glassa8efebe2023-12-31 08:25:54 -070077 rsdt = nomap_sysmem(rsdp->rsdt_address, 0);
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010078 dump_hdr(&rsdt->header);
79 }
80 if (rsdp->xsdt_address) {
Simon Glassa8efebe2023-12-31 08:25:54 -070081 xsdt = nomap_sysmem(rsdp->xsdt_address, 0);
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010082 dump_hdr(&xsdt->header);
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 }
Simon Glass0b885bc2020-04-26 09:19:53 -060091
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010092 for (i = 0; i < count; i++) {
93 struct acpi_table_header *hdr;
94 u64 entry;
95
96 if (rsdp->xsdt_address)
97 entry = xsdt->entry[i];
98 else
99 entry = rsdt->entry[i];
100 if (!entry)
101 break;
Simon Glassa8efebe2023-12-31 08:25:54 -0700102 hdr = nomap_sysmem(entry, 0);
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +0100103 dump_hdr(hdr);
104 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
105 list_fadt((struct acpi_fadt *)hdr);
106 }
107}
108
109static void list_rsdp(struct acpi_rsdp *rsdp)
110{
111 printf("RSDP %16lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
112 rsdp->length, rsdp->revision, rsdp->oem_id);
113 list_rsdt(rsdp);
Simon Glass0b885bc2020-04-26 09:19:53 -0600114}
115
Simon Glass09140112020-05-10 11:40:03 -0600116static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass0b885bc2020-04-26 09:19:53 -0600117 char *const argv[])
118{
119 struct acpi_rsdp *rsdp;
120
Simon Glass233f0e32021-12-01 09:02:37 -0700121 rsdp = map_sysmem(gd_acpi_start(), 0);
Simon Glass0b885bc2020-04-26 09:19:53 -0600122 if (!rsdp) {
123 printf("No ACPI tables present\n");
124 return 0;
125 }
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +0100126 printf("Name Base Size Detail\n"
127 "---- ---------------- ----- ----------------------------\n");
Simon Glass0b885bc2020-04-26 09:19:53 -0600128 list_rsdp(rsdp);
129
130 return 0;
131}
132
Simon Glass29718412023-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 Glassa4f82082020-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 Glass0992a902023-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 Glassa4f82082020-07-07 13:12:12 -0600159 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
160
161 return 0;
162}
163
Simon Glass09140112020-05-10 11:40:03 -0600164static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass0b885bc2020-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 Schuchardtaafbe1d2023-12-09 18:05:36 +0100171 if (argc < 2)
172 return CMD_RET_USAGE;
173
Simon Glass0b885bc2020-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 Scull3849ca72022-04-03 10:39:09 +0000179 str_to_upper(name, sig, ACPI_NAME_LEN);
Simon Glass0b885bc2020-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 Rini36162182023-10-07 15:13:08 -0400189U_BOOT_LONGHELP(acpi,
Simon Glass29718412023-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 Rini36162182023-10-07 15:13:08 -0400193 "acpi dump <name> - Dump ACPI table");
Simon Glass0b885bc2020-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 Glassa4f82082020-07-07 13:12:12 -0600197 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
Simon Glass29718412023-07-15 21:38:45 -0600198 U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set),
Simon Glass0b885bc2020-04-26 09:19:53 -0600199 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));