hw/pflash: use ldn_{be,le}_p and stn_{be,le}_p
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>
This commit is contained in:
parent
3b14a555fd
commit
5dd58358a5
@ -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];
|
||||
ret = ldn_be_p(p + offset, width);
|
||||
} 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();
|
||||
ret = ldn_le_p(p + offset, width);
|
||||
}
|
||||
trace_pflash_data_read(pfl->name, offset, width, ret);
|
||||
return ret;
|
||||
@ -408,34 +384,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;
|
||||
stn_be_p(p, width, value);
|
||||
} else {
|
||||
p[0] = value;
|
||||
p[1] = value >> 8;
|
||||
stn_le_p(p, width, value);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
|
||||
|
Loading…
Reference in New Issue
Block a user