From patchwork Mon Jan 27 05:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240164 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Sun, 26 Jan 2020 22:05:26 -0700 Subject: [PATCH 019/108] acpi: Move acpi_fill_header() to generic code In-Reply-To: <20200127050655.170614-1-sjg@chromium.org> References: <20200127050655.170614-1-sjg@chromium.org> Message-ID: <20200126220508.19.Iadbc6a54ae1387847aabfdb8e2c10e040fb1bf77@changeid> This function needs to be used by sandbox for tests. Move it into the generic directory. Signed-off-by: Simon Glass --- 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 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 #include #include +#include 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 #include #include +#include #include #include #include @@ -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);