218e99
From 76e63c2bd20deda91bf99de161deb85b5229bf7e Mon Sep 17 00:00:00 2001
218e99
From: Bandan Das <bsd@redhat.com>
218e99
Date: Tue, 15 Oct 2013 17:10:59 +0200
218e99
Subject: [PATCH 22/25] hda-codec: make mixemu selectable at runtime
218e99
218e99
RH-Author: Bandan Das <bsd@redhat.com>
218e99
Message-id: <1381857067-9399-3-git-send-email-bsd@redhat.com>
218e99
Patchwork-id: 54950
218e99
O-Subject: [PATCH RHEL-7 qemu-kvm v3 2/5] hda-codec: make mixemu selectable at runtime
218e99
Bugzilla: 954195
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
218e99
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
218e99
218e99
Define PARAM so that we have two versions of the "desc_codec
218e99
and family" structs. Add a property called "mixer" whose default
218e99
value depends on whether CONFIG_MIXEMU is defined or not which
218e99
will help us call the appropriate instance init functions.
218e99
218e99
Signed-off-by: Bandan Das <bsd@redhat.com>
218e99
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
218e99
(cherry picked from commit 2690e61e8e313461428334586ed9dbf56531dae9)
218e99
---
218e99
 hw/audio/hda-codec-common.h | 117 +++++++++++++++++++++++---------------------
218e99
 hw/audio/hda-codec.c        |  64 ++++++++++++++++++++++--
218e99
 2 files changed, 122 insertions(+), 59 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 hw/audio/hda-codec-common.h |  117 +++++++++++++++++++++++--------------------
218e99
 hw/audio/hda-codec.c        |   64 ++++++++++++++++++++++--
218e99
 2 files changed, 122 insertions(+), 59 deletions(-)
218e99
218e99
diff --git a/hw/audio/hda-codec-common.h b/hw/audio/hda-codec-common.h
218e99
index 2f7e95f..b4fdb51 100644
218e99
--- a/hw/audio/hda-codec-common.h
218e99
+++ b/hw/audio/hda-codec-common.h
218e99
@@ -24,7 +24,7 @@
218e99
  * HDA codec descriptions
218e99
  */
218e99
 
218e99
-#ifdef CONFIG_MIXEMU
218e99
+#ifdef HDA_MIXER
218e99
 #define QEMU_HDA_ID_OUTPUT  ((QEMU_HDA_ID_VENDOR << 16) | 0x12)
218e99
 #define QEMU_HDA_ID_DUPLEX  ((QEMU_HDA_ID_VENDOR << 16) | 0x22)
218e99
 #define QEMU_HDA_ID_MICRO   ((QEMU_HDA_ID_VENDOR << 16) | 0x32)
218e99
@@ -42,7 +42,7 @@
218e99
 
218e99
 
218e99
 /* common: audio output widget */
