]> git.proxmox.com Git - mirror_qemu.git/blame - include/exec/memory-internal.h
migration: use migration_in_postcopy() to check POSTCOPY_ACTIVE
[mirror_qemu.git] / include / exec / memory-internal.h
CommitLineData
67d95c15 1/*
9d70618c 2 * Declarations for functions which are internal to the memory subsystem.
67d95c15
AK
3 *
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
5 *
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
8 *
6b620ca3
PB
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.
67d95c15
AK
11 *
12 */
13
14/*
9d70618c
PM
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.
67d95c15
AK
18 */
19
7762c2c1
AK
20#ifndef MEMORY_INTERNAL_H
21#define MEMORY_INTERNAL_H
67d95c15
AK
22
23#ifndef CONFIG_USER_ONLY
785a507e
PB
24static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
25{
26 return fv->dispatch;
27}
28
29static inline AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)
30{
31 return flatview_to_dispatch(address_space_to_flatview(as));
32}
ac1970fb 33
48564041
PB
34FlatView *address_space_get_flatview(AddressSpace *as);
35void flatview_unref(FlatView *view);
36
d197063f
PB
37extern const MemoryRegionOps unassigned_mem_ops;
38
d2702032 39bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
6d7b9a6c
PM
40 unsigned size, bool is_write,
41 MemTxAttrs attrs);
d2702032 42
8629d3fc
AK
43void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section);
44AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv);
45void address_space_dispatch_compact(AddressSpaceDispatch *d);
66a6df1d 46void address_space_dispatch_free(AddressSpaceDispatch *d);
9a62e24f 47
b6b71cb5 48void mtree_print_dispatch(struct AddressSpaceDispatch *d,
5e8fd947
AK
49 MemoryRegion *root);
50
0ac20318
EC
51struct page_collection;
52
27266271
PM
53/* Opaque struct for passing info from memory_notdirty_write_prepare()
54 * to memory_notdirty_write_complete(). Callers should treat all fields
55 * as private, with the exception of @active.
56 *
57 * @active is a field which is not touched by either the prepare or
58 * complete functions, but which the caller can use if it wishes to
59 * track whether it has called prepare for this struct and so needs
60 * to later call the complete function.
61 */
62typedef struct {
63 CPUState *cpu;
0ac20318 64 struct page_collection *pages;
27266271
PM
65 ram_addr_t ram_addr;
66 vaddr mem_vaddr;
67 unsigned size;
27266271
PM
68 bool active;
69} NotDirtyInfo;
70
71/**
72 * memory_notdirty_write_prepare: call before writing to non-dirty memory
73 * @ndi: pointer to opaque NotDirtyInfo struct
74 * @cpu: CPU doing the write
75 * @mem_vaddr: virtual address of write
76 * @ram_addr: the ram address of the write
77 * @size: size of write in bytes
78 *
79 * Any code which writes to the host memory corresponding to
80 * guest RAM which has been marked as NOTDIRTY must wrap those
81 * writes in calls to memory_notdirty_write_prepare() and
82 * memory_notdirty_write_complete():
83 *
84 * NotDirtyInfo ndi;
85 * memory_notdirty_write_prepare(&ndi, ....);
86 * ... perform write here ...
87 * memory_notdirty_write_complete(&ndi);
88 *
89 * These calls will ensure that we flush any TCG translated code for
90 * the memory being written, update the dirty bits and (if possible)
91 * remove the slowpath callback for writing to the memory.
92 *
93 * This must only be called if we are using TCG; it will assert otherwise.
94 *
0ac20318 95 * We may take locks in the prepare call, so callers must ensure that
27266271
PM
96 * they don't exit (via longjump or otherwise) without calling complete.
97 *
98 * This call must only be made inside an RCU critical section.
99 * (Note that while we're executing a TCG TB we're always in an
100 * RCU critical section, which is likely to be the case for callers
101 * of these functions.)
102 */
103void memory_notdirty_write_prepare(NotDirtyInfo *ndi,
104 CPUState *cpu,
105 vaddr mem_vaddr,
106 ram_addr_t ram_addr,
107 unsigned size);
108/**
109 * memory_notdirty_write_complete: finish write to non-dirty memory
110 * @ndi: pointer to the opaque NotDirtyInfo struct which was initialized
111 * by memory_not_dirty_write_prepare().
112 */
113void memory_notdirty_write_complete(NotDirtyInfo *ndi);
114
67d95c15 115#endif
67d95c15 116#endif