xref: /openbmc/qemu/hw/virtio/vhost-user-snd-pci.c (revision d0f0cd5b)
1 /*
2  * Vhost-user Sound virtio device PCI glue
3  *
4  * Copyright (c) 2023 Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "qemu/osdep.h"
10 #include "hw/qdev-properties.h"
11 #include "hw/virtio/vhost-user-snd.h"
12 #include "hw/virtio/virtio-pci.h"
13 
14 struct VHostUserSoundPCI {
15     VirtIOPCIProxy parent_obj;
16     VHostUserSound vdev;
17 };
18 
19 typedef struct VHostUserSoundPCI VHostUserSoundPCI;
20 
21 #define TYPE_VHOST_USER_SND_PCI "vhost-user-snd-pci-base"
22 
23 DECLARE_INSTANCE_CHECKER(VHostUserSoundPCI, VHOST_USER_SND_PCI,
24                          TYPE_VHOST_USER_SND_PCI)
25 
26 static Property vhost_user_snd_pci_properties[] = {
27     DEFINE_PROP_END_OF_LIST(),
28 };
29 
30 static void vhost_user_snd_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
31 {
32     VHostUserSoundPCI *dev = VHOST_USER_SND_PCI(vpci_dev);
33     DeviceState *vdev = DEVICE(&dev->vdev);
34 
35     vpci_dev->nvectors = 1;
36 
37     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
38 }
39 
40 static void vhost_user_snd_pci_class_init(ObjectClass *klass, void *data)
41 {
42     DeviceClass *dc = DEVICE_CLASS(klass);
43     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
44     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
45     k->realize = vhost_user_snd_pci_realize;
46     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
47     device_class_set_props(dc, vhost_user_snd_pci_properties);
48     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
49     pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */
50     pcidev_k->revision = 0x00;
51     pcidev_k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
52 }
53 
54 static void vhost_user_snd_pci_instance_init(Object *obj)
55 {
56     VHostUserSoundPCI *dev = VHOST_USER_SND_PCI(obj);
57 
58     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
59                                 TYPE_VHOST_USER_SND);
60 }
61 
62 static const VirtioPCIDeviceTypeInfo vhost_user_snd_pci_info = {
63     .base_name = TYPE_VHOST_USER_SND_PCI,
64     .non_transitional_name = "vhost-user-snd-pci",
65     .instance_size = sizeof(VHostUserSoundPCI),
66     .instance_init = vhost_user_snd_pci_instance_init,
67     .class_init = vhost_user_snd_pci_class_init,
68 };
69 
70 static void vhost_user_snd_pci_register(void)
71 {
72     virtio_pci_types_register(&vhost_user_snd_pci_info);
73 }
74 
75 type_init(vhost_user_snd_pci_register);
76