]>
Commit | Line | Data |
---|---|---|
693510dd JQ |
1 | /* |
2 | * Vhost user scsi PCI Bindings | |
3 | * | |
4 | * Copyright (c) 2016 Nutanix Inc. All rights reserved. | |
5 | * | |
6 | * Author: | |
7 | * Felipe Franciosi <felipe@nutanix.com> | |
8 | * | |
9 | * This work is largely based on the "vhost-scsi" implementation by: | |
10 | * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | |
11 | * Nicholas Bellinger <nab@risingtidesystems.com> | |
12 | * | |
13 | * This work is licensed under the terms of the GNU LGPL, version 2 or later. | |
14 | * See the COPYING.LIB file in the top-level directory. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include "qemu/osdep.h" | |
19 | ||
20 | #include "standard-headers/linux/virtio_pci.h" | |
21 | #include "hw/virtio/vhost-user-scsi.h" | |
22 | #include "hw/virtio/virtio.h" | |
23 | #include "hw/virtio/virtio-scsi.h" | |
24 | #include "hw/pci/pci.h" | |
a27bd6c7 | 25 | #include "hw/qdev-properties.h" |
693510dd JQ |
26 | #include "qapi/error.h" |
27 | #include "qemu/error-report.h" | |
0b8fa32f | 28 | #include "qemu/module.h" |
693510dd JQ |
29 | #include "hw/pci/msi.h" |
30 | #include "hw/pci/msix.h" | |
31 | #include "hw/loader.h" | |
32 | #include "sysemu/kvm.h" | |
33 | #include "virtio-pci.h" | |
34 | ||
35 | typedef struct VHostUserSCSIPCI VHostUserSCSIPCI; | |
36 | ||
37 | #define TYPE_VHOST_USER_SCSI_PCI "vhost-user-scsi-pci-base" | |
38 | #define VHOST_USER_SCSI_PCI(obj) \ | |
39 | OBJECT_CHECK(VHostUserSCSIPCI, (obj), TYPE_VHOST_USER_SCSI_PCI) | |
40 | ||
41 | struct VHostUserSCSIPCI { | |
42 | VirtIOPCIProxy parent_obj; | |
43 | VHostUserSCSI vdev; | |
44 | }; | |
45 | ||
46 | static Property vhost_user_scsi_pci_properties[] = { | |
47 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | |
48 | DEV_NVECTORS_UNSPECIFIED), | |
49 | DEFINE_PROP_END_OF_LIST(), | |
50 | }; | |
51 | ||
52 | static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | |
53 | { | |
54 | VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(vpci_dev); | |
55 | DeviceState *vdev = DEVICE(&dev->vdev); | |
56 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); | |
57 | ||
58 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | |
59 | vpci_dev->nvectors = vs->conf.num_queues + 3; | |
60 | } | |
61 | ||
62 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | |
63 | object_property_set_bool(OBJECT(vdev), true, "realized", errp); | |
64 | } | |
65 | ||
66 | static void vhost_user_scsi_pci_class_init(ObjectClass *klass, void *data) | |
67 | { | |
68 | DeviceClass *dc = DEVICE_CLASS(klass); | |
69 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | |
70 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | |
71 | k->realize = vhost_user_scsi_pci_realize; | |
72 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | |
4f67d30b | 73 | device_class_set_props(dc, vhost_user_scsi_pci_properties); |
693510dd JQ |
74 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; |
75 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; | |
76 | pcidev_k->revision = 0x00; | |
77 | pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; | |
78 | } | |
79 | ||
80 | static void vhost_user_scsi_pci_instance_init(Object *obj) | |
81 | { | |
82 | VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(obj); | |
83 | ||
84 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | |
85 | TYPE_VHOST_USER_SCSI); | |
86 | object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), | |
d2623129 | 87 | "bootindex"); |
693510dd JQ |
88 | } |
89 | ||
90 | static const VirtioPCIDeviceTypeInfo vhost_user_scsi_pci_info = { | |
91 | .base_name = TYPE_VHOST_USER_SCSI_PCI, | |
92 | .generic_name = "vhost-user-scsi-pci", | |
93 | .transitional_name = "vhost-user-scsi-pci-transitional", | |
94 | .non_transitional_name = "vhost-user-scsi-pci-non-transitional", | |
95 | .instance_size = sizeof(VHostUserSCSIPCI), | |
96 | .instance_init = vhost_user_scsi_pci_instance_init, | |
97 | .class_init = vhost_user_scsi_pci_class_init, | |
98 | }; | |
99 | ||
100 | static void vhost_user_scsi_pci_register(void) | |
101 | { | |
102 | virtio_pci_types_register(&vhost_user_scsi_pci_info); | |
103 | } | |
104 | ||
105 | type_init(vhost_user_scsi_pci_register) |