From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] audio: fix pc speaker init
Date: Wed, 23 Jan 2019 22:01:36 +0100 [thread overview]
Message-ID: <2f82c614-882d-549d-be23-4a65d6e0d876@redhat.com> (raw)
In-Reply-To: <20190118122210.505-1-kraxel@redhat.com>
Hi Gerd,
On 1/18/19 1:22 PM, Gerd Hoffmann wrote:
> 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..acd80eb674 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;
Yeah \o/
>
> 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");
Too bad you fixed this message, it was funny :)
> - 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;
Previously we had soundhw_init() calling pcspk_audio_init() and ignore
failures. Now since you use isa_create_simple() which calls
qdev_init_nofail(), failure will directly exit(1).
Is it the expected behavior?
If not, we can keep the current behavior using:
if (isa_try_create(bus, TYPE_PC_SPEAKER) == NULL) {
return -1;
}
return 0;
Regards,
Phil.
> +}
> +
> static void pcspk_register(void)
> {
> type_register_static(&pcspk_info);
>
next prev parent reply other threads:[~2019-01-23 21:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 12:22 [Qemu-devel] [PATCH] audio: fix pc speaker init Gerd Hoffmann
2019-01-23 19:12 ` no-reply
2019-01-23 21:01 ` Philippe Mathieu-Daudé [this message]
2019-01-24 10:47 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2f82c614-882d-549d-be23-4a65d6e0d876@redhat.com \
--to=philmd@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).