mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
tests/qtest/libqos: Avoid double swapping when using modern virtio
The logic in the qvirtio_read/write function is rather a headache, involving byte-swapping when the target is big endian, just to maybe involve another byte-swapping in the qtest_read/write function immediately afterwards (on the QEMU side). Let's do it in a more obvious way here: For virtio 1.0, we know that the values have to be little endian, so let's read/write the bytes in that well known order here. Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Alex Bennée <alex.bennee@linaro.org> Message-ID: <20250430132817.610903-1-thuth@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
parent
246069e850
commit
3008224ca8
1 changed files with 29 additions and 15 deletions
|
@ -25,49 +25,63 @@
|
|||
*/
|
||||
static uint16_t qvirtio_readw(QVirtioDevice *d, QTestState *qts, uint64_t addr)
|
||||
{
|
||||
uint16_t val = qtest_readw(qts, addr);
|
||||
uint16_t val;
|
||||
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) {
|
||||
val = bswap16(val);
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
|
||||
qtest_memread(qts, addr, &val, sizeof(val));
|
||||
val = le16_to_cpu(val);
|
||||
} else {
|
||||
val = qtest_readw(qts, addr);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static uint32_t qvirtio_readl(QVirtioDevice *d, QTestState *qts, uint64_t addr)
|
||||
{
|
||||
uint32_t val = qtest_readl(qts, addr);
|
||||
uint32_t val;
|
||||
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) {
|
||||
val = bswap32(val);
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
|
||||
qtest_memread(qts, addr, &val, sizeof(val));
|
||||
val = le32_to_cpu(val);
|
||||
} else {
|
||||
val = qtest_readl(qts, addr);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void qvirtio_writew(QVirtioDevice *d, QTestState *qts,
|
||||
uint64_t addr, uint16_t val)
|
||||
{
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) {
|
||||
val = bswap16(val);
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
|
||||
val = cpu_to_le16(val);
|
||||
qtest_memwrite(qts, addr, &val, sizeof(val));
|
||||
} else {
|
||||
qtest_writew(qts, addr, val);
|
||||
}
|
||||
qtest_writew(qts, addr, val);
|
||||
}
|
||||
|
||||
static void qvirtio_writel(QVirtioDevice *d, QTestState *qts,
|
||||
uint64_t addr, uint32_t val)
|
||||
{
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) {
|
||||
val = bswap32(val);
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
|
||||
val = cpu_to_le32(val);
|
||||
qtest_memwrite(qts, addr, &val, sizeof(val));
|
||||
} else {
|
||||
qtest_writel(qts, addr, val);
|
||||
}
|
||||
qtest_writel(qts, addr, val);
|
||||
}
|
||||
|
||||
static void qvirtio_writeq(QVirtioDevice *d, QTestState *qts,
|
||||
uint64_t addr, uint64_t val)
|
||||
{
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) {
|
||||
val = bswap64(val);
|
||||
if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
|
||||
val = cpu_to_le64(val);
|
||||
qtest_memwrite(qts, addr, &val, sizeof(val));
|
||||
} else {
|
||||
qtest_writeq(qts, addr, val);
|
||||
}
|
||||
qtest_writeq(qts, addr, val);
|
||||
}
|
||||
|
||||
uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue