qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	Peter Crosthwaite <peter.crosthwaite@xilinx.com>,
	armbru@redhat.com, Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH for-2.3] sdhci: add "drive" property
Date: Sat, 21 Mar 2015 16:54:25 +0100	[thread overview]
Message-ID: <1426953265-19940-1-git-send-email-pbonzini@redhat.com> (raw)

Add a drive property that can be used with sdhci-pci (instead of the odd
"-drive if=sd,... -device sdhci-pci" that has no equivalent in the rest
of QEMU).  Then adjust the zynq platform to set it based on the DriveInfo
that it gets.

Note that in this case the BlockBackend is attached to the SDHCI controller.
This is not a problem; the ->dev field is really unused and the dev_opaque
still points to the SDState struct.

Required for 2.3, as it changes how users access the sdhci-pci device.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/arm/xilinx_zynq.c | 9 +++++++++
 hw/sd/sd.c           | 4 +++-
 hw/sd/sdhci.c        | 6 ++----
 hw/sd/sdhci.h        | 1 +
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
index 5c37521..5d2b262 100644
--- a/hw/arm/xilinx_zynq.c
+++ b/hw/arm/xilinx_zynq.c
@@ -114,6 +114,7 @@ static void zynq_init(MachineState *machine)
     MemoryRegion *ext_ram = g_new(MemoryRegion, 1);
     MemoryRegion *ocm_ram = g_new(MemoryRegion, 1);
     DeviceState *dev;
+    DriveInfo *dinfo;
     SysBusDevice *busdev;
     qemu_irq pic[64];
     Error *err = NULL;
@@ -217,11 +218,19 @@ static void zynq_init(MachineState *machine)
     gem_init(&nd_table[1], 0xE000C000, pic[77-IRQ_OFFSET]);
 
     dev = qdev_create(NULL, "generic-sdhci");
+    dinfo = drive_get_next(IF_SD);
+    if (dinfo) {
+        qdev_prop_set_drive_nofail(dev, "drive", blk_by_legacy_dinfo(dinfo));
+    }
     qdev_init_nofail(dev);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xE0100000);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[56-IRQ_OFFSET]);
 
     dev = qdev_create(NULL, "generic-sdhci");
+    dinfo = drive_get_next(IF_SD);
+    if (dinfo) {
+        qdev_prop_set_drive_nofail(dev, "drive", blk_by_legacy_dinfo(dinfo));
+    }
     qdev_init_nofail(dev);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xE0101000);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[79-IRQ_OFFSET]);
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index f955265..ff6bc6d 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -494,7 +494,9 @@ 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);
+        if (!blk_get_attached_dev(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..078b0bd 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1144,10 +1144,7 @@ static inline unsigned int sdhci_get_fifolen(SDHCIState *s)
 
 static void sdhci_initfn(SDHCIState *s)
 {
-    DriveInfo *di;
-
-    di = drive_get_next(IF_SD);
-    s->card = sd_init(di ? blk_by_legacy_dinfo(di) : NULL, false);
+    s->card = sd_init(s->blk, false);
     if (s->card == NULL) {
         exit(1);
     }
@@ -1217,6 +1214,7 @@ static Property sdhci_properties[] = {
     DEFINE_PROP_UINT32("capareg", SDHCIState, capareg,
             SDHC_CAPAB_REG_DEFAULT),
     DEFINE_PROP_UINT32("maxcurr", SDHCIState, maxcurr, 0),
+    DEFINE_PROP_DRIVE("drive", SDHCIState, blk),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/sd/sdhci.h b/hw/sd/sdhci.h
index 3352d23..69ccf58 100644
--- a/hw/sd/sdhci.h
+++ b/hw/sd/sdhci.h
@@ -237,6 +237,7 @@ typedef struct SDHCIState {
         PCIDevice pcidev;
         SysBusDevice busdev;
     };
+    BlockBackend *blk;
     SDState *card;
     MemoryRegion iomem;
 
-- 
2.3.0

             reply	other threads:[~2015-03-21 15:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-21 15:54 Paolo Bonzini [this message]
2015-03-23  9:10 ` [Qemu-devel] [PATCH for-2.3] sdhci: add "drive" property Markus Armbruster
2015-03-23 12:05   ` Paolo Bonzini
2015-03-23 12:09     ` Peter Maydell
2015-03-23 13:19       ` Paolo Bonzini
2015-03-23 13:43         ` Markus Armbruster
2015-03-23 13:35     ` Markus Armbruster
2015-03-23 13:56       ` Paolo Bonzini
2015-03-23 15:01       ` Peter Crosthwaite
2015-03-23 15:15         ` Peter Maydell
2015-03-23 15:58         ` Paolo Bonzini
2015-03-24 14:53         ` Markus Armbruster

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=1426953265-19940-1-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --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).