218e99
-static const desc_param common_params_audio_dac[] = {
218e99
+static const desc_param glue(common_params_audio_dac_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
218e99
         .val = ((AC_WID_AUD_OUT << AC_WCAP_TYPE_SHIFT) |
218e99
@@ -66,7 +66,7 @@ static const desc_param common_params_audio_dac[] = {
218e99
 };
218e99
 
218e99
 /* common: audio input widget */
218e99
-static const desc_param common_params_audio_adc[] = {
218e99
+static const desc_param glue(common_params_audio_adc_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
218e99
         .val = ((AC_WID_AUD_IN << AC_WCAP_TYPE_SHIFT) |
218e99
@@ -94,7 +94,7 @@ static const desc_param common_params_audio_adc[] = {
218e99
 };
218e99
 
218e99
 /* common: pin widget (line-out) */
218e99
-static const desc_param common_params_audio_lineout[] = {
218e99
+static const desc_param glue(common_params_audio_lineout_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
218e99
         .val = ((AC_WID_PIN << AC_WCAP_TYPE_SHIFT) |
218e99
@@ -116,7 +116,7 @@ static const desc_param common_params_audio_lineout[] = {
218e99
 };
218e99
 
218e99
 /* common: pin widget (line-in) */
218e99
-static const desc_param common_params_audio_linein[] = {
218e99
+static const desc_param glue(common_params_audio_linein_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_AUDIO_WIDGET_CAP,
218e99
         .val = ((AC_WID_PIN << AC_WCAP_TYPE_SHIFT) |
218e99
@@ -134,7 +134,7 @@ static const desc_param common_params_audio_linein[] = {
218e99
 };
218e99
 
218e99
 /* output: root node */
218e99
-static const desc_param output_params_root[] = {
218e99
+static const desc_param glue(output_params_root_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_VENDOR_ID,
218e99
         .val = QEMU_HDA_ID_OUTPUT,
218e99
@@ -151,7 +151,7 @@ static const desc_param output_params_root[] = {
218e99
 };
218e99
 
218e99
 /* output: audio function */
218e99
-static const desc_param output_params_audio_func[] = {
218e99
+static const desc_param glue(output_params_audio_func_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_FUNCTION_TYPE,
218e99
         .val = AC_GRP_AUDIO_FUNCTION,
218e99
@@ -186,28 +186,28 @@ static const desc_param output_params_audio_func[] = {
218e99
 };
218e99
 
218e99
 /* output: nodes */
218e99
-static const desc_node output_nodes[] = {
218e99
+static const desc_node glue(output_nodes_, PARAM)[] = {
218e99
     {
218e99
         .nid     = AC_NODE_ROOT,
218e99
         .name    = "root",
218e99
-        .params  = output_params_root,
218e99
-        .nparams = ARRAY_SIZE(output_params_root),
218e99
+        .params  = glue(output_params_root_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(output_params_root_, PARAM)),
218e99
     },{
218e99
         .nid     = 1,
218e99
         .name    = "func",
218e99
-        .params  = output_params_audio_func,
218e99
-        .nparams = ARRAY_SIZE(output_params_audio_func),
218e99
+        .params  = glue(output_params_audio_func_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(output_params_audio_func_, PARAM)),
218e99
     },{
218e99
         .nid     = 2,
218e99
         .name    = "dac",
218e99
-        .params  = common_params_audio_dac,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_dac),
218e99
+        .params  = glue(common_params_audio_dac_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_dac_, PARAM)),
218e99
         .stindex = 0,
218e99
     },{
218e99
         .nid     = 3,
218e99
         .name    = "out",
218e99
-        .params  = common_params_audio_lineout,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_lineout),
218e99
+        .params  = glue(common_params_audio_lineout_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_lineout_, PARAM)),
218e99
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
218e99
                     (AC_JACK_LINE_OUT     << AC_DEFCFG_DEVICE_SHIFT)    |
218e99
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
218e99
@@ -219,15 +219,15 @@ static const desc_node output_nodes[] = {
218e99
 };
218e99
 
218e99
 /* output: codec */
218e99
-static const desc_codec output = {
218e99
+static const desc_codec glue(output_, PARAM) = {
218e99
     .name   = "output",
218e99
     .iid    = QEMU_HDA_ID_OUTPUT,
218e99
-    .nodes  = output_nodes,
218e99
-    .nnodes = ARRAY_SIZE(output_nodes),
218e99
+    .nodes  = glue(output_nodes_, PARAM),
218e99
+    .nnodes = ARRAY_SIZE(glue(output_nodes_, PARAM)),
218e99
 };
218e99
 
218e99
 /* duplex: root node */
218e99
-static const desc_param duplex_params_root[] = {
218e99
+static const desc_param glue(duplex_params_root_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_VENDOR_ID,
218e99
         .val = QEMU_HDA_ID_DUPLEX,
218e99
@@ -244,7 +244,7 @@ static const desc_param duplex_params_root[] = {
218e99
 };
218e99
 
218e99
 /* duplex: audio function */
218e99
-static const desc_param duplex_params_audio_func[] = {
218e99
+static const desc_param glue(duplex_params_audio_func_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_FUNCTION_TYPE,
218e99
         .val = AC_GRP_AUDIO_FUNCTION,
218e99
@@ -279,28 +279,28 @@ static const desc_param duplex_params_audio_func[] = {
218e99
 };
218e99
 
218e99
 /* duplex: nodes */
218e99
-static const desc_node duplex_nodes[] = {
218e99
+static const desc_node glue(duplex_nodes_, PARAM)[] = {
218e99
     {
218e99
         .nid     = AC_NODE_ROOT,
218e99
         .name    = "root",
218e99
-        .params  = duplex_params_root,
218e99
-        .nparams = ARRAY_SIZE(duplex_params_root),
218e99
+        .params  = glue(duplex_params_root_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(duplex_params_root_, PARAM)),
218e99
     },{
218e99
         .nid     = 1,
218e99
         .name    = "func",
218e99
-        .params  = duplex_params_audio_func,
218e99
-        .nparams = ARRAY_SIZE(duplex_params_audio_func),
218e99
+        .params  = glue(duplex_params_audio_func_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(duplex_params_audio_func_, PARAM)),
218e99
     },{
218e99
         .nid     = 2,
218e99
         .name    = "dac",
218e99
-        .params  = common_params_audio_dac,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_dac),
218e99
+        .params  = glue(common_params_audio_dac_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_dac_, PARAM)),
218e99
         .stindex = 0,
218e99
     },{
218e99
         .nid     = 3,
218e99
         .name    = "out",
218e99
-        .params  = common_params_audio_lineout,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_lineout),
218e99
+        .params  = glue(common_params_audio_lineout_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_lineout_, PARAM)),
218e99
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
218e99
                     (AC_JACK_LINE_OUT     << AC_DEFCFG_DEVICE_SHIFT)    |
218e99
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
218e99
@@ -311,15 +311,15 @@ static const desc_node duplex_nodes[] = {
218e99
     },{
218e99
         .nid     = 4,
218e99
         .name    = "adc",
218e99
-        .params  = common_params_audio_adc,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_adc),
218e99
+        .params  = glue(common_params_audio_adc_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_adc_, PARAM)),
218e99
         .stindex = 1,
218e99
         .conn    = (uint32_t[]) { 5 },
218e99
     },{
218e99
         .nid     = 5,
218e99
         .name    = "in",
218e99
-        .params  = common_params_audio_linein,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_linein),
218e99
+        .params  = glue(common_params_audio_linein_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_linein_, PARAM)),
218e99
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
218e99
                     (AC_JACK_LINE_IN      << AC_DEFCFG_DEVICE_SHIFT)    |
218e99
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
218e99
@@ -330,15 +330,15 @@ static const desc_node duplex_nodes[] = {
218e99
 };
218e99
 
218e99
 /* duplex: codec */
218e99
-static const desc_codec duplex = {
218e99
+static const desc_codec glue(duplex_, PARAM) = {
218e99
     .name   = "duplex",
218e99
     .iid    = QEMU_HDA_ID_DUPLEX,
218e99
-    .nodes  = duplex_nodes,
218e99
-    .nnodes = ARRAY_SIZE(duplex_nodes),
218e99
+    .nodes  = glue(duplex_nodes_, PARAM),
218e99
+    .nnodes = ARRAY_SIZE(glue(duplex_nodes_, PARAM)),
218e99
 };
218e99
 
218e99
 /* micro: root node */
218e99
-static const desc_param micro_params_root[] = {
218e99
+static const desc_param glue(micro_params_root_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_VENDOR_ID,
218e99
         .val = QEMU_HDA_ID_MICRO,
218e99
@@ -355,7 +355,7 @@ static const desc_param micro_params_root[] = {
218e99
 };
218e99
 
218e99
 /* micro: audio function */
218e99
-static const desc_param micro_params_audio_func[] = {
218e99
+static const desc_param glue(micro_params_audio_func_, PARAM)[] = {
218e99
     {
218e99
         .id  = AC_PAR_FUNCTION_TYPE,
218e99
         .val = AC_GRP_AUDIO_FUNCTION,
218e99
@@ -390,28 +390,28 @@ static const desc_param micro_params_audio_func[] = {
218e99
 };
218e99
 
218e99
 /* micro: nodes */
218e99
-static const desc_node micro_nodes[] = {
218e99
+static const desc_node glue(micro_nodes_, PARAM)[] = {
218e99
     {
218e99
         .nid     = AC_NODE_ROOT,
218e99
         .name    = "root",
218e99
-        .params  = micro_params_root,
218e99
-        .nparams = ARRAY_SIZE(micro_params_root),
218e99
+        .params  = glue(micro_params_root_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(micro_params_root_, PARAM)),
218e99
     },{
218e99
         .nid     = 1,
218e99
         .name    = "func",
218e99
-        .params  = micro_params_audio_func,
218e99
-        .nparams = ARRAY_SIZE(micro_params_audio_func),
218e99
+        .params  = glue(micro_params_audio_func_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(micro_params_audio_func_, PARAM)),
218e99
     },{
218e99
         .nid     = 2,
218e99
         .name    = "dac",
218e99
-        .params  = common_params_audio_dac,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_dac),
218e99
+        .params  = glue(common_params_audio_dac_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_dac_, PARAM)),
218e99
         .stindex = 0,
218e99
     },{
218e99
         .nid     = 3,
218e99
         .name    = "out",
218e99
-        .params  = common_params_audio_lineout,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_lineout),
218e99
+        .params  = glue(common_params_audio_lineout_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_lineout_, PARAM)),
218e99
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
218e99
                     (AC_JACK_SPEAKER      << AC_DEFCFG_DEVICE_SHIFT)    |
218e99
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
218e99
@@ -422,15 +422,15 @@ static const desc_node micro_nodes[] = {
218e99
     },{
218e99
         .nid     = 4,
218e99
         .name    = "adc",
218e99
-        .params  = common_params_audio_adc,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_adc),
218e99
+        .params  = glue(common_params_audio_adc_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_adc_, PARAM)),
218e99
         .stindex = 1,
218e99
         .conn    = (uint32_t[]) { 5 },
218e99
     },{
218e99
         .nid     = 5,
218e99
         .name    = "in",
218e99
-        .params  = common_params_audio_linein,
218e99
-        .nparams = ARRAY_SIZE(common_params_audio_linein),
218e99
+        .params  = glue(common_params_audio_linein_, PARAM),
218e99
+        .nparams = ARRAY_SIZE(glue(common_params_audio_linein_, PARAM)),
218e99
         .config  = ((AC_JACK_PORT_COMPLEX << AC_DEFCFG_PORT_CONN_SHIFT) |
218e99
                     (AC_JACK_MIC_IN       << AC_DEFCFG_DEVICE_SHIFT)    |
218e99
                     (AC_JACK_CONN_UNKNOWN << AC_DEFCFG_CONN_TYPE_SHIFT) |
218e99
@@ -441,9 +441,16 @@ static const desc_node micro_nodes[] = {
218e99
 };
218e99
 
218e99
 /* micro: codec */
218e99
-static const desc_codec micro = {
218e99
+static const desc_codec glue(micro_, PARAM) = {
218e99
     .name   = "micro",
218e99
     .iid    = QEMU_HDA_ID_MICRO,
218e99
-    .nodes  = micro_nodes,
218e99
-    .nnodes = ARRAY_SIZE(micro_nodes),
218e99
+    .nodes  = glue(micro_nodes_, PARAM),
218e99
+    .nnodes = ARRAY_SIZE(glue(micro_nodes_, PARAM)),
218e99
 };
218e99
+
218e99
+#undef PARAM
218e99
+#undef HDA_MIXER
218e99
+#undef QEMU_HDA_ID_OUTPUT
218e99
+#undef QEMU_HDA_ID_DUPLEX
218e99
+#undef QEMU_HDA_ID_MICRO
218e99
+#undef QEMU_HDA_AMP_CAPS
218e99
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
218e99
index cb498fc..3217d90 100644
218e99
--- a/hw/audio/hda-codec.c
218e99
+++ b/hw/audio/hda-codec.c
218e99
@@ -118,7 +118,15 @@ static void hda_codec_parse_fmt(uint32_t format, struct audsettings *as)
218e99
 #define QEMU_HDA_AMP_NONE    (0)
218e99
 #define QEMU_HDA_AMP_STEPS   0x4a
218e99
 
218e99
+#ifdef CONFIG_MIXEMU
218e99
+#define   PARAM mixemu
218e99
+#define   HDA_MIXER
218e99
 #include "hda-codec-common.h"
218e99
+#endif
218e99
+
218e99
+#define   PARAM nomixemu
218e99
+#include  "hda-codec-common.h"
218e99
+
218e99
 /* -------------------------------------------------------------------------- */
218e99
 
218e99
 static const char *fmt2name[] = {
218e99
@@ -163,6 +171,7 @@ struct HDAAudioState {
218e99
 
218e99
     /* properties */
218e99
     uint32_t debug;
218e99
+    bool     mixer;
218e99
 };
218e99
 
218e99
 static void hda_audio_input_cb(void *opaque, int avail)
218e99
@@ -584,23 +593,70 @@ static const VMStateDescription vmstate_hda_audio = {
218e99
 };
218e99
 
218e99
 static Property hda_audio_properties[] = {
218e99
-    DEFINE_PROP_UINT32("debug", HDAAudioState, debug, 0),
218e99
+    DEFINE_PROP_UINT32("debug", HDAAudioState, debug,   0),
218e99
+#ifdef CONFIG_MIXEMU
218e99
+    DEFINE_PROP_BOOL("mixer", HDAAudioState, mixer,  true),
218e99
+#else
218e99
+    DEFINE_PROP_BOOL("mixer", HDAAudioState, mixer, false),
218e99
+#endif
218e99
     DEFINE_PROP_END_OF_LIST(),
218e99
 };
218e99
 
218e99
 static int hda_audio_init_output(HDACodecDevice *hda)
218e99
 {
218e99
-    return hda_audio_init(hda, &output);
218e99
+    HDAAudioState *a = DO_UPCAST(HDAAudioState, hda, hda);
218e99
+
218e99
+    if (!a->mixer) {
218e99
+        return hda_audio_init(hda, &output_nomixemu);
218e99
+    } else {
218e99
+
218e99
+#ifdef CONFIG_MIXEMU
218e99
+        return hda_audio_init(hda, &output_mixemu);
218e99
+#else
218e99
+        fprintf(stderr, "ERROR: "
218e99
+                "hda-codec : Mixer emulation has not been compiled in!\n");
218e99
+        return -1;
218e99
+#endif
218e99
+
218e99
+    }
218e99
 }
218e99
 
218e99
 static int hda_audio_init_duplex(HDACodecDevice *hda)
218e99
 {
218e99
-    return hda_audio_init(hda, &duplex);
218e99
+    HDAAudioState *a = DO_UPCAST(HDAAudioState, hda, hda);
218e99
+
218e99
+    if (!a->mixer) {
218e99
+        return hda_audio_init(hda, &duplex_nomixemu);
218e99
+    } else {
218e99
+
218e99
+#ifdef CONFIG_MIXEMU
218e99
+        return hda_audio_init(hda, &duplex_mixemu);
218e99
+#else
218e99
+        fprintf(stderr, "ERROR: "
218e99
+                "hda-codec : Mixer emulation has not been compiled in!\n");
218e99
+        return -1;
218e99
+#endif
218e99
+
218e99
+    }
218e99
 }
218e99
 
218e99
 static int hda_audio_init_micro(HDACodecDevice *hda)
218e99
 {
218e99
-    return hda_audio_init(hda, µ);
218e99
+    HDAAudioState *a = DO_UPCAST(HDAAudioState, hda, hda);
218e99
+
218e99
+    if (!a->mixer) {
218e99
+        return hda_audio_init(hda, &micro_nomixemu);
218e99
+    } else {
218e99
+
218e99
+#ifdef CONFIG_MIXEMU
218e99
+        return hda_audio_init(hda, &micro_mixemu);
218e99
+#else
218e99
+        fprintf(stderr, "ERROR: "
218e99
+                "hda-codec : Mixer emulation has not been compiled in!\n");
218e99
+        return -1;
218e99
+#endif
218e99
+
218e99
+    }
218e99
 }
218e99
 
218e99
 static void hda_audio_output_class_init(ObjectClass *klass, void *data)
218e99
-- 
218e99
1.7.1
218e99