tpm_ppi.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "hw/acpi/tpm.h"
  19. #include "tpm_ppi.h"
  20. #include "trace.h"
  21. void tpm_ppi_reset(TPMPPI *tpmppi)
  22. {
  23. if (tpmppi->buf[0x15a /* movv, docs/specs/tpm.txt */] & 0x1) {
  24. GuestPhysBlockList guest_phys_blocks;
  25. GuestPhysBlock *block;
  26. guest_phys_blocks_init(&guest_phys_blocks);
  27. guest_phys_blocks_append(&guest_phys_blocks);
  28. QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) {
  29. trace_tpm_ppi_memset(block->host_addr,
  30. block->target_end - block->target_start);
  31. memset(block->host_addr, 0,
  32. block->target_end - block->target_start);
  33. memory_region_set_dirty(block->mr, 0,
  34. block->target_end - block->target_start);
  35. }
  36. guest_phys_blocks_free(&guest_phys_blocks);
  37. }
  38. }
  39. void tpm_ppi_init(TPMPPI *tpmppi, struct MemoryRegion *m,
  40. hwaddr addr, Object *obj)
  41. {
  42. tpmppi->buf = qemu_memalign(qemu_real_host_page_size,
  43. HOST_PAGE_ALIGN(TPM_PPI_ADDR_SIZE));
  44. memory_region_init_ram_device_ptr(&tpmppi->ram, obj, "tpm-ppi",
  45. TPM_PPI_ADDR_SIZE, tpmppi->buf);
  46. vmstate_register_ram(&tpmppi->ram, DEVICE(obj));
  47. memory_region_add_subregion(m, addr, &tpmppi->ram);
  48. }