From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615333840; cv=none; d=zohomail.com; s=zohoarc; b=ULpS1+4OmvMBQ7yvzqYqu2KYPFvIXQQegWgorxfASCc9uBzqC2Mg0wLI6l6QcF9W2SsVMV3rGvCwL+5dLPOAn89xyoogwSPhwsxUE5MzPmFkwYFANGKnacMd7FRppBbvLRCWD6ZKXQtg6zUw+sS/Xf+/W6bgCgsbtCrQDshedCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333840; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=vJp/6KIq7jt0wWSOpNuyjar6abO6hZopWxChO98/pAg=; b=JRBaMFwbRwT8lSbr6vCIYR7R+AuGty8HcBkQtQGtAiGccv7tDugDLNy8pJUX+mn76aheXeQKgbGwzVh83TrBZJGHOctEiZjkQo84xpupXC4bZze7ZswIsJptATRzF+qMEMoAhKpI+/3JTHwFyw1OG9zx8i5yY4UY7tlFxac8QHs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615333840295391.4308617106615; Tue, 9 Mar 2021 15:50:40 -0800 (PST) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-402-7Upl-ds6PRGap2jzbqjazw-1; Tue, 09 Mar 2021 18:50:37 -0500 Received: by mail-ej1-f71.google.com with SMTP id en21so6417245ejc.2 for ; Tue, 09 Mar 2021 15:50:37 -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 b18sm8972008ejb.77.2021.03.09.15.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333839; 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=vJp/6KIq7jt0wWSOpNuyjar6abO6hZopWxChO98/pAg=; b=QeCH8ugNWigzV+27h6Iq5Dyg5fyvboKr4AM8aGGRsZjsVDW2UY2dqfjkQ/1XKjYDwqjoUG NI1K7Fu2ZoovgLnKItiHQdOsO11DBk+lSo+KlK3Tagt33JrK9QnYFjq5R6YauI9JUj5Fve gAlH8L9wmX7G7iaE8cdKbFr2vLpsTbA= X-MC-Unique: 7Upl-ds6PRGap2jzbqjazw-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=vJp/6KIq7jt0wWSOpNuyjar6abO6hZopWxChO98/pAg=; b=t1LLsAJ7eGeS7WcpCQhvd8WrvEsFr+j4MMsQuIukjZO1ASbPni8krntNUWnFZhtpRv +Qj3lAoZDqWNqhCpbi7ebpzWJruKodHiJRYrfYDImdYt/02MVk3YV9kSG9PUm+Fi6dDh cwaF+pVbXLv/9wOyuYvoIMkmz77/14Oe6lSGmy2pZLSYZ3S4g4LthMek7PCE9LDuT+Zl 6TV9kajZa/Uw+YgaAWbK9arsLc9jv3JqDzgEfPZCRNjIFNoBmBAPmX3RgQzjcCRwQscA AnKjMNN4fblPRgJhnsen00vG2CKTIThChLhTLGvA4r2lIQ8NGr9t8kWxKQHukKZWnrCP fnyA== X-Gm-Message-State: AOAM533YVY5KmvAogn1PJ++lQUlP4Ozg7Z5dmurhT1YZOnXihZBNOtqP 2MvjI/8nquJzYeDSmo/Kefm7MfrEpwcN8a6iS9SefYBrV+annl3TPSaj26DRXV3FM2FukrvT4dY adcObirB+nKYoyA== X-Received: by 2002:a17:906:a147:: with SMTP id bu7mr527690ejb.383.1615333836467; Tue, 09 Mar 2021 15:50:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDeHb/7aZc6ARNFKu4C8WGlIBLU6oP8l6VfUKoRPpg6Uyuk2X6NQhsWkTkagd0jpa/S4KcQA== X-Received: by 2002:a17:906:a147:: with SMTP id bu7mr527682ejb.383.1615333836296; Tue, 09 Mar 2021 15:50:36 -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 1/9] hw/block/pflash_cfi: Fix code style for checkpatch.pl Date: Wed, 10 Mar 2021 00:50:20 +0100 Message-Id: <20210309235028.912078-2-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) We are going to move this code, fix its style first. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng Reviewed-by: David Edmondson --- hw/block/pflash_cfi01.c | 36 ++++++++++++++++++++++++------------ hw/block/pflash_cfi02.c | 9 ++++++--- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 22287a1522e..b6919bbe474 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -115,7 +115,8 @@ static const VMStateDescription vmstate_pflash =3D { } }; =20 -/* Perform a CFI query based on the bank width of the flash. +/* + * 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. */ @@ -125,7 +126,8 @@ static uint32_t pflash_cfi_query(PFlashCFI01 *pfl, hwad= dr offset) uint32_t resp =3D 0; hwaddr boff; =20 - /* Adjust incoming offset to match expected device-width + /* + * Adjust incoming offset to match expected device-width * addressing. CFI query addresses are always specified in terms of * the maximum supported width of the device. This means that x8 * devices and x8/x16 devices in x8 mode behave differently. For @@ -141,7 +143,8 @@ static uint32_t pflash_cfi_query(PFlashCFI01 *pfl, hwad= dr offset) if (boff >=3D sizeof(pfl->cfi_table)) { return 0; } - /* Now we will construct the CFI response generated by a single + /* + * Now we will construct the CFI response generated by a single * device, then replicate that for all devices that make up the * bus. For wide parts used in x8 mode, CFI query responses * are different than native byte-wide parts. @@ -185,7 +188,8 @@ static uint32_t pflash_devid_query(PFlashCFI01 *pfl, hw= addr offset) uint32_t resp; hwaddr boff; =20 - /* Adjust incoming offset to match expected device-width + /* + * Adjust incoming offset to match expected device-width * addressing. Device ID read addresses are always specified in * terms of the maximum supported width of the device. This means * that x8 devices and x8/x16 devices in x8 mode behave @@ -198,7 +202,8 @@ static uint32_t pflash_devid_query(PFlashCFI01 *pfl, hw= addr offset) boff =3D offset >> (ctz32(pfl->bank_width) + ctz32(pfl->max_device_width) - ctz32(pfl->device_wid= th)); =20 - /* Mask off upper bits which may be used in to query block + /* + * Mask off upper bits which may be used in to query block * or sector lock status at other addresses. * Offsets 2/3 are block lock status, is not emulated. */ @@ -297,7 +302,8 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr of= fset, case 0x60: /* Block /un)lock */ case 0x70: /* Status Register */ case 0xe8: /* Write block */ - /* Status register read. Return status from each device in + /* + * Status register read. Return status from each device in * bank. */ ret =3D pfl->status; @@ -308,7 +314,8 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr of= fset, shift +=3D pfl->device_width * 8; } } else if (!pfl->device_width && width > 2) { - /* Handle 32 bit flash cases where device width is not + /* + * Handle 32 bit flash cases where device width is not * set. (Existing behavior before device width added.) */ ret |=3D pfl->status << 16; @@ -340,7 +347,8 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr of= fset, break; } } else { - /* If we have a read larger than the bank_width, combine multi= ple + /* + * If we have a read larger than the bank_width, combine multi= ple * manufacturer/device ID queries into a single response. */ int i; @@ -367,7 +375,8 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr of= fset, ret =3D 0; } } else { - /* If we have a read larger than the bank_width, combine multi= ple + /* + * If we have a read larger than the bank_width, combine multi= ple * CFI queries into a single response. */ int i; @@ -544,7 +553,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, =20 break; case 0xe8: - /* Mask writeblock size based on device width, or bank width if + /* + * Mask writeblock size based on device width, or bank width if * device width not specified. */ /* FIXME check @offset, @width */ @@ -718,7 +728,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) =20 total_len =3D pfl->sector_len * pfl->nb_blocs; =20 - /* These are only used to expose the parameters of each device + /* + * These are only used to expose the parameters of each device * in the cfi_table[]. */ num_devices =3D pfl->device_width ? (pfl->bank_width / pfl->device_wid= th) : 1; @@ -763,7 +774,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) } } =20 - /* Default to devices being used at their maximum device width. This w= as + /* + * Default to devices being used at their maximum device width. This w= as * assumed before the device_width support was added. */ if (!pfl->max_device_width) { diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 7962cff7455..fa981465e12 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -100,7 +100,8 @@ struct PFlashCFI02 { uint16_t unlock_addr1; uint8_t cfi_table[0x4d]; QEMUTimer timer; - /* The device replicates the flash memory across its memory space. Em= ulate + /* + * The device replicates the flash memory across its memory space. Em= ulate * that by having a container (.mem) filled with an array of aliases * (.mem_mappings) pointing to the flash memory (.orig_mem). */ @@ -884,8 +885,10 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) pfl->cfi_table[0x28] =3D 0x02; pfl->cfi_table[0x29] =3D 0x00; /* Max number of bytes in multi-bytes write */ - /* XXX: disable buffered write as it's not supported */ - // pfl->cfi_table[0x2A] =3D 0x05; + /* + * XXX: disable buffered write as it's not supported + * pfl->cfi_table[0x2A] =3D 0x05; + */ pfl->cfi_table[0x2A] =3D 0x00; pfl->cfi_table[0x2B] =3D 0x00; /* Number of erase block regions */ --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1615333845; cv=none; d=zohomail.com; s=zohoarc; b=NVLFCHvB3hMv687cn8Mk0hY/hBEs+6u9OBYjDEu1Ru389U+YpU/TBBkf+IX10gxN0IA6RISbmitqh8SpXNkYj2OvsCOMgS33udqapJlUlZ7q9NLKHqVdoCGnq4Tu8E1ETAyCeawyCqI20SgUa4/IoNVcP6fDa5I9/88sSMAuuGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333845; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=KGPgh1dIDJdjD0VFPE49/XWio89qIKTLCGFsAjUNGeg=; b=Bf25calYylvCJQ2bLiLKdzrcNRcuAzot3JdEY0tOfJLtcQc43BVbQoBGG0Sx8UJKxo+iXw1nrPZA34NR9H7GyS6zQZ4cpdcq8FuN5G66LHbr1wr2vAMUozTEqCczRdAkny4c3yqP94PsH5DrRQPO6esHQ0WROqMSsEYmgztABYU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1615333845213175.94210985925804; Tue, 9 Mar 2021 15:50:45 -0800 (PST) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-8Ap-I36rMZiCJ6YkxwDjrw-1; Tue, 09 Mar 2021 18:50:42 -0500 Received: by mail-ej1-f71.google.com with SMTP id au15so6446699ejc.8 for ; Tue, 09 Mar 2021 15:50:42 -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 r19sm9954620edp.52.2021.03.09.15.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333844; 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=KGPgh1dIDJdjD0VFPE49/XWio89qIKTLCGFsAjUNGeg=; b=V7TB3MlqGxoKx5xwoTQcuvM++yM0rZ7vHK6cPlFBvvfzXnGVBx5cSJjjerDoF/T34Ujtaq zckJma5VT2XK1XkMlqB7nsfA4DHN4jfQOxRx6EQztMA0UgaxfdObkyqeK4uYdTZqblrBeT WKgeiwC8Vy/yQEsqOzirgmEbGkj6jQc= X-MC-Unique: 8Ap-I36rMZiCJ6YkxwDjrw-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=KGPgh1dIDJdjD0VFPE49/XWio89qIKTLCGFsAjUNGeg=; b=WpsxWW9nEqCpIdPWWQ2/RAg645f5sQhY1/MSDHhaOlvtkMUU0AmP6k9KS9Um5EnuYn m4OO4pokzEguTYq01O/0XtZPqTo0ZuPHPODFYE86CaRRfewZidsTz9uk9JRygU+d1Jy5 IS98iH3WIQaBzXHSpUeUF7TUDgXQ02MvuYG01oz/4FA9YJxoMpGMn2k2PDg4P/e7kaJp qN0lZkF4sVD+G/Da0YCDizmZYGWng6QTQZkgKPEPnZSFtTi3MpScCMlcuFw3ZH8txwjz 58oATCesCbF6Gyv2yLFRreIg7TfuOO+e6AqUd/bddfIzMy+CKadiwsW9jSgvocgtBZQF Y8Eg== X-Gm-Message-State: AOAM531Z2UVxQaS+H3LUu3u1cVzg6JG4W5bcADc7Ulv1c6OHQYQkVoi/ FqX19cy77Nrs1z7Sq/I2mt2mwqmnEocKMxHwcNo58Ny0dl1yTOOtKAlMpGfGGJ9GPCvEKCNqux1 hRuuX6BELUckFbA== X-Received: by 2002:a17:906:c08f:: with SMTP id f15mr590172ejz.318.1615333841583; Tue, 09 Mar 2021 15:50:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfJ2PDUKA7kWCb844iEaOZBN+L2h+mFRyUUB3jpN2debum4xtGQyUoTboG1ptTFv2hMhTKQQ== X-Received: by 2002:a17:906:c08f:: with SMTP id f15mr590162ejz.318.1615333841409; Tue, 09 Mar 2021 15:50:41 -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 2/9] hw/block/pflash_cfi01: Extract pflash_cfi01_fill_cfi_table() Date: Wed, 10 Mar 2021 00:50:21 +0100 Message-Id: <20210309235028.912078-3-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) Fill the CFI table in out of DeviceRealize() in a new function: pflash_cfi01_fill_cfi_table(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng Reviewed-by: David Edmondson --- hw/block/pflash_cfi01.c | 140 +++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 67 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index b6919bbe474..03472ea5b64 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -704,30 +704,11 @@ static const MemoryRegionOps pflash_cfi01_ops =3D { .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 -static void pflash_cfi01_realize(DeviceState *dev, Error **errp) +static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl) { - ERRP_GUARD(); - PFlashCFI01 *pfl =3D PFLASH_CFI01(dev); - uint64_t total_len; - int ret; uint64_t blocks_per_device, sector_len_per_device, device_len; int num_devices; =20 - if (pfl->sector_len =3D=3D 0) { - error_setg(errp, "attribute \"sector-length\" not specified or zer= o."); - return; - } - if (pfl->nb_blocs =3D=3D 0) { - error_setg(errp, "attribute \"num-blocks\" not specified or zero."= ); - return; - } - if (pfl->name =3D=3D NULL) { - error_setg(errp, "attribute \"name\" not specified."); - return; - } - - total_len =3D pfl->sector_len * pfl->nb_blocs; - /* * These are only used to expose the parameters of each device * in the cfi_table[]. @@ -742,53 +723,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Err= or **errp) } device_len =3D sector_len_per_device * blocks_per_device; =20 - memory_region_init_rom_device( - &pfl->mem, OBJECT(dev), - &pflash_cfi01_ops, - pfl, - pfl->name, total_len, errp); - if (*errp) { - return; - } - - pfl->storage =3D memory_region_get_ram_ptr(&pfl->mem); - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); - - if (pfl->blk) { - uint64_t perm; - pfl->ro =3D !blk_supports_write_perm(pfl->blk); - perm =3D BLK_PERM_CONSISTENT_READ | (pfl->ro ? 0 : BLK_PERM_WRITE); - ret =3D blk_set_perm(pfl->blk, perm, BLK_PERM_ALL, errp); - if (ret < 0) { - return; - } - } else { - pfl->ro =3D 0; - } - - if (pfl->blk) { - if (!blk_check_size_and_read_all(pfl->blk, pfl->storage, total_len, - errp)) { - vmstate_unregister_ram(&pfl->mem, DEVICE(pfl)); - return; - } - } - - /* - * Default to devices being used at their maximum device width. This w= as - * assumed before the device_width support was added. - */ - if (!pfl->max_device_width) { - pfl->max_device_width =3D pfl->device_width; - } - - 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 */ /* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10] =3D 'Q'; @@ -876,6 +810,78 @@ 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_realize(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + PFlashCFI01 *pfl =3D PFLASH_CFI01(dev); + uint64_t total_len; + int ret; + + if (pfl->sector_len =3D=3D 0) { + error_setg(errp, "attribute \"sector-length\" not specified or zer= o."); + return; + } + if (pfl->nb_blocs =3D=3D 0) { + error_setg(errp, "attribute \"num-blocks\" not specified or zero."= ); + return; + } + if (pfl->name =3D=3D NULL) { + error_setg(errp, "attribute \"name\" not specified."); + return; + } + + total_len =3D pfl->sector_len * pfl->nb_blocs; + + memory_region_init_rom_device( + &pfl->mem, OBJECT(dev), + &pflash_cfi01_ops, + pfl, + pfl->name, total_len, errp); + if (*errp) { + return; + } + + pfl->storage =3D memory_region_get_ram_ptr(&pfl->mem); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); + + if (pfl->blk) { + uint64_t perm; + pfl->ro =3D !blk_supports_write_perm(pfl->blk); + perm =3D BLK_PERM_CONSISTENT_READ | (pfl->ro ? 0 : BLK_PERM_WRITE); + ret =3D blk_set_perm(pfl->blk, perm, BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } + } else { + pfl->ro =3D 0; + } + + if (pfl->blk) { + if (!blk_check_size_and_read_all(pfl->blk, pfl->storage, total_len, + errp)) { + vmstate_unregister_ram(&pfl->mem, DEVICE(pfl)); + return; + } + } + + /* + * Default to devices being used at their maximum device width. This w= as + * assumed before the device_width support was added. + */ + if (!pfl->max_device_width) { + pfl->max_device_width =3D pfl->device_width; + } + + 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_cfi01_fill_cfi_table(pfl); +} + static void pflash_cfi01_system_reset(DeviceState *dev) { PFlashCFI01 *pfl =3D PFLASH_CFI01(dev); --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1615333851; cv=none; d=zohomail.com; s=zohoarc; b=H+fTdGe4qR+hMbiPsWjg0/UjSfjfqk3ko0WhntEiO4aSVR5p2pHbp5MY2EFZXmO1VY6bdFLXFtmwoVAGik+BBcQ6aVcvkIg/GIEeEMrQCdE+EPUa0PV7Kqn3L9afSo9fbLk1Ho+RGH+dyCEZ+sKyRh//NOaT5wi3+jrVqs1+fmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333851; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=bP+dfqmjDokovQt4RSO6YJdtqZpqvWo3J8PFMVnml4w=; b=W4XzyK9+GQjR28Wu5ZhefwALQ58pvuS3XUAjJakfmBezdfcm5ybC+L50c7FrC/sgzeV/dh5JnKvK7yjmIKxAQyddyn/3pFoGRi9jC/d8Y7AgdNMNiBgC1fRAl993EoGsdZwI/UmEOxJVLPCUzAywda/JW2FrP/Bv6J6QSPsrf4A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1615333851417512.968902241058; Tue, 9 Mar 2021 15:50:51 -0800 (PST) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-357-3Wqc_dl5N4eNrMWtG9q-ow-1; Tue, 09 Mar 2021 18:50:48 -0500 Received: by mail-ej1-f71.google.com with SMTP id 11so6391331ejz.20 for ; Tue, 09 Mar 2021 15:50:48 -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 g1sm10029369edh.31.2021.03.09.15.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:50:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333850; 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=bP+dfqmjDokovQt4RSO6YJdtqZpqvWo3J8PFMVnml4w=; b=hwC7M+g7y91gfrmoOwMcM7jEQ16efszllnl10abKFp/eQIwK9j0+POruD0TVoE/gdZuriD mXryz6LksMEbtlzZCjOQR0pZJyAuXWSGyuAxriIrPh5xd9tt9Pku5j0Yy8JWnV6JbKj/rT 8804wBpW8LRkVHAeRqziWNYdZbkJMxE= X-MC-Unique: 3Wqc_dl5N4eNrMWtG9q-ow-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=bP+dfqmjDokovQt4RSO6YJdtqZpqvWo3J8PFMVnml4w=; b=dpT8uwUvTOL9blIQImf1vNBkh7zWs5Jr40qmUWtKRPISOKcsEVZg9sLlX0n7NtLbkP E3arierjXmuSFb/V1DZMxj8aVOPC4rRWWLh7bLt1Uik0o44VYqUB/4OoGmWecMFFadTz xWcbZkM96XMQBmHcgl/bTxkn7l1cPYcUIlimr8gs5NsITAFn3psHSK/j5rkXj3fUE+3V SzUIhvz8i1cIqOSap4U52x31U2dvkxWYpU1U5iJ95uJqheENZ/vf3u6a0HEeqaQzBzAx il6NeVJMMuawmfcv1JtLN9/8H3JyxkC+CCuP14NSWa8gqQgdmBCZ1KDCjZChC0BWnVzq 7xLQ== X-Gm-Message-State: AOAM531g+usw4QrKJucMgS003E5FzBx2SbIJgKIPkUTOOMVbvy8lSMaG weNj3ACwJSmNYrlI+s8bTD/UFeRh+0cviXRCQUURzqbd9JeorflsQOw/fDmMD6+RFRn6/fXV/JP byiwq6SKPqgmM5w== X-Received: by 2002:aa7:c5c4:: with SMTP id h4mr138108eds.375.1615333847179; Tue, 09 Mar 2021 15:50:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUyLHh125iyHm2/HgTf7o7AO5/gHOBdkA+2yLHl4axRD8UWzmBSu9e4oB3CR1HQar4OEhfLg== X-Received: by 2002:aa7:c5c4:: with SMTP id h4mr138102eds.375.1615333847022; Tue, 09 Mar 2021 15:50:47 -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 3/9] hw/block/pflash_cfi02: Extract pflash_cfi02_fill_cfi_table() Date: Wed, 10 Mar 2021 00:50:22 +0100 Message-Id: <20210309235028.912078-4-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) Fill the CFI table in out of DeviceRealize() in a new function: pflash_cfi02_fill_cfi_table(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng Reviewed-by: David Edmondson --- hw/block/pflash_cfi02.c | 193 +++++++++++++++++++++------------------- 1 file changed, 99 insertions(+), 94 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index fa981465e12..845f50ed99b 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -724,6 +724,104 @@ static const MemoryRegionOps pflash_cfi02_ops =3D { .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 +static void pflash_cfi02_fill_cfi_table(PFlashCFI02 *pfl, int nb_regions) +{ + /* Hardcoded CFI table (mostly from SG29 Spansion flash) */ + const uint16_t pri_ofs =3D 0x40; + /* Standard "QRY" string */ + pfl->cfi_table[0x10] =3D 'Q'; + pfl->cfi_table[0x11] =3D 'R'; + pfl->cfi_table[0x12] =3D 'Y'; + /* Command set (AMD/Fujitsu) */ + pfl->cfi_table[0x13] =3D 0x02; + pfl->cfi_table[0x14] =3D 0x00; + /* Primary extended table address */ + pfl->cfi_table[0x15] =3D pri_ofs; + pfl->cfi_table[0x16] =3D pri_ofs >> 8; + /* Alternate command set (none) */ + pfl->cfi_table[0x17] =3D 0x00; + pfl->cfi_table[0x18] =3D 0x00; + /* Alternate extended table (none) */ + pfl->cfi_table[0x19] =3D 0x00; + pfl->cfi_table[0x1A] =3D 0x00; + /* Vcc min */ + pfl->cfi_table[0x1B] =3D 0x27; + /* Vcc max */ + pfl->cfi_table[0x1C] =3D 0x36; + /* Vpp min (no Vpp pin) */ + pfl->cfi_table[0x1D] =3D 0x00; + /* Vpp max (no Vpp pin) */ + pfl->cfi_table[0x1E] =3D 0x00; + /* Timeout per single byte/word write (128 ms) */ + pfl->cfi_table[0x1F] =3D 0x07; + /* Timeout for min size buffer write (NA) */ + pfl->cfi_table[0x20] =3D 0x00; + /* Typical timeout for block erase (512 ms) */ + pfl->cfi_table[0x21] =3D 0x09; + /* Typical timeout for full chip erase (4096 ms) */ + pfl->cfi_table[0x22] =3D 0x0C; + /* Reserved */ + pfl->cfi_table[0x23] =3D 0x01; + /* Max timeout for buffer write (NA) */ + pfl->cfi_table[0x24] =3D 0x00; + /* Max timeout for block erase */ + pfl->cfi_table[0x25] =3D 0x0A; + /* Max timeout for chip erase */ + pfl->cfi_table[0x26] =3D 0x0D; + /* Device size */ + pfl->cfi_table[0x27] =3D ctz32(pfl->chip_len); + /* Flash device interface (8 & 16 bits) */ + pfl->cfi_table[0x28] =3D 0x02; + pfl->cfi_table[0x29] =3D 0x00; + /* Max number of bytes in multi-bytes write */ + /* + * XXX: disable buffered write as it's not supported + * pfl->cfi_table[0x2A] =3D 0x05; + */ + pfl->cfi_table[0x2A] =3D 0x00; + pfl->cfi_table[0x2B] =3D 0x00; + /* Number of erase block regions */ + pfl->cfi_table[0x2c] =3D nb_regions; + /* Erase block regions */ + for (int i =3D 0; i < nb_regions; ++i) { + uint32_t sector_len_per_device =3D pfl->sector_len[i]; + pfl->cfi_table[0x2d + 4 * i] =3D pfl->nb_blocs[i] - 1; + pfl->cfi_table[0x2e + 4 * i] =3D (pfl->nb_blocs[i] - 1) >> 8; + pfl->cfi_table[0x2f + 4 * i] =3D sector_len_per_device >> 8; + pfl->cfi_table[0x30 + 4 * i] =3D sector_len_per_device >> 16; + } + assert(0x2c + 4 * nb_regions < pri_ofs); + + /* Extended */ + pfl->cfi_table[0x00 + pri_ofs] =3D 'P'; + pfl->cfi_table[0x01 + pri_ofs] =3D 'R'; + pfl->cfi_table[0x02 + pri_ofs] =3D 'I'; + + /* Extended version 1.0 */ + pfl->cfi_table[0x03 + pri_ofs] =3D '1'; + pfl->cfi_table[0x04 + pri_ofs] =3D '0'; + + /* Address sensitive unlock required. */ + pfl->cfi_table[0x05 + pri_ofs] =3D 0x00; + /* Erase suspend to read/write. */ + pfl->cfi_table[0x06 + pri_ofs] =3D 0x02; + /* Sector protect not supported. */ + pfl->cfi_table[0x07 + pri_ofs] =3D 0x00; + /* Temporary sector unprotect not supported. */ + pfl->cfi_table[0x08 + pri_ofs] =3D 0x00; + + /* Sector protect/unprotect scheme. */ + pfl->cfi_table[0x09 + pri_ofs] =3D 0x00; + + /* Simultaneous operation not supported. */ + pfl->cfi_table[0x0a + pri_ofs] =3D 0x00; + /* Burst mode not supported. */ + pfl->cfi_table[0x0b + pri_ofs] =3D 0x00; + /* Page mode not supported. */ + pfl->cfi_table[0x0c + pri_ofs] =3D 0x00; + assert(0x0c + pri_ofs < ARRAY_SIZE(pfl->cfi_table)); +} + static void pflash_cfi02_realize(DeviceState *dev, Error **errp) { ERRP_GUARD(); @@ -837,100 +935,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Er= ror **errp) pfl->cmd =3D 0; pfl->status =3D 0; =20 - /* Hardcoded CFI table (mostly from SG29 Spansion flash) */ - const uint16_t pri_ofs =3D 0x40; - /* Standard "QRY" string */ - pfl->cfi_table[0x10] =3D 'Q'; - pfl->cfi_table[0x11] =3D 'R'; - pfl->cfi_table[0x12] =3D 'Y'; - /* Command set (AMD/Fujitsu) */ - pfl->cfi_table[0x13] =3D 0x02; - pfl->cfi_table[0x14] =3D 0x00; - /* Primary extended table address */ - pfl->cfi_table[0x15] =3D pri_ofs; - pfl->cfi_table[0x16] =3D pri_ofs >> 8; - /* Alternate command set (none) */ - pfl->cfi_table[0x17] =3D 0x00; - pfl->cfi_table[0x18] =3D 0x00; - /* Alternate extended table (none) */ - pfl->cfi_table[0x19] =3D 0x00; - pfl->cfi_table[0x1A] =3D 0x00; - /* Vcc min */ - pfl->cfi_table[0x1B] =3D 0x27; - /* Vcc max */ - pfl->cfi_table[0x1C] =3D 0x36; - /* Vpp min (no Vpp pin) */ - pfl->cfi_table[0x1D] =3D 0x00; - /* Vpp max (no Vpp pin) */ - pfl->cfi_table[0x1E] =3D 0x00; - /* Timeout per single byte/word write (128 ms) */ - pfl->cfi_table[0x1F] =3D 0x07; - /* Timeout for min size buffer write (NA) */ - pfl->cfi_table[0x20] =3D 0x00; - /* Typical timeout for block erase (512 ms) */ - pfl->cfi_table[0x21] =3D 0x09; - /* Typical timeout for full chip erase (4096 ms) */ - pfl->cfi_table[0x22] =3D 0x0C; - /* Reserved */ - pfl->cfi_table[0x23] =3D 0x01; - /* Max timeout for buffer write (NA) */ - pfl->cfi_table[0x24] =3D 0x00; - /* Max timeout for block erase */ - pfl->cfi_table[0x25] =3D 0x0A; - /* Max timeout for chip erase */ - pfl->cfi_table[0x26] =3D 0x0D; - /* Device size */ - pfl->cfi_table[0x27] =3D ctz32(pfl->chip_len); - /* Flash device interface (8 & 16 bits) */ - pfl->cfi_table[0x28] =3D 0x02; - pfl->cfi_table[0x29] =3D 0x00; - /* Max number of bytes in multi-bytes write */ - /* - * XXX: disable buffered write as it's not supported - * pfl->cfi_table[0x2A] =3D 0x05; - */ - pfl->cfi_table[0x2A] =3D 0x00; - pfl->cfi_table[0x2B] =3D 0x00; - /* Number of erase block regions */ - pfl->cfi_table[0x2c] =3D nb_regions; - /* Erase block regions */ - for (int i =3D 0; i < nb_regions; ++i) { - uint32_t sector_len_per_device =3D pfl->sector_len[i]; - pfl->cfi_table[0x2d + 4 * i] =3D pfl->nb_blocs[i] - 1; - pfl->cfi_table[0x2e + 4 * i] =3D (pfl->nb_blocs[i] - 1) >> 8; - pfl->cfi_table[0x2f + 4 * i] =3D sector_len_per_device >> 8; - pfl->cfi_table[0x30 + 4 * i] =3D sector_len_per_device >> 16; - } - assert(0x2c + 4 * nb_regions < pri_ofs); - - /* Extended */ - pfl->cfi_table[0x00 + pri_ofs] =3D 'P'; - pfl->cfi_table[0x01 + pri_ofs] =3D 'R'; - pfl->cfi_table[0x02 + pri_ofs] =3D 'I'; - - /* Extended version 1.0 */ - pfl->cfi_table[0x03 + pri_ofs] =3D '1'; - pfl->cfi_table[0x04 + pri_ofs] =3D '0'; - - /* Address sensitive unlock required. */ - pfl->cfi_table[0x05 + pri_ofs] =3D 0x00; - /* Erase suspend to read/write. */ - pfl->cfi_table[0x06 + pri_ofs] =3D 0x02; - /* Sector protect not supported. */ - pfl->cfi_table[0x07 + pri_ofs] =3D 0x00; - /* Temporary sector unprotect not supported. */ - pfl->cfi_table[0x08 + pri_ofs] =3D 0x00; - - /* Sector protect/unprotect scheme. */ - pfl->cfi_table[0x09 + pri_ofs] =3D 0x00; - - /* Simultaneous operation not supported. */ - pfl->cfi_table[0x0a + pri_ofs] =3D 0x00; - /* Burst mode not supported. */ - pfl->cfi_table[0x0b + pri_ofs] =3D 0x00; - /* Page mode not supported. */ - pfl->cfi_table[0x0c + pri_ofs] =3D 0x00; - assert(0x0c + pri_ofs < ARRAY_SIZE(pfl->cfi_table)); + pflash_cfi02_fill_cfi_table(pfl, nb_regions); } =20 static Property pflash_cfi02_properties[] =3D { --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615333858; cv=none; d=zohomail.com; s=zohoarc; b=gGCfv9gaHbZG88mz8Avdqznocejx7Tx5M+NK78IhdQOsJL+fsWasabc3ifJAzxPu7lGNyd3sBonaV0aN+LNHf8YzJRM3tfPO9bdvY8/w6OAZJWc5fGR7wGZKgbIi5h1UjW1w1/LIWwPREP4YnVAmGF5qyd8QeJ5470c/5Q0Tp4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333858; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=m6hiB0Ry4U+40peR1g9DMU6zeYRKlNPh+KKp/RGq7bo=; b=aIyIfmmJ240lYThPm9kdnQE1LvqyYOWteLyXfLRpDPJN9Wyrp98OPuCfBHNbcJb1Pl0d3pS11j5WC3/z+4QNrRaYtOyVWk0JAZOHyK+FKMzwePhb+BqKQQG85q/TtNBGbloUtad4++fYRCCp5AavC8xvCmwMsuhraSy440jNhPM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615333858843210.98903784947288; Tue, 9 Mar 2021 15:50:58 -0800 (PST) Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-kNrSXGi7Pjy_K0jwSlCa9Q-1; Tue, 09 Mar 2021 18:50:53 -0500 Received: by mail-ed1-f70.google.com with SMTP id w16so7547396edc.22 for ; Tue, 09 Mar 2021 15:50:53 -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 qo25sm1705379ejb.93.2021.03.09.15.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333857; 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=m6hiB0Ry4U+40peR1g9DMU6zeYRKlNPh+KKp/RGq7bo=; b=MJ2dKC35E//uYsDpT3hI2IAKKkJ7QaQm6j8e5S2STAjIABsizaa8EsbKFaknjG9GiT14Nx Qum6choXPZoLlzk6CN6mfH3Sk7+/+u3hB5OIKWWam4zpiin6TLVAJ2CRwkE4PJIrQZetPz LjWbyzp4+gui1M9YnyG8aNXhENktk0w= X-MC-Unique: kNrSXGi7Pjy_K0jwSlCa9Q-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=m6hiB0Ry4U+40peR1g9DMU6zeYRKlNPh+KKp/RGq7bo=; b=p7T9oQAKNR0TFuR35i5qgzV9JNqCRL6z70AkMQmNcApvcWXFm08A00QohidOqciTNO d8uz1uHTvqo0yi5+CBg/QlpMLqnng3I3UGC0R/FWHR2t+xBCTek7Zt2PfZ+uDck3rJzL w15yP/AqLIeNyrRIONXyFfk7BRdxbD6gyOFG/nakHV7XX3oikMvZwmKRdTrtfNRHHWWd Gl7hQFgao9+ln0klbW+0aF1vW3IERlkR3wibFyDDXBoLutY5E+6INlJNpjo5U1T5lGD0 fOgOdZsyExMu0CTi+LhAlqK5VDSgFEXsbcz/B2E9SxQ7aHJq6ckSc5thPko0NDIgSjWq R0tg== X-Gm-Message-State: AOAM533SaYVckkgirWsQV8RIVE9Y9wA5uky8nGW5Er5iBerJFAtfinOb vrpZCL3Lz3wpmPwlyuBZnqyS7SVajlSGCJ4oJBaM5VHWa9KDVh8dgAXpKdVo8MQbkYPDoKAJUKn 8lJwWbNs+Ctwv5Q== X-Received: by 2002:a17:906:4d44:: with SMTP id b4mr585779ejv.338.1615333852546; Tue, 09 Mar 2021 15:50:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhpJFHaX+Nz2j5x4uC5whRpvKqGT7q4Sw6OBlrjk3szSME4l5+uOFdZeahZvrYAKy1C10Rkg== X-Received: by 2002:a17:906:4d44:: with SMTP id b4mr585766ejv.338.1615333852397; Tue, 09 Mar 2021 15:50:52 -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 4/9] hw/block/pflash_cfi02: Set rom_mode to true in pflash_setup_mappings() Date: Wed, 10 Mar 2021 00:50:23 +0100 Message-Id: <20210309235028.912078-5-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) There is only one call to pflash_setup_mappings(). Convert 'rom_mode' to boolean and set it to true directly within pflash_setup_mappings(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/block/pflash_cfi02.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 845f50ed99b..5f949b4c792 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -108,7 +108,7 @@ struct PFlashCFI02 { MemoryRegion mem; MemoryRegion *mem_mappings; /* array; one per mapping */ MemoryRegion orig_mem; - int rom_mode; + bool rom_mode; int read_counter; /* used for lazy switch-back to rom mode */ int sectors_to_erase; uint64_t erase_time_remaining; @@ -181,6 +181,7 @@ static void pflash_setup_mappings(PFlashCFI02 *pfl) "pflash-alias", &pfl->orig_mem, 0, size); memory_region_add_subregion(&pfl->mem, i * size, &pfl->mem_mapping= s[i]); } + pfl->rom_mode =3D true; } =20 static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode) @@ -927,7 +928,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Erro= r **errp) pfl->sector_erase_map =3D bitmap_new(pfl->total_sectors); =20 pflash_setup_mappings(pfl); - pfl->rom_mode =3D 1; sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); =20 timer_init_ns(&pfl->timer, QEMU_CLOCK_VIRTUAL, pflash_timer, pfl); --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1615333861; cv=none; d=zohomail.com; s=zohoarc; b=EzruHV3by4ORjaMt6IPeToJvUcHdRAJDwemQC0X9PbftSoKJFewnoUlO2fuXB6Zp59cyVYhS2rmdU6JDUOJZYvb2cO8A8PD22mtaeaubixxvPQtkq7y2/84CguXM+FbiroA3eFxe+1GlfwK6lEQmjDGwn+MyfjBH3v90/e/Xchk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333861; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=q/qFh6Xk9X0lvLpKMyB8xS7GnadqS9EROoiuzpTd3qo=; b=UxzXATfLKbmeTAVP5wCkd6KtdagJq/Oa+sFN5Yz/8Eh1FolFQ9MkNqJvfatEbU4faFdxg3jok/piWNUx4Lo6/8dM9LuPImE2WCBEh6Tq27hIqzLzuVOajDtJIW5KmG5W2xtIABOMBFoVWr3VQUJ44AdrK76YklWCX8MIGRzGaSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1615333861350425.74677410099014; Tue, 9 Mar 2021 15:51:01 -0800 (PST) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-JkT1rYDlPyS_yR2xCq_u2Q-1; Tue, 09 Mar 2021 18:50:59 -0500 Received: by mail-ej1-f69.google.com with SMTP id gn30so6347909ejc.3 for ; Tue, 09 Mar 2021 15:50:58 -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 gt37sm1632919ejc.12.2021.03.09.15.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:50:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333860; 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=q/qFh6Xk9X0lvLpKMyB8xS7GnadqS9EROoiuzpTd3qo=; b=AGNn0T1ChXqHkqQaOPxYFJvMAlPNmXP4k97fWkrgosBmvFKBI/TLjqbS+w6jXVGbTmv1bO iE6xibhMwB9utbY6gVpG4Fb03XzfP80avpP5Litrt+f2lDm2iKN7oj7yM4WWythN/vS9Eb 5BsPn/CteTsSRoXzHb1aRehHgvE7kpE= X-MC-Unique: JkT1rYDlPyS_yR2xCq_u2Q-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=q/qFh6Xk9X0lvLpKMyB8xS7GnadqS9EROoiuzpTd3qo=; b=UrYQznFj4qyyoEPOlwjXZ45ZHGV5EgcDVn3ae5DWkRQ/heXNgCWr63cmXvR5s5CHLk PqFDw1Tf3/qTVKKkfgo+Tq/z9iOtJAw/bBwRMP3ZFdAlpn3hjC8PJabTRh8pMtkZfKXC JRYvZzCOlY7DABbMaII5Z+EecF+3rMunPFuj08CdxReK6jX/1xox+F4I3JooK+x2/V7x dO9EVfkRMJ1tCQ6uksNQVdXtU6PMmuHmhBSkNu+208QcR5P6dvAw94TRzEGgcsJh1Fsm eHQuaZQtf3Q3WjE4lLA8msxOUs4e2UvjHHy5KdBnRyhK6lhaiD92N7CVlamYr6F6wVFY HdvQ== X-Gm-Message-State: AOAM533jADYEl7UL+RLyP8mZXqMxLLO0pLpLHNq5sdgCMxIpacI1X2dk y/Ar3MGCeowZfwAIODV/W3H+T4r1sWfxo6ZY2HDAj+jbZNFSfbLAZHjR20R1AeR6X9tKD34XRhN N/VC+iMwJ1LIORQ== X-Received: by 2002:a17:906:add7:: with SMTP id lb23mr547336ejb.273.1615333857861; Tue, 09 Mar 2021 15:50:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbxQqKkXc9vnwzMUQF/ITk6sOkSsFWeMVQ11Gg30iVDpo58qrs9xT1vJQQJ0oBBG3z4C7PSg== X-Received: by 2002:a17:906:add7:: with SMTP id lb23mr547324ejb.273.1615333857719; Tue, 09 Mar 2021 15:50:57 -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 5/9] hw/block/pflash_cfi02: Open-code pflash_register_memory(rom=false) Date: Wed, 10 Mar 2021 00:50:24 +0100 Message-Id: <20210309235028.912078-6-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) There is only one call to pflash_register_memory() with rom_mode =3D=3D false. As we want to modify pflash_register_memory() in the next patch, open-code this trivial function in place for the 'rom_mode =3D=3D false' case. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/block/pflash_cfi02.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 5f949b4c792..4efbae2f0c9 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -467,8 +467,10 @@ static void pflash_write(void *opaque, hwaddr offset, = uint64_t value, switch (pfl->wcycle) { case 0: /* Set the device in I/O access mode if required */ - if (pfl->rom_mode) - pflash_register_memory(pfl, 0); + if (pfl->rom_mode) { + pfl->rom_mode =3D false; + memory_region_rom_device_set_romd(&pfl->orig_mem, false); + } pfl->read_counter =3D 0; /* We're in read mode */ check_unlock0: --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615333866; cv=none; d=zohomail.com; s=zohoarc; b=LuUdiNJhGxxQOx41T1bjOqQYl4yzcmNgA5vetv7pwQYsbfIjh0grrU8uOq5vze5hY+8yvd1O5boSMhE9O9m+SUk5qiN081bXT8M8P/DXAWohjFO8hjvkeOfksdn+UihoTQzzPhOBbGxcxGa3SxVgA9a1kPyCui4EWGH13R4vFX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333866; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=rGRRsOLRCmAO6MPW4R+6g0l5+eOKsAVF/J3+u7++AVw=; b=ZFQcILWkTdKz4jh0mBx6nyJPE8/dTIBv7XHcboQyMkilUc89+92elTNa/IAUpNefAu0PU5KITKxJK8GbdQxqyD6HDEgMB5KIqQ0k8+3SKZYlIiP8HVfyj2PzM2avAvKxrBFJH+FtKV+SqmmufIXN7SVCLAaLlzgOoxicJ06M04A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615333866747482.43170616386374; Tue, 9 Mar 2021 15:51:06 -0800 (PST) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-492-2kdX3JcJO_arX7-4LqsDew-1; Tue, 09 Mar 2021 18:51:04 -0500 Received: by mail-ej1-f70.google.com with SMTP id h14so6430332ejg.7 for ; Tue, 09 Mar 2021 15:51:04 -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 j1sm9011964ejt.18.2021.03.09.15.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333865; 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=rGRRsOLRCmAO6MPW4R+6g0l5+eOKsAVF/J3+u7++AVw=; b=Rh16leZeUoL2V/RsNvW9tc0sJtzmInt8lOMllicdPOiurVTkQv0iv5BWud5Lr3QGZbAglm nW3lyEyoffZ5w0Ro9B7D7J2cqmMJXrcPdpFxCDZ5vbNNERVoE5jpQL4NAXmufripS1KNO7 nuqor1n0KaWp+ilATJydM1sJdmqPUy4= X-MC-Unique: 2kdX3JcJO_arX7-4LqsDew-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=rGRRsOLRCmAO6MPW4R+6g0l5+eOKsAVF/J3+u7++AVw=; b=hL7UBGMXWqslF9ggmc5kcSLKaSmmsNW80i/VtL3ZbH/3s1SMI07Dppdbh2Eh6TURlc 8IRB908PXN64rXYz/vXqCLPCnRuOmPDqHxthO9r3hSZIwuCZ/GSf0aPp2RPr++nQHE3H OK/zA93MRr9pFI9iEJtzoMxiDLZLISqaNCRN5ELEaHO/1cnhEd6f8TuFdHoxJOkcHdaP ytM0gaCv62yknIwKvxpnzqJHUCxOecZUmRaZPNqSUaGX+KT+oBQhtOTG95NqUXsEcGln ly0xkBT7e2jZtDrEFDNOTmq/P1pdIIiCvuwzil2yGSwqvpuxqUjIdaoPhNqXroaIppfE FBcQ== X-Gm-Message-State: AOAM530poLUMYLFKBKWRpOTitEQjnxfJIn74SvymG3l7ssE2FQ3Aqr23 wWPmCv+delORe3xumuTyjB/86W6gBSVtVWxmhK7bmb6D72ncoXyALenoJA3zu/DAr0pYTNL42YI grm2BlTTozTLtkA== X-Received: by 2002:a05:6402:48c:: with SMTP id k12mr158734edv.237.1615333863031; Tue, 09 Mar 2021 15:51:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJylulpEb+WQWYL+ljXX3rf1bXPR7tOqr8HukAvLjRCBMcJHLdOxNl6LuIhp3AggFgD16hyFiQ== X-Received: by 2002:a05:6402:48c:: with SMTP id k12mr158724edv.237.1615333862826; Tue, 09 Mar 2021 15:51:02 -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 6/9] hw/block/pflash_cfi02: Rename register_memory(true) as mode_read_array Date: Wed, 10 Mar 2021 00:50:25 +0100 Message-Id: <20210309235028.912078-7-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: - When the timer expires and not in bypass mode - On a read access (on invalid command). - When the device is initialized. Here the ROMD mode is hidden by the memory_region_init_rom_device() call. pflash_register_memory(rom_mode=3Dtrue) already sets the ROM device in "read array" mode (from I/O device to ROM one). Explicit that by renaming the function as pflash_mode_read_array(), adding a trace event and resetting wcycle. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng Reviewed-by: David Edmondson --- hw/block/pflash_cfi02.c | 18 +++++++++--------- hw/block/trace-events | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 4efbae2f0c9..2ba77a0171b 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -184,10 +184,13 @@ static void pflash_setup_mappings(PFlashCFI02 *pfl) pfl->rom_mode =3D true; } =20 -static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode) +static void pflash_mode_read_array(PFlashCFI02 *pfl) { - memory_region_rom_device_set_romd(&pfl->orig_mem, rom_mode); - pfl->rom_mode =3D rom_mode; + trace_pflash_mode_read_array(); + pfl->cmd =3D 0x00; + pfl->wcycle =3D 0; + pfl->rom_mode =3D true; + memory_region_rom_device_set_romd(&pfl->orig_mem, true); } =20 static size_t pflash_regions_count(PFlashCFI02 *pfl) @@ -249,11 +252,10 @@ static void pflash_timer(void *opaque) toggle_dq7(pfl); if (pfl->bypass) { pfl->wcycle =3D 2; + pfl->cmd =3D 0; } else { - pflash_register_memory(pfl, 1); - pfl->wcycle =3D 0; + pflash_mode_read_array(pfl); } - pfl->cmd =3D 0; } =20 /* @@ -315,7 +317,7 @@ static uint64_t pflash_read(void *opaque, hwaddr offset= , unsigned int width) /* Lazy reset to ROMD mode after a certain amount of read accesses */ if (!pfl->rom_mode && pfl->wcycle =3D=3D 0 && ++pfl->read_counter > PFLASH_LAZY_ROMD_THRESHOLD) { - pflash_register_memory(pfl, 1); + pflash_mode_read_array(pfl); } offset &=3D pfl->chip_len - 1; boff =3D offset & 0xFF; @@ -933,8 +935,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Erro= r **errp) sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); =20 timer_init_ns(&pfl->timer, QEMU_CLOCK_VIRTUAL, pflash_timer, pfl); - pfl->wcycle =3D 0; - pfl->cmd =3D 0; pfl->status =3D 0; =20 pflash_cfi02_fill_cfi_table(pfl, nb_regions); diff --git a/hw/block/trace-events b/hw/block/trace-events index d32475c3989..f16d6e90cfd 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_cfi01.c # pflash_cfi02.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, unsigned size, uint32_t value, uint8_t cmd= , uint8_t wcycle) "offset:0x%04"PRIx64" size:%u value:0x%04x cmd:0x%02x wcy= cle:%u" pflash_io_write(uint64_t offset, unsigned size, uint32_t value, uint8_t wc= ycle) "offset:0x%04"PRIx64" size:%u value:0x%04x wcycle:%u" --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615333874; cv=none; d=zohomail.com; s=zohoarc; b=MsEayo/ZWimovmxxbzgXbwKKIS2GfS+/+5rBsssbtPb0TwdPBNQ+Sao5zHzGh6y5Kyar0xR+cU4jm5d5VAoXghVUaPbHIzUkOF5V6TJYD0uavT2djPXKBsgUe2erVlH0D2yAb5s2RgXKsMO8Xh92dlhPVsm3E5B2RYUBL0mvXSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=li90BbxJJcTIEYAnFQu9nBy4MfdtLcbjqZ4YJMARg+0=; b=CMU2ZbOwZXIJXfoKOx9gWVemWuo3RARsPxuieubDZmoIPWp58V/UBa3XxuiRrp0ThgT02VT+DGUoBUPg9mIuZptxyy2SED0e4dwXJqF3Z5KAVZWOOtyBmLc1MmP9SKNh38NDiDl+J8cnRYU2VcL790LWlTml4aSg7aNTiXhyd9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615333874219954.1016024485564; Tue, 9 Mar 2021 15:51:14 -0800 (PST) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-5a6DwaE7OV2HOtv-Zf-Q5Q-1; Tue, 09 Mar 2021 18:51:09 -0500 Received: by mail-ej1-f71.google.com with SMTP id li22so1886641ejb.18 for ; Tue, 09 Mar 2021 15:51:09 -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 v8sm265800edx.38.2021.03.09.15.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333873; 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=li90BbxJJcTIEYAnFQu9nBy4MfdtLcbjqZ4YJMARg+0=; b=dHZ7ACy0NQDhfmGmWWG21znqImunDmA+gzrrA4Ckrd8UcA7Uz94FtYoVf8YNcaJwMvM3HO ngNRdofXfZpseJW8AP0EVajZt29PXqw9rsxwYApGVZnaXrFDZgV+XEmanCJsIcSmCxDw+x 36m2a98u5f1EsZH8V/pPMh6nWxe2Zik= X-MC-Unique: 5a6DwaE7OV2HOtv-Zf-Q5Q-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=li90BbxJJcTIEYAnFQu9nBy4MfdtLcbjqZ4YJMARg+0=; b=mNL/SF+eRRC5ozj07jZdpB9Afw/BQr/eSsWNWsMM5BhAy+y5veE9//sIWmULTOpeq4 MvwsefkWsKwlUWGTRzkW4ytqCW6OKqf3bSLmo3ipVLYfCGPqnrrTBFuinS6TpqE8H5YO gp22adl8xOlWW5AA+G5YkWeOqMfigYFR1L/ajPGwCWvp9l85dBTxIctlLOmKCk/UG0QV Nr2Lq3BHVrg1NwkNXWL/oFQCE/RWP8rU+4WBKbXIeV3X/9GPahU/Xry5OXxQSYNAa/Ag yRL0Jux2czCM6Juxp2mDl6l6xg+vmmHPXZi75WDzUjSytmLfsSp0lmrtbXVOzveG9Qo4 u3tw== X-Gm-Message-State: AOAM533iiH6YPcOeh68D4wj3IT/jpFVzphCABZMkq1+8DcbqO5IeAncd W5sHGynP9BdvlycK8cvZktBGxx/p0KNKZynKxkN52dxwaTA6lrxb2lWnzDX+6dmC0shTbSzskJy LwFFJEXsIKurd5w== X-Received: by 2002:a17:906:565a:: with SMTP id v26mr587643ejr.516.1615333868304; Tue, 09 Mar 2021 15:51:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+IyyQQ6BFlk+Lfg5FF1ErQB4WC2WQAbbYLXUgf/CvqTXs0y732CHx0GYeRUqy/0402RiVCw== X-Received: by 2002:a17:906:565a:: with SMTP id v26mr587634ejr.516.1615333868203; Tue, 09 Mar 2021 15:51:08 -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 7/9] hw/block/pflash_cfi02: Factor out DeviceReset method Date: Wed, 10 Mar 2021 00:50:26 +0100 Message-Id: <20210309235028.912078-8-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) There is multiple places doing a device reset. Factor that out in a common method which matches the DeviceReset prototype, so we can also remove the reset code from the DeviceRealize() handler. Explicit the device is set in "read array" mode on reset. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Edmondson --- hw/block/pflash_cfi02.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 2ba77a0171b..484b056b898 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -193,6 +193,14 @@ static void pflash_mode_read_array(PFlashCFI02 *pfl) memory_region_rom_device_set_romd(&pfl->orig_mem, true); } =20 +static void pflash_cfi02_reset(DeviceState *dev) +{ + PFlashCFI02 *pfl =3D PFLASH_CFI02(dev); + + trace_pflash_reset(); + pflash_mode_read_array(pfl); +} + static size_t pflash_regions_count(PFlashCFI02 *pfl) { return pfl->cfi_table[0x2c]; @@ -330,8 +338,7 @@ static uint64_t pflash_read(void *opaque, hwaddr offset= , unsigned int width) 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; - pfl->cmd =3D 0; + pflash_cfi02_reset(DEVICE(pfl)); /* fall through to the read code */ case 0x80: /* Erase (unlock) */ /* We accept reads during second unlock sequence... */ @@ -710,10 +717,8 @@ static void pflash_write(void *opaque, hwaddr offset, = uint64_t value, =20 /* Reset flash */ reset_flash: - trace_pflash_reset(); pfl->bypass =3D 0; - pfl->wcycle =3D 0; - pfl->cmd =3D 0; + pflash_cfi02_reset(DEVICE(pfl)); return; =20 do_bypass: @@ -977,6 +982,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass,= void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); =20 dc->realize =3D pflash_cfi02_realize; + dc->reset =3D pflash_cfi02_reset; dc->unrealize =3D pflash_cfi02_unrealize; device_class_set_props(dc, pflash_cfi02_properties); set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); --=20 2.26.2 From nobody Wed Nov 19 07:03:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1615333877; cv=none; d=zohomail.com; s=zohoarc; b=fHOixfH5g7c8ZB2Q4bCwJh6wjqJpuFq4+SEn+6VLBfngAc7pa5FH87X6ZG3k9/HSqcKud43E1wrY7Kvr1CH/orUF5Jwe9t8BE9Tck5yEDt2BkkEsXt3gmKke0WzDtSiy1xx52zckcr54Iw4x8TI2/1ZLhrhAekGTmRhGWF7HA/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615333877; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=1sffFlZ9/SNFgtZee/CEsk5iX0bBYiTE0XhzbPNOxhU=; b=Kq1ts3LgSYmXtPOrVbUxoQxnywVMoX1cLuJ1HA4nvu0aefcSA8EKLAsgntWtuiaeZHb5iPA7/zZojBLrqlWJUkY9m4/FC0O+9t0AXXnYkzhC7XHpXm0GPObuokjwE/xqGC/QfTI6T/JivXZElN57vFYx+3Z6JmGhd1iRmRD4JVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 161533387752164.51440827772035; Tue, 9 Mar 2021 15:51:17 -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-235-HIFwOrTJPsGZag61PEKvYg-1; Tue, 09 Mar 2021 18:51:14 -0500 Received: by mail-ed1-f71.google.com with SMTP id a2so7544155edx.0 for ; Tue, 09 Mar 2021 15:51:14 -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 h15sm7172603edb.74.2021.03.09.15.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:51:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615333876; 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=1sffFlZ9/SNFgtZee/CEsk5iX0bBYiTE0XhzbPNOxhU=; b=Vhk5djBkG89APOeRZ1+UYmcbOrUEXKGhPJCykRpNwadADxRQWh6BUb7rnBW2h+UJD5wW4/ f6ApY4SasbgV8uogBLd8lLUyszcD5DD/SnWDOoEKt0vkpcz4ep7ypBRUGqVTpXdsVbENHR whgQIvH7Se9ou2AjxeGqya6GUVQNHwY= X-MC-Unique: HIFwOrTJPsGZag61PEKvYg-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=1sffFlZ9/SNFgtZee/CEsk5iX0bBYiTE0XhzbPNOxhU=; b=It4H6ddW8cWDdTE8NJvuq1mAaZRcjIe0AFUiZd/Mt25HHDybYv9VtxQWoMDuYuzKXy OQ4zUJgfKt03z+Nk9GGBrCrs1Z3NbrIvERW9/rW8qV17HCKPZLN0Iyr0E+ruTA/aPat6 M32dzZoMAY28Pc9vvV7cT1P3/PbbxxpajnV2CNbYrK2VA8Ngo4gNoReRJSgVXAbldwMF LwYejYYnwdu3Oqt2Anjf4LkQibSHVQAZ1NLBwEa3+/F5+xRs3JSxjPpIRLt7SGxl6tL3 Z0wHhodOSq9kci5C4HjbUj5LX1WAcG4rkY1qMK3Lnz5wzso3cNzSTgdT2Kvsa+tOJaaY wC+A== X-Gm-Message-State: AOAM531tFgGqoTZasKso1sa4QIds5X8RGZWrVJ+wrw7vgEmTINYg94jh ANYghUuNy/G1I8ZZzL/FHx1t+y1c9LykeUIKk81tSJn07K0AquMBAgRLHJj2H/YlHnohWiOvJB0 9p19fKvkNNlnm2w== X-Received: by 2002:a50:9d0b:: with SMTP id v11mr190502ede.308.1615333873705; Tue, 09 Mar 2021 15:51:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTEWns1FXeYiJTJdgIWM3J+uyhLArzMKGqWPuyHy+KUK3Q1lRRZYqdsO2EftnANh7RlSSrLg== X-Received: by 2002:a50:9d0b:: with SMTP id v11mr190485ede.308.1615333873519; Tue, 09 Mar 2021 15:51:13 -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 8/9] hw/block/pflash_cfi01: Clarify trace events Date: Wed, 10 Mar 2021 00:50:27 +0100 Message-Id: <20210309235028.912078-9-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) Use the 'mode_read_array' event when we set the device in such mode, and use the 'reset' event in DeviceReset handler. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng Reviewed-by: David Edmondson --- hw/block/pflash_cfi01.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 03472ea5b64..2618e00926d 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -663,7 +663,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offse= t, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); =20 mode_read_array: - trace_pflash_reset(); + 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) = */ @@ -886,6 +886,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). --=20 2.26.2 From nobody Wed Nov 19 07:03:53 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