2 * Physical memory management API
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
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.
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 */
26 #include "qemu-common.h"
27 #include "exec/cpu-common.h"
28 #ifndef CONFIG_USER_ONLY
29 #include "exec/hwaddr.h"
31 #include "qemu/queue.h"
32 #include "qemu/int128.h"
33 #include "qemu/notify.h"
34 #include "qapi/error.h"
36 #define MAX_PHYS_ADDR_SPACE_BITS 62
37 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
39 typedef struct MemoryRegionOps MemoryRegionOps
;
40 typedef struct MemoryRegionMmio MemoryRegionMmio
;
42 struct MemoryRegionMmio
{
43 CPUReadMemoryFunc
*read
[3];
44 CPUWriteMemoryFunc
*write
[3];
47 typedef struct IOMMUTLBEntry IOMMUTLBEntry
;
49 /* See address_space_translate: bit 0 is read, bit 1 is write. */
57 struct IOMMUTLBEntry
{
58 AddressSpace
*target_as
;
60 hwaddr translated_addr
;
61 hwaddr addr_mask
; /* 0xfff = 4k translation */
62 IOMMUAccessFlags perm
;
66 * Memory region callbacks
68 struct MemoryRegionOps
{
69 /* Read from the memory region. @addr is relative to @mr; @size is
71 uint64_t (*read
)(void *opaque
,
74 /* Write to the memory region. @addr is relative to @mr; @size is
76 void (*write
)(void *opaque
,
81 enum device_endian endianness
;
82 /* Guest-visible constraints: */
84 /* If nonzero, specify bounds on access sizes beyond which a machine
87 unsigned min_access_size
;
88 unsigned max_access_size
;
89 /* If true, unaligned accesses are supported. Otherwise unaligned
90 * accesses throw machine checks.
94 * If present, and returns #false, the transaction is not accepted
95 * by the device (and results in machine dependent behaviour such
96 * as a machine check exception).
98 bool (*accepts
)(void *opaque
, hwaddr addr
,
99 unsigned size
, bool is_write
);
101 /* Internal implementation constraints: */
103 /* If nonzero, specifies the minimum size implemented. Smaller sizes
104 * will be rounded upwards and a partial result will be returned.
106 unsigned min_access_size
;
107 /* If nonzero, specifies the maximum size implemented. Larger sizes
108 * will be done as a series of accesses with smaller sizes.
110 unsigned max_access_size
;
111 /* If true, unaligned accesses are supported. Otherwise all accesses
112 * are converted to (possibly multiple) naturally aligned accesses.
117 /* If .read and .write are not present, old_mmio may be used for
118 * backwards compatibility with old mmio registration
120 const MemoryRegionMmio old_mmio
;
123 typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps
;
125 struct MemoryRegionIOMMUOps
{
126 /* Return a TLB entry that contains a given address. */
127 IOMMUTLBEntry (*translate
)(MemoryRegion
*iommu
, hwaddr addr
);
130 typedef struct CoalescedMemoryRange CoalescedMemoryRange
;
131 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd
;
133 struct MemoryRegion
{
134 /* All fields are private - violators will be prosecuted */
135 const MemoryRegionOps
*ops
;
136 const MemoryRegionIOMMUOps
*iommu_ops
;
138 struct Object
*owner
;
139 MemoryRegion
*container
;
142 void (*destructor
)(MemoryRegion
*mr
);
148 bool readonly
; /* For RAM regions */
151 bool warning_printed
; /* For reservations */
152 bool flush_coalesced_mmio
;
157 QTAILQ_HEAD(subregions
, MemoryRegion
) subregions
;
158 QTAILQ_ENTRY(MemoryRegion
) subregions_link
;
159 QTAILQ_HEAD(coalesced_ranges
, CoalescedMemoryRange
) coalesced
;
161 uint8_t dirty_log_mask
;
162 unsigned ioeventfd_nb
;
163 MemoryRegionIoeventfd
*ioeventfds
;
164 NotifierList iommu_notify
;
168 * MemoryListener: callbacks structure for updates to the physical memory map
170 * Allows a component to adjust to changes in the guest-visible memory map.
171 * Use with memory_listener_register() and memory_listener_unregister().
173 struct MemoryListener
{
174 void (*begin
)(MemoryListener
*listener
);
175 void (*commit
)(MemoryListener
*listener
);
176 void (*region_add
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
177 void (*region_del
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
178 void (*region_nop
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
179 void (*log_start
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
180 void (*log_stop
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
181 void (*log_sync
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
182 void (*log_global_start
)(MemoryListener
*listener
);
183 void (*log_global_stop
)(MemoryListener
*listener
);
184 void (*eventfd_add
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
185 bool match_data
, uint64_t data
, EventNotifier
*e
);
186 void (*eventfd_del
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
187 bool match_data
, uint64_t data
, EventNotifier
*e
);
188 void (*coalesced_mmio_add
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
189 hwaddr addr
, hwaddr len
);
190 void (*coalesced_mmio_del
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
191 hwaddr addr
, hwaddr len
);
192 /* Lower = earlier (during add), later (during del) */
194 AddressSpace
*address_space_filter
;
195 QTAILQ_ENTRY(MemoryListener
) link
;
199 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
201 struct AddressSpace
{
202 /* All fields are private. */
205 struct FlatView
*current_map
;
207 struct MemoryRegionIoeventfd
*ioeventfds
;
208 struct AddressSpaceDispatch
*dispatch
;
209 struct AddressSpaceDispatch
*next_dispatch
;
210 MemoryListener dispatch_listener
;
212 QTAILQ_ENTRY(AddressSpace
) address_spaces_link
;
216 * MemoryRegionSection: describes a fragment of a #MemoryRegion
218 * @mr: the region, or %NULL if empty
219 * @address_space: the address space the region is mapped in
220 * @offset_within_region: the beginning of the section, relative to @mr's start
221 * @size: the size of the section; will not exceed @mr's boundaries
222 * @offset_within_address_space: the address of the first byte of the section
223 * relative to the region's address space
224 * @readonly: writes to this section are ignored
226 struct MemoryRegionSection
{
228 AddressSpace
*address_space
;
229 hwaddr offset_within_region
;
231 hwaddr offset_within_address_space
;
236 * memory_region_init: Initialize a memory region
238 * The region typically acts as a container for other memory regions. Use
239 * memory_region_add_subregion() to add subregions.
241 * @mr: the #MemoryRegion to be initialized
242 * @owner: the object that tracks the region's reference count
243 * @name: used for debugging; not visible to the user or ABI
244 * @size: size of the region; any subregions beyond this size will be clipped
246 void memory_region_init(MemoryRegion
*mr
,
247 struct Object
*owner
,
252 * memory_region_ref: Add 1 to a memory region's reference count
254 * Whenever memory regions are accessed outside the BQL, they need to be
255 * preserved against hot-unplug. MemoryRegions actually do not have their
256 * own reference count; they piggyback on a QOM object, their "owner".
257 * This function adds a reference to the owner.
259 * All MemoryRegions must have an owner if they can disappear, even if the
260 * device they belong to operates exclusively under the BQL. This is because
261 * the region could be returned at any time by memory_region_find, and this
262 * is usually under guest control.
264 * @mr: the #MemoryRegion
266 void memory_region_ref(MemoryRegion
*mr
);
269 * memory_region_unref: Remove 1 to a memory region's reference count
271 * Whenever memory regions are accessed outside the BQL, they need to be
272 * preserved against hot-unplug. MemoryRegions actually do not have their
273 * own reference count; they piggyback on a QOM object, their "owner".
274 * This function removes a reference to the owner and possibly destroys it.
276 * @mr: the #MemoryRegion
278 void memory_region_unref(MemoryRegion
*mr
);
281 * memory_region_init_io: Initialize an I/O memory region.
283 * Accesses into the region will cause the callbacks in @ops to be called.
284 * if @size is nonzero, subregions will be clipped to @size.
286 * @mr: the #MemoryRegion to be initialized.
287 * @owner: the object that tracks the region's reference count
288 * @ops: a structure containing read and write callbacks to be used when
289 * I/O is performed on the region.
290 * @opaque: passed to to the read and write callbacks of the @ops structure.
291 * @name: used for debugging; not visible to the user or ABI
292 * @size: size of the region.
294 void memory_region_init_io(MemoryRegion
*mr
,
295 struct Object
*owner
,
296 const MemoryRegionOps
*ops
,
302 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
303 * region will modify memory directly.
305 * @mr: the #MemoryRegion to be initialized.
306 * @owner: the object that tracks the region's reference count
307 * @name: the name of the region.
308 * @size: size of the region.
310 void memory_region_init_ram(MemoryRegion
*mr
,
311 struct Object
*owner
,
317 * memory_region_init_ram_from_file: Initialize RAM memory region with a
320 * @mr: the #MemoryRegion to be initialized.
321 * @owner: the object that tracks the region's reference count
322 * @name: the name of the region.
323 * @size: size of the region.
324 * @path: the path in which to allocate the RAM.
325 * @errp: pointer to Error*, to store an error if it happens.
327 void memory_region_init_ram_from_file(MemoryRegion
*mr
,
328 struct Object
*owner
,
336 * memory_region_init_ram_ptr: Initialize RAM memory region from a
337 * user-provided pointer. Accesses into the
338 * region will modify memory directly.
340 * @mr: the #MemoryRegion to be initialized.
341 * @owner: the object that tracks the region's reference count
342 * @name: the name of the region.
343 * @size: size of the region.
344 * @ptr: memory to be mapped; must contain at least @size bytes.
346 void memory_region_init_ram_ptr(MemoryRegion
*mr
,
347 struct Object
*owner
,
353 * memory_region_init_alias: Initialize a memory region that aliases all or a
354 * part of another memory region.
356 * @mr: the #MemoryRegion to be initialized.
357 * @owner: the object that tracks the region's reference count
358 * @name: used for debugging; not visible to the user or ABI
359 * @orig: the region to be referenced; @mr will be equivalent to
360 * @orig between @offset and @offset + @size - 1.
361 * @offset: start of the section in @orig to be referenced.
362 * @size: size of the region.
364 void memory_region_init_alias(MemoryRegion
*mr
,
365 struct Object
*owner
,
372 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
373 * handled via callbacks.
375 * @mr: the #MemoryRegion to be initialized.
376 * @owner: the object that tracks the region's reference count
377 * @ops: callbacks for write access handling.
378 * @name: the name of the region.
379 * @size: size of the region.
381 void memory_region_init_rom_device(MemoryRegion
*mr
,
382 struct Object
*owner
,
383 const MemoryRegionOps
*ops
,
389 * memory_region_init_reservation: Initialize a memory region that reserves
392 * A reservation region primariy serves debugging purposes. It claims I/O
393 * space that is not supposed to be handled by QEMU itself. Any access via
394 * the memory API will cause an abort().
396 * @mr: the #MemoryRegion to be initialized
397 * @owner: the object that tracks the region's reference count
398 * @name: used for debugging; not visible to the user or ABI
399 * @size: size of the region.
401 void memory_region_init_reservation(MemoryRegion
*mr
,
402 struct Object
*owner
,
407 * memory_region_init_iommu: Initialize a memory region that translates
410 * An IOMMU region translates addresses and forwards accesses to a target
413 * @mr: the #MemoryRegion to be initialized
414 * @owner: the object that tracks the region's reference count
415 * @ops: a function that translates addresses into the @target region
416 * @name: used for debugging; not visible to the user or ABI
417 * @size: size of the region.
419 void memory_region_init_iommu(MemoryRegion
*mr
,
420 struct Object
*owner
,
421 const MemoryRegionIOMMUOps
*ops
,
426 * memory_region_destroy: Destroy a memory region and reclaim all resources.
428 * @mr: the region to be destroyed. May not currently be a subregion
429 * (see memory_region_add_subregion()) or referenced in an alias
430 * (see memory_region_init_alias()).
432 void memory_region_destroy(MemoryRegion
*mr
);
435 * memory_region_owner: get a memory region's owner.
437 * @mr: the memory region being queried.
439 struct Object
*memory_region_owner(MemoryRegion
*mr
);
442 * memory_region_size: get a memory region's size.
444 * @mr: the memory region being queried.
446 uint64_t memory_region_size(MemoryRegion
*mr
);
449 * memory_region_is_ram: check whether a memory region is random access
451 * Returns %true is a memory region is random access.
453 * @mr: the memory region being queried
455 bool memory_region_is_ram(MemoryRegion
*mr
);
458 * memory_region_is_romd: check whether a memory region is in ROMD mode
460 * Returns %true if a memory region is a ROM device and currently set to allow
463 * @mr: the memory region being queried
465 static inline bool memory_region_is_romd(MemoryRegion
*mr
)
467 return mr
->rom_device
&& mr
->romd_mode
;
471 * memory_region_is_iommu: check whether a memory region is an iommu
473 * Returns %true is a memory region is an iommu.
475 * @mr: the memory region being queried
477 bool memory_region_is_iommu(MemoryRegion
*mr
);
480 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
482 * @mr: the memory region that was changed
483 * @entry: the new entry in the IOMMU translation table. The entry
484 * replaces all old entries for the same virtual I/O address range.
485 * Deleted entries have .@perm == 0.
487 void memory_region_notify_iommu(MemoryRegion
*mr
,
488 IOMMUTLBEntry entry
);
491 * memory_region_register_iommu_notifier: register a notifier for changes to
492 * IOMMU translation entries.
494 * @mr: the memory region to observe
495 * @n: the notifier to be added; the notifier receives a pointer to an
496 * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
497 * valid on exit from the notifier.
499 void memory_region_register_iommu_notifier(MemoryRegion
*mr
, Notifier
*n
);
502 * memory_region_unregister_iommu_notifier: unregister a notifier for
503 * changes to IOMMU translation entries.
505 * @n: the notifier to be removed.
507 void memory_region_unregister_iommu_notifier(Notifier
*n
);
510 * memory_region_name: get a memory region's name
512 * Returns the string that was used to initialize the memory region.
514 * @mr: the memory region being queried
516 const char *memory_region_name(MemoryRegion
*mr
);
519 * memory_region_is_logging: return whether a memory region is logging writes
521 * Returns %true if the memory region is logging writes
523 * @mr: the memory region being queried
525 bool memory_region_is_logging(MemoryRegion
*mr
);
528 * memory_region_is_rom: check whether a memory region is ROM
530 * Returns %true is a memory region is read-only memory.
532 * @mr: the memory region being queried
534 bool memory_region_is_rom(MemoryRegion
*mr
);
537 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
539 * Returns a host pointer to a RAM memory region (created with
540 * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
543 * @mr: the memory region being queried.
545 void *memory_region_get_ram_ptr(MemoryRegion
*mr
);
548 * memory_region_set_log: Turn dirty logging on or off for a region.
550 * Turns dirty logging on or off for a specified client (display, migration).
551 * Only meaningful for RAM regions.
553 * @mr: the memory region being updated.
554 * @log: whether dirty logging is to be enabled or disabled.
555 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
558 void memory_region_set_log(MemoryRegion
*mr
, bool log
, unsigned client
);
561 * memory_region_get_dirty: Check whether a range of bytes is dirty
562 * for a specified client.
564 * Checks whether a range of bytes has been written to since the last
565 * call to memory_region_reset_dirty() with the same @client. Dirty logging
568 * @mr: the memory region being queried.
569 * @addr: the address (relative to the start of the region) being queried.
570 * @size: the size of the range being queried.
571 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
574 bool memory_region_get_dirty(MemoryRegion
*mr
, hwaddr addr
,
575 hwaddr size
, unsigned client
);
578 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
580 * Marks a range of bytes as dirty, after it has been dirtied outside
583 * @mr: the memory region being dirtied.
584 * @addr: the address (relative to the start of the region) being dirtied.
585 * @size: size of the range being dirtied.
587 void memory_region_set_dirty(MemoryRegion
*mr
, hwaddr addr
,
591 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
592 * for a specified client. It clears them.
594 * Checks whether a range of bytes has been written to since the last
595 * call to memory_region_reset_dirty() with the same @client. Dirty logging
598 * @mr: the memory region being queried.
599 * @addr: the address (relative to the start of the region) being queried.
600 * @size: the size of the range being queried.
601 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
604 bool memory_region_test_and_clear_dirty(MemoryRegion
*mr
, hwaddr addr
,
605 hwaddr size
, unsigned client
);
607 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
608 * any external TLBs (e.g. kvm)
610 * Flushes dirty information from accelerators such as kvm and vhost-net
611 * and makes it available to users of the memory API.
613 * @mr: the region being flushed.
615 void memory_region_sync_dirty_bitmap(MemoryRegion
*mr
);
618 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
621 * Marks a range of pages as no longer dirty.
623 * @mr: the region being updated.
624 * @addr: the start of the subrange being cleaned.
625 * @size: the size of the subrange being cleaned.
626 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
629 void memory_region_reset_dirty(MemoryRegion
*mr
, hwaddr addr
,
630 hwaddr size
, unsigned client
);
633 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
635 * Allows a memory region to be marked as read-only (turning it into a ROM).
636 * only useful on RAM regions.
638 * @mr: the region being updated.
639 * @readonly: whether rhe region is to be ROM or RAM.
641 void memory_region_set_readonly(MemoryRegion
*mr
, bool readonly
);
644 * memory_region_rom_device_set_romd: enable/disable ROMD mode
646 * Allows a ROM device (initialized with memory_region_init_rom_device() to
647 * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
648 * device is mapped to guest memory and satisfies read access directly.
649 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
650 * Writes are always handled by the #MemoryRegion.write function.
652 * @mr: the memory region to be updated
653 * @romd_mode: %true to put the region into ROMD mode
655 void memory_region_rom_device_set_romd(MemoryRegion
*mr
, bool romd_mode
);
658 * memory_region_set_coalescing: Enable memory coalescing for the region.
660 * Enabled writes to a region to be queued for later processing. MMIO ->write
661 * callbacks may be delayed until a non-coalesced MMIO is issued.
662 * Only useful for IO regions. Roughly similar to write-combining hardware.
664 * @mr: the memory region to be write coalesced
666 void memory_region_set_coalescing(MemoryRegion
*mr
);
669 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
672 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
673 * Multiple calls can be issued coalesced disjoint ranges.
675 * @mr: the memory region to be updated.
676 * @offset: the start of the range within the region to be coalesced.
677 * @size: the size of the subrange to be coalesced.
679 void memory_region_add_coalescing(MemoryRegion
*mr
,
684 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
686 * Disables any coalescing caused by memory_region_set_coalescing() or
687 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
690 * @mr: the memory region to be updated.
692 void memory_region_clear_coalescing(MemoryRegion
*mr
);
695 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
698 * Ensure that pending coalesced MMIO request are flushed before the memory
699 * region is accessed. This property is automatically enabled for all regions
700 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
702 * @mr: the memory region to be updated.
704 void memory_region_set_flush_coalesced(MemoryRegion
*mr
);
707 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
710 * Clear the automatic coalesced MMIO flushing enabled via
711 * memory_region_set_flush_coalesced. Note that this service has no effect on
712 * memory regions that have MMIO coalescing enabled for themselves. For them,
713 * automatic flushing will stop once coalescing is disabled.
715 * @mr: the memory region to be updated.
717 void memory_region_clear_flush_coalesced(MemoryRegion
*mr
);
720 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
721 * is written to a location.
723 * Marks a word in an IO region (initialized with memory_region_init_io())
724 * as a trigger for an eventfd event. The I/O callback will not be called.
725 * The caller must be prepared to handle failure (that is, take the required
726 * action if the callback _is_ called).
728 * @mr: the memory region being updated.
729 * @addr: the address within @mr that is to be monitored
730 * @size: the size of the access to trigger the eventfd
731 * @match_data: whether to match against @data, instead of just @addr
732 * @data: the data to match against the guest write
733 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
735 void memory_region_add_eventfd(MemoryRegion
*mr
,
743 * memory_region_del_eventfd: Cancel an eventfd.
745 * Cancels an eventfd trigger requested by a previous
746 * memory_region_add_eventfd() call.
748 * @mr: the memory region being updated.
749 * @addr: the address within @mr that is to be monitored
750 * @size: the size of the access to trigger the eventfd
751 * @match_data: whether to match against @data, instead of just @addr
752 * @data: the data to match against the guest write
753 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
755 void memory_region_del_eventfd(MemoryRegion
*mr
,
763 * memory_region_add_subregion: Add a subregion to a container.
765 * Adds a subregion at @offset. The subregion may not overlap with other
766 * subregions (except for those explicitly marked as overlapping). A region
767 * may only be added once as a subregion (unless removed with
768 * memory_region_del_subregion()); use memory_region_init_alias() if you
769 * want a region to be a subregion in multiple locations.
771 * @mr: the region to contain the new subregion; must be a container
772 * initialized with memory_region_init().
773 * @offset: the offset relative to @mr where @subregion is added.
774 * @subregion: the subregion to be added.
776 void memory_region_add_subregion(MemoryRegion
*mr
,
778 MemoryRegion
*subregion
);
780 * memory_region_add_subregion_overlap: Add a subregion to a container
783 * Adds a subregion at @offset. The subregion may overlap with other
784 * subregions. Conflicts are resolved by having a higher @priority hide a
785 * lower @priority. Subregions without priority are taken as @priority 0.
786 * A region may only be added once as a subregion (unless removed with
787 * memory_region_del_subregion()); use memory_region_init_alias() if you
788 * want a region to be a subregion in multiple locations.
790 * @mr: the region to contain the new subregion; must be a container
791 * initialized with memory_region_init().
792 * @offset: the offset relative to @mr where @subregion is added.
793 * @subregion: the subregion to be added.
794 * @priority: used for resolving overlaps; highest priority wins.
796 void memory_region_add_subregion_overlap(MemoryRegion
*mr
,
798 MemoryRegion
*subregion
,
802 * memory_region_get_ram_addr: Get the ram address associated with a memory
805 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
806 * code is being reworked.
808 ram_addr_t
memory_region_get_ram_addr(MemoryRegion
*mr
);
811 * memory_region_del_subregion: Remove a subregion.
813 * Removes a subregion from its container.
815 * @mr: the container to be updated.
816 * @subregion: the region being removed; must be a current subregion of @mr.
818 void memory_region_del_subregion(MemoryRegion
*mr
,
819 MemoryRegion
*subregion
);
822 * memory_region_set_enabled: dynamically enable or disable a region
824 * Enables or disables a memory region. A disabled memory region
825 * ignores all accesses to itself and its subregions. It does not
826 * obscure sibling subregions with lower priority - it simply behaves as
827 * if it was removed from the hierarchy.
829 * Regions default to being enabled.
831 * @mr: the region to be updated
832 * @enabled: whether to enable or disable the region
834 void memory_region_set_enabled(MemoryRegion
*mr
, bool enabled
);
837 * memory_region_set_address: dynamically update the address of a region
839 * Dynamically updates the address of a region, relative to its container.
840 * May be used on regions are currently part of a memory hierarchy.
842 * @mr: the region to be updated
843 * @addr: new address, relative to container region
845 void memory_region_set_address(MemoryRegion
*mr
, hwaddr addr
);
848 * memory_region_set_alias_offset: dynamically update a memory alias's offset
850 * Dynamically updates the offset into the target region that an alias points
851 * to, as if the fourth argument to memory_region_init_alias() has changed.
853 * @mr: the #MemoryRegion to be updated; should be an alias.
854 * @offset: the new offset into the target memory region
856 void memory_region_set_alias_offset(MemoryRegion
*mr
,
860 * memory_region_present: checks if an address relative to a @container
861 * translates into #MemoryRegion within @container
863 * Answer whether a #MemoryRegion within @container covers the address
866 * @container: a #MemoryRegion within which @addr is a relative address
867 * @addr: the area within @container to be searched
869 bool memory_region_present(MemoryRegion
*container
, hwaddr addr
);
872 * memory_region_is_mapped: returns true if #MemoryRegion is mapped
873 * into any address space.
875 * @mr: a #MemoryRegion which should be checked if it's mapped
877 bool memory_region_is_mapped(MemoryRegion
*mr
);
880 * memory_region_find: translate an address/size relative to a
881 * MemoryRegion into a #MemoryRegionSection.
883 * Locates the first #MemoryRegion within @mr that overlaps the range
884 * given by @addr and @size.
886 * Returns a #MemoryRegionSection that describes a contiguous overlap.
887 * It will have the following characteristics:
888 * .@size = 0 iff no overlap was found
889 * .@mr is non-%NULL iff an overlap was found
891 * Remember that in the return value the @offset_within_region is
892 * relative to the returned region (in the .@mr field), not to the
895 * Similarly, the .@offset_within_address_space is relative to the
896 * address space that contains both regions, the passed and the
897 * returned one. However, in the special case where the @mr argument
898 * has no container (and thus is the root of the address space), the
899 * following will hold:
900 * .@offset_within_address_space >= @addr
901 * .@offset_within_address_space + .@size <= @addr + @size
903 * @mr: a MemoryRegion within which @addr is a relative address
904 * @addr: start of the area within @as to be searched
905 * @size: size of the area to be searched
907 MemoryRegionSection
memory_region_find(MemoryRegion
*mr
,
908 hwaddr addr
, uint64_t size
);
911 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
913 * Synchronizes the dirty page log for an entire address space.
914 * @as: the address space that contains the memory being synchronized
916 void address_space_sync_dirty_bitmap(AddressSpace
*as
);
919 * memory_region_transaction_begin: Start a transaction.
921 * During a transaction, changes will be accumulated and made visible
922 * only when the transaction ends (is committed).
924 void memory_region_transaction_begin(void);
927 * memory_region_transaction_commit: Commit a transaction and make changes
928 * visible to the guest.
930 void memory_region_transaction_commit(void);
933 * memory_listener_register: register callbacks to be called when memory
934 * sections are mapped or unmapped into an address
937 * @listener: an object containing the callbacks to be called
938 * @filter: if non-%NULL, only regions in this address space will be observed
940 void memory_listener_register(MemoryListener
*listener
, AddressSpace
*filter
);
943 * memory_listener_unregister: undo the effect of memory_listener_register()
945 * @listener: an object containing the callbacks to be removed
947 void memory_listener_unregister(MemoryListener
*listener
);
950 * memory_global_dirty_log_start: begin dirty logging for all regions
952 void memory_global_dirty_log_start(void);
955 * memory_global_dirty_log_stop: end dirty logging for all regions
957 void memory_global_dirty_log_stop(void);
959 void mtree_info(fprintf_function mon_printf
, void *f
);
962 * address_space_init: initializes an address space
964 * @as: an uninitialized #AddressSpace
965 * @root: a #MemoryRegion that routes addesses for the address space
966 * @name: an address space name. The name is only used for debugging
969 void address_space_init(AddressSpace
*as
, MemoryRegion
*root
, const char *name
);
973 * address_space_destroy: destroy an address space
975 * Releases all resources associated with an address space. After an address space
976 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
979 * @as: address space to be destroyed
981 void address_space_destroy(AddressSpace
*as
);
984 * address_space_rw: read from or write to an address space.
986 * Return true if the operation hit any unassigned memory or encountered an
989 * @as: #AddressSpace to be accessed
990 * @addr: address within that address space
991 * @buf: buffer with the data transferred
992 * @is_write: indicates the transfer direction
994 bool address_space_rw(AddressSpace
*as
, hwaddr addr
, uint8_t *buf
,
995 int len
, bool is_write
);
998 * address_space_write: write to address space.
1000 * Return true if the operation hit any unassigned memory or encountered an
1003 * @as: #AddressSpace to be accessed
1004 * @addr: address within that address space
1005 * @buf: buffer with the data transferred
1007 bool address_space_write(AddressSpace
*as
, hwaddr addr
,
1008 const uint8_t *buf
, int len
);
1011 * address_space_read: read from an address space.
1013 * Return true if the operation hit any unassigned memory or encountered an
1016 * @as: #AddressSpace to be accessed
1017 * @addr: address within that address space
1018 * @buf: buffer with the data transferred
1020 bool address_space_read(AddressSpace
*as
, hwaddr addr
, uint8_t *buf
, int len
);
1022 /* address_space_translate: translate an address range into an address space
1023 * into a MemoryRegion and an address range into that section
1025 * @as: #AddressSpace to be accessed
1026 * @addr: address within that address space
1027 * @xlat: pointer to address within the returned memory region section's
1029 * @len: pointer to length
1030 * @is_write: indicates the transfer direction
1032 MemoryRegion
*address_space_translate(AddressSpace
*as
, hwaddr addr
,
1033 hwaddr
*xlat
, hwaddr
*len
,
1036 /* address_space_access_valid: check for validity of accessing an address
1039 * Check whether memory is assigned to the given address space range, and
1040 * access is permitted by any IOMMU regions that are active for the address
1043 * For now, addr and len should be aligned to a page size. This limitation
1044 * will be lifted in the future.
1046 * @as: #AddressSpace to be accessed
1047 * @addr: address within that address space
1048 * @len: length of the area to be checked
1049 * @is_write: indicates the transfer direction
1051 bool address_space_access_valid(AddressSpace
*as
, hwaddr addr
, int len
, bool is_write
);
1053 /* address_space_map: map a physical memory region into a host virtual address
1055 * May map a subset of the requested range, given by and returned in @plen.
1056 * May return %NULL if resources needed to perform the mapping are exhausted.
1057 * Use only for reads OR writes - not for read-modify-write operations.
1058 * Use cpu_register_map_client() to know when retrying the map operation is
1059 * likely to succeed.
1061 * @as: #AddressSpace to be accessed
1062 * @addr: address within that address space
1063 * @plen: pointer to length of buffer; updated on return
1064 * @is_write: indicates the transfer direction
1066 void *address_space_map(AddressSpace
*as
, hwaddr addr
,
1067 hwaddr
*plen
, bool is_write
);
1069 /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
1071 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
1072 * the amount of memory that was actually read or written by the caller.
1074 * @as: #AddressSpace used
1075 * @addr: address within that address space
1076 * @len: buffer length as returned by address_space_map()
1077 * @access_len: amount of data actually transferred
1078 * @is_write: indicates the transfer direction
1080 void address_space_unmap(AddressSpace
*as
, void *buffer
, hwaddr len
,
1081 int is_write
, hwaddr access_len
);