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