man: improve -numa doc
[qemu/cris-port.git] / include / exec / memory.h
blobf4c8d4933e92967d70c9b72654ae65f56ae638d3
1 /*
2 * Physical memory management API
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef MEMORY_H
15 #define MEMORY_H
17 #ifndef CONFIG_USER_ONLY
19 #define DIRTY_MEMORY_VGA 0
20 #define DIRTY_MEMORY_CODE 1
21 #define DIRTY_MEMORY_MIGRATION 2
22 #define DIRTY_MEMORY_NUM 3 /* num of dirty bits */
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include "qemu-common.h"
27 #include "exec/cpu-common.h"
28 #ifndef CONFIG_USER_ONLY
29 #include "exec/hwaddr.h"
30 #endif
31 #include "qemu/queue.h"
32 #include "qemu/int128.h"
33 #include "qemu/notify.h"
35 #define MAX_PHYS_ADDR_SPACE_BITS 62
36 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
38 typedef struct MemoryRegionOps MemoryRegionOps;
39 typedef struct MemoryRegionMmio MemoryRegionMmio;
41 struct MemoryRegionMmio {
42 CPUReadMemoryFunc *read[3];
43 CPUWriteMemoryFunc *write[3];
46 typedef struct IOMMUTLBEntry IOMMUTLBEntry;
48 /* See address_space_translate: bit 0 is read, bit 1 is write. */
49 typedef enum {
50 IOMMU_NONE = 0,
51 IOMMU_RO = 1,
52 IOMMU_WO = 2,
53 IOMMU_RW = 3,
54 } IOMMUAccessFlags;
56 struct IOMMUTLBEntry {
57 AddressSpace *target_as;
58 hwaddr iova;
59 hwaddr translated_addr;
60 hwaddr addr_mask; /* 0xfff = 4k translation */
61 IOMMUAccessFlags perm;
65 * Memory region callbacks
67 struct MemoryRegionOps {
68 /* Read from the memory region. @addr is relative to @mr; @size is
69 * in bytes. */
70 uint64_t (*read)(void *opaque,
71 hwaddr addr,
72 unsigned size);
73 /* Write to the memory region. @addr is relative to @mr; @size is
74 * in bytes. */
75 void (*write)(void *opaque,
76 hwaddr addr,
77 uint64_t data,
78 unsigned size);
80 enum device_endian endianness;
81 /* Guest-visible constraints: */
82 struct {
83 /* If nonzero, specify bounds on access sizes beyond which a machine
84 * check is thrown.
86 unsigned min_access_size;
87 unsigned max_access_size;
88 /* If true, unaligned accesses are supported. Otherwise unaligned
89 * accesses throw machine checks.
91 bool unaligned;
93 * If present, and returns #false, the transaction is not accepted
94 * by the device (and results in machine dependent behaviour such
95 * as a machine check exception).
97 bool (*accepts)(void *opaque, hwaddr addr,
98 unsigned size, bool is_write);
99 } valid;
100 /* Internal implementation constraints: */
101 struct {
102 /* If nonzero, specifies the minimum size implemented. Smaller sizes
103 * will be rounded upwards and a partial result will be returned.
105 unsigned min_access_size;
106 /* If nonzero, specifies the maximum size implemented. Larger sizes
107 * will be done as a series of accesses with smaller sizes.
109 unsigned max_access_size;
110 /* If true, unaligned accesses are supported. Otherwise all accesses
111 * are converted to (possibly multiple) naturally aligned accesses.
113 bool unaligned;
114 } impl;
116 /* If .read and .write are not present, old_mmio may be used for
117 * backwards compatibility with old mmio registration
119 const MemoryRegionMmio old_mmio;
122 typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps;
124 struct MemoryRegionIOMMUOps {
125 /* Return a TLB entry that contains a given address. */
126 IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr);
129 typedef struct CoalescedMemoryRange CoalescedMemoryRange;
130 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
132 struct MemoryRegion {
133 /* All fields are private - violators will be prosecuted */
134 const MemoryRegionOps *ops;
135 const MemoryRegionIOMMUOps *iommu_ops;
136 void *opaque;
137 struct Object *owner;
138 MemoryRegion *container;
139 Int128 size;
140 hwaddr addr;
141 void (*destructor)(MemoryRegion *mr);
142 ram_addr_t ram_addr;
143 bool subpage;
144 bool terminates;
145 bool romd_mode;
146 bool ram;
147 bool readonly; /* For RAM regions */
148 bool enabled;
149 bool rom_device;
150 bool warning_printed; /* For reservations */
151 bool flush_coalesced_mmio;
152 MemoryRegion *alias;
153 hwaddr alias_offset;
154 int priority;
155 bool may_overlap;
156 QTAILQ_HEAD(subregions, MemoryRegion) subregions;
157 QTAILQ_ENTRY(MemoryRegion) subregions_link;
158 QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
159 const char *name;
160 uint8_t dirty_log_mask;
161 unsigned ioeventfd_nb;
162 MemoryRegionIoeventfd *ioeventfds;
163 NotifierList iommu_notify;
167 * MemoryListener: callbacks structure for updates to the physical memory map
169 * Allows a component to adjust to changes in the guest-visible memory map.
170 * Use with memory_listener_register() and memory_listener_unregister().
172 struct MemoryListener {
173 void (*begin)(MemoryListener *listener);
174 void (*commit)(MemoryListener *listener);
175 void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
176 void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
177 void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
178 void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
179 void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
180 void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
181 void (*log_global_start)(MemoryListener *listener);
182 void (*log_global_stop)(MemoryListener *listener);
183 void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
184 bool match_data, uint64_t data, EventNotifier *e);
185 void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
186 bool match_data, uint64_t data, EventNotifier *e);
187 void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
188 hwaddr addr, hwaddr len);
189 void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
190 hwaddr addr, hwaddr len);
191 /* Lower = earlier (during add), later (during del) */
192 unsigned priority;
193 AddressSpace *address_space_filter;
194 QTAILQ_ENTRY(MemoryListener) link;
198 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
200 struct AddressSpace {
201 /* All fields are private. */
202 char *name;
203 MemoryRegion *root;
204 struct FlatView *current_map;
205 int ioeventfd_nb;
206 struct MemoryRegionIoeventfd *ioeventfds;
207 struct AddressSpaceDispatch *dispatch;
208 struct AddressSpaceDispatch *next_dispatch;
209 MemoryListener dispatch_listener;
211 QTAILQ_ENTRY(AddressSpace) address_spaces_link;
215 * MemoryRegionSection: describes a fragment of a #MemoryRegion
217 * @mr: the region, or %NULL if empty
218 * @address_space: the address space the region is mapped in
219 * @offset_within_region: the beginning of the section, relative to @mr's start
220 * @size: the size of the section; will not exceed @mr's boundaries
221 * @offset_within_address_space: the address of the first byte of the section
222 * relative to the region's address space
223 * @readonly: writes to this section are ignored
225 struct MemoryRegionSection {
226 MemoryRegion *mr;
227 AddressSpace *address_space;
228 hwaddr offset_within_region;
229 Int128 size;
230 hwaddr offset_within_address_space;
231 bool readonly;
235 * memory_region_init: Initialize a memory region
237 * The region typically acts as a container for other memory regions. Use
238 * memory_region_add_subregion() to add subregions.
240 * @mr: the #MemoryRegion to be initialized
241 * @owner: the object that tracks the region's reference count
242 * @name: used for debugging; not visible to the user or ABI
243 * @size: size of the region; any subregions beyond this size will be clipped
245 void memory_region_init(MemoryRegion *mr,
246 struct Object *owner,
247 const char *name,
248 uint64_t size);
251 * memory_region_ref: Add 1 to a memory region's reference count
253 * Whenever memory regions are accessed outside the BQL, they need to be
254 * preserved against hot-unplug. MemoryRegions actually do not have their
255 * own reference count; they piggyback on a QOM object, their "owner".
256 * This function adds a reference to the owner.
258 * All MemoryRegions must have an owner if they can disappear, even if the
259 * device they belong to operates exclusively under the BQL. This is because
260 * the region could be returned at any time by memory_region_find, and this
261 * is usually under guest control.
263 * @mr: the #MemoryRegion
265 void memory_region_ref(MemoryRegion *mr);
268 * memory_region_unref: Remove 1 to a memory region's reference count
270 * Whenever memory regions are accessed outside the BQL, they need to be
271 * preserved against hot-unplug. MemoryRegions actually do not have their
272 * own reference count; they piggyback on a QOM object, their "owner".
273 * This function removes a reference to the owner and possibly destroys it.
275 * @mr: the #MemoryRegion
277 void memory_region_unref(MemoryRegion *mr);
280 * memory_region_init_io: Initialize an I/O memory region.
282 * Accesses into the region will cause the callbacks in @ops to be called.
283 * if @size is nonzero, subregions will be clipped to @size.
285 * @mr: the #MemoryRegion to be initialized.
286 * @owner: the object that tracks the region's reference count
287 * @ops: a structure containing read and write callbacks to be used when
288 * I/O is performed on the region.
289 * @opaque: passed to to the read and write callbacks of the @ops structure.
290 * @name: used for debugging; not visible to the user or ABI
291 * @size: size of the region.
293 void memory_region_init_io(MemoryRegion *mr,
294 struct Object *owner,
295 const MemoryRegionOps *ops,
296 void *opaque,
297 const char *name,
298 uint64_t size);
301 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
302 * region will modify memory directly.
304 * @mr: the #MemoryRegion to be initialized.
305 * @owner: the object that tracks the region's reference count
306 * @name: the name of the region.
307 * @size: size of the region.
309 void memory_region_init_ram(MemoryRegion *mr,
310 struct Object *owner,
311 const char *name,
312 uint64_t size);
315 * memory_region_init_ram_ptr: Initialize RAM memory region from a
316 * user-provided pointer. Accesses into the
317 * region will modify memory directly.
319 * @mr: the #MemoryRegion to be initialized.
320 * @owner: the object that tracks the region's reference count
321 * @name: the name of the region.
322 * @size: size of the region.
323 * @ptr: memory to be mapped; must contain at least @size bytes.
325 void memory_region_init_ram_ptr(MemoryRegion *mr,
326 struct Object *owner,
327 const char *name,
328 uint64_t size,
329 void *ptr);
332 * memory_region_init_alias: Initialize a memory region that aliases all or a
333 * part of another memory region.
335 * @mr: the #MemoryRegion to be initialized.
336 * @owner: the object that tracks the region's reference count
337 * @name: used for debugging; not visible to the user or ABI
338 * @orig: the region to be referenced; @mr will be equivalent to
339 * @orig between @offset and @offset + @size - 1.
340 * @offset: start of the section in @orig to be referenced.
341 * @size: size of the region.
343 void memory_region_init_alias(MemoryRegion *mr,
344 struct Object *owner,
345 const char *name,
346 MemoryRegion *orig,
347 hwaddr offset,
348 uint64_t size);
351 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
352 * handled via callbacks.
354 * @mr: the #MemoryRegion to be initialized.
355 * @owner: the object that tracks the region's reference count
356 * @ops: callbacks for write access handling.
357 * @name: the name of the region.
358 * @size: size of the region.
360 void memory_region_init_rom_device(MemoryRegion *mr,
361 struct Object *owner,
362 const MemoryRegionOps *ops,
363 void *opaque,
364 const char *name,
365 uint64_t size);
368 * memory_region_init_reservation: Initialize a memory region that reserves
369 * I/O space.
371 * A reservation region primariy serves debugging purposes. It claims I/O
372 * space that is not supposed to be handled by QEMU itself. Any access via
373 * the memory API will cause an abort().
375 * @mr: the #MemoryRegion to be initialized
376 * @owner: the object that tracks the region's reference count
377 * @name: used for debugging; not visible to the user or ABI
378 * @size: size of the region.
380 void memory_region_init_reservation(MemoryRegion *mr,
381 struct Object *owner,
382 const char *name,
383 uint64_t size);
386 * memory_region_init_iommu: Initialize a memory region that translates
387 * addresses
389 * An IOMMU region translates addresses and forwards accesses to a target
390 * memory region.
392 * @mr: the #MemoryRegion to be initialized
393 * @owner: the object that tracks the region's reference count
394 * @ops: a function that translates addresses into the @target region
395 * @name: used for debugging; not visible to the user or ABI
396 * @size: size of the region.
398 void memory_region_init_iommu(MemoryRegion *mr,
399 struct Object *owner,
400 const MemoryRegionIOMMUOps *ops,
401 const char *name,
402 uint64_t size);
405 * memory_region_destroy: Destroy a memory region and reclaim all resources.
407 * @mr: the region to be destroyed. May not currently be a subregion
408 * (see memory_region_add_subregion()) or referenced in an alias
409 * (see memory_region_init_alias()).
411 void memory_region_destroy(MemoryRegion *mr);
414 * memory_region_owner: get a memory region's owner.
416 * @mr: the memory region being queried.
418 struct Object *memory_region_owner(MemoryRegion *mr);
421 * memory_region_size: get a memory region's size.
423 * @mr: the memory region being queried.
425 uint64_t memory_region_size(MemoryRegion *mr);
428 * memory_region_is_ram: check whether a memory region is random access
430 * Returns %true is a memory region is random access.
432 * @mr: the memory region being queried
434 bool memory_region_is_ram(MemoryRegion *mr);
437 * memory_region_is_romd: check whether a memory region is in ROMD mode
439 * Returns %true if a memory region is a ROM device and currently set to allow
440 * direct reads.
442 * @mr: the memory region being queried
444 static inline bool memory_region_is_romd(MemoryRegion *mr)
446 return mr->rom_device && mr->romd_mode;
450 * memory_region_is_iommu: check whether a memory region is an iommu
452 * Returns %true is a memory region is an iommu.
454 * @mr: the memory region being queried
456 bool memory_region_is_iommu(MemoryRegion *mr);
459 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
461 * @mr: the memory region that was changed
462 * @entry: the new entry in the IOMMU translation table. The entry
463 * replaces all old entries for the same virtual I/O address range.
464 * Deleted entries have .@perm == 0.
466 void memory_region_notify_iommu(MemoryRegion *mr,
467 IOMMUTLBEntry entry);
470 * memory_region_register_iommu_notifier: register a notifier for changes to
471 * IOMMU translation entries.
473 * @mr: the memory region to observe
474 * @n: the notifier to be added; the notifier receives a pointer to an
475 * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
476 * valid on exit from the notifier.
478 void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
481 * memory_region_unregister_iommu_notifier: unregister a notifier for
482 * changes to IOMMU translation entries.
484 * @n: the notifier to be removed.
486 void memory_region_unregister_iommu_notifier(Notifier *n);
489 * memory_region_name: get a memory region's name
491 * Returns the string that was used to initialize the memory region.
493 * @mr: the memory region being queried
495 const char *memory_region_name(MemoryRegion *mr);
498 * memory_region_is_logging: return whether a memory region is logging writes
500 * Returns %true if the memory region is logging writes
502 * @mr: the memory region being queried
504 bool memory_region_is_logging(MemoryRegion *mr);
507 * memory_region_is_rom: check whether a memory region is ROM
509 * Returns %true is a memory region is read-only memory.
511 * @mr: the memory region being queried
513 bool memory_region_is_rom(MemoryRegion *mr);
516 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
518 * Returns a host pointer to a RAM memory region (created with
519 * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
520 * care.
522 * @mr: the memory region being queried.
524 void *memory_region_get_ram_ptr(MemoryRegion *mr);
527 * memory_region_set_log: Turn dirty logging on or off for a region.
529 * Turns dirty logging on or off for a specified client (display, migration).
530 * Only meaningful for RAM regions.
532 * @mr: the memory region being updated.
533 * @log: whether dirty logging is to be enabled or disabled.
534 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
535 * %DIRTY_MEMORY_VGA.
537 void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);
540 * memory_region_get_dirty: Check whether a range of bytes is dirty
541 * for a specified client.
543 * Checks whether a range of bytes has been written to since the last
544 * call to memory_region_reset_dirty() with the same @client. Dirty logging
545 * must be enabled.
547 * @mr: the memory region being queried.
548 * @addr: the address (relative to the start of the region) being queried.
549 * @size: the size of the range being queried.
550 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
551 * %DIRTY_MEMORY_VGA.
553 bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
554 hwaddr size, unsigned client);
557 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
559 * Marks a range of bytes as dirty, after it has been dirtied outside
560 * guest code.
562 * @mr: the memory region being dirtied.
563 * @addr: the address (relative to the start of the region) being dirtied.
564 * @size: size of the range being dirtied.
566 void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
567 hwaddr size);
570 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
571 * for a specified client. It clears them.
573 * Checks whether a range of bytes has been written to since the last
574 * call to memory_region_reset_dirty() with the same @client. Dirty logging
575 * must be enabled.
577 * @mr: the memory region being queried.
578 * @addr: the address (relative to the start of the region) being queried.
579 * @size: the size of the range being queried.
580 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
581 * %DIRTY_MEMORY_VGA.
583 bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
584 hwaddr size, unsigned client);
586 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
587 * any external TLBs (e.g. kvm)
589 * Flushes dirty information from accelerators such as kvm and vhost-net
590 * and makes it available to users of the memory API.
592 * @mr: the region being flushed.
594 void memory_region_sync_dirty_bitmap(MemoryRegion *mr);
597 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
598 * client.
600 * Marks a range of pages as no longer dirty.
602 * @mr: the region being updated.
603 * @addr: the start of the subrange being cleaned.
604 * @size: the size of the subrange being cleaned.
605 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
606 * %DIRTY_MEMORY_VGA.
608 void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
609 hwaddr size, unsigned client);
612 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
614 * Allows a memory region to be marked as read-only (turning it into a ROM).
615 * only useful on RAM regions.
617 * @mr: the region being updated.
618 * @readonly: whether rhe region is to be ROM or RAM.
620 void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
623 * memory_region_rom_device_set_romd: enable/disable ROMD mode
625 * Allows a ROM device (initialized with memory_region_init_rom_device() to
626 * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
627 * device is mapped to guest memory and satisfies read access directly.
628 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
629 * Writes are always handled by the #MemoryRegion.write function.
631 * @mr: the memory region to be updated
632 * @romd_mode: %true to put the region into ROMD mode
634 void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode);
637 * memory_region_set_coalescing: Enable memory coalescing for the region.
639 * Enabled writes to a region to be queued for later processing. MMIO ->write
640 * callbacks may be delayed until a non-coalesced MMIO is issued.
641 * Only useful for IO regions. Roughly similar to write-combining hardware.
643 * @mr: the memory region to be write coalesced
645 void memory_region_set_coalescing(MemoryRegion *mr);
648 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
649 * a region.
651 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
652 * Multiple calls can be issued coalesced disjoint ranges.
654 * @mr: the memory region to be updated.
655 * @offset: the start of the range within the region to be coalesced.
656 * @size: the size of the subrange to be coalesced.
658 void memory_region_add_coalescing(MemoryRegion *mr,
659 hwaddr offset,
660 uint64_t size);
663 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
665 * Disables any coalescing caused by memory_region_set_coalescing() or
666 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
667 * hardware.
669 * @mr: the memory region to be updated.
671 void memory_region_clear_coalescing(MemoryRegion *mr);
674 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
675 * accesses.
677 * Ensure that pending coalesced MMIO request are flushed before the memory
678 * region is accessed. This property is automatically enabled for all regions
679 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
681 * @mr: the memory region to be updated.
683 void memory_region_set_flush_coalesced(MemoryRegion *mr);
686 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
687 * accesses.
689 * Clear the automatic coalesced MMIO flushing enabled via
690 * memory_region_set_flush_coalesced. Note that this service has no effect on
691 * memory regions that have MMIO coalescing enabled for themselves. For them,
692 * automatic flushing will stop once coalescing is disabled.
694 * @mr: the memory region to be updated.
696 void memory_region_clear_flush_coalesced(MemoryRegion *mr);
699 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
700 * is written to a location.
702 * Marks a word in an IO region (initialized with memory_region_init_io())
703 * as a trigger for an eventfd event. The I/O callback will not be called.
704 * The caller must be prepared to handle failure (that is, take the required
705 * action if the callback _is_ called).
707 * @mr: the memory region being updated.
708 * @addr: the address within @mr that is to be monitored
709 * @size: the size of the access to trigger the eventfd
710 * @match_data: whether to match against @data, instead of just @addr
711 * @data: the data to match against the guest write
712 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
714 void memory_region_add_eventfd(MemoryRegion *mr,
715 hwaddr addr,
716 unsigned size,
717 bool match_data,
718 uint64_t data,
719 EventNotifier *e);
722 * memory_region_del_eventfd: Cancel an eventfd.
724 * Cancels an eventfd trigger requested by a previous
725 * memory_region_add_eventfd() call.
727 * @mr: the memory region being updated.
728 * @addr: the address within @mr that is to be monitored
729 * @size: the size of the access to trigger the eventfd
730 * @match_data: whether to match against @data, instead of just @addr
731 * @data: the data to match against the guest write
732 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
734 void memory_region_del_eventfd(MemoryRegion *mr,
735 hwaddr addr,
736 unsigned size,
737 bool match_data,
738 uint64_t data,
739 EventNotifier *e);
742 * memory_region_add_subregion: Add a subregion to a container.
744 * Adds a subregion at @offset. The subregion may not overlap with other
745 * subregions (except for those explicitly marked as overlapping). A region
746 * may only be added once as a subregion (unless removed with
747 * memory_region_del_subregion()); use memory_region_init_alias() if you
748 * want a region to be a subregion in multiple locations.
750 * @mr: the region to contain the new subregion; must be a container
751 * initialized with memory_region_init().
752 * @offset: the offset relative to @mr where @subregion is added.
753 * @subregion: the subregion to be added.
755 void memory_region_add_subregion(MemoryRegion *mr,
756 hwaddr offset,
757 MemoryRegion *subregion);
759 * memory_region_add_subregion_overlap: Add a subregion to a container
760 * with overlap.
762 * Adds a subregion at @offset. The subregion may overlap with other
763 * subregions. Conflicts are resolved by having a higher @priority hide a
764 * lower @priority. Subregions without priority are taken as @priority 0.
765 * A region may only be added once as a subregion (unless removed with
766 * memory_region_del_subregion()); use memory_region_init_alias() if you
767 * want a region to be a subregion in multiple locations.
769 * @mr: the region to contain the new subregion; must be a container
770 * initialized with memory_region_init().
771 * @offset: the offset relative to @mr where @subregion is added.
772 * @subregion: the subregion to be added.
773 * @priority: used for resolving overlaps; highest priority wins.
775 void memory_region_add_subregion_overlap(MemoryRegion *mr,
776 hwaddr offset,
777 MemoryRegion *subregion,
778 int priority);
781 * memory_region_get_ram_addr: Get the ram address associated with a memory
782 * region
784 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
785 * code is being reworked.
787 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr);
790 * memory_region_del_subregion: Remove a subregion.
792 * Removes a subregion from its container.
794 * @mr: the container to be updated.
795 * @subregion: the region being removed; must be a current subregion of @mr.
797 void memory_region_del_subregion(MemoryRegion *mr,
798 MemoryRegion *subregion);
801 * memory_region_set_enabled: dynamically enable or disable a region
803 * Enables or disables a memory region. A disabled memory region
804 * ignores all accesses to itself and its subregions. It does not
805 * obscure sibling subregions with lower priority - it simply behaves as
806 * if it was removed from the hierarchy.
808 * Regions default to being enabled.
810 * @mr: the region to be updated
811 * @enabled: whether to enable or disable the region
813 void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
816 * memory_region_set_address: dynamically update the address of a region
818 * Dynamically updates the address of a region, relative to its container.
819 * May be used on regions are currently part of a memory hierarchy.
821 * @mr: the region to be updated
822 * @addr: new address, relative to container region
824 void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
827 * memory_region_set_alias_offset: dynamically update a memory alias's offset
829 * Dynamically updates the offset into the target region that an alias points
830 * to, as if the fourth argument to memory_region_init_alias() has changed.
832 * @mr: the #MemoryRegion to be updated; should be an alias.
833 * @offset: the new offset into the target memory region
835 void memory_region_set_alias_offset(MemoryRegion *mr,
836 hwaddr offset);
839 * memory_region_present: checks if an address relative to a @container
840 * translates into #MemoryRegion within @container
842 * Answer whether a #MemoryRegion within @container covers the address
843 * @addr.
845 * @container: a #MemoryRegion within which @addr is a relative address
846 * @addr: the area within @container to be searched
848 bool memory_region_present(MemoryRegion *container, hwaddr addr);
851 * memory_region_is_mapped: returns true if #MemoryRegion is mapped
852 * into any address space.
854 * @mr: a #MemoryRegion which should be checked if it's mapped
856 bool memory_region_is_mapped(MemoryRegion *mr);
859 * memory_region_find: translate an address/size relative to a
860 * MemoryRegion into a #MemoryRegionSection.
862 * Locates the first #MemoryRegion within @mr that overlaps the range
863 * given by @addr and @size.
865 * Returns a #MemoryRegionSection that describes a contiguous overlap.
866 * It will have the following characteristics:
867 * .@size = 0 iff no overlap was found
868 * .@mr is non-%NULL iff an overlap was found
870 * Remember that in the return value the @offset_within_region is
871 * relative to the returned region (in the .@mr field), not to the
872 * @mr argument.
874 * Similarly, the .@offset_within_address_space is relative to the
875 * address space that contains both regions, the passed and the
876 * returned one. However, in the special case where the @mr argument
877 * has no container (and thus is the root of the address space), the
878 * following will hold:
879 * .@offset_within_address_space >= @addr
880 * .@offset_within_address_space + .@size <= @addr + @size
882 * @mr: a MemoryRegion within which @addr is a relative address
883 * @addr: start of the area within @as to be searched
884 * @size: size of the area to be searched
886 MemoryRegionSection memory_region_find(MemoryRegion *mr,
887 hwaddr addr, uint64_t size);
890 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
892 * Synchronizes the dirty page log for an entire address space.
893 * @as: the address space that contains the memory being synchronized
895 void address_space_sync_dirty_bitmap(AddressSpace *as);
898 * memory_region_transaction_begin: Start a transaction.
900 * During a transaction, changes will be accumulated and made visible
901 * only when the transaction ends (is committed).
903 void memory_region_transaction_begin(void);
906 * memory_region_transaction_commit: Commit a transaction and make changes
907 * visible to the guest.
909 void memory_region_transaction_commit(void);
912 * memory_listener_register: register callbacks to be called when memory
913 * sections are mapped or unmapped into an address
914 * space
916 * @listener: an object containing the callbacks to be called
917 * @filter: if non-%NULL, only regions in this address space will be observed
919 void memory_listener_register(MemoryListener *listener, AddressSpace *filter);
922 * memory_listener_unregister: undo the effect of memory_listener_register()
924 * @listener: an object containing the callbacks to be removed
926 void memory_listener_unregister(MemoryListener *listener);
929 * memory_global_dirty_log_start: begin dirty logging for all regions
931 void memory_global_dirty_log_start(void);
934 * memory_global_dirty_log_stop: end dirty logging for all regions
936 void memory_global_dirty_log_stop(void);
938 void mtree_info(fprintf_function mon_printf, void *f);
941 * address_space_init: initializes an address space
943 * @as: an uninitialized #AddressSpace
944 * @root: a #MemoryRegion that routes addesses for the address space
945 * @name: an address space name. The name is only used for debugging
946 * output.
948 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
952 * address_space_destroy: destroy an address space
954 * Releases all resources associated with an address space. After an address space
955 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
956 * as well.
958 * @as: address space to be destroyed
960 void address_space_destroy(AddressSpace *as);
963 * address_space_rw: read from or write to an address space.
965 * Return true if the operation hit any unassigned memory or encountered an
966 * IOMMU fault.
968 * @as: #AddressSpace to be accessed
969 * @addr: address within that address space
970 * @buf: buffer with the data transferred
971 * @is_write: indicates the transfer direction
973 bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
974 int len, bool is_write);
977 * address_space_write: write to address space.
979 * Return true if the operation hit any unassigned memory or encountered an
980 * IOMMU fault.
982 * @as: #AddressSpace to be accessed
983 * @addr: address within that address space
984 * @buf: buffer with the data transferred
986 bool address_space_write(AddressSpace *as, hwaddr addr,
987 const uint8_t *buf, int len);
990 * address_space_read: read from an address space.
992 * Return true if the operation hit any unassigned memory or encountered an
993 * IOMMU fault.
995 * @as: #AddressSpace to be accessed
996 * @addr: address within that address space
997 * @buf: buffer with the data transferred
999 bool address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
1001 /* address_space_translate: translate an address range into an address space
1002 * into a MemoryRegion and an address range into that section
1004 * @as: #AddressSpace to be accessed
1005 * @addr: address within that address space
1006 * @xlat: pointer to address within the returned memory region section's
1007 * #MemoryRegion.
1008 * @len: pointer to length
1009 * @is_write: indicates the transfer direction
1011 MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
1012 hwaddr *xlat, hwaddr *len,
1013 bool is_write);
1015 /* address_space_access_valid: check for validity of accessing an address
1016 * space range
1018 * Check whether memory is assigned to the given address space range, and
1019 * access is permitted by any IOMMU regions that are active for the address
1020 * space.
1022 * For now, addr and len should be aligned to a page size. This limitation
1023 * will be lifted in the future.
1025 * @as: #AddressSpace to be accessed
1026 * @addr: address within that address space
1027 * @len: length of the area to be checked
1028 * @is_write: indicates the transfer direction
1030 bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
1032 /* address_space_map: map a physical memory region into a host virtual address
1034 * May map a subset of the requested range, given by and returned in @plen.
1035 * May return %NULL if resources needed to perform the mapping are exhausted.
1036 * Use only for reads OR writes - not for read-modify-write operations.
1037 * Use cpu_register_map_client() to know when retrying the map operation is
1038 * likely to succeed.
1040 * @as: #AddressSpace to be accessed
1041 * @addr: address within that address space
1042 * @plen: pointer to length of buffer; updated on return
1043 * @is_write: indicates the transfer direction
1045 void *address_space_map(AddressSpace *as, hwaddr addr,
1046 hwaddr *plen, bool is_write);
1048 /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
1050 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
1051 * the amount of memory that was actually read or written by the caller.
1053 * @as: #AddressSpace used
1054 * @addr: address within that address space
1055 * @len: buffer length as returned by address_space_map()
1056 * @access_len: amount of data actually transferred
1057 * @is_write: indicates the transfer direction
1059 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
1060 int is_write, hwaddr access_len);
1063 #endif
1065 #endif