aboutsummaryrefslogtreecommitdiff
path: root/test/dm/acpigen.c
diff options
context:
space:
mode:
authorSimon Glass2020-07-07 13:11:54 -0600
committerBin Meng2020-07-17 14:32:24 +0800
commit7aed90d44c07ff4ea2f05e7a7b167040fe99f64f (patch)
treeb9cc8fcf5292a4cb42c8558114744a7e63cd2967 /test/dm/acpigen.c
parent3df33bda5c92a1a8b46b83ac9521fcf48a2fe50f (diff)
acpi: Support writing a name
ACPI supports storing names which are made up of multiple path components. Several special cases are supported. Add a function to emit a name. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'test/dm/acpigen.c')
-rw-r--r--test/dm/acpigen.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index c360f55dd3d..adfcf887655 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -505,3 +505,96 @@ static int dm_test_acpi_string(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_acpi_string, 0);
+
+/* Test writing a name */
+static int dm_test_acpi_name(struct unit_test_state *uts)
+{
+ struct acpi_ctx *ctx;
+ u8 *ptr;
+
+ ut_assertok(alloc_context(&ctx));
+
+ ptr = acpigen_get_current(ctx);
+
+ /*
+ * The names here are made up for testing the various cases. The
+ * grammar is in the ACPI spec 6.3 section 19.2.2
+ */
+ acpigen_write_name(ctx, "\\_SB");
+ acpigen_write_name(ctx, "\\_SB.I2C0");
+ acpigen_write_name(ctx, "\\_SB.I2C0.TPM2");
+ acpigen_write_name(ctx, "\\_SB.I2C0.TPM2.LONG");
+ acpigen_write_name(ctx, "^^^^SPI0.FLAS");
+ acpigen_write_name(ctx, "NN");
+ acpigen_write_name(ctx, "^AB.CD.D.EFG");
+ acpigen_write_name(ctx, "^^^^");
+ acpigen_write_name(ctx, "\\");
+ acpigen_write_name(ctx, "\\ABCD");
+
+ ut_asserteq(107, acpigen_get_current(ctx) - ptr);
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq_strn("\\_SB_", (char *)ptr + 1);
+ ptr += 6;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('\\', ptr[1]);
+ ut_asserteq(DUAL_NAME_PREFIX, ptr[2]);
+ ut_asserteq_strn("_SB_I2C0", (char *)ptr + 3);
+ ptr += 11;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('\\', ptr[1]);
+ ut_asserteq(MULTI_NAME_PREFIX, ptr[2]);
+ ut_asserteq(3, ptr[3]);
+ ut_asserteq_strn("_SB_I2C0TPM2", (char *)ptr + 4);
+ ptr += 16;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('\\', ptr[1]);
+ ut_asserteq(MULTI_NAME_PREFIX, ptr[2]);
+ ut_asserteq(4, ptr[3]);
+ ut_asserteq_strn("_SB_I2C0TPM2LONG", (char *)ptr + 4);
+ ptr += 20;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('^', ptr[1]);
+ ut_asserteq('^', ptr[2]);
+ ut_asserteq('^', ptr[3]);
+ ut_asserteq('^', ptr[4]);
+ ut_asserteq(DUAL_NAME_PREFIX, ptr[5]);
+ ut_asserteq_strn("SPI0FLAS", (char *)ptr + 6);
+ ptr += 14;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq_strn("NN__", (char *)ptr + 1);
+ ptr += 5;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('^', ptr[1]);
+ ut_asserteq(MULTI_NAME_PREFIX, ptr[2]);
+ ut_asserteq(4, ptr[3]);
+ ut_asserteq_strn("AB__CD__D___EFG_", (char *)ptr + 4);
+ ptr += 20;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('^', ptr[1]);
+ ut_asserteq('^', ptr[2]);
+ ut_asserteq('^', ptr[3]);
+ ut_asserteq('^', ptr[4]);
+ ut_asserteq(ZERO_OP, ptr[5]);
+ ptr += 6;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq('\\', ptr[1]);
+ ut_asserteq(ZERO_OP, ptr[2]);
+ ptr += 3;
+
+ ut_asserteq(NAME_OP, ptr[0]);
+ ut_asserteq_strn("\\ABCD", (char *)ptr + 1);
+ ptr += 5;
+
+ free_context(&ctx);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_name, 0);