Skip to contentSkip to conversation

hw/audio: Make 'soundhw' command line option a QOM interface

RFC PATCH New Philippe Mathieu-Daudé 1 participant 4 messages Apr 30, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover hw/audio: Make 'soundhw' command line option a QOM interface

After looking at Gerd's "audio: deprecate -soundhw":
https://www.mail-archive.com/[email protected]/msg698818.html
I updated a patch I started some time ago.
It is unfinished due to problem with hda-intel and pcspk. I have some idea how to fix pcspk, but it invasive. I haven't looked at hda-intel yet.
Looking at Gerd series, fixing these issue might be trivial for him, so I send this patch as it, in case it helps.

Since v1:
- Include Gerd ISA/PCI stub patches to avoid link failure when target does no kselect the bus.

Regards,

Phil.

Gerd Hoffmann (2):
stubs: add isa_create_simple
stubs: add pci_create_simple

Philippe Mathieu-Daudé (1):
hw/audio: Make 'soundhw' command line option a QOM interface

 include/hw/audio/soundhw.h |  20 +++-
 hw/audio/ac97.c            |  10 +-
 hw/audio/adlib.c           |  13 ++-
 hw/audio/cs4231a.c         |  13 ++-
 hw/audio/es1370.c          |  10 +-
 hw/audio/gus.c             |  13 ++-
 hw/audio/intel-hda.c       |  13 ++-
 hw/audio/pcspk.c           |  14 ++-
 hw/audio/sb16.c            |  13 ++-
 hw/audio/soundhw.c         | 203 ++++++++++++++++++++-----------------
 stubs/isa-bus.c            |   7 ++
 stubs/pci-bus.c            |   7 ++
 stubs/Makefile.objs        |   2 +
 13 files changed, 194 insertions(+), 144 deletions(-)
 create mode 100644 stubs/isa-bus.c
 create mode 100644 stubs/pci-bus.c
Signature · 1 line
2.21.1
#1 lore raw

PATCH v2 1/3 stubs: add isa_create_simple

From: Gerd Hoffmann <[email protected]>

Needed for -soundhw cleanup.

Message-Id: <[email protected]>

[PMD: Use g_assert_not_reached()]
---
 stubs/isa-bus.c     | 7 +++++++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/isa-bus.c
stubs/isa-bus.c new file +7 -0
new file mode 100644
index 0000000000..522f448997
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/isa/isa.h"
+
+ISADevice *isa_create_simple(ISABus *bus, const char *name)
+{
+    g_assert_not_reached();
+}
stubs/Makefile.objs +1 -0
index 45be5dc0ed..c61ff38cc8 100644
@@ -13,6 +13,7 @@ stub-obj-y += get-vm-name.o
 stub-obj-y += iothread.o
 stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
+stub-obj-y += isa-bus.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += machine-init-done.o
Signature · 1 line
2.21.1
#2 lore raw

PATCH v2 2/3 stubs: add pci_create_simple

In reply to Philippe Mathieu-Daudé

From: Gerd Hoffmann <[email protected]>

Needed for -soundhw cleanup.

Message-Id: <[email protected]>

[PMD: Use g_assert_not_reached()]
---
 stubs/pci-bus.c     | 7 +++++++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/pci-bus.c
stubs/pci-bus.c new file +7 -0
new file mode 100644
index 0000000000..a8932fa932
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+
+PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+{
+    g_assert_not_reached();
+}
stubs/Makefile.objs +1 -0
index c61ff38cc8..5e7f2b3f06 100644
@@ -40,6 +40,7 @@ stub-obj-y += target-get-monitor-def.o
 stub-obj-y += vmgenid.o
 stub-obj-y += xen-common.o
 stub-obj-y += xen-hvm.o
+stub-obj-y += pci-bus.o
 stub-obj-y += pci-host-piix.o
 stub-obj-y += ram-block.o
 stub-obj-y += ramfb.o
Signature · 1 line
2.21.1
#3 lore raw

RFC PATCH v2 3/3 hw/audio: Make 'soundhw' command line option a QOM interface

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Introduce the SOUNDHW_CMDLINE_INTERFACE QOM type to replace the deprecated register_soundhw() API.

The conversion of devices calling isa_register_soundhw() / pci_register_soundhw() is easy:
- Add SOUNDHW_CMDLINE_INTERFACE to InterfaceInfo[],
- Set cmdline_name to the soundhw name, the first argument of register_soundhw()to cmdline_name,
- Remove register_soundhw() call.

soundhw.c is rewritten:
- Register the new interface type,
- Use GLib APIs
- Remove register_soundhw() functions.

As the conversion is hardly splitable, it is unfortunately written as a single patch.

