xref: /openbmc/qemu/include/sysemu/hostmem.h (revision 0bdb12c7)
1 /*
2  * QEMU Host Memory Backend
3  *
4  * Copyright (C) 2013-2014 Red Hat Inc
5  *
6  * Authors:
7  *   Igor Mammedov <imammedo@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #ifndef SYSEMU_HOSTMEM_H
14 #define SYSEMU_HOSTMEM_H
15 
16 #include "sysemu/sysemu.h" /* for MAX_NODES */
17 #include "qom/object.h"
18 #include "exec/memory.h"
19 #include "qemu/option.h"
20 #include "qemu/bitmap.h"
21 
22 #define TYPE_MEMORY_BACKEND "memory-backend"
23 #define MEMORY_BACKEND(obj) \
24     OBJECT_CHECK(HostMemoryBackend, (obj), TYPE_MEMORY_BACKEND)
25 #define MEMORY_BACKEND_GET_CLASS(obj) \
26     OBJECT_GET_CLASS(HostMemoryBackendClass, (obj), TYPE_MEMORY_BACKEND)
27 #define MEMORY_BACKEND_CLASS(klass) \
28     OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND)
29 
30 typedef struct HostMemoryBackend HostMemoryBackend;
31 typedef struct HostMemoryBackendClass HostMemoryBackendClass;
32 
33 /**
34  * HostMemoryBackendClass:
35  * @parent_class: opaque parent class container
36  */
37 struct HostMemoryBackendClass {
38     ObjectClass parent_class;
39 
40     void (*alloc)(HostMemoryBackend *backend, Error **errp);
41 };
42 
43 /**
44  * @HostMemoryBackend
45  *
46  * @parent: opaque parent object container
47  * @size: amount of memory backend provides
48  * @mr: MemoryRegion representing host memory belonging to backend
49  */
50 struct HostMemoryBackend {
51     /* private */
52     Object parent;
53 
54     /* protected */
55     uint64_t size;
56     bool merge, dump;
57     bool prealloc, force_prealloc, is_mapped;
58     DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
59     HostMemPolicy policy;
60 
61     MemoryRegion mr;
62 };
63 
64 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend,
65                                              Error **errp);
66 
67 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
68 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
69 #endif
70