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/virtio/virtio-scsi.h" 19 #include "qemu/module.h" 20 #include "virtio-pci.h" 21 22 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; 23 24 /* 25 * virtio-scsi-pci: This extends VirtioPCIProxy. 26 */ 27 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci-base" 28 #define VIRTIO_SCSI_PCI(obj) \ 29 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI) 30 31 struct VirtIOSCSIPCI { 32 VirtIOPCIProxy parent_obj; 33 VirtIOSCSI vdev; 34 }; 35 36 static Property virtio_scsi_pci_properties[] = { 37 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, 38 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), 39 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 40 DEV_NVECTORS_UNSPECIFIED), 41 DEFINE_PROP_END_OF_LIST(), 42 }; 43 44 static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 45 { 46 VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev); 47 DeviceState *vdev = DEVICE(&dev->vdev); 48 VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); 49 DeviceState *proxy = DEVICE(vpci_dev); 50 char *bus_name; 51 52 if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { 53 vpci_dev->nvectors = vs->conf.num_queues + 3; 54 } 55 56 /* 57 * For command line compatibility, this sets the virtio-scsi-device bus 58 * name as before. 59 */ 60 if (proxy->id) { 61 bus_name = g_strdup_printf("%s.0", proxy->id); 62 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); 63 g_free(bus_name); 64 } 65 66 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 67 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 68 } 69 70 static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data) 71 { 72 DeviceClass *dc = DEVICE_CLASS(klass); 73 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 74 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 75 76 k->realize = virtio_scsi_pci_realize; 77 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 78 dc->props = virtio_scsi_pci_properties; 79 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 80 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; 81 pcidev_k->revision = 0x00; 82 pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; 83 } 84 85 static void virtio_scsi_pci_instance_init(Object *obj) 86 { 87 VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj); 88 89 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 90 TYPE_VIRTIO_SCSI); 91 } 92 93 static const VirtioPCIDeviceTypeInfo virtio_scsi_pci_info = { 94 .base_name = TYPE_VIRTIO_SCSI_PCI, 95 .generic_name = "virtio-scsi-pci", 96 .transitional_name = "virtio-scsi-pci-transitional", 97 .non_transitional_name = "virtio-scsi-pci-non-transitional", 98 .instance_size = sizeof(VirtIOSCSIPCI), 99 .instance_init = virtio_scsi_pci_instance_init, 100 .class_init = virtio_scsi_pci_class_init, 101 }; 102 103 static void virtio_scsi_pci_register(void) 104 { 105 virtio_pci_types_register(&virtio_scsi_pci_info); 106 } 107 108 type_init(virtio_scsi_pci_register) 109