2
0

memory.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. #ifndef MEMORY_H
  14. #define MEMORY_H
  15. #ifndef CONFIG_USER_ONLY
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "qemu-common.h"
  19. #include "cpu-common.h"
  20. #include "targphys.h"
  21. #include "qemu-queue.h"
  22. #include "iorange.h"
  23. #include "ioport.h"
  24. #include "int128.h"
  25. typedef struct MemoryRegionOps MemoryRegionOps;
  26. typedef struct MemoryRegion MemoryRegion;
  27. typedef struct MemoryRegionPortio MemoryRegionPortio;
  28. typedef struct MemoryRegionMmio MemoryRegionMmio;
  29. /* Must match *_DIRTY_FLAGS in cpu-all.h. To be replaced with dynamic
  30. * registration.
  31. */
  32. #define DIRTY_MEMORY_VGA 0
  33. #define DIRTY_MEMORY_CODE 1
  34. #define DIRTY_MEMORY_MIGRATION 3
  35. struct MemoryRegionMmio {
  36. CPUReadMemoryFunc *read[3];
  37. CPUWriteMemoryFunc *write[3];
  38. };
  39. /* Internal use; thunks between old-style IORange and MemoryRegions. */
  40. typedef struct MemoryRegionIORange MemoryRegionIORange;
  41. struct MemoryRegionIORange {
  42. IORange iorange;
  43. MemoryRegion *mr;
  44. target_phys_addr_t offset;
  45. };
  46. /*
  47. * Memory region callbacks
  48. */
  49. struct MemoryRegionOps {
  50. /* Read from the memory region. @addr is relative to @mr; @size is
  51. * in bytes. */
  52. uint64_t (*read)(void *opaque,
  53. target_phys_addr_t addr,
  54. unsigned size);
  55. /* Write to the memory region. @addr is relative to @mr; @size is
  56. * in bytes. */
  57. void (*write)(void *opaque,
  58. target_phys_addr_t addr,
  59. uint64_t data,
  60. unsigned size);
  61. enum device_endian endianness;
  62. /* Guest-visible constraints: */
  63. struct {
  64. /* If nonzero, specify bounds on access sizes beyond which a machine
  65. * check is thrown.
  66. */
  67. unsigned min_access_size;
  68. unsigned max_access_size;
  69. /* If true, unaligned accesses are supported. Otherwise unaligned
  70. * accesses throw machine checks.
  71. */
  72. bool unaligned;
  73. /*
  74. * If present, and returns #false, the transaction is not accepted
  75. * by the device (and results in machine dependent behaviour such
  76. * as a machine check exception).
  77. */
  78. bool (*accepts)(void *opaque, target_phys_addr_t addr,
  79. unsigned size, bool is_write);
  80. } valid;
  81. /* Internal implementation constraints: */
  82. struct {
  83. /* If nonzero, specifies the minimum size implemented. Smaller sizes
  84. * will be rounded upwards and a partial result will be returned.
  85. */
  86. unsigned min_access_size;
  87. /* If nonzero, specifies the maximum size implemented. Larger sizes
  88. * will be done as a series of accesses with smaller sizes.
  89. */
  90. unsigned max_access_size;
  91. /* If true, unaligned accesses are supported. Otherwise all accesses
  92. * are converted to (possibly multiple) naturally aligned accesses.
  93. */
  94. bool unaligned;
  95. } impl;
  96. /* If .read and .write are not present, old_portio may be used for
  97. * backwards compatibility with old portio registration
  98. */
  99. const MemoryRegionPortio *old_portio;
  100. /* If .read and .write are not present, old_mmio may be used for
  101. * backwards compatibility with old mmio registration
  102. */
  103. const MemoryRegionMmio old_mmio;
  104. };
  105. typedef struct CoalescedMemoryRange CoalescedMemoryRange;
  106. typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
  107. struct MemoryRegion {
  108. /* All fields are private - violators will be prosecuted */
  109. const MemoryRegionOps *ops;
  110. void *opaque;
  111. MemoryRegion *parent;
  112. Int128 size;
  113. target_phys_addr_t addr;
  114. void (*destructor)(MemoryRegion *mr);
  115. ram_addr_t ram_addr;
  116. bool subpage;
  117. bool terminates;
  118. bool readable;
  119. bool ram;
  120. bool readonly; /* For RAM regions */
  121. bool enabled;
  122. bool rom_device;
  123. bool warning_printed; /* For reservations */
  124. MemoryRegion *alias;
  125. target_phys_addr_t alias_offset;
  126. unsigned priority;
  127. bool may_overlap;
  128. QTAILQ_HEAD(subregions, MemoryRegion) subregions;
  129. QTAILQ_ENTRY(MemoryRegion) subregions_link;
  130. QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
  131. const char *name;
  132. uint8_t dirty_log_mask;
  133. unsigned ioeventfd_nb;
  134. MemoryRegionIoeventfd *ioeventfds;
  135. };
  136. struct MemoryRegionPortio {
  137. uint32_t offset;
  138. uint32_t len;
  139. unsigned size;
  140. IOPortReadFunc *read;
  141. IOPortWriteFunc *write;
  142. };
  143. #define PORTIO_END_OF_LIST() { }
  144. typedef struct MemoryRegionSection MemoryRegionSection;
  145. /**
  146. * MemoryRegionSection: describes a fragment of a #MemoryRegion
  147. *
  148. * @mr: the region, or %NULL if empty
  149. * @address_space: the address space the region is mapped in
  150. * @offset_within_region: the beginning of the section, relative to @mr's start
  151. * @size: the size of the section; will not exceed @mr's boundaries
  152. * @offset_within_address_space: the address of the first byte of the section
  153. * relative to the region's address space
  154. * @readonly: writes to this section are ignored
  155. */
  156. struct MemoryRegionSection {
  157. MemoryRegion *mr;
  158. MemoryRegion *address_space;
  159. target_phys_addr_t offset_within_region;
  160. uint64_t size;
  161. target_phys_addr_t offset_within_address_space;
  162. bool readonly;
  163. };
  164. typedef struct MemoryListener MemoryListener;
  165. /**
  166. * MemoryListener: callbacks structure for updates to the physical memory map
  167. *
  168. * Allows a component to adjust to changes in the guest-visible memory map.
  169. * Use with memory_listener_register() and memory_listener_unregister().
  170. */
  171. struct MemoryListener {
  172. void (*begin)(MemoryListener *listener);
  173. void (*commit)(MemoryListener *listener);
  174. void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
  175. void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
  176. void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
  177. void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
  178. void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
  179. void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
  180. void (*log_global_start)(MemoryListener *listener);
  181. void (*log_global_stop)(MemoryListener *listener);
  182. void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
  183. bool match_data, uint64_t data, EventNotifier *e);
  184. void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
  185. bool match_data, uint64_t data, EventNotifier *e);
  186. /* Lower = earlier (during add), later (during del) */
  187. unsigned priority;
  188. MemoryRegion *address_space_filter;
  189. QTAILQ_ENTRY(MemoryListener) link;
  190. };
  191. /**
  192. * memory_region_init: Initialize a memory region
  193. *
  194. * The region typically acts as a container for other memory regions. Use
  195. * memory_region_add_subregion() to add subregions.
  196. *
  197. * @mr: the #MemoryRegion to be initialized
  198. * @name: used for debugging; not visible to the user or ABI
  199. * @size: size of the region; any subregions beyond this size will be clipped
  200. */
  201. void memory_region_init(MemoryRegion *mr,
  202. const char *name,
  203. uint64_t size);
  204. /**
  205. * memory_region_init_io: Initialize an I/O memory region.
  206. *
  207. * Accesses into the region will cause the callbacks in @ops to be called.
  208. * if @size is nonzero, subregions will be clipped to @size.
  209. *
  210. * @mr: the #MemoryRegion to be initialized.
  211. * @ops: a structure containing read and write callbacks to be used when
  212. * I/O is performed on the region.
  213. * @opaque: passed to to the read and write callbacks of the @ops structure.
  214. * @name: used for debugging; not visible to the user or ABI
  215. * @size: size of the region.
  216. */
  217. void memory_region_init_io(MemoryRegion *mr,
  218. const MemoryRegionOps *ops,
  219. void *opaque,
  220. const char *name,
  221. uint64_t size);
  222. /**
  223. * memory_region_init_ram: Initialize RAM memory region. Accesses into the
  224. * region will modify memory directly.
  225. *
  226. * @mr: the #MemoryRegion to be initialized.
  227. * @name: the name of the region.
  228. * @size: size of the region.
  229. */
  230. void memory_region_init_ram(MemoryRegion *mr,
  231. const char *name,
  232. uint64_t size);
  233. /**
  234. * memory_region_init_ram: Initialize RAM memory region from a user-provided.
  235. * pointer. Accesses into the region will modify
  236. * memory directly.
  237. *
  238. * @mr: the #MemoryRegion to be initialized.
  239. * @name: the name of the region.
  240. * @size: size of the region.
  241. * @ptr: memory to be mapped; must contain at least @size bytes.
  242. */
  243. void memory_region_init_ram_ptr(MemoryRegion *mr,
  244. const char *name,
  245. uint64_t size,
  246. void *ptr);
  247. /**
  248. * memory_region_init_alias: Initialize a memory region that aliases all or a
  249. * part of another memory region.
  250. *
  251. * @mr: the #MemoryRegion to be initialized.
  252. * @name: used for debugging; not visible to the user or ABI
  253. * @orig: the region to be referenced; @mr will be equivalent to
  254. * @orig between @offset and @offset + @size - 1.
  255. * @offset: start of the section in @orig to be referenced.
  256. * @size: size of the region.
  257. */
  258. void memory_region_init_alias(MemoryRegion *mr,
  259. const char *name,
  260. MemoryRegion *orig,
  261. target_phys_addr_t offset,
  262. uint64_t size);
  263. /**
  264. * memory_region_init_rom_device: Initialize a ROM memory region. Writes are
  265. * handled via callbacks.
  266. *
  267. * @mr: the #MemoryRegion to be initialized.
  268. * @ops: callbacks for write access handling.
  269. * @name: the name of the region.
  270. * @size: size of the region.
  271. */
  272. void memory_region_init_rom_device(MemoryRegion *mr,
  273. const MemoryRegionOps *ops,
  274. void *opaque,
  275. const char *name,
  276. uint64_t size);
  277. /**
  278. * memory_region_init_reservation: Initialize a memory region that reserves
  279. * I/O space.
  280. *
  281. * A reservation region primariy serves debugging purposes. It claims I/O
  282. * space that is not supposed to be handled by QEMU itself. Any access via
  283. * the memory API will cause an abort().
  284. *
  285. * @mr: the #MemoryRegion to be initialized
  286. * @name: used for debugging; not visible to the user or ABI
  287. * @size: size of the region.
  288. */
  289. void memory_region_init_reservation(MemoryRegion *mr,
  290. const char *name,
  291. uint64_t size);
  292. /**
  293. * memory_region_destroy: Destroy a memory region and reclaim all resources.
  294. *
  295. * @mr: the region to be destroyed. May not currently be a subregion
  296. * (see memory_region_add_subregion()) or referenced in an alias
  297. * (see memory_region_init_alias()).
  298. */
  299. void memory_region_destroy(MemoryRegion *mr);
  300. /**
  301. * memory_region_size: get a memory region's size.
  302. *
  303. * @mr: the memory region being queried.
  304. */
  305. uint64_t memory_region_size(MemoryRegion *mr);
  306. /**
  307. * memory_region_is_ram: check whether a memory region is random access
  308. *
  309. * Returns %true is a memory region is random access.
  310. *
  311. * @mr: the memory region being queried
  312. */
  313. bool memory_region_is_ram(MemoryRegion *mr);
  314. /**
  315. * memory_region_is_romd: check whether a memory region is ROMD
  316. *
  317. * Returns %true is a memory region is ROMD and currently set to allow
  318. * direct reads.
  319. *
  320. * @mr: the memory region being queried
  321. */
  322. static inline bool memory_region_is_romd(MemoryRegion *mr)
  323. {
  324. return mr->rom_device && mr->readable;
  325. }
  326. /**
  327. * memory_region_name: get a memory region's name
  328. *
  329. * Returns the string that was used to initialize the memory region.
  330. *
  331. * @mr: the memory region being queried
  332. */
  333. const char *memory_region_name(MemoryRegion *mr);
  334. /**
  335. * memory_region_is_logging: return whether a memory region is logging writes
  336. *
  337. * Returns %true if the memory region is logging writes
  338. *
  339. * @mr: the memory region being queried
  340. */
  341. bool memory_region_is_logging(MemoryRegion *mr);
  342. /**
  343. * memory_region_is_rom: check whether a memory region is ROM
  344. *
  345. * Returns %true is a memory region is read-only memory.
  346. *
  347. * @mr: the memory region being queried
  348. */
  349. bool memory_region_is_rom(MemoryRegion *mr);
  350. /**
  351. * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
  352. *
  353. * Returns a host pointer to a RAM memory region (created with
  354. * memory_region_init_ram() or memory_region_init_ram_ptr()). Use with
  355. * care.
  356. *
  357. * @mr: the memory region being queried.
  358. */
  359. void *memory_region_get_ram_ptr(MemoryRegion *mr);
  360. /**
  361. * memory_region_set_log: Turn dirty logging on or off for a region.
  362. *
  363. * Turns dirty logging on or off for a specified client (display, migration).
  364. * Only meaningful for RAM regions.
  365. *
  366. * @mr: the memory region being updated.
  367. * @log: whether dirty logging is to be enabled or disabled.
  368. * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
  369. * %DIRTY_MEMORY_VGA.
  370. */
  371. void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);
  372. /**
  373. * memory_region_get_dirty: Check whether a range of bytes is dirty
  374. * for a specified client.
  375. *
  376. * Checks whether a range of bytes has been written to since the last
  377. * call to memory_region_reset_dirty() with the same @client. Dirty logging
  378. * must be enabled.
  379. *
  380. * @mr: the memory region being queried.
  381. * @addr: the address (relative to the start of the region) being queried.
  382. * @size: the size of the range being queried.
  383. * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
  384. * %DIRTY_MEMORY_VGA.
  385. */
  386. bool memory_region_get_dirty(MemoryRegion *mr, target_phys_addr_t addr,
  387. target_phys_addr_t size, unsigned client);
  388. /**
  389. * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region.
  390. *
  391. * Marks a range of bytes as dirty, after it has been dirtied outside
  392. * guest code.
  393. *
  394. * @mr: the memory region being dirtied.
  395. * @addr: the address (relative to the start of the region) being dirtied.
  396. * @size: size of the range being dirtied.
  397. */
  398. void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
  399. target_phys_addr_t size);
  400. /**
  401. * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
  402. * any external TLBs (e.g. kvm)
  403. *
  404. * Flushes dirty information from accelerators such as kvm and vhost-net
  405. * and makes it available to users of the memory API.
  406. *
  407. * @mr: the region being flushed.
  408. */
  409. void memory_region_sync_dirty_bitmap(MemoryRegion *mr);
  410. /**
  411. * memory_region_reset_dirty: Mark a range of pages as clean, for a specified
  412. * client.
  413. *
  414. * Marks a range of pages as no longer dirty.
  415. *
  416. * @mr: the region being updated.
  417. * @addr: the start of the subrange being cleaned.
  418. * @size: the size of the subrange being cleaned.
  419. * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
  420. * %DIRTY_MEMORY_VGA.
  421. */
  422. void memory_region_reset_dirty(MemoryRegion *mr, target_phys_addr_t addr,
  423. target_phys_addr_t size, unsigned client);
  424. /**
  425. * memory_region_set_readonly: Turn a memory region read-only (or read-write)
  426. *
  427. * Allows a memory region to be marked as read-only (turning it into a ROM).
  428. * only useful on RAM regions.
  429. *
  430. * @mr: the region being updated.
  431. * @readonly: whether rhe region is to be ROM or RAM.
  432. */
  433. void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
  434. /**
  435. * memory_region_rom_device_set_readable: enable/disable ROM readability
  436. *
  437. * Allows a ROM device (initialized with memory_region_init_rom_device() to
  438. * to be marked as readable (default) or not readable. When it is readable,
  439. * the device is mapped to guest memory. When not readable, reads are
  440. * forwarded to the #MemoryRegion.read function.
  441. *
  442. * @mr: the memory region to be updated
  443. * @readable: whether reads are satisified directly (%true) or via callbacks
  444. * (%false)
  445. */
  446. void memory_region_rom_device_set_readable(MemoryRegion *mr, bool readable);
  447. /**
  448. * memory_region_set_coalescing: Enable memory coalescing for the region.
  449. *
  450. * Enabled writes to a region to be queued for later processing. MMIO ->write
  451. * callbacks may be delayed until a non-coalesced MMIO is issued.
  452. * Only useful for IO regions. Roughly similar to write-combining hardware.
  453. *
  454. * @mr: the memory region to be write coalesced
  455. */
  456. void memory_region_set_coalescing(MemoryRegion *mr);
  457. /**
  458. * memory_region_add_coalescing: Enable memory coalescing for a sub-range of
  459. * a region.
  460. *
  461. * Like memory_region_set_coalescing(), but works on a sub-range of a region.
  462. * Multiple calls can be issued coalesced disjoint ranges.
  463. *
  464. * @mr: the memory region to be updated.
  465. * @offset: the start of the range within the region to be coalesced.
  466. * @size: the size of the subrange to be coalesced.
  467. */
  468. void memory_region_add_coalescing(MemoryRegion *mr,
  469. target_phys_addr_t offset,
  470. uint64_t size);
  471. /**
  472. * memory_region_clear_coalescing: Disable MMIO coalescing for the region.
  473. *
  474. * Disables any coalescing caused by memory_region_set_coalescing() or
  475. * memory_region_add_coalescing(). Roughly equivalent to uncacheble memory
  476. * hardware.
  477. *
  478. * @mr: the memory region to be updated.
  479. */
  480. void memory_region_clear_coalescing(MemoryRegion *mr);
  481. /**
  482. * memory_region_add_eventfd: Request an eventfd to be triggered when a word
  483. * is written to a location.
  484. *
  485. * Marks a word in an IO region (initialized with memory_region_init_io())
  486. * as a trigger for an eventfd event. The I/O callback will not be called.
  487. * The caller must be prepared to handle failure (that is, take the required
  488. * action if the callback _is_ called).
  489. *
  490. * @mr: the memory region being updated.
  491. * @addr: the address within @mr that is to be monitored
  492. * @size: the size of the access to trigger the eventfd
  493. * @match_data: whether to match against @data, instead of just @addr
  494. * @data: the data to match against the guest write
  495. * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
  496. **/
  497. void memory_region_add_eventfd(MemoryRegion *mr,
  498. target_phys_addr_t addr,
  499. unsigned size,
  500. bool match_data,
  501. uint64_t data,
  502. EventNotifier *e);
  503. /**
  504. * memory_region_del_eventfd: Cancel an eventfd.
  505. *
  506. * Cancels an eventfd trigger requested by a previous
  507. * memory_region_add_eventfd() call.
  508. *
  509. * @mr: the memory region being updated.
  510. * @addr: the address within @mr that is to be monitored
  511. * @size: the size of the access to trigger the eventfd
  512. * @match_data: whether to match against @data, instead of just @addr
  513. * @data: the data to match against the guest write
  514. * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
  515. */
  516. void memory_region_del_eventfd(MemoryRegion *mr,
  517. target_phys_addr_t addr,
  518. unsigned size,
  519. bool match_data,
  520. uint64_t data,
  521. EventNotifier *e);
  522. /**
  523. * memory_region_add_subregion: Add a subregion to a container.
  524. *
  525. * Adds a subregion at @offset. The subregion may not overlap with other
  526. * subregions (except for those explicitly marked as overlapping). A region
  527. * may only be added once as a subregion (unless removed with
  528. * memory_region_del_subregion()); use memory_region_init_alias() if you
  529. * want a region to be a subregion in multiple locations.
  530. *
  531. * @mr: the region to contain the new subregion; must be a container
  532. * initialized with memory_region_init().
  533. * @offset: the offset relative to @mr where @subregion is added.
  534. * @subregion: the subregion to be added.
  535. */
  536. void memory_region_add_subregion(MemoryRegion *mr,
  537. target_phys_addr_t offset,
  538. MemoryRegion *subregion);
  539. /**
  540. * memory_region_add_subregion: Add a subregion to a container, with overlap.
  541. *
  542. * Adds a subregion at @offset. The subregion may overlap with other
  543. * subregions. Conflicts are resolved by having a higher @priority hide a
  544. * lower @priority. Subregions without priority are taken as @priority 0.
  545. * A region may only be added once as a subregion (unless removed with
  546. * memory_region_del_subregion()); use memory_region_init_alias() if you
  547. * want a region to be a subregion in multiple locations.
  548. *
  549. * @mr: the region to contain the new subregion; must be a container
  550. * initialized with memory_region_init().
  551. * @offset: the offset relative to @mr where @subregion is added.
  552. * @subregion: the subregion to be added.
  553. * @priority: used for resolving overlaps; highest priority wins.
  554. */
  555. void memory_region_add_subregion_overlap(MemoryRegion *mr,
  556. target_phys_addr_t offset,
  557. MemoryRegion *subregion,
  558. unsigned priority);
  559. /**
  560. * memory_region_get_ram_addr: Get the ram address associated with a memory
  561. * region
  562. *
  563. * DO NOT USE THIS FUNCTION. This is a temporary workaround while the Xen
  564. * code is being reworked.
  565. */
  566. ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr);
  567. /**
  568. * memory_region_del_subregion: Remove a subregion.
  569. *
  570. * Removes a subregion from its container.
  571. *
  572. * @mr: the container to be updated.
  573. * @subregion: the region being removed; must be a current subregion of @mr.
  574. */
  575. void memory_region_del_subregion(MemoryRegion *mr,
  576. MemoryRegion *subregion);
  577. /*
  578. * memory_region_set_enabled: dynamically enable or disable a region
  579. *
  580. * Enables or disables a memory region. A disabled memory region
  581. * ignores all accesses to itself and its subregions. It does not
  582. * obscure sibling subregions with lower priority - it simply behaves as
  583. * if it was removed from the hierarchy.
  584. *
  585. * Regions default to being enabled.
  586. *
  587. * @mr: the region to be updated
  588. * @enabled: whether to enable or disable the region
  589. */
  590. void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
  591. /*
  592. * memory_region_set_address: dynamically update the address of a region
  593. *
  594. * Dynamically updates the address of a region, relative to its parent.
  595. * May be used on regions are currently part of a memory hierarchy.
  596. *
  597. * @mr: the region to be updated
  598. * @addr: new address, relative to parent region
  599. */
  600. void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr);
  601. /*
  602. * memory_region_set_alias_offset: dynamically update a memory alias's offset
  603. *
  604. * Dynamically updates the offset into the target region that an alias points
  605. * to, as if the fourth argument to memory_region_init_alias() has changed.
  606. *
  607. * @mr: the #MemoryRegion to be updated; should be an alias.
  608. * @offset: the new offset into the target memory region
  609. */
  610. void memory_region_set_alias_offset(MemoryRegion *mr,
  611. target_phys_addr_t offset);
  612. /**
  613. * memory_region_find: locate a MemoryRegion in an address space
  614. *
  615. * Locates the first #MemoryRegion within an address space given by
  616. * @address_space that overlaps the range given by @addr and @size.
  617. *
  618. * Returns a #MemoryRegionSection that describes a contiguous overlap.
  619. * It will have the following characteristics:
  620. * .@offset_within_address_space >= @addr
  621. * .@offset_within_address_space + .@size <= @addr + @size
  622. * .@size = 0 iff no overlap was found
  623. * .@mr is non-%NULL iff an overlap was found
  624. *
  625. * @address_space: a top-level (i.e. parentless) region that contains
  626. * the region to be found
  627. * @addr: start of the area within @address_space to be searched
  628. * @size: size of the area to be searched
  629. */
  630. MemoryRegionSection memory_region_find(MemoryRegion *address_space,
  631. target_phys_addr_t addr, uint64_t size);
  632. /**
  633. * memory_region_section_addr: get offset within MemoryRegionSection
  634. *
  635. * Returns offset within MemoryRegionSection
  636. *
  637. * @section: the memory region section being queried
  638. * @addr: address in address space
  639. */
  640. static inline target_phys_addr_t
  641. memory_region_section_addr(MemoryRegionSection *section,
  642. target_phys_addr_t addr)
  643. {
  644. addr -= section->offset_within_address_space;
  645. addr += section->offset_within_region;
  646. return addr;
  647. }
  648. /**
  649. * memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory
  650. *
  651. * Synchronizes the dirty page log for an entire address space.
  652. * @address_space: a top-level (i.e. parentless) region that contains the
  653. * memory being synchronized
  654. */
  655. void memory_global_sync_dirty_bitmap(MemoryRegion *address_space);
  656. /**
  657. * memory_region_transaction_begin: Start a transaction.
  658. *
  659. * During a transaction, changes will be accumulated and made visible
  660. * only when the transaction ends (is committed).
  661. */
  662. void memory_region_transaction_begin(void);
  663. /**
  664. * memory_region_transaction_commit: Commit a transaction and make changes
  665. * visible to the guest.
  666. */
  667. void memory_region_transaction_commit(void);
  668. /**
  669. * memory_listener_register: register callbacks to be called when memory
  670. * sections are mapped or unmapped into an address
  671. * space
  672. *
  673. * @listener: an object containing the callbacks to be called
  674. * @filter: if non-%NULL, only regions in this address space will be observed
  675. */
  676. void memory_listener_register(MemoryListener *listener, MemoryRegion *filter);
  677. /**
  678. * memory_listener_unregister: undo the effect of memory_listener_register()
  679. *
  680. * @listener: an object containing the callbacks to be removed
  681. */
  682. void memory_listener_unregister(MemoryListener *listener);
  683. /**
  684. * memory_global_dirty_log_start: begin dirty logging for all regions
  685. */
  686. void memory_global_dirty_log_start(void);
  687. /**
  688. * memory_global_dirty_log_stop: begin dirty logging for all regions
  689. */
  690. void memory_global_dirty_log_stop(void);
  691. void mtree_info(fprintf_function mon_printf, void *f);
  692. #endif
  693. #endif