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_PREALLOC_PROP "prealloc" 34 35 struct VirtIOMEM { 36 VirtIODevice parent_obj; 37 38 /* guest -> host request queue */ 39 VirtQueue *vq; 40 41 /* bitmap used to track unplugged memory */ 42 int32_t bitmap_size; 43 unsigned long *bitmap; 44 45 /* assigned memory backend and memory region */ 46 HostMemoryBackend *memdev; 47 48 /* NUMA node */ 49 uint32_t node; 50 51 /* assigned address of the region in guest physical memory */ 52 uint64_t addr; 53 54 /* usable region size (<= region_size) */ 55 uint64_t usable_region_size; 56 57 /* actual size (how much the guest plugged) */ 58 uint64_t size; 59 60 /* requested size */ 61 uint64_t requested_size; 62 63 /* block size and alignment */ 64 uint64_t block_size; 65 66 /* whether to prealloc memory when plugging new blocks */ 67 bool prealloc; 68 69 /* notifiers to notify when "size" changes */ 70 NotifierList size_change_notifiers; 71 72 /* listeners to notify on plug/unplug activity. */ 73 QLIST_HEAD(, RamDiscardListener) rdl_list; 74 }; 75 76 struct VirtIOMEMClass { 77 /* private */ 78 VirtIODevice parent; 79 80 /* public */ 81 void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi); 82 MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp); 83 void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); 84 void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); 85 }; 86 87 #endif 88