memory: add owner argument to initialization functions
[qemu/ar7.git] / include / exec / memory.h
blob3f48f076396a5ad450f306734abc79080a545b77
1 /*
2 * Physical memory management API
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef MEMORY_H
15 #define MEMORY_H
17 #ifndef CONFIG_USER_ONLY
19 #include <stdint.h>
20 #include <stdbool.h>
21 #include "qemu-common.h"
22 #include "exec/cpu-common.h"
23 #ifndef CONFIG_USER_ONLY
24 #include "exec/hwaddr.h"
25 #endif
26 #include "qemu/queue.h"
27 #include "qemu/int128.h"
28 #include "qemu/notify.h"
30 #define MAX_PHYS_ADDR_SPACE_BITS 62
31 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
33 typedef struct MemoryRegionOps MemoryRegionOps;
34 typedef struct MemoryRegionMmio MemoryRegionMmio;
36 /* Must match *_DIRTY_FLAGS in cpu-all.h. To be replaced with dynamic
37 * registration.
39 #define DIRTY_MEMORY_VGA 0
40 #define DIRTY_MEMORY_CODE 1
41 #define DIRTY_MEMORY_MIGRATION 3
43 struct MemoryRegionMmio {
44 CPUReadMemoryFunc *read[3];
45 CPUWriteMemoryFunc *write[3];
48 typedef struct IOMMUTLBEntry IOMMUTLBEntry;
50 /* See address_space_translate: bit 0 is read, bit 1 is write. */
51 typedef enum {
52 IOMMU_NONE = 0,
53 IOMMU_RO = 1,
54 IOMMU_WO = 2,
55 IOMMU_RW = 3,
56 } IOMMUAccessFlags;
58 struct IOMMUTLBEntry {
59 AddressSpace *target_as;
60 hwaddr iova;
61 hwaddr translated_addr;
62 hwaddr addr_mask; /* 0xfff = 4k translation */
63 IOMMUAccessFlags perm;
67 * Memory region callbacks
69 struct MemoryRegionOps {
70 /* Read from the memory region. @addr is relative to @mr; @size is
71 * in bytes. */
72 uint64_t (*read)(void *opaque,
73 hwaddr addr,
74 unsigned size);
75 /* Write to the memory region. @addr is relative to @mr; @size is
76 * in bytes. */
77 void (*write)(void *opaque,
78 hwaddr addr,
79 uint64_t data,
80 unsigned size);
82 enum device_endian endianness;
83 /* Guest-visible constraints: */
84 struct {
85 /* If nonzero, specify bounds on access sizes beyond which a machine
86 * check is thrown.
88 unsigned min_access_size;
89 unsigned max_access_size;
90 /* If true, unaligned accesses are supported. Otherwise unaligned
91 * accesses throw machine checks.
93 bool unaligned;
95 * If present, and returns #false, the transaction is not accepted
96 * by the device (and results in machine dependent behaviour such
97 * as a machine check exception).
99 bool (*accepts)(void *opaque, hwaddr addr,
100 unsigned size, bool is_write);
101 } valid;
102 /* Internal implementation constraints: */
103 struct {
104 /* If nonzero, specifies the minimum size implemented. Smaller sizes
105 * will be rounded upwards and a partial result will be returned.
107 unsigned min_access_size;
108 /* If nonzero, specifies the maximum size implemented. Larger sizes
109 * will be done as a series of accesses with smaller sizes.
111 unsigned max_access_size;
112 /* If true, unaligned accesses are supported. Otherwise all accesses
113 * are converted to (possibly multiple) naturally aligned accesses.
115 bool unaligned;
116 } impl;
118 /* If .read and .write are not present, old_mmio may be used for
119 * backwards compatibility with old mmio registration
121 const MemoryRegionMmio old_mmio;
124 typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps;
126 struct MemoryRegionIOMMUOps {
127 /* Return a TLB entry that contains a given address. */
128 IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr);
131 typedef struct CoalescedMemoryRange CoalescedMemoryRange;
132 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
134 struct MemoryRegion {
135 /* All fields are private - violators will be prosecuted */
136 const MemoryRegionOps *ops;
137 const MemoryRegionIOMMUOps *iommu_ops;
138 void *opaque;
139 struct Object *owner;
140 MemoryRegion *parent;
141 Int128 size;
142 hwaddr addr;
143 void (*destructor)(MemoryRegion *mr);
144 ram_addr_t ram_addr;
145 bool subpage;
146 bool terminates;
147 bool romd_mode;
148 bool ram;
149 bool readonly; /* For RAM regions */
150 bool enabled;
151 bool rom_device;
152 bool warning_printed; /* For reservations */
153 bool flush_coalesced_mmio;
154 MemoryRegion *alias;
155 hwaddr alias_offset;
156 unsigned priority;
157 bool may_overlap;
158 QTAILQ_HEAD(subregions, MemoryRegion) subregions;
159 QTAILQ_ENTRY(MemoryRegion) subregions_link;
160 QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
161 const char *name;
162 uint8_t dirty_log_mask;
163 unsigned ioeventfd_nb;
164 MemoryRegionIoeventfd *ioeventfds;
165 NotifierList iommu_notify;
169 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
171 struct AddressSpace {
172 /* All fields are private. */
173 char *name;
174 MemoryRegion *root;
175 struct FlatView *current_map;
176 int ioeventfd_nb;
177 struct MemoryRegionIoeventfd *ioeventfds;
178 struct AddressSpaceDispatch *dispatch;
179 QTAILQ_ENTRY(AddressSpace) address_spaces_link;
183 * MemoryRegionSection: describes a fragment of a #MemoryRegion
185 * @mr: the region, or %NULL if empty
186 * @address_space: the address space the region is mapped in
187 * @offset_within_region: the beginning of the section, relative to @mr's start
188 * @size: the size of the section; will not exceed @mr's boundaries
189 * @offset_within_address_space: the address of the first byte of the section
190 * relative to the region's address space
191 * @readonly: writes to this section are ignored
193 struct MemoryRegionSection {
194 MemoryRegion *mr;
195 AddressSpace *address_space;
196 hwaddr offset_within_region;
197 Int128 size;
198 hwaddr offset_within_address_space;
199 bool readonly;
202 typedef struct MemoryListener MemoryListener;
205 * MemoryListener: callbacks structure for updates to the physical memory map
207 * Allows a component to adjust to changes in the guest-visible memory map.
208 * Use with memory_listener_register() and memory_listener_unregister().
210 struct MemoryListener {
211 void (*begin)(MemoryListener *listener);
212 void (*commit)(MemoryListener *listener);
213 void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
214 void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
215 void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
216 void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
217 void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
218 void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
219 void (*log_global_start)(MemoryListener *listener);
220 void (*log_global_stop)(MemoryListener *listener);
221 void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
222 bool match_data, uint64_t data, EventNotifier *e);
223 void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
224 bool match_data, uint64_t data, EventNotifier *e);
225 void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
226 hwaddr addr, hwaddr len);
227 void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
228 hwaddr addr, hwaddr len);
229 /* Lower = earlier (during add), later (during del) */
230 unsigned priority;
231 AddressSpace *address_space_filter;
232 QTAILQ_ENTRY(MemoryListener) link;
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,
248 const char *name,
249 uint64_t size);
251 * memory_region_init_io: Initialize an I/O memory region.
253 * Accesses into the region will cause the callbacks in @ops to be called.
254 * if @size is nonzero, subregions will be clipped to @size.
256 * @mr: the #MemoryRegion to be initialized.
257 * @owner: the object that tracks the region's reference count
258 * @ops: a structure containing read and write callbacks to be used when
259 * I/O is performed on the region.
260 * @opaque: passed to to the read and write callbacks of the @ops structure.
261 * @name: used for debugging; not visible to the user or ABI
262 * @size: size of the region.
264 void memory_region_init_io(MemoryRegion *mr,
265 struct Object *owner,
266 const MemoryRegionOps *ops,
267 void *opaque,
268 const char *name,
269 uint64_t size);
272 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
273 * region will modify memory directly.
275 * @mr: the #MemoryRegion to be initialized.
276 * @owner: the object that tracks the region's reference count
277 * @name: the name of the region.
278 * @size: size of the region.
280 void memory_region_init_ram(MemoryRegion *mr,
281 struct Object *owner,
282 const char *name,
283 uint64_t size);
286 * memory_region_init_ram_ptr: Initialize RAM memory region from a
287 * user-provided pointer. Accesses into the
288 * region will modify memory directly.
290 * @mr: the #MemoryRegion to be initialized.
291 * @owner: the object that tracks the region's reference count
292 * @name: the name of the region.
293 * @size: size of the region.
294 * @ptr: memory to be mapped; must contain at least @size bytes.
296 void memory_region_init_ram_ptr(MemoryRegion *mr,
297 struct Object *owner,
298 const char *name,
299 uint64_t size,
300 void *ptr);
303 * memory_region_init_alias: Initialize a memory region that aliases all or a
304 * part of another memory region.
306 * @mr: the #MemoryRegion to be initialized.
307 * @owner: the object that tracks the region's reference count
308 * @name: used for debugging; not visible to the user or ABI
309 * @orig: the region to be referenced; @mr will be equivalent to
310 * @orig between @offset and @offset + @size - 1.
311 * @offset: start of the section in @orig to be referenced.
312 * @size: size of the region.
314 void memory_region_init_alias(MemoryRegion *mr,
315 struct Object *owner,
316 const char *name,
317 MemoryRegion *orig,
318 hwaddr offset,
319 uint64_t size);
322 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
323 * handled via callbacks.
325 * @mr: the #MemoryRegion to be initialized.
326 * @owner: the object that tracks the region's reference count
327 * @ops: callbacks for write access handling.
328 * @name: the name of the region.
329 * @size: size of the region.
331 void memory_region_init_rom_device(MemoryRegion *mr,
332 struct Object *owner,
333 const MemoryRegionOps *ops,
334 void *opaque,
335 const char *name,
336 uint64_t size);
339 * memory_region_init_reservation: Initialize a memory region that reserves
340 * I/O space.
342 * A reservation region primariy serves debugging purposes. It claims I/O
343 * space that is not supposed to be handled by QEMU itself. Any access via
344 * the memory API will cause an abort().
346 * @mr: the #MemoryRegion to be initialized
347 * @owner: the object that tracks the region's reference count
348 * @name: used for debugging; not visible to the user or ABI
349 * @size: size of the region.
351 void memory_region_init_reservation(MemoryRegion *mr,
352 struct Object *owner,
353 const char *name,
354 uint64_t size);
357 * memory_region_init_iommu: Initialize a memory region that translates
358 * addresses
360 * An IOMMU region translates addresses and forwards accesses to a target
361 * memory region.
363 * @mr: the #MemoryRegion to be initialized
364 * @owner: the object that tracks the region's reference count
365 * @ops: a function that translates addresses into the @target region
366 * @name: used for debugging; not visible to the user or ABI
367 * @size: size of the region.
369 void memory_region_init_iommu(MemoryRegion *mr,
370 struct Object *owner,
371 const MemoryRegionIOMMUOps *ops,
372 const char *name,
373 uint64_t size);
376 * memory_region_destroy: Destroy a memory region and reclaim all resources.
378 * @mr: the region to be destroyed. May not currently be a subregion
379 * (see memory_region_add_subregion()) or referenced in an alias
380 * (see memory_region_init_alias()).
382 void memory_region_destroy(MemoryRegion *mr);
385 * memory_region_size: get a memory region's size.
387 * @mr: the memory region being queried.
389 uint64_t memory_region_size(MemoryRegion *mr);
392 * memory_region_is_ram: check whether a memory region is random access
394 * Returns %true is a memory region is random access.
396 * @mr: the memory region being queried
398 bool memory_region_is_ram(MemoryRegion *mr);
401 * memory_region_is_romd: check whether a memory region is in ROMD mode
403 * Returns %true if a memory region is a ROM device and currently set to allow
404 * direct reads.
406 * @mr: the memory region being queried
408 static inline bool memory_region_is_romd(MemoryRegion *mr)
410 return mr->rom_device && mr->romd_mode;
414 * memory_region_is_iommu: check whether a memory region is an iommu
416 * Returns %true is a memory region is an iommu.
418 * @mr: the memory region being queried
420 bool memory_region_is_iommu(MemoryRegion *mr);
423 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
425 * @mr: the memory region that was changed
426 * @entry: the new entry in the IOMMU translation table. The entry
427 * replaces all old entries for the same virtual I/O address range.
428 * Deleted entries have .@perm == 0.
430 void memory_region_notify_iommu(MemoryRegion *mr,
431 IOMMUTLBEntry entry);
434 * memory_region_register_iommu_notifier: register a notifier for changes to
435 * IOMMU translation entries.
437 * @mr: the memory region to observe
438 * @n: the notifier to be added; the notifier receives a pointer to an
439 * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
440 * valid on exit from the notifier.
442 void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
445 * memory_region_unregister_iommu_notifier: unregister a notifier for
446 * changes to IOMMU translation entries.
448 * @n: the notifier to be removed.
450 void memory_region_unregister_iommu_notifier(Notifier *n);
453 * memory_region_name: get a memory region's name
455 * Returns the string that was used to initialize the memory region.
457 * @mr: the memory region being queried
459 const char *memory_region_name(MemoryRegion *mr);
462 * memory_region_is_logging: return whether a memory region is logging writes
464 * Returns %true if the memory region is logging writes
466 * @mr: the memory region being queried
468 bool memory_region_is_logging(MemoryRegion *mr);
471 * memory_region_is_rom: check whether a memory region is ROM
473 * Returns %true is a memory region is read-only memory.
475 * @mr: the memory region being queried
477 bool memory_region_is_rom(MemoryRegion *mr);
480 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
482 * Returns a host pointer to a RAM memory region (created with
483 * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
484 * care.
486 * @mr: the memory region being queried.
488 void *memory_region_get_ram_ptr(MemoryRegion *mr);
491 * memory_region_set_log: Turn dirty logging on or off for a region.
493 * Turns dirty logging on or off for a specified client (display, migration).
494 * Only meaningful for RAM regions.
496 * @mr: the memory region being updated.
497 * @log: whether dirty logging is to be enabled or disabled.
498 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
499 * %DIRTY_MEMORY_VGA.
501 void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);
504 * memory_region_get_dirty: Check whether a range of bytes is dirty
505 * for a specified client.
507 * Checks whether a range of bytes has been written to since the last
508 * call to memory_region_reset_dirty() with the same @client. Dirty logging
509 * must be enabled.
511 * @mr: the memory region being queried.
512 * @addr: the address (relative to the start of the region) being queried.
513 * @size: the size of the range being queried.
514 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
515 * %DIRTY_MEMORY_VGA.
517 bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
518 hwaddr size, unsigned client);
521 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
523 * Marks a range of bytes as dirty, after it has been dirtied outside
524 * guest code.
526 * @mr: the memory region being dirtied.
527 * @addr: the address (relative to the start of the region) being dirtied.
528 * @size: size of the range being dirtied.
530 void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
531 hwaddr size);
534 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
535 * for a specified client. It clears them.
537 * Checks whether a range of bytes has been written to since the last
538 * call to memory_region_reset_dirty() with the same @client. Dirty logging
539 * must be enabled.
541 * @mr: the memory region being queried.
542 * @addr: the address (relative to the start of the region) being queried.
543 * @size: the size of the range being queried.
544 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
545 * %DIRTY_MEMORY_VGA.
547 bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
548 hwaddr size, unsigned client);
550 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
551 * any external TLBs (e.g. kvm)
553 * Flushes dirty information from accelerators such as kvm and vhost-net
554 * and makes it available to users of the memory API.
556 * @mr: the region being flushed.
558 void memory_region_sync_dirty_bitmap(MemoryRegion *mr);
561 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
562 * client.
564 * Marks a range of pages as no longer dirty.
566 * @mr: the region being updated.
567 * @addr: the start of the subrange being cleaned.
568 * @size: the size of the subrange being cleaned.
569 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
570 * %DIRTY_MEMORY_VGA.
572 void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
573 hwaddr size, unsigned client);
576 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
578 * Allows a memory region to be marked as read-only (turning it into a ROM).
579 * only useful on RAM regions.
581 * @mr: the region being updated.
582 * @readonly: whether rhe region is to be ROM or RAM.
584 void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
587 * memory_region_rom_device_set_romd: enable/disable ROMD mode
589 * Allows a ROM device (initialized with memory_region_init_rom_device() to
590 * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
591 * device is mapped to guest memory and satisfies read access directly.
592 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
593 * Writes are always handled by the #MemoryRegion.write function.
595 * @mr: the memory region to be updated
596 * @romd_mode: %true to put the region into ROMD mode
598 void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode);
601 * memory_region_set_coalescing: Enable memory coalescing for the region.
603 * Enabled writes to a region to be queued for later processing. MMIO ->write
604 * callbacks may be delayed until a non-coalesced MMIO is issued.
605 * Only useful for IO regions. Roughly similar to write-combining hardware.
607 * @mr: the memory region to be write coalesced
609 void memory_region_set_coalescing(MemoryRegion *mr);
612 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
613 * a region.
615 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
616 * Multiple calls can be issued coalesced disjoint ranges.
618 * @mr: the memory region to be updated.
619 * @offset: the start of the range within the region to be coalesced.
620 * @size: the size of the subrange to be coalesced.
622 void memory_region_add_coalescing(MemoryRegion *mr,
623 hwaddr offset,
624 uint64_t size);
627 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
629 * Disables any coalescing caused by memory_region_set_coalescing() or
630 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
631 * hardware.
633 * @mr: the memory region to be updated.
635 void memory_region_clear_coalescing(MemoryRegion *mr);
638 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
639 * accesses.
641 * Ensure that pending coalesced MMIO request are flushed before the memory
642 * region is accessed. This property is automatically enabled for all regions
643 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
645 * @mr: the memory region to be updated.
647 void memory_region_set_flush_coalesced(MemoryRegion *mr);
650 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
651 * accesses.
653 * Clear the automatic coalesced MMIO flushing enabled via
654 * memory_region_set_flush_coalesced. Note that this service has no effect on
655 * memory regions that have MMIO coalescing enabled for themselves. For them,
656 * automatic flushing will stop once coalescing is disabled.
658 * @mr: the memory region to be updated.
660 void memory_region_clear_flush_coalesced(MemoryRegion *mr);
663 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
664 * is written to a location.
666 * Marks a word in an IO region (initialized with memory_region_init_io())
667 * as a trigger for an eventfd event. The I/O callback will not be called.
668 * The caller must be prepared to handle failure (that is, take the required
669 * action if the callback _is_ called).
671 * @mr: the memory region being updated.
672 * @addr: the address within @mr that is to be monitored
673 * @size: the size of the access to trigger the eventfd
674 * @match_data: whether to match against @data, instead of just @addr
675 * @data: the data to match against the guest write
676 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
678 void memory_region_add_eventfd(MemoryRegion *mr,
679 hwaddr addr,
680 unsigned size,
681 bool match_data,
682 uint64_t data,
683 EventNotifier *e);
686 * memory_region_del_eventfd: Cancel an eventfd.
688 * Cancels an eventfd trigger requested by a previous
689 * memory_region_add_eventfd() call.
691 * @mr: the memory region being updated.
692 * @addr: the address within @mr that is to be monitored
693 * @size: the size of the access to trigger the eventfd
694 * @match_data: whether to match against @data, instead of just @addr
695 * @data: the data to match against the guest write
696 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
698 void memory_region_del_eventfd(MemoryRegion *mr,
699 hwaddr addr,
700 unsigned size,
701 bool match_data,
702 uint64_t data,
703 EventNotifier *e);
706 * memory_region_add_subregion: Add a subregion to a container.
708 * Adds a subregion at @offset. The subregion may not overlap with other
709 * subregions (except for those explicitly marked as overlapping). A region
710 * may only be added once as a subregion (unless removed with
711 * memory_region_del_subregion()); use memory_region_init_alias() if you
712 * want a region to be a subregion in multiple locations.
714 * @mr: the region to contain the new subregion; must be a container
715 * initialized with memory_region_init().
716 * @offset: the offset relative to @mr where @subregion is added.
717 * @subregion: the subregion to be added.
719 void memory_region_add_subregion(MemoryRegion *mr,
720 hwaddr offset,
721 MemoryRegion *subregion);
723 * memory_region_add_subregion_overlap: Add a subregion to a container
724 * with overlap.
726 * Adds a subregion at @offset. The subregion may overlap with other
727 * subregions. Conflicts are resolved by having a higher @priority hide a
728 * lower @priority. Subregions without priority are taken as @priority 0.
729 * A region may only be added once as a subregion (unless removed with
730 * memory_region_del_subregion()); use memory_region_init_alias() if you
731 * want a region to be a subregion in multiple locations.
733 * @mr: the region to contain the new subregion; must be a container
734 * initialized with memory_region_init().
735 * @offset: the offset relative to @mr where @subregion is added.
736 * @subregion: the subregion to be added.
737 * @priority: used for resolving overlaps; highest priority wins.
739 void memory_region_add_subregion_overlap(MemoryRegion *mr,
740 hwaddr offset,
741 MemoryRegion *subregion,
742 unsigned priority);
745 * memory_region_get_ram_addr: Get the ram address associated with a memory
746 * region
748 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
749 * code is being reworked.
751 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr);
754 * memory_region_del_subregion: Remove a subregion.
756 * Removes a subregion from its container.
758 * @mr: the container to be updated.
759 * @subregion: the region being removed; must be a current subregion of @mr.
761 void memory_region_del_subregion(MemoryRegion *mr,
762 MemoryRegion *subregion);
765 * memory_region_set_enabled: dynamically enable or disable a region
767 * Enables or disables a memory region. A disabled memory region
768 * ignores all accesses to itself and its subregions. It does not
769 * obscure sibling subregions with lower priority - it simply behaves as
770 * if it was removed from the hierarchy.
772 * Regions default to being enabled.
774 * @mr: the region to be updated
775 * @enabled: whether to enable or disable the region
777 void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
780 * memory_region_set_address: dynamically update the address of a region
782 * Dynamically updates the address of a region, relative to its parent.
783 * May be used on regions are currently part of a memory hierarchy.
785 * @mr: the region to be updated
786 * @addr: new address, relative to parent region
788 void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
791 * memory_region_set_alias_offset: dynamically update a memory alias's offset
793 * Dynamically updates the offset into the target region that an alias points
794 * to, as if the fourth argument to memory_region_init_alias() has changed.
796 * @mr: the #MemoryRegion to be updated; should be an alias.
797 * @offset: the new offset into the target memory region
799 void memory_region_set_alias_offset(MemoryRegion *mr,
800 hwaddr offset);
803 * memory_region_find: translate an address/size relative to a
804 * MemoryRegion into a #MemoryRegionSection.
806 * Locates the first #MemoryRegion within @mr that overlaps the range
807 * given by @addr and @size.
809 * Returns a #MemoryRegionSection that describes a contiguous overlap.
810 * It will have the following characteristics:
811 * .@size = 0 iff no overlap was found
812 * .@mr is non-%NULL iff an overlap was found
814 * Remember that in the return value the @offset_within_region is
815 * relative to the returned region (in the .@mr field), not to the
816 * @mr argument.
818 * Similarly, the .@offset_within_address_space is relative to the
819 * address space that contains both regions, the passed and the
820 * returned one. However, in the special case where the @mr argument
821 * has no parent (and thus is the root of the address space), the
822 * following will hold:
823 * .@offset_within_address_space >= @addr
824 * .@offset_within_address_space + .@size <= @addr + @size
826 * @mr: a MemoryRegion within which @addr is a relative address
827 * @addr: start of the area within @as to be searched
828 * @size: size of the area to be searched
830 MemoryRegionSection memory_region_find(MemoryRegion *mr,
831 hwaddr addr, uint64_t size);
834 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
836 * Synchronizes the dirty page log for an entire address space.
837 * @as: the address space that contains the memory being synchronized
839 void address_space_sync_dirty_bitmap(AddressSpace *as);
842 * memory_region_transaction_begin: Start a transaction.
844 * During a transaction, changes will be accumulated and made visible
845 * only when the transaction ends (is committed).
847 void memory_region_transaction_begin(void);
850 * memory_region_transaction_commit: Commit a transaction and make changes
851 * visible to the guest.
853 void memory_region_transaction_commit(void);
856 * memory_listener_register: register callbacks to be called when memory
857 * sections are mapped or unmapped into an address
858 * space
860 * @listener: an object containing the callbacks to be called
861 * @filter: if non-%NULL, only regions in this address space will be observed
863 void memory_listener_register(MemoryListener *listener, AddressSpace *filter);
866 * memory_listener_unregister: undo the effect of memory_listener_register()
868 * @listener: an object containing the callbacks to be removed
870 void memory_listener_unregister(MemoryListener *listener);
873 * memory_global_dirty_log_start: begin dirty logging for all regions
875 void memory_global_dirty_log_start(void);
878 * memory_global_dirty_log_stop: end dirty logging for all regions
880 void memory_global_dirty_log_stop(void);
882 void mtree_info(fprintf_function mon_printf, void *f);
885 * address_space_init: initializes an address space
887 * @as: an uninitialized #AddressSpace
888 * @root: a #MemoryRegion that routes addesses for the address space
889 * @name: an address space name. The name is only used for debugging
890 * output.
892 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
896 * address_space_destroy: destroy an address space
898 * Releases all resources associated with an address space. After an address space
899 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
900 * as well.
902 * @as: address space to be destroyed
904 void address_space_destroy(AddressSpace *as);
907 * address_space_rw: read from or write to an address space.
909 * Return true if the operation hit any unassigned memory or encountered an
910 * IOMMU fault.
912 * @as: #AddressSpace to be accessed
913 * @addr: address within that address space
914 * @buf: buffer with the data transferred
915 * @is_write: indicates the transfer direction
917 bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
918 int len, bool is_write);
921 * address_space_write: write to address space.
923 * Return true if the operation hit any unassigned memory or encountered an
924 * IOMMU fault.
926 * @as: #AddressSpace to be accessed
927 * @addr: address within that address space
928 * @buf: buffer with the data transferred
930 bool address_space_write(AddressSpace *as, hwaddr addr,
931 const uint8_t *buf, int len);
934 * address_space_read: read from an address space.
936 * Return true if the operation hit any unassigned memory or encountered an
937 * IOMMU fault.
939 * @as: #AddressSpace to be accessed
940 * @addr: address within that address space
941 * @buf: buffer with the data transferred
943 bool address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
945 /* address_space_translate: translate an address range into an address space
946 * into a MemoryRegion and an address range into that section
948 * @as: #AddressSpace to be accessed
949 * @addr: address within that address space
950 * @xlat: pointer to address within the returned memory region section's
951 * #MemoryRegion.
952 * @len: pointer to length
953 * @is_write: indicates the transfer direction
955 MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
956 hwaddr *xlat, hwaddr *len,
957 bool is_write);
959 /* address_space_access_valid: check for validity of accessing an address
960 * space range
962 * Check whether memory is assigned to the given address space range, and
963 * access is permitted by any IOMMU regions that are active for the address
964 * space.
966 * For now, addr and len should be aligned to a page size. This limitation
967 * will be lifted in the future.
969 * @as: #AddressSpace to be accessed
970 * @addr: address within that address space
971 * @len: length of the area to be checked
972 * @is_write: indicates the transfer direction
974 bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
976 /* address_space_map: map a physical memory region into a host virtual address
978 * May map a subset of the requested range, given by and returned in @plen.
979 * May return %NULL if resources needed to perform the mapping are exhausted.
980 * Use only for reads OR writes - not for read-modify-write operations.
981 * Use cpu_register_map_client() to know when retrying the map operation is
982 * likely to succeed.
984 * @as: #AddressSpace to be accessed
985 * @addr: address within that address space
986 * @plen: pointer to length of buffer; updated on return
987 * @is_write: indicates the transfer direction
989 void *address_space_map(AddressSpace *as, hwaddr addr,
990 hwaddr *plen, bool is_write);
992 /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
994 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
995 * the amount of memory that was actually read or written by the caller.
997 * @as: #AddressSpace used
998 * @addr: address within that address space
999 * @len: buffer length as returned by address_space_map()
1000 * @access_len: amount of data actually transferred
1001 * @is_write: indicates the transfer direction
1003 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
1004 int is_write, hwaddr access_len);
1007 #endif
1009 #endif