xref: /openbmc/qemu/hw/virtio/vhost-scsi-pci.c (revision e1b1f534)
1 /*
2  * Vhost scsi PCI bindings
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Stefan Hajnoczi   <stefanha@linux.vnet.ibm.com>
8  *
9  * Changes for QEMU mainline + tcm_vhost kernel upstream:
10  *  Nicholas Bellinger <nab@risingtidesystems.com>
11  *
12  * This work is licensed under the terms of the GNU LGPL, version 2 or later.
13  * See the COPYING.LIB file in the top-level directory.
14  *
15  */
16 
17 #include "qemu/osdep.h"
18 
19 #include "standard-headers/linux/virtio_pci.h"
20 #include "hw/qdev-properties.h"
21 #include "hw/virtio/vhost-scsi.h"
22 #include "qapi/error.h"
23 #include "qemu/module.h"
24 #include "hw/virtio/virtio-pci.h"
25 #include "qom/object.h"
26 
27 typedef struct VHostSCSIPCI VHostSCSIPCI;
28 
29 /*
30  * vhost-scsi-pci: This extends VirtioPCIProxy.
31  */
32 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci-base"
33 DECLARE_INSTANCE_CHECKER(VHostSCSIPCI, VHOST_SCSI_PCI,
34                          TYPE_VHOST_SCSI_PCI)
35 
36 struct VHostSCSIPCI {
37     VirtIOPCIProxy parent_obj;
38     VHostSCSI vdev;
39 };
40 
41 static Property vhost_scsi_pci_properties[] = {
42     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
43                        DEV_NVECTORS_UNSPECIFIED),
44     DEFINE_PROP_END_OF_LIST(),
45 };
46 
vhost_scsi_pci_realize(VirtIOPCIProxy * vpci_dev,Error ** errp)47 static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
48 {
49     VHostSCSIPCI *dev = VHOST_SCSI_PCI(vpci_dev);
50     DeviceState *vdev = DEVICE(&dev->vdev);
51     VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf;
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     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
63 }
64 
vhost_scsi_pci_class_init(ObjectClass * klass,void * data)65 static void vhost_scsi_pci_class_init(ObjectClass *klass, void *data)
66 {
67     DeviceClass *dc = DEVICE_CLASS(klass);
68     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
69     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
70     k->realize = vhost_scsi_pci_realize;
71     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
72     device_class_set_props(dc, vhost_scsi_pci_properties);
73     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
74     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
75     pcidev_k->revision = 0x00;
76     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
77 }
78 
vhost_scsi_pci_instance_init(Object * obj)79 static void vhost_scsi_pci_instance_init(Object *obj)
80 {
81     VHostSCSIPCI *dev = VHOST_SCSI_PCI(obj);
82 
83     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
84                                 TYPE_VHOST_SCSI);
85     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
86                               "bootindex");
87 }
88 
89 static const VirtioPCIDeviceTypeInfo vhost_scsi_pci_info = {
90     .base_name             = TYPE_VHOST_SCSI_PCI,
91     .generic_name          = "vhost-scsi-pci",
92     .transitional_name     = "vhost-scsi-pci-transitional",
93     .non_transitional_name = "vhost-scsi-pci-non-transitional",
94     .instance_size = sizeof(VHostSCSIPCI),
95     .instance_init = vhost_scsi_pci_instance_init,
96     .class_init    = vhost_scsi_pci_class_init,
97 };
98 
vhost_scsi_pci_register(void)99 static void vhost_scsi_pci_register(void)
100 {
101     virtio_pci_types_register(&vhost_scsi_pci_info);
102 }
103 
104 type_init(vhost_scsi_pci_register)
105