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
21 #include "qemu-common.h"
22 #include "exec/cpu-common.h"
23 #ifndef CONFIG_USER_ONLY
24 #include "exec/hwaddr.h"
26 #include "qemu/queue.h"
27 #include "exec/iorange.h"
28 #include "exec/ioport.h"
29 #include "qemu/int128.h"
30 #include "qemu/notify.h"
32 #define MAX_PHYS_ADDR_SPACE_BITS 62
33 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
35 typedef struct MemoryRegionOps MemoryRegionOps
;
36 typedef struct MemoryRegionPortio MemoryRegionPortio
;
37 typedef struct MemoryRegionMmio MemoryRegionMmio
;
39 /* Must match *_DIRTY_FLAGS in cpu-all.h. To be replaced with dynamic
42 #define DIRTY_MEMORY_VGA 0
43 #define DIRTY_MEMORY_CODE 1
44 #define DIRTY_MEMORY_MIGRATION 3
46 struct MemoryRegionMmio
{
47 CPUReadMemoryFunc
*read
[3];
48 CPUWriteMemoryFunc
*write
[3];
51 /* Internal use; thunks between old-style IORange and MemoryRegions. */
52 typedef struct MemoryRegionIORange MemoryRegionIORange
;
53 struct MemoryRegionIORange
{
59 typedef struct IOMMUTLBEntry IOMMUTLBEntry
;
61 /* See address_space_translate: bit 0 is read, bit 1 is write. */
69 struct IOMMUTLBEntry
{
70 AddressSpace
*target_as
;
72 hwaddr translated_addr
;
73 hwaddr addr_mask
; /* 0xfff = 4k translation */
74 IOMMUAccessFlags perm
;
78 * Memory region callbacks
80 struct MemoryRegionOps
{
81 /* Read from the memory region. @addr is relative to @mr; @size is
83 uint64_t (*read
)(void *opaque
,
86 /* Write to the memory region. @addr is relative to @mr; @size is
88 void (*write
)(void *opaque
,
93 enum device_endian endianness
;
94 /* Guest-visible constraints: */
96 /* If nonzero, specify bounds on access sizes beyond which a machine
99 unsigned min_access_size
;
100 unsigned max_access_size
;
101 /* If true, unaligned accesses are supported. Otherwise unaligned
102 * accesses throw machine checks.
106 * If present, and returns #false, the transaction is not accepted
107 * by the device (and results in machine dependent behaviour such
108 * as a machine check exception).
110 bool (*accepts
)(void *opaque
, hwaddr addr
,
111 unsigned size
, bool is_write
);
113 /* Internal implementation constraints: */
115 /* If nonzero, specifies the minimum size implemented. Smaller sizes
116 * will be rounded upwards and a partial result will be returned.
118 unsigned min_access_size
;
119 /* If nonzero, specifies the maximum size implemented. Larger sizes
120 * will be done as a series of accesses with smaller sizes.
122 unsigned max_access_size
;
123 /* If true, unaligned accesses are supported. Otherwise all accesses
124 * are converted to (possibly multiple) naturally aligned accesses.
129 /* If .read and .write are not present, old_portio may be used for
130 * backwards compatibility with old portio registration
132 const MemoryRegionPortio
*old_portio
;
133 /* If .read and .write are not present, old_mmio may be used for
134 * backwards compatibility with old mmio registration
136 const MemoryRegionMmio old_mmio
;
139 typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps
;
141 struct MemoryRegionIOMMUOps
{
142 /* Return a TLB entry that contains a given address. */
143 IOMMUTLBEntry (*translate
)(MemoryRegion
*iommu
, hwaddr addr
);
146 typedef struct CoalescedMemoryRange CoalescedMemoryRange
;
147 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd
;
149 struct MemoryRegion
{
150 /* All fields are private - violators will be prosecuted */
151 const MemoryRegionOps
*ops
;
152 const MemoryRegionIOMMUOps
*iommu_ops
;
154 MemoryRegion
*parent
;
157 void (*destructor
)(MemoryRegion
*mr
);
163 bool readonly
; /* For RAM regions */
166 bool warning_printed
; /* For reservations */
167 bool flush_coalesced_mmio
;
172 QTAILQ_HEAD(subregions
, MemoryRegion
) subregions
;
173 QTAILQ_ENTRY(MemoryRegion
) subregions_link
;
174 QTAILQ_HEAD(coalesced_ranges
, CoalescedMemoryRange
) coalesced
;
176 uint8_t dirty_log_mask
;
177 unsigned ioeventfd_nb
;
178 MemoryRegionIoeventfd
*ioeventfds
;
179 NotifierList iommu_notify
;
182 struct MemoryRegionPortio
{
186 IOPortReadFunc
*read
;
187 IOPortWriteFunc
*write
;
190 #define PORTIO_END_OF_LIST() { }
193 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
195 struct AddressSpace
{
196 /* All fields are private. */
199 struct FlatView
*current_map
;
201 struct MemoryRegionIoeventfd
*ioeventfds
;
202 struct AddressSpaceDispatch
*dispatch
;
203 QTAILQ_ENTRY(AddressSpace
) address_spaces_link
;
207 * MemoryRegionSection: describes a fragment of a #MemoryRegion
209 * @mr: the region, or %NULL if empty
210 * @address_space: the address space the region is mapped in
211 * @offset_within_region: the beginning of the section, relative to @mr's start
212 * @size: the size of the section; will not exceed @mr's boundaries
213 * @offset_within_address_space: the address of the first byte of the section
214 * relative to the region's address space
215 * @readonly: writes to this section are ignored
217 struct MemoryRegionSection
{
219 AddressSpace
*address_space
;
220 hwaddr offset_within_region
;
222 hwaddr offset_within_address_space
;
226 typedef struct MemoryListener MemoryListener
;
229 * MemoryListener: callbacks structure for updates to the physical memory map
231 * Allows a component to adjust to changes in the guest-visible memory map.
232 * Use with memory_listener_register() and memory_listener_unregister().
234 struct MemoryListener
{
235 void (*begin
)(MemoryListener
*listener
);
236 void (*commit
)(MemoryListener
*listener
);
237 void (*region_add
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
238 void (*region_del
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
239 void (*region_nop
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
240 void (*log_start
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
241 void (*log_stop
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
242 void (*log_sync
)(MemoryListener
*listener
, MemoryRegionSection
*section
);
243 void (*log_global_start
)(MemoryListener
*listener
);
244 void (*log_global_stop
)(MemoryListener
*listener
);
245 void (*eventfd_add
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
246 bool match_data
, uint64_t data
, EventNotifier
*e
);
247 void (*eventfd_del
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
248 bool match_data
, uint64_t data
, EventNotifier
*e
);
249 void (*coalesced_mmio_add
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
250 hwaddr addr
, hwaddr len
);
251 void (*coalesced_mmio_del
)(MemoryListener
*listener
, MemoryRegionSection
*section
,
252 hwaddr addr
, hwaddr len
);
253 /* Lower = earlier (during add), later (during del) */
255 AddressSpace
*address_space_filter
;
256 QTAILQ_ENTRY(MemoryListener
) link
;
260 * memory_region_init: Initialize a memory region
262 * The region typically acts as a container for other memory regions. Use
263 * memory_region_add_subregion() to add subregions.
265 * @mr: the #MemoryRegion to be initialized
266 * @name: used for debugging; not visible to the user or ABI
267 * @size: size of the region; any subregions beyond this size will be clipped
269 void memory_region_init(MemoryRegion
*mr
,
273 * memory_region_init_io: Initialize an I/O memory region.
275 * Accesses into the region will cause the callbacks in @ops to be called.
276 * if @size is nonzero, subregions will be clipped to @size.
278 * @mr: the #MemoryRegion to be initialized.
279 * @ops: a structure containing read and write callbacks to be used when
280 * I/O is performed on the region.
281 * @opaque: passed to to the read and write callbacks of the @ops structure.
282 * @name: used for debugging; not visible to the user or ABI
283 * @size: size of the region.
285 void memory_region_init_io(MemoryRegion
*mr
,
286 const MemoryRegionOps
*ops
,
292 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
293 * region will modify memory directly.
295 * @mr: the #MemoryRegion to be initialized.
296 * @name: the name of the region.
297 * @size: size of the region.
299 void memory_region_init_ram(MemoryRegion
*mr
,
304 * memory_region_init_ram_ptr: Initialize RAM memory region from a
305 * user-provided pointer. Accesses into the
306 * region will modify memory directly.
308 * @mr: the #MemoryRegion to be initialized.
309 * @name: the name of the region.
310 * @size: size of the region.
311 * @ptr: memory to be mapped; must contain at least @size bytes.
313 void memory_region_init_ram_ptr(MemoryRegion
*mr
,
319 * memory_region_init_alias: Initialize a memory region that aliases all or a
320 * part of another memory region.
322 * @mr: the #MemoryRegion to be initialized.
323 * @name: used for debugging; not visible to the user or ABI
324 * @orig: the region to be referenced; @mr will be equivalent to
325 * @orig between @offset and @offset + @size - 1.
326 * @offset: start of the section in @orig to be referenced.
327 * @size: size of the region.
329 void memory_region_init_alias(MemoryRegion
*mr
,
336 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
337 * handled via callbacks.
339 * @mr: the #MemoryRegion to be initialized.
340 * @ops: callbacks for write access handling.
341 * @name: the name of the region.
342 * @size: size of the region.
344 void memory_region_init_rom_device(MemoryRegion
*mr
,
345 const MemoryRegionOps
*ops
,
351 * memory_region_init_reservation: Initialize a memory region that reserves
354 * A reservation region primariy serves debugging purposes. It claims I/O
355 * space that is not supposed to be handled by QEMU itself. Any access via
356 * the memory API will cause an abort().
358 * @mr: the #MemoryRegion to be initialized
359 * @name: used for debugging; not visible to the user or ABI
360 * @size: size of the region.
362 void memory_region_init_reservation(MemoryRegion
*mr
,
367 * memory_region_init_iommu: Initialize a memory region that translates
370 * An IOMMU region translates addresses and forwards accesses to a target
373 * @mr: the #MemoryRegion to be initialized
374 * @ops: a function that translates addresses into the @target region
375 * @name: used for debugging; not visible to the user or ABI
376 * @size: size of the region.
378 void memory_region_init_iommu(MemoryRegion
*mr
,
379 const MemoryRegionIOMMUOps
*ops
,
384 * memory_region_destroy: Destroy a memory region and reclaim all resources.
386 * @mr: the region to be destroyed. May not currently be a subregion
387 * (see memory_region_add_subregion()) or referenced in an alias
388 * (see memory_region_init_alias()).
390 void memory_region_destroy(MemoryRegion
*mr
);
393 * memory_region_size: get a memory region's size.
395 * @mr: the memory region being queried.
397 uint64_t memory_region_size(MemoryRegion
*mr
);
400 * memory_region_is_ram: check whether a memory region is random access
402 * Returns %true is a memory region is random access.
404 * @mr: the memory region being queried
406 bool memory_region_is_ram(MemoryRegion
*mr
);
409 * memory_region_is_romd: check whether a memory region is in ROMD mode
411 * Returns %true if a memory region is a ROM device and currently set to allow
414 * @mr: the memory region being queried
416 static inline bool memory_region_is_romd(MemoryRegion
*mr
)
418 return mr
->rom_device
&& mr
->romd_mode
;
422 * memory_region_is_iommu: check whether a memory region is an iommu
424 * Returns %true is a memory region is an iommu.
426 * @mr: the memory region being queried
428 bool memory_region_is_iommu(MemoryRegion
*mr
);
431 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
433 * @mr: the memory region that was changed
434 * @entry: the new entry in the IOMMU translation table. The entry
435 * replaces all old entries for the same virtual I/O address range.
436 * Deleted entries have .@perm == 0.
438 void memory_region_notify_iommu(MemoryRegion
*mr
,
439 IOMMUTLBEntry entry
);
442 * memory_region_register_iommu_notifier: register a notifier for changes to
443 * IOMMU translation entries.
445 * @mr: the memory region to observe
446 * @n: the notifier to be added; the notifier receives a pointer to an
447 * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
448 * valid on exit from the notifier.
450 void memory_region_register_iommu_notifier(MemoryRegion
*mr
, Notifier
*n
);
453 * memory_region_unregister_iommu_notifier: unregister a notifier for
454 * changes to IOMMU translation entries.
456 * @n: the notifier to be removed.
458 void memory_region_unregister_iommu_notifier(Notifier
*n
);
461 * memory_region_name: get a memory region's name
463 * Returns the string that was used to initialize the memory region.
465 * @mr: the memory region being queried
467 const char *memory_region_name(MemoryRegion
*mr
);
470 * memory_region_is_logging: return whether a memory region is logging writes
472 * Returns %true if the memory region is logging writes
474 * @mr: the memory region being queried
476 bool memory_region_is_logging(MemoryRegion
*mr
);
479 * memory_region_is_rom: check whether a memory region is ROM
481 * Returns %true is a memory region is read-only memory.
483 * @mr: the memory region being queried
485 bool memory_region_is_rom(MemoryRegion
*mr
);
488 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
490 * Returns a host pointer to a RAM memory region (created with
491 * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
494 * @mr: the memory region being queried.
496 void *memory_region_get_ram_ptr(MemoryRegion
*mr
);
499 * memory_region_set_log: Turn dirty logging on or off for a region.
501 * Turns dirty logging on or off for a specified client (display, migration).
502 * Only meaningful for RAM regions.
504 * @mr: the memory region being updated.
505 * @log: whether dirty logging is to be enabled or disabled.
506 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
509 void memory_region_set_log(MemoryRegion
*mr
, bool log
, unsigned client
);
512 * memory_region_get_dirty: Check whether a range of bytes is dirty
513 * for a specified client.
515 * Checks whether a range of bytes has been written to since the last
516 * call to memory_region_reset_dirty() with the same @client. Dirty logging
519 * @mr: the memory region being queried.
520 * @addr: the address (relative to the start of the region) being queried.
521 * @size: the size of the range being queried.
522 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
525 bool memory_region_get_dirty(MemoryRegion
*mr
, hwaddr addr
,
526 hwaddr size
, unsigned client
);
529 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
531 * Marks a range of bytes as dirty, after it has been dirtied outside
534 * @mr: the memory region being dirtied.
535 * @addr: the address (relative to the start of the region) being dirtied.
536 * @size: size of the range being dirtied.
538 void memory_region_set_dirty(MemoryRegion
*mr
, hwaddr addr
,
542 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
543 * for a specified client. It clears them.
545 * Checks whether a range of bytes has been written to since the last
546 * call to memory_region_reset_dirty() with the same @client. Dirty logging
549 * @mr: the memory region being queried.
550 * @addr: the address (relative to the start of the region) being queried.
551 * @size: the size of the range being queried.
552 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
555 bool memory_region_test_and_clear_dirty(MemoryRegion
*mr
, hwaddr addr
,
556 hwaddr size
, unsigned client
);
558 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
559 * any external TLBs (e.g. kvm)
561 * Flushes dirty information from accelerators such as kvm and vhost-net
562 * and makes it available to users of the memory API.
564 * @mr: the region being flushed.
566 void memory_region_sync_dirty_bitmap(MemoryRegion
*mr
);
569 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
572 * Marks a range of pages as no longer dirty.
574 * @mr: the region being updated.
575 * @addr: the start of the subrange being cleaned.
576 * @size: the size of the subrange being cleaned.
577 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
580 void memory_region_reset_dirty(MemoryRegion
*mr
, hwaddr addr
,
581 hwaddr size
, unsigned client
);
584 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
586 * Allows a memory region to be marked as read-only (turning it into a ROM).
587 * only useful on RAM regions.
589 * @mr: the region being updated.
590 * @readonly: whether rhe region is to be ROM or RAM.
592 void memory_region_set_readonly(MemoryRegion
*mr
, bool readonly
);
595 * memory_region_rom_device_set_romd: enable/disable ROMD mode
597 * Allows a ROM device (initialized with memory_region_init_rom_device() to
598 * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
599 * device is mapped to guest memory and satisfies read access directly.
600 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
601 * Writes are always handled by the #MemoryRegion.write function.
603 * @mr: the memory region to be updated
604 * @romd_mode: %true to put the region into ROMD mode
606 void memory_region_rom_device_set_romd(MemoryRegion
*mr
, bool romd_mode
);
609 * memory_region_set_coalescing: Enable memory coalescing for the region.
611 * Enabled writes to a region to be queued for later processing. MMIO ->write
612 * callbacks may be delayed until a non-coalesced MMIO is issued.
613 * Only useful for IO regions. Roughly similar to write-combining hardware.
615 * @mr: the memory region to be write coalesced
617 void memory_region_set_coalescing(MemoryRegion
*mr
);
620 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
623 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
624 * Multiple calls can be issued coalesced disjoint ranges.
626 * @mr: the memory region to be updated.
627 * @offset: the start of the range within the region to be coalesced.
628 * @size: the size of the subrange to be coalesced.
630 void memory_region_add_coalescing(MemoryRegion
*mr
,
635 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
637 * Disables any coalescing caused by memory_region_set_coalescing() or
638 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
641 * @mr: the memory region to be updated.
643 void memory_region_clear_coalescing(MemoryRegion
*mr
);
646 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
649 * Ensure that pending coalesced MMIO request are flushed before the memory
650 * region is accessed. This property is automatically enabled for all regions
651 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
653 * @mr: the memory region to be updated.
655 void memory_region_set_flush_coalesced(MemoryRegion
*mr
);
658 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
661 * Clear the automatic coalesced MMIO flushing enabled via
662 * memory_region_set_flush_coalesced. Note that this service has no effect on
663 * memory regions that have MMIO coalescing enabled for themselves. For them,
664 * automatic flushing will stop once coalescing is disabled.
666 * @mr: the memory region to be updated.
668 void memory_region_clear_flush_coalesced(MemoryRegion
*mr
);
671 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
672 * is written to a location.
674 * Marks a word in an IO region (initialized with memory_region_init_io())
675 * as a trigger for an eventfd event. The I/O callback will not be called.
676 * The caller must be prepared to handle failure (that is, take the required
677 * action if the callback _is_ called).
679 * @mr: the memory region being updated.
680 * @addr: the address within @mr that is to be monitored
681 * @size: the size of the access to trigger the eventfd
682 * @match_data: whether to match against @data, instead of just @addr
683 * @data: the data to match against the guest write
684 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
686 void memory_region_add_eventfd(MemoryRegion
*mr
,
694 * memory_region_del_eventfd: Cancel an eventfd.
696 * Cancels an eventfd trigger requested by a previous
697 * memory_region_add_eventfd() call.
699 * @mr: the memory region being updated.
700 * @addr: the address within @mr that is to be monitored
701 * @size: the size of the access to trigger the eventfd
702 * @match_data: whether to match against @data, instead of just @addr
703 * @data: the data to match against the guest write
704 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
706 void memory_region_del_eventfd(MemoryRegion
*mr
,
714 * memory_region_add_subregion: Add a subregion to a container.
716 * Adds a subregion at @offset. The subregion may not overlap with other
717 * subregions (except for those explicitly marked as overlapping). A region
718 * may only be added once as a subregion (unless removed with
719 * memory_region_del_subregion()); use memory_region_init_alias() if you
720 * want a region to be a subregion in multiple locations.
722 * @mr: the region to contain the new subregion; must be a container
723 * initialized with memory_region_init().
724 * @offset: the offset relative to @mr where @subregion is added.
725 * @subregion: the subregion to be added.
727 void memory_region_add_subregion(MemoryRegion
*mr
,
729 MemoryRegion
*subregion
);
731 * memory_region_add_subregion_overlap: Add a subregion to a container
734 * Adds a subregion at @offset. The subregion may overlap with other
735 * subregions. Conflicts are resolved by having a higher @priority hide a
736 * lower @priority. Subregions without priority are taken as @priority 0.
737 * A region may only be added once as a subregion (unless removed with
738 * memory_region_del_subregion()); use memory_region_init_alias() if you
739 * want a region to be a subregion in multiple locations.
741 * @mr: the region to contain the new subregion; must be a container
742 * initialized with memory_region_init().
743 * @offset: the offset relative to @mr where @subregion is added.
744 * @subregion: the subregion to be added.
745 * @priority: used for resolving overlaps; highest priority wins.
747 void memory_region_add_subregion_overlap(MemoryRegion
*mr
,
749 MemoryRegion
*subregion
,
753 * memory_region_get_ram_addr: Get the ram address associated with a memory
756 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
757 * code is being reworked.
759 ram_addr_t
memory_region_get_ram_addr(MemoryRegion
*mr
);
762 * memory_region_del_subregion: Remove a subregion.
764 * Removes a subregion from its container.
766 * @mr: the container to be updated.
767 * @subregion: the region being removed; must be a current subregion of @mr.
769 void memory_region_del_subregion(MemoryRegion
*mr
,
770 MemoryRegion
*subregion
);
773 * memory_region_set_enabled: dynamically enable or disable a region
775 * Enables or disables a memory region. A disabled memory region
776 * ignores all accesses to itself and its subregions. It does not
777 * obscure sibling subregions with lower priority - it simply behaves as
778 * if it was removed from the hierarchy.
780 * Regions default to being enabled.
782 * @mr: the region to be updated
783 * @enabled: whether to enable or disable the region
785 void memory_region_set_enabled(MemoryRegion
*mr
, bool enabled
);
788 * memory_region_set_address: dynamically update the address of a region
790 * Dynamically updates the address of a region, relative to its parent.
791 * May be used on regions are currently part of a memory hierarchy.
793 * @mr: the region to be updated
794 * @addr: new address, relative to parent region
796 void memory_region_set_address(MemoryRegion
*mr
, hwaddr addr
);
799 * memory_region_set_alias_offset: dynamically update a memory alias's offset
801 * Dynamically updates the offset into the target region that an alias points
802 * to, as if the fourth argument to memory_region_init_alias() has changed.
804 * @mr: the #MemoryRegion to be updated; should be an alias.
805 * @offset: the new offset into the target memory region
807 void memory_region_set_alias_offset(MemoryRegion
*mr
,
811 * memory_region_find: translate an address/size relative to a
812 * MemoryRegion into a #MemoryRegionSection.
814 * Locates the first #MemoryRegion within @mr that overlaps the range
815 * given by @addr and @size.
817 * Returns a #MemoryRegionSection that describes a contiguous overlap.
818 * It will have the following characteristics:
819 * .@size = 0 iff no overlap was found
820 * .@mr is non-%NULL iff an overlap was found
822 * Remember that in the return value the @offset_within_region is
823 * relative to the returned region (in the .@mr field), not to the
826 * Similarly, the .@offset_within_address_space is relative to the
827 * address space that contains both regions, the passed and the
828 * returned one. However, in the special case where the @mr argument
829 * has no parent (and thus is the root of the address space), the
830 * following will hold:
831 * .@offset_within_address_space >= @addr
832 * .@offset_within_address_space + .@size <= @addr + @size
834 * @mr: a MemoryRegion within which @addr is a relative address
835 * @addr: start of the area within @as to be searched
836 * @size: size of the area to be searched
838 MemoryRegionSection
memory_region_find(MemoryRegion
*mr
,
839 hwaddr addr
, uint64_t size
);
842 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
844 * Synchronizes the dirty page log for an entire address space.
845 * @as: the address space that contains the memory being synchronized
847 void address_space_sync_dirty_bitmap(AddressSpace
*as
);
850 * memory_region_transaction_begin: Start a transaction.
852 * During a transaction, changes will be accumulated and made visible
853 * only when the transaction ends (is committed).
855 void memory_region_transaction_begin(void);
858 * memory_region_transaction_commit: Commit a transaction and make changes
859 * visible to the guest.
861 void memory_region_transaction_commit(void);
864 * memory_listener_register: register callbacks to be called when memory
865 * sections are mapped or unmapped into an address
868 * @listener: an object containing the callbacks to be called
869 * @filter: if non-%NULL, only regions in this address space will be observed
871 void memory_listener_register(MemoryListener
*listener
, AddressSpace
*filter
);
874 * memory_listener_unregister: undo the effect of memory_listener_register()
876 * @listener: an object containing the callbacks to be removed
878 void memory_listener_unregister(MemoryListener
*listener
);
881 * memory_global_dirty_log_start: begin dirty logging for all regions
883 void memory_global_dirty_log_start(void);
886 * memory_global_dirty_log_stop: end dirty logging for all regions
888 void memory_global_dirty_log_stop(void);
890 void mtree_info(fprintf_function mon_printf
, void *f
);
893 * address_space_init: initializes an address space
895 * @as: an uninitialized #AddressSpace
896 * @root: a #MemoryRegion that routes addesses for the address space
897 * @name: an address space name. The name is only used for debugging
900 void address_space_init(AddressSpace
*as
, MemoryRegion
*root
, const char *name
);
904 * address_space_destroy: destroy an address space
906 * Releases all resources associated with an address space. After an address space
907 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
910 * @as: address space to be destroyed
912 void address_space_destroy(AddressSpace
*as
);
915 * address_space_rw: read from or write to an address space.
917 * Return true if the operation hit any unassigned memory or encountered an
920 * @as: #AddressSpace to be accessed
921 * @addr: address within that address space
922 * @buf: buffer with the data transferred
923 * @is_write: indicates the transfer direction
925 bool address_space_rw(AddressSpace
*as
, hwaddr addr
, uint8_t *buf
,
926 int len
, bool is_write
);
929 * address_space_write: write to address space.
931 * Return true if the operation hit any unassigned memory or encountered an
934 * @as: #AddressSpace to be accessed
935 * @addr: address within that address space
936 * @buf: buffer with the data transferred
938 bool address_space_write(AddressSpace
*as
, hwaddr addr
,
939 const uint8_t *buf
, int len
);
942 * address_space_read: read from an address space.
944 * Return true if the operation hit any unassigned memory or encountered an
947 * @as: #AddressSpace to be accessed
948 * @addr: address within that address space
949 * @buf: buffer with the data transferred
951 bool address_space_read(AddressSpace
*as
, hwaddr addr
, uint8_t *buf
, int len
);
953 /* address_space_translate: translate an address range into an address space
954 * into a MemoryRegion and an address range into that section
956 * @as: #AddressSpace to be accessed
957 * @addr: address within that address space
958 * @xlat: pointer to address within the returned memory region section's
960 * @len: pointer to length
961 * @is_write: indicates the transfer direction
963 MemoryRegion
*address_space_translate(AddressSpace
*as
, hwaddr addr
,
964 hwaddr
*xlat
, hwaddr
*len
,
967 /* address_space_access_valid: check for validity of accessing an address
970 * Check whether memory is assigned to the given address space range, and
971 * access is permitted by any IOMMU regions that are active for the address
974 * For now, addr and len should be aligned to a page size. This limitation
975 * will be lifted in the future.
977 * @as: #AddressSpace to be accessed
978 * @addr: address within that address space
979 * @len: length of the area to be checked
980 * @is_write: indicates the transfer direction
982 bool address_space_access_valid(AddressSpace
*as
, hwaddr addr
, int len
, bool is_write
);
984 /* address_space_map: map a physical memory region into a host virtual address
986 * May map a subset of the requested range, given by and returned in @plen.
987 * May return %NULL if resources needed to perform the mapping are exhausted.
988 * Use only for reads OR writes - not for read-modify-write operations.
989 * Use cpu_register_map_client() to know when retrying the map operation is
992 * @as: #AddressSpace to be accessed
993 * @addr: address within that address space
994 * @plen: pointer to length of buffer; updated on return
995 * @is_write: indicates the transfer direction
997 void *address_space_map(AddressSpace
*as
, hwaddr addr
,
998 hwaddr
*plen
, bool is_write
);
1000 /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
1002 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
1003 * the amount of memory that was actually read or written by the caller.
1005 * @as: #AddressSpace used
1006 * @addr: address within that address space
1007 * @len: buffer length as returned by address_space_map()
1008 * @access_len: amount of data actually transferred
1009 * @is_write: indicates the transfer direction
1011 void address_space_unmap(AddressSpace
*as
, void *buffer
, hwaddr len
,
1012 int is_write
, hwaddr access_len
);