qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] audio: make sound cards require the audiodev property
@ 2023-09-22  9:44 Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 1/9] audio: Add easy dummy audio initialiser Paolo Bonzini
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

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: <20230922093126.264016-1-pbonzini@redhat.com>

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(-)

-- 
2.41.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/9] audio: Add easy dummy audio initialiser
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22 11:45   ` Marc-André Lureau
  2023-09-22  9:44 ` [PATCH 2/9] Introduce machine property "audiodev" Paolo Bonzini
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

From: Martin Kletzander <mkletzan@redhat.com>

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.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 audio/audio.c | 34 ++++++++++++++++++++++++++++++++++
 audio/audio.h |  2 ++
 2 files changed, 36 insertions(+)

diff --git a/audio/audio.c b/audio/audio.c
index d72e7db7fb9..8c74bc6b88c 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -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) {
diff --git a/audio/audio.h b/audio/audio.h
index a276ec13eba..81d39526625 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -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



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 2/9] Introduce machine property "audiodev"
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 1/9] audio: Add easy dummy audio initialiser Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 3/9] vl: support -audio BACKEND without model Paolo Bonzini
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

From: Martin Kletzander <mkletzan@redhat.com>

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.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
[Make the property optional, instead of including it in all machines. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 audio/audio.c       |  4 ++--
 hw/core/machine.c   | 28 ++++++++++++++++++++++++++++
 include/hw/boards.h |  7 +++++++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 8c74bc6b88c..62047ea3069 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -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, "
diff --git a/hw/core/machine.c b/hw/core/machine.c
index da699cf4e14..f677e96a223 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -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)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 6c67af196a3..b5153f5f85b 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 3/9] vl: support -audio BACKEND without model
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 1/9] audio: Add easy dummy audio initialiser Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 2/9] Introduce machine property "audiodev" Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 4/9] hw/arm: Support machine-default audiodev with fallback Paolo Bonzini
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 5a1413da2aa..70c9eb34dcf 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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;
             }
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 4/9] hw/arm: Support machine-default audiodev with fallback
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
                   ` (2 preceding siblings ...)
  2023-09-22  9:44 ` [PATCH 3/9] vl: support -audio BACKEND without model Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 5/9] hw/ppc: " Paolo Bonzini
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

From: Martin Kletzander <mkletzan@redhat.com>

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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(-)

diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c
index b109ece3ae0..8b4f8a1a36a 100644
--- a/hw/arm/integratorcp.c
+++ b/hw/arm/integratorcp.c
@@ -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)
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index dc4e43e0ee2..05c3f621954 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -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)
diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
index 9e49e9e1776..35aff46b4b4 100644
--- a/hw/arm/nseries.c
+++ b/hw/arm/nseries.c
@@ -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 = {
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
index d5a2ae7af6e..8b65c0b8ad6 100644
--- a/hw/arm/omap2.c
+++ b/hw/arm/omap2.c
@@ -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",
diff --git a/hw/arm/palm.c b/hw/arm/palm.c
index 17c11ac4cec..b86f2c331bb 100644
--- a/hw/arm/palm.c
+++ b/hw/arm/palm.c
@@ -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)
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index a5aa2f046ae..ad677dd4d81 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -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 = {
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index f732fe0acf9..3620bb63ea9 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -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 = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index 05b9462a5b7..d10008dbd78 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -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 = {
diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index 56abadd9b8b..4dde7cf631a 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -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",
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
index 21483f75fd9..d7ca2867fea 100644
--- a/hw/arm/xlnx-zcu102.c
+++ b/hw/arm/xlnx-zcu102.c
@@ -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",
diff --git a/hw/arm/z2.c b/hw/arm/z2.c
index dc25304290a..745f5bfad94 100644
--- a/hw/arm/z2.c
+++ b/hw/arm/z2.c
@@ -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)
diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c
index f568759e05a..08935424630 100644
--- a/hw/input/tsc210x.c
+++ b/hw/input/tsc210x.c
@@ -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);
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 5/9] hw/ppc: Support machine-default audiodev with fallback
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
                   ` (3 preceding siblings ...)
  2023-09-22  9:44 ` [PATCH 4/9] hw/arm: Support machine-default audiodev with fallback Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 6/9] vt82c686: " Paolo Bonzini
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

