xref: /openbmc/qemu/include/hw/virtio/virtio-mem.h (revision 53c7c924)
1 /*
2  * Virtio MEM device
3  *
4  * Copyright (C) 2020 Red Hat, Inc.
5  *
6  * Authors:
7  *  David Hildenbrand <david@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #ifndef HW_VIRTIO_MEM_H
14 #define HW_VIRTIO_MEM_H
15 
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"
21 
22 #define TYPE_VIRTIO_MEM "virtio-mem"
23 
24 OBJECT_DECLARE_TYPE(VirtIOMEM, VirtIOMEMClass,
25                     VIRTIO_MEM)
26 
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"
33 #define VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP "unplugged-inaccessible"
34 #define VIRTIO_MEM_EARLY_MIGRATION_PROP "x-early-migration"
35 #define VIRTIO_MEM_PREALLOC_PROP "prealloc"
36 
37 struct VirtIOMEM {
38     VirtIODevice parent_obj;
39 
40     /* guest -> host request queue */
41     VirtQueue *vq;
42 
43     /* bitmap used to track unplugged memory */
44     int32_t bitmap_size;
45     unsigned long *bitmap;
46 
47     /* assigned memory backend and memory region */
48     HostMemoryBackend *memdev;
49 
50     /* NUMA node */
51     uint32_t node;
52 
53     /* assigned address of the region in guest physical memory */
54     uint64_t addr;
55 
56     /* usable region size (<= region_size) */
57     uint64_t usable_region_size;
58 
59     /* actual size (how much the guest plugged) */
60     uint64_t size;
61 
62     /* requested size */
63     uint64_t requested_size;
64 
65     /* block size and alignment */
66     uint64_t block_size;
67 
68     /*
69      * Whether we indicate VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE to the guest.
70      * For !x86 targets this will always be "on" and consequently indicate
71      * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE.
72      */
73     OnOffAuto unplugged_inaccessible;
74 
75     /* whether to prealloc memory when plugging new blocks */
76     bool prealloc;
77 
78     /*
79      * Whether we migrate properties that are immutable while migration is
80      * active early, before state of other devices and especially, before
81      * migrating any RAM content.
82      */
83     bool early_migration;
84 
85     /* notifiers to notify when "size" changes */
86     NotifierList size_change_notifiers;
87 
88     /* listeners to notify on plug/unplug activity. */
89     QLIST_HEAD(, RamDiscardListener) rdl_list;
90 };
91 
92 struct VirtIOMEMClass {
93     /* private */
94     VirtIODevice parent;
95 
96     /* public */
97     void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi);
98     MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp);
99     void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier);
100     void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier);
101     void (*unplug_request_check)(VirtIOMEM *vmem, Error **errp);
102 };
103 
104 #endif
105