[PATCH 019/108] acpi: Move acpi_fill_header() to generic code
Simon Glass
sjg at chromium.org
Mon Jan 27 06:05:26 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>
---
include/acpi_table.h | 10 ++++++++++
lib/acpi/acpi_table.c | 10 ++++++++++
test/dm/acpi.c | 28 ++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/include/acpi_table.h b/include/acpi_table.h
index d5a9e1c96f..9904e421c3 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -501,6 +501,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 85147ac61a..771a3580ce 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)
{
@@ -83,3 +84,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.0.341.g760bfbb309-goog
More information about the U-Boot
mailing list