aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorvin Köhne <corvink@FreeBSD.org>2021-10-07 14:14:31 +0000
committerCorvin Köhne <corvink@FreeBSD.org>2023-02-28 10:04:34 +0000
commit2c1cbd083696086aeb9f0d75ddcfbb04183de081 (patch)
tree2fdb0a3a779e927fbd0fe6d9087b60801f4f717a
parent6726130d6860fa5a19181e69546976eafb044538 (diff)
bhyve: maintain a list of acpi devices
The list is used to generate the dsdt entry for every acpi device. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D3830 (cherry picked from commit fbd045021d9ffdae5e5bb20e1d1890fd4b46498e)
-rw-r--r--usr.sbin/bhyve/acpi.c29
-rw-r--r--usr.sbin/bhyve/acpi.h3
-rw-r--r--usr.sbin/bhyve/acpi_device.c6
3 files changed, 38 insertions, 0 deletions
diff --git a/usr.sbin/bhyve/acpi.c b/usr.sbin/bhyve/acpi.c
index bdb0e97076ad..84a54cc485c5 100644
--- a/usr.sbin/bhyve/acpi.c
+++ b/usr.sbin/bhyve/acpi.c
@@ -107,6 +107,30 @@ struct basl_fio {
if (fflush(x) != 0) goto err_exit;
/*
+ * A list for additional ACPI devices like a TPM.
+ */
+struct acpi_device_list_entry {
+ SLIST_ENTRY(acpi_device_list_entry) chain;
+ const struct acpi_device *dev;
+};
+static SLIST_HEAD(acpi_device_list,
+ acpi_device_list_entry) acpi_devices = SLIST_HEAD_INITIALIZER(acpi_devices);
+
+int
+acpi_tables_add_device(const struct acpi_device *const dev)
+{
+ struct acpi_device_list_entry *const entry = calloc(1, sizeof(*entry));
+ if (entry == NULL) {
+ return (ENOMEM);
+ }
+
+ entry->dev = dev;
+ SLIST_INSERT_HEAD(&acpi_devices, entry, chain);
+
+ return (0);
+}
+
+/*
* Helper routines for writing to the DSDT from other modules.
*/
void
@@ -219,6 +243,11 @@ basl_fwrite_dsdt(FILE *fp)
vmgenc_write_dsdt();
+ const struct acpi_device_list_entry *entry;
+ SLIST_FOREACH(entry, &acpi_devices, chain) {
+ acpi_device_write_dsdt(entry->dev);
+ }
+
dsdt_line("}");
if (dsdt_error != 0)
diff --git a/usr.sbin/bhyve/acpi.h b/usr.sbin/bhyve/acpi.h
index 50e5337f332a..98479913732c 100644
--- a/usr.sbin/bhyve/acpi.h
+++ b/usr.sbin/bhyve/acpi.h
@@ -31,6 +31,8 @@
#ifndef _ACPI_H_
#define _ACPI_H_
+#include "acpi_device.h"
+
#define SCI_INT 9
#define SMI_CMD 0xb2
@@ -55,6 +57,7 @@ struct vmctx;
int acpi_build(struct vmctx *ctx, int ncpu);
void acpi_raise_gpe(struct vmctx *ctx, unsigned bit);
+int acpi_tables_add_device(const struct acpi_device *const dev);
void dsdt_line(const char *fmt, ...);
void dsdt_fixed_ioport(uint16_t iobase, uint16_t length);
void dsdt_fixed_irq(uint8_t irq);
diff --git a/usr.sbin/bhyve/acpi_device.c b/usr.sbin/bhyve/acpi_device.c
index 10259006c619..047d411deec2 100644
--- a/usr.sbin/bhyve/acpi_device.c
+++ b/usr.sbin/bhyve/acpi_device.c
@@ -68,6 +68,12 @@ acpi_device_create(struct acpi_device **const new_dev,
return (ENOMEM);
}
+ const int error = acpi_tables_add_device(dev);
+ if (error) {
+ acpi_device_destroy(dev);
+ return (error);
+ }
+
*new_dev = dev;
return (0);