1 /* 2 * Virtio scsi PCI Bindings 3 * 4 * Copyright IBM, Corp. 2007 5 * Copyright (c) 2009 CodeSourcery 6 * 7 * Authors: 8 * Anthony Liguori <aliguori@us.ibm.com> 9 * Paul Brook <paul@codesourcery.com> 10 * 11 * This work is licensed under the terms of the GNU GPL, version 2 or 12 * (at your option) any later version. See the COPYING file in the 13 * top-level directory. 14 */ 15 16 #include "qemu/osdep.h" 17 18 #include "hw/qdev-properties.h" 19 #include "hw/virtio/virtio-scsi.h" 20 #include "qemu/module.h" 21 #include "virtio-pci.h" 22 23 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; 24 25 /* 26 * virtio-scsi-pci: This extends VirtioPCIProxy. 27 */ 28 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci-base" 29 #define VIRTIO_SCSI_PCI(obj) \ 30 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI) 31 32 struct VirtIOSCSIPCI { 33 VirtIOPCIProxy parent_obj; 34 VirtIOSCSI vdev; 35 }; 36 37 static Property virtio_scsi_pci_properties[] = { 38 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, 39 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), 40 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 41 DEV_NVECTORS_UNSPECIFIED), 42 DEFINE_PROP_END_OF_LIST(), 43 }; 44 45 static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 46 { 47 VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev); 48 DeviceState *vdev = DEVICE(&dev->vdev); 49 DeviceState *proxy = DEVICE(vpci_dev); 50 VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf; 51 char *bus_name; 52 53 if (conf->num_queues == VIRTIO_SCSI_AUTO_NUM_QUEUES) { 54 conf->num_queues = 55 virtio_pci_optimal_num_queues(VIRTIO_SCSI_VQ_NUM_FIXED); 56 } 57 58 if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { 59 vpci_dev->nvectors = conf->num_queues + VIRTIO_SCSI_VQ_NUM_FIXED + 1; 60 } 61 62 /* 63 * For command line compatibility, this sets the virtio-scsi-device bus 64 * name as before. 65 */ 66 if (proxy->id) { 67 bus_name = g_strdup_printf("%s.0", proxy->id); 68 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); 69 g_free(bus_name); 70 } 71 72 qdev_realize(vdev, BUS(&vpci_dev->bus), errp); 73 } 74 75 static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data) 76 { 77 DeviceClass *dc = DEVICE_CLASS(klass); 78 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 79 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 80 81 k->realize = virtio_scsi_pci_realize; 82 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 83 device_class_set_props(dc, virtio_scsi_pci_properties); 84 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 85 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; 86 pcidev_k->revision = 0x00; 87 pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; 88 } 89 90 static void virtio_scsi_pci_instance_init(Object *obj) 91 { 92 VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj); 93 94 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 95 TYPE_VIRTIO_SCSI); 96 } 97 98 static const VirtioPCIDeviceTypeInfo virtio_scsi_pci_info = { 99 .base_name = TYPE_VIRTIO_SCSI_PCI, 100 .generic_name = "virtio-scsi-pci", 101 .transitional_name = "virtio-scsi-pci-transitional", 102 .non_transitional_name = "virtio-scsi-pci-non-transitional", 103 .instance_size = sizeof(VirtIOSCSIPCI), 104 .instance_init = virtio_scsi_pci_instance_init, 105 .class_init = virtio_scsi_pci_class_init, 106 }; 107 108 static void virtio_scsi_pci_register(void) 109 { 110 virtio_pci_types_register(&virtio_scsi_pci_info); 111 } 112 113 type_init(virtio_scsi_pci_register) 114