From nobody Wed Nov 19 08:22:19 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