]>
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 | ||
1ab4c8ce JQ |
19 | #define DIRTY_MEMORY_VGA 0 |
20 | #define DIRTY_MEMORY_CODE 1 | |
21 | #define DIRTY_MEMORY_MIGRATION 2 | |
22 | #define DIRTY_MEMORY_NUM 3 /* num of dirty bits */ | |
23 | ||
093bc2cd AK |
24 | #include <stdint.h> |
25 | #include <stdbool.h> | |
26 | #include "qemu-common.h" | |
022c62cb | 27 | #include "exec/cpu-common.h" |
ce927ed9 | 28 | #ifndef CONFIG_USER_ONLY |
022c62cb | 29 | #include "exec/hwaddr.h" |
ce927ed9 | 30 | #endif |
cc05c43a | 31 | #include "exec/memattrs.h" |
1de7afc9 | 32 | #include "qemu/queue.h" |
1de7afc9 | 33 | #include "qemu/int128.h" |
06866575 | 34 | #include "qemu/notify.h" |
7f56e740 | 35 | #include "qapi/error.h" |
b4fefef9 | 36 | #include "qom/object.h" |
374f2981 | 37 | #include "qemu/rcu.h" |
093bc2cd | 38 | |
052e87b0 PB |
39 | #define MAX_PHYS_ADDR_SPACE_BITS 62 |
40 | #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) | |
41 | ||
b4fefef9 PC |
42 | #define TYPE_MEMORY_REGION "qemu:memory-region" |
43 | #define MEMORY_REGION(obj) \ | |
44 | OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION) | |
45 | ||
093bc2cd | 46 | typedef struct MemoryRegionOps MemoryRegionOps; |
74901c3b | 47 | typedef struct MemoryRegionMmio MemoryRegionMmio; |
093bc2cd | 48 | |
74901c3b AK |
49 | struct MemoryRegionMmio { |
50 | CPUReadMemoryFunc *read[3]; | |
51 | CPUWriteMemoryFunc *write[3]; | |
52 | }; | |
53 | ||
30951157 AK |
54 | typedef struct IOMMUTLBEntry IOMMUTLBEntry; |
55 | ||
56 | /* See address_space_translate: bit 0 is read, bit 1 is write. */ | |
57 | typedef enum { | |
58 | IOMMU_NONE = 0, | |
59 | IOMMU_RO = 1, | |
60 | IOMMU_WO = 2, | |
61 | IOMMU_RW = 3, | |
62 | } IOMMUAccessFlags; | |
63 | ||
64 | struct IOMMUTLBEntry { | |
65 | AddressSpace *target_as; | |
66 | hwaddr iova; | |
67 | hwaddr translated_addr; | |
68 | hwaddr addr_mask; /* 0xfff = 4k translation */ | |
69 | IOMMUAccessFlags perm; | |
70 | }; | |
71 | ||
cc05c43a PM |
72 | /* New-style MMIO accessors can indicate that the transaction failed. |
73 | * A zero (MEMTX_OK) response means success; anything else is a failure | |
74 | * of some kind. The memory subsystem will bitwise-OR together results | |
75 | * if it is synthesizing an operation from multiple smaller accesses. | |
76 | */ | |
77 | #define MEMTX_OK 0 | |
78 | #define MEMTX_ERROR (1U << 0) /* device returned an error */ | |
79 | #define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */ | |
80 | typedef uint32_t MemTxResult; | |
81 | ||
093bc2cd AK |
82 | /* |
83 | * Memory region callbacks | |
84 | */ | |
85 | struct MemoryRegionOps { | |
86 | /* Read from the memory region. @addr is relative to @mr; @size is | |
87 | * in bytes. */ | |
88 | uint64_t (*read)(void *opaque, | |
a8170e5e | 89 | hwaddr addr, |
093bc2cd AK |
90 | unsigned size); |
91 | /* Write to the memory region. @addr is relative to @mr; @size is | |
92 | * in bytes. */ | |
93 | void (*write)(void *opaque, | |
a8170e5e | 94 | hwaddr addr, |
093bc2cd AK |
95 | uint64_t data, |
96 | unsigned size); | |
97 | ||
cc05c43a PM |
98 | MemTxResult (*read_with_attrs)(void *opaque, |
99 | hwaddr addr, | |
100 | uint64_t *data, | |
101 | unsigned size, | |
102 | MemTxAttrs attrs); | |
103 | MemTxResult (*write_with_attrs)(void *opaque, | |
104 | hwaddr addr, | |
105 | uint64_t data, | |
106 | unsigned size, | |
107 | MemTxAttrs attrs); | |
108 | ||
093bc2cd AK |
109 | enum device_endian endianness; |
110 | /* Guest-visible constraints: */ | |
111 | struct { | |
112 | /* If nonzero, specify bounds on access sizes beyond which a machine | |
113 | * check is thrown. | |
114 | */ | |
115 | unsigned min_access_size; | |
116 | unsigned max_access_size; | |
117 | /* If true, unaligned accesses are supported. Otherwise unaligned | |
118 | * accesses throw machine checks. | |
119 | */ | |
120 | bool unaligned; | |
897fa7cf AK |
121 | /* |
122 | * If present, and returns #false, the transaction is not accepted | |
123 | * by the device (and results in machine dependent behaviour such | |
124 | * as a machine check exception). | |
125 | */ | |
a8170e5e | 126 | bool (*accepts)(void *opaque, hwaddr addr, |
897fa7cf | 127 | unsigned size, bool is_write); |
093bc2cd AK |
128 | } valid; |
129 | /* Internal implementation constraints: */ | |
130 | struct { | |
131 | /* If nonzero, specifies the minimum size implemented. Smaller sizes | |
132 | * will be rounded upwards and a partial result will be returned. | |
133 | */ | |
134 | unsigned min_access_size; | |
135 | /* If nonzero, specifies the maximum size implemented. Larger sizes | |
136 | * will be done as a series of accesses with smaller sizes. | |
137 | */ | |
138 | unsigned max_access_size; | |
139 | /* If true, unaligned accesses are supported. Otherwise all accesses | |
140 | * are converted to (possibly multiple) naturally aligned accesses. | |
141 | */ | |
edc1ba7a | 142 | bool unaligned; |
093bc2cd | 143 | } impl; |
627a0e90 | 144 | |
74901c3b AK |
145 | /* If .read and .write are not present, old_mmio may be used for |
146 | * backwards compatibility with old mmio registration | |
147 | */ | |
148 | const MemoryRegionMmio old_mmio; | |
093bc2cd AK |
149 | }; |
150 | ||
30951157 AK |
151 | typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps; |
152 | ||
153 | struct MemoryRegionIOMMUOps { | |
154 | /* Return a TLB entry that contains a given address. */ | |
8d7b8cb9 | 155 | IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); |
30951157 AK |
156 | }; |
157 | ||
093bc2cd | 158 | typedef struct CoalescedMemoryRange CoalescedMemoryRange; |
3e9d69e7 | 159 | typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; |
093bc2cd AK |
160 | |
161 | struct MemoryRegion { | |
b4fefef9 | 162 | Object parent_obj; |
093bc2cd AK |
163 | /* All fields are private - violators will be prosecuted */ |
164 | const MemoryRegionOps *ops; | |
30951157 | 165 | const MemoryRegionIOMMUOps *iommu_ops; |
093bc2cd | 166 | void *opaque; |
feca4ac1 | 167 | MemoryRegion *container; |
08dafab4 | 168 | Int128 size; |
a8170e5e | 169 | hwaddr addr; |
545e92e0 | 170 | void (*destructor)(MemoryRegion *mr); |
093bc2cd | 171 | ram_addr_t ram_addr; |
a2b257d6 | 172 | uint64_t align; |
b3b00c78 | 173 | bool subpage; |
14a3c10a | 174 | bool terminates; |
5f9a5ea1 | 175 | bool romd_mode; |
8ea9252a | 176 | bool ram; |
e4dc3f59 | 177 | bool skip_dump; |
fb1cd6f9 | 178 | bool readonly; /* For RAM regions */ |
6bba19ba | 179 | bool enabled; |
75c578dc | 180 | bool rom_device; |
1660e72d | 181 | bool warning_printed; /* For reservations */ |
d410515e | 182 | bool flush_coalesced_mmio; |
093bc2cd | 183 | MemoryRegion *alias; |
a8170e5e | 184 | hwaddr alias_offset; |
d33382da | 185 | int32_t priority; |
093bc2cd AK |
186 | bool may_overlap; |
187 | QTAILQ_HEAD(subregions, MemoryRegion) subregions; | |
188 | QTAILQ_ENTRY(MemoryRegion) subregions_link; | |
189 | QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced; | |
302fa283 | 190 | const char *name; |
5a583347 | 191 | uint8_t dirty_log_mask; |
3e9d69e7 AK |
192 | unsigned ioeventfd_nb; |
193 | MemoryRegionIoeventfd *ioeventfds; | |
06866575 | 194 | NotifierList iommu_notify; |
093bc2cd AK |
195 | }; |
196 | ||
c2fc83e8 PB |
197 | /** |
198 | * MemoryListener: callbacks structure for updates to the physical memory map | |
199 | * | |
200 | * Allows a component to adjust to changes in the guest-visible memory map. | |
201 | * Use with memory_listener_register() and memory_listener_unregister(). | |
202 | */ | |
203 | struct MemoryListener { | |
204 | void (*begin)(MemoryListener *listener); | |
205 | void (*commit)(MemoryListener *listener); | |
206 | void (*region_add)(MemoryListener *listener, MemoryRegionSection *section); | |
207 | void (*region_del)(MemoryListener *listener, MemoryRegionSection *section); | |
208 | void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section); | |
209 | void (*log_start)(MemoryListener *listener, MemoryRegionSection *section); | |
210 | void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section); | |
211 | void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section); | |
212 | void (*log_global_start)(MemoryListener *listener); | |
213 | void (*log_global_stop)(MemoryListener *listener); | |
214 | void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section, | |
215 | bool match_data, uint64_t data, EventNotifier *e); | |
216 | void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section, | |
217 | bool match_data, uint64_t data, EventNotifier *e); | |
218 | void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section, | |
219 | hwaddr addr, hwaddr len); | |
220 | void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section, | |
221 | hwaddr addr, hwaddr len); | |
222 | /* Lower = earlier (during add), later (during del) */ | |
223 | unsigned priority; | |
224 | AddressSpace *address_space_filter; | |
225 | QTAILQ_ENTRY(MemoryListener) link; | |
226 | }; | |
227 | ||
9ad2bbc1 AK |
228 | /** |
229 | * AddressSpace: describes a mapping of addresses to #MemoryRegion objects | |
230 | */ | |
231 | struct AddressSpace { | |
232 | /* All fields are private. */ | |
374f2981 | 233 | struct rcu_head rcu; |
7dca8043 | 234 | char *name; |
9ad2bbc1 | 235 | MemoryRegion *root; |
374f2981 PB |
236 | |
237 | /* Accessed via RCU. */ | |
9ad2bbc1 | 238 | struct FlatView *current_map; |
374f2981 | 239 | |
9ad2bbc1 AK |
240 | int ioeventfd_nb; |
241 | struct MemoryRegionIoeventfd *ioeventfds; | |
ac1970fb | 242 | struct AddressSpaceDispatch *dispatch; |
00752703 | 243 | struct AddressSpaceDispatch *next_dispatch; |
89ae337a PB |
244 | MemoryListener dispatch_listener; |
245 | ||
0d673e36 | 246 | QTAILQ_ENTRY(AddressSpace) address_spaces_link; |
9ad2bbc1 AK |
247 | }; |
248 | ||
e2177955 AK |
249 | /** |
250 | * MemoryRegionSection: describes a fragment of a #MemoryRegion | |
251 | * | |
252 | * @mr: the region, or %NULL if empty | |
7664e80c | 253 | * @address_space: the address space the region is mapped in |
e2177955 AK |
254 | * @offset_within_region: the beginning of the section, relative to @mr's start |
255 | * @size: the size of the section; will not exceed @mr's boundaries | |
256 | * @offset_within_address_space: the address of the first byte of the section | |
257 | * relative to the region's address space | |
7a8499e8 | 258 | * @readonly: writes to this section are ignored |
e2177955 AK |
259 | */ |
260 | struct MemoryRegionSection { | |
261 | MemoryRegion *mr; | |
f6790af6 | 262 | AddressSpace *address_space; |
a8170e5e | 263 | hwaddr offset_within_region; |
052e87b0 | 264 | Int128 size; |
a8170e5e | 265 | hwaddr offset_within_address_space; |
7a8499e8 | 266 | bool readonly; |
e2177955 AK |
267 | }; |
268 | ||
093bc2cd AK |
269 | /** |
270 | * memory_region_init: Initialize a memory region | |
271 | * | |
69ddaf66 | 272 | * The region typically acts as a container for other memory regions. Use |
093bc2cd AK |
273 | * memory_region_add_subregion() to add subregions. |
274 | * | |
275 | * @mr: the #MemoryRegion to be initialized | |
2c9b15ca | 276 | * @owner: the object that tracks the region's reference count |
093bc2cd AK |
277 | * @name: used for debugging; not visible to the user or ABI |
278 | * @size: size of the region; any subregions beyond this size will be clipped | |
279 | */ | |
280 | void memory_region_init(MemoryRegion *mr, | |
2c9b15ca | 281 | struct Object *owner, |
093bc2cd AK |
282 | const char *name, |
283 | uint64_t size); | |
46637be2 PB |
284 | |
285 | /** | |
286 | * memory_region_ref: Add 1 to a memory region's reference count | |
287 | * | |
288 | * Whenever memory regions are accessed outside the BQL, they need to be | |
289 | * preserved against hot-unplug. MemoryRegions actually do not have their | |
290 | * own reference count; they piggyback on a QOM object, their "owner". | |
291 | * This function adds a reference to the owner. | |
292 | * | |
293 | * All MemoryRegions must have an owner if they can disappear, even if the | |
294 | * device they belong to operates exclusively under the BQL. This is because | |
295 | * the region could be returned at any time by memory_region_find, and this | |
296 | * is usually under guest control. | |
297 | * | |
298 | * @mr: the #MemoryRegion | |
299 | */ | |
300 | void memory_region_ref(MemoryRegion *mr); | |
301 | ||
302 | /** | |
303 | * memory_region_unref: Remove 1 to a memory region's reference count | |
304 | * | |
305 | * Whenever memory regions are accessed outside the BQL, they need to be | |
306 | * preserved against hot-unplug. MemoryRegions actually do not have their | |
307 | * own reference count; they piggyback on a QOM object, their "owner". | |
308 | * This function removes a reference to the owner and possibly destroys it. | |
309 | * | |
310 | * @mr: the #MemoryRegion | |
311 | */ | |
312 | void memory_region_unref(MemoryRegion *mr); | |
313 | ||
093bc2cd AK |
314 | /** |
315 | * memory_region_init_io: Initialize an I/O memory region. | |
316 | * | |
69ddaf66 | 317 | * Accesses into the region will cause the callbacks in @ops to be called. |
093bc2cd AK |
318 | * if @size is nonzero, subregions will be clipped to @size. |
319 | * | |
320 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 321 | * @owner: the object that tracks the region's reference count |
093bc2cd AK |
322 | * @ops: a structure containing read and write callbacks to be used when |
323 | * I/O is performed on the region. | |
324 | * @opaque: passed to to the read and write callbacks of the @ops structure. | |
325 | * @name: used for debugging; not visible to the user or ABI | |
326 | * @size: size of the region. | |
327 | */ | |
328 | void memory_region_init_io(MemoryRegion *mr, | |
2c9b15ca | 329 | struct Object *owner, |
093bc2cd AK |
330 | const MemoryRegionOps *ops, |
331 | void *opaque, | |
332 | const char *name, | |
333 | uint64_t size); | |
334 | ||
335 | /** | |
336 | * memory_region_init_ram: Initialize RAM memory region. Accesses into the | |
69ddaf66 | 337 | * region will modify memory directly. |
093bc2cd AK |
338 | * |
339 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 340 | * @owner: the object that tracks the region's reference count |
c5705a77 | 341 | * @name: the name of the region. |
093bc2cd | 342 | * @size: size of the region. |
49946538 | 343 | * @errp: pointer to Error*, to store an error if it happens. |
093bc2cd AK |
344 | */ |
345 | void memory_region_init_ram(MemoryRegion *mr, | |
2c9b15ca | 346 | struct Object *owner, |
093bc2cd | 347 | const char *name, |
49946538 HT |
348 | uint64_t size, |
349 | Error **errp); | |
093bc2cd | 350 | |
60786ef3 MT |
351 | /** |
352 | * memory_region_init_resizeable_ram: Initialize memory region with resizeable | |
353 | * RAM. Accesses into the region will | |
354 | * modify memory directly. Only an initial | |
355 | * portion of this RAM is actually used. | |
356 | * The used size can change across reboots. | |
357 | * | |
358 | * @mr: the #MemoryRegion to be initialized. | |
359 | * @owner: the object that tracks the region's reference count | |
360 | * @name: the name of the region. | |
361 | * @size: used size of the region. | |
362 | * @max_size: max size of the region. | |
363 | * @resized: callback to notify owner about used size change. | |
364 | * @errp: pointer to Error*, to store an error if it happens. | |
365 | */ | |
366 | void memory_region_init_resizeable_ram(MemoryRegion *mr, | |
367 | struct Object *owner, | |
368 | const char *name, | |
369 | uint64_t size, | |
370 | uint64_t max_size, | |
371 | void (*resized)(const char*, | |
372 | uint64_t length, | |
373 | void *host), | |
374 | Error **errp); | |
0b183fc8 PB |
375 | #ifdef __linux__ |
376 | /** | |
377 | * memory_region_init_ram_from_file: Initialize RAM memory region with a | |
378 | * mmap-ed backend. | |
379 | * | |
380 | * @mr: the #MemoryRegion to be initialized. | |
381 | * @owner: the object that tracks the region's reference count | |
382 | * @name: the name of the region. | |
383 | * @size: size of the region. | |
dbcb8981 | 384 | * @share: %true if memory must be mmaped with the MAP_SHARED flag |
0b183fc8 | 385 | * @path: the path in which to allocate the RAM. |
7f56e740 | 386 | * @errp: pointer to Error*, to store an error if it happens. |
0b183fc8 PB |
387 | */ |
388 | void memory_region_init_ram_from_file(MemoryRegion *mr, | |
389 | struct Object *owner, | |
390 | const char *name, | |
391 | uint64_t size, | |
dbcb8981 | 392 | bool share, |
7f56e740 PB |
393 | const char *path, |
394 | Error **errp); | |
0b183fc8 PB |
395 | #endif |
396 | ||
093bc2cd | 397 | /** |
1a7e8cae BZ |
398 | * memory_region_init_ram_ptr: Initialize RAM memory region from a |
399 | * user-provided pointer. Accesses into the | |
400 | * region will modify memory directly. | |
093bc2cd AK |
401 | * |
402 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 403 | * @owner: the object that tracks the region's reference count |
c5705a77 | 404 | * @name: the name of the region. |
093bc2cd AK |
405 | * @size: size of the region. |
406 | * @ptr: memory to be mapped; must contain at least @size bytes. | |
407 | */ | |
408 | void memory_region_init_ram_ptr(MemoryRegion *mr, | |
2c9b15ca | 409 | struct Object *owner, |
093bc2cd AK |
410 | const char *name, |
411 | uint64_t size, | |
412 | void *ptr); | |
413 | ||
414 | /** | |
415 | * memory_region_init_alias: Initialize a memory region that aliases all or a | |
416 | * part of another memory region. | |
417 | * | |
418 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 419 | * @owner: the object that tracks the region's reference count |
093bc2cd AK |
420 | * @name: used for debugging; not visible to the user or ABI |
421 | * @orig: the region to be referenced; @mr will be equivalent to | |
422 | * @orig between @offset and @offset + @size - 1. | |
423 | * @offset: start of the section in @orig to be referenced. | |
424 | * @size: size of the region. | |
425 | */ | |
426 | void memory_region_init_alias(MemoryRegion *mr, | |
2c9b15ca | 427 | struct Object *owner, |
093bc2cd AK |
428 | const char *name, |
429 | MemoryRegion *orig, | |
a8170e5e | 430 | hwaddr offset, |
093bc2cd | 431 | uint64_t size); |
d0a9b5bc AK |
432 | |
433 | /** | |
434 | * memory_region_init_rom_device: Initialize a ROM memory region. Writes are | |
435 | * handled via callbacks. | |
436 | * | |
437 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 438 | * @owner: the object that tracks the region's reference count |
d0a9b5bc | 439 | * @ops: callbacks for write access handling. |
c5705a77 | 440 | * @name: the name of the region. |
d0a9b5bc | 441 | * @size: size of the region. |
33e0eb52 | 442 | * @errp: pointer to Error*, to store an error if it happens. |
d0a9b5bc AK |
443 | */ |
444 | void memory_region_init_rom_device(MemoryRegion *mr, | |
2c9b15ca | 445 | struct Object *owner, |
d0a9b5bc | 446 | const MemoryRegionOps *ops, |
75f5941c | 447 | void *opaque, |
d0a9b5bc | 448 | const char *name, |
33e0eb52 HT |
449 | uint64_t size, |
450 | Error **errp); | |
d0a9b5bc | 451 | |
1660e72d JK |
452 | /** |
453 | * memory_region_init_reservation: Initialize a memory region that reserves | |
454 | * I/O space. | |
455 | * | |
456 | * A reservation region primariy serves debugging purposes. It claims I/O | |
457 | * space that is not supposed to be handled by QEMU itself. Any access via | |
458 | * the memory API will cause an abort(). | |
459 | * | |
460 | * @mr: the #MemoryRegion to be initialized | |
2c9b15ca | 461 | * @owner: the object that tracks the region's reference count |
1660e72d JK |
462 | * @name: used for debugging; not visible to the user or ABI |
463 | * @size: size of the region. | |
464 | */ | |
465 | void memory_region_init_reservation(MemoryRegion *mr, | |
2c9b15ca | 466 | struct Object *owner, |
1660e72d JK |
467 | const char *name, |
468 | uint64_t size); | |
30951157 AK |
469 | |
470 | /** | |
471 | * memory_region_init_iommu: Initialize a memory region that translates | |
472 | * addresses | |
473 | * | |
474 | * An IOMMU region translates addresses and forwards accesses to a target | |
475 | * memory region. | |
476 | * | |
477 | * @mr: the #MemoryRegion to be initialized | |
2c9b15ca | 478 | * @owner: the object that tracks the region's reference count |
30951157 AK |
479 | * @ops: a function that translates addresses into the @target region |
480 | * @name: used for debugging; not visible to the user or ABI | |
481 | * @size: size of the region. | |
482 | */ | |
483 | void memory_region_init_iommu(MemoryRegion *mr, | |
2c9b15ca | 484 | struct Object *owner, |
30951157 AK |
485 | const MemoryRegionIOMMUOps *ops, |
486 | const char *name, | |
487 | uint64_t size); | |
488 | ||
803c0816 PB |
489 | /** |
490 | * memory_region_owner: get a memory region's owner. | |
491 | * | |
492 | * @mr: the memory region being queried. | |
493 | */ | |
494 | struct Object *memory_region_owner(MemoryRegion *mr); | |
495 | ||
093bc2cd AK |
496 | /** |
497 | * memory_region_size: get a memory region's size. | |
498 | * | |
499 | * @mr: the memory region being queried. | |
500 | */ | |
501 | uint64_t memory_region_size(MemoryRegion *mr); | |
502 | ||
8ea9252a AK |
503 | /** |
504 | * memory_region_is_ram: check whether a memory region is random access | |
505 | * | |
506 | * Returns %true is a memory region is random access. | |
507 | * | |
508 | * @mr: the memory region being queried | |
509 | */ | |
510 | bool memory_region_is_ram(MemoryRegion *mr); | |
511 | ||
e4dc3f59 ND |
512 | /** |
513 | * memory_region_is_skip_dump: check whether a memory region should not be | |
514 | * dumped | |
515 | * | |
516 | * Returns %true is a memory region should not be dumped(e.g. VFIO BAR MMAP). | |
517 | * | |
518 | * @mr: the memory region being queried | |
519 | */ | |
520 | bool memory_region_is_skip_dump(MemoryRegion *mr); | |
521 | ||
522 | /** | |
523 | * memory_region_set_skip_dump: Set skip_dump flag, dump will ignore this memory | |
524 | * region | |
525 | * | |
526 | * @mr: the memory region being queried | |
527 | */ | |
528 | void memory_region_set_skip_dump(MemoryRegion *mr); | |
529 | ||
fd062573 | 530 | /** |
5f9a5ea1 | 531 | * memory_region_is_romd: check whether a memory region is in ROMD mode |
fd062573 | 532 | * |
5f9a5ea1 | 533 | * Returns %true if a memory region is a ROM device and currently set to allow |
fd062573 BS |
534 | * direct reads. |
535 | * | |
536 | * @mr: the memory region being queried | |
537 | */ | |
538 | static inline bool memory_region_is_romd(MemoryRegion *mr) | |
539 | { | |
5f9a5ea1 | 540 | return mr->rom_device && mr->romd_mode; |
fd062573 BS |
541 | } |
542 | ||
30951157 AK |
543 | /** |
544 | * memory_region_is_iommu: check whether a memory region is an iommu | |
545 | * | |
546 | * Returns %true is a memory region is an iommu. | |
547 | * | |
548 | * @mr: the memory region being queried | |
549 | */ | |
550 | bool memory_region_is_iommu(MemoryRegion *mr); | |
551 | ||
06866575 DG |
552 | /** |
553 | * memory_region_notify_iommu: notify a change in an IOMMU translation entry. | |
554 | * | |
555 | * @mr: the memory region that was changed | |
556 | * @entry: the new entry in the IOMMU translation table. The entry | |
557 | * replaces all old entries for the same virtual I/O address range. | |
558 | * Deleted entries have .@perm == 0. | |
559 | */ | |
560 | void memory_region_notify_iommu(MemoryRegion *mr, | |
561 | IOMMUTLBEntry entry); | |
562 | ||
563 | /** | |
564 | * memory_region_register_iommu_notifier: register a notifier for changes to | |
565 | * IOMMU translation entries. | |
566 | * | |
567 | * @mr: the memory region to observe | |
568 | * @n: the notifier to be added; the notifier receives a pointer to an | |
569 | * #IOMMUTLBEntry as the opaque value; the pointer ceases to be | |
570 | * valid on exit from the notifier. | |
571 | */ | |
572 | void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n); | |
573 | ||
574 | /** | |
575 | * memory_region_unregister_iommu_notifier: unregister a notifier for | |
576 | * changes to IOMMU translation entries. | |
577 | * | |
578 | * @n: the notifier to be removed. | |
579 | */ | |
580 | void memory_region_unregister_iommu_notifier(Notifier *n); | |
581 | ||
8991c79b AK |
582 | /** |
583 | * memory_region_name: get a memory region's name | |
584 | * | |
585 | * Returns the string that was used to initialize the memory region. | |
586 | * | |
587 | * @mr: the memory region being queried | |
588 | */ | |
5d546d4b | 589 | const char *memory_region_name(const MemoryRegion *mr); |
8991c79b | 590 | |
55043ba3 AK |
591 | /** |
592 | * memory_region_is_logging: return whether a memory region is logging writes | |
593 | * | |
594 | * Returns %true if the memory region is logging writes | |
595 | * | |
596 | * @mr: the memory region being queried | |
597 | */ | |
598 | bool memory_region_is_logging(MemoryRegion *mr); | |
599 | ||
ce7923da AK |
600 | /** |
601 | * memory_region_is_rom: check whether a memory region is ROM | |
602 | * | |
603 | * Returns %true is a memory region is read-only memory. | |
604 | * | |
605 | * @mr: the memory region being queried | |
606 | */ | |
607 | bool memory_region_is_rom(MemoryRegion *mr); | |
608 | ||
a35ba7be PB |
609 | /** |
610 | * memory_region_get_fd: Get a file descriptor backing a RAM memory region. | |
611 | * | |
612 | * Returns a file descriptor backing a file-based RAM memory region, | |
613 | * or -1 if the region is not a file-based RAM memory region. | |
614 | * | |
615 | * @mr: the RAM or alias memory region being queried. | |
616 | */ | |
617 | int memory_region_get_fd(MemoryRegion *mr); | |
618 | ||
093bc2cd AK |
619 | /** |
620 | * memory_region_get_ram_ptr: Get a pointer into a RAM memory region. | |
621 | * | |
622 | * Returns a host pointer to a RAM memory region (created with | |
623 | * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with | |
624 | * care. | |
625 | * | |
626 | * @mr: the memory region being queried. | |
627 | */ | |
628 | void *memory_region_get_ram_ptr(MemoryRegion *mr); | |
629 | ||
093bc2cd AK |
630 | /** |
631 | * memory_region_set_log: Turn dirty logging on or off for a region. | |
632 | * | |
633 | * Turns dirty logging on or off for a specified client (display, migration). | |
634 | * Only meaningful for RAM regions. | |
635 | * | |
636 | * @mr: the memory region being updated. | |
637 | * @log: whether dirty logging is to be enabled or disabled. | |
638 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
639 | * %DIRTY_MEMORY_VGA. | |
640 | */ | |
641 | void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client); | |
642 | ||
643 | /** | |
cd7a45c9 BS |
644 | * memory_region_get_dirty: Check whether a range of bytes is dirty |
645 | * for a specified client. | |
093bc2cd | 646 | * |
cd7a45c9 | 647 | * Checks whether a range of bytes has been written to since the last |
093bc2cd AK |
648 | * call to memory_region_reset_dirty() with the same @client. Dirty logging |
649 | * must be enabled. | |
650 | * | |
651 | * @mr: the memory region being queried. | |
652 | * @addr: the address (relative to the start of the region) being queried. | |
cd7a45c9 | 653 | * @size: the size of the range being queried. |
093bc2cd AK |
654 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or |
655 | * %DIRTY_MEMORY_VGA. | |
656 | */ | |
a8170e5e AK |
657 | bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr, |
658 | hwaddr size, unsigned client); | |
093bc2cd AK |
659 | |
660 | /** | |
fd4aa979 | 661 | * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region. |
093bc2cd | 662 | * |
fd4aa979 BS |
663 | * Marks a range of bytes as dirty, after it has been dirtied outside |
664 | * guest code. | |
093bc2cd | 665 | * |
fd4aa979 | 666 | * @mr: the memory region being dirtied. |
093bc2cd | 667 | * @addr: the address (relative to the start of the region) being dirtied. |
fd4aa979 | 668 | * @size: size of the range being dirtied. |
093bc2cd | 669 | */ |
a8170e5e AK |
670 | void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, |
671 | hwaddr size); | |
093bc2cd | 672 | |
6c279db8 JQ |
673 | /** |
674 | * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty | |
675 | * for a specified client. It clears them. | |
676 | * | |
677 | * Checks whether a range of bytes has been written to since the last | |
678 | * call to memory_region_reset_dirty() with the same @client. Dirty logging | |
679 | * must be enabled. | |
680 | * | |
681 | * @mr: the memory region being queried. | |
682 | * @addr: the address (relative to the start of the region) being queried. | |
683 | * @size: the size of the range being queried. | |
684 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
685 | * %DIRTY_MEMORY_VGA. | |
686 | */ | |
687 | bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, | |
688 | hwaddr size, unsigned client); | |
093bc2cd AK |
689 | /** |
690 | * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with | |
691 | * any external TLBs (e.g. kvm) | |
692 | * | |
693 | * Flushes dirty information from accelerators such as kvm and vhost-net | |
694 | * and makes it available to users of the memory API. | |
695 | * | |
696 | * @mr: the region being flushed. | |
697 | */ | |
698 | void memory_region_sync_dirty_bitmap(MemoryRegion *mr); | |
699 | ||
700 | /** | |
701 | * memory_region_reset_dirty: Mark a range of pages as clean, for a specified | |
702 | * client. | |
703 | * | |
704 | * Marks a range of pages as no longer dirty. | |
705 | * | |
706 | * @mr: the region being updated. | |
707 | * @addr: the start of the subrange being cleaned. | |
708 | * @size: the size of the subrange being cleaned. | |
709 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
710 | * %DIRTY_MEMORY_VGA. | |
711 | */ | |
a8170e5e AK |
712 | void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, |
713 | hwaddr size, unsigned client); | |
093bc2cd AK |
714 | |
715 | /** | |
716 | * memory_region_set_readonly: Turn a memory region read-only (or read-write) | |
717 | * | |
718 | * Allows a memory region to be marked as read-only (turning it into a ROM). | |
719 | * only useful on RAM regions. | |
720 | * | |
721 | * @mr: the region being updated. | |
722 | * @readonly: whether rhe region is to be ROM or RAM. | |
723 | */ | |
724 | void memory_region_set_readonly(MemoryRegion *mr, bool readonly); | |
725 | ||
d0a9b5bc | 726 | /** |
5f9a5ea1 | 727 | * memory_region_rom_device_set_romd: enable/disable ROMD mode |
d0a9b5bc AK |
728 | * |
729 | * Allows a ROM device (initialized with memory_region_init_rom_device() to | |
5f9a5ea1 JK |
730 | * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the |
731 | * device is mapped to guest memory and satisfies read access directly. | |
732 | * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function. | |
733 | * Writes are always handled by the #MemoryRegion.write function. | |
d0a9b5bc AK |
734 | * |
735 | * @mr: the memory region to be updated | |
5f9a5ea1 | 736 | * @romd_mode: %true to put the region into ROMD mode |
d0a9b5bc | 737 | */ |
5f9a5ea1 | 738 | void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode); |
d0a9b5bc | 739 | |
093bc2cd AK |
740 | /** |
741 | * memory_region_set_coalescing: Enable memory coalescing for the region. | |
742 | * | |
743 | * Enabled writes to a region to be queued for later processing. MMIO ->write | |
744 | * callbacks may be delayed until a non-coalesced MMIO is issued. | |
745 | * Only useful for IO regions. Roughly similar to write-combining hardware. | |
746 | * | |
747 | * @mr: the memory region to be write coalesced | |
748 | */ | |
749 | void memory_region_set_coalescing(MemoryRegion *mr); | |
750 | ||
751 | /** | |
752 | * memory_region_add_coalescing: Enable memory coalescing for a sub-range of | |
753 | * a region. | |
754 | * | |
755 | * Like memory_region_set_coalescing(), but works on a sub-range of a region. | |
756 | * Multiple calls can be issued coalesced disjoint ranges. | |
757 | * | |
758 | * @mr: the memory region to be updated. | |
759 | * @offset: the start of the range within the region to be coalesced. | |
760 | * @size: the size of the subrange to be coalesced. | |
761 | */ | |
762 | void memory_region_add_coalescing(MemoryRegion *mr, | |
a8170e5e | 763 | hwaddr offset, |
093bc2cd AK |
764 | uint64_t size); |
765 | ||
766 | /** | |
767 | * memory_region_clear_coalescing: Disable MMIO coalescing for the region. | |
768 | * | |
769 | * Disables any coalescing caused by memory_region_set_coalescing() or | |
770 | * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory | |
771 | * hardware. | |
772 | * | |
773 | * @mr: the memory region to be updated. | |
774 | */ | |
775 | void memory_region_clear_coalescing(MemoryRegion *mr); | |
776 | ||
d410515e JK |
777 | /** |
778 | * memory_region_set_flush_coalesced: Enforce memory coalescing flush before | |
779 | * accesses. | |
780 | * | |
781 | * Ensure that pending coalesced MMIO request are flushed before the memory | |
782 | * region is accessed. This property is automatically enabled for all regions | |
783 | * passed to memory_region_set_coalescing() and memory_region_add_coalescing(). | |
784 | * | |
785 | * @mr: the memory region to be updated. | |
786 | */ | |
787 | void memory_region_set_flush_coalesced(MemoryRegion *mr); | |
788 | ||
789 | /** | |
790 | * memory_region_clear_flush_coalesced: Disable memory coalescing flush before | |
791 | * accesses. | |
792 | * | |
793 | * Clear the automatic coalesced MMIO flushing enabled via | |
794 | * memory_region_set_flush_coalesced. Note that this service has no effect on | |
795 | * memory regions that have MMIO coalescing enabled for themselves. For them, | |
796 | * automatic flushing will stop once coalescing is disabled. | |
797 | * | |
798 | * @mr: the memory region to be updated. | |
799 | */ | |
800 | void memory_region_clear_flush_coalesced(MemoryRegion *mr); | |
801 | ||
3e9d69e7 AK |
802 | /** |
803 | * memory_region_add_eventfd: Request an eventfd to be triggered when a word | |
804 | * is written to a location. | |
805 | * | |
806 | * Marks a word in an IO region (initialized with memory_region_init_io()) | |
807 | * as a trigger for an eventfd event. The I/O callback will not be called. | |
69ddaf66 | 808 | * The caller must be prepared to handle failure (that is, take the required |
3e9d69e7 AK |
809 | * action if the callback _is_ called). |
810 | * | |
811 | * @mr: the memory region being updated. | |
812 | * @addr: the address within @mr that is to be monitored | |
813 | * @size: the size of the access to trigger the eventfd | |
814 | * @match_data: whether to match against @data, instead of just @addr | |
815 | * @data: the data to match against the guest write | |
816 | * @fd: the eventfd to be triggered when @addr, @size, and @data all match. | |
817 | **/ | |
818 | void memory_region_add_eventfd(MemoryRegion *mr, | |
a8170e5e | 819 | hwaddr addr, |
3e9d69e7 AK |
820 | unsigned size, |
821 | bool match_data, | |
822 | uint64_t data, | |
753d5e14 | 823 | EventNotifier *e); |
3e9d69e7 AK |
824 | |
825 | /** | |
69ddaf66 | 826 | * memory_region_del_eventfd: Cancel an eventfd. |
3e9d69e7 | 827 | * |
69ddaf66 ASRJ |
828 | * Cancels an eventfd trigger requested by a previous |
829 | * memory_region_add_eventfd() call. | |
3e9d69e7 AK |
830 | * |
831 | * @mr: the memory region being updated. | |
832 | * @addr: the address within @mr that is to be monitored | |
833 | * @size: the size of the access to trigger the eventfd | |
834 | * @match_data: whether to match against @data, instead of just @addr | |
835 | * @data: the data to match against the guest write | |
836 | * @fd: the eventfd to be triggered when @addr, @size, and @data all match. | |
837 | */ | |
838 | void memory_region_del_eventfd(MemoryRegion *mr, | |
a8170e5e | 839 | hwaddr addr, |
3e9d69e7 AK |
840 | unsigned size, |
841 | bool match_data, | |
842 | uint64_t data, | |
753d5e14 PB |
843 | EventNotifier *e); |
844 | ||
093bc2cd | 845 | /** |
69ddaf66 | 846 | * memory_region_add_subregion: Add a subregion to a container. |
093bc2cd | 847 | * |
69ddaf66 | 848 | * Adds a subregion at @offset. The subregion may not overlap with other |
093bc2cd AK |
849 | * subregions (except for those explicitly marked as overlapping). A region |
850 | * may only be added once as a subregion (unless removed with | |
851 | * memory_region_del_subregion()); use memory_region_init_alias() if you | |
852 | * want a region to be a subregion in multiple locations. | |
853 | * | |
854 | * @mr: the region to contain the new subregion; must be a container | |
855 | * initialized with memory_region_init(). | |
856 | * @offset: the offset relative to @mr where @subregion is added. | |
857 | * @subregion: the subregion to be added. | |
858 | */ | |
859 | void memory_region_add_subregion(MemoryRegion *mr, | |
a8170e5e | 860 | hwaddr offset, |
093bc2cd AK |
861 | MemoryRegion *subregion); |
862 | /** | |
1a7e8cae BZ |
863 | * memory_region_add_subregion_overlap: Add a subregion to a container |
864 | * with overlap. | |
093bc2cd | 865 | * |
69ddaf66 | 866 | * Adds a subregion at @offset. The subregion may overlap with other |
093bc2cd AK |
867 | * subregions. Conflicts are resolved by having a higher @priority hide a |
868 | * lower @priority. Subregions without priority are taken as @priority 0. | |
869 | * A region may only be added once as a subregion (unless removed with | |
870 | * memory_region_del_subregion()); use memory_region_init_alias() if you | |
871 | * want a region to be a subregion in multiple locations. | |
872 | * | |
873 | * @mr: the region to contain the new subregion; must be a container | |
874 | * initialized with memory_region_init(). | |
875 | * @offset: the offset relative to @mr where @subregion is added. | |
876 | * @subregion: the subregion to be added. | |
877 | * @priority: used for resolving overlaps; highest priority wins. | |
878 | */ | |
879 | void memory_region_add_subregion_overlap(MemoryRegion *mr, | |
a8170e5e | 880 | hwaddr offset, |
093bc2cd | 881 | MemoryRegion *subregion, |
a1ff8ae0 | 882 | int priority); |
e34911c4 AK |
883 | |
884 | /** | |
885 | * memory_region_get_ram_addr: Get the ram address associated with a memory | |
886 | * region | |
887 | * | |
dabdf394 | 888 | * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen |
e34911c4 AK |
889 | * code is being reworked. |
890 | */ | |
891 | ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr); | |
892 | ||
a2b257d6 | 893 | uint64_t memory_region_get_alignment(const MemoryRegion *mr); |
093bc2cd AK |
894 | /** |
895 | * memory_region_del_subregion: Remove a subregion. | |
896 | * | |
897 | * Removes a subregion from its container. | |
898 | * | |
899 | * @mr: the container to be updated. | |
900 | * @subregion: the region being removed; must be a current subregion of @mr. | |
901 | */ | |
902 | void memory_region_del_subregion(MemoryRegion *mr, | |
903 | MemoryRegion *subregion); | |
904 | ||
6bba19ba AK |
905 | /* |
906 | * memory_region_set_enabled: dynamically enable or disable a region | |
907 | * | |
908 | * Enables or disables a memory region. A disabled memory region | |
909 | * ignores all accesses to itself and its subregions. It does not | |
910 | * obscure sibling subregions with lower priority - it simply behaves as | |
911 | * if it was removed from the hierarchy. | |
912 | * | |
913 | * Regions default to being enabled. | |
914 | * | |
915 | * @mr: the region to be updated | |
916 | * @enabled: whether to enable or disable the region | |
917 | */ | |
918 | void memory_region_set_enabled(MemoryRegion *mr, bool enabled); | |
919 | ||
2282e1af AK |
920 | /* |
921 | * memory_region_set_address: dynamically update the address of a region | |
922 | * | |
feca4ac1 | 923 | * Dynamically updates the address of a region, relative to its container. |
2282e1af AK |
924 | * May be used on regions are currently part of a memory hierarchy. |
925 | * | |
926 | * @mr: the region to be updated | |
feca4ac1 | 927 | * @addr: new address, relative to container region |
2282e1af | 928 | */ |
a8170e5e | 929 | void memory_region_set_address(MemoryRegion *mr, hwaddr addr); |
2282e1af | 930 | |
e7af4c67 MT |
931 | /* |
932 | * memory_region_set_size: dynamically update the size of a region. | |
933 | * | |
934 | * Dynamically updates the size of a region. | |
935 | * | |
936 | * @mr: the region to be updated | |
937 | * @size: used size of the region. | |
938 | */ | |
939 | void memory_region_set_size(MemoryRegion *mr, uint64_t size); | |
940 | ||
4703359e AK |
941 | /* |
942 | * memory_region_set_alias_offset: dynamically update a memory alias's offset | |
943 | * | |
944 | * Dynamically updates the offset into the target region that an alias points | |
945 | * to, as if the fourth argument to memory_region_init_alias() has changed. | |
946 | * | |
947 | * @mr: the #MemoryRegion to be updated; should be an alias. | |
948 | * @offset: the new offset into the target memory region | |
949 | */ | |
950 | void memory_region_set_alias_offset(MemoryRegion *mr, | |
a8170e5e | 951 | hwaddr offset); |
4703359e | 952 | |
3ce10901 | 953 | /** |
feca4ac1 PB |
954 | * memory_region_present: checks if an address relative to a @container |
955 | * translates into #MemoryRegion within @container | |
3ce10901 | 956 | * |
feca4ac1 | 957 | * Answer whether a #MemoryRegion within @container covers the address |
3ce10901 PB |
958 | * @addr. |
959 | * | |
feca4ac1 PB |
960 | * @container: a #MemoryRegion within which @addr is a relative address |
961 | * @addr: the area within @container to be searched | |
3ce10901 | 962 | */ |
feca4ac1 | 963 | bool memory_region_present(MemoryRegion *container, hwaddr addr); |
3ce10901 | 964 | |
eed2bacf IM |
965 | /** |
966 | * memory_region_is_mapped: returns true if #MemoryRegion is mapped | |
967 | * into any address space. | |
968 | * | |
969 | * @mr: a #MemoryRegion which should be checked if it's mapped | |
970 | */ | |
971 | bool memory_region_is_mapped(MemoryRegion *mr); | |
972 | ||
e2177955 | 973 | /** |
73034e9e PB |
974 | * memory_region_find: translate an address/size relative to a |
975 | * MemoryRegion into a #MemoryRegionSection. | |
e2177955 | 976 | * |
73034e9e PB |
977 | * Locates the first #MemoryRegion within @mr that overlaps the range |
978 | * given by @addr and @size. | |
e2177955 AK |
979 | * |
980 | * Returns a #MemoryRegionSection that describes a contiguous overlap. | |
981 | * It will have the following characteristics: | |
e2177955 AK |
982 | * .@size = 0 iff no overlap was found |
983 | * .@mr is non-%NULL iff an overlap was found | |
984 | * | |
73034e9e PB |
985 | * Remember that in the return value the @offset_within_region is |
986 | * relative to the returned region (in the .@mr field), not to the | |
987 | * @mr argument. | |
988 | * | |
989 | * Similarly, the .@offset_within_address_space is relative to the | |
990 | * address space that contains both regions, the passed and the | |
991 | * returned one. However, in the special case where the @mr argument | |
feca4ac1 | 992 | * has no container (and thus is the root of the address space), the |
73034e9e PB |
993 | * following will hold: |
994 | * .@offset_within_address_space >= @addr | |
995 | * .@offset_within_address_space + .@size <= @addr + @size | |
996 | * | |
997 | * @mr: a MemoryRegion within which @addr is a relative address | |
998 | * @addr: start of the area within @as to be searched | |
e2177955 AK |
999 | * @size: size of the area to be searched |
1000 | */ | |
73034e9e | 1001 | MemoryRegionSection memory_region_find(MemoryRegion *mr, |
a8170e5e | 1002 | hwaddr addr, uint64_t size); |
e2177955 | 1003 | |
86e775c6 | 1004 | /** |
1d671369 | 1005 | * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory |
86e775c6 AK |
1006 | * |
1007 | * Synchronizes the dirty page log for an entire address space. | |
1d671369 | 1008 | * @as: the address space that contains the memory being synchronized |
86e775c6 | 1009 | */ |
1d671369 | 1010 | void address_space_sync_dirty_bitmap(AddressSpace *as); |
86e775c6 | 1011 | |
69ddaf66 ASRJ |
1012 | /** |
1013 | * memory_region_transaction_begin: Start a transaction. | |
1014 | * | |
1015 | * During a transaction, changes will be accumulated and made visible | |
dabdf394 | 1016 | * only when the transaction ends (is committed). |
4ef4db86 AK |
1017 | */ |
1018 | void memory_region_transaction_begin(void); | |
69ddaf66 ASRJ |
1019 | |
1020 | /** | |
1021 | * memory_region_transaction_commit: Commit a transaction and make changes | |
1022 | * visible to the guest. | |
4ef4db86 AK |
1023 | */ |
1024 | void memory_region_transaction_commit(void); | |
1025 | ||
7664e80c AK |
1026 | /** |
1027 | * memory_listener_register: register callbacks to be called when memory | |
1028 | * sections are mapped or unmapped into an address | |
1029 | * space | |
1030 | * | |
1031 | * @listener: an object containing the callbacks to be called | |
7376e582 | 1032 | * @filter: if non-%NULL, only regions in this address space will be observed |
7664e80c | 1033 | */ |
f6790af6 | 1034 | void memory_listener_register(MemoryListener *listener, AddressSpace *filter); |
7664e80c AK |
1035 | |
1036 | /** | |
1037 | * memory_listener_unregister: undo the effect of memory_listener_register() | |
1038 | * | |
1039 | * @listener: an object containing the callbacks to be removed | |
1040 | */ | |
1041 | void memory_listener_unregister(MemoryListener *listener); | |
1042 | ||
1043 | /** | |
1044 | * memory_global_dirty_log_start: begin dirty logging for all regions | |
1045 | */ | |
1046 | void memory_global_dirty_log_start(void); | |
1047 | ||
1048 | /** | |
1a7e8cae | 1049 | * memory_global_dirty_log_stop: end dirty logging for all regions |
7664e80c AK |
1050 | */ |
1051 | void memory_global_dirty_log_stop(void); | |
1052 | ||
314e2987 BS |
1053 | void mtree_info(fprintf_function mon_printf, void *f); |
1054 | ||
3b643495 PM |
1055 | /** |
1056 | * memory_region_dispatch_read: perform a read directly to the specified | |
1057 | * MemoryRegion. | |
1058 | * | |
1059 | * @mr: #MemoryRegion to access | |
1060 | * @addr: address within that region | |
1061 | * @pval: pointer to uint64_t which the data is written to | |
1062 | * @size: size of the access in bytes | |
1063 | * @attrs: memory transaction attributes to use for the access | |
1064 | */ | |
1065 | MemTxResult memory_region_dispatch_read(MemoryRegion *mr, | |
1066 | hwaddr addr, | |
1067 | uint64_t *pval, | |
1068 | unsigned size, | |
1069 | MemTxAttrs attrs); | |
1070 | /** | |
1071 | * memory_region_dispatch_write: perform a write directly to the specified | |
1072 | * MemoryRegion. | |
1073 | * | |
1074 | * @mr: #MemoryRegion to access | |
1075 | * @addr: address within that region | |
1076 | * @data: data to write | |
1077 | * @size: size of the access in bytes | |
1078 | * @attrs: memory transaction attributes to use for the access | |
1079 | */ | |
1080 | MemTxResult memory_region_dispatch_write(MemoryRegion *mr, | |
1081 | hwaddr addr, | |
1082 | uint64_t data, | |
1083 | unsigned size, | |
1084 | MemTxAttrs attrs); | |
1085 | ||
9ad2bbc1 AK |
1086 | /** |
1087 | * address_space_init: initializes an address space | |
1088 | * | |
1089 | * @as: an uninitialized #AddressSpace | |
1090 | * @root: a #MemoryRegion that routes addesses for the address space | |
7dca8043 AK |
1091 | * @name: an address space name. The name is only used for debugging |
1092 | * output. | |
9ad2bbc1 | 1093 | */ |
7dca8043 | 1094 | void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name); |
9ad2bbc1 | 1095 | |
83f3c251 AK |
1096 | |
1097 | /** | |
1098 | * address_space_destroy: destroy an address space | |
1099 | * | |
1100 | * Releases all resources associated with an address space. After an address space | |
1101 | * is destroyed, its root memory region (given by address_space_init()) may be destroyed | |
1102 | * as well. | |
1103 | * | |
1104 | * @as: address space to be destroyed | |
1105 | */ | |
1106 | void address_space_destroy(AddressSpace *as); | |
1107 | ||
ac1970fb AK |
1108 | /** |
1109 | * address_space_rw: read from or write to an address space. | |
1110 | * | |
30951157 AK |
1111 | * Return true if the operation hit any unassigned memory or encountered an |
1112 | * IOMMU fault. | |
fd8aaa76 | 1113 | * |
ac1970fb AK |
1114 | * @as: #AddressSpace to be accessed |
1115 | * @addr: address within that address space | |
1116 | * @buf: buffer with the data transferred | |
1117 | * @is_write: indicates the transfer direction | |
1118 | */ | |
fd8aaa76 | 1119 | bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, |
ac1970fb AK |
1120 | int len, bool is_write); |
1121 | ||
1122 | /** | |
1123 | * address_space_write: write to address space. | |
1124 | * | |
30951157 AK |
1125 | * Return true if the operation hit any unassigned memory or encountered an |
1126 | * IOMMU fault. | |
fd8aaa76 | 1127 | * |
ac1970fb AK |
1128 | * @as: #AddressSpace to be accessed |
1129 | * @addr: address within that address space | |
1130 | * @buf: buffer with the data transferred | |
1131 | */ | |
fd8aaa76 | 1132 | bool address_space_write(AddressSpace *as, hwaddr addr, |
ac1970fb AK |
1133 | const uint8_t *buf, int len); |
1134 | ||
1135 | /** | |
1136 | * address_space_read: read from an address space. | |
1137 | * | |
30951157 AK |
1138 | * Return true if the operation hit any unassigned memory or encountered an |
1139 | * IOMMU fault. | |
fd8aaa76 | 1140 | * |
ac1970fb AK |
1141 | * @as: #AddressSpace to be accessed |
1142 | * @addr: address within that address space | |
1143 | * @buf: buffer with the data transferred | |
1144 | */ | |
fd8aaa76 | 1145 | bool address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len); |
ac1970fb | 1146 | |
149f54b5 | 1147 | /* address_space_translate: translate an address range into an address space |
5c8a00ce | 1148 | * into a MemoryRegion and an address range into that section |
149f54b5 PB |
1149 | * |
1150 | * @as: #AddressSpace to be accessed | |
1151 | * @addr: address within that address space | |
1152 | * @xlat: pointer to address within the returned memory region section's | |
1153 | * #MemoryRegion. | |
1154 | * @len: pointer to length | |
1155 | * @is_write: indicates the transfer direction | |
1156 | */ | |
5c8a00ce PB |
1157 | MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, |
1158 | hwaddr *xlat, hwaddr *len, | |
1159 | bool is_write); | |
149f54b5 | 1160 | |
51644ab7 PB |
1161 | /* address_space_access_valid: check for validity of accessing an address |
1162 | * space range | |
1163 | * | |
30951157 AK |
1164 | * Check whether memory is assigned to the given address space range, and |
1165 | * access is permitted by any IOMMU regions that are active for the address | |
1166 | * space. | |
51644ab7 PB |
1167 | * |
1168 | * For now, addr and len should be aligned to a page size. This limitation | |
1169 | * will be lifted in the future. | |
1170 | * | |
1171 | * @as: #AddressSpace to be accessed | |
1172 | * @addr: address within that address space | |
1173 | * @len: length of the area to be checked | |
1174 | * @is_write: indicates the transfer direction | |
1175 | */ | |
1176 | bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write); | |
1177 | ||
ac1970fb AK |
1178 | /* address_space_map: map a physical memory region into a host virtual address |
1179 | * | |
1180 | * May map a subset of the requested range, given by and returned in @plen. | |
1181 | * May return %NULL if resources needed to perform the mapping are exhausted. | |
1182 | * Use only for reads OR writes - not for read-modify-write operations. | |
1183 | * Use cpu_register_map_client() to know when retrying the map operation is | |
1184 | * likely to succeed. | |
1185 | * | |
1186 | * @as: #AddressSpace to be accessed | |
1187 | * @addr: address within that address space | |
1188 | * @plen: pointer to length of buffer; updated on return | |
1189 | * @is_write: indicates the transfer direction | |
1190 | */ | |
a8170e5e AK |
1191 | void *address_space_map(AddressSpace *as, hwaddr addr, |
1192 | hwaddr *plen, bool is_write); | |
ac1970fb AK |
1193 | |
1194 | /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map() | |
1195 | * | |
1196 | * Will also mark the memory as dirty if @is_write == %true. @access_len gives | |
1197 | * the amount of memory that was actually read or written by the caller. | |
1198 | * | |
1199 | * @as: #AddressSpace used | |
1200 | * @addr: address within that address space | |
1201 | * @len: buffer length as returned by address_space_map() | |
1202 | * @access_len: amount of data actually transferred | |
1203 | * @is_write: indicates the transfer direction | |
1204 | */ | |
a8170e5e AK |
1205 | void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, |
1206 | int is_write, hwaddr access_len); | |
ac1970fb AK |
1207 | |
1208 | ||
093bc2cd AK |
1209 | #endif |
1210 | ||
1211 | #endif |