From: Martin Kletzander <mkletzan@redhat.com>

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/ppc/prep.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index f6fd35fcb9e..739ff0ea8ad 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -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)
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
                   ` (4 preceding siblings ...)
  2023-09-22  9:44 ` [PATCH 5/9] hw/ppc: " Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22 12:16   ` BALATON Zoltan
  2023-09-22  9:44 ` [PATCH 7/9] vl: recognize audiodev groups in configuration files Paolo Bonzini
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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(-)

diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 57bdfb4e78c..3ec8e43708a 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -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 = {
diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
index c827f615f3b..d0671824f94 100644
--- a/hw/mips/fuloong2e.c
+++ b/hw/mips/fuloong2e.c
@@ -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)
diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
index bd397cf2b5c..45b94cab73a 100644
--- a/hw/ppc/pegasos2.c
+++ b/hw/ppc/pegasos2.c
@@ -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 = {
diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index 1e615b8d355..8c3abc67131 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -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)
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 7/9] vl: recognize audiodev groups in configuration files
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
                   ` (5 preceding siblings ...)
  2023-09-22  9:44 ` [PATCH 6/9] vt82c686: " Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev= Paolo Bonzini
  2023-09-22  9:44 ` [PATCH 9/9] audio: Be more strict during audio backend initialisation Paolo Bonzini
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 docs/config/q35-emulated.cfg         |  4 ++++
 docs/config/q35-virtio-graphical.cfg |  4 ++++
 softmmu/vl.c                         | 10 ++++++++++
 3 files changed, 18 insertions(+)

diff --git a/docs/config/q35-emulated.cfg b/docs/config/q35-emulated.cfg
index c8806e6d362..b4bd7e858a9 100644
--- a/docs/config/q35-emulated.cfg
+++ b/docs/config/q35-emulated.cfg
@@ -288,3 +288,7 @@
   driver = "hda-duplex"
   bus = "ich9-hda-audio.0"
   cad = "0"
+  audiodev = "audiodev0"
+
+[audiodev "audiodev0"]
+  driver = "none"                      # CHANGE ME
diff --git a/docs/config/q35-virtio-graphical.cfg b/docs/config/q35-virtio-graphical.cfg
index 148b5d2c5e4..820860aefe0 100644
--- a/docs/config/q35-virtio-graphical.cfg
+++ b/docs/config/q35-virtio-graphical.cfg
@@ -248,3 +248,7 @@
   driver = "hda-duplex"
   bus = "sound.0"
   cad = "0"
+  audiodev = "audiodev0"
+
+[audiodev "audiodev0"]
+  driver = "none"                      # CHANGE ME
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 70c9eb34dcf..f74fc3d3e40 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev=
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
                   ` (6 preceding siblings ...)
  2023-09-22  9:44 ` [PATCH 7/9] vl: recognize audiodev groups in configuration files Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  2023-09-22 11:17   ` Philippe Mathieu-Daudé
  2023-09-22  9:44 ` [PATCH 9/9] audio: Be more strict during audio backend initialisation Paolo Bonzini
  8 siblings, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

From: Martin Kletzander <mkletzan@redhat.com>

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.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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(-)

