From: Bin Meng <bin.meng@processmission.com>
To: QEMU <qemu-devel@nongnu.org>
Cc: Alistair Francis <alistair@alistair23.me>,
Hanna Reitz <hreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org
Subject: [PATCH 03/10] hw/block: m25p80: Fix dummy byte handling for Macronix flash
Date: Tue, 30 Jun 2026 21:57:22 +0800 [thread overview]
Message-ID: <20260630135729.466264-4-bin.meng@processmission.com> (raw)
In-Reply-To: <20260630135729.466264-1-bin.meng@processmission.com>
Macronix flashes expose DC[1:0] bits in the volatile configuration
register [1]. These bits select the number of dummy clock cycles
used by the fast-read command families.
Convert the Macronix dummy-cycle settings through per-command-family
tables and round up the non-byte-aligned cases that the byte-oriented
SSI model cannot represent exactly.
[1] https://www.macronix.com/Lists/Datasheet/Attachments/8657/MX66L51235F,%203V,%20512Mb,%20v1.1.pdf
Fixes: cf6f1efe0b57 ("m25p80: Fast read commands family changes")
Signed-off-by: Bin Meng <bin.meng@processmission.com>
---
hw/block/m25p80.c | 66 +++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 28 deletions(-)
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index ba109cc055..745d13dff6 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -975,7 +975,6 @@ static uint8_t numonyx_extract_cfg_num_dummies(Flash *s)
{
uint8_t num_dummies;
uint8_t mode;
- assert(get_man(s) == MAN_NUMONYX);
mode = numonyx_mode(s);
num_dummies = extract32(s->volatile_cfg, 4, 4);
@@ -1029,6 +1028,41 @@ static uint8_t numonyx_extract_cfg_num_dummies(Flash *s)
return num_dummies / 8;
}
+static uint8_t macronix_extract_cfg_num_dummies(Flash *s, uint8_t bus_width)
+{
+ static const uint8_t dummy_cycles_fast[4] = { 8, 6, 8, 10 };
+ static const uint8_t dummy_cycles_dio[4] = { 4, 6, 8, 10 };
+ static const uint8_t dummy_cycles_qio[4] = { 6, 4, 8, 10 };
+ const uint8_t *dummy_cycles = dummy_cycles_fast;
+ uint8_t num_dummies;
+
+ assert(get_man(s) == MAN_MACRONIX);
+
+ switch (s->cmd_in_progress) {
+ case DIOR:
+ case DIOR4:
+ dummy_cycles = dummy_cycles_dio;
+ break;
+ case QIOR:
+ case QIOR4:
+ dummy_cycles = dummy_cycles_qio;
+ break;
+ default:
+ break;
+ }
+
+ num_dummies = dummy_cycles[extract32(s->volatile_cfg, 6, 2)];
+ num_dummies *= bus_width;
+
+ if (num_dummies % 8) {
+ qemu_log_mask(LOG_UNIMP,
+ "M25P80: the number of dummy bits is not multiple of 8");
+ num_dummies = ROUND_UP(num_dummies, 8);
+ }
+
+ return num_dummies / 8;
+}
+
static void decode_fast_read_cmd(Flash *s)
{
s->needed_bytes = get_addr_length(s);
@@ -1044,11 +1078,7 @@ static void decode_fast_read_cmd(Flash *s)
s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
break;
case MAN_MACRONIX:
- if (extract32(s->volatile_cfg, 6, 2) == 1) {
- s->needed_bytes += 6;
- } else {
- s->needed_bytes += 8;
- }
+ s->needed_bytes += macronix_extract_cfg_num_dummies(s, 1);
break;
case MAN_SPANSION:
s->needed_bytes += extract32(s->spansion_cr2v,
@@ -1096,17 +1126,7 @@ static void decode_dio_read_cmd(Flash *s)
s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
break;
case MAN_MACRONIX:
- switch (extract32(s->volatile_cfg, 6, 2)) {
- case 1:
- s->needed_bytes += 6;
- break;
- case 2:
- s->needed_bytes += 8;
- break;
- default:
- s->needed_bytes += 4;
- break;
- }
+ s->needed_bytes += macronix_extract_cfg_num_dummies(s, 2);
break;
case MAN_ISSI:
/*
@@ -1146,17 +1166,7 @@ static void decode_qio_read_cmd(Flash *s)
s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
break;
case MAN_MACRONIX:
- switch (extract32(s->volatile_cfg, 6, 2)) {
- case 1:
- s->needed_bytes += 4;
- break;
- case 2:
- s->needed_bytes += 8;
- break;
- default:
- s->needed_bytes += 6;
- break;
- }
+ s->needed_bytes += macronix_extract_cfg_num_dummies(s, 4);
break;
case MAN_ISSI:
/*
--
2.34.1
next prev parent reply other threads:[~2026-06-30 13:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 13:57 [PATCH 00/10] hw/{block,ssi}: Fix spi-nor flash dummy byte handling Bin Meng
2026-06-30 13:57 ` [PATCH 01/10] hw/block: m25p80: Fix dummy byte handling for Winbond flash Bin Meng
2026-07-06 7:48 ` Philippe Mathieu-Daudé
2026-07-06 16:54 ` Bin Meng
2026-06-30 13:57 ` [PATCH 02/10] hw/block: m25p80: Fix dummy byte handling for Numonyx/Micron flash Bin Meng
2026-06-30 13:57 ` Bin Meng [this message]
2026-07-06 7:52 ` [PATCH 03/10] hw/block: m25p80: Fix dummy byte handling for Macronix flash Philippe Mathieu-Daudé
2026-06-30 13:57 ` [PATCH 04/10] hw/block: m25p80: Fix dummy byte handling for Spansion flash Bin Meng
2026-06-30 13:57 ` [PATCH 05/10] hw/ssi: npcm7xx_fiu: Correct the dummy cycle emulation logic Bin Meng
2026-06-30 13:57 ` [PATCH 06/10] hw/ssi: xilinx_spips: Fix dummy phase handling Bin Meng
2026-07-06 8:10 ` Philippe Mathieu-Daudé
2026-07-06 17:27 ` Bin Meng
2026-06-30 13:57 ` [PATCH 07/10] hw/ssi: aspeed_smc: Fix direct-read dummy bytes Bin Meng
2026-06-30 14:45 ` Cédric Le Goater
2026-06-30 13:57 ` [PATCH 08/10] Revert "aspeed/smc: Fix number of dummy cycles for FAST_READ_4 command" Bin Meng
2026-06-30 14:45 ` Cédric Le Goater
2026-06-30 13:57 ` [PATCH 09/10] Revert "aspeed/smc: snoop SPI transfers to fake dummy cycles" Bin Meng
2026-06-30 14:46 ` Cédric Le Goater
2026-06-30 13:57 ` [PATCH 10/10] docs/devel: Document SSI dummy-cycle ownership Bin Meng
2026-07-06 8:13 ` Philippe Mathieu-Daudé
2026-06-30 14:45 ` [PATCH 00/10] hw/{block,ssi}: Fix spi-nor flash dummy byte handling Cédric Le Goater
2026-07-06 7:13 ` Cédric Le Goater
2026-07-06 8:19 ` Philippe Mathieu-Daudé
2026-07-06 8:40 ` Cédric Le Goater
2026-07-06 9:58 ` Philippe Mathieu-Daudé
2026-07-06 10:26 ` Cédric Le Goater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260630135729.466264-4-bin.meng@processmission.com \
--to=bin.meng@processmission.com \
--cc=alistair@alistair23.me \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.