xref: /openbmc/qemu/hw/virtio/vhost-user-snd.c (revision b86c6ba6)
1 /*
2  * Vhost-user snd virtio device
3  *
4  * Copyright (c) 2023 Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
5  *
6  * Simple wrapper of the generic vhost-user-device.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "hw/qdev-properties.h"
14 #include "hw/virtio/virtio-bus.h"
15 #include "hw/virtio/vhost-user-snd.h"
16 #include "standard-headers/linux/virtio_ids.h"
17 #include "standard-headers/linux/virtio_snd.h"
18 
19 static const VMStateDescription vu_snd_vmstate = {
20     .name = "vhost-user-snd",
21     .unmigratable = 1,
22 };
23 
24 static Property vsnd_properties[] = {
25     DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
26     DEFINE_PROP_END_OF_LIST(),
27 };
28 
29 static void vu_snd_base_realize(DeviceState *dev, Error **errp)
30 {
31     VHostUserBase *vub = VHOST_USER_BASE(dev);
32     VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev);
33 
34     vub->virtio_id = VIRTIO_ID_SOUND;
35     vub->num_vqs = 4;
36     vub->config_size = sizeof(struct virtio_snd_config);
37     vub->vq_size = 64;
38 
39     vubs->parent_realize(dev, errp);
40 }
41 
42 static void vu_snd_class_init(ObjectClass *klass, void *data)
43 {
44     DeviceClass *dc = DEVICE_CLASS(klass);
45     VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
46 
47     dc->vmsd = &vu_snd_vmstate;
48     device_class_set_props(dc, vsnd_properties);
49     device_class_set_parent_realize(dc, vu_snd_base_realize,
50                                     &vubc->parent_realize);
51 
52     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
53 }
54 
55 static const TypeInfo vu_snd_info = {
56     .name = TYPE_VHOST_USER_SND,
57     .parent = TYPE_VHOST_USER_BASE,
58     .instance_size = sizeof(VHostUserSound),
59     .class_init = vu_snd_class_init,
60 };
61 
62 static void vu_snd_register_types(void)
63 {
64     type_register_static(&vu_snd_info);
65 }
66 
67 type_init(vu_snd_register_types)
68