All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v1 08/35] acpi: Support string output
Date: Tue, 28 Apr 2020 20:21:32 -0600	[thread overview]
Message-ID: <20200429022159.254271-6-sjg@chromium.org> (raw)
In-Reply-To: <20200429022159.254271-1-sjg@chromium.org>

Add support for output of strings and streams of bytes.

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

Changes in v1: None

 include/acpi/acpigen.h | 19 +++++++++++++++++++
 lib/acpi/acpigen.c     | 14 ++++++++++++++
 test/dm/acpigen.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)

diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
index 8809cdb4e1..7365cce738 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -46,4 +46,23 @@ void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
  */
 void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
 
+/**
+ * acpigen_emit_stream() - Emit a stream of bytes
+ *
+ * @ctx: ACPI context pointer
+ * @data: Data to output
+ * @size: Size of data in bytes
+ */
+void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
+
+/**
+ * acpigen_emit_string() - Emit a string
+ *
+ * Emit a string with a nul terminator
+ *
+ * @ctx: ACPI context pointer
+ * @str: String to output, or NULL for an empty string
+ */
+void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
+
 #endif
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
index 59bd3af0b7..1223f0d1c4 100644
--- a/lib/acpi/acpigen.c
+++ b/lib/acpi/acpigen.c
@@ -36,3 +36,17 @@ void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)
 	acpigen_emit_byte(ctx, (data >> 16) & 0xff);
 	acpigen_emit_byte(ctx, (data >> 24) & 0xff);
 }
+
+void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size)
+{
+	int i;
+
+	for (i = 0; i < size; i++)
+		acpigen_emit_byte(ctx, data[i]);
+}
+
+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 */
+}
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index ab1261db9f..77d1a3bba6 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -17,6 +17,9 @@
 #include <dm/test.h>
 #include <test/ut.h>
 
