tpm_ppi.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * tpm_ppi.c - TPM Physical Presence Interface
  3. *
  4. * Copyright (C) 2018 IBM Corporation
  5. *
  6. * Authors:
  7. * Stefan Berger <stefanb@us.ibm.com>
  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. */
  13. #include "qemu/osdep.h"
  14. #include "qapi/error.h"
  15. #include "cpu.h"
  16. #include "sysemu/memory_mapping.h"
  17. #include "migration/vmstate.h"
  18. #include "tpm_ppi.h"
  19. #include "trace.h"
  20. void tpm_ppi_reset(TPMPPI *tpmppi)
  21. {
  22. if (tpmppi->buf[0x15a /* movv, docs/specs/tpm.txt */] & 0x1) {
  23. GuestPhysBlockList guest_phys_blocks;
  24. GuestPhysBlock *block;
  25. guest_phys_blocks_init(&guest_phys_blocks);
  26. guest_phys_blocks_append(&guest_phys_blocks);
  27. QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) {
  28. trace_tpm_ppi_memset(block->host_addr,
  29. block->target_end - block->target_start);
  30. memset(block->host_addr, 0,
  31. block->target_end - block->target_start);
  32. memory_region_set_dirty(block->mr, 0,
  33. block->target_end - block->target_start);
  34. }
  35. guest_phys_blocks_free(&guest_phys_blocks);
  36. }
  37. }
  38. void tpm_ppi_init(TPMPPI *tpmppi, struct MemoryRegion *m,
  39. hwaddr addr, Object *obj)
  40. {
  41. tpmppi->buf = g_malloc0(HOST_PAGE_ALIGN(TPM_PPI_ADDR_SIZE));
  42. memory_region_init_ram_device_ptr(&tpmppi->ram, obj, "tpm-ppi",
  43. TPM_PPI_ADDR_SIZE, tpmppi->buf);
  44. vmstate_register_ram(&tpmppi->ram, DEVICE(obj));
  45. memory_region_add_subregion(m, addr, &tpmppi->ram);
  46. }