blob: df5644723a39523a1a193a828909cfe148bcc1fc [file] [log] [blame]
Igor Mammedov1f070482014-06-06 17:54:29 +02001/*
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 Armbruster121d0712016-06-29 10:12:57 +020012
13#ifndef SYSEMU_HOSTMEM_H
14#define SYSEMU_HOSTMEM_H
Igor Mammedov1f070482014-06-06 17:54:29 +020015
Markus Armbrusterb58c5c22019-08-12 07:23:55 +020016#include "sysemu/numa.h"
Markus Armbruster8ac25c82019-06-19 22:10:41 +020017#include "qapi/qapi-types-machine.h"
Igor Mammedov1f070482014-06-06 17:54:29 +020018#include "qom/object.h"
Igor Mammedov1f070482014-06-06 17:54:29 +020019#include "exec/memory.h"
Hu Tao4cf1b762014-06-10 19:15:25 +080020#include "qemu/bitmap.h"
Igor Mammedov1f070482014-06-06 17:54:29 +020021
22#define TYPE_MEMORY_BACKEND "memory-backend"
Eduardo Habkostc821774a2020-08-31 17:07:37 -040023OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
Eduardo Habkost30b57072020-09-16 14:25:17 -040024 MEMORY_BACKEND)
Igor Mammedov1f070482014-06-06 17:54:29 +020025
Igor Mammedov900c0ba2020-02-19 11:08:37 -050026/* 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 Mammedov1f070482014-06-06 17:54:29 +020041
42/**
43 * HostMemoryBackendClass:
44 * @parent_class: opaque parent class container
45 */
46struct HostMemoryBackendClass {
47 ObjectClass parent_class;
Hu Taobd9262d2014-06-10 19:15:19 +080048
49 void (*alloc)(HostMemoryBackend *backend, Error **errp);
Igor Mammedov1f070482014-06-06 17:54:29 +020050};
51
52/**
53 * @HostMemoryBackend
54 *
55 * @parent: opaque parent object container
56 * @size: amount of memory backend provides
Igor Mammedov1f070482014-06-06 17:54:29 +020057 * @mr: MemoryRegion representing host memory belonging to backend
Igor Mammedovffac16f2020-02-19 11:09:50 -050058 * @prealloc_threads: number of threads to be used for preallocatining RAM
Igor Mammedov1f070482014-06-06 17:54:29 +020059 */
60struct HostMemoryBackend {
61 /* private */
62 Object parent;
63
64 /* protected */
65 uint64_t size;
Marc-André Lureaufa0cb342018-09-12 16:18:00 +040066 bool merge, dump, use_canonical_path;
Igor Mammedov4ebc74d2020-02-19 11:09:51 -050067 bool prealloc, is_mapped, share;
Igor Mammedovffac16f2020-02-19 11:09:50 -050068 uint32_t prealloc_threads;
Hu Tao4cf1b762014-06-10 19:15:25 +080069 DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
70 HostMemPolicy policy;
Igor Mammedov1f070482014-06-06 17:54:29 +020071
72 MemoryRegion mr;
73};
74
Peter Xu4728b572017-03-10 21:09:29 +080075bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
David Hildenbrand7943e972018-06-19 15:41:36 +020076MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
Igor Mammedov1f070482014-06-06 17:54:29 +020077
Xiao Guangrong2aece632016-07-13 12:18:06 +080078void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
79bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
David Gibson2b108082018-04-03 15:05:45 +100080size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
Marc-André Lureaufa0cb342018-09-12 16:18:00 +040081char *host_memory_backend_get_name(HostMemoryBackend *backend);
David Gibson2b108082018-04-03 15:05:45 +100082
Igor Mammedov1f070482014-06-06 17:54:29 +020083#endif