[PATCH v1 09/43] acpi: Support generation of a scope

Wolfgang Wallner wolfgang.wallner at br-automation.com
Thu Jun 25 12:55:01 CEST 2020


Hi Simon,

-----"Simon Glass" <sjg at chromium.org> schrieb: -----
> Betreff: [PATCH v1 09/43] acpi: Support generation of a scope
> 
> Add a function to write a scope to the generated ACPI code.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
>  include/acpi/acpigen.h | 10 ++++++++++
>  lib/acpi/acpigen.c     |  7 +++++++
>  test/dm/acpi.c         |  3 +--
>  test/dm/acpigen.c      | 33 ++++++++++++++++++++++++++++++++-
>  4 files changed, 50 insertions(+), 3 deletions(-)
> 
> diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
> index 7c117c1cf6..af66c9828f 100644
> --- a/include/acpi/acpigen.h
> +++ b/include/acpi/acpigen.h
> @@ -31,6 +31,7 @@ enum {
>  	DWORD_PREFIX		= 0x0c,
>  	STRING_PREFIX		= 0x0d,
>  	QWORD_PREFIX		= 0x0e,
> +	SCOPE_OP		= 0x10,
>  	BUFFER_OP		= 0x11,
>  	PACKAGE_OP		= 0x12,
>  	METHOD_OP		= 0x14,
> @@ -258,6 +259,14 @@ void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
>   */
>  void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);
>  
> +/**
> + * acpigen_write_scope() - Write a scope
> + *
> + * @ctx: ACPI context pointer
> + * @name: Scope to write (e.g. "\\_SB.ABCD")

Nit: IMHO 'path' or 'scope' wopuld be better names for this parameter, as
it is usually not a single device name.

> + */
> +void acpigen_write_scope(struct acpi_ctx *ctx, const char *name);
> +
>  /**
>   * acpigen_write_uuid() - Write a UUID
>   *
> @@ -396,6 +405,7 @@ void acpigen_write_power_res(struct acpi_ctx *ctx, const char *name, uint level,
>   */
>  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
> diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
> index e0af36f775..77d6434806 100644
> --- a/lib/acpi/acpigen.c
> +++ b/lib/acpi/acpigen.c
> @@ -257,6 +257,13 @@ void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath)
>  	acpigen_emit_namestring(ctx, namepath);
>  }
>  
> +void acpigen_write_scope(struct acpi_ctx *ctx, const char *name)
> +{
> +	acpigen_emit_byte(ctx, SCOPE_OP);
> +	acpigen_write_len_f(ctx);
> +	acpigen_emit_namestring(ctx, name);
> +}
> +
>  static void acpigen_write_method_(struct acpi_ctx *ctx, const char *name,
>  				  uint flags)
>  {
> diff --git a/test/dm/acpi.c b/test/dm/acpi.c
> index 7768f9514c..b94c4ba4d1 100644
> --- a/test/dm/acpi.c
> +++ b/test/dm/acpi.c
> @@ -20,9 +20,8 @@
>  #include <dm/acpi.h>
>  #include <dm/test.h>
>  #include <test/ut.h>
> +#include "acpi.h"
>  
> -#define ACPI_TEST_DEV_NAME	"ABCD"
> -#define ACPI_TEST_CHILD_NAME	"EFGH"
>  #define BUF_SIZE		4096
>  
>  /**
> diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
> index 0322dd4f60..93dfa301d6 100644
> --- a/test/dm/acpigen.c
> +++ b/test/dm/acpigen.c
> @@ -18,6 +18,7 @@
>  #include <dm/test.h>
>  #include <dm/uclass-internal.h>
>  #include <test/ut.h>
> +#include "acpi.h"
>  
>  #define TEST_STRING	"frogmore"
>  #define TEST_STRING2	"ranch"
> @@ -359,7 +360,7 @@ DM_TEST(dm_test_acpi_spi, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
>   */
>  static int get_length(u8 *ptr)
>  {
> -	if (!(*ptr & 0x80))
> +	if (!(*ptr & ACPI_PKG_LEN_3_BYTES))
>  		return -EINVAL;
>  
>  	return (*ptr & 0xf) | ptr[1] << 4 | ptr[2] << 12;
> @@ -906,3 +907,33 @@ static int dm_test_acpi_write_values(struct unit_test_state *uts)
>  }
>  DM_TEST(dm_test_acpi_write_values, 0);
>  
> +/* Test writing a scope */
> +static int dm_test_acpi_scope(struct unit_test_state *uts)
> +{
> +	char buf[ACPI_PATH_MAX];
> +	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_TEST_ACPI, &dev));
> +	ut_assertok(acpi_device_path(dev, buf, sizeof(buf)));
> +	acpigen_write_scope(ctx, buf);
> +	acpigen_pop_len(ctx);
> +
> +	ut_asserteq(SCOPE_OP, *ptr++);
> +	ut_asserteq(13, get_length(ptr));
> +	ptr += 3;
> +	ut_asserteq(ROOT_PREFIX, *ptr++);
> +	ut_asserteq(DUAL_NAME_PREFIX, *ptr++);
> +	ut_asserteq_strn("_SB_" ACPI_TEST_DEV_NAME, (char *)ptr);
> +	ptr += 8;
> +	ut_asserteq_ptr(ptr, ctx->current);
> +
> +	free_context(&ctx);
> +
> +	return 0;
> +}
> +DM_TEST(dm_test_acpi_scope, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
> -- 
> 2.27.0.290.gba653c62da-goog

Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>



More information about the U-Boot mailing list