---
pcspk and hda-intel are problematic, so the conversion is not finished there, code is marked /* XXX */.

---
 include/hw/audio/soundhw.h |  20 +++-
 hw/audio/ac97.c            |  10 +-
 hw/audio/adlib.c           |  13 ++-
 hw/audio/cs4231a.c         |  13 ++-
 hw/audio/es1370.c          |  10 +-
 hw/audio/gus.c             |  13 ++-
 hw/audio/intel-hda.c       |  13 ++-
 hw/audio/pcspk.c           |  14 ++-
 hw/audio/sb16.c            |  13 ++-
 hw/audio/soundhw.c         | 203 ++++++++++++++++++++-----------------
 10 files changed, 178 insertions(+), 144 deletions(-)
include/hw/audio/soundhw.h +15 -5
index c8eef82418..4d65412493 100644
@@ -1,13 +1,23 @@
 #ifndef HW_SOUNDHW_H
 #define HW_SOUNDHW_H
 
-void isa_register_soundhw(const char *name, const char *descr,
-                          int (*init_isa)(ISABus *bus));
-
-void pci_register_soundhw(const char *name, const char *descr,
-                          int (*init_pci)(PCIBus *bus));
+#include "qom/object.h"
 
 void soundhw_init(void);
 void select_soundhw(const char *optarg);
 
+#define SOUNDHW_CMDLINE_INTERFACE "soundhw-deprecated"
+
+#define SOUNDHW_CMDLINE_CLASS(class) \
+    OBJECT_CLASS_CHECK(SoundHwCmdlineClass, (class), SOUNDHW_CMDLINE_INTERFACE)
+
+typedef struct SoundHwCmdlineClass {
+    /*< private >*/
+    InterfaceClass parent_class;
+    /*< public >*/
+
+    const char *cmdline_name;
+    bool option_used;
+} SoundHwCmdlineClass;
+
 #endif
hw/audio/ac97.c +3 -7
index 1ec87feec0..5599f97f39 100644
@@ -1395,12 +1395,6 @@ static void ac97_exit(PCIDevice *dev)
     AUD_remove_card(&s->card);
 }
 
