blob: 79e9335b5db8eadb041670902d8f0c69c7891de5 [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 */
6#include <common.h>
7#include <command.h>
Simon Glass4e4bf942022-07-31 12:28:48 -06008#include <display_options.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>
Simon Glass0b885bc2020-04-26 09:19:53 -060013#include <dm/acpi.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17/**
18 * dump_hdr() - Dump an ACPI header
19 *
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010020 * Except for the Firmware ACPI Control Structure (FACS)
21 * additionally show the revision information.
Simon Glass0b885bc2020-04-26 09:19:53 -060022 *
23 * @hdr: ACPI header to dump
24 */
25static void dump_hdr(struct acpi_table_header *hdr)
26{
27 bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN);
28
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010029 printf("%.*s %16lx %5x", ACPI_NAME_LEN, hdr->signature,
Simon Glass0b885bc2020-04-26 09:19:53 -060030 (ulong)map_to_sysmem(hdr), hdr->length);
31 if (has_hdr) {
Simon Glass06f6f3d2021-12-01 09:03:06 -070032 printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
Simon Glass0b885bc2020-04-26 09:19:53 -060033 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 Glass0b885bc2020-04-26 09:19:53 -060040static int dump_table_name(const char *sig)
41{
42 struct acpi_table_header *hdr;
43
Simon Glass37bf4402023-05-04 16:54:58 -060044 hdr = acpi_find_table(sig);
Simon Glass0b885bc2020-04-26 09:19:53 -060045 if (!hdr)
46 return -ENOENT;
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010047 printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature,
Simon Glassa8efebe2023-12-31 08:25:54 -070048 (ulong)nomap_to_sysmem(hdr));
Simon Glass0b885bc2020-04-26 09:19:53 -060049 print_buffer(0, hdr, 1, hdr->length, 0);
50
51 return 0;
52}
53
54static void list_fadt(struct acpi_fadt *fadt)
55{
56 if (fadt->dsdt)
Simon Glassa8efebe2023-12-31 08:25:54 -070057 dump_hdr(nomap_sysmem(fadt->dsdt, 0));
Simon Glass0b885bc2020-04-26 09:19:53 -060058 if (fadt->firmware_ctrl)
Simon Glassa8efebe2023-12-31 08:25:54 -070059 dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0));
Simon Glass0b885bc2020-04-26 09:19:53 -060060}
61
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010062static void list_rsdt(struct acpi_rsdp *rsdp)
Simon Glass0b885bc2020-04-26 09:19:53 -060063{
64 int len, i, count;
Simon Glass0b885bc2020-04-26 09:19:53 -060065 struct acpi_rsdt *rsdt;
66 struct acpi_xsdt *xsdt;
67
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010068 if (rsdp->rsdt_address) {
Simon Glassa8efebe2023-12-31 08:25:54 -070069 rsdt = nomap_sysmem(rsdp->rsdt_address, 0);
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010070 dump_hdr(&rsdt->header);
71 }
72 if (rsdp->xsdt_address) {
Simon Glassa8efebe2023-12-31 08:25:54 -070073 xsdt = nomap_sysmem(rsdp->xsdt_address, 0);
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010074 dump_hdr(&xsdt->header);
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 }
Simon Glass0b885bc2020-04-26 09:19:53 -060083
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010084 for (i = 0; i < count; i++) {
85 struct acpi_table_header *hdr;
86 u64 entry;
87
88 if (rsdp->xsdt_address)
89 entry = xsdt->entry[i];
90 else
91 entry = rsdt->entry[i];
92 if (!entry)
93 break;
Simon Glassa8efebe2023-12-31 08:25:54 -070094 hdr = nomap_sysmem(entry, 0);
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +010095 dump_hdr(hdr);
96 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
97 list_fadt((struct acpi_fadt *)hdr);
98 }
99}
100
101static void list_rsdp(struct acpi_rsdp *rsdp)
102{
103 printf("RSDP %16lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
104 rsdp->length, rsdp->revision, rsdp->oem_id);
105 list_rsdt(rsdp);
Simon Glass0b885bc2020-04-26 09:19:53 -0600106}
107
Simon Glass09140112020-05-10 11:40:03 -0600108static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass0b885bc2020-04-26 09:19:53 -0600109 char *const argv[])
110{
111 struct acpi_rsdp *rsdp;
112
Simon Glass233f0e32021-12-01 09:02:37 -0700113 rsdp = map_sysmem(gd_acpi_start(), 0);
Simon Glass0b885bc2020-04-26 09:19:53 -0600114 if (!rsdp) {
115 printf("No ACPI tables present\n");
116 return 0;
117 }
Heinrich Schuchardt36e3a1e2023-11-21 15:41:28 +0100118 printf("Name Base Size Detail\n"
119 "---- ---------------- ----- ----------------------------\n");
Simon Glass0b885bc2020-04-26 09:19:53 -0600120 list_rsdp(rsdp);
121
122 return 0;
123}
124
Simon Glass29718412023-07-15 21:38:45 -0600125static 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 Glassa4f82082020-07-07 13:12:12 -0600141static 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 Glass0992a902023-05-04 16:54:57 -0600147 if (!IS_ENABLED(CONFIG_ACPIGEN)) {
148 printf("Not supported (enable ACPIGEN)\n");
149 return CMD_RET_FAILURE;
150 }
Simon Glassa4f82082020-07-07 13:12:12 -0600151 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
152
153 return 0;
154}
155
Simon Glass09140112020-05-10 11:40:03 -0600156static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass0b885bc2020-04-26 09:19:53 -0600157 char *const argv[])
158{
159 const char *name;
160 char sig[ACPI_NAME_LEN];
161 int ret;
162
Heinrich Schuchardtaafbe1d2023-12-09 18:05:36 +0100163 if (argc < 2)
164 return CMD_RET_USAGE;
165
Simon Glass0b885bc2020-04-26 09:19:53 -0600166 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 Scull3849ca72022-04-03 10:39:09 +0000171 str_to_upper(name, sig, ACPI_NAME_LEN);
Simon Glass0b885bc2020-04-26 09:19:53 -0600172 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 Rini36162182023-10-07 15:13:08 -0400181U_BOOT_LONGHELP(acpi,
Simon Glass29718412023-07-15 21:38:45 -0600182 "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 Rini36162182023-10-07 15:13:08 -0400185 "acpi dump <name> - Dump ACPI table");
Simon Glass0b885bc2020-04-26 09:19:53 -0600186
187U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text,
188 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list),
Simon Glassa4f82082020-07-07 13:12:12 -0600189 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
Simon Glass29718412023-07-15 21:38:45 -0600190 U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set),
Simon Glass0b885bc2020-04-26 09:19:53 -0600191 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));