From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Hanna Reitz" <hreitz@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v2 1/2] hw/block/pflash_cfi01: Use the LD/ST API in pflash_data_read/write
Date: Mon, 8 Jan 2024 13:53:41 +0100 [thread overview]
Message-ID: <20240108125342.48298-2-philmd@linaro.org> (raw)
In-Reply-To: <20240108125342.48298-1-philmd@linaro.org>
Similarly to commit c3d25271b2 ("hw/block/pflash_cfi02: Use the
ldst API in pflash_write") for CFI type 2, use the LD/ST API for
CFI type 1.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/block/pflash_cfi01.c | 63 ++++++-----------------------------------
1 file changed, 8 insertions(+), 55 deletions(-)
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 3e2dc08bd7..ce63ba43b6 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -225,34 +225,10 @@ static uint32_t pflash_data_read(PFlashCFI01 *pfl, hwaddr offset,
uint32_t ret;
p = pfl->storage;
- switch (width) {
- case 1:
- ret = p[offset];
- break;
- case 2:
- if (be) {
- ret = p[offset] << 8;
- ret |= p[offset + 1];
- } else {
- ret = p[offset];
- ret |= p[offset + 1] << 8;
- }
- break;
- case 4:
- if (be) {
- ret = p[offset] << 24;
- ret |= p[offset + 1] << 16;
- ret |= p[offset + 2] << 8;
- ret |= p[offset + 3];
- } else {
- ret = p[offset];
- ret |= p[offset + 1] << 8;
- ret |= p[offset + 2] << 16;
- ret |= p[offset + 3] << 24;
- }
- break;
- default:
- abort();
+ if (be) {
+ ret = ldn_be_p(p, width);
+ } else {
+ ret = ldn_le_p(p, width);
}
trace_pflash_data_read(pfl->name, offset, width, ret);
return ret;
@@ -406,34 +382,11 @@ static inline void pflash_data_write(PFlashCFI01 *pfl, hwaddr offset,
uint8_t *p = pfl->storage;
trace_pflash_data_write(pfl->name, offset, width, value, pfl->counter);
- switch (width) {
- case 1:
- p[offset] = value;
- break;
- case 2:
- if (be) {
- p[offset] = value >> 8;
- p[offset + 1] = value;
- } else {
- p[offset] = value;
- p[offset + 1] = value >> 8;
- }
- break;
- case 4:
- if (be) {
- p[offset] = value >> 24;
- p[offset + 1] = value >> 16;
- p[offset + 2] = value >> 8;
- p[offset + 3] = value;
- } else {
- p[offset] = value;
- p[offset + 1] = value >> 8;
- p[offset + 2] = value >> 16;
- p[offset + 3] = value >> 24;
- }
- break;
+ if (be) {
+ stn_be_p(p, width, value);
+ } else {
+ stn_le_p(p, width, value);
}
-
}
static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
--
2.41.0
next prev parent reply other threads:[~2024-01-08 12:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-08 12:53 [PATCH v2 0/2] hw/pflash: implement update buffer for block writes Philippe Mathieu-Daudé
2024-01-08 12:53 ` Philippe Mathieu-Daudé [this message]
2024-01-08 12:53 ` [PATCH v2 2/2] " Philippe Mathieu-Daudé
2024-01-08 13:05 ` Philippe Mathieu-Daudé
2024-01-12 16:54 ` Peter Maydell
2024-01-16 16:08 ` Philippe Mathieu-Daudé
2024-01-16 16:09 ` Peter Maydell
2024-01-17 7:52 ` Peter Xu
2024-01-09 21:40 ` Richard Henderson
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=20240108125342.48298-2-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=hreitz@redhat.com \
--cc=kraxel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).