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