1 /* 2 * Declarations for functions which are internal to the memory subsystem. 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, memory.c and accel/tcg/cputlb.c ONLY, 16 * for declarations which are shared between the memory subsystem's 17 * internals and the TCG TLB code. Do not include it from elsewhere. 18 */ 19 20 #ifndef MEMORY_INTERNAL_H 21 #define MEMORY_INTERNAL_H 22 23 #ifndef CONFIG_USER_ONLY 24 static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv) 25 { 26 return fv->dispatch; 27 } 28 29 static inline AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as) 30 { 31 return flatview_to_dispatch(address_space_to_flatview(as)); 32 } 33 34 FlatView *address_space_get_flatview(AddressSpace *as); 35 void flatview_unref(FlatView *view); 36 37 extern const MemoryRegionOps unassigned_mem_ops; 38 39 bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, 40 unsigned size, bool is_write); 41 42 void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section); 43 AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv); 44 void address_space_dispatch_compact(AddressSpaceDispatch *d); 45 void address_space_dispatch_free(AddressSpaceDispatch *d); 46 47 void mtree_print_dispatch(fprintf_function mon, void *f, 48 struct AddressSpaceDispatch *d, 49 MemoryRegion *root); 50 51 /* Opaque struct for passing info from memory_notdirty_write_prepare() 52 * to memory_notdirty_write_complete(). Callers should treat all fields 53 * as private, with the exception of @active. 54 * 55 * @active is a field which is not touched by either the prepare or 56 * complete functions, but which the caller can use if it wishes to 57 * track whether it has called prepare for this struct and so needs 58 * to later call the complete function. 59 */ 60 typedef struct { 61 CPUState *cpu; 62 ram_addr_t ram_addr; 63 vaddr mem_vaddr; 64 unsigned size; 65 bool locked; 66 bool active; 67 } NotDirtyInfo; 68 69 /** 70 * memory_notdirty_write_prepare: call before writing to non-dirty memory 71 * @ndi: pointer to opaque NotDirtyInfo struct 72 * @cpu: CPU doing the write 73 * @mem_vaddr: virtual address of write 74 * @ram_addr: the ram address of the write 75 * @size: size of write in bytes 76 * 77 * Any code which writes to the host memory corresponding to 78 * guest RAM which has been marked as NOTDIRTY must wrap those 79 * writes in calls to memory_notdirty_write_prepare() and 80 * memory_notdirty_write_complete(): 81 * 82 * NotDirtyInfo ndi; 83 * memory_notdirty_write_prepare(&ndi, ....); 84 * ... perform write here ... 85 * memory_notdirty_write_complete(&ndi); 86 * 87 * These calls will ensure that we flush any TCG translated code for 88 * the memory being written, update the dirty bits and (if possible) 89 * remove the slowpath callback for writing to the memory. 90 * 91 * This must only be called if we are using TCG; it will assert otherwise. 92 * 93 * We may take a lock in the prepare call, so callers must ensure that 94 * they don't exit (via longjump or otherwise) without calling complete. 95 * 96 * This call must only be made inside an RCU critical section. 97 * (Note that while we're executing a TCG TB we're always in an 98 * RCU critical section, which is likely to be the case for callers 99 * of these functions.) 100 */ 101 void memory_notdirty_write_prepare(NotDirtyInfo *ndi, 102 CPUState *cpu, 103 vaddr mem_vaddr, 104 ram_addr_t ram_addr, 105 unsigned size); 106 /** 107 * memory_notdirty_write_complete: finish write to non-dirty memory 108 * @ndi: pointer to the opaque NotDirtyInfo struct which was initialized 109 * by memory_not_dirty_write_prepare(). 110 */ 111 void memory_notdirty_write_complete(NotDirtyInfo *ndi); 112 113 #endif 114 #endif 115