-static int ac97_init (PCIBus *bus)
-{
-    pci_create_simple(bus, -1, TYPE_AC97);
-    return 0;
-}
-
 static Property ac97_properties[] = {
     DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
     DEFINE_PROP_END_OF_LIST (),
@@ -1410,6 +1404,7 @@ static void ac97_class_init (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     k->realize = ac97_realize;
     k->exit = ac97_exit;
@@ -1422,6 +1417,7 @@ static void ac97_class_init (ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_ac97;
     device_class_set_props(dc, ac97_properties);
     dc->reset = ac97_on_reset;
+    sk->cmdline_name = "ac97";
 }
 
 static const TypeInfo ac97_info = {
@@ -1431,6 +1427,7 @@ static const TypeInfo ac97_info = {
     .class_init    = ac97_class_init,
     .interfaces = (InterfaceInfo[]) {
         { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+        { SOUNDHW_CMDLINE_INTERFACE },
         { },
     },
 };
@@ -1438,7 +1435,6 @@ static const TypeInfo ac97_info = {
 static void ac97_register_types (void)
 {
     type_register_static (&ac97_info);
-    pci_register_soundhw("ac97", "Intel 82801AA AC97 Audio", ac97_init);
 }
 
 type_init (ac97_register_types)
hw/audio/adlib.c +6 -7
index d6c1fb0586..a2b298c264 100644
@@ -308,11 +308,13 @@ static Property adlib_properties[] = {
 static void adlib_class_initfn (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     dc->realize = adlib_realizefn;
     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
     dc->desc = ADLIB_DESC;
     device_class_set_props(dc, adlib_properties);
+    sk->cmdline_name = "adlib";
 }
 
 static const TypeInfo adlib_info = {
@@ -320,18 +322,15 @@ static const TypeInfo adlib_info = {
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof (AdlibState),
     .class_init    = adlib_class_initfn,
+    .interfaces    = (InterfaceInfo[]) {
+        { SOUNDHW_CMDLINE_INTERFACE },
+        { },
+    },
 };
 
-static int Adlib_init (ISABus *bus)
-{
-    isa_create_simple (bus, TYPE_ADLIB);
-    return 0;
-}
-
 static void adlib_register_types (void)
 {
     type_register_static (&adlib_info);
-    isa_register_soundhw("adlib", ADLIB_DESC, Adlib_init);
 }
 
 type_init (adlib_register_types)
hw/audio/cs4231a.c +6 -7
index ffdbb58d6a..bdbb792777 100644
@@ -683,12 +683,6 @@ static void cs4231a_realizefn (DeviceState *dev, Error **errp)
     AUD_register_card ("cs4231a", &s->card);
 }
 
-static int cs4231a_init (ISABus *bus)
-{
-    isa_create_simple (bus, TYPE_CS4231A);
-    return 0;
-}
-
 static Property cs4231a_properties[] = {
     DEFINE_AUDIO_PROPERTIES(CSState, card),
     DEFINE_PROP_UINT32 ("iobase",  CSState, port, 0x534),
@@ -700,6 +694,7 @@ static Property cs4231a_properties[] = {
 static void cs4231a_class_initfn (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     dc->realize = cs4231a_realizefn;
     dc->reset = cs4231a_reset;
@@ -707,6 +702,7 @@ static void cs4231a_class_initfn (ObjectClass *klass, void *data)
     dc->desc = "Crystal Semiconductor CS4231A";
     dc->vmsd = &vmstate_cs4231a;
     device_class_set_props(dc, cs4231a_properties);
+    sk->cmdline_name = "cs4231a";
 }
 
 static const TypeInfo cs4231a_info = {
@@ -715,12 +711,15 @@ static const TypeInfo cs4231a_info = {
     .instance_size = sizeof (CSState),
     .instance_init = cs4231a_initfn,
     .class_init    = cs4231a_class_initfn,
+    .interfaces    = (InterfaceInfo[]) {
+        { SOUNDHW_CMDLINE_INTERFACE },
+        { },
+    },
 };
 
 static void cs4231a_register_types (void)
 {
     type_register_static (&cs4231a_info);
-    isa_register_soundhw("cs4231a", "CS4231A", cs4231a_init);
 }
 
 type_init (cs4231a_register_types)
hw/audio/es1370.c +3 -7
index 89c4dabcd4..e162fe6e95 100644
@@ -881,12 +881,6 @@ static void es1370_exit(PCIDevice *dev)
     AUD_remove_card(&s->card);
 }
 
-static int es1370_init (PCIBus *bus)
-{
-    pci_create_simple (bus, -1, TYPE_ES1370);
-    return 0;
-}
-
 static Property es1370_properties[] = {
     DEFINE_AUDIO_PROPERTIES(ES1370State, card),
     DEFINE_PROP_END_OF_LIST(),
@@ -896,6 +890,7 @@ static void es1370_class_init (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     k->realize = es1370_realize;
     k->exit = es1370_exit;
@@ -909,6 +904,7 @@ static void es1370_class_init (ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_es1370;
     dc->reset = es1370_on_reset;
     device_class_set_props(dc, es1370_properties);
+    sk->cmdline_name = "es1370";
 }
 
 static const TypeInfo es1370_info = {
@@ -918,6 +914,7 @@ static const TypeInfo es1370_info = {
     .class_init    = es1370_class_init,
     .interfaces = (InterfaceInfo[]) {
         { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+        { SOUNDHW_CMDLINE_INTERFACE },
         { },
     },
 };
@@ -925,7 +922,6 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
     type_register_static (&es1370_info);
-    pci_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370", es1370_init);
 }
 
 type_init (es1370_register_types)
hw/audio/gus.c +6 -7
index eb4a803fb5..6ecf7f9a0a 100644
@@ -292,12 +292,6 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     AUD_set_active_out (s->voice, 1);
 }
 
-static int GUS_init (ISABus *bus)
-{
-    isa_create_simple (bus, TYPE_GUS);
-    return 0;
-}
-
 static Property gus_properties[] = {
     DEFINE_AUDIO_PROPERTIES(GUSState, card),
     DEFINE_PROP_UINT32 ("freq",    GUSState, freq,        44100),
@@ -310,12 +304,14 @@ static Property gus_properties[] = {
 static void gus_class_initfn (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     dc->realize = gus_realizefn;
     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
     dc->desc = "Gravis Ultrasound GF1";
     dc->vmsd = &vmstate_gus;
     device_class_set_props(dc, gus_properties);
+    sk->cmdline_name = "gus";
 }
 
 static const TypeInfo gus_info = {
@@ -323,12 +319,15 @@ static const TypeInfo gus_info = {
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof (GUSState),
     .class_init    = gus_class_initfn,
+    .interfaces    = (InterfaceInfo[]) {
+        { SOUNDHW_CMDLINE_INTERFACE },
+        { },
+    },
 };
 
 static void gus_register_types (void)
 {
     type_register_static (&gus_info);
-    isa_register_soundhw("gus", "Gravis Ultrasound GF1", GUS_init);
 }
 
 type_init (gus_register_types)
hw/audio/intel-hda.c +12 -1
index e8d18b7c58..77b4091433 100644
@@ -1281,11 +1281,15 @@ static const TypeInfo intel_hda_info_ich9 = {
 static void hda_codec_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
+    SoundHwCmdlineClass *shc = SOUNDHW_CMDLINE_CLASS(klass);
+
     k->realize = hda_codec_dev_realize;
     k->unrealize = hda_codec_dev_unrealize;
     set_bit(DEVICE_CATEGORY_SOUND, k->categories);
     k->bus_type = TYPE_HDA_BUS;
     device_class_set_props(k, hda_props);
+    k->desc = "Intel HD Audio";
+    shc->cmdline_name = "hda";
 }
 
 static const TypeInfo hda_codec_device_type_info = {
@@ -1295,6 +1299,10 @@ static const TypeInfo hda_codec_device_type_info = {
     .abstract = true,
     .class_size = sizeof(HDACodecDeviceClass),
     .class_init = hda_codec_device_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { SOUNDHW_CMDLINE_INTERFACE },
+        { },
+    },
 };
 
 /*
@@ -1321,7 +1329,10 @@ static void intel_hda_register_types(void)
     type_register_static(&intel_hda_info_ich6);
     type_register_static(&intel_hda_info_ich9);
     type_register_static(&hda_codec_device_type_info);
-    pci_register_soundhw("hda", "Intel HD Audio", intel_hda_and_codec_init);
+
+    if (0) {
+        intel_hda_and_codec_init(NULL); /* XXX */
+    }
 }
 
 type_init(intel_hda_register_types)
hw/audio/pcspk.c +12 -2
index 29dc00bf8d..f9aafea115 100644
@@ -112,7 +112,7 @@ static void pcspk_callback(void *opaque, int free)
     }
 }
 
-static int pcspk_audio_init(ISABus *bus)
+static int pcspk_audio_init(BusState *bus)
 {
     PCSpkState *s = pcspk_state;
     struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUDIO_FORMAT_U8, 0};
@@ -218,14 +218,21 @@ static Property pcspk_properties[] = {
 static void pcspk_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     dc->realize = pcspk_realizefn;
     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
+    dc->desc = "PC speaker";
     dc->vmsd = &vmstate_spk;
     device_class_set_props(dc, pcspk_properties);
     /* Reason: realize sets global pcspk_state */
     /* Reason: pit object link */
     dc->user_creatable = false;
+    sk->cmdline_name = "pcspk";
+
+    if (0) {
+        pcspk_audio_init(NULL); /* XXX */
+    }
 }
 
 static const TypeInfo pcspk_info = {
@@ -234,11 +241,14 @@ static const TypeInfo pcspk_info = {
     .instance_size  = sizeof(PCSpkState),
     .instance_init  = pcspk_initfn,
     .class_init     = pcspk_class_initfn,
+    .interfaces = (InterfaceInfo[]) {
+        { SOUNDHW_CMDLINE_INTERFACE },
+        { },
+    },
 };
 
 static void pcspk_register(void)
 {
     type_register_static(&pcspk_info);
-    isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init);
 }
 type_init(pcspk_register)
hw/audio/sb16.c +6 -7
index df6f755a37..e562338ad7 100644
@@ -1415,12 +1415,6 @@ static void sb16_realizefn (DeviceState *dev, Error **errp)
     AUD_register_card ("sb16", &s->card);
 }
 
-static int SB16_init (ISABus *bus)
-{
-    isa_create_simple (bus, TYPE_SB16);
-    return 0;
-}
-
 static Property sb16_properties[] = {
     DEFINE_AUDIO_PROPERTIES(SB16State, card),
     DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
@@ -1434,12 +1428,14 @@ static Property sb16_properties[] = {
 static void sb16_class_initfn (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
+    SoundHwCmdlineClass *sk = SOUNDHW_CMDLINE_CLASS(klass);
 
     dc->realize = sb16_realizefn;
     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
     dc->desc = "Creative Sound Blaster 16";
     dc->vmsd = &vmstate_sb16;
     device_class_set_props(dc, sb16_properties);
+    sk->cmdline_name = "sb16";
 }
 
 static const TypeInfo sb16_info = {
@@ -1448,12 +1444,15 @@ static const TypeInfo sb16_info = {
     .instance_size = sizeof (SB16State),
     .instance_init = sb16_initfn,
     .class_init    = sb16_class_initfn,
+    .interfaces    = (InterfaceInfo[]) {
+        { SOUNDHW_CMDLINE_INTERFACE },
+        { },
+    },
 };
 
 static void sb16_register_types (void)
 {
     type_register_static (&sb16_info);
-    isa_register_soundhw("sb16", "Creative Sound Blaster 16", SB16_init);
 }
 
 type_init (sb16_register_types)
hw/audio/soundhw.c +109 -94

234 lines not on this page · raw message

Signature · 1 line
2.21.1