diff mbox series

[v1,13/43] acpi: Support generation of a device

Message ID 20200615035738.248710-10-sjg@chromium.org
State Accepted
Commit 91c2f9c32ed76269b9786a6c506233e9b91bdfce
Headers show
Series x86: Programmatic generation of ACPI tables (Part C) | expand

Commit Message

Simon Glass June 15, 2020, 3:57 a.m. UTC
Allow writing an ACPI device to the generated ACPI code.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 include/acpi/acpigen.h |  9 +++++++++
 lib/acpi/acpigen.c     |  7 +++++++
 test/dm/acpigen.c      | 27 +++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

Comments

Wolfgang Wallner June 25, 2020, 10:55 a.m. UTC | #1
Hi Simon,

-----"Simon Glass" <sjg at chromium.org> schrieb: -----
> 
> Betreff: [PATCH v1 13/43] acpi: Support generation of a device
> 
> Allow writing an ACPI device to the generated ACPI code.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
>  include/acpi/acpigen.h |  9 +++++++++
>  lib/acpi/acpigen.c     |  7 +++++++
>  test/dm/acpigen.c      | 27 +++++++++++++++++++++++++++
>  3 files changed, 43 insertions(+)

Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>
Bin Meng June 30, 2020, 5:58 a.m. UTC | #2
On Mon, Jun 15, 2020 at 11:57 AM Simon Glass <sjg at chromium.org> wrote:
>
> Allow writing an ACPI device to the generated ACPI code.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  include/acpi/acpigen.h |  9 +++++++++
>  lib/acpi/acpigen.c     |  7 +++++++
>  test/dm/acpigen.c      | 27 +++++++++++++++++++++++++++
>  3 files changed, 43 insertions(+)
>

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
diff mbox series

Patch

diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
index 4361a28a08..19f84dc867 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -56,6 +56,7 @@  enum {
 	AND_OP			= 0x7b,
 	OR_OP			= 0x7d,
 	NOT_OP			= 0x80,
+	DEVICE_OP		= 0x82,
 	POWER_RES_OP		= 0x84,
 	RETURN_OP		= 0xa4,
 };
@@ -310,6 +311,14 @@  void acpigen_write_method(struct acpi_ctx *ctx, const char *name, int nargs);
 void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name,
 				     int nargs);
 
+/**
+ * acpigen_write_device() - Write an ACPI device
+ *
+ * @ctx: ACPI context pointer
+ * @name: Device name to write
+ */
+void acpigen_write_device(struct acpi_ctx *ctx, const char *name);
+
 /**
  * acpigen_write_sta() - Write a _STA method
  *
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
index 6f5972f1f7..5fe1f59f82 100644
--- a/lib/acpi/acpigen.c
+++ b/lib/acpi/acpigen.c
@@ -288,6 +288,13 @@  void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name,
 			      ACPI_METHOD_SERIALIZED_MASK);
 }
 
+void acpigen_write_device(struct acpi_ctx *ctx, const char *name)
+{
+	acpigen_emit_ext_op(ctx, DEVICE_OP);
+	acpigen_write_len_f(ctx);
+	acpigen_emit_namestring(ctx, name);
+}
+
 void acpigen_write_sta(struct acpi_ctx *ctx, uint status)
 {
 	/* Method (_STA, 0, NotSerialized) { Return (status) } */
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index 80697300e7..5cd7fb5657 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -983,3 +983,30 @@  static int dm_test_acpi_resource_template(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_acpi_resource_template, 0);
+
+/* Test writing a device */
+static int dm_test_acpi_device(struct unit_test_state *uts)
+{
+	struct acpi_ctx *ctx;
+	u8 *ptr;
+
+	ut_assertok(alloc_context(&ctx));
+	ptr = acpigen_get_current(ctx);
+
+	acpigen_write_device(ctx, "\\_SB." ACPI_TEST_DEV_NAME);
+	acpigen_pop_len(ctx);
+
+	ut_asserteq(EXT_OP_PREFIX, *ptr++);
+	ut_asserteq(DEVICE_OP, *ptr++);
+	ut_asserteq(0xd, get_length(ptr));
+	ptr += 3;
+	ut_asserteq(ROOT_PREFIX, *ptr++);
+	ut_asserteq(DUAL_NAME_PREFIX, *ptr++);
+	ptr += 8;
+	ut_asserteq_ptr(ptr, ctx->current);
+
+	free_context(&ctx);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_device, 0);