Skip to contentSkip to conversation

audio: make sound cards require the audiodev property

PATCH In review Paolo Bonzini 4 participants 15 messages Sep 22, 2023 Arm/versatile express platform

lore
Share & tools
lore
#0 lore raw

cover audio: make sound cards require the audiodev property

This is the remaining part of Martin's patches to remove the deprecations connected to audio backend configuration. With these patches, all sound cards have to be configured with an audio backend; only embedded cards get the luxury of a default backend that emits or records no audio at all. Fortunately, this is easy to do with the existing "-audio" option.

Apart from some rebasing changes, the changes are:

- the "-M" option for the embedded audiodev is only added to machines that need it, and renamed from "default-audiodev" to just "audiodev".

- the embedded audiodev is also accessible by specifying "-audio DRIVER" without a model

- the audiodev option is also configurable with -readconfig

- MIPS fuloong2e and PPC pegasos2 need changes in order to expose the embedded audiodev, too

Paolo

Based-on: <[email protected]>

Martin Kletzander (6):
audio: Add easy dummy audio initialiser
Introduce machine property "audiodev"
hw/arm: Support machine-default audiodev with fallback hw/ppc: Support machine-default audiodev with fallback
audio: Make AUD_register_card fallible and require audiodev=
audio: Be more strict during audio backend initialisation

Paolo Bonzini (3):
vl: support -audio BACKEND without model
vt82c686: Support machine-default audiodev with fallback
vl: recognize audiodev groups in configuration files

 audio/audio.c                        | 177 +++++++++++----------------
 audio/audio.h                        |   4 +-
 docs/about/deprecated.rst            |   6 -
 docs/about/removed-features.rst      |  11 +-
 docs/config/q35-emulated.cfg         |   4 +
 docs/config/q35-virtio-graphical.cfg |   4 +
 hw/arm/integratorcp.c                |  10 +-
 hw/arm/musicpal.c                    |  11 +-
 hw/arm/nseries.c                     |   4 +
 hw/arm/omap2.c                       |  10 +-
 hw/arm/palm.c                        |   2 +
 hw/arm/realview.c                    |  11 ++
 hw/arm/spitz.c                       |  12 +-
 hw/arm/versatilepb.c                 |   7 ++
 hw/arm/vexpress.c                    |   4 +
 hw/arm/xlnx-zcu102.c                 |   5 +
 hw/arm/z2.c                          |  14 ++-
 hw/audio/ac97.c                      |   6 +-
 hw/audio/adlib.c                     |   6 +-
 hw/audio/cs4231a.c                   |   6 +-
 hw/audio/es1370.c                    |   5 +-
 hw/audio/gus.c                       |   6 +-
 hw/audio/hda-codec.c                 |   5 +-
 hw/audio/lm4549.c                    |   8 +-
 hw/audio/pcspk.c                     |   4 +-
 hw/audio/sb16.c                      |   6 +-
 hw/audio/via-ac97.c                  |   6 +-
 hw/audio/wm8750.c                    |   5 +-
 hw/core/machine.c                    |  28 +++++
 hw/display/xlnx_dp.c                 |   6 +-
 hw/input/tsc210x.c                   |  10 +-
 hw/isa/vt82c686.c                    |   2 +
 hw/mips/fuloong2e.c                  |  12 +-
 hw/ppc/pegasos2.c                    |  10 +-
 hw/ppc/prep.c                        |   6 +
 hw/ppc/sam460ex.c                    |   2 +
 hw/usb/dev-audio.c                   |   5 +-
 include/hw/boards.h                  |   7 ++
 softmmu/vl.c                         |  25 +++-
 39 files changed, 315 insertions(+), 157 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/9 audio: Add easy dummy audio initialiser

From: Martin Kletzander <[email protected]>

In case of sound devices which are created by default (some of them even with -nodefaults) it would not be nice to users if qemu required explicit:

-audiodev driver=none,id=audio0 -machine audiodev=audio0

when they just want to run a VM and not care about any audio output. Instead this little helper makes it easy to create a dummy audiodev (driver=none) in case there is no audiodev specified for the machine. To make sure users are not surprised by no sound output a helping message is also printed out.

---
 audio/audio.c | 34 ++++++++++++++++++++++++++++++++++
 audio/audio.h |  2 ++
 2 files changed, 36 insertions(+)
audio/audio.c +34 -0
index d72e7db7fb9..8c74bc6b88c 100644
@@ -41,6 +41,7 @@
 #include "sysemu/runstate.h"
 #include "ui/qemu-spice.h"
 #include "trace.h"
+#include "hw/boards.h"
 
 #define AUDIO_CAP "audio"
 #include "audio_int.h"
@@ -2174,6 +2175,39 @@ bool audio_init_audiodevs(void)
     return true;
 }
 
+static void audio_init_dummy(const char *id)
+{
+    Audiodev *dev = g_new0(Audiodev, 1);
+    AudiodevListEntry *e = g_new0(AudiodevListEntry, 1);
+
+    dev->driver = AUDIODEV_DRIVER_NONE;
+    dev->id = g_strdup(id);
+
+    audio_validate_opts(dev, &error_abort);
+    audio_init(dev, NULL);
+
+    e->dev = dev;
+    QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
+}
+
+const char *audio_maybe_init_dummy(const char *default_id)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+
+    if (ms->default_audiodev) {
+        return ms->default_audiodev;
+    }
+
+    dolog("warning: No audiodev specified for implicit machine devices, "
+          "no audio output will be available for these. "
+          "For setting a backend audiodev for such devices try using "
+          "the audiodev machine option.\n");
+
+    audio_init_dummy(default_id);
+
+    return default_id;
+}
+
 audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
 {
     return (audsettings) {
audio/audio.h +2 -0
index a276ec13eba..81d39526625 100644
@@ -176,6 +176,8 @@ void audio_help(void);
 AudioState *audio_state_by_name(const char *name);
 const char *audio_get_id(QEMUSoundCard *card);
 
+const char *audio_maybe_init_dummy(const char *default_id);
+
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
 
Signature · 1 line
2.41.0
#2 lore raw

Re: [PATCH 1/9] audio: Add easy dummy audio initialiser

Hi

Quoted 48 lines · Paolo Bonzini

From: Martin Kletzander <[email protected]>

In case of sound devices which are created by default (some of them even with -nodefaults) it would not be nice to users if qemu required explicit:

-audiodev driver=none,id=audio0 -machine audiodev=audio0

when they just want to run a VM and not care about any audio output. Instead this little helper makes it easy to create a dummy audiodev (driver=none) in case there is no audiodev specified for the machine. To make sure users are not surprised by no sound output a helping message is also printed out.

---
 audio/audio.c | 34 ++++++++++++++++++++++++++++++++++
 audio/audio.h |  2 ++
 2 files changed, 36 insertions(+)
audio/audio.c +13 -0
index d72e7db7fb9..8c74bc6b88c 100644
@@ -41,6 +41,7 @@
 #include "sysemu/runstate.h"
 #include "ui/qemu-spice.h"
 #include "trace.h"
+#include "hw/boards.h"
 
 #define AUDIO_CAP "audio"
 #include "audio_int.h"
@@ -2174,6 +2175,39 @@ bool audio_init_audiodevs(void)
     return true;
 }
 
+static void audio_init_dummy(const char *id)
+{
+    Audiodev *dev = g_new0(Audiodev, 1);
+    AudiodevListEntry *e = g_new0(AudiodevListEntry, 1);
+
+    dev->driver = AUDIODEV_DRIVER_NONE;
+    dev->id = g_strdup(id);
+
+    audio_validate_opts(dev, &error_abort);
+    audio_init(dev, NULL);
+
+    e->dev = dev;

audio/audio.c bool audio_init_audiodevs(void) · line 2199

Quoted 10 lines
audio/audio.c +10 -0
+    QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
+}
+
+const char *audio_maybe_init_dummy(const char *default_id)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+
+    if (ms->default_audiodev) {
+        return ms->default_audiodev;
+    }

../audio/audio.c:2197:11: error: ‘MachineState’ {aka ‘struct MachineState’} has no member named ‘default_audiodev’
2197 | if (ms->default_audiodev) {

introduced in next patch

Quoted 31 lines
audio/audio.c +11 -0
+
+    dolog("warning: No audiodev specified for implicit machine devices, "
+          "no audio output will be available for these. "
+          "For setting a backend audiodev for such devices try using "
+          "the audiodev machine option.\n");
+
+    audio_init_dummy(default_id);
+
+    return default_id;
+}
+
 audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
 {
     return (audsettings) {
audio/audio.h +2 -1
index a276ec13eba..81d39526625 100644
@@ -176,6 +176,8 @@ void audio_help(void);
 AudioState *audio_state_by_name(const char *name);
 const char *audio_get_id(QEMUSoundCard *card);
 
+const char *audio_maybe_init_dummy(const char *default_id);
+
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
 
--

2.41.0

Signature · 1 line
Marc-André Lureau
#3 lore raw

PATCH 2/9 Introduce machine property "audiodev"

In reply to Paolo Bonzini

From: Martin Kletzander <[email protected]>

Many machine types have default audio devices with no way to set the underlying audiodev. Instead of adding an option for each and every one of them, this new property can be used as a default during machine initialisation when creating such devices.

[Make the property optional, instead of including it in all machines. - Paolo]
---
 audio/audio.c       |  4 ++--
 hw/core/machine.c   | 28 ++++++++++++++++++++++++++++
 include/hw/boards.h |  7 +++++++
 3 files changed, 37 insertions(+), 2 deletions(-)
audio/audio.c +2 -2
index 8c74bc6b88c..62047ea3069 100644
@@ -2194,8 +2194,8 @@ const char *audio_maybe_init_dummy(const char *default_id)
 {
     MachineState *ms = MACHINE(qdev_get_machine());
 
-    if (ms->default_audiodev) {
-        return ms->default_audiodev;
+    if (ms->audiodev) {
+        return ms->audiodev;
     }
 
     dolog("warning: No audiodev specified for implicit machine devices, "
hw/core/machine.c +28 -0
index da699cf4e14..f677e96a223 100644
@@ -682,6 +682,22 @@ bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type)
     return allowed;
 }
 
+static char *machine_get_audiodev(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->audiodev);
+}
+
+static void machine_set_audiodev(Object *obj, const char *value,
+                                         Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->audiodev);
+    ms->audiodev = g_strdup(value);
+}
+
 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
 {
     int i;
@@ -927,6 +943,17 @@ out_free:
     qapi_free_BootConfiguration(config);
 }
 
+void machine_add_audiodev_property(MachineClass *mc)
+{
+    ObjectClass *oc = OBJECT_CLASS(mc);
+
+    object_class_property_add_str(oc, "audiodev",
+                                  machine_get_audiodev,
+                                  machine_set_audiodev);
+    object_class_property_set_description(oc, "audiodev",
+                                          "Audiodev to use for default machine devices");
+}
+
 static void machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -1132,6 +1159,7 @@ static void machine_finalize(Object *obj)
     g_free(ms->device_memory);
     g_free(ms->nvdimms_state);
     g_free(ms->numa_state);
+    g_free(ms->audiodev);
 }
 
 bool machine_usb(MachineState *machine)
include/hw/boards.h +7 -0
index 6c67af196a3..b5153f5f85b 100644
@@ -24,6 +24,7 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
 
 extern MachineState *current_machine;
 
+void machine_add_audiodev_property(MachineClass *mc);
 void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp);
 bool machine_usb(MachineState *machine);
 int machine_phandle_start(MachineState *machine);
