git: 158adced65f8 - main - bhyve: save softc of ACPI devices

From: Corvin Köhne <corvink_at_FreeBSD.org>
Date: Thu, 13 Apr 2023 06:00:19 UTC
The branch main has been updated by corvink:

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

commit 158adced65f844682d26e1e64f247de94212f135
Author:     Corvin Köhne <corvink@FreeBSD.org>
AuthorDate: 2022-07-22 08:15:28 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2023-04-13 06:00:09 +0000

    bhyve: save softc of ACPI devices
    
    This will be useful for writing device specific ACPI tables or DSDT
    methods.
    
    Reviewed by:            markj
    MFC after:              1 week
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D39322
---
 usr.sbin/bhyve/acpi_device.c | 13 ++++++++++++-
 usr.sbin/bhyve/acpi_device.h |  7 +++++--
 usr.sbin/bhyve/qemu_fwcfg.c  |  2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/bhyve/acpi_device.c b/usr.sbin/bhyve/acpi_device.c
index 51603e138fba..e37fc50b8c91 100644
--- a/usr.sbin/bhyve/acpi_device.c
+++ b/usr.sbin/bhyve/acpi_device.c
@@ -36,18 +36,20 @@ struct acpi_resource_list_entry {
  * Holds information about an ACPI device.
  *
  * @param vm_ctx VM context the ACPI device was created in.
+ * @param softc  A pointer to the software context of the ACPI device.
  * @param emul   Device emulation struct. It contains some information like the
                  name of the ACPI device and some device specific functions.
  * @param crs    Current resources used by the ACPI device.
  */
 struct acpi_device {
 	struct vmctx *vm_ctx;
+	void *softc;
 	const struct acpi_device_emul *emul;
 	SLIST_HEAD(acpi_resource_list, acpi_resource_list_entry) crs;
 };
 
 int
-acpi_device_create(struct acpi_device **const new_dev,
+acpi_device_create(struct acpi_device **const new_dev, void *const softc,
     struct vmctx *const vm_ctx, const struct acpi_device_emul *const emul)
 {
 	assert(new_dev != NULL);
@@ -60,6 +62,7 @@ acpi_device_create(struct acpi_device **const new_dev,
 	}
 
 	dev->vm_ctx = vm_ctx;
+	dev->softc = softc;
 	dev->emul = emul;
 	SLIST_INIT(&dev->crs);
 
@@ -136,6 +139,14 @@ acpi_device_add_res_fixed_memory32(struct acpi_device *const dev,
 	return (0);
 }
 
+void *
+acpi_device_get_softc(const struct acpi_device *const dev)
+{
+	assert(dev != NULL);
+
+	return (dev->softc);
+}
+
 int
 acpi_device_build_table(const struct acpi_device *const dev)
 {
diff --git a/usr.sbin/bhyve/acpi_device.h b/usr.sbin/bhyve/acpi_device.h
index 4d734b422ec5..32e299f2da86 100644
--- a/usr.sbin/bhyve/acpi_device.h
+++ b/usr.sbin/bhyve/acpi_device.h
@@ -38,13 +38,14 @@ struct acpi_device_emul {
  * Creates an ACPI device.
  *
  * @param[out] new_dev Returns the newly create ACPI device.
+ * @param[in]  softc   Pointer to the software context of the ACPI device.
  * @param[in]  vm_ctx  VM context the ACPI device is created in.
  * @param[in]  emul    Device emulation struct. It contains some information
  *                     like the name of the ACPI device and some device specific
  *                     functions.
  */
-int acpi_device_create(struct acpi_device **new_dev, struct vmctx *vm_ctx,
-    const struct acpi_device_emul *emul);
+int acpi_device_create(struct acpi_device **new_dev, void *softc,
+    struct vmctx *vm_ctx, const struct acpi_device_emul *emul);
 void acpi_device_destroy(struct acpi_device *dev);
 
 int acpi_device_add_res_fixed_ioport(struct acpi_device *dev, UINT16 port,
@@ -52,5 +53,7 @@ int acpi_device_add_res_fixed_ioport(struct acpi_device *dev, UINT16 port,
 int acpi_device_add_res_fixed_memory32(struct acpi_device *dev,
     UINT8 write_protected, UINT32 address, UINT32 length);
 
+void *acpi_device_get_softc(const struct acpi_device *dev);
+
 int acpi_device_build_table(const struct acpi_device *dev);
 int acpi_device_write_dsdt(const struct acpi_device *dev);
diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c
index ddd73d06d34d..af819dc4a952 100644
--- a/usr.sbin/bhyve/qemu_fwcfg.c
+++ b/usr.sbin/bhyve/qemu_fwcfg.c
@@ -401,7 +401,7 @@ qemu_fwcfg_init(struct vmctx *const ctx)
 	 * tables and register io ports for fwcfg, if it's used.
 	 */
 	if (strcmp(lpc_fwcfg(), "qemu") == 0) {
-		error = acpi_device_create(&fwcfg_sc.acpi_dev, ctx,
+		error = acpi_device_create(&fwcfg_sc.acpi_dev, &fwcfg_sc, ctx,
 		    &qemu_fwcfg_acpi_device_emul);
 		if (error) {
 			warnx("%s: failed to create ACPI device for QEMU FwCfg",