summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKONRAD Frederic <fred.konrad@greensocs.com>2013-03-21 15:15:14 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2013-03-26 09:26:36 -0500
commit3ab1dfdd50a7c852e4921935250c22f486c5b8a4 (patch)
tree9da613cff82b0068eefce42c89893f196f4c3a71
parent4bfeb18a454bd71c406683fb473375e02c724b00 (diff)
downloadqemu-3ab1dfdd50a7c852e4921935250c22f486c5b8a4.tar.gz
qemu-3ab1dfdd50a7c852e4921935250c22f486c5b8a4.tar.bz2
qemu-3ab1dfdd50a7c852e4921935250c22f486c5b8a4.zip
virtio-scsi: add the virtio-scsi device.
Create virtio-scsi which extends virtio-device, so it can be connected on virtio-bus. Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com> Message-id: 1363875320-7985-5-git-send-email-fred.konrad@greensocs.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/virtio-scsi.c85
-rw-r--r--hw/virtio-scsi.h5
2 files changed, 85 insertions, 5 deletions
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 08fcb80b1b..56d1b272f7 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -17,6 +17,7 @@
#include "qemu/error-report.h"
#include <hw/scsi.h>
#include <hw/scsi-defs.h>
+#include "hw/virtio-bus.h"
#define VIRTIO_SCSI_VQ_SIZE 128
#define VIRTIO_SCSI_CDB_SIZE 32
@@ -686,15 +687,30 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = {
.load_request = virtio_scsi_load_request,
};
-VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
+static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
+ VirtIOSCSIConf *proxyconf,
+ VirtIOSCSI **ps)
{
- VirtIOSCSI *s;
+ VirtIOSCSI *s = *ps;
static int virtio_scsi_id;
int i;
- s = (VirtIOSCSI *)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI,
- sizeof(VirtIOSCSIConfig),
- sizeof(VirtIOSCSI));
+ /*
+ * We have two cases here: the old virtio-scsi-pci device, and the
+ * refactored virtio-scsi.
+ */
+
+ if (s == NULL) {
+ /* virtio-scsi-pci */
+ s = (VirtIOSCSI *)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI,
+ sizeof(VirtIOSCSIConfig),
+ sizeof(VirtIOSCSI));
+ } else {
+ /* virtio-scsi */
+ virtio_init(VIRTIO_DEVICE(s), "virtio-scsi", VIRTIO_ID_SCSI,
+ sizeof(VirtIOSCSIConfig));
+ }
+
s->cmd_vqs = g_malloc0(proxyconf->num_queues * sizeof(VirtQueue *));
s->qdev = dev;
@@ -726,6 +742,12 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
return &s->vdev;
}
+VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
+{
+ VirtIOSCSI *s = NULL;
+ return virtio_scsi_common_init(dev, proxyconf, &s);
+}
+
void virtio_scsi_exit(VirtIODevice *vdev)
{
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
@@ -733,3 +755,56 @@ void virtio_scsi_exit(VirtIODevice *vdev)
g_free(s->cmd_vqs);
virtio_cleanup(vdev);
}
+
+static int virtio_scsi_device_init(VirtIODevice *vdev)
+{
+ DeviceState *qdev = DEVICE(vdev);
+ VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+ if (virtio_scsi_common_init(qdev, &(s->conf), &s) == NULL) {
+ return -1;
+ }
+ return 0;
+}
+
+static int virtio_scsi_device_exit(DeviceState *qdev)
+{
+ VirtIOSCSI *s = VIRTIO_SCSI(qdev);
+ VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+
+ unregister_savevm(qdev, "virtio-scsi", s);
+ g_free(s->cmd_vqs);
+ virtio_common_cleanup(vdev);
+ return 0;
+}
+
+static Property virtio_scsi_properties[] = {
+ DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSI, conf),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_scsi_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+ dc->exit = virtio_scsi_device_exit;
+ dc->props = virtio_scsi_properties;
+ vdc->init = virtio_scsi_device_init;
+ vdc->get_config = virtio_scsi_get_config;
+ vdc->set_config = virtio_scsi_set_config;
+ vdc->get_features = virtio_scsi_get_features;
+ vdc->reset = virtio_scsi_reset;
+}
+
+static const TypeInfo virtio_scsi_info = {
+ .name = TYPE_VIRTIO_SCSI,
+ .parent = TYPE_VIRTIO_DEVICE,
+ .instance_size = sizeof(VirtIOSCSI),
+ .class_init = virtio_scsi_class_init,
+};
+
+static void virtio_register_types(void)
+{
+ type_register_static(&virtio_scsi_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index da02f08b28..758c29bafa 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -18,6 +18,11 @@
#include "hw/pci/pci.h"
#include "hw/scsi.h"
+#define TYPE_VIRTIO_SCSI "virtio-scsi"
+#define VIRTIO_SCSI(obj) \
+ OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
+
+
/* The ID for virtio_scsi */
#define VIRTIO_ID_SCSI 8