[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 10/27] virtio-snd: Add code for the realize function
From: |
Shreyansh Chouhan |
Subject: |
[RFC PATCH 10/27] virtio-snd: Add code for the realize function |
Date: |
Thu, 29 Apr 2021 17:34:28 +0530 |
Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
---
hw/audio/virtio-snd.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index edaeffd6b7..caad157705 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -97,8 +97,43 @@ static uint64_t virtio_snd_get_features(VirtIODevice *vdev,
uint64_t features,
return vdev->host_features;
}
+/*
+ * Initializes the VirtIOSound card device. Validates the configuration
+ * passed by the command line. Initializes the virtqueues. Allocates resources
+ * for and initializes streams, jacks and chmaps.
+ *
+ * @dev: VirtIOSound card device
+ * @errp: Set if there is an error
+ */
static void virtio_snd_device_realize(DeviceState *dev, Error **errp)
{
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ VirtIOSound *s = VIRTIO_SOUND(dev);
+
+ virtio_init(vdev, "virtio-snd", VIRTIO_ID_SOUND,
sizeof(virtio_snd_config));
+
+ /* set number of jacks and streams */
+ if (s->snd_conf.jacks > 8) {
+ error_setg(errp, "Invalid number of jacks: %d", s->snd_conf.jacks);
+ return;
+ }
+ if (s->snd_conf.streams < 1 || s->snd_conf.streams > 10) {
+ error_setg(errp, "Invalid number of streams: %d", s->snd_conf.streams);
+ return;
+ }
+
+ if (s->snd_conf.chmaps > VIRTIO_SND_CHMAP_MAX_SIZE) {
+ error_setg(errp, "Invalid number of channel maps: %d",
+ s->snd_conf.chmaps);
+ return;
+ }
+
+ /* set up QEMUSoundCard and audiodev */
+ AUD_register_card ("virtio_snd_card", &s->card);
+
+ s->streams = g_new0(virtio_snd_pcm_stream *, s->snd_conf.streams);
+ s->pcm_params = g_new0(virtio_snd_pcm_params *, s->snd_conf.streams);
+ s->jacks = g_new0(virtio_snd_jack *, s->snd_conf.jacks);
}
static void virtio_snd_device_unrealize(DeviceState *dev)
--
2.25.1
- Re: [RFC PATCH 01/27] virtio-snd: Add virtio sound header file, (continued)
- [RFC PATCH 02/27] virtio-snd: Add jack control structures, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 04/27] virtio-snd: Add chmap control structures, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 03/27] virtio-snd: Add PCM control structures, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 05/27] virtio-snd: Add device implementation structures, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 06/27] virtio-snd: Add PCI wrapper code for VirtIOSound, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 07/27] virtio-snd: Add properties for class init, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 08/27] virtio-snd: Add code for get config function, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 09/27] virtio-snd: Add code for set config function, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 10/27] virtio-snd: Add code for the realize function,
Shreyansh Chouhan <=
- [RFC PATCH 12/27] virtio-snd: Add control virtqueue handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 11/27] virtio-snd: Add macros for logging, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 13/27] virtio-snd: Add VIRTIO_SND_R_JACK_INFO handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 15/27] virtio-snd: Add VIRTIO_SND_R_PCM_INFO handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 14/27] virtio-snd: Add stub for VIRTIO_SND_R_JACK_REMAP handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 18/27] virtio-snd: Add default configs to realize fn, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 16/27] virtio-snd: Add VIRITO_SND_R_PCM_SET_PARAMS handle, Shreyansh Chouhan, 2021/04/29