All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.3] sdhci: add "drive" property
@ 2015-03-21 15:54 Paolo Bonzini
  2015-03-23  9:10 ` Markus Armbruster
  0 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2015-03-21 15:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: Edgar E. Iglesias, Peter Crosthwaite, armbru, Peter Maydell

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-03-24 14:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-21 15:54 [Qemu-devel] [PATCH for-2.3] sdhci: add "drive" property Paolo Bonzini
2015-03-23  9:10 ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.