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 typedef struct VirtIOMEM VirtIOMEM; 25 typedef struct VirtIOMEMClass VirtIOMEMClass; 26 #define VIRTIO_MEM(obj) \ 27 OBJECT_CHECK(VirtIOMEM, (obj), TYPE_VIRTIO_MEM) 28 #define VIRTIO_MEM_CLASS(oc) \ 29 OBJECT_CLASS_CHECK(VirtIOMEMClass, (oc), TYPE_VIRTIO_MEM) 30 #define VIRTIO_MEM_GET_CLASS(obj) \ 31 OBJECT_GET_CLASS(VirtIOMEMClass, (obj), TYPE_VIRTIO_MEM) 32 33 #define VIRTIO_MEM_MEMDEV_PROP "memdev" 34 #define VIRTIO_MEM_NODE_PROP "node" 35 #define VIRTIO_MEM_SIZE_PROP "size" 36 #define VIRTIO_MEM_REQUESTED_SIZE_PROP "requested-size" 37 #define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size" 38 #define VIRTIO_MEM_ADDR_PROP "memaddr" 39 40 struct VirtIOMEM { 41 VirtIODevice parent_obj; 42 43 /* guest -> host request queue */ 44 VirtQueue *vq; 45 46 /* bitmap used to track unplugged memory */ 47 int32_t bitmap_size; 48 unsigned long *bitmap; 49 50 /* assigned memory backend and memory region */ 51 HostMemoryBackend *memdev; 52 53 /* NUMA node */ 54 uint32_t node; 55 56 /* assigned address of the region in guest physical memory */ 57 uint64_t addr; 58 59 /* usable region size (<= region_size) */ 60 uint64_t usable_region_size; 61 62 /* actual size (how much the guest plugged) */ 63 uint64_t size; 64 65 /* requested size */ 66 uint64_t requested_size; 67 68 /* block size and alignment */ 69 uint64_t block_size; 70 71 /* notifiers to notify when "size" changes */ 72 NotifierList size_change_notifiers; 73 74 /* don't migrate unplugged memory */ 75 NotifierWithReturn precopy_notifier; 76 }; 77 78 struct VirtIOMEMClass { 79 /* private */ 80 VirtIODevice parent; 81 82 /* public */ 83 void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi); 84 MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp); 85 void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); 86 void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); 87 }; 88 89 #endif 90