]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
acpi: Support generation of a device
authorSimon Glass <sjg@chromium.org>
Wed, 8 Jul 2020 03:32:14 +0000 (21:32 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Fri, 17 Jul 2020 06:32:24 +0000 (14:32 +0800)
Allow writing an ACPI device to the generated ACPI code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
[bmeng: Fix build failures on Sandbox]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
include/acpi/acpigen.h
lib/acpi/acpigen.c
test/dm/acpigen.c

index 1f37c9c31cdfaa5cb32c3ed611ababa0b858e618..59d7c2ff6f35aabfa80a5436ab8508422145d37b 100644 (file)
@@ -56,6 +56,7 @@ enum {
        AND_OP                  = 0x7b,
        OR_OP                   = 0x7d,
        NOT_OP                  = 0x80,
+       DEVICE_OP               = 0x82,
        POWER_RES_OP            = 0x84,
        RETURN_OP               = 0xa4,
 };
@@ -313,6 +314,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
  *
index 45691b79610ae4d00daf8d83a13193edbceaa225..a66601a1383f50461436121ddeb2f7860edd425f 100644 (file)
@@ -291,6 +291,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) } */
index 822641afb01220a9a9c708eede08a13f88650401..cea1a62b950e7965af063f0eb0a8b3be527401c0 100644 (file)
@@ -993,3 +993,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, acpi_test_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);