aboutsummaryrefslogtreecommitdiff
path: root/lib/acpi
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-07-07 13:11:55 -0600
committerBin Meng <bmeng.cn@gmail.com>2020-07-17 14:32:24 +0800
commit29df845204e6b67583491b3c9883432c3a74d923 (patch)
treec980614d634f18b49ee01342b2d3cf7a23e2a324 /lib/acpi
parent7aed90d44c07ff4ea2f05e7a7b167040fe99f64f (diff)
downloadu-boot-29df845204e6b67583491b3c9883432c3a74d923.zip
u-boot-29df845204e6b67583491b3c9883432c3a74d923.tar.gz
u-boot-29df845204e6b67583491b3c9883432c3a74d923.tar.bz2
acpi: Support writing a UUID
ACPI supports writing a UUID in a special format. Add a function to handle this. 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 'lib/acpi')
-rw-r--r--lib/acpi/acpigen.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
index 0a6c1e3..3e8374e 100644
--- a/lib/acpi/acpigen.c
+++ b/lib/acpi/acpigen.c
@@ -11,6 +11,7 @@
#include <common.h>
#include <dm.h>
#include <log.h>
+#include <uuid.h>
#include <acpi/acpigen.h>
#include <dm/acpi.h>
@@ -249,3 +250,40 @@ void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath)
acpigen_emit_byte(ctx, NAME_OP);
acpigen_emit_namestring(ctx, namepath);
}
+
+/*
+ * ToUUID(uuid)
+ *
+ * ACPI 6.3 Section 19.6.142 table 19-438 defines a special output order for the
+ * bytes that make up a UUID Buffer object:
+ *
+ * UUID byte order for input to this function:
+ * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
+ *
+ * UUID byte order output by this function:
+ * ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp
+ */
+int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid)
+{
+ u8 buf[UUID_BIN_LEN];
+ int ret;
+
+ /* Parse UUID string into bytes */
+ ret = uuid_str_to_bin(uuid, buf, UUID_STR_FORMAT_GUID);
+ if (ret)
+ return log_msg_ret("bad hex", -EINVAL);
+
+ /* BufferOp */
+ acpigen_emit_byte(ctx, BUFFER_OP);
+ acpigen_write_len_f(ctx);
+
+ /* Buffer length in bytes */
+ acpigen_write_word(ctx, UUID_BIN_LEN);
+
+ /* Output UUID in expected order */
+ acpigen_emit_stream(ctx, (char *)buf, UUID_BIN_LEN);
+
+ acpigen_pop_len(ctx);
+
+ return 0;
+}