* [Qemu-devel] [PATCH v2] audio: fix pc speaker init
@ 2019-01-24 11:08 Gerd Hoffmann
2019-01-24 11:28 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Gerd Hoffmann @ 2019-01-24 11:08 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Get rid of the pcspk_state global, allow pc speaker
be added using "-device isa-pcspk".
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/audio/pcspk.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 908696d483..b80a62ce90 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -57,7 +57,6 @@ typedef struct {
} PCSpkState;
static const char *s_spk = "pcspk";
-static PCSpkState *pcspk_state;
static inline void generate_samples(PCSpkState *s)
{
@@ -111,22 +110,6 @@ static void pcspk_callback(void *opaque, int free)
}
}
-static int pcspk_audio_init(ISABus *bus)
-{
- PCSpkState *s = pcspk_state;
- struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 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");
- return -1;
- }
-
- return 0;
-}
-
static uint64_t pcspk_io_read(void *opaque, hwaddr addr,
unsigned size)
{
@@ -179,12 +162,20 @@ static void pcspk_initfn(Object *obj)
static void pcspk_realizefn(DeviceState *dev, Error **errp)
{
+ struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 0};
ISADevice *isadev = ISA_DEVICE(dev);
PCSpkState *s = PC_SPEAKER(dev);
isa_register_ioport(isadev, &s->ioport, s->iobase);
- pcspk_state = s;
+ 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) {
+ error_setg(errp, "Initializing audio voice failed");
+ AUD_remove_card(&s->card);
+ return;
+ }
}
static bool migrate_needed(void *opaque)
@@ -221,8 +212,6 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)
set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
dc->vmsd = &vmstate_spk;
dc->props = pcspk_properties;
- /* Reason: realize sets global pcspk_state */
- dc->user_creatable = false;
}
static const TypeInfo pcspk_info = {
@@ -233,6 +222,12 @@ static const TypeInfo pcspk_info = {
.class_init = pcspk_class_initfn,
};
+static int pcspk_audio_init(ISABus *bus)
+{
+ isa_create_simple(bus, TYPE_PC_SPEAKER);
+ return 0;
+}
+
static void pcspk_register(void)
{
type_register_static(&pcspk_info);
--
2.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] audio: fix pc speaker init
2019-01-24 11:08 [Qemu-devel] [PATCH v2] audio: fix pc speaker init Gerd Hoffmann
@ 2019-01-24 11:28 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-01-24 11:28 UTC (permalink / raw)
To: Gerd Hoffmann, qemu-devel
Hi Gerd,
On 1/24/19 12:08 PM, Gerd Hoffmann wrote:
> Get rid of the pcspk_state global, allow pc speaker
> be added using "-device isa-pcspk".
It was not easy to figure what you changed since the discussion on the
v1, but I finally got it: 2 spaces were removed to please
checkpatch/patchew.
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> hw/audio/pcspk.c | 35 +++++++++++++++--------------------
> 1 file changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
> index 908696d483..b80a62ce90 100644
> --- a/hw/audio/pcspk.c
> +++ b/hw/audio/pcspk.c
> @@ -57,7 +57,6 @@ typedef struct {
> } PCSpkState;
>
> static const char *s_spk = "pcspk";
> -static PCSpkState *pcspk_state;
>
> static inline void generate_samples(PCSpkState *s)
> {
> @@ -111,22 +110,6 @@ static void pcspk_callback(void *opaque, int free)
> }
> }
>
> -static int pcspk_audio_init(ISABus *bus)
> -{
> - PCSpkState *s = pcspk_state;
> - struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 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");
> - return -1;
> - }
> -
> - return 0;
> -}
> -
> static uint64_t pcspk_io_read(void *opaque, hwaddr addr,
> unsigned size)
> {
> @@ -179,12 +162,20 @@ static void pcspk_initfn(Object *obj)
>
> static void pcspk_realizefn(DeviceState *dev, Error **errp)
> {
> + struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 0};
> ISADevice *isadev = ISA_DEVICE(dev);
> PCSpkState *s = PC_SPEAKER(dev);
>
> isa_register_ioport(isadev, &s->ioport, s->iobase);
>
> - pcspk_state = s;
> + 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) {
> + error_setg(errp, "Initializing audio voice failed");
> + AUD_remove_card(&s->card);
> + return;
> + }
> }
>
> static bool migrate_needed(void *opaque)
> @@ -221,8 +212,6 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)
> set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
> dc->vmsd = &vmstate_spk;
> dc->props = pcspk_properties;
> - /* Reason: realize sets global pcspk_state */
> - dc->user_creatable = false;
> }
>
> static const TypeInfo pcspk_info = {
> @@ -233,6 +222,12 @@ static const TypeInfo pcspk_info = {
> .class_init = pcspk_class_initfn,
> };
>
> +static int pcspk_audio_init(ISABus *bus)
> +{
> + isa_create_simple(bus, TYPE_PC_SPEAKER);
> + return 0;
> +}
> +
> static void pcspk_register(void)
> {
> type_register_static(&pcspk_info);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-24 11:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-24 11:08 [Qemu-devel] [PATCH v2] audio: fix pc speaker init Gerd Hoffmann
2019-01-24 11:28 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.