diff mbox

[1/3] omap: Get BlockDriverState* in mmc controller init, not board init

Message ID 1345124754-4173-2-git-send-email-peter.maydell@linaro.org
State Rejected
Headers show

Commit Message

Peter Maydell Aug. 16, 2012, 1:45 p.m. UTC
Instead of getting the BlockDriverState* in the omap board init
and passing it to the mmc controller's init function, have the
mmc controller get the next IF_SD device and use it if present.
This brings us into line with other SD controller models and
means that we correctly emulate an SD controller with no card
present if the user didn't ask for an SD card.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/omap.h     |    3 +--
 hw/omap1.c    |    8 +-------
 hw/omap2.c    |    8 +-------
 hw/omap_mmc.c |   12 ++++++++----
 4 files changed, 11 insertions(+), 20 deletions(-)
diff mbox

Patch

diff --git a/hw/omap.h b/hw/omap.h
index 413851b..de5ec8c 100644
--- a/hw/omap.h
+++ b/hw/omap.h
@@ -754,10 +754,9 @@  void omap_rfbi_attach(struct omap_dss_s *s, int cs, struct rfbi_chip_s *chip);
 struct omap_mmc_s;
 struct omap_mmc_s *omap_mmc_init(target_phys_addr_t base,
                 MemoryRegion *sysmem,
-                BlockDriverState *bd,
                 qemu_irq irq, qemu_irq dma[], omap_clk clk);
 struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
-                BlockDriverState *bd, qemu_irq irq, qemu_irq dma[],
+                qemu_irq irq, qemu_irq dma[],
                 omap_clk fclk, omap_clk iclk);
 void omap_mmc_reset(struct omap_mmc_s *s);
 void omap_mmc_handlers(struct omap_mmc_s *s, qemu_irq ro, qemu_irq cover);
diff --git a/hw/omap1.c b/hw/omap1.c
index ad60cc4..641e260 100644
--- a/hw/omap1.c
+++ b/hw/omap1.c
@@ -3823,7 +3823,6 @@  struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
             g_malloc0(sizeof(struct omap_mpu_state_s));
     qemu_irq *cpu_irq;
     qemu_irq dma_irqs[6];
-    DriveInfo *dinfo;
     SysBusDevice *busdev;
 
     if (!core)
@@ -3961,12 +3960,7 @@  struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
     s->dpll[2] = omap_dpll_init(system_memory, 0xfffed100,
                                 omap_findclk(s, "dpll3"));
 
-    dinfo = drive_get(IF_SD, 0, 0);
-    if (!dinfo) {
-        fprintf(stderr, "qemu: missing SecureDigital device\n");
-        exit(1);
-    }
-    s->mmc = omap_mmc_init(0xfffb7800, system_memory, dinfo->bdrv,
+    s->mmc = omap_mmc_init(0xfffb7800, system_memory,
                            qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN),
                            &s->drq[OMAP_DMA_MMC_TX],
                     omap_findclk(s, "mmc_ck"));
diff --git a/hw/omap2.c b/hw/omap2.c
index 4278dd1..28178dd 100644
--- a/hw/omap2.c
+++ b/hw/omap2.c
@@ -2246,7 +2246,6 @@  struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
             g_malloc0(sizeof(struct omap_mpu_state_s));
     qemu_irq *cpu_irq;
     qemu_irq dma_irqs[4];
-    DriveInfo *dinfo;
     int i;
     SysBusDevice *busdev;
     struct omap_target_agent_s *ta;
@@ -2454,12 +2453,7 @@  struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                              qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_GPMC_IRQ),
                              s->drq[OMAP24XX_DMA_GPMC]);
 
-    dinfo = drive_get(IF_SD, 0, 0);
-    if (!dinfo) {
-        fprintf(stderr, "qemu: missing SecureDigital device\n");
-        exit(1);
-    }
-    s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), dinfo->bdrv,
+    s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9),
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_MMC_IRQ),
                     &s->drq[OMAP24XX_DMA_MMC1_TX],
                     omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
diff --git a/hw/omap_mmc.c b/hw/omap_mmc.c
index aec0285..eada07d 100644
--- a/hw/omap_mmc.c
+++ b/hw/omap_mmc.c
@@ -19,6 +19,7 @@ 
 #include "hw.h"
 #include "omap.h"
 #include "sd.h"
+#include "blockdev.h"
 
 struct omap_mmc_s {
     qemu_irq irq;
@@ -574,9 +575,9 @@  static void omap_mmc_cover_cb(void *opaque, int line, int level)
 
 struct omap_mmc_s *omap_mmc_init(target_phys_addr_t base,
                 MemoryRegion *sysmem,
-                BlockDriverState *bd,
                 qemu_irq irq, qemu_irq dma[], omap_clk clk)
 {
+    DriveInfo *dinfo;
     struct omap_mmc_s *s = (struct omap_mmc_s *)
             g_malloc0(sizeof(struct omap_mmc_s));
 
@@ -592,15 +593,17 @@  struct omap_mmc_s *omap_mmc_init(target_phys_addr_t base,
     memory_region_add_subregion(sysmem, base, &s->iomem);
 
     /* Instantiate the storage */
-    s->card = sd_init(bd, 0);
+    dinfo = drive_get_next(IF_SD);
+    s->card = sd_init(dinfo ? dinfo->bdrv : NULL, 0);
 
     return s;
 }
 
 struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
-                BlockDriverState *bd, qemu_irq irq, qemu_irq dma[],
+                qemu_irq irq, qemu_irq dma[],
                 omap_clk fclk, omap_clk iclk)
 {
+    DriveInfo *dinfo;
     struct omap_mmc_s *s = (struct omap_mmc_s *)
             g_malloc0(sizeof(struct omap_mmc_s));
 
@@ -617,7 +620,8 @@  struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
     omap_l4_attach(ta, 0, &s->iomem);
 
     /* Instantiate the storage */
-    s->card = sd_init(bd, 0);
+    dinfo = drive_get_next(IF_SD);
+    s->card = sd_init(dinfo ? dinfo->bdrv : NULL, 0);
 
     s->cdet = qemu_allocate_irqs(omap_mmc_cover_cb, s, 1)[0];
     sd_set_cb(s->card, NULL, s->cdet);