1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "qemu/osdep.h"
17
18#include "hw/qdev-properties.h"
19#include "hw/virtio/virtio-scsi.h"
20#include "qemu/module.h"
21#include "virtio-pci.h"
22#include "qom/object.h"
23
24typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
25
26
27
28
29#define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci-base"
30DECLARE_INSTANCE_CHECKER(VirtIOSCSIPCI, VIRTIO_SCSI_PCI,
31 TYPE_VIRTIO_SCSI_PCI)
32
33struct VirtIOSCSIPCI {
34 VirtIOPCIProxy parent_obj;
35 VirtIOSCSI vdev;
36};
37
38static Property virtio_scsi_pci_properties[] = {
39 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
40 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
41 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
42 DEV_NVECTORS_UNSPECIFIED),
43 DEFINE_PROP_END_OF_LIST(),
44};
45
46static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
47{
48 VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev);
49 DeviceState *vdev = DEVICE(&dev->vdev);
50 DeviceState *proxy = DEVICE(vpci_dev);
51 VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;
52 char *bus_name;
53
54 if (conf->num_queues == VIRTIO_SCSI_AUTO_NUM_QUEUES) {
55 conf->num_queues =
56 virtio_pci_optimal_num_queues(VIRTIO_SCSI_VQ_NUM_FIXED);
57 }
58
59 if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
60 vpci_dev->nvectors = conf->num_queues + VIRTIO_SCSI_VQ_NUM_FIXED + 1;
61 }
62
63
64
65
66
67 if (proxy->id) {
68 bus_name = g_strdup_printf("%s.0", proxy->id);
69 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
70 g_free(bus_name);
71 }
72
73 qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
74}
75
76static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data)
77{
78 DeviceClass *dc = DEVICE_CLASS(klass);
79 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
80 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
81
82 k->realize = virtio_scsi_pci_realize;
83 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
84 device_class_set_props(dc, virtio_scsi_pci_properties);
85 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
86 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
87 pcidev_k->revision = 0x00;
88 pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
89}
90
91static void virtio_scsi_pci_instance_init(Object *obj)
92{
93 VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj);
94
95 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
96 TYPE_VIRTIO_SCSI);
97}
98
99static const VirtioPCIDeviceTypeInfo virtio_scsi_pci_info = {
100 .base_name = TYPE_VIRTIO_SCSI_PCI,
101 .generic_name = "virtio-scsi-pci",
102 .transitional_name = "virtio-scsi-pci-transitional",
103 .non_transitional_name = "virtio-scsi-pci-non-transitional",
104 .instance_size = sizeof(VirtIOSCSIPCI),
105 .instance_init = virtio_scsi_pci_instance_init,
106 .class_init = virtio_scsi_pci_class_init,
107};
108
109static void virtio_scsi_pci_register(void)
110{
111 virtio_pci_types_register(&virtio_scsi_pci_info);
112}
113
114type_init(virtio_scsi_pci_register)
115