From nobody Wed Nov 19 08:25:43 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=1615395953; cv=none; d=zohomail.com; s=zohoarc; b=Xn6wrTTIuRadgbstSHx0cNCoDbdcmOrmb7Glhxwoj5Y6q5tRXvH9gq4RIt0pNesjpjpFA2lb9APvEkZM+Can3ojwgYMcgzhpoE2JPiFxexQO51ewQzMhCd+3FffnJ256SYDBDlwIw7cCujaZpZ3XyM7SWZbHWePJVMzZg0ILC68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615395953; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0p2T4LOlo1WwNURg6exWZWmw0vfUpBnGF9RSkW5uJpI=; b=M+go94UadVcPqAEZ0VzQhE1DSlFMEX01nUs6h9eK7s8Dzl0Dr1JzWkAVM6xP+Gysv1JSXGPyAGkNtXnJ+tlj54dpmWuZbTkdBwy4oHrDSLR5FAQOYoL7eEYDAgEqqM9wcmL6Cjt4bpynHsu+7mbMKMhnyWWdefWTliJAGY3UNwU= 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 161539595314797.80237814449595; Wed, 10 Mar 2021 09:05:53 -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-297-JAHR_zyCMhqakIopZpCveg-1; Wed, 10 Mar 2021 12:05:49 -0500 Received: by mail-ej1-f71.google.com with SMTP id rl7so7485949ejb.16 for ; Wed, 10 Mar 2021 09:05:49 -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 r17sm2642145edm.89.2021.03.10.09.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 09:05:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615395950; 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=0p2T4LOlo1WwNURg6exWZWmw0vfUpBnGF9RSkW5uJpI=; b=YR2ZK102B2A+YXWmUODNEN4KXKRx7imnRsoADeH4UPqZbS4COolHNbadRR1eebx+N1o2Qy X2PMce8MjE6rWCdeSMsAKfde+yL8eqlviYDlGybrJv++zeuIJ16GhFuMLLLipeAccOIuaX fgVb03J550idy9U8E8fKXsQfu5LcwBg= X-MC-Unique: JAHR_zyCMhqakIopZpCveg-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=0p2T4LOlo1WwNURg6exWZWmw0vfUpBnGF9RSkW5uJpI=; b=ImEcu1qpSWm9JWKxWG0QovC1qIgJWqejU3Eze9bgUqrPB/VLmxpvEypm7KsmmjHYjY 4/JngT8s+9OjHLipmGpNSzPhkeMAHPyUUoPvn61a0xbKGTBeENOuRP+EmFGpCREWLnIn 3i6jKA7gb52Bd3ACUWV6v+V4RqVicNvV8oBwU7koJmbjuFez0/XB/JBR6iBLFok8QLRb ZMtmbcFntKs4uoF3Jm0KEfH5Io66Tr3K1B536C8MNSfpeeuyitVhcjLMogEthI+1iyAg 1tJC6oMI7jDNZK5EV9z9WqMIG+V1QasBVnYONMABQUeO5puXW/+2+ALkn1MJhyu8mbFf 6iow== X-Gm-Message-State: AOAM530BLQ4gX4qB7oFiHQSUt5PfCGqRzaHLp3qhTW7whPTL4RF7EWIX we0QosDIcYjnBIcxd8XgMiQ20/bdAeZFiH09PidaZZPnoyarCVs8VrzUBeUXP0du2HSNPhG1joM fsFwGGjAodVv9iA== X-Received: by 2002:a17:906:2504:: with SMTP id i4mr4733081ejb.115.1615395948208; Wed, 10 Mar 2021 09:05:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzL4BGaDaskaudXSodstxoWEbJ5WyVz6yHWXhY64YFw++K8wXpzcP/22nWHKUMz9pVrVyyLmw== X-Received: by 2002:a17:906:2504:: with SMTP id i4mr4732978ejb.115.1615395947286; Wed, 10 Mar 2021 09:05:47 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Max Reitz , David Edmondson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, Stephen Checkoway , Kevin Wolf , Bin Meng Subject: [PATCH v2 03/12] hw/block/pflash_cfi02: Extract pflash_cfi02_fill_cfi_table() Date: Wed, 10 Mar 2021 18:05:19 +0100 Message-Id: <20210310170528.1184868-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310170528.1184868-1-philmd@redhat.com> References: <20210310170528.1184868-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(). Reviewed-by: Bin Meng Reviewed-by: David Edmondson Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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