1 /*
2  * Vhost-user vsock PCI Bindings
3  *
4  * Copyright 2020 Red Hat, Inc.
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or
7  * (at your option) any later version.  See the COPYING file in the
8  * top-level directory.
9  */
10 
11 #include "qemu/osdep.h"
12 
13 #include "virtio-pci.h"
14 #include "hw/qdev-properties.h"
15 #include "hw/virtio/vhost-user-vsock.h"
16 #include "qom/object.h"
17 
18 typedef struct VHostUserVSockPCI VHostUserVSockPCI;
19 
20 /*
21  * vhost-user-vsock-pci: This extends VirtioPCIProxy.
22  */
23 #define TYPE_VHOST_USER_VSOCK_PCI "vhost-user-vsock-pci-base"
24 DECLARE_INSTANCE_CHECKER(VHostUserVSockPCI, VHOST_USER_VSOCK_PCI,
25                          TYPE_VHOST_USER_VSOCK_PCI)
26 
27 struct VHostUserVSockPCI {
28     VirtIOPCIProxy parent_obj;
29     VHostUserVSock vdev;
30 };
31 
32 /* vhost-user-vsock-pci */
33 
34 static Property vhost_user_vsock_pci_properties[] = {
35     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
36     DEFINE_PROP_END_OF_LIST(),
37 };
38 
39 static void vhost_user_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
40 {
41     VHostUserVSockPCI *dev = VHOST_USER_VSOCK_PCI(vpci_dev);
42     DeviceState *vdev = DEVICE(&dev->vdev);
43 
44     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
45 }
46 
47 static void vhost_user_vsock_pci_class_init(ObjectClass *klass, void *data)
48 {
49     DeviceClass *dc = DEVICE_CLASS(klass);
50     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
51     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
52     k->realize = vhost_user_vsock_pci_realize;
53     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
54     device_class_set_props(dc, vhost_user_vsock_pci_properties);
55     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
56     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
57     pcidev_k->revision = 0x00;
58     pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
59 }
60 
61 static void vhost_user_vsock_pci_instance_init(Object *obj)
62 {
63     VHostUserVSockPCI *dev = VHOST_USER_VSOCK_PCI(obj);
64 
65     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
66                                 TYPE_VHOST_USER_VSOCK);
67 }
68 
69 static const VirtioPCIDeviceTypeInfo vhost_user_vsock_pci_info = {
70     .base_name             = TYPE_VHOST_USER_VSOCK_PCI,
71     .generic_name          = "vhost-user-vsock-pci",
72     .transitional_name     = "vhost-user-vsock-pci-transitional",
73     .non_transitional_name = "vhost-user-vsock-pci-non-transitional",
74     .instance_size = sizeof(VHostUserVSockPCI),
75     .instance_init = vhost_user_vsock_pci_instance_init,
76     .class_init    = vhost_user_vsock_pci_class_init,
77 };
78 
79 static void virtio_pci_vhost_register(void)
80 {
81     virtio_pci_types_register(&vhost_user_vsock_pci_info);
82 }
83 
84 type_init(virtio_pci_vhost_register)
85