[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-7.2.9 15/20] hw/pflash: use ldn_{be,le}_p and stn_{be,le}_p
From: |
Michael Tokarev |
Subject: |
[Stable-7.2.9 15/20] hw/pflash: use ldn_{be,le}_p and stn_{be,le}_p |
Date: |
Tue, 23 Jan 2024 11:48:25 +0300 |
From: Gerd Hoffmann <kraxel@redhat.com>
Use the helper functions we have to read/write multi-byte values
in correct byte order.
Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240108160900.104835-3-kraxel@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 5dd58358a57048e5ceabf5c91c0544f4f56afdcd)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index c250214944..dbb3d0312d 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -226,34 +226,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 + offset, width);
+ } else {
+ ret = ldn_le_p(p + offset, width);
}
trace_pflash_data_read(pfl->name, offset, width, ret);
return ret;
@@ -409,34 +385,11 @@ static inline void pflash_data_write(PFlashCFI01 *pfl,
hwaddr offset,
trace_pflash_data_write(pfl->name, offset, width, value, pfl->counter);
p = pfl->storage + offset;
- switch (width) {
- case 1:
- p[0] = value;
- break;
- case 2:
- if (be) {
- p[0] = value >> 8;
- p[1] = value;
- } else {
- p[0] = value;
- p[1] = value >> 8;
- }
- break;
- case 4:
- if (be) {
- p[0] = value >> 24;
- p[1] = value >> 16;
- p[2] = value >> 8;
- p[3] = value;
- } else {
- p[0] = value;
- p[1] = value >> 8;
- p[2] = value >> 16;
- p[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.39.2
- [Stable-7.2.9 00/20] Patch Round-up for stable 7.2.9, freeze on 2024-01-27, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 09/20] load_elf: fix iterator's type for elf file processing, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 11/20] target/i386: Do not re-compute new pc with CF_PCREL, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 10/20] target/i386: Fix 32-bit wrapping of pc/eip computation, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 12/20] target/i386: fix incorrect EIP in PC-relative translation blocks, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 13/20] target/i386: pcrel: store low bits of physical address in data[0], Michael Tokarev, 2024/01/23
- [Stable-7.2.9 14/20] hw/pflash: refactor pflash_data_write(), Michael Tokarev, 2024/01/23
- [Stable-7.2.9 15/20] hw/pflash: use ldn_{be,le}_p and stn_{be,le}_p,
Michael Tokarev <=
- [Stable-7.2.9 16/20] hw/pflash: implement update buffer for block writes, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 17/20] hw/scsi/esp-pci: use correct address register for PCI DMA transfers, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 18/20] hw/scsi/esp-pci: generate PCI interrupt from separate ESP and PCI sources, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 19/20] hw/scsi/esp-pci: synchronise setting of DMA_STAT_DONE with ESP completion interrupt, Michael Tokarev, 2024/01/23
- [Stable-7.2.9 20/20] hw/scsi/esp-pci: set DMA_STAT_BCMBLT when BLAST command issued, Michael Tokarev, 2024/01/23
- Re: [Stable-7.2.9 00/20] Patch Round-up for stable 7.2.9, freeze on 2024-01-27, Paolo Bonzini, 2024/01/23