xref: /openbmc/qemu/include/hw/virtio/virtio-mem.h (revision db1015e9)
1910b2576SDavid Hildenbrand /*
2910b2576SDavid Hildenbrand  * Virtio MEM device
3910b2576SDavid Hildenbrand  *
4910b2576SDavid Hildenbrand  * Copyright (C) 2020 Red Hat, Inc.
5910b2576SDavid Hildenbrand  *
6910b2576SDavid Hildenbrand  * Authors:
7910b2576SDavid Hildenbrand  *  David Hildenbrand <david@redhat.com>
8910b2576SDavid Hildenbrand  *
9910b2576SDavid Hildenbrand  * This work is licensed under the terms of the GNU GPL, version 2.
10910b2576SDavid Hildenbrand  * See the COPYING file in the top-level directory.
11910b2576SDavid Hildenbrand  */
12910b2576SDavid Hildenbrand 
13910b2576SDavid Hildenbrand #ifndef HW_VIRTIO_MEM_H
14910b2576SDavid Hildenbrand #define HW_VIRTIO_MEM_H
15910b2576SDavid Hildenbrand 
16910b2576SDavid Hildenbrand #include "standard-headers/linux/virtio_mem.h"
17910b2576SDavid Hildenbrand #include "hw/virtio/virtio.h"
18910b2576SDavid Hildenbrand #include "qapi/qapi-types-misc.h"
19910b2576SDavid Hildenbrand #include "sysemu/hostmem.h"
20*db1015e9SEduardo Habkost #include "qom/object.h"
21910b2576SDavid Hildenbrand 
22910b2576SDavid Hildenbrand #define TYPE_VIRTIO_MEM "virtio-mem"
23910b2576SDavid Hildenbrand 
24*db1015e9SEduardo Habkost typedef struct VirtIOMEM VirtIOMEM;
25*db1015e9SEduardo Habkost typedef struct VirtIOMEMClass VirtIOMEMClass;
26910b2576SDavid Hildenbrand #define VIRTIO_MEM(obj) \
27910b2576SDavid Hildenbrand         OBJECT_CHECK(VirtIOMEM, (obj), TYPE_VIRTIO_MEM)
28910b2576SDavid Hildenbrand #define VIRTIO_MEM_CLASS(oc) \
29910b2576SDavid Hildenbrand         OBJECT_CLASS_CHECK(VirtIOMEMClass, (oc), TYPE_VIRTIO_MEM)
30910b2576SDavid Hildenbrand #define VIRTIO_MEM_GET_CLASS(obj) \
31910b2576SDavid Hildenbrand         OBJECT_GET_CLASS(VirtIOMEMClass, (obj), TYPE_VIRTIO_MEM)
32910b2576SDavid Hildenbrand 
33910b2576SDavid Hildenbrand #define VIRTIO_MEM_MEMDEV_PROP "memdev"
34910b2576SDavid Hildenbrand #define VIRTIO_MEM_NODE_PROP "node"
35910b2576SDavid Hildenbrand #define VIRTIO_MEM_SIZE_PROP "size"
36910b2576SDavid Hildenbrand #define VIRTIO_MEM_REQUESTED_SIZE_PROP "requested-size"
37910b2576SDavid Hildenbrand #define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size"
38910b2576SDavid Hildenbrand #define VIRTIO_MEM_ADDR_PROP "memaddr"
39910b2576SDavid Hildenbrand 
40*db1015e9SEduardo Habkost struct VirtIOMEM {
41910b2576SDavid Hildenbrand     VirtIODevice parent_obj;
42910b2576SDavid Hildenbrand 
43910b2576SDavid Hildenbrand     /* guest -> host request queue */
44910b2576SDavid Hildenbrand     VirtQueue *vq;
45910b2576SDavid Hildenbrand 
46910b2576SDavid Hildenbrand     /* bitmap used to track unplugged memory */
47910b2576SDavid Hildenbrand     int32_t bitmap_size;
48910b2576SDavid Hildenbrand     unsigned long *bitmap;
49910b2576SDavid Hildenbrand 
50910b2576SDavid Hildenbrand     /* assigned memory backend and memory region */
51910b2576SDavid Hildenbrand     HostMemoryBackend *memdev;
52910b2576SDavid Hildenbrand 
53910b2576SDavid Hildenbrand     /* NUMA node */
54910b2576SDavid Hildenbrand     uint32_t node;
55910b2576SDavid Hildenbrand 
56910b2576SDavid Hildenbrand     /* assigned address of the region in guest physical memory */
57910b2576SDavid Hildenbrand     uint64_t addr;
58910b2576SDavid Hildenbrand 
59910b2576SDavid Hildenbrand     /* usable region size (<= region_size) */
60910b2576SDavid Hildenbrand     uint64_t usable_region_size;
61910b2576SDavid Hildenbrand 
62910b2576SDavid Hildenbrand     /* actual size (how much the guest plugged) */
63910b2576SDavid Hildenbrand     uint64_t size;
64910b2576SDavid Hildenbrand 
65910b2576SDavid Hildenbrand     /* requested size */
66910b2576SDavid Hildenbrand     uint64_t requested_size;
67910b2576SDavid Hildenbrand 
68910b2576SDavid Hildenbrand     /* block size and alignment */
69910b2576SDavid Hildenbrand     uint64_t block_size;
70c95b4437SDavid Hildenbrand 
71c95b4437SDavid Hildenbrand     /* notifiers to notify when "size" changes */
72c95b4437SDavid Hildenbrand     NotifierList size_change_notifiers;
730bc7806cSDavid Hildenbrand 
740bc7806cSDavid Hildenbrand     /* don't migrate unplugged memory */
750bc7806cSDavid Hildenbrand     NotifierWithReturn precopy_notifier;
76*db1015e9SEduardo Habkost };
77910b2576SDavid Hildenbrand 
78*db1015e9SEduardo Habkost struct VirtIOMEMClass {
79910b2576SDavid Hildenbrand     /* private */
80910b2576SDavid Hildenbrand     VirtIODevice parent;
81910b2576SDavid Hildenbrand 
82910b2576SDavid Hildenbrand     /* public */
83910b2576SDavid Hildenbrand     void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi);
84910b2576SDavid Hildenbrand     MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp);
85c95b4437SDavid Hildenbrand     void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier);
86c95b4437SDavid Hildenbrand     void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier);
87*db1015e9SEduardo Habkost };
88910b2576SDavid Hildenbrand 
89910b2576SDavid Hildenbrand #endif
90