[PATCH v2 16/35] acpi: Support writing a string
Simon Glass
sjg at chromium.org
Sun May 10 22:33:50 CEST 2020
ACPI supports storing a simple nul-terminated string. Add support for
this.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2: None
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(-)
diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
index a4edcb097b..f65de53a76 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -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
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
index ece0111320..a4ac3c8875 100644
--- a/lib/acpi/acpigen.c
+++ b/lib/acpi/acpigen.c
@@ -146,3 +146,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);
+}
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index 9350943a12..dc6993b7a7 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -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);
--
2.26.2.645.ge9eca65c58-goog
More information about the U-Boot
mailing list