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