xref: /openbmc/qemu/hw/virtio/vhost-scsi-pci.c (revision 500eb6db)
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/virtio/vhost-scsi.h"
21 #include "qapi/error.h"
22 #include "qemu/module.h"
23 #include "virtio-pci.h"
24 
25 typedef struct VHostSCSIPCI VHostSCSIPCI;
26 
27 /*
28  * vhost-scsi-pci: This extends VirtioPCIProxy.
29  */
30 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci-base"
31 #define VHOST_SCSI_PCI(obj) \
32         OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
33 
34 struct VHostSCSIPCI {
35     VirtIOPCIProxy parent_obj;
36     VHostSCSI vdev;
37 };
38 
39 static Property vhost_scsi_pci_properties[] = {
40     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
41                        DEV_NVECTORS_UNSPECIFIED),
42     DEFINE_PROP_END_OF_LIST(),
43 };
44 
45 static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
46 {
47     VHostSCSIPCI *dev = VHOST_SCSI_PCI(vpci_dev);
48     DeviceState *vdev = DEVICE(&dev->vdev);
49     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
50 
51     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
52         vpci_dev->nvectors = vs->conf.num_queues + 3;
53     }
54 
55     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
56     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
57 }
58 
59 static void vhost_scsi_pci_class_init(ObjectClass *klass, void *data)
60 {
61     DeviceClass *dc = DEVICE_CLASS(klass);
62     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
63     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
64     k->realize = vhost_scsi_pci_realize;
65     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
66     dc->props = vhost_scsi_pci_properties;
67     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
68     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
69     pcidev_k->revision = 0x00;
70     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
71 }
72 
73 static void vhost_scsi_pci_instance_init(Object *obj)
74 {
75     VHostSCSIPCI *dev = VHOST_SCSI_PCI(obj);
76 
77     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
78                                 TYPE_VHOST_SCSI);
79     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
80                               "bootindex", &error_abort);
81 }
82 
83 static const VirtioPCIDeviceTypeInfo vhost_scsi_pci_info = {
84     .base_name             = TYPE_VHOST_SCSI_PCI,
85     .generic_name          = "vhost-scsi-pci",
86     .transitional_name     = "vhost-scsi-pci-transitional",
87     .non_transitional_name = "vhost-scsi-pci-non-transitional",
88     .instance_size = sizeof(VHostSCSIPCI),
89     .instance_init = vhost_scsi_pci_instance_init,
90     .class_init    = vhost_scsi_pci_class_init,
91 };
92 
93 static void vhost_scsi_pci_register(void)
94 {
95     virtio_pci_types_register(&vhost_scsi_pci_info);
96 }
97 
98 type_init(vhost_scsi_pci_register)
99