diff --git a/usr.sbin/bhyve/basl.c b/usr.sbin/bhyve/basl.c index 1da0a7028f57..e8724b857381 100644 --- a/usr.sbin/bhyve/basl.c +++ b/usr.sbin/bhyve/basl.c @@ -446,6 +446,42 @@ basl_table_append_gas(struct basl_table *const table, const uint8_t space_id, return (basl_table_append_bytes(table, &gas_le, sizeof(gas_le))); } +int +basl_table_append_header(struct basl_table *const table, + const uint8_t signature[ACPI_NAMESEG_SIZE], const uint8_t revision, + const uint32_t oem_revision) +{ + ACPI_TABLE_HEADER header_le; + /* + 1 is required for the null terminator */ + char oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1]; + + assert(table != NULL); + assert(table->len == 0); + + memcpy(header_le.Signature, signature, ACPI_NAMESEG_SIZE); + header_le.Length = 0; /* patched by basl_finish */ + header_le.Revision = revision; + header_le.Checksum = 0; /* patched by basl_finish */ + memcpy(header_le.OemId, "BHYVE ", ACPI_OEM_ID_SIZE); + snprintf(oem_table_id, ACPI_OEM_TABLE_ID_SIZE, "BV%.4s ", signature); + memcpy(header_le.OemTableId, oem_table_id, + sizeof(header_le.OemTableId)); + header_le.OemRevision = htole32(oem_revision); + memcpy(header_le.AslCompilerId, "BASL", ACPI_NAMESEG_SIZE); + header_le.AslCompilerRevision = htole32(0x20220504); + + BASL_EXEC( + basl_table_append_bytes(table, &header_le, sizeof(header_le))); + + BASL_EXEC(basl_table_add_length(table, + offsetof(ACPI_TABLE_HEADER, Length), sizeof(header_le.Length))); + BASL_EXEC(basl_table_add_checksum(table, + offsetof(ACPI_TABLE_HEADER, Checksum), 0, + BASL_TABLE_CHECKSUM_LEN_FULL_TABLE)); + + return (0); +} + int basl_table_append_int(struct basl_table *const table, const uint64_t val, const uint8_t size) diff --git a/usr.sbin/bhyve/basl.h b/usr.sbin/bhyve/basl.h index 978b2722acf9..aab4a16a63f5 100644 --- a/usr.sbin/bhyve/basl.h +++ b/usr.sbin/bhyve/basl.h @@ -46,6 +46,9 @@ int basl_table_append_checksum(struct basl_table *table, uint32_t start, int basl_table_append_gas(struct basl_table *table, uint8_t space_id, uint8_t bit_width, uint8_t bit_offset, uint8_t access_width, uint64_t address); +int basl_table_append_header(struct basl_table *table, + const uint8_t signature[ACPI_NAMESEG_SIZE], uint8_t revision, + uint32_t oem_revision); int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size); int basl_table_append_length(struct basl_table *table, uint8_t size); int basl_table_append_pointer(struct basl_table *table,