xref: /openbmc/qemu/hw/virtio/vhost-vsock-pci.c (revision 09a274d8)
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 "virtio-pci.h"
17 #include "hw/virtio/vhost-vsock.h"
18 
19 typedef struct VHostVSockPCI VHostVSockPCI;
20 
21 /*
22  * vhost-vsock-pci: This extends VirtioPCIProxy.
23  */
24 #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci-base"
25 #define VHOST_VSOCK_PCI(obj) \
26         OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
27 
28 struct VHostVSockPCI {
29     VirtIOPCIProxy parent_obj;
30     VHostVSock vdev;
31 };
32 
33 /* vhost-vsock-pci */
34 
35 static Property vhost_vsock_pci_properties[] = {
36     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
37     DEFINE_PROP_END_OF_LIST(),
38 };
39 
40 static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
41 {
42     VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev);
43     DeviceState *vdev = DEVICE(&dev->vdev);
44 
45     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
46     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
47 }
48 
49 static void vhost_vsock_pci_class_init(ObjectClass *klass, void *data)
50 {
51     DeviceClass *dc = DEVICE_CLASS(klass);
52     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
53     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
54     k->realize = vhost_vsock_pci_realize;
55     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
56     dc->props = vhost_vsock_pci_properties;
57     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
58     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
59     pcidev_k->revision = 0x00;
60     pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
61 }
62 
63 static void vhost_vsock_pci_instance_init(Object *obj)
64 {
65     VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj);
66 
67     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
68                                 TYPE_VHOST_VSOCK);
69 }
70 
71 static const VirtioPCIDeviceTypeInfo vhost_vsock_pci_info = {
72     .base_name             = TYPE_VHOST_VSOCK_PCI,
73     .generic_name          = "vhost-vsock-pci",
74     .transitional_name     = "vhost-vsock-pci-transitional",
75     .non_transitional_name = "vhost-vsock-pci-non-transitional",
76     .instance_size = sizeof(VHostVSockPCI),
77     .instance_init = vhost_vsock_pci_instance_init,
78     .class_init    = vhost_vsock_pci_class_init,
79 };
80 
81 static void virtio_pci_vhost_register(void)
82 {
83     virtio_pci_types_register(&vhost_vsock_pci_info);
84 }
85 
86 type_init(virtio_pci_vhost_register)
87