| 1 | /* |
| 2 | * QEMU physical memory interfaces (target independent). |
| 3 | * |
| 4 | * Copyright (c) 2003 Fabrice Bellard |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | #ifndef QEMU_SYSTEM_PHYSMEM_H |
| 9 | #define QEMU_SYSTEM_PHYSMEM_H |
| 10 | |
| 11 | #include "exec/hwaddr.h" |
| 12 | #include "system/ramlist.h" |
| 13 | |
| 14 | /** |
| 15 | * physical_memory_map: Map guest physical memory region into host virtual |
| 16 | * address. |
| 17 | * |
| 18 | * Map a memory region from the legacy global #address_space_memory address |
| 19 | * space. May return %NULL and set *@plen to zero(0), if resources needed to |
| 20 | * perform the mapping are exhausted. |
| 21 | * |
| 22 | * @addr: address within that address space |
| 23 | * @len: pointer to length of buffer; updated on return |
| 24 | * @is_write: whether the translation operation is for write |
| 25 | */ |
| 26 | void *physical_memory_map(hwaddr addr, hwaddr *plen, bool is_write); |
| 27 | |
| 28 | /** |
| 29 | * physical_memory_unmap: Unmaps a memory region previously mapped by |
| 30 | * physical_memory_map() |
| 31 | * |
| 32 | * @buffer: host pointer as returned by physical_memory_map() |
| 33 | * @len: buffer length as returned by physical_memory_map() |
| 34 | * @is_write: whether the translation operation is for write |
| 35 | * @access_len: amount of data actually transferred |
| 36 | */ |
| 37 | void physical_memory_unmap(void *buffer, hwaddr len, |
| 38 | bool is_write, hwaddr access_len); |
| 39 | |
| 40 | /** |
| 41 | * physical_memory_read: Read from the legacy global address space. |
| 42 | * |
| 43 | * This function access the legacy global #address_space_memory address |
| 44 | * space and does not say whether the operation succeeded or failed. |
| 45 | * |
| 46 | * @addr: address within the legacy global address space |
| 47 | * @buf: buffer with the data transferred |
| 48 | * @len: length of the data transferred |
| 49 | */ |
| 50 | void physical_memory_read(hwaddr addr, void *buf, hwaddr len); |
| 51 | |
| 52 | /** |
| 53 | * physical_memory_write: Write to the legacy global address space. |
| 54 | * |
| 55 | * This function access the legacy global #address_space_memory address |
| 56 | * space and does not say whether the operation succeeded or failed. |
| 57 | * |
| 58 | * @addr: address within the legacy global address space |
| 59 | * @buf: buffer with the data transferred |
| 60 | * @len: the number of bytes to write |
| 61 | */ |
| 62 | void physical_memory_write(hwaddr addr, const void *buf, hwaddr len); |
| 63 | |
| 64 | #define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1) |
| 65 | #define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE)) |
| 66 | |
| 67 | bool physical_memory_get_dirty_flag(ram_addr_t addr, unsigned client); |
| 68 | |
| 69 | bool physical_memory_is_clean(ram_addr_t addr); |
| 70 | |
| 71 | uint8_t physical_memory_range_includes_clean(ram_addr_t start, |
| 72 | ram_addr_t length, |
| 73 | uint8_t mask); |
| 74 | |
| 75 | void physical_memory_set_dirty_flag(ram_addr_t addr, unsigned client); |
| 76 | |
| 77 | void physical_memory_set_dirty_range(ram_addr_t start, ram_addr_t length, |
| 78 | uint8_t mask); |
| 79 | |
| 80 | /* |
| 81 | * Contrary to physical_memory_sync_dirty_bitmap() this function returns |
| 82 | * the number of dirty pages in @bitmap passed as argument. On the other hand, |
| 83 | * physical_memory_sync_dirty_bitmap() returns newly dirtied pages that |
| 84 | * weren't set in the global migration bitmap. |
| 85 | */ |
| 86 | uint64_t physical_memory_set_dirty_lebitmap(unsigned long *bitmap, |
| 87 | ram_addr_t start, |
| 88 | ram_addr_t pages); |
| 89 | |
| 90 | void physical_memory_dirty_bits_cleared(ram_addr_t start, ram_addr_t length); |
| 91 | |
| 92 | uint64_t physical_memory_test_and_clear_dirty(ram_addr_t start, |
| 93 | ram_addr_t length, |
| 94 | unsigned client, |
| 95 | unsigned long *bmap); |
| 96 | |
| 97 | DirtyBitmapSnapshot * |
| 98 | physical_memory_snapshot_and_clear_dirty(MemoryRegion *mr, hwaddr offset, |
| 99 | hwaddr length, unsigned client); |
| 100 | |
| 101 | bool physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap, |
| 102 | ram_addr_t start, |
| 103 | ram_addr_t length); |
| 104 | int ram_block_rebind(Error **errp); |
| 105 | |
| 106 | #endif |