]> Git Repo - u-boot.git/blame - cmd/acpi.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[u-boot.git] / cmd / acpi.c
CommitLineData
0b885bcf
SG
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Google LLC
4 * Written by Simon Glass <[email protected]>
5 */
d678a59d 6#include <common.h>
0b885bcf 7#include <command.h>
4e4bf944 8#include <display_options.h>
c95ade8d 9#include <log.h>
0b885bcf
SG
10#include <mapmem.h>
11#include <acpi/acpi_table.h>
12#include <asm/acpi_table.h>
401d1c4f 13#include <asm/global_data.h>
0b885bcf
SG
14#include <dm/acpi.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/**
19 * dump_hdr() - Dump an ACPI header
20 *
36e3a1e9
HS
21 * Except for the Firmware ACPI Control Structure (FACS)
22 * additionally show the revision information.
0b885bcf
SG
23 *
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
36e3a1e9 30 printf("%.*s %16lx %5x", ACPI_NAME_LEN, hdr->signature,
0b885bcf
SG
31 (ulong)map_to_sysmem(hdr), hdr->length);
32 if (has_hdr) {
06f6f3d4 33 printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision,
0b885bcf 34 hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
4735d03a 35 hdr->creator_id, hdr->creator_revision);
0b885bcf
SG
36 } else {
37 printf("\n");
38 }
39}
40
0b885bcf
SG
41static int dump_table_name(const char *sig)
42{
43 struct acpi_table_header *hdr;
44
37bf4407 45 hdr = acpi_find_table(sig);
0b885bcf
SG
46 if (!hdr)
47 return -ENOENT;
36e3a1e9 48 printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature,
a8efebe7 49 (ulong)nomap_to_sysmem(hdr));
0b885bcf
SG
50 print_buffer(0, hdr, 1, hdr->length, 0);
51
52 return 0;
53}
54
55static void list_fadt(struct acpi_fadt *fadt)
56{
c5924b1c
HS
57 if (fadt->header.revision >= 3 && fadt->x_dsdt)
58 dump_hdr(nomap_sysmem(fadt->x_dsdt, 0));
59 else if (fadt->dsdt)
a8efebe7 60 dump_hdr(nomap_sysmem(fadt->dsdt, 0));
c95ade8d
HS
61 if (!IS_ENABLED(CONFIG_X86) &&
62 !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI))
63 log_err("FADT not ACPI-hardware-reduced-compliant\n");
c5924b1c
HS
64 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)
a8efebe7 67 dump_hdr(nomap_sysmem(fadt->firmware_ctrl, 0));
0b885bcf
SG
68}
69
36e3a1e9 70static void list_rsdt(struct acpi_rsdp *rsdp)
0b885bcf
SG
71{
72 int len, i, count;
36e3a1e9
HS
73 struct acpi_rsdt *rsdt;
74 struct acpi_xsdt *xsdt;
0b885bcf 75
36e3a1e9 76 if (rsdp->rsdt_address) {
a8efebe7 77 rsdt = nomap_sysmem(rsdp->rsdt_address, 0);
36e3a1e9
HS
78 dump_hdr(&rsdt->header);
79 }
80 if (rsdp->xsdt_address) {
a8efebe7 81 xsdt = nomap_sysmem(rsdp->xsdt_address, 0);
0b885bcf 82 dump_hdr(&xsdt->header);
36e3a1e9
HS
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 }
91
0b885bcf
SG
92 for (i = 0; i < count; i++) {
93 struct acpi_table_header *hdr;
36e3a1e9 94 u64 entry;
0b885bcf 95
36e3a1e9
HS
96 if (rsdp->xsdt_address)
97 entry = xsdt->entry[i];
98 else
99 entry = rsdt->entry[i];
100 if (!entry)
0b885bcf 101 break;
a8efebe7 102 hdr = nomap_sysmem(entry, 0);
0b885bcf
SG
103 dump_hdr(hdr);
104 if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN))
105 list_fadt((struct acpi_fadt *)hdr);
0b885bcf 106 }
0b885bcf
SG
107}
108
36e3a1e9 109static void list_rsdp(struct acpi_rsdp *rsdp)
0b885bcf 110{
36e3a1e9 111 printf("RSDP %16lx %5x v%02d %.6s\n", (ulong)map_to_sysmem(rsdp),
0b885bcf 112 rsdp->length, rsdp->revision, rsdp->oem_id);
36e3a1e9 113 list_rsdt(rsdp);
0b885bcf
SG
114}
115
09140113 116static int do_acpi_list(struct cmd_tbl *cmdtp, int flag, int argc,
0b885bcf
SG
117 char *const argv[])
118{
119 struct acpi_rsdp *rsdp;
120
233f0e35 121 rsdp = map_sysmem(gd_acpi_start(), 0);
0b885bcf
SG
122 if (!rsdp) {
123 printf("No ACPI tables present\n");
124 return 0;
125 }
36e3a1e9
HS
126 printf("Name Base Size Detail\n"
127 "---- ---------------- ----- ----------------------------\n");
0b885bcf
SG
128 list_rsdp(rsdp);
129
130 return 0;
131}
132
29718414
SG
133static 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
a4f82089
SG
149static 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]);
0992a90d
SG
155 if (!IS_ENABLED(CONFIG_ACPIGEN)) {
156 printf("Not supported (enable ACPIGEN)\n");
157 return CMD_RET_FAILURE;
158 }
a4f82089
SG
159 acpi_dump_items(dump_contents ? ACPI_DUMP_CONTENTS : ACPI_DUMP_LIST);
160
161 return 0;
162}
163
09140113 164static int do_acpi_dump(struct cmd_tbl *cmdtp, int flag, int argc,
0b885bcf
SG
165 char *const argv[])
166{
167 const char *name;
168 char sig[ACPI_NAME_LEN];
169 int ret;
170
aafbe1da
HS
171 if (argc < 2)
172 return CMD_RET_USAGE;
173
0b885bcf
SG
174 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 }
3849ca7b 179 str_to_upper(name, sig, ACPI_NAME_LEN);
0b885bcf
SG
180 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
3616218b 189U_BOOT_LONGHELP(acpi,
29718414
SG
190 "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"
3616218b 193 "acpi dump <name> - Dump ACPI table");
0b885bcf
SG
194
195U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text,
196 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list),
a4f82089 197 U_BOOT_SUBCMD_MKENT(items, 2, 1, do_acpi_items),
29718414 198 U_BOOT_SUBCMD_MKENT(set, 2, 1, do_acpi_set),
0b885bcf 199 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump));
This page took 0.142912 seconds and 4 git commands to generate.