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>
This commit is contained in:
Philippe Mathieu-Daudé 2019-05-05 23:14:29 +02:00
parent 7f7bdcaff5
commit c3d25271b2
1 changed files with 8 additions and 30 deletions

View File

@ -365,38 +365,16 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,
goto check_unlock0; goto check_unlock0;
case 0xA0: case 0xA0:
trace_pflash_data_write(offset, width << 1, value, 0); trace_pflash_data_write(offset, width << 1, value, 0);
p = pfl->storage;
if (!pfl->ro) { if (!pfl->ro) {
switch (width) { p = (uint8_t *)pfl->storage + offset;
case 1: if (pfl->be) {
p[offset] &= value; uint64_t current = ldn_be_p(p, width);
pflash_update(pfl, offset, 1); stn_be_p(p, width, current & value);
break; } else {
case 2: uint64_t current = ldn_le_p(p, width);
if (be) { stn_le_p(p, width, current & value);
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;
} }
pflash_update(pfl, offset, width);
} }
/* /*
* While programming, status bit DQ7 should hold the opposite * While programming, status bit DQ7 should hold the opposite