aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorNikunj A Dadhania <nikunj@linux.vnet.ibm.com>2014-09-22 15:27:43 -0600
committerAlex Williamson <alex.williamson@redhat.com>2014-09-22 15:27:43 -0600
commit75bd0c7253f384e868b638db5c6350796cf584f7 (patch)
treef7c2556100d23bfe2d7da07c896d4e3d8a3272a7 /hw
parent6758008e2c4e79fb6bd04fe8e7a41665fa583965 (diff)
vfio: make rom read endian sensitive
All memory regions used by VFIO are LITTLE_ENDIAN and they already take care of endiannes when accessing real device BARs except ROM - it was broken on BE hosts. This fixes endiannes for ROM BARs the same way as it is done for other BARs. This has been tested on PPC64 BE/LE host/guest in all possible combinations including TCG. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> [aik: added commit log] Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/misc/vfio.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 22ebcbd796..d66f3d2425 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -1250,7 +1250,13 @@ static void vfio_pci_load_rom(VFIODevice *vdev)
static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
{
VFIODevice *vdev = opaque;
- uint64_t val = ((uint64_t)1 << (size * 8)) - 1;
+ union {
+ uint8_t byte;
+ uint16_t word;
+ uint32_t dword;
+ uint64_t qword;
+ } val;
+ uint64_t data = 0;
/* Load the ROM lazily when the guest tries to read it */
if (unlikely(!vdev->rom && !vdev->rom_read_failed)) {
@@ -1260,11 +1266,26 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
memcpy(&val, vdev->rom + addr,
(addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0);
+ switch (size) {
+ case 1:
+ data = val.byte;
+ break;
+ case 2:
+ data = le16_to_cpu(val.word);
+ break;
+ case 4:
+ data = le32_to_cpu(val.dword);
+ break;
+ default:
+ hw_error("vfio: unsupported read size, %d bytes\n", size);
+ break;
+ }
+
DPRINTF("%s(%04x:%02x:%02x.%x, 0x%"HWADDR_PRIx", 0x%x) = 0x%"PRIx64"\n",
__func__, vdev->host.domain, vdev->host.bus, vdev->host.slot,
- vdev->host.function, addr, size, val);
+ vdev->host.function, addr, size, data);
- return val;
+ return data;
}
static void vfio_rom_write(void *opaque, hwaddr addr,