From patchwork Tue Jan 9 16:54:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 10152925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EE94A601A1 for ; Tue, 9 Jan 2018 16:55:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD00E223C7 for ; Tue, 9 Jan 2018 16:55:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D023D283BD; Tue, 9 Jan 2018 16:55:22 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 08594223C7 for ; Tue, 9 Jan 2018 16:55:21 +0000 (UTC) Received: from localhost ([::1]:34232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYxBI-0003JO-QU for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jan 2018 11:55:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYxAc-0002me-OR for qemu-devel@nongnu.org; Tue, 09 Jan 2018 11:54:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYxAb-0000MZ-PV for qemu-devel@nongnu.org; Tue, 09 Jan 2018 11:54:38 -0500 Received: from ssl.serverraum.org ([2a01:4f8:222:d45::1:2]:52859) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eYxAY-0000IA-Tl; Tue, 09 Jan 2018 11:54:35 -0500 Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher DHE-RSA-CAMELLIA256-SHA256 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id C14F922234; Tue, 9 Jan 2018 17:54:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1515516870; bh=ga/Rg7IMsdxfMhlPNvKR13sc3kROjThbc/aDcvmYU2U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QGFufOhrZUzBxWvQZ4AT2RddrbmBM+s++a0twt+rGLTtO0DHguXpP386C5SRJhv+8 ouO6EpJe3cji/v8xxuZCJLyEPQCAoyacyHmRmBD3FzLxB62CajHI5xaQx3Vjo5anCu hqw3QopeXV4dPiz4OBldmH13GQm6+GhO7dgtGBG8= MIME-Version: 1.0 Date: Tue, 09 Jan 2018 17:54:30 +0100 From: Michael Walle To: =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= In-Reply-To: <20180103162400.10396-3-f4bug@amsat.org> References: <20180103162400.10396-1-f4bug@amsat.org> <20180103162400.10396-3-f4bug@amsat.org> Message-ID: <60c89dbec86c14e2f0883d121872d0f6@walle.cc> X-Sender: michael@walle.cc User-Agent: Roundcube Webmail/1.2.3 X-Virus-Scanned: clamav-milter 0.99.2 at web X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a01:4f8:222:d45::1:2 Subject: Re: [Qemu-devel] [PATCH 2/6] hw/sd/milkymist-memcard: split realize() out of SysBusDevice 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: "Edgar E . Iglesias" , Peter Maydell , Xiaoqiang Zhao , qemu-devel@nongnu.org, Alistair Francis , qemu-arm@nongnu.org, =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hey Philippe, Am 2018-01-03 17:23, schrieb Philippe Mathieu-Daudé: > Create the SDCard in the realize() function. > > Signed-off-by: Philippe Mathieu-Daudé > --- > hw/sd/milkymist-memcard.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c > index 5de3e00e2f..5df3a0f815 100644 > --- a/hw/sd/milkymist-memcard.c > +++ b/hw/sd/milkymist-memcard.c > @@ -255,24 +255,29 @@ static void milkymist_memcard_reset(DeviceState > *d) > static int milkymist_memcard_init(SysBusDevice *dev) > { > MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev); > - DriveInfo *dinfo; > + > + memory_region_init_io(&s->regs_region, OBJECT(s), > &memcard_mmio_ops, s, > + "milkymist-memcard", R_MAX * 4); > + sysbus_init_mmio(dev, &s->regs_region); > + > + return 0; > +} Creating the device (milkymist_memcard_create()) fails with an assertion: sysbus_mmio_map_common: Assertion `n >= 0 && n < dev->num_mmio' failed. because dev->num_mmio is still 0. Seems that sysbus_init_mmio() hasn't been called yet. Do we have to move the milkymist_memcard_init() to .instance_init? Eg. static void milkymist_memcard_realize(DeviceState *dev, Error **errp) @@ -300,9 +299,7 @@ static const VMStateDescription vmstate_milkymist_memcard = { static void milkymist_memcard_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = milkymist_memcard_init; dc->realize = milkymist_memcard_realize; dc->reset = milkymist_memcard_reset; dc->vmsd = &vmstate_milkymist_memcard; @@ -314,6 +311,7 @@ static const TypeInfo milkymist_memcard_info = { .name = TYPE_MILKYMIST_MEMCARD, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(MilkymistMemcardState), + .instance_init = milkymist_memcard_init, .class_init = milkymist_memcard_class_init, }; -michael > + > +static void milkymist_memcard_realize(DeviceState *dev, Error **errp) > +{ > + MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev); > BlockBackend *blk; > + DriveInfo *dinfo; > > /* FIXME use a qdev drive property instead of drive_get_next() */ > dinfo = drive_get_next(IF_SD); > blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; > s->card = sd_init(blk, false); > if (s->card == NULL) { > - return -1; > + error_setg(errp, "failed to init SD card"); > + return; > } > - > s->enabled = blk && blk_is_inserted(blk); > - > - memory_region_init_io(&s->regs_region, OBJECT(s), > &memcard_mmio_ops, s, > - "milkymist-memcard", R_MAX * 4); > - sysbus_init_mmio(dev, &s->regs_region); > - > - return 0; > } > > static const VMStateDescription vmstate_milkymist_memcard = { > @@ -298,6 +303,7 @@ static void > milkymist_memcard_class_init(ObjectClass *klass, void *data) > SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); > > k->init = milkymist_memcard_init; > + dc->realize = milkymist_memcard_realize; > dc->reset = milkymist_memcard_reset; > dc->vmsd = &vmstate_milkymist_memcard; > /* Reason: init() method uses drive_get_next() */ diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 5df3a0f815..21c0e91926 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -252,15 +252,14 @@ static void milkymist_memcard_reset(DeviceState *d) } } -static int milkymist_memcard_init(SysBusDevice *dev) +static void milkymist_memcard_init(Object *obj) { - MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev); + MilkymistMemcardState *s = MILKYMIST_MEMCARD(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, "milkymist-memcard", R_MAX * 4); sysbus_init_mmio(dev, &s->regs_region); - - return 0; }