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