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 #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 /* hostmem-ram.c */ 31 /** 32 * @TYPE_MEMORY_BACKEND_RAM: 33 * name of backend that uses mmap on the anonymous RAM 34 */ 35 36 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" 37 38 /* hostmem-file.c */ 39 /** 40 * @TYPE_MEMORY_BACKEND_FILE: 41 * name of backend that uses mmap on a file descriptor 42 */ 43 #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" 44 45 typedef struct HostMemoryBackend HostMemoryBackend; 46 typedef struct HostMemoryBackendClass HostMemoryBackendClass; 47 48 /** 49 * HostMemoryBackendClass: 50 * @parent_class: opaque parent class container 51 */ 52 struct HostMemoryBackendClass { 53 ObjectClass parent_class; 54 55 void (*alloc)(HostMemoryBackend *backend, Error **errp); 56 }; 57 58 /** 59 * @HostMemoryBackend 60 * 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 65 */ 66 struct HostMemoryBackend { 67 /* private */ 68 Object parent; 69 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; 77 78 MemoryRegion mr; 79 }; 80 81 bool host_memory_backend_mr_inited(HostMemoryBackend *backend); 82 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend); 83 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); 88 89 #endif 90