@@ -12,6 +12,8 @@
#ifndef QEMU_TPM_H
#define QEMU_TPM_H
+#include "qemu/osdep.h"
+#include "exec/hwaddr.h"
#include "qapi/qapi-types-tpm.h"
#include "qom/object.h"
@@ -78,6 +80,8 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
return TPM_IF_GET_CLASS(ti)->get_version(ti);
}
+void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
+
#else /* CONFIG_TPM */
#define tpm_init() (0)
new file mode 100644
@@ -0,0 +1,47 @@
+/*
+ * tpm-sysbus.c - Support functions for SysBus TPM devices
+ *
+ * Copyright (c) 2023 QEMU contributors
+ *
+ * Authors:
+ * Joelle van Dyne <j@getutm.app>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysemu/tpm.h"
+#include "hw/platform-bus.h"
+#include "hw/sysbus.h"
+#include "qapi/error.h"
+
+/**
+ * Called from a machine's pre_plug handler to set the device's physical addr.
+ */
+void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base)
+{
+ PlatformBusDevice *pbusdev = PLATFORM_BUS_DEVICE(pbus);
+ SysBusDevice *sbdev = SYS_BUS_DEVICE(tpmif);
+ MemoryRegion *sbdev_mr;
+ hwaddr tpm_base;
+ uint64_t tpm_size;
+
+ /* exit early if TPM is not a sysbus device */
+ if (!object_dynamic_cast(OBJECT(tpmif), TYPE_SYS_BUS_DEVICE)) {
+ return;
+ }
+
+ assert(object_dynamic_cast(pbus, TYPE_PLATFORM_BUS_DEVICE));
+
+ tpm_base = platform_bus_get_mmio_addr(pbusdev, sbdev, 0);
+ assert(tpm_base != -1);
+
+ tpm_base += pbus_base;
+
+ sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
+ tpm_size = memory_region_size(sbdev_mr);
+
+ object_property_set_uint(OBJECT(sbdev), "x-baseaddr",
+ tpm_base, &error_abort);
+ object_property_set_uint(OBJECT(sbdev), "x-size",
+ tpm_size, &error_abort);
+}
@@ -1,6 +1,7 @@
system_ss.add(when: 'CONFIG_TPM_TIS', if_true: files('tpm_tis_common.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_ISA', if_true: files('tpm_tis_isa.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm_tis_sysbus.c'))
+system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm-sysbus.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_I2C', if_true: files('tpm_tis_i2c.c'))
system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb.c'))
system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb_common.c'))