All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 05/35] acpi: Support generation of ACPI code
Date: Sun, 10 May 2020 14:33:39 -0600	[thread overview]
Message-ID: <20200510203409.203520-4-sjg@chromium.org> (raw)
In-Reply-To: <20200510203409.203520-1-sjg@chromium.org>

Add a new file to handle generating ACPI code programatically. This is
used when information must be dynamically added to the tables, e.g. the
SSDT.

Initial support is just for writing simple values.

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

Changes in v2: None
Changes in v1: None

 include/acpi/acpigen.h | 49 +++++++++++++++++++++++++++++++
 lib/acpi/Makefile      |  1 +
 lib/acpi/acpigen.c     | 38 ++++++++++++++++++++++++
 test/dm/Makefile       |  1 +
 test/dm/acpigen.c      | 65 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 154 insertions(+)
 create mode 100644 include/acpi/acpigen.h
 create mode 100644 lib/acpi/acpigen.c
 create mode 100644 test/dm/acpigen.c

diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
new file mode 100644
index 0000000000..8809cdb4e1
--- /dev/null
+++ b/include/acpi/acpigen.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Core ACPI (Advanced Configuration and Power Interface) support
+ *
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot file acpigen.h
+ */
+
+#ifndef __ACPI_ACPIGEN_H
+#define __ACPI_ACPIGEN_H
+
+#include <linux/types.h>
+
+struct acpi_ctx;
+
+/**
+ * acpigen_get_current() - Get the current ACPI code output pointer
+ *
+ * @ctx: ACPI context pointer
+ * @return output pointer
+ */
+u8 *acpigen_get_current(struct acpi_ctx *ctx);
+
+/**
+ * acpigen_emit_byte() - Emit a byte to the ACPI code
+ *
+ * @ctx: ACPI context pointer
+ * @data: Value to output
+ */
+void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
+
+/**
+ * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
+ *
+ * @ctx: ACPI context pointer
+ * @data: Value to output
+ */
+void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
+
+/**
+ * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
+ *
+ * @ctx: ACPI context pointer
+ * @data: Value to output
+ */
+void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
+
+#endif
diff --git a/lib/acpi/Makefile b/lib/acpi/Makefile
index caae6c01bd..85a1f774ad 100644
--- a/lib/acpi/Makefile
+++ b/lib/acpi/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 #
 
+obj-y += acpigen.o
 obj-y += acpi_device.o
 obj-y += acpi_table.o
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
new file mode 100644
index 0000000000..59bd3af0b7
--- /dev/null
+++ b/lib/acpi/acpigen.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Generation of ACPI (Advanced Configuration and Power Interface) tables
+ *
+ * Copyright 2019 Google LLC
+ * Mostly taken from coreboot
+ */
+
+#define LOG_CATEGORY LOGC_ACPI
+
+#include <common.h>
+#include <dm.h>
+#include <acpi/acpigen.h>
+#include <dm/acpi.h>
+
+u8 *acpigen_get_current(struct acpi_ctx *ctx)
+{
+	return ctx->current;
+}
+
+void acpigen_emit_byte(struct acpi_ctx *ctx, uint data)
+{
+	*(u8 *)ctx->current++ = data;
+}
+
+void acpigen_emit_word(struct acpi_ctx *ctx, uint data)
+{
+	acpigen_emit_byte(ctx, data & 0xff);
+	acpigen_emit_byte(ctx, (data >> 8) & 0xff);
+}
+
+void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)
+{
+	acpigen_emit_byte(ctx, data & 0xff);
+	acpigen_emit_byte(ctx, (data >> 8) & 0xff);
+	acpigen_emit_byte(ctx, (data >> 16) & 0xff);
+	acpigen_emit_byte(ctx, (data >> 24) & 0xff);
+}
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 6c18fd04ce..e3e0cccf01 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
 obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_ACPIGEN) += acpi.o
+obj-$(CONFIG_ACPIGEN) += acpigen.o
 obj-$(CONFIG_SOUND) += audio.o
 obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BOARD) += board.o
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
new file mode 100644
index 0000000000..68f2b73132
--- /dev/null
+++ b/test/dm/acpigen.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for ACPI code generation
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <acpi/acpigen.h>
+#include <asm/unaligned.h>
+#include <dm/acpi.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int alloc_context(struct acpi_ctx **ctxp)
+{
+	struct acpi_ctx *ctx;
+
+	*ctxp = NULL;
+	ctx = malloc(sizeof(*ctx));
+	if (!ctx)
+		return -ENOMEM;
+	ctx->current = malloc(150);
+	if (!ctx->current)
+		return -ENOMEM;
+	*ctxp = ctx;
+
+	return 0;
+}
+
+static void free_context(struct acpi_ctx **ctxp)
+{
+	free(*ctxp);
+	*ctxp = NULL;
+}
+
+/* Test emitting simple types and acpigen_get_current() */
+static int dm_test_acpi_emit_simple(struct unit_test_state *uts)
+{
+	struct acpi_ctx *ctx;
+	u8 *ptr;
+
+	ut_assertok(alloc_context(&ctx));
+
+	ptr = acpigen_get_current(ctx);
+	acpigen_emit_byte(ctx, 0x23);
+	ut_asserteq(1, acpigen_get_current(ctx) - ptr);
+	ut_asserteq(0x23, *(u8 *)ptr);
+
+	acpigen_emit_word(ctx, 0x1234);
+	ut_asserteq(3, acpigen_get_current(ctx) - ptr);
+	ut_asserteq(0x1234, get_unaligned((u16 *)(ptr + 1)));
+
+	acpigen_emit_dword(ctx, 0x87654321);
+	ut_asserteq(7, acpigen_get_current(ctx) - ptr);
+	ut_asserteq(0x87654321, get_unaligned((u32 *)(ptr + 3)));
+
+	free_context(&ctx);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_emit_simple, 0);
-- 
2.26.2.645.ge9eca65c58-goog

  parent reply	other threads:[~2020-05-10 20:33 UTC|newest]

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