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