2 * Physical memory management
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
7 * Avi Kivity <avi@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
17 #include "exec-memory.h"
23 #define WANT_EXEC_OBSOLETE
24 #include "exec-obsolete.h"
26 unsigned memory_region_transaction_depth
= 0;
27 static bool memory_region_update_pending
= false;
28 static bool global_dirty_log
= false;
30 static QLIST_HEAD(, MemoryListener
) memory_listeners
31 = QLIST_HEAD_INITIALIZER(memory_listeners
);
33 typedef struct AddrRange AddrRange
;
36 * Note using signed integers limits us to physical addresses at most
37 * 63 bits wide. They are needed for negative offsetting in aliases
38 * (large MemoryRegion::alias_offset).
45 static AddrRange
addrrange_make(Int128 start
, Int128 size
)
47 return (AddrRange
) { start
, size
};
50 static bool addrrange_equal(AddrRange r1
, AddrRange r2
)
52 return int128_eq(r1
.start
, r2
.start
) && int128_eq(r1
.size
, r2
.size
);
55 static Int128
addrrange_end(AddrRange r
)
57 return int128_add(r
.start
, r
.size
);
60 static AddrRange
addrrange_shift(AddrRange range
, Int128 delta
)
62 int128_addto(&range
.start
, delta
);
66 static bool addrrange_contains(AddrRange range
, Int128 addr
)
68 return int128_ge(addr
, range
.start
)
69 && int128_lt(addr
, addrrange_end(range
));
72 static bool addrrange_intersects(AddrRange r1
, AddrRange r2
)
74 return addrrange_contains(r1
, r2
.start
)
75 || addrrange_contains(r2
, r1
.start
);
78 static AddrRange
addrrange_intersection(AddrRange r1
, AddrRange r2
)
80 Int128 start
= int128_max(r1
.start
, r2
.start
);
81 Int128 end
= int128_min(addrrange_end(r1
), addrrange_end(r2
));
82 return addrrange_make(start
, int128_sub(end
, start
));
85 struct CoalescedMemoryRange
{
87 QTAILQ_ENTRY(CoalescedMemoryRange
) link
;
90 struct MemoryRegionIoeventfd
{
97 static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd a
,
98 MemoryRegionIoeventfd b
)
100 if (int128_lt(a
.addr
.start
, b
.addr
.start
)) {
102 } else if (int128_gt(a
.addr
.start
, b
.addr
.start
)) {
104 } else if (int128_lt(a
.addr
.size
, b
.addr
.size
)) {
106 } else if (int128_gt(a
.addr
.size
, b
.addr
.size
)) {
108 } else if (a
.match_data
< b
.match_data
) {
110 } else if (a
.match_data
> b
.match_data
) {
112 } else if (a
.match_data
) {
113 if (a
.data
< b
.data
) {
115 } else if (a
.data
> b
.data
) {
121 } else if (a
.fd
> b
.fd
) {
127 static bool memory_region_ioeventfd_equal(MemoryRegionIoeventfd a
,
128 MemoryRegionIoeventfd b
)
130 return !memory_region_ioeventfd_before(a
, b
)
131 && !memory_region_ioeventfd_before(b
, a
);
134 typedef struct FlatRange FlatRange
;
135 typedef struct FlatView FlatView
;
137 /* Range of memory in the global map. Addresses are absolute. */
140 target_phys_addr_t offset_in_region
;
142 uint8_t dirty_log_mask
;
147 /* Flattened global view of current active memory hierarchy. Kept in sorted
153 unsigned nr_allocated
;
156 typedef struct AddressSpace AddressSpace
;
157 typedef struct AddressSpaceOps AddressSpaceOps
;
159 /* A system address space - I/O, memory, etc. */
160 struct AddressSpace
{
161 const AddressSpaceOps
*ops
;
163 FlatView current_map
;
165 MemoryRegionIoeventfd
*ioeventfds
;
168 struct AddressSpaceOps
{
169 void (*range_add
)(AddressSpace
*as
, FlatRange
*fr
);
170 void (*range_del
)(AddressSpace
*as
, FlatRange
*fr
);
171 void (*log_start
)(AddressSpace
*as
, FlatRange
*fr
);
172 void (*log_stop
)(AddressSpace
*as
, FlatRange
*fr
);
173 void (*ioeventfd_add
)(AddressSpace
*as
, MemoryRegionIoeventfd
*fd
);
174 void (*ioeventfd_del
)(AddressSpace
*as
, MemoryRegionIoeventfd
*fd
);
177 #define FOR_EACH_FLAT_RANGE(var, view) \
178 for (var = (view)->ranges; var < (view)->ranges + (view)->nr; ++var)
180 static bool flatrange_equal(FlatRange
*a
, FlatRange
*b
)
182 return a
->mr
== b
->mr
183 && addrrange_equal(a
->addr
, b
->addr
)
184 && a
->offset_in_region
== b
->offset_in_region
185 && a
->readable
== b
->readable
186 && a
->readonly
== b
->readonly
;
189 static void flatview_init(FlatView
*view
)
193 view
->nr_allocated
= 0;
196 /* Insert a range into a given position. Caller is responsible for maintaining
199 static void flatview_insert(FlatView
*view
, unsigned pos
, FlatRange
*range
)
201 if (view
->nr
== view
->nr_allocated
) {
202 view
->nr_allocated
= MAX(2 * view
->nr
, 10);
203 view
->ranges
= g_realloc(view
->ranges
,
204 view
->nr_allocated
* sizeof(*view
->ranges
));
206 memmove(view
->ranges
+ pos
+ 1, view
->ranges
+ pos
,
207 (view
->nr
- pos
) * sizeof(FlatRange
));
208 view
->ranges
[pos
] = *range
;
212 static void flatview_destroy(FlatView
*view
)
214 g_free(view
->ranges
);
217 static bool can_merge(FlatRange
*r1
, FlatRange
*r2
)
219 return int128_eq(addrrange_end(r1
->addr
), r2
->addr
.start
)
221 && int128_eq(int128_add(int128_make64(r1
->offset_in_region
),
223 int128_make64(r2
->offset_in_region
))
224 && r1
->dirty_log_mask
== r2
->dirty_log_mask
225 && r1
->readable
== r2
->readable
226 && r1
->readonly
== r2
->readonly
;
229 /* Attempt to simplify a view by merging ajacent ranges */
230 static void flatview_simplify(FlatView
*view
)
235 while (i
< view
->nr
) {
238 && can_merge(&view
->ranges
[j
-1], &view
->ranges
[j
])) {
239 int128_addto(&view
->ranges
[i
].addr
.size
, view
->ranges
[j
].addr
.size
);
243 memmove(&view
->ranges
[i
], &view
->ranges
[j
],
244 (view
->nr
- j
) * sizeof(view
->ranges
[j
]));
249 static void memory_region_read_accessor(void *opaque
,
250 target_phys_addr_t addr
,
256 MemoryRegion
*mr
= opaque
;
259 tmp
= mr
->ops
->read(mr
->opaque
, addr
, size
);
260 *value
|= (tmp
& mask
) << shift
;
263 static void memory_region_write_accessor(void *opaque
,
264 target_phys_addr_t addr
,
270 MemoryRegion
*mr
= opaque
;
273 tmp
= (*value
>> shift
) & mask
;
274 mr
->ops
->write(mr
->opaque
, addr
, tmp
, size
);
277 static void access_with_adjusted_size(target_phys_addr_t addr
,
280 unsigned access_size_min
,
281 unsigned access_size_max
,
282 void (*access
)(void *opaque
,
283 target_phys_addr_t addr
,
290 uint64_t access_mask
;
291 unsigned access_size
;
294 if (!access_size_min
) {
297 if (!access_size_max
) {
300 access_size
= MAX(MIN(size
, access_size_max
), access_size_min
);
301 access_mask
= -1ULL >> (64 - access_size
* 8);
302 for (i
= 0; i
< size
; i
+= access_size
) {
303 /* FIXME: big-endian support */
304 access(opaque
, addr
+ i
, value
, access_size
, i
* 8, access_mask
);
308 static void as_memory_range_add(AddressSpace
*as
, FlatRange
*fr
)
310 MemoryRegionSection section
= {
312 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
313 .offset_within_region
= fr
->offset_in_region
,
314 .size
= int128_get64(fr
->addr
.size
),
317 cpu_register_physical_memory_log(§ion
, fr
->readable
, fr
->readonly
);
320 static void as_memory_range_del(AddressSpace
*as
, FlatRange
*fr
)
322 MemoryRegionSection section
= {
323 .mr
= &io_mem_unassigned
,
324 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
325 .offset_within_region
= int128_get64(fr
->addr
.start
),
326 .size
= int128_get64(fr
->addr
.size
),
329 cpu_register_physical_memory_log(§ion
, true, false);
332 static void as_memory_log_start(AddressSpace
*as
, FlatRange
*fr
)
336 static void as_memory_log_stop(AddressSpace
*as
, FlatRange
*fr
)
340 static void as_memory_ioeventfd_add(AddressSpace
*as
, MemoryRegionIoeventfd
*fd
)
344 assert(fd
->match_data
&& int128_get64(fd
->addr
.size
) == 4);
346 r
= kvm_set_ioeventfd_mmio_long(fd
->fd
, int128_get64(fd
->addr
.start
),
353 static void as_memory_ioeventfd_del(AddressSpace
*as
, MemoryRegionIoeventfd
*fd
)
357 r
= kvm_set_ioeventfd_mmio_long(fd
->fd
, int128_get64(fd
->addr
.start
),
364 static const AddressSpaceOps address_space_ops_memory
= {
365 .range_add
= as_memory_range_add
,
366 .range_del
= as_memory_range_del
,
367 .log_start
= as_memory_log_start
,
368 .log_stop
= as_memory_log_stop
,
369 .ioeventfd_add
= as_memory_ioeventfd_add
,
370 .ioeventfd_del
= as_memory_ioeventfd_del
,
373 static AddressSpace address_space_memory
= {
374 .ops
= &address_space_ops_memory
,
377 static const MemoryRegionPortio
*find_portio(MemoryRegion
*mr
, uint64_t offset
,
378 unsigned width
, bool write
)
380 const MemoryRegionPortio
*mrp
;
382 for (mrp
= mr
->ops
->old_portio
; mrp
->size
; ++mrp
) {
383 if (offset
>= mrp
->offset
&& offset
< mrp
->offset
+ mrp
->len
384 && width
== mrp
->size
385 && (write
? (bool)mrp
->write
: (bool)mrp
->read
)) {
392 static void memory_region_iorange_read(IORange
*iorange
,
397 MemoryRegion
*mr
= container_of(iorange
, MemoryRegion
, iorange
);
399 if (mr
->ops
->old_portio
) {
400 const MemoryRegionPortio
*mrp
= find_portio(mr
, offset
, width
, false);
402 *data
= ((uint64_t)1 << (width
* 8)) - 1;
404 *data
= mrp
->read(mr
->opaque
, offset
+ mr
->offset
);
405 } else if (width
== 2) {
406 mrp
= find_portio(mr
, offset
, 1, false);
408 *data
= mrp
->read(mr
->opaque
, offset
+ mr
->offset
) |
409 (mrp
->read(mr
->opaque
, offset
+ mr
->offset
+ 1) << 8);
414 access_with_adjusted_size(offset
+ mr
->offset
, data
, width
,
415 mr
->ops
->impl
.min_access_size
,
416 mr
->ops
->impl
.max_access_size
,
417 memory_region_read_accessor
, mr
);
420 static void memory_region_iorange_write(IORange
*iorange
,
425 MemoryRegion
*mr
= container_of(iorange
, MemoryRegion
, iorange
);
427 if (mr
->ops
->old_portio
) {
428 const MemoryRegionPortio
*mrp
= find_portio(mr
, offset
, width
, true);
431 mrp
->write(mr
->opaque
, offset
+ mr
->offset
, data
);
432 } else if (width
== 2) {
433 mrp
= find_portio(mr
, offset
, 1, false);
435 mrp
->write(mr
->opaque
, offset
+ mr
->offset
, data
& 0xff);
436 mrp
->write(mr
->opaque
, offset
+ mr
->offset
+ 1, data
>> 8);
440 access_with_adjusted_size(offset
+ mr
->offset
, &data
, width
,
441 mr
->ops
->impl
.min_access_size
,
442 mr
->ops
->impl
.max_access_size
,
443 memory_region_write_accessor
, mr
);
446 static const IORangeOps memory_region_iorange_ops
= {
447 .read
= memory_region_iorange_read
,
448 .write
= memory_region_iorange_write
,
451 static void as_io_range_add(AddressSpace
*as
, FlatRange
*fr
)
453 iorange_init(&fr
->mr
->iorange
, &memory_region_iorange_ops
,
454 int128_get64(fr
->addr
.start
), int128_get64(fr
->addr
.size
));
455 ioport_register(&fr
->mr
->iorange
);
458 static void as_io_range_del(AddressSpace
*as
, FlatRange
*fr
)
460 isa_unassign_ioport(int128_get64(fr
->addr
.start
),
461 int128_get64(fr
->addr
.size
));
464 static void as_io_ioeventfd_add(AddressSpace
*as
, MemoryRegionIoeventfd
*fd
)
468 assert(fd
->match_data
&& int128_get64(fd
->addr
.size
) == 2);
470 r
= kvm_set_ioeventfd_pio_word(fd
->fd
, int128_get64(fd
->addr
.start
),
477 static void as_io_ioeventfd_del(AddressSpace
*as
, MemoryRegionIoeventfd
*fd
)
481 r
= kvm_set_ioeventfd_pio_word(fd
->fd
, int128_get64(fd
->addr
.start
),
488 static const AddressSpaceOps address_space_ops_io
= {
489 .range_add
= as_io_range_add
,
490 .range_del
= as_io_range_del
,
491 .ioeventfd_add
= as_io_ioeventfd_add
,
492 .ioeventfd_del
= as_io_ioeventfd_del
,
495 static AddressSpace address_space_io
= {
496 .ops
= &address_space_ops_io
,
499 static AddressSpace
*memory_region_to_address_space(MemoryRegion
*mr
)
504 if (mr
== address_space_memory
.root
) {
505 return &address_space_memory
;
507 if (mr
== address_space_io
.root
) {
508 return &address_space_io
;
513 /* Render a memory region into the global view. Ranges in @view obscure
516 static void render_memory_region(FlatView
*view
,
522 MemoryRegion
*subregion
;
524 target_phys_addr_t offset_in_region
;
534 int128_addto(&base
, int128_make64(mr
->addr
));
535 readonly
|= mr
->readonly
;
537 tmp
= addrrange_make(base
, mr
->size
);
539 if (!addrrange_intersects(tmp
, clip
)) {
543 clip
= addrrange_intersection(tmp
, clip
);
546 int128_subfrom(&base
, int128_make64(mr
->alias
->addr
));
547 int128_subfrom(&base
, int128_make64(mr
->alias_offset
));
548 render_memory_region(view
, mr
->alias
, base
, clip
, readonly
);
552 /* Render subregions in priority order. */
553 QTAILQ_FOREACH(subregion
, &mr
->subregions
, subregions_link
) {
554 render_memory_region(view
, subregion
, base
, clip
, readonly
);
557 if (!mr
->terminates
) {
561 offset_in_region
= int128_get64(int128_sub(clip
.start
, base
));
565 /* Render the region itself into any gaps left by the current view. */
566 for (i
= 0; i
< view
->nr
&& int128_nz(remain
); ++i
) {
567 if (int128_ge(base
, addrrange_end(view
->ranges
[i
].addr
))) {
570 if (int128_lt(base
, view
->ranges
[i
].addr
.start
)) {
571 now
= int128_min(remain
,
572 int128_sub(view
->ranges
[i
].addr
.start
, base
));
574 fr
.offset_in_region
= offset_in_region
;
575 fr
.addr
= addrrange_make(base
, now
);
576 fr
.dirty_log_mask
= mr
->dirty_log_mask
;
577 fr
.readable
= mr
->readable
;
578 fr
.readonly
= readonly
;
579 flatview_insert(view
, i
, &fr
);
581 int128_addto(&base
, now
);
582 offset_in_region
+= int128_get64(now
);
583 int128_subfrom(&remain
, now
);
585 if (int128_eq(base
, view
->ranges
[i
].addr
.start
)) {
586 now
= int128_min(remain
, view
->ranges
[i
].addr
.size
);
587 int128_addto(&base
, now
);
588 offset_in_region
+= int128_get64(now
);
589 int128_subfrom(&remain
, now
);
592 if (int128_nz(remain
)) {
594 fr
.offset_in_region
= offset_in_region
;
595 fr
.addr
= addrrange_make(base
, remain
);
596 fr
.dirty_log_mask
= mr
->dirty_log_mask
;
597 fr
.readable
= mr
->readable
;
598 fr
.readonly
= readonly
;
599 flatview_insert(view
, i
, &fr
);
603 /* Render a memory topology into a list of disjoint absolute ranges. */
604 static FlatView
generate_memory_topology(MemoryRegion
*mr
)
608 flatview_init(&view
);
610 render_memory_region(&view
, mr
, int128_zero(),
611 addrrange_make(int128_zero(), int128_2_64()), false);
612 flatview_simplify(&view
);
617 static void address_space_add_del_ioeventfds(AddressSpace
*as
,
618 MemoryRegionIoeventfd
*fds_new
,
620 MemoryRegionIoeventfd
*fds_old
,
625 /* Generate a symmetric difference of the old and new fd sets, adding
626 * and deleting as necessary.
630 while (iold
< fds_old_nb
|| inew
< fds_new_nb
) {
631 if (iold
< fds_old_nb
632 && (inew
== fds_new_nb
633 || memory_region_ioeventfd_before(fds_old
[iold
],
635 as
->ops
->ioeventfd_del(as
, &fds_old
[iold
]);
637 } else if (inew
< fds_new_nb
638 && (iold
== fds_old_nb
639 || memory_region_ioeventfd_before(fds_new
[inew
],
641 as
->ops
->ioeventfd_add(as
, &fds_new
[inew
]);
650 static void address_space_update_ioeventfds(AddressSpace
*as
)
653 unsigned ioeventfd_nb
= 0;
654 MemoryRegionIoeventfd
*ioeventfds
= NULL
;
658 FOR_EACH_FLAT_RANGE(fr
, &as
->current_map
) {
659 for (i
= 0; i
< fr
->mr
->ioeventfd_nb
; ++i
) {
660 tmp
= addrrange_shift(fr
->mr
->ioeventfds
[i
].addr
,
661 int128_sub(fr
->addr
.start
,
662 int128_make64(fr
->offset_in_region
)));
663 if (addrrange_intersects(fr
->addr
, tmp
)) {
665 ioeventfds
= g_realloc(ioeventfds
,
666 ioeventfd_nb
* sizeof(*ioeventfds
));
667 ioeventfds
[ioeventfd_nb
-1] = fr
->mr
->ioeventfds
[i
];
668 ioeventfds
[ioeventfd_nb
-1].addr
= tmp
;
673 address_space_add_del_ioeventfds(as
, ioeventfds
, ioeventfd_nb
,
674 as
->ioeventfds
, as
->ioeventfd_nb
);
676 g_free(as
->ioeventfds
);
677 as
->ioeventfds
= ioeventfds
;
678 as
->ioeventfd_nb
= ioeventfd_nb
;
681 typedef void ListenerCallback(MemoryListener
*listener
,
682 MemoryRegionSection
*mrs
);
684 /* Want "void (&MemoryListener::*callback)(const MemoryRegionSection& s)" */
685 static void memory_listener_update_region(FlatRange
*fr
, AddressSpace
*as
,
686 size_t callback_offset
)
688 MemoryRegionSection section
= {
690 .address_space
= as
->root
,
691 .offset_within_region
= fr
->offset_in_region
,
692 .size
= int128_get64(fr
->addr
.size
),
693 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
695 MemoryListener
*listener
;
697 QLIST_FOREACH(listener
, &memory_listeners
, link
) {
698 ListenerCallback
*callback
699 = *(ListenerCallback
**)((void *)listener
+ callback_offset
);
700 callback(listener
, §ion
);
704 #define MEMORY_LISTENER_UPDATE_REGION(fr, as, callback) \
705 memory_listener_update_region(fr, as, offsetof(MemoryListener, callback))
707 static void address_space_update_topology_pass(AddressSpace
*as
,
713 FlatRange
*frold
, *frnew
;
715 /* Generate a symmetric difference of the old and new memory maps.
716 * Kill ranges in the old map, and instantiate ranges in the new map.
719 while (iold
< old_view
.nr
|| inew
< new_view
.nr
) {
720 if (iold
< old_view
.nr
) {
721 frold
= &old_view
.ranges
[iold
];
725 if (inew
< new_view
.nr
) {
726 frnew
= &new_view
.ranges
[inew
];
733 || int128_lt(frold
->addr
.start
, frnew
->addr
.start
)
734 || (int128_eq(frold
->addr
.start
, frnew
->addr
.start
)
735 && !flatrange_equal(frold
, frnew
)))) {
736 /* In old, but (not in new, or in new but attributes changed). */
739 MEMORY_LISTENER_UPDATE_REGION(frold
, as
, region_del
);
740 as
->ops
->range_del(as
, frold
);
744 } else if (frold
&& frnew
&& flatrange_equal(frold
, frnew
)) {
745 /* In both (logging may have changed) */
748 if (frold
->dirty_log_mask
&& !frnew
->dirty_log_mask
) {
749 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, log_stop
);
750 as
->ops
->log_stop(as
, frnew
);
751 } else if (frnew
->dirty_log_mask
&& !frold
->dirty_log_mask
) {
752 as
->ops
->log_start(as
, frnew
);
753 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, log_start
);
763 as
->ops
->range_add(as
, frnew
);
764 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, region_add
);
773 static void address_space_update_topology(AddressSpace
*as
)
775 FlatView old_view
= as
->current_map
;
776 FlatView new_view
= generate_memory_topology(as
->root
);
778 address_space_update_topology_pass(as
, old_view
, new_view
, false);
779 address_space_update_topology_pass(as
, old_view
, new_view
, true);
781 as
->current_map
= new_view
;
782 flatview_destroy(&old_view
);
783 address_space_update_ioeventfds(as
);
786 static void memory_region_update_topology(MemoryRegion
*mr
)
788 if (memory_region_transaction_depth
) {
789 memory_region_update_pending
|= !mr
|| mr
->enabled
;
793 if (mr
&& !mr
->enabled
) {
797 if (address_space_memory
.root
) {
798 address_space_update_topology(&address_space_memory
);
800 if (address_space_io
.root
) {
801 address_space_update_topology(&address_space_io
);
804 memory_region_update_pending
= false;
807 void memory_region_transaction_begin(void)
809 ++memory_region_transaction_depth
;
812 void memory_region_transaction_commit(void)
814 assert(memory_region_transaction_depth
);
815 --memory_region_transaction_depth
;
816 if (!memory_region_transaction_depth
&& memory_region_update_pending
) {
817 memory_region_update_topology(NULL
);
821 static void memory_region_destructor_none(MemoryRegion
*mr
)
825 static void memory_region_destructor_ram(MemoryRegion
*mr
)
827 qemu_ram_free(mr
->ram_addr
);
830 static void memory_region_destructor_ram_from_ptr(MemoryRegion
*mr
)
832 qemu_ram_free_from_ptr(mr
->ram_addr
);
835 static void memory_region_destructor_iomem(MemoryRegion
*mr
)
837 cpu_unregister_io_memory(mr
->ram_addr
);
840 static void memory_region_destructor_rom_device(MemoryRegion
*mr
)
842 qemu_ram_free(mr
->ram_addr
& TARGET_PAGE_MASK
);
843 cpu_unregister_io_memory(mr
->ram_addr
& ~TARGET_PAGE_MASK
);
846 static bool memory_region_wrong_endianness(MemoryRegion
*mr
)
848 #ifdef TARGET_WORDS_BIGENDIAN
849 return mr
->ops
->endianness
== DEVICE_LITTLE_ENDIAN
;
851 return mr
->ops
->endianness
== DEVICE_BIG_ENDIAN
;
855 void memory_region_init(MemoryRegion
*mr
,
861 mr
->size
= int128_make64(size
);
862 if (size
== UINT64_MAX
) {
863 mr
->size
= int128_2_64();
869 mr
->terminates
= false;
872 mr
->readonly
= false;
873 mr
->rom_device
= false;
874 mr
->destructor
= memory_region_destructor_none
;
876 mr
->may_overlap
= false;
878 QTAILQ_INIT(&mr
->subregions
);
879 memset(&mr
->subregions_link
, 0, sizeof mr
->subregions_link
);
880 QTAILQ_INIT(&mr
->coalesced
);
881 mr
->name
= g_strdup(name
);
882 mr
->dirty_log_mask
= 0;
883 mr
->ioeventfd_nb
= 0;
884 mr
->ioeventfds
= NULL
;
887 static bool memory_region_access_valid(MemoryRegion
*mr
,
888 target_phys_addr_t addr
,
892 if (mr
->ops
->valid
.accepts
893 && !mr
->ops
->valid
.accepts(mr
->opaque
, addr
, size
, is_write
)) {
897 if (!mr
->ops
->valid
.unaligned
&& (addr
& (size
- 1))) {
901 /* Treat zero as compatibility all valid */
902 if (!mr
->ops
->valid
.max_access_size
) {
906 if (size
> mr
->ops
->valid
.max_access_size
907 || size
< mr
->ops
->valid
.min_access_size
) {
913 static uint64_t memory_region_dispatch_read1(MemoryRegion
*mr
,
914 target_phys_addr_t addr
,
919 if (!memory_region_access_valid(mr
, addr
, size
, false)) {
920 return -1U; /* FIXME: better signalling */
923 if (!mr
->ops
->read
) {
924 return mr
->ops
->old_mmio
.read
[bitops_ffsl(size
)](mr
->opaque
, addr
);
927 /* FIXME: support unaligned access */
928 access_with_adjusted_size(addr
+ mr
->offset
, &data
, size
,
929 mr
->ops
->impl
.min_access_size
,
930 mr
->ops
->impl
.max_access_size
,
931 memory_region_read_accessor
, mr
);
936 static void adjust_endianness(MemoryRegion
*mr
, uint64_t *data
, unsigned size
)
938 if (memory_region_wrong_endianness(mr
)) {
943 *data
= bswap16(*data
);
946 *data
= bswap32(*data
);
954 static uint64_t memory_region_dispatch_read(MemoryRegion
*mr
,
955 target_phys_addr_t addr
,
960 ret
= memory_region_dispatch_read1(mr
, addr
, size
);
961 adjust_endianness(mr
, &ret
, size
);
965 static void memory_region_dispatch_write(MemoryRegion
*mr
,
966 target_phys_addr_t addr
,
970 if (!memory_region_access_valid(mr
, addr
, size
, true)) {
971 return; /* FIXME: better signalling */
974 adjust_endianness(mr
, &data
, size
);
976 if (!mr
->ops
->write
) {
977 mr
->ops
->old_mmio
.write
[bitops_ffsl(size
)](mr
->opaque
, addr
, data
);
981 /* FIXME: support unaligned access */
982 access_with_adjusted_size(addr
+ mr
->offset
, &data
, size
,
983 mr
->ops
->impl
.min_access_size
,
984 mr
->ops
->impl
.max_access_size
,
985 memory_region_write_accessor
, mr
);
988 void memory_region_init_io(MemoryRegion
*mr
,
989 const MemoryRegionOps
*ops
,
994 memory_region_init(mr
, name
, size
);
997 mr
->terminates
= true;
998 mr
->destructor
= memory_region_destructor_iomem
;
999 mr
->ram_addr
= cpu_register_io_memory(mr
);
1002 void memory_region_init_ram(MemoryRegion
*mr
,
1006 memory_region_init(mr
, name
, size
);
1008 mr
->terminates
= true;
1009 mr
->destructor
= memory_region_destructor_ram
;
1010 mr
->ram_addr
= qemu_ram_alloc(size
, mr
);
1013 void memory_region_init_ram_ptr(MemoryRegion
*mr
,
1018 memory_region_init(mr
, name
, size
);
1020 mr
->terminates
= true;
1021 mr
->destructor
= memory_region_destructor_ram_from_ptr
;
1022 mr
->ram_addr
= qemu_ram_alloc_from_ptr(size
, ptr
, mr
);
1025 void memory_region_init_alias(MemoryRegion
*mr
,
1028 target_phys_addr_t offset
,
1031 memory_region_init(mr
, name
, size
);
1033 mr
->alias_offset
= offset
;
1036 void memory_region_init_rom_device(MemoryRegion
*mr
,
1037 const MemoryRegionOps
*ops
,
1042 memory_region_init(mr
, name
, size
);
1044 mr
->opaque
= opaque
;
1045 mr
->terminates
= true;
1046 mr
->rom_device
= true;
1047 mr
->destructor
= memory_region_destructor_rom_device
;
1048 mr
->ram_addr
= qemu_ram_alloc(size
, mr
);
1049 mr
->ram_addr
|= cpu_register_io_memory(mr
);
1052 static uint64_t invalid_read(void *opaque
, target_phys_addr_t addr
,
1055 MemoryRegion
*mr
= opaque
;
1057 if (!mr
->warning_printed
) {
1058 fprintf(stderr
, "Invalid read from memory region %s\n", mr
->name
);
1059 mr
->warning_printed
= true;
1064 static void invalid_write(void *opaque
, target_phys_addr_t addr
, uint64_t data
,
1067 MemoryRegion
*mr
= opaque
;
1069 if (!mr
->warning_printed
) {
1070 fprintf(stderr
, "Invalid write to memory region %s\n", mr
->name
);
1071 mr
->warning_printed
= true;
1075 static const MemoryRegionOps reservation_ops
= {
1076 .read
= invalid_read
,
1077 .write
= invalid_write
,
1078 .endianness
= DEVICE_NATIVE_ENDIAN
,
1081 void memory_region_init_reservation(MemoryRegion
*mr
,
1085 memory_region_init_io(mr
, &reservation_ops
, mr
, name
, size
);
1088 void memory_region_destroy(MemoryRegion
*mr
)
1090 assert(QTAILQ_EMPTY(&mr
->subregions
));
1092 memory_region_clear_coalescing(mr
);
1093 g_free((char *)mr
->name
);
1094 g_free(mr
->ioeventfds
);
1097 uint64_t memory_region_size(MemoryRegion
*mr
)
1099 if (int128_eq(mr
->size
, int128_2_64())) {
1102 return int128_get64(mr
->size
);
1105 const char *memory_region_name(MemoryRegion
*mr
)
1110 bool memory_region_is_ram(MemoryRegion
*mr
)
1115 bool memory_region_is_logging(MemoryRegion
*mr
)
1117 return mr
->dirty_log_mask
;
1120 bool memory_region_is_rom(MemoryRegion
*mr
)
1122 return mr
->ram
&& mr
->readonly
;
1125 void memory_region_set_offset(MemoryRegion
*mr
, target_phys_addr_t offset
)
1127 mr
->offset
= offset
;
1130 void memory_region_set_log(MemoryRegion
*mr
, bool log
, unsigned client
)
1132 uint8_t mask
= 1 << client
;
1134 mr
->dirty_log_mask
= (mr
->dirty_log_mask
& ~mask
) | (log
* mask
);
1135 memory_region_update_topology(mr
);
1138 bool memory_region_get_dirty(MemoryRegion
*mr
, target_phys_addr_t addr
,
1141 assert(mr
->terminates
);
1142 return cpu_physical_memory_get_dirty(mr
->ram_addr
+ addr
, 1 << client
);
1145 void memory_region_set_dirty(MemoryRegion
*mr
, target_phys_addr_t addr
,
1146 target_phys_addr_t size
)
1148 assert(mr
->terminates
);
1149 return cpu_physical_memory_set_dirty_range(mr
->ram_addr
+ addr
, size
, -1);
1152 void memory_region_sync_dirty_bitmap(MemoryRegion
*mr
)
1156 FOR_EACH_FLAT_RANGE(fr
, &address_space_memory
.current_map
) {
1158 MEMORY_LISTENER_UPDATE_REGION(fr
, &address_space_memory
, log_sync
);
1163 void memory_region_set_readonly(MemoryRegion
*mr
, bool readonly
)
1165 if (mr
->readonly
!= readonly
) {
1166 mr
->readonly
= readonly
;
1167 memory_region_update_topology(mr
);
1171 void memory_region_rom_device_set_readable(MemoryRegion
*mr
, bool readable
)
1173 if (mr
->readable
!= readable
) {
1174 mr
->readable
= readable
;
1175 memory_region_update_topology(mr
);
1179 void memory_region_reset_dirty(MemoryRegion
*mr
, target_phys_addr_t addr
,
1180 target_phys_addr_t size
, unsigned client
)
1182 assert(mr
->terminates
);
1183 cpu_physical_memory_reset_dirty(mr
->ram_addr
+ addr
,
1184 mr
->ram_addr
+ addr
+ size
,
1188 void *memory_region_get_ram_ptr(MemoryRegion
*mr
)
1191 return memory_region_get_ram_ptr(mr
->alias
) + mr
->alias_offset
;
1194 assert(mr
->terminates
);
1196 return qemu_get_ram_ptr(mr
->ram_addr
& TARGET_PAGE_MASK
);
1199 static void memory_region_update_coalesced_range(MemoryRegion
*mr
)
1202 CoalescedMemoryRange
*cmr
;
1205 FOR_EACH_FLAT_RANGE(fr
, &address_space_memory
.current_map
) {
1207 qemu_unregister_coalesced_mmio(int128_get64(fr
->addr
.start
),
1208 int128_get64(fr
->addr
.size
));
1209 QTAILQ_FOREACH(cmr
, &mr
->coalesced
, link
) {
1210 tmp
= addrrange_shift(cmr
->addr
,
1211 int128_sub(fr
->addr
.start
,
1212 int128_make64(fr
->offset_in_region
)));
1213 if (!addrrange_intersects(tmp
, fr
->addr
)) {
1216 tmp
= addrrange_intersection(tmp
, fr
->addr
);
1217 qemu_register_coalesced_mmio(int128_get64(tmp
.start
),
1218 int128_get64(tmp
.size
));
1224 void memory_region_set_coalescing(MemoryRegion
*mr
)
1226 memory_region_clear_coalescing(mr
);
1227 memory_region_add_coalescing(mr
, 0, int128_get64(mr
->size
));
1230 void memory_region_add_coalescing(MemoryRegion
*mr
,
1231 target_phys_addr_t offset
,
1234 CoalescedMemoryRange
*cmr
= g_malloc(sizeof(*cmr
));
1236 cmr
->addr
= addrrange_make(int128_make64(offset
), int128_make64(size
));
1237 QTAILQ_INSERT_TAIL(&mr
->coalesced
, cmr
, link
);
1238 memory_region_update_coalesced_range(mr
);
1241 void memory_region_clear_coalescing(MemoryRegion
*mr
)
1243 CoalescedMemoryRange
*cmr
;
1245 while (!QTAILQ_EMPTY(&mr
->coalesced
)) {
1246 cmr
= QTAILQ_FIRST(&mr
->coalesced
);
1247 QTAILQ_REMOVE(&mr
->coalesced
, cmr
, link
);
1250 memory_region_update_coalesced_range(mr
);
1253 void memory_region_add_eventfd(MemoryRegion
*mr
,
1254 target_phys_addr_t addr
,
1260 MemoryRegionIoeventfd mrfd
= {
1261 .addr
.start
= int128_make64(addr
),
1262 .addr
.size
= int128_make64(size
),
1263 .match_data
= match_data
,
1269 for (i
= 0; i
< mr
->ioeventfd_nb
; ++i
) {
1270 if (memory_region_ioeventfd_before(mrfd
, mr
->ioeventfds
[i
])) {
1275 mr
->ioeventfds
= g_realloc(mr
->ioeventfds
,
1276 sizeof(*mr
->ioeventfds
) * mr
->ioeventfd_nb
);
1277 memmove(&mr
->ioeventfds
[i
+1], &mr
->ioeventfds
[i
],
1278 sizeof(*mr
->ioeventfds
) * (mr
->ioeventfd_nb
-1 - i
));
1279 mr
->ioeventfds
[i
] = mrfd
;
1280 memory_region_update_topology(mr
);
1283 void memory_region_del_eventfd(MemoryRegion
*mr
,
1284 target_phys_addr_t addr
,
1290 MemoryRegionIoeventfd mrfd
= {
1291 .addr
.start
= int128_make64(addr
),
1292 .addr
.size
= int128_make64(size
),
1293 .match_data
= match_data
,
1299 for (i
= 0; i
< mr
->ioeventfd_nb
; ++i
) {
1300 if (memory_region_ioeventfd_equal(mrfd
, mr
->ioeventfds
[i
])) {
1304 assert(i
!= mr
->ioeventfd_nb
);
1305 memmove(&mr
->ioeventfds
[i
], &mr
->ioeventfds
[i
+1],
1306 sizeof(*mr
->ioeventfds
) * (mr
->ioeventfd_nb
- (i
+1)));
1308 mr
->ioeventfds
= g_realloc(mr
->ioeventfds
,
1309 sizeof(*mr
->ioeventfds
)*mr
->ioeventfd_nb
+ 1);
1310 memory_region_update_topology(mr
);
1313 static void memory_region_add_subregion_common(MemoryRegion
*mr
,
1314 target_phys_addr_t offset
,
1315 MemoryRegion
*subregion
)
1317 MemoryRegion
*other
;
1319 assert(!subregion
->parent
);
1320 subregion
->parent
= mr
;
1321 subregion
->addr
= offset
;
1322 QTAILQ_FOREACH(other
, &mr
->subregions
, subregions_link
) {
1323 if (subregion
->may_overlap
|| other
->may_overlap
) {
1326 if (int128_gt(int128_make64(offset
),
1327 int128_add(int128_make64(other
->addr
), other
->size
))
1328 || int128_le(int128_add(int128_make64(offset
), subregion
->size
),
1329 int128_make64(other
->addr
))) {
1333 printf("warning: subregion collision %llx/%llx (%s) "
1334 "vs %llx/%llx (%s)\n",
1335 (unsigned long long)offset
,
1336 (unsigned long long)int128_get64(subregion
->size
),
1338 (unsigned long long)other
->addr
,
1339 (unsigned long long)int128_get64(other
->size
),
1343 QTAILQ_FOREACH(other
, &mr
->subregions
, subregions_link
) {
1344 if (subregion
->priority
>= other
->priority
) {
1345 QTAILQ_INSERT_BEFORE(other
, subregion
, subregions_link
);
1349 QTAILQ_INSERT_TAIL(&mr
->subregions
, subregion
, subregions_link
);
1351 memory_region_update_topology(mr
);
1355 void memory_region_add_subregion(MemoryRegion
*mr
,
1356 target_phys_addr_t offset
,
1357 MemoryRegion
*subregion
)
1359 subregion
->may_overlap
= false;
1360 subregion
->priority
= 0;
1361 memory_region_add_subregion_common(mr
, offset
, subregion
);
1364 void memory_region_add_subregion_overlap(MemoryRegion
*mr
,
1365 target_phys_addr_t offset
,
1366 MemoryRegion
*subregion
,
1369 subregion
->may_overlap
= true;
1370 subregion
->priority
= priority
;
1371 memory_region_add_subregion_common(mr
, offset
, subregion
);
1374 void memory_region_del_subregion(MemoryRegion
*mr
,
1375 MemoryRegion
*subregion
)
1377 assert(subregion
->parent
== mr
);
1378 subregion
->parent
= NULL
;
1379 QTAILQ_REMOVE(&mr
->subregions
, subregion
, subregions_link
);
1380 memory_region_update_topology(mr
);
1383 void memory_region_set_enabled(MemoryRegion
*mr
, bool enabled
)
1385 if (enabled
== mr
->enabled
) {
1388 mr
->enabled
= enabled
;
1389 memory_region_update_topology(NULL
);
1392 void memory_region_set_address(MemoryRegion
*mr
, target_phys_addr_t addr
)
1394 MemoryRegion
*parent
= mr
->parent
;
1395 unsigned priority
= mr
->priority
;
1396 bool may_overlap
= mr
->may_overlap
;
1398 if (addr
== mr
->addr
|| !parent
) {
1403 memory_region_transaction_begin();
1404 memory_region_del_subregion(parent
, mr
);
1406 memory_region_add_subregion_overlap(parent
, addr
, mr
, priority
);
1408 memory_region_add_subregion(parent
, addr
, mr
);
1410 memory_region_transaction_commit();
1413 void memory_region_set_alias_offset(MemoryRegion
*mr
, target_phys_addr_t offset
)
1415 target_phys_addr_t old_offset
= mr
->alias_offset
;
1418 mr
->alias_offset
= offset
;
1420 if (offset
== old_offset
|| !mr
->parent
) {
1424 memory_region_update_topology(mr
);
1427 ram_addr_t
memory_region_get_ram_addr(MemoryRegion
*mr
)
1429 return mr
->ram_addr
;
1432 static int cmp_flatrange_addr(const void *addr_
, const void *fr_
)
1434 const AddrRange
*addr
= addr_
;
1435 const FlatRange
*fr
= fr_
;
1437 if (int128_le(addrrange_end(*addr
), fr
->addr
.start
)) {
1439 } else if (int128_ge(addr
->start
, addrrange_end(fr
->addr
))) {
1445 static FlatRange
*address_space_lookup(AddressSpace
*as
, AddrRange addr
)
1447 return bsearch(&addr
, as
->current_map
.ranges
, as
->current_map
.nr
,
1448 sizeof(FlatRange
), cmp_flatrange_addr
);
1451 MemoryRegionSection
memory_region_find(MemoryRegion
*address_space
,
1452 target_phys_addr_t addr
, uint64_t size
)
1454 AddressSpace
*as
= memory_region_to_address_space(address_space
);
1455 AddrRange range
= addrrange_make(int128_make64(addr
),
1456 int128_make64(size
));
1457 FlatRange
*fr
= address_space_lookup(as
, range
);
1458 MemoryRegionSection ret
= { .mr
= NULL
, .size
= 0 };
1464 while (fr
> as
->current_map
.ranges
1465 && addrrange_intersects(fr
[-1].addr
, range
)) {
1470 range
= addrrange_intersection(range
, fr
->addr
);
1471 ret
.offset_within_region
= fr
->offset_in_region
;
1472 ret
.offset_within_region
+= int128_get64(int128_sub(range
.start
,
1474 ret
.size
= int128_get64(range
.size
);
1475 ret
.offset_within_address_space
= int128_get64(range
.start
);
1479 void memory_global_sync_dirty_bitmap(MemoryRegion
*address_space
)
1481 AddressSpace
*as
= memory_region_to_address_space(address_space
);
1484 FOR_EACH_FLAT_RANGE(fr
, &as
->current_map
) {
1485 MEMORY_LISTENER_UPDATE_REGION(fr
, as
, log_sync
);
1489 void memory_global_dirty_log_start(void)
1491 MemoryListener
*listener
;
1493 cpu_physical_memory_set_dirty_tracking(1);
1494 global_dirty_log
= true;
1495 QLIST_FOREACH(listener
, &memory_listeners
, link
) {
1496 listener
->log_global_start(listener
);
1500 void memory_global_dirty_log_stop(void)
1502 MemoryListener
*listener
;
1504 global_dirty_log
= false;
1505 QLIST_FOREACH(listener
, &memory_listeners
, link
) {
1506 listener
->log_global_stop(listener
);
1508 cpu_physical_memory_set_dirty_tracking(0);
1511 static void listener_add_address_space(MemoryListener
*listener
,
1516 if (global_dirty_log
) {
1517 listener
->log_global_start(listener
);
1519 FOR_EACH_FLAT_RANGE(fr
, &as
->current_map
) {
1520 MemoryRegionSection section
= {
1522 .address_space
= as
->root
,
1523 .offset_within_region
= fr
->offset_in_region
,
1524 .size
= int128_get64(fr
->addr
.size
),
1525 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
1527 listener
->region_add(listener
, §ion
);
1531 void memory_listener_register(MemoryListener
*listener
)
1533 QLIST_INSERT_HEAD(&memory_listeners
, listener
, link
);
1534 listener_add_address_space(listener
, &address_space_memory
);
1535 listener_add_address_space(listener
, &address_space_io
);
1538 void memory_listener_unregister(MemoryListener
*listener
)
1540 QLIST_REMOVE(listener
, link
);
1543 void set_system_memory_map(MemoryRegion
*mr
)
1545 address_space_memory
.root
= mr
;
1546 memory_region_update_topology(NULL
);
1549 void set_system_io_map(MemoryRegion
*mr
)
1551 address_space_io
.root
= mr
;
1552 memory_region_update_topology(NULL
);
1555 uint64_t io_mem_read(int io_index
, target_phys_addr_t addr
, unsigned size
)
1557 return memory_region_dispatch_read(io_mem_region
[io_index
], addr
, size
);
1560 void io_mem_write(int io_index
, target_phys_addr_t addr
,
1561 uint64_t val
, unsigned size
)
1563 memory_region_dispatch_write(io_mem_region
[io_index
], addr
, val
, size
);
1566 typedef struct MemoryRegionList MemoryRegionList
;
1568 struct MemoryRegionList
{
1569 const MemoryRegion
*mr
;
1571 QTAILQ_ENTRY(MemoryRegionList
) queue
;
1574 typedef QTAILQ_HEAD(queue
, MemoryRegionList
) MemoryRegionListHead
;
1576 static void mtree_print_mr(fprintf_function mon_printf
, void *f
,
1577 const MemoryRegion
*mr
, unsigned int level
,
1578 target_phys_addr_t base
,
1579 MemoryRegionListHead
*alias_print_queue
)
1581 MemoryRegionList
*new_ml
, *ml
, *next_ml
;
1582 MemoryRegionListHead submr_print_queue
;
1583 const MemoryRegion
*submr
;
1590 for (i
= 0; i
< level
; i
++) {
1595 MemoryRegionList
*ml
;
1598 /* check if the alias is already in the queue */
1599 QTAILQ_FOREACH(ml
, alias_print_queue
, queue
) {
1600 if (ml
->mr
== mr
->alias
&& !ml
->printed
) {
1606 ml
= g_new(MemoryRegionList
, 1);
1608 ml
->printed
= false;
1609 QTAILQ_INSERT_TAIL(alias_print_queue
, ml
, queue
);
1611 mon_printf(f
, TARGET_FMT_plx
"-" TARGET_FMT_plx
" (prio %d): alias %s @%s "
1612 TARGET_FMT_plx
"-" TARGET_FMT_plx
"\n",
1615 + (target_phys_addr_t
)int128_get64(mr
->size
) - 1,
1621 + (target_phys_addr_t
)int128_get64(mr
->size
) - 1);
1623 mon_printf(f
, TARGET_FMT_plx
"-" TARGET_FMT_plx
" (prio %d): %s\n",
1626 + (target_phys_addr_t
)int128_get64(mr
->size
) - 1,
1631 QTAILQ_INIT(&submr_print_queue
);
1633 QTAILQ_FOREACH(submr
, &mr
->subregions
, subregions_link
) {
1634 new_ml
= g_new(MemoryRegionList
, 1);
1636 QTAILQ_FOREACH(ml
, &submr_print_queue
, queue
) {
1637 if (new_ml
->mr
->addr
< ml
->mr
->addr
||
1638 (new_ml
->mr
->addr
== ml
->mr
->addr
&&
1639 new_ml
->mr
->priority
> ml
->mr
->priority
)) {
1640 QTAILQ_INSERT_BEFORE(ml
, new_ml
, queue
);
1646 QTAILQ_INSERT_TAIL(&submr_print_queue
, new_ml
, queue
);
1650 QTAILQ_FOREACH(ml
, &submr_print_queue
, queue
) {
1651 mtree_print_mr(mon_printf
, f
, ml
->mr
, level
+ 1, base
+ mr
->addr
,
1655 QTAILQ_FOREACH_SAFE(ml
, &submr_print_queue
, queue
, next_ml
) {
1660 void mtree_info(fprintf_function mon_printf
, void *f
)
1662 MemoryRegionListHead ml_head
;
1663 MemoryRegionList
*ml
, *ml2
;
1665 QTAILQ_INIT(&ml_head
);
1667 mon_printf(f
, "memory\n");
1668 mtree_print_mr(mon_printf
, f
, address_space_memory
.root
, 0, 0, &ml_head
);
1670 /* print aliased regions */
1671 QTAILQ_FOREACH(ml
, &ml_head
, queue
) {
1673 mon_printf(f
, "%s\n", ml
->mr
->name
);
1674 mtree_print_mr(mon_printf
, f
, ml
->mr
, 0, 0, &ml_head
);
1678 QTAILQ_FOREACH_SAFE(ml
, &ml_head
, queue
, ml2
) {
1682 if (address_space_io
.root
&&
1683 !QTAILQ_EMPTY(&address_space_io
.root
->subregions
)) {
1684 QTAILQ_INIT(&ml_head
);
1685 mon_printf(f
, "I/O\n");
1686 mtree_print_mr(mon_printf
, f
, address_space_io
.root
, 0, 0, &ml_head
);