blob: 0c144092420eae705aa1f2fc932df6418215901c [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 */
6#include <common.h>
7#include <command.h>
Simon Glass1ab16922022-07-31 12:28:48 -06008#include <display_options.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>
Simon Glassfaf08c72020-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 Schuchardt27e9ebb2023-11-21 15:41:28 +010020 * Except for the Firmware ACPI Control Structure (FACS)
21 * additionally show the revision information.
Simon Glassfaf08c72020-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 Schuchardt27e9ebb2023-11-21 15:41:28 +010029 printf("%.*s %16lx %5x", ACPI_NAME_LEN, hdr->signature,
Simon Glassfaf08c72020-04-26 09:19:53 -060030 (ulong)map_to_sysmem(hdr), hdr->length);
31 if (has_hdr) {
Simon Glasseb025f32021-12-01 09:03:06 -070032 printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
Simon Glassfaf08c72020-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 Glassfaf08c72020-04-26 09:19:53 -060040static int dump_table_name(const char *sig)
41{
42 struct acpi_table_header *hdr;
43
Simon Glass7ae69762023-05-04 16:54:58 -060044 hdr = acpi_find_table(sig);
Simon Glassfaf08c72020-04-26 09:19:53 -060045 if (!hdr)
46 return -ENOENT;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010047 printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature,
Simon Glassfaf08c72020-04-26 09:19:53 -060048 (ulong)map_to_sysmem(hdr));
49 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)
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 Schuchardt27e9ebb2023-11-21 15:41:28 +010062static void list_rsdt(struct acpi_rsdp *rsdp)
Simon Glassfaf08c72020-04-26 09:19:53 -060063{
64 int len, i, count;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010065 struct acpi_rsdt *rsdt;
66 struct acpi_xsdt *xsdt;
Simon Glassfaf08c72020-04-26 09:19:53 -060067
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010068 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 Glassfaf08c72020-04-26 09:19:53 -060074 dump_hdr(&xsdt->header);
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010075 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 Glassfaf08c72020-04-26 09:19:53 -060084 for (i = 0; i < count; i++) {
85 struct acpi_table_header *hdr;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010086 u64 entry;
Simon Glassfaf08c72020-04-26 09:19:53 -060087
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010088 if (rsdp->xsdt_address)
89 entry = xsdt->entry[i];
90 else
91 entry = rsdt->entry[i];
92 if (!entry)
Simon Glassfaf08c72020-04-26 09:19:53 -060093 break;
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +010094 hdr = map_sysmem(entry, 0);
Simon Glassfaf08c72020-04-26 09:19:53 -060095 dump_hdr(hdr);
96 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
97 list_fadt((struct acpi_fadt *)hdr);
Simon Glassfaf08c72020-04-26 09:19:53 -060098 }
Simon Glassfaf08c72020-04-26 09:19:53 -060099}
100
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100101static void list_rsdp(struct acpi_rsdp *rsdp)
Simon Glassfaf08c72020-04-26 09:19:53 -0600102{
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100103 printf("RSDP %16lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
Simon Glassfaf08c72020-04-26 09:19:53 -0600104 rsdp->length, rsdp->revision, rsdp->oem_id);
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100105 list_rsdt(rsdp);
Simon Glassfaf08c72020-04-26 09:19:53 -0600106}
107
Simon Glassed38aef2020-05-10 11:40:03 -0600108static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassfaf08c72020-04-26 09:19:53 -0600109 char *const argv[])
110{
111 struct acpi_rsdp *rsdp;
112
Simon Glassb33f2f92021-12-01 09:02:37 -0700113 rsdp = map_sysmem(gd_acpi_start(), 0);
Simon Glassfaf08c72020-04-26 09:19:53 -0600114 if (!rsdp) {
115 printf("No ACPI tables present\n");
116 return 0;
117 }
Heinrich Schuchardt27e9ebb2023-11-21 15:41:28 +0100118 printf("Name Base Size Detail\n"
119 "---- ---------------- ----- ----------------------------\n");
Simon Glassfaf08c72020-04-26 09:19:53 -0600120 list_rsdp(rsdp);
121
122 return 0;
123}
124
Simon Glass2b943422023-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 Glass64bbc0d2020-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 Glasse264be42023-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 Glass64bbc0d2020-07-07 13:12:12 -0600151 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
152
153 return 0;
154}
155
Simon Glassed38aef2020-05-10 11:40:03 -0600156static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassfaf08c72020-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 Schuchardt28a54ae2023-12-09 18:05:36 +0100163 if (argc < 2)
164 return CMD_RET_USAGE;
165
Simon Glassfaf08c72020-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 Scull3189cd12022-04-03 10:39:09 +0000171 str_to_upper(name, sig, ACPI_NAME_LEN);
Simon Glassfaf08c72020-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 Rini03f146c2023-10-07 15:13:08 -0400181U_BOOT_LONGHELP(acpi,
Simon Glass2b943422023-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 Rini03f146c2023-10-07 15:13:08 -0400185 "acpi dump <name> - Dump ACPI table");
Simon Glassfaf08c72020-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 Glass64bbc0d2020-07-07 13:12:12 -0600189 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
Simon Glass2b943422023-07-15 21:38:45 -0600190 U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set),
Simon Glassfaf08c72020-04-26 09:19:53 -0600191 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));