bhyve: maintain RSDT and XSDT by basl

In a subsquent commit the TPM emulation will build it's own TPM2 table.
This needs to be registered to the RSDT and XSDT. Instead of making the
rsdt and xsdt variables global, we can simply add a helper to basl.

Reviewed by:		markj
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D40559
This commit is contained in:
Corvin Köhne 2023-06-15 11:12:53 +02:00
parent 480bef9481
commit 24a0fef9dc
No known key found for this signature in database
GPG Key ID: D854DA56315E026A
3 changed files with 62 additions and 56 deletions

View File

@ -91,9 +91,6 @@ static FILE *dsdt_fp;
static int dsdt_indent_level;
static int dsdt_error;
static struct basl_table *rsdt;
static struct basl_table *xsdt;
struct basl_fio {
int fd;
FILE *fp;
@ -532,10 +529,7 @@ build_fadt(struct vmctx *const ctx)
BASL_EXEC(basl_table_add_pointer(table, ACPI_SIG_DSDT,
offsetof(ACPI_TABLE_FADT, XDsdt), sizeof(fadt.XDsdt)));
BASL_EXEC(basl_table_append_pointer(rsdt, ACPI_SIG_FADT,
ACPI_RSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_append_pointer(xsdt, ACPI_SIG_FADT,
ACPI_XSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_register_to_rsdt(table));
return (0);
}
@ -557,10 +551,7 @@ build_hpet(struct vmctx *const ctx)
hpet.Flags = ACPI_HPET_PAGE_PROTECT4;
BASL_EXEC(basl_table_append_content(table, &hpet, sizeof(hpet)));
BASL_EXEC(basl_table_append_pointer(rsdt, ACPI_SIG_HPET,
ACPI_RSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_append_pointer(xsdt, ACPI_SIG_HPET,
ACPI_XSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_register_to_rsdt(table));
return (0);
}
@ -635,10 +626,7 @@ build_madt(struct vmctx *const ctx)
BASL_EXEC(basl_table_append_bytes(table, &madt_lapic_nmi,
sizeof(madt_lapic_nmi)));
BASL_EXEC(basl_table_append_pointer(rsdt, ACPI_SIG_MADT,
ACPI_RSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_append_pointer(xsdt, ACPI_SIG_MADT,
ACPI_XSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_register_to_rsdt(table));
return (0);
}
@ -663,10 +651,7 @@ build_mcfg(struct vmctx *const ctx)
BASL_EXEC(basl_table_append_bytes(table, &mcfg_allocation,
sizeof(mcfg_allocation)));
BASL_EXEC(basl_table_append_pointer(rsdt, ACPI_SIG_MCFG,
ACPI_RSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_append_pointer(xsdt, ACPI_SIG_MCFG,
ACPI_XSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_register_to_rsdt(table));
return (0);
}
@ -708,19 +693,6 @@ build_rsdp(struct vmctx *const ctx)
return (0);
}
static int
build_rsdt(struct vmctx *const ctx)
{
BASL_EXEC(
basl_table_create(&rsdt, ctx, ACPI_SIG_RSDT, BASL_TABLE_ALIGNMENT));
/* Header */
BASL_EXEC(basl_table_append_header(rsdt, ACPI_SIG_RSDT, 1, 1));
/* Pointers (added by other build_XXX funcs) */
return (0);
}
static int
build_spcr(struct vmctx *const ctx)
{
@ -744,23 +716,7 @@ build_spcr(struct vmctx *const ctx)
spcr.TerminalType = ACPI_SPCR_TERMINAL_TYPE_VT_UTF8;
BASL_EXEC(basl_table_append_content(table, &spcr, sizeof(spcr)));
BASL_EXEC(basl_table_append_pointer(rsdt, ACPI_SIG_SPCR,
ACPI_RSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_append_pointer(xsdt, ACPI_SIG_SPCR,
ACPI_XSDT_ENTRY_SIZE));
return (0);
}
static int
build_xsdt(struct vmctx *const ctx)
{
BASL_EXEC(
basl_table_create(&xsdt, ctx, ACPI_SIG_XSDT, BASL_TABLE_ALIGNMENT));
/* Header */
BASL_EXEC(basl_table_append_header(xsdt, ACPI_SIG_XSDT, 1, 1));
/* Pointers (added by other build_XXX funcs) */
BASL_EXEC(basl_table_register_to_rsdt(table));
return (0);
}
@ -790,7 +746,7 @@ acpi_build(struct vmctx *ctx, int ncpu)
if (getenv("BHYVE_ACPI_KEEPTMPS"))
basl_keep_temps = 1;
BASL_EXEC(basl_init());
BASL_EXEC(basl_init(ctx));
BASL_EXEC(basl_make_templates());
@ -802,8 +758,6 @@ acpi_build(struct vmctx *ctx, int ncpu)
* first table after XSDT.
*/
BASL_EXEC(build_rsdp(ctx));
BASL_EXEC(build_rsdt(ctx));
BASL_EXEC(build_xsdt(ctx));
BASL_EXEC(build_fadt(ctx));
BASL_EXEC(build_madt(ctx));
BASL_EXEC(build_hpet(ctx));

View File

@ -58,6 +58,8 @@ static STAILQ_HEAD(basl_table_list, basl_table) basl_tables = STAILQ_HEAD_INITIA
basl_tables);
static struct qemu_loader *basl_loader;
static struct basl_table *rsdt;
static struct basl_table *xsdt;
static __inline uint64_t
basl_le_dec(void *pp, size_t len)
@ -358,10 +360,41 @@ basl_finish(void)
return (0);
}
int
basl_init(void)
static int
basl_init_rsdt(struct vmctx *const ctx)
{
return (qemu_loader_create(&basl_loader, QEMU_FWCFG_FILE_TABLE_LOADER));
BASL_EXEC(
basl_table_create(&rsdt, ctx, ACPI_SIG_RSDT, BASL_TABLE_ALIGNMENT));
/* Header */
BASL_EXEC(basl_table_append_header(rsdt, ACPI_SIG_RSDT, 1, 1));
/* Pointers (added by basl_table_register_to_rsdt) */
return (0);
}
static int
basl_init_xsdt(struct vmctx *const ctx)
{
BASL_EXEC(
basl_table_create(&xsdt, ctx, ACPI_SIG_XSDT, BASL_TABLE_ALIGNMENT));
/* Header */
BASL_EXEC(basl_table_append_header(xsdt, ACPI_SIG_XSDT, 1, 1));
/* Pointers (added by basl_table_register_to_rsdt) */
return (0);
}
int
basl_init(struct vmctx *const ctx)
{
BASL_EXEC(basl_init_rsdt(ctx));
BASL_EXEC(basl_init_xsdt(ctx));
BASL_EXEC(
qemu_loader_create(&basl_loader, QEMU_FWCFG_FILE_TABLE_LOADER));
return (0);
}
int
@ -627,3 +660,20 @@ basl_table_create(struct basl_table **const table, struct vmctx *ctx,
return (0);
}
int
basl_table_register_to_rsdt(struct basl_table *table)
{
const ACPI_TABLE_HEADER *header;
assert(table != NULL);
header = (const ACPI_TABLE_HEADER *)table->data;
BASL_EXEC(basl_table_append_pointer(rsdt, header->Signature,
ACPI_RSDT_ENTRY_SIZE));
BASL_EXEC(basl_table_append_pointer(xsdt, header->Signature,
ACPI_XSDT_ENTRY_SIZE));
return (0);
}

View File

@ -67,7 +67,7 @@ void basl_fill_gas(ACPI_GENERIC_ADDRESS *gas, uint8_t space_id,
uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
uint64_t address);
int basl_finish(void);
int basl_init(void);
int basl_init(struct vmctx *ctx);
int basl_table_add_checksum(struct basl_table *const table, const uint32_t off,
const uint32_t start, const uint32_t len);
int basl_table_add_length(struct basl_table *const table, const uint32_t off,
@ -97,3 +97,5 @@ int basl_table_append_pointer(struct basl_table *table,
const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size);
int basl_table_create(struct basl_table **table, struct vmctx *ctx,
const uint8_t *name, uint32_t alignment);
/* Adds the table to RSDT and XSDT */
int basl_table_register_to_rsdt(struct basl_table *table);