git: cc16e0f79dbf - stable/13 - bhyve: Make the MADT dynamically sized.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 11 May 2022 18:56:07 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=cc16e0f79dbfdd3e3584a408d358a0b0475606b0

commit cc16e0f79dbfdd3e3584a408d358a0b0475606b0
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-03-09 23:38:58 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-11 18:48:17 +0000

    bhyve: Make the MADT dynamically sized.
    
    Use basl_ncpu instead of VM_MAXCPU in MADT_SIZE.  Since several of the
    offsets are no longer compile time constants, unroll the loop
    generating ACPI tables.
    
    Reviewed by:    grehan
    Differential Revision:  https://reviews.freebsd.org/D34490
    
    (cherry picked from commit 340a293f9147a37bb71c80a767e37794ca277a28)
---
 usr.sbin/bhyve/acpi.c | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/usr.sbin/bhyve/acpi.c b/usr.sbin/bhyve/acpi.c
index 580bb900dd43..360191ac6c4d 100644
--- a/usr.sbin/bhyve/acpi.c
+++ b/usr.sbin/bhyve/acpi.c
@@ -89,10 +89,10 @@ __FBSDID("$FreeBSD$");
  *	44		Fixed Header
  *	8 * maxcpu	Processor Local APIC entries
  *	12		I/O APIC entry
- *	2 * 10		Interrupt Source Override entires
+ *	2 * 10		Interrupt Source Override entries
  *	6		Local APIC NMI entry
  */
-#define	MADT_SIZE		(44 + VM_MAXCPU*8 + 12 + 2*10 + 6)
+#define	MADT_SIZE		roundup2((44 + basl_ncpu*8 + 12 + 2*10 + 6), 0x100)
 #define	FADT_OFFSET		(MADT_OFFSET + MADT_SIZE)
 #define	FADT_SIZE		0x140
 #define	HPET_OFFSET		(FADT_OFFSET + FADT_SIZE)
@@ -943,28 +943,10 @@ basl_make_templates(void)
 	return (err);
 }
 
-static struct {
-	int	(*wsect)(FILE *fp);
-	uint64_t  offset;
-} basl_ftables[] =
-{
-	{ basl_fwrite_rsdp, 0},
-	{ basl_fwrite_rsdt, RSDT_OFFSET },
-	{ basl_fwrite_xsdt, XSDT_OFFSET },
-	{ basl_fwrite_madt, MADT_OFFSET },
-	{ basl_fwrite_fadt, FADT_OFFSET },
-	{ basl_fwrite_hpet, HPET_OFFSET },
-	{ basl_fwrite_mcfg, MCFG_OFFSET },
-	{ basl_fwrite_facs, FACS_OFFSET },
-	{ basl_fwrite_dsdt, DSDT_OFFSET },
-	{ NULL }
-};
-
 int
 acpi_build(struct vmctx *ctx, int ncpu)
 {
 	int err;
-	int i;
 
 	basl_ncpu = ncpu;
 
@@ -986,18 +968,30 @@ acpi_build(struct vmctx *ctx, int ncpu)
 	if (getenv("BHYVE_ACPI_KEEPTMPS"))
 		basl_keep_temps = 1;
 
-	i = 0;
 	err = basl_make_templates();
 
 	/*
 	 * Run through all the ASL files, compiling them and
 	 * copying them into guest memory
 	 */
-	while (!err && basl_ftables[i].wsect != NULL) {
-		err = basl_compile(ctx, basl_ftables[i].wsect,
-				   basl_ftables[i].offset);
-		i++;
-	}
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_rsdp, 0);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_rsdt, RSDT_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_xsdt, XSDT_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_madt, MADT_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_fadt, FADT_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_hpet, HPET_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_mcfg, MCFG_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_facs, FACS_OFFSET);
+	if (err == 0)
+		err = basl_compile(ctx, basl_fwrite_dsdt, DSDT_OFFSET);
 
 	return (err);
 }