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