qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH V2 07/10] SD card: introduce "if-idx" property for S


From: Igor Mitsyanko
Subject: [Qemu-devel] [PATCH V2 07/10] SD card: introduce "if-idx" property for SD card objects
Date: Thu, 05 Apr 2012 19:48:30 +0400

Rather then pass on a BlockDriverState pointer to SD init function, we now 
should set
"if-idx" property of SD card object to a value corresponding to index of 
DriveInfo
we want to attach to SD card.
All users were converted to use this new approach to SD card initialization. 
Omap and PXA
mmc initialization functions are modified to accept DriveInfo * instead of 
BlockDriverState *,
so these function may have easy access to block device coresponding index.
Host controllers should set "if-idx" property before initializing freshly 
instantiated
SD card. During initialization, card will be linked with block device of the 
same interface
index.

Signed-off-by: Igor Mitsyanko <address@hidden>
---
 hw/milkymist-memcard.c |    7 ++++++-
 hw/omap.h              |    4 ++--
 hw/omap1.c             |    2 +-
 hw/omap2.c             |    2 +-
 hw/omap_mmc.c          |   16 ++++++++++++----
 hw/pl181.c             |    7 ++++++-
 hw/pxa.h               |    2 +-
 hw/pxa2xx.c            |    5 ++---
 hw/pxa2xx_mmci.c       |    8 ++++++--
 hw/sd.c                |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 hw/sd.h                |    4 ++--
 hw/ssi-sd.c            |    7 ++++++-
 12 files changed, 89 insertions(+), 22 deletions(-)

diff --git a/hw/milkymist-memcard.c b/hw/milkymist-memcard.c
index 1d84d44..2fff47f 100644
--- a/hw/milkymist-memcard.c
+++ b/hw/milkymist-memcard.c
@@ -251,10 +251,15 @@ static int milkymist_memcard_init(SysBusDevice *dev)
 {
     MilkymistMemcardState *s = FROM_SYSBUS(typeof(*s), dev);
     DriveInfo *dinfo;
+    Error *errp = NULL;
 
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
     dinfo = drive_get_next(IF_SD);
-    SD_INIT(s->card, dinfo ? dinfo->bdrv : NULL, false);
+    if (dinfo) {
+        object_property_set_int(OBJECT(s->card), dinfo->unit, "if-idx", &errp);
+    }
+    assert_no_error(errp);
+    SD_INIT(s->card, false);
     s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;
 
     memory_region_init_io(&s->regs_region, &memcard_mmio_ops, s,
diff --git a/hw/omap.h b/hw/omap.h
index 6c3d004..969f9cd 100644
--- a/hw/omap.h
+++ b/hw/omap.h
@@ -754,10 +754,10 @@ 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,
+                DriveInfo *di,
                 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[],
+                DriveInfo *di, 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 80d47f0..fb722bc 100644
--- a/hw/omap1.c
+++ b/hw/omap1.c
@@ -3964,7 +3964,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion 
*system_memory,
         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, dinfo,
                            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 42fce5e..770389b 100644
--- a/hw/omap2.c
+++ b/hw/omap2.c
@@ -2459,7 +2459,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion 
*sysmem,
         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), dinfo,
                     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 15bc1ae..3bf29c2 100644
--- a/hw/omap_mmc.c
+++ b/hw/omap_mmc.c
@@ -19,6 +19,8 @@
 #include "hw.h"
 #include "omap.h"
 #include "sd.h"
+#include "qerror.h"
+#include "blockdev.h"
 
 struct omap_mmc_s {
     qemu_irq irq;
@@ -575,9 +577,10 @@ 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,
+                DriveInfo *di,
                 qemu_irq irq, qemu_irq dma[], omap_clk clk)
 {
+    Error *errp = NULL;
     struct omap_mmc_s *s = (struct omap_mmc_s *)
             g_malloc0(sizeof(struct omap_mmc_s));
 
@@ -594,15 +597,18 @@ struct omap_mmc_s *omap_mmc_init(target_phys_addr_t base,
 
     /* Instantiate the storage */
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
-    SD_INIT(s->card, bd, false);
+    object_property_set_int(OBJECT(s->card), di->unit, "if-idx", &errp);
+    assert_no_error(errp);
+    SD_INIT(s->card, false);
 
     return s;
 }
 
 struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
-                BlockDriverState *bd, qemu_irq irq, qemu_irq dma[],
+                DriveInfo *di, qemu_irq irq, qemu_irq dma[],
                 omap_clk fclk, omap_clk iclk)
 {
+    Error *errp = NULL;
     struct omap_mmc_s *s = (struct omap_mmc_s *)
             g_malloc0(sizeof(struct omap_mmc_s));
 
@@ -620,7 +626,9 @@ struct omap_mmc_s *omap2_mmc_init(struct 
omap_target_agent_s *ta,
 
     /* Instantiate the storage */
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
-    SD_INIT(s->card, bd, false);
+    object_property_set_int(OBJECT(s->card), di->unit, "if-idx", &errp);
+    assert_no_error(errp);
+    SD_INIT(s->card, false);
 
     s->cdet = qemu_allocate_irqs(omap_mmc_cover_cb, s, 1)[0];
     SD_SET_CB(s->card, NULL, s->cdet);
diff --git a/hw/pl181.c b/hw/pl181.c
index b2b1ed4..a0a8fe3 100644
--- a/hw/pl181.c
+++ b/hw/pl181.c
@@ -477,6 +477,7 @@ static int pl181_init(SysBusDevice *dev)
 {
     pl181_state *s = FROM_SYSBUS(pl181_state, dev);
     DriveInfo *dinfo;
+    Error *errp = NULL;
 
     memory_region_init_io(&s->iomem, &pl181_ops, s, "pl181", 0x1000);
     sysbus_init_mmio(dev, &s->iomem);
@@ -485,7 +486,11 @@ static int pl181_init(SysBusDevice *dev)
     qdev_init_gpio_out(&s->busdev.qdev, s->cardstatus, 2);
     dinfo = drive_get_next(IF_SD);
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
-    SD_INIT(s->card, dinfo ? dinfo->bdrv : NULL, false);
+    if (dinfo) {
+        object_property_set_int(OBJECT(s->card), dinfo->unit, "if-idx", &errp);
+    }
+    assert_no_error(errp);
+    SD_INIT(s->card, false);
     return 0;
 }
 
diff --git a/hw/pxa.h b/hw/pxa.h
index 025be34..e76f144 100644
--- a/hw/pxa.h
+++ b/hw/pxa.h
@@ -87,7 +87,7 @@ void pxa2xx_lcdc_oritentation(void *opaque, int angle);
 typedef struct PXA2xxMMCIState PXA2xxMMCIState;
 PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
                 target_phys_addr_t base,
-                BlockDriverState *bd, qemu_irq irq,
+                DriveInfo *di, qemu_irq irq,
                 qemu_irq rx_dma, qemu_irq tx_dma);
 void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
                 qemu_irq coverswitch);
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index ddaa846..1e5f72f 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -14,7 +14,6 @@
 #include "i2c.h"
 #include "ssi.h"
 #include "qemu-char.h"
-#include "blockdev.h"
 
 static struct {
     target_phys_addr_t io_base;
@@ -2101,7 +2100,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
         fprintf(stderr, "qemu: missing SecureDigital device\n");
         exit(1);
     }
-    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000, dinfo->bdrv,
+    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000, dinfo,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_MMC),
                     qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_MMCI),
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
@@ -2232,7 +2231,7 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, 
unsigned int sdram_size)
         fprintf(stderr, "qemu: missing SecureDigital device\n");
         exit(1);
     }