@@ -358,6 +359,12 @@ struct MachineState {
     MemoryRegion *ram;
     DeviceMemoryState *device_memory;
 
+    /*
+     * Included in MachineState for simplicity, but not supported
+     * unless machine_add_audiodev_property is called.
+     */
+    char *audiodev;
+
     ram_addr_t ram_size;
     ram_addr_t maxram_size;
     uint64_t   ram_slots;
Signature · 1 line
2.41.0
#4 lore raw

PATCH 3/9 vl: support -audio BACKEND without model

In reply to Paolo Bonzini

For machines with an embedded audio device, "-audio BACKEND" will set the audiodev property of the machine itself.

---
 softmmu/vl.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
softmmu/vl.c +10 -5
index 5a1413da2aa..70c9eb34dcf 100644
@@ -2933,11 +2933,12 @@ void qemu_init(int argc, char **argv)
                 if (!qdict_haskey(dict, "id")) {
                     qdict_put_str(dict, "id", "audiodev0");
                 }
-                if (!qdict_haskey(dict, "model")) {
-                    error_setg(&error_fatal, "Parameter 'model' is missing");
+                if (qdict_haskey(dict, "model")) {
+                    model = g_strdup(qdict_get_str(dict, "model"));
+                    qdict_del(dict, "model");
+                } else {
+                    model = g_strdup("default");
                 }
-                model = g_strdup(qdict_get_str(dict, "model"));
-                qdict_del(dict, "model");
                 if (is_help_option(model)) {
                     show_valid_soundhw();
                     exit(0);
@@ -2947,7 +2948,11 @@ void qemu_init(int argc, char **argv)
                 visit_type_Audiodev(v, NULL, &dev, &error_fatal);
                 visit_free(v);
                 audio_define(dev);
-                select_soundhw(model, dev->id);
+                if (g_str_equal(model, "default")) {
+                    qdict_put_str(machine_opts_dict, "audiodev", dev->id);
+                } else {
+                    select_soundhw(model, dev->id);
+                }
                 g_free(model);
                 break;
             }
Signature · 1 line
2.41.0
#5 lore raw

PATCH 4/9 hw/arm: Support machine-default audiodev with fallback

In reply to Paolo Bonzini

From: Martin Kletzander <[email protected]>

---
 hw/arm/integratorcp.c | 10 +++++++++-
 hw/arm/musicpal.c     | 11 +++++++++--
 hw/arm/nseries.c      |  4 ++++
 hw/arm/omap2.c        |  8 ++++++++
 hw/arm/palm.c         |  2 ++
 hw/arm/realview.c     | 11 +++++++++++
 hw/arm/spitz.c        | 12 +++++++++---
 hw/arm/versatilepb.c  |  7 +++++++
 hw/arm/vexpress.c     |  4 ++++
 hw/arm/xlnx-zcu102.c  |  5 +++++
 hw/arm/z2.c           | 14 +++++++++++++-
 hw/input/tsc210x.c    |  8 ++++++++
 12 files changed, 89 insertions(+), 7 deletions(-)
hw/arm/integratorcp.c +9 -1
index b109ece3ae0..8b4f8a1a36a 100644
@@ -27,6 +27,7 @@
 #include "hw/irq.h"
 #include "hw/sd/sd.h"
 #include "qom/object.h"
+#include "audio/audio.h"
 
 #define TYPE_INTEGRATOR_CM "integrator_core"
 OBJECT_DECLARE_SIMPLE_TYPE(IntegratorCMState, INTEGRATOR_CM)
@@ -660,7 +661,12 @@ static void integratorcp_init(MachineState *machine)
                                &error_fatal);
     }
 
-    sysbus_create_varargs("pl041", 0x1d000000, pic[25], NULL);
+    dev = qdev_new("pl041");
+    qdev_prop_set_string(dev, "audiodev",
+                         audio_maybe_init_dummy("integrator.defaudio"));
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x1d000000);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[25]);
 
     if (nd_table[0].used)
         smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
@@ -678,6 +684,8 @@ static void integratorcp_machine_init(MachineClass *mc)
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm926");
     mc->default_ram_id = "integrator.ram";
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("integratorcp", integratorcp_machine_init)
hw/arm/musicpal.c +9 -2
index dc4e43e0ee2..05c3f621954 100644
@@ -37,9 +37,9 @@
 #include "qemu/cutils.h"
 #include "qom/object.h"
 #include "hw/net/mv88w8618_eth.h"
+#include "audio/audio.h"
 #include "qemu/error-report.h"
 
-
 #define MP_MISC_BASE            0x80002000
 #define MP_MISC_SIZE            0x00001000
 
@@ -1326,7 +1326,12 @@ static void musicpal_init(MachineState *machine)
         qdev_connect_gpio_out(key_dev, i, qdev_get_gpio_in(dev, i + 15));
     }
 
