@@ -16,6 +16,8 @@
#include "trace.h"
#include "hw/block-common.h"
#include "blockdev.h"
+#include "virtio-transport.h"
+#include "virtio-pci.h"
#include "virtio-blk.h"
#include "scsi-defs.h"
#ifdef __linux__
@@ -665,3 +667,66 @@ void virtio_blk_exit(VirtIODevice *vdev)
blockdev_mark_auto_del(s->bs);
virtio_cleanup(vdev);
}
+
+/******************** VirtIOBlk Device **********************/
+
+static int virtio_blkdev_init(DeviceState *dev)
+{
+ VirtIODevice *vdev;
+ VirtIOBlockState *s = VIRTIO_BLK_FROM_QDEV(dev);
+
+ assert(s->trl != NULL);
+
+ vdev = virtio_blk_init(dev, &s->blk);
+ if (!vdev) {
+ return -1;
+ }
+
+ /* Pass default host_features to transport */
+ s->trl->host_features = s->host_features;
+
+ if (virtio_call_backend_init_cb(dev, s->trl, vdev) != 0) {
+ return -1;
+ }
+
+ /* Binding should be ready here, let's get final features */
+ if (vdev->binding->get_features) {
+ s->host_features = vdev->binding->get_features(vdev->binding_opaque);
+ }
+ return 0;
+}
+
+static Property virtio_blkdev_properties[] = {
+ DEFINE_BLOCK_PROPERTIES(VirtIOBlockState, blk.conf),
+ DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlockState, blk.conf),
+ DEFINE_PROP_STRING("serial", VirtIOBlockState, blk.serial),
+#ifdef __linux__
+ DEFINE_PROP_BIT("scsi", VirtIOBlockState, blk.scsi, 0, true),
+#endif
+ DEFINE_PROP_BIT("config-wce", VirtIOBlockState, blk.config_wce, 0, true),
+ DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlockState, host_features),
+
+ DEFINE_PROP_TRANSPORT("transport", VirtIOBlockState, trl),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blkdev_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ dc->init = virtio_blkdev_init;
+ dc->props = virtio_blkdev_properties;
+}
+
+static TypeInfo virtio_blkdev_info = {
+ .name = "virtio-blk",
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(VirtIOBlockState),
+ .class_init = virtio_blkdev_class_init,
+};
+
+static void virtio_blk_register_types(void)
+{
+ type_register_static(&virtio_blkdev_info);
+}
+
+type_init(virtio_blk_register_types)
@@ -14,7 +14,9 @@
#ifndef _QEMU_VIRTIO_BLK_H
#define _QEMU_VIRTIO_BLK_H
+#include "sysbus.h"
#include "virtio.h"
+#include "virtio-transport.h"
#include "hw/block-common.h"
/* from Linux's linux/virtio_blk.h */
@@ -111,4 +113,17 @@ struct VirtIOBlkConf
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)
+
+typedef struct {
+ DeviceState qdev;
+ /* virtio-blk */
+ VirtIOBlkConf blk;
+
+ uint32_t host_features;
+
+ VirtIOTransportLink *trl;
+} VirtIOBlockState;
+
+#define VIRTIO_BLK_FROM_QDEV(dev) DO_UPCAST(VirtIOBlockState, qdev, dev)
+
#endif
Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com> --- hw/virtio-blk.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-blk.h | 15 +++++++++++++ 2 files changed, 80 insertions(+)