memory: optimize qemu_get_ram_ptr and qemu_ram_ptr_length
[qemu/rayw.git] / include / exec / memory.h
blob34f21f1aed4e7e9c022068f00a541484c2752947
1 /*
2 * Physical memory management API
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef MEMORY_H
15 #define MEMORY_H
17 #ifndef CONFIG_USER_ONLY
19 #define DIRTY_MEMORY_VGA 0
20 #define DIRTY_MEMORY_CODE 1
21 #define DIRTY_MEMORY_MIGRATION 2
22 #define DIRTY_MEMORY_NUM 3 /* num of dirty bits */
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include "exec/cpu-common.h"
27 #ifndef CONFIG_USER_ONLY
28 #include "exec/hwaddr.h"
29 #endif
30 #include "exec/memattrs.h"
31 #include "qemu/queue.h"
32 #include "qemu/int128.h"
33 #include "qemu/notify.h"
34 #include "qapi/error.h"
35 #include "qom/object.h"
36 #include "qemu/rcu.h"
37 #include "qemu/typedefs.h"
39 #define MAX_PHYS_ADDR_SPACE_BITS 62
40 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
42 #define TYPE_MEMORY_REGION "qemu:memory-region"
43 #define MEMORY_REGION(obj) \
44 OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION)
46 typedef struct MemoryRegionOps MemoryRegionOps;
47 typedef struct MemoryRegionMmio MemoryRegionMmio;
49 struct MemoryRegionMmio {
50 CPUReadMemoryFunc *read[3];
51 CPUWriteMemoryFunc *write[3];
54 typedef struct IOMMUTLBEntry IOMMUTLBEntry;
56 /* See address_space_translate: bit 0 is read, bit 1 is write. */
57 typedef enum {
58 IOMMU_NONE = 0,
59 IOMMU_RO = 1,
60 IOMMU_WO = 2,
61 IOMMU_RW = 3,
62 } IOMMUAccessFlags;
64 struct IOMMUTLBEntry {
65 AddressSpace *target_as;
66 hwaddr iova;
67 hwaddr translated_addr;
68 hwaddr addr_mask; /* 0xfff = 4k translation */
69 IOMMUAccessFlags perm;
72 /* New-style MMIO accessors can indicate that the transaction failed.
73 * A zero (MEMTX_OK) response means success; anything else is a failure
74 * of some kind. The memory subsystem will bitwise-OR together results
75 * if it is synthesizing an operation from multiple smaller accesses.
77 #define MEMTX_OK 0
78 #define MEMTX_ERROR (1U << 0) /* device returned an error */
79 #define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */
80 typedef uint32_t MemTxResult;
83 * Memory region callbacks
85 struct MemoryRegionOps {
86 /* Read from the memory region. @addr is relative to @mr; @size is
87 * in bytes. */
88 uint64_t (*read)(void *opaque,
89 hwaddr addr,
90 unsigned size);
91 /* Write to the memory region. @addr is relative to @mr; @size is
92 * in bytes. */
93 void (*write)(void *opaque,
94 hwaddr addr,
95 uint64_t data,
96 unsigned size);
98 MemTxResult (*read_with_attrs)(void *opaque,
99 hwaddr addr,
100 uint64_t *data,
101 unsigned size,
102 MemTxAttrs attrs);
103 MemTxResult (*write_with_attrs)(void *opaque,
104 hwaddr addr,
105 uint64_t data,
106 unsigned size,
107 MemTxAttrs attrs);
109 enum device_endian endianness;
110 /* Guest-visible constraints: */
111 struct {
112 /* If nonzero, specify bounds on access sizes beyond which a machine
113 * check is thrown.
115 unsigned min_access_size;
116 unsigned max_access_size;
117 /* If true, unaligned accesses are supported. Otherwise unaligned
118 * accesses throw machine checks.
120 bool unaligned;
122 * If present, and returns #false, the transaction is not accepted
123 * by the device (and results in machine dependent behaviour such
124 * as a machine check exception).
126 bool (*accepts)(void *opaque, hwaddr addr,
127 unsigned size, bool is_write);
128 } valid;
129 /* Internal implementation constraints: */
130 struct {
131 /* If nonzero, specifies the minimum size implemented. Smaller sizes
132 * will be rounded upwards and a partial result will be returned.
134 unsigned min_access_size;
135 /* If nonzero, specifies the maximum size implemented. Larger sizes
136 * will be done as a series of accesses with smaller sizes.
138 unsigned max_access_size;
139 /* If true, unaligned accesses are supported. Otherwise all accesses
140 * are converted to (possibly multiple) naturally aligned accesses.
142 bool unaligned;
143 } impl;
145 /* If .read and .write are not present, old_mmio may be used for
146 * backwards compatibility with old mmio registration
148 const MemoryRegionMmio old_mmio;
151 typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps;
153 struct MemoryRegionIOMMUOps {
154 /* Return a TLB entry that contains a given address. */
155 IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write);
158 typedef struct CoalescedMemoryRange CoalescedMemoryRange;
159 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
161 struct MemoryRegion {
162 Object parent_obj;
164 /* All fields are private - violators will be prosecuted */
166 /* The following fields should fit in a cache line */
167 bool romd_mode;
168 bool ram;
169 bool subpage;
170 bool readonly; /* For RAM regions */
171 bool rom_device;
172 bool flush_coalesced_mmio;
173 bool global_locking;
174 uint8_t dirty_log_mask;
175 ram_addr_t ram_addr;
176 RAMBlock *ram_block;
177 Object *owner;
178 const MemoryRegionIOMMUOps *iommu_ops;
180 const MemoryRegionOps *ops;
181 void *opaque;
182 MemoryRegion *container;
183 Int128 size;
184 hwaddr addr;
185 void (*destructor)(MemoryRegion *mr);
186 uint64_t align;
187 bool terminates;
188 bool skip_dump;
189 bool enabled;
190 bool warning_printed; /* For reservations */
191 uint8_t vga_logging_count;
192 MemoryRegion *alias;
193 hwaddr alias_offset;
194 int32_t priority;
195 bool may_overlap;
196 QTAILQ_HEAD(subregions, MemoryRegion) subregions;
197 QTAILQ_ENTRY(MemoryRegion) subregions_link;
198 QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
199 const char *name;
200 unsigned ioeventfd_nb;
201 MemoryRegionIoeventfd *ioeventfds;
202 NotifierList iommu_notify;
206 * MemoryListener: callbacks structure for updates to the physical memory map
208 * Allows a component to adjust to changes in the guest-visible memory map.
209 * Use with memory_listener_register() and memory_listener_unregister().
211 struct MemoryListener {
212 void (*begin)(MemoryListener *listener);
213 void (*commit)(MemoryListener *listener);
214 void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
215 void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
216 void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
217 void (*log_start)(MemoryListener *listener, MemoryRegionSection *section,
218 int old, int new);
219 void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section,
220 int old, int new);
221 void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
222 void (*log_global_start)(MemoryListener *listener);
223 void (*log_global_stop)(MemoryListener *listener);
224 void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
225 bool match_data, uint64_t data, EventNotifier *e);
226 void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
227 bool match_data, uint64_t data, EventNotifier *e);
228 void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
229 hwaddr addr, hwaddr len);
230 void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
231 hwaddr addr, hwaddr len);
232 /* Lower = earlier (during add), later (during del) */
233 unsigned priority;
234 AddressSpace *address_space_filter;
235 QTAILQ_ENTRY(MemoryListener) link;
239 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
241 struct AddressSpace {
242 /* All fields are private. */
243 struct rcu_head rcu;
244 char *name;
245 MemoryRegion *root;
246 int ref_count;
247 bool malloced;
249 /* Accessed via RCU. */
250 struct FlatView *current_map;
252 int ioeventfd_nb;
253 struct MemoryRegionIoeventfd *ioeventfds;
254 struct AddressSpaceDispatch *dispatch;
255 struct AddressSpaceDispatch *next_dispatch;
256 MemoryListener dispatch_listener;
258 QTAILQ_ENTRY(AddressSpace) address_spaces_link;
262 * MemoryRegionSection: describes a fragment of a #MemoryRegion
264 * @mr: the region, or %NULL if empty
265 * @address_space: the address space the region is mapped in
266 * @offset_within_region: the beginning of the section, relative to @mr's start
267 * @size: the size of the section; will not exceed @mr's boundaries
268 * @offset_within_address_space: the address of the first byte of the section
269 * relative to the region's address space
270 * @readonly: writes to this section are ignored
272 struct MemoryRegionSection {
273 MemoryRegion *mr;
274 AddressSpace *address_space;
275 hwaddr offset_within_region;
276 Int128 size;
277 hwaddr offset_within_address_space;
278 bool readonly;
282 * memory_region_init: Initialize a memory region
284 * The region typically acts as a container for other memory regions. Use
285 * memory_region_add_subregion() to add subregions.
287 * @mr: the #MemoryRegion to be initialized
288 * @owner: the object that tracks the region's reference count
289 * @name: used for debugging; not visible to the user or ABI
290 * @size: size of the region; any subregions beyond this size will be clipped
292 void memory_region_init(MemoryRegion *mr,
293 struct Object *owner,
294 const char *name,
295 uint64_t size);
298 * memory_region_ref: Add 1 to a memory region's reference count
300 * Whenever memory regions are accessed outside the BQL, they need to be
301 * preserved against hot-unplug. MemoryRegions actually do not have their
302 * own reference count; they piggyback on a QOM object, their "owner".
303 * This function adds a reference to the owner.
305 * All MemoryRegions must have an owner if they can disappear, even if the
306 * device they belong to operates exclusively under the BQL. This is because
307 * the region could be returned at any time by memory_region_find, and this
308 * is usually under guest control.
310 * @mr: the #MemoryRegion
312 void memory_region_ref(MemoryRegion *mr);
315 * memory_region_unref: Remove 1 to a memory region's reference count
317 * Whenever memory regions are accessed outside the BQL, they need to be
318 * preserved against hot-unplug. MemoryRegions actually do not have their
319 * own reference count; they piggyback on a QOM object, their "owner".
320 * This function removes a reference to the owner and possibly destroys it.
322 * @mr: the #MemoryRegion
324 void memory_region_unref(MemoryRegion *mr);
327 * memory_region_init_io: Initialize an I/O memory region.
329 * Accesses into the region will cause the callbacks in @ops to be called.
330 * if @size is nonzero, subregions will be clipped to @size.
332 * @mr: the #MemoryRegion to be initialized.
333 * @owner: the object that tracks the region's reference count
334 * @ops: a structure containing read and write callbacks to be used when
335 * I/O is performed on the region.
336 * @opaque: passed to the read and write callbacks of the @ops structure.
337 * @name: used for debugging; not visible to the user or ABI
338 * @size: size of the region.
340 void memory_region_init_io(MemoryRegion *mr,
341 struct Object *owner,
342 const MemoryRegionOps *ops,
343 void *opaque,
344 const char *name,
345 uint64_t size);
348 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
349 * region will modify memory directly.
351 * @mr: the #MemoryRegion to be initialized.
352 * @owner: the object that tracks the region's reference count
353 * @name: the name of the region.
354 * @size: size of the region.
355 * @errp: pointer to Error*, to store an error if it happens.
357 void memory_region_init_ram(MemoryRegion *mr,
358 struct Object *owner,
359 const char *name,
360 uint64_t size,
361 Error **errp);
364 * memory_region_init_resizeable_ram: Initialize memory region with resizeable
365 * RAM. Accesses into the region will
366 * modify memory directly. Only an initial
367 * portion of this RAM is actually used.
368 * The used size can change across reboots.
370 * @mr: the #MemoryRegion to be initialized.
371 * @owner: the object that tracks the region's reference count
372 * @name: the name of the region.
373 * @size: used size of the region.
374 * @max_size: max size of the region.
375 * @resized: callback to notify owner about used size change.
376 * @errp: pointer to Error*, to store an error if it happens.
378 void memory_region_init_resizeable_ram(MemoryRegion *mr,
379 struct Object *owner,
380 const char *name,
381 uint64_t size,
382 uint64_t max_size,
383 void (*resized)(const char*,
384 uint64_t length,
385 void *host),
386 Error **errp);
387 #ifdef __linux__
389 * memory_region_init_ram_from_file: Initialize RAM memory region with a
390 * mmap-ed backend.
392 * @mr: the #MemoryRegion to be initialized.
393 * @owner: the object that tracks the region's reference count
394 * @name: the name of the region.
395 * @size: size of the region.
396 * @share: %true if memory must be mmaped with the MAP_SHARED flag
397 * @path: the path in which to allocate the RAM.
398 * @errp: pointer to Error*, to store an error if it happens.
400 void memory_region_init_ram_from_file(MemoryRegion *mr,
401 struct Object *owner,
402 const char *name,
403 uint64_t size,
404 bool share,
405 const char *path,
406 Error **errp);
407 #endif
410 * memory_region_init_ram_ptr: Initialize RAM memory region from a
411 * user-provided pointer. Accesses into the
412 * region will modify memory directly.
414 * @mr: the #MemoryRegion to be initialized.
415 * @owner: the object that tracks the region's reference count
416 * @name: the name of the region.
417 * @size: size of the region.
418 * @ptr: memory to be mapped; must contain at least @size bytes.
420 void memory_region_init_ram_ptr(MemoryRegion *mr,
421 struct Object *owner,
422 const char *name,
423 uint64_t size,
424 void *ptr);
427 * memory_region_init_alias: Initialize a memory region that aliases all or a
428 * part of another memory region.
430 * @mr: the #MemoryRegion to be initialized.
431 * @owner: the object that tracks the region's reference count
432 * @name: used for debugging; not visible to the user or ABI
433 * @orig: the region to be referenced; @mr will be equivalent to
434 * @orig between @offset and @offset + @size - 1.
435 * @offset: start of the section in @orig to be referenced.
436 * @size: size of the region.
438 void memory_region_init_alias(MemoryRegion *mr,
439 struct Object *owner,
440 const char *name,
441 MemoryRegion *orig,
442 hwaddr offset,
443 uint64_t size);
446 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
447 * handled via callbacks.
449 * If NULL callbacks pointer is given, then I/O space is not supposed to be
450 * handled by QEMU itself. Any access via the memory API will cause an abort().
452 * @mr: the #MemoryRegion to be initialized.
453 * @owner: the object that tracks the region's reference count
454 * @ops: callbacks for write access handling.
455 * @name: the name of the region.
456 * @size: size of the region.
457 * @errp: pointer to Error*, to store an error if it happens.
459 void memory_region_init_rom_device(MemoryRegion *mr,
460 struct Object *owner,
461 const MemoryRegionOps *ops,
462 void *opaque,
463 const char *name,
464 uint64_t size,
465 Error **errp);
468 * memory_region_init_reservation: Initialize a memory region that reserves
469 * I/O space.
471 * A reservation region primariy serves debugging purposes. It claims I/O
472 * space that is not supposed to be handled by QEMU itself. Any access via
473 * the memory API will cause an abort().
474 * This function is deprecated. Use memory_region_init_io() with NULL
475 * callbacks instead.
477 * @mr: the #MemoryRegion to be initialized
478 * @owner: the object that tracks the region's reference count
479 * @name: used for debugging; not visible to the user or ABI
480 * @size: size of the region.
482 static inline void memory_region_init_reservation(MemoryRegion *mr,
483 Object *owner,
484 const char *name,
485 uint64_t size)
487 memory_region_init_io(mr, owner, NULL, mr, name, size);
491 * memory_region_init_iommu: Initialize a memory region that translates
492 * addresses
494 * An IOMMU region translates addresses and forwards accesses to a target
495 * memory region.
497 * @mr: the #MemoryRegion to be initialized
498 * @owner: the object that tracks the region's reference count
499 * @ops: a function that translates addresses into the @target region
500 * @name: used for debugging; not visible to the user or ABI
501 * @size: size of the region.
503 void memory_region_init_iommu(MemoryRegion *mr,
504 struct Object *owner,
505 const MemoryRegionIOMMUOps *ops,
506 const char *name,
507 uint64_t size);
510 * memory_region_owner: get a memory region's owner.
512 * @mr: the memory region being queried.
514 struct Object *memory_region_owner(MemoryRegion *mr);
517 * memory_region_size: get a memory region's size.
519 * @mr: the memory region being queried.
521 uint64_t memory_region_size(MemoryRegion *mr);
524 * memory_region_is_ram: check whether a memory region is random access
526 * Returns %true is a memory region is random access.
528 * @mr: the memory region being queried
530 static inline bool memory_region_is_ram(MemoryRegion *mr)
532 return mr->ram;
536 * memory_region_is_skip_dump: check whether a memory region should not be
537 * dumped
539 * Returns %true is a memory region should not be dumped(e.g. VFIO BAR MMAP).
541 * @mr: the memory region being queried
543 bool memory_region_is_skip_dump(MemoryRegion *mr);
546 * memory_region_set_skip_dump: Set skip_dump flag, dump will ignore this memory
547 * region
549 * @mr: the memory region being queried
551 void memory_region_set_skip_dump(MemoryRegion *mr);
554 * memory_region_is_romd: check whether a memory region is in ROMD mode
556 * Returns %true if a memory region is a ROM device and currently set to allow
557 * direct reads.
559 * @mr: the memory region being queried
561 static inline bool memory_region_is_romd(MemoryRegion *mr)
563 return mr->rom_device && mr->romd_mode;
567 * memory_region_is_iommu: check whether a memory region is an iommu
569 * Returns %true is a memory region is an iommu.
571 * @mr: the memory region being queried
573 static inline bool memory_region_is_iommu(MemoryRegion *mr)
575 return mr->iommu_ops;
580 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
582 * @mr: the memory region that was changed
583 * @entry: the new entry in the IOMMU translation table. The entry
584 * replaces all old entries for the same virtual I/O address range.
585 * Deleted entries have .@perm == 0.
587 void memory_region_notify_iommu(MemoryRegion *mr,
588 IOMMUTLBEntry entry);
591 * memory_region_register_iommu_notifier: register a notifier for changes to
592 * IOMMU translation entries.
594 * @mr: the memory region to observe
595 * @n: the notifier to be added; the notifier receives a pointer to an
596 * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
597 * valid on exit from the notifier.
599 void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
602 * memory_region_iommu_replay: replay existing IOMMU translations to
603 * a notifier
605 * @mr: the memory region to observe
606 * @n: the notifier to which to replay iommu mappings
607 * @granularity: Minimum page granularity to replay notifications for
608 * @is_write: Whether to treat the replay as a translate "write"
609 * through the iommu
611 void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n,
612 hwaddr granularity, bool is_write);
615 * memory_region_unregister_iommu_notifier: unregister a notifier for
616 * changes to IOMMU translation entries.
618 * @n: the notifier to be removed.
620 void memory_region_unregister_iommu_notifier(Notifier *n);
623 * memory_region_name: get a memory region's name
625 * Returns the string that was used to initialize the memory region.
627 * @mr: the memory region being queried
629 const char *memory_region_name(const MemoryRegion *mr);
632 * memory_region_is_logging: return whether a memory region is logging writes
634 * Returns %true if the memory region is logging writes for the given client
636 * @mr: the memory region being queried
637 * @client: the client being queried
639 bool memory_region_is_logging(MemoryRegion *mr, uint8_t client);
642 * memory_region_get_dirty_log_mask: return the clients for which a
643 * memory region is logging writes.
645 * Returns a bitmap of clients, in which the DIRTY_MEMORY_* constants
646 * are the bit indices.
648 * @mr: the memory region being queried
650 uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr);
653 * memory_region_is_rom: check whether a memory region is ROM
655 * Returns %true is a memory region is read-only memory.
657 * @mr: the memory region being queried
659 static inline bool memory_region_is_rom(MemoryRegion *mr)
661 return mr->ram && mr->readonly;
666 * memory_region_get_fd: Get a file descriptor backing a RAM memory region.
668 * Returns a file descriptor backing a file-based RAM memory region,
669 * or -1 if the region is not a file-based RAM memory region.
671 * @mr: the RAM or alias memory region being queried.
673 int memory_region_get_fd(MemoryRegion *mr);
676 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
678 * Returns a host pointer to a RAM memory region (created with
679 * memory_region_init_ram() or memory_region_init_ram_ptr()).
681 * Use with care; by the time this function returns, the returned pointer is
682 * not protected by RCU anymore. If the caller is not within an RCU critical
683 * section and does not hold the iothread lock, it must have other means of
684 * protecting the pointer, such as a reference to the region that includes
685 * the incoming ram_addr_t.
687 * @mr: the memory region being queried.
689 void *memory_region_get_ram_ptr(MemoryRegion *mr);
691 /* memory_region_ram_resize: Resize a RAM region.
693 * Only legal before guest might have detected the memory size: e.g. on
694 * incoming migration, or right after reset.
696 * @mr: a memory region created with @memory_region_init_resizeable_ram.
697 * @newsize: the new size the region
698 * @errp: pointer to Error*, to store an error if it happens.
700 void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize,
701 Error **errp);
704 * memory_region_set_log: Turn dirty logging on or off for a region.
706 * Turns dirty logging on or off for a specified client (display, migration).
707 * Only meaningful for RAM regions.
709 * @mr: the memory region being updated.
710 * @log: whether dirty logging is to be enabled or disabled.
711 * @client: the user of the logging information; %DIRTY_MEMORY_VGA only.
713 void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);
716 * memory_region_get_dirty: Check whether a range of bytes is dirty
717 * for a specified client.
719 * Checks whether a range of bytes has been written to since the last
720 * call to memory_region_reset_dirty() with the same @client. Dirty logging
721 * must be enabled.
723 * @mr: the memory region being queried.
724 * @addr: the address (relative to the start of the region) being queried.
725 * @size: the size of the range being queried.
726 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
727 * %DIRTY_MEMORY_VGA.
729 bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
730 hwaddr size, unsigned client);
733 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
735 * Marks a range of bytes as dirty, after it has been dirtied outside
736 * guest code.
738 * @mr: the memory region being dirtied.
739 * @addr: the address (relative to the start of the region) being dirtied.
740 * @size: size of the range being dirtied.
742 void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
743 hwaddr size);
746 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
747 * for a specified client. It clears them.
749 * Checks whether a range of bytes has been written to since the last
750 * call to memory_region_reset_dirty() with the same @client. Dirty logging
751 * must be enabled.
753 * @mr: the memory region being queried.
754 * @addr: the address (relative to the start of the region) being queried.
755 * @size: the size of the range being queried.
756 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
757 * %DIRTY_MEMORY_VGA.
759 bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
760 hwaddr size, unsigned client);
762 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
763 * any external TLBs (e.g. kvm)
765 * Flushes dirty information from accelerators such as kvm and vhost-net
766 * and makes it available to users of the memory API.
768 * @mr: the region being flushed.
770 void memory_region_sync_dirty_bitmap(MemoryRegion *mr);
773 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
774 * client.
776 * Marks a range of pages as no longer dirty.
778 * @mr: the region being updated.
779 * @addr: the start of the subrange being cleaned.
780 * @size: the size of the subrange being cleaned.
781 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
782 * %DIRTY_MEMORY_VGA.
784 void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
785 hwaddr size, unsigned client);
788 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
790 * Allows a memory region to be marked as read-only (turning it into a ROM).
791 * only useful on RAM regions.
793 * @mr: the region being updated.
794 * @readonly: whether rhe region is to be ROM or RAM.
796 void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
799 * memory_region_rom_device_set_romd: enable/disable ROMD mode
801 * Allows a ROM device (initialized with memory_region_init_rom_device() to
802 * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
803 * device is mapped to guest memory and satisfies read access directly.
804 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
805 * Writes are always handled by the #MemoryRegion.write function.
807 * @mr: the memory region to be updated
808 * @romd_mode: %true to put the region into ROMD mode
810 void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode);
813 * memory_region_set_coalescing: Enable memory coalescing for the region.
815 * Enabled writes to a region to be queued for later processing. MMIO ->write
816 * callbacks may be delayed until a non-coalesced MMIO is issued.
817 * Only useful for IO regions. Roughly similar to write-combining hardware.
819 * @mr: the memory region to be write coalesced
821 void memory_region_set_coalescing(MemoryRegion *mr);
824 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
825 * a region.
827 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
828 * Multiple calls can be issued coalesced disjoint ranges.
830 * @mr: the memory region to be updated.
831 * @offset: the start of the range within the region to be coalesced.
832 * @size: the size of the subrange to be coalesced.
834 void memory_region_add_coalescing(MemoryRegion *mr,
835 hwaddr offset,
836 uint64_t size);
839 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
841 * Disables any coalescing caused by memory_region_set_coalescing() or
842 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
843 * hardware.
845 * @mr: the memory region to be updated.
847 void memory_region_clear_coalescing(MemoryRegion *mr);
850 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
851 * accesses.
853 * Ensure that pending coalesced MMIO request are flushed before the memory
854 * region is accessed. This property is automatically enabled for all regions
855 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
857 * @mr: the memory region to be updated.
859 void memory_region_set_flush_coalesced(MemoryRegion *mr);
862 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
863 * accesses.
865 * Clear the automatic coalesced MMIO flushing enabled via
866 * memory_region_set_flush_coalesced. Note that this service has no effect on
867 * memory regions that have MMIO coalescing enabled for themselves. For them,
868 * automatic flushing will stop once coalescing is disabled.
870 * @mr: the memory region to be updated.
872 void memory_region_clear_flush_coalesced(MemoryRegion *mr);
875 * memory_region_set_global_locking: Declares the access processing requires
876 * QEMU's global lock.
878 * When this is invoked, accesses to the memory region will be processed while
879 * holding the global lock of QEMU. This is the default behavior of memory
880 * regions.
882 * @mr: the memory region to be updated.
884 void memory_region_set_global_locking(MemoryRegion *mr);
887 * memory_region_clear_global_locking: Declares that access processing does
888 * not depend on the QEMU global lock.
890 * By clearing this property, accesses to the memory region will be processed
891 * outside of QEMU's global lock (unless the lock is held on when issuing the
892 * access request). In this case, the device model implementing the access
893 * handlers is responsible for synchronization of concurrency.
895 * @mr: the memory region to be updated.
897 void memory_region_clear_global_locking(MemoryRegion *mr);
900 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
901 * is written to a location.
903 * Marks a word in an IO region (initialized with memory_region_init_io())
904 * as a trigger for an eventfd event. The I/O callback will not be called.
905 * The caller must be prepared to handle failure (that is, take the required
906 * action if the callback _is_ called).
908 * @mr: the memory region being updated.
909 * @addr: the address within @mr that is to be monitored
910 * @size: the size of the access to trigger the eventfd
911 * @match_data: whether to match against @data, instead of just @addr
912 * @data: the data to match against the guest write
913 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
915 void memory_region_add_eventfd(MemoryRegion *mr,
916 hwaddr addr,
917 unsigned size,
918 bool match_data,
919 uint64_t data,
920 EventNotifier *e);
923 * memory_region_del_eventfd: Cancel an eventfd.
925 * Cancels an eventfd trigger requested by a previous
926 * memory_region_add_eventfd() call.
928 * @mr: the memory region being updated.
929 * @addr: the address within @mr that is to be monitored
930 * @size: the size of the access to trigger the eventfd
931 * @match_data: whether to match against @data, instead of just @addr
932 * @data: the data to match against the guest write
933 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
935 void memory_region_del_eventfd(MemoryRegion *mr,
936 hwaddr addr,
937 unsigned size,
938 bool match_data,
939 uint64_t data,
940 EventNotifier *e);
943 * memory_region_add_subregion: Add a subregion to a container.
945 * Adds a subregion at @offset. The subregion may not overlap with other
946 * subregions (except for those explicitly marked as overlapping). A region
947 * may only be added once as a subregion (unless removed with
948 * memory_region_del_subregion()); use memory_region_init_alias() if you
949 * want a region to be a subregion in multiple locations.
951 * @mr: the region to contain the new subregion; must be a container
952 * initialized with memory_region_init().
953 * @offset: the offset relative to @mr where @subregion is added.
954 * @subregion: the subregion to be added.
956 void memory_region_add_subregion(MemoryRegion *mr,
957 hwaddr offset,
958 MemoryRegion *subregion);
960 * memory_region_add_subregion_overlap: Add a subregion to a container
961 * with overlap.
963 * Adds a subregion at @offset. The subregion may overlap with other
964 * subregions. Conflicts are resolved by having a higher @priority hide a
965 * lower @priority. Subregions without priority are taken as @priority 0.
966 * A region may only be added once as a subregion (unless removed with
967 * memory_region_del_subregion()); use memory_region_init_alias() if you
968 * want a region to be a subregion in multiple locations.
970 * @mr: the region to contain the new subregion; must be a container
971 * initialized with memory_region_init().
972 * @offset: the offset relative to @mr where @subregion is added.
973 * @subregion: the subregion to be added.
974 * @priority: used for resolving overlaps; highest priority wins.
976 void memory_region_add_subregion_overlap(MemoryRegion *mr,
977 hwaddr offset,
978 MemoryRegion *subregion,
979 int priority);
982 * memory_region_get_ram_addr: Get the ram address associated with a memory
983 * region
985 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
986 * code is being reworked.
988 static inline ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr)
990 return mr->ram_addr;
993 uint64_t memory_region_get_alignment(const MemoryRegion *mr);
995 * memory_region_del_subregion: Remove a subregion.
997 * Removes a subregion from its container.
999 * @mr: the container to be updated.
1000 * @subregion: the region being removed; must be a current subregion of @mr.
1002 void memory_region_del_subregion(MemoryRegion *mr,
1003 MemoryRegion *subregion);
1006 * memory_region_set_enabled: dynamically enable or disable a region
1008 * Enables or disables a memory region. A disabled memory region
1009 * ignores all accesses to itself and its subregions. It does not
1010 * obscure sibling subregions with lower priority - it simply behaves as
1011 * if it was removed from the hierarchy.
1013 * Regions default to being enabled.
1015 * @mr: the region to be updated
1016 * @enabled: whether to enable or disable the region
1018 void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
1021 * memory_region_set_address: dynamically update the address of a region
1023 * Dynamically updates the address of a region, relative to its container.
1024 * May be used on regions are currently part of a memory hierarchy.
1026 * @mr: the region to be updated
1027 * @addr: new address, relative to container region
1029 void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
1032 * memory_region_set_size: dynamically update the size of a region.
1034 * Dynamically updates the size of a region.
1036 * @mr: the region to be updated
1037 * @size: used size of the region.
1039 void memory_region_set_size(MemoryRegion *mr, uint64_t size);
1042 * memory_region_set_alias_offset: dynamically update a memory alias's offset
1044 * Dynamically updates the offset into the target region that an alias points
1045 * to, as if the fourth argument to memory_region_init_alias() has changed.
1047 * @mr: the #MemoryRegion to be updated; should be an alias.
1048 * @offset: the new offset into the target memory region
1050 void memory_region_set_alias_offset(MemoryRegion *mr,
1051 hwaddr offset);
1054 * memory_region_present: checks if an address relative to a @container
1055 * translates into #MemoryRegion within @container
1057 * Answer whether a #MemoryRegion within @container covers the address
1058 * @addr.
1060 * @container: a #MemoryRegion within which @addr is a relative address
1061 * @addr: the area within @container to be searched
1063 bool memory_region_present(MemoryRegion *container, hwaddr addr);
1066 * memory_region_is_mapped: returns true if #MemoryRegion is mapped
1067 * into any address space.
1069 * @mr: a #MemoryRegion which should be checked if it's mapped
1071 bool memory_region_is_mapped(MemoryRegion *mr);
1074 * memory_region_find: translate an address/size relative to a
1075 * MemoryRegion into a #MemoryRegionSection.
1077 * Locates the first #MemoryRegion within @mr that overlaps the range
1078 * given by @addr and @size.
1080 * Returns a #MemoryRegionSection that describes a contiguous overlap.
1081 * It will have the following characteristics:
1082 * .@size = 0 iff no overlap was found
1083 * .@mr is non-%NULL iff an overlap was found
1085 * Remember that in the return value the @offset_within_region is
1086 * relative to the returned region (in the .@mr field), not to the
1087 * @mr argument.
1089 * Similarly, the .@offset_within_address_space is relative to the
1090 * address space that contains both regions, the passed and the
1091 * returned one. However, in the special case where the @mr argument
1092 * has no container (and thus is the root of the address space), the
1093 * following will hold:
1094 * .@offset_within_address_space >= @addr
1095 * .@offset_within_address_space + .@size <= @addr + @size
1097 * @mr: a MemoryRegion within which @addr is a relative address
1098 * @addr: start of the area within @as to be searched
1099 * @size: size of the area to be searched
1101 MemoryRegionSection memory_region_find(MemoryRegion *mr,
1102 hwaddr addr, uint64_t size);
1105 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
1107 * Synchronizes the dirty page log for an entire address space.
1108 * @as: the address space that contains the memory being synchronized
1110 void address_space_sync_dirty_bitmap(AddressSpace *as);
1113 * memory_region_transaction_begin: Start a transaction.
1115 * During a transaction, changes will be accumulated and made visible
1116 * only when the transaction ends (is committed).
1118 void memory_region_transaction_begin(void);
1121 * memory_region_transaction_commit: Commit a transaction and make changes
1122 * visible to the guest.
1124 void memory_region_transaction_commit(void);
1127 * memory_listener_register: register callbacks to be called when memory
1128 * sections are mapped or unmapped into an address
1129 * space
1131 * @listener: an object containing the callbacks to be called
1132 * @filter: if non-%NULL, only regions in this address space will be observed
1134 void memory_listener_register(MemoryListener *listener, AddressSpace *filter);
1137 * memory_listener_unregister: undo the effect of memory_listener_register()
1139 * @listener: an object containing the callbacks to be removed
1141 void memory_listener_unregister(MemoryListener *listener);
1144 * memory_global_dirty_log_start: begin dirty logging for all regions
1146 void memory_global_dirty_log_start(void);
1149 * memory_global_dirty_log_stop: end dirty logging for all regions
1151 void memory_global_dirty_log_stop(void);
1153 void mtree_info(fprintf_function mon_printf, void *f);
1156 * memory_region_dispatch_read: perform a read directly to the specified
1157 * MemoryRegion.
1159 * @mr: #MemoryRegion to access
1160 * @addr: address within that region
1161 * @pval: pointer to uint64_t which the data is written to
1162 * @size: size of the access in bytes
1163 * @attrs: memory transaction attributes to use for the access
1165 MemTxResult memory_region_dispatch_read(MemoryRegion *mr,
1166 hwaddr addr,
1167 uint64_t *pval,
1168 unsigned size,
1169 MemTxAttrs attrs);
1171 * memory_region_dispatch_write: perform a write directly to the specified
1172 * MemoryRegion.
1174 * @mr: #MemoryRegion to access
1175 * @addr: address within that region
1176 * @data: data to write
1177 * @size: size of the access in bytes
1178 * @attrs: memory transaction attributes to use for the access
1180 MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
1181 hwaddr addr,
1182 uint64_t data,
1183 unsigned size,
1184 MemTxAttrs attrs);
1187 * address_space_init: initializes an address space
1189 * @as: an uninitialized #AddressSpace
1190 * @root: a #MemoryRegion that routes addresses for the address space
1191 * @name: an address space name. The name is only used for debugging
1192 * output.
1194 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
1197 * address_space_init_shareable: return an address space for a memory region,
1198 * creating it if it does not already exist
1200 * @root: a #MemoryRegion that routes addresses for the address space
1201 * @name: an address space name. The name is only used for debugging
1202 * output.
1204 * This function will return a pointer to an existing AddressSpace
1205 * which was initialized with the specified MemoryRegion, or it will
1206 * create and initialize one if it does not already exist. The ASes
1207 * are reference-counted, so the memory will be freed automatically
1208 * when the AddressSpace is destroyed via address_space_destroy.
1210 AddressSpace *address_space_init_shareable(MemoryRegion *root,
1211 const char *name);
1214 * address_space_destroy: destroy an address space
1216 * Releases all resources associated with an address space. After an address space
1217 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
1218 * as well.
1220 * @as: address space to be destroyed
1222 void address_space_destroy(AddressSpace *as);
1225 * address_space_rw: read from or write to an address space.
1227 * Return a MemTxResult indicating whether the operation succeeded
1228 * or failed (eg unassigned memory, device rejected the transaction,
1229 * IOMMU fault).
1231 * @as: #AddressSpace to be accessed
1232 * @addr: address within that address space
1233 * @attrs: memory transaction attributes
1234 * @buf: buffer with the data transferred
1235 * @is_write: indicates the transfer direction
1237 MemTxResult address_space_rw(AddressSpace *as, hwaddr addr,
1238 MemTxAttrs attrs, uint8_t *buf,
1239 int len, bool is_write);
1242 * address_space_write: write to address space.
1244 * Return a MemTxResult indicating whether the operation succeeded
1245 * or failed (eg unassigned memory, device rejected the transaction,
1246 * IOMMU fault).
1248 * @as: #AddressSpace to be accessed
1249 * @addr: address within that address space
1250 * @attrs: memory transaction attributes
1251 * @buf: buffer with the data transferred
1253 MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
1254 MemTxAttrs attrs,
1255 const uint8_t *buf, int len);
1257 /* address_space_ld*: load from an address space
1258 * address_space_st*: store to an address space
1260 * These functions perform a load or store of the byte, word,
1261 * longword or quad to the specified address within the AddressSpace.
1262 * The _le suffixed functions treat the data as little endian;
1263 * _be indicates big endian; no suffix indicates "same endianness
1264 * as guest CPU".
1266 * The "guest CPU endianness" accessors are deprecated for use outside
1267 * target-* code; devices should be CPU-agnostic and use either the LE
1268 * or the BE accessors.
1270 * @as #AddressSpace to be accessed
1271 * @addr: address within that address space
1272 * @val: data value, for stores
1273 * @attrs: memory transaction attributes
1274 * @result: location to write the success/failure of the transaction;
1275 * if NULL, this information is discarded
1277 uint32_t address_space_ldub(AddressSpace *as, hwaddr addr,
1278 MemTxAttrs attrs, MemTxResult *result);
1279 uint32_t address_space_lduw_le(AddressSpace *as, hwaddr addr,
1280 MemTxAttrs attrs, MemTxResult *result);
1281 uint32_t address_space_lduw_be(AddressSpace *as, hwaddr addr,
1282 MemTxAttrs attrs, MemTxResult *result);
1283 uint32_t address_space_ldl_le(AddressSpace *as, hwaddr addr,
1284 MemTxAttrs attrs, MemTxResult *result);
1285 uint32_t address_space_ldl_be(AddressSpace *as, hwaddr addr,
1286 MemTxAttrs attrs, MemTxResult *result);
1287 uint64_t address_space_ldq_le(AddressSpace *as, hwaddr addr,
1288 MemTxAttrs attrs, MemTxResult *result);
1289 uint64_t address_space_ldq_be(AddressSpace *as, hwaddr addr,
1290 MemTxAttrs attrs, MemTxResult *result);
1291 void address_space_stb(AddressSpace *as, hwaddr addr, uint32_t val,
1292 MemTxAttrs attrs, MemTxResult *result);
1293 void address_space_stw_le(AddressSpace *as, hwaddr addr, uint32_t val,
1294 MemTxAttrs attrs, MemTxResult *result);
1295 void address_space_stw_be(AddressSpace *as, hwaddr addr, uint32_t val,
1296 MemTxAttrs attrs, MemTxResult *result);
1297 void address_space_stl_le(AddressSpace *as, hwaddr addr, uint32_t val,
1298 MemTxAttrs attrs, MemTxResult *result);
1299 void address_space_stl_be(AddressSpace *as, hwaddr addr, uint32_t val,
1300 MemTxAttrs attrs, MemTxResult *result);
1301 void address_space_stq_le(AddressSpace *as, hwaddr addr, uint64_t val,
1302 MemTxAttrs attrs, MemTxResult *result);
1303 void address_space_stq_be(AddressSpace *as, hwaddr addr, uint64_t val,
1304 MemTxAttrs attrs, MemTxResult *result);
1306 #ifdef NEED_CPU_H
1307 uint32_t address_space_lduw(AddressSpace *as, hwaddr addr,
1308 MemTxAttrs attrs, MemTxResult *result);
1309 uint32_t address_space_ldl(AddressSpace *as, hwaddr addr,
1310 MemTxAttrs attrs, MemTxResult *result);
1311 uint64_t address_space_ldq(AddressSpace *as, hwaddr addr,
1312 MemTxAttrs attrs, MemTxResult *result);
1313 void address_space_stl_notdirty(AddressSpace *as, hwaddr addr, uint32_t val,
1314 MemTxAttrs attrs, MemTxResult *result);
1315 void address_space_stw(AddressSpace *as, hwaddr addr, uint32_t val,
1316 MemTxAttrs attrs, MemTxResult *result);
1317 void address_space_stl(AddressSpace *as, hwaddr addr, uint32_t val,
1318 MemTxAttrs attrs, MemTxResult *result);
1319 void address_space_stq(AddressSpace *as, hwaddr addr, uint64_t val,
1320 MemTxAttrs attrs, MemTxResult *result);
1321 #endif
1323 /* address_space_translate: translate an address range into an address space
1324 * into a MemoryRegion and an address range into that section. Should be
1325 * called from an RCU critical section, to avoid that the last reference
1326 * to the returned region disappears after address_space_translate returns.
1328 * @as: #AddressSpace to be accessed
1329 * @addr: address within that address space
1330 * @xlat: pointer to address within the returned memory region section's
1331 * #MemoryRegion.
1332 * @len: pointer to length
1333 * @is_write: indicates the transfer direction
1335 MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
1336 hwaddr *xlat, hwaddr *len,
1337 bool is_write);
1339 /* address_space_access_valid: check for validity of accessing an address
1340 * space range
1342 * Check whether memory is assigned to the given address space range, and
1343 * access is permitted by any IOMMU regions that are active for the address
1344 * space.
1346 * For now, addr and len should be aligned to a page size. This limitation
1347 * will be lifted in the future.
1349 * @as: #AddressSpace to be accessed
1350 * @addr: address within that address space
1351 * @len: length of the area to be checked
1352 * @is_write: indicates the transfer direction
1354 bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
1356 /* address_space_map: map a physical memory region into a host virtual address
1358 * May map a subset of the requested range, given by and returned in @plen.
1359 * May return %NULL if resources needed to perform the mapping are exhausted.
1360 * Use only for reads OR writes - not for read-modify-write operations.
1361 * Use cpu_register_map_client() to know when retrying the map operation is
1362 * likely to succeed.
1364 * @as: #AddressSpace to be accessed
1365 * @addr: address within that address space
1366 * @plen: pointer to length of buffer; updated on return
1367 * @is_write: indicates the transfer direction
1369 void *address_space_map(AddressSpace *as, hwaddr addr,
1370 hwaddr *plen, bool is_write);
1372 /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
1374 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
1375 * the amount of memory that was actually read or written by the caller.
1377 * @as: #AddressSpace used
1378 * @addr: address within that address space
1379 * @len: buffer length as returned by address_space_map()
1380 * @access_len: amount of data actually transferred
1381 * @is_write: indicates the transfer direction
1383 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
1384 int is_write, hwaddr access_len);
1387 /* Internal functions, part of the implementation of address_space_read. */
1388 MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr,
1389 MemTxAttrs attrs, uint8_t *buf,
1390 int len, hwaddr addr1, hwaddr l,
1391 MemoryRegion *mr);
1392 MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,
1393 MemTxAttrs attrs, uint8_t *buf, int len);
1394 void *qemu_get_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
1396 static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
1398 if (is_write) {
1399 return memory_region_is_ram(mr) && !mr->readonly;
1400 } else {
1401 return memory_region_is_ram(mr) || memory_region_is_romd(mr);
1404 return false;
1408 * address_space_read: read from an address space.
1410 * Return a MemTxResult indicating whether the operation succeeded
1411 * or failed (eg unassigned memory, device rejected the transaction,
1412 * IOMMU fault).
1414 * @as: #AddressSpace to be accessed
1415 * @addr: address within that address space
1416 * @attrs: memory transaction attributes
1417 * @buf: buffer with the data transferred
1419 static inline __attribute__((__always_inline__))
1420 MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs,
1421 uint8_t *buf, int len)
1423 MemTxResult result = MEMTX_OK;
1424 hwaddr l, addr1;
1425 void *ptr;
1426 MemoryRegion *mr;
1428 if (__builtin_constant_p(len)) {
1429 if (len) {
1430 rcu_read_lock();
1431 l = len;
1432 mr = address_space_translate(as, addr, &addr1, &l, false);
1433 if (len == l && memory_access_is_direct(mr, false)) {
1434 addr1 += memory_region_get_ram_addr(mr);
1435 ptr = qemu_get_ram_ptr(mr->ram_block, addr1);
1436 memcpy(buf, ptr, len);
1437 } else {
1438 result = address_space_read_continue(as, addr, attrs, buf, len,
1439 addr1, l, mr);
1441 rcu_read_unlock();
1443 } else {
1444 result = address_space_read_full(as, addr, attrs, buf, len);
1446 return result;
1449 #endif
1451 #endif