Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2020-03-26' into staging
[qemu.git] / include / sysemu / hostmem.h
blob8276e53683c86557fecac069763c60d8e28151e3
1 /*
2 * QEMU Host Memory Backend
4 * Copyright (C) 2013-2014 Red Hat Inc
6 * Authors:
7 * Igor Mammedov <imammedo@redhat.com>
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.
13 #ifndef SYSEMU_HOSTMEM_H
14 #define SYSEMU_HOSTMEM_H
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"
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)
30 /* hostmem-ram.c */
31 /**
32 * @TYPE_MEMORY_BACKEND_RAM:
33 * name of backend that uses mmap on the anonymous RAM
36 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
38 /* hostmem-file.c */
39 /**
40 * @TYPE_MEMORY_BACKEND_FILE:
41 * name of backend that uses mmap on a file descriptor
43 #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file"
45 typedef struct HostMemoryBackend HostMemoryBackend;
46 typedef struct HostMemoryBackendClass HostMemoryBackendClass;
48 /**
49 * HostMemoryBackendClass:
50 * @parent_class: opaque parent class container
52 struct HostMemoryBackendClass {
53 ObjectClass parent_class;
55 void (*alloc)(HostMemoryBackend *backend, Error **errp);
58 /**
59 * @HostMemoryBackend
61 * @parent: opaque parent object container
62 * @size: amount of memory backend provides
63 * @mr: MemoryRegion representing host memory belonging to backend
64 * @prealloc_threads: number of threads to be used for preallocatining RAM
66 struct HostMemoryBackend {
67 /* private */
68 Object parent;
70 /* protected */
71 uint64_t size;
72 bool merge, dump, use_canonical_path;
73 bool prealloc, is_mapped, share;
74 uint32_t prealloc_threads;
75 DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
76 HostMemPolicy policy;
78 MemoryRegion mr;
81 bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
82 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
84 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
85 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
86 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
87 char *host_memory_backend_get_name(HostMemoryBackend *backend);
89 #endif