virtio-mem: Implement RamDiscardManager interface
[qemu/kevin.git] / include / hw / virtio / virtio-mem.h
blob9a6e348fa2c26a67596298cccd9e9c7425b22d92
1 /*
2 * Virtio MEM device
4 * Copyright (C) 2020 Red Hat, Inc.
6 * Authors:
7 * David Hildenbrand <david@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2.
10 * See the COPYING file in the top-level directory.
13 #ifndef HW_VIRTIO_MEM_H
14 #define HW_VIRTIO_MEM_H
16 #include "standard-headers/linux/virtio_mem.h"
17 #include "hw/virtio/virtio.h"
18 #include "qapi/qapi-types-misc.h"
19 #include "sysemu/hostmem.h"
20 #include "qom/object.h"
22 #define TYPE_VIRTIO_MEM "virtio-mem"
24 OBJECT_DECLARE_TYPE(VirtIOMEM, VirtIOMEMClass,
25 VIRTIO_MEM)
27 #define VIRTIO_MEM_MEMDEV_PROP "memdev"
28 #define VIRTIO_MEM_NODE_PROP "node"
29 #define VIRTIO_MEM_SIZE_PROP "size"
30 #define VIRTIO_MEM_REQUESTED_SIZE_PROP "requested-size"
31 #define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size"
32 #define VIRTIO_MEM_ADDR_PROP "memaddr"
34 struct VirtIOMEM {
35 VirtIODevice parent_obj;
37 /* guest -> host request queue */
38 VirtQueue *vq;
40 /* bitmap used to track unplugged memory */
41 int32_t bitmap_size;
42 unsigned long *bitmap;
44 /* assigned memory backend and memory region */
45 HostMemoryBackend *memdev;
47 /* NUMA node */
48 uint32_t node;
50 /* assigned address of the region in guest physical memory */
51 uint64_t addr;
53 /* usable region size (<= region_size) */
54 uint64_t usable_region_size;
56 /* actual size (how much the guest plugged) */
57 uint64_t size;
59 /* requested size */
60 uint64_t requested_size;
62 /* block size and alignment */
63 uint64_t block_size;
65 /* notifiers to notify when "size" changes */
66 NotifierList size_change_notifiers;
68 /* don't migrate unplugged memory */
69 NotifierWithReturn precopy_notifier;
71 /* listeners to notify on plug/unplug activity. */
72 QLIST_HEAD(, RamDiscardListener) rdl_list;
75 struct VirtIOMEMClass {
76 /* private */
77 VirtIODevice parent;
79 /* public */
80 void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi);
81 MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp);
82 void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier);
83 void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier);
86 #endif