-    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000, dinfo->bdrv,
+    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000, dinfo,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_MMC),
                     qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_MMCI),
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
diff --git a/hw/pxa2xx_mmci.c b/hw/pxa2xx_mmci.c
index a7081b0..c06a108 100644
--- a/hw/pxa2xx_mmci.c
+++ b/hw/pxa2xx_mmci.c
@@ -14,6 +14,7 @@
 #include "pxa.h"
 #include "sd.h"
 #include "qdev.h"
+#include "blockdev.h"
 
 struct PXA2xxMMCIState {
     MemoryRegion iomem;
@@ -528,10 +529,11 @@ static int pxa2xx_mmci_load(QEMUFile *f, void *opaque, 
int version_id)
 
 PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
                 target_phys_addr_t base,
-                BlockDriverState *bd, qemu_irq irq,
+                DriveInfo *di, qemu_irq irq,
                 qemu_irq rx_dma, qemu_irq tx_dma)
 {
     PXA2xxMMCIState *s;
+    Error *errp = NULL;
 
     s = (PXA2xxMMCIState *) g_malloc0(sizeof(PXA2xxMMCIState));
     s->irq = irq;
@@ -544,7 +546,9 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
 
     /* Instantiate the actual storage */
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
-    SD_INIT(s->card, bd, false);
+    object_property_set_int(OBJECT(s->card), di->unit, "if-idx", &errp);
+    assert_no_error(errp);
+    SD_INIT(s->card, false);
 
     register_savevm(NULL, "pxa2xx_mmci", 0, 0,
                     pxa2xx_mmci_save, pxa2xx_mmci_load, s);
diff --git a/hw/sd.c b/hw/sd.c
index 58d94ed..1ea1756 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -30,9 +30,10 @@
  */
 
 #include "hw.h"
-#include "block.h"
+#include "blockdev.h"
 #include "sd.h"
 #include "bitmap.h"
+#include "qapi/qapi-visit-core.h"
 
 //#define DEBUG_SD 1
 
@@ -112,7 +113,7 @@ struct SDState {
     qemu_irq inserted_cb;
     BlockDriverState *bdrv;
     uint8_t *buf;
-
+    int32_t if_idx;
     bool enable;
 };
 
@@ -486,8 +487,14 @@ static const VMStateDescription sd_vmstate = {
    whether card should be in SSI or MMC/SD mode.  It is also up to the
    board to ensure that ssi transfers only occur when the chip select
    is asserted.  */
-static void sd_init(SDState *sd, BlockDriverState *bs, bool is_spi)
+static void sd_init(SDState *sd, bool is_spi)
 {
+    DriveInfo *di = drive_get_by_index(IF_SD, sd->if_idx);
+    BlockDriverState *bs = NULL;
+
+    if (di) {
+        bs = di->bdrv;
+    }
     sd->buf = qemu_blockalign(bs, 512);
     sd->spi = is_spi;
     sd->enable = true;
@@ -1764,10 +1771,44 @@ static void sd_class_init(ObjectClass *class, void 
*data)
     k->enable = sd_enable;
 }
 
+static void sd_get_if_index(Object *obj, Visitor *v, void *opaque,
+                         const char *name, Error **errp)
+{
+    int64_t if_idx = SD_CARD(obj)->if_idx;
+
+    visit_type_int(v, &if_idx, name, errp);
+}
+
+static void sd_set_if_index(Object *obj, Visitor *v, void *opaque,
+                         const char *name, Error **errp)
+{
+    SDState *sd = SD_CARD(obj);
+    int64_t if_idx;
+
+    visit_type_int(v, &if_idx, name, errp);
+    if (sd->bdrv) {
+        error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(sd->bdrv));
+    } else if (if_idx < 0 || if_idx > INT32_MAX) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "if-idx", "positive 
int32");
+    } else {
+        sd->if_idx = if_idx;
+    }
+}
+
+static void sd_initfn(Object *obj)
+{
+    SDState *sd = SD_CARD(obj);
+
+    sd->if_idx = -1;
+    object_property_add(obj, "if-idx", "int", sd_get_if_index, sd_set_if_index,
+            NULL, NULL, NULL);
+}
+
 static TypeInfo sd_type_info = {
     .name = TYPE_SD_CARD,
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(SDState),
+    .instance_init = sd_initfn,
     .class_init = sd_class_init,
     .class_size = sizeof(SDClass)
 };
