diff mbox series

[v2,19/39] acpi: Move acpi_fill_header() to generic code

Message ID 20200308214442.v2.19.Iadbc6a54ae1387847aabfdb8e2c10e040fb1bf77@changeid
State New
Headers show
Series dm: Add programmatic generation of ACPI tables (part A) | expand

Commit Message

Simon Glass March 9, 2020, 3:44 a.m. UTC
This function needs to be used by sandbox for tests. Move it into the
generic directory.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
---

Changes in v2: None

 arch/x86/lib/acpi_table.c |  9 ---------
 include/acpi_table.h      | 10 ++++++++++
 lib/acpi/acpi_table.c     | 10 ++++++++++
 test/dm/acpi.c            | 28 ++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 9 deletions(-)

Comments

Wolfgang Wallner March 10, 2020, 12:33 p.m. UTC | #1
Hi Simon,

-----"Simon Glass" <sjg at chromium.org> schrieb: -----
> 
> This function needs to be used by sandbox for tests. Move it into the
> generic directory.

Nit: Move it into the generic directory and add a test for it.

> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
> ---
> 
> Changes in v2: None
> 
>  arch/x86/lib/acpi_table.c |  9 ---------
>  include/acpi_table.h      | 10 ++++++++++
>  lib/acpi/acpi_table.c     | 10 ++++++++++
>  test/dm/acpi.c            | 28 ++++++++++++++++++++++++++++
>  4 files changed, 48 insertions(+), 9 deletions(-)
> 

Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>

regards, Wolfgang
Wolfgang Wallner March 11, 2020, 9:04 a.m. UTC | #2
Hi Simon,

looking at this patch some more I have another question, see below.

-----"Simon Glass" <sjg at chromium.org> schrieb: -----
> 
> This function needs to be used by sandbox for tests. Move it into the
> generic directory.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
> ---

[snip] 

> @@ -81,3 +82,30 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
>  	return 0;
>  }
>  DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
> +
> +/* Test acpi_fill_header() */
> +static int dm_test_acpi_fill_header(struct unit_test_state *uts)
> +{
> +	struct acpi_table_header hdr;
> +
> +	/* Make sure these 5 fields are not changed */
> +	hdr.length = 0x11;
> +	hdr.revision = 0x22;
> +	hdr.checksum = 0x33;
> +	hdr.aslc_revision = 0x44;
> +	acpi_fill_header(&hdr, "ABCD");
> +
> +	ut_assertok(memcmp("ABCD", hdr.signature, sizeof(hdr.signature)));

Could ut_asserteq_mem() be used here?
The output would be a little more verbose.

With ut_assertok(memcmp()):
 test/dm/acpi.c:104, dm_test_acpi_fill_header(): 0 == memcmp("ABCD", hdr.signature, sizeof(hdr.signature)): Expected 0x0 (0), got 0x13 (19)

With ut_assertmem_eq():
 test/dm/acpi.c:103, dm_test_acpi_fill_header(): "ABCD" = hdr.signature: Expected "41424344", got "41424331"

> +	ut_asserteq(0x11, hdr.length);
> +	ut_asserteq(0x22, hdr.revision);
> +	ut_asserteq(0x33, hdr.checksum);
> +	ut_assertok(memcmp(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id)));
> +	ut_assertok(memcmp(OEM_TABLE_ID, hdr.oem_table_id,
> +			   sizeof(hdr.oem_table_id)));
> +	ut_asserteq(U_BOOT_BUILD_DATE, hdr.oem_revision);
> +	ut_assertok(memcmp(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)));
> +	ut_asserteq(0x44, hdr.aslc_revision);
> +
> +	return 0;
> +}
> +DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
> -- 
> 2.25.1.481.gfbce0eb801-goog

regards, Wolfgang
diff mbox series

Patch

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 71913b6f65..487fef87f2 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -60,15 +60,6 @@  static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
 			sizeof(struct acpi_rsdp));
 }
 
-void acpi_fill_header(struct acpi_table_header *header, char *signature)
-{
-	memcpy(header->signature, signature, 4);
-	memcpy(header->oem_id, OEM_ID, 6);
-	memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
-	header->oem_revision = U_BOOT_BUILD_DATE;
-	memcpy(header->aslc_id, ASLC_ID, 4);
-}
-
 static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
 {
 	struct acpi_table_header *header = &(rsdt->header);
diff --git a/include/acpi_table.h b/include/acpi_table.h
index db84b79be5..3fd2ef16b0 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -509,6 +509,16 @@  int acpi_get_table_revision(enum acpi_tables table);
  */
 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);
 
+/**
+ * acpi_fill_header() - Set up a new table header
+ *
+ * This sets all fields except length, revision, checksum and aslc_revision
+ *
+ * @header: ACPI header to update
+ * @signature: Table signature to use (4 characters)
+ */
+void acpi_fill_header(struct acpi_table_header *header, char *signature);
+
 #endif /* !__ACPI__*/
 
 #include <asm/acpi_table.h>
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index ed312ac663..a86bfa6187 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -9,6 +9,7 @@ 
 #include <dm.h>
 #include <acpi_table.h>
 #include <cpu.h>
+#include <version.h>
 
 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
 {
@@ -84,3 +85,12 @@  int acpi_get_table_revision(enum acpi_tables table)
 		return -EINVAL;
 	}
 }
+
+void acpi_fill_header(struct acpi_table_header *header, char *signature)
+{
+	memcpy(header->signature, signature, 4);
+	memcpy(header->oem_id, OEM_ID, 6);
+	memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
+	header->oem_revision = U_BOOT_BUILD_DATE;
+	memcpy(header->aslc_id, ASLC_ID, 4);
+}
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 2737896643..e28ebf4f90 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -9,6 +9,7 @@ 
 #include <common.h>
 #include <acpi_table.h>
 #include <dm.h>
+#include <version.h>
 #include <dm/acpi.h>
 #include <dm/test.h>
 #include <test/ut.h>
@@ -81,3 +82,30 @@  static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test acpi_fill_header() */
+static int dm_test_acpi_fill_header(struct unit_test_state *uts)
+{
+	struct acpi_table_header hdr;
+
+	/* Make sure these 5 fields are not changed */
+	hdr.length = 0x11;
+	hdr.revision = 0x22;
+	hdr.checksum = 0x33;
+	hdr.aslc_revision = 0x44;
+	acpi_fill_header(&hdr, "ABCD");
+
+	ut_assertok(memcmp("ABCD", hdr.signature, sizeof(hdr.signature)));
+	ut_asserteq(0x11, hdr.length);
+	ut_asserteq(0x22, hdr.revision);
+	ut_asserteq(0x33, hdr.checksum);
+	ut_assertok(memcmp(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id)));
+	ut_assertok(memcmp(OEM_TABLE_ID, hdr.oem_table_id,
+			   sizeof(hdr.oem_table_id)));
+	ut_asserteq(U_BOOT_BUILD_DATE, hdr.oem_revision);
+	ut_assertok(memcmp(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)));
+	ut_asserteq(0x44, hdr.aslc_revision);
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);