hw/riscv: Move sifive_u_otp model to hw/misc
[qemu/ar7.git] / hw / virtio / vhost-user-blk-pci.c
bloba62a71e067b478f5ed987f2d779e4eae4386b443
1 /*
2 * Vhost user blk PCI Bindings
4 * Copyright(C) 2017 Intel Corporation.
6 * Authors:
7 * Changpeng Liu <changpeng.liu@intel.com>
9 * Largely based on the "vhost-user-scsi.c" and "vhost-scsi.c" implemented by:
10 * Felipe Franciosi <felipe@nutanix.com>
11 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
12 * Nicholas Bellinger <nab@risingtidesystems.com>
14 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
15 * See the COPYING.LIB file in the top-level directory.
19 #include "qemu/osdep.h"
21 #include "standard-headers/linux/virtio_pci.h"
22 #include "hw/virtio/virtio.h"
23 #include "hw/virtio/vhost-user-blk.h"
24 #include "hw/pci/pci.h"
25 #include "hw/qdev-properties.h"
26 #include "qapi/error.h"
27 #include "qemu/error-report.h"
28 #include "qemu/module.h"
29 #include "virtio-pci.h"
31 typedef struct VHostUserBlkPCI VHostUserBlkPCI;
34 * vhost-user-blk-pci: This extends VirtioPCIProxy.
36 #define TYPE_VHOST_USER_BLK_PCI "vhost-user-blk-pci-base"
37 #define VHOST_USER_BLK_PCI(obj) \
38 OBJECT_CHECK(VHostUserBlkPCI, (obj), TYPE_VHOST_USER_BLK_PCI)
40 struct VHostUserBlkPCI {
41 VirtIOPCIProxy parent_obj;
42 VHostUserBlk vdev;
45 static Property vhost_user_blk_pci_properties[] = {
46 DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
47 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
48 DEV_NVECTORS_UNSPECIFIED),
49 DEFINE_PROP_END_OF_LIST(),
52 static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
54 VHostUserBlkPCI *dev = VHOST_USER_BLK_PCI(vpci_dev);
55 DeviceState *vdev = DEVICE(&dev->vdev);
57 if (dev->vdev.num_queues == VHOST_USER_BLK_AUTO_NUM_QUEUES) {
58 dev->vdev.num_queues = virtio_pci_optimal_num_queues(0);
61 if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
62 vpci_dev->nvectors = dev->vdev.num_queues + 1;
65 qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
68 static void vhost_user_blk_pci_class_init(ObjectClass *klass, void *data)
70 DeviceClass *dc = DEVICE_CLASS(klass);
71 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
72 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
74 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
75 device_class_set_props(dc, vhost_user_blk_pci_properties);
76 k->realize = vhost_user_blk_pci_realize;
77 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
78 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
79 pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
80 pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
83 static void vhost_user_blk_pci_instance_init(Object *obj)
85 VHostUserBlkPCI *dev = VHOST_USER_BLK_PCI(obj);
87 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
88 TYPE_VHOST_USER_BLK);
89 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
90 "bootindex");
93 static const VirtioPCIDeviceTypeInfo vhost_user_blk_pci_info = {
94 .base_name = TYPE_VHOST_USER_BLK_PCI,
95 .generic_name = "vhost-user-blk-pci",
96 .transitional_name = "vhost-user-blk-pci-transitional",
97 .non_transitional_name = "vhost-user-blk-pci-non-transitional",
98 .instance_size = sizeof(VHostUserBlkPCI),
99 .instance_init = vhost_user_blk_pci_instance_init,
100 .class_init = vhost_user_blk_pci_class_init,
103 static void vhost_user_blk_pci_register(void)
105 virtio_pci_types_register(&vhost_user_blk_pci_info);
108 type_init(vhost_user_blk_pci_register)