]>
Commit | Line | Data |
---|---|---|
093bc2cd AK |
1 | /* |
2 | * Physical memory management API | |
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. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
12 | */ | |
13 | ||
14 | #ifndef MEMORY_H | |
15 | #define MEMORY_H | |
16 | ||
17 | #ifndef CONFIG_USER_ONLY | |
18 | ||
19 | #include <stdint.h> | |
20 | #include <stdbool.h> | |
21 | #include "qemu-common.h" | |
22 | #include "cpu-common.h" | |
23 | #include "targphys.h" | |
24 | #include "qemu-queue.h" | |
658b2224 | 25 | #include "iorange.h" |
627a0e90 | 26 | #include "ioport.h" |
08dafab4 | 27 | #include "int128.h" |
093bc2cd AK |
28 | |
29 | typedef struct MemoryRegionOps MemoryRegionOps; | |
30 | typedef struct MemoryRegion MemoryRegion; | |
627a0e90 | 31 | typedef struct MemoryRegionPortio MemoryRegionPortio; |
74901c3b | 32 | typedef struct MemoryRegionMmio MemoryRegionMmio; |
093bc2cd AK |
33 | |
34 | /* Must match *_DIRTY_FLAGS in cpu-all.h. To be replaced with dynamic | |
35 | * registration. | |
36 | */ | |
37 | #define DIRTY_MEMORY_VGA 0 | |
38 | #define DIRTY_MEMORY_CODE 1 | |
39 | #define DIRTY_MEMORY_MIGRATION 3 | |
40 | ||
74901c3b AK |
41 | struct MemoryRegionMmio { |
42 | CPUReadMemoryFunc *read[3]; | |
43 | CPUWriteMemoryFunc *write[3]; | |
44 | }; | |
45 | ||
093bc2cd AK |
46 | /* |
47 | * Memory region callbacks | |
48 | */ | |
49 | struct MemoryRegionOps { | |
50 | /* Read from the memory region. @addr is relative to @mr; @size is | |
51 | * in bytes. */ | |
52 | uint64_t (*read)(void *opaque, | |
53 | target_phys_addr_t addr, | |
54 | unsigned size); | |
55 | /* Write to the memory region. @addr is relative to @mr; @size is | |
56 | * in bytes. */ | |
57 | void (*write)(void *opaque, | |
58 | target_phys_addr_t addr, | |
59 | uint64_t data, | |
60 | unsigned size); | |
61 | ||
62 | enum device_endian endianness; | |
63 | /* Guest-visible constraints: */ | |
64 | struct { | |
65 | /* If nonzero, specify bounds on access sizes beyond which a machine | |
66 | * check is thrown. | |
67 | */ | |
68 | unsigned min_access_size; | |
69 | unsigned max_access_size; | |
70 | /* If true, unaligned accesses are supported. Otherwise unaligned | |
71 | * accesses throw machine checks. | |
72 | */ | |
73 | bool unaligned; | |
897fa7cf AK |
74 | /* |
75 | * If present, and returns #false, the transaction is not accepted | |
76 | * by the device (and results in machine dependent behaviour such | |
77 | * as a machine check exception). | |
78 | */ | |
79 | bool (*accepts)(void *opaque, target_phys_addr_t addr, | |
80 | unsigned size, bool is_write); | |
093bc2cd AK |
81 | } valid; |
82 | /* Internal implementation constraints: */ | |
83 | struct { | |
84 | /* If nonzero, specifies the minimum size implemented. Smaller sizes | |
85 | * will be rounded upwards and a partial result will be returned. | |
86 | */ | |
87 | unsigned min_access_size; | |
88 | /* If nonzero, specifies the maximum size implemented. Larger sizes | |
89 | * will be done as a series of accesses with smaller sizes. | |
90 | */ | |
91 | unsigned max_access_size; | |
92 | /* If true, unaligned accesses are supported. Otherwise all accesses | |
93 | * are converted to (possibly multiple) naturally aligned accesses. | |
94 | */ | |
95 | bool unaligned; | |
96 | } impl; | |
627a0e90 AK |
97 | |
98 | /* If .read and .write are not present, old_portio may be used for | |
99 | * backwards compatibility with old portio registration | |
100 | */ | |
101 | const MemoryRegionPortio *old_portio; | |
74901c3b AK |
102 | /* If .read and .write are not present, old_mmio may be used for |
103 | * backwards compatibility with old mmio registration | |
104 | */ | |
105 | const MemoryRegionMmio old_mmio; | |
093bc2cd AK |
106 | }; |
107 | ||
108 | typedef struct CoalescedMemoryRange CoalescedMemoryRange; | |
3e9d69e7 | 109 | typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; |
093bc2cd AK |
110 | |
111 | struct MemoryRegion { | |
112 | /* All fields are private - violators will be prosecuted */ | |
113 | const MemoryRegionOps *ops; | |
114 | void *opaque; | |
115 | MemoryRegion *parent; | |
08dafab4 | 116 | Int128 size; |
093bc2cd | 117 | target_phys_addr_t addr; |
545e92e0 | 118 | void (*destructor)(MemoryRegion *mr); |
093bc2cd | 119 | ram_addr_t ram_addr; |
658b2224 | 120 | IORange iorange; |
b3b00c78 | 121 | bool subpage; |
14a3c10a | 122 | bool terminates; |
d0a9b5bc | 123 | bool readable; |
8ea9252a | 124 | bool ram; |
fb1cd6f9 | 125 | bool readonly; /* For RAM regions */ |
6bba19ba | 126 | bool enabled; |
75c578dc | 127 | bool rom_device; |
1660e72d | 128 | bool warning_printed; /* For reservations */ |
093bc2cd AK |
129 | MemoryRegion *alias; |
130 | target_phys_addr_t alias_offset; | |
131 | unsigned priority; | |
132 | bool may_overlap; | |
133 | QTAILQ_HEAD(subregions, MemoryRegion) subregions; | |
134 | QTAILQ_ENTRY(MemoryRegion) subregions_link; | |
135 | QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced; | |
136 | const char *name; | |
5a583347 | 137 | uint8_t dirty_log_mask; |
3e9d69e7 AK |
138 | unsigned ioeventfd_nb; |
139 | MemoryRegionIoeventfd *ioeventfds; | |
093bc2cd AK |
140 | }; |
141 | ||
627a0e90 AK |
142 | struct MemoryRegionPortio { |
143 | uint32_t offset; | |
144 | uint32_t len; | |
145 | unsigned size; | |
146 | IOPortReadFunc *read; | |
147 | IOPortWriteFunc *write; | |
148 | }; | |
149 | ||
2dd30228 | 150 | #define PORTIO_END_OF_LIST() { } |
627a0e90 | 151 | |
e2177955 AK |
152 | typedef struct MemoryRegionSection MemoryRegionSection; |
153 | ||
154 | /** | |
155 | * MemoryRegionSection: describes a fragment of a #MemoryRegion | |
156 | * | |
157 | * @mr: the region, or %NULL if empty | |
7664e80c | 158 | * @address_space: the address space the region is mapped in |
e2177955 AK |
159 | * @offset_within_region: the beginning of the section, relative to @mr's start |
160 | * @size: the size of the section; will not exceed @mr's boundaries | |
161 | * @offset_within_address_space: the address of the first byte of the section | |
162 | * relative to the region's address space | |
7a8499e8 | 163 | * @readonly: writes to this section are ignored |
e2177955 AK |
164 | */ |
165 | struct MemoryRegionSection { | |
166 | MemoryRegion *mr; | |
7664e80c | 167 | MemoryRegion *address_space; |
e2177955 AK |
168 | target_phys_addr_t offset_within_region; |
169 | uint64_t size; | |
170 | target_phys_addr_t offset_within_address_space; | |
7a8499e8 | 171 | bool readonly; |
e2177955 AK |
172 | }; |
173 | ||
7664e80c AK |
174 | typedef struct MemoryListener MemoryListener; |
175 | ||
176 | /** | |
177 | * MemoryListener: callbacks structure for updates to the physical memory map | |
178 | * | |
179 | * Allows a component to adjust to changes in the guest-visible memory map. | |
180 | * Use with memory_listener_register() and memory_listener_unregister(). | |
181 | */ | |
182 | struct MemoryListener { | |
50c1e149 AK |
183 | void (*begin)(MemoryListener *listener); |
184 | void (*commit)(MemoryListener *listener); | |
7664e80c AK |
185 | void (*region_add)(MemoryListener *listener, MemoryRegionSection *section); |
186 | void (*region_del)(MemoryListener *listener, MemoryRegionSection *section); | |
50c1e149 | 187 | void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section); |
7664e80c AK |
188 | void (*log_start)(MemoryListener *listener, MemoryRegionSection *section); |
189 | void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section); | |
190 | void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section); | |
191 | void (*log_global_start)(MemoryListener *listener); | |
192 | void (*log_global_stop)(MemoryListener *listener); | |
80a1ea37 AK |
193 | void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section, |
194 | bool match_data, uint64_t data, int fd); | |
195 | void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section, | |
196 | bool match_data, uint64_t data, int fd); | |
72e22d2f AK |
197 | /* Lower = earlier (during add), later (during del) */ |
198 | unsigned priority; | |
7376e582 | 199 | MemoryRegion *address_space_filter; |
72e22d2f | 200 | QTAILQ_ENTRY(MemoryListener) link; |
7664e80c AK |
201 | }; |
202 | ||
093bc2cd AK |
203 | /** |
204 | * memory_region_init: Initialize a memory region | |
205 | * | |
69ddaf66 | 206 | * The region typically acts as a container for other memory regions. Use |
093bc2cd AK |
207 | * memory_region_add_subregion() to add subregions. |
208 | * | |
209 | * @mr: the #MemoryRegion to be initialized | |
210 | * @name: used for debugging; not visible to the user or ABI | |
211 | * @size: size of the region; any subregions beyond this size will be clipped | |
212 | */ | |
213 | void memory_region_init(MemoryRegion *mr, | |
214 | const char *name, | |
215 | uint64_t size); | |
216 | /** | |
217 | * memory_region_init_io: Initialize an I/O memory region. | |
218 | * | |
69ddaf66 | 219 | * Accesses into the region will cause the callbacks in @ops to be called. |
093bc2cd AK |
220 | * if @size is nonzero, subregions will be clipped to @size. |
221 | * | |
222 | * @mr: the #MemoryRegion to be initialized. | |
223 | * @ops: a structure containing read and write callbacks to be used when | |
224 | * I/O is performed on the region. | |
225 | * @opaque: passed to to the read and write callbacks of the @ops structure. | |
226 | * @name: used for debugging; not visible to the user or ABI | |
227 | * @size: size of the region. | |
228 | */ | |
229 | void memory_region_init_io(MemoryRegion *mr, | |
230 | const MemoryRegionOps *ops, | |
231 | void *opaque, | |
232 | const char *name, | |
233 | uint64_t size); | |
234 | ||
235 | /** | |
236 | * memory_region_init_ram: Initialize RAM memory region. Accesses into the | |
69ddaf66 | 237 | * region will modify memory directly. |
093bc2cd AK |
238 | * |
239 | * @mr: the #MemoryRegion to be initialized. | |
c5705a77 | 240 | * @name: the name of the region. |
093bc2cd AK |
241 | * @size: size of the region. |
242 | */ | |
243 | void memory_region_init_ram(MemoryRegion *mr, | |
093bc2cd AK |
244 | const char *name, |
245 | uint64_t size); | |
246 | ||
247 | /** | |
248 | * memory_region_init_ram: Initialize RAM memory region from a user-provided. | |
69ddaf66 | 249 | * pointer. Accesses into the region will modify |
093bc2cd AK |
250 | * memory directly. |
251 | * | |
252 | * @mr: the #MemoryRegion to be initialized. | |
c5705a77 | 253 | * @name: the name of the region. |
093bc2cd AK |
254 | * @size: size of the region. |
255 | * @ptr: memory to be mapped; must contain at least @size bytes. | |
256 | */ | |
257 | void memory_region_init_ram_ptr(MemoryRegion *mr, | |
093bc2cd AK |
258 | const char *name, |
259 | uint64_t size, | |
260 | void *ptr); | |
261 | ||
262 | /** | |
263 | * memory_region_init_alias: Initialize a memory region that aliases all or a | |
264 | * part of another memory region. | |
265 | * | |
266 | * @mr: the #MemoryRegion to be initialized. | |
267 | * @name: used for debugging; not visible to the user or ABI | |
268 | * @orig: the region to be referenced; @mr will be equivalent to | |
269 | * @orig between @offset and @offset + @size - 1. | |
270 | * @offset: start of the section in @orig to be referenced. | |
271 | * @size: size of the region. | |
272 | */ | |
273 | void memory_region_init_alias(MemoryRegion *mr, | |
274 | const char *name, | |
275 | MemoryRegion *orig, | |
276 | target_phys_addr_t offset, | |
277 | uint64_t size); | |
d0a9b5bc AK |
278 | |
279 | /** | |
280 | * memory_region_init_rom_device: Initialize a ROM memory region. Writes are | |
281 | * handled via callbacks. | |
282 | * | |
283 | * @mr: the #MemoryRegion to be initialized. | |
284 | * @ops: callbacks for write access handling. | |
c5705a77 | 285 | * @name: the name of the region. |
d0a9b5bc AK |
286 | * @size: size of the region. |
287 | */ | |
288 | void memory_region_init_rom_device(MemoryRegion *mr, | |
289 | const MemoryRegionOps *ops, | |
75f5941c | 290 | void *opaque, |
d0a9b5bc AK |
291 | const char *name, |
292 | uint64_t size); | |
293 | ||
1660e72d JK |
294 | /** |
295 | * memory_region_init_reservation: Initialize a memory region that reserves | |
296 | * I/O space. | |
297 | * | |
298 | * A reservation region primariy serves debugging purposes. It claims I/O | |
299 | * space that is not supposed to be handled by QEMU itself. Any access via | |
300 | * the memory API will cause an abort(). | |
301 | * | |
302 | * @mr: the #MemoryRegion to be initialized | |
303 | * @name: used for debugging; not visible to the user or ABI | |
304 | * @size: size of the region. | |
305 | */ | |
306 | void memory_region_init_reservation(MemoryRegion *mr, | |
307 | const char *name, | |
308 | uint64_t size); | |
093bc2cd | 309 | /** |
69ddaf66 | 310 | * memory_region_destroy: Destroy a memory region and reclaim all resources. |
093bc2cd AK |
311 | * |
312 | * @mr: the region to be destroyed. May not currently be a subregion | |
313 | * (see memory_region_add_subregion()) or referenced in an alias | |
314 | * (see memory_region_init_alias()). | |
315 | */ | |
316 | void memory_region_destroy(MemoryRegion *mr); | |
317 | ||
318 | /** | |
319 | * memory_region_size: get a memory region's size. | |
320 | * | |
321 | * @mr: the memory region being queried. | |
322 | */ | |
323 | uint64_t memory_region_size(MemoryRegion *mr); | |
324 | ||
8ea9252a AK |
325 | /** |
326 | * memory_region_is_ram: check whether a memory region is random access | |
327 | * | |
328 | * Returns %true is a memory region is random access. | |
329 | * | |
330 | * @mr: the memory region being queried | |
331 | */ | |
332 | bool memory_region_is_ram(MemoryRegion *mr); | |
333 | ||
8991c79b AK |
334 | /** |
335 | * memory_region_name: get a memory region's name | |
336 | * | |
337 | * Returns the string that was used to initialize the memory region. | |
338 | * | |
339 | * @mr: the memory region being queried | |
340 | */ | |
341 | const char *memory_region_name(MemoryRegion *mr); | |
342 | ||
55043ba3 AK |
343 | /** |
344 | * memory_region_is_logging: return whether a memory region is logging writes | |
345 | * | |
346 | * Returns %true if the memory region is logging writes | |
347 | * | |
348 | * @mr: the memory region being queried | |
349 | */ | |
350 | bool memory_region_is_logging(MemoryRegion *mr); | |
351 | ||
ce7923da AK |
352 | /** |
353 | * memory_region_is_rom: check whether a memory region is ROM | |
354 | * | |
355 | * Returns %true is a memory region is read-only memory. | |
356 | * | |
357 | * @mr: the memory region being queried | |
358 | */ | |
359 | bool memory_region_is_rom(MemoryRegion *mr); | |
360 | ||
093bc2cd AK |
361 | /** |
362 | * memory_region_get_ram_ptr: Get a pointer into a RAM memory region. | |
363 | * | |
364 | * Returns a host pointer to a RAM memory region (created with | |
365 | * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with | |
366 | * care. | |
367 | * | |
368 | * @mr: the memory region being queried. | |
369 | */ | |
370 | void *memory_region_get_ram_ptr(MemoryRegion *mr); | |
371 | ||
093bc2cd AK |
372 | /** |
373 | * memory_region_set_log: Turn dirty logging on or off for a region. | |
374 | * | |
375 | * Turns dirty logging on or off for a specified client (display, migration). | |
376 | * Only meaningful for RAM regions. | |
377 | * | |
378 | * @mr: the memory region being updated. | |
379 | * @log: whether dirty logging is to be enabled or disabled. | |
380 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
381 | * %DIRTY_MEMORY_VGA. | |
382 | */ | |
383 | void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client); | |
384 | ||
385 | /** | |
cd7a45c9 BS |
386 | * memory_region_get_dirty: Check whether a range of bytes is dirty |
387 | * for a specified client. | |
093bc2cd | 388 | * |
cd7a45c9 | 389 | * Checks whether a range of bytes has been written to since the last |
093bc2cd AK |
390 | * call to memory_region_reset_dirty() with the same @client. Dirty logging |
391 | * must be enabled. | |
392 | * | |
393 | * @mr: the memory region being queried. | |
394 | * @addr: the address (relative to the start of the region) being queried. | |
cd7a45c9 | 395 | * @size: the size of the range being queried. |
093bc2cd AK |
396 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or |
397 | * %DIRTY_MEMORY_VGA. | |
398 | */ | |
399 | bool memory_region_get_dirty(MemoryRegion *mr, target_phys_addr_t addr, | |
cd7a45c9 | 400 | target_phys_addr_t size, unsigned client); |
093bc2cd AK |
401 | |
402 | /** | |
fd4aa979 | 403 | * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region. |
093bc2cd | 404 | * |
fd4aa979 BS |
405 | * Marks a range of bytes as dirty, after it has been dirtied outside |
406 | * guest code. | |
093bc2cd | 407 | * |
fd4aa979 | 408 | * @mr: the memory region being dirtied. |
093bc2cd | 409 | * @addr: the address (relative to the start of the region) being dirtied. |
fd4aa979 | 410 | * @size: size of the range being dirtied. |
093bc2cd | 411 | */ |
fd4aa979 BS |
412 | void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr, |
413 | target_phys_addr_t size); | |
093bc2cd AK |
414 | |
415 | /** | |
416 | * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with | |
417 | * any external TLBs (e.g. kvm) | |
418 | * | |
419 | * Flushes dirty information from accelerators such as kvm and vhost-net | |
420 | * and makes it available to users of the memory API. | |
421 | * | |
422 | * @mr: the region being flushed. | |
423 | */ | |
424 | void memory_region_sync_dirty_bitmap(MemoryRegion *mr); | |
425 | ||
426 | /** | |
427 | * memory_region_reset_dirty: Mark a range of pages as clean, for a specified | |
428 | * client. | |
429 | * | |
430 | * Marks a range of pages as no longer dirty. | |
431 | * | |
432 | * @mr: the region being updated. | |
433 | * @addr: the start of the subrange being cleaned. | |
434 | * @size: the size of the subrange being cleaned. | |
435 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
436 | * %DIRTY_MEMORY_VGA. | |
437 | */ | |
438 | void memory_region_reset_dirty(MemoryRegion *mr, target_phys_addr_t addr, | |
439 | target_phys_addr_t size, unsigned client); | |
440 | ||
441 | /** | |
442 | * memory_region_set_readonly: Turn a memory region read-only (or read-write) | |
443 | * | |
444 | * Allows a memory region to be marked as read-only (turning it into a ROM). | |
445 | * only useful on RAM regions. | |
446 | * | |
447 | * @mr: the region being updated. | |
448 | * @readonly: whether rhe region is to be ROM or RAM. | |
449 | */ | |
450 | void memory_region_set_readonly(MemoryRegion *mr, bool readonly); | |
451 | ||
d0a9b5bc AK |
452 | /** |
453 | * memory_region_rom_device_set_readable: enable/disable ROM readability | |
454 | * | |
455 | * Allows a ROM device (initialized with memory_region_init_rom_device() to | |
456 | * to be marked as readable (default) or not readable. When it is readable, | |
457 | * the device is mapped to guest memory. When not readable, reads are | |
458 | * forwarded to the #MemoryRegion.read function. | |
459 | * | |
460 | * @mr: the memory region to be updated | |
461 | * @readable: whether reads are satisified directly (%true) or via callbacks | |
462 | * (%false) | |
463 | */ | |
464 | void memory_region_rom_device_set_readable(MemoryRegion *mr, bool readable); | |
465 | ||
093bc2cd AK |
466 | /** |
467 | * memory_region_set_coalescing: Enable memory coalescing for the region. | |
468 | * | |
469 | * Enabled writes to a region to be queued for later processing. MMIO ->write | |
470 | * callbacks may be delayed until a non-coalesced MMIO is issued. | |
471 | * Only useful for IO regions. Roughly similar to write-combining hardware. | |
472 | * | |
473 | * @mr: the memory region to be write coalesced | |
474 | */ | |
475 | void memory_region_set_coalescing(MemoryRegion *mr); | |
476 | ||
477 | /** | |
478 | * memory_region_add_coalescing: Enable memory coalescing for a sub-range of | |
479 | * a region. | |
480 | * | |
481 | * Like memory_region_set_coalescing(), but works on a sub-range of a region. | |
482 | * Multiple calls can be issued coalesced disjoint ranges. | |
483 | * | |
484 | * @mr: the memory region to be updated. | |
485 | * @offset: the start of the range within the region to be coalesced. | |
486 | * @size: the size of the subrange to be coalesced. | |
487 | */ | |
488 | void memory_region_add_coalescing(MemoryRegion *mr, | |
489 | target_phys_addr_t offset, | |
490 | uint64_t size); | |
491 | ||
492 | /** | |
493 | * memory_region_clear_coalescing: Disable MMIO coalescing for the region. | |
494 | * | |
495 | * Disables any coalescing caused by memory_region_set_coalescing() or | |
496 | * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory | |
497 | * hardware. | |
498 | * | |
499 | * @mr: the memory region to be updated. | |
500 | */ | |
501 | void memory_region_clear_coalescing(MemoryRegion *mr); | |
502 | ||
3e9d69e7 AK |
503 | /** |
504 | * memory_region_add_eventfd: Request an eventfd to be triggered when a word | |
505 | * is written to a location. | |
506 | * | |
507 | * Marks a word in an IO region (initialized with memory_region_init_io()) | |
508 | * as a trigger for an eventfd event. The I/O callback will not be called. | |
69ddaf66 | 509 | * The caller must be prepared to handle failure (that is, take the required |
3e9d69e7 AK |
510 | * action if the callback _is_ called). |
511 | * | |
512 | * @mr: the memory region being updated. | |
513 | * @addr: the address within @mr that is to be monitored | |
514 | * @size: the size of the access to trigger the eventfd | |
515 | * @match_data: whether to match against @data, instead of just @addr | |
516 | * @data: the data to match against the guest write | |
517 | * @fd: the eventfd to be triggered when @addr, @size, and @data all match. | |
518 | **/ | |
519 | void memory_region_add_eventfd(MemoryRegion *mr, | |
520 | target_phys_addr_t addr, | |
521 | unsigned size, | |
522 | bool match_data, | |
523 | uint64_t data, | |
524 | int fd); | |
525 | ||
526 | /** | |
69ddaf66 | 527 | * memory_region_del_eventfd: Cancel an eventfd. |
3e9d69e7 | 528 | * |
69ddaf66 ASRJ |
529 | * Cancels an eventfd trigger requested by a previous |
530 | * memory_region_add_eventfd() call. | |
3e9d69e7 AK |
531 | * |
532 | * @mr: the memory region being updated. | |
533 | * @addr: the address within @mr that is to be monitored | |
534 | * @size: the size of the access to trigger the eventfd | |
535 | * @match_data: whether to match against @data, instead of just @addr | |
536 | * @data: the data to match against the guest write | |
537 | * @fd: the eventfd to be triggered when @addr, @size, and @data all match. | |
538 | */ | |
539 | void memory_region_del_eventfd(MemoryRegion *mr, | |
540 | target_phys_addr_t addr, | |
541 | unsigned size, | |
542 | bool match_data, | |
543 | uint64_t data, | |
544 | int fd); | |
093bc2cd | 545 | /** |
69ddaf66 | 546 | * memory_region_add_subregion: Add a subregion to a container. |
093bc2cd | 547 | * |
69ddaf66 | 548 | * Adds a subregion at @offset. The subregion may not overlap with other |
093bc2cd AK |
549 | * subregions (except for those explicitly marked as overlapping). A region |
550 | * may only be added once as a subregion (unless removed with | |
551 | * memory_region_del_subregion()); use memory_region_init_alias() if you | |
552 | * want a region to be a subregion in multiple locations. | |
553 | * | |
554 | * @mr: the region to contain the new subregion; must be a container | |
555 | * initialized with memory_region_init(). | |
556 | * @offset: the offset relative to @mr where @subregion is added. | |
557 | * @subregion: the subregion to be added. | |
558 | */ | |
559 | void memory_region_add_subregion(MemoryRegion *mr, | |
560 | target_phys_addr_t offset, | |
561 | MemoryRegion *subregion); | |
562 | /** | |
69ddaf66 | 563 | * memory_region_add_subregion: Add a subregion to a container, with overlap. |
093bc2cd | 564 | * |
69ddaf66 | 565 | * Adds a subregion at @offset. The subregion may overlap with other |
093bc2cd AK |
566 | * subregions. Conflicts are resolved by having a higher @priority hide a |
567 | * lower @priority. Subregions without priority are taken as @priority 0. | |
568 | * A region may only be added once as a subregion (unless removed with | |
569 | * memory_region_del_subregion()); use memory_region_init_alias() if you | |
570 | * want a region to be a subregion in multiple locations. | |
571 | * | |
572 | * @mr: the region to contain the new subregion; must be a container | |
573 | * initialized with memory_region_init(). | |
574 | * @offset: the offset relative to @mr where @subregion is added. | |
575 | * @subregion: the subregion to be added. | |
576 | * @priority: used for resolving overlaps; highest priority wins. | |
577 | */ | |
578 | void memory_region_add_subregion_overlap(MemoryRegion *mr, | |
579 | target_phys_addr_t offset, | |
580 | MemoryRegion *subregion, | |
581 | unsigned priority); | |
e34911c4 AK |
582 | |
583 | /** | |
584 | * memory_region_get_ram_addr: Get the ram address associated with a memory | |
585 | * region | |
586 | * | |
dabdf394 | 587 | * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen |
e34911c4 AK |
588 | * code is being reworked. |
589 | */ | |
590 | ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr); | |
591 | ||
093bc2cd AK |
592 | /** |
593 | * memory_region_del_subregion: Remove a subregion. | |
594 | * | |
595 | * Removes a subregion from its container. | |
596 | * | |
597 | * @mr: the container to be updated. | |
598 | * @subregion: the region being removed; must be a current subregion of @mr. | |
599 | */ | |
600 | void memory_region_del_subregion(MemoryRegion *mr, | |
601 | MemoryRegion *subregion); | |
602 | ||
6bba19ba AK |
603 | /* |
604 | * memory_region_set_enabled: dynamically enable or disable a region | |
605 | * | |
606 | * Enables or disables a memory region. A disabled memory region | |
607 | * ignores all accesses to itself and its subregions. It does not | |
608 | * obscure sibling subregions with lower priority - it simply behaves as | |
609 | * if it was removed from the hierarchy. | |
610 | * | |
611 | * Regions default to being enabled. | |
612 | * | |
613 | * @mr: the region to be updated | |
614 | * @enabled: whether to enable or disable the region | |
615 | */ | |
616 | void memory_region_set_enabled(MemoryRegion *mr, bool enabled); | |
617 | ||
2282e1af AK |
618 | /* |
619 | * memory_region_set_address: dynamically update the address of a region | |
620 | * | |
621 | * Dynamically updates the address of a region, relative to its parent. | |
622 | * May be used on regions are currently part of a memory hierarchy. | |
623 | * | |
624 | * @mr: the region to be updated | |
625 | * @addr: new address, relative to parent region | |
626 | */ | |
627 | void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr); | |
628 | ||
4703359e AK |
629 | /* |
630 | * memory_region_set_alias_offset: dynamically update a memory alias's offset | |
631 | * | |
632 | * Dynamically updates the offset into the target region that an alias points | |
633 | * to, as if the fourth argument to memory_region_init_alias() has changed. | |
634 | * | |
635 | * @mr: the #MemoryRegion to be updated; should be an alias. | |
636 | * @offset: the new offset into the target memory region | |
637 | */ | |
638 | void memory_region_set_alias_offset(MemoryRegion *mr, | |
639 | target_phys_addr_t offset); | |
640 | ||
e2177955 AK |
641 | /** |
642 | * memory_region_find: locate a MemoryRegion in an address space | |
643 | * | |
644 | * Locates the first #MemoryRegion within an address space given by | |
645 | * @address_space that overlaps the range given by @addr and @size. | |
646 | * | |
647 | * Returns a #MemoryRegionSection that describes a contiguous overlap. | |
648 | * It will have the following characteristics: | |
649 | * .@offset_within_address_space >= @addr | |
650 | * .@offset_within_address_space + .@size <= @addr + @size | |
651 | * .@size = 0 iff no overlap was found | |
652 | * .@mr is non-%NULL iff an overlap was found | |
653 | * | |
654 | * @address_space: a top-level (i.e. parentless) region that contains | |
655 | * the region to be found | |
656 | * @addr: start of the area within @address_space to be searched | |
657 | * @size: size of the area to be searched | |
658 | */ | |
659 | MemoryRegionSection memory_region_find(MemoryRegion *address_space, | |
660 | target_phys_addr_t addr, uint64_t size); | |
661 | ||
86e775c6 AK |
662 | |
663 | /** | |
664 | * memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory | |
665 | * | |
666 | * Synchronizes the dirty page log for an entire address space. | |
667 | * @address_space: a top-level (i.e. parentless) region that contains the | |
668 | * memory being synchronized | |
669 | */ | |
670 | void memory_global_sync_dirty_bitmap(MemoryRegion *address_space); | |
671 | ||
69ddaf66 ASRJ |
672 | /** |
673 | * memory_region_transaction_begin: Start a transaction. | |
674 | * | |
675 | * During a transaction, changes will be accumulated and made visible | |
dabdf394 | 676 | * only when the transaction ends (is committed). |
4ef4db86 AK |
677 | */ |
678 | void memory_region_transaction_begin(void); | |
69ddaf66 ASRJ |
679 | |
680 | /** | |
681 | * memory_region_transaction_commit: Commit a transaction and make changes | |
682 | * visible to the guest. | |
4ef4db86 AK |
683 | */ |
684 | void memory_region_transaction_commit(void); | |
685 | ||
7664e80c AK |
686 | /** |
687 | * memory_listener_register: register callbacks to be called when memory | |
688 | * sections are mapped or unmapped into an address | |
689 | * space | |
690 | * | |
691 | * @listener: an object containing the callbacks to be called | |
7376e582 | 692 | * @filter: if non-%NULL, only regions in this address space will be observed |
7664e80c | 693 | */ |
7376e582 | 694 | void memory_listener_register(MemoryListener *listener, MemoryRegion *filter); |
7664e80c AK |
695 | |
696 | /** | |
697 | * memory_listener_unregister: undo the effect of memory_listener_register() | |
698 | * | |
699 | * @listener: an object containing the callbacks to be removed | |
700 | */ | |
701 | void memory_listener_unregister(MemoryListener *listener); | |
702 | ||
703 | /** | |
704 | * memory_global_dirty_log_start: begin dirty logging for all regions | |
705 | */ | |
706 | void memory_global_dirty_log_start(void); | |
707 | ||
708 | /** | |
709 | * memory_global_dirty_log_stop: begin dirty logging for all regions | |
710 | */ | |
711 | void memory_global_dirty_log_stop(void); | |
712 | ||
314e2987 BS |
713 | void mtree_info(fprintf_function mon_printf, void *f); |
714 | ||
093bc2cd AK |
715 | #endif |
716 | ||
717 | #endif |