From patchwork Wed Jun 15 14:12:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 635895 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rV7r86m72z9t19 for ; Thu, 16 Jun 2016 00:17:12 +1000 (AEST) Received: from localhost ([::1]:42454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDBd0-0007xN-RK for incoming@patchwork.ozlabs.org; Wed, 15 Jun 2016 10:17:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDBZC-00058w-MR for qemu-devel@nongnu.org; Wed, 15 Jun 2016 10:13:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDBZ4-0001Bf-MD for qemu-devel@nongnu.org; Wed, 15 Jun 2016 10:13:13 -0400 Received: from 9.mo6.mail-out.ovh.net ([87.98.171.146]:59398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDBZ4-0001Am-BU for qemu-devel@nongnu.org; Wed, 15 Jun 2016 10:13:06 -0400 Received: from player738.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 53227FFA980 for ; Wed, 15 Jun 2016 16:13:05 +0200 (CEST) Received: from hermes.ibm.com (LFbn-1-2234-107.w90-76.abo.wanadoo.fr [90.76.55.107]) (Authenticated sender: clg@kaod.org) by player738.ha.ovh.net (Postfix) with ESMTPSA id D6FE9466; Wed, 15 Jun 2016 16:12:58 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Crosthwaite Date: Wed, 15 Jun 2016 16:12:51 +0200 Message-Id: <1465999971-29401-1-git-send-email-clg@kaod.org> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-Ovh-Tracer-Id: 7093450889785281362 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekledrkeeigdejvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 87.98.171.146 Subject: [Qemu-devel] [PATCH v2] m25p80: provide a realize to support late inits. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Marcin Krzeminski , qemu-devel@nongnu.org, Max Reitz , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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; }