xref: /openbmc/qemu/include/sysemu/hostmem.h (revision 0e8e77d4)
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/numa.h"
17 #include "qapi/qapi-types-machine.h"
18 #include "qom/object.h"
19 #include "exec/memory.h"
20 #include "qemu/bitmap.h"
21 
22 #define TYPE_MEMORY_BACKEND "memory-backend"
23 OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
24                     MEMORY_BACKEND)
25 
26 /* hostmem-ram.c */
27 /**
28  * @TYPE_MEMORY_BACKEND_RAM:
29  * name of backend that uses mmap on the anonymous RAM
30  */
31 
32 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
33 
34 /* hostmem-file.c */
35 /**
36  * @TYPE_MEMORY_BACKEND_FILE:
37  * name of backend that uses mmap on a file descriptor
38  */
39 #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file"
40 
41 
42 /**
43  * HostMemoryBackendClass:
44  * @parent_class: opaque parent class container
45  */
46 struct HostMemoryBackendClass {
47     ObjectClass parent_class;
48 
49     void (*alloc)(HostMemoryBackend *backend, Error **errp);
50 };
51 
52 /**
53  * @HostMemoryBackend
54  *
55  * @parent: opaque parent object container
56  * @size: amount of memory backend provides
57  * @mr: MemoryRegion representing host memory belonging to backend
58  * @prealloc_threads: number of threads to be used for preallocatining RAM
59  */
60 struct HostMemoryBackend {
61     /* private */
62     Object parent;
63 
64     /* protected */
65     uint64_t size;
66     bool merge, dump, use_canonical_path;
67     bool prealloc, is_mapped, share;
68     uint32_t prealloc_threads;
69     DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
70     HostMemPolicy policy;
71 
72     MemoryRegion mr;
73 };
74 
75 bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
76 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
77 
78 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
79 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
80 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
81 char *host_memory_backend_get_name(HostMemoryBackend *backend);
82 
83 #endif
84