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