memory_mapping.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * QEMU memory mapping
  3. *
  4. * Copyright Fujitsu, Corp. 2011, 2012
  5. *
  6. * Authors:
  7. * Wen Congyang <wency@cn.fujitsu.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 MEMORY_MAPPING_H
  14. #define MEMORY_MAPPING_H
  15. #include "qemu/queue.h"
  16. #include "exec/cpu-common.h"
  17. typedef struct GuestPhysBlock {
  18. /* visible to guest, reflects PCI hole, etc */
  19. hwaddr target_start;
  20. /* implies size */
  21. hwaddr target_end;
  22. /* points into host memory */
  23. uint8_t *host_addr;
  24. /* points to the MemoryRegion that this block belongs to */
  25. MemoryRegion *mr;
  26. QTAILQ_ENTRY(GuestPhysBlock) next;
  27. } GuestPhysBlock;
  28. /* point-in-time snapshot of guest-visible physical mappings */
  29. typedef struct GuestPhysBlockList {
  30. unsigned num;
  31. QTAILQ_HEAD(, GuestPhysBlock) head;
  32. } GuestPhysBlockList;
  33. /* The physical and virtual address in the memory mapping are contiguous. */
  34. typedef struct MemoryMapping {
  35. hwaddr phys_addr;
  36. vaddr virt_addr;
  37. ram_addr_t length;
  38. QTAILQ_ENTRY(MemoryMapping) next;
  39. } MemoryMapping;
  40. struct MemoryMappingList {
  41. unsigned int num;
  42. MemoryMapping *last_mapping;
  43. QTAILQ_HEAD(, MemoryMapping) head;
  44. };
  45. /*
  46. * add or merge the memory region [phys_addr, phys_addr + length) into the
  47. * memory mapping's list. The region's virtual address starts with virt_addr,
  48. * and is contiguous. The list is sorted by phys_addr.
  49. */
  50. void memory_mapping_list_add_merge_sorted(MemoryMappingList *list,
  51. hwaddr phys_addr,
  52. hwaddr virt_addr,
  53. ram_addr_t length);
  54. void memory_mapping_list_free(MemoryMappingList *list);
  55. void memory_mapping_list_init(MemoryMappingList *list);
  56. void guest_phys_blocks_free(GuestPhysBlockList *list);
  57. void guest_phys_blocks_init(GuestPhysBlockList *list);
  58. void guest_phys_blocks_append(GuestPhysBlockList *list);
  59. bool qemu_get_guest_memory_mapping(MemoryMappingList *list,
  60. const GuestPhysBlockList *guest_phys_blocks,
  61. Error **errp);
  62. /* get guest's memory mapping without do paging(virtual address is 0). */
  63. void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list,
  64. const GuestPhysBlockList *guest_phys_blocks);
  65. void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
  66. int64_t length);
  67. #endif