From nobody Thu Apr 25 05:10:31 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=1562860693; cv=none; d=zoho.com; s=zohoarc; b=MagtAjgl5wD6EL7U/dmxBfICN2PGPmV3LKemF8tdcnDGl95Q7JoQuvGJIaDC7E5tcCSHgeYbpa6En8ew21btPjNTkzT/kqvzll+pdQME3u3u1bZ7Foo3nVup/a1x5Djw6E4w/xoP8q5WFIXhba6xuLAHUl88YrcHSODoHLhRZj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860693; 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=b45BR1ogRtPXX5sxH6K/BWbwnggm9/mJB1zEV6Xuk70=; b=GZPJgWUhUM6Eh8CDwG2VgFnU3b5MV0ISGjkJwT0xvX/3o40BE00ywAx8JTeUz9gqNgDsjgYjM9IDr5Fs/wzGA6O4sf5yXIKQGP7XjdRuOuTsM5snVxvDXkfOVHJCsbjsbwFkX/lJ4ni1aYVunrSLqBJdqrRNfQRbHi2r6o7wS6E= 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 156286069313574.67223519592108; Thu, 11 Jul 2019 08:58:13 -0700 (PDT) Received: from localhost ([::1]:43036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbSV-0006aj-NQ for importer@patchew.org; Thu, 11 Jul 2019 11:58:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33319) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbRn-0003ut-0W for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlbRk-0006R8-1L for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlbRe-0006LI-19; Thu, 11 Jul 2019 11:57:18 -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 44F5683F44; Thu, 11 Jul 2019 15:57:16 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0E01F5D9DC; Thu, 11 Jul 2019 15:57:12 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 17:56:59 +0200 Message-Id: <20190711155703.15627-2-philmd@redhat.com> In-Reply-To: <20190711155703.15627-1-philmd@redhat.com> References: <20190711155703.15627-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.27]); Thu, 11 Jul 2019 15:57:16 +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 v4 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 , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Alistair Francis , Wei Yang , Laszlo Ersek 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 --- v2: Fixed commit description (Laszlo) --- 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 db4a246b22..9e34fd4e82 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 0; --=20 2.20.1 From nobody Thu Apr 25 05:10:31 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=1562860685; cv=none; d=zoho.com; s=zohoarc; b=XxRwUqjmbp4vEOGA/UAdyytGxI6k7jGHIqyFgYko00mpiCi4iwg87hFximXfXmGhDMUOPQMB2eaySYSeJ+A7jhCuDPtram9afsdcGr1F22oWZhGBzFQdo8J+Bs1DY/MCX17n91m+dB72BU3OAvzQG9I304cQGJ4jy1nX2YbCZug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860685; 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=Qk75ofLVVw96rbrUMQ3DYdc2ja1FioacugqpVjqEZTM=; b=D3M/hGZmG2yPWBuwTuptDYBiwobWbOj1im1qVJknNwMY1D1l6IGoBe+/ohOnVIUz0xyH91a5REBoF5w2cQiyo35nMrE/EZd0guALdinFf82yXTCU1swW7PqlaXzf8rLkymx4zuc/Ypg7BSDV4Gyntu9kSXLfvAD1s5fi/JRK65E= 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 156286068576620.053886366580855; Thu, 11 Jul 2019 08:58:05 -0700 (PDT) Received: from localhost ([::1]:43032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbSO-0005wX-H9 for importer@patchew.org; Thu, 11 Jul 2019 11:58:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33389) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbRs-0004Jg-PX for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlbRq-0006YX-4u for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45528) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlbRk-0006Pf-2s; Thu, 11 Jul 2019 11:57:25 -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 370DC2CD801; Thu, 11 Jul 2019 15:57:22 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAE815D9CC; Thu, 11 Jul 2019 15:57:16 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 17:57:00 +0200 Message-Id: <20190711155703.15627-3-philmd@redhat.com> In-Reply-To: <20190711155703.15627-1-philmd@redhat.com> References: <20190711155703.15627-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.29]); Thu, 11 Jul 2019 15:57:22 +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 v4 2/5] hw/block/pflash_cfi01: Use the correct READ_ARRAY value 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 , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laszlo Ersek , Max Reitz , Alistair Francis , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In the "Read Array Flowchart" the command has a value of 0xFF. In the document [*] the "Read Array Flowchart", the READ_ARRAY command has a value of 0xff. Use the correct value in the pflash model. There is no change of behavior in the guest, because: - when the guest were sending 0xFF, the reset_flash label was setting the command value as 0x00 - 0x00 was used internally for READ_ARRAY To keep migration with older versions behaving correctly, we decide to always migrate the READ_ARRAY as 0x00. [*] "Common Flash Interface (CFI) and Command Sets" (Intel Application Note 646) Appendix B "Basic Command Set" Reviewed-by: John Snow Reviewed-by: Alistair Francis Regression-tested-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v3: Handle migrating the 'cmd' field. v4: Handle migrating to older QEMU (Dave) Since Laszlo stated he did not test migration [*], I'm keeping his test tag, because the change with v2 has no impact in the tests he ran. Likewise I'm keeping John and Alistair tags, but I'd like an extra review for the migration change, thanks! [*] https://lists.gnu.org/archive/html/qemu-devel/2019-07/msg00679.html --- hw/block/pflash_cfi01.c | 57 ++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 9e34fd4e82..85bb2132c0 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -96,6 +96,37 @@ struct PFlashCFI01 { bool old_multiple_chip_handling; }; =20 +static int pflash_pre_save(void *opaque) +{ + PFlashCFI01 *s =3D opaque; + + /* + * Previous to QEMU v4.1 an incorrect value of 0x00 was used for the + * READ_ARRAY command. To preserve migrating to these older version, + * always migrate the READ_ARRAY command as 0x00. + */ + if (s->cmd =3D=3D 0xff) { + s->cmd =3D 0x00; + } + + return 0; +} + +static int pflash_post_save(void *opaque) +{ + PFlashCFI01 *s =3D opaque; + + /* + * If migration failed, the guest will continue to run. + * Restore the correct READ_ARRAY value. + */ + if (s->cmd =3D=3D 0x00) { + s->cmd =3D 0xff; + } + + return 0; +} + static int pflash_post_load(void *opaque, int version_id); =20 static const VMStateDescription vmstate_pflash =3D { @@ -103,6 +134,8 @@ static const VMStateDescription vmstate_pflash =3D { .version_id =3D 1, .minimum_version_id =3D 1, .post_load =3D pflash_post_load, + .pre_save =3D pflash_pre_save, + .post_save =3D pflash_post_save, .fields =3D (VMStateField[]) { VMSTATE_UINT8(wcycle, PFlashCFI01), VMSTATE_UINT8(cmd, PFlashCFI01), @@ -277,10 +310,9 @@ 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; + pfl->cmd =3D 0xff; /* fall through to read code */ - case 0x00: - /* Flash area read */ + case 0xff: /* Read Array */ ret =3D pflash_data_read(pfl, offset, width, be); break; case 0x10: /* Single byte program */ @@ -448,8 +480,6 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, case 0: /* read mode */ switch (cmd) { - case 0x00: /* ??? */ - goto reset_flash; case 0x10: /* Single Byte Program */ case 0x40: /* Single Byte Program */ DPRINTF("%s: Single Byte Program\n", __func__); @@ -526,7 +556,7 @@ 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 */ + } else if (cmd =3D=3D 0xff) { /* Read Array */ goto reset_flash; } else goto error_flash; @@ -553,7 +583,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, } else if (cmd =3D=3D 0x01) { pfl->wcycle =3D 0; pfl->status |=3D 0x80; - } else if (cmd =3D=3D 0xff) { + } else if (cmd =3D=3D 0xff) { /* read array mode */ goto reset_flash; } else { DPRINTF("%s: Unknown (un)locking command\n", __func__); @@ -645,7 +675,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 0xff; } =20 =20 @@ -761,7 +791,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) } =20 pfl->wcycle =3D 0; - pfl->cmd =3D 0; + pfl->cmd =3D 0xff; pfl->status =3D 0; /* Hardcoded CFI table */ /* Standard "QRY" string */ @@ -1001,5 +1031,14 @@ static int pflash_post_load(void *opaque, int versio= n_id) pfl->vmstate =3D qemu_add_vm_change_state_handler(postload_update_= cb, pfl); } + + /* + * Previous to QEMU v4.1 an incorrect value of 0x00 was used for the + * READ_ARRAY command. + */ + if (pfl->cmd =3D=3D 0x00) { + pfl->cmd =3D 0xff; + } + return 0; } --=20 2.20.1 From nobody Thu Apr 25 05:10:31 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=1562860709; cv=none; d=zoho.com; s=zohoarc; b=N6A0gka3PYwo2lORrvu9MZfWxSyrMPhJOUYRrrFoIYsLSLUOkC0ujZ9d9rl/DPl4QS1It6rWByl9pzkACqfc+afs97mm5tEzJWbG1eI86RZf8AWHU97aS0SnHYdXgYt6yYhDuYauK4Je8eAnmkq8WxKb9KoD6cVkUo208YfqLfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860709; 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=aNuQZaAXTyoGu7r+dqoJEhEtPO7GeRGXDXku+obLvCo=; b=jKSo0FE/ta9ft5PH7Ou9mwnF8J9QpcBoq8c0327FaW0XGuZaZw4L/5lPlWHpnqd6K8rLGwTRXKltcBRq7qWl6eMyFL06rhYrXo/LLAw3xsXVoEfxKx7mxvxa1CUxSRVHt19quR9CiEh5WHKQgXm34FMCrZBgnLfg3zqgO7iq0wQ= 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 1562860709666667.388658674467; Thu, 11 Jul 2019 08:58:29 -0700 (PDT) Received: from localhost ([::1]:43048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbSm-00089l-NB for importer@patchew.org; Thu, 11 Jul 2019 11:58:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33415) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbRu-0004Rk-UR for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlbRt-0006cJ-Ee for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59796) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlbRo-0006U2-40; Thu, 11 Jul 2019 11:57:30 -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 500AF3086220; Thu, 11 Jul 2019 15:57:26 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A24D95D9CC; Thu, 11 Jul 2019 15:57:22 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 17:57:01 +0200 Message-Id: <20190711155703.15627-4-philmd@redhat.com> In-Reply-To: <20190711155703.15627-1-philmd@redhat.com> References: <20190711155703.15627-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.42]); Thu, 11 Jul 2019 15:57:26 +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 v4 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 , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laszlo Ersek , Max Reitz , Alistair Francis , John Snow 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 twice: - 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. 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 Regression-tested-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi01.c | 36 ++++++++++++++++++++---------------- hw/block/trace-events | 1 + 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 85bb2132c0..6c3fefcd2d 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -145,6 +145,14 @@ static const VMStateDescription vmstate_pflash =3D { } }; =20 +static void pflash_mode_read_array(PFlashCFI01 *pfl) +{ + trace_pflash_mode_read_array(); + pfl->cmd =3D 0xff; /* Read Array */ + 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. @@ -502,7 +510,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; @@ -527,10 +535,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; + goto mode_read_array; case 0xff: /* Read array mode */ DPRINTF("%s: Read array mode\n", __func__); - goto reset_flash; + goto mode_read_array; default: goto error_flash; } @@ -557,7 +565,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, pfl->wcycle =3D 0; pfl->status |=3D 0x80; } else if (cmd =3D=3D 0xff) { /* Read Array */ - goto reset_flash; + goto mode_read_array; } else goto error_flash; =20 @@ -584,15 +592,15 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr off= set, pfl->wcycle =3D 0; pfl->status |=3D 0x80; } else if (cmd =3D=3D 0xff) { /* read array mode */ - goto reset_flash; + 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; + goto mode_read_array; } else { DPRINTF("%s: leaving query mode\n", __func__); } @@ -652,7 +660,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: @@ -662,7 +670,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 @@ -671,11 +679,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offs= et, "(offset " TARGET_FMT_plx ", wcycle 0x%x cmd 0x%x value = 0x%x)" "\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 0xff; + mode_read_array: + pflash_mode_read_array(pfl); } =20 =20 @@ -790,8 +795,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) pfl->max_device_width =3D pfl->device_width; } =20 - pfl->wcycle =3D 0; - pfl->cmd =3D 0xff; + pflash_mode_read_array(pfl); pfl->status =3D 0; /* 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 Thu Apr 25 05:10:31 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=1562860690; cv=none; d=zoho.com; s=zohoarc; b=aEPqBMHOEsSRP8UGRY5fNASrIdszAZZsmpJsgxQ9jDPjlMe7nsIjMuC/iL7ObOr9D8NnZYRfmKW4bOhg9NA7I/fn9i+IPlyiq008B/bHQxJ/VdI7Txp8IU6kzcsYo6/3/150Ihv3agTQlthON/tHnMNjYGyDCuVn6Kaux22AGZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860690; 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=et3PuEUwTn1Z/fT09ID6tWrkHtzNKphFtr5tC0Fgho4=; b=KslUStuGo4jgd8KivlLScB/hcrYPIcSfpWPSSXy2OpQ6Eqz7vOQevlcp7PhUIHYG8IsOffkGlWGYV5xMbcdpuGT2luPUivDPnH/RxEerbdRCBLg1Pp1Zrl3kEPzl5vQ6+PKB5cKJGAlrQdT5BzvkKrXpvweJlOrKJjodAAS9nRY= 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 1562860690608582.0351819850351; Thu, 11 Jul 2019 08:58:10 -0700 (PDT) Received: from localhost ([::1]:43034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbST-0006Iq-1O for importer@patchew.org; Thu, 11 Jul 2019 11:58:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33453) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbRx-0004h3-VY for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlbRv-0006eM-T3 for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlbRt-0006bu-IG; Thu, 11 Jul 2019 11:57:33 -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 C61AD30C1321; Thu, 11 Jul 2019 15:57:32 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDB825D9CC; Thu, 11 Jul 2019 15:57:26 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 17:57:02 +0200 Message-Id: <20190711155703.15627-5-philmd@redhat.com> In-Reply-To: <20190711155703.15627-1-philmd@redhat.com> References: <20190711155703.15627-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.45]); Thu, 11 Jul 2019 15:57:32 +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 v4 4/5] hw/block/pflash_cfi01: Start state machine as READY to accept commands 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 , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laszlo Ersek , Max Reitz , Alistair Francis , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When the state machine is ready to accept command, the bit 7 of the status register (SR) is set to 1. The guest polls the status register and check this bit before writting command to the internal 'Write State Machine' (WSM). Set SR.7 bit to 1 when the device is created. There is no migration impact by this change. Reference: Read Array Flowchart "Common Flash Interface (CFI) and Command Sets" (Intel Application Note 646) Appendix B "Basic Command Set" Reviewed-by: John Snow Reviewed-by: Alistair Francis Regression-tested-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v3: Added migration comment. --- hw/block/pflash_cfi01.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 6c3fefcd2d..aa2126f6dc 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -796,7 +796,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) } =20 pflash_mode_read_array(pfl); - pfl->status =3D 0; + pfl->status =3D 0x80; /* WSM ready */ /* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10] =3D 'Q'; --=20 2.20.1 From nobody Thu Apr 25 05:10:31 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=1562860722; cv=none; d=zoho.com; s=zohoarc; b=PKbjruVYidG7Lu3jNhEI1oqu+x31Y/l0FRkqccnQll3BC2zE5uzjRE2Yt71+RQuYvMwf05kAYP17r9r3TRviFpsWfVUC2/InCbEKaHF0Vk2wRvsKuFodJNPqYpRXmSyA9cGsAPlvHLzjNAkFagQnEFcwv0BF18/mqVSir7+kH0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860722; 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=LKIHgQn5BbOHFXD1SaCcvYkDLekMRKsnmoAXYOFAiQY=; b=EtWAlJVGx4uwA3HRa9z+k1JaBWQ2gTnDTTq+1wbTQyOFW302ZJoV7nAXCbFguuxhVF3UOEvMQlXrlrTC/dP4ydSzRTXPZCV+blO0j1IX6lKiZM9olLbu5vrvJ+t+aQZFlGa7cc4CnH/2Y4OAxCL1ihs7EECRkR81mP9YOS2Wf1M= 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 1562860722618986.677126430183; Thu, 11 Jul 2019 08:58:42 -0700 (PDT) Received: from localhost ([::1]:43058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbSz-0000iZ-NW for importer@patchew.org; Thu, 11 Jul 2019 11:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33488) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbS3-00056l-Uj for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlbS1-0006iN-Ir for qemu-devel@nongnu.org; Thu, 11 Jul 2019 11:57:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlbRy-0006f9-Qi; Thu, 11 Jul 2019 11:57:39 -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 BAC2BBB10; Thu, 11 Jul 2019 15:57:36 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B04E5D9CC; Thu, 11 Jul 2019 15:57:33 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 17:57:03 +0200 Message-Id: <20190711155703.15627-6-philmd@redhat.com> In-Reply-To: <20190711155703.15627-1-philmd@redhat.com> References: <20190711155703.15627-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.26]); Thu, 11 Jul 2019 15:57:36 +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 v4 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 , qemu-block@nongnu.org, John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis , Max Reitz , Laszlo Ersek 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 Regression-tested-by: Laszlo Ersek Reviewed-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v3: reword description --- 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 aa2126f6dc..dd2ace92a8 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -795,8 +795,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'; @@ -884,6 +882,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, @@ -928,6 +938,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