diff mbox series

[v5,20/29] acpi: Add support for DMAR

Message ID 20200408165737.v5.20.Iffd9fd365ee53abc99a8f1e85c40d30c9368c19d@changeid
State Superseded
Headers show
Series dm: Add programmatic generation of ACPI tables (part A) | expand

Commit Message

Simon Glass April 8, 2020, 10:57 p.m. UTC
The DMA Remapping Reporting (DMAR) table contains information about DMA
remapping.

Add a version simple version of this table with only the minimum fields
filled out. i.e. no entries.

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>
Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v5:
- Add #ifndef CONFIG_SANDBOX to maintain bisectability without merging patches

Changes in v4:
- Drop ASL_REVISION

Changes in v3:
- Make use of BIT()
- Fix DMA_ typo
- Add missing error check in acpi_create_dmar()
- Drop duplicate assert

Changes in v2:
- Drop two unnecessary __packed
- Move __packed to after struct

 include/acpi/acpi_table.h | 54 +++++++++++++++++++++++++++++++++++++++
 lib/acpi/acpi_table.c     | 31 ++++++++++++++++++++++
 test/dm/acpi.c            | 16 ++++++++++++
 3 files changed, 101 insertions(+)

Comments

Bin Meng April 16, 2020, 6:17 a.m. UTC | #1
On Thu, Apr 9, 2020 at 6:58 AM Simon Glass <sjg at chromium.org> wrote:
>
> The DMA Remapping Reporting (DMAR) table contains information about DMA
> remapping.
>
> Add a version simple version of this table with only the minimum fields
> filled out. i.e. no entries.
>
> Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
> Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> Changes in v5:
> - Add #ifndef CONFIG_SANDBOX to maintain bisectability without merging patches
>
> Changes in v4:
> - Drop ASL_REVISION
>
> Changes in v3:
> - Make use of BIT()
> - Fix DMA_ typo
> - Add missing error check in acpi_create_dmar()
> - Drop duplicate assert
>
> Changes in v2:
> - Drop two unnecessary __packed
> - Move __packed to after struct
>
>  include/acpi/acpi_table.h | 54 +++++++++++++++++++++++++++++++++++++++
>  lib/acpi/acpi_table.c     | 31 ++++++++++++++++++++++
>  test/dm/acpi.c            | 16 ++++++++++++
>  3 files changed, 101 insertions(+)
>

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index fdd7682c897..194be9aa589 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -360,6 +360,51 @@  struct acpi_csrt_shared_info {
 	u32 max_block_size;
 };
 
+enum dmar_type {
+	DMAR_DRHD = 0,
+	DMAR_RMRR = 1,
+	DMAR_ATSR = 2,
+	DMAR_RHSA = 3,
+	DMAR_ANDD = 4
+};
+
+enum {
+	DRHD_INCLUDE_PCI_ALL = BIT(0)
+};
+
+enum dmar_flags {
+	DMAR_INTR_REMAP			= BIT(0),
+	DMAR_X2APIC_OPT_OUT		= BIT(1),
+	DMAR_CTRL_PLATFORM_OPT_IN_FLAG	= BIT(2),
+};
+
+struct dmar_entry {
+	u16 type;
+	u16 length;
+	u8 flags;
+	u8 reserved;
+	u16 segment;
+	u64 bar;
+};
+
+struct dmar_rmrr_entry {
+	u16 type;
+	u16 length;
+	u16 reserved;
+	u16 segment;
+	u64 bar;
+	u64 limit;
+};
+
+/* DMAR (DMA Remapping Reporting Structure) */
+struct __packed acpi_dmar {
+	struct acpi_table_header header;
+	u8 host_address_width;
+	u8 flags;
+	u8 reserved[10];
+	struct dmar_entry structure[0];
+};
+
 /* DBG2 definitions are partially used for SPCR interface_type */
 
 /* Types for port_type field */
@@ -451,6 +496,15 @@  enum acpi_tables {
  */
 int acpi_get_table_revision(enum acpi_tables table);
 
+/**
+ * acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table
+ *
+ * @dmar: Place to put the table
+ * @flags: DMAR flags to use
+ * @return 0 if OK, -ve on error
+ */
+int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);
+
 #endif /* !__ACPI__*/
 
 #include <asm/acpi_table.h>
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 3268430cd1e..4633dcb9488 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -7,6 +7,37 @@ 
 
 #include <common.h>
 #include <acpi/acpi_table.h>
+#include <dm.h>
+#include <cpu.h>
+
+/* Temporary change to ensure bisectability */
+#ifndef CONFIG_SANDBOX
+int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
+{
+	struct acpi_table_header *header = &dmar->header;
+	struct cpu_info info;
+	struct udevice *cpu;
+	int ret;
+
+	ret = uclass_first_device(UCLASS_CPU, &cpu);
+	if (ret)
+		return log_msg_ret("cpu", ret);
+	ret = cpu_get_info(cpu, &info);
+	if (ret)
+		return log_msg_ret("info", ret);
+	memset((void *)dmar, 0, sizeof(struct acpi_dmar));
+
+	/* Fill out header fields. */
+	acpi_fill_header(&dmar->header, "DMAR");
+	header->length = sizeof(struct acpi_dmar);
+	header->revision = acpi_get_table_revision(ACPITAB_DMAR);
+
+	dmar->host_address_width = info.address_width - 1;
+	dmar->flags = flags;
+
+	return 0;
+}
+#endif
 
 int acpi_get_table_revision(enum acpi_tables table)
 {
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 85c846b0d7f..e7b8abd5569 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -67,3 +67,19 @@  static int dm_test_acpi_get_table_revision(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_acpi_get_table_revision,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Temporary change to ensure bisectability */
+#ifndef CONFIG_SANDBOX
+/* Test acpi_create_dmar() */
+static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
+{
+	struct acpi_dmar dmar;
+
+	ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
+	ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
+	ut_asserteq(32 - 1, dmar.host_address_width);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+#endif