dm: Add programmatic generation of ACPI tables (part B)
cover dm: Add programmatic generation of ACPI tables (part B)
NOTE: I have resent this as v1 to avoid confusion
This is split from the original series in an attempt to get things applied in chunks.
This part includes:
- writing basic ACPI code for integers, strings, names, packages
- writing descriptors for GPIO, I2C, interrupts, SPI
- writing code to enable/disable ACPI peripherals via GPIOs
- writing SSDT and DSDT tables
- additional ways to determine ACPI device names
Much of this code is taken from coreboot and I have tried to avoid changing the original code for no reason. Changes include:
- splitting the acpi_dp functions into their own file
- adding tests
- adding (lots of) comments
- using a context pointer instead of global variables
- tidying up some code where couldn't resist (e.g. acpigen_emit_namestring())
Changes in v1:
- Capitalise ACPI_OPS_PTR
- Split into more patches for review
- Add tests
- Fix 'the an' typo
- Move header definitions into this patch
- Update sandbox driver slightly for testing
- Switch parameter order of _acpi_fill_ssdt() and make it static
- Fix 'sentinal' and 'METHOD_FILL_SDDT' typos
- Correct the commit subject
- Generalise the ACPI function recursion with acpi_recurse_method()
- Generalise the ACPI function recursion with acpi_recurse_method()
- Use OEM_TABLE_ID instead of ACPI_TABLE_CREATOR
- Update ACPI_DSTATUS enum
- Generalise the ACPI function recursion with acpi_recurse_method()
- Use acpi,ddn instead of acpi,desc
- Rename to acpi_device_infer_name()
- Update newly created sandbox tests
Simon Glass (35):
dm: core: Add an ACPI name for the root node
acpi: Add a function to get a device path and scope
acpi: Add a way to check device status
irq: Add a method to convert an interrupt to ACPI
acpi: Support generation of ACPI code
acpi: Support generation of interrupt descriptor
gpio: Add a method to convert a GPIO to ACPI
acpi: Support string output
acpi: Support generation of GPIO descriptor
acpi: Support generation of a GPIO/irq for a device
acpi: Support generation of I2C descriptor
acpi: Support generation of SPI descriptor
acpigen: Support writing a length
acpigen: Support writing a package
acpi: Support writing an integer
acpi: Support writing a string
acpi: Support writing a name
acpi: Support writing a UUID
acpi: Support writing Device Properties objects via _DSD
acpi: Support writing a GPIO
acpi: Support copying properties from device tree to ACPI
acpi: Add support for various misc ACPI opcodes
acpi: Add support for writing a Power Resource
acpi: Add support for writing a GPIO power sequence
acpi: Add support for a generic power sequence
acpi: Add support for SSDT generation
x86: acpi: Move MADT down a bit
acpi: Record the items added to SSDT
acpi: Support ordering SSDT data by device
x86: Allow devices to write an SSDT
acpi: Add support for DSDT generation
x86: Allow devices to write to DSDT
pci: Avoid a crash in device_is_on_pci_bus()
dm: acpi: Enhance acpi_get_name()
acpi: Add an acpi split command
arch/sandbox/dts/test.dts | 14 +- arch/x86/lib/acpi_table.c | 75 ++- cmd/acpi.c | 15 +- doc/device-tree-bindings/chosen.txt | 9 + doc/device-tree-bindings/device.txt | 13 + drivers/core/acpi.c | 207 ++++++- drivers/core/root.c | 13 + drivers/gpio/gpio-uclass.c | 21 + drivers/gpio/sandbox.c | 78 +++ drivers/i2c/sandbox_i2c.c | 1 + drivers/misc/irq-uclass.c | 18 +- drivers/misc/irq_sandbox.c | 16 + drivers/rtc/sandbox_rtc.c | 11 + drivers/spi/sandbox_spi.c | 1 + include/acpi/acpi_device.h | 400 +++++++++++++ include/acpi/acpi_dp.h | 283 +++++++++ include/acpi/acpi_table.h | 6 + include/acpi/acpigen.h | 347 +++++++++++ include/asm-generic/gpio.h | 27 + include/dm/acpi.h | 63 ++ include/dm/device.h | 2 +- include/irq.h | 43 ++ include/spi.h | 4 +- include/test/ut.h | 17 + lib/acpi/Makefile | 3 + lib/acpi/acpi_device.c | 808 ++++++++++++++++++++++++++ lib/acpi/acpi_dp.c | 395 +++++++++++++ lib/acpi/acpigen.c | 475 +++++++++++++++ test/dm/Makefile | 2 + test/dm/acpi.c | 277 ++++++++- test/dm/acpi_dp.c | 510 ++++++++++++++++ test/dm/acpigen.c | 861 ++++++++++++++++++++++++++++ test/dm/gpio.c | 62 ++ test/dm/irq.c | 23 + test/dm/pci.c | 14 + 35 files changed, 5081 insertions(+), 33 deletions(-) create mode 100644 include/acpi/acpi_device.h create mode 100644 include/acpi/acpi_dp.h create mode 100644 include/acpi/acpigen.h create mode 100644 lib/acpi/acpi_device.c create mode 100644 lib/acpi/acpi_dp.c create mode 100644 lib/acpi/acpigen.c create mode 100644 test/dm/acpi_dp.c create mode 100644 test/dm/acpigen.c
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 1/35 dm: core: Add an ACPI name for the root node
This always has a fixed ACPI name so add it as a driver function.
---
Changes in v1:
- Capitalise ACPI_OPS_PTR
drivers/core/root.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/core/root.c +13 -0
@@ -11,6 +11,7 @@#include <fdtdec.h> #include <malloc.h> #include <linux/libfdt.h> +#include <dm/acpi.h> #include <dm/device.h> #include <dm/device-internal.h> #include <dm/lists.h>
@@ -372,10 +373,22 @@ int dm_init_and_scan(bool pre_reloc_only)return 0 ; } +#ifdef CONFIG_ACPIGEN +static int root_acpi_get_name (const struct udevice *dev,char *out_name) +{ +return acpi_copy_name (out_name,"\\_SB" ); +} + +struct acpi_ops root_acpi_ops = { + .get_name = root_acpi_get_name, +}; +#endif +/* This is the root driver - all drivers are children of this */ U_BOOT_DRIVER (root_driver) = { .name ="root_driver" , .id =UCLASS_ROOT , +ACPI_OPS_PTR (&root_acpi_ops) };/* This is the root uclass */
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
Antwort: [PATCH v1 01/35] dm: core: Add an ACPI name for the root node
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 5 lines
Betreff: [PATCH v1 01/35] dm: core: Add an ACPI name for the root node
This always has a fixed ACPI name so add it as a driver function.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v1:
- CapitaliseACPI_OPS_PTR
drivers/core/root.c| 13 +++++++++++++1 file changed, 13 insertions(+)
PATCH 2/35 acpi: Add a function to get a device path and scope
In reply to Simon GlassAdd a function to build up the ACPI path for a device and another for its scope.
---
Changes in v1:
- Split into more patches for review
- Add tests
arch/sandbox/dts/test.dts | 3 ++ include/acpi/acpi_device.h | 44 ++++++++++++++++++ lib/acpi/Makefile | 1 + lib/acpi/acpi_device.c | 82 ++++++++++++++++++++++++++++++++ test/dm/acpi.c | 95 ++++++++++++++++++++++++++++++++------ 5 files changed, 212 insertions(+), 13 deletions(-) create mode 100644 include/acpi/acpi_device.h create mode 100644 lib/acpi/acpi_device.c
arch/sandbox/dts/test.dts +3 -0
@@ -224,6 +224,9 @@ acpi-test { compatible = "denx,u-boot-acpi-test"; + child { + compatible = "denx,u-boot-acpi-test"; + }; }; acpi-test2 {
include/acpi/acpi_device.h new file +44 -0
44 lines not on this page · raw message
lib/acpi/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-y += acpi_device.o obj-y += acpi_table.o
lib/acpi/acpi_device.c new file +82 -0
82 lines not on this page · raw message
test/dm/acpi.c +82 -13
157 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
Antwort: [PATCH v1 02/35] acpi: Add a function to get a device path and scope
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 21 lines
Betreff: [PATCH v1 02/35] acpi: Add a function to get a device path and scope
Add a function to build up the ACPI path for a device and another for its
scope.Signed-off-by Simon Glass <[email protected]>---
Changes in v1:
- Split into more patches for review
- Add testsarch/sandbox/dts/test.dts | 3 ++ include/acpi/acpi_device.h | 44 ++++++++++++++++++ lib/acpi/Makefile | 1 + lib/acpi/acpi_device.c | 82 ++++++++++++++++++++++++++++++++ test/dm/acpi.c | 95 ++++++++++++++++++++++++++++++++------ 5 files changed, 212 insertions(+), 13 deletions(-)
Quoted 2 lines
create mode 100644
include/acpi/acpi_device.hcreate mode 100644lib/acpi/acpi_device.c
PATCH 3/35 acpi: Add a way to check device status
In reply to Simon GlassAt present U-Boot does not support the different ACPI status values, but it is best to put this logic in a central place. Add a function to get the device status.
---
Changes in v1: None
include/acpi/acpi_device.h | 26 ++++++++++++++++++++++++++ lib/acpi/acpi_device.c | 5 +++++ test/dm/acpi.c | 12 ++++++++++++ 3 files changed, 43 insertions(+)
include/acpi/acpi_device.h +26 -0
@@ -14,6 +14,21 @@ struct udevice;/* Length of a full path to an ACPI device */ #define ACPI_PATH_MAX 30 +/* Values that can be returned for ACPI device _STA method */ +enum acpi_dev_status { +ACPI_DSTATUS_PRESENT =BIT (0 ), +ACPI_DSTATUS_ENABLED =BIT (1 ), +ACPI_DSTATUS_SHOW_IN_UI =BIT (2 ), +ACPI_DSTATUS_OK =BIT (3 ), +ACPI_DSTATUS_HAS_BATTERY =BIT (4 ), + +ACPI_DSTATUS_ALL_OFF =0 , +ACPI_DSTATUS_HIDDEN_ON =ACPI_DSTATUS_PRESENT |ACPI_DSTATUS_ENABLED | +ACPI_DSTATUS_OK , +ACPI_DSTATUS_ALL_ON =ACPI_DSTATUS_HIDDEN_ON | +ACPI_DSTATUS_SHOW_IN_UI , +}; +/** * acpi_device_path() - Get the full path to an ACPI device *
@@ -41,4 +56,15 @@ int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);*/ int acpi_device_scope (const struct udevice *dev,char *scope,int maxlen); +/** +* acpi_device_status() - Get the status of a device +* +* This currently just returns ACPI_DSTATUS_ALL_ON. It does not support +* inactive or hidden devices. +* +* @dev: Device to check +* @return device status, as ACPI_DSTATUS_... +*/ +enum acpi_dev_status acpi_device_status (const struct udevice *dev); +#endif
lib/acpi/acpi_device.c +5 -0
@@ -80,3 +80,8 @@ int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen)return 0 ; } + +enum acpi_dev_status acpi_device_status (const struct udevice *dev) +{ +return ACPI_DSTATUS_ALL_ON ; +}
test/dm/acpi.c +12 -0
@@ -384,3 +384,15 @@ static int dm_test_acpi_device_path(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_device_path,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_device_status() */ +static int dm_test_acpi_device_status (struct unit_test_state *uts) +{ +struct udevice *dev; + +ut_assertok (uclass_first_device_err (UCLASS_TEST_ACPI , &dev)); +ut_asserteq (ACPI_DSTATUS_ALL_ON ,acpi_device_status (dev)); + +return 0 ; +} +DM_TEST (dm_test_acpi_device_status,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 4/35 irq: Add a method to convert an interrupt to ACPI
In reply to Simon GlassWhen generating ACPI tables we need to convert IRQs in U-Boot to the ACPI structures required by ACPI. This is a SoC-specific conversion and cannot be handled by generic code, so add a new IRQ method to do the conversion.
---
Changes in v1:
- Fix 'the an' typo
- Move header definitions into this patch
drivers/misc/irq-uclass.c | 18 ++++++++++-- drivers/misc/irq_sandbox.c | 16 +++++++++++ include/acpi/acpi_device.h | 59 ++++++++++++++++++++++++++++++++++++++ include/irq.h | 43 +++++++++++++++++++++++++++ test/dm/irq.c | 22 ++++++++++++++ 5 files changed, 156 insertions(+), 2 deletions(-)
drivers/misc/irq-uclass.c +16 -2
@@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq *irq)const struct irq_ops *ops;log_debug ("(dev=%p, irq=%p)\n" , dev, irq); -if (!irq) -return 0 ; ops =irq_get_ops (dev); irq->dev = dev;
@@ -176,6 +174,22 @@ int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)return 0 ; } +#if CONFIG_IS_ENABLED (ACPIGEN ) +int irq_get_acpi (const struct irq *irq,struct acpi_irq *acpi_irq) +{ +struct irq_ops *ops; + +if (!irq_is_valid (irq)) +return -EINVAL ; + + ops =irq_get_ops (irq->dev); +if (!ops->get_acpi) +return -ENOSYS ; + +return ops->get_acpi (irq, acpi_irq); +} +#endif +UCLASS_DRIVER (irq) = { .id =UCLASS_IRQ , .name ="irq" ,
drivers/misc/irq_sandbox.c +16 -0
@@ -8,6 +8,7 @@#include <common.h> #include <dm.h> #include <irq.h> +#include <acpi/acpi_device.h> #include <asm/test.h> /**
@@ -73,6 +74,18 @@ static int sandbox_irq_of_xlate(struct irq *irq,return 0 ; } +static __maybe_unused int sandbox_get_acpi (const struct irq *irq, +struct acpi_irq *acpi_irq) +{ + acpi_irq->pin = irq->id; + acpi_irq->mode =ACPI_IRQ_LEVEL_TRIGGERED ; + acpi_irq->polarity =ACPI_IRQ_ACTIVE_HIGH ; + acpi_irq->shared =ACPI_IRQ_SHARED ; + acpi_irq->wake =ACPI_IRQ_WAKE ; + +return 0 ; +} +static const struct irq_ops sandbox_irq_ops = { .route_pmc_gpio_gpe = sandbox_route_pmc_gpio_gpe, .set_polarity = sandbox_set_polarity,
@@ -80,6 +93,9 @@ static const struct irq_ops sandbox_irq_ops = { .restore_polarities = sandbox_restore_polarities, .read_and_clear = sandbox_irq_read_and_clear, .of_xlate = sandbox_irq_of_xlate, +#if CONFIG_IS_ENABLED (ACPIGEN ) + .get_acpi = sandbox_get_acpi, +#endif };static const struct udevice_id sandbox_irq_ids[] = {
include/acpi/acpi_device.h +59 -0
71 lines not on this page · raw message
include/irq.h +43 -0
73 lines not on this page · raw message
test/dm/irq.c +22 -0
@@ -8,6 +8,7 @@#include <common.h> #include <dm.h> #include <irq.h> +#include <acpi/acpi_device.h> #include <asm/test.h> #include <dm/test.h> #include <test/ut.h>
@@ -75,3 +76,24 @@ static int dm_test_request(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_request,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test of irq_get_acpi() */ +static int dm_test_irq_get_acpi (struct unit_test_state *uts) +{ +struct acpi_irq airq; +struct udevice *dev; +struct irq irq; + +ut_assertok (uclass_first_device_err (UCLASS_TEST_FDT , &dev)); +ut_assertok (irq_get_by_index (dev,0 , &irq)); + +ut_assertok (irq_get_acpi (&irq, &airq)); +ut_asserteq (3 , airq.pin); +ut_asserteq (ACPI_IRQ_LEVEL_TRIGGERED , airq.mode); +ut_asserteq (ACPI_IRQ_ACTIVE_HIGH , airq.polarity); +ut_asserteq (ACPI_IRQ_SHARED , airq.shared); +ut_asserteq (ACPI_IRQ_WAKE , airq.wake); + +return 0 ; +} +DM_TEST (dm_test_irq_get_acpi,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 5/35 acpi: Support generation of ACPI code
In reply to Simon GlassAdd a new file to handle generating ACPI code programatically. This is used when information must be dynamically added to the tables, e.g. the SSDT.
Initial support is just for writing simple values.
---
Changes in v1: None
include/acpi/acpigen.h | 49 +++++++++++++++++++++++++++++++ lib/acpi/Makefile | 1 + lib/acpi/acpigen.c | 38 ++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/acpigen.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 include/acpi/acpigen.h create mode 100644 lib/acpi/acpigen.c create mode 100644 test/dm/acpigen.c
include/acpi/acpigen.h new file +49 -0
@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Core ACPI (Advanced Configuration and Power Interface) support +* +* Copyright 2019 Google LLC +* +* Modified from coreboot file acpigen.h +*/ + +#ifndef __ACPI_ACPIGEN_H +#define __ACPI_ACPIGEN_H + +#include <linux/types.h> + +struct acpi_ctx ; + +/** +* acpigen_get_current() - Get the current ACPI code output pointer +* +* @ctx: ACPI context pointer +* @return output pointer +*/ +u8 *acpigen_get_current (struct acpi_ctx *ctx); + +/** +* acpigen_emit_byte() - Emit a byte to the ACPI code +* +* @ctx: ACPI context pointer +* @data: Value to output +*/ +void acpigen_emit_byte (struct acpi_ctx *ctx,uint data); + +/** +* acpigen_emit_word() - Emit a 16-bit word to the ACPI code +* +* @ctx: ACPI context pointer +* @data: Value to output +*/ +void acpigen_emit_word (struct acpi_ctx *ctx,uint data); + +/** +* acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code +* +* @ctx: ACPI context pointer +* @data: Value to output +*/ +void acpigen_emit_dword (struct acpi_ctx *ctx,uint data); + +#endif
lib/acpi/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-y += acpigen.o obj-y += acpi_device.o obj-y += acpi_table.o
lib/acpi/acpigen.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Generation of ACPI (Advanced Configuration and Power Interface) tables +* +* Copyright 2019 Google LLC +* Mostly taken from coreboot +*/ + +#define LOG_CATEGORY LOGC_ACPI + +#include <common.h> +#include <dm.h> +#include <acpi/acpigen.h> +#include <dm/acpi.h> + +u8 *acpigen_get_current (struct acpi_ctx *ctx) +{ +return ctx->current; +} + +void acpigen_emit_byte (struct acpi_ctx *ctx,uint data) +{ + *(u8 *)ctx->current++ = data; +} + +void acpigen_emit_word (struct acpi_ctx *ctx,uint data) +{ +acpigen_emit_byte (ctx, data &0xff ); +acpigen_emit_byte (ctx, (data >>8 ) &0xff ); +} + +void acpigen_emit_dword (struct acpi_ctx *ctx,uint data) +{ +acpigen_emit_byte (ctx, data &0xff ); +acpigen_emit_byte (ctx, (data >>8 ) &0xff ); +acpigen_emit_byte (ctx, (data >>16 ) &0xff ); +acpigen_emit_byte (ctx, (data >>24 ) &0xff ); +}
test/dm/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_ACPIGEN) += acpi.o +obj-$(CONFIG_ACPIGEN) += acpigen.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o
test/dm/acpigen.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 6/35 acpi: Support generation of interrupt descriptor
In reply to Simon GlassAdd a function to write an interrupt descriptor to the generated ACPI code.
---
Changes in v1: None
include/acpi/acpi_device.h | 15 +++++ lib/acpi/acpi_device.c | 118 +++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 31 ++++++++++ 3 files changed, 164 insertions(+)
include/acpi/acpi_device.h +15 -0
@@ -9,6 +9,8 @@#ifndef __ACPI_DEVICE_H#define __ACPI_DEVICE_H +struct acpi_ctx ; +struct irq ;struct udevice ;/* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */
@@ -126,4 +128,17 @@ int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);*/ enum acpi_dev_status acpi_device_status (const struct udevice *dev); +/** +* acpi_device_write_interrupt_irq() - Write an interrupt descriptor +* +* This writes an ACPI interrupt descriptor for the given interrupt, converting +* fields as needed. +* +* @ctx: ACPI context pointer +* @req_irq: Interrupt to output +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx, +const struct irq *req_irq); +#endif
lib/acpi/acpi_device.c +118 -0
127 lines not on this page · raw message
test/dm/acpigen.c +31 -0
@@ -8,8 +8,10 @@#include <common.h> #include <dm.h> +#include <irq.h> #include <malloc.h> #include <acpi/acpigen.h> +#include <acpi/acpi_device.h> #include <asm/unaligned.h> #include <dm/acpi.h> #include <dm/test.h>
@@ -63,3 +65,32 @@ static int dm_test_acpi_emit_simple(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_emit_simple,0 ); + +/* Test emitting an interrupt descriptor */ +static int dm_test_acpi_interrupt (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +struct udevice *dev; +struct irq irq; +u8 *ptr; + +ut_assertok (alloc_context (&ctx)); + + ptr =acpigen_get_current (ctx); + +ut_assertok (uclass_first_device_err (UCLASS_TEST_FDT , &dev)); +ut_assertok (irq_get_by_index (dev,0 , &irq)); + +ut_assertok (acpi_device_write_interrupt_irq (ctx, &irq)); +ut_asserteq (9 ,acpigen_get_current (ctx) - ptr); +ut_asserteq (ACPI_DESCRIPTOR_INTERRUPT , ptr[0 ]); +ut_asserteq (6 ,get_unaligned ((u16 *)(ptr +1 ))); +ut_asserteq (0x19 , ptr[3 ]); +ut_asserteq (1 , ptr[4 ]); +ut_asserteq (3 ,get_unaligned ((u32 *)(ptr +5 ))); + +free_context (&ctx); + +return 0 ; +} +DM_TEST (dm_test_acpi_interrupt,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 7/35 gpio: Add a method to convert a GPIO to ACPI
In reply to Simon GlassWhen generating ACPI tables we need to convert GPIOs in U-Boot to the ACPI structures required by ACPI. This is a SoC-specific conversion and cannot be handled by generic code, so add a new GPIO method to do the conversion.
---
Changes in v1:
- Update sandbox driver slightly for testing
drivers/gpio/gpio-uclass.c | 21 +++++++++ drivers/gpio/sandbox.c | 78 +++++++++++++++++++++++++++++++++ include/acpi/acpi_device.h | 90 ++++++++++++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 27 ++++++++++++ test/dm/gpio.c | 62 ++++++++++++++++++++++++++ test/dm/irq.c | 1 + 6 files changed, 279 insertions(+)
drivers/gpio/gpio-uclass.c +21 -0
@@ -13,6 +13,7 @@#include <errno.h> #include <fdtdec.h> #include <malloc.h> +#include <acpi/acpi_device.h> #include <asm/gpio.h> #include <linux/bug.h> #include <linux/ctype.h>
@@ -793,6 +794,26 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)return 0 ; } +#if CONFIG_IS_ENABLED (ACPIGEN ) +int gpio_get_acpi (const struct gpio_desc *desc,struct acpi_gpio *gpio) +{ +struct dm_gpio_ops *ops; + +if (!dm_gpio_is_valid (desc)) { +/* Indicate that the GPIO is not valid */ + gpio->pin_count =0 ; + gpio->pins[0 ] =0 ; +return -EINVAL ; + } + + ops =gpio_get_ops (desc->dev); +if (!ops->get_acpi) +return -ENOSYS ; + +return ops->get_acpi (desc, gpio); +} +#endif +int gpio_claim_vector (const int *gpio_num_array,const char *fmt) {int i, ret;
drivers/gpio/sandbox.c +78 -0
119 lines not on this page · raw message
include/acpi/acpi_device.h +90 -0
96 lines not on this page · raw message
include/asm-generic/gpio.h +27 -0
@@ -9,6 +9,7 @@#include <dm/ofnode.h> +struct acpi_gpio ;struct ofnode_phandle_args ;/*
@@ -328,6 +329,20 @@ struct dm_gpio_ops {*/ int (*get_dir_flags)(struct udevice *dev,unsigned int offset,ulong *flags); + +#if CONFIG_IS_ENABLED (ACPIGEN ) +/** +* get_acpi() - Get the ACPI info for a GPIO +* +* This converts a GPIO to an ACPI structure for adding to the ACPI +* tables. +* +* @desc: GPIO description to convert +* @gpio: Output ACPI GPIO information +* @return ACPI pin number or -ve on error +*/ +int (*get_acpi)(const struct gpio_desc *desc,struct acpi_gpio *gpio); +#endif };/**
@@ -673,4 +688,16 @@ int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags);*/ int gpio_get_number (const struct gpio_desc *desc); +/** +* gpio_get_acpi() - Get the ACPI pin for a GPIO +* +* This converts a GPIO to an ACPI pin number for adding to the ACPI +* tables. If the GPIO is invalid, the pin_count and pins[0] are set to 0 +* +* @desc: GPIO description to convert +* @gpio: Output ACPI GPIO information +* @return ACPI pin number or -ve on error +*/ +int gpio_get_acpi (const struct gpio_desc *desc,struct acpi_gpio *gpio); +#endif /* _ASM_GENERIC_GPIO_H_ */
test/dm/gpio.c +62 -0
71 lines not on this page · raw message
test/dm/irq.c +1 -0
@@ -87,6 +87,7 @@ static int dm_test_irq_get_acpi(struct unit_test_state *uts)ut_assertok (uclass_first_device_err (UCLASS_TEST_FDT , &dev));ut_assertok (irq_get_by_index (dev,0 , &irq)); +/* see sandbox_get_acpi() */ ut_assertok (irq_get_acpi (&irq, &airq));ut_asserteq (3 , airq.pin);ut_asserteq (ACPI_IRQ_LEVEL_TRIGGERED , airq.mode);
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 8/35 acpi: Support string output
In reply to Simon GlassAdd support for output of strings and streams of bytes.
---
Changes in v1: None
include/acpi/acpigen.h | 19 +++++++++++++++++++ lib/acpi/acpigen.c | 14 ++++++++++++++ test/dm/acpigen.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+)
include/acpi/acpigen.h +19 -0
@@ -46,4 +46,23 @@ void acpigen_emit_word(struct acpi_ctx *ctx, uint data);*/ void acpigen_emit_dword (struct acpi_ctx *ctx,uint data); +/** +* acpigen_emit_stream() - Emit a stream of bytes +* +* @ctx: ACPI context pointer +* @data: Data to output +* @size: Size of data in bytes +*/ +void acpigen_emit_stream (struct acpi_ctx *ctx,const char *data,int size); + +/** +* acpigen_emit_string() - Emit a string +* +* Emit a string with a nul terminator +* +* @ctx: ACPI context pointer +* @str: String to output, or NULL for an empty string +*/ +void acpigen_emit_string (struct acpi_ctx *ctx,const char *str); +#endif
lib/acpi/acpigen.c +14 -0
@@ -36,3 +36,17 @@ void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)acpigen_emit_byte (ctx, (data >>16 ) &0xff );acpigen_emit_byte (ctx, (data >>24 ) &0xff ); } + +void acpigen_emit_stream (struct acpi_ctx *ctx,const char *data,int size) +{ +int i; + +for (i =0 ; i < size; i++) +acpigen_emit_byte (ctx, data[i]); +} + +void acpigen_emit_string (struct acpi_ctx *ctx,const char *str) +{ +acpigen_emit_stream (ctx, str, str ?strlen (str) :0 ); +acpigen_emit_byte (ctx,'\0' );/* NUL */ +}
test/dm/acpigen.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 9/35 acpi: Support generation of GPIO descriptor
In reply to Simon GlassAdd a function to write a GPIO descriptor to the generated ACPI code.
---
Changes in v1: None
include/acpi/acpi_device.h | 22 ++++++ lib/acpi/acpi_device.c | 151 +++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 89 ++++++++++++++++++++++ 3 files changed, 262 insertions(+)
include/acpi/acpi_device.h +22 -0
@@ -10,6 +10,7 @@#define __ACPI_DEVICE_Hstruct acpi_ctx ; +struct gpio_desc ;struct irq ;struct udevice ;
@@ -231,4 +232,25 @@ enum acpi_dev_status acpi_device_status(const struct udevice *dev);int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx,const struct irq *req_irq); +/** +* acpi_device_write_gpio() - Write GpioIo() or GpioInt() descriptor +* +* @gpio: GPIO information to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_gpio (struct acpi_ctx *ctx,const struct acpi_gpio *gpio); + +/** +* acpi_device_write_gpio_desc() - Write a GPIO to ACPI +* +* This creates a GPIO descriptor for a GPIO, including information ACPI needs +* to use it. The type is always ACPI_GPIO_TYPE_IO. +* +* @ctx: ACPI context pointer +* @desc: GPIO to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_gpio_desc (struct acpi_ctx *ctx, +const struct gpio_desc *desc); +#endif
lib/acpi/acpi_device.c +151 -0
160 lines not on this page · raw message
test/dm/acpigen.c +89 -0
98 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 10/35 acpi: Support generation of a GPIO/irq for a device
In reply to Simon GlassSome devices use interrupts but some use GPIOs. Since these are fully specified in the device tree we can automatically produce the correct ACPI descriptor for a device.
Add a function to handle this.
---
Changes in v1: None
include/acpi/acpi_device.h | 15 ++++++++++++++ lib/acpi/acpi_device.c | 26 ++++++++++++++++++++++++ test/dm/acpigen.c | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+)
include/acpi/acpi_device.h +15 -0
@@ -253,4 +253,19 @@ int acpi_device_write_gpio(struct acpi_ctx *ctx, const struct acpi_gpio *gpio);int acpi_device_write_gpio_desc (struct acpi_ctx *ctx,const struct gpio_desc *desc); +/** +* acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to ACPI +* +* This reads an interrupt from the device tree "interrupts-extended" property, +* if available. If not it reads the first GPIO with the name @prop. +* +* If an interrupt is found, an ACPI interrupt descriptor is written to the ACPI +* output. If not, but an GPIO is found, a GPIO descriptor is written. +* +* @return 0 if OK, -ve if neither an interrupt nor a GPIO could be found, or +* some other error occurred +*/ +int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop); +#endif
lib/acpi/acpi_device.c +26 -0
@@ -354,3 +354,29 @@ int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,return 0 ; } + +int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop) +{ +struct irq req_irq; +int ret; + + ret =irq_get_by_index (dev,0 , &req_irq); +if (!ret) { + ret =acpi_device_write_interrupt_irq (ctx, &req_irq); +if (ret) +return log_msg_ret ("irq" , ret); + }else { +struct gpio_desc req_gpio; + + ret =gpio_request_by_name (dev, prop,0 , &req_gpio, +GPIOD_IS_IN ); +if (ret) +return log_msg_ret ("no gpio" , ret); + ret =acpi_device_write_gpio_desc (ctx, &req_gpio); +if (ret) +return log_msg_ret ("gpio" , ret); + } + +return 0 ; +}
test/dm/acpigen.c +41 -0
50 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 11/35 acpi: Support generation of I2C descriptor
In reply to Simon GlassAdd a function to write a GPIO descriptor to the generated ACPI code.
---
Changes in v1: None
drivers/i2c/sandbox_i2c.c | 11 ++++ drivers/rtc/sandbox_rtc.c | 11 ++++ include/acpi/acpi_device.h | 37 +++++++++++++ lib/acpi/acpi_device.c | 103 +++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 32 ++++++++++++ 5 files changed, 194 insertions(+)
drivers/i2c/sandbox_i2c.c +11 -0
@@ -10,6 +10,7 @@#include <errno.h> #include <i2c.h> #include <asm/test.h> +#include <dm/acpi.h> #include <dm/lists.h> #include <dm/device-internal.h>
@@ -82,6 +83,15 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,return ops->xfer (emul, msg, nmsgs); } +static int sandbox_i2c_get_name (const struct udevice *dev,char *out_name) +{ +return acpi_copy_name (out_name,"SI2C" ); +} + +struct acpi_ops sandbox_i2c_acpi_ops = { + .get_name = sandbox_i2c_get_name, +}; +static const struct dm_i2c_ops sandbox_i2c_ops = { .xfer = sandbox_i2c_xfer, };
@@ -97,4 +107,5 @@ U_BOOT_DRIVER(i2c_sandbox) = { .of_match = sandbox_i2c_ids, .ops = &sandbox_i2c_ops, .priv_auto_alloc_size = sizeof(struct sandbox_i2c_priv), + ACPI_OPS_PTR(&sandbox_i2c_acpi_ops) };
drivers/rtc/sandbox_rtc.c +11 -0
@@ -9,6 +9,7 @@#include <i2c.h> #include <rtc.h> #include <asm/rtc.h> +#include <dm/acpi.h> #define REG_COUNT 0x80
@@ -84,6 +85,15 @@ static int sandbox_rtc_write8(struct udevice *dev, unsigned int reg, int val)return dm_i2c_reg_write (dev, reg, val); } +static int sandbox_rtc_get_name (const struct udevice *dev,char *out_name) +{ +return acpi_copy_name (out_name,"RTCC" ); +} + +struct acpi_ops sandbox_rtc_acpi_ops = { + .get_name = sandbox_rtc_get_name, +}; +static const struct rtc_ops sandbox_rtc_ops = { .get = sandbox_rtc_get, .set = sandbox_rtc_set,
@@ -102,4 +112,5 @@ U_BOOT_DRIVER(rtc_sandbox) = { .id = UCLASS_RTC, .of_match = sandbox_rtc_ids, .ops = &sandbox_rtc_ops, + ACPI_OPS_PTR(&sandbox_rtc_acpi_ops) };
include/acpi/acpi_device.h +37 -0
@@ -9,6 +9,8 @@#ifndef __ACPI_DEVICE_H#define __ACPI_DEVICE_H +#include <i2c.h> +struct acpi_ctx ;struct gpio_desc ;struct irq ;
@@ -181,6 +183,29 @@ struct acpi_gpio {enum acpi_gpio_polarity polarity; }; +/* ACPI Descriptors for Serial Bus interfaces */ +#define ACPI_SERIAL_BUS_TYPE_I2C 1 +#define ACPI_SERIAL_BUS_TYPE_SPI 2 +#define ACPI_I2C_SERIAL_BUS_REVISION_ID 1/* TODO: upgrade to 2 */ +#define ACPI_I2C_TYPE_SPECIFIC_REVISION_ID 1 +#define ACPI_SPI_SERIAL_BUS_REVISION_ID 1 +#define ACPI_SPI_TYPE_SPECIFIC_REVISION_ID 1 + +/** +* struct acpi_i2c - representation of an ACPI I2C device +* +* @address: 7-bit or 10-bit I2C address +* @mode_10bit: Which address size is used +* @speed: Bus speed in Hz +* @resource: Resource name for the I2C controller +*/ +struct acpi_i2c { +u16 address; +enum i2c_address_mode mode_10bit; +enum i2c_speed_rate speed; +const char *resource; +}; +/** * acpi_device_path() - Get the full path to an ACPI device *
@@ -268,4 +293,16 @@ int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx,struct udevice *dev,const char *prop); +/** +* acpi_device_write_i2c_dev() - Write an I2C device to ACPI +* +* This creates a I2cSerialBus descriptor for an I2C device, including +* information ACPI needs to use it. +* +* @ctx: ACPI context pointer +* @dev: I2C device to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_i2c_dev (struct acpi_ctx *ctx,const struct udevice *dev); +#endif
lib/acpi/acpi_device.c +103 -0
106 lines not on this page · raw message
test/dm/acpigen.c +32 -0
@@ -266,3 +266,35 @@ static int dm_test_acpi_interrupt_or_gpio(struct unit_test_state *uts) }DM_TEST (dm_test_acpi_interrupt_or_gpio,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test emitting an I2C descriptor */ +static int dm_test_acpi_i2c (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +struct udevice *dev; +u8 *ptr; + +ut_assertok (alloc_context (&ctx)); + + ptr =acpigen_get_current (ctx); + +ut_assertok (uclass_get_device (UCLASS_RTC ,0 , &dev)); +ut_assertok (acpi_device_write_i2c_dev (ctx, dev)); +ut_asserteq (28 ,acpigen_get_current (ctx) - ptr); +ut_asserteq (ACPI_DESCRIPTOR_SERIAL_BUS , ptr[0 ]); +ut_asserteq (25 ,get_unaligned ((u16 *)(ptr +1 ))); +ut_asserteq (ACPI_I2C_SERIAL_BUS_REVISION_ID , ptr[3 ]); +ut_asserteq (0 , ptr[4 ]); +ut_asserteq (ACPI_SERIAL_BUS_TYPE_I2C , ptr[5 ]); +ut_asserteq (0 ,get_unaligned ((u16 *)(ptr +7 ))); +ut_asserteq (ACPI_I2C_TYPE_SPECIFIC_REVISION_ID , ptr[9 ]); +ut_asserteq (6 ,get_unaligned ((u16 *)(ptr +10 ))); +ut_asserteq (100000 ,get_unaligned ((u32 *)(ptr +12 ))); +ut_asserteq (0x43 ,get_unaligned ((u16 *)(ptr +16 ))); +ut_asserteq_str ("\\_SB.SI2C" , (char *)ptr +18 ); + +free_context (&ctx); + +return 0 ; +} +DM_TEST (dm_test_acpi_i2c,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 12/35 acpi: Support generation of SPI descriptor
In reply to Simon GlassAdd a function to write a SPI descriptor to the generated ACPI code.
---
Changes in v1: None
drivers/spi/sandbox_spi.c | 11 ++++ include/acpi/acpi_device.h | 36 +++++++++++ include/spi.h | 4 +- lib/acpi/acpi_device.c | 119 +++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 36 +++++++++++ 5 files changed, 204 insertions(+), 2 deletions(-)
drivers/spi/sandbox_spi.c +11 -0
@@ -20,6 +20,7 @@#include <linux/errno.h> #include <asm/spi.h> #include <asm/state.h> +#include <dm/acpi.h> #include <dm/device-internal.h> #ifndef CONFIG_SPI_IDLE_VAL
@@ -132,6 +133,15 @@ static int sandbox_spi_get_mmap(struct udevice *dev, ulong *map_basep,return 0 ; } +static int sandbox_spi_get_name (const struct udevice *dev,char *out_name) +{ +return acpi_copy_name (out_name,"SSPI" ); +} + +struct acpi_ops sandbox_spi_acpi_ops = { + .get_name = sandbox_spi_get_name, +}; +static const struct dm_spi_ops sandbox_spi_ops = { .xfer = sandbox_spi_xfer, .set_speed = sandbox_spi_set_speed,
@@ -150,4 +160,5 @@ U_BOOT_DRIVER(spi_sandbox) = { .id = UCLASS_SPI, .of_match = sandbox_spi_ids, .ops = &sandbox_spi_ops, + ACPI_OPS_PTR(&sandbox_spi_acpi_ops) };
include/acpi/acpi_device.h +36 -0
@@ -10,6 +10,7 @@#define __ACPI_DEVICE_H#include <i2c.h> +#include <spi.h> struct acpi_ctx ;struct gpio_desc ;
@@ -206,6 +207,29 @@ struct acpi_i2c {const char *resource; }; +/** +* struct acpi_spi - representation of an ACPI SPI device +* +* @device_select: Chip select used by this device (typically 0) +* @device_select_polarity: Polarity for the device +* @wire_mode: Number of wires used for SPI +* @speed: Bus speed in Hz +* @data_bit_length: Word length for SPI (typically 8) +* @clock_phase: Clock phase to capture data +* @clock_polarity: Bus polarity +* @resource: Resource name for the SPI controller +*/ +struct acpi_spi { +u16 device_select; +enum spi_polarity device_select_polarity; +enum spi_wire_mode wire_mode; +unsigned int speed; +u8 data_bit_length; +enum spi_clock_phase clock_phase; +enum spi_polarity clock_polarity; +const char *resource; +}; +/** * acpi_device_path() - Get the full path to an ACPI device *
@@ -305,4 +329,16 @@ int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx,*/ int acpi_device_write_i2c_dev (struct acpi_ctx *ctx,const struct udevice *dev); +/** +* acpi_device_write_spi_dev() - Write a SPI device to ACPI +* +* This writes a serial bus descriptor for the SPI device so that ACPI can use +* it +* +* @ctx: ACPI context pointer +* @dev: SPI device to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_spi_dev (struct acpi_ctx *ctx,const struct udevice *dev); +#endif
include/spi.h +2 -2
@@ -12,8 +12,8 @@#include <common.h> /* SPI mode flags */ -#define SPI_CPHA BIT(0)/* clock phase */ -#define SPI_CPOL BIT(1)/* clock polarity */ +#define SPI_CPHA BIT(0)/* clock phase (1 = SPI_CLOCK_PHASE_SECOND) */ +#define SPI_CPOL BIT(1)/* clock polarity (1 = SPI_POLARITY_HIGH) */ #define SPI_MODE_0 (0|0)/* (original MicroWire) */ #define SPI_MODE_1 (0|SPI_CPHA)#define SPI_MODE_2 (SPI_CPOL|0)
lib/acpi/acpi_device.c +119 -0
122 lines not on this page · raw message
test/dm/acpigen.c +36 -0
@@ -298,3 +298,39 @@ static int dm_test_acpi_i2c(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_i2c,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test emitting a SPI descriptor */ +static int dm_test_acpi_spi (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +struct udevice *dev; +u8 *ptr; + +ut_assertok (alloc_context (&ctx)); + + ptr =acpigen_get_current (ctx); + +ut_assertok (uclass_first_device_err (UCLASS_SPI_FLASH , &dev)); +ut_assertok (acpi_device_write_spi_dev (ctx, dev)); +ut_asserteq (31 ,acpigen_get_current (ctx) - ptr); +ut_asserteq (ACPI_DESCRIPTOR_SERIAL_BUS , ptr[0 ]); +ut_asserteq (28 ,get_unaligned ((u16 *)(ptr +1 ))); +ut_asserteq (ACPI_SPI_SERIAL_BUS_REVISION_ID , ptr[3 ]); +ut_asserteq (0 , ptr[4 ]); +ut_asserteq (ACPI_SERIAL_BUS_TYPE_SPI , ptr[5 ]); +ut_asserteq (2 , ptr[6 ]); +ut_asserteq (0 ,get_unaligned ((u16 *)(ptr +7 ))); +ut_asserteq (ACPI_SPI_TYPE_SPECIFIC_REVISION_ID , ptr[9 ]); +ut_asserteq (9 ,get_unaligned ((u16 *)(ptr +10 ))); +ut_asserteq (40000000 ,get_unaligned ((u32 *)(ptr +12 ))); +ut_asserteq (8 , ptr[16 ]); +ut_asserteq (0 , ptr[17 ]); +ut_asserteq (0 , ptr[18 ]); +ut_asserteq (0 ,get_unaligned ((u16 *)(ptr +19 ))); +ut_asserteq_str ("\\_SB.SSPI" , (char *)ptr +21 ); + +free_context (&ctx); + +return 0 ; +} +DM_TEST (dm_test_acpi_spi,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 13/35 acpigen: Support writing a length
In reply to Simon GlassIt is convenient to write a length value for preceding a block of data. Of course the length is not known or is hard to calculate a priori. So add a way to mark the start on a stack, so the length can be updated when known.
---
Changes in v1: None
include/acpi/acpigen.h | 3 ++ include/dm/acpi.h | 7 +++++ lib/acpi/acpigen.c | 32 +++++++++++++++++++++ test/dm/acpigen.c | 64 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 104 insertions(+), 2 deletions(-)
include/acpi/acpigen.h +3 -0
@@ -65,4 +65,7 @@ void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);*/ void acpigen_emit_string (struct acpi_ctx *ctx,const char *str); +void acpigen_write_len_f (struct acpi_ctx *ctx); +void acpigen_pop_len (struct acpi_ctx *ctx); +#endif
include/dm/acpi.h +7 -0
@@ -22,6 +22,9 @@/* Length of an ACPI name string including nul terminator */ #define ACPI_NAME_MAX (ACPI_NAME_LEN + 1) +/* Number of nested objects supported */ +#define ACPIGEN_LENSTACK_SIZE 10 +#if !defined(__ACPI__)/**
@@ -34,12 +37,16 @@* 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 +* @len_stack: Stack of 'length' words to fix up later +* @ltop: Points to current top of stack (0 = empty) */ struct acpi_ctx {void *current;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt; +char *len_stack[ACPIGEN_LENSTACK_SIZE ]; +int ltop; };/**
lib/acpi/acpigen.c +32 -0
@@ -37,6 +37,38 @@ void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)acpigen_emit_byte (ctx, (data >>24 ) &0xff ); } +/* +* Maximum length for an ACPI object generated by this code, +* +* If you need to change this, change acpigen_write_len_f(ctx) and +* acpigen_pop_len(ctx) +*/ +#define ACPIGEN_MAXLEN 0xfffff + +void acpigen_write_len_f (struct acpi_ctx *ctx) +{ +assert (ctx->ltop < (ACPIGEN_LENSTACK_SIZE -1 )); + ctx->len_stack[ctx->ltop++] = ctx->current; +acpigen_emit_byte (ctx,0 ); +acpigen_emit_byte (ctx,0 ); +acpigen_emit_byte (ctx,0 ); +} + +void acpigen_pop_len (struct acpi_ctx *ctx) +{ +int len; +char *p; + +assert (ctx->ltop >0 ); + p = ctx->len_stack[--ctx->ltop]; + len = ctx->current - (void *)p; +assert (len <=ACPIGEN_MAXLEN ); +/* generate store length for 0xfffff max */ + p[0 ] = (0x80 | (len &0xf )); + p[1 ] = (len >>4 &0xff ); + p[2 ] = (len >>12 &0xff ); +} +void acpigen_emit_stream (struct acpi_ctx *ctx,const char *data,int size) {int i;
test/dm/acpigen.c +62 -2
85 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 14/35 acpigen: Support writing a package
In reply to Simon GlassA package collects together several elements. Add an easy way of writing a package header and updating its length later.
---
Changes in v1: None
include/acpi/acpigen.h | 62 ++++++++++++++++++++++++++++++++++++++++++ lib/acpi/acpigen.c | 12 ++++++++ test/dm/acpigen.c | 27 ++++++++++++++++++ 3 files changed, 101 insertions(+)
include/acpi/acpigen.h +62 -0
@@ -14,6 +14,11 @@struct acpi_ctx ; +/* ACPI Op/Prefix codes */ +enum { +PACKAGE_OP =0x12 , +}; +/** * acpigen_get_current() - Get the current ACPI code output pointer *
@@ -65,7 +70,64 @@ void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);*/ void acpigen_emit_string (struct acpi_ctx *ctx,const char *str); +/** +* acpigen_write_len_f() - Write a 'forward' length placeholder +* +* This adds space for a length value in the ACPI stream and pushes the current +* position (before the length) on the stack. After calling this you can write +* some data and then call acpigen_pop_len() to update the length value. +* +* Usage: +* +* acpigen_write_len_f() ------\ +* acpigen_write...() | +* acpigen_write...() | +* acpigen_write_len_f() --\ | +* acpigen_write...() | | +* acpigen_write...() | | +* acpigen_pop_len() ------/ | +* acpigen_write...() | +* acpigen_pop_len() ----------/ +* +* @ctx: ACPI context pointer +*/ void acpigen_write_len_f (struct acpi_ctx *ctx); + +/** +* acpigen_pop_len() - Update the previously stacked length placeholder +* +* Call this after the data for the block gas been written. It updates the +* top length value in the stack and pops it off. +* +* @ctx: ACPI context pointer +*/ void acpigen_pop_len (struct acpi_ctx *ctx); +/** +* acpigen_write_package() - Start writing a package +* +* A package collects together a number of elements in the ACPI code. To write +* a package use: +* +* acpigen_write_package(ctx, 3); +* ...write things +* acpigen_pop_len() +* +* If you don't know the number of elements in advance, acpigen_write_package() +* returns a pointer to the value so you can update it later: +* +* char *num_elements = acpigen_write_package(ctx, 0); +* ...write things +* *num_elements += 1; +* ...write things +* *num_elements += 1; +* acpigen_pop_len() +* +* @ctx: ACPI context pointer +* @nr_el: Number of elements (0 if not known) +* @returns pointer to the number of elements, which can be updated by the +* caller if needed +*/ +char *acpigen_write_package (struct acpi_ctx *ctx,int nr_el); +#endif
lib/acpi/acpigen.c +12 -0
@@ -69,6 +69,18 @@ void acpigen_pop_len(struct acpi_ctx *ctx) p[2 ] = (len >>12 &0xff ); } +char *acpigen_write_package (struct acpi_ctx *ctx,int nr_el) +{ +char *p; + +acpigen_emit_byte (ctx,PACKAGE_OP ); +acpigen_write_len_f (ctx); + p = ctx->current; +acpigen_emit_byte (ctx, nr_el); + +return p; +} +void acpigen_emit_stream (struct acpi_ctx *ctx,const char *data,int size) {int i;
test/dm/acpigen.c +27 -0
@@ -394,3 +394,30 @@ static int dm_test_acpi_len(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_len,0 ); + +/* Test emitting a package */ +static int dm_test_acpi_package (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +char *num_elements; +u8 *ptr; + +ut_assertok (alloc_context (&ctx)); + + ptr =acpigen_get_current (ctx); + + num_elements =acpigen_write_package (ctx,3 ); +ut_asserteq_ptr (num_elements, ptr +4 ); + +/* For easy of testing, just emit a byte, not valid package contents */ +acpigen_emit_byte (ctx,0x23 ); +acpigen_pop_len (ctx); +ut_asserteq (PACKAGE_OP , ptr[0 ]); +ut_asserteq (5 ,get_length (ptr +1 )); +ut_asserteq (3 , ptr[4 ]); + +free_context (&ctx); + +return 0 ; +} +DM_TEST (dm_test_acpi_package,0 );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 15/35 acpi: Support writing an integer
In reply to Simon GlassACPI supports storing integers in various ways. Add a function to handle this.
---
Changes in v1: None
include/acpi/acpigen.h | 17 ++++++++++++++ lib/acpi/acpigen.c | 51 ++++++++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+)
include/acpi/acpigen.h +17 -0
@@ -16,6 +16,12 @@ struct acpi_ctx;/* ACPI Op/Prefix codes */ enum { +ZERO_OP =0x00 , +ONE_OP =0x01 , +BYTE_PREFIX =0x0a , +WORD_PREFIX =0x0b , +DWORD_PREFIX =0x0c , +QWORD_PREFIX =0x0e ,PACKAGE_OP =0x12 , };
@@ -130,4 +136,15 @@ void acpigen_pop_len(struct acpi_ctx *ctx);*/ char *acpigen_write_package (struct acpi_ctx *ctx,int nr_el); +/** +* acpigen_write_integer() - Write an integer +* +* This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on +* the integer size) and an integer value. Note that WORD means 16 bits in ACPI. +* +* @ctx: ACPI context pointer +* @data: Integer to write +*/ +void acpigen_write_integer (struct acpi_ctx *ctx,u64 data); +#endif
lib/acpi/acpigen.c +51 -0
57 lines not on this page · raw message
test/dm/acpigen.c +46 -0
55 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 16/35 acpi: Support writing a string
In reply to Simon GlassACPI supports storing a simple nul-terminated string. Add support for this.
---
Changes in v1: None
include/acpi/acpigen.h | 10 ++++++++++ lib/acpi/acpigen.c | 6 ++++++ test/dm/acpigen.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-)
include/acpi/acpigen.h +10 -0
@@ -21,6 +21,7 @@ enum {BYTE_PREFIX =0x0a ,WORD_PREFIX =0x0b ,DWORD_PREFIX =0x0c , +STRING_PREFIX =0x0d ,QWORD_PREFIX =0x0e , PACKAGE_OP = 0x12, };
@@ -147,4 +148,13 @@ char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);*/ void acpigen_write_integer (struct acpi_ctx *ctx,u64 data); +/** +* acpigen_write_string() - Write a string +* +* This writes a STRING_PREFIX followed by a nul-terminated string +* +* @ctx: ACPI context pointer +* @str: String to write +*/ +void acpigen_write_string (struct acpi_ctx *ctx,const char *str);#endif
lib/acpi/acpigen.c +6 -0
@@ -145,3 +145,9 @@ void acpigen_emit_string(struct acpi_ctx *ctx, const char *str)acpigen_emit_stream (ctx, str, str ?strlen (str) :0 );acpigen_emit_byte (ctx,'\0' );/* NUL */ } + +void acpigen_write_string (struct acpi_ctx *ctx,const char *str) +{ +acpigen_emit_byte (ctx,STRING_PREFIX ); +acpigen_emit_string (ctx, str); +}
test/dm/acpigen.c +30 -2
@@ -20,6 +20,7 @@#include <test/ut.h> #define TEST_STRING "frogmore" +#define TEST_STRING2 "ranch"#define TEST_STREAM2 "\xfa\xde"#define TEST_INT8 0x7d
@@ -400,7 +401,7 @@ static int dm_test_acpi_len(struct unit_test_state *uts) }DM_TEST (dm_test_acpi_len,0 ); -/* Test emitting a package */ +/* Test writing a package */ static int dm_test_acpi_package (struct unit_test_state *uts) {struct acpi_ctx *ctx;
@@ -427,7 +428,7 @@ static int dm_test_acpi_package(struct unit_test_state *uts) }DM_TEST (dm_test_acpi_package,0 ); -/* Test emitting an integer */ +/* Test writing an integer */ static int dm_test_acpi_integer (struct unit_test_state *uts) {struct acpi_ctx *ctx;
@@ -467,3 +468,30 @@ static int dm_test_acpi_integer(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_integer,0 ); + +/* Test writing a string */ +static int dm_test_acpi_string (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +u8 *ptr; + +ut_assertok (alloc_context (&ctx)); + + ptr =acpigen_get_current (ctx); + +acpigen_write_string (ctx,TEST_STRING ); +acpigen_write_string (ctx,TEST_STRING2 ); + +ut_asserteq (2 +sizeof (TEST_STRING ) +sizeof (TEST_STRING2 ), +acpigen_get_current (ctx) - ptr); +ut_asserteq (STRING_PREFIX , ptr[0 ]); +ut_asserteq_str (TEST_STRING , (char *)ptr +1 ); + ptr +=1 +sizeof (TEST_STRING ); +ut_asserteq (STRING_PREFIX , ptr[0 ]); +ut_asserteq_str (TEST_STRING2 , (char *)ptr +1 ); + +free_context (&ctx); + +return 0 ; +} +DM_TEST (dm_test_acpi_string,0 );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 17/35 acpi: Support writing a name
In reply to Simon GlassACPI supports storing names which are made up of multiple path components. Several special cases are supported. Add a function to emit a name.
---
Changes in v1: None
include/acpi/acpigen.h | 25 +++++++++++ include/test/ut.h | 17 ++++++++ lib/acpi/acpigen.c | 96 ++++++++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 93 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 231 insertions(+)
include/acpi/acpigen.h +25 -0
@@ -18,12 +18,15 @@ struct acpi_ctx;enum {ZERO_OP =0x00 ,ONE_OP =0x01 , +NAME_OP =0x08 ,BYTE_PREFIX =0x0a ,WORD_PREFIX =0x0b ,DWORD_PREFIX =0x0c ,STRING_PREFIX =0x0d ,QWORD_PREFIX =0x0e ,PACKAGE_OP =0x12 , +DUAL_NAME_PREFIX =0x2e , +MULTI_NAME_PREFIX =0x2f , };/**
@@ -157,4 +160,26 @@ void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);* @str: String to write */ void acpigen_write_string (struct acpi_ctx *ctx,const char *str); + +/** +* acpigen_emit_namestring() - Emit an ACPI name +* +* This writes out an ACPI name or path in the required special format. It does +* not add the NAME_OP prefix. +* +* @ctx: ACPI context pointer +* @namepath: Name / path to emit +*/ +void acpigen_emit_namestring (struct acpi_ctx *ctx,const char *namepath); + +/** +* acpigen_write_name() - Write out an ACPI name +* +* This writes out an ACPI name or path in the required special format with a +* NAME_OP prefix. +* +* @ctx: ACPI context pointer +* @namepath: Name / path to emit +*/ +void acpigen_write_name (struct acpi_ctx *ctx,const char *namepath);#endif
include/test/ut.h +17 -0
@@ -133,6 +133,23 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); } \ } +/* +* Assert that two string expressions are equal, up to length of the +* first +*/ +#define ut_asserteq_strn (expr1, expr2) { \ + const char *_val1 = (expr1), *_val2 = (expr2); \ + int _len = strlen(_val1); \ + \ + if (memcmp(_val1, _val2, _len)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + #expr1 " = " #expr2, \ + "Expected \"%.*s\", got \"%.*s\"", \ + _len, _val1, _len, _val2); \ + return CMD_RET_FAILURE; \ + } \ +} +/* Assert that two memory areas are equal */ #define ut_asserteq_mem (expr1, expr2, len) { \ const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \
lib/acpi/acpigen.c +96 -0
99 lines not on this page · raw message
test/dm/acpigen.c +93 -0
96 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 18/35 acpi: Support writing a UUID
In reply to Simon GlassACPI supports writing a UUID in a special format. Add a function to handle this.
---
Changes in v1: None
include/acpi/acpigen.h | 13 +++++++++++++ lib/acpi/acpigen.c | 38 ++++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+)
include/acpi/acpigen.h +13 -0
@@ -24,6 +24,7 @@ enum {DWORD_PREFIX =0x0c ,STRING_PREFIX =0x0d ,QWORD_PREFIX =0x0e , +BUFFER_OP =0x11 ,PACKAGE_OP =0x12 ,DUAL_NAME_PREFIX =0x2e , MULTI_NAME_PREFIX = 0x2f,
@@ -182,4 +183,16 @@ void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);* @namepath: Name / path to emit */ void acpigen_write_name (struct acpi_ctx *ctx,const char *namepath); + +/** +* acpigen_write_uuid() - Write a UUID +* +* This writes out a UUID in the format used by ACPI, with a BUFFER_OP prefix. +* +* @ctx: ACPI context pointer +* @uuid: UUID to write in the form aabbccdd-eeff-gghh-iijj-kkllmmnnoopp +* @return 0 if OK, -EINVAL if the format is incorrect +*/ +int acpigen_write_uuid (struct acpi_ctx *ctx,const char *uuid); +#endif
lib/acpi/acpigen.c +38 -0
@@ -247,3 +247,41 @@ void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath)acpigen_emit_byte (ctx,NAME_OP );acpigen_emit_namestring (ctx, namepath); } + +/* +* ToUUID(uuid) +* +* ACPI 6.3 Section 19.6.142 table 19-438 defines a special output order for the +* bytes that make up a UUID Buffer object: +* +* UUID byte order for input to this function: +* aabbccdd-eeff-gghh-iijj-kkllmmnnoopp +* +* UUID byte order output by this function: +* ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp +*/ +#define UUID_LEN 16 +int acpigen_write_uuid (struct acpi_ctx *ctx,const char *uuid) +{ +u8 buf[UUID_LEN ]; +int ret; + +/* Parse UUID string into bytes */ + ret =uuid_str_to_bin (uuid, buf,UUID_STR_FORMAT_GUID ); +if (ret) +return log_msg_ret ("bad hex" , -EINVAL ); + +/* BufferOp */ +acpigen_emit_byte (ctx,BUFFER_OP ); +acpigen_write_len_f (ctx); + +/* Buffer length in bytes */ +acpigen_write_word (ctx,UUID_LEN ); + +/* Output UUID in expected order */ +acpigen_emit_stream (ctx, (char *)buf,UUID_LEN ); + +acpigen_pop_len (ctx); + +return 0 ; +}
test/dm/acpigen.c +33 -0
@@ -588,3 +588,36 @@ static int dm_test_acpi_name(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_name,0 ); + +/* Test writing a UUID */ +static int dm_test_acpi_uuid (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +u8 *ptr; + +ut_assertok (alloc_context (&ctx)); + + ptr =acpigen_get_current (ctx); + +ut_assertok (acpigen_write_uuid (ctx, +"dbb8e3e6-5886-4ba6-8795-1319f52a966b" )); +ut_asserteq (23 ,acpigen_get_current (ctx) - ptr); +ut_asserteq (BUFFER_OP , ptr[0 ]); +ut_asserteq (22 ,get_length (ptr +1 )); +ut_asserteq (0xdbb8e3e6 ,get_unaligned ((u32 *)(ptr +7 ))); +ut_asserteq (0x5886 ,get_unaligned ((u16 *)(ptr +11 ))); +ut_asserteq (0x4ba6 ,get_unaligned ((u16 *)(ptr +13 ))); +ut_asserteq (0x9587 ,get_unaligned ((u16 *)(ptr +15 ))); +ut_asserteq (0x2af51913 ,get_unaligned ((u32 *)(ptr +17 ))); +ut_asserteq (0x6b96 ,get_unaligned ((u16 *)(ptr +21 ))); + +/* Try a bad UUID */ +ut_asserteq (-EINVAL , +acpigen_write_uuid (ctx, +"dbb8e3e6-5886-4ba6x8795-1319f52a966b" )); + +free_context (&ctx); + +return 0 ; +} +DM_TEST (dm_test_acpi_uuid,0 );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 19/35 acpi: Support writing Device Properties objects via _DSD
In reply to Simon GlassMore complex device properties can be provided to drivers via a device-specific data (_DSD) object.
To create this we need to build it up in a separate data structure and then generate the ACPI code, due to its recursive nature.
Add an implementation of this.
---
Changes in v1: None
include/acpi/acpi_dp.h | 215 ++++++++++++++++++++++ include/acpi/acpigen.h | 1 + lib/acpi/Makefile | 1 + lib/acpi/acpi_dp.c | 322 ++++++++++++++++++++++++++++++++ lib/acpi/acpigen.c | 3 + test/dm/Makefile | 1 + test/dm/acpi_dp.c | 404 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 947 insertions(+) create mode 100644 include/acpi/acpi_dp.h create mode 100644 lib/acpi/acpi_dp.c create mode 100644 test/dm/acpi_dp.c
include/acpi/acpi_dp.h new file +215 -0
@@ -0,0 +1,215 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Device properties, a temporary data structure for adding to ACPI code +* +* Copyright 2019 Google LLC +* Mostly taken from coreboot file acpi_device.h +*/ + +#ifndef __ACPI_DP_H +#define __ACPI_DP_H + +struct acpi_ctx ; + +/* +* Writing Device Properties objects via _DSD +* +* This is described in ACPI 6.3 section 6.2.5 +* +* This provides a structure to handle nested device-specific data which ends +* up in a _DSD table. +* +* https://www.kernel.org/doc/html/latest/firmware-guide/acpi/DSD-properties-rules.html +* https://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf +* https://uefi.org/sites/default/files/resources/_DSD-hierarchical-data-extension-UUID-v1.1.pdf +* +* The Device Property Hierarchy can be multiple levels deep with multiple +* children possible in each level. In order to support this flexibility +* the device property hierarchy must be built up before being written out. +* +* For example: +* +* // Child table with string and integer +* struct acpi_dp *child = acpi_dp_new_table("CHLD"); +* acpi_dp_add_string(child, "childstring", "CHILD"); +* acpi_dp_add_integer(child, "childint", 100); +* +* // _DSD table with integer and gpio and child pointer +* struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); +* acpi_dp_add_integer(dsd, "number1", 1); +* acpi_dp_add_gpio(dsd, "gpio", "\_SB.PCI0.GPIO", 0, 0, 1); +* acpi_dp_add_child(dsd, "child", child); +* +* // Write entries into SSDT and clean up resources +* acpi_dp_write(dsd); +* +* Name(_DSD, Package() { +* ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") +* Package() { +* Package() { "gpio", Package() { \_SB.PCI0.GPIO, 0, 0, 0 } } +* Package() { "number1", 1 } +* } +* ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b") +* Package() { +* Package() { "child", CHLD } +* } +* } +* Name(CHLD, Package() { +* ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") +* Package() { +* Package() { "childstring", "CHILD" } +* Package() { "childint", 100 } +* } +* } +*/ + +#define ACPI_DP_UUID "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" +#define ACPI_DP_CHILD_UUID "dbb8e3e6-5886-4ba6-8795-1319f52a966b" + +/** +* enum acpi_dp_type - types of device property objects +* +* These refer to the types defined by struct acpi_dp below +* +* @ACPI_DP_TYPE_UNKNOWN: Unknown / do not use +* @ACPI_DP_TYPE_INTEGER: Integer value (u64) in @integer +* @ACPI_DP_TYPE_STRING: String value in @string +* @ACPI_DP_TYPE_REFERENCE: Reference to another object, with value in @string +* @ACPI_DP_TYPE_TABLE: Type for a top-level table which may have children +* @ACPI_DP_TYPE_ARRAY: Array of items with first item in @array and following +* items linked from that item's @next +* @ACPI_DP_TYPE_CHILD: Child object, with siblings in that child's @next +*/ +enum acpi_dp_type { +ACPI_DP_TYPE_UNKNOWN , +ACPI_DP_TYPE_INTEGER , +ACPI_DP_TYPE_STRING , +ACPI_DP_TYPE_REFERENCE , +ACPI_DP_TYPE_TABLE , +ACPI_DP_TYPE_ARRAY , +ACPI_DP_TYPE_CHILD , +}; + +/** +* struct acpi_dp - ACPI device properties +* +* @type: Table type +* @name: Name of object, typically _DSD but could be CHLD for a child object +* @next: Next object in list (next array element or next sibling) +* @child: Pointer to first child, if @type == ACPI_DP_TYPE_CHILD, else NULL +* @array: First array element, if @type == ACPI_DP_TYPE_ARRAY, else NULL +* @integer: Integer value of the property, if @type == ACPI_DP_TYPE_INTEGER +* @string: String value of the property, if @type == ACPI_DP_TYPE_STRING; +* child name if @type == ACPI_DP_TYPE_CHILD; +* reference name if @type == ACPI_DP_TYPE_REFERENCE; +*/ +struct acpi_dp { +enum acpi_dp_type type; +const char *name; +struct acpi_dp *next; +union { +struct acpi_dp *child; +struct acpi_dp *array; + }; +union { +u64 integer; +const char *string; + }; +}; + +/** +* acpi_dp_new_table() - Start a new Device Property table +* +* @ref: ACPI reference (e.g. "_DSD") +* @return pointer to table, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_new_table (const char *ref); + +/** +* acpi_dp_add_integer() - Add integer Device Property +* +* A new node is added to the end of the property list of @dp +* +* @dp: Table to add this property to +* @name: Name of property +* @value: Integer value +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_integer (struct acpi_dp *dp,const char *name, +u64 value); + +/** +* acpi_dp_add_string() - Add string Device Property +* +* A new node is added to the end of the property list of @dp +* +* @dp: Table to add this property to +* @name: Name of property +* @string: String value +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_string (struct acpi_dp *dp,const char *name, +const char *string); + +/** +* acpi_dp_add_reference() - Add reference Device Property +* +* A new node is added to the end of the property list of @dp +* +* @dp: Table to add this property to +* @name: Name of property +* @reference: Reference value +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_reference (struct acpi_dp *dp,const char *name, +const char *reference); + +/** +* acpi_dp_add_array() - Add array Device Property +* +* A new node is added to the end of the property list of @dp, with the array +* attached to that. +* +* @dp: Table to add this property to +* @name: Name of property +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_array (struct acpi_dp *dp,struct acpi_dp *array); + +/** +* acpi_dp_add_integer_array() - Add an array of integers +* +* A new node is added to the end of the property list of @dp, with the array +* attached to that. Each element of the array becomes a new node. +* +* @dp: Table to add this property to +* @name: Name of property +* @return pointer to new array node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_integer_array (struct acpi_dp *dp,const char *name, +u64 *array,int len); + +/** +* acpi_dp_add_child() - Add a child table of Device Properties +* +* A new node is added as a child of @dp +* +* @dp: Table to add this child to +* @name: Name of child +* @child: Child node to add +* @return pointer to new array node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_child (struct acpi_dp *dp,const char *name, +struct acpi_dp *child); + +/** +* acpi_dp_write() - Write Device Property hierarchy and clean up resources +* +* This writes the table using acpigen and then frees it +* +* @table: Table to write +* @return 0 if OK, -ve on error +*/ +int acpi_dp_write (struct acpi_ctx *ctx,struct acpi_dp *table); + +#endif
include/acpi/acpigen.h +1 -0
@@ -28,6 +28,7 @@ enum {PACKAGE_OP =0x12 ,DUAL_NAME_PREFIX =0x2e ,MULTI_NAME_PREFIX =0x2f , + ROOT_PREFIX = 0x5c, };/**
lib/acpi/Makefile +1 -0
@@ -3,4 +3,5 @@ obj-y += acpigen.o obj-y += acpi_device.o +obj-y += acpi_dp.o obj-y += acpi_table.o
lib/acpi/acpi_dp.c new file +322 -0
322 lines not on this page · raw message
lib/acpi/acpigen.c +3 -0
@@ -13,6 +13,9 @@#include <acpi/acpigen.h> #include <dm/acpi.h> +/* CPU path format */ +#define ACPI_CPU_STRING "\\_PR.CP%02d" +u8 *acpigen_get_current (struct acpi_ctx *ctx) {return ctx->current;
test/dm/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_ACPIGEN) += acpi.o obj-$(CONFIG_ACPIGEN) += acpigen.o +obj-$(CONFIG_ACPIGEN) += acpi_dp.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o
test/dm/acpi_dp.c new file +404 -0
404 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 20/35 acpi: Support writing a GPIO
In reply to Simon GlassAllowing writing out a reference to a GPIO within the ACPI output. This can be used by ACPI code to access a GPIO at runtime.
---
Changes in v1: None
include/acpi/acpi_dp.h | 18 ++++++++++++++++++ lib/acpi/acpi_dp.c | 21 +++++++++++++++++++++ test/dm/acpi_dp.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+)
include/acpi/acpi_dp.h +18 -0
@@ -202,6 +202,24 @@ struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name,struct acpi_dp *acpi_dp_add_child (struct acpi_dp *dp,const char *name,struct acpi_dp *child); +/** +* acpi_dp_add_gpio() - Add a GPIO to a list of Device Properties +* +* A new node is added to the end of the property list of @dp, with the +* GPIO properties added to the the new node +* +* @dp: Table to add this property to +* @name: Name of property +* @ref: Reference to device with a _CRS containing GpioIO or GpioInt +* @index: Index of the GPIO resource in _CRS starting from zero +* @pin: Pin in the GPIO resource, typically zero +* @active_low: true if pin is active low +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_gpio (struct acpi_dp *dp,const char *name, +const char *ref,int index,int pin, +bool active_low); +/** * acpi_dp_write() - Write Device Property hierarchy and clean up resources *
lib/acpi/acpi_dp.c +21 -0
@@ -320,3 +320,24 @@ struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name,return dp_array; } + +struct acpi_dp *acpi_dp_add_gpio (struct acpi_dp *dp,const char *name, +const char *ref,int index,int pin, +bool active_low) +{ +struct acpi_dp *gpio; + +assert (dp); + gpio =acpi_dp_new_table (name); +if (!gpio) +return NULL ; + +acpi_dp_add_reference (gpio,NULL , ref); +acpi_dp_add_integer (gpio,NULL , index); +acpi_dp_add_integer (gpio,NULL , pin); +acpi_dp_add_integer (gpio,NULL , active_low); + +acpi_dp_add_array (dp, gpio); + +return gpio; +}
test/dm/acpi_dp.c +39 -0
@@ -402,3 +402,42 @@ static int dm_test_acpi_dp_child(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_dp_child,0 ); + +/* Test emitting a GPIO */ +static int dm_test_acpi_dp_gpio (struct unit_test_state *uts) +{ +struct acpi_ctx *ctx; +struct acpi_dp *dp; +u8 *ptr, *pptr; + +ut_assertok (alloc_context (&ctx)); + + dp =acpi_dp_new_table ("FRED" ); +ut_assertnonnull (dp); + +/* Try a few different parameters */ +ut_assertnonnull (acpi_dp_add_gpio (dp,"reset" ,TEST_REF ,0x23 ,0x24 , + false)); +ut_assertnonnull (acpi_dp_add_gpio (dp,"allow" ,TEST_REF ,0 ,0 , true)); + + ptr =acpigen_get_current (ctx); +ut_assertok (acpi_dp_write (ctx, dp)); +ut_asserteq (0x6e ,acpigen_get_current (ctx) - ptr); + + pptr = ptr +0x2c ;//0x3a; +ut_asserteq_str ("reset" , (char *)pptr); +ut_asserteq_strn (EXPECT_REF , (char *)pptr +0xe ); +ut_asserteq (0x23 , pptr[0x1b ]); +ut_asserteq (0x24 , pptr[0x1d ]); +ut_asserteq (ZERO_OP , pptr[0x1e ]); + + pptr = ptr +0x51 ; +ut_asserteq_str ("allow" , (char *)pptr); +ut_asserteq_strn (EXPECT_REF , (char *)pptr +0xe ); +ut_asserteq (ZERO_OP , pptr[0x1a ]); +ut_asserteq (ZERO_OP , pptr[0x1b ]); +ut_asserteq (ONE_OP , pptr[0x1c ]); + +return 0 ; +} +DM_TEST (dm_test_acpi_dp_gpio,0 );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 21/35 acpi: Support copying properties from device tree to ACPI
In reply to Simon GlassSome drivers in Linux support both device tree and ACPI. U-Boot itself uses Linux device-tree bindings for its own configuration but does not use ACPI.
It is convenient to copy these values over to the device tree for passing to linux. Add some convenience functions to help with this.
---
Changes in v1: None
arch/sandbox/dts/test.dts | 1 + include/acpi/acpi_dp.h | 50 +++++++++++++++++++++++++++++ lib/acpi/acpi_dp.c | 52 ++++++++++++++++++++++++++++++ test/dm/acpi_dp.c | 67 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+)
arch/sandbox/dts/test.dts +1 -0
@@ -109,6 +109,7 @@ uint-value = <(-1234)>; int64-value = /bits/ 64 <0x1111222233334444>; int-array = <5678 9123 4567>; + str-value = "test string"; interrupts-extended = <&irq 3 0>; };
include/acpi/acpi_dp.h +50 -0
54 lines not on this page · raw message
lib/acpi/acpi_dp.c +52 -0
55 lines not on this page · raw message
test/dm/acpi_dp.c +67 -0
70 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 22/35 acpi: Add support for various misc ACPI opcodes
In reply to Simon GlassAdd more functions to handle some miscellaneous ACPI opcodes.
---
Changes in v1: None
include/acpi/acpigen.h | 114 +++++++++++++++++++++++++++++++++++++++++ lib/acpi/acpigen.c | 83 ++++++++++++++++++++++++++++++ test/dm/acpigen.c | 75 +++++++++++++++++++++++++++ 3 files changed, 272 insertions(+)
include/acpi/acpigen.h +114 -0
@@ -26,9 +26,26 @@ enum {QWORD_PREFIX =0x0e ,BUFFER_OP =0x11 ,PACKAGE_OP =0x12 , +METHOD_OP =0x14 , +SLEEP_OP =0x22 ,DUAL_NAME_PREFIX =0x2e ,MULTI_NAME_PREFIX =0x2f , +DEBUG_OP =0x31 , +EXT_OP_PREFIX =0x5b ,ROOT_PREFIX =0x5c , +LOCAL0_OP =0x60 , +LOCAL1_OP =0x61 , +LOCAL2_OP =0x62 , +LOCAL3_OP =0x63 , +LOCAL4_OP =0x64 , +LOCAL5_OP =0x65 , +LOCAL6_OP =0x66 , +LOCAL7_OP =0x67 , +STORE_OP =0x70 , +AND_OP =0x7b , +OR_OP =0x7d , +NOT_OP =0x80 , + RETURN_OP = 0xa4, };/**
@@ -196,4 +213,101 @@ void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);*/ int acpigen_write_uuid (struct acpi_ctx *ctx,const char *uuid); +/** +* acpigen_emit_ext_op() - Emit an extended op with the EXT_OP_PREFIX prefix +* +* @ctx: ACPI context pointer +* @op: Operation code (e.g. SLEEP_OP) +*/ +void acpigen_emit_ext_op (struct acpi_ctx *ctx,uint op); + +/** +* acpigen_write_method() - Write a method header +* +* @ctx: ACPI context pointer +* @name: Method name (4 characters) +* @nargs: Number of method arguments (0 if none) +*/ +void acpigen_write_method (struct acpi_ctx *ctx,const char *name,int nargs); + +/** +* acpigen_write_method_serialized() - Write a method header +* +* This sets the 'serialized' flag so that the method is thread-safe +* +* @ctx: ACPI context pointer +* @name: Method name (4 characters) +* @nargs: Number of method arguments (0 if none) +*/ +void acpigen_write_method_serialized (struct acpi_ctx *ctx,const char *name, +int nargs); + +/** +* acpigen_write_sta() - Write a _STA method +* +* @ctx: ACPI context pointer +* @status: Status value to return +*/ +void acpigen_write_sta (struct acpi_ctx *ctx,uint status); + +/** +* acpigen_write_sleep() - Write a sleep operation +* +* @ctx: ACPI context pointer +* @sleep_ms: Number of milliseconds to sleep for +*/ +void acpigen_write_sleep (struct acpi_ctx *ctx,u64 sleep_ms); + +/** +* acpigen_write_store() - Write a store operation +* +* @ctx: ACPI context pointer +*/ +void acpigen_write_store (struct acpi_ctx *ctx); + +/** +* acpigen_write_debug_string() - Write a debug string +* +* This writes a debug operation with an associated string +* +* @ctx: ACPI context pointer +* @str: String to write +*/ +void acpigen_write_debug_string (struct acpi_ctx *ctx,const char *str); + +/** +* acpigen_write_or() - Write a bitwise OR operation +* +* res = arg1 | arg2 +* +* @ctx: ACPI context pointer +* @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP) +* @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP) +* @res: ACPI opcode for result (e.g. LOCAL2_OP) +*/ +void acpigen_write_or (struct acpi_ctx *ctx,u8 arg1,u8 arg2,u8 res); + +/** +* acpigen_write_and() - Write a bitwise AND operation +* +* res = arg1 & arg2 +* +* @ctx: ACPI context pointer +* @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP) +* @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP) +* @res: ACPI opcode for result (e.g. LOCAL2_OP) +*/ +void acpigen_write_and (struct acpi_ctx *ctx,u8 arg1,u8 arg2,u8 res); + +/** +* acpigen_write_or() - Write a bitwise NOT operation +* +* res = ~arg1 +* +* @ctx: ACPI context pointer +* @arg: ACPI opcode for operand (e.g. LOCAL0_OP) +* @res: ACPI opcode for result (e.g. LOCAL2_OP) +*/ +void acpigen_write_not (struct acpi_ctx *ctx,u8 arg,u8 res); +#endif
lib/acpi/acpigen.c +83 -0
98 lines not on this page · raw message
test/dm/acpigen.c +75 -0
78 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 23/35 acpi: Add support for writing a Power Resource
In reply to Simon GlassThese are used in ACPI to disable power to various pats of the system when in sleep. Add a way to create a power resource, with the caller finishing off the details.
---
Changes in v1: None
include/acpi/acpigen.h | 22 ++++++++++++++++++++++ lib/acpi/acpigen.c | 22 ++++++++++++++++++++++ test/dm/acpigen.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+)
include/acpi/acpigen.h +22 -0
@@ -45,6 +45,7 @@ enum {AND_OP =0x7b ,OR_OP =0x7d ,NOT_OP =0x80 , +POWER_RES_OP =0x84 , RETURN_OP = 0xa4, };
@@ -310,4 +311,25 @@ void acpigen_write_and(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);*/ void acpigen_write_not (struct acpi_ctx *ctx,u8 arg,u8 res); +/** +* acpigen_write_power_res() - Write a power resource +* +* Name (_PRx, Package(One) { name }) +* ... +* PowerResource (name, level, order) +* +* The caller should fill in the rest of the power resource and then call +* acpigen_pop_len() to close it off +* +* @ctx: ACPI context pointer +* @name: Name of power resource (e.g. "PRIC") +* @level: Deepest sleep level that this resource must be kept on (0=S0, 3=S3) +* @order: Order that this must be enabled/disabled (e.g. 0) +* @dev_stats: List of states to define, e.g. {"_PR0", "_PR3"} +* @dev_states_count: Number of dev states +*/ +void acpigen_write_power_res (struct acpi_ctx *ctx,const char *name,uint level, +uint order,const char *const dev_states[], +size_t dev_states_count); +#endif
lib/acpi/acpigen.c +22 -0
@@ -326,6 +326,28 @@ int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid)return 0 ; } +void acpigen_write_power_res (struct acpi_ctx *ctx,const char *name,uint level, +uint order,const char *const dev_states[], +size_t dev_states_count) +{ +size_t i; + +for (i =0 ; i < dev_states_count; i++) { +acpigen_write_name (ctx, dev_states[i]); +acpigen_write_package (ctx,1 ); +acpigen_emit_simple_namestring (ctx, name); +acpigen_pop_len (ctx);/* Package */ + } + +acpigen_emit_ext_op (ctx,POWER_RES_OP ); + +acpigen_write_len_f (ctx); + +acpigen_emit_simple_namestring (ctx, name); +acpigen_emit_byte (ctx, level); +acpigen_emit_word (ctx, order); +} +/* Sleep (ms) */ void acpigen_write_sleep (struct acpi_ctx *ctx,u64 sleep_ms) {
test/dm/acpigen.c +41 -0
44 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 24/35 acpi: Add support for writing a GPIO power sequence
In reply to Simon GlassPower to some devices is controlled by GPIOs. Add a way to generate ACPI code to enable and disable a GPIO so that this can be handled within an ACPI method.
---
Changes in v1: None
include/acpi/acpigen.h | 12 +++++++ lib/acpi/acpigen.c | 80 ++++++++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 54 ++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+)
include/acpi/acpigen.h +12 -0
@@ -13,6 +13,7 @@#include <linux/types.h> struct acpi_ctx ; +struct acpi_gpio ;/* ACPI Op/Prefix codes */ enum {
@@ -332,4 +333,15 @@ void acpigen_write_power_res(struct acpi_ctx *ctx, const char *name, uint level, uint order, const char *const dev_states[], size_t dev_states_count); +/* +* Helper functions for enabling/disabling Tx GPIOs based on the GPIO +* polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to +* make callbacks into SoC acpigen code. +* +* Returns 0 on success and -1 on error. +*/ +int acpigen_set_enable_tx_gpio (struct acpi_ctx *ctx,u32 tx_state_val, +const char *dw0_name,struct acpi_gpio *gpio, +bool enable); +#endif
lib/acpi/acpigen.c +80 -0
89 lines not on this page · raw message
test/dm/acpigen.c +54 -0
57 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 25/35 acpi: Add support for a generic power sequence
In reply to Simon GlassAdd a way for devices to enable and disable themselves using ACPI code that updates GPIOs. This takes several timing parameters and supports enable, reset and stop.
---
Changes in v1: None
include/acpi/acpi_device.h | 41 ++++++++++++++++ lib/acpi/acpi_device.c | 99 ++++++++++++++++++++++++++++++++++++++ test/dm/acpigen.c | 68 ++++++++++++++++++++++++++ 3 files changed, 208 insertions(+)
include/acpi/acpi_device.h +41 -0
@@ -341,4 +341,45 @@ int acpi_device_write_i2c_dev(struct acpi_ctx *ctx, const struct udevice *dev);*/ int acpi_device_write_spi_dev (struct acpi_ctx *ctx,const struct udevice *dev); +/** +* acpi_device_add_power_res() - Add a basic PowerResource block for a device +* +* This includes GPIOs to control enable, reset and stop operation of the +* device. Each GPIO is optional, but at least one must be provided. +* This can be applied to any device that has power control, so is fairly +* generic. +* +* Reset - Put the device into / take the device out of reset. +* Enable - Enable / disable power to device. +* Stop - Stop / start operation of device. +* +* @ctx: ACPI context pointer +* @tx_state_val: Mask to use to toggle the TX state on the GPIO pin, e,g. +* PAD_CFG0_TX_STATE +* @dw0_name: Name to use for access to dw0, e.g. "\\_SB.GPC0" +* @reset_gpio: GPIO used to take device out of reset or to put it into reset +* @reset_delay_ms: Delay to be inserted after device is taken out of reset +* (_ON method delay) +* @reset_off_delay_ms: Delay to be inserted after device is put into reset +* (_OFF method delay) +* @enable_gpio: GPIO used to enable device +* @enable_delay_ms: Delay to be inserted after device is enabled +* @enable_off_delay_ms: Delay to be inserted after device is disabled +* (_OFF method delay) +* @stop_gpio: GPIO used to stop operation of device +* @stop_delay_ms: Delay to be inserted after disabling stop (_ON method delay) +* @stop_off_delay_ms: Delay to be inserted after enabling stop. +* (_OFF method delay) +* +* @return 0 if OK, -ve if at least one GPIO is not provided +*/ +int acpi_device_add_power_res (struct acpi_ctx *ctx,u32 tx_state_val, +const char *dw0_name, +const struct gpio_desc *reset_gpio, +uint reset_delay_ms,uint reset_off_delay_ms, +const struct gpio_desc *enable_gpio, +uint enable_delay_ms,uint enable_off_delay_ms, +const struct gpio_desc *stop_gpio, +uint stop_delay_ms,uint stop_off_delay_ms); +#endif
lib/acpi/acpi_device.c +99 -0
105 lines not on this page · raw message
test/dm/acpigen.c +68 -0
71 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 26/35 acpi: Add support for SSDT generation
In reply to Simon GlassSome devices need to generate code for the Secondary System Descriptor Table (SSDT). Add a method to handle this.
---
Changes in v1:
- Switch parameter order of _acpi_fill_ssdt() and make it static
- Fix 'sentinal' and 'METHOD_FILL_SDDT' typos
arch/sandbox/dts/test.dts | 2 ++ drivers/core/acpi.c | 14 +++++++++++++ include/dm/acpi.h | 23 +++++++++++++++++++++ test/dm/acpi.c | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+)
arch/sandbox/dts/test.dts +2 -0
@@ -225,6 +225,7 @@ acpi-test { compatible = "denx,u-boot-acpi-test"; + acpi-ssdt-test-data = "ab"; child { compatible = "denx,u-boot-acpi-test"; };
@@ -232,6 +233,7 @@ acpi-test2 { compatible = "denx,u-boot-acpi-test"; + acpi-ssdt-test-data = "cd"; }; clocks {
drivers/core/acpi.c +14 -0
@@ -17,6 +17,7 @@/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES , +METHOD_FILL_SSDT , };/* Prototype for all methods */
@@ -50,6 +51,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method)switch (method) {case METHOD_WRITE_TABLES :return aops->write_tables; +case METHOD_FILL_SSDT : +return aops->fill_ssdt; } }
@@ -83,6 +86,17 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,return 0 ; } +int acpi_fill_ssdt (struct acpi_ctx *ctx) +{ +int ret; + +log_debug ("Writing SSDT tables\n" ); + ret =acpi_recurse_method (ctx,dm_root (),METHOD_FILL_SSDT ); +log_debug ("Writing SSDT finished, err=%d\n" , ret); + +return ret; +} +int acpi_write_dev_tables (struct acpi_ctx *ctx) {int ret;
include/dm/acpi.h +23 -0
@@ -72,6 +72,19 @@ struct acpi_ops {* @return 0 if OK, -ve on error */ int (*write_tables)(const struct udevice *dev,struct acpi_ctx *ctx); + +/** +* fill_ssdt() - Generate SSDT code for a device +* +* This is called to create the SSDT code. THe method should write out +* whatever ACPI code is needed by this device. It will end up in the +* SSDT table. +* +* @dev: Device to write +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int (*fill_ssdt)(const struct udevice *dev,struct acpi_ctx *ctx); };#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops)
@@ -116,6 +129,16 @@ int acpi_copy_name(char *out_name, const char *name);*/ int acpi_write_dev_tables (struct acpi_ctx *ctx); +/** +* acpi_fill_ssdt() - Generate ACPI tables for SSDT +* +* This is called to create the SSDT code for all devices. +* +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int acpi_fill_ssdt (struct acpi_ctx *ctx); +#endif /* __ACPI__ */ #endif
test/dm/acpi.c +42 -0
60 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 27/35 x86: acpi: Move MADT down a bit
In reply to Simon GlassPut this table before MCFG so that it matches the order that coreboot uses when passing tables to Linux. This is a cosmetic change since the order of the tables does not otherwise matter.
---
Changes in v1:
- Correct the commit subject
arch/x86/lib/acpi_table.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/lib/acpi_table.c +6 -6
@@ -417,18 +417,18 @@ ulong write_acpi_tables(ulong start_addr)acpi_create_fadt (fadt, facs, dsdt);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 (ctx, madt); -debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);acpi_inc_align (ctx, mcfg->header.length);acpi_add_table (ctx, mcfg); +debug ("ACPI: * MADT\n" ); + madt = ctx->current; +acpi_create_madt (madt); +acpi_inc_align (ctx, madt->header.length); +acpi_add_table (ctx, madt); +debug ("ACPI: * CSRT\n" ); csrt = ctx->current;acpi_create_csrt (csrt);
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 28/35 acpi: Record the items added to SSDT
In reply to Simon GlassIt is useful to be able to control the order of data written to the SSDT so that we can compare the output against known-good kernel dumps.
Add code to record each item that is added along with the device that added it. That allows us to reorder things later if needed.
---
Changes in v1:
- Generalise the ACPI function recursion with acpi_recurse_method()
drivers/core/acpi.c | 83 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-)
drivers/core/acpi.c +79 -4
@@ -9,11 +9,20 @@#define LOG_CATEOGRY LOGC_ACPI#include <common.h> +#include <malloc.h> #include <dm.h> #include <dm/acpi.h> #include <dm/device-internal.h> #include <dm/root.h> +#define MAX_ITEMS 100 + +/* Type of table that we collected */ +enum gen_type_t { +TYPE_NONE , +TYPE_SSDT , +}; +/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES ,
@@ -23,6 +32,25 @@ enum method_t {/* Prototype for all methods */ typedef int (*acpi_method )(const struct udevice *dev,struct acpi_ctx *ctx); +/** +* struct acpi_item - Holds info about ACPI data generated by a driver method +* +* @dev: Device that generated this data +* @type: Table type it refers to +* @buf: Buffer containing the data +* @size: Size of the data in bytes +*/ +struct acpi_item { +struct udevice *dev; +enum gen_type_t type; +char *buf; +int size; +}; + +/* List of ACPI items collected */ +static struct acpi_item acpi_item[MAX_ITEMS ]; +static int item_count; +int acpi_copy_name (char *out_name,const char *name) {strncpy (out_name, name,ACPI_NAME_LEN );
@@ -42,6 +70,43 @@ int acpi_get_name(const struct udevice *dev, char *out_name)return -ENOSYS ; } +/** +* acpi_add_item() - Add a new item to the list of data collected +* +* @ctx: ACPI context +* @dev: Device that generated the data +* @type: Table type it refers to +* @start: The start of the data (the end is obtained from ctx->current) +* @return 0 if OK, -ENOSPC if too many items, -ENOMEM if out of memory +*/ +static int acpi_add_item (struct acpi_ctx *ctx,struct udevice *dev, +enum gen_type_t type,void *start) +{ +struct acpi_item *item; +void *end = ctx->current; + +if (item_count ==MAX_ITEMS ) { +log_err ("Too many items\n" ); +return log_msg_ret ("mem" , -ENOSPC ); + } + + item = &acpi_item[item_count]; + item->dev = dev; + item->type = type; + item->size = end - start; +if (!item->size) +return 0 ; + item->buf =malloc (item->size); +if (!item->buf) +return log_msg_ret ("mem" , -ENOMEM ); +memcpy (item->buf, start, item->size); + item_count++; +log_debug ("* %s: Added type %d, %p, size %x\n" , dev->name, type, start, + item->size); + +return 0 ; +} +acpi_method acpi_get_method (struct udevice *dev,enum method_t method) {struct acpi_ops *aops;
@@ -60,7 +125,7 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method) }int acpi_recurse_method (struct acpi_ctx *ctx,struct udevice *parent, -enum method_t method) +enum method_t method,enum gen_type_t type) {struct udevice *dev;acpi_method func;
@@ -68,6 +133,8 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, func =acpi_get_method (parent, method);if (func) { +void *start = ctx->current; +log_debug ("\n" );log_debug ("- %s %p\n" , parent->name, func); ret =device_ofdata_to_platdata (parent);
@@ -76,9 +143,16 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, ret =func (parent, ctx);if (ret)return log_msg_ret ("func" , ret); + +/* Add the item to the internal list */ +if (type !=TYPE_NONE ) { + ret =acpi_add_item (ctx, parent, type, start); +if (ret) +return log_msg_ret ("add" , ret); + } } device_foreach_child(dev, parent) { - ret =acpi_recurse_method (ctx, dev, method); + ret =acpi_recurse_method (ctx, dev, method, type);if (ret)return log_msg_ret ("recurse" , ret); }
@@ -91,7 +165,7 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)int ret;log_debug ("Writing SSDT tables\n" ); - ret =acpi_recurse_method (ctx,dm_root (),METHOD_FILL_SSDT ); + ret =acpi_recurse_method (ctx,dm_root (),METHOD_FILL_SSDT ,TYPE_SSDT );log_debug ("Writing SSDT finished, err=%d\n" , ret);return ret;
@@ -102,7 +176,8 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx)int ret;log_debug ("Writing device tables\n" ); - ret =acpi_recurse_method (ctx,dm_root (),METHOD_WRITE_TABLES ); + ret =acpi_recurse_method (ctx,dm_root (),METHOD_WRITE_TABLES , +TYPE_NONE );log_debug ("Writing finished, err=%d\n" , ret);return ret;
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 29/35 acpi: Support ordering SSDT data by device
In reply to Simon GlassAdd a /chosen property to control the order in which the data appears in the SSDT. This allows matching up U-Boot's output from a dump of the known-good data obtained from within Linux.
---
Changes in v1:
- Generalise the ACPI function recursion with acpi_recurse_method()
arch/sandbox/dts/test.dts | 5 ++- doc/device-tree-bindings/chosen.txt | 9 +++++ drivers/core/acpi.c | 62 +++++++++++++++++++++++++++++ test/dm/acpi.c | 15 ++++--- 4 files changed, 83 insertions(+), 8 deletions(-)
arch/sandbox/dts/test.dts +3 -2
@@ -223,7 +223,7 @@ compatible = "denx,u-boot-devres-test"; }; - acpi-test { + acpi_test1: acpi-test { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "ab"; child {
@@ -231,7 +231,7 @@ }; }; - acpi-test2 { + acpi_test2: acpi-test2 { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "cd"; };
@@ -864,6 +864,7 @@ setting = "sunrise ohoka"; other-node = "/some-bus/c-test at 5"; int-values = <0x1937 72993>; + u-boot,acpi-ssdt-order = <&acpi_test2 &acpi_test1>; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>;
doc/device-tree-bindings/chosen.txt +9 -0
@@ -134,3 +134,12 @@ Example phandlepart = <&mmc 1>; }; }; + +u-boot,acpi-ssdt-order +---------------------- + +This provides the ordering to use when writing device data to the ACPI SSDT +(Secondary System Descriptor Table). Each cell is a phandle pointer to a device +node to add. The ACPI information is written in this order. + +If the ordering does not include all nodes, an error is generated.
drivers/core/acpi.c +62 -0
79 lines not on this page · raw message
test/dm/acpi.c +9 -6
@@ -425,13 +425,16 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) buf[4 ] ='z' ;/* sentinel */ ut_assertok (acpi_fill_ssdt (&ctx)); -/* These values come from acpi-test's acpi-ssdt-test-data property */ -ut_asserteq ('a' , buf[0 ]); -ut_asserteq ('b' , buf[1 ]); +/* +* These values come from acpi-test2's acpi-ssdt-test-data property. +* This device comes first because of u-boot,acpi-ssdt-order +*/ +ut_asserteq ('c' , buf[0 ]); +ut_asserteq ('d' , buf[1 ]); -/* These values come from acpi-test2's acpi-ssdt-test-data property */ -ut_asserteq ('c' , buf[2 ]); -ut_asserteq ('d' , buf[3 ]); +/* These values come from acpi-test's acpi-ssdt-test-data property */ +ut_asserteq ('a' , buf[2 ]); +ut_asserteq ('b' , buf[3 ]);ut_asserteq ('z' , buf[4 ]);
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 30/35 x86: Allow devices to write an SSDT
In reply to Simon GlassCall the new core function to write the SSDT. This is made up of fragments generated by devices that have the fill_ssdt() method.
---
Changes in v1:
- Use OEM_TABLE_ID instead of ACPI_TABLE_CREATOR
- Update ACPI_DSTATUS enum
arch/x86/lib/acpi_table.c | 50 +++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_table.h | 6 +++++ 2 files changed, 56 insertions(+)
arch/x86/lib/acpi_table.c +50 -0
@@ -13,6 +13,7 @@#include <mapmem.h> #include <serial.h> #include <version.h> +#include <acpi/acpigen.h> #include <acpi/acpi_table.h> #include <asm/acpi/global_nvs.h> #include <asm/ioapic.h>
@@ -353,6 +354,46 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) header->checksum =table_compute_checksum ((void *)spcr, header->length); } +static void acpi_ssdt_write_cbtable (struct acpi_ctx *ctx) +{ +uintptr_t base; +u32 size; + + base =0 ; + size =0 ; + +acpigen_write_device (ctx,"CTBL" ); +acpigen_write_coreboot_hid (ctx,COREBOOT_ACPI_ID_CBTABLE ); +acpigen_write_name_integer (ctx,"_UID" ,0 ); +acpigen_write_sta (ctx,ACPI_DSTATUS_HIDDEN_ON ); +acpigen_write_name (ctx,"_CRS" ); +acpigen_write_resourcetemplate_header (ctx); +acpigen_write_mem32fixed (ctx,0 , base, size); +acpigen_write_resourcetemplate_footer (ctx); +acpigen_pop_len (ctx); +} + +void acpi_create_ssdt (struct acpi_ctx *ctx,struct acpi_table_header *ssdt, +const char *oem_table_id) +{ +memset ((void *)ssdt,'\0' ,sizeof (struct acpi_table_header )); + +acpi_fill_header (ssdt,"SSDT" ); + ssdt->revision =acpi_get_table_revision (ACPITAB_SSDT ); + ssdt->aslc_revision =1 ; + ssdt->length =sizeof (struct acpi_table_header ); + +acpi_inc (ctx,sizeof (struct acpi_table_header )); + +/* Write object to declare coreboot tables */ +acpi_ssdt_write_cbtable (ctx); +acpi_fill_ssdt (ctx); + +/* (Re)calculate length and checksum. */ + ssdt->length = ctx->current - (void *)ssdt; + ssdt->checksum =table_compute_checksum ((void *)ssdt, ssdt->length); +} +/* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */
@@ -362,6 +403,7 @@ ulong write_acpi_tables(ulong start_addr)struct acpi_facs *facs;struct acpi_table_header *dsdt;struct acpi_fadt *fadt; +struct acpi_table_header *ssdt;struct acpi_mcfg *mcfg;struct acpi_madt *madt;struct acpi_csrt *csrt;
@@ -417,6 +459,14 @@ ulong write_acpi_tables(ulong start_addr)acpi_create_fadt (fadt, facs, dsdt);acpi_add_table (ctx, fadt); +debug ("ACPI: * SSDT\n" ); + ssdt = (struct acpi_table_header *)ctx->current; +acpi_create_ssdt (ctx, ssdt,OEM_TABLE_ID ); +if (ssdt->length >sizeof (struct acpi_table_header )) { +acpi_inc_align (ctx, ssdt->length); +acpi_add_table (ctx, ssdt); + } +debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);
include/acpi/acpi_table.h +6 -0
@@ -25,6 +25,12 @@struct acpi_ctx ; +/* List of ACPI HID that use the coreboot ACPI ID */ +enum coreboot_acpi_ids { +COREBOOT_ACPI_ID_CBTABLE =0x0000 ,/* BOOT0000 */ +COREBOOT_ACPI_ID_MAX =0xFFFF ,/* BOOTFFFF */ +}; +/* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 31/35 acpi: Add support for DSDT generation
In reply to Simon GlassSome devices need to inject extra code into the Differentiated System Descriptor Table (DSDT). Add a method to handle this.
---
Changes in v1:
- Generalise the ACPI function recursion with acpi_recurse_method()
arch/sandbox/dts/test.dts | 2 ++ drivers/core/acpi.c | 25 +++++++++++++++++++++- include/dm/acpi.h | 23 ++++++++++++++++++++ test/dm/acpi.c | 44 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +2 -0
@@ -226,6 +226,7 @@ acpi_test1: acpi-test { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "ab"; + acpi-dsdt-test-data = "hi"; child { compatible = "denx,u-boot-acpi-test"; };
@@ -234,6 +235,7 @@ acpi_test2: acpi-test2 { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "cd"; + acpi-dsdt-test-data = "jk"; }; clocks {
drivers/core/acpi.c +24 -1
@@ -21,12 +21,14 @@enum gen_type_t {TYPE_NONE ,TYPE_SSDT , +TYPE_DSDT , };/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES ,METHOD_FILL_SSDT , +METHOD_INJECT_DSDT , };/* Prototype for all methods */
@@ -130,7 +132,9 @@ static int build_type(struct acpi_ctx *ctx, void *start, enum gen_type_t type)void *end = ctx->current; ptr = start; - order =ofnode_read_chosen_prop ("u-boot,acpi-ssdt-order" , &size); + order =ofnode_read_chosen_prop (type ==TYPE_DSDT ? +"u-boot,acpi-dsdt-order" : +"u-boot,acpi-ssdt-order" , &size);if (!order) {log_warning ("Failed to find ordering, leaving as is\n" );return 0 ;
@@ -175,6 +179,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method)return aops->write_tables;case METHOD_FILL_SSDT :return aops->fill_ssdt; +case METHOD_INJECT_DSDT : +return aops->inject_dsdt; } }
@@ -233,6 +239,23 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)return ret; } +int acpi_inject_dsdt (struct acpi_ctx *ctx) +{ +void *start = ctx->current; +int ret; + +log_debug ("Writing DSDT tables\n" ); + item_count =0 ; + ret =acpi_recurse_method (ctx,dm_root (),METHOD_INJECT_DSDT , +TYPE_DSDT ); +log_debug ("Writing DSDT finished, err=%d\n" , ret); + ret =build_type (ctx, start,TYPE_DSDT ); +if (ret) +return log_msg_ret ("build" , ret); + +return ret; +} +int acpi_write_dev_tables (struct acpi_ctx *ctx) {int ret;
include/dm/acpi.h +23 -0
@@ -85,6 +85,19 @@ struct acpi_ops {* @return 0 if OK, -ve on error */ int (*fill_ssdt)(const struct udevice *dev,struct acpi_ctx *ctx); + +/** +* inject_dsdt() - Generate DSDT code for a device +* +* This is called to create the DSDT code. THe method should write out +* whatever ACPI code is needed by this device. It will end up in the +* DSDT table. +* +* @dev: Device to write +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int (*inject_dsdt)(const struct udevice *dev,struct acpi_ctx *ctx); };#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops)
@@ -139,6 +152,16 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx);*/ int acpi_fill_ssdt (struct acpi_ctx *ctx); +/** +* acpi_inject_dsdt() - Generate ACPI tables for DSDT +* +* This is called to create the DSDT code for all devices. +* +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int acpi_inject_dsdt (struct acpi_ctx *ctx); +#endif /* __ACPI__ */ #endif
test/dm/acpi.c +44 -0
57 lines not on this page · raw message
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 32/35 x86: Allow devices to write to DSDT
In reply to Simon GlassCall the new core function to inject ASL programmatically into the DSDT. This is made up of fragments generated by devices that have the inject_dsdt() method. The normal, compiled ASL file is added after this.
---
Changes in v1: None
arch/x86/lib/acpi_table.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/x86/lib/acpi_table.c +14 -1
@@ -431,7 +431,20 @@ ulong write_acpi_tables(ulong start_addr)memcpy (ctx->current, (char *)&AmlCode +sizeof (struct acpi_table_header ), dsdt->length -sizeof (struct acpi_table_header )); -acpi_inc_align (ctx, dsdt->length -sizeof (struct acpi_table_header )); + +if (dsdt->length >=sizeof (struct acpi_table_header )) { +acpi_inject_dsdt (ctx); +memcpy (ctx->current, + (char *)AmlCode +sizeof (struct acpi_table_header ), + dsdt->length -sizeof (struct acpi_table_header )); +acpi_inc (ctx, dsdt->length -sizeof (struct acpi_table_header )); + +/* (Re)calculate length and checksum. */ + dsdt->length = ctx->current - (void *)dsdt; + dsdt->checksum =0 ; + dsdt->checksum =table_compute_checksum (dsdt, dsdt->length); + } +acpi_align (ctx);/* Pack GNVS into the ACPI table area */ for (i =0 ; i < dsdt->length; i++) {
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 33/35 pci: Avoid a crash in device_is_on_pci_bus()
In reply to Simon GlassThis function cannot currently be called on the root node. Add a check for this as well as a test.
---
Changes in v1: None
include/dm/device.h | 2 +- test/dm/pci.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
include/dm/device.h +1 -1
@@ -742,7 +742,7 @@ int dev_enable_by_path(const char *path);*/ static inline bool device_is_on_pci_bus (const struct udevice *dev) { -return device_get_uclass_id (dev->parent) ==UCLASS_PCI ; +return dev->parent &&device_get_uclass_id (dev->parent) ==UCLASS_PCI ; }/**
test/dm/pci.c +14 -0
@@ -339,3 +339,17 @@ static int dm_test_pci_addr_live(struct unit_test_state *uts) }DM_TEST (dm_test_pci_addr_live,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT |DM_TESTF_LIVE_TREE ); + +/* Test device_is_on_pci_bus() */ +static int dm_test_pci_on_bus (struct unit_test_state *uts) +{ +struct udevice *dev; + +ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x1f ,0 ), &dev)); +ut_asserteq (true,device_is_on_pci_bus (dev)); +ut_asserteq (false,device_is_on_pci_bus (dev_get_parent (dev))); +ut_asserteq (true,device_is_on_pci_bus (dev)); + +return 0 ; +} +DM_TEST (dm_test_pci_on_bus,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 34/35 dm: acpi: Enhance acpi_get_name()
In reply to Simon GlassFor many device types it is possible to figure out the name just by looking at its uclass or parent. Add a function to handle this, since it allows us to cover the vast majority of cases automatically.
However it is sometimes impossible to figure out an ACPI name for a device just by looking at its uclass. For example a touch device may have a vendor-specific name. Add a new "acpi,name" property to allow a custom name to be created.
With this new feature we can drop the get_name() methods in the sandbox I2C and SPI drivers. They were only added for testing purposes. Update the tests to use the new values.
---
Changes in v1:
- Use acpi,ddn instead of acpi,desc
- Rename to acpi_device_infer_name()
- Update newly created sandbox tests
arch/sandbox/dts/test.dts | 1 + doc/device-tree-bindings/device.txt | 13 ++++ drivers/core/acpi.c | 13 +++- drivers/i2c/sandbox_i2c.c | 10 --- drivers/spi/sandbox_spi.c | 10 --- include/acpi/acpi_device.h | 15 ++++ lib/acpi/acpi_device.c | 105 ++++++++++++++++++++++++++++ test/dm/acpi.c | 42 ++++++++++- test/dm/acpigen.c | 4 +- 9 files changed, 188 insertions(+), 25 deletions(-)
arch/sandbox/dts/test.dts +1 -0
@@ -111,6 +111,7 @@ int-array = <5678 9123 4567>; str-value = "test string"; interrupts-extended = <&irq 3 0>; + acpi,name = "GHIJ"; }; junk {
doc/device-tree-bindings/device.txt +13 -0
@@ -17,6 +17,8 @@ the acpi,compatible property. System) Device Name) - acpi,hid : Contains the string to use as the HID (Hardware ID) identifier _HID + - acpi,name : Provides the ACPI name for a device, which is a string consisting + of four alphanumeric character (upper case) - 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
@@ -34,3 +36,14 @@ elan_touchscreen: elan-touchscreen at 10 { interrupts-extended = <&acpi_gpe GPIO_21_IRQ IRQ_TYPE_EDGE_FALLING>; linux,probed; }; + +pcie-a0 at 14,0 { + reg = <0x0000a000 0 0 0 0>; + acpi,name = "RP01"; + wifi: wifi { + compatible = "intel,generic-wifi"; + acpi,ddn = "Intel WiFi"; + acpi,name = "WF00"; + interrupts-extended = <&acpi_gpe 0x3c 0>; + }; +};
drivers/core/acpi.c +11 -2
@@ -9,8 +9,9 @@#define LOG_CATEOGRY LOGC_ACPI#include <common.h> -#include <malloc.h> #include <dm.h> +#include <malloc.h> +#include <acpi/acpi_device.h> #include <dm/acpi.h> #include <dm/device-internal.h> #include <dm/root.h>
@@ -64,12 +65,20 @@ int acpi_copy_name(char *out_name, const char *name)int acpi_get_name (const struct udevice *dev,char *out_name) {struct acpi_ops *aops; +const char *name; +int ret; aops =device_get_acpi_ops (dev);if (aops && aops->get_name)return aops->get_name (dev, out_name); + name =dev_read_string (dev,"acpi,name" ); +if (name) +return acpi_copy_name (out_name, name); + ret =acpi_device_infer_name (dev, out_name); +if (ret) +return log_msg_ret ("dev" , ret); -return -ENOSYS ; +return 0 ; }/**
drivers/i2c/sandbox_i2c.c +0 -10
@@ -83,15 +83,6 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,return ops->xfer (emul, msg, nmsgs); } -static int sandbox_i2c_get_name (const struct udevice *dev,char *out_name) -{ -return acpi_copy_name (out_name,"SI2C" ); -} - -struct acpi_ops sandbox_i2c_acpi_ops = { - .get_name = sandbox_i2c_get_name, -}; -static const struct dm_i2c_ops sandbox_i2c_ops = { .xfer = sandbox_i2c_xfer, };
@@ -107,5 +98,4 @@ U_BOOT_DRIVER(i2c_sandbox) = { .of_match = sandbox_i2c_ids, .ops = &sandbox_i2c_ops, .priv_auto_alloc_size = sizeof(struct sandbox_i2c_priv), - ACPI_OPS_PTR(&sandbox_i2c_acpi_ops) };
drivers/spi/sandbox_spi.c +0 -10
@@ -133,15 +133,6 @@ static int sandbox_spi_get_mmap(struct udevice *dev, ulong *map_basep,return 0 ; } -static int sandbox_spi_get_name (const struct udevice *dev,char *out_name) -{ -return acpi_copy_name (out_name,"SSPI" ); -} - -struct acpi_ops sandbox_spi_acpi_ops = { - .get_name = sandbox_spi_get_name, -}; -static const struct dm_spi_ops sandbox_spi_ops = { .xfer = sandbox_spi_xfer, .set_speed = sandbox_spi_set_speed,
@@ -160,5 +151,4 @@ U_BOOT_DRIVER(spi_sandbox) = { .id = UCLASS_SPI, .of_match = sandbox_spi_ids, .ops = &sandbox_spi_ops, - ACPI_OPS_PTR(&sandbox_spi_acpi_ops) };
include/acpi/acpi_device.h +15 -0
@@ -382,4 +382,19 @@ int acpi_device_add_power_res(struct acpi_ctx *ctx, u32 tx_state_val,const struct gpio_desc *stop_gpio, uint stop_delay_ms, uint stop_off_delay_ms); +/** +* acpi_device_infer_name() - Infer the name from its uclass or parent +* +* Many ACPI devices have a standard name that can be inferred from the uclass +* they are in, of the uclass of their parent. These rules are implemented in +* this function. It attempts to produce a name for a device based on these +* rules. +* +* @dev: Device to check +* @out_name: Place to put the name (must hold ACPI_NAME_MAX bytes) +* @return 0 if a name was found, -ENOENT if not found, -ENXIO if the device +* sequence number could not be determined +*/ +int acpi_device_infer_name (const struct udevice *dev,char *out_name); +#endif
lib/acpi/acpi_device.c +105 -0
114 lines not on this page · raw message
test/dm/acpi.c +41 -1
53 lines not on this page · raw message
test/dm/acpigen.c +2 -2
@@ -303,7 +303,7 @@ static int dm_test_acpi_i2c(struct unit_test_state *uts)ut_asserteq (6 ,get_unaligned ((u16 *)(ptr +10 )));ut_asserteq (100000 ,get_unaligned ((u32 *)(ptr +12 )));ut_asserteq (0x43 ,get_unaligned ((u16 *)(ptr +16 ))); -ut_asserteq_str ("\\_SB.SI2C" , (char *)ptr +18 ); +ut_asserteq_str ("\\_SB.I2C0" , (char *)ptr +18 );free_context (&ctx);
@@ -339,7 +339,7 @@ static int dm_test_acpi_spi(struct unit_test_state *uts)ut_asserteq (0 , ptr[17 ]);ut_asserteq (0 , ptr[18 ]);ut_asserteq (0 ,get_unaligned ((u16 *)(ptr +19 ))); -ut_asserteq_str ("\\_SB.SSPI" , (char *)ptr +21 ); +ut_asserteq_str ("\\_SB.SPI0" , (char *)ptr +21 );free_context (&ctx);
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
PATCH 35/35 acpi: Add an acpi split command
In reply to Simon GlassAdd a command that shows the individual blocks of data generated by each device. This can be helpful for debugging.
---
Changes in v1: None
cmd/acpi.c | 15 +++++++++++++-- drivers/core/acpi.c | 16 ++++++++++++++++ include/dm/acpi.h | 10 ++++++++++ test/dm/acpi.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-)
cmd/acpi.c +13 -2
@@ -153,6 +153,17 @@ static int do_acpi_list(cmd_tbl_t *cmdtp, int flag, int argc,return 0 ; } +static int do_acpi_items (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +bool dump; + + dump = argc >=2 && !strcmp ("-d" , argv[1 ]); +acpi_dump_items (dump); + +return 0 ; +} +static int do_acpi_dump (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {
@@ -160,8 +171,6 @@ static int do_acpi_dump(cmd_tbl_t *cmdtp, int flag, int argc,char sig[ACPI_NAME_LEN ];int ret; -if (argc <2 ) -return CMD_RET_USAGE ; name = argv[1 ];if (strlen (name) !=ACPI_NAME_LEN ) {printf ("Table name '%s' must be four characters\n" , name);
@@ -179,8 +188,10 @@ static int do_acpi_dump(cmd_tbl_t *cmdtp, int flag, int argc,static char acpi_help_text[] ="list - list ACPI tables\n" +"acpi items [-d] - List/dump each piece of ACPI data from devices\n" "acpi dump <name> - Dump ACPI table" ;U_BOOT_CMD_WITH_SUBCMDS (acpi,"ACPI tables" , acpi_help_text,U_BOOT_SUBCMD_MKENT (list,1 ,1 , do_acpi_list), +U_BOOT_SUBCMD_MKENT (items,2 ,1 , do_acpi_items),U_BOOT_SUBCMD_MKENT (dump,2 ,1 , do_acpi_dump));
drivers/core/acpi.c +16 -0
@@ -118,6 +118,22 @@ static int acpi_add_item(struct acpi_ctx *ctx, struct udevice *dev,return 0 ; } +void acpi_dump_items (bool dump_contents) +{ +int i; + +for (i =0 ; i < item_count; i++) { +struct acpi_item *item = &acpi_item[i]; + +printf ("dev '%s', type %d, size %x\n" , item->dev->name, + item->type, item->size); +if (dump_contents) { +print_buffer (0 , item->buf,1 , item->size,0 ); +printf ("\n" ); + } + } +} +struct acpi_item *find_item (const char *devname) {int i;
include/dm/acpi.h +10 -0
@@ -162,6 +162,16 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx);*/ int acpi_inject_dsdt (struct acpi_ctx *ctx); +/** +* acpi_dump_items() - Dump out the collected ACPI items +* +* This lists the ACPI DSDT and SSDT items generated by the various U-Boot +* drivers. +* +* @dump_contents: true to dump the binary contents, false to just show the list +*/ +void acpi_dump_items (bool dump_contents); +#endif /* __ACPI__ */ #endif
test/dm/acpi.c +39 -0
@@ -525,3 +525,42 @@ static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_inject_dsdt,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test 'acpi items' command */ +static int dm_test_acpi_cmd_items (struct unit_test_state *uts) +{ +struct acpi_ctx ctx; +void *buf; + + buf =malloc (BUF_SIZE ); +ut_assertnonnull (buf); + + ctx.current = buf; +ut_assertok (acpi_fill_ssdt (&ctx)); +console_record_reset (); +run_command ("acpi items" ,0 ); +ut_assert_nextline ("dev 'acpi-test', type 1, size 2" ); +ut_assert_nextline ("dev 'acpi-test2', type 1, size 2" ); +ut_assert_console_end (); + + ctx.current = buf; +ut_assertok (acpi_inject_dsdt (&ctx)); +console_record_reset (); +run_command ("acpi items" ,0 ); +ut_assert_nextline ("dev 'acpi-test', type 2, size 2" ); +ut_assert_nextline ("dev 'acpi-test2', type 2, size 2" ); +ut_assert_console_end (); + +console_record_reset (); +run_command ("acpi items -d" ,0 ); +ut_assert_nextline ("dev 'acpi-test', type 2, size 2" ); +ut_assert_nextlines_are_dump (2 ); +ut_assert_nextline ("%s" ,"" ); +ut_assert_nextline ("dev 'acpi-test2', type 2, size 2" ); +ut_assert_nextlines_are_dump (2 ); +ut_assert_nextline ("%s" ,"" ); +ut_assert_console_end (); + +return 0 ; +} +DM_TEST (dm_test_acpi_cmd_items,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog