]> git.proxmox.com Git - mirror_qemu.git/blob - memory-internal.h
memory: add address_space_destroy()
[mirror_qemu.git] / memory-internal.h
1 /*
2 * Declarations for obsolete exec.c functions
3 *
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
5 *
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or
10 * later. See the COPYING file in the top-level directory.
11 *
12 */
13
14 /*
15 * This header is for use by exec.c and memory.c ONLY. Do not include it.
16 * The functions declared here will be removed soon.
17 */
18
19 #ifndef MEMORY_INTERNAL_H
20 #define MEMORY_INTERNAL_H
21
22 #ifndef CONFIG_USER_ONLY
23 #include "hw/xen.h"
24
25 typedef struct PhysPageEntry PhysPageEntry;
26
27 struct PhysPageEntry {
28 uint16_t is_leaf : 1;
29 /* index into phys_sections (is_leaf) or phys_map_nodes (!is_leaf) */
30 uint16_t ptr : 15;
31 };
32
33 typedef struct AddressSpaceDispatch AddressSpaceDispatch;
34
35 struct AddressSpaceDispatch {
36 /* This is a multi-level map on the physical address space.
37 * The bottom level has pointers to MemoryRegionSections.
38 */
39 PhysPageEntry phys_map;
40 MemoryListener listener;
41 };
42
43 void address_space_init_dispatch(AddressSpace *as);
44 void address_space_destroy_dispatch(AddressSpace *as);
45
46 ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
47 MemoryRegion *mr);
48 ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
49 void qemu_ram_free(ram_addr_t addr);
50 void qemu_ram_free_from_ptr(ram_addr_t addr);
51
52 struct MemoryRegion;
53 struct MemoryRegionSection;
54
55 void qemu_register_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
56 void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
57
58 int cpu_physical_memory_set_dirty_tracking(int enable);
59
60 #define VGA_DIRTY_FLAG 0x01
61 #define CODE_DIRTY_FLAG 0x02
62 #define MIGRATION_DIRTY_FLAG 0x08
63
64 static inline int cpu_physical_memory_get_dirty_flags(ram_addr_t addr)
65 {
66 return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS];
67 }
68
69 /* read dirty bit (return 0 or 1) */
70 static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
71 {
72 return cpu_physical_memory_get_dirty_flags(addr) == 0xff;
73 }
74
75 static inline int cpu_physical_memory_get_dirty(ram_addr_t start,
76 ram_addr_t length,
77 int dirty_flags)
78 {
79 int ret = 0;
80 ram_addr_t addr, end;
81
82 end = TARGET_PAGE_ALIGN(start + length);
83 start &= TARGET_PAGE_MASK;
84 for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
85 ret |= cpu_physical_memory_get_dirty_flags(addr) & dirty_flags;
86 }
87 return ret;
88 }
89
90 static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr,
91 int dirty_flags)
92 {
93 if ((dirty_flags & MIGRATION_DIRTY_FLAG) &&
94 !cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
95 MIGRATION_DIRTY_FLAG)) {
96 ram_list.dirty_pages++;
97 }
98 return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags;
99 }
100
101 static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
102 {
103 cpu_physical_memory_set_dirty_flags(addr, 0xff);
104 }
105
106 static inline int cpu_physical_memory_clear_dirty_flags(ram_addr_t addr,
107 int dirty_flags)
108 {
109 int mask = ~dirty_flags;
110
111 if ((dirty_flags & MIGRATION_DIRTY_FLAG) &&
112 cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
113 MIGRATION_DIRTY_FLAG)) {
114 ram_list.dirty_pages--;
115 }
116 return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask;
117 }
118
119 static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
120 ram_addr_t length,
121 int dirty_flags)
122 {
123 ram_addr_t addr, end;
124
125 end = TARGET_PAGE_ALIGN(start + length);
126 start &= TARGET_PAGE_MASK;
127 for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
128 cpu_physical_memory_set_dirty_flags(addr, dirty_flags);
129 }
130 xen_modified_memory(addr, length);
131 }
132
133 static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
134 ram_addr_t length,
135 int dirty_flags)
136 {
137 ram_addr_t addr, end;
138
139 end = TARGET_PAGE_ALIGN(start + length);
140 start &= TARGET_PAGE_MASK;
141 for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
142 cpu_physical_memory_clear_dirty_flags(addr, dirty_flags);
143 }
144 }
145
146 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
147 int dirty_flags);
148
149 extern const IORangeOps memory_region_iorange_ops;
150
151 #endif
152
153 #endif