| 1 | /* |
| 2 | * Vhost vsock PCI Bindings |
| 3 | * |
| 4 | * Copyright 2015 Red Hat, Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Stefan Hajnoczi <stefanha@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 | |
| 16 | #include "hw/virtio/virtio-pci.h" |
| 17 | #include "hw/core/qdev-properties.h" |
| 18 | #include "hw/virtio/vhost-vsock.h" |
| 19 | #include "qemu/module.h" |
| 20 | #include "qom/object.h" |
| 21 | |
| 22 | typedef struct VHostVSockPCI VHostVSockPCI; |
| 23 | |
| 24 | /* |
| 25 | * vhost-vsock-pci: This extends VirtioPCIProxy. |
| 26 | */ |
| 27 | #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci-base" |
| 28 | DECLARE_INSTANCE_CHECKER(VHostVSockPCI, VHOST_VSOCK_PCI, |
| 29 | TYPE_VHOST_VSOCK_PCI) |
| 30 | |
| 31 | struct VHostVSockPCI { |
| 32 | VirtIOPCIProxy parent_obj; |
| 33 | VHostVSock vdev; |
| 34 | }; |
| 35 | |
| 36 | /* vhost-vsock-pci */ |
| 37 | |
| 38 | static const Property vhost_vsock_pci_properties[] = { |
| 39 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), |
| 40 | }; |
| 41 | |
| 42 | static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
| 43 | { |
| 44 | VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev); |
| 45 | DeviceState *vdev = DEVICE(&dev->vdev); |
| 46 | VirtIODevice *virtio_dev = VIRTIO_DEVICE(vdev); |
| 47 | |
| 48 | /* |
| 49 | * To avoid migration issues, we force virtio version 1 only when |
| 50 | * legacy check is enabled in the new machine types (>= 5.1). |
| 51 | */ |
| 52 | if (!virtio_legacy_check_disabled(virtio_dev)) { |
| 53 | virtio_pci_force_virtio_1(vpci_dev); |
| 54 | } |
| 55 | |
| 56 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
| 57 | } |
| 58 | |
| 59 | static void vhost_vsock_pci_class_init(ObjectClass *klass, const void *data) |
| 60 | { |
| 61 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 62 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); |
| 63 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); |
| 64 | k->realize = vhost_vsock_pci_realize; |
| 65 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
| 66 | device_class_set_props(dc, vhost_vsock_pci_properties); |
| 67 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; |
| 68 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK; |
| 69 | pcidev_k->revision = 0x00; |
| 70 | pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER; |
| 71 | } |
| 72 | |
| 73 | static void vhost_vsock_pci_instance_init(Object *obj) |
| 74 | { |
| 75 | VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj); |
| 76 | |
| 77 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
| 78 | TYPE_VHOST_VSOCK); |
| 79 | } |
| 80 | |
| 81 | static const VirtioPCIDeviceTypeInfo vhost_vsock_pci_info = { |
| 82 | .base_name = TYPE_VHOST_VSOCK_PCI, |
| 83 | .generic_name = "vhost-vsock-pci", |
| 84 | .non_transitional_name = "vhost-vsock-pci-non-transitional", |
| 85 | .instance_size = sizeof(VHostVSockPCI), |
| 86 | .instance_init = vhost_vsock_pci_instance_init, |
| 87 | .class_init = vhost_vsock_pci_class_init, |
| 88 | }; |
| 89 | |
| 90 | static void virtio_pci_vhost_register(void) |
| 91 | { |
| 92 | virtio_pci_types_register(&vhost_vsock_pci_info); |
| 93 | } |
| 94 | |
| 95 | type_init(virtio_pci_vhost_register) |