qdev: Convert uses of qdev_set_parent_bus() with Coccinelle
[qemu.git] / hw / virtio / vhost-user-vsock-pci.c
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
17 typedef struct VHostUserVSockPCI VHostUserVSockPCI;
18
19 /*
20 * vhost-user-vsock-pci: This extends VirtioPCIProxy.
21 */
22 #define TYPE_VHOST_USER_VSOCK_PCI "vhost-user-vsock-pci-base"
23 #define VHOST_USER_VSOCK_PCI(obj) \
24 OBJECT_CHECK(VHostUserVSockPCI, (obj), TYPE_VHOST_USER_VSOCK_PCI)
25
26 struct VHostUserVSockPCI {
27 VirtIOPCIProxy parent_obj;
28 VHostUserVSock vdev;
29 };
30
31 /* vhost-user-vsock-pci */
32
33 static Property vhost_user_vsock_pci_properties[] = {
34 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
35 DEFINE_PROP_END_OF_LIST(),
36 };
37
38 static void vhost_user_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
39 {
40 VHostUserVSockPCI *dev = VHOST_USER_VSOCK_PCI(vpci_dev);
41 DeviceState *vdev = DEVICE(&dev->vdev);
42
43 qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
44 }
45
46 static void vhost_user_vsock_pci_class_init(ObjectClass *klass, void *data)
47 {
48 DeviceClass *dc = DEVICE_CLASS(klass);
49 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
50 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
51 k->realize = vhost_user_vsock_pci_realize;
52 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
53 device_class_set_props(dc, vhost_user_vsock_pci_properties);
54 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
55 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
56 pcidev_k->revision = 0x00;
57 pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
58 }
59
60 static void vhost_user_vsock_pci_instance_init(Object *obj)
61 {
62 VHostUserVSockPCI *dev = VHOST_USER_VSOCK_PCI(obj);
63
64 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
65 TYPE_VHOST_USER_VSOCK);
66 }
67
68 static const VirtioPCIDeviceTypeInfo vhost_user_vsock_pci_info = {
69 .base_name = TYPE_VHOST_USER_VSOCK_PCI,
70 .generic_name = "vhost-user-vsock-pci",
71 .transitional_name = "vhost-user-vsock-pci-transitional",
72 .non_transitional_name = "vhost-user-vsock-pci-non-transitional",
73 .instance_size = sizeof(VHostUserVSockPCI),
74 .instance_init = vhost_user_vsock_pci_instance_init,
75 .class_init = vhost_user_vsock_pci_class_init,
76 };
77
78 static void virtio_pci_vhost_register(void)
79 {
80 virtio_pci_types_register(&vhost_user_vsock_pci_info);
81 }
82
83 type_init(virtio_pci_vhost_register)