qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Alistair Francis <alistair.francis@xilinx.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Michael Walle <michael@walle.cc>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Andrzej Zaborowski" <balrogg@gmail.com>,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
	"Stefan Weil" <sw@weilnetz.de>
Subject: [Qemu-devel] [PATCH v2 2/6] hw/sd/milkymist-memcard: split realize() out of SysBusDevice init()
Date: Tue, 23 Jan 2018 00:58:33 -0300	[thread overview]
Message-ID: <20180123035837.16578-3-f4bug@amsat.org> (raw)
In-Reply-To: <20180123035837.16578-1-f4bug@amsat.org>

Create the SDCard in the realize() function.

Suggested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/sd/milkymist-memcard.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index 1292c0c099..a8e65892c7 100644
--- a/hw/sd/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
@@ -257,27 +257,31 @@ static void milkymist_memcard_reset(DeviceState *d)
     device_reset(DEVICE(s->card));
 }
 
-static int milkymist_memcard_init(SysBusDevice *dev)
+static void milkymist_memcard_init(Object *obj)
+{
+    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);
+}
+
+static void milkymist_memcard_realize(DeviceState *dev, Error **errp)
 {
     MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev);
-    DriveInfo *dinfo;
     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 = {
@@ -300,9 +304,8 @@ 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;
     /* Reason: init() method uses drive_get_next() */
@@ -313,6 +316,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,
 };
 
-- 
2.15.1

  parent reply	other threads:[~2018-01-23  3:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23  3:58 [Qemu-devel] [PATCH v2 0/6] SDHCI: convert legacy devices to the SDBus API (part 6) Philippe Mathieu-Daudé
2018-01-23  3:58 ` [Qemu-devel] [PATCH v2 1/6] hw/sd/milkymist-memcard: use qemu_log_mask() Philippe Mathieu-Daudé
2018-01-31 16:29   ` Alistair Francis
2018-02-01  9:07   ` Michael Walle
2018-01-23  3:58 ` Philippe Mathieu-Daudé [this message]
2018-01-31 16:30   ` [Qemu-devel] [PATCH v2 2/6] hw/sd/milkymist-memcard: split realize() out of SysBusDevice init() Alistair Francis
2018-02-01  9:07   ` Michael Walle
2018-01-23  3:58 ` [Qemu-devel] [PATCH v2 3/6] hw/sd/milkymist-memcard: expose a SDBus and connect the SDCard to it Philippe Mathieu-Daudé
2018-01-31 16:31   ` Alistair Francis
2018-02-01  9:08   ` Michael Walle
2018-01-23  3:58 ` [Qemu-devel] [PATCH v2 4/6] hw/sd/pl181: " Philippe Mathieu-Daudé
2018-01-31 16:41   ` Alistair Francis
2018-02-06 12:43     ` Philippe Mathieu-Daudé
2018-02-06 13:06       ` Peter Maydell
2018-02-06 13:53         ` Philippe Mathieu-Daudé
2018-02-06 13:59           ` Peter Maydell
2018-01-23  3:58 ` [Qemu-devel] [PATCH v2 5/6] hw/sd/ssi-sd: use the SDBus API, connect the SDCard to the bus Philippe Mathieu-Daudé
2018-01-31 16:42   ` Alistair Francis
2018-01-23  3:58 ` [Qemu-devel] [PATCH v2 6/6] hw/sd: move sdcard legacy API to "hw/sd/sdcard_legacy.h" Philippe Mathieu-Daudé
2018-01-31 16:43   ` Alistair Francis
2018-01-31 14:05 ` [Qemu-devel] [PATCH v2 0/6] SDHCI: convert legacy devices to the SDBus API (part 6) Philippe Mathieu-Daudé

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=20180123035837.16578-3-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=alistair.francis@xilinx.com \
    --cc=balrogg@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=michael@walle.cc \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /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).