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