qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@gmail.com, peter.crosthwaite@xilinx.com,
	michael@walle.cc, armbru@redhat.com, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH for-2.3 v2 1/2] sd: move blk_attach_dev_nofail to caller
Date: Mon, 23 Mar 2015 15:55:37 +0100	[thread overview]
Message-ID: <1427122538-26060-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1427122538-26060-1-git-send-email-pbonzini@redhat.com>

blk_attach_dev might not be necessary for devices that use a drive-type
property.  It is not appropriate to make the call unconditional in
sd_init.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/sd/milkymist-memcard.c | 3 +++
 hw/sd/omap_mmc.c          | 4 ++++
 hw/sd/pl181.c             | 7 ++++++-
 hw/sd/pxa2xx_mmci.c       | 4 ++++
 hw/sd/sd.c                | 1 -
 hw/sd/sdhci.c             | 7 ++++++-
 hw/sd/ssi-sd.c            | 7 ++++++-
 7 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index 9661eaf..dc81b9b 100644
--- a/hw/sd/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
@@ -257,6 +257,9 @@ static int milkymist_memcard_init(SysBusDevice *dev)
 
     dinfo = drive_get_next(IF_SD);
     blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
+    if (blk) {
+        blk_attach_dev_nofail(blk, s);
+    }
     s->card = sd_init(blk, false);
     if (s->card == NULL) {
         return -1;
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index d072dec..f169cb1 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -19,6 +19,7 @@
 #include "hw/hw.h"
 #include "hw/arm/omap.h"
 #include "hw/sd.h"
+#include "sysemu/block-backend.h"
 
 struct omap_mmc_s {
     qemu_irq irq;
@@ -621,6 +622,9 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
     omap_l4_attach(ta, 0, &s->iomem);
 
     /* Instantiate the storage */
+    if (blk) {
+        blk_attach_dev_nofail(blk, s);
+    }
     s->card = sd_init(blk, false);
     if (s->card == NULL) {
         exit(1);
diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c
index e704b6e..1b7a72f 100644
--- a/hw/sd/pl181.c
+++ b/hw/sd/pl181.c
@@ -484,6 +484,7 @@ static int pl181_init(SysBusDevice *sbd)
     DeviceState *dev = DEVICE(sbd);
     PL181State *s = PL181(dev);
     DriveInfo *dinfo;
+    BlockBackend *blk;
 
     memory_region_init_io(&s->iomem, OBJECT(s), &pl181_ops, s, "pl181", 0x1000);
     sysbus_init_mmio(sbd, &s->iomem);
@@ -491,7 +492,11 @@ static int pl181_init(SysBusDevice *sbd)
     sysbus_init_irq(sbd, &s->irq[1]);
     qdev_init_gpio_out(dev, s->cardstatus, 2);
     dinfo = drive_get_next(IF_SD);
-    s->card = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false);
+    blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
+    if (blk) {
+        blk_attach_dev_nofail(blk, s);
+    }
+    s->card = sd_init(blk, false);
     if (s->card == NULL) {
         return -1;
     }
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index ac3ab39..0366414 100644
--- a/hw/sd/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -14,6 +14,7 @@
 #include "hw/arm/pxa.h"
 #include "hw/sd.h"
 #include "hw/qdev.h"
+#include "sysemu/block-backend.h"
 
 struct PXA2xxMMCIState {
     MemoryRegion iomem;
@@ -538,6 +539,9 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
     memory_region_add_subregion(sysmem, base, &s->iomem);
 
     /* Instantiate the actual storage */
+    if (blk) {
+        blk_attach_dev_nofail(blk, s);
+    }
     s->card = sd_init(blk, false);
     if (s->card == NULL) {
         exit(1);
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index f955265..794969b 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -494,7 +494,6 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     sd->enable = true;
     sd_reset(sd, blk);
     if (sd->blk) {
-        blk_attach_dev_nofail(sd->blk, sd);
         blk_set_dev_ops(sd->blk, &sd_block_ops, sd);
     }
     vmstate_register(NULL, -1, &sd_vmstate, sd);
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 27b914a..ed60674 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1145,9 +1145,14 @@ static inline unsigned int sdhci_get_fifolen(SDHCIState *s)
 static void sdhci_initfn(SDHCIState *s)
 {
     DriveInfo *di;
+    BlockBackend *blk;
 
     di = drive_get_next(IF_SD);
-    s->card = sd_init(di ? blk_by_legacy_dinfo(di) : NULL, false);
+    blk = di ? blk_by_legacy_dinfo(di) : NULL;
+    if (blk) {
+        blk_attach_dev_nofail(blk, s);
+    }
+    s->card = sd_init(blk, false);
     if (s->card == NULL) {
         exit(1);
     }
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index a71fbca..488b615 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -253,10 +253,15 @@ static int ssi_sd_init(SSISlave *d)
     DeviceState *dev = DEVICE(d);
     ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d);
     DriveInfo *dinfo;
+    BlockBackend *blk;
 
     s->mode = SSI_SD_CMD;
     dinfo = drive_get_next(IF_SD);
-    s->sd = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true);
+    blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
+    if (blk) {
+        blk_attach_dev_nofail(blk, s);
+    }
+    s->sd = sd_init(blk, true);
     if (s->sd == NULL) {
         return -1;
     }
-- 
2.3.3

  reply	other threads:[~2015-03-23 14:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-23 14:55 [Qemu-devel] [PATCH for-2.3 v2 0/2] sdhci: add "drive" property Paolo Bonzini
2015-03-23 14:55 ` Paolo Bonzini [this message]
2015-03-23 14:55 ` [Qemu-devel] [PATCH for-2.3 v2 2/2] " Paolo Bonzini

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=1427122538-26060-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=michael@walle.cc \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --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).