Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 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 | */ |
Markus Armbruster | 121d071 | 2016-06-29 10:12:57 +0200 | [diff] [blame] | 12 | |
| 13 | #ifndef SYSEMU_HOSTMEM_H |
| 14 | #define SYSEMU_HOSTMEM_H |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 15 | |
Markus Armbruster | b58c5c2 | 2019-08-12 07:23:55 +0200 | [diff] [blame] | 16 | #include "sysemu/numa.h" |
Markus Armbruster | 8ac25c8 | 2019-06-19 22:10:41 +0200 | [diff] [blame] | 17 | #include "qapi/qapi-types-machine.h" |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 18 | #include "qom/object.h" |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 19 | #include "exec/memory.h" |
Hu Tao | 4cf1b76 | 2014-06-10 19:15:25 +0800 | [diff] [blame] | 20 | #include "qemu/bitmap.h" |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 21 | |
| 22 | #define TYPE_MEMORY_BACKEND "memory-backend" |
Eduardo Habkost | c821774a | 2020-08-31 17:07:37 -0400 | [diff] [blame] | 23 | OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass, |
Eduardo Habkost | 30b5707 | 2020-09-16 14:25:17 -0400 | [diff] [blame] | 24 | MEMORY_BACKEND) |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 25 | |
Igor Mammedov | 900c0ba | 2020-02-19 11:08:37 -0500 | [diff] [blame] | 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 | |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * HostMemoryBackendClass: |
| 44 | * @parent_class: opaque parent class container |
| 45 | */ |
| 46 | struct HostMemoryBackendClass { |
| 47 | ObjectClass parent_class; |
Hu Tao | bd9262d | 2014-06-10 19:15:19 +0800 | [diff] [blame] | 48 | |
| 49 | void (*alloc)(HostMemoryBackend *backend, Error **errp); |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * @HostMemoryBackend |
| 54 | * |
| 55 | * @parent: opaque parent object container |
| 56 | * @size: amount of memory backend provides |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 57 | * @mr: MemoryRegion representing host memory belonging to backend |
Igor Mammedov | ffac16f | 2020-02-19 11:09:50 -0500 | [diff] [blame] | 58 | * @prealloc_threads: number of threads to be used for preallocatining RAM |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 59 | */ |
| 60 | struct HostMemoryBackend { |
| 61 | /* private */ |
| 62 | Object parent; |
| 63 | |
| 64 | /* protected */ |
| 65 | uint64_t size; |
Marc-André Lureau | fa0cb34 | 2018-09-12 16:18:00 +0400 | [diff] [blame] | 66 | bool merge, dump, use_canonical_path; |
Igor Mammedov | 4ebc74d | 2020-02-19 11:09:51 -0500 | [diff] [blame] | 67 | bool prealloc, is_mapped, share; |
Igor Mammedov | ffac16f | 2020-02-19 11:09:50 -0500 | [diff] [blame] | 68 | uint32_t prealloc_threads; |
Hu Tao | 4cf1b76 | 2014-06-10 19:15:25 +0800 | [diff] [blame] | 69 | DECLARE_BITMAP(host_nodes, MAX_NODES + 1); |
| 70 | HostMemPolicy policy; |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 71 | |
| 72 | MemoryRegion mr; |
| 73 | }; |
| 74 | |
Peter Xu | 4728b57 | 2017-03-10 21:09:29 +0800 | [diff] [blame] | 75 | bool host_memory_backend_mr_inited(HostMemoryBackend *backend); |
David Hildenbrand | 7943e97 | 2018-06-19 15:41:36 +0200 | [diff] [blame] | 76 | MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend); |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 77 | |
Xiao Guangrong | 2aece63 | 2016-07-13 12:18:06 +0800 | [diff] [blame] | 78 | void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped); |
| 79 | bool host_memory_backend_is_mapped(HostMemoryBackend *backend); |
David Gibson | 2b10808 | 2018-04-03 15:05:45 +1000 | [diff] [blame] | 80 | size_t host_memory_backend_pagesize(HostMemoryBackend *memdev); |
Marc-André Lureau | fa0cb34 | 2018-09-12 16:18:00 +0400 | [diff] [blame] | 81 | char *host_memory_backend_get_name(HostMemoryBackend *backend); |
David Gibson | 2b10808 | 2018-04-03 15:05:45 +1000 | [diff] [blame] | 82 | |
Igor Mammedov | 1f07048 | 2014-06-06 17:54:29 +0200 | [diff] [blame] | 83 | #endif |