1 /* 2 * Declarations for obsolete exec.c functions 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 or 10 * later. See the COPYING file in the top-level directory. 11 * 12 */ 13 14 /* 15 * This header is for use by exec.c and memory.c ONLY. Do not include it. 16 * The functions declared here will be removed soon. 17 */ 18 19 #ifndef MEMORY_INTERNAL_H 20 #define MEMORY_INTERNAL_H 21 22 #ifndef CONFIG_USER_ONLY 23 #include "hw/xen/xen.h" 24 25 26 typedef struct AddressSpaceDispatch AddressSpaceDispatch; 27 28 void address_space_init_dispatch(AddressSpace *as); 29 void address_space_destroy_dispatch(AddressSpace *as); 30 31 extern const MemoryRegionOps unassigned_mem_ops; 32 33 bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, 34 unsigned size, bool is_write); 35 36 ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, 37 MemoryRegion *mr); 38 ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); 39 void *qemu_get_ram_ptr(ram_addr_t addr); 40 void qemu_ram_free(ram_addr_t addr); 41 void qemu_ram_free_from_ptr(ram_addr_t addr); 42 43 static inline bool cpu_physical_memory_get_dirty(ram_addr_t start, 44 ram_addr_t length, 45 unsigned client) 46 { 47 unsigned long end, page, next; 48 49 assert(client < DIRTY_MEMORY_NUM); 50 51 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; 52 page = start >> TARGET_PAGE_BITS; 53 next = find_next_bit(ram_list.dirty_memory[client], end, page); 54 55 return next < end; 56 } 57 58 static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr, 59 unsigned client) 60 { 61 return cpu_physical_memory_get_dirty(addr, 1, client); 62 } 63 64 static inline bool cpu_physical_memory_is_clean(ram_addr_t addr) 65 { 66 bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA); 67 bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE); 68 bool migration = 69 cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_MIGRATION); 70 return !(vga && code && migration); 71 } 72 73 static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr, 74 unsigned client) 75 { 76 assert(client < DIRTY_MEMORY_NUM); 77 set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]); 78 } 79 80 static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, 81 ram_addr_t length) 82 { 83 unsigned long end, page; 84 85 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; 86 page = start >> TARGET_PAGE_BITS; 87 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION], page, end - page); 88 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_VGA], page, end - page); 89 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_CODE], page, end - page); 90 xen_modified_memory(start, length); 91 } 92 93 static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, 94 ram_addr_t length, 95 unsigned client) 96 { 97 unsigned long end, page; 98 99 assert(client < DIRTY_MEMORY_NUM); 100 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; 101 page = start >> TARGET_PAGE_BITS; 102 bitmap_clear(ram_list.dirty_memory[client], page, end - page); 103 } 104 105 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t length, 106 unsigned client); 107 108 #endif 109 110 #endif 111