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.
16 #include "qemu/osdep.h"
17 #include "qapi/error.h"
18 #include "qemu-common.h"
20 #include "exec/exec-all.h" /* qemu_sprint_backtrace */
21 #include "exec/memory.h"
22 #include "exec/address-spaces.h"
23 #include "exec/ioport.h"
24 #include "qapi/visitor.h"
25 #include "qemu/bitops.h"
26 #include "qemu/error-report.h"
27 #include "qom/object.h"
30 #include "exec/memory-internal.h"
31 #include "exec/ram_addr.h"
32 #include "sysemu/kvm.h"
33 #include "sysemu/sysemu.h"
35 //#define DEBUG_UNASSIGNED
37 static unsigned memory_region_transaction_depth
;
38 static bool memory_region_update_pending
;
39 static bool ioeventfd_update_pending
;
40 static bool global_dirty_log
= false;
42 static QTAILQ_HEAD(memory_listeners
, MemoryListener
) memory_listeners
43 = QTAILQ_HEAD_INITIALIZER(memory_listeners
);
45 static QTAILQ_HEAD(, AddressSpace
) address_spaces
46 = QTAILQ_HEAD_INITIALIZER(address_spaces
);
48 typedef struct AddrRange AddrRange
;
51 * Note that signed integers are needed for negative offsetting in aliases
52 * (large MemoryRegion::alias_offset).
59 static AddrRange
addrrange_make(Int128 start
, Int128 size
)
61 return (AddrRange
) { start
, size
};
64 static bool addrrange_equal(AddrRange r1
, AddrRange r2
)
66 return int128_eq(r1
.start
, r2
.start
) && int128_eq(r1
.size
, r2
.size
);
69 static Int128
addrrange_end(AddrRange r
)
71 return int128_add(r
.start
, r
.size
);
74 static AddrRange
addrrange_shift(AddrRange range
, Int128 delta
)
76 int128_addto(&range
.start
, delta
);
80 static bool addrrange_contains(AddrRange range
, Int128 addr
)
82 return int128_ge(addr
, range
.start
)
83 && int128_lt(addr
, addrrange_end(range
));
86 static bool addrrange_intersects(AddrRange r1
, AddrRange r2
)
88 return addrrange_contains(r1
, r2
.start
)
89 || addrrange_contains(r2
, r1
.start
);
92 static AddrRange
addrrange_intersection(AddrRange r1
, AddrRange r2
)
94 Int128 start
= int128_max(r1
.start
, r2
.start
);
95 Int128 end
= int128_min(addrrange_end(r1
), addrrange_end(r2
));
96 return addrrange_make(start
, int128_sub(end
, start
));
99 enum ListenerDirection
{ Forward
, Reverse
};
101 static bool memory_listener_match(MemoryListener
*listener
,
102 MemoryRegionSection
*section
)
104 return !listener
->address_space_filter
105 || listener
->address_space_filter
== section
->address_space
;
108 #define MEMORY_LISTENER_CALL_GLOBAL(_callback, _direction, _args...) \
110 MemoryListener *_listener; \
112 switch (_direction) { \
114 QTAILQ_FOREACH(_listener, &memory_listeners, link) { \
115 if (_listener->_callback) { \
116 _listener->_callback(_listener, ##_args); \
121 QTAILQ_FOREACH_REVERSE(_listener, &memory_listeners, \
122 memory_listeners, link) { \
123 if (_listener->_callback) { \
124 _listener->_callback(_listener, ##_args); \
133 #define MEMORY_LISTENER_CALL(_callback, _direction, _section, _args...) \
135 MemoryListener *_listener; \
137 switch (_direction) { \
139 QTAILQ_FOREACH(_listener, &memory_listeners, link) { \
140 if (_listener->_callback \
141 && memory_listener_match(_listener, _section)) { \
142 _listener->_callback(_listener, _section, ##_args); \
147 QTAILQ_FOREACH_REVERSE(_listener, &memory_listeners, \
148 memory_listeners, link) { \
149 if (_listener->_callback \
150 && memory_listener_match(_listener, _section)) { \
151 _listener->_callback(_listener, _section, ##_args); \
160 /* No need to ref/unref .mr, the FlatRange keeps it alive. */
161 #define MEMORY_LISTENER_UPDATE_REGION(fr, as, dir, callback, _args...) \
163 MemoryRegionSection mrs = section_from_flat_range(fr, as); \
164 MEMORY_LISTENER_CALL(callback, dir, &mrs, ##_args); \
167 struct CoalescedMemoryRange
{
169 QTAILQ_ENTRY(CoalescedMemoryRange
) link
;
172 struct MemoryRegionIoeventfd
{
179 static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd a
,
180 MemoryRegionIoeventfd b
)
182 if (int128_lt(a
.addr
.start
, b
.addr
.start
)) {
184 } else if (int128_gt(a
.addr
.start
, b
.addr
.start
)) {
186 } else if (int128_lt(a
.addr
.size
, b
.addr
.size
)) {
188 } else if (int128_gt(a
.addr
.size
, b
.addr
.size
)) {
190 } else if (a
.match_data
< b
.match_data
) {
192 } else if (a
.match_data
> b
.match_data
) {
194 } else if (a
.match_data
) {
195 if (a
.data
< b
.data
) {
197 } else if (a
.data
> b
.data
) {
203 } else if (a
.e
> b
.e
) {
209 static bool memory_region_ioeventfd_equal(MemoryRegionIoeventfd a
,
210 MemoryRegionIoeventfd b
)
212 return !memory_region_ioeventfd_before(a
, b
)
213 && !memory_region_ioeventfd_before(b
, a
);
216 typedef struct FlatRange FlatRange
;
217 typedef struct FlatView FlatView
;
219 /* Range of memory in the global map. Addresses are absolute. */
222 hwaddr offset_in_region
;
224 uint8_t dirty_log_mask
;
229 /* Flattened global view of current active memory hierarchy. Kept in sorted
237 unsigned nr_allocated
;
240 typedef struct AddressSpaceOps AddressSpaceOps
;
242 #define FOR_EACH_FLAT_RANGE(var, view) \
243 for (var = (view)->ranges; var < (view)->ranges + (view)->nr; ++var)
245 static inline MemoryRegionSection
246 section_from_flat_range(FlatRange
*fr
, AddressSpace
*as
)
248 return (MemoryRegionSection
) {
251 .offset_within_region
= fr
->offset_in_region
,
252 .size
= fr
->addr
.size
,
253 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
254 .readonly
= fr
->readonly
,
258 static bool flatrange_equal(FlatRange
*a
, FlatRange
*b
)
260 return a
->mr
== b
->mr
261 && addrrange_equal(a
->addr
, b
->addr
)
262 && a
->offset_in_region
== b
->offset_in_region
263 && a
->romd_mode
== b
->romd_mode
264 && a
->readonly
== b
->readonly
;
267 static void flatview_init(FlatView
*view
)
272 view
->nr_allocated
= 0;
275 /* Insert a range into a given position. Caller is responsible for maintaining
278 static void flatview_insert(FlatView
*view
, unsigned pos
, FlatRange
*range
)
280 if (view
->nr
== view
->nr_allocated
) {
281 view
->nr_allocated
= MAX(2 * view
->nr
, 10);
282 view
->ranges
= g_realloc(view
->ranges
,
283 view
->nr_allocated
* sizeof(*view
->ranges
));
285 memmove(view
->ranges
+ pos
+ 1, view
->ranges
+ pos
,
286 (view
->nr
- pos
) * sizeof(FlatRange
));
287 view
->ranges
[pos
] = *range
;
288 memory_region_ref(range
->mr
);
292 static void flatview_destroy(FlatView
*view
)
296 for (i
= 0; i
< view
->nr
; i
++) {
297 memory_region_unref(view
->ranges
[i
].mr
);
299 g_free(view
->ranges
);
303 static void flatview_ref(FlatView
*view
)
305 atomic_inc(&view
->ref
);
308 static void flatview_unref(FlatView
*view
)
310 if (atomic_fetch_dec(&view
->ref
) == 1) {
311 flatview_destroy(view
);
315 static bool can_merge(FlatRange
*r1
, FlatRange
*r2
)
317 return int128_eq(addrrange_end(r1
->addr
), r2
->addr
.start
)
319 && int128_eq(int128_add(int128_make64(r1
->offset_in_region
),
321 int128_make64(r2
->offset_in_region
))
322 && r1
->dirty_log_mask
== r2
->dirty_log_mask
323 && r1
->romd_mode
== r2
->romd_mode
324 && r1
->readonly
== r2
->readonly
;
327 /* Attempt to simplify a view by merging adjacent ranges */
328 static void flatview_simplify(FlatView
*view
)
333 while (i
< view
->nr
) {
336 && can_merge(&view
->ranges
[j
-1], &view
->ranges
[j
])) {
337 int128_addto(&view
->ranges
[i
].addr
.size
, view
->ranges
[j
].addr
.size
);
341 memmove(&view
->ranges
[i
], &view
->ranges
[j
],
342 (view
->nr
- j
) * sizeof(view
->ranges
[j
]));
347 static bool memory_region_big_endian(MemoryRegion
*mr
)
349 #ifdef TARGET_WORDS_BIGENDIAN
350 return mr
->ops
->endianness
!= DEVICE_LITTLE_ENDIAN
;
352 return mr
->ops
->endianness
== DEVICE_BIG_ENDIAN
;
356 static bool memory_region_wrong_endianness(MemoryRegion
*mr
)
358 #ifdef TARGET_WORDS_BIGENDIAN
359 return mr
->ops
->endianness
== DEVICE_LITTLE_ENDIAN
;
361 return mr
->ops
->endianness
== DEVICE_BIG_ENDIAN
;
365 static void adjust_endianness(MemoryRegion
*mr
, uint64_t *data
, unsigned size
)
367 if (memory_region_wrong_endianness(mr
)) {
372 *data
= bswap16(*data
);
375 *data
= bswap32(*data
);
378 *data
= bswap64(*data
);
386 static hwaddr
memory_region_to_absolute_addr(MemoryRegion
*mr
, hwaddr offset
)
389 hwaddr abs_addr
= offset
;
391 abs_addr
+= mr
->addr
;
392 for (root
= mr
; root
->container
; ) {
393 root
= root
->container
;
394 abs_addr
+= root
->addr
;
400 static int get_cpu_index(void)
403 return current_cpu
->cpu_index
;
408 static MemTxResult
memory_region_oldmmio_read_accessor(MemoryRegion
*mr
,
418 tmp
= mr
->ops
->old_mmio
.read
[ctz32(size
)](mr
->opaque
, addr
);
420 trace_memory_region_subpage_read(get_cpu_index(), mr
, addr
, tmp
, size
);
421 } else if (mr
== &io_mem_notdirty
) {
422 /* Accesses to code which has previously been translated into a TB show
423 * up in the MMIO path, as accesses to the io_mem_notdirty
425 trace_memory_region_tb_read(get_cpu_index(), addr
, tmp
, size
);
426 } else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED
) {
427 hwaddr abs_addr
= memory_region_to_absolute_addr(mr
, addr
);
428 trace_memory_region_ops_read(get_cpu_index(), mr
, abs_addr
, tmp
, size
);
430 *value
|= (tmp
& mask
) << shift
;
434 static MemTxResult
memory_region_read_accessor(MemoryRegion
*mr
,
444 tmp
= mr
->ops
->read(mr
->opaque
, addr
, size
);
446 trace_memory_region_subpage_read(get_cpu_index(), mr
, addr
, tmp
, size
);
447 } else if (mr
== &io_mem_notdirty
) {
448 /* Accesses to code which has previously been translated into a TB show
449 * up in the MMIO path, as accesses to the io_mem_notdirty
451 trace_memory_region_tb_read(get_cpu_index(), addr
, tmp
, size
);
452 } else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED
) {
453 hwaddr abs_addr
= memory_region_to_absolute_addr(mr
, addr
);
454 trace_memory_region_ops_read(get_cpu_index(), mr
, abs_addr
, tmp
, size
);
456 *value
|= (tmp
& mask
) << shift
;
460 static MemTxResult
memory_region_read_with_attrs_accessor(MemoryRegion
*mr
,
471 r
= mr
->ops
->read_with_attrs(mr
->opaque
, addr
, &tmp
, size
, attrs
);
473 trace_memory_region_subpage_read(get_cpu_index(), mr
, addr
, tmp
, size
);
474 } else if (mr
== &io_mem_notdirty
) {
475 /* Accesses to code which has previously been translated into a TB show
476 * up in the MMIO path, as accesses to the io_mem_notdirty
478 trace_memory_region_tb_read(get_cpu_index(), addr
, tmp
, size
);
479 } else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED
) {
480 hwaddr abs_addr
= memory_region_to_absolute_addr(mr
, addr
);
481 trace_memory_region_ops_read(get_cpu_index(), mr
, abs_addr
, tmp
, size
);
483 *value
|= (tmp
& mask
) << shift
;
487 static MemTxResult
memory_region_oldmmio_write_accessor(MemoryRegion
*mr
,
497 tmp
= (*value
>> shift
) & mask
;
499 trace_memory_region_subpage_write(get_cpu_index(), mr
, addr
, tmp
, size
);
500 } else if (mr
== &io_mem_notdirty
) {
501 /* Accesses to code which has previously been translated into a TB show
502 * up in the MMIO path, as accesses to the io_mem_notdirty
504 trace_memory_region_tb_write(get_cpu_index(), addr
, tmp
, size
);
505 } else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED
) {
506 hwaddr abs_addr
= memory_region_to_absolute_addr(mr
, addr
);
507 trace_memory_region_ops_write(get_cpu_index(), mr
, abs_addr
, tmp
, size
);
509 mr
->ops
->old_mmio
.write
[ctz32(size
)](mr
->opaque
, addr
, tmp
);
513 static MemTxResult
memory_region_write_accessor(MemoryRegion
*mr
,
523 tmp
= (*value
>> shift
) & mask
;
525 trace_memory_region_subpage_write(get_cpu_index(), mr
, addr
, tmp
, size
);
526 } else if (mr
== &io_mem_notdirty
) {
527 /* Accesses to code which has previously been translated into a TB show
528 * up in the MMIO path, as accesses to the io_mem_notdirty
530 trace_memory_region_tb_write(get_cpu_index(), addr
, tmp
, size
);
531 } else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED
) {
532 hwaddr abs_addr
= memory_region_to_absolute_addr(mr
, addr
);
533 trace_memory_region_ops_write(get_cpu_index(), mr
, abs_addr
, tmp
, size
);
535 mr
->ops
->write(mr
->opaque
, addr
, tmp
, size
);
539 static MemTxResult
memory_region_write_with_attrs_accessor(MemoryRegion
*mr
,
549 tmp
= (*value
>> shift
) & mask
;
551 trace_memory_region_subpage_write(get_cpu_index(), mr
, addr
, tmp
, size
);
552 } else if (mr
== &io_mem_notdirty
) {
553 /* Accesses to code which has previously been translated into a TB show
554 * up in the MMIO path, as accesses to the io_mem_notdirty
556 trace_memory_region_tb_write(get_cpu_index(), addr
, tmp
, size
);
557 } else if (TRACE_MEMORY_REGION_OPS_WRITE_ENABLED
) {
558 hwaddr abs_addr
= memory_region_to_absolute_addr(mr
, addr
);
559 trace_memory_region_ops_write(get_cpu_index(), mr
, abs_addr
, tmp
, size
);
561 return mr
->ops
->write_with_attrs(mr
->opaque
, addr
, tmp
, size
, attrs
);
564 static MemTxResult
access_with_adjusted_size(hwaddr addr
,
567 unsigned access_size_min
,
568 unsigned access_size_max
,
569 MemTxResult (*access
)(MemoryRegion
*mr
,
579 uint64_t access_mask
;
580 unsigned access_size
;
582 MemTxResult r
= MEMTX_OK
;
584 if (!access_size_min
) {
587 if (!access_size_max
) {
591 /* FIXME: support unaligned access? */
592 access_size
= MAX(MIN(size
, access_size_max
), access_size_min
);
593 access_mask
= -1ULL >> (64 - access_size
* 8);
594 if (memory_region_big_endian(mr
)) {
595 for (i
= 0; i
< size
; i
+= access_size
) {
596 r
|= access(mr
, addr
+ i
, value
, access_size
,
597 (size
- access_size
- i
) * 8, access_mask
, attrs
);
600 for (i
= 0; i
< size
; i
+= access_size
) {
601 r
|= access(mr
, addr
+ i
, value
, access_size
, i
* 8,
608 static AddressSpace
*memory_region_to_address_space(MemoryRegion
*mr
)
612 while (mr
->container
) {
615 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
616 if (mr
== as
->root
) {
623 /* Render a memory region into the global view. Ranges in @view obscure
626 static void render_memory_region(FlatView
*view
,
632 MemoryRegion
*subregion
;
634 hwaddr offset_in_region
;
644 int128_addto(&base
, int128_make64(mr
->addr
));
645 readonly
|= mr
->readonly
;
647 tmp
= addrrange_make(base
, mr
->size
);
649 if (!addrrange_intersects(tmp
, clip
)) {
653 clip
= addrrange_intersection(tmp
, clip
);
656 int128_subfrom(&base
, int128_make64(mr
->alias
->addr
));
657 int128_subfrom(&base
, int128_make64(mr
->alias_offset
));
658 render_memory_region(view
, mr
->alias
, base
, clip
, readonly
);
662 /* Render subregions in priority order. */
663 QTAILQ_FOREACH(subregion
, &mr
->subregions
, subregions_link
) {
664 render_memory_region(view
, subregion
, base
, clip
, readonly
);
667 if (!mr
->terminates
) {
671 offset_in_region
= int128_get64(int128_sub(clip
.start
, base
));
676 fr
.dirty_log_mask
= memory_region_get_dirty_log_mask(mr
);
677 fr
.romd_mode
= mr
->romd_mode
;
678 fr
.readonly
= readonly
;
680 /* Render the region itself into any gaps left by the current view. */
681 for (i
= 0; i
< view
->nr
&& int128_nz(remain
); ++i
) {
682 if (int128_ge(base
, addrrange_end(view
->ranges
[i
].addr
))) {
685 if (int128_lt(base
, view
->ranges
[i
].addr
.start
)) {
686 now
= int128_min(remain
,
687 int128_sub(view
->ranges
[i
].addr
.start
, base
));
688 fr
.offset_in_region
= offset_in_region
;
689 fr
.addr
= addrrange_make(base
, now
);
690 flatview_insert(view
, i
, &fr
);
692 int128_addto(&base
, now
);
693 offset_in_region
+= int128_get64(now
);
694 int128_subfrom(&remain
, now
);
696 now
= int128_sub(int128_min(int128_add(base
, remain
),
697 addrrange_end(view
->ranges
[i
].addr
)),
699 int128_addto(&base
, now
);
700 offset_in_region
+= int128_get64(now
);
701 int128_subfrom(&remain
, now
);
703 if (int128_nz(remain
)) {
704 fr
.offset_in_region
= offset_in_region
;
705 fr
.addr
= addrrange_make(base
, remain
);
706 flatview_insert(view
, i
, &fr
);
710 /* Render a memory topology into a list of disjoint absolute ranges. */
711 static FlatView
*generate_memory_topology(MemoryRegion
*mr
)
715 view
= g_new(FlatView
, 1);
719 render_memory_region(view
, mr
, int128_zero(),
720 addrrange_make(int128_zero(), int128_2_64()), false);
722 flatview_simplify(view
);
727 static void address_space_add_del_ioeventfds(AddressSpace
*as
,
728 MemoryRegionIoeventfd
*fds_new
,
730 MemoryRegionIoeventfd
*fds_old
,
734 MemoryRegionIoeventfd
*fd
;
735 MemoryRegionSection section
;
737 /* Generate a symmetric difference of the old and new fd sets, adding
738 * and deleting as necessary.
742 while (iold
< fds_old_nb
|| inew
< fds_new_nb
) {
743 if (iold
< fds_old_nb
744 && (inew
== fds_new_nb
745 || memory_region_ioeventfd_before(fds_old
[iold
],
748 section
= (MemoryRegionSection
) {
750 .offset_within_address_space
= int128_get64(fd
->addr
.start
),
751 .size
= fd
->addr
.size
,
753 MEMORY_LISTENER_CALL(eventfd_del
, Forward
, §ion
,
754 fd
->match_data
, fd
->data
, fd
->e
);
756 } else if (inew
< fds_new_nb
757 && (iold
== fds_old_nb
758 || memory_region_ioeventfd_before(fds_new
[inew
],
761 section
= (MemoryRegionSection
) {
763 .offset_within_address_space
= int128_get64(fd
->addr
.start
),
764 .size
= fd
->addr
.size
,
766 MEMORY_LISTENER_CALL(eventfd_add
, Reverse
, §ion
,
767 fd
->match_data
, fd
->data
, fd
->e
);
776 static FlatView
*address_space_get_flatview(AddressSpace
*as
)
781 view
= atomic_rcu_read(&as
->current_map
);
787 static void address_space_update_ioeventfds(AddressSpace
*as
)
791 unsigned ioeventfd_nb
= 0;
792 MemoryRegionIoeventfd
*ioeventfds
= NULL
;
796 view
= address_space_get_flatview(as
);
797 FOR_EACH_FLAT_RANGE(fr
, view
) {
798 for (i
= 0; i
< fr
->mr
->ioeventfd_nb
; ++i
) {
799 tmp
= addrrange_shift(fr
->mr
->ioeventfds
[i
].addr
,
800 int128_sub(fr
->addr
.start
,
801 int128_make64(fr
->offset_in_region
)));
802 if (addrrange_intersects(fr
->addr
, tmp
)) {
804 ioeventfds
= g_realloc(ioeventfds
,
805 ioeventfd_nb
* sizeof(*ioeventfds
));
806 ioeventfds
[ioeventfd_nb
-1] = fr
->mr
->ioeventfds
[i
];
807 ioeventfds
[ioeventfd_nb
-1].addr
= tmp
;
812 address_space_add_del_ioeventfds(as
, ioeventfds
, ioeventfd_nb
,
813 as
->ioeventfds
, as
->ioeventfd_nb
);
815 g_free(as
->ioeventfds
);
816 as
->ioeventfds
= ioeventfds
;
817 as
->ioeventfd_nb
= ioeventfd_nb
;
818 flatview_unref(view
);
821 static void address_space_update_topology_pass(AddressSpace
*as
,
822 const FlatView
*old_view
,
823 const FlatView
*new_view
,
827 FlatRange
*frold
, *frnew
;
829 /* Generate a symmetric difference of the old and new memory maps.
830 * Kill ranges in the old map, and instantiate ranges in the new map.
833 while (iold
< old_view
->nr
|| inew
< new_view
->nr
) {
834 if (iold
< old_view
->nr
) {
835 frold
= &old_view
->ranges
[iold
];
839 if (inew
< new_view
->nr
) {
840 frnew
= &new_view
->ranges
[inew
];
847 || int128_lt(frold
->addr
.start
, frnew
->addr
.start
)
848 || (int128_eq(frold
->addr
.start
, frnew
->addr
.start
)
849 && !flatrange_equal(frold
, frnew
)))) {
850 /* In old but not in new, or in both but attributes changed. */
853 MEMORY_LISTENER_UPDATE_REGION(frold
, as
, Reverse
, region_del
);
857 } else if (frold
&& frnew
&& flatrange_equal(frold
, frnew
)) {
858 /* In both and unchanged (except logging may have changed) */
861 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, Forward
, region_nop
);
862 if (frnew
->dirty_log_mask
& ~frold
->dirty_log_mask
) {
863 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, Forward
, log_start
,
864 frold
->dirty_log_mask
,
865 frnew
->dirty_log_mask
);
867 if (frold
->dirty_log_mask
& ~frnew
->dirty_log_mask
) {
868 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, Reverse
, log_stop
,
869 frold
->dirty_log_mask
,
870 frnew
->dirty_log_mask
);
880 MEMORY_LISTENER_UPDATE_REGION(frnew
, as
, Forward
, region_add
);
889 static void address_space_update_topology(AddressSpace
*as
)
891 FlatView
*old_view
= address_space_get_flatview(as
);
892 FlatView
*new_view
= generate_memory_topology(as
->root
);
894 address_space_update_topology_pass(as
, old_view
, new_view
, false);
895 address_space_update_topology_pass(as
, old_view
, new_view
, true);
897 /* Writes are protected by the BQL. */
898 atomic_rcu_set(&as
->current_map
, new_view
);
899 call_rcu(old_view
, flatview_unref
, rcu
);
901 /* Note that all the old MemoryRegions are still alive up to this
902 * point. This relieves most MemoryListeners from the need to
903 * ref/unref the MemoryRegions they get---unless they use them
904 * outside the iothread mutex, in which case precise reference
905 * counting is necessary.
907 flatview_unref(old_view
);
909 address_space_update_ioeventfds(as
);
912 void memory_region_transaction_begin(void)
914 qemu_flush_coalesced_mmio_buffer();
915 ++memory_region_transaction_depth
;
918 static void memory_region_clear_pending(void)
920 memory_region_update_pending
= false;
921 ioeventfd_update_pending
= false;
924 void memory_region_transaction_commit(void)
928 assert(memory_region_transaction_depth
);
929 --memory_region_transaction_depth
;
930 if (!memory_region_transaction_depth
) {
931 if (memory_region_update_pending
) {
932 MEMORY_LISTENER_CALL_GLOBAL(begin
, Forward
);
934 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
935 address_space_update_topology(as
);
938 MEMORY_LISTENER_CALL_GLOBAL(commit
, Forward
);
939 } else if (ioeventfd_update_pending
) {
940 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
941 address_space_update_ioeventfds(as
);
944 memory_region_clear_pending();
948 static void memory_region_destructor_none(MemoryRegion
*mr
)
952 static void memory_region_destructor_ram(MemoryRegion
*mr
)
954 qemu_ram_free(mr
->ram_block
);
957 static bool memory_region_need_escape(char c
)
959 return c
== '/' || c
== '[' || c
== '\\' || c
== ']';
962 static char *memory_region_escape_name(const char *name
)
969 for (p
= name
; *p
; p
++) {
970 bytes
+= memory_region_need_escape(*p
) ? 4 : 1;
972 if (bytes
== p
- name
) {
973 return g_memdup(name
, bytes
+ 1);
976 escaped
= g_malloc(bytes
+ 1);
977 for (p
= name
, q
= escaped
; *p
; p
++) {
979 if (unlikely(memory_region_need_escape(c
))) {
982 *q
++ = "0123456789abcdef"[c
>> 4];
983 c
= "0123456789abcdef"[c
& 15];
991 void memory_region_init(MemoryRegion
*mr
,
996 object_initialize(mr
, sizeof(*mr
), TYPE_MEMORY_REGION
);
997 mr
->size
= int128_make64(size
);
998 if (size
== UINT64_MAX
) {
999 mr
->size
= int128_2_64();
1001 mr
->name
= g_strdup(name
);
1003 mr
->ram_block
= NULL
;
1006 char *escaped_name
= memory_region_escape_name(name
);
1007 char *name_array
= g_strdup_printf("%s[*]", escaped_name
);
1010 owner
= container_get(qdev_get_machine(), "/unattached");
1013 object_property_add_child(owner
, name_array
, OBJECT(mr
), &error_abort
);
1014 object_unref(OBJECT(mr
));
1016 g_free(escaped_name
);
1020 static void memory_region_get_addr(Object
*obj
, Visitor
*v
, const char *name
,
1021 void *opaque
, Error
**errp
)
1023 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1024 uint64_t value
= mr
->addr
;
1026 visit_type_uint64(v
, name
, &value
, errp
);
1029 static void memory_region_get_container(Object
*obj
, Visitor
*v
,
1030 const char *name
, void *opaque
,
1033 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1034 gchar
*path
= (gchar
*)"";
1036 if (mr
->container
) {
1037 path
= object_get_canonical_path(OBJECT(mr
->container
));
1039 visit_type_str(v
, name
, &path
, errp
);
1040 if (mr
->container
) {
1045 static Object
*memory_region_resolve_container(Object
*obj
, void *opaque
,
1048 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1050 return OBJECT(mr
->container
);
1053 static void memory_region_get_priority(Object
*obj
, Visitor
*v
,
1054 const char *name
, void *opaque
,
1057 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1058 int32_t value
= mr
->priority
;
1060 visit_type_int32(v
, name
, &value
, errp
);
1063 static void memory_region_get_size(Object
*obj
, Visitor
*v
, const char *name
,
1064 void *opaque
, Error
**errp
)
1066 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1067 uint64_t value
= memory_region_size(mr
);
1069 visit_type_uint64(v
, name
, &value
, errp
);
1072 static void memory_region_initfn(Object
*obj
)
1074 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1077 mr
->ops
= &unassigned_mem_ops
;
1079 mr
->romd_mode
= true;
1080 mr
->global_locking
= true;
1081 mr
->destructor
= memory_region_destructor_none
;
1082 QTAILQ_INIT(&mr
->subregions
);
1083 QTAILQ_INIT(&mr
->coalesced
);
1085 op
= object_property_add(OBJECT(mr
), "container",
1086 "link<" TYPE_MEMORY_REGION
">",
1087 memory_region_get_container
,
1088 NULL
, /* memory_region_set_container */
1089 NULL
, NULL
, &error_abort
);
1090 op
->resolve
= memory_region_resolve_container
;
1092 object_property_add(OBJECT(mr
), "addr", "uint64",
1093 memory_region_get_addr
,
1094 NULL
, /* memory_region_set_addr */
1095 NULL
, NULL
, &error_abort
);
1096 object_property_add(OBJECT(mr
), "priority", "uint32",
1097 memory_region_get_priority
,
1098 NULL
, /* memory_region_set_priority */
1099 NULL
, NULL
, &error_abort
);
1100 object_property_add(OBJECT(mr
), "size", "uint64",
1101 memory_region_get_size
,
1102 NULL
, /* memory_region_set_size, */
1103 NULL
, NULL
, &error_abort
);
1106 static int qemu_target_backtrace(target_ulong
*array
, size_t size
)
1110 #if defined(TARGET_ARM)
1111 CPUArchState
*env
= current_cpu
->env_ptr
;
1112 array
[0] = env
->regs
[15];
1113 array
[1] = env
->regs
[14];
1114 #elif defined(TARGET_MIPS)
1115 CPUArchState
*env
= current_cpu
->env_ptr
;
1116 array
[0] = env
->active_tc
.PC
;
1117 array
[1] = env
->active_tc
.gpr
[31];
1127 #include "disas/disas.h"
1128 const char *qemu_sprint_backtrace(char *buffer
, size_t length
)
1132 target_ulong caller
[2];
1134 qemu_target_backtrace(caller
, 2);
1135 symbol
= lookup_symbol(caller
[0]);
1136 p
+= sprintf(p
, "[%s]", symbol
);
1137 symbol
= lookup_symbol(caller
[1]);
1138 p
+= sprintf(p
, "[%s]", symbol
);
1140 p
+= sprintf(p
, "[cpu not running]");
1142 assert((p
- buffer
) < length
);
1146 static uint64_t unassigned_mem_read(void *opaque
, hwaddr addr
,
1149 if (trace_unassigned
) {
1151 fprintf(stderr
, "Unassigned mem read " TARGET_FMT_plx
" %s\n",
1152 addr
, qemu_sprint_backtrace(buffer
, sizeof(buffer
)));
1155 if (current_cpu
!= NULL
) {
1156 cpu_unassigned_access(current_cpu
, addr
, false, false, 0, size
);
1161 static void unassigned_mem_write(void *opaque
, hwaddr addr
,
1162 uint64_t val
, unsigned size
)
1164 if (trace_unassigned
) {
1166 fprintf(stderr
, "Unassigned mem write " TARGET_FMT_plx
1167 " = 0x%" PRIx64
" %s\n",
1168 addr
, val
, qemu_sprint_backtrace(buffer
, sizeof(buffer
)));
1170 if (current_cpu
!= NULL
) {
1171 cpu_unassigned_access(current_cpu
, addr
, true, false, 0, size
);
1175 static bool unassigned_mem_accepts(void *opaque
, hwaddr addr
,
1176 unsigned size
, bool is_write
)
1181 const MemoryRegionOps unassigned_mem_ops
= {
1182 .valid
.accepts
= unassigned_mem_accepts
,
1183 .endianness
= DEVICE_NATIVE_ENDIAN
,
1186 bool memory_region_access_valid(MemoryRegion
*mr
,
1191 int access_size_min
, access_size_max
;
1194 if (!mr
->ops
->valid
.unaligned
&& (addr
& (size
- 1))) {
1195 fprintf(stderr
, "Misaligned i/o to address %08" HWADDR_PRIx
1196 " with size %u for memory region %s\n",
1197 addr
, size
, mr
->name
);
1201 if (!mr
->ops
->valid
.accepts
) {
1205 access_size_min
= mr
->ops
->valid
.min_access_size
;
1206 if (!mr
->ops
->valid
.min_access_size
) {
1207 access_size_min
= 1;
1210 access_size_max
= mr
->ops
->valid
.max_access_size
;
1211 if (!mr
->ops
->valid
.max_access_size
) {
1212 access_size_max
= 4;
1215 access_size
= MAX(MIN(size
, access_size_max
), access_size_min
);
1216 for (i
= 0; i
< size
; i
+= access_size
) {
1217 if (!mr
->ops
->valid
.accepts(mr
->opaque
, addr
+ i
, access_size
,
1226 static MemTxResult
memory_region_dispatch_read1(MemoryRegion
*mr
,
1234 if (mr
->ops
->read
) {
1235 return access_with_adjusted_size(addr
, pval
, size
,
1236 mr
->ops
->impl
.min_access_size
,
1237 mr
->ops
->impl
.max_access_size
,
1238 memory_region_read_accessor
,
1240 } else if (mr
->ops
->read_with_attrs
) {
1241 return access_with_adjusted_size(addr
, pval
, size
,
1242 mr
->ops
->impl
.min_access_size
,
1243 mr
->ops
->impl
.max_access_size
,
1244 memory_region_read_with_attrs_accessor
,
1247 return access_with_adjusted_size(addr
, pval
, size
, 1, 4,
1248 memory_region_oldmmio_read_accessor
,
1253 MemTxResult
memory_region_dispatch_read(MemoryRegion
*mr
,
1261 if (!memory_region_access_valid(mr
, addr
, size
, false)) {
1262 *pval
= unassigned_mem_read(mr
, addr
, size
);
1263 return MEMTX_DECODE_ERROR
;
1266 r
= memory_region_dispatch_read1(mr
, addr
, pval
, size
, attrs
);
1267 adjust_endianness(mr
, pval
, size
);
1271 /* Return true if an eventfd was signalled */
1272 static bool memory_region_dispatch_write_eventfds(MemoryRegion
*mr
,
1278 MemoryRegionIoeventfd ioeventfd
= {
1279 .addr
= addrrange_make(int128_make64(addr
), int128_make64(size
)),
1284 for (i
= 0; i
< mr
->ioeventfd_nb
; i
++) {
1285 ioeventfd
.match_data
= mr
->ioeventfds
[i
].match_data
;
1286 ioeventfd
.e
= mr
->ioeventfds
[i
].e
;
1288 if (memory_region_ioeventfd_equal(ioeventfd
, mr
->ioeventfds
[i
])) {
1289 event_notifier_set(ioeventfd
.e
);
1297 MemTxResult
memory_region_dispatch_write(MemoryRegion
*mr
,
1303 if (!memory_region_access_valid(mr
, addr
, size
, true)) {
1304 unassigned_mem_write(mr
, addr
, data
, size
);
1305 return MEMTX_DECODE_ERROR
;
1308 adjust_endianness(mr
, &data
, size
);
1310 if ((!kvm_eventfds_enabled()) &&
1311 memory_region_dispatch_write_eventfds(mr
, addr
, data
, size
, attrs
)) {
1315 if (mr
->ops
->write
) {
1316 return access_with_adjusted_size(addr
, &data
, size
,
1317 mr
->ops
->impl
.min_access_size
,
1318 mr
->ops
->impl
.max_access_size
,
1319 memory_region_write_accessor
, mr
,
1321 } else if (mr
->ops
->write_with_attrs
) {
1323 access_with_adjusted_size(addr
, &data
, size
,
1324 mr
->ops
->impl
.min_access_size
,
1325 mr
->ops
->impl
.max_access_size
,
1326 memory_region_write_with_attrs_accessor
,
1329 return access_with_adjusted_size(addr
, &data
, size
, 1, 4,
1330 memory_region_oldmmio_write_accessor
,
1335 void memory_region_init_io(MemoryRegion
*mr
,
1337 const MemoryRegionOps
*ops
,
1342 memory_region_init(mr
, owner
, name
, size
);
1343 mr
->ops
= ops
? ops
: &unassigned_mem_ops
;
1344 mr
->opaque
= opaque
;
1345 mr
->terminates
= true;
1348 void memory_region_init_ram(MemoryRegion
*mr
,
1354 memory_region_init(mr
, owner
, name
, size
);
1356 mr
->terminates
= true;
1357 mr
->destructor
= memory_region_destructor_ram
;
1358 mr
->ram_block
= qemu_ram_alloc(size
, mr
, errp
);
1359 mr
->dirty_log_mask
= tcg_enabled() ? (1 << DIRTY_MEMORY_CODE
) : 0;
1362 void memory_region_init_resizeable_ram(MemoryRegion
*mr
,
1367 void (*resized
)(const char*,
1372 memory_region_init(mr
, owner
, name
, size
);
1374 mr
->terminates
= true;
1375 mr
->destructor
= memory_region_destructor_ram
;
1376 mr
->ram_block
= qemu_ram_alloc_resizeable(size
, max_size
, resized
,
1378 mr
->dirty_log_mask
= tcg_enabled() ? (1 << DIRTY_MEMORY_CODE
) : 0;
1382 void memory_region_init_ram_from_file(MemoryRegion
*mr
,
1383 struct Object
*owner
,
1390 memory_region_init(mr
, owner
, name
, size
);
1392 mr
->terminates
= true;
1393 mr
->destructor
= memory_region_destructor_ram
;
1394 mr
->ram_block
= qemu_ram_alloc_from_file(size
, mr
, share
, path
, errp
);
1395 mr
->dirty_log_mask
= tcg_enabled() ? (1 << DIRTY_MEMORY_CODE
) : 0;
1399 void memory_region_init_ram_ptr(MemoryRegion
*mr
,
1405 memory_region_init(mr
, owner
, name
, size
);
1407 mr
->terminates
= true;
1408 mr
->destructor
= memory_region_destructor_ram
;
1409 mr
->dirty_log_mask
= tcg_enabled() ? (1 << DIRTY_MEMORY_CODE
) : 0;
1411 /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */
1412 assert(ptr
!= NULL
);
1413 mr
->ram_block
= qemu_ram_alloc_from_ptr(size
, ptr
, mr
, &error_fatal
);
1416 void memory_region_set_skip_dump(MemoryRegion
*mr
)
1418 mr
->skip_dump
= true;
1421 void memory_region_init_alias(MemoryRegion
*mr
,
1428 memory_region_init(mr
, owner
, name
, size
);
1430 mr
->alias_offset
= offset
;
1433 void memory_region_init_rom(MemoryRegion
*mr
,
1434 struct Object
*owner
,
1439 memory_region_init(mr
, owner
, name
, size
);
1441 mr
->readonly
= true;
1442 mr
->terminates
= true;
1443 mr
->destructor
= memory_region_destructor_ram
;
1444 mr
->ram_block
= qemu_ram_alloc(size
, mr
, errp
);
1445 mr
->dirty_log_mask
= tcg_enabled() ? (1 << DIRTY_MEMORY_CODE
) : 0;
1448 void memory_region_init_rom_device(MemoryRegion
*mr
,
1450 const MemoryRegionOps
*ops
,
1457 memory_region_init(mr
, owner
, name
, size
);
1459 mr
->opaque
= opaque
;
1460 mr
->terminates
= true;
1461 mr
->rom_device
= true;
1462 mr
->destructor
= memory_region_destructor_ram
;
1463 mr
->ram_block
= qemu_ram_alloc(size
, mr
, errp
);
1466 void memory_region_init_iommu(MemoryRegion
*mr
,
1468 const MemoryRegionIOMMUOps
*ops
,
1472 memory_region_init(mr
, owner
, name
, size
);
1473 mr
->iommu_ops
= ops
,
1474 mr
->terminates
= true; /* then re-forwards */
1475 QLIST_INIT(&mr
->iommu_notify
);
1476 mr
->iommu_notify_flags
= IOMMU_NOTIFIER_NONE
;
1479 static void memory_region_finalize(Object
*obj
)
1481 MemoryRegion
*mr
= MEMORY_REGION(obj
);
1483 assert(!mr
->container
);
1485 /* We know the region is not visible in any address space (it
1486 * does not have a container and cannot be a root either because
1487 * it has no references, so we can blindly clear mr->enabled.
1488 * memory_region_set_enabled instead could trigger a transaction
1489 * and cause an infinite loop.
1491 mr
->enabled
= false;
1492 memory_region_transaction_begin();
1493 while (!QTAILQ_EMPTY(&mr
->subregions
)) {
1494 MemoryRegion
*subregion
= QTAILQ_FIRST(&mr
->subregions
);
1495 memory_region_del_subregion(mr
, subregion
);
1497 memory_region_transaction_commit();
1500 memory_region_clear_coalescing(mr
);
1501 g_free((char *)mr
->name
);
1502 g_free(mr
->ioeventfds
);
1505 Object
*memory_region_owner(MemoryRegion
*mr
)
1507 Object
*obj
= OBJECT(mr
);
1511 void memory_region_ref(MemoryRegion
*mr
)
1513 /* MMIO callbacks most likely will access data that belongs
1514 * to the owner, hence the need to ref/unref the owner whenever
1515 * the memory region is in use.
1517 * The memory region is a child of its owner. As long as the
1518 * owner doesn't call unparent itself on the memory region,
1519 * ref-ing the owner will also keep the memory region alive.
1520 * Memory regions without an owner are supposed to never go away;
1521 * we do not ref/unref them because it slows down DMA sensibly.
1523 if (mr
&& mr
->owner
) {
1524 object_ref(mr
->owner
);
1528 void memory_region_unref(MemoryRegion
*mr
)
1530 if (mr
&& mr
->owner
) {
1531 object_unref(mr
->owner
);
1535 uint64_t memory_region_size(MemoryRegion
*mr
)
1537 if (int128_eq(mr
->size
, int128_2_64())) {
1540 return int128_get64(mr
->size
);
1543 const char *memory_region_name(const MemoryRegion
*mr
)
1546 ((MemoryRegion
*)mr
)->name
=
1547 object_get_canonical_path_component(OBJECT(mr
));
1552 bool memory_region_is_skip_dump(MemoryRegion
*mr
)
1554 return mr
->skip_dump
;
1557 uint8_t memory_region_get_dirty_log_mask(MemoryRegion
*mr
)
1559 uint8_t mask
= mr
->dirty_log_mask
;
1560 if (global_dirty_log
) {
1561 mask
|= (1 << DIRTY_MEMORY_MIGRATION
);
1566 bool memory_region_is_logging(MemoryRegion
*mr
, uint8_t client
)
1568 return memory_region_get_dirty_log_mask(mr
) & (1 << client
);
1571 static void memory_region_update_iommu_notify_flags(MemoryRegion
*mr
)
1573 IOMMUNotifierFlag flags
= IOMMU_NOTIFIER_NONE
;
1574 IOMMUNotifier
*iommu_notifier
;
1576 QLIST_FOREACH(iommu_notifier
, &mr
->iommu_notify
, node
) {
1577 flags
|= iommu_notifier
->notifier_flags
;
1580 if (flags
!= mr
->iommu_notify_flags
&&
1581 mr
->iommu_ops
->notify_flag_changed
) {
1582 mr
->iommu_ops
->notify_flag_changed(mr
, mr
->iommu_notify_flags
,
1586 mr
->iommu_notify_flags
= flags
;
1589 void memory_region_register_iommu_notifier(MemoryRegion
*mr
,
1592 /* We need to register for at least one bitfield */
1593 assert(n
->notifier_flags
!= IOMMU_NOTIFIER_NONE
);
1594 QLIST_INSERT_HEAD(&mr
->iommu_notify
, n
, node
);
1595 memory_region_update_iommu_notify_flags(mr
);
1598 uint64_t memory_region_iommu_get_min_page_size(MemoryRegion
*mr
)
1600 assert(memory_region_is_iommu(mr
));
1601 if (mr
->iommu_ops
&& mr
->iommu_ops
->get_min_page_size
) {
1602 return mr
->iommu_ops
->get_min_page_size(mr
);
1604 return TARGET_PAGE_SIZE
;
1607 void memory_region_iommu_replay(MemoryRegion
*mr
, IOMMUNotifier
*n
,
1610 hwaddr addr
, granularity
;
1611 IOMMUTLBEntry iotlb
;
1613 granularity
= memory_region_iommu_get_min_page_size(mr
);
1615 for (addr
= 0; addr
< memory_region_size(mr
); addr
+= granularity
) {
1616 iotlb
= mr
->iommu_ops
->translate(mr
, addr
, is_write
);
1617 if (iotlb
.perm
!= IOMMU_NONE
) {
1618 n
->notify(n
, &iotlb
);
1621 /* if (2^64 - MR size) < granularity, it's possible to get an
1622 * infinite loop here. This should catch such a wraparound */
1623 if ((addr
+ granularity
) < addr
) {
1629 void memory_region_unregister_iommu_notifier(MemoryRegion
*mr
,
1632 QLIST_REMOVE(n
, node
);
1633 memory_region_update_iommu_notify_flags(mr
);
1636 void memory_region_notify_iommu(MemoryRegion
*mr
,
1637 IOMMUTLBEntry entry
)
1639 IOMMUNotifier
*iommu_notifier
;
1640 IOMMUNotifierFlag request_flags
;
1642 assert(memory_region_is_iommu(mr
));
1644 if (entry
.perm
& IOMMU_RW
) {
1645 request_flags
= IOMMU_NOTIFIER_MAP
;
1647 request_flags
= IOMMU_NOTIFIER_UNMAP
;
1650 QLIST_FOREACH(iommu_notifier
, &mr
->iommu_notify
, node
) {
1651 if (iommu_notifier
->notifier_flags
& request_flags
) {
1652 iommu_notifier
->notify(iommu_notifier
, &entry
);
1657 void memory_region_set_log(MemoryRegion
*mr
, bool log
, unsigned client
)
1659 uint8_t mask
= 1 << client
;
1660 uint8_t old_logging
;
1662 assert(client
== DIRTY_MEMORY_VGA
);
1663 old_logging
= mr
->vga_logging_count
;
1664 mr
->vga_logging_count
+= log
? 1 : -1;
1665 if (!!old_logging
== !!mr
->vga_logging_count
) {
1669 memory_region_transaction_begin();
1670 mr
->dirty_log_mask
= (mr
->dirty_log_mask
& ~mask
) | (log
* mask
);
1671 memory_region_update_pending
|= mr
->enabled
;
1672 memory_region_transaction_commit();
1675 bool memory_region_get_dirty(MemoryRegion
*mr
, hwaddr addr
,
1676 hwaddr size
, unsigned client
)
1678 assert(mr
->ram_block
);
1679 return cpu_physical_memory_get_dirty(memory_region_get_ram_addr(mr
) + addr
,
1683 void memory_region_set_dirty(MemoryRegion
*mr
, hwaddr addr
,
1686 assert(mr
->ram_block
);
1687 cpu_physical_memory_set_dirty_range(memory_region_get_ram_addr(mr
) + addr
,
1689 memory_region_get_dirty_log_mask(mr
));
1692 bool memory_region_test_and_clear_dirty(MemoryRegion
*mr
, hwaddr addr
,
1693 hwaddr size
, unsigned client
)
1695 assert(mr
->ram_block
);
1696 return cpu_physical_memory_test_and_clear_dirty(
1697 memory_region_get_ram_addr(mr
) + addr
, size
, client
);
1701 void memory_region_sync_dirty_bitmap(MemoryRegion
*mr
)
1706 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
1707 FlatView
*view
= address_space_get_flatview(as
);
1708 FOR_EACH_FLAT_RANGE(fr
, view
) {
1710 MEMORY_LISTENER_UPDATE_REGION(fr
, as
, Forward
, log_sync
);
1713 flatview_unref(view
);
1717 void memory_region_set_readonly(MemoryRegion
*mr
, bool readonly
)
1719 if (mr
->readonly
!= readonly
) {
1720 memory_region_transaction_begin();
1721 mr
->readonly
= readonly
;
1722 memory_region_update_pending
|= mr
->enabled
;
1723 memory_region_transaction_commit();
1727 void memory_region_rom_device_set_romd(MemoryRegion
*mr
, bool romd_mode
)
1729 if (mr
->romd_mode
!= romd_mode
) {
1730 memory_region_transaction_begin();
1731 mr
->romd_mode
= romd_mode
;
1732 memory_region_update_pending
|= mr
->enabled
;
1733 memory_region_transaction_commit();
1737 void memory_region_reset_dirty(MemoryRegion
*mr
, hwaddr addr
,
1738 hwaddr size
, unsigned client
)
1740 assert(mr
->ram_block
);
1741 cpu_physical_memory_test_and_clear_dirty(
1742 memory_region_get_ram_addr(mr
) + addr
, size
, client
);
1745 int memory_region_get_fd(MemoryRegion
*mr
)
1753 fd
= mr
->ram_block
->fd
;
1759 void memory_region_set_fd(MemoryRegion
*mr
, int fd
)
1765 mr
->ram_block
->fd
= fd
;
1769 void *memory_region_get_ram_ptr(MemoryRegion
*mr
)
1772 uint64_t offset
= 0;
1776 offset
+= mr
->alias_offset
;
1779 assert(mr
->ram_block
);
1780 ptr
= qemu_map_ram_ptr(mr
->ram_block
, offset
);
1786 MemoryRegion
*memory_region_from_host(void *ptr
, ram_addr_t
*offset
)
1790 block
= qemu_ram_block_from_host(ptr
, false, offset
);
1798 ram_addr_t
memory_region_get_ram_addr(MemoryRegion
*mr
)
1800 return mr
->ram_block
? mr
->ram_block
->offset
: RAM_ADDR_INVALID
;
1803 void memory_region_ram_resize(MemoryRegion
*mr
, ram_addr_t newsize
, Error
**errp
)
1805 assert(mr
->ram_block
);
1807 qemu_ram_resize(mr
->ram_block
, newsize
, errp
);
1810 static void memory_region_update_coalesced_range_as(MemoryRegion
*mr
, AddressSpace
*as
)
1814 CoalescedMemoryRange
*cmr
;
1816 MemoryRegionSection section
;
1818 view
= address_space_get_flatview(as
);
1819 FOR_EACH_FLAT_RANGE(fr
, view
) {
1821 section
= (MemoryRegionSection
) {
1822 .address_space
= as
,
1823 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
1824 .size
= fr
->addr
.size
,
1827 MEMORY_LISTENER_CALL(coalesced_mmio_del
, Reverse
, §ion
,
1828 int128_get64(fr
->addr
.start
),
1829 int128_get64(fr
->addr
.size
));
1830 QTAILQ_FOREACH(cmr
, &mr
->coalesced
, link
) {
1831 tmp
= addrrange_shift(cmr
->addr
,
1832 int128_sub(fr
->addr
.start
,
1833 int128_make64(fr
->offset_in_region
)));
1834 if (!addrrange_intersects(tmp
, fr
->addr
)) {
1837 tmp
= addrrange_intersection(tmp
, fr
->addr
);
1838 MEMORY_LISTENER_CALL(coalesced_mmio_add
, Forward
, §ion
,
1839 int128_get64(tmp
.start
),
1840 int128_get64(tmp
.size
));
1844 flatview_unref(view
);
1847 static void memory_region_update_coalesced_range(MemoryRegion
*mr
)
1851 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
1852 memory_region_update_coalesced_range_as(mr
, as
);
1856 void memory_region_set_coalescing(MemoryRegion
*mr
)
1858 memory_region_clear_coalescing(mr
);
1859 memory_region_add_coalescing(mr
, 0, int128_get64(mr
->size
));
1862 void memory_region_add_coalescing(MemoryRegion
*mr
,
1866 CoalescedMemoryRange
*cmr
= g_malloc(sizeof(*cmr
));
1868 cmr
->addr
= addrrange_make(int128_make64(offset
), int128_make64(size
));
1869 QTAILQ_INSERT_TAIL(&mr
->coalesced
, cmr
, link
);
1870 memory_region_update_coalesced_range(mr
);
1871 memory_region_set_flush_coalesced(mr
);
1874 void memory_region_clear_coalescing(MemoryRegion
*mr
)
1876 CoalescedMemoryRange
*cmr
;
1877 bool updated
= false;
1879 qemu_flush_coalesced_mmio_buffer();
1880 mr
->flush_coalesced_mmio
= false;
1882 while (!QTAILQ_EMPTY(&mr
->coalesced
)) {
1883 cmr
= QTAILQ_FIRST(&mr
->coalesced
);
1884 QTAILQ_REMOVE(&mr
->coalesced
, cmr
, link
);
1890 memory_region_update_coalesced_range(mr
);
1894 void memory_region_set_flush_coalesced(MemoryRegion
*mr
)
1896 mr
->flush_coalesced_mmio
= true;
1899 void memory_region_clear_flush_coalesced(MemoryRegion
*mr
)
1901 qemu_flush_coalesced_mmio_buffer();
1902 if (QTAILQ_EMPTY(&mr
->coalesced
)) {
1903 mr
->flush_coalesced_mmio
= false;
1907 void memory_region_set_global_locking(MemoryRegion
*mr
)
1909 mr
->global_locking
= true;
1912 void memory_region_clear_global_locking(MemoryRegion
*mr
)
1914 mr
->global_locking
= false;
1917 static bool userspace_eventfd_warning
;
1919 void memory_region_add_eventfd(MemoryRegion
*mr
,
1926 MemoryRegionIoeventfd mrfd
= {
1927 .addr
.start
= int128_make64(addr
),
1928 .addr
.size
= int128_make64(size
),
1929 .match_data
= match_data
,
1935 if (kvm_enabled() && (!(kvm_eventfds_enabled() ||
1936 userspace_eventfd_warning
))) {
1937 userspace_eventfd_warning
= true;
1938 error_report("Using eventfd without MMIO binding in KVM. "
1939 "Suboptimal performance expected");
1943 adjust_endianness(mr
, &mrfd
.data
, size
);
1945 memory_region_transaction_begin();
1946 for (i
= 0; i
< mr
->ioeventfd_nb
; ++i
) {
1947 if (memory_region_ioeventfd_before(mrfd
, mr
->ioeventfds
[i
])) {
1952 mr
->ioeventfds
= g_realloc(mr
->ioeventfds
,
1953 sizeof(*mr
->ioeventfds
) * mr
->ioeventfd_nb
);
1954 memmove(&mr
->ioeventfds
[i
+1], &mr
->ioeventfds
[i
],
1955 sizeof(*mr
->ioeventfds
) * (mr
->ioeventfd_nb
-1 - i
));
1956 mr
->ioeventfds
[i
] = mrfd
;
1957 ioeventfd_update_pending
|= mr
->enabled
;
1958 memory_region_transaction_commit();
1961 void memory_region_del_eventfd(MemoryRegion
*mr
,
1968 MemoryRegionIoeventfd mrfd
= {
1969 .addr
.start
= int128_make64(addr
),
1970 .addr
.size
= int128_make64(size
),
1971 .match_data
= match_data
,
1978 adjust_endianness(mr
, &mrfd
.data
, size
);
1980 memory_region_transaction_begin();
1981 for (i
= 0; i
< mr
->ioeventfd_nb
; ++i
) {
1982 if (memory_region_ioeventfd_equal(mrfd
, mr
->ioeventfds
[i
])) {
1986 assert(i
!= mr
->ioeventfd_nb
);
1987 memmove(&mr
->ioeventfds
[i
], &mr
->ioeventfds
[i
+1],
1988 sizeof(*mr
->ioeventfds
) * (mr
->ioeventfd_nb
- (i
+1)));
1990 mr
->ioeventfds
= g_realloc(mr
->ioeventfds
,
1991 sizeof(*mr
->ioeventfds
)*mr
->ioeventfd_nb
+ 1);
1992 ioeventfd_update_pending
|= mr
->enabled
;
1993 memory_region_transaction_commit();
1996 static void memory_region_update_container_subregions(MemoryRegion
*subregion
)
1998 MemoryRegion
*mr
= subregion
->container
;
1999 MemoryRegion
*other
;
2001 memory_region_transaction_begin();
2003 memory_region_ref(subregion
);
2004 QTAILQ_FOREACH(other
, &mr
->subregions
, subregions_link
) {
2005 if (subregion
->priority
>= other
->priority
) {
2006 QTAILQ_INSERT_BEFORE(other
, subregion
, subregions_link
);
2010 QTAILQ_INSERT_TAIL(&mr
->subregions
, subregion
, subregions_link
);
2012 memory_region_update_pending
|= mr
->enabled
&& subregion
->enabled
;
2013 memory_region_transaction_commit();
2016 static void memory_region_add_subregion_common(MemoryRegion
*mr
,
2018 MemoryRegion
*subregion
)
2020 assert(!subregion
->container
);
2021 subregion
->container
= mr
;
2022 subregion
->addr
= offset
;
2023 memory_region_update_container_subregions(subregion
);
2026 void memory_region_add_subregion(MemoryRegion
*mr
,
2028 MemoryRegion
*subregion
)
2030 subregion
->priority
= 0;
2031 memory_region_add_subregion_common(mr
, offset
, subregion
);
2034 void memory_region_add_subregion_overlap(MemoryRegion
*mr
,
2036 MemoryRegion
*subregion
,
2039 subregion
->priority
= priority
;
2040 memory_region_add_subregion_common(mr
, offset
, subregion
);
2043 void memory_region_del_subregion(MemoryRegion
*mr
,
2044 MemoryRegion
*subregion
)
2046 memory_region_transaction_begin();
2047 assert(subregion
->container
== mr
);
2048 subregion
->container
= NULL
;
2049 QTAILQ_REMOVE(&mr
->subregions
, subregion
, subregions_link
);
2050 memory_region_unref(subregion
);
2051 memory_region_update_pending
|= mr
->enabled
&& subregion
->enabled
;
2052 memory_region_transaction_commit();
2055 void memory_region_set_enabled(MemoryRegion
*mr
, bool enabled
)
2057 if (enabled
== mr
->enabled
) {
2060 memory_region_transaction_begin();
2061 mr
->enabled
= enabled
;
2062 memory_region_update_pending
= true;
2063 memory_region_transaction_commit();
2066 void memory_region_set_size(MemoryRegion
*mr
, uint64_t size
)
2068 Int128 s
= int128_make64(size
);
2070 if (size
== UINT64_MAX
) {
2073 if (int128_eq(s
, mr
->size
)) {
2076 memory_region_transaction_begin();
2078 memory_region_update_pending
= true;
2079 memory_region_transaction_commit();
2082 static void memory_region_readd_subregion(MemoryRegion
*mr
)
2084 MemoryRegion
*container
= mr
->container
;
2087 memory_region_transaction_begin();
2088 memory_region_ref(mr
);
2089 memory_region_del_subregion(container
, mr
);
2090 mr
->container
= container
;
2091 memory_region_update_container_subregions(mr
);
2092 memory_region_unref(mr
);
2093 memory_region_transaction_commit();
2097 void memory_region_set_address(MemoryRegion
*mr
, hwaddr addr
)
2099 if (addr
!= mr
->addr
) {
2101 memory_region_readd_subregion(mr
);
2105 void memory_region_set_alias_offset(MemoryRegion
*mr
, hwaddr offset
)
2109 if (offset
== mr
->alias_offset
) {
2113 memory_region_transaction_begin();
2114 mr
->alias_offset
= offset
;
2115 memory_region_update_pending
|= mr
->enabled
;
2116 memory_region_transaction_commit();
2119 uint64_t memory_region_get_alignment(const MemoryRegion
*mr
)
2124 static int cmp_flatrange_addr(const void *addr_
, const void *fr_
)
2126 const AddrRange
*addr
= addr_
;
2127 const FlatRange
*fr
= fr_
;
2129 if (int128_le(addrrange_end(*addr
), fr
->addr
.start
)) {
2131 } else if (int128_ge(addr
->start
, addrrange_end(fr
->addr
))) {
2137 static FlatRange
*flatview_lookup(FlatView
*view
, AddrRange addr
)
2139 return bsearch(&addr
, view
->ranges
, view
->nr
,
2140 sizeof(FlatRange
), cmp_flatrange_addr
);
2143 bool memory_region_is_mapped(MemoryRegion
*mr
)
2145 return mr
->container
? true : false;
2148 /* Same as memory_region_find, but it does not add a reference to the
2149 * returned region. It must be called from an RCU critical section.
2151 static MemoryRegionSection
memory_region_find_rcu(MemoryRegion
*mr
,
2152 hwaddr addr
, uint64_t size
)
2154 MemoryRegionSection ret
= { .mr
= NULL
};
2162 for (root
= mr
; root
->container
; ) {
2163 root
= root
->container
;
2167 as
= memory_region_to_address_space(root
);
2171 range
= addrrange_make(int128_make64(addr
), int128_make64(size
));
2173 view
= atomic_rcu_read(&as
->current_map
);
2174 fr
= flatview_lookup(view
, range
);
2179 while (fr
> view
->ranges
&& addrrange_intersects(fr
[-1].addr
, range
)) {
2184 ret
.address_space
= as
;
2185 range
= addrrange_intersection(range
, fr
->addr
);
2186 ret
.offset_within_region
= fr
->offset_in_region
;
2187 ret
.offset_within_region
+= int128_get64(int128_sub(range
.start
,
2189 ret
.size
= range
.size
;
2190 ret
.offset_within_address_space
= int128_get64(range
.start
);
2191 ret
.readonly
= fr
->readonly
;
2195 MemoryRegionSection
memory_region_find(MemoryRegion
*mr
,
2196 hwaddr addr
, uint64_t size
)
2198 MemoryRegionSection ret
;
2200 ret
= memory_region_find_rcu(mr
, addr
, size
);
2202 memory_region_ref(ret
.mr
);
2208 bool memory_region_present(MemoryRegion
*container
, hwaddr addr
)
2213 mr
= memory_region_find_rcu(container
, addr
, 1).mr
;
2215 return mr
&& mr
!= container
;
2218 void memory_global_dirty_log_sync(void)
2220 MemoryListener
*listener
;
2225 QTAILQ_FOREACH(listener
, &memory_listeners
, link
) {
2226 if (!listener
->log_sync
) {
2229 /* Global listeners are being phased out. */
2230 assert(listener
->address_space_filter
);
2231 as
= listener
->address_space_filter
;
2232 view
= address_space_get_flatview(as
);
2233 FOR_EACH_FLAT_RANGE(fr
, view
) {
2234 MemoryRegionSection mrs
= section_from_flat_range(fr
, as
);
2235 listener
->log_sync(listener
, &mrs
);
2237 flatview_unref(view
);
2241 void memory_global_dirty_log_start(void)
2243 global_dirty_log
= true;
2245 MEMORY_LISTENER_CALL_GLOBAL(log_global_start
, Forward
);
2247 /* Refresh DIRTY_LOG_MIGRATION bit. */
2248 memory_region_transaction_begin();
2249 memory_region_update_pending
= true;
2250 memory_region_transaction_commit();
2253 void memory_global_dirty_log_stop(void)
2255 global_dirty_log
= false;
2257 /* Refresh DIRTY_LOG_MIGRATION bit. */
2258 memory_region_transaction_begin();
2259 memory_region_update_pending
= true;
2260 memory_region_transaction_commit();
2262 MEMORY_LISTENER_CALL_GLOBAL(log_global_stop
, Reverse
);
2265 static void listener_add_address_space(MemoryListener
*listener
,
2271 if (listener
->address_space_filter
2272 && listener
->address_space_filter
!= as
) {
2276 if (listener
->begin
) {
2277 listener
->begin(listener
);
2279 if (global_dirty_log
) {
2280 if (listener
->log_global_start
) {
2281 listener
->log_global_start(listener
);
2285 view
= address_space_get_flatview(as
);
2286 FOR_EACH_FLAT_RANGE(fr
, view
) {
2287 MemoryRegionSection section
= {
2289 .address_space
= as
,
2290 .offset_within_region
= fr
->offset_in_region
,
2291 .size
= fr
->addr
.size
,
2292 .offset_within_address_space
= int128_get64(fr
->addr
.start
),
2293 .readonly
= fr
->readonly
,
2295 if (fr
->dirty_log_mask
&& listener
->log_start
) {
2296 listener
->log_start(listener
, §ion
, 0, fr
->dirty_log_mask
);
2298 if (listener
->region_add
) {
2299 listener
->region_add(listener
, §ion
);
2302 if (listener
->commit
) {
2303 listener
->commit(listener
);
2305 flatview_unref(view
);
2308 void memory_listener_register(MemoryListener
*listener
, AddressSpace
*filter
)
2310 MemoryListener
*other
= NULL
;
2313 listener
->address_space_filter
= filter
;
2314 if (QTAILQ_EMPTY(&memory_listeners
)
2315 || listener
->priority
>= QTAILQ_LAST(&memory_listeners
,
2316 memory_listeners
)->priority
) {
2317 QTAILQ_INSERT_TAIL(&memory_listeners
, listener
, link
);
2319 QTAILQ_FOREACH(other
, &memory_listeners
, link
) {
2320 if (listener
->priority
< other
->priority
) {
2324 QTAILQ_INSERT_BEFORE(other
, listener
, link
);
2327 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
2328 listener_add_address_space(listener
, as
);
2332 void memory_listener_unregister(MemoryListener
*listener
)
2334 QTAILQ_REMOVE(&memory_listeners
, listener
, link
);
2337 void address_space_init(AddressSpace
*as
, MemoryRegion
*root
, const char *name
)
2339 memory_region_ref(root
);
2340 memory_region_transaction_begin();
2343 as
->malloced
= false;
2344 as
->current_map
= g_new(FlatView
, 1);
2345 flatview_init(as
->current_map
);
2346 as
->ioeventfd_nb
= 0;
2347 as
->ioeventfds
= NULL
;
2348 QTAILQ_INSERT_TAIL(&address_spaces
, as
, address_spaces_link
);
2349 as
->name
= g_strdup(name
? name
: "anonymous");
2350 address_space_init_dispatch(as
);
2351 memory_region_update_pending
|= root
->enabled
;
2352 memory_region_transaction_commit();
2355 static void do_address_space_destroy(AddressSpace
*as
)
2357 MemoryListener
*listener
;
2358 bool do_free
= as
->malloced
;
2360 address_space_destroy_dispatch(as
);
2362 QTAILQ_FOREACH(listener
, &memory_listeners
, link
) {
2363 assert(listener
->address_space_filter
!= as
);
2366 flatview_unref(as
->current_map
);
2368 g_free(as
->ioeventfds
);
2369 memory_region_unref(as
->root
);
2375 AddressSpace
*address_space_init_shareable(MemoryRegion
*root
, const char *name
)
2379 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
2380 if (root
== as
->root
&& as
->malloced
) {
2386 as
= g_malloc0(sizeof *as
);
2387 address_space_init(as
, root
, name
);
2388 as
->malloced
= true;
2392 void address_space_destroy(AddressSpace
*as
)
2394 MemoryRegion
*root
= as
->root
;
2397 if (as
->ref_count
) {
2400 /* Flush out anything from MemoryListeners listening in on this */
2401 memory_region_transaction_begin();
2403 memory_region_transaction_commit();
2404 QTAILQ_REMOVE(&address_spaces
, as
, address_spaces_link
);
2405 address_space_unregister(as
);
2407 /* At this point, as->dispatch and as->current_map are dummy
2408 * entries that the guest should never use. Wait for the old
2409 * values to expire before freeing the data.
2412 call_rcu(as
, do_address_space_destroy
, rcu
);
2415 typedef struct MemoryRegionList MemoryRegionList
;
2417 struct MemoryRegionList
{
2418 const MemoryRegion
*mr
;
2419 QTAILQ_ENTRY(MemoryRegionList
) queue
;
2422 typedef QTAILQ_HEAD(queue
, MemoryRegionList
) MemoryRegionListHead
;
2424 static void mtree_print_mr(fprintf_function mon_printf
, void *f
,
2425 const MemoryRegion
*mr
, unsigned int level
,
2427 MemoryRegionListHead
*alias_print_queue
)
2429 MemoryRegionList
*new_ml
, *ml
, *next_ml
;
2430 MemoryRegionListHead submr_print_queue
;
2431 const MemoryRegion
*submr
;
2438 for (i
= 0; i
< level
; i
++) {
2443 MemoryRegionList
*ml
;
2446 /* check if the alias is already in the queue */
2447 QTAILQ_FOREACH(ml
, alias_print_queue
, queue
) {
2448 if (ml
->mr
== mr
->alias
) {
2454 ml
= g_new(MemoryRegionList
, 1);
2456 QTAILQ_INSERT_TAIL(alias_print_queue
, ml
, queue
);
2458 mon_printf(f
, TARGET_FMT_plx
"-" TARGET_FMT_plx
2459 " (prio %d, %c%c): alias %s @%s " TARGET_FMT_plx
2460 "-" TARGET_FMT_plx
"%s\n",
2463 + (int128_nz(mr
->size
) ?
2464 (hwaddr
)int128_get64(int128_sub(mr
->size
,
2465 int128_one())) : 0),
2467 mr
->romd_mode
? 'R' : '-',
2468 !mr
->readonly
&& !(mr
->rom_device
&& mr
->romd_mode
) ? 'W'
2470 memory_region_name(mr
),
2471 memory_region_name(mr
->alias
),
2474 + (int128_nz(mr
->size
) ?
2475 (hwaddr
)int128_get64(int128_sub(mr
->size
,
2476 int128_one())) : 0),
2477 mr
->enabled
? "" : " [disabled]");
2480 TARGET_FMT_plx
"-" TARGET_FMT_plx
" (prio %d, %c%c): %s%s\n",
2483 + (int128_nz(mr
->size
) ?
2484 (hwaddr
)int128_get64(int128_sub(mr
->size
,
2485 int128_one())) : 0),
2487 mr
->romd_mode
? 'R' : '-',
2488 !mr
->readonly
&& !(mr
->rom_device
&& mr
->romd_mode
) ? 'W'
2490 memory_region_name(mr
),
2491 mr
->enabled
? "" : " [disabled]");
2494 QTAILQ_INIT(&submr_print_queue
);
2496 QTAILQ_FOREACH(submr
, &mr
->subregions
, subregions_link
) {
2497 new_ml
= g_new(MemoryRegionList
, 1);
2499 QTAILQ_FOREACH(ml
, &submr_print_queue
, queue
) {
2500 if (new_ml
->mr
->addr
< ml
->mr
->addr
||
2501 (new_ml
->mr
->addr
== ml
->mr
->addr
&&
2502 new_ml
->mr
->priority
> ml
->mr
->priority
)) {
2503 QTAILQ_INSERT_BEFORE(ml
, new_ml
, queue
);
2509 QTAILQ_INSERT_TAIL(&submr_print_queue
, new_ml
, queue
);
2513 QTAILQ_FOREACH(ml
, &submr_print_queue
, queue
) {
2514 mtree_print_mr(mon_printf
, f
, ml
->mr
, level
+ 1, base
+ mr
->addr
,
2518 QTAILQ_FOREACH_SAFE(ml
, &submr_print_queue
, queue
, next_ml
) {
2523 void mtree_info(fprintf_function mon_printf
, void *f
)
2525 MemoryRegionListHead ml_head
;
2526 MemoryRegionList
*ml
, *ml2
;
2529 QTAILQ_INIT(&ml_head
);
2531 QTAILQ_FOREACH(as
, &address_spaces
, address_spaces_link
) {
2532 mon_printf(f
, "address-space: %s\n", as
->name
);
2533 mtree_print_mr(mon_printf
, f
, as
->root
, 1, 0, &ml_head
);
2534 mon_printf(f
, "\n");
2537 /* print aliased regions */
2538 QTAILQ_FOREACH(ml
, &ml_head
, queue
) {
2539 mon_printf(f
, "memory-region: %s\n", memory_region_name(ml
->mr
));
2540 mtree_print_mr(mon_printf
, f
, ml
->mr
, 1, 0, &ml_head
);
2541 mon_printf(f
, "\n");
2544 QTAILQ_FOREACH_SAFE(ml
, &ml_head
, queue
, ml2
) {
2549 static const TypeInfo memory_region_info
= {
2550 .parent
= TYPE_OBJECT
,
2551 .name
= TYPE_MEMORY_REGION
,
2552 .instance_size
= sizeof(MemoryRegion
),
2553 .instance_init
= memory_region_initfn
,
2554 .instance_finalize
= memory_region_finalize
,
2557 static void memory_register_types(void)
2559 type_register_static(&memory_region_info
);
2562 type_init(memory_register_types
)