diff --git a/audio/audio.c b/audio/audio.c
index 62047ea3069..4fd27309cf8 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -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)
diff --git a/audio/audio.h b/audio/audio.h
index 81d39526625..44b7547caba 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -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,
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
index 8b65c0b8ad6..53c741bbb3b 100644
--- a/hw/arm/omap2.c
+++ b/hw/arm/omap2.c
@@ -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));
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index c2a5ce062a1..6a7a2dc80c4 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -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));
 }
 
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 5f979b1487d..bd73806d83a 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -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,
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 5c6d6437320..3aa105748d3 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -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[] = {
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 4f738a0ad88..90f73d4c23d 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -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);
 }
 
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 787345ce543..6c2b586ca71 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -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;
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index a26048cf15e..b9ad1f4c39e 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -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);
diff --git a/hw/audio/lm4549.c b/hw/audio/lm4549.c
index 418041bc9c6..e7bfcc4b9fe 100644
--- a/hw/audio/lm4549.c
+++ b/hw/audio/lm4549.c
@@ -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;
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index daf92a4ce11..fe7f07ced21 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -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);
     }
 
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index 535ccccdc98..18f6d252db3 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -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[] = {
diff --git a/hw/audio/via-ac97.c b/hw/audio/via-ac97.c
index 676254b7a40..30095a4c7aa 100644
--- a/hw/audio/via-ac97.c
+++ b/hw/audio/via-ac97.c
@@ -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)
diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c
index b5722b37c36..57954a63144 100644
--- a/hw/audio/wm8750.c
+++ b/hw/audio/wm8750.c
@@ -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));
 }
 
diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c
index 341e91e886f..eee8f33a584 100644
--- a/hw/display/xlnx_dp.c
+++ b/hw/display/xlnx_dp.c
@@ -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",
diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c
index 08935424630..67b0780c2c7 100644
--- a/hw/input/tsc210x.c
+++ b/hw/input/tsc210x.c
@@ -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);
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index 8748c1ba040..d5ac1f8962e 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -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;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 9/9] audio: Be more strict during audio backend initialisation
  2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
                   ` (7 preceding siblings ...)
  2023-09-22  9:44 ` [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev= Paolo Bonzini
@ 2023-09-22  9:44 ` Paolo Bonzini
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: mkletzan

From: Martin Kletzander <mkletzan@redhat.com>

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.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 audio/audio.c                   | 138 ++++++++------------------------
 docs/about/deprecated.rst       |   6 --
 docs/about/removed-features.rst |  11 ++-
 3 files changed, 42 insertions(+), 113 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 4fd27309cf8..31e3195c8d7 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -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);
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
index 2f51cf770ae..d59bcf36230 100644
--- a/docs/about/deprecated.rst
+++ b/docs/about/deprecated.rst
@@ -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)
 ''''''''''''''''''''''''''''''''''''''
 
diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst
index e75e1b9ac31..56e078ad126 100644
--- a/docs/about/removed-features.rst
+++ b/docs/about/removed-features.rst
@@ -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
 ------------------------------------
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev=
  2023-09-22  9:44 ` [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev= Paolo Bonzini
@ 2023-09-22 11:17   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-22 11:17 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: mkletzan

On 22/9/23 11:44, Paolo Bonzini wrote:
> From: Martin Kletzander <mkletzan@redhat.com>
> 
> 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.
> 
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   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(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/9] audio: Add easy dummy audio initialiser
  2023-09-22  9:44 ` [PATCH 1/9] audio: Add easy dummy audio initialiser Paolo Bonzini
@ 2023-09-22 11:45   ` Marc-André Lureau
  0 siblings, 0 replies; 15+ messages in thread
From: Marc-André Lureau @ 2023-09-22 11:45 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, mkletzan

Hi

On Fri, Sep 22, 2023 at 1:46 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> From: Martin Kletzander <mkletzan@redhat.com>
>
> 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.
>
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  audio/audio.c | 34 ++++++++++++++++++++++++++++++++++
>  audio/audio.h |  2 ++
>  2 files changed, 36 insertions(+)
>
> diff --git a/audio/audio.c b/audio/audio.c
> index d72e7db7fb9..8c74bc6b88c 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -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;
> +    }

../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

> +
> +    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) {
> diff --git a/audio/audio.h b/audio/audio.h
> index a276ec13eba..81d39526625 100644
> --- a/audio/audio.h
> +++ b/audio/audio.h
> @@ -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
>
>


-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback
  2023-09-22  9:44 ` [PATCH 6/9] vt82c686: " Paolo Bonzini
@ 2023-09-22 12:16   ` BALATON Zoltan
  2023-09-22 13:32     ` Paolo Bonzini
  0 siblings, 1 reply; 15+ messages in thread
From: BALATON Zoltan @ 2023-09-22 12:16 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, mkletzan

On Fri, 22 Sep 2023, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 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(-)
>
> diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
> index 57bdfb4e78c..3ec8e43708a 100644
> --- a/hw/isa/vt82c686.c
> +++ b/hw/isa/vt82c686.c
> @@ -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 = {
> diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
> index c827f615f3b..d0671824f94 100644
> --- a/hw/mips/fuloong2e.c
> +++ b/hw/mips/fuloong2e.c
> @@ -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)
> diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
> index bd397cf2b5c..45b94cab73a 100644
> --- a/hw/ppc/pegasos2.c
> +++ b/hw/ppc/pegasos2.c
> @@ -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);
> +

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

>     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 = {
> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
> index 1e615b8d355..8c3abc67131 100644
> --- a/hw/ppc/sam460ex.c
> +++ b/hw/ppc/sam460ex.c
> @@ -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

> }
>
> DEFINE_MACHINE("sam460ex", sam460ex_machine_init)
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback
  2023-09-22 12:16   ` BALATON Zoltan
@ 2023-09-22 13:32     ` Paolo Bonzini
  2023-09-22 23:54       ` BALATON Zoltan
  0 siblings, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2023-09-22 13:32 UTC (permalink / raw)
  To: BALATON Zoltan; +Cc: qemu-devel, mkletzan

On Fri, Sep 22, 2023 at 2:17 PM BALATON Zoltan <balaton@eik.bme.hu> wrote:
> >     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?

No, this line shouldn't be there.

> 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.

> 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



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/9] vt82c686: Support machine-default audiodev with fallback
  2023-09-22 13:32     ` Paolo Bonzini
@ 2023-09-22 23:54       ` BALATON Zoltan
  0 siblings, 0 replies; 15+ messages in thread
