4 * Copyright (C) 2020 Red Hat, Inc.
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 typedef struct VirtIOMEM VirtIOMEM
;
25 typedef struct VirtIOMEMClass VirtIOMEMClass
;
26 DECLARE_OBJ_CHECKERS(VirtIOMEM
, VirtIOMEMClass
,
27 VIRTIO_MEM
, TYPE_VIRTIO_MEM
)
29 #define VIRTIO_MEM_MEMDEV_PROP "memdev"
30 #define VIRTIO_MEM_NODE_PROP "node"
31 #define VIRTIO_MEM_SIZE_PROP "size"
32 #define VIRTIO_MEM_REQUESTED_SIZE_PROP "requested-size"
33 #define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size"
34 #define VIRTIO_MEM_ADDR_PROP "memaddr"
37 VirtIODevice parent_obj
;
39 /* guest -> host request queue */
42 /* bitmap used to track unplugged memory */
44 unsigned long *bitmap
;
46 /* assigned memory backend and memory region */
47 HostMemoryBackend
*memdev
;
52 /* assigned address of the region in guest physical memory */
55 /* usable region size (<= region_size) */
56 uint64_t usable_region_size
;
58 /* actual size (how much the guest plugged) */
62 uint64_t requested_size
;
64 /* block size and alignment */
67 /* notifiers to notify when "size" changes */
68 NotifierList size_change_notifiers
;
70 /* don't migrate unplugged memory */
71 NotifierWithReturn precopy_notifier
;
74 struct VirtIOMEMClass
{
79 void (*fill_device_info
)(const VirtIOMEM
*vmen
, VirtioMEMDeviceInfo
*vi
);
80 MemoryRegion
*(*get_memory_region
)(VirtIOMEM
*vmem
, Error
**errp
);
81 void (*add_size_change_notifier
)(VirtIOMEM
*vmem
, Notifier
*notifier
);
82 void (*remove_size_change_notifier
)(VirtIOMEM
*vmem
, Notifier
*notifier
);