tpm_ppi.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "qemu/memalign.h"
  15. #include "qapi/error.h"
  16. #include "system/memory_mapping.h"
  17. #include "migration/vmstate.h"
  18. #include "hw/qdev-core.h"
  19. #include "hw/acpi/tpm.h"
  20. #include "tpm_ppi.h"
  21. #include "trace.h"
  22. void tpm_ppi_reset(TPMPPI *tpmppi)
  23. {
  24. if (tpmppi->buf[0x15a /* movv, docs/specs/tpm.rst */] & 0x1) {
  25. GuestPhysBlockList guest_phys_blocks;
  26. GuestPhysBlock *block;
  27. guest_phys_blocks_init(&guest_phys_blocks);
  28. guest_phys_blocks_append(&guest_phys_blocks);
  29. QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) {
  30. hwaddr mr_offs = block->host_addr -
  31. (uint8_t *)memory_region_get_ram_ptr(block->mr);
  32. trace_tpm_ppi_memset(block->host_addr,
  33. block->target_end - block->target_start);
  34. memset(block->host_addr, 0,
  35. block->target_end - block->target_start);
  36. memory_region_set_dirty(block->mr, mr_offs,
  37. block->target_end - block->target_start);
  38. }
  39. guest_phys_blocks_free(&guest_phys_blocks);
  40. }
  41. }
  42. void tpm_ppi_init_memory(TPMPPI *tpmppi, Object *obj)
  43. {
  44. size_t host_page_size = qemu_real_host_page_size();
  45. tpmppi->buf = qemu_memalign(host_page_size,
  46. ROUND_UP(TPM_PPI_ADDR_SIZE, host_page_size));
  47. memory_region_init_ram_device_ptr(&tpmppi->ram, obj, "tpm-ppi",
  48. TPM_PPI_ADDR_SIZE, tpmppi->buf);
  49. vmstate_register_ram(&tpmppi->ram, DEVICE(obj));
  50. }