[PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code
Simon Glass
sjg at chromium.org
Mon Mar 9 04:44:43 CET 2020
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(-)
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);
--
2.25.1.481.gfbce0eb801-goog
More information about the U-Boot
mailing list