hostmem.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Thread-safe guest to host memory mapping
  3. *
  4. * Copyright 2012 Red Hat, Inc. and/or its affiliates
  5. *
  6. * Authors:
  7. * Stefan Hajnoczi <stefanha@redhat.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. #ifndef HOSTMEM_H
  14. #define HOSTMEM_H
  15. #include "exec/memory.h"
  16. #include "qemu/thread.h"
  17. typedef struct {
  18. void *host_addr;
  19. hwaddr guest_addr;
  20. uint64_t size;
  21. bool readonly;
  22. } HostMemRegion;
  23. typedef struct {
  24. /* The listener is invoked when regions change and a new list of regions is
  25. * built up completely before they are installed.
  26. */
  27. MemoryListener listener;
  28. HostMemRegion *new_regions;
  29. size_t num_new_regions;
  30. /* Current regions are accessed from multiple threads either to lookup
  31. * addresses or to install a new list of regions. The lock protects the
  32. * pointer and the regions.
  33. */
  34. QemuMutex current_regions_lock;
  35. HostMemRegion *current_regions;
  36. size_t num_current_regions;
  37. } HostMem;
  38. void hostmem_init(HostMem *hostmem);
  39. void hostmem_finalize(HostMem *hostmem);
  40. /**
  41. * Map a guest physical address to a pointer
  42. *
  43. * Note that there is map/unmap mechanism here. The caller must ensure that
  44. * mapped memory is no longer used across events like hot memory unplug. This
  45. * can be done with other mechanisms like bdrv_drain_all() that quiesce
  46. * in-flight I/O.
  47. */
  48. void *hostmem_lookup(HostMem *hostmem, hwaddr phys, hwaddr len, bool is_write);
  49. #endif /* HOSTMEM_H */