Message ID | 20230714070931.23476-9-j@getutm.app (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | tpm: introduce TPM CRB SysBus device | expand |
On 7/14/23 03:09, Joelle van Dyne wrote: > TPM needs to know its own base address in order to generate its DSDT > device entry. > > Signed-off-by: Joelle van Dyne <j@getutm.app> It would be great to also cover the crb-device with tests: from tests/qtest/meson.build: (config_all.has_key('CONFIG_TCG') and config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ It should be easy to make a copy of these two tis-device tests and rename them to crb-device tests, adapt them, and run them at least on aarch64. Regards, Stefan
On 7/20/23 13:57, Stefan Berger wrote: > > > On 7/14/23 03:09, Joelle van Dyne wrote: >> TPM needs to know its own base address in order to generate its DSDT >> device entry. >> >> Signed-off-by: Joelle van Dyne <j@getutm.app> > > > It would be great to also cover the crb-device with tests: > > from tests/qtest/meson.build: > > (config_all.has_key('CONFIG_TCG') and config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? \ > ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ > > It should be easy to make a copy of these two tis-device tests and rename them to crb-device tests, adapt them, and run them at least on aarch64. ... actually make a copy of the files tests/qtest/tpm-crb-swtpm-test.c & tests/qtest/tpm-crb-test.c. > > Regards, > Stefan
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index e19b042ce8..9c536c52bc 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -1040,6 +1040,37 @@ static void virt_mem_plug(HotplugHandler *hotplug_dev, dev, &error_abort); } +#ifdef CONFIG_TPM +static void virt_tpm_plug(LoongArchMachineState *lams, TPMIf *tpmif) +{ + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(lams->platform_bus_dev); + hwaddr pbus_base = VIRT_PLATFORM_BUS_BASEADDRESS; + SysBusDevice *sbdev = SYS_BUS_DEVICE(tpmif); + MemoryRegion *sbdev_mr; + hwaddr tpm_base; + uint64_t tpm_size; + + if (!sbdev || !object_dynamic_cast(OBJECT(sbdev), TYPE_SYS_BUS_DEVICE)) { + return; + } + + tpm_base = platform_bus_get_mmio_addr(pbus, 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); + + if (object_property_find(OBJECT(sbdev), "baseaddr")) { + object_property_set_uint(OBJECT(sbdev), "baseaddr", tpm_base, NULL); + } + if (object_property_find(OBJECT(sbdev), "size")) { + object_property_set_uint(OBJECT(sbdev), "size", tpm_size, NULL); + } +} +#endif + static void loongarch_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -1054,6 +1085,12 @@ static void loongarch_machine_device_plug_cb(HotplugHandler *hotplug_dev, } else if (memhp_type_supported(dev)) { virt_mem_plug(hotplug_dev, dev, errp); } + +#ifdef CONFIG_TPM + if (object_dynamic_cast(OBJECT(dev), TYPE_TPM_IF)) { + virt_tpm_plug(lams, TPM_IF(dev)); + } +#endif } static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
TPM needs to know its own base address in order to generate its DSDT device entry. Signed-off-by: Joelle van Dyne <j@getutm.app> --- hw/loongarch/virt.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)