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" |
Alex Bennée | e1b1f53 | 2022-03-21 15:30:25 +0000 | [diff] [blame] | 17 | #include "hw/virtio/virtio-pci.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 18 | #include "qom/object.h" |
Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 19 | |
| 20 | struct VHostUserFSPCI { |
| 21 | VirtIOPCIProxy parent_obj; |
| 22 | VHostUserFS vdev; |
| 23 | }; |
| 24 | |
| 25 | typedef struct VHostUserFSPCI VHostUserFSPCI; |
| 26 | |
| 27 | #define TYPE_VHOST_USER_FS_PCI "vhost-user-fs-pci-base" |
| 28 | |
Eduardo Habkost | 8110fa1 | 2020-08-31 17:07:33 -0400 | [diff] [blame] | 29 | DECLARE_INSTANCE_CHECKER(VHostUserFSPCI, VHOST_USER_FS_PCI, |
| 30 | TYPE_VHOST_USER_FS_PCI) |
Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 31 | |
| 32 | static Property vhost_user_fs_pci_properties[] = { |
| 33 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, |
| 34 | DEV_NVECTORS_UNSPECIFIED), |
| 35 | DEFINE_PROP_END_OF_LIST(), |
| 36 | }; |
| 37 | |
| 38 | static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
| 39 | { |
| 40 | VHostUserFSPCI *dev = VHOST_USER_FS_PCI(vpci_dev); |
| 41 | DeviceState *vdev = DEVICE(&dev->vdev); |
| 42 | |
| 43 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { |
Stefan Hajnoczi | 366844f | 2019-12-09 11:07:59 +0000 | [diff] [blame] | 44 | /* Also reserve config change and hiprio queue vectors */ |
| 45 | vpci_dev->nvectors = dev->vdev.conf.num_request_queues + 2; |
Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Markus Armbruster | 99ba777 | 2020-06-10 07:32:00 +0200 | [diff] [blame] | 48 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) |
| 52 | { |
| 53 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 54 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); |
| 55 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); |
| 56 | k->realize = vhost_user_fs_pci_realize; |
| 57 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 58 | device_class_set_props(dc, vhost_user_fs_pci_properties); |
Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 59 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; |
| 60 | pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ |
| 61 | pcidev_k->revision = 0x00; |
| 62 | pcidev_k->class_id = PCI_CLASS_STORAGE_OTHER; |
| 63 | } |
| 64 | |
| 65 | static void vhost_user_fs_pci_instance_init(Object *obj) |
| 66 | { |
| 67 | VHostUserFSPCI *dev = VHOST_USER_FS_PCI(obj); |
| 68 | |
| 69 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
| 70 | TYPE_VHOST_USER_FS); |
Laszlo Ersek | 6da32fe | 2021-01-12 14:16:03 +0100 | [diff] [blame] | 71 | object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), |
| 72 | "bootindex"); |
Dr. David Alan Gilbert | 9d59bed | 2019-09-30 11:51:35 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static const VirtioPCIDeviceTypeInfo vhost_user_fs_pci_info = { |
| 76 | .base_name = TYPE_VHOST_USER_FS_PCI, |
| 77 | .non_transitional_name = "vhost-user-fs-pci", |
| 78 | .instance_size = sizeof(VHostUserFSPCI), |
| 79 | .instance_init = vhost_user_fs_pci_instance_init, |
| 80 | .class_init = vhost_user_fs_pci_class_init, |
| 81 | }; |
| 82 | |
| 83 | static void vhost_user_fs_pci_register(void) |
| 84 | { |
| 85 | virtio_pci_types_register(&vhost_user_fs_pci_info); |
| 86 | } |
| 87 | |
| 88 | type_init(vhost_user_fs_pci_register); |