Revert "vfio: Make BARs native endian"

This reverts commit c40708176a.

The resulting code wrongly assumed target and host endianness are
the same which is not always the case for PPC64.

[aw: or potentially any host supporting VFIO and TCG]

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
master
Alexey Kardashevskiy 2014-09-22 15:26:36 -06:00 committed by Alex Williamson
parent 07e2863d02
commit 6758008e2c
1 changed files with 10 additions and 31 deletions

View File

@ -1098,10 +1098,10 @@ static void vfio_bar_write(void *opaque, hwaddr addr,
buf.byte = data; buf.byte = data;
break; break;
case 2: case 2:
buf.word = data; buf.word = cpu_to_le16(data);
break; break;
case 4: case 4:
buf.dword = data; buf.dword = cpu_to_le32(data);
break; break;
default: default:
hw_error("vfio: unsupported write size, %d bytes", size); hw_error("vfio: unsupported write size, %d bytes", size);
@ -1158,10 +1158,10 @@ static uint64_t vfio_bar_read(void *opaque,
data = buf.byte; data = buf.byte;
break; break;
case 2: case 2:
data = buf.word; data = le16_to_cpu(buf.word);
break; break;
case 4: case 4:
data = buf.dword; data = le32_to_cpu(buf.dword);
break; break;
default: default:
hw_error("vfio: unsupported read size, %d bytes", size); hw_error("vfio: unsupported read size, %d bytes", size);
@ -1188,7 +1188,7 @@ static uint64_t vfio_bar_read(void *opaque,
static const MemoryRegionOps vfio_bar_ops = { static const MemoryRegionOps vfio_bar_ops = {
.read = vfio_bar_read, .read = vfio_bar_read,
.write = vfio_bar_write, .write = vfio_bar_write,
.endianness = DEVICE_NATIVE_ENDIAN, .endianness = DEVICE_LITTLE_ENDIAN,
}; };
static void vfio_pci_load_rom(VFIODevice *vdev) static void vfio_pci_load_rom(VFIODevice *vdev)
@ -1250,42 +1250,21 @@ static void vfio_pci_load_rom(VFIODevice *vdev)
static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size) static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
{ {
VFIODevice *vdev = opaque; VFIODevice *vdev = opaque;
union { uint64_t val = ((uint64_t)1 << (size * 8)) - 1;
uint8_t byte;
uint16_t word;
uint32_t dword;
uint64_t qword;
} buf;
uint64_t data = 0;
/* Load the ROM lazily when the guest tries to read it */ /* Load the ROM lazily when the guest tries to read it */
if (unlikely(!vdev->rom && !vdev->rom_read_failed)) { if (unlikely(!vdev->rom && !vdev->rom_read_failed)) {
vfio_pci_load_rom(vdev); vfio_pci_load_rom(vdev);
} }
memcpy(&buf, vdev->rom + addr, memcpy(&val, vdev->rom + addr,
(addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0); (addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0);
switch (size) {
case 1:
data = buf.byte;
break;
case 2:
data = buf.word;
break;
case 4:
data = buf.dword;
break;
default:
hw_error("vfio: unsupported read size, %d bytes", size);
break;
}
DPRINTF("%s(%04x:%02x:%02x.%x, 0x%"HWADDR_PRIx", 0x%x) = 0x%"PRIx64"\n", DPRINTF("%s(%04x:%02x:%02x.%x, 0x%"HWADDR_PRIx", 0x%x) = 0x%"PRIx64"\n",
__func__, vdev->host.domain, vdev->host.bus, vdev->host.slot, __func__, vdev->host.domain, vdev->host.bus, vdev->host.slot,
vdev->host.function, addr, size, data); vdev->host.function, addr, size, val);
return data; return val;
} }
static void vfio_rom_write(void *opaque, hwaddr addr, static void vfio_rom_write(void *opaque, hwaddr addr,
@ -1296,7 +1275,7 @@ static void vfio_rom_write(void *opaque, hwaddr addr,
static const MemoryRegionOps vfio_rom_ops = { static const MemoryRegionOps vfio_rom_ops = {
.read = vfio_rom_read, .read = vfio_rom_read,
.write = vfio_rom_write, .write = vfio_rom_write,
.endianness = DEVICE_NATIVE_ENDIAN, .endianness = DEVICE_LITTLE_ENDIAN,
}; };
static bool vfio_blacklist_opt_rom(VFIODevice *vdev) static bool vfio_blacklist_opt_rom(VFIODevice *vdev)