diff --git a/hw/sd.h b/hw/sd.h
index d8f0195..e2b458a 100644
--- a/hw/sd.h
+++ b/hw/sd.h
@@ -73,7 +73,7 @@ typedef struct SDState SDState;
 typedef struct SDClass {
     ObjectClass parent_class;
 
-    void (*init)(SDState *sd, BlockDriverState *bs, bool is_spi);
+    void (*init)(SDState *sd, bool is_spi);
     int (*do_command)(SDState *sd, SDRequest *req, uint8_t *response);
     void (*write_data)(SDState *sd, uint8_t value);
     uint8_t (*read_data)(SDState *sd);
@@ -90,7 +90,7 @@ typedef struct SDClass {
 #define SD_GET_CLASS(obj)       \
      OBJECT_GET_CLASS(SDClass, (obj), TYPE_SD_CARD)
 
-#define SD_INIT(sd, bdrv, is_spi)   (SD_GET_CLASS(sd)->init(sd, bdrv, is_spi))
+#define SD_INIT(sd, bdrv, is_spi)   (SD_GET_CLASS(sd)->init(sd, is_spi))
 #define SD_DO_COMMAND(sd, req, rsp) (SD_GET_CLASS(sd)->do_command(sd, req, 
rsp))
 #define SD_WRITE(sd, value)         (SD_GET_CLASS(sd)->write_data(sd, value))
 #define SD_READ(sd)                 (SD_GET_CLASS(sd)->read_data(sd))
diff --git a/hw/ssi-sd.c b/hw/ssi-sd.c
index beecc0e..38057ba 100644
--- a/hw/ssi-sd.c
+++ b/hw/ssi-sd.c
@@ -236,11 +236,16 @@ static int ssi_sd_init(SSISlave *dev)
 {
     ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, dev);
     DriveInfo *dinfo;
+    Error *errp = NULL;
 
     s->mode = SSI_SD_CMD;
     dinfo = drive_get_next(IF_SD);
     s->sd = SD_CARD(object_new(TYPE_SD_CARD));
-    SD_INIT(s->sd, dinfo ? dinfo->bdrv : NULL, true);
+    if (dinfo) {
+        object_property_set_int(OBJECT(s->sd), dinfo->unit, "if-idx", &errp);
+    }
+    assert_no_error(errp);
+    SD_INIT(s->sd, true);
     register_savevm(&dev->qdev, "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s);
     return 0;
 }
-- 
1.7.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]