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