MAINTAINERS: add section for QEMU Guest Agent
[qemu/ar7.git] / include / exec / memory.h
blob74a58b4883a66a714e5e4a4eb07b806f6b84a93c
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"
34 #include "qapi/error.h"
35 #include "qom/object.h"
37 #define MAX_PHYS_ADDR_SPACE_BITS 62
38 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
40 #define TYPE_MEMORY_REGION "qemu:memory-region"
41 #define MEMORY_REGION(obj) \
42 OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION)
44 typedef struct MemoryRegionOps MemoryRegionOps;
45 typedef struct MemoryRegionMmio MemoryRegionMmio;
47 struct MemoryRegionMmio {
48 CPUReadMemoryFunc *read[3];
49 CPUWriteMemoryFunc *write[3];
52 typedef struct IOMMUTLBEntry IOMMUTLBEntry;
54 /* See address_space_translate: bit 0 is read, bit 1 is write. */
55 typedef enum {
56 IOMMU_NONE = 0,
57 IOMMU_RO = 1,
58 IOMMU_WO = 2,
59 IOMMU_RW = 3,
60 } IOMMUAccessFlags;
62 struct IOMMUTLBEntry {
63 AddressSpace *target_as;
64 hwaddr iova;
65 hwaddr translated_addr;
66 hwaddr addr_mask; /* 0xfff = 4k translation */
67 IOMMUAccessFlags perm;
71 * Memory region callbacks
73 struct MemoryRegionOps {
74 /* Read from the memory region. @addr is relative to @mr; @size is
75 * in bytes. */
76 uint64_t (*read)(void *opaque,
77 hwaddr addr,
78 unsigned size);
79 /* Write to the memory region. @addr is relative to @mr; @size is
80 * in bytes. */
81 void (*write)(void *opaque,
82 hwaddr addr,
83 uint64_t data,
84 unsigned size);
86 enum device_endian endianness;
87 /* Guest-visible constraints: */
88 struct {
89 /* If nonzero, specify bounds on access sizes beyond which a machine
90 * check is thrown.
92 unsigned min_access_size;
93 unsigned max_access_size;
94 /* If true, unaligned accesses are supported. Otherwise unaligned
95 * accesses throw machine checks.
97 bool unaligned;
99 * If present, and returns #false, the transaction is not accepted
100 * by the device (and results in machine dependent behaviour such
101 * as a machine check exception).
103 bool (*accepts)(void *opaque, hwaddr addr,
104 unsigned size, bool is_write);
105 } valid;
106 /* Internal implementation constraints: */
107 struct {
108 /* If nonzero, specifies the minimum size implemented. Smaller sizes
109 * will be rounded upwards and a partial result will be returned.
111 unsigned min_access_size;
112 /* If nonzero, specifies the maximum size implemented. Larger sizes
113 * will be done as a series of accesses with smaller sizes.
115 unsigned max_access_size;
116 /* If true, unaligned accesses are supported. Otherwise all accesses
117 * are converted to (possibly multiple) naturally aligned accesses.
119 bool unaligned;
120 } impl;
122 /* If .read and .write are not present, old_mmio may be used for
123 * backwards compatibility with old mmio registration
125 const MemoryRegionMmio old_mmio;
128 typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps;
130 struct MemoryRegionIOMMUOps {
131 /* Return a TLB entry that contains a given address. */
132 IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write);
135 typedef struct CoalescedMemoryRange CoalescedMemoryRange;
136 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
138 struct MemoryRegion {
139 Object parent_obj;
140 /* All fields are private - violators will be prosecuted */
141 const MemoryRegionOps *ops;
142 const MemoryRegionIOMMUOps *iommu_ops;
143 void *opaque;
144 MemoryRegion *container;
145 Int128 size;
146 hwaddr addr;
147 void (*destructor)(MemoryRegion *mr);
148 ram_addr_t ram_addr;
149 bool subpage;
150 bool terminates;
151 bool romd_mode;
152 bool ram;
153 bool skip_dump;
154 bool readonly; /* For RAM regions */
155 bool enabled;
156 bool rom_device;
157 bool warning_printed; /* For reservations */
158 bool flush_coalesced_mmio;
159 MemoryRegion *alias;
160 hwaddr alias_offset;
161 int32_t priority;
162 bool may_overlap;
163 QTAILQ_HEAD(subregions, MemoryRegion) subregions;
164 QTAILQ_ENTRY(MemoryRegion) subregions_link;
165 QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
166 const char *name;
167 uint8_t dirty_log_mask;
168 unsigned ioeventfd_nb;
169 MemoryRegionIoeventfd *ioeventfds;
170 NotifierList iommu_notify;
174 * MemoryListener: callbacks structure for updates to the physical memory map
176 * Allows a component to adjust to changes in the guest-visible memory map.
177 * Use with memory_listener_register() and memory_listener_unregister().
179 struct MemoryListener {
180 void (*begin)(MemoryListener *listener);
181 void (*commit)(MemoryListener *listener);
182 void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
183 void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
184 void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
185 void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
186 void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
187 void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
188 void (*log_global_start)(MemoryListener *listener);
189 void (*log_global_stop)(MemoryListener *listener);
190 void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
191 bool match_data, uint64_t data, EventNotifier *e);
192 void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
193 bool match_data, uint64_t data, EventNotifier *e);
194 void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
195 hwaddr addr, hwaddr len);
196 void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
197 hwaddr addr, hwaddr len);
198 /* Lower = earlier (during add), later (during del) */
199 unsigned priority;
200 AddressSpace *address_space_filter;
201 QTAILQ_ENTRY(MemoryListener) link;
205 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
207 struct AddressSpace {
208 /* All fields are private. */
209 char *name;
210 MemoryRegion *root;
211 struct FlatView *current_map;
212 int ioeventfd_nb;
213 struct MemoryRegionIoeventfd *ioeventfds;
214 struct AddressSpaceDispatch *dispatch;
215 struct AddressSpaceDispatch *next_dispatch;
216 MemoryListener dispatch_listener;
218 QTAILQ_ENTRY(AddressSpace) address_spaces_link;
222 * MemoryRegionSection: describes a fragment of a #MemoryRegion
224 * @mr: the region, or %NULL if empty
225 * @address_space: the address space the region is mapped in
226 * @offset_within_region: the beginning of the section, relative to @mr's start
227 * @size: the size of the section; will not exceed @mr's boundaries
228 * @offset_within_address_space: the address of the first byte of the section
229 * relative to the region's address space
230 * @readonly: writes to this section are ignored
232 struct MemoryRegionSection {
233 MemoryRegion *mr;
234 AddressSpace *address_space;
235 hwaddr offset_within_region;
236 Int128 size;
237 hwaddr offset_within_address_space;
238 bool readonly;
242 * memory_region_init: Initialize a memory region
244 * The region typically acts as a container for other memory regions. Use
245 * memory_region_add_subregion() to add subregions.
247 * @mr: the #MemoryRegion to be initialized
248 * @owner: the object that tracks the region's reference count
249 * @name: used for debugging; not visible to the user or ABI
250 * @size: size of the region; any subregions beyond this size will be clipped
252 void memory_region_init(MemoryRegion *mr,
253 struct Object *owner,
254 const char *name,
255 uint64_t size);
258 * memory_region_ref: Add 1 to a memory region's reference count
260 * Whenever memory regions are accessed outside the BQL, they need to be
261 * preserved against hot-unplug. MemoryRegions actually do not have their
262 * own reference count; they piggyback on a QOM object, their "owner".
263 * This function adds a reference to the owner.
265 * All MemoryRegions must have an owner if they can disappear, even if the
266 * device they belong to operates exclusively under the BQL. This is because
267 * the region could be returned at any time by memory_region_find, and this
268 * is usually under guest control.
270 * @mr: the #MemoryRegion
272 void memory_region_ref(MemoryRegion *mr);
275 * memory_region_unref: Remove 1 to a memory region's reference count
277 * Whenever memory regions are accessed outside the BQL, they need to be
278 * preserved against hot-unplug. MemoryRegions actually do not have their
279 * own reference count; they piggyback on a QOM object, their "owner".
280 * This function removes a reference to the owner and possibly destroys it.
282 * @mr: the #MemoryRegion
284 void memory_region_unref(MemoryRegion *mr);
287 * memory_region_init_io: Initialize an I/O memory region.
289 * Accesses into the region will cause the callbacks in @ops to be called.
290 * if @size is nonzero, subregions will be clipped to @size.
292 * @mr: the #MemoryRegion to be initialized.
293 * @owner: the object that tracks the region's reference count
294 * @ops: a structure containing read and write callbacks to be used when
295 * I/O is performed on the region.
296 * @opaque: passed to to the read and write callbacks of the @ops structure.
297 * @name: used for debugging; not visible to the user or ABI
298 * @size: size of the region.
300 void memory_region_init_io(MemoryRegion *mr,
301 struct Object *owner,
302 const MemoryRegionOps *ops,
303 void *opaque,
304 const char *name,
305 uint64_t size);
308 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
309 * region will modify memory directly.
311 * @mr: the #MemoryRegion to be initialized.
312 * @owner: the object that tracks the region's reference count
313 * @name: the name of the region.
314 * @size: size of the region.
315 * @errp: pointer to Error*, to store an error if it happens.
317 void memory_region_init_ram(MemoryRegion *mr,
318 struct Object *owner,
319 const char *name,
320 uint64_t size,
321 Error **errp);
323 #ifdef __linux__
325 * memory_region_init_ram_from_file: Initialize RAM memory region with a
326 * mmap-ed backend.
328 * @mr: the #MemoryRegion to be initialized.
329 * @owner: the object that tracks the region's reference count
330 * @name: the name of the region.
331 * @size: size of the region.
332 * @share: %true if memory must be mmaped with the MAP_SHARED flag
333 * @path: the path in which to allocate the RAM.
334 * @errp: pointer to Error*, to store an error if it happens.
336 void memory_region_init_ram_from_file(MemoryRegion *mr,
337 struct Object *owner,
338 const char *name,
339 uint64_t size,
340 bool share,
341 const char *path,
342 Error **errp);
343 #endif
346 * memory_region_init_ram_ptr: Initialize RAM memory region from a
347 * user-provided pointer. Accesses into the
348 * region will modify memory directly.
350 * @mr: the #MemoryRegion to be initialized.
351 * @owner: the object that tracks the region's reference count
352 * @name: the name of the region.
353 * @size: size of the region.
354 * @ptr: memory to be mapped; must contain at least @size bytes.
356 void memory_region_init_ram_ptr(MemoryRegion *mr,
357 struct Object *owner,
358 const char *name,
359 uint64_t size,
360 void *ptr);
363 * memory_region_init_alias: Initialize a memory region that aliases all or a
364 * part of another memory region.
366 * @mr: the #MemoryRegion to be initialized.
367 * @owner: the object that tracks the region's reference count
368 * @name: used for debugging; not visible to the user or ABI
369 * @orig: the region to be referenced; @mr will be equivalent to
370 * @orig between @offset and @offset + @size - 1.
371 * @offset: start of the section in @orig to be referenced.
372 * @size: size of the region.
374 void memory_region_init_alias(MemoryRegion *mr,
375 struct Object *owner,
376 const char *name,
377 MemoryRegion *orig,
378 hwaddr offset,
379 uint64_t size);
382 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
383 * handled via callbacks.
385 * @mr: the #MemoryRegion to be initialized.
386 * @owner: the object that tracks the region's reference count
387 * @ops: callbacks for write access handling.
388 * @name: the name of the region.
389 * @size: size of the region.
390 * @errp: pointer to Error*, to store an error if it happens.
392 void memory_region_init_rom_device(MemoryRegion *mr,
393 struct Object *owner,
394 const MemoryRegionOps *ops,
395 void *opaque,
396 const char *name,
397 uint64_t size,
398 Error **errp);
401 * memory_region_init_reservation: Initialize a memory region that reserves
402 * I/O space.
404 * A reservation region primariy serves debugging purposes. It claims I/O
405 * space that is not supposed to be handled by QEMU itself. Any access via
406 * the memory API will cause an abort().
408 * @mr: the #MemoryRegion to be initialized
409 * @owner: the object that tracks the region's reference count
410 * @name: used for debugging; not visible to the user or ABI
411 * @size: size of the region.
413 void memory_region_init_reservation(MemoryRegion *mr,
414 struct Object *owner,
415 const char *name,
416 uint64_t size);
419 * memory_region_init_iommu: Initialize a memory region that translates
420 * addresses
422 * An IOMMU region translates addresses and forwards accesses to a target
423 * memory region.
425 * @mr: the #MemoryRegion to be initialized
426 * @owner: the object that tracks the region's reference count
427 * @ops: a function that translates addresses into the @target region
428 * @name: used for debugging; not visible to the user or ABI
429 * @size: size of the region.
431 void memory_region_init_iommu(MemoryRegion *mr,
432 struct Object *owner,
433 const MemoryRegionIOMMUOps *ops,
434 const char *name,
435 uint64_t size);
438 * memory_region_owner: get a memory region's owner.
440 * @mr: the memory region being queried.
442 struct Object *memory_region_owner(MemoryRegion *mr);
445 * memory_region_size: get a memory region's size.
447 * @mr: the memory region being queried.
449 uint64_t memory_region_size(MemoryRegion *mr);
452 * memory_region_is_ram: check whether a memory region is random access
454 * Returns %true is a memory region is random access.
456 * @mr: the memory region being queried
458 bool memory_region_is_ram(MemoryRegion *mr);
461 * memory_region_is_skip_dump: check whether a memory region should not be
462 * dumped
464 * Returns %true is a memory region should not be dumped(e.g. VFIO BAR MMAP).
466 * @mr: the memory region being queried
468 bool memory_region_is_skip_dump(MemoryRegion *mr);
471 * memory_region_set_skip_dump: Set skip_dump flag, dump will ignore this memory
472 * region
474 * @mr: the memory region being queried
476 void memory_region_set_skip_dump(MemoryRegion *mr);
479 * memory_region_is_romd: check whether a memory region is in ROMD mode
481 * Returns %true if a memory region is a ROM device and currently set to allow
482 * direct reads.
484 * @mr: the memory region being queried
486 static inline bool memory_region_is_romd(MemoryRegion *mr)
488 return mr->rom_device && mr->romd_mode;
492 * memory_region_is_iommu: check whether a memory region is an iommu
494 * Returns %true is a memory region is an iommu.
496 * @mr: the memory region being queried
498 bool memory_region_is_iommu(MemoryRegion *mr);
501 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
503 * @mr: the memory region that was changed
504 * @entry: the new entry in the IOMMU translation table. The entry
505 * replaces all old entries for the same virtual I/O address range.
506 * Deleted entries have .@perm == 0.
508 void memory_region_notify_iommu(MemoryRegion *mr,
509 IOMMUTLBEntry entry);
512 * memory_region_register_iommu_notifier: register a notifier for changes to
513 * IOMMU translation entries.
515 * @mr: the memory region to observe
516 * @n: the notifier to be added; the notifier receives a pointer to an
517 * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
518 * valid on exit from the notifier.
520 void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
523 * memory_region_unregister_iommu_notifier: unregister a notifier for
524 * changes to IOMMU translation entries.
526 * @n: the notifier to be removed.
528 void memory_region_unregister_iommu_notifier(Notifier *n);
531 * memory_region_name: get a memory region's name
533 * Returns the string that was used to initialize the memory region.
535 * @mr: the memory region being queried
537 const char *memory_region_name(const MemoryRegion *mr);
540 * memory_region_is_logging: return whether a memory region is logging writes
542 * Returns %true if the memory region is logging writes
544 * @mr: the memory region being queried
546 bool memory_region_is_logging(MemoryRegion *mr);
549 * memory_region_is_rom: check whether a memory region is ROM
551 * Returns %true is a memory region is read-only memory.
553 * @mr: the memory region being queried
555 bool memory_region_is_rom(MemoryRegion *mr);
558 * memory_region_get_fd: Get a file descriptor backing a RAM memory region.
560 * Returns a file descriptor backing a file-based RAM memory region,
561 * or -1 if the region is not a file-based RAM memory region.
563 * @mr: the RAM or alias memory region being queried.
565 int memory_region_get_fd(MemoryRegion *mr);
568 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
570 * Returns a host pointer to a RAM memory region (created with
571 * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
572 * care.
574 * @mr: the memory region being queried.
576 void *memory_region_get_ram_ptr(MemoryRegion *mr);
579 * memory_region_set_log: Turn dirty logging on or off for a region.
581 * Turns dirty logging on or off for a specified client (display, migration).
582 * Only meaningful for RAM regions.
584 * @mr: the memory region being updated.
585 * @log: whether dirty logging is to be enabled or disabled.
586 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
587 * %DIRTY_MEMORY_VGA.
589 void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);
592 * memory_region_get_dirty: Check whether a range of bytes is dirty
593 * for a specified client.
595 * Checks whether a range of bytes has been written to since the last
596 * call to memory_region_reset_dirty() with the same @client. Dirty logging
597 * must be enabled.
599 * @mr: the memory region being queried.
600 * @addr: the address (relative to the start of the region) being queried.
601 * @size: the size of the range being queried.
602 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
603 * %DIRTY_MEMORY_VGA.
605 bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
606 hwaddr size, unsigned client);
609 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
611 * Marks a range of bytes as dirty, after it has been dirtied outside
612 * guest code.
614 * @mr: the memory region being dirtied.
615 * @addr: the address (relative to the start of the region) being dirtied.
616 * @size: size of the range being dirtied.
618 void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
619 hwaddr size);
622 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
623 * for a specified client. It clears them.
625 * Checks whether a range of bytes has been written to since the last
626 * call to memory_region_reset_dirty() with the same @client. Dirty logging
627 * must be enabled.
629 * @mr: the memory region being queried.
630 * @addr: the address (relative to the start of the region) being queried.
631 * @size: the size of the range being queried.
632 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
633 * %DIRTY_MEMORY_VGA.
635 bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
636 hwaddr size, unsigned client);
638 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
639 * any external TLBs (e.g. kvm)
641 * Flushes dirty information from accelerators such as kvm and vhost-net
642 * and makes it available to users of the memory API.
644 * @mr: the region being flushed.
646 void memory_region_sync_dirty_bitmap(MemoryRegion *mr);
649 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
650 * client.
652 * Marks a range of pages as no longer dirty.
654 * @mr: the region being updated.
655 * @addr: the start of the subrange being cleaned.
656 * @size: the size of the subrange being cleaned.
657 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
658 * %DIRTY_MEMORY_VGA.
660 void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
661 hwaddr size, unsigned client);
664 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
666 * Allows a memory region to be marked as read-only (turning it into a ROM).
667 * only useful on RAM regions.
669 * @mr: the region being updated.
670 * @readonly: whether rhe region is to be ROM or RAM.
672 void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
675 * memory_region_rom_device_set_romd: enable/disable ROMD mode
677 * Allows a ROM device (initialized with memory_region_init_rom_device() to
678 * set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
679 * device is mapped to guest memory and satisfies read access directly.
680 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
681 * Writes are always handled by the #MemoryRegion.write function.
683 * @mr: the memory region to be updated
684 * @romd_mode: %true to put the region into ROMD mode
686 void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode);
689 * memory_region_set_coalescing: Enable memory coalescing for the region.
691 * Enabled writes to a region to be queued for later processing. MMIO ->write
692 * callbacks may be delayed until a non-coalesced MMIO is issued.
693 * Only useful for IO regions. Roughly similar to write-combining hardware.
695 * @mr: the memory region to be write coalesced
697 void memory_region_set_coalescing(MemoryRegion *mr);
700 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
701 * a region.
703 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
704 * Multiple calls can be issued coalesced disjoint ranges.
706 * @mr: the memory region to be updated.
707 * @offset: the start of the range within the region to be coalesced.
708 * @size: the size of the subrange to be coalesced.
710 void memory_region_add_coalescing(MemoryRegion *mr,
711 hwaddr offset,
712 uint64_t size);
715 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
717 * Disables any coalescing caused by memory_region_set_coalescing() or
718 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
719 * hardware.
721 * @mr: the memory region to be updated.
723 void memory_region_clear_coalescing(MemoryRegion *mr);
726 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
727 * accesses.
729 * Ensure that pending coalesced MMIO request are flushed before the memory
730 * region is accessed. This property is automatically enabled for all regions
731 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
733 * @mr: the memory region to be updated.
735 void memory_region_set_flush_coalesced(MemoryRegion *mr);
738 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
739 * accesses.
741 * Clear the automatic coalesced MMIO flushing enabled via
742 * memory_region_set_flush_coalesced. Note that this service has no effect on
743 * memory regions that have MMIO coalescing enabled for themselves. For them,
744 * automatic flushing will stop once coalescing is disabled.
746 * @mr: the memory region to be updated.
748 void memory_region_clear_flush_coalesced(MemoryRegion *mr);
751 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
752 * is written to a location.
754 * Marks a word in an IO region (initialized with memory_region_init_io())
755 * as a trigger for an eventfd event. The I/O callback will not be called.
756 * The caller must be prepared to handle failure (that is, take the required
757 * action if the callback _is_ called).
759 * @mr: the memory region being updated.
760 * @addr: the address within @mr that is to be monitored
761 * @size: the size of the access to trigger the eventfd
762 * @match_data: whether to match against @data, instead of just @addr
763 * @data: the data to match against the guest write
764 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
766 void memory_region_add_eventfd(MemoryRegion *mr,
767 hwaddr addr,
768 unsigned size,
769 bool match_data,
770 uint64_t data,
771 EventNotifier *e);
774 * memory_region_del_eventfd: Cancel an eventfd.
776 * Cancels an eventfd trigger requested by a previous
777 * memory_region_add_eventfd() call.
779 * @mr: the memory region being updated.
780 * @addr: the address within @mr that is to be monitored
781 * @size: the size of the access to trigger the eventfd
782 * @match_data: whether to match against @data, instead of just @addr
783 * @data: the data to match against the guest write
784 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
786 void memory_region_del_eventfd(MemoryRegion *mr,
787 hwaddr addr,
788 unsigned size,
789 bool match_data,
790 uint64_t data,
791 EventNotifier *e);
794 * memory_region_add_subregion: Add a subregion to a container.
796 * Adds a subregion at @offset. The subregion may not overlap with other
797 * subregions (except for those explicitly marked as overlapping). A region
798 * may only be added once as a subregion (unless removed with
799 * memory_region_del_subregion()); use memory_region_init_alias() if you
800 * want a region to be a subregion in multiple locations.
802 * @mr: the region to contain the new subregion; must be a container
803 * initialized with memory_region_init().
804 * @offset: the offset relative to @mr where @subregion is added.
805 * @subregion: the subregion to be added.
807 void memory_region_add_subregion(MemoryRegion *mr,
808 hwaddr offset,
809 MemoryRegion *subregion);
811 * memory_region_add_subregion_overlap: Add a subregion to a container
812 * with overlap.
814 * Adds a subregion at @offset. The subregion may overlap with other
815 * subregions. Conflicts are resolved by having a higher @priority hide a
816 * lower @priority. Subregions without priority are taken as @priority 0.
817 * A region may only be added once as a subregion (unless removed with
818 * memory_region_del_subregion()); use memory_region_init_alias() if you
819 * want a region to be a subregion in multiple locations.
821 * @mr: the region to contain the new subregion; must be a container
822 * initialized with memory_region_init().
823 * @offset: the offset relative to @mr where @subregion is added.
824 * @subregion: the subregion to be added.
825 * @priority: used for resolving overlaps; highest priority wins.
827 void memory_region_add_subregion_overlap(MemoryRegion *mr,
828 hwaddr offset,
829 MemoryRegion *subregion,
830 int priority);
833 * memory_region_get_ram_addr: Get the ram address associated with a memory
834 * region
836 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
837 * code is being reworked.
839 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr);
842 * memory_region_del_subregion: Remove a subregion.
844 * Removes a subregion from its container.
846 * @mr: the container to be updated.
847 * @subregion: the region being removed; must be a current subregion of @mr.
849 void memory_region_del_subregion(MemoryRegion *mr,
850 MemoryRegion *subregion);
853 * memory_region_set_enabled: dynamically enable or disable a region
855 * Enables or disables a memory region. A disabled memory region
856 * ignores all accesses to itself and its subregions. It does not
857 * obscure sibling subregions with lower priority - it simply behaves as
858 * if it was removed from the hierarchy.
860 * Regions default to being enabled.
862 * @mr: the region to be updated
863 * @enabled: whether to enable or disable the region
865 void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
868 * memory_region_set_address: dynamically update the address of a region
870 * Dynamically updates the address of a region, relative to its container.
871 * May be used on regions are currently part of a memory hierarchy.
873 * @mr: the region to be updated
874 * @addr: new address, relative to container region
876 void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
879 * memory_region_set_alias_offset: dynamically update a memory alias's offset
881 * Dynamically updates the offset into the target region that an alias points
882 * to, as if the fourth argument to memory_region_init_alias() has changed.
884 * @mr: the #MemoryRegion to be updated; should be an alias.
885 * @offset: the new offset into the target memory region
887 void memory_region_set_alias_offset(MemoryRegion *mr,
888 hwaddr offset);
891 * memory_region_present: checks if an address relative to a @container
892 * translates into #MemoryRegion within @container
894 * Answer whether a #MemoryRegion within @container covers the address
895 * @addr.
897 * @container: a #MemoryRegion within which @addr is a relative address
898 * @addr: the area within @container to be searched
900 bool memory_region_present(MemoryRegion *container, hwaddr addr);
903 * memory_region_is_mapped: returns true if #MemoryRegion is mapped
904 * into any address space.
906 * @mr: a #MemoryRegion which should be checked if it's mapped
908 bool memory_region_is_mapped(MemoryRegion *mr);
911 * memory_region_find: translate an address/size relative to a
912 * MemoryRegion into a #MemoryRegionSection.
914 * Locates the first #MemoryRegion within @mr that overlaps the range
915 * given by @addr and @size.
917 * Returns a #MemoryRegionSection that describes a contiguous overlap.
918 * It will have the following characteristics:
919 * .@size = 0 iff no overlap was found
920 * .@mr is non-%NULL iff an overlap was found
922 * Remember that in the return value the @offset_within_region is
923 * relative to the returned region (in the .@mr field), not to the
924 * @mr argument.
926 * Similarly, the .@offset_within_address_space is relative to the
927 * address space that contains both regions, the passed and the
928 * returned one. However, in the special case where the @mr argument
929 * has no container (and thus is the root of the address space), the
930 * following will hold:
931 * .@offset_within_address_space >= @addr
932 * .@offset_within_address_space + .@size <= @addr + @size
934 * @mr: a MemoryRegion within which @addr is a relative address
935 * @addr: start of the area within @as to be searched
936 * @size: size of the area to be searched
938 MemoryRegionSection memory_region_find(MemoryRegion *mr,
939 hwaddr addr, uint64_t size);
942 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
944 * Synchronizes the dirty page log for an entire address space.
945 * @as: the address space that contains the memory being synchronized
947 void address_space_sync_dirty_bitmap(AddressSpace *as);
950 * memory_region_transaction_begin: Start a transaction.
952 * During a transaction, changes will be accumulated and made visible
953 * only when the transaction ends (is committed).
955 void memory_region_transaction_begin(void);
958 * memory_region_transaction_commit: Commit a transaction and make changes
959 * visible to the guest.
961 void memory_region_transaction_commit(void);
964 * memory_listener_register: register callbacks to be called when memory
965 * sections are mapped or unmapped into an address
966 * space
968 * @listener: an object containing the callbacks to be called
969 * @filter: if non-%NULL, only regions in this address space will be observed
971 void memory_listener_register(MemoryListener *listener, AddressSpace *filter);
974 * memory_listener_unregister: undo the effect of memory_listener_register()
976 * @listener: an object containing the callbacks to be removed
978 void memory_listener_unregister(MemoryListener *listener);
981 * memory_global_dirty_log_start: begin dirty logging for all regions
983 void memory_global_dirty_log_start(void);
986 * memory_global_dirty_log_stop: end dirty logging for all regions
988 void memory_global_dirty_log_stop(void);
990 void mtree_info(fprintf_function mon_printf, void *f);
993 * address_space_init: initializes an address space
995 * @as: an uninitialized #AddressSpace
996 * @root: a #MemoryRegion that routes addesses for the address space
997 * @name: an address space name. The name is only used for debugging
998 * output.
1000 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
1004 * address_space_destroy: destroy an address space
1006 * Releases all resources associated with an address space. After an address space
1007 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
1008 * as well.
1010 * @as: address space to be destroyed
1012 void address_space_destroy(AddressSpace *as);
1015 * address_space_rw: read from or write to an address space.
1017 * Return true if the operation hit any unassigned memory or encountered an
1018 * IOMMU fault.
1020 * @as: #AddressSpace to be accessed
1021 * @addr: address within that address space
1022 * @buf: buffer with the data transferred
1023 * @is_write: indicates the transfer direction
1025 bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
1026 int len, bool is_write);
1029 * address_space_write: write to address space.
1031 * Return true if the operation hit any unassigned memory or encountered an
1032 * IOMMU fault.
1034 * @as: #AddressSpace to be accessed
1035 * @addr: address within that address space
1036 * @buf: buffer with the data transferred
1038 bool address_space_write(AddressSpace *as, hwaddr addr,
1039 const uint8_t *buf, int len);
1042 * address_space_read: read from an address space.
1044 * Return true if the operation hit any unassigned memory or encountered an
1045 * IOMMU fault.
1047 * @as: #AddressSpace to be accessed
1048 * @addr: address within that address space
1049 * @buf: buffer with the data transferred
1051 bool address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
1053 /* address_space_translate: translate an address range into an address space
1054 * into a MemoryRegion and an address range into that section
1056 * @as: #AddressSpace to be accessed
1057 * @addr: address within that address space
1058 * @xlat: pointer to address within the returned memory region section's
1059 * #MemoryRegion.
1060 * @len: pointer to length
1061 * @is_write: indicates the transfer direction
1063 MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
1064 hwaddr *xlat, hwaddr *len,
1065 bool is_write);
1067 /* address_space_access_valid: check for validity of accessing an address
1068 * space range
1070 * Check whether memory is assigned to the given address space range, and
1071 * access is permitted by any IOMMU regions that are active for the address
1072 * space.
1074 * For now, addr and len should be aligned to a page size. This limitation
1075 * will be lifted in the future.
1077 * @as: #AddressSpace to be accessed
1078 * @addr: address within that address space
1079 * @len: length of the area to be checked
1080 * @is_write: indicates the transfer direction
1082 bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
1084 /* address_space_map: map a physical memory region into a host virtual address
1086 * May map a subset of the requested range, given by and returned in @plen.
1087 * May return %NULL if resources needed to perform the mapping are exhausted.
1088 * Use only for reads OR writes - not for read-modify-write operations.
1089 * Use cpu_register_map_client() to know when retrying the map operation is
1090 * likely to succeed.
1092 * @as: #AddressSpace to be accessed
1093 * @addr: address within that address space
1094 * @plen: pointer to length of buffer; updated on return
1095 * @is_write: indicates the transfer direction
1097 void *address_space_map(AddressSpace *as, hwaddr addr,
1098 hwaddr *plen, bool is_write);
1100 /* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
1102 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
1103 * the amount of memory that was actually read or written by the caller.
1105 * @as: #AddressSpace used
1106 * @addr: address within that address space
1107 * @len: buffer length as returned by address_space_map()
1108 * @access_len: amount of data actually transferred
1109 * @is_write: indicates the transfer direction
1111 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
1112 int is_write, hwaddr access_len);
1115 #endif
1117 #endif