Re: [PATCH v3 29/29] acpi: Add an acpi command
On Tue, Mar 31, 2020 at 07:14:18PM +0100, Leif Lindholm wrote: > On Mon, Mar 30, 2020 at 17:13:05 -0600, Simon Glass wrote: > > +static void list_fact(struct acpi_fadt *fadt) > > Hmm, should this function be called list_facp or list_fadt? > (The wonder that is the table called FADT with the marker FACP.) Spec refers to some historical reasons. -- With Best Regards, Andy Shevchenko
Re: [PATCH v3 29/29] acpi: Add an acpi command
On Mon, Mar 30, 2020 at 05:13:05PM -0600, Simon Glass wrote: > It is useful to dump ACPI tables in U-Boot to see what has been generated. > Add a command to handle this. > > To allow the command to find the tables, add a position into the global > data. > > Support subcommands to list and dump the tables. ... > +static void dump_hdr(struct acpi_table_header *hdr) > +{ > + bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN); I believe more than one table has the same header structure. Either this function is incorrectly called (should be dump_facs_hdr() or alike), or you need to make it better, i.e. generic. > + printf("%.*s %08lx %06x", ACPI_NAME_LEN, hdr->signature, > +(ulong)map_to_sysmem(hdr), hdr->length); > + if (has_hdr) { > + printf(" (v%02d %.6s %.8s %u %.4s %d)\n", hdr->revision, > +hdr->oem_id, hdr->oem_table_id, hdr->oem_revision, > +hdr->aslc_id, hdr->aslc_revision); > + } else { > + printf("\n"); > + } > +} -- With Best Regards, Andy Shevchenko
Re: [PATCH v3 29/29] acpi: Add an acpi command
On Mon, Mar 30, 2020 at 17:13:05 -0600, Simon Glass wrote: > It is useful to dump ACPI tables in U-Boot to see what has been generated. > Add a command to handle this. > > To allow the command to find the tables, add a position into the global > data. > > Support subcommands to list and dump the tables. > > Signed-off-by: Simon Glass > Reviewed-by: Wolfgang Wallner > --- > > Changes in v3: None > Changes in v2: None > > arch/sandbox/include/asm/global_data.h | 1 + > arch/x86/include/asm/global_data.h | 1 + > cmd/Kconfig| 14 ++ > cmd/Makefile | 1 + > cmd/acpi.c | 179 + > lib/acpi/acpi_table.c | 1 + > test/dm/acpi.c | 73 ++ > 7 files changed, 270 insertions(+) > create mode 100644 cmd/acpi.c > > diff --git a/arch/sandbox/include/asm/global_data.h > b/arch/sandbox/include/asm/global_data.h > index f4ce72d5660..f95ddb058a2 100644 > --- a/arch/sandbox/include/asm/global_data.h > +++ b/arch/sandbox/include/asm/global_data.h > @@ -13,6 +13,7 @@ > struct arch_global_data { > uint8_t *ram_buf; /* emulated RAM buffer */ > void*text_base; /* pointer to base of text region */ > + ulong acpi_start; /* Start address of ACPI tables */ > }; > > #include > diff --git a/arch/x86/include/asm/global_data.h > b/arch/x86/include/asm/global_data.h > index f4c1839104e..4aee2f3e8c4 100644 > --- a/arch/x86/include/asm/global_data.h > +++ b/arch/x86/include/asm/global_data.h > @@ -123,6 +123,7 @@ struct arch_global_data { > #ifdef CONFIG_FSP_VERSION2 > struct fsp_header *fsp_s_hdr; /* Pointer to FSP-S header */ > #endif > + ulong acpi_start; /* Start address of ACPI tables */ > }; > > #endif > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 6403bc45a5e..2d3bfe0ab91 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -190,6 +190,20 @@ comment "Commands" > > menu "Info commands" > > +config CMD_ACPI > + bool "acpi" > + default y if ACPIGEN > + help > + List and dump ACPI tables. ACPI (Advanced Configuration and Power > + Interface) is used mostly on x86 for providing information to the > + Operating System about devices in the system. The tables are set up > + by the firmware, typically U-Boot but possibly an earlier firmware > + module, if U-Boot is chain-loaded from something else. ACPI tables > + can also include code, to perform hardware-specific tasks required > + by the Operating Systems. This allows some amount of separation > + between the firmware and OS, and is particularly useful when you > + want to make hardware changes without the OS needing to be adjusted. > + > config CMD_BDI > bool "bdinfo" > default y > diff --git a/cmd/Makefile b/cmd/Makefile > index f1dd513a4b4..15a9693ed0e 100644 > --- a/cmd/Makefile > +++ b/cmd/Makefile > @@ -11,6 +11,7 @@ obj-y += help.o > obj-y += version.o > > # command > +obj-$(CONFIG_CMD_ACPI) += acpi.o > obj-$(CONFIG_CMD_AES) += aes.o > obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o > obj-$(CONFIG_CMD_ADC) += adc.o > diff --git a/cmd/acpi.c b/cmd/acpi.c > new file mode 100644 > index 000..8a320435736 > --- /dev/null > +++ b/cmd/acpi.c > @@ -0,0 +1,179 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright 2019 Google LLC > + * Written by Simon Glass > + */ > +#include > +#include > +#include > +#include > +#include > +#include > + > +DECLARE_GLOBAL_DATA_PTR; > + > +static void dump_hdr(struct acpi_table_header *hdr) > +{ > + bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN); > + > + printf("%.*s %08lx %06x", ACPI_NAME_LEN, hdr->signature, > +(ulong)map_to_sysmem(hdr), hdr->length); > + if (has_hdr) { > + printf(" (v%02d %.6s %.8s %u %.4s %d)\n", hdr->revision, > +hdr->oem_id, hdr->oem_table_id, hdr->oem_revision, > +hdr->aslc_id, hdr->aslc_revision); > + } else { > + printf("\n"); > + } > +} > + > +/** > + * find_table() - Look up an ACPI table > + * > + * @sig: Signature of table (4 characters, upper case) > + * @return pointer to table header, or NULL if not found > + */ > +struct acpi_table_header *find_table(const char *sig) > +{ > + struct acpi_rsdp *rsdp; > + struct acpi_rsdt *rsdt; > + int len, i, count; > + > + rsdp = map_sysmem(gd->arch.acpi_start, 0); > + if (!rsdp) > + return NULL; > + rsdt = map_sysmem(rsdp->rsdt_address, 0); > + len = rsdt->header.length - sizeof(rsdt->header); > + count = len / sizeof(u32); > + for (i = 0; i < count; i++) { > + struct acpi_table_header *hdr; > + > + hdr = map_sysmem(rsdt->entry[i], 0); > + if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) > + retur
[PATCH v3 29/29] acpi: Add an acpi command
It is useful to dump ACPI tables in U-Boot to see what has been generated. Add a command to handle this. To allow the command to find the tables, add a position into the global data. Support subcommands to list and dump the tables. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v3: None Changes in v2: None arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + cmd/Kconfig| 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 179 + lib/acpi/acpi_table.c | 1 + test/dm/acpi.c | 73 ++ 7 files changed, 270 insertions(+) create mode 100644 cmd/acpi.c diff --git a/arch/sandbox/include/asm/global_data.h b/arch/sandbox/include/asm/global_data.h index f4ce72d5660..f95ddb058a2 100644 --- a/arch/sandbox/include/asm/global_data.h +++ b/arch/sandbox/include/asm/global_data.h @@ -13,6 +13,7 @@ struct arch_global_data { uint8_t *ram_buf; /* emulated RAM buffer */ void*text_base; /* pointer to base of text region */ + ulong acpi_start; /* Start address of ACPI tables */ }; #include diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h index f4c1839104e..4aee2f3e8c4 100644 --- a/arch/x86/include/asm/global_data.h +++ b/arch/x86/include/asm/global_data.h @@ -123,6 +123,7 @@ struct arch_global_data { #ifdef CONFIG_FSP_VERSION2 struct fsp_header *fsp_s_hdr; /* Pointer to FSP-S header */ #endif + ulong acpi_start; /* Start address of ACPI tables */ }; #endif diff --git a/cmd/Kconfig b/cmd/Kconfig index 6403bc45a5e..2d3bfe0ab91 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -190,6 +190,20 @@ comment "Commands" menu "Info commands" +config CMD_ACPI + bool "acpi" + default y if ACPIGEN + help + List and dump ACPI tables. ACPI (Advanced Configuration and Power + Interface) is used mostly on x86 for providing information to the + Operating System about devices in the system. The tables are set up + by the firmware, typically U-Boot but possibly an earlier firmware + module, if U-Boot is chain-loaded from something else. ACPI tables + can also include code, to perform hardware-specific tasks required + by the Operating Systems. This allows some amount of separation + between the firmware and OS, and is particularly useful when you + want to make hardware changes without the OS needing to be adjusted. + config CMD_BDI bool "bdinfo" default y diff --git a/cmd/Makefile b/cmd/Makefile index f1dd513a4b4..15a9693ed0e 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -11,6 +11,7 @@ obj-y += help.o obj-y += version.o # command +obj-$(CONFIG_CMD_ACPI) += acpi.o obj-$(CONFIG_CMD_AES) += aes.o obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o diff --git a/cmd/acpi.c b/cmd/acpi.c new file mode 100644 index 000..8a320435736 --- /dev/null +++ b/cmd/acpi.c @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019 Google LLC + * Written by Simon Glass + */ +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static void dump_hdr(struct acpi_table_header *hdr) +{ + bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN); + + printf("%.*s %08lx %06x", ACPI_NAME_LEN, hdr->signature, + (ulong)map_to_sysmem(hdr), hdr->length); + if (has_hdr) { + printf(" (v%02d %.6s %.8s %u %.4s %d)\n", hdr->revision, + hdr->oem_id, hdr->oem_table_id, hdr->oem_revision, + hdr->aslc_id, hdr->aslc_revision); + } else { + printf("\n"); + } +} + +/** + * find_table() - Look up an ACPI table + * + * @sig: Signature of table (4 characters, upper case) + * @return pointer to table header, or NULL if not found + */ +struct acpi_table_header *find_table(const char *sig) +{ + struct acpi_rsdp *rsdp; + struct acpi_rsdt *rsdt; + int len, i, count; + + rsdp = map_sysmem(gd->arch.acpi_start, 0); + if (!rsdp) + return NULL; + rsdt = map_sysmem(rsdp->rsdt_address, 0); + len = rsdt->header.length - sizeof(rsdt->header); + count = len / sizeof(u32); + for (i = 0; i < count; i++) { + struct acpi_table_header *hdr; + + hdr = map_sysmem(rsdt->entry[i], 0); + if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) + return hdr; + if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) { + struct acpi_fadt *fadt = (struct acpi_fadt *)hdr; + + if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt) + ret