From nobody Sun May 19 01:15:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563315420; cv=none; d=zoho.com; s=zohoarc; b=MrKdCUAwUNseysHzRyacI5l+YomQty+LThWU4XObmh6cYDTPtcYbIOegBp4p5Nk3LNKL2z7G9Ndb3+ZOs5oPpLl9eLb1UOcnu+8T+WBxAdlZZ6m+KykOej/Ewxewnog6HXvNXnE3MFR4gYbRLnxlpyIMn5MTKsUwuPTLydVaVFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563315420; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/zYTfAzeSVwmuXlOY5XDVtVNVE5xWNjUHd+Xy5agBJg=; b=RMwuiOabjJbymQTMjkDIZ36j6GYhHPBpeOU8SQD+sy60OZdbrb7QAfkhaEpLnmJUbhvSZX3uPIXsyha0EBIKDW2DB3Bs6lvbJl3aiLTWXDSg15fBt94INNLr2P9at8cFYgpM8OV+6Wi7uB7FDofApbkamvZCQ21P/vyJwJVx+fQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156331542044035.792265950523415; Tue, 16 Jul 2019 15:17:00 -0700 (PDT) Received: from localhost ([::1]:52632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVko-0007fw-Pd for importer@patchew.org; Tue, 16 Jul 2019 18:16:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41518) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVkA-0005rW-Jf for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnVk9-0002HP-GH for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnVk7-0002Ef-6m; Tue, 16 Jul 2019 18:16:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C93B308A963; Tue, 16 Jul 2019 22:16:14 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D60D54F0BB; Tue, 16 Jul 2019 22:16:08 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2019 00:15:51 +0200 Message-Id: <20190716221555.11145-2-philmd@redhat.com> In-Reply-To: <20190716221555.11145-1-philmd@redhat.com> References: <20190716221555.11145-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 16 Jul 2019 22:16:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH-for-4.1 v6 1/5] hw/block/pflash_cfi01: Removed an unused timer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Laszlo Ersek , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Alistair Francis , Wei Yang , John Snow , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The 'CFI02' NOR flash was introduced in commit 29133e9a0fff, with timing modelled. One year later, the CFI01 model was introduced (commit 05ee37ebf630) based on the CFI02 model. As noted in the header, "It does not support timings". 12 years later, we never had to model the device timings. Time to remove the unused timer, we can still add it back if required. Suggested-by: Laszlo Ersek Reviewed-by: Wei Yang Reviewed-by: Laszlo Ersek Reviewed-by: Alistair Francis Regression-tested-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi01.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 435be1e35c..a9529957f8 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -42,7 +42,6 @@ #include "hw/block/flash.h" #include "sysemu/block-backend.h" #include "qapi/error.h" -#include "qemu/timer.h" #include "qemu/bitops.h" #include "qemu/error-report.h" #include "qemu/host-utils.h" @@ -90,7 +89,6 @@ struct PFlashCFI01 { uint8_t cfi_table[0x52]; uint64_t counter; unsigned int writeblock_size; - QEMUTimer *timer; MemoryRegion mem; char *name; void *storage; @@ -114,18 +112,6 @@ static const VMStateDescription vmstate_pflash =3D { } }; =20 -static void pflash_timer (void *opaque) -{ - PFlashCFI01 *pfl =3D opaque; - - trace_pflash_timer_expired(pfl->cmd); - /* Reset flash */ - pfl->status ^=3D 0x80; - memory_region_rom_device_set_romd(&pfl->mem, true); - pfl->wcycle =3D 0; - pfl->cmd =3D 0; -} - /* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -774,7 +760,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) pfl->max_device_width =3D pfl->device_width; } =20 - pfl->timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, pflash_timer, pfl); pfl->wcycle =3D 0; pfl->cmd =3D 0; pfl->status =3D 0x80; /* WSM ready */ --=20 2.20.1 From nobody Sun May 19 01:15:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563315409; cv=none; d=zoho.com; s=zohoarc; b=bTCdhU2Zs5s7MNlufBh7xmhF6dokXyg0uJ5RAN4Bnop5PB+E1o+lM5uuhIR1hgS2AlAX0PWdCxYRC8Q/5c7MkEhDCraiwENhdgqlcKfT1BOo6uQS2xp4PjZEaJB+WyCVGOpHvzUAQsTBqU2rcuc5cHwNy/9naBpvODGxoBiKUq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563315409; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=D6EqkF38sKMixXQpd9P0czN4HMYBXwrKE7bhIDLGL5g=; b=NMT9eFOrR9sG6MUb8zmCbz0qmlyz4BK9wSLGAe7Z3pPtwdptmdMvXqK1aPdBkHeBzVLGmw89JJVW+lJfRuCanFjFh703csQnArRMvl1os2/23RcTanIQewmLwvLfUDcRusatQbHdfmuBzNfaO52hsksKZ8WVOiiUF3DTCMHCyzU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563315409547622.5715252053211; Tue, 16 Jul 2019 15:16:49 -0700 (PDT) Received: from localhost ([::1]:52628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVkd-0007Ci-Vd for importer@patchew.org; Tue, 16 Jul 2019 18:16:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41593) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVkG-0006A2-MU for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnVkF-0002MY-H5 for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnVkD-0002Jj-5j; Tue, 16 Jul 2019 18:16:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A11E8553A; Tue, 16 Jul 2019 22:16:20 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C5BC5DAA4; Tue, 16 Jul 2019 22:16:14 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2019 00:15:52 +0200 Message-Id: <20190716221555.11145-3-philmd@redhat.com> In-Reply-To: <20190716221555.11145-1-philmd@redhat.com> References: <20190716221555.11145-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 16 Jul 2019 22:16:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH-for-4.1 v6 2/5] hw/block/pflash_cfi01: Document use of non-CFI compliant command '0x00' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Laszlo Ersek , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Alistair Francis , John Snow , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The command 0x00 is used by this model since its origin (commit 05ee37ebf630). In this commit the command is described with a amusing '/* ??? */' comment, probably meaning 'FIXME'. switch (cmd) { case 0x00: /* ??? */ ... This comment survived 12 years because the 0x00 value is indeed not specified by the CFI open standard (as of this commit). The 'cmd' field is transfered during migration. To keep the migration feature working with older QEMU version, we have to take a lot of care with migrated field. We figured out it is too late to remove a non-specified value from this model (this would make migration review very complex). It is however not too late to improve the documentation. Add few comments to remember this is a special value related to QEMU, and we won't find information about it on the CFI spec. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- v6: new patch --- hw/block/pflash_cfi01.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index a9529957f8..6838e8a1ab 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -277,9 +277,13 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr o= ffset, /* This should never happen : reset state & treat it as a read */ DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd); pfl->wcycle =3D 0; - pfl->cmd =3D 0; + /* + * The command 0x00 is not assigned by the CFI open standard, + * but QEMU historically uses it for the READ_ARRAY command (0xff). + */ + pfl->cmd =3D 0x00; /* fall through to read code */ - case 0x00: + case 0x00: /* This model reset value for READ_ARRAY (not CFI compliant= ) */ /* Flash area read */ ret =3D pflash_data_read(pfl, offset, width, be); break; @@ -448,7 +452,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, case 0: /* read mode */ switch (cmd) { - case 0x00: /* ??? */ + case 0x00: /* This model reset value for READ_ARRAY (not CFI) */ goto reset_flash; case 0x10: /* Single Byte Program */ case 0x40: /* Single Byte Program */ @@ -645,7 +649,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, trace_pflash_reset(); memory_region_rom_device_set_romd(&pfl->mem, true); pfl->wcycle =3D 0; - pfl->cmd =3D 0; + pfl->cmd =3D 0x00; /* This model reset value for READ_ARRAY (not CFI) = */ } =20 =20 @@ -761,7 +765,11 @@ static void pflash_cfi01_realize(DeviceState *dev, Err= or **errp) } =20 pfl->wcycle =3D 0; - pfl->cmd =3D 0; + /* + * The command 0x00 is not assigned by the CFI open standard, + * but QEMU historically uses it for the READ_ARRAY command (0xff). + */ + pfl->cmd =3D 0x00; pfl->status =3D 0x80; /* WSM ready */ /* Hardcoded CFI table */ /* Standard "QRY" string */ --=20 2.20.1 From nobody Sun May 19 01:15:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563315442; cv=none; d=zoho.com; s=zohoarc; b=VxpIOall6mWJsfJRBx1rk+TaHJ3rU+C2ZXLqXWMiA34MSyHEq6cMUa1tnuwcbeIPgdNYAs1rVTHhLi+EcnY2S9bJl0g6obf78Co18C9kUCZmx9An1z24lS5Z9xWTNraM+yf2BNBVsKwprM4i9NQ+aovA2bWefxsndI03pI4ko/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563315442; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gfRtWgZK0M04udbxeVrBu4l+wCgfC42/jq+lXgx3PyM=; b=n3UWjzNx4FX2GYvJTHaa1SRTebbyzDTNAwQKv1XVidS+/+SwatRJ/YRsSh9jPFPsFFbNPiey5iKnWPyqX2be1lOqxMguuzJ7My/Mu5BTJK/YtHAlSuWrjW5EhB655FSSFQOcfA1x40/QAVZXTYRsGoDhhl9QBZ4W9D0EkzmvkV4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15633154423757.387310749438825; Tue, 16 Jul 2019 15:17:22 -0700 (PDT) Received: from localhost ([::1]:52641 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVl8-0000Pa-QP for importer@patchew.org; Tue, 16 Jul 2019 18:17:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41733) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVkX-0007Cp-5Q for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnVkV-0002YR-O0 for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnVkS-0002Sq-RL; Tue, 16 Jul 2019 18:16:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46A713092640; Tue, 16 Jul 2019 22:16:33 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD8115D96F; Tue, 16 Jul 2019 22:16:21 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2019 00:15:53 +0200 Message-Id: <20190716221555.11145-4-philmd@redhat.com> In-Reply-To: <20190716221555.11145-1-philmd@redhat.com> References: <20190716221555.11145-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 16 Jul 2019 22:16:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH-for-4.1 v6 3/5] hw/block/pflash_cfi01: Extract pflash_mode_read_array() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Laszlo Ersek , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Alistair Francis , John Snow , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The same pattern is used when setting the flash in READ_ARRAY mode: - Set the state machine command to READ_ARRAY - Reset the write_cycle counter - Reset the memory region in ROMD Refactor the current code by extracting this pattern. It is used three times: - On a read access (on invalid command). Note this default case is not reachable by the state machine updates in pflash_data_write(). However we might reach this case migrating from a future QEMU version that would implement newer commands, without incrementing the migration version. Since we never know, we keep this default case. Previous to this patch, an invalid read command would not reset the memory region in ROMD mode, so: . A further read access would keep going into I/O mode, calling the same switch in pflash_read(). Undefined behaviour, probably unexpected. . A further write access in I/O mode. Since the default case set (wcycle=3D0, cmd=3D0x00), we jump to reset_flash which set the flash in READ_ARRAY. After this patch, if we get an invalid read command we directly set (wcycle=3D0, cmd=3D0x00) and put the device in ROMD mode. Further I/O access are now properly handled. - On a write access (on command failure, error, or explicitly asked) - When the device is initialized. Here the ROMD mode is hidden by the memory_region_init_rom_device() call. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- v6: split of the label rename to ease review the pattern is used 3 times (was 2 times previously) describe the 3rd time and reset the review tags :( --- hw/block/pflash_cfi01.c | 31 +++++++++++++++---------------- hw/block/trace-events | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 6838e8a1ab..a28d0f8cc7 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -112,6 +112,18 @@ static const VMStateDescription vmstate_pflash =3D { } }; =20 +static void pflash_mode_read_array(PFlashCFI01 *pfl) +{ + trace_pflash_mode_read_array(); + /* + * The command 0x00 is not assigned by the CFI open standard, + * but QEMU historically uses it for the READ_ARRAY command (0xff). + */ + pfl->cmd =3D 0x00; + pfl->wcycle =3D 0; + memory_region_rom_device_set_romd(&pfl->mem, true); +} + /* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -276,12 +288,7 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr o= ffset, default: /* This should never happen : reset state & treat it as a read */ DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd); - pfl->wcycle =3D 0; - /* - * The command 0x00 is not assigned by the CFI open standard, - * but QEMU historically uses it for the READ_ARRAY command (0xff). - */ - pfl->cmd =3D 0x00; + pflash_mode_read_array(pfl); /* fall through to read code */ case 0x00: /* This model reset value for READ_ARRAY (not CFI compliant= ) */ /* Flash area read */ @@ -646,10 +653,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offs= et, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); =20 reset_flash: - trace_pflash_reset(); - memory_region_rom_device_set_romd(&pfl->mem, true); - pfl->wcycle =3D 0; - pfl->cmd =3D 0x00; /* This model reset value for READ_ARRAY (not CFI) = */ + pflash_mode_read_array(pfl); } =20 =20 @@ -764,12 +768,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Err= or **errp) pfl->max_device_width =3D pfl->device_width; } =20 - pfl->wcycle =3D 0; - /* - * The command 0x00 is not assigned by the CFI open standard, - * but QEMU historically uses it for the READ_ARRAY command (0xff). - */ - pfl->cmd =3D 0x00; + pflash_mode_read_array(pfl); pfl->status =3D 0x80; /* WSM ready */ /* Hardcoded CFI table */ /* Standard "QRY" string */ diff --git a/hw/block/trace-events b/hw/block/trace-events index 13d1b21dd4..91a8a106c0 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -7,6 +7,7 @@ fdc_ioport_write(uint8_t reg, uint8_t value) "write reg 0x%= 02x val 0x%02x" # pflash_cfi02.c # pflash_cfi01.c pflash_reset(void) "reset" +pflash_mode_read_array(void) "mode: read array" pflash_timer_expired(uint8_t cmd) "command 0x%02x done" pflash_io_read(uint64_t offset, int width, int fmt_width, uint32_t value, = uint8_t cmd, uint8_t wcycle) "offset:0x%04"PRIx64" width:%d value:0x%0*x cm= d:0x%02x wcycle:%u" pflash_io_write(uint64_t offset, int width, int fmt_width, uint32_t value,= uint8_t wcycle) "offset:0x%04"PRIx64" width:%d value:0x%0*x wcycle:%u" --=20 2.20.1 From nobody Sun May 19 01:15:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563315446; cv=none; d=zoho.com; s=zohoarc; b=JnuNC5/KTG0/88YsEyMDAtb8QMwWXqne6jn2LcZqT0+rPniC11Nkhfg3O05ZBzDwF3Z19aDXI4yOOjLFj2oxipDPGYe4rasofGW3unsf5jLZ0mZKArgyTIHIoX0K9XTMaM/hjbU31phna+YkWqoBgm1zO2hxa+3C0yatFfQBIxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563315446; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6dgmGJ5elQ5fVB0Zq8Ho1N/ytfmfIl5mLht6R7b4HZM=; b=YNtGOLi+uWC+r4gBXXc3mO1RKJ6I4PbZG/R3PviAcAsp4iI4NGY4fV7wuiehNxwQs8uiyC5B1FpVQKM+xj6jd070as2T0vcP7NYfG/bpAVnOjgVRiJqbuQtWUTfwX0Q1mK7q2uK+M4WwvrPRJC7f2q1z0LLRRgG7Dsbv2LcJ44o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15633154462421019.1442655403699; Tue, 16 Jul 2019 15:17:26 -0700 (PDT) Received: from localhost ([::1]:52648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVlE-0000wj-RV for importer@patchew.org; Tue, 16 Jul 2019 18:17:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41804) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVke-0007eY-3o for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnVkc-0002cZ-RW for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:16:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36206) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnVkZ-0002a3-7v; Tue, 16 Jul 2019 18:16:43 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 441D0308FFB1; Tue, 16 Jul 2019 22:16:42 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1223A5DAA4; Tue, 16 Jul 2019 22:16:33 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2019 00:15:54 +0200 Message-Id: <20190716221555.11145-5-philmd@redhat.com> In-Reply-To: <20190716221555.11145-1-philmd@redhat.com> References: <20190716221555.11145-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 16 Jul 2019 22:16:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH-for-4.1 v6 4/5] hw/block/pflash_cfi01: Rename 'reset_flash' label as 'mode_read_array' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Laszlo Ersek , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Alistair Francis , John Snow , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Rename the 'reset_flash' as 'mode_read_array' to make explicit we do not reset the device, we simply set its internal state machine in the READ_ARRAY mode. We do not reset the status register error bits, as a device reset would do. Reviewed-by: John Snow Reviewed-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v6: split of from previous patch to ease review dropped Laszlo's Regression-tested-by tag --- hw/block/pflash_cfi01.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index a28d0f8cc7..65afdbf3a7 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -460,7 +460,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, /* read mode */ switch (cmd) { case 0x00: /* This model reset value for READ_ARRAY (not CFI) */ - goto reset_flash; + goto mode_read_array; case 0x10: /* Single Byte Program */ case 0x40: /* Single Byte Program */ DPRINTF("%s: Single Byte Program\n", __func__); @@ -483,7 +483,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, case 0x50: /* Clear status bits */ DPRINTF("%s: Clear status bits\n", __func__); pfl->status =3D 0x0; - goto reset_flash; + goto mode_read_array; case 0x60: /* Block (un)lock */ DPRINTF("%s: Block unlock\n", __func__); break; @@ -508,10 +508,10 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr off= set, break; case 0xf0: /* Probe for AMD flash */ DPRINTF("%s: Probe for AMD flash\n", __func__); - goto reset_flash; - case 0xff: /* Read array mode */ + goto mode_read_array; + case 0xff: /* Read Array */ DPRINTF("%s: Read array mode\n", __func__); - goto reset_flash; + goto mode_read_array; default: goto error_flash; } @@ -537,8 +537,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, if (cmd =3D=3D 0xd0) { /* confirm */ pfl->wcycle =3D 0; pfl->status |=3D 0x80; - } else if (cmd =3D=3D 0xff) { /* read array mode */ - goto reset_flash; + } else if (cmd =3D=3D 0xff) { /* Read Array */ + goto mode_read_array; } else goto error_flash; =20 @@ -564,16 +564,16 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr off= set, } else if (cmd =3D=3D 0x01) { pfl->wcycle =3D 0; pfl->status |=3D 0x80; - } else if (cmd =3D=3D 0xff) { - goto reset_flash; + } else if (cmd =3D=3D 0xff) { /* Read Array */ + goto mode_read_array; } else { DPRINTF("%s: Unknown (un)locking command\n", __func__); - goto reset_flash; + goto mode_read_array; } break; case 0x98: - if (cmd =3D=3D 0xff) { - goto reset_flash; + if (cmd =3D=3D 0xff) { /* Read Array */ + goto mode_read_array; } else { DPRINTF("%s: leaving query mode\n", __func__); } @@ -633,7 +633,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, " the data is already written to storage!\n" "Flash device reset into READ mode.\n", __func__); - goto reset_flash; + goto mode_read_array; } break; default: @@ -643,7 +643,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, default: /* Should never happen */ DPRINTF("%s: invalid write state\n", __func__); - goto reset_flash; + goto mode_read_array; } return; =20 @@ -652,7 +652,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, "(offset " TARGET_FMT_plx ", wcycle 0x%x cmd 0x%x value = 0x%x)" "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); =20 - reset_flash: + mode_read_array: pflash_mode_read_array(pfl); } =20 --=20 2.20.1 From nobody Sun May 19 01:15:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563315458; cv=none; d=zoho.com; s=zohoarc; b=RzJINyBAzF8ZzsIwCGyGcVXisHhHVmtMaLebfxuncctlvKj3kj0BLXSxGeKoe3aVDIr1Ck1gcci5rnbsaAIDizDz3rg8jJ4pIkXv1YG4s6aApLA0eUW5L9jlzYdha5DFweRVxJynRFh2jY+ObqQ5jNdGzWRhea7lg6XMK92/kAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563315458; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=fDUiG19airQa6ezh6Fe3dG6/tNa2CIHhLOvs0T7JBvw=; b=HtIrRs9f9WGy78luOiZX4Q0Hxs5RjBZPoWtMUGNMnDVF8fYoB7wnr13T1fpmHLWAXHkg7MqFlvx+c1g1qnzUFHnqFYaZCBtZdU3Wu5lM+0DtSC+xYbwfTFeH2B58Xw8A1T7eQ6+rN1mbVfmDCU6T0XEHD4MegR9IPr9nlrzRiDw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563315458439603.081479404911; Tue, 16 Jul 2019 15:17:38 -0700 (PDT) Received: from localhost ([::1]:52652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVlR-0001xG-87 for importer@patchew.org; Tue, 16 Jul 2019 18:17:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41879) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnVks-0008WI-3Z for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:17:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnVkq-0002kv-Pa for qemu-devel@nongnu.org; Tue, 16 Jul 2019 18:17:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnVko-0002hz-0Z; Tue, 16 Jul 2019 18:16:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AB19308218D; Tue, 16 Jul 2019 22:16:57 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 64CF95D96F; Tue, 16 Jul 2019 22:16:42 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2019 00:15:55 +0200 Message-Id: <20190716221555.11145-6-philmd@redhat.com> In-Reply-To: <20190716221555.11145-1-philmd@redhat.com> References: <20190716221555.11145-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 16 Jul 2019 22:16:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH-for-4.1 v6 5/5] hw/block/pflash_cfi01: Add the DeviceReset() handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Laszlo Ersek , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Alistair Francis , John Snow , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A "system reset" sets the device state machine in READ_ARRAY mode and, after some delay, set the SR.7 READY bit. We do not model timings, so we set the SR.7 bit directly. The TYPE_DEVICE interface provides a DeviceReset handler. This pflash device is a subclass of TYPE_SYS_BUS_DEVICE (which is a subclass of TYPE_DEVICE). SYS_BUS devices are automatically plugged into the 'main system bus', which is the root of the qbus tree. Devices in the qbus tree are guaranteed to have their reset() handler called after realize() and before we try to run the guest. To avoid incoherent states when the machine resets (see but report below), factor out the reset code into pflash_cfi01_system_reset, and register the method as a device reset callback. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1678713 Reported-by: Laszlo Ersek Reviewed-by: John Snow Reviewed-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v6: dropped Laszlo's Regression-tested-by tag --- hw/block/pflash_cfi01.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 65afdbf3a7..ee0ed70242 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -768,8 +768,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) pfl->max_device_width =3D pfl->device_width; } =20 - pflash_mode_read_array(pfl); - pfl->status =3D 0x80; /* WSM ready */ /* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10] =3D 'Q'; @@ -857,6 +855,18 @@ static void pflash_cfi01_realize(DeviceState *dev, Err= or **errp) pfl->cfi_table[0x3f] =3D 0x01; /* Number of protection fields */ } =20 +static void pflash_cfi01_system_reset(DeviceState *dev) +{ + PFlashCFI01 *pfl =3D PFLASH_CFI01(dev); + + pflash_mode_read_array(pfl); + /* + * The WSM ready timer occurs at most 150ns after system reset. + * This model deliberately ignores this delay. + */ + pfl->status =3D 0x80; +} + static Property pflash_cfi01_properties[] =3D { DEFINE_PROP_DRIVE("drive", PFlashCFI01, blk), /* num-blocks is the number of blocks actually visible to the guest, @@ -901,6 +911,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass,= void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->reset =3D pflash_cfi01_system_reset; dc->realize =3D pflash_cfi01_realize; dc->props =3D pflash_cfi01_properties; dc->vmsd =3D &vmstate_pflash; --=20 2.20.1