1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
9 #include <acpi/acpi_table.h>
10 #include <asm/acpi_table.h>
13 DECLARE_GLOBAL_DATA_PTR;
16 * dump_hdr() - Dump an ACPI header
18 * If the header is for FACS then it shows the revision information as well
20 * @hdr: ACPI header to dump
22 static void dump_hdr(struct acpi_table_header *hdr)
24 bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN);
26 printf("%.*s %08lx %06x", ACPI_NAME_LEN, hdr->signature,
27 (ulong)map_to_sysmem(hdr), hdr->length);
29 printf(" (v%02d %.6s %.8s %x %.4s %x)\n", hdr->revision,
30 hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
31 hdr->aslc_id, hdr->aslc_revision);
38 * find_table() - Look up an ACPI table
40 * @sig: Signature of table (4 characters, upper case)
41 * @return pointer to table header, or NULL if not found
43 struct acpi_table_header *find_table(const char *sig)
45 struct acpi_rsdp *rsdp;
46 struct acpi_rsdt *rsdt;
49 rsdp = map_sysmem(gd->arch.acpi_start, 0);
52 rsdt = map_sysmem(rsdp->rsdt_address, 0);
53 len = rsdt->header.length - sizeof(rsdt->header);
54 count = len / sizeof(u32);
55 for (i = 0; i < count; i++) {
56 struct acpi_table_header *hdr;
58 hdr = map_sysmem(rsdt->entry[i], 0);
59 if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN))
61 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) {
62 struct acpi_fadt *fadt = (struct acpi_fadt *)hdr;
64 if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt)
65 return map_sysmem(fadt->dsdt, 0);
66 if (!memcmp(sig, "FACS", ACPI_NAME_LEN) &&
68 return map_sysmem(fadt->firmware_ctrl, 0);
75 static int dump_table_name(const char *sig)
77 struct acpi_table_header *hdr;
79 hdr = find_table(sig);
82 printf("%.*s @ %08lx\n", ACPI_NAME_LEN, hdr->signature,
83 (ulong)map_to_sysmem(hdr));
84 print_buffer(0, hdr, 1, hdr->length, 0);
89 static void list_fadt(struct acpi_fadt *fadt)
92 dump_hdr(map_sysmem(fadt->dsdt, 0));
93 if (fadt->firmware_ctrl)
94 dump_hdr(map_sysmem(fadt->firmware_ctrl, 0));
97 static int list_rsdt(struct acpi_rsdt *rsdt, struct acpi_xsdt *xsdt)
101 dump_hdr(&rsdt->header);
103 dump_hdr(&xsdt->header);
104 len = rsdt->header.length - sizeof(rsdt->header);
105 count = len / sizeof(u32);
106 for (i = 0; i < count; i++) {
107 struct acpi_table_header *hdr;
111 hdr = map_sysmem(rsdt->entry[i], 0);
113 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
114 list_fadt((struct acpi_fadt *)hdr);
116 if (xsdt->entry[i] != rsdt->entry[i]) {
117 printf(" (xsdt mismatch %llx)\n",
126 static int list_rsdp(struct acpi_rsdp *rsdp)
128 struct acpi_rsdt *rsdt;
129 struct acpi_xsdt *xsdt;
131 printf("RSDP %08lx %06x (v%02d %.6s)\n", (ulong)map_to_sysmem(rsdp),
132 rsdp->length, rsdp->revision, rsdp->oem_id);
133 rsdt = map_sysmem(rsdp->rsdt_address, 0);
134 xsdt = map_sysmem(rsdp->xsdt_address, 0);
135 list_rsdt(rsdt, xsdt);
140 static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
143 struct acpi_rsdp *rsdp;
145 rsdp = map_sysmem(gd->arch.acpi_start, 0);
147 printf("No ACPI tables present\n");
150 printf("ACPI tables start at %lx\n", gd->arch.acpi_start);
156 static int do_acpi_items(struct cmd_tbl *cmdtp, int flag, int argc,
161 dump_contents = argc >= 2 && !strcmp("-d", argv[1]);
162 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
167 static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
171 char sig[ACPI_NAME_LEN];
175 if (strlen(name) != ACPI_NAME_LEN) {
176 printf("Table name '%s' must be four characters\n", name);
177 return CMD_RET_FAILURE;
179 str_to_upper(name, sig, -1);
180 ret = dump_table_name(sig);
182 printf("Table '%.*s' not found\n", ACPI_NAME_LEN, sig);
183 return CMD_RET_FAILURE;
189 static char acpi_help_text[] =
190 "list - list ACPI tables\n"
191 "acpi items [-d] - List/dump each piece of ACPI data from devices\n"
192 "acpi dump <name> - Dump ACPI table";
194 U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text,
195 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list),
196 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
197 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));