105
/* If .read and .write are not present, old_portio may be used for
106
* backwards compatibility with old portio registration
108
const MemoryRegionPortio *old_portio;
109
118
/* If .read and .write are not present, old_mmio may be used for
110
119
* backwards compatibility with old mmio registration
112
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);
115
131
typedef struct CoalescedMemoryRange CoalescedMemoryRange;
116
132
typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
118
134
struct MemoryRegion {
119
135
/* All fields are private - violators will be prosecuted */
120
136
const MemoryRegionOps *ops;
137
const MemoryRegionIOMMUOps *iommu_ops;
139
struct Object *owner;
122
140
MemoryRegion *parent;
144
162
uint8_t dirty_log_mask;
145
163
unsigned ioeventfd_nb;
146
164
MemoryRegionIoeventfd *ioeventfds;
149
struct MemoryRegionPortio {
153
IOPortReadFunc *read;
154
IOPortWriteFunc *write;
157
#define PORTIO_END_OF_LIST() { }
165
NotifierList iommu_notify;
168
typedef struct MemoryListener MemoryListener;
171
* MemoryListener: callbacks structure for updates to the physical memory map
173
* Allows a component to adjust to changes in the guest-visible memory map.
174
* Use with memory_listener_register() and memory_listener_unregister().
176
struct MemoryListener {
177
void (*begin)(MemoryListener *listener);
178
void (*commit)(MemoryListener *listener);
179
void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
180
void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
181
void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
182
void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
183
void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
184
void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
185
void (*log_global_start)(MemoryListener *listener);
186
void (*log_global_stop)(MemoryListener *listener);
187
void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
188
bool match_data, uint64_t data, EventNotifier *e);
189
void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
190
bool match_data, uint64_t data, EventNotifier *e);
191
void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
192
hwaddr addr, hwaddr len);
193
void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
194
hwaddr addr, hwaddr len);
195
/* Lower = earlier (during add), later (during del) */
197
AddressSpace *address_space_filter;
198
QTAILQ_ENTRY(MemoryListener) link;
160
202
* AddressSpace: describes a mapping of addresses to #MemoryRegion objects
162
204
struct AddressSpace {
163
205
/* All fields are private. */
165
207
MemoryRegion *root;
166
208
struct FlatView *current_map;
167
209
int ioeventfd_nb;
168
210
struct MemoryRegionIoeventfd *ioeventfds;
169
211
struct AddressSpaceDispatch *dispatch;
212
struct AddressSpaceDispatch *next_dispatch;
213
MemoryListener dispatch_listener;
170
215
QTAILQ_ENTRY(AddressSpace) address_spaces_link;
185
230
MemoryRegion *mr;
186
231
AddressSpace *address_space;
187
232
hwaddr offset_within_region;
189
234
hwaddr offset_within_address_space;
193
typedef struct MemoryListener MemoryListener;
196
* MemoryListener: callbacks structure for updates to the physical memory map
198
* Allows a component to adjust to changes in the guest-visible memory map.
199
* Use with memory_listener_register() and memory_listener_unregister().
201
struct MemoryListener {
202
void (*begin)(MemoryListener *listener);
203
void (*commit)(MemoryListener *listener);
204
void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
205
void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
206
void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
207
void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
208
void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
209
void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
210
void (*log_global_start)(MemoryListener *listener);
211
void (*log_global_stop)(MemoryListener *listener);
212
void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
213
bool match_data, uint64_t data, EventNotifier *e);
214
void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
215
bool match_data, uint64_t data, EventNotifier *e);
216
void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
217
hwaddr addr, hwaddr len);
218
void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
219
hwaddr addr, hwaddr len);
220
/* Lower = earlier (during add), later (during del) */
222
AddressSpace *address_space_filter;
223
QTAILQ_ENTRY(MemoryListener) link;
227
239
* memory_region_init: Initialize a memory region
230
242
* memory_region_add_subregion() to add subregions.
232
244
* @mr: the #MemoryRegion to be initialized
245
* @owner: the object that tracks the region's reference count
233
246
* @name: used for debugging; not visible to the user or ABI
234
247
* @size: size of the region; any subregions beyond this size will be clipped
236
249
void memory_region_init(MemoryRegion *mr,
250
struct Object *owner,
237
251
const char *name,
255
* memory_region_ref: Add 1 to a memory region's reference count
257
* Whenever memory regions are accessed outside the BQL, they need to be
258
* preserved against hot-unplug. MemoryRegions actually do not have their
259
* own reference count; they piggyback on a QOM object, their "owner".
260
* This function adds a reference to the owner.
262
* All MemoryRegions must have an owner if they can disappear, even if the
263
* device they belong to operates exclusively under the BQL. This is because
264
* the region could be returned at any time by memory_region_find, and this
265
* is usually under guest control.
267
* @mr: the #MemoryRegion
269
void memory_region_ref(MemoryRegion *mr);
272
* memory_region_unref: Remove 1 to a memory region's reference count
274
* Whenever memory regions are accessed outside the BQL, they need to be
275
* preserved against hot-unplug. MemoryRegions actually do not have their
276
* own reference count; they piggyback on a QOM object, their "owner".
277
* This function removes a reference to the owner and possibly destroys it.
279
* @mr: the #MemoryRegion
281
void memory_region_unref(MemoryRegion *mr);
240
284
* memory_region_init_io: Initialize an I/O memory region.
323
377
* the memory API will cause an abort().
325
379
* @mr: the #MemoryRegion to be initialized
380
* @owner: the object that tracks the region's reference count
326
381
* @name: used for debugging; not visible to the user or ABI
327
382
* @size: size of the region.
329
384
void memory_region_init_reservation(MemoryRegion *mr,
385
struct Object *owner,
330
386
const char *name,
390
* memory_region_init_iommu: Initialize a memory region that translates
393
* An IOMMU region translates addresses and forwards accesses to a target
396
* @mr: the #MemoryRegion to be initialized
397
* @owner: the object that tracks the region's reference count
398
* @ops: a function that translates addresses into the @target region
399
* @name: used for debugging; not visible to the user or ABI
400
* @size: size of the region.
402
void memory_region_init_iommu(MemoryRegion *mr,
403
struct Object *owner,
404
const MemoryRegionIOMMUOps *ops,
333
409
* memory_region_destroy: Destroy a memory region and reclaim all resources.
355
438
bool memory_region_is_ram(MemoryRegion *mr);
358
* memory_region_is_romd: check whether a memory region is ROMD
441
* memory_region_is_romd: check whether a memory region is in ROMD mode
360
* Returns %true is a memory region is ROMD and currently set to allow
443
* Returns %true if a memory region is a ROM device and currently set to allow
363
446
* @mr: the memory region being queried
365
448
static inline bool memory_region_is_romd(MemoryRegion *mr)
367
return mr->rom_device && mr->readable;
450
return mr->rom_device && mr->romd_mode;
454
* memory_region_is_iommu: check whether a memory region is an iommu
456
* Returns %true is a memory region is an iommu.
458
* @mr: the memory region being queried
460
bool memory_region_is_iommu(MemoryRegion *mr);
463
* memory_region_notify_iommu: notify a change in an IOMMU translation entry.
465
* @mr: the memory region that was changed
466
* @entry: the new entry in the IOMMU translation table. The entry
467
* replaces all old entries for the same virtual I/O address range.
468
* Deleted entries have .@perm == 0.
470
void memory_region_notify_iommu(MemoryRegion *mr,
471
IOMMUTLBEntry entry);
474
* memory_region_register_iommu_notifier: register a notifier for changes to
475
* IOMMU translation entries.
477
* @mr: the memory region to observe
478
* @n: the notifier to be added; the notifier receives a pointer to an
479
* #IOMMUTLBEntry as the opaque value; the pointer ceases to be
480
* valid on exit from the notifier.
482
void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
485
* memory_region_unregister_iommu_notifier: unregister a notifier for
486
* changes to IOMMU translation entries.
488
* @n: the notifier to be removed.
490
void memory_region_unregister_iommu_notifier(Notifier *n);
371
493
* memory_region_name: get a memory region's name
373
495
* Returns the string that was used to initialize the memory region.
502
624
void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
505
* memory_region_rom_device_set_readable: enable/disable ROM readability
627
* memory_region_rom_device_set_romd: enable/disable ROMD mode
507
629
* Allows a ROM device (initialized with memory_region_init_rom_device() to
508
* to be marked as readable (default) or not readable. When it is readable,
509
* the device is mapped to guest memory. When not readable, reads are
510
* forwarded to the #MemoryRegion.read function.
630
* set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the
631
* device is mapped to guest memory and satisfies read access directly.
632
* When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
633
* Writes are always handled by the #MemoryRegion.write function.
512
635
* @mr: the memory region to be updated
513
* @readable: whether reads are satisified directly (%true) or via callbacks
636
* @romd_mode: %true to put the region into ROMD mode
516
void memory_region_rom_device_set_readable(MemoryRegion *mr, bool readable);
638
void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode);
519
641
* memory_region_set_coalescing: Enable memory coalescing for the region.
721
* memory_region_find: locate a MemoryRegion in an address space
723
* Locates the first #MemoryRegion within an address space given by
724
* @address_space that overlaps the range given by @addr and @size.
843
* memory_region_present: translate an address/size relative to a
844
* MemoryRegion into a #MemoryRegionSection.
846
* Answer whether a #MemoryRegion within @parent covers the address
849
* @parent: a MemoryRegion within which @addr is a relative address
850
* @addr: the area within @parent to be searched
852
bool memory_region_present(MemoryRegion *parent, hwaddr addr);
855
* memory_region_find: translate an address/size relative to a
856
* MemoryRegion into a #MemoryRegionSection.
858
* Locates the first #MemoryRegion within @mr that overlaps the range
859
* given by @addr and @size.
726
861
* Returns a #MemoryRegionSection that describes a contiguous overlap.
727
862
* It will have the following characteristics:
863
* .@size = 0 iff no overlap was found
864
* .@mr is non-%NULL iff an overlap was found
866
* Remember that in the return value the @offset_within_region is
867
* relative to the returned region (in the .@mr field), not to the
870
* Similarly, the .@offset_within_address_space is relative to the
871
* address space that contains both regions, the passed and the
872
* returned one. However, in the special case where the @mr argument
873
* has no parent (and thus is the root of the address space), the
874
* following will hold:
728
875
* .@offset_within_address_space >= @addr
729
876
* .@offset_within_address_space + .@size <= @addr + @size
730
* .@size = 0 iff no overlap was found
731
* .@mr is non-%NULL iff an overlap was found
733
* @address_space: a top-level (i.e. parentless) region that contains
734
* the region to be found
735
* @addr: start of the area within @address_space to be searched
878
* @mr: a MemoryRegion within which @addr is a relative address
879
* @addr: start of the area within @as to be searched
736
880
* @size: size of the area to be searched
738
MemoryRegionSection memory_region_find(MemoryRegion *address_space,
882
MemoryRegionSection memory_region_find(MemoryRegion *mr,
739
883
hwaddr addr, uint64_t size);
742
* memory_region_section_addr: get offset within MemoryRegionSection
744
* Returns offset within MemoryRegionSection
746
* @section: the memory region section being queried
747
* @addr: address in address space
750
memory_region_section_addr(MemoryRegionSection *section,
753
addr -= section->offset_within_address_space;
754
addr += section->offset_within_region;
759
* memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory
886
* address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
761
888
* Synchronizes the dirty page log for an entire address space.
762
* @address_space: a top-level (i.e. parentless) region that contains the
763
* memory being synchronized
889
* @as: the address space that contains the memory being synchronized
765
void memory_global_sync_dirty_bitmap(MemoryRegion *address_space);
891
void address_space_sync_dirty_bitmap(AddressSpace *as);
768
894
* memory_region_transaction_begin: Start a transaction.
831
959
* address_space_rw: read from or write to an address space.
961
* Return true if the operation hit any unassigned memory or encountered an
833
964
* @as: #AddressSpace to be accessed
834
965
* @addr: address within that address space
835
966
* @buf: buffer with the data transferred
836
967
* @is_write: indicates the transfer direction
838
void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
969
bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
839
970
int len, bool is_write);
842
973
* address_space_write: write to address space.
975
* Return true if the operation hit any unassigned memory or encountered an
844
978
* @as: #AddressSpace to be accessed
845
979
* @addr: address within that address space
846
980
* @buf: buffer with the data transferred
848
void address_space_write(AddressSpace *as, hwaddr addr,
982
bool address_space_write(AddressSpace *as, hwaddr addr,
849
983
const uint8_t *buf, int len);
852
986
* address_space_read: read from an address space.
988
* Return true if the operation hit any unassigned memory or encountered an
854
991
* @as: #AddressSpace to be accessed
855
992
* @addr: address within that address space
856
993
* @buf: buffer with the data transferred
858
void address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
995
bool address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
997
/* address_space_translate: translate an address range into an address space
998
* into a MemoryRegion and an address range into that section
1000
* @as: #AddressSpace to be accessed
1001
* @addr: address within that address space
1002
* @xlat: pointer to address within the returned memory region section's
1004
* @len: pointer to length
1005
* @is_write: indicates the transfer direction
1007
MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
1008
hwaddr *xlat, hwaddr *len,
1011
/* address_space_access_valid: check for validity of accessing an address
1014
* Check whether memory is assigned to the given address space range, and
1015
* access is permitted by any IOMMU regions that are active for the address
1018
* For now, addr and len should be aligned to a page size. This limitation
1019
* will be lifted in the future.
1021
* @as: #AddressSpace to be accessed
1022
* @addr: address within that address space
1023
* @len: length of the area to be checked
1024
* @is_write: indicates the transfer direction
1026
bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
860
1028
/* address_space_map: map a physical memory region into a host virtual address