tpm-sysbus.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * tpm-sysbus.c - Support functions for SysBus TPM devices
  3. *
  4. * Copyright (c) 2023 QEMU contributors
  5. *
  6. * Authors:
  7. * Joelle van Dyne <j@getutm.app>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #include "system/tpm.h"
  13. #include "hw/platform-bus.h"
  14. #include "hw/sysbus.h"
  15. #include "qapi/error.h"
  16. /**
  17. * Called from a machine's pre_plug handler to set the device's physical addr.
  18. */
  19. void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base)
  20. {
  21. PlatformBusDevice *pbusdev = PLATFORM_BUS_DEVICE(pbus);
  22. SysBusDevice *sbdev = SYS_BUS_DEVICE(tpmif);
  23. MemoryRegion *sbdev_mr;
  24. hwaddr tpm_base;
  25. uint64_t tpm_size;
  26. /* exit early if TPM is not a sysbus device */
  27. if (!object_dynamic_cast(OBJECT(tpmif), TYPE_SYS_BUS_DEVICE)) {
  28. return;
  29. }
  30. assert(object_dynamic_cast(pbus, TYPE_PLATFORM_BUS_DEVICE));
  31. tpm_base = platform_bus_get_mmio_addr(pbusdev, sbdev, 0);
  32. assert(tpm_base != -1);
  33. tpm_base += pbus_base;
  34. sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
  35. tpm_size = memory_region_size(sbdev_mr);
  36. object_property_set_uint(OBJECT(sbdev), "x-baseaddr",
  37. tpm_base, &error_abort);
  38. object_property_set_uint(OBJECT(sbdev), "x-size",
  39. tpm_size, &error_abort);
  40. }