xref: /openbmc/qemu/hw/virtio/vhost-vsock-pci.c (revision eec398119fc6911d99412c37af06a6bc27871f85)
1ef7e7845SJuan Quintela /*
2ef7e7845SJuan Quintela  * Vhost vsock PCI Bindings
3ef7e7845SJuan Quintela  *
4ef7e7845SJuan Quintela  * Copyright 2015 Red Hat, Inc.
5ef7e7845SJuan Quintela  *
6ef7e7845SJuan Quintela  * Authors:
7ef7e7845SJuan Quintela  *  Stefan Hajnoczi <stefanha@redhat.com>
8ef7e7845SJuan Quintela  *
9ef7e7845SJuan Quintela  * This work is licensed under the terms of the GNU GPL, version 2 or
10ef7e7845SJuan Quintela  * (at your option) any later version.  See the COPYING file in the
11ef7e7845SJuan Quintela  * top-level directory.
12ef7e7845SJuan Quintela  */
13ef7e7845SJuan Quintela 
14ef7e7845SJuan Quintela #include "qemu/osdep.h"
15ef7e7845SJuan Quintela 
16*e1b1f534SAlex Bennée #include "hw/virtio/virtio-pci.h"
17a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
18ef7e7845SJuan Quintela #include "hw/virtio/vhost-vsock.h"
190b8fa32fSMarkus Armbruster #include "qemu/module.h"
20db1015e9SEduardo Habkost #include "qom/object.h"
21ef7e7845SJuan Quintela 
22ef7e7845SJuan Quintela typedef struct VHostVSockPCI VHostVSockPCI;
23ef7e7845SJuan Quintela 
24ef7e7845SJuan Quintela /*
25ef7e7845SJuan Quintela  * vhost-vsock-pci: This extends VirtioPCIProxy.
26ef7e7845SJuan Quintela  */
27ef7e7845SJuan Quintela #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci-base"
288110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(VHostVSockPCI, VHOST_VSOCK_PCI,
298110fa1dSEduardo Habkost                          TYPE_VHOST_VSOCK_PCI)
30ef7e7845SJuan Quintela 
31ef7e7845SJuan Quintela struct VHostVSockPCI {
32ef7e7845SJuan Quintela     VirtIOPCIProxy parent_obj;
33ef7e7845SJuan Quintela     VHostVSock vdev;
34ef7e7845SJuan Quintela };
35ef7e7845SJuan Quintela 
36ef7e7845SJuan Quintela /* vhost-vsock-pci */
37ef7e7845SJuan Quintela 
38ef7e7845SJuan Quintela static Property vhost_vsock_pci_properties[] = {
39ef7e7845SJuan Quintela     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
40ef7e7845SJuan Quintela     DEFINE_PROP_END_OF_LIST(),
41ef7e7845SJuan Quintela };
42ef7e7845SJuan Quintela 
vhost_vsock_pci_realize(VirtIOPCIProxy * vpci_dev,Error ** errp)43ef7e7845SJuan Quintela static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
44ef7e7845SJuan Quintela {
45ef7e7845SJuan Quintela     VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev);
46ef7e7845SJuan Quintela     DeviceState *vdev = DEVICE(&dev->vdev);
4762090705SStefano Garzarella     VirtIODevice *virtio_dev = VIRTIO_DEVICE(vdev);
4862090705SStefano Garzarella 
4962090705SStefano Garzarella     /*
5062090705SStefano Garzarella      * To avoid migration issues, we force virtio version 1 only when
5162090705SStefano Garzarella      * legacy check is enabled in the new machine types (>= 5.1).
5262090705SStefano Garzarella      */
5362090705SStefano Garzarella     if (!virtio_legacy_check_disabled(virtio_dev)) {
5462090705SStefano Garzarella         virtio_pci_force_virtio_1(vpci_dev);
5562090705SStefano Garzarella     }
56ef7e7845SJuan Quintela 
5799ba777eSMarkus Armbruster     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
58ef7e7845SJuan Quintela }
59ef7e7845SJuan Quintela 
vhost_vsock_pci_class_init(ObjectClass * klass,void * data)60ef7e7845SJuan Quintela static void vhost_vsock_pci_class_init(ObjectClass *klass, void *data)
61ef7e7845SJuan Quintela {
62ef7e7845SJuan Quintela     DeviceClass *dc = DEVICE_CLASS(klass);
63ef7e7845SJuan Quintela     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
64ef7e7845SJuan Quintela     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
65ef7e7845SJuan Quintela     k->realize = vhost_vsock_pci_realize;
66ef7e7845SJuan Quintela     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
674f67d30bSMarc-André Lureau     device_class_set_props(dc, vhost_vsock_pci_properties);
68ef7e7845SJuan Quintela     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
69ef7e7845SJuan Quintela     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
70ef7e7845SJuan Quintela     pcidev_k->revision = 0x00;
71ef7e7845SJuan Quintela     pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
72ef7e7845SJuan Quintela }
73ef7e7845SJuan Quintela 
vhost_vsock_pci_instance_init(Object * obj)74ef7e7845SJuan Quintela static void vhost_vsock_pci_instance_init(Object *obj)
75ef7e7845SJuan Quintela {
76ef7e7845SJuan Quintela     VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj);
77ef7e7845SJuan Quintela 
78ef7e7845SJuan Quintela     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
79ef7e7845SJuan Quintela                                 TYPE_VHOST_VSOCK);
80ef7e7845SJuan Quintela }
81ef7e7845SJuan Quintela 
82ef7e7845SJuan Quintela static const VirtioPCIDeviceTypeInfo vhost_vsock_pci_info = {
83ef7e7845SJuan Quintela     .base_name             = TYPE_VHOST_VSOCK_PCI,
84ef7e7845SJuan Quintela     .generic_name          = "vhost-vsock-pci",
85ef7e7845SJuan Quintela     .non_transitional_name = "vhost-vsock-pci-non-transitional",
86ef7e7845SJuan Quintela     .instance_size = sizeof(VHostVSockPCI),
87ef7e7845SJuan Quintela     .instance_init = vhost_vsock_pci_instance_init,
88ef7e7845SJuan Quintela     .class_init    = vhost_vsock_pci_class_init,
89ef7e7845SJuan Quintela };
90ef7e7845SJuan Quintela 
virtio_pci_vhost_register(void)91ef7e7845SJuan Quintela static void virtio_pci_vhost_register(void)
92ef7e7845SJuan Quintela {
93ef7e7845SJuan Quintela     virtio_pci_types_register(&vhost_vsock_pci_info);
94ef7e7845SJuan Quintela }
95ef7e7845SJuan Quintela 
96ef7e7845SJuan Quintela type_init(virtio_pci_vhost_register)
97