1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
8 #include <display_options.h>
10 #include <acpi/acpi_table.h>
11 #include <asm/acpi_table.h>
12 #include <asm/global_data.h>
15 DECLARE_GLOBAL_DATA_PTR;
18 * dump_hdr() - Dump an ACPI header
20 * If the header is for FACS then it shows the revision information as well
22 * @hdr: ACPI header to dump
24 static void dump_hdr(struct acpi_table_header *hdr)
26 bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN);
28 printf("%.*s %08lx %5x", ACPI_NAME_LEN, hdr->signature,
29 (ulong)map_to_sysmem(hdr), hdr->length);
31 printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
32 hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
33 hdr->aslc_id, hdr->aslc_revision);
40 * find_table() - Look up an ACPI table
42 * @sig: Signature of table (4 characters, upper case)
43 * Return: pointer to table header, or NULL if not found
45 struct acpi_table_header *find_table(const char *sig)
47 struct acpi_rsdp *rsdp;
48 struct acpi_rsdt *rsdt;
51 rsdp = map_sysmem(gd_acpi_start(), 0);
54 rsdt = map_sysmem(rsdp->rsdt_address, 0);
55 len = rsdt->header.length - sizeof(rsdt->header);
56 count = len / sizeof(u32);
57 for (i = 0; i < count; i++) {
58 struct acpi_table_header *hdr;
60 hdr = map_sysmem(rsdt->entry[i], 0);
61 if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN))
63 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) {
64 struct acpi_fadt *fadt = (struct acpi_fadt *)hdr;
66 if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt)
67 return map_sysmem(fadt->dsdt, 0);
68 if (!memcmp(sig, "FACS", ACPI_NAME_LEN) &&
70 return map_sysmem(fadt->firmware_ctrl, 0);
77 static int dump_table_name(const char *sig)
79 struct acpi_table_header *hdr;
81 hdr = find_table(sig);
84 printf("%.*s @ %08lx\n", ACPI_NAME_LEN, hdr->signature,
85 (ulong)map_to_sysmem(hdr));
86 print_buffer(0, hdr, 1, hdr->length, 0);
91 static void list_fadt(struct acpi_fadt *fadt)
94 dump_hdr(map_sysmem(fadt->dsdt, 0));
95 if (fadt->firmware_ctrl)
96 dump_hdr(map_sysmem(fadt->firmware_ctrl, 0));
99 static int list_rsdt(struct acpi_rsdt *rsdt, struct acpi_xsdt *xsdt)
103 dump_hdr(&rsdt->header);
105 dump_hdr(&xsdt->header);
106 len = rsdt->header.length - sizeof(rsdt->header);
107 count = len / sizeof(u32);
108 for (i = 0; i < count; i++) {
109 struct acpi_table_header *hdr;
113 hdr = map_sysmem(rsdt->entry[i], 0);
115 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
116 list_fadt((struct acpi_fadt *)hdr);
118 if (xsdt->entry[i] != rsdt->entry[i]) {
119 printf(" (xsdt mismatch %llx)\n",
128 static int list_rsdp(struct acpi_rsdp *rsdp)
130 struct acpi_rsdt *rsdt;
131 struct acpi_xsdt *xsdt;
133 printf("RSDP %08lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
134 rsdp->length, rsdp->revision, rsdp->oem_id);
135 rsdt = map_sysmem(rsdp->rsdt_address, 0);
136 xsdt = map_sysmem(rsdp->xsdt_address, 0);
137 list_rsdt(rsdt, xsdt);
142 static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
145 struct acpi_rsdp *rsdp;
147 rsdp = map_sysmem(gd_acpi_start(), 0);
149 printf("No ACPI tables present\n");
152 printf("Name Base Size Detail\n");
153 printf("---- -------- ----- ------\n");
159 static int do_acpi_items(struct cmd_tbl *cmdtp, int flag, int argc,
164 dump_contents = argc >= 2 && !strcmp("-d", argv[1]);
165 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
170 static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
174 char sig[ACPI_NAME_LEN];
178 if (strlen(name) != ACPI_NAME_LEN) {
179 printf("Table name '%s' must be four characters\n", name);
180 return CMD_RET_FAILURE;
182 str_to_upper(name, sig, ACPI_NAME_LEN);
183 ret = dump_table_name(sig);
185 printf("Table '%.*s' not found\n", ACPI_NAME_LEN, sig);
186 return CMD_RET_FAILURE;
192 #ifdef CONFIG_SYS_LONGHELP
193 static char acpi_help_text[] =
194 "list - list ACPI tables\n"
195 "acpi items [-d] - List/dump each piece of ACPI data from devices\n"
196 "acpi dump <name> - Dump ACPI table";
199 U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text,
200 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list),
201 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
202 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));