-    wm8750_dev = i2c_slave_create_simple(i2c, TYPE_WM8750, MP_WM_ADDR);
+    wm8750_dev = i2c_slave_new(TYPE_WM8750, MP_WM_ADDR);
+
+    qdev_prop_set_string(DEVICE(wm8750_dev), "audiodev",
+                         audio_maybe_init_dummy("musicpal.defaudio"));
+    i2c_slave_realize_and_unref(wm8750_dev, i2c, &error_abort);
+
     dev = qdev_new(TYPE_MV88W8618_AUDIO);
     s = SYS_BUS_DEVICE(dev);
     object_property_set_link(OBJECT(dev), "wm8750", OBJECT(wm8750_dev),
@@ -1347,6 +1352,8 @@ static void musicpal_machine_init(MachineClass *mc)
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm926");
     mc->default_ram_size = MP_RAM_DEFAULT_SIZE;
     mc->default_ram_id = "musicpal.ram";
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("musicpal", musicpal_machine_init)
hw/arm/nseries.c +4 -0
index 9e49e9e1776..35aff46b4b4 100644
@@ -1432,6 +1432,8 @@ static void n800_class_init(ObjectClass *oc, void *data)
     /* Actually two chips of 0x4000000 bytes each */
     mc->default_ram_size = 0x08000000;
     mc->default_ram_id = "omap2.dram";
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo n800_type = {
@@ -1452,6 +1454,8 @@ static void n810_class_init(ObjectClass *oc, void *data)
     /* Actually two chips of 0x4000000 bytes each */
     mc->default_ram_size = 0x08000000;
     mc->default_ram_id = "omap2.dram";
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo n810_type = {
hw/arm/omap2.c +8 -0
index d5a2ae7af6e..8b65c0b8ad6 100644
@@ -603,12 +603,20 @@ static struct omap_eac_s *omap_eac_init(struct omap_target_agent_s *ta,
                 qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
 {
     struct omap_eac_s *s = g_new0(struct omap_eac_s, 1);
+    const char *audiodev_id = audio_maybe_init_dummy("eac.defaudio");
 
     s->irq = irq;
     s->codec.rxdrq = *drq ++;
     s->codec.txdrq = *drq;
     omap_eac_reset(s);
 
+    s->codec.card.name = g_strdup(audiodev_id);
+    s->codec.card.state = audio_state_by_name(s->codec.card.name);
+    if (!s->codec.card.state) {
+        error_setg(&error_fatal, "Cannot find audiodev with id '%s'",
+                   s->codec.card.name);
+    }
+
     AUD_register_card("OMAP EAC", &s->codec.card);
 
     memory_region_init_io(&s->iomem, NULL, &omap_eac_ops, s, "omap.eac",
hw/arm/palm.c +2 -0
index 17c11ac4cec..b86f2c331bb 100644
@@ -310,6 +310,8 @@ static void palmte_machine_init(MachineClass *mc)
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
     mc->default_ram_size = 0x02000000;
     mc->default_ram_id = "omap1.dram";
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("cheetah", palmte_machine_init)
hw/arm/realview.c +11 -0
index a5aa2f046ae..ad677dd4d81 100644
@@ -29,6 +29,7 @@
 #include "hw/irq.h"
 #include "hw/i2c/arm_sbcon_i2c.h"
 #include "hw/sd/sd.h"
+#include "audio/audio.h"
 
 #define SMP_BOOT_ADDR 0xe0000000
 #define SMP_BOOTREG_ADDR 0x10000030
@@ -207,6 +208,8 @@ static void realview_init(MachineState *machine,
 
     pl041 = qdev_new("pl041");
     qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
+    qdev_prop_set_string(pl041, "audiodev",
+                         audio_maybe_init_dummy("realview.defaudio"));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(pl041), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(pl041), 0, 0x10004000);
     sysbus_connect_irq(SYS_BUS_DEVICE(pl041), 0, pic[19]);
@@ -412,6 +415,8 @@ static void realview_eb_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_SCSI;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm926");
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo realview_eb_type = {
@@ -430,6 +435,8 @@ static void realview_eb_mpcore_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = 4;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm11mpcore");
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo realview_eb_mpcore_type = {
@@ -446,6 +453,8 @@ static void realview_pb_a8_class_init(ObjectClass *oc, void *data)
     mc->init = realview_pb_a8_init;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a8");
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo realview_pb_a8_type = {
@@ -463,6 +472,8 @@ static void realview_pbx_a9_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = 4;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo realview_pbx_a9_type = {
hw/arm/spitz.c +9 -3
index f732fe0acf9..3620bb63ea9 100644
@@ -35,6 +35,7 @@
 #include "exec/address-spaces.h"
 #include "cpu.h"
 #include "qom/object.h"
+#include "audio/audio.h"
 
 enum spitz_model_e { spitz, akita, borzoi, terrier };
 
@@ -779,10 +780,13 @@ static void spitz_i2c_setup(PXA2xxState *cpu)
     /* Attach the CPU on one end of our I2C bus.  */
     I2CBus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
 
-    DeviceState *wm;
-
     /* Attach a WM8750 to the bus */
-    wm = DEVICE(i2c_slave_create_simple(bus, TYPE_WM8750, 0));
+    I2CSlave *i2c_dev = i2c_slave_new(TYPE_WM8750, 0);
+    DeviceState *wm = DEVICE(i2c_dev);
+
+    qdev_prop_set_string(wm, "audiodev",
+                         audio_maybe_init_dummy("spitz.defaudio"));
+    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
 
     spitz_wm8750_addr(wm, 0, 0);
     qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_WM,
@@ -1037,6 +1041,8 @@ static void spitz_common_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_IDE;
     mc->ignore_memory_transaction_failures = true;
     mc->init = spitz_common_init;
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo spitz_common_info = {
hw/arm/versatilepb.c +7 -0
index 05b9462a5b7..d10008dbd78 100644
@@ -26,6 +26,7 @@
 #include "hw/char/pl011.h"
 #include "hw/sd/sd.h"
 #include "qom/object.h"
+#include "audio/audio.h"
 
 #define VERSATILE_FLASH_ADDR 0x34000000
 #define VERSATILE_FLASH_SIZE (64 * 1024 * 1024)
@@ -343,6 +344,8 @@ static void versatile_init(MachineState *machine, int board_id)
     /* Add PL041 AACI Interface to the LM4549 codec */
     pl041 = qdev_new("pl041");
     qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
+    qdev_prop_set_string(pl041, "audiodev",
+                         audio_maybe_init_dummy("versatilepb.defaudio"));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(pl041), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(pl041), 0, 0x10004000);
     sysbus_connect_irq(SYS_BUS_DEVICE(pl041), 0, sic[24]);
@@ -416,6 +419,8 @@ static void versatilepb_class_init(ObjectClass *oc, void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm926");
     mc->default_ram_id = "versatile.ram";
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo versatilepb_type = {
@@ -434,6 +439,8 @@ static void versatileab_class_init(ObjectClass *oc, void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm926");
     mc->default_ram_id = "versatile.ram";
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo versatileab_type = {
hw/arm/vexpress.c +4 -0
index 56abadd9b8b..4dde7cf631a 100644
@@ -44,6 +44,7 @@
 #include "hw/i2c/arm_sbcon_i2c.h"
 #include "hw/sd/sd.h"
 #include "qom/object.h"
+#include "audio/audio.h"
 
 #define VEXPRESS_BOARD_ID 0x8e0
 #define VEXPRESS_FLASH_SIZE (64 * 1024 * 1024)
@@ -613,6 +614,8 @@ static void vexpress_common_init(MachineState *machine)
 
     pl041 = qdev_new("pl041");
     qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
+    qdev_prop_set_string(pl041, "audiodev",
+                         audio_maybe_init_dummy("vexpress.defaudio"));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(pl041), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(pl041), 0, map[VE_PL041]);
     sysbus_connect_irq(SYS_BUS_DEVICE(pl041), 0, pic[11]);
@@ -776,6 +779,7 @@ static void vexpress_class_init(ObjectClass *oc, void *data)
     mc->ignore_memory_transaction_failures = true;
     mc->default_ram_id = "vexpress.highmem";
 
+    machine_add_audiodev_property(mc);
     object_class_property_add_bool(oc, "secure", vexpress_get_secure,
                                    vexpress_set_secure);
     object_class_property_set_description(oc, "secure",
hw/arm/xlnx-zcu102.c +5 -0
index 21483f75fd9..d7ca2867fea 100644
@@ -24,6 +24,7 @@
 #include "sysemu/device_tree.h"
 #include "qom/object.h"
 #include "net/can_emu.h"
+#include "audio/audio.h"
 
 struct XlnxZCU102 {
     MachineState parent_obj;
@@ -143,6 +144,9 @@ static void xlnx_zcu102_init(MachineState *machine)
 
     object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_XLNX_ZYNQMP);
 
+    qdev_prop_set_string(DEVICE(&s->soc.dp), "audiodev",
+                         audio_maybe_init_dummy("zcu102.defaudio"));
+
     object_property_set_link(OBJECT(&s->soc), "ddr-ram", OBJECT(machine->ram),
                              &error_abort);
     object_property_set_bool(OBJECT(&s->soc), "secure", s->secure,
@@ -275,6 +279,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data)
     mc->default_cpus = XLNX_ZYNQMP_NUM_APU_CPUS;
     mc->default_ram_id = "ddr-ram";
 
+    machine_add_audiodev_property(mc);
     object_class_property_add_bool(oc, "secure", zcu102_get_secure,
                                    zcu102_set_secure);
     object_class_property_set_description(oc, "secure",
hw/arm/z2.c +13 -1
index dc25304290a..745f5bfad94 100644
@@ -27,6 +27,7 @@
 #include "exec/address-spaces.h"
 #include "cpu.h"
 #include "qom/object.h"
+#include "qapi/error.h"
 
 #ifdef DEBUG_Z2
 #define DPRINTF(fmt, ...) \
@@ -307,6 +308,7 @@ static void z2_init(MachineState *machine)
     void *z2_lcd;
     I2CBus *bus;
     DeviceState *wm;
+    I2CSlave *i2c_dev;
 
     /* Setup CPU & memory */
     mpu = pxa270_init(z2_binfo.ram_size, machine->cpu_type);
@@ -328,8 +330,16 @@ static void z2_init(MachineState *machine)
     type_register_static(&aer915_info);
     z2_lcd = ssi_create_peripheral(mpu->ssp[1], TYPE_ZIPIT_LCD);
     bus = pxa2xx_i2c_bus(mpu->i2c[0]);
+
     i2c_slave_create_simple(bus, TYPE_AER915, 0x55);
-    wm = DEVICE(i2c_slave_create_simple(bus, TYPE_WM8750, 0x1b));
+
+    i2c_dev = i2c_slave_new(TYPE_WM8750, 0x1b);
+    wm = DEVICE(i2c_dev);
+
+    qdev_prop_set_string(wm, "audiodev",
+                         audio_maybe_init_dummy("z2.defaudio"));
+    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
+
     mpu->i2s->opaque = wm;
     mpu->i2s->codec_out = wm8750_dac_dat;
     mpu->i2s->codec_in = wm8750_adc_dat;
@@ -348,6 +358,8 @@ static void z2_machine_init(MachineClass *mc)
     mc->init = z2_init;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c5");
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("z2", z2_machine_init)
hw/input/tsc210x.c +8 -0
index f568759e05a..08935424630 100644
@@ -1097,6 +1097,14 @@ static void tsc210x_init(TSC210xState *s,
 
     qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, 1, name);
 
+    const char *audiodev_id = audio_maybe_init_dummy("tsc.defaudio");
+    s->card.name = g_strdup(audiodev_id);
+    s->card.state = audio_state_by_name(s->card.name);
+    if (!s->card.state) {
+        error_setg(&error_fatal, "Cannot find audiodev with id '%s'",
+                   s->card.name);
+    }
+
     AUD_register_card(s->name, &s->card);
 
     qemu_register_reset((void *) tsc210x_reset, s);
Signature · 1 line
2.41.0
#6 lore raw

PATCH 5/9 hw/ppc: Support machine-default audiodev with fallback

In reply to Paolo Bonzini

From: Martin Kletzander <[email protected]>

---
 hw/ppc/prep.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/prep.c +6 -0
index f6fd35fcb9e..739ff0ea8ad 100644
@@ -45,6 +45,7 @@
 #include "trace.h"
 #include "elf.h"
 #include "qemu/units.h"
+#include "audio/audio.h"
 
 /* SMP is not enabled, for now */
 #define MAX_CPUS 1
@@ -310,6 +311,9 @@ static void ibm_40p_init(MachineState *machine)
         dev = DEVICE(isa_dev);
         qdev_prop_set_uint32(dev, "iobase", 0x830);
         qdev_prop_set_uint32(dev, "irq", 10);
+
+        qdev_prop_set_string(dev, "audiodev",
+                             audio_maybe_init_dummy("ppc.defaudio"));
         isa_realize_and_unref(isa_dev, isa_bus, &error_fatal);
 
         isa_dev = isa_new("pc87312");
@@ -426,6 +430,8 @@ static void ibm_40p_machine_init(MachineClass *mc)
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("604");
     mc->default_display = "std";
     mc->default_nic = "pcnet";
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("40p", ibm_40p_machine_init)
Signature · 1 line
2.41.0
#7 lore raw

PATCH 6/9 vt82c686: Support machine-default audiodev with fallback

In reply to Paolo Bonzini
---
 hw/isa/vt82c686.c   |  2 ++
 hw/mips/fuloong2e.c | 12 +++++++++---
 hw/ppc/pegasos2.c   | 10 ++++++++--
 hw/ppc/sam460ex.c   |  2 ++
 4 files changed, 21 insertions(+), 5 deletions(-)
hw/isa/vt82c686.c +2 -0
index 57bdfb4e78c..3ec8e43708a 100644
@@ -578,6 +578,8 @@ static void via_isa_init(Object *obj)
     object_initialize_child(obj, "uhci2", &s->uhci[1], TYPE_VT82C686B_USB_UHCI);
     object_initialize_child(obj, "ac97", &s->ac97, TYPE_VIA_AC97);
     object_initialize_child(obj, "mc97", &s->mc97, TYPE_VIA_MC97);
+
+    object_property_add_alias(obj, "audiodev", OBJECT(&s->ac97), "audiodev");
 }
 
 static const TypeInfo via_isa_info = {
hw/mips/fuloong2e.c +9 -3
index c827f615f3b..d0671824f94 100644
@@ -41,6 +41,7 @@
 #include "sysemu/reset.h"
 #include "sysemu/sysemu.h"
 #include "qemu/error-report.h"
+#include "audio/audio.h"
 
 #define ENVP_PADDR              0x2000
 #define ENVP_VADDR              cpu_mips_phys_to_kseg0(NULL, ENVP_PADDR)
@@ -295,9 +296,12 @@ static void mips_fuloong2e_init(MachineState *machine)
     pci_bus = bonito_init((qemu_irq *)&(env->irq[2]));
 
     /* South bridge -> IP5 */
-    pci_dev = pci_create_simple_multifunction(pci_bus,
-                                              PCI_DEVFN(FULOONG2E_VIA_SLOT, 0),
-                                              TYPE_VT82C686B_ISA);
+    pci_dev = pci_new_multifunction(PCI_DEVFN(FULOONG2E_VIA_SLOT, 0),
+                                    TYPE_VT82C686B_ISA);
+    qdev_prop_set_string(DEVICE(pci_dev), "audiodev",
+                         audio_maybe_init_dummy("fuloong2e.defaudio"));
+    pci_realize_and_unref(pci_dev, pci_bus, &error_abort);
+
     object_property_add_alias(OBJECT(machine), "rtc-time",
                               object_resolve_path_component(OBJECT(pci_dev),
                                                             "rtc"),
@@ -337,6 +341,8 @@ static void mips_fuloong2e_machine_init(MachineClass *mc)
     mc->default_ram_size = 256 * MiB;
     mc->default_ram_id = "fuloong2e.ram";
     mc->minimum_page_bits = 14;
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("fuloong2e", mips_fuloong2e_machine_init)
hw/ppc/pegasos2.c +8 -2
index bd397cf2b5c..45b94cab73a 100644
@@ -37,6 +37,7 @@
 #include "qemu/datadir.h"
 #include "sysemu/device_tree.h"
 #include "hw/ppc/vof.h"
+#include "audio/audio.h"
 
 #include <libfdt.h>
 
@@ -180,8 +181,11 @@ static void pegasos2_init(MachineState *machine)
     pci_bus_irqs(pci_bus, pegasos2_pci_irq, pm, PCI_NUM_PINS);
 
     /* VIA VT8231 South Bridge (multifunction PCI device) */
-    via = OBJECT(pci_create_simple_multifunction(pci_bus, PCI_DEVFN(12, 0),
-                                                 TYPE_VT8231_ISA));
+    via = OBJECT(pci_new_multifunction(PCI_DEVFN(12, 0), TYPE_VT8231_ISA));
+    qdev_prop_set_string(DEVICE(via), "audiodev",
+                         audio_maybe_init_dummy("pegasos2.defaudio"));
+    pci_realize_and_unref(PCI_DEVICE(via), pci_bus, &error_abort);
+
     for (i = 0; i < PCI_NUM_PINS; i++) {
         pm->via_pirq[i] = qdev_get_gpio_in_named(DEVICE(via), "pirq", i);
     }
@@ -564,6 +568,8 @@ static void pegasos2_machine_class_init(ObjectClass *oc, void *data)
     vhc->encode_hpt_for_kvm_pr = vhyp_encode_hpt_for_kvm_pr;
 
     vmc->setprop = pegasos2_setprop;
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo pegasos2_machine_info = {
hw/ppc/sam460ex.c +2 -0
index 1e615b8d355..8c3abc67131 100644
@@ -530,6 +530,8 @@ static void sam460ex_machine_init(MachineClass *mc)
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("460exb");
     mc->default_ram_size = 512 * MiB;
     mc->default_ram_id = "ppc4xx.sdram";
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("sam460ex", sam460ex_machine_init)
Signature · 1 line
2.41.0
#8 lore raw

Re: [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback

Quoted 71 lines · Paolo Bonzini

---

hw/isa/vt82c686.c   |  2 ++
hw/mips/fuloong2e.c | 12 +++++++++---
hw/ppc/pegasos2.c   | 10 ++++++++--
hw/ppc/sam460ex.c   |  2 ++
4 files changed, 21 insertions(+), 5 deletions(-)
hw/isa/vt82c686.c +2 -0
index 57bdfb4e78c..3ec8e43708a 100644
@@ -578,6 +578,8 @@ static void via_isa_init(Object *obj)
    object_initialize_child(obj, "uhci2", &s->uhci[1], TYPE_VT82C686B_USB_UHCI);
    object_initialize_child(obj, "ac97", &s->ac97, TYPE_VIA_AC97);
    object_initialize_child(obj, "mc97", &s->mc97, TYPE_VIA_MC97);
+
+    object_property_add_alias(obj, "audiodev", OBJECT(&s->ac97), "audiodev");
 }
 
 static const TypeInfo via_isa_info = {
hw/mips/fuloong2e.c +9 -3
index c827f615f3b..d0671824f94 100644
@@ -41,6 +41,7 @@
 #include "sysemu/reset.h"
 #include "sysemu/sysemu.h"
 #include "qemu/error-report.h"
+#include "audio/audio.h"
 
 #define ENVP_PADDR              0x2000
 #define ENVP_VADDR              cpu_mips_phys_to_kseg0(NULL, ENVP_PADDR)
@@ -295,9 +296,12 @@ static void mips_fuloong2e_init(MachineState *machine)
    pci_bus = bonito_init((qemu_irq *)&(env->irq[2]));
 
    /* South bridge -> IP5 */
-    pci_dev = pci_create_simple_multifunction(pci_bus,
-                                              PCI_DEVFN(FULOONG2E_VIA_SLOT, 0),
-                                              TYPE_VT82C686B_ISA);
+    pci_dev = pci_new_multifunction(PCI_DEVFN(FULOONG2E_VIA_SLOT, 0),
+                                    TYPE_VT82C686B_ISA);
+    qdev_prop_set_string(DEVICE(pci_dev), "audiodev",
+                         audio_maybe_init_dummy("fuloong2e.defaudio"));
+    pci_realize_and_unref(pci_dev, pci_bus, &error_abort);
+
    object_property_add_alias(OBJECT(machine), "rtc-time",
                              object_resolve_path_component(OBJECT(pci_dev),
                                                            "rtc"),
@@ -337,6 +341,8 @@ static void mips_fuloong2e_machine_init(MachineClass *mc)
    mc->default_ram_size = 256 * MiB;
    mc->default_ram_id = "fuloong2e.ram";
    mc->minimum_page_bits = 14;
+
+    machine_add_audiodev_property(mc);
 }
 
 DEFINE_MACHINE("fuloong2e", mips_fuloong2e_machine_init)
hw/ppc/pegasos2.c +1 -0
index bd397cf2b5c..45b94cab73a 100644
@@ -37,6 +37,7 @@
 #include "qemu/datadir.h"
 #include "sysemu/device_tree.h"
 #include "hw/ppc/vof.h"
+#include "audio/audio.h"
 
 #include <libfdt.h>
 

hw/ppc/pegasos2.c static void pegasos2_init(MachineState *machine) · line 188

Quoted 10 lines
hw/ppc/pegasos2.c +5 -2
@@ -180,8 +181,11 @@ static void pegasos2_init(MachineState *machine)
    pci_bus_irqs(pci_bus, pegasos2_pci_irq, pm, PCI_NUM_PINS);
 
    /* VIA VT8231 South Bridge (multifunction PCI device) */
-    via = OBJECT(pci_create_simple_multifunction(pci_bus, PCI_DEVFN(12, 0),
-                                                 TYPE_VT8231_ISA));
+    via = OBJECT(pci_new_multifunction(PCI_DEVFN(12, 0), TYPE_VT8231_ISA));
+    qdev_prop_set_string(DEVICE(via), "audiodev",
+                         audio_maybe_init_dummy("pegasos2.defaudio"));
+    pci_realize_and_unref(PCI_DEVICE(via), pci_bus, &error_abort);
+

Do not add blank line here, the rest is still part of via init.

Quoted 17 lines
hw/ppc/pegasos2.c +2 -0
    for (i = 0; i < PCI_NUM_PINS; i++) {
        pm->via_pirq[i] = qdev_get_gpio_in_named(DEVICE(via), "pirq", i);
    }
@@ -564,6 +568,8 @@ static void pegasos2_machine_class_init(ObjectClass *oc, void *data)
    vhc->encode_hpt_for_kvm_pr = vhyp_encode_hpt_for_kvm_pr;
 
    vmc->setprop = pegasos2_setprop;
+
+    machine_add_audiodev_property(mc);
 }
 
 static const TypeInfo pegasos2_machine_info = {
hw/ppc/sam460ex.c +0 -0
index 1e615b8d355..8c3abc67131 100644

hw/ppc/sam460ex.c static void sam460ex_machine_init(MachineClass *mc) · line 534

Quoted 5 lines
hw/ppc/sam460ex.c +2 -0
@@ -530,6 +530,8 @@ static void sam460ex_machine_init(MachineClass *mc)
    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("460exb");
    mc->default_ram_size = 512 * MiB;
    mc->default_ram_id = "ppc4xx.sdram";
+
+    machine_add_audiodev_property(mc);

This hunk has nothing to do with vt82686 so probably should be in previoius patch. Also sam460ex embedded sound part is not emulated and can only use PCI sound cards. What this line is needed for? If every machine now needs this call, can it be added in some generic machine init func in hw/core/machine.c instead?

I'm not sure about this whole series. Looks like it gets rid of 71 lines but adding 158 and makes the users' life harder by requireing them to specify drivers they may not even know about. What's the point? Is there still a default to use the normally used audiodev for the platform or people will now get errors and no sound unless they change their command lines?

Regards,
BALATON Zoltan

Quoted 4 lines
hw/ppc/sam460ex.c +0 -0
 }
 
 DEFINE_MACHINE("sam460ex", sam460ex_machine_init)
#9 lore raw

Re: [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback

Quoted 9 lines · BALATON Zoltan

Review

Quoted 5 lines
    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("460exb");
    mc->default_ram_size = 512 * MiB;
    mc->default_ram_id = "ppc4xx.sdram";
(quoted diff) +2 -0
+
+    machine_add_audiodev_property(mc);

This hunk has nothing to do with vt82686 so probably should be in previoius patch. Also sam460ex embedded sound part is not emulated and can only use PCI sound cards. What this line is needed for?

No, this line shouldn't be there.

Quoted 3 lines

If every machine
now needs this call, can it be added in some generic machine init func in hw/core/machine.c instead?

It is not needed by every machine, only by every machine that has embedded sound.

Quoted 6 lines

I'm not sure about this whole series. Looks like it gets rid of 71 lines but adding 158 and makes the users' life harder by requireing them to specify drivers they may not even know about. What's the point? Is there still a default to use the normally used audiodev for the platform or people will now get errors and no sound unless they change their command lines?

I think you're right, I should have sent this series without the last two patches.

The first seven add more functionality, because they let you use -audiodev for configuration of embedded boards. This is why they add some lines of code.

The last two patches instead are the ones that make -audio or -audiodev mandatory. They should be separate and they may not be a good idea without something like "-audio default". And if no "-audio default" is added, there is more code that can go (for example the --audio-drv-list option to configure and CONFIG_AUDIO_DRIVERS).

Paolo

#10 lore raw

Re: [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback

Quoted 34 lines · Paolo Bonzini
Quoted 9 lines · BALATON Zoltan

Review

Quoted 5 lines
    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("460exb");
    mc->default_ram_size = 512 * MiB;
    mc->default_ram_id = "ppc4xx.sdram";
(quoted diff) +2 -0
+
+    machine_add_audiodev_property(mc);

This hunk has nothing to do with vt82686 so probably should be in previoius patch. Also sam460ex embedded sound part is not emulated and can only use PCI sound cards. What this line is needed for?

No, this line shouldn't be there.

Quoted 3 lines

If every machine
now needs this call, can it be added in some generic machine init func in hw/core/machine.c instead?

It is not needed by every machine, only by every machine that has embedded sound.

Quoted 6 lines

I'm not sure about this whole series. Looks like it gets rid of 71 lines but adding 158 and makes the users' life harder by requireing them to specify drivers they may not even know about. What's the point? Is there still a default to use the normally used audiodev for the platform or people will now get errors and no sound unless they change their command lines?

I think you're right, I should have sent this series without the last two patches.

The first seven add more functionality, because they let you use -audiodev for configuration of embedded boards. This is why they add some lines of code.

Quoted 5 lines

The last two patches instead are the ones that make -audio or -audiodev mandatory. They should be separate and they may not be a good idea without something like "-audio default". And if no "-audio default" is added, there is more code that can go (for example the --audio-drv-list option to configure and CONFIG_AUDIO_DRIVERS).

I still don't see the point, because it already works without these changes. With current master one can specify -audiodev for -M paegasos2 and it gives a warning but does the right thing and sets the audiodev for via-ac97. I think the warning can be avoided by using -global to set the via-ac97 audiodev property but since it picks up the -audiodev there's no need to. Apart from the warning this is convenient for the user, what's proposed in this series seems less so. What is the issue this series tries to solve?

Regards,
BALATON Zoltan

#11 lore raw

PATCH 7/9 vl: recognize audiodev groups in configuration files

In reply to Paolo Bonzini

This is necessary for the q35 configuration tests to pass, once audiodev becomes mandatory.

---
 docs/config/q35-emulated.cfg         |  4 ++++
 docs/config/q35-virtio-graphical.cfg |  4 ++++
 softmmu/vl.c                         | 10 ++++++++++
 3 files changed, 18 insertions(+)
docs/config/q35-emulated.cfg +4 -0
index c8806e6d362..b4bd7e858a9 100644
@@ -288,3 +288,7 @@
   driver = "hda-duplex"
   bus = "ich9-hda-audio.0"
   cad = "0"
+  audiodev = "audiodev0"
+
+[audiodev "audiodev0"]
+  driver = "none"                      # CHANGE ME
docs/config/q35-virtio-graphical.cfg +4 -0
index 148b5d2c5e4..820860aefe0 100644
@@ -248,3 +248,7 @@
   driver = "hda-duplex"
   bus = "sound.0"
   cad = "0"
+  audiodev = "audiodev0"
+
+[audiodev "audiodev0"]
+  driver = "none"                      # CHANGE ME
softmmu/vl.c +10 -0
index 70c9eb34dcf..f74fc3d3e40 100644
@@ -2125,6 +2125,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
 static bool is_qemuopts_group(const char *group)
 {
     if (g_str_equal(group, "object") ||
+        g_str_equal(group, "audiodev") ||
         g_str_equal(group, "machine") ||
         g_str_equal(group, "smp-opts") ||
         g_str_equal(group, "boot-opts")) {
@@ -2140,6 +2141,15 @@ static void qemu_record_config_group(const char *group, QDict *dict,
         Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(dict));
         object_option_add_visitor(v);
         visit_free(v);
+
+    } else if (g_str_equal(group, "audiodev")) {
+        Audiodev *dev = NULL;
+        Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(dict));
+        if (visit_type_Audiodev(v, NULL, &dev, errp)) {
+            audio_define(dev);
+        }
+        visit_free(v);
+
     } else if (g_str_equal(group, "machine")) {
         /*
          * Cannot merge string-valued and type-safe dictionaries, so JSON
Signature · 1 line
2.41.0
#12 lore raw

PATCH 8/9 audio: Make AUD_register_card fallible and require audiodev=

In reply to Paolo Bonzini

From: Martin Kletzander <[email protected]>

Now that all callers support error reporting with errp and all machine-default devices use an explicit audiodev, this can be changed. To make the detection easier make AUD_register_card() return false on error.

---
 audio/audio.c        | 7 +++++--
 audio/audio.h        | 2 +-
 hw/arm/omap2.c       | 2 +-
 hw/audio/ac97.c      | 6 +++++-
 hw/audio/adlib.c     | 6 ++++--
 hw/audio/cs4231a.c   | 6 ++++--
 hw/audio/es1370.c    | 5 ++++-
 hw/audio/gus.c       | 6 ++++--
 hw/audio/hda-codec.c | 5 ++++-
 hw/audio/lm4549.c    | 8 +++++---
 hw/audio/pcspk.c     | 4 +---
 hw/audio/sb16.c      | 6 ++++--
 hw/audio/via-ac97.c  | 6 ++++--
 hw/audio/wm8750.c    | 5 ++++-
 hw/display/xlnx_dp.c | 6 ++++--
 hw/input/tsc210x.c   | 2 +-
 hw/usb/dev-audio.c   | 5 ++++-
 17 files changed, 59 insertions(+), 28 deletions(-)
audio/audio.c +5 -2
index 62047ea3069..4fd27309cf8 100644
@@ -1825,15 +1825,18 @@ void audio_free_audiodev_list(AudiodevListHead *head)
     }
 }
 
-void AUD_register_card (const char *name, QEMUSoundCard *card)
+bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
 {
     if (!card->state) {
-        card->state = audio_init(NULL, name);
+        error_setg(errp, "No audiodev specified for %s", name);
+        return false;
     }
 
     card->name = g_strdup (name);
     memset (&card->entries, 0, sizeof (card->entries));
     QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
+
+    return true;
 }
 
 void AUD_remove_card (QEMUSoundCard *card)
audio/audio.h +1 -1
index 81d39526625..44b7547caba 100644
@@ -94,7 +94,7 @@ typedef struct QEMUAudioTimeStamp {
 void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
 void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
 
-void AUD_register_card (const char *name, QEMUSoundCard *card);
+bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
 void AUD_remove_card (QEMUSoundCard *card);
 CaptureVoiceOut *AUD_add_capture(
     AudioState *s,
hw/arm/omap2.c +1 -1
index 8b65c0b8ad6..53c741bbb3b 100644
@@ -617,7 +617,7 @@ static struct omap_eac_s *omap_eac_init(struct omap_target_agent_s *ta,
                    s->codec.card.name);
     }
 
-    AUD_register_card("OMAP EAC", &s->codec.card);
+    AUD_register_card("OMAP EAC", &s->codec.card, &error_abort);
 
     memory_region_init_io(&s->iomem, NULL, &omap_eac_ops, s, "omap.eac",
                           omap_l4_region_size(ta, 0));
hw/audio/ac97.c +5 -1
index c2a5ce062a1..6a7a2dc80c4 100644
@@ -1273,6 +1273,10 @@ static void ac97_realize(PCIDevice *dev, Error **errp)
     AC97LinkState *s = AC97(dev);
     uint8_t *c = s->dev.config;
 
+    if (!AUD_register_card ("ac97", &s->card, errp)) {
+        return;
+    }
+
     /* TODO: no need to override */
     c[PCI_COMMAND] = 0x00;      /* pcicmd pci command rw, ro */
     c[PCI_COMMAND + 1] = 0x00;
@@ -1306,7 +1310,7 @@ static void ac97_realize(PCIDevice *dev, Error **errp)
                           "ac97-nabm", 256);
     pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nam);
     pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nabm);
-    AUD_register_card("ac97", &s->card);
+
     ac97_on_reset(DEVICE(s));
 }
 
hw/audio/adlib.c +4 -2
index 5f979b1487d..bd73806d83a 100644
@@ -255,6 +255,10 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
     AdlibState *s = ADLIB(dev);
     struct audsettings as;
 
+    if (!AUD_register_card ("adlib", &s->card, errp)) {
+        return;
+    }
+
     s->opl = OPLCreate (3579545, s->freq);
     if (!s->opl) {
         error_setg (errp, "OPLCreate %d failed", s->freq);
@@ -270,8 +274,6 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
     as.fmt = AUDIO_FORMAT_S16;
     as.endianness = AUDIO_HOST_ENDIANNESS;
 
-    AUD_register_card ("adlib", &s->card);
-
     s->voice = AUD_open_out (
         &s->card,
         s->voice,
hw/audio/cs4231a.c +4 -2
index 5c6d6437320..3aa105748d3 100644
@@ -678,13 +678,15 @@ static void cs4231a_realizefn (DeviceState *dev, Error **errp)
         return;
     }
 
+    if (!AUD_register_card ("cs4231a", &s->card, errp)) {
+        return;
+    }
+
     s->pic = isa_bus_get_irq(bus, s->irq);
     k = ISADMA_GET_CLASS(s->isa_dma);
     k->register_channel(s->isa_dma, s->dma, cs_dma_read, s);
 
     isa_register_ioport (d, &s->ioports, s->port);
-
-    AUD_register_card ("cs4231a", &s->card);
 }
 
 static Property cs4231a_properties[] = {
hw/audio/es1370.c +4 -1
index 4f738a0ad88..90f73d4c23d 100644
@@ -853,6 +853,10 @@ static void es1370_realize(PCIDevice *dev, Error **errp)
     ES1370State *s = ES1370(dev);
     uint8_t *c = s->dev.config;
 
+    if (!AUD_register_card ("es1370", &s->card, errp)) {
+        return;
+    }
+
     c[PCI_STATUS + 1] = PCI_STATUS_DEVSEL_SLOW >> 8;
 
 #if 0
@@ -868,7 +872,6 @@ static void es1370_realize(PCIDevice *dev, Error **errp)
     memory_region_init_io (&s->io, OBJECT(s), &es1370_io_ops, s, "es1370", 256);
     pci_register_bar (&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
 
-    AUD_register_card ("es1370", &s->card);
     es1370_reset (s);
 }
 
hw/audio/gus.c +4 -2
index 787345ce543..6c2b586ca71 100644
@@ -241,14 +241,16 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     IsaDmaClass *k;
     struct audsettings as;
 
+    if (!AUD_register_card ("gus", &s->card, errp)) {
+        return;
+    }
+
     s->isa_dma = isa_bus_get_dma(bus, s->emu.gusdma);
     if (!s->isa_dma) {
         error_setg(errp, "ISA controller does not support DMA");
         return;
     }
 
-    AUD_register_card ("gus", &s->card);
-
     as.freq = s->freq;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
hw/audio/hda-codec.c +4 -1
index a26048cf15e..b9ad1f4c39e 100644
@@ -685,11 +685,14 @@ static void hda_audio_init(HDACodecDevice *hda,
     const desc_param *param;
     uint32_t i, type;
 
+    if (!AUD_register_card("hda", &a->card, errp)) {
+        return;
+    }
+
     a->desc = desc;
     a->name = object_get_typename(OBJECT(a));
     dprint(a, 1, "%s: cad %d\n", __func__, a->hda.cad);
 
-    AUD_register_card("hda", &a->card);
     for (i = 0; i < a->desc->nnodes; i++) {
         node = a->desc->nodes + i;
         param = hda_codec_find_param(node, AC_PAR_AUDIO_WIDGET_CAP);
hw/audio/lm4549.c +5 -3
index 418041bc9c6..e7bfcc4b9fe 100644
@@ -281,6 +281,11 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque,
 {
     struct audsettings as;
 
+    /* Register an audio card */
+    if (!AUD_register_card("lm4549", &s->card, errp)) {
+        return;
+    }
+
     /* Store the callback and opaque pointer */
     s->data_req_cb = data_req_cb;
     s->opaque = opaque;
@@ -288,9 +293,6 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque,
     /* Init the registers */
     lm4549_reset(s);
 
-    /* Register an audio card */
-    AUD_register_card("lm4549", &s->card);
-
     /* Open a default voice */
     as.freq = 48000;
     as.nchannels = 2;
hw/audio/pcspk.c +1 -3
index daf92a4ce11..fe7f07ced21 100644
@@ -123,8 +123,6 @@ static int pcspk_audio_init(PCSpkState *s)
         return 0;
     }
 
-    AUD_register_card(s_spk, &s->card);
-
     s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
     if (!s->voice) {
         AUD_log(s_spk, "Could not open voice\n");
@@ -191,7 +189,7 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
     isa_register_ioport(isadev, &s->ioport, s->iobase);
 
-    if (s->card.state) {
+    if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
         pcspk_audio_init(s);
     }
 
hw/audio/sb16.c +4 -2
index 535ccccdc98..18f6d252db3 100644
@@ -1402,6 +1402,10 @@ static void sb16_realizefn (DeviceState *dev, Error **errp)
     SB16State *s = SB16 (dev);
     IsaDmaClass *k;
 
+    if (!AUD_register_card ("sb16", &s->card, errp)) {
+        return;
+    }
+
     s->isa_hdma = isa_bus_get_dma(bus, s->hdma);
     s->isa_dma = isa_bus_get_dma(bus, s->dma);
     if (!s->isa_dma || !s->isa_hdma) {
@@ -1434,8 +1438,6 @@ static void sb16_realizefn (DeviceState *dev, Error **errp)
     k->register_channel(s->isa_dma, s->dma, SB_read_DMA, s);
 
     s->can_write = 1;
-
-    AUD_register_card ("sb16", &s->card);
 }
 
 static Property sb16_properties[] = {
hw/audio/via-ac97.c +4 -2
index 676254b7a40..30095a4c7aa 100644
@@ -426,6 +426,10 @@ static void via_ac97_realize(PCIDevice *pci_dev, Error **errp)
     ViaAC97State *s = VIA_AC97(pci_dev);
     Object *o = OBJECT(s);
 
+    if (!AUD_register_card ("via-ac97", &s->card, errp)) {
+        return;
+    }
+
     /*
      * Command register Bus Master bit is documented to be fixed at 0 but it's
      * needed for PCI DMA to work in QEMU. The pegasos2 firmware writes 0 here
@@ -445,8 +449,6 @@ static void via_ac97_realize(PCIDevice *pci_dev, Error **errp)
     pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->fm);
     memory_region_init_io(&s->midi, o, &midi_ops, s, "via-ac97.midi", 4);
     pci_register_bar(pci_dev, 2, PCI_BASE_ADDRESS_SPACE_IO, &s->midi);
-
-    AUD_register_card ("via-ac97", &s->card);
 }
 
 static void via_ac97_exit(PCIDevice *dev)
hw/audio/wm8750.c +4 -1
index b5722b37c36..57954a63144 100644
@@ -624,7 +624,10 @@ static void wm8750_realize(DeviceState *dev, Error **errp)
 {
     WM8750State *s = WM8750(dev);
 
-    AUD_register_card(CODEC, &s->card);
+    if (!AUD_register_card(CODEC, &s->card, errp)) {
+        return;
+    }
+
     wm8750_reset(I2C_SLAVE(s));
 }
 
hw/display/xlnx_dp.c +4 -2
index 341e91e886f..eee8f33a584 100644
@@ -1302,6 +1302,10 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)
     DisplaySurface *surface;
     struct audsettings as;
 
+    if (!AUD_register_card("xlnx_dp.audio", &s->aud_card, errp)) {
+        return;
+    }
+
     aux_bus_realize(s->aux_bus);
 
     qdev_realize(DEVICE(s->dpcd), BUS(s->aux_bus), &error_fatal);
@@ -1320,8 +1324,6 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)
     as.fmt = AUDIO_FORMAT_S16;
     as.endianness = 0;
 
-    AUD_register_card("xlnx_dp.audio", &s->aud_card);
-
     s->amixer_output_stream = AUD_open_out(&s->aud_card,
                                            s->amixer_output_stream,
                                            "xlnx_dp.audio.out",
hw/input/tsc210x.c +1 -1
index 08935424630..67b0780c2c7 100644
@@ -1105,7 +1105,7 @@ static void tsc210x_init(TSC210xState *s,
                    s->card.name);
     }
 
-    AUD_register_card(s->name, &s->card);
+    AUD_register_card(s->name, &s->card, &error_abort);
 
     qemu_register_reset((void *) tsc210x_reset, s);
     vmstate_register(NULL, 0, vmsd, s);
hw/usb/dev-audio.c +4 -1
index 8748c1ba040..d5ac1f8962e 100644
@@ -944,12 +944,15 @@ static void usb_audio_realize(USBDevice *dev, Error **errp)
     USBAudioState *s = USB_AUDIO(dev);
     int i;
 
+    if (!AUD_register_card(TYPE_USB_AUDIO, &s->card, errp)) {
+        return;
+    }
+
     dev->usb_desc = s->multi ? &desc_audio_multi : &desc_audio;
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
     s->dev.opaque = s;
-    AUD_register_card(TYPE_USB_AUDIO, &s->card);
 
     s->out.altset        = ALTSET_OFF;
     s->out.vol.mute      = false;
Signature · 1 line
2.41.0
Reviewed-by on v1 8/9
#13 lore raw

Re: [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev=

Quoted 19 lines · Paolo Bonzini

From: Martin Kletzander <[email protected]>

Now that all callers support error reporting with errp and all machine-default devices use an explicit audiodev, this can be changed. To make the detection easier make AUD_register_card() return false on error.

---
  audio/audio.c        | 7 +++++--
  audio/audio.h        | 2 +-
  hw/arm/omap2.c       | 2 +-
  hw/audio/ac97.c      | 6 +++++-
  hw/audio/adlib.c     | 6 ++++--
  hw/audio/cs4231a.c   | 6 ++++--
  hw/audio/es1370.c    | 5 ++++-
  hw/audio/gus.c       | 6 ++++--
  hw/audio/hda-codec.c | 5 ++++-
  hw/audio/lm4549.c    | 8 +++++---
Quoted 8 lines
  hw/audio/pcspk.c     | 4 +---
  hw/audio/sb16.c      | 6 ++++--
  hw/audio/via-ac97.c  | 6 ++++--
  hw/audio/wm8750.c    | 5 ++++-
  hw/display/xlnx_dp.c | 6 ++++--
  hw/input/tsc210x.c   | 2 +-
  hw/usb/dev-audio.c   | 5 ++++-
  17 files changed, 59 insertions(+), 28 deletions(-)
#14 lore raw

PATCH 9/9 audio: Be more strict during audio backend initialisation

In reply to Paolo Bonzini

From: Martin Kletzander <[email protected]>

Now that audiodev= is required and audio_init() will not be called without and AudioDev we can remove the fallback functionality and error out in case audio drivers fail initialisation or when the driver does not exist.

---
 audio/audio.c                   | 138 ++++++++------------------------
 docs/about/deprecated.rst       |   6 --
 docs/about/removed-features.rst |  11 ++-
 3 files changed, 42 insertions(+), 113 deletions(-)
audio/audio.c +35 -103
index 4fd27309cf8..31e3195c8d7 100644
@@ -74,10 +74,9 @@ void audio_driver_register(audio_driver *drv)
     QLIST_INSERT_HEAD(&audio_drivers, drv, next);
 }
 
-static audio_driver *audio_driver_lookup(const char *name)
+static audio_driver *audio_driver_lookup(const char *name, Error **errp)
 {
     struct audio_driver *d;
-    Error *local_err = NULL;
     int rv;
 
     QLIST_FOREACH(d, &audio_drivers, next) {
@@ -85,15 +84,19 @@ static audio_driver *audio_driver_lookup(const char *name)
             return d;
         }
     }
-    rv = audio_module_load(name, &local_err);
+    rv = audio_module_load(name, errp);
     if (rv > 0) {
         QLIST_FOREACH(d, &audio_drivers, next) {
             if (strcmp(name, d->name) == 0) {
                 return d;
             }
         }
-    } else if (rv < 0) {
-        error_report_err(local_err);
+    }
+
+    if (rv < 0) {
+        error_prepend(errp, "Cannot load audio driver `%s': ", name);
+    } else {
+        error_setg(errp, "Unknown audio driver `%s'", name);
     }
     return NULL;
 }
@@ -1551,31 +1554,27 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
     return total;
 }
 
-static int audio_driver_init(AudioState *s, struct audio_driver *drv,
-                             bool msg, Audiodev *dev)
+static void audio_driver_init(AudioState *s, struct audio_driver *drv,
+                              Audiodev *dev)
 {
     s->drv_opaque = drv->init(dev);
 
-    if (s->drv_opaque) {
-        if (!drv->pcm_ops->get_buffer_in) {
-            drv->pcm_ops->get_buffer_in = audio_generic_get_buffer_in;
-            drv->pcm_ops->put_buffer_in = audio_generic_put_buffer_in;
-        }
-        if (!drv->pcm_ops->get_buffer_out) {
-            drv->pcm_ops->get_buffer_out = audio_generic_get_buffer_out;
-            drv->pcm_ops->put_buffer_out = audio_generic_put_buffer_out;
-        }
-
-        audio_init_nb_voices_out(s, drv);
-        audio_init_nb_voices_in(s, drv);
-        s->drv = drv;
-        return 0;
-    } else {
-        if (msg) {
-            dolog("Could not init `%s' audio driver\n", drv->name);
-        }
-        return -1;
+    if (!s->drv_opaque) {
+        error_setg(&error_fatal, "Could not init `%s' audio driver", drv->name);
     }
+
+    if (!drv->pcm_ops->get_buffer_in) {
+        drv->pcm_ops->get_buffer_in = audio_generic_get_buffer_in;
+        drv->pcm_ops->put_buffer_in = audio_generic_put_buffer_in;
+    }
+    if (!drv->pcm_ops->get_buffer_out) {
+        drv->pcm_ops->get_buffer_out = audio_generic_get_buffer_out;
+        drv->pcm_ops->put_buffer_out = audio_generic_put_buffer_out;
+    }
+
+    audio_init_nb_voices_out(s, drv);
+    audio_init_nb_voices_in(s, drv);
+    s->drv = drv;
 }
 
 static void audio_vm_change_state_handler (void *opaque, bool running,
@@ -1680,59 +1679,26 @@ static const VMStateDescription vmstate_audio = {
 
 static void audio_validate_opts(Audiodev *dev, Error **errp);
 
-static AudiodevListEntry *audiodev_find(
-    AudiodevListHead *head, const char *drvname)
-{
-    AudiodevListEntry *e;
-    QSIMPLEQ_FOREACH(e, head, next) {
-        if (strcmp(AudiodevDriver_str(e->dev->driver), drvname) == 0) {
-            return e;
-        }
-    }
-
-    return NULL;
-}
-
 /*
  * if we have dev, this function was called because of an -audiodev argument =>
  *   initialize a new state with it
  * if dev == NULL => legacy implicit initialization, return the already created
  *   state or create a new one
  */
-static AudioState *audio_init(Audiodev *dev, const char *name)
+static AudioState *audio_init(Audiodev *dev)
 {
     static bool atexit_registered;
-    size_t i;
-    int done = 0;
     const char *drvname = NULL;
     VMChangeStateEntry *e;
     AudioState *s;
-    struct audio_driver *driver;
-    /* silence gcc warning about uninitialized variable */
-    AudiodevListHead head = QSIMPLEQ_HEAD_INITIALIZER(head);
 
-    if (dev) {
-        /* -audiodev option */
-        drvname = AudiodevDriver_str(dev->driver);
-    } else {
-        if (!QTAILQ_EMPTY(&audio_states)) {
-            dev = QTAILQ_FIRST(&audio_states)->dev;
-            if (!g_str_equal(dev->id, "#none")) {
-                dolog("Device %s: audiodev default parameter is deprecated, please "
-                      "specify audiodev=%s\n", name,
-                      dev->id);
-            }
-            return QTAILQ_FIRST(&audio_states);
-        }
-
-        dolog("No audio device specified\n");
-        dev = g_new0(Audiodev, 1);
-        dev->id = g_strdup("#none");
-        dev->driver = AUDIODEV_DRIVER_NONE;
-        dev->u.none.in = g_new0(AudiodevPerDirectionOptions, 1);
-        dev->u.none.out = g_new0(AudiodevPerDirectionOptions, 1);
+    if (!dev) {
+        error_setg(&error_abort, "Mandatory audiodev parameter required");
     }
 
+    /* -audiodev option */
+    drvname = AudiodevDriver_str(dev->driver);
+
     s = g_new0(AudioState, 1);
     s->dev = dev;
 
@@ -1761,41 +1727,7 @@ static AudioState *audio_init(Audiodev *dev, const char *name)
         s->nb_hw_voices_in = 0;
     }
 
-    if (drvname) {
-        driver = audio_driver_lookup(drvname);
-        if (driver) {
-            done = !audio_driver_init(s, driver, true, dev);
-        } else {
-            dolog ("Unknown audio driver `%s'\n", drvname);
-        }
-        if (!done) {
-            free_audio_state(s);
-            return NULL;
-        }
-    } else {
-        for (i = 0; audio_prio_list[i]; i++) {
-            AudiodevListEntry *e = audiodev_find(&head, audio_prio_list[i]);
-            driver = audio_driver_lookup(audio_prio_list[i]);
-
-            if (e && driver) {
-                s->dev = dev = e->dev;
-                audio_validate_opts(dev, &error_abort);
-                done = !audio_driver_init(s, driver, false, dev);
-                if (done) {
-                    e->dev = NULL;
-                    break;
-                }
-            }
-        }
-    }
-    audio_free_audiodev_list(&head);
-
-    if (!done) {
-        driver = audio_driver_lookup("none");
-        done = !audio_driver_init(s, driver, false, dev);
-        assert(done);
-        dolog("warning: Using timer based audio emulation\n");
-    }
+    audio_driver_init(s, audio_driver_lookup(drvname, &error_fatal), dev);
 
     if (dev->timer_period <= 0) {
         s->period_ticks = 1;
@@ -2132,7 +2064,7 @@ void audio_help(void)
     printf("Available audio drivers:\n");
 
     for (i = 0; i < AUDIODEV_DRIVER__MAX; i++) {
-        audio_driver *driver = audio_driver_lookup(AudiodevDriver_str(i));
+        audio_driver *driver = audio_driver_lookup(AudiodevDriver_str(i), NULL);
         if (driver) {
             printf("%s\n", driver->name);
         }
@@ -2170,7 +2102,7 @@ bool audio_init_audiodevs(void)
     AudiodevListEntry *e;
 
     QSIMPLEQ_FOREACH(e, &audiodevs, next) {
-        if (!audio_init(e->dev, NULL)) {
+        if (!audio_init(e->dev)) {
             return false;
         }
     }
@@ -2187,7 +2119,7 @@ static void audio_init_dummy(const char *id)
     dev->id = g_strdup(id);
 
     audio_validate_opts(dev, &error_abort);
-    audio_init(dev, NULL);
+    audio_init(dev);
 
     e->dev = dev;
     QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
docs/about/deprecated.rst +0 -6
index 2f51cf770ae..d59bcf36230 100644
@@ -37,12 +37,6 @@ coverage.
 System emulator command line arguments
 --------------------------------------
 
-Creating sound card devices without ``audiodev=`` property (since 4.2)
-''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
-When not using the deprecated legacy audio config, each sound card
-should specify an ``audiodev=`` property.
-
 Short-form boolean options (since 6.0)
 ''''''''''''''''''''''''''''''''''''''
 
docs/about/removed-features.rst +6 -4
index e75e1b9ac31..56e078ad126 100644
@@ -442,11 +442,13 @@ line using a ``secret`` object instance.
 The ``-audiodev`` and ``-audio`` command line options are now the only
 way to specify audio backend settings.
 
-Creating vnc without ``audiodev=`` property (removed in 8.2)
-''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+Creating sound card devices and vnc without ``audiodev=`` property (removed in 8.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
-When using vnc, you should specify an ``audiodev=`` property if
-you plan to transmit audio through the VNC protocol.
+Each sound card has to specify an ``audiodev=`` property, unless the
+machine defines an ``audiodev=`` property.  Additionally, when using vnc,
+you should specify an ``audiodev=`` property if you plan to transmit audio
+through the VNC protocol.
 
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
Signature · 1 line
2.41.0