mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 16:23:55 -06:00
memory: Single byte swap along the I/O path
Now that MemOp has been pushed down into the memory API, and callers are encoding endianness, we can collapse byte swaps along the I/O path into the accelerator and target independent adjust_endianness. Collapsing byte swaps along the I/O path enables additional endian inversion logic, e.g. SPARC64 Invert Endian TTE bit, with redundant byte swaps cancelling out. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Suggested-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Tony Nguyen <tony.nguyen@bt.com> Message-Id: <911ff31af11922a9afba9b7ce128af8b8b80f316.1566466906.git.tony.nguyen@bt.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
be5c4787e9
commit
9bf825bf3d
5 changed files with 23 additions and 142 deletions
33
memory.c
33
memory.c
|
@ -351,32 +351,23 @@ static bool memory_region_big_endian(MemoryRegion *mr)
|
|||
#endif
|
||||
}
|
||||
|
||||
static bool memory_region_wrong_endianness(MemoryRegion *mr)
|
||||
static void adjust_endianness(MemoryRegion *mr, uint64_t *data, MemOp op)
|
||||
{
|
||||
#ifdef TARGET_WORDS_BIGENDIAN
|
||||
return mr->ops->endianness == DEVICE_LITTLE_ENDIAN;
|
||||
#else
|
||||
return mr->ops->endianness == DEVICE_BIG_ENDIAN;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void adjust_endianness(MemoryRegion *mr, uint64_t *data, unsigned size)
|
||||
{
|
||||
if (memory_region_wrong_endianness(mr)) {
|
||||
switch (size) {
|
||||
case 1:
|
||||
if ((op & MO_BSWAP) != devend_memop(mr->ops->endianness)) {
|
||||
switch (op & MO_SIZE) {
|
||||
case MO_8:
|
||||
break;
|
||||
case 2:
|
||||
case MO_16:
|
||||
*data = bswap16(*data);
|
||||
break;
|
||||
case 4:
|
||||
case MO_32:
|
||||
*data = bswap32(*data);
|
||||
break;
|
||||
case 8:
|
||||
case MO_64:
|
||||
*data = bswap64(*data);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1458,7 +1449,7 @@ MemTxResult memory_region_dispatch_read(MemoryRegion *mr,
|
|||
}
|
||||
|
||||
r = memory_region_dispatch_read1(mr, addr, pval, size, attrs);
|
||||
adjust_endianness(mr, pval, size);
|
||||
adjust_endianness(mr, pval, op);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -1501,7 +1492,7 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
|
|||
return MEMTX_DECODE_ERROR;
|
||||
}
|
||||
|
||||
adjust_endianness(mr, &data, size);
|
||||
adjust_endianness(mr, &data, op);
|
||||
|
||||
if ((!kvm_eventfds_enabled()) &&
|
||||
memory_region_dispatch_write_eventfds(mr, addr, data, size, attrs)) {
|
||||
|
@ -2350,7 +2341,7 @@ void memory_region_add_eventfd(MemoryRegion *mr,
|
|||
}
|
||||
|
||||
if (size) {
|
||||
adjust_endianness(mr, &mrfd.data, size);
|
||||
adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE);
|
||||
}
|
||||
memory_region_transaction_begin();
|
||||
for (i = 0; i < mr->ioeventfd_nb; ++i) {
|
||||
|
@ -2385,7 +2376,7 @@ void memory_region_del_eventfd(MemoryRegion *mr,
|
|||
unsigned i;
|
||||
|
||||
if (size) {
|
||||
adjust_endianness(mr, &mrfd.data, size);
|
||||
adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE);
|
||||
}
|
||||
memory_region_transaction_begin();
|
||||
for (i = 0; i < mr->ioeventfd_nb; ++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue