Revert "virtio-pci: replace byte swap hack"

This reverts commit 9807caccd605d09a72495637959568d690e10175.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Blue Swirl 2013-01-06 18:30:17 +00:00
parent 9807caccd6
commit 8e4a424b30
2 changed files with 34 additions and 1 deletions

18
exec.c
View File

@ -2587,6 +2587,24 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
} }
#endif #endif
#if !defined(CONFIG_USER_ONLY)
/*
* A helper function for the _utterly broken_ virtio device model to find out if
* it's running on a big endian machine. Don't do this at home kids!
*/
bool virtio_is_big_endian(void);
bool virtio_is_big_endian(void)
{
#if defined(TARGET_WORDS_BIGENDIAN)
return true;
#else
return false;
#endif
}
#endif
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
bool cpu_physical_memory_is_io(hwaddr phys_addr) bool cpu_physical_memory_is_io(hwaddr phys_addr)
{ {

View File

@ -92,6 +92,9 @@
*/ */
#define wmb() do { } while (0) #define wmb() do { } while (0)
/* HACK for virtio to determine if it's running a big endian guest */
bool virtio_is_big_endian(void);
/* virtio device */ /* virtio device */
/* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */ /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */
static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d) static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
@ -400,9 +403,15 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
break; break;
case 2: case 2:
val = virtio_config_readw(proxy->vdev, addr); val = virtio_config_readw(proxy->vdev, addr);
if (virtio_is_big_endian()) {
val = bswap16(val);
}
break; break;
case 4: case 4:
val = virtio_config_readl(proxy->vdev, addr); val = virtio_config_readl(proxy->vdev, addr);
if (virtio_is_big_endian()) {
val = bswap32(val);
}
break; break;
} }
return val; return val;
@ -427,9 +436,15 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
virtio_config_writeb(proxy->vdev, addr, val); virtio_config_writeb(proxy->vdev, addr, val);
break; break;
case 2: case 2:
if (virtio_is_big_endian()) {
val = bswap16(val);
}
virtio_config_writew(proxy->vdev, addr, val); virtio_config_writew(proxy->vdev, addr, val);
break; break;
case 4: case 4:
if (virtio_is_big_endian()) {
val = bswap32(val);
}
virtio_config_writel(proxy->vdev, addr, val); virtio_config_writel(proxy->vdev, addr, val);
break; break;
} }
@ -442,7 +457,7 @@ static const MemoryRegionOps virtio_pci_config_ops = {
.min_access_size = 1, .min_access_size = 1,
.max_access_size = 4, .max_access_size = 4,
}, },
.endianness = DEVICE_NATIVE_ENDIAN, .endianness = DEVICE_LITTLE_ENDIAN,
}; };
static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,