From nobody Wed Nov 19 08:22:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615333882; cv=none; d=zohomail.com; s=zohoarc; b=BBNbY4FmvlcZC2agYK1qzch4sHESiXMhLzH7bPNDSVFHDrO6kA8pVINYhdiy3hc2aTR74zZQKB+K+3le9oVaF9auEz4/KvYazQCGZVjKNZpZ1cRRBb9CmTUxoGo5euHsVkII0dy1hQ8yDfUwjHoeMPDZVA3LnVPeS7EBMwplJi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333882; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=+qy+PTHxX7Huj9tjoLOPMC5OSIt87dLhiTpUcqMgFpc=; b=nptqXMi6HRy0bhnLWDf8azIc8skfkexvXWsRN5xmECRkzVKViDolkvo/5A81wy5zZhTFmL6GCE3IKDMYamy2DDXk9Th3MAy7fjP+qGbPGCanvIT57IZHYPvq0FD+i4/7kWgtDq/lr4dIT7fPj5ZRp3Kki2CMBVnHrJTyxIz7pbo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1615333882755549.1331810619287; Tue, 9 Mar 2021 15:51:22 -0800 (PST) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-VdqKGzOJMt6hzZO6YSncHw-1; Tue, 09 Mar 2021 18:51:20 -0500 Received: by mail-ed1-f71.google.com with SMTP id t27so7545744edi.2 for ; Tue, 09 Mar 2021 15:51:19 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id p19sm10094548edr.57.2021.03.09.15.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+qy+PTHxX7Huj9tjoLOPMC5OSIt87dLhiTpUcqMgFpc=; b=ZRdiYYqqRdEddBzFcoI6Z+A0NEpBlIbFtTguSYHETIMv7EpuxlWM2tyHX3K6PoTx9NvlQh 1BU68FyqmPs+hqMvR7hSl9TTiBifV+1yl1JQU7MfrfAE170AxGWq6/MMCM816u8ad4w3tT aSZ9SBqa3KFAnxPkSmy9QAvKvLSVCd4= X-MC-Unique: VdqKGzOJMt6hzZO6YSncHw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+qy+PTHxX7Huj9tjoLOPMC5OSIt87dLhiTpUcqMgFpc=; b=CjYfG1b/UklApyCPjkBkg9mV6LfLMJcEsogZooJTow2cAQR3hBtO8GvoyInB8e5Neo otln3oKMd9QQTDqD6zwpt714gz0znnmHoHxh+3dCheelFgPegnDlM/jVsdMfLBDxtJFM QL894VQA3NDzFNOnPVQtpLiYAItll9X5SCdqBxjN7OgOS1VgoJ9OgbZPMyKeZC+Jz9Z0 Ch81gZxcaixCgVV/tM8AqCQDPp+bHxrK6kAw6UrXWH9muAaveWqg4dhQS3nsYuhNzxhQ UKWPwgbUgQG8ZeL0FSt1OpHYfQW2r2kE6j+F27/Zl1/iyg0gQ6NABqLOsLYBTIjRBFxL QiKg== X-Gm-Message-State: AOAM531k/O/FTw8kfyYBjfCwzAz2alNbKCXokV0RxSMgdCEAxUZ5AlNI Y6p10x+Ny4w5zYyLXgDAYQboDvNTgUYs7WJbkkjh/Usr/sL8XrVM2RUKc+zjJUWcisMk1sRgevX NxtayR1iSE2vZBg== X-Received: by 2002:a50:fc94:: with SMTP id f20mr180152edq.370.1615333878985; Tue, 09 Mar 2021 15:51:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIfelKM7fpky08JbD8KlJyfEgtCvmAqDAoD4S5W2kW2STAedUUU1l+W8QOncswpaSyK+UfmA== X-Received: by 2002:a50:fc94:: with SMTP id f20mr180138edq.370.1615333878855; Tue, 09 Mar 2021 15:51:18 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Max Reitz , Kevin Wolf , Stephen Checkoway , David Edmondson , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 9/9] hw/block/pflash_cfi01: Extract pflash_mode_read_array() Date: Wed, 10 Mar 2021 00:50:28 +0100 Message-Id: <20210309235028.912078-10-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210309235028.912078-1-philmd@redhat.com> References: <20210309235028.912078-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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). - 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. Reviewed-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Edmondson --- hw/block/pflash_cfi01.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 2618e00926d..32c9b289715 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -115,6 +115,19 @@ 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). + */ + trace_pflash_mode_read_array(); + 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 @@ -283,12 +296,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 */ @@ -663,10 +671,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offs= et, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); =20 mode_read_array: - trace_pflash_mode_read_array(); - 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 @@ -872,13 +877,8 @@ 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; pfl->status =3D 0x80; /* WSM ready */ + pflash_mode_read_array(pfl); pflash_cfi01_fill_cfi_table(pfl); } =20 @@ -887,13 +887,7 @@ static void pflash_cfi01_system_reset(DeviceState *dev) PFlashCFI01 *pfl =3D PFLASH_CFI01(dev); =20 trace_pflash_reset(); - /* - * 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); + pflash_mode_read_array(pfl); /* * The WSM ready timer occurs at most 150ns after system reset. * This model deliberately ignores this delay. --=20 2.26.2