From: "Cédric Le Goater" <clg@kaod.org>
To: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org,
"Marcin Krzeminski" <marcin.krzeminski@nokia.com>,
"Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH v2] m25p80: provide a realize to support late inits.
Date: Wed, 15 Jun 2016 16:12:51 +0200 [thread overview]
Message-ID: <1465999971-29401-1-git-send-email-clg@kaod.org> (raw)
We also need to realize() the SSISlave part of the object. This is why
the previous realize() ops is stored in M25P80Class and called in the
object realize() ops.
This is fully compatible with the existing users of m25p80 and it
provides a way to handle errors on the drive backend.
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
Should apply on top of :
m25p80: fix test on blk_pread() return value
https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg05574.html
Changes since v2 :
- Added a FIXME comment removed in v1
hw/block/m25p80.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
Index: qemu-ast2400-mainline.git/hw/block/m25p80.c
===================================================================
--- qemu-ast2400-mainline.git.orig/hw/block/m25p80.c
+++ qemu-ast2400-mainline.git/hw/block/m25p80.c
@@ -28,6 +28,7 @@
#include "hw/ssi/ssi.h"
#include "qemu/bitops.h"
#include "qemu/log.h"
+#include "qapi/error.h"
#ifndef M25P80_ERR_DEBUG
#define M25P80_ERR_DEBUG 0
@@ -339,6 +340,7 @@ typedef struct Flash {
typedef struct M25P80Class {
SSISlaveClass parent_class;
+ DeviceRealize parent_dc_realize;
FlashPartInfo *pi;
} M25P80Class;
@@ -880,7 +882,6 @@ static uint32_t m25p80_transfer8(SSISlav
static int m25p80_init(SSISlave *ss)
{
- DriveInfo *dinfo;
Flash *s = M25P80(ss);
M25P80Class *mc = M25P80_GET_CLASS(s);
@@ -888,6 +889,17 @@ static int m25p80_init(SSISlave *ss)
s->size = s->pi->sector_size * s->pi->n_sectors;
s->dirty_page = -1;
+ return 0;
+}
+
+static void m25p80_realize(DeviceState *dev, Error **errp)
+{
+ Flash *s = M25P80(dev);
+ M25P80Class *mc = M25P80_GET_CLASS(s);
+ DriveInfo *dinfo;
+
+ /* initialize the SSISlave part */
+ mc->parent_dc_realize(dev, errp);
/* FIXME use a qdev drive property instead of drive_get_next() */
dinfo = drive_get_next(IF_MTD);
@@ -899,18 +911,15 @@ static int m25p80_init(SSISlave *ss)
s->storage = blk_blockalign(s->blk, s->size);
- /* FIXME: Move to late init */
if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) {
- fprintf(stderr, "Failed to initialize SPI flash!\n");
- return 1;
+ error_setg(errp, "failed to read the initial flash content");
+ return;
}
} else {
DB_PRINT_L(0, "No BDRV - binding to RAM\n");
s->storage = blk_blockalign(NULL, s->size);
memset(s->storage, 0xFF, s->size);
}
-
- return 0;
}
static void m25p80_reset(DeviceState *d)
@@ -967,6 +976,8 @@ static void m25p80_class_init(ObjectClas
dc->vmsd = &vmstate_m25p80;
dc->props = m25p80_properties;
dc->reset = m25p80_reset;
+ mc->parent_dc_realize = dc->realize;
+ dc->realize = m25p80_realize;
mc->pi = data;
}
reply other threads:[~2016-06-15 14:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1465999971-29401-1-git-send-email-clg@kaod.org \
--to=clg@kaod.org \
--cc=crosthwaite.peter@gmail.com \
--cc=kwolf@redhat.com \
--cc=marcin.krzeminski@nokia.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.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).