Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
virtio-pmem: prototype version of virtio pmem device
This device configures memory address range information with file backend type. It acts like persistent memory device for KVM guest. It presents the memory address range to virtio-pmem driver over virtio channel and does the block flush whenever there is request from guest to flush/sync. (later part is yet to be implemented).
- Loading branch information
Pankaj Gupta
committed
Oct 11, 2017
1 parent
cda4a33
commit 9c428db
Showing
7 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Virtio pmem device | ||
| * | ||
| * | ||
| */ | ||
|
|
||
|
|
||
| #include "qemu/osdep.h" | ||
| #include "qapi/error.h" | ||
| #include "qemu-common.h" | ||
| #include "qemu/error-report.h" | ||
| #include "hw/virtio/virtio-pmem.h" | ||
|
|
||
|
|
||
| static void virtio_pmem_system_reset(void *opaque) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| static void virtio_pmem_flush(VirtIODevice *vdev, VirtQueue *vq) | ||
| { | ||
| //VirtIOPMEM *vm = VIRTIO_PMEM(vdev); | ||
| } | ||
|
|
||
|
|
||
| static void virtio_pmem_get_config(VirtIODevice *vdev, uint8_t *config) | ||
| { | ||
| VirtIOPMEM *pmem = VIRTIO_PMEM(vdev); | ||
| struct virtio_pmem_config *pmemcfg = (struct virtio_pmem_config *) config; | ||
|
|
||
| pmemcfg->start = pmem->start; | ||
| pmemcfg->size = pmem->size; | ||
| pmemcfg->align = pmem->align; | ||
| } | ||
|
|
||
| static uint64_t virtio_pmem_get_features(VirtIODevice *vdev, uint64_t features, | ||
| Error **errp) | ||
| { | ||
| virtio_add_feature(&features, VIRTIO_PMEM_PLUG); | ||
| return features; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static void virtio_pmem_realize(DeviceState *dev, Error **errp) | ||
| { | ||
| VirtIODevice *vdev = VIRTIO_DEVICE(dev); | ||
| VirtIOPMEM *pmem = VIRTIO_PMEM(dev); | ||
| MachineState *ms = MACHINE(qdev_get_machine()); | ||
| MemoryRegion *mr; | ||
| PCMachineState *pcms = | ||
| PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE)); | ||
|
|
||
| if (!pmem->memdev) { | ||
| error_setg(errp, "virtio-pmem not set"); | ||
| return; | ||
| } | ||
|
|
||
| pmem->start = pcms->hotplug_memory.base; | ||
|
|
||
| /*if (!pcmc->broken_reserved_end) { | ||
| pmem->size = memory_region_size(&pcms->hotplug_memory.mr); | ||
| }*/ | ||
|
|
||
|
|
||
| mr = host_memory_backend_get_memory(pmem->memdev, errp); | ||
| pmem->size = memory_region_size(mr); | ||
| pmem->align = memory_region_get_alignment(mr); | ||
|
|
||
| virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, | ||
| sizeof(struct virtio_pmem_config)); | ||
|
|
||
| pmem->rq_vq = virtio_add_queue(vdev, 128, virtio_pmem_flush); | ||
|
|
||
| host_memory_backend_set_mapped(pmem->memdev, true); | ||
| qemu_register_reset(virtio_pmem_system_reset, pmem); | ||
|
|
||
| } | ||
|
|
||
| static void virtio_mem_check_memdev(Object *obj, const char *name, Object *val, | ||
| Error **errp) | ||
| { | ||
|
|
||
| if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) { | ||
|
|
||
| char *path = object_get_canonical_path_component(val); | ||
| error_setg(errp, "Can't use already busy memdev: %s", path); | ||
| g_free(path); | ||
| return; | ||
| } | ||
|
|
||
| qdev_prop_allow_set_link_before_realize(obj, name, val, errp); | ||
| } | ||
|
|
||
| static void virtio_pmem_instance_init(Object *obj) | ||
| { | ||
|
|
||
| VirtIOPMEM *vm = VIRTIO_PMEM(obj); | ||
|
|
||
| object_property_add_link(obj, "memdev", TYPE_MEMORY_BACKEND, | ||
| (Object **)&vm->memdev, | ||
| (void *) virtio_mem_check_memdev, | ||
| OBJ_PROP_LINK_UNREF_ON_RELEASE, | ||
| &error_abort); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| static void virtio_pmem_class_init(ObjectClass *klass, void *data) | ||
| { | ||
| VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); | ||
|
|
||
| vdc->realize = virtio_pmem_realize; | ||
| vdc->get_config = virtio_pmem_get_config; | ||
| vdc->get_features = virtio_pmem_get_features; | ||
| } | ||
|
|
||
| static TypeInfo virtio_pmem_info = { | ||
| .name = TYPE_VIRTIO_PMEM, | ||
| .parent = TYPE_VIRTIO_DEVICE, | ||
| .class_size = sizeof(VirtIOPMEM), | ||
| .class_init = virtio_pmem_class_init, | ||
| .instance_init = virtio_pmem_instance_init, | ||
| }; | ||
|
|
||
|
|
||
| static void virtio_register_types(void) | ||
| { | ||
| type_register_static(&virtio_pmem_info); | ||
| } | ||
|
|
||
| type_init(virtio_register_types) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Virtio pmem Device | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| #ifndef QEMU_VIRTIO_PMEM_H | ||
| #define QEMU_VIRTIO_PMEM_H | ||
|
|
||
| #include "hw/virtio/virtio.h" | ||
| #include "exec/memory.h" | ||
| #include "sysemu/hostmem.h" | ||
| #include "standard-headers/linux/virtio_ids.h" | ||
| #include "hw/boards.h" | ||
| #include "hw/i386/pc.h" | ||
|
|
||
| #define VIRTIO_PMEM_PLUG 0 | ||
|
|
||
| #define TYPE_VIRTIO_PMEM "virtio-pmem" | ||
|
|
||
| #define VIRTIO_PMEM(obj) \ | ||
| OBJECT_CHECK(VirtIOPMEM, (obj), TYPE_VIRTIO_PMEM) | ||
|
|
||
| typedef struct VirtIOPMEM { | ||
|
|
||
| VirtIODevice parent_obj; | ||
| uint64_t start; | ||
| uint64_t size; | ||
| uint64_t align; | ||
|
|
||
| VirtQueue *rq_vq; | ||
| MemoryRegion *mr; | ||
| HostMemoryBackend *memdev; | ||
| } VirtIOPMEM; | ||
|
|
||
| struct virtio_pmem_config { | ||
|
|
||
| uint64_t start; | ||
| uint64_t size; | ||
| uint64_t align; | ||
| }; | ||
|
|
||
| //bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); | ||
|
|
||
| #endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters