dm: Add programmatic generation of ACPI tables (part A)
Subsystems (3)
v7 cover dm: Add programmatic generation of ACPI tables (part A)
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
Changes in v7:
- Rebase to master
Changes in v5:
- Drop bisectability changes
Changes in v4:
- Put 'interrupts-extended' property on one line
- Rename acpi-probed to linux,probed
- Note that linux,probed is an out-of-tree feature
- Separate out the log newline
- Update comment in acpi_inc_align() to show the alignment
- Put back cast on table_compute_checksum()
- Rename list_fact() to list_fadt()
- Add a comment to dump_hdr()
Changes in v3:
- Drop mention of PRIC
- Rename acpi,desc to acpi,ddn
- Correct description of acpi,probed
- Drop hid-descr-addr
- Just add the device.txt binding file in this patch
- Change the example to ELAN
- Add a pointer to information about acpi,compatible
- Rename acpi_align_large() to acpi_align64()
- Fix 'RSDP' typo
- Fix 'XDST' typo
- Move acpi_align_large() out of dm_test_acpi_setup_base_tables()
- Beef up the comment explaining how the unaligned address is used
Changes in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
- Drop definition of ACPI_TABLE_CREATOR
- Make _acpi_write_dev_tables() static and switch argument order
- Generalise the ACPI function recursion with acpi_recurse_method()
Simon Glass (9):
acpi: Add a binding for ACPI settings in the device tree
acpi: Add a method to write tables for a device
acpi: Convert part of acpi_table to use acpi_ctx
x86: Allow devices to write ACPI tables
acpi: Drop code for missing XSDT from acpi_write_rsdp()
acpi: Move acpi_add_table() to generic code
acpi: Put table-setup code in its own function
acpi: Move the xsdt pointer to acpi_ctx
acpi: Add an acpi command
arch/sandbox/dts/test.dts | 4 + arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + arch/x86/lib/acpi_table.c | 239 +++++-------------------- cmd/Kconfig | 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 186 +++++++++++++++++++ doc/device-tree-bindings/device.txt | 36 ++++ drivers/core/acpi.c | 62 +++++++ include/acpi/acpi_table.h | 65 +++++++ include/dm/acpi.h | 37 ++++ lib/acpi/acpi_table.c | 174 +++++++++++++++++- test/dm/acpi.c | 238 +++++++++++++++++++++++- 13 files changed, 855 insertions(+), 203 deletions(-) create mode 100644 cmd/acpi.c create mode 100644 doc/device-tree-bindings/device.txt
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 1/9 acpi: Add a binding for ACPI settings in the device tree
Devices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
---
Changes in v7: None
Changes in v5: None
Changes in v4:
- Put 'interrupts-extended' property on one line
- Rename acpi-probed to linux,probed
- Note that linux,probed is an out-of-tree feature
Changes in v3:
- Drop mention of PRIC
- Rename acpi,desc to acpi,ddn
- Correct description of acpi,probed
- Drop hid-descr-addr
- Just add the device.txt binding file in this patch
- Change the example to ELAN
- Add a pointer to information about acpi,compatible
Changes in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
doc/device-tree-bindings/device.txt | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 doc/device-tree-bindings/device.txt
doc/device-tree-bindings/device.txt new file +36 -0
@@ -0,0 +1,36 @@ +Devices +======= + +Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented here. See +also hid-over-i2c.txt which describes HID devices. See also +Documentation/firmware-guide/acpi/enumeration.rst in the Linux kernel for +the acpi,compatible property. + + - acpi,has-power-resource : (boolean) true if this device has a power resource. + This causes an ACPI PowerResource to be written containing the properties + provided by this binding, to describe how to handle powering the device up + and down using GPIOs + - acpi,compatible : compatible string to report + - acpi,ddn : Contains the string to use as the _DDN (DOS (Disk Operating + System) Device Name) + - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HID + - acpi,uid : _UID value for device + - linux,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that + Linux will only load the driver if the device can be detected (e.g. on I2C + bus). Note that this is an out-of-tree Linux feature. + + +Example +------- + +elan_touchscreen: elan-touchscreen at 10 { + compatible = "i2c-chip"; + reg = <0x10>; + acpi,hid = "ELAN0001"; + acpi,ddn = "ELAN Touchscreen"; + interrupts-extended = <&acpi_gpe GPIO_21_IRQ IRQ_TYPE_EDGE_FALLING>; + linux,probed; +};
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 1/9 acpi: Add a binding for ACPI settings in the device tree
Hi Wolfgang, Andy,
Quoted 10 lines · Simon Glass
Devices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Do you have any comments against this patch?
Regards,
Bin
PATCH v7 1/9 acpi: Add a binding for ACPI settings in the device tree
Quoted 9 lines · Bin Meng
Hi Wolfgang, Andy,
Quoted 5 lines · Simon Glass
Devices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree.
Quoted 7 lines
Quoted 5 lines
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Do you have any comments against this patch?
As long as it doesn't mention PRP0001, I'm fine with it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Antwort: Re: [PATCH v7 1/9] acpi: Add a binding for ACPI settings in the device tree
In reply to Bin MengHi Bin,
-----"Bin Meng" <[email protected]> schrieb: -----
Quoted 13 lines
Betreff: Re: [PATCH v7 1/9] acpi: Add a binding for ACPI settings in the device tree
Hi Wolfgang, Andy,
Quoted 2 lines · Simon Glass
Devices need to report various identifiers in the ACPI tables.
Rather than
Quoted 1 line
hard-coding these in drivers it is typically better to put them in
the
Quoted 2 lines
device tree.
Quoted 7 lines
Quoted 5 lines
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Do you have any comments against this patch?
I'm fine with the patch as it is.
However, two remarks:
1) I proposed some rewording in [1].
I'm fine with dropping it, I just point it out to make sure that it is deliberately dropped and no just overseen.
2) In [2] Andy stated that "acpi,compatible" can't work. @Andy: did I get this wrong? Is it still fine to add it in the binding?
regards, Wolfgang
[1] https://lists.denx.de/pipermail/u-boot/2020-April/406818.html
[2] https://lists.denx.de/pipermail/u-boot/2020-April/406943.html
PATCH v7 1/9 acpi: Add a binding for ACPI settings in the device tree
Quoted 25 lines · Wolfgang Wallner
Quoted 13 lines
Betreff: Re: [PATCH v7 1/9] acpi: Add a binding for ACPI settings in the device tree
Hi Wolfgang, Andy,
Quoted 2 lines · Simon Glass
Devices need to report various identifiers in the ACPI tables.
Rather than
Quoted 1 line
hard-coding these in drivers it is typically better to put them in
the
Quoted 2 lines
device tree.
Quoted 7 lines
Quoted 5 lines
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Do you have any comments against this patch?
I'm fine with the patch as it is.
However, two remarks:
Quoted 7 lines
1) I proposed some rewording in [1].
I'm fine with dropping it, I just point it out to make sure that it is deliberately dropped and no just overseen.2) In [2] Andy stated that "acpi,compatible" can't work. @Andy: did I get this wrong? Is it still fine to add it in the binding?
We can support it in the code, but user should themselves choose how to use it. This will be half-baked solution, though.
So, I suggest for now to drop it completely.
Quoted 2 lines
[1] https://lists.denx.de/pipermail/u-boot/2020-April/406818.html
[2] https://lists.denx.de/pipermail/u-boot/2020-April/406943.html
Signature · 2 lines
With Best Regards, Andy Shevchenko
Antwort: Re: Re: [PATCH v7 1/9] acpi: Add a binding for ACPI settings in the device tree
Hi,
-----"Andy Shevchenko" <[email protected]> schrieb: -----
Quoted 48 lines
An: "Wolfgang Wallner" <[email protected]>
Von: "Andy Shevchenko" <[email protected]>
Datum: 21.04.2020 16:41
Kopie: "Bin Meng" <[email protected]>, "Simon Glass" <[email protected]>, "Andy Shevchenko" <[email protected]>, "U-Boot Mailing List" <[email protected]>, "Leif Lindholm" <[email protected]>
Betreff: Re: Re: [PATCH v7 1/9] acpi: Add a binding for ACPI settings in the device treeQuoted 1 line · Wolfgang Wallner
Quoted 1 line
Betreff: Re: [PATCH v7 1/9] acpi: Add a binding for ACPI settings
in
Quoted 5 lines
Quoted 5 lines
the device tree
Hi Wolfgang, Andy,
On Mon, Apr 20, 2020 at 4:37 AM Simon Glass <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 2 lines
Devices need to report various identifiers in the ACPI tables.
Rather than
Quoted 1 line
hard-coding these in drivers it is typically better to put them
in
Quoted 15 lines
Quoted 10 lines
the
Quoted 7 lines
device tree.
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Do you have any comments against this patch?
I'm fine with the patch as it is.
However, two remarks:
Quoted 7 lines
1) I proposed some rewording in [1].
I'm fine with dropping it, I just point it out to make sure that it is deliberately dropped and no just overseen.2) In [2] Andy stated that "acpi,compatible" can't work. @Andy: did I get this wrong? Is it still fine to add it in the binding?
Quoted 5 lines
We can support it in the code, but user should themselves choose how to use it.
This will be half-baked solution, though.So, I suggest for now to drop it completely.
Ok, thanks for clarifying.
That was the only aspect of the the patch I still felt I don't understand enough. So whether "acpi,compatible" is dropped or not:
Quoted 3 lines
regards, Wolfgang
PATCH v7 2/9 acpi: Add a method to write tables for a device
In reply to Simon GlassA device may want to write out ACPI tables to describe itself to Linux. Add a method to permit this.
---
Changes in v7: None
Changes in v5:
- Drop bisectability changes
Changes in v4:
- Separate out the log newline
Changes in v3: None
Changes in v2:
- Drop definition of ACPI_TABLE_CREATOR
- Make _acpi_write_dev_tables() static and switch argument order
- Generalise the ACPI function recursion with acpi_recurse_method()
arch/sandbox/dts/test.dts | 4 +++ arch/x86/lib/acpi_table.c | 9 ----- drivers/core/acpi.c | 62 ++++++++++++++++++++++++++++++++ include/acpi/acpi_table.h | 10 ++++++ include/dm/acpi.h | 30 ++++++++++++++++ lib/acpi/acpi_table.c | 13 +++++-- test/dm/acpi.c | 74 +++++++++++++++++++++++++++++++++++++-- 7 files changed, 187 insertions(+), 15 deletions(-)
arch/sandbox/dts/test.dts +4 -0
@@ -226,6 +226,10 @@ compatible = "denx,u-boot-acpi-test"; }; + acpi-test2 { + compatible = "denx,u-boot-acpi-test"; + }; + clocks { clk_fixed: clk-fixed { compatible = "fixed-clock";
arch/x86/lib/acpi_table.c +0 -9
@@ -60,15 +60,6 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, sizeof(struct acpi_rsdp)); } -void acpi_fill_header (struct acpi_table_header *header,char *signature) -{ -memcpy (header->signature, signature,4 ); -memcpy (header->oem_id,OEM_ID ,6 ); -memcpy (header->oem_table_id,OEM_TABLE_ID ,8 ); - header->oem_revision =U_BOOT_BUILD_DATE ; -memcpy (header->aslc_id,ASLC_ID ,4 ); -} -static void acpi_write_rsdt (struct acpi_rsdt *rsdt) {struct acpi_table_header *header = &(rsdt->header);
drivers/core/acpi.c +62 -0
73 lines not on this page · raw message
include/acpi/acpi_table.h +10 -0
@@ -505,6 +505,16 @@ int acpi_get_table_revision(enum acpi_tables table);*/ int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags); +/** +* acpi_fill_header() - Set up a new table header +* +* This sets all fields except length, revision, checksum and aslc_revision +* +* @header: ACPI header to update +* @signature: Table signature to use (4 characters) +*/ +void acpi_fill_header (struct acpi_table_header *header,char *signature); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
include/dm/acpi.h +30 -0
@@ -24,6 +24,17 @@#if !defined(__ACPI__) +/** +* struct acpi_ctx - Context used for writing ACPI tables +* +* This contains a few useful pieces of information used when writing +* +* @current: Current address for writing +*/ +struct acpi_ctx { +void *current; +}; +/** * struct acpi_ops - ACPI operations supported by driver model */
@@ -38,6 +49,15 @@ struct acpi_ops {* other error */ int (*get_name)(const struct udevice *dev,char *out_name); + +/** +* write_tables() - Write out any tables required by this device +* +* @dev: Device to write +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int (*write_tables)(const struct udevice *dev,struct acpi_ctx *ctx); };#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops)
@@ -72,6 +92,16 @@ int acpi_get_name(const struct udevice *dev, char *out_name);*/ int acpi_copy_name (char *out_name,const char *name); +/** +* acpi_write_dev_tables() - Write ACPI tables required by devices +* +* This scans through all devices and tells them to write any tables they want +* to write. +* +* @return 0 if OK, -ve if any device returned an error +*/ +int acpi_write_dev_tables (struct acpi_ctx *ctx); +#endif /* __ACPI__ */ #endif
lib/acpi/acpi_table.c +10 -3
@@ -9,9 +9,8 @@#include <acpi/acpi_table.h> #include <dm.h> #include <cpu.h> +#include <version.h> -/* Temporary change to ensure bisectability */ -#ifndef CONFIG_SANDBOX int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags) {struct acpi_table_header *header = &dmar->header;
@@ -37,7 +36,6 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)return 0 ; } -#endif int acpi_get_table_revision (enum acpi_tables table) {
@@ -91,3 +89,12 @@ int acpi_get_table_revision(enum acpi_tables table)return -EINVAL ; } } + +void acpi_fill_header (struct acpi_table_header *header,char *signature) +{ +memcpy (header->signature, signature,4 ); +memcpy (header->oem_id,OEM_ID ,6 ); +memcpy (header->oem_table_id,OEM_TABLE_ID ,8 ); + header->oem_revision =U_BOOT_BUILD_DATE ; +memcpy (header->aslc_id,ASLC_ID ,4 ); +}
test/dm/acpi.c +71 -3
101 lines not on this page · raw message
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 3/9 acpi: Convert part of acpi_table to use acpi_ctx
In reply to Simon GlassThe current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this would be better done in a helper function.
Update write_acpi_tables() to make use of the new acpi_ctx structure, adding a few helpers to clean things up.
---
Changes in v7: None
Changes in v5: None
Changes in v4:
- Update comment in acpi_inc_align() to show the alignment
Changes in v3:
- Rename acpi_align_large() to acpi_align64()
Changes in v2: None
arch/x86/lib/acpi_table.c | 88 +++++++++++++++++++-------------------- include/acpi/acpi_table.h | 36 ++++++++++++++++ lib/acpi/acpi_table.c | 24 ++++++++++- test/dm/acpi.c | 28 +++++++++++++ 4 files changed, 130 insertions(+), 46 deletions(-)
arch/x86/lib/acpi_table.c +43 -45
@@ -10,6 +10,7 @@#include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h> +#include <mapmem.h> #include <serial.h> #include <version.h> #include <acpi/acpi_table.h>
@@ -19,6 +20,7 @@#include <asm/mpspec.h> #include <asm/tables.h> #include <asm/arch/global_nvs.h> +#include <dm/acpi.h> /* * IASL compiles the dsdt entries and writes the hex values
@@ -478,9 +480,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)/* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */ -ulong write_acpi_tables (ulong start) +ulong write_acpi_tables (ulong start_addr) { -u32 current; +struct acpi_ctx sctx, *ctx = &sctx;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt;
@@ -491,60 +493,61 @@ ulong write_acpi_tables(ulong start)struct acpi_madt *madt;struct acpi_csrt *csrt;struct acpi_spcr *spcr; +void *start; +ulong addr;int i; - current = start; + start =map_sysmem (start_addr,0 ); + ctx->current = start;/* Align ACPI tables to 16 byte */ - current =ALIGN (current,16 ); +acpi_align (ctx); -debug ("ACPI: Writing ACPI tables at %lx\n" , start); +debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr);/* We need at least an RSDP and an RSDT Table */ - rsdp = (struct acpi_rsdp *)current; - current +=sizeof (struct acpi_rsdp ); - current =ALIGN (current,16 ); - rsdt = (struct acpi_rsdt *)current; - current +=sizeof (struct acpi_rsdt ); - current =ALIGN (current,16 ); - xsdt = (struct acpi_xsdt *)current; - current +=sizeof (struct acpi_xsdt ); + rsdp = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); + rsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); + xsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));/* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). */ - current =ALIGN (current,64 ); +acpi_align64 (ctx);/* clear all table memory */ -memset ((void *)start,0 , current - start); +memset ((void *)start,0 , ctx->current - start);acpi_write_rsdp (rsdp, rsdt, xsdt);acpi_write_rsdt (rsdt);acpi_write_xsdt (xsdt);debug ("ACPI: * FACS\n" ); - facs = (struct acpi_facs *)current; - current +=sizeof (struct acpi_facs ); - current =ALIGN (current,16 ); + facs = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_facs ));acpi_create_facs (facs);debug ("ACPI: * DSDT\n" ); - dsdt = (struct acpi_table_header *)current; + dsdt = ctx->current;memcpy (dsdt, &AmlCode,sizeof (struct acpi_table_header )); - current +=sizeof (struct acpi_table_header ); -memcpy ((char *)current, +acpi_inc (ctx,sizeof (struct acpi_table_header )); +memcpy (ctx->current, (char *)&AmlCode +sizeof (struct acpi_table_header ), dsdt->length -sizeof (struct acpi_table_header )); - current += dsdt->length -sizeof (struct acpi_table_header ); - current =ALIGN (current,16 ); +acpi_inc_align (ctx, dsdt->length -sizeof (struct acpi_table_header ));/* Pack GNVS into the ACPI table area */ for (i =0 ; i < dsdt->length; i++) {u32 *gnvs = (u32 *)((u32 )dsdt + i);if (*gnvs ==ACPI_GNVS_ADDR ) { -debug ("Fix up global NVS in DSDT to 0x%08x\n" , current); - *gnvs = current; +ulong addr = (ulong )map_to_sysmem (ctx->current); + +debug ("Fix up global NVS in DSDT to %#08lx\n" , addr); + *gnvs = addr;break ; } }
@@ -554,51 +557,46 @@ ulong write_acpi_tables(ulong start) dsdt->checksum =table_compute_checksum ((void *)dsdt, dsdt->length);/* Fill in platform-specific global NVS variables */ -acpi_create_gnvs ((struct acpi_global_nvs *)current); - current +=sizeof (struct acpi_global_nvs ); - current =ALIGN (current,16 ); +acpi_create_gnvs (ctx->current); +acpi_inc_align (ctx,sizeof (struct acpi_global_nvs ));debug ("ACPI: * FADT\n" ); - fadt = (struct acpi_fadt *)current; - current +=sizeof (struct acpi_fadt ); - current =ALIGN (current,16 ); + fadt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_fadt ));acpi_create_fadt (fadt, facs, dsdt);acpi_add_table (rsdp, fadt);debug ("ACPI: * MADT\n" ); - madt = (struct acpi_madt *)current; + madt = ctx->current;acpi_create_madt (madt); - current += madt->header.length; +acpi_inc_align (ctx, madt->header.length);acpi_add_table (rsdp, madt); - current =ALIGN (current,16 );debug ("ACPI: * MCFG\n" ); - mcfg = (struct acpi_mcfg *)current; + mcfg = ctx->current;acpi_create_mcfg (mcfg); - current += mcfg->header.length; +acpi_inc_align (ctx, mcfg->header.length);acpi_add_table (rsdp, mcfg); - current =ALIGN (current,16 );debug ("ACPI: * CSRT\n" ); - csrt = (struct acpi_csrt *)current; + csrt = ctx->current;acpi_create_csrt (csrt); - current += csrt->header.length; +acpi_inc_align (ctx, csrt->header.length);acpi_add_table (rsdp, csrt); - current =ALIGN (current,16 );debug ("ACPI: * SPCR\n" ); - spcr = (struct acpi_spcr *)current; + spcr = ctx->current;acpi_create_spcr (spcr); - current += spcr->header.length; +acpi_inc_align (ctx, spcr->header.length);acpi_add_table (rsdp, spcr); - current =ALIGN (current,16 ); -debug ("current = %x\n" , current); + addr =map_to_sysmem (ctx->current); +debug ("current = %lx\n" , addr); acpi_rsdp_addr = (unsigned long )rsdp;debug ("ACPI: done\n" ); -return current; +return addr; }ulong acpi_get_rsdp_addr (void )
include/acpi/acpi_table.h +36 -0
@@ -23,6 +23,8 @@#if !defined(__ACPI__) +struct acpi_ctx ; +/* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
@@ -515,6 +517,40 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);*/ void acpi_fill_header (struct acpi_table_header *header,char *signature); +/** +* acpi_align() - Align the ACPI output pointer to a 16-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align (struct acpi_ctx *ctx); + +/** +* acpi_align64() - Align the ACPI output pointer to a 64-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align64 (struct acpi_ctx *ctx); + +/** +* acpi_inc() - Increment the ACPI output pointer by a bit +* +* The pointer is NOT aligned afterwards. +* +* @ctx: ACPI context +* @amount: Amount to increment by +*/ +void acpi_inc (struct acpi_ctx *ctx,uint amount); + +/** +* acpi_inc_align() - Increment the ACPI output pointer by a bit and align +* +* The pointer is aligned afterwards to a 16-byte boundary +* +* @ctx: ACPI context +* @amount: Amount to increment by +*/ +void acpi_inc_align (struct acpi_ctx *ctx,uint amount); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/acpi/acpi_table.c +23 -1
@@ -6,10 +6,11 @@*/ #include <common.h> -#include <acpi/acpi_table.h> #include <dm.h> #include <cpu.h> #include <version.h> +#include <acpi/acpi_table.h> +#include <dm/acpi.h> int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags) {
@@ -98,3 +99,24 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature) header->oem_revision =U_BOOT_BUILD_DATE ;memcpy (header->aslc_id,ASLC_ID ,4 ); } + +void acpi_align (struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN ((ulong )ctx->current,16 ); +} + +void acpi_align64 (struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN ((ulong )ctx->current,64 ); +} + +void acpi_inc (struct acpi_ctx *ctx,uint amount) +{ + ctx->current += amount; +} + +void acpi_inc_align (struct acpi_ctx *ctx,uint amount) +{ + ctx->current += amount; +acpi_align (ctx); +}
test/dm/acpi.c +28 -0
@@ -151,3 +151,31 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_write_tables,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test basic ACPI functions */ +static int dm_test_acpi_basic (struct unit_test_state *uts) +{ +struct acpi_ctx ctx; + +/* Check align works */ + ctx.current = (void *)5 ; +acpi_align (&ctx); +ut_asserteq_ptr ((void *)16 , ctx.current); + +/* Check that align does nothing if already aligned */ +acpi_align (&ctx); +ut_asserteq_ptr ((void *)16 , ctx.current); +acpi_align64 (&ctx); +ut_asserteq_ptr ((void *)64 , ctx.current); +acpi_align64 (&ctx); +ut_asserteq_ptr ((void *)64 , ctx.current); + +/* Check incrementing */ +acpi_inc (&ctx,3 ); +ut_asserteq_ptr ((void *)67 , ctx.current); +acpi_inc_align (&ctx,3 ); +ut_asserteq_ptr ((void *)80 , ctx.current); + +return 0 ; +} +DM_TEST (dm_test_acpi_basic,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 4/9 x86: Allow devices to write ACPI tables
In reply to Simon GlassCall the new core function to permit devices to write their own ACPI tables. These tables will appear after all other tables.
---
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
arch/x86/lib/acpi_table.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/lib/acpi_table.c +2 -0
@@ -590,6 +590,8 @@ ulong write_acpi_tables(ulong start_addr)acpi_inc_align (ctx, spcr->header.length);acpi_add_table (rsdp, spcr); +acpi_write_dev_tables (ctx); + addr =map_to_sysmem (ctx->current);debug ("current = %lx\n" , addr);
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 5/9 acpi: Drop code for missing XSDT from acpi_write_rsdp()
In reply to Simon GlassWe don't actually support tables without an XSDT so we can drop this dead code.
---
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
arch/x86/lib/acpi_table.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
arch/x86/lib/acpi_table.c +2 -13
@@ -42,19 +42,8 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, rsdp->length =sizeof (struct acpi_rsdp ); rsdp->rsdt_address = (u32 )rsdt; -/* -* Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2 -* -* Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. -* If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR -* revision 0) -*/ -if (xsdt ==NULL ) { - rsdp->revision =ACPI_RSDP_REV_ACPI_1_0 ; - }else { - rsdp->xsdt_address = (u64 )(u32 )xsdt; - rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ; - } + rsdp->xsdt_address = (u64 )(u32 )xsdt; + rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ;/* Calculate checksums */ rsdp->checksum =table_compute_checksum ((void *)rsdp,20 );
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 6/9 acpi: Move acpi_add_table() to generic code
In reply to Simon GlassMove this code to a generic location so that we can test it with sandbox. This requires adding a few new fields to acpi_ctx, so drop the local variables used in the original code.
Also use mapmem to avoid pointer-to-address casts which don't work on sandbox.
---
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- Fix 'RSDP' typo
Changes in v2: None
arch/x86/lib/acpi_table.c | 83 +++++---------------------------------- include/acpi/acpi_table.h | 9 +++++ include/dm/acpi.h | 5 +++ lib/acpi/acpi_table.c | 61 ++++++++++++++++++++++++++++ test/dm/acpi.c | 4 ++ 5 files changed, 89 insertions(+), 73 deletions(-)
arch/x86/lib/acpi_table.c +10 -73
@@ -83,67 +83,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt) sizeof(struct acpi_xsdt)); } -/** -* Add an ACPI table to the RSDT (and XSDT) structure, recalculate length -* and checksum. -*/ -static void acpi_add_table (struct acpi_rsdp *rsdp,void *table) -{ -int i, entries_num; -struct acpi_rsdt *rsdt; -struct acpi_xsdt *xsdt; - -/* The RSDT is mandatory while the XSDT is not */ - rsdt = (struct acpi_rsdt *)rsdp->rsdt_address; - -/* This should always be MAX_ACPI_TABLES */ - entries_num =ARRAY_SIZE (rsdt->entry); - -for (i =0 ; i < entries_num; i++) { -if (rsdt->entry[i] ==0 ) -break ; - } - -if (i >= entries_num) { -debug ("ACPI: Error: too many tables\n" ); -return ; - } - -/* Add table to the RSDT */ - rsdt->entry[i] = (u32 )table; - -/* Fix RSDT length or the kernel will assume invalid entries */ - rsdt->header.length =sizeof (struct acpi_table_header ) + -sizeof (u32) * (i +1 ); - -/* Re-calculate checksum */ - rsdt->header.checksum =0 ; - rsdt->header.checksum =table_compute_checksum ((u8 *)rsdt, - rsdt->header.length); - -/* The RSDT is mandatory while the XSDT is not */ -if (!rsdp->xsdt_address) -return ; - -/* -* And now the same thing for the XSDT. We use the same index as for -* now we want the XSDT and RSDT to always be in sync in U-Boot -*/ - xsdt = (struct acpi_xsdt *)((u32 )rsdp->xsdt_address); - -/* Add table to the XSDT */ - xsdt->entry[i] = (u64 )(u32 )table; - -/* Fix XSDT length */ - xsdt->header.length =sizeof (struct acpi_table_header ) + -sizeof (u64) * (i +1 ); - -/* Re-calculate checksum */ - xsdt->header.checksum =0 ; - xsdt->header.checksum =table_compute_checksum ((u8 *)xsdt, - xsdt->header.length); -} -static void acpi_create_facs (struct acpi_facs *facs) {memset ((void *)facs,0 ,sizeof (struct acpi_facs ));
@@ -472,8 +411,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)ulong write_acpi_tables (ulong start_addr) {struct acpi_ctx sctx, *ctx = &sctx; -struct acpi_rsdp *rsdp; -struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt;struct acpi_facs *facs;struct acpi_table_header *dsdt;
@@ -495,9 +432,9 @@ ulong write_acpi_tables(ulong start_addr)debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr);/* We need at least an RSDP and an RSDT Table */ - rsdp = ctx->current; + ctx->rsdp = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); - rsdt = ctx->current; + ctx->rsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); xsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));
@@ -510,8 +447,8 @@ ulong write_acpi_tables(ulong start_addr)/* clear all table memory */ memset ((void *)start,0 , ctx->current - start); -acpi_write_rsdp (rsdp, rsdt, xsdt); -acpi_write_rsdt (rsdt); +acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); +acpi_write_rsdt (ctx->rsdt);acpi_write_xsdt (xsdt);debug ("ACPI: * FACS\n" );
@@ -553,38 +490,38 @@ ulong write_acpi_tables(ulong start_addr) fadt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_fadt ));acpi_create_fadt (fadt, facs, dsdt); -acpi_add_table (rsdp, fadt); +acpi_add_table (ctx, fadt);debug ("ACPI: * MADT\n" ); madt = ctx->current;acpi_create_madt (madt);acpi_inc_align (ctx, madt->header.length); -acpi_add_table (rsdp, madt); +acpi_add_table (ctx, madt);debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);acpi_inc_align (ctx, mcfg->header.length); -acpi_add_table (rsdp, mcfg); +acpi_add_table (ctx, mcfg);debug ("ACPI: * CSRT\n" ); csrt = ctx->current;acpi_create_csrt (csrt);acpi_inc_align (ctx, csrt->header.length); -acpi_add_table (rsdp, csrt); +acpi_add_table (ctx, csrt);debug ("ACPI: * SPCR\n" ); spcr = ctx->current;acpi_create_spcr (spcr);acpi_inc_align (ctx, spcr->header.length); -acpi_add_table (rsdp, spcr); +acpi_add_table (ctx, spcr);acpi_write_dev_tables (ctx); addr =map_to_sysmem (ctx->current);debug ("current = %lx\n" , addr); - acpi_rsdp_addr = (unsigned long )rsdp; + acpi_rsdp_addr = (unsigned long )ctx->rsdp;debug ("ACPI: done\n" );return addr;
include/acpi/acpi_table.h +9 -0
@@ -551,6 +551,15 @@ void acpi_inc(struct acpi_ctx *ctx, uint amount);*/ void acpi_inc_align (struct acpi_ctx *ctx,uint amount); +/** +* acpi_add_table() - Add a new table to the RSDP and XSDT +* +* @ctx: ACPI context +* @table: Table to add +* @return 0 if OK, -E2BIG if too many tables +*/ +int acpi_add_table (struct acpi_ctx *ctx,void *table); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
include/dm/acpi.h +5 -0
@@ -30,9 +30,14 @@* This contains a few useful pieces of information used when writing * * @current: Current address for writing +* @rsdp: Pointer to the Root System Description Pointer, typically used when +* adding a new table. The RSDP holds pointers to the RSDT and XSDT. +* @rsdt: Pointer to the Root System Description Table */ struct acpi_ctx {void *current; +struct acpi_rsdp *rsdp; +struct acpi_rsdt *rsdt; };/**
lib/acpi/acpi_table.c +61 -0
70 lines not on this page · raw message
test/dm/acpi.c +4 -0
@@ -21,10 +21,14 @@ static int testacpi_write_tables(const struct udevice *dev, struct acpi_ctx *ctx) {struct acpi_dmar *dmar; +int ret; dmar = (struct acpi_dmar *)ctx->current;acpi_create_dmar (dmar,DMAR_INTR_REMAP ); ctx->current +=sizeof (struct acpi_dmar ); + ret =acpi_add_table (ctx, dmar); +if (ret) +return log_msg_ret ("add" , ret);return 0 ; }
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 7/9 acpi: Put table-setup code in its own function
In reply to Simon GlassWe always write three basic tables to ACPI at the start. Move this into its own function, along with acpi_fill_header(), so we can write a test for this code.
---
Changes in v7: None
Changes in v5: None
Changes in v4:
- Put back cast on table_compute_checksum()
Changes in v3:
- Fix 'XDST' typo
- Move acpi_align_large() out of dm_test_acpi_setup_base_tables()
- Beef up the comment explaining how the unaligned address is used
Changes in v2: None
arch/x86/lib/acpi_table.c | 72 +----------------------------------- include/acpi/acpi_table.h | 10 +++++ lib/acpi/acpi_table.c | 77 +++++++++++++++++++++++++++++++++++++++ test/dm/acpi.c | 58 ++++++++++++++++++++++++++++- 4 files changed, 144 insertions(+), 73 deletions(-)
arch/x86/lib/acpi_table.c +1 -71
@@ -31,58 +31,6 @@ extern const unsigned char AmlCode[];/* ACPI RSDP address to be used in boot parameters */ static ulong acpi_rsdp_addr; -static void acpi_write_rsdp (struct acpi_rsdp *rsdp,struct acpi_rsdt *rsdt, -struct acpi_xsdt *xsdt) -{ -memset (rsdp,0 ,sizeof (struct acpi_rsdp )); - -memcpy (rsdp->signature,RSDP_SIG ,8 ); -memcpy (rsdp->oem_id,OEM_ID ,6 ); - - rsdp->length =sizeof (struct acpi_rsdp ); - rsdp->rsdt_address = (u32 )rsdt; - - rsdp->xsdt_address = (u64 )(u32 )xsdt; - rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ; - -/* Calculate checksums */ - rsdp->checksum =table_compute_checksum ((void *)rsdp,20 ); - rsdp->ext_checksum =table_compute_checksum ((void *)rsdp, -sizeof (struct acpi_rsdp )); -} - -static void acpi_write_rsdt (struct acpi_rsdt *rsdt) -{ -struct acpi_table_header *header = &(rsdt->header); - -/* Fill out header fields */ -acpi_fill_header (header,"RSDT" ); - header->length =sizeof (struct acpi_rsdt ); - header->revision =1 ; - -/* Entries are filled in later, we come with an empty set */ - -/* Fix checksum */ - header->checksum =table_compute_checksum ((void *)rsdt, -sizeof (struct acpi_rsdt )); -} - -static void acpi_write_xsdt (struct acpi_xsdt *xsdt) -{ -struct acpi_table_header *header = &(xsdt->header); - -/* Fill out header fields */ -acpi_fill_header (header,"XSDT" ); - header->length =sizeof (struct acpi_xsdt ); - header->revision =1 ; - -/* Entries are filled in later, we come with an empty set */ - -/* Fix checksum */ - header->checksum =table_compute_checksum ((void *)xsdt, -sizeof (struct acpi_xsdt )); -} -static void acpi_create_facs (struct acpi_facs *facs) {memset ((void *)facs,0 ,sizeof (struct acpi_facs ));
@@ -411,7 +359,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)ulong write_acpi_tables (ulong start_addr) {struct acpi_ctx sctx, *ctx = &sctx; -struct acpi_xsdt *xsdt;struct acpi_facs *facs;struct acpi_table_header *dsdt;struct acpi_fadt *fadt;
@@ -424,33 +371,16 @@ ulong write_acpi_tables(ulong start_addr)int i; start =map_sysmem (start_addr,0 ); - ctx->current = start; - -/* Align ACPI tables to 16 byte */ -acpi_align (ctx);debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr); -/* We need at least an RSDP and an RSDT Table */ - ctx->rsdp = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); - ctx->rsdt = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); - xsdt = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_xsdt )); +acpi_setup_base_tables (ctx, start);/* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). */ acpi_align64 (ctx); -/* clear all table memory */ -memset ((void *)start,0 , ctx->current - start); - -acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); -acpi_write_rsdt (ctx->rsdt); -acpi_write_xsdt (xsdt); -debug ("ACPI: * FACS\n" ); facs = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_facs ));
include/acpi/acpi_table.h +10 -0
@@ -560,6 +560,16 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount);*/ int acpi_add_table (struct acpi_ctx *ctx,void *table); +/** +* acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT +* +* Set up the context with the given start position. Some basic tables are +* always needed, so set them up as well. +* +* @ctx: Context to set up +*/ +void acpi_setup_base_tables (struct acpi_ctx *ctx,void *start); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/acpi/acpi_table.c +77 -0
80 lines not on this page · raw message
test/dm/acpi.c +56 -2
80 lines not on this page · raw message
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 7/9 acpi: Put table-setup code in its own function
Hi Simon, Wolfgang,
Quoted 6 lines · Simon Glass
We always write three basic tables to ACPI at the start. Move this into its own function, along with
acpi_fill_header(), so we can write a test for this code.Signed-off-by Simon Glass <[email protected]>
I see Wolfgang gave a RB tag to the v5 patch, so I am going to add that tag here since no changes between v5 and v7
But I wonder why this new series is tagged as v7. Do I miss v6?
Quoted 12 lines
---
Changes in v7: None
Changes in v5: None
Changes in v4:
- Put back cast ontable_compute_checksum()Changes in v3:
- Fix 'XDST' typo
- Moveacpi_align_large()out ofdm_test_acpi_setup_base_tables()
- Beef up the comment explaining how the unaligned address is used
Quoted 8 lines
Changes in v2: None
arch/x86/lib/acpi_table.c | 72 +----------------------------------- include/acpi/acpi_table.h | 10 +++++ lib/acpi/acpi_table.c | 77 +++++++++++++++++++++++++++++++++++++++ test/dm/acpi.c | 58 ++++++++++++++++++++++++++++- 4 files changed, 144 insertions(+), 73 deletions(-)
Regards,
Bin
PATCH v7 7/9 acpi: Put table-setup code in its own function
Hi Bin,
Quoted 9 lines · Bin Meng
Hi Simon, Wolfgang,
Quoted 5 lines · Simon Glass
We always write three basic tables to ACPI at the start. Move this into its own function, along with
acpi_fill_header(), so we can write a test for this code.
Quoted 8 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>I see Wolfgang gave a RB tag to the v5 patch, so I am going to add that tag here since no changes between v5 and v7
Reviewed-by Wolfgang Wallner <[email protected]>But I wonder why this new series is tagged as v7. Do I miss v6?
I'm not sure...but I think I might have skipped a version.
Regards,
SImon
Antwort: Re: [PATCH v7 7/9] acpi: Put table-setup code in its own function
Hi Bin, Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 16 lines
Betreff: Re: [PATCH v7 7/9] acpi: Put table-setup code in its own function
Hi Bin,
Quoted 11 lines · Bin Meng
Hi Simon, Wolfgang,
Quoted 6 lines · Simon Glass
We always write three basic tables to ACPI at the start. Move this into its own function, along with
acpi_fill_header(), so we can write a test for this code.Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
Quoted 6 lines
I see Wolfgang gave a RB tag to the v5 patch, so I am going to add that tag here since no changes between v5 and v7
Reviewed-by Wolfgang Wallner <[email protected]>But I wonder why this new series is tagged as v7. Do I miss v6?
I'm not sure...but I think I might have skipped a version.
v5 was the last full version of part A of this series.
v6 contained only two fixes for v5, and was applied together with parts of v5. v7 are the remainig patches of v5.
regards, Wolfgang
PATCH v7 7/9 acpi: Put table-setup code in its own function
Hi Wolfgang,
Quoted 25 lines · Wolfgang Wallner
Hi Bin, Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 21 lines
Betreff: Re: [PATCH v7 7/9] acpi: Put table-setup code in its own function
Hi Bin,
Quoted 16 lines · Bin Meng
Hi Simon, Wolfgang,
Quoted 6 lines · Simon Glass
We always write three basic tables to ACPI at the start. Move this into its own function, along with
acpi_fill_header(), so we can write a test for this code.Signed-off-by Simon Glass <[email protected]>I see Wolfgang gave a RB tag to the v5 patch, so I am going to add that tag here since no changes between v5 and v7
Reviewed-by Wolfgang Wallner <[email protected]>
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
But I wonder why this new series is tagged as v7. Do I miss v6?
I'm not sure...but I think I might have skipped a version.
v5 was the last full version of part A of this series.
v6 contained only two fixes for v5, and was applied together with parts of v5. v7 are the remainig patches of v5.
Ah, yes! Thanks for the information.
Regards,
Bin
PATCH v7 8/9 acpi: Move the xsdt pointer to acpi_ctx
In reply to Simon GlassPut this in the context along with the other important pointers.
---
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
include/dm/acpi.h | 2 ++ lib/acpi/acpi_table.c | 10 ++++------ test/dm/acpi.c | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-)
include/dm/acpi.h +2 -0
@@ -33,11 +33,13 @@* @rsdp: Pointer to the Root System Description Pointer, typically used when * adding a new table. The RSDP holds pointers to the RSDT and XSDT. * @rsdt: Pointer to the Root System Description Table +* @xsdt: Pointer to the Extended System Description Table */ struct acpi_ctx {void *current;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt; +struct acpi_xsdt *xsdt; };/**
lib/acpi/acpi_table.c +4 -6
@@ -165,7 +165,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)* And now the same thing for the XSDT. We use the same index as for * now we want the XSDT and RSDT to always be in sync in U-Boot */ - xsdt = (struct acpi_xsdt *)((uintptr_t )ctx->rsdp->xsdt_address); + xsdt = ctx->xsdt;/* Add table to the XSDT */ xsdt->entry[i] =map_to_sysmem (table);
@@ -236,8 +236,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt)void acpi_setup_base_tables (struct acpi_ctx *ctx,void *start) { -struct acpi_xsdt *xsdt; - ctx->current = start;/* Align ACPI tables to 16 byte */
@@ -248,13 +246,13 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); ctx->rsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); - xsdt = ctx->current; + ctx->xsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));/* clear all table memory */ memset ((void *)start,'\0' , ctx->current - start); -acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); +acpi_write_rsdp (ctx->rsdp, ctx->rsdt, ctx->xsdt);acpi_write_rsdt (ctx->rsdt); -acpi_write_xsdt (xsdt); +acpi_write_xsdt (ctx->xsdt); }
test/dm/acpi.c +5 -0
@@ -160,6 +160,10 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)ut_asserteq (map_to_sysmem (dmar +1 ), ctx.rsdt->entry[1 ]);ut_asserteq (0 , ctx.rsdt->entry[2 ]); +ut_asserteq (map_to_sysmem (dmar), ctx.xsdt->entry[0 ]); +ut_asserteq (map_to_sysmem (dmar +1 ), ctx.xsdt->entry[1 ]); +ut_asserteq (0 , ctx.xsdt->entry[2 ]); +return 0 ; }DM_TEST (dm_test_acpi_write_tables,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
@@ -223,6 +227,7 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts)ut_assertok (table_compute_checksum (rsdt,sizeof (*rsdt))); xsdt =PTR_ALIGN ((void *)rsdt +sizeof (*rsdt),16 ); +ut_asserteq_ptr (xsdt, ctx.xsdt);ut_assertok (memcmp ("XSDT" , xsdt->header.signature,ACPI_NAME_LEN ));ut_asserteq (sizeof (*xsdt), xsdt->header.length);ut_assertok (table_compute_checksum (xsdt,sizeof (*xsdt)));
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
PATCH v7 9/9 acpi: Add an acpi command
In reply to Simon GlassIt 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.
---
Changes in v7:
- Rebase to master
Changes in v5: None
Changes in v4:
- Rename list_fact() to list_fadt()
- Add a comment to dump_hdr()
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 | 186 +++++++++++++++++++++++++ lib/acpi/acpi_table.c | 1 + test/dm/acpi.c | 73 ++++++++++ 7 files changed, 277 insertions(+) create mode 100644 cmd/acpi.c
arch/sandbox/include/asm/global_data.h +1 -0
@@ -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 <asm-generic/global_data.h>
arch/x86/include/asm/global_data.h +1 -0
@@ -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
cmd/Kconfig +14 -0
@@ -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
cmd/Makefile +1 -0
@@ -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
cmd/acpi.c new file +186 -0
186 lines not on this page · raw message
lib/acpi/acpi_table.c +1 -0
@@ -240,6 +240,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)/* Align ACPI tables to 16 byte */ acpi_align (ctx); + gd->arch.acpi_start =map_to_sysmem (ctx->current);/* We need at least an RSDP and an RSDT Table */ ctx->rsdp = ctx->current;
test/dm/acpi.c +73 -0
91 lines not on this page · raw message
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
v7 cover dm: Add programmatic generation of ACPI tables (part A)
In reply to Simon GlassQuoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
So, overall I have no concerns, except that compatible string in ACPI seems half-baked solution and, due to PRP0001 awareness (my understanding that it should not be part of production devices), seems not needed right now. It means we should require to have _HID and/or _CID.
Code looks fine to me, though.
Quoted 69 lines
Changes in v7:
- Rebase to masterChanges in v5:
- Drop bisectability changesChanges in v4:
- Put 'interrupts-extended' property on one line
- Rename acpi-probed to linux,probed
- Note that linux,probed is an out-of-tree feature
- Separate out the log newline
- Update comment inacpi_inc_align()to show the alignment
- Put back cast ontable_compute_checksum()
- Renamelist_fact()tolist_fadt()
- Add a comment todump_hdr()Changes in v3:
- Drop mention of PRIC
- Rename acpi,desc to acpi,ddn
- Correct description of acpi,probed
- Drop hid-descr-addr
- Just add the device.txt binding file in this patch
- Change the example to ELAN
- Add a pointer to information about acpi,compatible
- Renameacpi_align_large()toacpi_align64()
- Fix 'RSDP' typo
- Fix 'XDST' typo
- Moveacpi_align_large()out ofdm_test_acpi_setup_base_tables()
- Beef up the comment explaining how the unaligned address is usedChanges in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
- Drop definition ofACPI_TABLE_CREATOR
- Make_acpi_write_dev_tables()static and switch argument order
- Generalise the ACPI function recursion withacpi_recurse_method()Simon Glass (9):
acpi: Add a binding for ACPI settings in the device tree
acpi: Add a method to write tables for a device
acpi: Convert part ofacpi_tableto useacpi_ctx
x86: Allow devices to write ACPI tables
acpi: Drop code for missing XSDT fromacpi_write_rsdp()
acpi: Moveacpi_add_table()to generic code
acpi: Put table-setup code in its own function
acpi: Move the xsdt pointer toacpi_ctx
acpi: Add an acpi commandarch/sandbox/dts/test.dts | 4 + arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + arch/x86/lib/acpi_table.c | 239 +++++-------------------- cmd/Kconfig | 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 186 +++++++++++++++++++ doc/device-tree-bindings/device.txt | 36 ++++ drivers/core/acpi.c | 62 +++++++ include/acpi/acpi_table.h | 65 +++++++ include/dm/acpi.h | 37 ++++ lib/acpi/acpi_table.c | 174 +++++++++++++++++- test/dm/acpi.c | 238 +++++++++++++++++++++++- 13 files changed, 855 insertions(+), 203 deletions(-) create mode 100644 cmd/acpi.c create mode 100644 doc/device-tree-bindings/device.txtSignature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
v7 cover dm: Add programmatic generation of ACPI tables (part A)
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
So, overall I have no concerns, except that compatible string in ACPI seems half-baked solution and, due to PRP0001 awareness (my understanding that it should not be part of production devices), seems not needed right now. It means we should require to have
_HIDand/or_CID.
OK I am really not sure what to say about this. Let's deal with it when we see the use of it later.
Quoted 3 lines
Code looks fine to me, though.
OK good. I will send part B soon.
Quoted 66 lines
Quoted 66 lines
Changes in v7:
- Rebase to masterChanges in v5:
- Drop bisectability changesChanges in v4:
- Put 'interrupts-extended' property on one line
- Rename acpi-probed to linux,probed
- Note that linux,probed is an out-of-tree feature
- Separate out the log newline
- Update comment inacpi_inc_align()to show the alignment
- Put back cast ontable_compute_checksum()
- Renamelist_fact()tolist_fadt()
- Add a comment todump_hdr()Changes in v3:
- Drop mention of PRIC
- Rename acpi,desc to acpi,ddn
- Correct description of acpi,probed
- Drop hid-descr-addr
- Just add the device.txt binding file in this patch
- Change the example to ELAN
- Add a pointer to information about acpi,compatible
- Renameacpi_align_large()toacpi_align64()
- Fix 'RSDP' typo
- Fix 'XDST' typo
- Moveacpi_align_large()out ofdm_test_acpi_setup_base_tables()
- Beef up the comment explaining how the unaligned address is usedChanges in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
- Drop definition ofACPI_TABLE_CREATOR
- Make_acpi_write_dev_tables()static and switch argument order
- Generalise the ACPI function recursion withacpi_recurse_method()Simon Glass (9):
acpi: Add a binding for ACPI settings in the device tree
acpi: Add a method to write tables for a device
acpi: Convert part ofacpi_tableto useacpi_ctx
x86: Allow devices to write ACPI tables
acpi: Drop code for missing XSDT fromacpi_write_rsdp()
acpi: Moveacpi_add_table()to generic code
acpi: Put table-setup code in its own function
acpi: Move the xsdt pointer toacpi_ctx
acpi: Add an acpi commandarch/sandbox/dts/test.dts | 4 + arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + arch/x86/lib/acpi_table.c | 239 +++++-------------------- cmd/Kconfig | 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 186 +++++++++++++++++++ doc/device-tree-bindings/device.txt | 36 ++++ drivers/core/acpi.c | 62 +++++++ include/acpi/acpi_table.h | 65 +++++++ include/dm/acpi.h | 37 ++++ lib/acpi/acpi_table.c | 174 +++++++++++++++++- test/dm/acpi.c | 238 +++++++++++++++++++++++- 13 files changed, 855 insertions(+), 203 deletions(-) create mode 100644 cmd/acpi.c create mode 100644 doc/device-tree-bindings/device.txt
Quoted 3 lines
Quoted 3 lines
--
2.26.1.301.g55bc3eb7cb9-goog
Regards,
Simon
v7 cover dm: Add programmatic generation of ACPI tables (part A)
Hi Simon,
Quoted 17 lines · Simon Glass
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
So, overall I have no concerns, except that compatible string in ACPI seems half-baked solution and, due to PRP0001 awareness (my understanding that it should not be part of production devices), seems not needed right now. It means we should require to have
_HIDand/or_CID.
Quoted 9 lines
OK I am really not sure what to say about this. Let's deal with it when we see the use of it later.
Quoted 3 lines
Code looks fine to me, though.
OK good. I will send part B soon.
v7 has been applied to u-boot-x86, thanks!
Regards,
Bin
v7 cover dm: Add programmatic generation of ACPI tables (part A)
Hi Simon,
Quoted 25 lines · Bin Meng
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
So, overall I have no concerns, except that compatible string in ACPI seems half-baked solution and, due to PRP0001 awareness (my understanding that it should not be part of production devices), seems not needed right now. It means we should require to have
_HIDand/or_CID.OK I am really not sure what to say about this. Let's deal with it when we see the use of it later.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Code looks fine to me, though.
OK good. I will send part B soon.
v7 has been applied to u-boot-x86, thanks!
Unfortunately this series breaks sandbox_spl, please take a look.
https://gitlab.denx.de/u-boot/custodians/u-boot-x86/-/jobs/81615
Regards,
Bin
v7 cover dm: Add programmatic generation of ACPI tables (part A)
Hi Simon,
Quoted 35 lines · Bin Meng
Hi Simon,
Quoted 31 lines · Bin Meng
Hi Simon,
Quoted 26 lines · Simon Glass
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
So, overall I have no concerns, except that compatible string in ACPI seems half-baked solution and, due to PRP0001 awareness (my understanding that it should not be part of production devices), seems not needed right now. It means we should require to have
_HIDand/or_CID.OK I am really not sure what to say about this. Let's deal with it when we see the use of it later.
Quoted 3 lines
Code looks fine to me, though.
OK good. I will send part B soon.
Quoted 7 lines
Quoted 2 lines
v7 has been applied to u-boot-x86, thanks!
Unfortunately this series breaks
sandbox_spl, please take a look.https://gitlab.denx.de/u-boot/custodians/u-boot-x86/-/jobs/81615
Did you send out a fix for this series so that I can squash in?
Regards,
Bin
v7 cover dm: Add programmatic generation of ACPI tables (part A)
Hi Bin,
Quoted 42 lines · Bin Meng
Hi Simon,
Quoted 38 lines · Bin Meng
Hi Simon,
Quoted 33 lines · Bin Meng
Hi Simon,
Quoted 17 lines · Simon Glass
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
So, overall I have no concerns, except that compatible string in ACPI seems half-baked solution and, due to PRP0001 awareness (my understanding that it should not be part of production devices), seems not needed right now. It means we should require to have
_HIDand/or_CID.Quoted 9 lines
OK I am really not sure what to say about this. Let's deal with it when we see the use of it later.
Quoted 3 lines
Code looks fine to me, though.
OK good. I will send part B soon.
v7 has been applied to u-boot-x86, thanks!
Quoted 6 lines
Quoted 4 lines
Unfortunately this series breaks
sandbox_spl, please take a look.https://gitlab.denx.de/u-boot/custodians/u-boot-x86/-/jobs/81615
Did you send out a fix for this series so that I can squash in?
Oops, no, I sent out a new series. I will send a fixup patch.
Regards,
Simon
v7 cover dm: Add programmatic generation of ACPI tables (part A)
In reply to Simon GlassQuoted 4 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
v7 is just a rebase as requested
Hello Simon,
Andrei Warkentin pointed me to a similar development for EDK2:
Dynamic Tables Framework
https://github.com/tianocore/edk2/tree/master/DynamicTablesPkg
Best regards
Heinrich
v7 cover dm: Add programmatic generation of ACPI tables (part A)
Hi Heinrich,
Quoted 5 lines · Heinrich Schuchardt
Quoted 3 lines · Simon Glass
This is split from the original series in an attempt to get things applied in chunks.
Quoted 8 lines
Quoted 1 line
v7 is just a rebase as requested
Hello Simon,
Andrei Warkentin pointed me to a similar development for EDK2:
Dynamic Tables Framework
https://github.com/tianocore/edk2/tree/master/DynamicTablesPkg
Thanks, I had a quick look. Are you thinking we should try to have a common library for this?
Regards,
Simon