summaryrefslogtreecommitdiffstats
path: root/hw/block
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé2019-05-05 23:14:29 +0200
committerPhilippe Mathieu-Daudé2019-07-02 02:31:13 +0200
commitc3d25271b2117a1416f5818d9d2b399b4e1e77b3 (patch)
tree58067c500da912dd49b1a8a48a08a6c718662f5f /hw/block
parenthw/block/pflash_cfi02: Simplify a statement using fall through (diff)
downloadqemu-c3d25271b2117a1416f5818d9d2b399b4e1e77b3.tar.gz
qemu-c3d25271b2117a1416f5818d9d2b399b4e1e77b3.tar.xz
qemu-c3d25271b2117a1416f5818d9d2b399b4e1e77b3.zip
hw/block/pflash_cfi02: Use the ldst API in pflash_write()
The load/store API eases code review. Signed-off-by: Stephen Checkoway <stephen.checkoway@oberlin.edu> Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> [PMD: Extracted from bigger patch] Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'hw/block')
-rw-r--r--hw/block/pflash_cfi02.c38
1 files changed, 8 insertions, 30 deletions
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 9e8c28af8f..ae38ed0bae 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -365,38 +365,16 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,
goto check_unlock0;
case 0xA0:
trace_pflash_data_write(offset, width << 1, value, 0);
- p = pfl->storage;
if (!pfl->ro) {
- switch (width) {
- case 1:
- p[offset] &= value;
- pflash_update(pfl, offset, 1);
- break;
- case 2:
- if (be) {
- p[offset] &= value >> 8;
- p[offset + 1] &= value;
- } else {
- p[offset] &= value;
- p[offset + 1] &= value >> 8;
- }
- pflash_update(pfl, offset, 2);
- 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;
- }
- pflash_update(pfl, offset, 4);
- break;
+ p = (uint8_t *)pfl->storage + offset;
+ if (pfl->be) {
+ uint64_t current = ldn_be_p(p, width);
+ stn_be_p(p, width, current & value);
+ } else {
+ uint64_t current = ldn_le_p(p, width);
+ stn_le_p(p, width, current & value);
}
+ pflash_update(pfl, offset, width);
}
/*
* While programming, status bit DQ7 should hold the opposite