Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Vhost-user filesystem virtio device PCI glue |
| 3 | * |
| 4 | * Copyright 2018-2019 Red Hat, Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Dr. David Alan Gilbert <dgilbert@redhat.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or |
| 10 | * (at your option) any later version. See the COPYING file in the |
| 11 | * top-level directory. |
| 12 | */ |
| 13 | |
| 14 | #include "qemu/osdep.h" |
| 15 | #include "hw/qdev-properties.h" |
| 16 | #include "hw/virtio/vhost-user-fs.h" |
| 17 | #include "virtio-pci.h" |
| 18 | |
| 19 | struct VHostUserFSPCI { |
| 20 | VirtIOPCIProxy parent_obj; |
| 21 | VHostUserFS vdev; |
| 22 | }; |
| 23 | |
| 24 | typedef struct VHostUserFSPCI VHostUserFSPCI; |
| 25 | |
| 26 | #define TYPE_VHOST_USER_FS_PCI "vhost-user-fs-pci-base" |
| 27 | |
| 28 | #define VHOST_USER_FS_PCI(obj) \ |
| 29 | OBJECT_CHECK(VHostUserFSPCI, (obj), TYPE_VHOST_USER_FS_PCI) |
| 30 | |
| 31 | static Property vhost_user_fs_pci_properties[] = { |
| 32 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, |
| 33 | DEV_NVECTORS_UNSPECIFIED), |
| 34 | DEFINE_PROP_END_OF_LIST(), |
| 35 | }; |
| 36 | |
| 37 | static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
| 38 | { |
| 39 | VHostUserFSPCI *dev = VHOST_USER_FS_PCI(vpci_dev); |
| 40 | DeviceState *vdev = DEVICE(&dev->vdev); |
| 41 | |
| 42 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { |
| 43 | vpci_dev->nvectors = dev->vdev.conf.num_request_queues + 1; |
| 44 | } |
| 45 | |
| 46 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); |
| 47 | object_property_set_bool(OBJECT(vdev), true, "realized", errp); |
| 48 | } |
| 49 | |
| 50 | static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) |
| 51 | { |
| 52 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 53 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); |
| 54 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); |
| 55 | k->realize = vhost_user_fs_pci_realize; |
| 56 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); |
| 57 | dc->props = vhost_user_fs_pci_properties; |
| 58 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; |
| 59 | pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ |
| 60 | pcidev_k->revision = 0x00; |
| 61 | pcidev_k->class_id = PCI_CLASS_STORAGE_OTHER; |
| 62 | } |
| 63 | |
| 64 | static void vhost_user_fs_pci_instance_init(Object *obj) |
| 65 | { |
| 66 | VHostUserFSPCI *dev = VHOST_USER_FS_PCI(obj); |
| 67 | |
| 68 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
| 69 | TYPE_VHOST_USER_FS); |
| 70 | } |
| 71 | |
| 72 | static const VirtioPCIDeviceTypeInfo vhost_user_fs_pci_info = { |
| 73 | .base_name = TYPE_VHOST_USER_FS_PCI, |
| 74 | .non_transitional_name = "vhost-user-fs-pci", |
| 75 | .instance_size = sizeof(VHostUserFSPCI), |
| 76 | .instance_init = vhost_user_fs_pci_instance_init, |
| 77 | .class_init = vhost_user_fs_pci_class_init, |
| 78 | }; |
| 79 | |
| 80 | static void vhost_user_fs_pci_register(void) |
| 81 | { |
| 82 | virtio_pci_types_register(&vhost_user_fs_pci_info); |
| 83 | } |
| 84 | |
| 85 | type_init(vhost_user_fs_pci_register); |