From patchwork Fri Jan 18 12:22:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10770009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C073113B4 for ; Fri, 18 Jan 2019 12:38:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACE9A2CA63 for ; Fri, 18 Jan 2019 12:38:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E4512CAB9; Fri, 18 Jan 2019 12:38:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4A7F12CA63 for ; Fri, 18 Jan 2019 12:38:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:37903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkTPo-0003z0-A3 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Jan 2019 07:38:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkTAX-0007Pv-GK for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:22:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkTAW-0004sF-Hj for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:22:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkTAW-0004Ta-AW for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:22:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD768C05090E for ; Fri, 18 Jan 2019 12:22:11 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CB125C554; Fri, 18 Jan 2019 12:22:11 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D1EDF491B; Fri, 18 Jan 2019 13:22:10 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 13:22:10 +0100 Message-Id: <20190118122210.505-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 18 Jan 2019 12:22:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] audio: fix pc speaker init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Get rid of the pcspk_state global, allow pc speaker be added using "-device isa-pcspk". Signed-off-by: Gerd Hoffmann --- 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; 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);