From dece4f2d875a3964e1d6438dafa108dda8a7a1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corvin=20K=C3=B6hne?= Date: Mon, 15 May 2023 13:24:14 +0200 Subject: [PATCH] bhyve: register TPM device as ACPI device The TPM device is an ACPI device with some custom ACPI tables. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40453 --- usr.sbin/bhyve/tpm_device.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/usr.sbin/bhyve/tpm_device.c b/usr.sbin/bhyve/tpm_device.c index 77fd1ccf6a52..56df6ab0e30c 100644 --- a/usr.sbin/bhyve/tpm_device.c +++ b/usr.sbin/bhyve/tpm_device.c @@ -13,11 +13,21 @@ #include #include +#include "acpi_device.h" #include "config.h" #include "tpm_device.h" +#define TPM_ACPI_DEVICE_NAME "TPM" +#define TPM_ACPI_HARDWARE_ID "MSFT0101" + struct tpm_device { struct vmctx *vm_ctx; + struct acpi_device *acpi_dev; +}; + +static const struct acpi_device_emul tpm_acpi_device_emul = { + .name = TPM_ACPI_DEVICE_NAME, + .hid = TPM_ACPI_HARDWARE_ID, }; void @@ -26,6 +36,7 @@ tpm_device_destroy(struct tpm_device *const dev) if (dev == NULL) return; + acpi_device_destroy(dev->acpi_dev); free(dev); } @@ -57,6 +68,11 @@ tpm_device_create(struct tpm_device **const new_dev, struct vmctx *const vm_ctx, dev->vm_ctx = vm_ctx; + error = acpi_device_create(&dev->acpi_dev, dev, dev->vm_ctx, + &tpm_acpi_device_emul); + if (error) + goto err_out; + *new_dev = dev; return (0);