qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RESEND][PATCH 3/9] microdrive: qdevify
Date: Mon, 25 Apr 2011 13:06:29 +0400	[thread overview]
Message-ID: <1303722395-10791-3-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1303722395-10791-1-git-send-email-dbaryshkov@gmail.com>

Switch dscm1xxxx microdrive driver to use qdev infrastructure.
---
 hw/ide/microdrive.c |   49 +++++++++++++++++++++++++++++++++++++++----------
 hw/pcmcia.h         |    2 +-
 hw/spitz.c          |    5 ++++-
 hw/tosa.c           |    5 ++++-
 4 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index 9fbbf0e..7692603 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -38,8 +38,8 @@
 
 /* DSCM-1XXXX Microdrive hard disk with CF+ II / PCMCIA interface.  */
 typedef struct {
-    IDEBus bus;
     PCMCIACardState card;
+    IDEBus bus;
     uint32_t attr_base;
     uint32_t io_base;
 
@@ -529,22 +529,51 @@ static int dscm1xxxx_detach(void *opaque)
     return 0;
 }
 
-PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv)
+PCMCIACardState *dscm1xxxx_init(PCMCIASocket *socket, DriveInfo *bdrv)
+{
+    DeviceState *dev;
+    MicroDriveState *md;
+
+    dev = qdev_create(&socket->qbus, "dscm1xxxx");
+    qdev_init_nofail(dev);
+    md = DO_UPCAST(MicroDriveState, card.dev, dev);
+
+    ide_create_drive(&md->bus, 0, bdrv);
+    md->bus.ifs[0].drive_kind = IDE_CFATA;
+    md->bus.ifs[0].mdata_size = METADATA_SIZE;
+    md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
+
+    return &md->card;
+}
+
+static int dscm1xxxx_initfn(PCMCIACardState *state)
 {
-    MicroDriveState *md = (MicroDriveState *) qemu_mallocz(sizeof(MicroDriveState));
+    MicroDriveState *md;
+    md = DO_UPCAST(MicroDriveState, card, state);
+
     md->card.state = md;
     md->card.attach = dscm1xxxx_attach;
     md->card.detach = dscm1xxxx_detach;
     md->card.cis = dscm1xxxx_cis;
     md->card.cis_len = sizeof(dscm1xxxx_cis);
 
-    ide_init2_with_non_qdev_drives(&md->bus, bdrv, NULL,
-                                   qemu_allocate_irqs(md_set_irq, md, 1)[0]);
-    md->bus.ifs[0].drive_kind = IDE_CFATA;
-    md->bus.ifs[0].mdata_size = METADATA_SIZE;
-    md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
+    ide_bus_new(&md->bus, &state->dev, 0);
+    qdev_init_gpio_in(&state->dev, md_set_irq, 1);
+    ide_init2(&md->bus, qdev_get_gpio_in(&state->dev, 0));
 
-    vmstate_register(NULL, -1, &vmstate_microdrive, md);
+    return 0;
+}
 
-    return &md->card;
+static PCMCIACardInfo dscm1xxxx_info = {
+    .qdev.name      = "dscm1xxxx",
+    .qdev.desc      = "QEMU CF MicroDrive emulation",
+    .init           = dscm1xxxx_initfn,
+    .qdev.size      = sizeof(MicroDriveState),
+    .qdev.vmsd      = &vmstate_microdrive,
+};
+
+static void dscm1xxxx_register(void)
+{
+    pcmcia_card_register(&dscm1xxxx_info);
 }
+device_init(dscm1xxxx_register);
diff --git a/hw/pcmcia.h b/hw/pcmcia.h
index 561d86c..c6b8100 100644
--- a/hw/pcmcia.h
+++ b/hw/pcmcia.h
@@ -64,4 +64,4 @@ void pcmcia_card_register(PCMCIACardInfo *info);
 DeviceState *pxa2xx_pcmcia_init(target_phys_addr_t base, uint8_t id);
 
 /* dscm1xxxx.c */
-PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv);
+PCMCIACardState *dscm1xxxx_init(PCMCIASocket *socket, DriveInfo *bdrv);
diff --git a/hw/spitz.c b/hw/spitz.c
index ce19b5a..51cc08c 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -714,7 +714,10 @@ static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
         return;
     bs = dinfo->bdrv;
     if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
-        md = dscm1xxxx_init(dinfo);
+        md = dscm1xxxx_init(
+                        DO_UPCAST(PCMCIASocket, qbus,
+                            qdev_get_child_bus(cpu->pcmcia[slot], "pcmcia")),
+                        dinfo);
         pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
     }
 }
diff --git a/hw/tosa.c b/hw/tosa.c
index 577b59f..f00555b 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -59,7 +59,10 @@ static void tosa_microdrive_attach(PXA2xxState *cpu)
         return;
     bs = dinfo->bdrv;
     if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
-        md = dscm1xxxx_init(dinfo);
+        md = dscm1xxxx_init(
+                        DO_UPCAST(PCMCIASocket, qbus,
+                            qdev_get_child_bus(cpu->pcmcia[0], "pcmcia")),
+                        dinfo);
         pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
     }
 }
-- 
1.7.4.1

  parent reply	other threads:[~2011-04-25  9:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-25  9:06 [Qemu-devel] [RESEND][PATCH 1/9] pxa2xx_pcmcia: qdevify Dmitry Eremin-Solenikov
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 2/9] PCMCIA: start qdev'ication Dmitry Eremin-Solenikov
2011-05-16  1:52   ` andrzej zaborowski
2011-05-16  5:10     ` Dmitry Eremin-Solenikov
2011-04-25  9:06 ` Dmitry Eremin-Solenikov [this message]
2011-05-16  2:01   ` [Qemu-devel] [RESEND][PATCH 3/9] microdrive: qdevify andrzej zaborowski
2011-05-16  4:54     ` Dmitry Eremin-Solenikov
2011-05-16 12:26       ` andrzej zaborowski
2011-05-16 13:08         ` Dmitry Eremin-Solenikov
2011-05-17  1:38           ` andrzej zaborowski
2011-05-17  5:44             ` Jan Kiszka
2011-05-17 11:08               ` andrzej zaborowski
2011-05-17 11:33                 ` Jan Kiszka
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 4/9] pcmcia: move all card callbacks to PCMCIACardInfo Dmitry Eremin-Solenikov
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 5/9] pcmcia: move attach and detach socket methods to PCMCIASocket Dmitry Eremin-Solenikov
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 6/9] pxa: change order of pcmcia devices instantiation, so that the socket 0 will be default Dmitry Eremin-Solenikov
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 7/9] ide-core: allocate metadata storage for CFATA drives Dmitry Eremin-Solenikov
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 8/9] strongarm: add PCMCIA support Dmitry Eremin-Solenikov
2011-04-25  9:06 ` [Qemu-devel] [RESEND][PATCH 9/9] collie: add support for PCMCIA bus Dmitry Eremin-Solenikov
2011-04-29 19:40 ` [Qemu-devel] [RESEND][PATCH 1/9] pxa2xx_pcmcia: qdevify Dmitry Eremin-Solenikov
2011-05-03  9:02   ` Dmitry Eremin-Solenikov

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=1303722395-10791-3-git-send-email-dbaryshkov@gmail.com \
    --to=dbaryshkov@gmail.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).