+#define TEST_STRING	"frogmore"
+#define TEST_STREAM2	"\xfa\xde"
+
 static int alloc_context(struct acpi_ctx **ctxp)
 {
 	struct acpi_ctx *ctx;
@@ -66,6 +69,45 @@ static int dm_test_acpi_emit_simple(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_acpi_emit_simple, 0);
 
+/* Test emitting a stream */
+static int dm_test_acpi_emit_stream(struct unit_test_state *uts)
+{
+	struct acpi_ctx *ctx;
+	u8 *ptr;
+
+	ut_assertok(alloc_context(&ctx));
+
+	ptr = acpigen_get_current(ctx);
+	acpigen_emit_stream(ctx, TEST_STREAM2, 2);
+	ut_asserteq(2, acpigen_get_current(ctx) - ptr);
+	ut_asserteq((u8)TEST_STREAM2[0], ptr[0]);
+	ut_asserteq((u8)TEST_STREAM2[1], ptr[1]);
+
+	free_context(&ctx);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_emit_stream, 0);
+
+/* Test emitting a string */
+static int dm_test_acpi_emit_string(struct unit_test_state *uts)
+{
+	struct acpi_ctx *ctx;
+	u8 *ptr;
+
+	ut_assertok(alloc_context(&ctx));
+
+	ptr = acpigen_get_current(ctx);
+	acpigen_emit_string(ctx, TEST_STRING);
+	ut_asserteq(sizeof(TEST_STRING), acpigen_get_current(ctx) - ptr);
+	ut_asserteq_str(TEST_STRING, (char *)ptr);
+
+	free_context(&ctx);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_emit_string, 0);
+
 /* Test emitting an interrupt descriptor */
 static int dm_test_acpi_interrupt(struct unit_test_state *uts)
 {
-- 
2.26.2.303.gf8c07b1a785-goog

  parent reply	other threads:[~2020-04-29  2:21 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29  2:21 [PATCH v1 00/35] dm: Add programmatic generation of ACPI tables (part B) Simon Glass
2020-04-29  2:21 ` [PATCH v1 01/35] dm: core: Add an ACPI name for the root node Simon Glass
2020-04-30 12:44   ` Antwort: " Wolfgang Wallner
2020-04-29  2:21 ` [PATCH v1 02/35] acpi: Add a function to get a device path and scope Simon Glass
2020-04-29  2:21 ` [PATCH v1 03/35] acpi: Add a way to check device status Simon Glass
2020-04-29  2:21 ` [PATCH v1 04/35] irq: Add a method to convert an interrupt to ACPI Simon Glass
2020-04-29  2:21 ` [PATCH v1 05/35] acpi: Support generation of ACPI code Simon Glass
2020-04-29  2:21 ` [PATCH v1 06/35] acpi: Support generation of interrupt descriptor Simon Glass
2020-04-29  2:21 ` [PATCH v1 07/35] gpio: Add a method to convert a GPIO to ACPI Simon Glass
2020-04-29  2:21 ` Simon Glass [this message]
2020-04-29  2:21 ` [PATCH v1 09/35] acpi: Support generation of GPIO descriptor Simon Glass
2020-04-29  2:21 ` [PATCH v1 10/35] acpi: Support generation of a GPIO/irq for a device Simon Glass
2020-04-29  2:21 ` [PATCH v1 11/35] acpi: Support generation of I2C descriptor Simon Glass
2020-04-29  2:21 ` [PATCH v1 12/35] acpi: Support generation of SPI descriptor Simon Glass
2020-04-29  2:21 ` [PATCH v1 13/35] acpigen: Support writing a length Simon Glass
2020-04-29  2:21 ` [PATCH v1 14/35] acpigen: Support writing a package Simon Glass
2020-04-29  2:21 ` [PATCH v1 15/35] acpi: Support writing an integer Simon Glass
2020-04-29  2:21 ` [PATCH v1 16/35] acpi: Support writing a string Simon Glass
2020-04-29  2:21 ` [PATCH v1 17/35] acpi: Support writing a name Simon Glass
2020-04-29  2:21 ` [PATCH v1 18/35] acpi: Support writing a UUID Simon Glass
2020-04-29  2:21 ` [PATCH v1 19/35] acpi: Support writing Device Properties objects via _DSD Simon Glass
2020-04-29  2:21 ` [PATCH v1 20/35] acpi: Support writing a GPIO Simon Glass
2020-04-29  2:21 ` [PATCH v1 21/35] acpi: Support copying properties from device tree to ACPI Simon Glass
2020-04-29  2:21 ` [PATCH v1 22/35] acpi: Add support for various misc ACPI opcodes Simon Glass
2020-04-29  2:21 ` [PATCH v1 23/35] acpi: Add support for writing a Power Resource Simon Glass
2020-04-29  2:21 ` [PATCH v1 24/35] acpi: Add support for writing a GPIO power sequence Simon Glass
2020-04-29  2:21 ` [PATCH v1 25/35] acpi: Add support for a generic " Simon Glass
2020-04-29  2:21 ` [PATCH v1 26/35] acpi: Add support for SSDT generation Simon Glass
2020-04-29  2:21 ` [PATCH v1 27/35] x86: acpi: Move MADT down a bit Simon Glass
2020-04-29  2:21 ` [PATCH v1 28/35] acpi: Record the items added to SSDT Simon Glass
2020-04-29  2:21 ` [PATCH v1 29/35] acpi: Support ordering SSDT data by device Simon Glass
2020-04-29  2:21 ` [PATCH v1 30/35] x86: Allow devices to write an SSDT Simon Glass
2020-04-29  2:21 ` [PATCH v1 31/35] acpi: Add support for DSDT generation Simon Glass
2020-04-29  2:21 ` [PATCH v1 32/35] x86: Allow devices to write to DSDT Simon Glass
2020-04-29  2:21 ` [PATCH v1 33/35] pci: Avoid a crash in device_is_on_pci_bus() Simon Glass
2020-04-29  2:21 ` [PATCH v1 34/35] dm: acpi: Enhance acpi_get_name() Simon Glass
2020-04-29  2:21 ` [PATCH v1 35/35] acpi: Add an acpi split command Simon Glass
2020-04-30 13:52 ` Antwort: [PATCH v1 02/35] acpi: Add a function to get a device path and scope Wolfgang Wallner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200429022159.254271-6-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.