aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorvin Köhne <corvink@FreeBSD.org>2021-10-07 13:57:01 +0000
committerCorvin Köhne <corvink@FreeBSD.org>2023-02-28 10:04:33 +0000
commiteb8931d77cee0af57578159297f95571a2d723f8 (patch)
tree75bdfd65f89d0780e64049cc063b92eec200cb83
parentb5d47fa9a5112f13cac8282c18d36f40661967a0 (diff)
downloadsrc-eb8931d77cee0af57578159297f95571a2d723f8.tar.gz
src-eb8931d77cee0af57578159297f95571a2d723f8.zip
bhyve: add helper func to add acpi resources
These helper function can be used to assign acpi resources to an acpi_device. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38328 (cherry picked from commit 13a1df5b85e992570f45248bfe9d581dc182b755)
-rw-r--r--usr.sbin/bhyve/acpi_device.c45
-rw-r--r--usr.sbin/bhyve/acpi_device.h5
2 files changed, 50 insertions, 0 deletions
diff --git a/usr.sbin/bhyve/acpi_device.c b/usr.sbin/bhyve/acpi_device.c
index 66d50de814fd..402e32faa93a 100644
--- a/usr.sbin/bhyve/acpi_device.c
+++ b/usr.sbin/bhyve/acpi_device.c
@@ -90,3 +90,48 @@ acpi_device_destroy(struct acpi_device *const dev)
free(__DECONST(void *, dev->name));
free(dev);
}
+
+int
+acpi_device_add_res_fixed_ioport(struct acpi_device *const dev,
+ const UINT16 port, const UINT8 length)
+{
+ if (dev == NULL) {
+ return (EINVAL);
+ }
+
+ struct acpi_resource_list_entry *const res = calloc(1, sizeof(*res));
+ if (res == NULL) {
+ return (ENOMEM);
+ }
+
+ res->type = ACPI_RESOURCE_TYPE_FIXED_IO;
+ res->data.FixedIo.Address = port;
+ res->data.FixedIo.AddressLength = length;
+
+ SLIST_INSERT_HEAD(&dev->crs, res, chain);
+
+ return (0);
+}
+
+int
+acpi_device_add_res_fixed_memory32(struct acpi_device *const dev,
+ const UINT8 write_protected, const UINT32 address, const UINT32 length)
+{
+ if (dev == NULL) {
+ return (EINVAL);
+ }
+
+ struct acpi_resource_list_entry *const res = calloc(1, sizeof(*res));
+ if (res == NULL) {
+ return (ENOMEM);
+ }
+
+ res->type = ACPI_RESOURCE_TYPE_FIXED_MEMORY32;
+ res->data.FixedMemory32.WriteProtect = write_protected;
+ res->data.FixedMemory32.Address = address;
+ res->data.FixedMemory32.AddressLength = length;
+
+ SLIST_INSERT_HEAD(&dev->crs, res, chain);
+
+ return (0);
+}
diff --git a/usr.sbin/bhyve/acpi_device.h b/usr.sbin/bhyve/acpi_device.h
index 1728acd4cdcd..d9618d7e0a43 100644
--- a/usr.sbin/bhyve/acpi_device.h
+++ b/usr.sbin/bhyve/acpi_device.h
@@ -29,3 +29,8 @@ struct acpi_device;
int acpi_device_create(struct acpi_device **const new_dev,
struct vmctx *const vm_ctx, const char *const name, const char *const hid);
void acpi_device_destroy(struct acpi_device *const dev);
+
+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);