Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / include / sysemu / hostmem.h
blob0e411aaa29e1a8734c39cd9fb90046b012c4d5de
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"
21 #include "qemu/thread-context.h"
23 #define TYPE_MEMORY_BACKEND "memory-backend"
24 OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
25 MEMORY_BACKEND)
27 /* hostmem-ram.c */
28 /**
29 * @TYPE_MEMORY_BACKEND_RAM:
30 * name of backend that uses mmap on the anonymous RAM
33 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
35 /* hostmem-file.c */
36 /**
37 * @TYPE_MEMORY_BACKEND_FILE:
38 * name of backend that uses mmap on a file descriptor
40 #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file"
43 /**
44 * HostMemoryBackendClass:
45 * @parent_class: opaque parent class container
47 struct HostMemoryBackendClass {
48 ObjectClass parent_class;
50 /**
51 * alloc: Allocate memory from backend.
53 * @backend: the #HostMemoryBackend.
54 * @errp: pointer to Error*, to store an error if it happens.
56 * Return: true on success, else false setting @errp with error.
58 bool (*alloc)(HostMemoryBackend *backend, Error **errp);
61 /**
62 * @HostMemoryBackend
64 * @parent: opaque parent object container
65 * @size: amount of memory backend provides
66 * @mr: MemoryRegion representing host memory belonging to backend
67 * @prealloc_threads: number of threads to be used for preallocatining RAM
69 struct HostMemoryBackend {
70 /* private */
71 Object parent;
73 /* protected */
74 uint64_t size;
75 bool merge, dump, use_canonical_path;
76 bool prealloc, is_mapped, share, reserve;
77 uint32_t prealloc_threads;
78 ThreadContext *prealloc_context;
79 DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
80 HostMemPolicy policy;
82 MemoryRegion mr;
85 bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
86 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
88 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
89 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
90 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
91 char *host_memory_backend_get_name(HostMemoryBackend *backend);
93 #endif