]>
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 | ||
022c62cb PB |
19 | #include "exec/cpu-common.h" |
20 | #include "exec/hwaddr.h" | |
cc05c43a | 21 | #include "exec/memattrs.h" |
0987d735 | 22 | #include "exec/ramlist.h" |
1de7afc9 | 23 | #include "qemu/queue.h" |
1de7afc9 | 24 | #include "qemu/int128.h" |
06866575 | 25 | #include "qemu/notify.h" |
b4fefef9 | 26 | #include "qom/object.h" |
374f2981 | 27 | #include "qemu/rcu.h" |
1221a474 | 28 | #include "hw/qdev-core.h" |
093bc2cd | 29 | |
07bdaa41 PB |
30 | #define RAM_ADDR_INVALID (~(ram_addr_t)0) |
31 | ||
052e87b0 PB |
32 | #define MAX_PHYS_ADDR_SPACE_BITS 62 |
33 | #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) | |
34 | ||
b4fefef9 PC |
35 | #define TYPE_MEMORY_REGION "qemu:memory-region" |
36 | #define MEMORY_REGION(obj) \ | |
37 | OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION) | |
38 | ||
3df9d748 AK |
39 | #define TYPE_IOMMU_MEMORY_REGION "qemu:iommu-memory-region" |
40 | #define IOMMU_MEMORY_REGION(obj) \ | |
41 | OBJECT_CHECK(IOMMUMemoryRegion, (obj), TYPE_IOMMU_MEMORY_REGION) | |
1221a474 AK |
42 | #define IOMMU_MEMORY_REGION_CLASS(klass) \ |
43 | OBJECT_CLASS_CHECK(IOMMUMemoryRegionClass, (klass), \ | |
44 | TYPE_IOMMU_MEMORY_REGION) | |
45 | #define IOMMU_MEMORY_REGION_GET_CLASS(obj) \ | |
46 | OBJECT_GET_CLASS(IOMMUMemoryRegionClass, (obj), \ | |
47 | TYPE_IOMMU_MEMORY_REGION) | |
3df9d748 | 48 | |
093bc2cd | 49 | typedef struct MemoryRegionOps MemoryRegionOps; |
74901c3b | 50 | typedef struct MemoryRegionMmio MemoryRegionMmio; |
093bc2cd | 51 | |
74901c3b AK |
52 | struct MemoryRegionMmio { |
53 | CPUReadMemoryFunc *read[3]; | |
54 | CPUWriteMemoryFunc *write[3]; | |
55 | }; | |
56 | ||
30951157 AK |
57 | typedef struct IOMMUTLBEntry IOMMUTLBEntry; |
58 | ||
59 | /* See address_space_translate: bit 0 is read, bit 1 is write. */ | |
60 | typedef enum { | |
61 | IOMMU_NONE = 0, | |
62 | IOMMU_RO = 1, | |
63 | IOMMU_WO = 2, | |
64 | IOMMU_RW = 3, | |
65 | } IOMMUAccessFlags; | |
66 | ||
f06a696d PX |
67 | #define IOMMU_ACCESS_FLAG(r, w) (((r) ? IOMMU_RO : 0) | ((w) ? IOMMU_WO : 0)) |
68 | ||
30951157 AK |
69 | struct IOMMUTLBEntry { |
70 | AddressSpace *target_as; | |
71 | hwaddr iova; | |
72 | hwaddr translated_addr; | |
73 | hwaddr addr_mask; /* 0xfff = 4k translation */ | |
74 | IOMMUAccessFlags perm; | |
75 | }; | |
76 | ||
cdb30812 PX |
77 | /* |
78 | * Bitmap for different IOMMUNotifier capabilities. Each notifier can | |
79 | * register with one or multiple IOMMU Notifier capability bit(s). | |
80 | */ | |
81 | typedef enum { | |
82 | IOMMU_NOTIFIER_NONE = 0, | |
83 | /* Notify cache invalidations */ | |
84 | IOMMU_NOTIFIER_UNMAP = 0x1, | |
85 | /* Notify entry changes (newly created entries) */ | |
86 | IOMMU_NOTIFIER_MAP = 0x2, | |
87 | } IOMMUNotifierFlag; | |
88 | ||
89 | #define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) | |
90 | ||
698feb5e PX |
91 | struct IOMMUNotifier; |
92 | typedef void (*IOMMUNotify)(struct IOMMUNotifier *notifier, | |
93 | IOMMUTLBEntry *data); | |
94 | ||
cdb30812 | 95 | struct IOMMUNotifier { |
698feb5e | 96 | IOMMUNotify notify; |
cdb30812 | 97 | IOMMUNotifierFlag notifier_flags; |
698feb5e PX |
98 | /* Notify for address space range start <= addr <= end */ |
99 | hwaddr start; | |
100 | hwaddr end; | |
cdb30812 PX |
101 | QLIST_ENTRY(IOMMUNotifier) node; |
102 | }; | |
103 | typedef struct IOMMUNotifier IOMMUNotifier; | |
104 | ||
698feb5e PX |
105 | static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, |
106 | IOMMUNotifierFlag flags, | |
107 | hwaddr start, hwaddr end) | |
108 | { | |
109 | n->notify = fn; | |
110 | n->notifier_flags = flags; | |
111 | n->start = start; | |
112 | n->end = end; | |
113 | } | |
114 | ||
cc05c43a PM |
115 | /* New-style MMIO accessors can indicate that the transaction failed. |
116 | * A zero (MEMTX_OK) response means success; anything else is a failure | |
117 | * of some kind. The memory subsystem will bitwise-OR together results | |
118 | * if it is synthesizing an operation from multiple smaller accesses. | |
119 | */ | |
120 | #define MEMTX_OK 0 | |
121 | #define MEMTX_ERROR (1U << 0) /* device returned an error */ | |
122 | #define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */ | |
123 | typedef uint32_t MemTxResult; | |
124 | ||
093bc2cd AK |
125 | /* |
126 | * Memory region callbacks | |
127 | */ | |
128 | struct MemoryRegionOps { | |
129 | /* Read from the memory region. @addr is relative to @mr; @size is | |
130 | * in bytes. */ | |
131 | uint64_t (*read)(void *opaque, | |
a8170e5e | 132 | hwaddr addr, |
093bc2cd AK |
133 | unsigned size); |
134 | /* Write to the memory region. @addr is relative to @mr; @size is | |
135 | * in bytes. */ | |
136 | void (*write)(void *opaque, | |
a8170e5e | 137 | hwaddr addr, |
093bc2cd AK |
138 | uint64_t data, |
139 | unsigned size); | |
140 | ||
cc05c43a PM |
141 | MemTxResult (*read_with_attrs)(void *opaque, |
142 | hwaddr addr, | |
143 | uint64_t *data, | |
144 | unsigned size, | |
145 | MemTxAttrs attrs); | |
146 | MemTxResult (*write_with_attrs)(void *opaque, | |
147 | hwaddr addr, | |
148 | uint64_t data, | |
149 | unsigned size, | |
150 | MemTxAttrs attrs); | |
c9356746 FK |
151 | /* Instruction execution pre-callback: |
152 | * @addr is the address of the access relative to the @mr. | |
153 | * @size is the size of the area returned by the callback. | |
154 | * @offset is the location of the pointer inside @mr. | |
155 | * | |
156 | * Returns a pointer to a location which contains guest code. | |
157 | */ | |
158 | void *(*request_ptr)(void *opaque, hwaddr addr, unsigned *size, | |
159 | unsigned *offset); | |
cc05c43a | 160 | |
093bc2cd AK |
161 | enum device_endian endianness; |
162 | /* Guest-visible constraints: */ | |
163 | struct { | |
164 | /* If nonzero, specify bounds on access sizes beyond which a machine | |
165 | * check is thrown. | |
166 | */ | |
167 | unsigned min_access_size; | |
168 | unsigned max_access_size; | |
169 | /* If true, unaligned accesses are supported. Otherwise unaligned | |
170 | * accesses throw machine checks. | |
171 | */ | |
172 | bool unaligned; | |
897fa7cf AK |
173 | /* |
174 | * If present, and returns #false, the transaction is not accepted | |
175 | * by the device (and results in machine dependent behaviour such | |
176 | * as a machine check exception). | |
177 | */ | |
a8170e5e | 178 | bool (*accepts)(void *opaque, hwaddr addr, |
897fa7cf | 179 | unsigned size, bool is_write); |
093bc2cd AK |
180 | } valid; |
181 | /* Internal implementation constraints: */ | |
182 | struct { | |
183 | /* If nonzero, specifies the minimum size implemented. Smaller sizes | |
184 | * will be rounded upwards and a partial result will be returned. | |
185 | */ | |
186 | unsigned min_access_size; | |
187 | /* If nonzero, specifies the maximum size implemented. Larger sizes | |
188 | * will be done as a series of accesses with smaller sizes. | |
189 | */ | |
190 | unsigned max_access_size; | |
191 | /* If true, unaligned accesses are supported. Otherwise all accesses | |
192 | * are converted to (possibly multiple) naturally aligned accesses. | |
193 | */ | |
edc1ba7a | 194 | bool unaligned; |
093bc2cd | 195 | } impl; |
627a0e90 | 196 | |
74901c3b AK |
197 | /* If .read and .write are not present, old_mmio may be used for |
198 | * backwards compatibility with old mmio registration | |
199 | */ | |
200 | const MemoryRegionMmio old_mmio; | |
093bc2cd AK |
201 | }; |
202 | ||
1221a474 AK |
203 | typedef struct IOMMUMemoryRegionClass { |
204 | /* private */ | |
205 | struct DeviceClass parent_class; | |
30951157 | 206 | |
bf55b7af PX |
207 | /* |
208 | * Return a TLB entry that contains a given address. Flag should | |
209 | * be the access permission of this translation operation. We can | |
210 | * set flag to IOMMU_NONE to mean that we don't need any | |
211 | * read/write permission checks, like, when for region replay. | |
212 | */ | |
3df9d748 | 213 | IOMMUTLBEntry (*translate)(IOMMUMemoryRegion *iommu, hwaddr addr, |
bf55b7af | 214 | IOMMUAccessFlags flag); |
f682e9c2 | 215 | /* Returns minimum supported page size */ |
3df9d748 | 216 | uint64_t (*get_min_page_size)(IOMMUMemoryRegion *iommu); |
5bf3d319 | 217 | /* Called when IOMMU Notifier flag changed */ |
3df9d748 | 218 | void (*notify_flag_changed)(IOMMUMemoryRegion *iommu, |
5bf3d319 PX |
219 | IOMMUNotifierFlag old_flags, |
220 | IOMMUNotifierFlag new_flags); | |
faa362e3 | 221 | /* Set this up to provide customized IOMMU replay function */ |
3df9d748 | 222 | void (*replay)(IOMMUMemoryRegion *iommu, IOMMUNotifier *notifier); |
1221a474 | 223 | } IOMMUMemoryRegionClass; |
30951157 | 224 | |
093bc2cd | 225 | typedef struct CoalescedMemoryRange CoalescedMemoryRange; |
3e9d69e7 | 226 | typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; |
093bc2cd AK |
227 | |
228 | struct MemoryRegion { | |
b4fefef9 | 229 | Object parent_obj; |
a676854f | 230 | |
093bc2cd | 231 | /* All fields are private - violators will be prosecuted */ |
a676854f PB |
232 | |
233 | /* The following fields should fit in a cache line */ | |
234 | bool romd_mode; | |
235 | bool ram; | |
236 | bool subpage; | |
237 | bool readonly; /* For RAM regions */ | |
238 | bool rom_device; | |
239 | bool flush_coalesced_mmio; | |
240 | bool global_locking; | |
241 | uint8_t dirty_log_mask; | |
3df9d748 | 242 | bool is_iommu; |
58eaa217 | 243 | RAMBlock *ram_block; |
612263cf | 244 | Object *owner; |
a676854f PB |
245 | |
246 | const MemoryRegionOps *ops; | |
093bc2cd | 247 | void *opaque; |
feca4ac1 | 248 | MemoryRegion *container; |
08dafab4 | 249 | Int128 size; |
a8170e5e | 250 | hwaddr addr; |
545e92e0 | 251 | void (*destructor)(MemoryRegion *mr); |
a2b257d6 | 252 | uint64_t align; |
14a3c10a | 253 | bool terminates; |
21e00fa5 | 254 | bool ram_device; |
6bba19ba | 255 | bool enabled; |
1660e72d | 256 | bool warning_printed; /* For reservations */ |
deb809ed | 257 | uint8_t vga_logging_count; |
093bc2cd | 258 | MemoryRegion *alias; |
a8170e5e | 259 | hwaddr alias_offset; |
d33382da | 260 | int32_t priority; |
093bc2cd AK |
261 | QTAILQ_HEAD(subregions, MemoryRegion) subregions; |
262 | QTAILQ_ENTRY(MemoryRegion) subregions_link; | |
263 | QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced; | |
302fa283 | 264 | const char *name; |
3e9d69e7 AK |
265 | unsigned ioeventfd_nb; |
266 | MemoryRegionIoeventfd *ioeventfds; | |
3df9d748 AK |
267 | }; |
268 | ||
269 | struct IOMMUMemoryRegion { | |
270 | MemoryRegion parent_obj; | |
271 | ||
cdb30812 | 272 | QLIST_HEAD(, IOMMUNotifier) iommu_notify; |
5bf3d319 | 273 | IOMMUNotifierFlag iommu_notify_flags; |
093bc2cd AK |
274 | }; |
275 | ||
512fa408 PX |
276 | #define IOMMU_NOTIFIER_FOREACH(n, mr) \ |
277 | QLIST_FOREACH((n), &(mr)->iommu_notify, node) | |
278 | ||
c2fc83e8 PB |
279 | /** |
280 | * MemoryListener: callbacks structure for updates to the physical memory map | |
281 | * | |
282 | * Allows a component to adjust to changes in the guest-visible memory map. | |
283 | * Use with memory_listener_register() and memory_listener_unregister(). | |
284 | */ | |
285 | struct MemoryListener { | |
286 | void (*begin)(MemoryListener *listener); | |
287 | void (*commit)(MemoryListener *listener); | |
288 | void (*region_add)(MemoryListener *listener, MemoryRegionSection *section); | |
289 | void (*region_del)(MemoryListener *listener, MemoryRegionSection *section); | |
290 | void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section); | |
b2dfd71c PB |
291 | void (*log_start)(MemoryListener *listener, MemoryRegionSection *section, |
292 | int old, int new); | |
293 | void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section, | |
294 | int old, int new); | |
c2fc83e8 PB |
295 | void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section); |
296 | void (*log_global_start)(MemoryListener *listener); | |
297 | void (*log_global_stop)(MemoryListener *listener); | |
298 | void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section, | |
299 | bool match_data, uint64_t data, EventNotifier *e); | |
300 | void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section, | |
301 | bool match_data, uint64_t data, EventNotifier *e); | |
302 | void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section, | |
303 | hwaddr addr, hwaddr len); | |
304 | void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section, | |
305 | hwaddr addr, hwaddr len); | |
306 | /* Lower = earlier (during add), later (during del) */ | |
307 | unsigned priority; | |
d45fa784 | 308 | AddressSpace *address_space; |
c2fc83e8 | 309 | QTAILQ_ENTRY(MemoryListener) link; |
9a54635d | 310 | QTAILQ_ENTRY(MemoryListener) link_as; |
c2fc83e8 PB |
311 | }; |
312 | ||
9ad2bbc1 AK |
313 | /** |
314 | * AddressSpace: describes a mapping of addresses to #MemoryRegion objects | |
315 | */ | |
316 | struct AddressSpace { | |
317 | /* All fields are private. */ | |
374f2981 | 318 | struct rcu_head rcu; |
7dca8043 | 319 | char *name; |
9ad2bbc1 | 320 | MemoryRegion *root; |
f0c02d15 PC |
321 | int ref_count; |
322 | bool malloced; | |
374f2981 PB |
323 | |
324 | /* Accessed via RCU. */ | |
9ad2bbc1 | 325 | struct FlatView *current_map; |
374f2981 | 326 | |
9ad2bbc1 AK |
327 | int ioeventfd_nb; |
328 | struct MemoryRegionIoeventfd *ioeventfds; | |
ac1970fb | 329 | struct AddressSpaceDispatch *dispatch; |
00752703 | 330 | struct AddressSpaceDispatch *next_dispatch; |
89ae337a | 331 | MemoryListener dispatch_listener; |
9a54635d | 332 | QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners; |
0d673e36 | 333 | QTAILQ_ENTRY(AddressSpace) address_spaces_link; |
9ad2bbc1 AK |
334 | }; |
335 | ||
e2177955 AK |
336 | /** |
337 | * MemoryRegionSection: describes a fragment of a #MemoryRegion | |
338 | * | |
339 | * @mr: the region, or %NULL if empty | |
7664e80c | 340 | * @address_space: the address space the region is mapped in |
e2177955 AK |
341 | * @offset_within_region: the beginning of the section, relative to @mr's start |
342 | * @size: the size of the section; will not exceed @mr's boundaries | |
343 | * @offset_within_address_space: the address of the first byte of the section | |
344 | * relative to the region's address space | |
7a8499e8 | 345 | * @readonly: writes to this section are ignored |
e2177955 AK |
346 | */ |
347 | struct MemoryRegionSection { | |
348 | MemoryRegion *mr; | |
f6790af6 | 349 | AddressSpace *address_space; |
a8170e5e | 350 | hwaddr offset_within_region; |
052e87b0 | 351 | Int128 size; |
a8170e5e | 352 | hwaddr offset_within_address_space; |
7a8499e8 | 353 | bool readonly; |
e2177955 AK |
354 | }; |
355 | ||
093bc2cd AK |
356 | /** |
357 | * memory_region_init: Initialize a memory region | |
358 | * | |
69ddaf66 | 359 | * The region typically acts as a container for other memory regions. Use |
093bc2cd AK |
360 | * memory_region_add_subregion() to add subregions. |
361 | * | |
362 | * @mr: the #MemoryRegion to be initialized | |
2c9b15ca | 363 | * @owner: the object that tracks the region's reference count |
093bc2cd AK |
364 | * @name: used for debugging; not visible to the user or ABI |
365 | * @size: size of the region; any subregions beyond this size will be clipped | |
366 | */ | |
367 | void memory_region_init(MemoryRegion *mr, | |
2c9b15ca | 368 | struct Object *owner, |
093bc2cd AK |
369 | const char *name, |
370 | uint64_t size); | |
46637be2 PB |
371 | |
372 | /** | |
373 | * memory_region_ref: Add 1 to a memory region's reference count | |
374 | * | |
375 | * Whenever memory regions are accessed outside the BQL, they need to be | |
376 | * preserved against hot-unplug. MemoryRegions actually do not have their | |
377 | * own reference count; they piggyback on a QOM object, their "owner". | |
378 | * This function adds a reference to the owner. | |
379 | * | |
380 | * All MemoryRegions must have an owner if they can disappear, even if the | |
381 | * device they belong to operates exclusively under the BQL. This is because | |
382 | * the region could be returned at any time by memory_region_find, and this | |
383 | * is usually under guest control. | |
384 | * | |
385 | * @mr: the #MemoryRegion | |
386 | */ | |
387 | void memory_region_ref(MemoryRegion *mr); | |
388 | ||
389 | /** | |
390 | * memory_region_unref: Remove 1 to a memory region's reference count | |
391 | * | |
392 | * Whenever memory regions are accessed outside the BQL, they need to be | |
393 | * preserved against hot-unplug. MemoryRegions actually do not have their | |
394 | * own reference count; they piggyback on a QOM object, their "owner". | |
395 | * This function removes a reference to the owner and possibly destroys it. | |
396 | * | |
397 | * @mr: the #MemoryRegion | |
398 | */ | |
399 | void memory_region_unref(MemoryRegion *mr); | |
400 | ||
093bc2cd AK |
401 | /** |
402 | * memory_region_init_io: Initialize an I/O memory region. | |
403 | * | |
69ddaf66 | 404 | * Accesses into the region will cause the callbacks in @ops to be called. |
093bc2cd AK |
405 | * if @size is nonzero, subregions will be clipped to @size. |
406 | * | |
407 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 408 | * @owner: the object that tracks the region's reference count |
093bc2cd AK |
409 | * @ops: a structure containing read and write callbacks to be used when |
410 | * I/O is performed on the region. | |
b6af0975 | 411 | * @opaque: passed to the read and write callbacks of the @ops structure. |
093bc2cd AK |
412 | * @name: used for debugging; not visible to the user or ABI |
413 | * @size: size of the region. | |
414 | */ | |
415 | void memory_region_init_io(MemoryRegion *mr, | |
2c9b15ca | 416 | struct Object *owner, |
093bc2cd AK |
417 | const MemoryRegionOps *ops, |
418 | void *opaque, | |
419 | const char *name, | |
420 | uint64_t size); | |
421 | ||
422 | /** | |
423 | * memory_region_init_ram: Initialize RAM memory region. Accesses into the | |
69ddaf66 | 424 | * region will modify memory directly. |
093bc2cd AK |
425 | * |
426 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 427 | * @owner: the object that tracks the region's reference count |
e8f5fe2d DDAG |
428 | * @name: Region name, becomes part of RAMBlock name used in migration stream |
429 | * must be unique within any device | |
093bc2cd | 430 | * @size: size of the region. |
49946538 | 431 | * @errp: pointer to Error*, to store an error if it happens. |
093bc2cd AK |
432 | */ |
433 | void memory_region_init_ram(MemoryRegion *mr, | |
2c9b15ca | 434 | struct Object *owner, |
093bc2cd | 435 | const char *name, |
49946538 HT |
436 | uint64_t size, |
437 | Error **errp); | |
093bc2cd | 438 | |
60786ef3 MT |
439 | /** |
440 | * memory_region_init_resizeable_ram: Initialize memory region with resizeable | |
441 | * RAM. Accesses into the region will | |
442 | * modify memory directly. Only an initial | |
443 | * portion of this RAM is actually used. | |
444 | * The used size can change across reboots. | |
445 | * | |
446 | * @mr: the #MemoryRegion to be initialized. | |
447 | * @owner: the object that tracks the region's reference count | |
e8f5fe2d DDAG |
448 | * @name: Region name, becomes part of RAMBlock name used in migration stream |
449 | * must be unique within any device | |
60786ef3 MT |
450 | * @size: used size of the region. |
451 | * @max_size: max size of the region. | |
452 | * @resized: callback to notify owner about used size change. | |
453 | * @errp: pointer to Error*, to store an error if it happens. | |
454 | */ | |
455 | void memory_region_init_resizeable_ram(MemoryRegion *mr, | |
456 | struct Object *owner, | |
457 | const char *name, | |
458 | uint64_t size, | |
459 | uint64_t max_size, | |
460 | void (*resized)(const char*, | |
461 | uint64_t length, | |
462 | void *host), | |
463 | Error **errp); | |
0b183fc8 PB |
464 | #ifdef __linux__ |
465 | /** | |
466 | * memory_region_init_ram_from_file: Initialize RAM memory region with a | |
467 | * mmap-ed backend. | |
468 | * | |
469 | * @mr: the #MemoryRegion to be initialized. | |
470 | * @owner: the object that tracks the region's reference count | |
e8f5fe2d DDAG |
471 | * @name: Region name, becomes part of RAMBlock name used in migration stream |
472 | * must be unique within any device | |
0b183fc8 | 473 | * @size: size of the region. |
dbcb8981 | 474 | * @share: %true if memory must be mmaped with the MAP_SHARED flag |
0b183fc8 | 475 | * @path: the path in which to allocate the RAM. |
7f56e740 | 476 | * @errp: pointer to Error*, to store an error if it happens. |
0b183fc8 PB |
477 | */ |
478 | void memory_region_init_ram_from_file(MemoryRegion *mr, | |
479 | struct Object *owner, | |
480 | const char *name, | |
481 | uint64_t size, | |
dbcb8981 | 482 | bool share, |
7f56e740 PB |
483 | const char *path, |
484 | Error **errp); | |
fea617c5 MAL |
485 | |
486 | /** | |
487 | * memory_region_init_ram_from_fd: Initialize RAM memory region with a | |
488 | * mmap-ed backend. | |
489 | * | |
490 | * @mr: the #MemoryRegion to be initialized. | |
491 | * @owner: the object that tracks the region's reference count | |
492 | * @name: the name of the region. | |
493 | * @size: size of the region. | |
494 | * @share: %true if memory must be mmaped with the MAP_SHARED flag | |
495 | * @fd: the fd to mmap. | |
496 | * @errp: pointer to Error*, to store an error if it happens. | |
497 | */ | |
498 | void memory_region_init_ram_from_fd(MemoryRegion *mr, | |
499 | struct Object *owner, | |
500 | const char *name, | |
501 | uint64_t size, | |
502 | bool share, | |
503 | int fd, | |
504 | Error **errp); | |
0b183fc8 PB |
505 | #endif |
506 | ||
093bc2cd | 507 | /** |
1a7e8cae BZ |
508 | * memory_region_init_ram_ptr: Initialize RAM memory region from a |
509 | * user-provided pointer. Accesses into the | |
510 | * region will modify memory directly. | |
093bc2cd AK |
511 | * |
512 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 513 | * @owner: the object that tracks the region's reference count |
e8f5fe2d DDAG |
514 | * @name: Region name, becomes part of RAMBlock name used in migration stream |
515 | * must be unique within any device | |
093bc2cd AK |
516 | * @size: size of the region. |
517 | * @ptr: memory to be mapped; must contain at least @size bytes. | |
518 | */ | |
519 | void memory_region_init_ram_ptr(MemoryRegion *mr, | |
2c9b15ca | 520 | struct Object *owner, |
093bc2cd AK |
521 | const char *name, |
522 | uint64_t size, | |
523 | void *ptr); | |
524 | ||
21e00fa5 AW |
525 | /** |
526 | * memory_region_init_ram_device_ptr: Initialize RAM device memory region from | |
527 | * a user-provided pointer. | |
528 | * | |
529 | * A RAM device represents a mapping to a physical device, such as to a PCI | |
530 | * MMIO BAR of an vfio-pci assigned device. The memory region may be mapped | |
531 | * into the VM address space and access to the region will modify memory | |
532 | * directly. However, the memory region should not be included in a memory | |
533 | * dump (device may not be enabled/mapped at the time of the dump), and | |
534 | * operations incompatible with manipulating MMIO should be avoided. Replaces | |
535 | * skip_dump flag. | |
536 | * | |
537 | * @mr: the #MemoryRegion to be initialized. | |
538 | * @owner: the object that tracks the region's reference count | |
539 | * @name: the name of the region. | |
540 | * @size: size of the region. | |
541 | * @ptr: memory to be mapped; must contain at least @size bytes. | |
542 | */ | |
543 | void memory_region_init_ram_device_ptr(MemoryRegion *mr, | |
544 | struct Object *owner, | |
545 | const char *name, | |
546 | uint64_t size, | |
547 | void *ptr); | |
548 | ||
093bc2cd AK |
549 | /** |
550 | * memory_region_init_alias: Initialize a memory region that aliases all or a | |
551 | * part of another memory region. | |
552 | * | |
553 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 554 | * @owner: the object that tracks the region's reference count |
093bc2cd AK |
555 | * @name: used for debugging; not visible to the user or ABI |
556 | * @orig: the region to be referenced; @mr will be equivalent to | |
557 | * @orig between @offset and @offset + @size - 1. | |
558 | * @offset: start of the section in @orig to be referenced. | |
559 | * @size: size of the region. | |
560 | */ | |
561 | void memory_region_init_alias(MemoryRegion *mr, | |
2c9b15ca | 562 | struct Object *owner, |
093bc2cd AK |
563 | const char *name, |
564 | MemoryRegion *orig, | |
a8170e5e | 565 | hwaddr offset, |
093bc2cd | 566 | uint64_t size); |
d0a9b5bc | 567 | |
a1777f7f PM |
568 | /** |
569 | * memory_region_init_rom: Initialize a ROM memory region. | |
570 | * | |
571 | * This has the same effect as calling memory_region_init_ram() | |
572 | * and then marking the resulting region read-only with | |
573 | * memory_region_set_readonly(). | |
574 | * | |
575 | * @mr: the #MemoryRegion to be initialized. | |
576 | * @owner: the object that tracks the region's reference count | |
e8f5fe2d DDAG |
577 | * @name: Region name, becomes part of RAMBlock name used in migration stream |
578 | * must be unique within any device | |
a1777f7f PM |
579 | * @size: size of the region. |
580 | * @errp: pointer to Error*, to store an error if it happens. | |
581 | */ | |
582 | void memory_region_init_rom(MemoryRegion *mr, | |
583 | struct Object *owner, | |
584 | const char *name, | |
585 | uint64_t size, | |
586 | Error **errp); | |
587 | ||
d0a9b5bc AK |
588 | /** |
589 | * memory_region_init_rom_device: Initialize a ROM memory region. Writes are | |
590 | * handled via callbacks. | |
591 | * | |
592 | * @mr: the #MemoryRegion to be initialized. | |
2c9b15ca | 593 | * @owner: the object that tracks the region's reference count |
39e0b03d | 594 | * @ops: callbacks for write access handling (must not be NULL). |
e8f5fe2d DDAG |
595 | * @name: Region name, becomes part of RAMBlock name used in migration stream |
596 | * must be unique within any device | |
d0a9b5bc | 597 | * @size: size of the region. |
33e0eb52 | 598 | * @errp: pointer to Error*, to store an error if it happens. |
d0a9b5bc AK |
599 | */ |
600 | void memory_region_init_rom_device(MemoryRegion *mr, | |
2c9b15ca | 601 | struct Object *owner, |
d0a9b5bc | 602 | const MemoryRegionOps *ops, |
75f5941c | 603 | void *opaque, |
d0a9b5bc | 604 | const char *name, |
33e0eb52 HT |
605 | uint64_t size, |
606 | Error **errp); | |
d0a9b5bc | 607 | |
1660e72d JK |
608 | /** |
609 | * memory_region_init_reservation: Initialize a memory region that reserves | |
610 | * I/O space. | |
611 | * | |
612 | * A reservation region primariy serves debugging purposes. It claims I/O | |
613 | * space that is not supposed to be handled by QEMU itself. Any access via | |
614 | * the memory API will cause an abort(). | |
6d6d2abf PF |
615 | * This function is deprecated. Use memory_region_init_io() with NULL |
616 | * callbacks instead. | |
1660e72d JK |
617 | * |
618 | * @mr: the #MemoryRegion to be initialized | |
2c9b15ca | 619 | * @owner: the object that tracks the region's reference count |
1660e72d JK |
620 | * @name: used for debugging; not visible to the user or ABI |
621 | * @size: size of the region. | |
622 | */ | |
6d6d2abf PF |
623 | static inline void memory_region_init_reservation(MemoryRegion *mr, |
624 | Object *owner, | |
1660e72d | 625 | const char *name, |
6d6d2abf PF |
626 | uint64_t size) |
627 | { | |
628 | memory_region_init_io(mr, owner, NULL, mr, name, size); | |
629 | } | |
30951157 AK |
630 | |
631 | /** | |
1221a474 AK |
632 | * memory_region_init_iommu: Initialize a memory region of a custom type |
633 | * that translates addresses | |
30951157 AK |
634 | * |
635 | * An IOMMU region translates addresses and forwards accesses to a target | |
636 | * memory region. | |
637 | * | |
1221a474 AK |
638 | * @typename: QOM class name |
639 | * @_iommu_mr: the #IOMMUMemoryRegion to be initialized | |
640 | * @instance_size: the IOMMUMemoryRegion subclass instance size | |
2c9b15ca | 641 | * @owner: the object that tracks the region's reference count |
30951157 AK |
642 | * @ops: a function that translates addresses into the @target region |
643 | * @name: used for debugging; not visible to the user or ABI | |
644 | * @size: size of the region. | |
645 | */ | |
1221a474 AK |
646 | void memory_region_init_iommu(void *_iommu_mr, |
647 | size_t instance_size, | |
648 | const char *mrtypename, | |
649 | Object *owner, | |
30951157 AK |
650 | const char *name, |
651 | uint64_t size); | |
652 | ||
803c0816 PB |
653 | /** |
654 | * memory_region_owner: get a memory region's owner. | |
655 | * | |
656 | * @mr: the memory region being queried. | |
657 | */ | |
658 | struct Object *memory_region_owner(MemoryRegion *mr); | |
659 | ||
093bc2cd AK |
660 | /** |
661 | * memory_region_size: get a memory region's size. | |
662 | * | |
663 | * @mr: the memory region being queried. | |
664 | */ | |
665 | uint64_t memory_region_size(MemoryRegion *mr); | |
666 | ||
8ea9252a AK |
667 | /** |
668 | * memory_region_is_ram: check whether a memory region is random access | |
669 | * | |
670 | * Returns %true is a memory region is random access. | |
671 | * | |
672 | * @mr: the memory region being queried | |
673 | */ | |
1619d1fe PB |
674 | static inline bool memory_region_is_ram(MemoryRegion *mr) |
675 | { | |
676 | return mr->ram; | |
677 | } | |
8ea9252a | 678 | |
e4dc3f59 | 679 | /** |
21e00fa5 | 680 | * memory_region_is_ram_device: check whether a memory region is a ram device |
e4dc3f59 | 681 | * |
21e00fa5 | 682 | * Returns %true is a memory region is a device backed ram region |
e4dc3f59 ND |
683 | * |
684 | * @mr: the memory region being queried | |
685 | */ | |
21e00fa5 | 686 | bool memory_region_is_ram_device(MemoryRegion *mr); |
e4dc3f59 | 687 | |
fd062573 | 688 | /** |
5f9a5ea1 | 689 | * memory_region_is_romd: check whether a memory region is in ROMD mode |
fd062573 | 690 | * |
5f9a5ea1 | 691 | * Returns %true if a memory region is a ROM device and currently set to allow |
fd062573 BS |
692 | * direct reads. |
693 | * | |
694 | * @mr: the memory region being queried | |
695 | */ | |
696 | static inline bool memory_region_is_romd(MemoryRegion *mr) | |
697 | { | |
5f9a5ea1 | 698 | return mr->rom_device && mr->romd_mode; |
fd062573 BS |
699 | } |
700 | ||
30951157 | 701 | /** |
3df9d748 | 702 | * memory_region_get_iommu: check whether a memory region is an iommu |
30951157 | 703 | * |
3df9d748 AK |
704 | * Returns pointer to IOMMUMemoryRegion if a memory region is an iommu, |
705 | * otherwise NULL. | |
30951157 AK |
706 | * |
707 | * @mr: the memory region being queried | |
708 | */ | |
3df9d748 | 709 | static inline IOMMUMemoryRegion *memory_region_get_iommu(MemoryRegion *mr) |
1619d1fe | 710 | { |
12d37882 | 711 | if (mr->alias) { |
3df9d748 AK |
712 | return memory_region_get_iommu(mr->alias); |
713 | } | |
714 | if (mr->is_iommu) { | |
715 | return (IOMMUMemoryRegion *) mr; | |
12d37882 | 716 | } |
3df9d748 | 717 | return NULL; |
1619d1fe PB |
718 | } |
719 | ||
1221a474 AK |
720 | /** |
721 | * memory_region_get_iommu_class_nocheck: returns iommu memory region class | |
722 | * if an iommu or NULL if not | |
723 | * | |
724 | * Returns pointer to IOMMUMemoryRegioniClass if a memory region is an iommu, | |
725 | * otherwise NULL. This is fast path avoinding QOM checking, use with caution. | |
726 | * | |
727 | * @mr: the memory region being queried | |
728 | */ | |
729 | static inline IOMMUMemoryRegionClass *memory_region_get_iommu_class_nocheck( | |
730 | IOMMUMemoryRegion *iommu_mr) | |
731 | { | |
732 | return (IOMMUMemoryRegionClass *) (((Object *)iommu_mr)->class); | |
733 | } | |
734 | ||
3df9d748 | 735 | #define memory_region_is_iommu(mr) (memory_region_get_iommu(mr) != NULL) |
30951157 | 736 | |
f682e9c2 AK |
737 | /** |
738 | * memory_region_iommu_get_min_page_size: get minimum supported page size | |
739 | * for an iommu | |
740 | * | |
741 | * Returns minimum supported page size for an iommu. | |
742 | * | |
3df9d748 | 743 | * @iommu_mr: the memory region being queried |
f682e9c2 | 744 | */ |
3df9d748 | 745 | uint64_t memory_region_iommu_get_min_page_size(IOMMUMemoryRegion *iommu_mr); |
f682e9c2 | 746 | |
06866575 DG |
747 | /** |
748 | * memory_region_notify_iommu: notify a change in an IOMMU translation entry. | |
749 | * | |
cdb30812 PX |
750 | * The notification type will be decided by entry.perm bits: |
751 | * | |
752 | * - For UNMAP (cache invalidation) notifies: set entry.perm to IOMMU_NONE. | |
753 | * - For MAP (newly added entry) notifies: set entry.perm to the | |
754 | * permission of the page (which is definitely !IOMMU_NONE). | |
755 | * | |
756 | * Note: for any IOMMU implementation, an in-place mapping change | |
757 | * should be notified with an UNMAP followed by a MAP. | |
758 | * | |
3df9d748 | 759 | * @iommu_mr: the memory region that was changed |
06866575 DG |
760 | * @entry: the new entry in the IOMMU translation table. The entry |
761 | * replaces all old entries for the same virtual I/O address range. | |
762 | * Deleted entries have .@perm == 0. | |
763 | */ | |
3df9d748 | 764 | void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, |
06866575 DG |
765 | IOMMUTLBEntry entry); |
766 | ||
bd2bfa4c PX |
767 | /** |
768 | * memory_region_notify_one: notify a change in an IOMMU translation | |
769 | * entry to a single notifier | |
770 | * | |
771 | * This works just like memory_region_notify_iommu(), but it only | |
772 | * notifies a specific notifier, not all of them. | |
773 | * | |
774 | * @notifier: the notifier to be notified | |
775 | * @entry: the new entry in the IOMMU translation table. The entry | |
776 | * replaces all old entries for the same virtual I/O address range. | |
777 | * Deleted entries have .@perm == 0. | |
778 | */ | |
779 | void memory_region_notify_one(IOMMUNotifier *notifier, | |
780 | IOMMUTLBEntry *entry); | |
781 | ||
06866575 DG |
782 | /** |
783 | * memory_region_register_iommu_notifier: register a notifier for changes to | |
784 | * IOMMU translation entries. | |
785 | * | |
786 | * @mr: the memory region to observe | |
cdb30812 PX |
787 | * @n: the IOMMUNotifier to be added; the notify callback receives a |
788 | * pointer to an #IOMMUTLBEntry as the opaque value; the pointer | |
789 | * ceases to be valid on exit from the notifier. | |
06866575 | 790 | */ |
cdb30812 PX |
791 | void memory_region_register_iommu_notifier(MemoryRegion *mr, |
792 | IOMMUNotifier *n); | |
06866575 | 793 | |
a788f227 DG |
794 | /** |
795 | * memory_region_iommu_replay: replay existing IOMMU translations to | |
f682e9c2 AK |
796 | * a notifier with the minimum page granularity returned by |
797 | * mr->iommu_ops->get_page_size(). | |
a788f227 | 798 | * |
3df9d748 | 799 | * @iommu_mr: the memory region to observe |
a788f227 | 800 | * @n: the notifier to which to replay iommu mappings |
a788f227 | 801 | */ |
3df9d748 | 802 | void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n); |
a788f227 | 803 | |
de472e4a PX |
804 | /** |
805 | * memory_region_iommu_replay_all: replay existing IOMMU translations | |
806 | * to all the notifiers registered. | |
807 | * | |
3df9d748 | 808 | * @iommu_mr: the memory region to observe |
de472e4a | 809 | */ |
3df9d748 | 810 | void memory_region_iommu_replay_all(IOMMUMemoryRegion *iommu_mr); |
de472e4a | 811 | |
06866575 DG |
812 | /** |
813 | * memory_region_unregister_iommu_notifier: unregister a notifier for | |
814 | * changes to IOMMU translation entries. | |
815 | * | |
d22d8956 AK |
816 | * @mr: the memory region which was observed and for which notity_stopped() |
817 | * needs to be called | |
06866575 DG |
818 | * @n: the notifier to be removed. |
819 | */ | |
cdb30812 PX |
820 | void memory_region_unregister_iommu_notifier(MemoryRegion *mr, |
821 | IOMMUNotifier *n); | |
06866575 | 822 | |
8991c79b AK |
823 | /** |
824 | * memory_region_name: get a memory region's name | |
825 | * | |
826 | * Returns the string that was used to initialize the memory region. | |
827 | * | |
828 | * @mr: the memory region being queried | |
829 | */ | |
5d546d4b | 830 | const char *memory_region_name(const MemoryRegion *mr); |
8991c79b | 831 | |
55043ba3 AK |
832 | /** |
833 | * memory_region_is_logging: return whether a memory region is logging writes | |
834 | * | |
2d1a35be | 835 | * Returns %true if the memory region is logging writes for the given client |
55043ba3 AK |
836 | * |
837 | * @mr: the memory region being queried | |
2d1a35be | 838 | * @client: the client being queried |
55043ba3 | 839 | */ |
2d1a35be PB |
840 | bool memory_region_is_logging(MemoryRegion *mr, uint8_t client); |
841 | ||
842 | /** | |
843 | * memory_region_get_dirty_log_mask: return the clients for which a | |
844 | * memory region is logging writes. | |
845 | * | |
677e7805 PB |
846 | * Returns a bitmap of clients, in which the DIRTY_MEMORY_* constants |
847 | * are the bit indices. | |
2d1a35be PB |
848 | * |
849 | * @mr: the memory region being queried | |
850 | */ | |
851 | uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr); | |
55043ba3 | 852 | |
ce7923da AK |
853 | /** |
854 | * memory_region_is_rom: check whether a memory region is ROM | |
855 | * | |
856 | * Returns %true is a memory region is read-only memory. | |
857 | * | |
858 | * @mr: the memory region being queried | |
859 | */ | |
1619d1fe PB |
860 | static inline bool memory_region_is_rom(MemoryRegion *mr) |
861 | { | |
862 | return mr->ram && mr->readonly; | |
863 | } | |
864 | ||
ce7923da | 865 | |
a35ba7be PB |
866 | /** |
867 | * memory_region_get_fd: Get a file descriptor backing a RAM memory region. | |
868 | * | |
869 | * Returns a file descriptor backing a file-based RAM memory region, | |
870 | * or -1 if the region is not a file-based RAM memory region. | |
871 | * | |
872 | * @mr: the RAM or alias memory region being queried. | |
873 | */ | |
874 | int memory_region_get_fd(MemoryRegion *mr); | |
875 | ||
07bdaa41 PB |
876 | /** |
877 | * memory_region_from_host: Convert a pointer into a RAM memory region | |
878 | * and an offset within it. | |
879 | * | |
880 | * Given a host pointer inside a RAM memory region (created with | |
881 | * memory_region_init_ram() or memory_region_init_ram_ptr()), return | |
882 | * the MemoryRegion and the offset within it. | |
883 | * | |
884 | * Use with care; by the time this function returns, the returned pointer is | |
885 | * not protected by RCU anymore. If the caller is not within an RCU critical | |
886 | * section and does not hold the iothread lock, it must have other means of | |
887 | * protecting the pointer, such as a reference to the region that includes | |
888 | * the incoming ram_addr_t. | |
889 | * | |
890 | * @mr: the memory region being queried. | |
891 | */ | |
892 | MemoryRegion *memory_region_from_host(void *ptr, ram_addr_t *offset); | |
893 | ||
093bc2cd AK |
894 | /** |
895 | * memory_region_get_ram_ptr: Get a pointer into a RAM memory region. | |
896 | * | |
897 | * Returns a host pointer to a RAM memory region (created with | |
49b24afc PB |
898 | * memory_region_init_ram() or memory_region_init_ram_ptr()). |
899 | * | |
900 | * Use with care; by the time this function returns, the returned pointer is | |
901 | * not protected by RCU anymore. If the caller is not within an RCU critical | |
902 | * section and does not hold the iothread lock, it must have other means of | |
903 | * protecting the pointer, such as a reference to the region that includes | |
904 | * the incoming ram_addr_t. | |
093bc2cd AK |
905 | * |
906 | * @mr: the memory region being queried. | |
907 | */ | |
908 | void *memory_region_get_ram_ptr(MemoryRegion *mr); | |
909 | ||
37d7c084 PB |
910 | /* memory_region_ram_resize: Resize a RAM region. |
911 | * | |
912 | * Only legal before guest might have detected the memory size: e.g. on | |
913 | * incoming migration, or right after reset. | |
914 | * | |
915 | * @mr: a memory region created with @memory_region_init_resizeable_ram. | |
916 | * @newsize: the new size the region | |
917 | * @errp: pointer to Error*, to store an error if it happens. | |
918 | */ | |
919 | void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, | |
920 | Error **errp); | |
921 | ||
093bc2cd AK |
922 | /** |
923 | * memory_region_set_log: Turn dirty logging on or off for a region. | |
924 | * | |
925 | * Turns dirty logging on or off for a specified client (display, migration). | |
926 | * Only meaningful for RAM regions. | |
927 | * | |
928 | * @mr: the memory region being updated. | |
929 | * @log: whether dirty logging is to be enabled or disabled. | |
dbddac6d | 930 | * @client: the user of the logging information; %DIRTY_MEMORY_VGA only. |
093bc2cd AK |
931 | */ |
932 | void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client); | |
933 | ||
934 | /** | |
cd7a45c9 BS |
935 | * memory_region_get_dirty: Check whether a range of bytes is dirty |
936 | * for a specified client. | |
093bc2cd | 937 | * |
cd7a45c9 | 938 | * Checks whether a range of bytes has been written to since the last |
093bc2cd AK |
939 | * call to memory_region_reset_dirty() with the same @client. Dirty logging |
940 | * must be enabled. | |
941 | * | |
942 | * @mr: the memory region being queried. | |
943 | * @addr: the address (relative to the start of the region) being queried. | |
cd7a45c9 | 944 | * @size: the size of the range being queried. |
093bc2cd AK |
945 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or |
946 | * %DIRTY_MEMORY_VGA. | |
947 | */ | |
a8170e5e AK |
948 | bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr, |
949 | hwaddr size, unsigned client); | |
093bc2cd AK |
950 | |
951 | /** | |
fd4aa979 | 952 | * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region. |
093bc2cd | 953 | * |
fd4aa979 BS |
954 | * Marks a range of bytes as dirty, after it has been dirtied outside |
955 | * guest code. | |
093bc2cd | 956 | * |
fd4aa979 | 957 | * @mr: the memory region being dirtied. |
093bc2cd | 958 | * @addr: the address (relative to the start of the region) being dirtied. |
fd4aa979 | 959 | * @size: size of the range being dirtied. |
093bc2cd | 960 | */ |
a8170e5e AK |
961 | void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, |
962 | hwaddr size); | |
093bc2cd | 963 | |
6c279db8 JQ |
964 | /** |
965 | * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty | |
966 | * for a specified client. It clears them. | |
967 | * | |
968 | * Checks whether a range of bytes has been written to since the last | |
969 | * call to memory_region_reset_dirty() with the same @client. Dirty logging | |
970 | * must be enabled. | |
971 | * | |
972 | * @mr: the memory region being queried. | |
973 | * @addr: the address (relative to the start of the region) being queried. | |
974 | * @size: the size of the range being queried. | |
975 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
976 | * %DIRTY_MEMORY_VGA. | |
977 | */ | |
978 | bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, | |
979 | hwaddr size, unsigned client); | |
8deaf12c GH |
980 | |
981 | /** | |
982 | * memory_region_snapshot_and_clear_dirty: Get a snapshot of the dirty | |
983 | * bitmap and clear it. | |
984 | * | |
985 | * Creates a snapshot of the dirty bitmap, clears the dirty bitmap and | |
986 | * returns the snapshot. The snapshot can then be used to query dirty | |
987 | * status, using memory_region_snapshot_get_dirty. Unlike | |
988 | * memory_region_test_and_clear_dirty this allows to query the same | |
989 | * page multiple times, which is especially useful for display updates | |
990 | * where the scanlines often are not page aligned. | |
991 | * | |
992 | * The dirty bitmap region which gets copyed into the snapshot (and | |
993 | * cleared afterwards) can be larger than requested. The boundaries | |
994 | * are rounded up/down so complete bitmap longs (covering 64 pages on | |
995 | * 64bit hosts) can be copied over into the bitmap snapshot. Which | |
996 | * isn't a problem for display updates as the extra pages are outside | |
997 | * the visible area, and in case the visible area changes a full | |
998 | * display redraw is due anyway. Should other use cases for this | |
999 | * function emerge we might have to revisit this implementation | |
1000 | * detail. | |
1001 | * | |
1002 | * Use g_free to release DirtyBitmapSnapshot. | |
1003 | * | |
1004 | * @mr: the memory region being queried. | |
1005 | * @addr: the address (relative to the start of the region) being queried. | |
1006 | * @size: the size of the range being queried. | |
1007 | * @client: the user of the logging information; typically %DIRTY_MEMORY_VGA. | |
1008 | */ | |
1009 | DirtyBitmapSnapshot *memory_region_snapshot_and_clear_dirty(MemoryRegion *mr, | |
1010 | hwaddr addr, | |
1011 | hwaddr size, | |
1012 | unsigned client); | |
1013 | ||
1014 | /** | |
1015 | * memory_region_snapshot_get_dirty: Check whether a range of bytes is dirty | |
1016 | * in the specified dirty bitmap snapshot. | |
1017 | * | |
1018 | * @mr: the memory region being queried. | |
1019 | * @snap: the dirty bitmap snapshot | |
1020 | * @addr: the address (relative to the start of the region) being queried. | |
1021 | * @size: the size of the range being queried. | |
1022 | */ | |
1023 | bool memory_region_snapshot_get_dirty(MemoryRegion *mr, | |
1024 | DirtyBitmapSnapshot *snap, | |
1025 | hwaddr addr, hwaddr size); | |
1026 | ||
093bc2cd AK |
1027 | /** |
1028 | * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with | |
1029 | * any external TLBs (e.g. kvm) | |
1030 | * | |
1031 | * Flushes dirty information from accelerators such as kvm and vhost-net | |
1032 | * and makes it available to users of the memory API. | |
1033 | * | |
1034 | * @mr: the region being flushed. | |
1035 | */ | |
1036 | void memory_region_sync_dirty_bitmap(MemoryRegion *mr); | |
1037 | ||
1038 | /** | |
1039 | * memory_region_reset_dirty: Mark a range of pages as clean, for a specified | |
1040 | * client. | |
1041 | * | |
1042 | * Marks a range of pages as no longer dirty. | |
1043 | * | |
1044 | * @mr: the region being updated. | |
1045 | * @addr: the start of the subrange being cleaned. | |
1046 | * @size: the size of the subrange being cleaned. | |
1047 | * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or | |
1048 | * %DIRTY_MEMORY_VGA. | |
1049 | */ | |
a8170e5e AK |
1050 | void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, |
1051 | hwaddr size, unsigned client); | |
093bc2cd AK |
1052 | |
1053 | /** | |
1054 | * memory_region_set_readonly: Turn a memory region read-only (or read-write) | |
1055 | * | |
1056 | * Allows a memory region to be marked as read-only (turning it into a ROM). | |
1057 | * only useful on RAM regions. | |
1058 | * | |
1059 | * @mr: the region being updated. | |
1060 | * @readonly: whether rhe region is to be ROM or RAM. | |
1061 | */ | |
1062 | void memory_region_set_readonly(MemoryRegion *mr, bool readonly); | |
1063 | ||
d0a9b5bc | 1064 | /** |
5f9a5ea1 | 1065 | * memory_region_rom_device_set_romd: enable/disable ROMD mode |
d0a9b5bc AK |
1066 | * |
1067 | * Allows a ROM device (initialized with memory_region_init_rom_device() to | |
5f9a5ea1 JK |
1068 | * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the |
1069 | * device is mapped to guest memory and satisfies read access directly. | |
1070 | * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function. | |
1071 | * Writes are always handled by the #MemoryRegion.write function. | |
d0a9b5bc AK |
1072 | * |
1073 | * @mr: the memory region to be updated | |
5f9a5ea1 | 1074 | * @romd_mode: %true to put the region into ROMD mode |
d0a9b5bc | 1075 | */ |
5f9a5ea1 | 1076 | void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode); |
d0a9b5bc | 1077 | |
093bc2cd AK |
1078 | /** |
1079 | * memory_region_set_coalescing: Enable memory coalescing for the region. | |
1080 | * | |
1081 | * Enabled writes to a region to be queued for later processing. MMIO ->write | |
1082 | * callbacks may be delayed until a non-coalesced MMIO is issued. | |
1083 | * Only useful for IO regions. Roughly similar to write-combining hardware. | |
1084 | * | |
1085 | * @mr: the memory region to be write coalesced | |
1086 | */ | |
1087 | void memory_region_set_coalescing(MemoryRegion *mr); | |
1088 | ||
1089 | /** | |
1090 | * memory_region_add_coalescing: Enable memory coalescing for a sub-range of | |
1091 | * a region. | |
1092 | * | |
1093 | * Like memory_region_set_coalescing(), but works on a sub-range of a region. | |
1094 | * Multiple calls can be issued coalesced disjoint ranges. | |
1095 | * | |
1096 | * @mr: the memory region to be updated. | |
1097 | * @offset: the start of the range within the region to be coalesced. | |
1098 | * @size: the size of the subrange to be coalesced. | |
1099 | */ | |
1100 | void memory_region_add_coalescing(MemoryRegion *mr, | |
a8170e5e | 1101 | hwaddr offset, |
093bc2cd AK |
1102 | uint64_t size); |
1103 | ||
1104 | /** | |
1105 | * memory_region_clear_coalescing: Disable MMIO coalescing for the region. | |
1106 | * | |
1107 | * Disables any coalescing caused by memory_region_set_coalescing() or | |
1108 | * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory | |
1109 | * hardware. | |
1110 | * | |
1111 | * @mr: the memory region to be updated. | |
1112 | */ | |
1113 | void memory_region_clear_coalescing(MemoryRegion *mr); | |
1114 | ||
d410515e JK |
1115 | /** |
1116 | * memory_region_set_flush_coalesced: Enforce memory coalescing flush before | |
1117 | * accesses. | |
1118 | * | |
1119 | * Ensure that pending coalesced MMIO request are flushed before the memory | |
1120 | * region is accessed. This property is automatically enabled for all regions | |
1121 | * passed to memory_region_set_coalescing() and memory_region_add_coalescing(). | |
1122 | * | |
1123 | * @mr: the memory region to be updated. | |
1124 | */ | |
1125 | void memory_region_set_flush_coalesced(MemoryRegion *mr); | |
1126 | ||
1127 | /** | |
1128 | * memory_region_clear_flush_coalesced: Disable memory coalescing flush before | |
1129 | * accesses. | |
1130 | * | |
1131 | * Clear the automatic coalesced MMIO flushing enabled via | |
1132 | * memory_region_set_flush_coalesced. Note that this service has no effect on | |
1133 | * memory regions that have MMIO coalescing enabled for themselves. For them, | |
1134 | * automatic flushing will stop once coalescing is disabled. | |
1135 | * | |
1136 | * @mr: the memory region to be updated. | |
1137 | */ | |
1138 | void memory_region_clear_flush_coalesced(MemoryRegion *mr); | |
1139 | ||
196ea131 JK |
1140 | /** |
1141 | * memory_region_set_global_locking: Declares the access processing requires | |
1142 | * QEMU's global lock. | |
1143 | * | |
1144 | * When this is invoked, accesses to the memory region will be processed while | |
1145 | * holding the global lock of QEMU. This is the default behavior of memory | |
1146 | * regions. | |
1147 | * | |
1148 | * @mr: the memory region to be updated. | |
1149 | */ | |
1150 | void memory_region_set_global_locking(MemoryRegion *mr); | |
1151 | ||
1152 | /** | |
1153 | * memory_region_clear_global_locking: Declares that access processing does | |
1154 | * not depend on the QEMU global lock. | |
1155 | * | |
1156 | * By clearing this property, accesses to the memory region will be processed | |
1157 | * outside of QEMU's global lock (unless the lock is held on when issuing the | |
1158 | * access request). In this case, the device model implementing the access | |
1159 | * handlers is responsible for synchronization of concurrency. | |
1160 | * | |
1161 | * @mr: the memory region to be updated. | |
1162 | */ | |
1163 | void memory_region_clear_global_locking(MemoryRegion *mr); | |
1164 | ||
3e9d69e7 AK |
1165 | /** |
1166 | * memory_region_add_eventfd: Request an eventfd to be triggered when a word | |
1167 | * is written to a location. | |
1168 | * | |
1169 | * Marks a word in an IO region (initialized with memory_region_init_io()) | |
1170 | * as a trigger for an eventfd event. The I/O callback will not be called. | |
69ddaf66 | 1171 | * The caller must be prepared to handle failure (that is, take the required |
3e9d69e7 AK |
1172 | * action if the callback _is_ called). |
1173 | * | |
1174 | * @mr: the memory region being updated. | |
1175 | * @addr: the address within @mr that is to be monitored | |
1176 | * @size: the size of the access to trigger the eventfd | |
1177 | * @match_data: whether to match against @data, instead of just @addr | |
1178 | * @data: the data to match against the guest write | |
1179 | * @fd: the eventfd to be triggered when @addr, @size, and @data all match. | |
1180 | **/ | |
1181 | void memory_region_add_eventfd(MemoryRegion *mr, | |
a8170e5e | 1182 | hwaddr addr, |
3e9d69e7 AK |
1183 | unsigned size, |
1184 | bool match_data, | |
1185 | uint64_t data, | |
753d5e14 | 1186 | EventNotifier *e); |
3e9d69e7 AK |
1187 | |
1188 | /** | |
69ddaf66 | 1189 | * memory_region_del_eventfd: Cancel an eventfd. |
3e9d69e7 | 1190 | * |
69ddaf66 ASRJ |
1191 | * Cancels an eventfd trigger requested by a previous |
1192 | * memory_region_add_eventfd() call. | |
3e9d69e7 AK |
1193 | * |
1194 | * @mr: the memory region being updated. | |
1195 | * @addr: the address within @mr that is to be monitored | |
1196 | * @size: the size of the access to trigger the eventfd | |
1197 | * @match_data: whether to match against @data, instead of just @addr | |
1198 | * @data: the data to match against the guest write | |
1199 | * @fd: the eventfd to be triggered when @addr, @size, and @data all match. | |
1200 | */ | |
1201 | void memory_region_del_eventfd(MemoryRegion *mr, | |
a8170e5e | 1202 | hwaddr addr, |
3e9d69e7 AK |
1203 | unsigned size, |
1204 | bool match_data, | |
1205 | uint64_t data, | |
753d5e14 PB |
1206 | EventNotifier *e); |
1207 | ||
093bc2cd | 1208 | /** |
69ddaf66 | 1209 | * memory_region_add_subregion: Add a subregion to a container. |
093bc2cd | 1210 | * |
69ddaf66 | 1211 | * Adds a subregion at @offset. The subregion may not overlap with other |
093bc2cd AK |
1212 | * subregions (except for those explicitly marked as overlapping). A region |
1213 | * may only be added once as a subregion (unless removed with | |
1214 | * memory_region_del_subregion()); use memory_region_init_alias() if you | |
1215 | * want a region to be a subregion in multiple locations. | |
1216 | * | |
1217 | * @mr: the region to contain the new subregion; must be a container | |
1218 | * initialized with memory_region_init(). | |
1219 | * @offset: the offset relative to @mr where @subregion is added. | |
1220 | * @subregion: the subregion to be added. | |
1221 | */ | |
1222 | void memory_region_add_subregion(MemoryRegion *mr, | |
a8170e5e | 1223 | hwaddr offset, |
093bc2cd AK |
1224 | MemoryRegion *subregion); |
1225 | /** | |
1a7e8cae BZ |
1226 | * memory_region_add_subregion_overlap: Add a subregion to a container |
1227 | * with overlap. | |
093bc2cd | 1228 | * |
69ddaf66 | 1229 | * Adds a subregion at @offset. The subregion may overlap with other |
093bc2cd AK |
1230 | * subregions. Conflicts are resolved by having a higher @priority hide a |
1231 | * lower @priority. Subregions without priority are taken as @priority 0. | |
1232 | * A region may only be added once as a subregion (unless removed with | |
1233 | * memory_region_del_subregion()); use memory_region_init_alias() if you | |
1234 | * want a region to be a subregion in multiple locations. | |
1235 | * | |
1236 | * @mr: the region to contain the new subregion; must be a container | |
1237 | * initialized with memory_region_init(). | |
1238 | * @offset: the offset relative to @mr where @subregion is added. | |
1239 | * @subregion: the subregion to be added. | |
1240 | * @priority: used for resolving overlaps; highest priority wins. | |
1241 | */ | |
1242 | void memory_region_add_subregion_overlap(MemoryRegion *mr, | |
a8170e5e | 1243 | hwaddr offset, |
093bc2cd | 1244 | MemoryRegion *subregion, |
a1ff8ae0 | 1245 | int priority); |
e34911c4 AK |
1246 | |
1247 | /** | |
1248 | * memory_region_get_ram_addr: Get the ram address associated with a memory | |
1249 | * region | |
e34911c4 | 1250 | */ |
7ebb2745 | 1251 | ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr); |
e34911c4 | 1252 | |
a2b257d6 | 1253 | uint64_t memory_region_get_alignment(const MemoryRegion *mr); |
093bc2cd AK |
1254 | /** |
1255 | * memory_region_del_subregion: Remove a subregion. | |
1256 | * | |
1257 | * Removes a subregion from its container. | |
1258 | * | |
1259 | * @mr: the container to be updated. | |
1260 | * @subregion: the region being removed; must be a current subregion of @mr. | |
1261 | */ | |
1262 | void memory_region_del_subregion(MemoryRegion *mr, | |
1263 | MemoryRegion *subregion); | |
1264 | ||
6bba19ba AK |
1265 | /* |
1266 | * memory_region_set_enabled: dynamically enable or disable a region | |
1267 | * | |
1268 | * Enables or disables a memory region. A disabled memory region | |
1269 | * ignores all accesses to itself and its subregions. It does not | |
1270 | * obscure sibling subregions with lower priority - it simply behaves as | |
1271 | * if it was removed from the hierarchy. | |
1272 | * | |
1273 | * Regions default to being enabled. | |
1274 | * | |
1275 | * @mr: the region to be updated | |
1276 | * @enabled: whether to enable or disable the region | |
1277 | */ | |
1278 | void memory_region_set_enabled(MemoryRegion *mr, bool enabled); | |
1279 | ||
2282e1af AK |
1280 | /* |
1281 | * memory_region_set_address: dynamically update the address of a region | |
1282 | * | |
feca4ac1 | 1283 | * Dynamically updates the address of a region, relative to its container. |
2282e1af AK |
1284 | * May be used on regions are currently part of a memory hierarchy. |
1285 | * | |
1286 | * @mr: the region to be updated | |
feca4ac1 | 1287 | * @addr: new address, relative to container region |
2282e1af | 1288 | */ |
a8170e5e | 1289 | void memory_region_set_address(MemoryRegion *mr, hwaddr addr); |
2282e1af | 1290 | |
e7af4c67 MT |
1291 | /* |
1292 | * memory_region_set_size: dynamically update the size of a region. | |
1293 | * | |
1294 | * Dynamically updates the size of a region. | |
1295 | * | |
1296 | * @mr: the region to be updated | |
1297 | * @size: used size of the region. | |
1298 | */ | |
1299 | void memory_region_set_size(MemoryRegion *mr, uint64_t size); | |
1300 | ||
4703359e AK |
1301 | /* |
1302 | * memory_region_set_alias_offset: dynamically update a memory alias's offset | |
1303 | * | |
1304 | * Dynamically updates the offset into the target region that an alias points | |
1305 | * to, as if the fourth argument to memory_region_init_alias() has changed. | |
1306 | * | |
1307 | * @mr: the #MemoryRegion to be updated; should be an alias. | |
1308 | * @offset: the new offset into the target memory region | |
1309 | */ | |
1310 | void memory_region_set_alias_offset(MemoryRegion *mr, | |
a8170e5e | 1311 | hwaddr offset); |
4703359e | 1312 | |
3ce10901 | 1313 | /** |
feca4ac1 PB |
1314 | * memory_region_present: checks if an address relative to a @container |
1315 | * translates into #MemoryRegion within @container | |
3ce10901 | 1316 | * |
feca4ac1 | 1317 | * Answer whether a #MemoryRegion within @container covers the address |
3ce10901 PB |
1318 | * @addr. |
1319 | * | |
feca4ac1 PB |
1320 | * @container: a #MemoryRegion within which @addr is a relative address |
1321 | * @addr: the area within @container to be searched | |
3ce10901 | 1322 | */ |
feca4ac1 | 1323 | bool memory_region_present(MemoryRegion *container, hwaddr addr); |
3ce10901 | 1324 | |
eed2bacf IM |
1325 | /** |
1326 | * memory_region_is_mapped: returns true if #MemoryRegion is mapped | |
1327 | * into any address space. | |
1328 | * | |
1329 | * @mr: a #MemoryRegion which should be checked if it's mapped | |
1330 | */ | |
1331 | bool memory_region_is_mapped(MemoryRegion *mr); | |
1332 | ||
e2177955 | 1333 | /** |
73034e9e PB |
1334 | * memory_region_find: translate an address/size relative to a |
1335 | * MemoryRegion into a #MemoryRegionSection. | |
e2177955 | 1336 | * |
73034e9e PB |
1337 | * Locates the first #MemoryRegion within @mr that overlaps the range |
1338 | * given by @addr and @size. | |
e2177955 AK |
1339 | * |
1340 | * Returns a #MemoryRegionSection that describes a contiguous overlap. | |
1341 | * It will have the following characteristics: | |
e2177955 AK |
1342 | * .@size = 0 iff no overlap was found |
1343 | * .@mr is non-%NULL iff an overlap was found | |
1344 | * | |
73034e9e PB |
1345 | * Remember that in the return value the @offset_within_region is |
1346 | * relative to the returned region (in the .@mr field), not to the | |
1347 | * @mr argument. | |
1348 | * | |
1349 | * Similarly, the .@offset_within_address_space is relative to the | |
1350 | * address space that contains both regions, the passed and the | |
1351 | * returned one. However, in the special case where the @mr argument | |
feca4ac1 | 1352 | * has no container (and thus is the root of the address space), the |
73034e9e PB |
1353 | * following will hold: |
1354 | * .@offset_within_address_space >= @addr | |
1355 | * .@offset_within_address_space + .@size <= @addr + @size | |
1356 | * | |
1357 | * @mr: a MemoryRegion within which @addr is a relative address | |
1358 | * @addr: start of the area within @as to be searched | |
e2177955 AK |
1359 | * @size: size of the area to be searched |
1360 | */ | |
73034e9e | 1361 | MemoryRegionSection memory_region_find(MemoryRegion *mr, |
a8170e5e | 1362 | hwaddr addr, uint64_t size); |
e2177955 | 1363 | |
86e775c6 | 1364 | /** |
9c1f8f44 | 1365 | * memory_global_dirty_log_sync: synchronize the dirty log for all memory |
86e775c6 | 1366 | * |
9c1f8f44 | 1367 | * Synchronizes the dirty page log for all address spaces. |
86e775c6 | 1368 | */ |
9c1f8f44 | 1369 | void memory_global_dirty_log_sync(void); |
86e775c6 | 1370 | |
69ddaf66 ASRJ |
1371 | /** |
1372 | * memory_region_transaction_begin: Start a transaction. | |
1373 | * | |
1374 | * During a transaction, changes will be accumulated and made visible | |
dabdf394 | 1375 | * only when the transaction ends (is committed). |
4ef4db86 AK |
1376 | */ |
1377 | void memory_region_transaction_begin(void); | |
69ddaf66 ASRJ |
1378 | |
1379 | /** | |
1380 | * memory_region_transaction_commit: Commit a transaction and make changes | |
1381 | * visible to the guest. | |
4ef4db86 AK |
1382 | */ |
1383 | void memory_region_transaction_commit(void); | |
1384 | ||
7664e80c AK |
1385 | /** |
1386 | * memory_listener_register: register callbacks to be called when memory | |
1387 | * sections are mapped or unmapped into an address | |
1388 | * space | |
1389 | * | |
1390 | * @listener: an object containing the callbacks to be called | |
7376e582 | 1391 | * @filter: if non-%NULL, only regions in this address space will be observed |
7664e80c | 1392 | */ |
f6790af6 | 1393 | void memory_listener_register(MemoryListener *listener, AddressSpace *filter); |
7664e80c AK |
1394 | |
1395 | /** | |
1396 | * memory_listener_unregister: undo the effect of memory_listener_register() | |
1397 | * | |
1398 | * @listener: an object containing the callbacks to be removed | |
1399 | */ | |
1400 | void memory_listener_unregister(MemoryListener *listener); | |
1401 | ||
1402 | /** | |
1403 | * memory_global_dirty_log_start: begin dirty logging for all regions | |
1404 | */ | |
1405 | void memory_global_dirty_log_start(void); | |
1406 | ||
1407 | /** | |
1a7e8cae | 1408 | * memory_global_dirty_log_stop: end dirty logging for all regions |
7664e80c AK |
1409 | */ |
1410 | void memory_global_dirty_log_stop(void); | |
1411 | ||
57bb40c9 | 1412 | void mtree_info(fprintf_function mon_printf, void *f, bool flatview); |
314e2987 | 1413 | |
c9356746 FK |
1414 | /** |
1415 | * memory_region_request_mmio_ptr: request a pointer to an mmio | |
1416 | * MemoryRegion. If it is possible map a RAM MemoryRegion with this pointer. | |
1417 | * When the device wants to invalidate the pointer it will call | |
1418 | * memory_region_invalidate_mmio_ptr. | |
1419 | * | |
1420 | * @mr: #MemoryRegion to check | |
1421 | * @addr: address within that region | |
1422 | * | |
1423 | * Returns true on success, false otherwise. | |
1424 | */ | |
1425 | bool memory_region_request_mmio_ptr(MemoryRegion *mr, hwaddr addr); | |
1426 | ||
1427 | /** | |
1428 | * memory_region_invalidate_mmio_ptr: invalidate the pointer to an mmio | |
1429 | * previously requested. | |
1430 | * In the end that means that if something wants to execute from this area it | |
1431 | * will need to request the pointer again. | |
1432 | * | |
1433 | * @mr: #MemoryRegion associated to the pointer. | |
1434 | * @addr: address within that region | |
1435 | * @size: size of that area. | |
1436 | */ | |
1437 | void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset, | |
1438 | unsigned size); | |
1439 | ||
3b643495 PM |
1440 | /** |
1441 | * memory_region_dispatch_read: perform a read directly to the specified | |
1442 | * MemoryRegion. | |
1443 | * | |
1444 | * @mr: #MemoryRegion to access | |
1445 | * @addr: address within that region | |
1446 | * @pval: pointer to uint64_t which the data is written to | |
1447 | * @size: size of the access in bytes | |
1448 | * @attrs: memory transaction attributes to use for the access | |
1449 | */ | |
1450 | MemTxResult memory_region_dispatch_read(MemoryRegion *mr, | |
1451 | hwaddr addr, | |
1452 | uint64_t *pval, | |
1453 | unsigned size, | |
1454 | MemTxAttrs attrs); | |
1455 | /** | |
1456 | * memory_region_dispatch_write: perform a write directly to the specified | |
1457 | * MemoryRegion. | |
1458 | * | |
1459 | * @mr: #MemoryRegion to access | |
1460 | * @addr: address within that region | |
1461 | * @data: data to write | |
1462 | * @size: size of the access in bytes | |
1463 | * @attrs: memory transaction attributes to use for the access | |
1464 | */ | |
1465 | MemTxResult memory_region_dispatch_write(MemoryRegion *mr, | |
1466 | hwaddr addr, | |
1467 | uint64_t data, | |
1468 | unsigned size, | |
1469 | MemTxAttrs attrs); | |
1470 | ||
9ad2bbc1 AK |
1471 | /** |
1472 | * address_space_init: initializes an address space | |
1473 | * | |
1474 | * @as: an uninitialized #AddressSpace | |
67cc32eb | 1475 | * @root: a #MemoryRegion that routes addresses for the address space |
7dca8043 AK |
1476 | * @name: an address space name. The name is only used for debugging |
1477 | * output. | |
9ad2bbc1 | 1478 | */ |
7dca8043 | 1479 | void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name); |
9ad2bbc1 | 1480 | |
f0c02d15 PC |
1481 | /** |
1482 | * address_space_init_shareable: return an address space for a memory region, | |
1483 | * creating it if it does not already exist | |
1484 | * | |
1485 | * @root: a #MemoryRegion that routes addresses for the address space | |
1486 | * @name: an address space name. The name is only used for debugging | |
1487 | * output. | |
1488 | * | |
1489 | * This function will return a pointer to an existing AddressSpace | |
1490 | * which was initialized with the specified MemoryRegion, or it will | |
1491 | * create and initialize one if it does not already exist. The ASes | |
1492 | * are reference-counted, so the memory will be freed automatically | |
1493 | * when the AddressSpace is destroyed via address_space_destroy. | |
1494 | */ | |
1495 | AddressSpace *address_space_init_shareable(MemoryRegion *root, | |
1496 | const char *name); | |
83f3c251 AK |
1497 | |
1498 | /** | |
1499 | * address_space_destroy: destroy an address space | |
1500 | * | |
1501 | * Releases all resources associated with an address space. After an address space | |
1502 | * is destroyed, its root memory region (given by address_space_init()) may be destroyed | |
1503 | * as well. | |
1504 | * | |
1505 | * @as: address space to be destroyed | |
1506 | */ | |
1507 | void address_space_destroy(AddressSpace *as); | |
1508 | ||
ac1970fb AK |
1509 | /** |
1510 | * address_space_rw: read from or write to an address space. | |
1511 | * | |
5c9eb028 PM |
1512 | * Return a MemTxResult indicating whether the operation succeeded |
1513 | * or failed (eg unassigned memory, device rejected the transaction, | |
1514 | * IOMMU fault). | |
fd8aaa76 | 1515 | * |
ac1970fb AK |
1516 | * @as: #AddressSpace to be accessed |
1517 | * @addr: address within that address space | |
5c9eb028 | 1518 | * @attrs: memory transaction attributes |
ac1970fb AK |
1519 | * @buf: buffer with the data transferred |
1520 | * @is_write: indicates the transfer direction | |
1521 | */ | |
5c9eb028 PM |
1522 | MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, |
1523 | MemTxAttrs attrs, uint8_t *buf, | |
1524 | int len, bool is_write); | |
ac1970fb AK |
1525 | |
1526 | /** | |
1527 | * address_space_write: write to address space. | |
1528 | * | |
5c9eb028 PM |
1529 | * Return a MemTxResult indicating whether the operation succeeded |
1530 | * or failed (eg unassigned memory, device rejected the transaction, | |
1531 | * IOMMU fault). | |
fd8aaa76 | 1532 | * |
ac1970fb AK |
1533 | * @as: #AddressSpace to be accessed |
1534 | * @addr: address within that address space | |
5c9eb028 | 1535 | * @attrs: memory transaction attributes |
ac1970fb AK |
1536 | * @buf: buffer with the data transferred |
1537 | */ | |
5c9eb028 PM |
1538 | MemTxResult address_space_write(AddressSpace *as, hwaddr addr, |
1539 | MemTxAttrs attrs, | |
1540 | const uint8_t *buf, int len); | |
ac1970fb | 1541 | |
3cc8f884 | 1542 | /* address_space_ld*: load from an address space |
50013115 PM |
1543 | * address_space_st*: store to an address space |
1544 | * | |
1545 | * These functions perform a load or store of the byte, word, | |
1546 | * longword or quad to the specified address within the AddressSpace. | |
1547 | * The _le suffixed functions treat the data as little endian; | |
1548 | * _be indicates big endian; no suffix indicates "same endianness | |
1549 | * as guest CPU". | |
1550 | * | |
1551 | * The "guest CPU endianness" accessors are deprecated for use outside | |
1552 | * target-* code; devices should be CPU-agnostic and use either the LE | |
1553 | * or the BE accessors. | |
1554 | * | |
1555 | * @as #AddressSpace to be accessed | |
1556 | * @addr: address within that address space | |
1557 | * @val: data value, for stores | |
1558 | * @attrs: memory transaction attributes | |
1559 | * @result: location to write the success/failure of the transaction; | |
1560 | * if NULL, this information is discarded | |
1561 | */ | |
1562 | uint32_t address_space_ldub(AddressSpace *as, hwaddr addr, | |
1563 | MemTxAttrs attrs, MemTxResult *result); | |
1564 | uint32_t address_space_lduw_le(AddressSpace *as, hwaddr addr, | |
1565 | MemTxAttrs attrs, MemTxResult *result); | |
1566 | uint32_t address_space_lduw_be(AddressSpace *as, hwaddr addr, | |
1567 | MemTxAttrs attrs, MemTxResult *result); | |
1568 | uint32_t address_space_ldl_le(AddressSpace *as, hwaddr addr, | |
1569 | MemTxAttrs attrs, MemTxResult *result); | |
1570 | uint32_t address_space_ldl_be(AddressSpace *as, hwaddr addr, | |
1571 | MemTxAttrs attrs, MemTxResult *result); | |
1572 | uint64_t address_space_ldq_le(AddressSpace *as, hwaddr addr, | |
1573 | MemTxAttrs attrs, MemTxResult *result); | |
1574 | uint64_t address_space_ldq_be(AddressSpace *as, hwaddr addr, | |
1575 | MemTxAttrs attrs, MemTxResult *result); | |
1576 | void address_space_stb(AddressSpace *as, hwaddr addr, uint32_t val, | |
1577 | MemTxAttrs attrs, MemTxResult *result); | |
1578 | void address_space_stw_le(AddressSpace *as, hwaddr addr, uint32_t val, | |
1579 | MemTxAttrs attrs, MemTxResult *result); | |
1580 | void address_space_stw_be(AddressSpace *as, hwaddr addr, uint32_t val, | |
1581 | MemTxAttrs attrs, MemTxResult *result); | |
1582 | void address_space_stl_le(AddressSpace *as, hwaddr addr, uint32_t val, | |
1583 | MemTxAttrs attrs, MemTxResult *result); | |
1584 | void address_space_stl_be(AddressSpace *as, hwaddr addr, uint32_t val, | |
1585 | MemTxAttrs attrs, MemTxResult *result); | |
1586 | void address_space_stq_le(AddressSpace *as, hwaddr addr, uint64_t val, | |
1587 | MemTxAttrs attrs, MemTxResult *result); | |
1588 | void address_space_stq_be(AddressSpace *as, hwaddr addr, uint64_t val, | |
1589 | MemTxAttrs attrs, MemTxResult *result); | |
1590 | ||
0ce265ff PB |
1591 | uint32_t ldub_phys(AddressSpace *as, hwaddr addr); |
1592 | uint32_t lduw_le_phys(AddressSpace *as, hwaddr addr); | |
1593 | uint32_t lduw_be_phys(AddressSpace *as, hwaddr addr); | |
1594 | uint32_t ldl_le_phys(AddressSpace *as, hwaddr addr); | |
1595 | uint32_t ldl_be_phys(AddressSpace *as, hwaddr addr); | |
1596 | uint64_t ldq_le_phys(AddressSpace *as, hwaddr addr); | |
1597 | uint64_t ldq_be_phys(AddressSpace *as, hwaddr addr); | |
1598 | void stb_phys(AddressSpace *as, hwaddr addr, uint32_t val); | |
1599 | void stw_le_phys(AddressSpace *as, hwaddr addr, uint32_t val); | |
1600 | void stw_be_phys(AddressSpace *as, hwaddr addr, uint32_t val); | |
1601 | void stl_le_phys(AddressSpace *as, hwaddr addr, uint32_t val); | |
1602 | void stl_be_phys(AddressSpace *as, hwaddr addr, uint32_t val); | |
1603 | void stq_le_phys(AddressSpace *as, hwaddr addr, uint64_t val); | |
1604 | void stq_be_phys(AddressSpace *as, hwaddr addr, uint64_t val); | |
1605 | ||
1f4e496e PB |
1606 | struct MemoryRegionCache { |
1607 | hwaddr xlat; | |
1f4e496e | 1608 | hwaddr len; |
90c4fe5f | 1609 | AddressSpace *as; |
1f4e496e PB |
1610 | }; |
1611 | ||
90c4fe5f | 1612 | #define MEMORY_REGION_CACHE_INVALID ((MemoryRegionCache) { .as = NULL }) |
5eba0404 | 1613 | |
1f4e496e PB |
1614 | /* address_space_cache_init: prepare for repeated access to a physical |
1615 | * memory region | |
1616 | * | |
1617 | * @cache: #MemoryRegionCache to be filled | |
1618 | * @as: #AddressSpace to be accessed | |
1619 | * @addr: address within that address space | |
1620 | * @len: length of buffer | |
1621 | * @is_write: indicates the transfer direction | |
1622 | * | |
1623 | * Will only work with RAM, and may map a subset of the requested range by | |
1624 | * returning a value that is less than @len. On failure, return a negative | |
1625 | * errno value. | |
1626 | * | |
1627 | * Because it only works with RAM, this function can be used for | |
1628 | * read-modify-write operations. In this case, is_write should be %true. | |
1629 | * | |
1630 | * Note that addresses passed to the address_space_*_cached functions | |
1631 | * are relative to @addr. | |
1632 | */ | |
1633 | int64_t address_space_cache_init(MemoryRegionCache *cache, | |
1634 | AddressSpace *as, | |
1635 | hwaddr addr, | |
1636 | hwaddr len, | |
1637 | bool is_write); | |
1638 | ||
1639 | /** | |
1640 | * address_space_cache_invalidate: complete a write to a #MemoryRegionCache | |
1641 | * | |
1642 | * @cache: The #MemoryRegionCache to operate on. | |
1643 | * @addr: The first physical address that was written, relative to the | |
1644 | * address that was passed to @address_space_cache_init. | |
1645 | * @access_len: The number of bytes that were written starting at @addr. | |
1646 | */ | |
1647 | void address_space_cache_invalidate(MemoryRegionCache *cache, | |
1648 | hwaddr addr, | |
1649 | hwaddr access_len); | |
1650 | ||
1651 | /** | |
1652 | * address_space_cache_destroy: free a #MemoryRegionCache | |
1653 | * | |
1654 | * @cache: The #MemoryRegionCache whose memory should be released. | |
1655 | */ | |
1656 | void address_space_cache_destroy(MemoryRegionCache *cache); | |
1657 | ||
1658 | /* address_space_ld*_cached: load from a cached #MemoryRegion | |
1659 | * address_space_st*_cached: store into a cached #MemoryRegion | |
1660 | * | |
1661 | * These functions perform a load or store of the byte, word, | |
1662 | * longword or quad to the specified address. The address is | |
1663 | * a physical address in the AddressSpace, but it must lie within | |
1664 | * a #MemoryRegion that was mapped with address_space_cache_init. | |
1665 | * | |
1666 | * The _le suffixed functions treat the data as little endian; | |
1667 | * _be indicates big endian; no suffix indicates "same endianness | |
1668 | * as guest CPU". | |
1669 | * | |
1670 | * The "guest CPU endianness" accessors are deprecated for use outside | |
1671 | * target-* code; devices should be CPU-agnostic and use either the LE | |
1672 | * or the BE accessors. | |
1673 | * | |
1674 | * @cache: previously initialized #MemoryRegionCache to be accessed | |
1675 | * @addr: address within the address space | |
1676 | * @val: data value, for stores | |
1677 | * @attrs: memory transaction attributes | |
1678 | * @result: location to write the success/failure of the transaction; | |
1679 | * if NULL, this information is discarded | |
1680 | */ | |
1681 | uint32_t address_space_ldub_cached(MemoryRegionCache *cache, hwaddr addr, | |
1682 | MemTxAttrs attrs, MemTxResult *result); | |
1683 | uint32_t address_space_lduw_le_cached(MemoryRegionCache *cache, hwaddr addr, | |
1684 | MemTxAttrs attrs, MemTxResult *result); | |
1685 | uint32_t address_space_lduw_be_cached(MemoryRegionCache *cache, hwaddr addr, | |
1686 | MemTxAttrs attrs, MemTxResult *result); | |
1687 | uint32_t address_space_ldl_le_cached(MemoryRegionCache *cache, hwaddr addr, | |
1688 | MemTxAttrs attrs, MemTxResult *result); | |
1689 | uint32_t address_space_ldl_be_cached(MemoryRegionCache *cache, hwaddr addr, | |
1690 | MemTxAttrs attrs, MemTxResult *result); | |
1691 | uint64_t address_space_ldq_le_cached(MemoryRegionCache *cache, hwaddr addr, | |
1692 | MemTxAttrs attrs, MemTxResult *result); | |
1693 | uint64_t address_space_ldq_be_cached(MemoryRegionCache *cache, hwaddr addr, | |
1694 | MemTxAttrs attrs, MemTxResult *result); | |
1695 | void address_space_stb_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val, | |
1696 | MemTxAttrs attrs, MemTxResult *result); | |
1697 | void address_space_stw_le_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val, | |
1698 | MemTxAttrs attrs, MemTxResult *result); | |
1699 | void address_space_stw_be_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val, | |
1700 | MemTxAttrs attrs, MemTxResult *result); | |
1701 | void address_space_stl_le_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val, | |
1702 | MemTxAttrs attrs, MemTxResult *result); | |
1703 | void address_space_stl_be_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val, | |
1704 | MemTxAttrs attrs, MemTxResult *result); | |
1705 | void address_space_stq_le_cached(MemoryRegionCache *cache, hwaddr addr, uint64_t val, | |
1706 | MemTxAttrs attrs, MemTxResult *result); | |
1707 | void address_space_stq_be_cached(MemoryRegionCache *cache, hwaddr addr, uint64_t val, | |
1708 | MemTxAttrs attrs, MemTxResult *result); | |
1709 | ||
1710 | uint32_t ldub_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1711 | uint32_t lduw_le_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1712 | uint32_t lduw_be_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1713 | uint32_t ldl_le_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1714 | uint32_t ldl_be_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1715 | uint64_t ldq_le_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1716 | uint64_t ldq_be_phys_cached(MemoryRegionCache *cache, hwaddr addr); | |
1717 | void stb_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val); | |
1718 | void stw_le_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val); | |
1719 | void stw_be_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val); | |
1720 | void stl_le_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val); | |
1721 | void stl_be_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint32_t val); | |
1722 | void stq_le_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint64_t val); | |
1723 | void stq_be_phys_cached(MemoryRegionCache *cache, hwaddr addr, uint64_t val); | |
052c8fa9 JW |
1724 | /* address_space_get_iotlb_entry: translate an address into an IOTLB |
1725 | * entry. Should be called from an RCU critical section. | |
1726 | */ | |
1727 | IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, | |
1728 | bool is_write); | |
1f4e496e | 1729 | |
149f54b5 | 1730 | /* address_space_translate: translate an address range into an address space |
41063e1e PB |
1731 | * into a MemoryRegion and an address range into that section. Should be |
1732 | * called from an RCU critical section, to avoid that the last reference | |
1733 | * to the returned region disappears after address_space_translate returns. | |
149f54b5 PB |
1734 | * |
1735 | * @as: #AddressSpace to be accessed | |
1736 | * @addr: address within that address space | |
1737 | * @xlat: pointer to address within the returned memory region section's | |
1738 | * #MemoryRegion. | |
1739 | * @len: pointer to length | |
1740 | * @is_write: indicates the transfer direction | |
1741 | */ | |
5c8a00ce PB |
1742 | MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, |
1743 | hwaddr *xlat, hwaddr *len, | |
1744 | bool is_write); | |
149f54b5 | 1745 | |
51644ab7 PB |
1746 | /* address_space_access_valid: check for validity of accessing an address |
1747 | * space range | |
1748 | * | |
30951157 AK |
1749 | * Check whether memory is assigned to the given address space range, and |
1750 | * access is permitted by any IOMMU regions that are active for the address | |
1751 | * space. | |
51644ab7 PB |
1752 | * |
1753 | * For now, addr and len should be aligned to a page size. This limitation | |
1754 | * will be lifted in the future. | |
1755 | * | |
1756 | * @as: #AddressSpace to be accessed | |
1757 | * @addr: address within that address space | |
1758 | * @len: length of the area to be checked | |
1759 | * @is_write: indicates the transfer direction | |
1760 | */ | |
1761 | bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write); | |
1762 | ||
ac1970fb AK |
1763 | /* address_space_map: map a physical memory region into a host virtual address |
1764 | * | |
1765 | * May map a subset of the requested range, given by and returned in @plen. | |
1766 | * May return %NULL if resources needed to perform the mapping are exhausted. | |
1767 | * Use only for reads OR writes - not for read-modify-write operations. | |
1768 | * Use cpu_register_map_client() to know when retrying the map operation is | |
1769 | * likely to succeed. | |
1770 | * | |
1771 | * @as: #AddressSpace to be accessed | |
1772 | * @addr: address within that address space | |
1773 | * @plen: pointer to length of buffer; updated on return | |
1774 | * @is_write: indicates the transfer direction | |
1775 | */ | |
a8170e5e AK |
1776 | void *address_space_map(AddressSpace *as, hwaddr addr, |
1777 | hwaddr *plen, bool is_write); | |
ac1970fb AK |
1778 | |
1779 | /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map() | |
1780 | * | |
1781 | * Will also mark the memory as dirty if @is_write == %true. @access_len gives | |
1782 | * the amount of memory that was actually read or written by the caller. | |
1783 | * | |
1784 | * @as: #AddressSpace used | |
1785 | * @addr: address within that address space | |
1786 | * @len: buffer length as returned by address_space_map() | |
1787 | * @access_len: amount of data actually transferred | |
1788 | * @is_write: indicates the transfer direction | |
1789 | */ | |
a8170e5e AK |
1790 | void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, |
1791 | int is_write, hwaddr access_len); | |
ac1970fb AK |
1792 | |
1793 | ||
a203ac70 PB |
1794 | /* Internal functions, part of the implementation of address_space_read. */ |
1795 | MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, | |
1796 | MemTxAttrs attrs, uint8_t *buf, | |
1797 | int len, hwaddr addr1, hwaddr l, | |
1798 | MemoryRegion *mr); | |
3cc8f884 PB |
1799 | MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr, |
1800 | MemTxAttrs attrs, uint8_t *buf, int len); | |
0878d0e1 | 1801 | void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr); |
3cc8f884 PB |
1802 | |
1803 | static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) | |
1804 | { | |
1805 | if (is_write) { | |
4a2e242b AW |
1806 | return memory_region_is_ram(mr) && |
1807 | !mr->readonly && !memory_region_is_ram_device(mr); | |
3cc8f884 | 1808 | } else { |
4a2e242b AW |
1809 | return (memory_region_is_ram(mr) && !memory_region_is_ram_device(mr)) || |
1810 | memory_region_is_romd(mr); | |
3cc8f884 | 1811 | } |
3cc8f884 PB |
1812 | } |
1813 | ||
1814 | /** | |
1815 | * address_space_read: read from an address space. | |
1816 | * | |
1817 | * Return a MemTxResult indicating whether the operation succeeded | |
1818 | * or failed (eg unassigned memory, device rejected the transaction, | |
1819 | * IOMMU fault). | |
1820 | * | |
1821 | * @as: #AddressSpace to be accessed | |
1822 | * @addr: address within that address space | |
1823 | * @attrs: memory transaction attributes | |
1824 | * @buf: buffer with the data transferred | |
1825 | */ | |
1826 | static inline __attribute__((__always_inline__)) | |
1827 | MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, | |
1828 | uint8_t *buf, int len) | |
1829 | { | |
1830 | MemTxResult result = MEMTX_OK; | |
1831 | hwaddr l, addr1; | |
1832 | void *ptr; | |
1833 | MemoryRegion *mr; | |
1834 | ||
1835 | if (__builtin_constant_p(len)) { | |
1836 | if (len) { | |
1837 | rcu_read_lock(); | |
1838 | l = len; | |
1839 | mr = address_space_translate(as, addr, &addr1, &l, false); | |
1840 | if (len == l && memory_access_is_direct(mr, false)) { | |
0878d0e1 | 1841 | ptr = qemu_map_ram_ptr(mr->ram_block, addr1); |
3cc8f884 PB |
1842 | memcpy(buf, ptr, len); |
1843 | } else { | |
1844 | result = address_space_read_continue(as, addr, attrs, buf, len, | |
1845 | addr1, l, mr); | |
1846 | } | |
1847 | rcu_read_unlock(); | |
1848 | } | |
1849 | } else { | |
1850 | result = address_space_read_full(as, addr, attrs, buf, len); | |
1851 | } | |
1852 | return result; | |
1853 | } | |
a203ac70 | 1854 | |
1f4e496e PB |
1855 | /** |
1856 | * address_space_read_cached: read from a cached RAM region | |
1857 | * | |
1858 | * @cache: Cached region to be addressed | |
1859 | * @addr: address relative to the base of the RAM region | |
1860 | * @buf: buffer with the data transferred | |
1861 | * @len: length of the data transferred | |
1862 | */ | |
1863 | static inline void | |
1864 | address_space_read_cached(MemoryRegionCache *cache, hwaddr addr, | |
1865 | void *buf, int len) | |
1866 | { | |
1867 | assert(addr < cache->len && len <= cache->len - addr); | |
90c4fe5f | 1868 | address_space_read(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIFIED, buf, len); |
1f4e496e PB |
1869 | } |
1870 | ||
1871 | /** | |
1872 | * address_space_write_cached: write to a cached RAM region | |
1873 | * | |
1874 | * @cache: Cached region to be addressed | |
1875 | * @addr: address relative to the base of the RAM region | |
1876 | * @buf: buffer with the data transferred | |
1877 | * @len: length of the data transferred | |
1878 | */ | |
1879 | static inline void | |
1880 | address_space_write_cached(MemoryRegionCache *cache, hwaddr addr, | |
1881 | void *buf, int len) | |
1882 | { | |
1883 | assert(addr < cache->len && len <= cache->len - addr); | |
90c4fe5f | 1884 | address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIFIED, buf, len); |
1f4e496e PB |
1885 | } |
1886 | ||
093bc2cd AK |
1887 | #endif |
1888 | ||
1889 | #endif |