From: BALATON Zoltan @ 2023-09-22 23:54 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, mkletzan

[-- Attachment #1: Type: text/plain, Size: 2314 bytes --]

On Fri, 22 Sep 2023, Paolo Bonzini wrote:
> On Fri, Sep 22, 2023 at 2:17 PM BALATON Zoltan <balaton@eik.bme.hu> wrote:
>>>     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?
>
> No, this line shouldn't be there.
>
>> 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.
>
>> 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).

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-09-22 23:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
2023-09-22  9:44 ` [PATCH 1/9] audio: Add easy dummy audio initialiser Paolo Bonzini
2023-09-22 11:45   ` Marc-André Lureau
2023-09-22  9:44 ` [PATCH 2/9] Introduce machine property "audiodev" Paolo Bonzini
2023-09-22  9:44 ` [PATCH 3/9] vl: support -audio BACKEND without model Paolo Bonzini
2023-09-22  9:44 ` [PATCH 4/9] hw/arm: Support machine-default audiodev with fallback Paolo Bonzini
2023-09-22  9:44 ` [PATCH 5/9] hw/ppc: " Paolo Bonzini
2023-09-22  9:44 ` [PATCH 6/9] vt82c686: " Paolo Bonzini
2023-09-22 12:16   ` BALATON Zoltan
2023-09-22 13:32     ` Paolo Bonzini
2023-09-22 23:54       ` BALATON Zoltan
2023-09-22  9:44 ` [PATCH 7/9] vl: recognize audiodev groups in configuration files Paolo Bonzini
2023-09-22  9:44 ` [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev= Paolo Bonzini
2023-09-22 11:17   ` Philippe Mathieu-Daudé
2023-09-22  9:44 ` [PATCH 9/9] audio: Be more strict during audio backend initialisation Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).