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 5/9] pcmcia: move attach and detach socket methods to PCMCIASocket
Date: Mon, 25 Apr 2011 13:06:31 +0400	[thread overview]
Message-ID: <1303722395-10791-5-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1303722395-10791-1-git-send-email-dbaryshkov@gmail.com>

Make attach and detach calls to be automatically called by PCMCIA card
instantiation code, rather than calling them by hand from the board
code.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
---
 hw/pcmcia.c        |   45 +++++++++++++++++++++++++++++++-
 hw/pcmcia.h        |    2 +
 hw/pxa.h           |    4 ---
 hw/pxa2xx_pcmcia.c |   73 +++++++++++++++++++++++----------------------------
 hw/spitz.c         |    1 -
 hw/tosa.c          |    1 -
 6 files changed, 79 insertions(+), 47 deletions(-)

diff --git a/hw/pcmcia.c b/hw/pcmcia.c
index 17a49b6..d661663 100644
--- a/hw/pcmcia.c
+++ b/hw/pcmcia.c
@@ -86,16 +86,59 @@ static int pcmcia_device_init(DeviceState *dev, DeviceInfo *info)
 {
     PCMCIACardState *state = DO_UPCAST(PCMCIACardState, dev, dev);
     PCMCIACardInfo *pinfo = DO_UPCAST(PCMCIACardInfo, qdev, info);
+    PCMCIASocket *socket = DO_UPCAST(PCMCIASocket, qbus, dev->parent_bus);
     int rc;
 
+    if (socket->attached) {
+        return -1;
+    }
+
     state->info = pinfo;
     rc = pinfo->init(state);
-    return rc;
+    if (rc) {
+        return rc;
+    }
+
+    socket->attached = 1;
+    state->slot = socket;
+
+    rc = socket->attach(socket, state);
+    if (rc) {
+        return rc;
+    }
+
+    rc = state->info->attach(state);
+    if (rc) {
+        socket->detach(socket);
+        return rc;
+    }
+
+    return 0;
+}
+
+static int pcmcia_device_exit(DeviceState *dev)
+{
+    PCMCIACardState *state = DO_UPCAST(PCMCIACardState, dev, dev);
+    PCMCIASocket *socket = DO_UPCAST(PCMCIASocket, qbus, dev->parent_bus);
+
+    if (!socket->attached) {
+        return -ENOENT;
+    }
+
+    state->info->detach(state);
+    state->slot = NULL;
+
+    socket->detach(socket);
+
+    socket->attached = 0;
+
+    return 0;
 }
 
 void pcmcia_card_register(PCMCIACardInfo *info)
 {
     info->qdev.init = pcmcia_device_init;
+    info->qdev.exit = pcmcia_device_exit;
     info->qdev.bus_info = &pcmcia_bus_info;
     assert(info->qdev.size >= sizeof(PCMCIACardState));
     qdev_register(&info->qdev);
diff --git a/hw/pcmcia.h b/hw/pcmcia.h
index 2c012d9..4f90af7 100644
--- a/hw/pcmcia.h
+++ b/hw/pcmcia.h
@@ -11,6 +11,8 @@ struct PCMCIASocket {
     int attached;
     const char *slot_string;
     const char *card_string;
+    int (*attach)(PCMCIASocket *socket, PCMCIACardState *card);
+    int (*detach)(PCMCIASocket *socket);
 };
 
 void pcmcia_socket_register(PCMCIASocket *socket, DeviceState *parent);
diff --git a/hw/pxa.h b/hw/pxa.h
index 25176ef..c145029 100644
--- a/hw/pxa.h
+++ b/hw/pxa.h
@@ -89,10 +89,6 @@ PXA2xxMMCIState *pxa2xx_mmci_init(target_phys_addr_t base,
 void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
                 qemu_irq coverswitch);
 
-/* pxa2xx_pcmcia.c */
-int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card);
-int pxa2xx_pcmcia_dettach(void *opaque);
-
 /* pxa2xx_keypad.c */
 struct  keymap {
     int column;
diff --git a/hw/pxa2xx_pcmcia.c b/hw/pxa2xx_pcmcia.c
index ae7d01a..efd4c09 100644
--- a/hw/pxa2xx_pcmcia.c
+++ b/hw/pxa2xx_pcmcia.c
@@ -150,6 +150,37 @@ DeviceState *pxa2xx_pcmcia_init(target_phys_addr_t base, uint8_t id)
     return &dev->qdev;
 }
 
+/* Insert a new card into a slot */
+static int pxa2xx_pcmcia_attach(PCMCIASocket *socket, PCMCIACardState *card)
+{
+    PXA2xxPCMCIAState *s = container_of(socket, PXA2xxPCMCIAState, slot);
+
+    if (s->cd_irq) {
+        qemu_irq_raise(s->cd_irq);
+    }
+
+    s->card = card;
+
+    return 0;
+}
+
+/* Eject card from the slot */
+static int pxa2xx_pcmcia_detach(PCMCIASocket *socket)
+{
+    PXA2xxPCMCIAState *s = container_of(socket, PXA2xxPCMCIAState, slot);
+
+    s->card = NULL;
+
+    if (s->irq) {
+        qemu_irq_lower(s->irq);
+    }
+    if (s->cd_irq) {
+        qemu_irq_lower(s->cd_irq);
+    }
+
+    return 0;
+}
+
 static int pxa2xx_pcmcia_initfn(SysBusDevice *dev)
 {
     int iomemtype;
@@ -186,48 +217,10 @@ static int pxa2xx_pcmcia_initfn(SysBusDevice *dev)
     snprintf(str, 256, "PXA PC Card Socket %d", s->id);
     s->slot.slot_string = str;
 
+    s->slot.attach = pxa2xx_pcmcia_attach;
+    s->slot.detach = pxa2xx_pcmcia_detach;
     s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0];
     pcmcia_socket_register(&s->slot, &s->busdev.qdev);
-    return 0;
-}
-
-/* Insert a new card into a slot */
-int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card)
-{
-    PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
-    if (s->slot.attached)
-        return -EEXIST;
-
-    if (s->cd_irq) {
-        qemu_irq_raise(s->cd_irq);
-    }
-
-    s->card = card;
-
-    s->slot.attached = 1;
-    s->card->slot = &s->slot;
-    s->card->info->attach(s->card);
-
-    return 0;
-}
-
-/* Eject card from the slot */
-int pxa2xx_pcmcia_dettach(void *opaque)
-{
-    PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
-    if (!s->slot.attached)
-        return -ENOENT;
-
-    s->card->info->detach(s->card);
-    s->card->slot = NULL;
-    s->card = NULL;
-
-    s->slot.attached = 0;
-
-    if (s->irq)
-        qemu_irq_lower(s->irq);
-    if (s->cd_irq)
-        qemu_irq_lower(s->cd_irq);
 
     return 0;
 }
diff --git a/hw/spitz.c b/hw/spitz.c
index 51cc08c..cf2ee82 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -718,7 +718,6 @@ static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
                         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 f00555b..e867dc4 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -63,7 +63,6 @@ static void tosa_microdrive_attach(PXA2xxState *cpu)
                         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 ` [Qemu-devel] [RESEND][PATCH 3/9] microdrive: qdevify Dmitry Eremin-Solenikov
2011-05-16  2:01   ` 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 ` Dmitry Eremin-Solenikov [this message]
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-5-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).