From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDBny-0007QC-Fy for qemu-devel@nongnu.org; Wed, 15 Jun 2016 10:28:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDBnu-0005ll-9f for qemu-devel@nongnu.org; Wed, 15 Jun 2016 10:28:29 -0400 Received: from 16.mo6.mail-out.ovh.net ([87.98.139.208]:53629) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDBnt-0005lR-Gt for qemu-devel@nongnu.org; Wed, 15 Jun 2016 10:28:26 -0400 Received: from player738.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id C2CD6FFAF71 for ; Wed, 15 Jun 2016 16:28:22 +0200 (CEST) References: <1465999230-28050-1-git-send-email-clg@kaod.org> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= Message-ID: <576165FF.9010002@kaod.org> Date: Wed, 15 Jun 2016 16:28:15 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] m25p80: provide a realize to support late inits. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Peter Crosthwaite Cc: Kevin Wolf , qemu-block@nongnu.org, Marcin Krzeminski , qemu-devel@nongnu.org, Max Reitz On 06/15/2016 04:20 PM, Paolo Bonzini wrote: >=20 >=20 > On 15/06/2016 16:00, C=C3=A9dric Le Goater wrote: >> 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=C3=A9dric Le Goater >=20 > I think you should instead: >=20 > 1) change hw/ssi/ssi.c's ssi_slave_init to be an override of dc->realiz= e >=20 > 2) change SSISlaveClass's init member to a realize function OK. I will look into that.=20 Thanks, C. > Thanks, >=20 > Paolo >=20 >> --- >> >> Should apply on top of : >> =20 >> m25p80: fix test on blk_pread() return value >> https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg05574.htm= l >> >> hw/block/m25p80.c | 24 +++++++++++++++++------- >> 1 file changed, 17 insertions(+), 7 deletions(-) >> >> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c >> index 51d85960566f..c47722d3a3e5 100644 >> --- a/hw/block/m25p80.c >> +++ b/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" >> =20 >> #ifndef M25P80_ERR_DEBUG >> #define M25P80_ERR_DEBUG 0 >> @@ -339,6 +340,7 @@ typedef struct Flash { >> =20 >> typedef struct M25P80Class { >> SSISlaveClass parent_class; >> + DeviceRealize parent_dc_realize; >> FlashPartInfo *pi; >> } M25P80Class; >> =20 >> @@ -880,7 +882,6 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uin= t32_t tx) >> =20 >> static int m25p80_init(SSISlave *ss) >> { >> - DriveInfo *dinfo; >> Flash *s =3D M25P80(ss); >> M25P80Class *mc =3D M25P80_GET_CLASS(s); >> =20 >> @@ -888,8 +889,18 @@ static int m25p80_init(SSISlave *ss) >> =20 >> s->size =3D s->pi->sector_size * s->pi->n_sectors; >> s->dirty_page =3D -1; >> + return 0; >> +} >> + >> +static void m25p80_realize(DeviceState *dev, Error **errp) >> +{ >> + Flash *s =3D M25P80(dev); >> + M25P80Class *mc =3D M25P80_GET_CLASS(s); >> + DriveInfo *dinfo; >> + >> + /* initialize the SSISlave part */ >> + mc->parent_dc_realize(dev, errp); >> =20 >> - /* FIXME use a qdev drive property instead of drive_get_next() */ >> dinfo =3D drive_get_next(IF_MTD); >> =20 >> if (dinfo) { >> @@ -899,18 +910,15 @@ static int m25p80_init(SSISlave *ss) >> =20 >> s->storage =3D blk_blockalign(s->blk, s->size); >> =20 >> - /* FIXME: Move to late init */ >> if (blk_pread(s->blk, 0, s->storage, s->size) !=3D s->size) { >> - fprintf(stderr, "Failed to initialize SPI flash!\n"); >> - return 1; >> + error_setg(errp, "failed to read the initial flash conten= t"); >> + return; >> } >> } else { >> DB_PRINT_L(0, "No BDRV - binding to RAM\n"); >> s->storage =3D blk_blockalign(NULL, s->size); >> memset(s->storage, 0xFF, s->size); >> } >> - >> - return 0; >> } >> =20 >> static void m25p80_reset(DeviceState *d) >> @@ -967,6 +975,8 @@ static void m25p80_class_init(ObjectClass *klass, = void *data) >> dc->vmsd =3D &vmstate_m25p80; >> dc->props =3D m25p80_properties; >> dc->reset =3D m25p80_reset; >> + mc->parent_dc_realize =3D dc->realize; >> + dc->realize =3D m25p80_realize; >> mc->pi =3D data; >> } >> =20 >>