]> git.proxmox.com Git - mirror_qemu.git/blame - memory.h
Rename target_phys_addr_t to hwaddr
[mirror_qemu.git] / memory.h
CommitLineData
093bc2cd
AK
1/*
2 * Physical memory management API
3 *
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
5 *
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14#ifndef MEMORY_H
15#define MEMORY_H
16
17#ifndef CONFIG_USER_ONLY
18
19#include <stdint.h>
20#include <stdbool.h>
21#include "qemu-common.h"
22#include "cpu-common.h"
a8170e5e 23#include "hwaddr.h"
093bc2cd 24#include "qemu-queue.h"
658b2224 25#include "iorange.h"
627a0e90 26#include "ioport.h"
08dafab4 27#include "int128.h"
093bc2cd
AK
28
29typedef struct MemoryRegionOps MemoryRegionOps;
30typedef struct MemoryRegion MemoryRegion;
627a0e90 31typedef struct MemoryRegionPortio MemoryRegionPortio;
74901c3b 32typedef struct MemoryRegionMmio MemoryRegionMmio;
093bc2cd
AK
33
34/* Must match *_DIRTY_FLAGS in cpu-all.h. To be replaced with dynamic
35 * registration.
36 */
37#define DIRTY_MEMORY_VGA 0
38#define DIRTY_MEMORY_CODE 1
39#define DIRTY_MEMORY_MIGRATION 3
40
74901c3b
AK
41struct MemoryRegionMmio {
42 CPUReadMemoryFunc *read[3];
43 CPUWriteMemoryFunc *write[3];
44};
45
a2d33521
AK
46/* Internal use; thunks between old-style IORange and MemoryRegions. */
47typedef struct MemoryRegionIORange MemoryRegionIORange;
48struct MemoryRegionIORange {
49 IORange iorange;
50 MemoryRegion *mr;
a8170e5e 51 hwaddr offset;
a2d33521
AK
52};
53
093bc2cd
AK
54/*
55 * Memory region callbacks
56 */
57struct MemoryRegionOps {
58 /* Read from the memory region. @addr is relative to @mr; @size is
59 * in bytes. */
60 uint64_t (*read)(void *opaque,
a8170e5e 61 hwaddr addr,
093bc2cd
AK
62 unsigned size);
63 /* Write to the memory region. @addr is relative to @mr; @size is
64 * in bytes. */
65 void (*write)(void *opaque,
a8170e5e 66 hwaddr addr,
093bc2cd
AK
67 uint64_t data,
68 unsigned size);
69
70 enum device_endian endianness;
71 /* Guest-visible constraints: */
72 struct {
73 /* If nonzero, specify bounds on access sizes beyond which a machine
74 * check is thrown.
75 */
76 unsigned min_access_size;
77 unsigned max_access_size;
78 /* If true, unaligned accesses are supported. Otherwise unaligned
79 * accesses throw machine checks.
80 */
81 bool unaligned;
897fa7cf
AK
82 /*
83 * If present, and returns #false, the transaction is not accepted
84 * by the device (and results in machine dependent behaviour such
85 * as a machine check exception).
86 */
a8170e5e 87 bool (*accepts)(void *opaque, hwaddr addr,
897fa7cf 88 unsigned size, bool is_write);
093bc2cd
AK
89 } valid;
90 /* Internal implementation constraints: */
91 struct {
92 /* If nonzero, specifies the minimum size implemented. Smaller sizes
93 * will be rounded upwards and a partial result will be returned.
94 */
95 unsigned min_access_size;
96 /* If nonzero, specifies the maximum size implemented. Larger sizes
97 * will be done as a series of accesses with smaller sizes.
98 */
99 unsigned max_access_size;
100 /* If true, unaligned accesses are supported. Otherwise all accesses
101 * are converted to (possibly multiple) naturally aligned accesses.
102 */
103 bool unaligned;
104 } impl;
627a0e90
AK
105
106 /* If .read and .write are not present, old_portio may be used for
107 * backwards compatibility with old portio registration
108 */
109 const MemoryRegionPortio *old_portio;
74901c3b
AK
110 /* If .read and .write are not present, old_mmio may be used for
111 * backwards compatibility with old mmio registration
112 */
113 const MemoryRegionMmio old_mmio;
093bc2cd
AK
114};
115
116typedef struct CoalescedMemoryRange CoalescedMemoryRange;
3e9d69e7 117typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
093bc2cd
AK
118
119struct MemoryRegion {
120 /* All fields are private - violators will be prosecuted */
121 const MemoryRegionOps *ops;
122 void *opaque;
123 MemoryRegion *parent;
08dafab4 124 Int128 size;
a8170e5e 125 hwaddr addr;
545e92e0 126 void (*destructor)(MemoryRegion *mr);
093bc2cd 127 ram_addr_t ram_addr;
b3b00c78 128 bool subpage;
14a3c10a 129 bool terminates;
d0a9b5bc 130 bool readable;
8ea9252a 131 bool ram;
fb1cd6f9 132 bool readonly; /* For RAM regions */
6bba19ba 133 bool enabled;
75c578dc 134 bool rom_device;
1660e72d 135 bool warning_printed; /* For reservations */
d410515e 136 bool flush_coalesced_mmio;
093bc2cd 137 MemoryRegion *alias;
a8170e5e 138 hwaddr alias_offset;
093bc2cd
AK
139 unsigned priority;
140 bool may_overlap;
141 QTAILQ_HEAD(subregions, MemoryRegion) subregions;
142 QTAILQ_ENTRY(MemoryRegion) subregions_link;
143 QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
144 const char *name;
5a583347 145 uint8_t dirty_log_mask;
3e9d69e7
AK
146 unsigned ioeventfd_nb;
147 MemoryRegionIoeventfd *ioeventfds;
093bc2cd
AK
148};
149
627a0e90
AK
150struct MemoryRegionPortio {
151 uint32_t offset;
152 uint32_t len;
153 unsigned size;
154 IOPortReadFunc *read;
155 IOPortWriteFunc *write;
156};
157
2dd30228 158#define PORTIO_END_OF_LIST() { }
627a0e90 159
9ad2bbc1
AK
160typedef struct AddressSpace AddressSpace;
161
162/**
163 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
164 */
165struct AddressSpace {
166 /* All fields are private. */
0d673e36 167 const char *name;
9ad2bbc1
AK
168 MemoryRegion *root;
169 struct FlatView *current_map;
170 int ioeventfd_nb;
171 struct MemoryRegionIoeventfd *ioeventfds;
ac1970fb 172 struct AddressSpaceDispatch *dispatch;
0d673e36 173 QTAILQ_ENTRY(AddressSpace) address_spaces_link;
9ad2bbc1
AK
174};
175
e2177955
AK
176typedef struct MemoryRegionSection MemoryRegionSection;
177
178/**
179 * MemoryRegionSection: describes a fragment of a #MemoryRegion
180 *
181 * @mr: the region, or %NULL if empty
7664e80c 182 * @address_space: the address space the region is mapped in
e2177955
AK
183 * @offset_within_region: the beginning of the section, relative to @mr's start
184 * @size: the size of the section; will not exceed @mr's boundaries
185 * @offset_within_address_space: the address of the first byte of the section
186 * relative to the region's address space
7a8499e8 187 * @readonly: writes to this section are ignored
e2177955
AK
188 */
189struct MemoryRegionSection {
190 MemoryRegion *mr;
f6790af6 191 AddressSpace *address_space;
a8170e5e 192 hwaddr offset_within_region;
e2177955 193 uint64_t size;
a8170e5e 194 hwaddr offset_within_address_space;
7a8499e8 195 bool readonly;
e2177955
AK
196};
197
7664e80c
AK
198typedef struct MemoryListener MemoryListener;
199
200/**
201 * MemoryListener: callbacks structure for updates to the physical memory map
202 *
203 * Allows a component to adjust to changes in the guest-visible memory map.
204 * Use with memory_listener_register() and memory_listener_unregister().
205 */
206struct MemoryListener {
50c1e149
AK
207 void (*begin)(MemoryListener *listener);
208 void (*commit)(MemoryListener *listener);
7664e80c
AK
209 void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
210 void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
50c1e149 211 void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
7664e80c
AK
212 void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
213 void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
214 void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
215 void (*log_global_start)(MemoryListener *listener);
216 void (*log_global_stop)(MemoryListener *listener);
80a1ea37 217 void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
753d5e14 218 bool match_data, uint64_t data, EventNotifier *e);
80a1ea37 219 void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
753d5e14 220 bool match_data, uint64_t data, EventNotifier *e);
95d2994a 221 void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
a8170e5e 222 hwaddr addr, hwaddr len);
95d2994a 223 void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
a8170e5e 224 hwaddr addr, hwaddr len);
72e22d2f
AK
225 /* Lower = earlier (during add), later (during del) */
226 unsigned priority;
f6790af6 227 AddressSpace *address_space_filter;
72e22d2f 228 QTAILQ_ENTRY(MemoryListener) link;
7664e80c
AK
229};
230
093bc2cd
AK
231/**
232 * memory_region_init: Initialize a memory region
233 *
69ddaf66 234 * The region typically acts as a container for other memory regions. Use
093bc2cd
AK
235 * memory_region_add_subregion() to add subregions.
236 *
237 * @mr: the #MemoryRegion to be initialized
238 * @name: used for debugging; not visible to the user or ABI
239 * @size: size of the region; any subregions beyond this size will be clipped
240 */
241void memory_region_init(MemoryRegion *mr,
242 const char *name,
243 uint64_t size);
244/**
245 * memory_region_init_io: Initialize an I/O memory region.
246 *
69ddaf66 247 * Accesses into the region will cause the callbacks in @ops to be called.
093bc2cd
AK
248 * if @size is nonzero, subregions will be clipped to @size.
249 *
250 * @mr: the #MemoryRegion to be initialized.
251 * @ops: a structure containing read and write callbacks to be used when
252 * I/O is performed on the region.
253 * @opaque: passed to to the read and write callbacks of the @ops structure.
254 * @name: used for debugging; not visible to the user or ABI
255 * @size: size of the region.
256 */
257void memory_region_init_io(MemoryRegion *mr,
258 const MemoryRegionOps *ops,
259 void *opaque,
260 const char *name,
261 uint64_t size);
262
263/**
264 * memory_region_init_ram: Initialize RAM memory region. Accesses into the
69ddaf66 265 * region will modify memory directly.
093bc2cd
AK
266 *
267 * @mr: the #MemoryRegion to be initialized.
c5705a77 268 * @name: the name of the region.
093bc2cd
AK
269 * @size: size of the region.
270 */
271void memory_region_init_ram(MemoryRegion *mr,
093bc2cd
AK
272 const char *name,
273 uint64_t size);
274
275/**
1a7e8cae
BZ
276 * memory_region_init_ram_ptr: Initialize RAM memory region from a
277 * user-provided pointer. Accesses into the
278 * region will modify memory directly.
093bc2cd
AK
279 *
280 * @mr: the #MemoryRegion to be initialized.
c5705a77 281 * @name: the name of the region.
093bc2cd
AK
282 * @size: size of the region.
283 * @ptr: memory to be mapped; must contain at least @size bytes.
284 */
285void memory_region_init_ram_ptr(MemoryRegion *mr,
093bc2cd
AK
286 const char *name,
287 uint64_t size,
288 void *ptr);
289
290/**
291 * memory_region_init_alias: Initialize a memory region that aliases all or a
292 * part of another memory region.
293 *
294 * @mr: the #MemoryRegion to be initialized.
295 * @name: used for debugging; not visible to the user or ABI
296 * @orig: the region to be referenced; @mr will be equivalent to
297 * @orig between @offset and @offset + @size - 1.
298 * @offset: start of the section in @orig to be referenced.
299 * @size: size of the region.
300 */
301void memory_region_init_alias(MemoryRegion *mr,
302 const char *name,
303 MemoryRegion *orig,
a8170e5e 304 hwaddr offset,
093bc2cd 305 uint64_t size);
d0a9b5bc
AK
306
307/**
308 * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
309 * handled via callbacks.
310 *
311 * @mr: the #MemoryRegion to be initialized.
312 * @ops: callbacks for write access handling.
c5705a77 313 * @name: the name of the region.
d0a9b5bc
AK
314 * @size: size of the region.
315 */
316void memory_region_init_rom_device(MemoryRegion *mr,
317 const MemoryRegionOps *ops,
75f5941c 318 void *opaque,
d0a9b5bc
AK
319 const char *name,
320 uint64_t size);
321
1660e72d
JK
322/**
323 * memory_region_init_reservation: Initialize a memory region that reserves
324 * I/O space.
325 *
326 * A reservation region primariy serves debugging purposes. It claims I/O
327 * space that is not supposed to be handled by QEMU itself. Any access via
328 * the memory API will cause an abort().
329 *
330 * @mr: the #MemoryRegion to be initialized
331 * @name: used for debugging; not visible to the user or ABI
332 * @size: size of the region.
333 */
334void memory_region_init_reservation(MemoryRegion *mr,
335 const char *name,
336 uint64_t size);
093bc2cd 337/**
69ddaf66 338 * memory_region_destroy: Destroy a memory region and reclaim all resources.
093bc2cd
AK
339 *
340 * @mr: the region to be destroyed. May not currently be a subregion
341 * (see memory_region_add_subregion()) or referenced in an alias
342 * (see memory_region_init_alias()).
343 */
344void memory_region_destroy(MemoryRegion *mr);
345
346/**
347 * memory_region_size: get a memory region's size.
348 *
349 * @mr: the memory region being queried.
350 */
351uint64_t memory_region_size(MemoryRegion *mr);
352
8ea9252a
AK
353/**
354 * memory_region_is_ram: check whether a memory region is random access
355 *
356 * Returns %true is a memory region is random access.
357 *
358 * @mr: the memory region being queried
359 */
360bool memory_region_is_ram(MemoryRegion *mr);
361
fd062573
BS
362/**
363 * memory_region_is_romd: check whether a memory region is ROMD
364 *
365 * Returns %true is a memory region is ROMD and currently set to allow
366 * direct reads.
367 *
368 * @mr: the memory region being queried
369 */
370static inline bool memory_region_is_romd(MemoryRegion *mr)
371{
372 return mr->rom_device && mr->readable;
373}
374
8991c79b
AK
375/**
376 * memory_region_name: get a memory region's name
377 *
378 * Returns the string that was used to initialize the memory region.
379 *
380 * @mr: the memory region being queried
381 */
382const char *memory_region_name(MemoryRegion *mr);
383
55043ba3
AK
384/**
385 * memory_region_is_logging: return whether a memory region is logging writes
386 *
387 * Returns %true if the memory region is logging writes
388 *
389 * @mr: the memory region being queried
390 */
391bool memory_region_is_logging(MemoryRegion *mr);
392
ce7923da
AK
393/**
394 * memory_region_is_rom: check whether a memory region is ROM
395 *
396 * Returns %true is a memory region is read-only memory.
397 *
398 * @mr: the memory region being queried
399 */
400bool memory_region_is_rom(MemoryRegion *mr);
401
093bc2cd
AK
402/**
403 * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
404 *
405 * Returns a host pointer to a RAM memory region (created with
406 * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
407 * care.
408 *
409 * @mr: the memory region being queried.
410 */
411void *memory_region_get_ram_ptr(MemoryRegion *mr);
412
093bc2cd
AK
413/**
414 * memory_region_set_log: Turn dirty logging on or off for a region.
415 *
416 * Turns dirty logging on or off for a specified client (display, migration).
417 * Only meaningful for RAM regions.
418 *
419 * @mr: the memory region being updated.
420 * @log: whether dirty logging is to be enabled or disabled.
421 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
422 * %DIRTY_MEMORY_VGA.
423 */
424void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);
425
426/**
cd7a45c9
BS
427 * memory_region_get_dirty: Check whether a range of bytes is dirty
428 * for a specified client.
093bc2cd 429 *
cd7a45c9 430 * Checks whether a range of bytes has been written to since the last
093bc2cd
AK
431 * call to memory_region_reset_dirty() with the same @client. Dirty logging
432 * must be enabled.
433 *
434 * @mr: the memory region being queried.
435 * @addr: the address (relative to the start of the region) being queried.
cd7a45c9 436 * @size: the size of the range being queried.
093bc2cd
AK
437 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
438 * %DIRTY_MEMORY_VGA.
439 */
a8170e5e
AK
440bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
441 hwaddr size, unsigned client);
093bc2cd
AK
442
443/**
fd4aa979 444 * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
093bc2cd 445 *
fd4aa979
BS
446 * Marks a range of bytes as dirty, after it has been dirtied outside
447 * guest code.
093bc2cd 448 *
fd4aa979 449 * @mr: the memory region being dirtied.
093bc2cd 450 * @addr: the address (relative to the start of the region) being dirtied.
fd4aa979 451 * @size: size of the range being dirtied.
093bc2cd 452 */
a8170e5e
AK
453void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
454 hwaddr size);
093bc2cd
AK
455
456/**
457 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
458 * any external TLBs (e.g. kvm)
459 *
460 * Flushes dirty information from accelerators such as kvm and vhost-net
461 * and makes it available to users of the memory API.
462 *
463 * @mr: the region being flushed.
464 */
465void memory_region_sync_dirty_bitmap(MemoryRegion *mr);
466
467/**
468 * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
469 * client.
470 *
471 * Marks a range of pages as no longer dirty.
472 *
473 * @mr: the region being updated.
474 * @addr: the start of the subrange being cleaned.
475 * @size: the size of the subrange being cleaned.
476 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
477 * %DIRTY_MEMORY_VGA.
478 */
a8170e5e
AK
479void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
480 hwaddr size, unsigned client);
093bc2cd
AK
481
482/**
483 * memory_region_set_readonly: Turn a memory region read-only (or read-write)
484 *
485 * Allows a memory region to be marked as read-only (turning it into a ROM).
486 * only useful on RAM regions.
487 *
488 * @mr: the region being updated.
489 * @readonly: whether rhe region is to be ROM or RAM.
490 */
491void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
492
d0a9b5bc
AK
493/**
494 * memory_region_rom_device_set_readable: enable/disable ROM readability
495 *
496 * Allows a ROM device (initialized with memory_region_init_rom_device() to
497 * to be marked as readable (default) or not readable. When it is readable,
498 * the device is mapped to guest memory. When not readable, reads are
499 * forwarded to the #MemoryRegion.read function.
500 *
501 * @mr: the memory region to be updated
502 * @readable: whether reads are satisified directly (%true) or via callbacks
503 * (%false)
504 */
505void memory_region_rom_device_set_readable(MemoryRegion *mr, bool readable);
506
093bc2cd
AK
507/**
508 * memory_region_set_coalescing: Enable memory coalescing for the region.
509 *
510 * Enabled writes to a region to be queued for later processing. MMIO ->write
511 * callbacks may be delayed until a non-coalesced MMIO is issued.
512 * Only useful for IO regions. Roughly similar to write-combining hardware.
513 *
514 * @mr: the memory region to be write coalesced
515 */
516void memory_region_set_coalescing(MemoryRegion *mr);
517
518/**
519 * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
520 * a region.
521 *
522 * Like memory_region_set_coalescing(), but works on a sub-range of a region.
523 * Multiple calls can be issued coalesced disjoint ranges.
524 *
525 * @mr: the memory region to be updated.
526 * @offset: the start of the range within the region to be coalesced.
527 * @size: the size of the subrange to be coalesced.
528 */
529void memory_region_add_coalescing(MemoryRegion *mr,
a8170e5e 530 hwaddr offset,
093bc2cd
AK
531 uint64_t size);
532
533/**
534 * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
535 *
536 * Disables any coalescing caused by memory_region_set_coalescing() or
537 * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
538 * hardware.
539 *
540 * @mr: the memory region to be updated.
541 */
542void memory_region_clear_coalescing(MemoryRegion *mr);
543
d410515e
JK
544/**
545 * memory_region_set_flush_coalesced: Enforce memory coalescing flush before
546 * accesses.
547 *
548 * Ensure that pending coalesced MMIO request are flushed before the memory
549 * region is accessed. This property is automatically enabled for all regions
550 * passed to memory_region_set_coalescing() and memory_region_add_coalescing().
551 *
552 * @mr: the memory region to be updated.
553 */
554void memory_region_set_flush_coalesced(MemoryRegion *mr);
555
556/**
557 * memory_region_clear_flush_coalesced: Disable memory coalescing flush before
558 * accesses.
559 *
560 * Clear the automatic coalesced MMIO flushing enabled via
561 * memory_region_set_flush_coalesced. Note that this service has no effect on
562 * memory regions that have MMIO coalescing enabled for themselves. For them,
563 * automatic flushing will stop once coalescing is disabled.
564 *
565 * @mr: the memory region to be updated.
566 */
567void memory_region_clear_flush_coalesced(MemoryRegion *mr);
568
3e9d69e7
AK
569/**
570 * memory_region_add_eventfd: Request an eventfd to be triggered when a word
571 * is written to a location.
572 *
573 * Marks a word in an IO region (initialized with memory_region_init_io())
574 * as a trigger for an eventfd event. The I/O callback will not be called.
69ddaf66 575 * The caller must be prepared to handle failure (that is, take the required
3e9d69e7
AK
576 * action if the callback _is_ called).
577 *
578 * @mr: the memory region being updated.
579 * @addr: the address within @mr that is to be monitored
580 * @size: the size of the access to trigger the eventfd
581 * @match_data: whether to match against @data, instead of just @addr
582 * @data: the data to match against the guest write
583 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
584 **/
585void memory_region_add_eventfd(MemoryRegion *mr,
a8170e5e 586 hwaddr addr,
3e9d69e7
AK
587 unsigned size,
588 bool match_data,
589 uint64_t data,
753d5e14 590 EventNotifier *e);
3e9d69e7
AK
591
592/**
69ddaf66 593 * memory_region_del_eventfd: Cancel an eventfd.
3e9d69e7 594 *
69ddaf66
ASRJ
595 * Cancels an eventfd trigger requested by a previous
596 * memory_region_add_eventfd() call.
3e9d69e7
AK
597 *
598 * @mr: the memory region being updated.
599 * @addr: the address within @mr that is to be monitored
600 * @size: the size of the access to trigger the eventfd
601 * @match_data: whether to match against @data, instead of just @addr
602 * @data: the data to match against the guest write
603 * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
604 */
605void memory_region_del_eventfd(MemoryRegion *mr,
a8170e5e 606 hwaddr addr,
3e9d69e7
AK
607 unsigned size,
608 bool match_data,
609 uint64_t data,
753d5e14
PB
610 EventNotifier *e);
611
093bc2cd 612/**
69ddaf66 613 * memory_region_add_subregion: Add a subregion to a container.
093bc2cd 614 *
69ddaf66 615 * Adds a subregion at @offset. The subregion may not overlap with other
093bc2cd
AK
616 * subregions (except for those explicitly marked as overlapping). A region
617 * may only be added once as a subregion (unless removed with
618 * memory_region_del_subregion()); use memory_region_init_alias() if you
619 * want a region to be a subregion in multiple locations.
620 *
621 * @mr: the region to contain the new subregion; must be a container
622 * initialized with memory_region_init().
623 * @offset: the offset relative to @mr where @subregion is added.
624 * @subregion: the subregion to be added.
625 */
626void memory_region_add_subregion(MemoryRegion *mr,
a8170e5e 627 hwaddr offset,
093bc2cd
AK
628 MemoryRegion *subregion);
629/**
1a7e8cae
BZ
630 * memory_region_add_subregion_overlap: Add a subregion to a container
631 * with overlap.
093bc2cd 632 *
69ddaf66 633 * Adds a subregion at @offset. The subregion may overlap with other
093bc2cd
AK
634 * subregions. Conflicts are resolved by having a higher @priority hide a
635 * lower @priority. Subregions without priority are taken as @priority 0.
636 * A region may only be added once as a subregion (unless removed with
637 * memory_region_del_subregion()); use memory_region_init_alias() if you
638 * want a region to be a subregion in multiple locations.
639 *
640 * @mr: the region to contain the new subregion; must be a container
641 * initialized with memory_region_init().
642 * @offset: the offset relative to @mr where @subregion is added.
643 * @subregion: the subregion to be added.
644 * @priority: used for resolving overlaps; highest priority wins.
645 */
646void memory_region_add_subregion_overlap(MemoryRegion *mr,
a8170e5e 647 hwaddr offset,
093bc2cd
AK
648 MemoryRegion *subregion,
649 unsigned priority);
e34911c4
AK
650
651/**
652 * memory_region_get_ram_addr: Get the ram address associated with a memory
653 * region
654 *
dabdf394 655 * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
e34911c4
AK
656 * code is being reworked.
657 */
658ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr);
659
093bc2cd
AK
660/**
661 * memory_region_del_subregion: Remove a subregion.
662 *
663 * Removes a subregion from its container.
664 *
665 * @mr: the container to be updated.
666 * @subregion: the region being removed; must be a current subregion of @mr.
667 */
668void memory_region_del_subregion(MemoryRegion *mr,
669 MemoryRegion *subregion);
670
6bba19ba
AK
671/*
672 * memory_region_set_enabled: dynamically enable or disable a region
673 *
674 * Enables or disables a memory region. A disabled memory region
675 * ignores all accesses to itself and its subregions. It does not
676 * obscure sibling subregions with lower priority - it simply behaves as
677 * if it was removed from the hierarchy.
678 *
679 * Regions default to being enabled.
680 *
681 * @mr: the region to be updated
682 * @enabled: whether to enable or disable the region
683 */
684void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
685
2282e1af
AK
686/*
687 * memory_region_set_address: dynamically update the address of a region
688 *
689 * Dynamically updates the address of a region, relative to its parent.
690 * May be used on regions are currently part of a memory hierarchy.
691 *
692 * @mr: the region to be updated
693 * @addr: new address, relative to parent region
694 */
a8170e5e 695void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
2282e1af 696
4703359e
AK
697/*
698 * memory_region_set_alias_offset: dynamically update a memory alias's offset
699 *
700 * Dynamically updates the offset into the target region that an alias points
701 * to, as if the fourth argument to memory_region_init_alias() has changed.
702 *
703 * @mr: the #MemoryRegion to be updated; should be an alias.
704 * @offset: the new offset into the target memory region
705 */
706void memory_region_set_alias_offset(MemoryRegion *mr,
a8170e5e 707 hwaddr offset);
4703359e 708
e2177955
AK
709/**
710 * memory_region_find: locate a MemoryRegion in an address space
711 *
712 * Locates the first #MemoryRegion within an address space given by
713 * @address_space that overlaps the range given by @addr and @size.
714 *
715 * Returns a #MemoryRegionSection that describes a contiguous overlap.
716 * It will have the following characteristics:
717 * .@offset_within_address_space >= @addr
718 * .@offset_within_address_space + .@size <= @addr + @size
719 * .@size = 0 iff no overlap was found
720 * .@mr is non-%NULL iff an overlap was found
721 *
722 * @address_space: a top-level (i.e. parentless) region that contains
723 * the region to be found
724 * @addr: start of the area within @address_space to be searched
725 * @size: size of the area to be searched
726 */
727MemoryRegionSection memory_region_find(MemoryRegion *address_space,
a8170e5e 728 hwaddr addr, uint64_t size);
e2177955 729
fd062573
BS
730/**
731 * memory_region_section_addr: get offset within MemoryRegionSection
732 *
733 * Returns offset within MemoryRegionSection
734 *
735 * @section: the memory region section being queried
736 * @addr: address in address space
737 */
a8170e5e 738static inline hwaddr
fd062573 739memory_region_section_addr(MemoryRegionSection *section,
a8170e5e 740 hwaddr addr)
fd062573
BS
741{
742 addr -= section->offset_within_address_space;
743 addr += section->offset_within_region;
744 return addr;
745}
86e775c6
AK
746
747/**
748 * memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory
749 *
750 * Synchronizes the dirty page log for an entire address space.
751 * @address_space: a top-level (i.e. parentless) region that contains the
752 * memory being synchronized
753 */
754void memory_global_sync_dirty_bitmap(MemoryRegion *address_space);
755
69ddaf66
ASRJ
756/**
757 * memory_region_transaction_begin: Start a transaction.
758 *
759 * During a transaction, changes will be accumulated and made visible
dabdf394 760 * only when the transaction ends (is committed).
4ef4db86
AK
761 */
762void memory_region_transaction_begin(void);
69ddaf66
ASRJ
763
764/**
765 * memory_region_transaction_commit: Commit a transaction and make changes
766 * visible to the guest.
4ef4db86
AK
767 */
768void memory_region_transaction_commit(void);
769
7664e80c
AK
770/**
771 * memory_listener_register: register callbacks to be called when memory
772 * sections are mapped or unmapped into an address
773 * space
774 *
775 * @listener: an object containing the callbacks to be called
7376e582 776 * @filter: if non-%NULL, only regions in this address space will be observed
7664e80c 777 */
f6790af6 778void memory_listener_register(MemoryListener *listener, AddressSpace *filter);
7664e80c
AK
779
780/**
781 * memory_listener_unregister: undo the effect of memory_listener_register()
782 *
783 * @listener: an object containing the callbacks to be removed
784 */
785void memory_listener_unregister(MemoryListener *listener);
786
787/**
788 * memory_global_dirty_log_start: begin dirty logging for all regions
789 */
790void memory_global_dirty_log_start(void);
791
792/**
1a7e8cae 793 * memory_global_dirty_log_stop: end dirty logging for all regions
7664e80c
AK
794 */
795void memory_global_dirty_log_stop(void);
796
314e2987
BS
797void mtree_info(fprintf_function mon_printf, void *f);
798
9ad2bbc1
AK
799/**
800 * address_space_init: initializes an address space
801 *
802 * @as: an uninitialized #AddressSpace
803 * @root: a #MemoryRegion that routes addesses for the address space
804 */
805void address_space_init(AddressSpace *as, MemoryRegion *root);
806
83f3c251
AK
807
808/**
809 * address_space_destroy: destroy an address space
810 *
811 * Releases all resources associated with an address space. After an address space
812 * is destroyed, its root memory region (given by address_space_init()) may be destroyed
813 * as well.
814 *
815 * @as: address space to be destroyed
816 */
817void address_space_destroy(AddressSpace *as);
818
ac1970fb
AK
819/**
820 * address_space_rw: read from or write to an address space.
821 *
822 * @as: #AddressSpace to be accessed
823 * @addr: address within that address space
824 * @buf: buffer with the data transferred
825 * @is_write: indicates the transfer direction
826 */
a8170e5e 827void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
ac1970fb
AK
828 int len, bool is_write);
829
830/**
831 * address_space_write: write to address space.
832 *
833 * @as: #AddressSpace to be accessed
834 * @addr: address within that address space
835 * @buf: buffer with the data transferred
836 */
a8170e5e 837void address_space_write(AddressSpace *as, hwaddr addr,
ac1970fb
AK
838 const uint8_t *buf, int len);
839
840/**
841 * address_space_read: read from an address space.
842 *
843 * @as: #AddressSpace to be accessed
844 * @addr: address within that address space
845 * @buf: buffer with the data transferred
846 */
a8170e5e 847void address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
ac1970fb
AK
848
849/* address_space_map: map a physical memory region into a host virtual address
850 *
851 * May map a subset of the requested range, given by and returned in @plen.
852 * May return %NULL if resources needed to perform the mapping are exhausted.
853 * Use only for reads OR writes - not for read-modify-write operations.
854 * Use cpu_register_map_client() to know when retrying the map operation is
855 * likely to succeed.
856 *
857 * @as: #AddressSpace to be accessed
858 * @addr: address within that address space
859 * @plen: pointer to length of buffer; updated on return
860 * @is_write: indicates the transfer direction
861 */
a8170e5e
AK
862void *address_space_map(AddressSpace *as, hwaddr addr,
863 hwaddr *plen, bool is_write);
ac1970fb
AK
864
865/* address_space_unmap: Unmaps a memory region previously mapped by address_space_map()
866 *
867 * Will also mark the memory as dirty if @is_write == %true. @access_len gives
868 * the amount of memory that was actually read or written by the caller.
869 *
870 * @as: #AddressSpace used
871 * @addr: address within that address space
872 * @len: buffer length as returned by address_space_map()
873 * @access_len: amount of data actually transferred
874 * @is_write: indicates the transfer direction
875 */
a8170e5e
AK
876void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
877 int is_write, hwaddr access_len);
ac1970fb
AK
878
879
093bc2cd
AK
880#endif
881
882#endif