From a945846e7c08c91c5e34b23d86437eb5b74e67b2 Mon Sep 17 00:00:00 2001 From: Tao Yuhong Date: Wed, 2 Jun 2021 06:57:46 -0400 Subject: [PATCH] DM: TPM: tpm passthrough device must use fixed base GPA The TPM driver will access some mmio registers using absolute address, That means TPM base GPA must use same HPA value, when passthough it to VM Tracked-On: #6126 Signed-off-by: Tao Yuhong --- devicemodel/hw/mmio/core.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/devicemodel/hw/mmio/core.c b/devicemodel/hw/mmio/core.c index ad44b99c1..a2dfe8edb 100644 --- a/devicemodel/hw/mmio/core.c +++ b/devicemodel/hw/mmio/core.c @@ -73,7 +73,12 @@ int parse_pt_acpidev(char *opt) /* TODO: support acpi dev framework, remove these TPM hard code */ if (strncmp(opt, "MSFT0101", 8) == 0) { strncpy(mmio_devs[mmio_dev_idx].name, "MSFT0101", 8); + /* TODO: We would parse the /proc/iomem to get the corresponding resources */ mmio_devs[mmio_dev_idx].dev.base_hpa = 0xFED40000UL; + /* FIXME: The 0xFED40000 doesn't conflict with other mmio or system memory so far. + * This need to be fixed by redesign the mmio_dev_alloc_gpa_resource32(). + */ + mmio_devs[mmio_dev_idx].dev.base_gpa = 0xFED40000UL; mmio_devs[mmio_dev_idx].dev.size = 0x00005000UL; mmio_dev_idx++; pt_tpm2 = true; @@ -126,10 +131,16 @@ int init_mmio_dev(struct vmctx *ctx, struct mmio_dev_ops *ops, struct acrn_mmiod int ret; uint32_t base; - ret = mmio_dev_alloc_gpa_resource32(&base, mmiodev->size); - if (ret < 0) - return ret; - mmiodev->base_gpa = base; + if (mmiodev->base_gpa == 0UL) { + /* FIXME: The mmio_dev_alloc_gpa_resource32 needs to add one new parameter to indicate + * if the caller needs one specific GPA instead of dynamic allocation. + */ + ret = mmio_dev_alloc_gpa_resource32(&base, mmiodev->size); + if (ret < 0) + return ret; + mmiodev->base_gpa = base; + } + return ops->init(ctx, mmiodev); }