xref: /openbmc/qemu/include/sysemu/hostmem.h (revision 7d87775f)
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 #include "qemu/thread-context.h"
22 
23 #define TYPE_MEMORY_BACKEND "memory-backend"
24 OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
25                     MEMORY_BACKEND)
26 
27 /* hostmem-ram.c */
28 /**
29  * @TYPE_MEMORY_BACKEND_RAM:
30  * name of backend that uses mmap on the anonymous RAM
31  */
32 
33 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
34 
35 /* hostmem-file.c */
36 /**
37  * @TYPE_MEMORY_BACKEND_FILE:
38  * name of backend that uses mmap on a file descriptor
39  */
40 #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file"
41 
42 #define TYPE_MEMORY_BACKEND_MEMFD "memory-backend-memfd"
43 
44 
45 /**
46  * HostMemoryBackendClass:
47  * @parent_class: opaque parent class container
48  */
49 struct HostMemoryBackendClass {
50     ObjectClass parent_class;
51 
52     /**
53      * alloc: Allocate memory from backend.
54      *
55      * @backend: the #HostMemoryBackend.
56      * @errp: pointer to Error*, to store an error if it happens.
57      *
58      * Return: true on success, else false setting @errp with error.
59      */
60     bool (*alloc)(HostMemoryBackend *backend, Error **errp);
61 };
62 
63 /**
64  * @HostMemoryBackend
65  *
66  * @parent: opaque parent object container
67  * @size: amount of memory backend provides
68  * @mr: MemoryRegion representing host memory belonging to backend
69  * @prealloc_threads: number of threads to be used for preallocatining RAM
70  */
71 struct HostMemoryBackend {
72     /* private */
73     Object parent;
74 
75     /* protected */
76     uint64_t size;
77     bool merge, dump, use_canonical_path;
78     bool prealloc, is_mapped, share, reserve;
79     bool guest_memfd, aligned;
80     uint32_t prealloc_threads;
81     ThreadContext *prealloc_context;
82     DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
83     HostMemPolicy policy;
84 
85     MemoryRegion mr;
86 };
87 
88 bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
89 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
90 
91 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
92 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
93 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
94 char *host_memory_backend_get_name(HostMemoryBackend *backend);
95 
96 #endif
97