aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorvin Köhne <corvink@FreeBSD.org>2021-10-07 13:58:27 +0000
committerCorvin Köhne <corvink@FreeBSD.org>2023-02-28 10:04:34 +0000
commit6726130d6860fa5a19181e69546976eafb044538 (patch)
tree494c6017a48f426cda7597e6033a3ac1d2d47076
parenteb8931d77cee0af57578159297f95571a2d723f8 (diff)
downloadsrc-6726130d6860fa5a19181e69546976eafb044538.tar.gz
src-6726130d6860fa5a19181e69546976eafb044538.zip
bhyve: add helper func to write a dsdt entry
The guest will check the dsdt to detect acpi devices. Therefore, add a helper function to create such a dsdt entry for an acpi device. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38329 (cherry picked from commit 682a522d61223920f23a202aa57901f38bdfd8dd)
-rw-r--r--usr.sbin/bhyve/acpi_device.c46
-rw-r--r--usr.sbin/bhyve/acpi_device.h2
2 files changed, 48 insertions, 0 deletions
diff --git a/usr.sbin/bhyve/acpi_device.c b/usr.sbin/bhyve/acpi_device.c
index 402e32faa93a..10259006c619 100644
--- a/usr.sbin/bhyve/acpi_device.c
+++ b/usr.sbin/bhyve/acpi_device.c
@@ -10,6 +10,7 @@
#include <machine/vmm.h>
+#include <assert.h>
#include <err.h>
#include <errno.h>
#include <vmmapi.h>
@@ -135,3 +136,48 @@ acpi_device_add_res_fixed_memory32(struct acpi_device *const dev,
return (0);
}
+
+static void
+acpi_device_write_dsdt_crs(const struct acpi_device *const dev)
+{
+ const struct acpi_resource_list_entry *res;
+ SLIST_FOREACH(res, &dev->crs, chain) {
+ switch (res->type) {
+ case ACPI_RESOURCE_TYPE_FIXED_IO:
+ dsdt_fixed_ioport(res->data.FixedIo.Address,
+ res->data.FixedIo.AddressLength);
+ break;
+ case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+ dsdt_fixed_mem32(res->data.FixedMemory32.Address,
+ res->data.FixedMemory32.AddressLength);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ }
+}
+
+void
+acpi_device_write_dsdt(const struct acpi_device *const dev)
+{
+ if (dev == NULL) {
+ return;
+ }
+
+ dsdt_line("");
+ dsdt_line(" Scope (\\_SB)");
+ dsdt_line(" {");
+ dsdt_line(" Device (%s)", dev->name);
+ dsdt_line(" {");
+ dsdt_line(" Name (_HID, \"%s\")", dev->hid);
+ dsdt_line(" Name (_STA, 0x0F)");
+ dsdt_line(" Name (_CRS, ResourceTemplate ()");
+ dsdt_line(" {");
+ dsdt_indent(4);
+ acpi_device_write_dsdt_crs(dev);
+ dsdt_unindent(4);
+ dsdt_line(" })");
+ dsdt_line(" }");
+ dsdt_line(" }");
+}
diff --git a/usr.sbin/bhyve/acpi_device.h b/usr.sbin/bhyve/acpi_device.h
index d9618d7e0a43..5fb3ea18e481 100644
--- a/usr.sbin/bhyve/acpi_device.h
+++ b/usr.sbin/bhyve/acpi_device.h
@@ -34,3 +34,5 @@ int acpi_device_add_res_fixed_ioport(struct acpi_device *const dev,
const UINT16 port, UINT8 length);
int acpi_device_add_res_fixed_memory32(struct acpi_device *const dev,
const UINT8 write_protected, const UINT32 address, const UINT32 length);
+
+void acpi_device_write_dsdt(const struct acpi_device *const dev);