[RFC PATCH 01/27] virtio-snd: Add virtio sound header file

Shreyansh Chouhan posted 27 patches 4 years, 9 months ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
[RFC PATCH 01/27] virtio-snd: Add virtio sound header file
Posted by Shreyansh Chouhan 4 years, 9 months ago
Added device configuration and common definitions to the header
file.

Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
---
 include/hw/virtio/virtio-snd.h | 97 ++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 include/hw/virtio/virtio-snd.h

diff --git a/include/hw/virtio/virtio-snd.h b/include/hw/virtio/virtio-snd.h
new file mode 100644
index 0000000000..bbbf174c51
--- /dev/null
+++ b/include/hw/virtio/virtio-snd.h
@@ -0,0 +1,97 @@
+/*
+ * Virtio Sound Device
+ */
+
+#ifndef QEMU_VIRTIO_SOUND_H
+#define QEMU_VIRTIO_SOUND_H
+
+#include "qemu/units.h"
+#include "hw/virtio/virtio.h"
+#include "qemu/queue.h"
+#include "audio/audio.h"
+#include "audio/audio_int.h"
+
+#define VIRTIO_ID_SOUND 25
+
+/* CONFIGURATION SPACE */
+
+typedef struct virtio_snd_config {
+    /* # of jacks available */
+    uint32_t jacks;
+    /* # of streams avalable */
+    uint32_t streams;
+    /* # chmaps available */
+    uint32_t chmaps;
+} virtio_snd_config;
+
+/* COMMON DEFINITIONS */
+
+/* supported sample data directions. */
+enum {
+    VIRTIO_SND_D_OUTPUT = 0,
+    VIRTIO_SND_D_INPUT
+};
+
+enum {
+    /* jack control request types */
+    VIRTIO_SND_R_JACK_INFO = 1,
+    VIRTIO_SND_R_JACK_REMAP,
+
+    /* PCM control request types */
+    VIRTIO_SND_R_PCM_INFO = 0x0100,
+    VIRTIO_SND_R_PCM_SET_PARAMS,
+    VIRTIO_SND_R_PCM_PREPARE,
+    VIRTIO_SND_R_PCM_RELEASE,
+    VIRTIO_SND_R_PCM_START,
+    VIRTIO_SND_R_PCM_STOP,
+
+    /* channel map control request type */
+    VIRTIO_SND_R_CHMAP_INFO = 0x200,
+
+    /* jack event types */
+    VIRTIO_SND_EVT_JACK_CONNECTED = 0x1000,
+    VIRTIO_SND_EVT_JACK_DISCONNECTED,
+
+    /* PCM event types */
+    VIRTIO_SND_EVT_PCM_PERIOD_ELAPSED = 0x1100,
+    VIRTIO_SND_EVT_PCM_XRUN,
+
+    /* common status codes */
+    VIRTIO_SND_S_OK = 0x8000,
+    VIRTIO_SND_S_BAD_MSG,
+    VIRTIO_SND_S_NOT_SUPP,
+    VIRTIO_SND_S_IO_ERR
+};
+
+/* common header for request/response*/
+typedef struct virtio_snd_hdr {
+    uint32_t code;
+} virtio_snd_hdr;
+
+/* event notification */
+typedef struct virtio_snd_event {
+    /* VIRTIO_SND_EVT_* */
+    virtio_snd_hdr hdr;
+    /* Optional event data */
+    uint32_t data;
+} virtio_snd_event;
+
+/* common control request to query an item information */
+typedef struct virtio_snd_query_info {
+    /* VIRTIO_SND_R_*_INFO */
+    struct virtio_snd_hdr hdr;
+    /* item start identifier */
+    uint32_t start_id;
+    /* # of items to query */
+    uint32_t count;
+    /* size of a single item information in bytes */
+    uint32_t size;
+} virtio_snd_query_info;
+
+/* common item information header */
+typedef struct virtio_snd_info {
+    /* functional group node id (HDA Spec 7.1.2) */
+    uint32_t hda_fn_nid;
+} virtio_snd_info;
+
+#endif
-- 
2.25.1


Re: [RFC PATCH 01/27] virtio-snd: Add virtio sound header file
Posted by Gerd Hoffmann 4 years, 9 months ago
On Thu, Apr 29, 2021 at 05:34:19PM +0530, Shreyansh Chouhan wrote:
> Added device configuration and common definitions to the header
> file.
> 
> Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
> ---
>  include/hw/virtio/virtio-snd.h | 97 ++++++++++++++++++++++++++++++++++

This is the place for the data structures used by qemu internally.

The structs and #defines for the guest/host protocol should go to
include/standard-headers/linux/ instead.

There is a script (scripts/update-linux-headers.sh) to sync the files
with the linux source tree content.  As far I know the linux guest
driver is scheduled for merge in the 5.13 merge window, so once 5.13-rc1
is out of the door this should start working.

Syncing against a development tree is possible too as temporary stopgap,
but some extra care is needed then to avoid unwanted changes to
non-virtio-sound files slipping in.

Possibly it makes sense to also sync other linux header files that way
(for hda jacks maybe?).  We also import the input headers to get all the
KEY_* #defines for example.

take care,
  Gerd