| 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 | |
| 14 | #ifndef MEMORY_MAPPING_H |
| 15 | #define MEMORY_MAPPING_H |
| 16 | |
| 17 | #include "qemu/queue.h" |
| 18 | #include "exec/hwaddr.h" |
| 19 | #include "exec/vaddr.h" |
| 20 | #include "system/ram_addr.h" |
| 21 | |
| 22 | typedef struct GuestPhysBlock { |
| 23 | /* visible to guest, reflects PCI hole, etc */ |
| 24 | hwaddr target_start; |
| 25 | |
| 26 | /* implies size */ |
| 27 | hwaddr target_end; |
| 28 | |
| 29 | /* points into host memory */ |
| 30 | uint8_t *host_addr; |
| 31 | |
| 32 | /* points to the MemoryRegion that this block belongs to */ |
| 33 | MemoryRegion *mr; |
| 34 | |
| 35 | QTAILQ_ENTRY(GuestPhysBlock) next; |
| 36 | } GuestPhysBlock; |
| 37 | |
| 38 | /* point-in-time snapshot of guest-visible physical mappings */ |
| 39 | typedef struct GuestPhysBlockList { |
| 40 | unsigned num; |
| 41 | QTAILQ_HEAD(, GuestPhysBlock) head; |
| 42 | } GuestPhysBlockList; |
| 43 | |
| 44 | /* The physical and virtual address in the memory mapping are contiguous. */ |
| 45 | typedef struct MemoryMapping { |
| 46 | hwaddr phys_addr; |
| 47 | vaddr virt_addr; |
| 48 | ram_addr_t length; |
| 49 | QTAILQ_ENTRY(MemoryMapping) next; |
| 50 | } MemoryMapping; |
| 51 | |
| 52 | struct MemoryMappingList { |
| 53 | unsigned int num; |
| 54 | MemoryMapping *last_mapping; |
| 55 | QTAILQ_HEAD(, MemoryMapping) head; |
| 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * add or merge the memory region [phys_addr, phys_addr + length) into the |
| 60 | * memory mapping's list. The region's virtual address starts with virt_addr, |
| 61 | * and is contiguous. The list is sorted by phys_addr. |
| 62 | */ |
| 63 | void memory_mapping_list_add_merge_sorted(MemoryMappingList *list, |
| 64 | hwaddr phys_addr, |
| 65 | hwaddr virt_addr, |
| 66 | ram_addr_t length); |
| 67 | |
| 68 | void memory_mapping_list_free(MemoryMappingList *list); |
| 69 | |
| 70 | void memory_mapping_list_init(MemoryMappingList *list); |
| 71 | |
| 72 | void guest_phys_blocks_free(GuestPhysBlockList *list); |
| 73 | void guest_phys_blocks_init(GuestPhysBlockList *list); |
| 74 | void guest_phys_blocks_append(GuestPhysBlockList *list); |
| 75 | |
| 76 | bool qemu_get_guest_memory_mapping(MemoryMappingList *list, |
| 77 | const GuestPhysBlockList *guest_phys_blocks, |
| 78 | Error **errp); |
| 79 | |
| 80 | /* get guest's memory mapping without do paging(virtual address is 0). */ |
| 81 | void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list, |
| 82 | const GuestPhysBlockList *guest_phys_blocks); |
| 83 | |
| 84 | void memory_mapping_filter(MemoryMappingList *list, int64_t begin, |
| 85 | int64_t length); |
| 86 | |
| 87 | #endif |