The branch main has been updated by corvink:

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

commit 7959d80d99ae06ba06cbe7a206ef9bc513e4109b
Author:     Corvin Köhne <[email protected]>
AuthorDate: 2022-04-06 09:10:37 +0000
Commit:     Corvin Köhne <[email protected]>
CommitDate: 2023-04-25 06:29:29 +0000

    bhyve: make use of qemus acpi table loader
    
    Add all acpi tables to qemus acpi table loader. This passes the acpi
    tables by fwcfg to the guest.
    
    Reviewed by:            markj
    MFC after:              1 week
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D38439
---
 usr.sbin/bhyve/basl.c       | 21 ++++++++++++++++++++-
 usr.sbin/bhyve/basl.h       |  4 ++--
 usr.sbin/bhyve/qemu_fwcfg.h |  2 ++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/bhyve/basl.c b/usr.sbin/bhyve/basl.c
index e002c3724ef0..348174c6520d 100644
--- a/usr.sbin/bhyve/basl.c
+++ b/usr.sbin/bhyve/basl.c
@@ -20,6 +20,7 @@
 #include <vmmapi.h>
 
 #include "basl.h"
+#include "qemu_loader.h"
 
 struct basl_table_checksum {
        STAILQ_ENTRY(basl_table_checksum) chain;
@@ -56,6 +57,8 @@ struct basl_table {
 static STAILQ_HEAD(basl_table_list, basl_table) basl_tables = 
STAILQ_HEAD_INITIALIZER(
     basl_tables);
 
+static struct qemu_loader *basl_loader;
+
 static __inline uint64_t
 basl_le_dec(void *pp, size_t len)
 {
@@ -163,6 +166,12 @@ basl_finish_install_guest_tables(struct basl_table *const 
table, uint32_t *const
        }
        memcpy(gva, table->data, table->len);
 
+       /* Cause guest bios to copy the ACPI table into guest memory. */
+       BASL_EXEC(
+           qemu_fwcfg_add_file(table->fwcfg_name, table->len, table->data));
+       BASL_EXEC(qemu_loader_alloc(basl_loader, table->fwcfg_name,
+           table->alignment, QEMU_LOADER_ALLOC_HIGH));
+
        return (0);
 }
 
@@ -219,6 +228,10 @@ basl_finish_patch_checksums(struct basl_table *const table)
                        sum += *(gva + i);
                }
                *checksum_gva = -sum;
+
+               /* Cause guest bios to patch the checksum. */
+               BASL_EXEC(qemu_loader_add_checksum(basl_loader,
+                   table->fwcfg_name, checksum->off, checksum->start, len));
        }
 
        return (0);
@@ -286,6 +299,11 @@ basl_finish_patch_pointers(struct basl_table *const table)
                val = basl_le_dec(gva + pointer->off, pointer->size);
                val += BHYVE_ACPI_BASE + src_table->off;
                basl_le_enc(gva + pointer->off, val, pointer->size);
+
+               /* Cause guest bios to patch the pointer. */
+               BASL_EXEC(
+                   qemu_loader_add_pointer(basl_loader, table->fwcfg_name,
+                       src_table->fwcfg_name, pointer->off, pointer->size));
        }
 
        return (0);
@@ -335,6 +353,7 @@ basl_finish(void)
                 */
                BASL_EXEC(basl_finish_patch_checksums(table));
        }
+       BASL_EXEC(qemu_loader_finish(basl_loader));
 
        return (0);
 }
@@ -342,7 +361,7 @@ basl_finish(void)
 int
 basl_init(void)
 {
-       return (0);
+       return (qemu_loader_create(&basl_loader, QEMU_FWCFG_FILE_TABLE_LOADER));
 }
 
 int
diff --git a/usr.sbin/bhyve/basl.h b/usr.sbin/bhyve/basl.h
index c7fdd783a9d5..4d9ab4c589a8 100644
--- a/usr.sbin/bhyve/basl.h
+++ b/usr.sbin/bhyve/basl.h
@@ -11,6 +11,8 @@
 #include <contrib/dev/acpica/include/acpi.h>
 #pragma GCC diagnostic pop
 
+#include "qemu_fwcfg.h"
+
 #define ACPI_GAS_ACCESS_WIDTH_LEGACY 0
 #define ACPI_GAS_ACCESS_WIDTH_UNDEFINED 0
 #define ACPI_GAS_ACCESS_WIDTH_BYTE 1
@@ -59,8 +61,6 @@
                }                                                            \
        } while (0)
 
-#define QEMU_FWCFG_MAX_NAME 56
-
 struct basl_table;
 
 void basl_fill_gas(ACPI_GENERIC_ADDRESS *gas, uint8_t space_id,
diff --git a/usr.sbin/bhyve/qemu_fwcfg.h b/usr.sbin/bhyve/qemu_fwcfg.h
index f3846d64085a..d318d0434285 100644
--- a/usr.sbin/bhyve/qemu_fwcfg.h
+++ b/usr.sbin/bhyve/qemu_fwcfg.h
@@ -13,6 +13,8 @@
 #define QEMU_FWCFG_MAX_ENTRIES 0x4000
 #define QEMU_FWCFG_MAX_NAME 56
 
+#define QEMU_FWCFG_FILE_TABLE_LOADER "etc/table-loader"
+
 struct qemu_fwcfg_item {
        uint32_t size;
        uint8_t *data;

Reply via email to