Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / sysemu / memory_mapping.h
blob021e0a623091b08a42fe5a0941cf2289f0fdad32
1 /*
2 * QEMU memory mapping
4 * Copyright Fujitsu, Corp. 2011, 2012
6 * Authors:
7 * Wen Congyang <wency@cn.fujitsu.com>
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.
14 #ifndef MEMORY_MAPPING_H
15 #define MEMORY_MAPPING_H
17 #include "qemu/queue.h"
18 #include "exec/cpu-common.h"
20 typedef struct GuestPhysBlock {
21 /* visible to guest, reflects PCI hole, etc */
22 hwaddr target_start;
24 /* implies size */
25 hwaddr target_end;
27 /* points into host memory */
28 uint8_t *host_addr;
30 /* points to the MemoryRegion that this block belongs to */
31 MemoryRegion *mr;
33 QTAILQ_ENTRY(GuestPhysBlock) next;
34 } GuestPhysBlock;
36 /* point-in-time snapshot of guest-visible physical mappings */
37 typedef struct GuestPhysBlockList {
38 unsigned num;
39 QTAILQ_HEAD(, GuestPhysBlock) head;
40 } GuestPhysBlockList;
42 /* The physical and virtual address in the memory mapping are contiguous. */
43 typedef struct MemoryMapping {
44 hwaddr phys_addr;
45 vaddr virt_addr;
46 ram_addr_t length;
47 QTAILQ_ENTRY(MemoryMapping) next;
48 } MemoryMapping;
50 struct MemoryMappingList {
51 unsigned int num;
52 MemoryMapping *last_mapping;
53 QTAILQ_HEAD(, MemoryMapping) head;
57 * add or merge the memory region [phys_addr, phys_addr + length) into the
58 * memory mapping's list. The region's virtual address starts with virt_addr,
59 * and is contiguous. The list is sorted by phys_addr.
61 void memory_mapping_list_add_merge_sorted(MemoryMappingList *list,
62 hwaddr phys_addr,
63 hwaddr virt_addr,
64 ram_addr_t length);
66 void memory_mapping_list_free(MemoryMappingList *list);
68 void memory_mapping_list_init(MemoryMappingList *list);
70 void guest_phys_blocks_free(GuestPhysBlockList *list);
71 void guest_phys_blocks_init(GuestPhysBlockList *list);
72 void guest_phys_blocks_append(GuestPhysBlockList *list);
74 bool qemu_get_guest_memory_mapping(MemoryMappingList *list,
75 const GuestPhysBlockList *guest_phys_blocks,
76 Error **errp);
78 /* get guest's memory mapping without do paging(virtual address is 0). */
79 void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list,
80 const GuestPhysBlockList *guest_phys_blocks);
82 void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
83 int64_t length);
85 #endif