qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Riku Voipio" <riku.voipio@iki.fi>,
	"Juha Riihimäki" <juha.riihimaki@nokia.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	patches@linaro.org
Subject: [Qemu-devel] [PATCH 07/12] onenand: Pass BlockDriverState to init function
Date: Fri, 15 Jul 2011 15:58:21 +0100	[thread overview]
Message-ID: <1310741906-1606-8-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1310741906-1606-1-git-send-email-peter.maydell@linaro.org>

Pass the BlockDriverState to the onenand init function so it doesn't
need to look up the drive itself.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/flash.h   |    3 ++-
 hw/nseries.c |   10 ++++++----
 hw/onenand.c |   14 ++++++++------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/hw/flash.h b/hw/flash.h
index 43260ce..1aae43d 100644
--- a/hw/flash.h
+++ b/hw/flash.h
@@ -38,7 +38,8 @@ uint32_t nand_getbuswidth(DeviceState *dev);
 /* onenand.c */
 void onenand_base_update(void *opaque, target_phys_addr_t new);
 void onenand_base_unmap(void *opaque);
-void *onenand_init(uint32_t id, int regshift, qemu_irq irq);
+void *onenand_init(BlockDriverState *bdrv, uint32_t id,
+                   int regshift, qemu_irq irq);
 void *onenand_raw_otp(void *opaque);
 
 /* ecc.c */
diff --git a/hw/nseries.c b/hw/nseries.c
index 32f2f53..4fef05d 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -31,6 +31,7 @@
 #include "hw.h"
 #include "bt.h"
 #include "loader.h"
+#include "blockdev.h"
 
 /* Nokia N8x0 support */
 struct n800_s {
@@ -163,13 +164,14 @@ static const uint8_t n8x0_cal_bt_id[] = {
 static void n8x0_nand_setup(struct n800_s *s)
 {
     char *otp_region;
+    DriveInfo *dinfo;
 
+    dinfo = drive_get(IF_MTD, 0, 0);
     /* Either ec40xx or ec48xx are OK for the ID */
+    s->nand = onenand_init(dinfo ? dinfo->bdrv : 0, 0xec4800, 1,
+                           qdev_get_gpio_in(s->cpu->gpio, N8X0_ONENAND_GPIO));
     omap_gpmc_attach(s->cpu->gpmc, N8X0_ONENAND_CS, 0, onenand_base_update,
-                    onenand_base_unmap,
-                    (s->nand = onenand_init(0xec4800, 1,
-                                            qdev_get_gpio_in(s->cpu->gpio,
-                                                    N8X0_ONENAND_GPIO))));
+                     onenand_base_unmap, s->nand);
     otp_region = onenand_raw_otp(s->nand);
 
     memcpy(otp_region + 0x000, n8x0_cal_wlan_mac, sizeof(n8x0_cal_wlan_mac));
diff --git a/hw/onenand.c b/hw/onenand.c
index 71c1ab4..3a19d7f 100644
--- a/hw/onenand.c
+++ b/hw/onenand.c
@@ -615,10 +615,10 @@ static CPUWriteMemoryFunc * const onenand_writefn[] = {
     onenand_write,
 };
 
-void *onenand_init(uint32_t id, int regshift, qemu_irq irq)
+void *onenand_init(BlockDriverState *bdrv, uint32_t id,
+                   int regshift, qemu_irq irq)
 {
     OneNANDState *s = (OneNANDState *) qemu_mallocz(sizeof(*s));
-    DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
     uint32_t size = 1 << (24 + ((id >> 12) & 7));
     void *ram;
 
@@ -632,11 +632,13 @@ void *onenand_init(uint32_t id, int regshift, qemu_irq irq)
     s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0;
     s->iomemtype = cpu_register_io_memory(onenand_readfn,
                     onenand_writefn, s, DEVICE_NATIVE_ENDIAN);
-    if (!dinfo)
+    s->bdrv = bdrv;
+    if (!s->bdrv) {
         s->image = memset(qemu_malloc(size + (size >> 5)),
-                        0xff, size + (size >> 5));
-    else
-        s->bdrv = dinfo->bdrv;
+                          0xff, size + (size >> 5));
+    } else {
+        s->bdrv_cur = s->bdrv;
+    }
     s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT),
                     0xff, (64 + 2) << PAGE_SHIFT);
     s->ram = qemu_ram_alloc(NULL, "onenand.ram", 0xc000 << s->shift);
-- 
1.7.1

  parent reply	other threads:[~2011-07-15 14:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-15 14:58 [Qemu-devel] [PATCH 00/12] bugfix and qdevify NAND and ONENAND devices Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 01/12] hw/nand: Pass block device state to init function Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 02/12] hw/nand: Support large NAND devices Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 03/12] hw/nand: Support devices wider than 8 bits Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 04/12] hw/nand: Support multiple reads following READ STATUS Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 05/12] hw/nand: Writing to NAND can only clear bits Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 06/12] hw/nand: qdevify Peter Maydell
2011-07-15 14:58 ` Peter Maydell [this message]
2011-07-15 14:58 ` [Qemu-devel] [PATCH 08/12] onenand: Handle various ID fields separately Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 09/12] onenand: Ignore zero writes to boot command space Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 10/12] hw/onenand: program actions can only clear bits Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 11/12] hw/sysbus: Add sysbus_mmio_unmap() for unmapping a region Peter Maydell
2011-07-15 14:58 ` [Qemu-devel] [PATCH 12/12] hw/onenand: qdevify Peter Maydell
2011-07-28 13:51 ` [Qemu-devel] [PATCH 00/12] bugfix and qdevify NAND and ONENAND devices Peter Maydell

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=1310741906-1606-8-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=armbru@redhat.com \
    --cc=juha.riihimaki@nokia.com \
    --cc=patches@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).