xref: /openbmc/qemu/hw/s390x/virtio-ccw-scsi.c (revision 1be5a765c08cee3a9587c8a8d3fc2ea247b13f9c)
1e594bfedSThomas Huth /*
2e594bfedSThomas Huth  * virtio ccw scsi implementation
3e594bfedSThomas Huth  *
4e594bfedSThomas Huth  * Copyright 2012, 2015 IBM Corp.
5e594bfedSThomas Huth  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6e594bfedSThomas Huth  *
7e594bfedSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8e594bfedSThomas Huth  * your option) any later version. See the COPYING file in the top-level
9e594bfedSThomas Huth  * directory.
10e594bfedSThomas Huth  */
11e594bfedSThomas Huth 
12e594bfedSThomas Huth #include "qemu/osdep.h"
13a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
14e594bfedSThomas Huth #include "hw/virtio/virtio.h"
15e594bfedSThomas Huth #include "qapi/error.h"
160b8fa32fSMarkus Armbruster #include "qemu/module.h"
17e594bfedSThomas Huth #include "virtio-ccw.h"
18*7da50d64SPaolo Bonzini #include "hw/virtio/virtio-scsi.h"
19*7da50d64SPaolo Bonzini 
20*7da50d64SPaolo Bonzini #define TYPE_VIRTIO_SCSI_CCW "virtio-scsi-ccw"
21*7da50d64SPaolo Bonzini OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSICcw, VIRTIO_SCSI_CCW)
22*7da50d64SPaolo Bonzini 
23*7da50d64SPaolo Bonzini struct VirtIOSCSICcw {
24*7da50d64SPaolo Bonzini     VirtioCcwDevice parent_obj;
25*7da50d64SPaolo Bonzini     VirtIOSCSI vdev;
26*7da50d64SPaolo Bonzini };
27e594bfedSThomas Huth 
virtio_ccw_scsi_realize(VirtioCcwDevice * ccw_dev,Error ** errp)28e594bfedSThomas Huth static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
29e594bfedSThomas Huth {
30e594bfedSThomas Huth     VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
31e594bfedSThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
32e594bfedSThomas Huth     DeviceState *qdev = DEVICE(ccw_dev);
33e594bfedSThomas Huth     char *bus_name;
34e594bfedSThomas Huth 
35e594bfedSThomas Huth     /*
36e594bfedSThomas Huth      * For command line compatibility, this sets the virtio-scsi-device bus
37e594bfedSThomas Huth      * name as before.
38e594bfedSThomas Huth      */
39e594bfedSThomas Huth     if (qdev->id) {
40e594bfedSThomas Huth         bus_name = g_strdup_printf("%s.0", qdev->id);
41e594bfedSThomas Huth         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
42e594bfedSThomas Huth         g_free(bus_name);
43e594bfedSThomas Huth     }
44e594bfedSThomas Huth 
4599ba777eSMarkus Armbruster     qdev_realize(vdev, BUS(&ccw_dev->bus), errp);
46e594bfedSThomas Huth }
47e594bfedSThomas Huth 
virtio_ccw_scsi_instance_init(Object * obj)48e594bfedSThomas Huth static void virtio_ccw_scsi_instance_init(Object *obj)
49e594bfedSThomas Huth {
50e594bfedSThomas Huth     VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
51e594bfedSThomas Huth 
52e594bfedSThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
53e594bfedSThomas Huth                                 TYPE_VIRTIO_SCSI);
54e594bfedSThomas Huth }
55e594bfedSThomas Huth 
56e594bfedSThomas Huth static Property virtio_ccw_scsi_properties[] = {
57e594bfedSThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
58e594bfedSThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
59e594bfedSThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
60e594bfedSThomas Huth                        VIRTIO_CCW_MAX_REV),
61e594bfedSThomas Huth     DEFINE_PROP_END_OF_LIST(),
62e594bfedSThomas Huth };
63e594bfedSThomas Huth 
virtio_ccw_scsi_class_init(ObjectClass * klass,void * data)64e594bfedSThomas Huth static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
65e594bfedSThomas Huth {
66e594bfedSThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
67e594bfedSThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
68e594bfedSThomas Huth 
69e594bfedSThomas Huth     k->realize = virtio_ccw_scsi_realize;
704f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_ccw_scsi_properties);
71e594bfedSThomas Huth     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
72e594bfedSThomas Huth }
73e594bfedSThomas Huth 
74e594bfedSThomas Huth static const TypeInfo virtio_ccw_scsi = {
75e594bfedSThomas Huth     .name          = TYPE_VIRTIO_SCSI_CCW,
76e594bfedSThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
77e594bfedSThomas Huth     .instance_size = sizeof(VirtIOSCSICcw),
78e594bfedSThomas Huth     .instance_init = virtio_ccw_scsi_instance_init,
79e594bfedSThomas Huth     .class_init    = virtio_ccw_scsi_class_init,
80e594bfedSThomas Huth };
81e594bfedSThomas Huth 
virtio_ccw_scsi_register(void)82e594bfedSThomas Huth static void virtio_ccw_scsi_register(void)
83e594bfedSThomas Huth {
84e594bfedSThomas Huth     type_register_static(&virtio_ccw_scsi);
85e594bfedSThomas Huth }
86e594bfedSThomas Huth 
87e594bfedSThomas Huth type_init(virtio_ccw_scsi_register)
88