diff mbox series

[v1,14/43] acpi: Support writing named values

Message ID 20200615035738.248710-11-sjg@chromium.org
State Accepted
Commit bb6772c3ffb0b2df22fd22cfe8d17276823af06d
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 named integers and strings to the generated ACPI code.

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

 include/acpi/acpigen.h | 72 ++++++++++++++++++++++++++++++++++++++
 lib/acpi/acpigen.c     | 49 ++++++++++++++++++++++++++
 test/dm/acpigen.c      | 78 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 199 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 14/43] acpi: Support writing named values
> 
> Allow writing named integers and strings to the generated ACPI code.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
>  include/acpi/acpigen.h | 72 ++++++++++++++++++++++++++++++++++++++
>  lib/acpi/acpigen.c     | 49 ++++++++++++++++++++++++++
>  test/dm/acpigen.c      | 78 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 199 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 named integers and strings to the generated ACPI code.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  include/acpi/acpigen.h | 72 ++++++++++++++++++++++++++++++++++++++
>  lib/acpi/acpigen.c     | 49 ++++++++++++++++++++++++++
>  test/dm/acpigen.c      | 78 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 199 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 19f84dc867..01620fd36b 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -231,6 +231,78 @@  void acpigen_write_one(struct acpi_ctx *ctx);
  */
 void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
 
+/**
+ * acpigen_write_name_zero() - Write a named zero value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ */
+void acpigen_write_name_zero(struct acpi_ctx *ctx, const char *name);
+
+/**
+ * acpigen_write_name_one() - Write a named one value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ */
+void acpigen_write_name_one(struct acpi_ctx *ctx, const char *name);
+
+/**
+ * acpigen_write_name_byte() - Write a named byte value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ * @val: Value to write
+ */
+void acpigen_write_name_byte(struct acpi_ctx *ctx, const char *name, uint val);
+
+/**
+ * acpigen_write_name_word() - Write a named word value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ * @val: Value to write
+ */
+void acpigen_write_name_word(struct acpi_ctx *ctx, const char *name, uint val);
+
+/**
+ * acpigen_write_name_dword() - Write a named dword value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ * @val: Value to write
+ */
+void acpigen_write_name_dword(struct acpi_ctx *ctx, const char *name, uint val);
+
+/**
+ * acpigen_write_name_qword() - Write a named qword value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ * @val: Value to write
+ */
+void acpigen_write_name_qword(struct acpi_ctx *ctx, const char *name, u64 val);
+
+/**
+ * acpigen_write_name_integer() - Write a named integer value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ * @val: Value to write
+ */
+void acpigen_write_name_integer(struct acpi_ctx *ctx, const char *name,
+				u64 val);
+
+/**
+ * acpigen_write_name_string() - Write a named string value
+ *
+ * @ctx: ACPI context pointer
+ * @name: Name of the value
+ * @string: String to write
+ */
+void acpigen_write_name_string(struct acpi_ctx *ctx, const char *name,
+			       const char *string);
+
 /**
  * acpigen_write_string() - Write a string
  *
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
index 5fe1f59f82..86af88d1bc 100644
--- a/lib/acpi/acpigen.c
+++ b/lib/acpi/acpigen.c
@@ -142,6 +142,55 @@  void acpigen_write_integer(struct acpi_ctx *ctx, u64 data)
 		acpigen_write_qword(ctx, data);
 }
 
+void acpigen_write_name_zero(struct acpi_ctx *ctx, const char *name)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_zero(ctx);
+}
+
+void acpigen_write_name_one(struct acpi_ctx *ctx, const char *name)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_one(ctx);
+}
+
+void acpigen_write_name_byte(struct acpi_ctx *ctx, const char *name, uint val)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_byte(ctx, val);
+}
+
+void acpigen_write_name_word(struct acpi_ctx *ctx, const char *name, uint val)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_word(ctx, val);
+}
+
+void acpigen_write_name_dword(struct acpi_ctx *ctx, const char *name, uint val)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_dword(ctx, val);
+}
+
+void acpigen_write_name_qword(struct acpi_ctx *ctx, const char *name, u64 val)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_qword(ctx, val);
+}
+
+void acpigen_write_name_integer(struct acpi_ctx *ctx, const char *name, u64 val)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_integer(ctx, val);
+}
+
+void acpigen_write_name_string(struct acpi_ctx *ctx, const char *name,
+			       const char *string)
+{
+	acpigen_write_name(ctx, name);
+	acpigen_write_string(ctx, string);
+}
+
 void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size)
 {
 	int i;
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index 5cd7fb5657..4fcd155b93 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -1010,3 +1010,81 @@  static int dm_test_acpi_device(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_acpi_device, 0);
+
+/* Test writing named values */
+static int dm_test_acpi_write_name(struct unit_test_state *uts)
+{
+	const char *name = "\\_SB." ACPI_TEST_DEV_NAME;
+	struct acpi_ctx *ctx;
+	u8 *ptr;
+
+	ut_assertok(alloc_context(&ctx));
+	ptr = acpigen_get_current(ctx);
+
+	acpigen_write_name_zero(ctx, name);
+	acpigen_write_name_one(ctx, name);
+	acpigen_write_name_byte(ctx, name, TEST_INT8);
+	acpigen_write_name_word(ctx, name, TEST_INT16);
+	acpigen_write_name_dword(ctx, name, TEST_INT32);
+	acpigen_write_name_qword(ctx, name, TEST_INT64);
+	acpigen_write_name_integer(ctx, name, TEST_INT64 + 1);
+	acpigen_write_name_string(ctx, name, "baldrick");
+	acpigen_write_name_string(ctx, name, NULL);
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ut_asserteq_strn("\\._SB_ABCD", (char *)ptr);
+	ptr += 10;
+	ut_asserteq(ZERO_OP, *ptr++);
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(ONE_OP, *ptr++);
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(BYTE_PREFIX, *ptr++);
+	ut_asserteq(TEST_INT8, *ptr++);
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(WORD_PREFIX, *ptr++);
+	ut_asserteq(TEST_INT16, get_unaligned((u16 *)ptr));
+	ptr += 2;
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(DWORD_PREFIX, *ptr++);
+	ut_asserteq(TEST_INT32, get_unaligned((u32 *)ptr));
+	ptr += 4;
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(QWORD_PREFIX, *ptr++);
+	ut_asserteq_64(TEST_INT64, get_unaligned((u64 *)ptr));
+	ptr += 8;
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(QWORD_PREFIX, *ptr++);
+	ut_asserteq_64(TEST_INT64 + 1, get_unaligned((u64 *)ptr));
+	ptr += 8;
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(STRING_PREFIX, *ptr++);
+	ut_asserteq_str("baldrick", (char *)ptr)
+	ptr += 9;
+
+	ut_asserteq(NAME_OP, *ptr++);
+	ptr += 10;
+	ut_asserteq(STRING_PREFIX, *ptr++);
+	ut_asserteq('\0', *ptr++);
+
+	ut_asserteq_ptr(ptr, ctx->current);
+
+	free_context(&ctx);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_write_name, 0);
+