From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUpIJ-0007VB-V1 for qemu-devel@nongnu.org; Thu, 18 Sep 2014 23:55:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUpI5-0002RH-Uz for qemu-devel@nongnu.org; Thu, 18 Sep 2014 23:55:39 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:55641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUpI5-0002Q3-B4 for qemu-devel@nongnu.org; Thu, 18 Sep 2014 23:55:25 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 19 Sep 2014 13:55:17 +1000 From: Alexey Kardashevskiy Date: Fri, 19 Sep 2014 13:55:09 +1000 Message-Id: <1411098909-23780-3-git-send-email-aik@ozlabs.ru> In-Reply-To: <1411098909-23780-1-git-send-email-aik@ozlabs.ru> References: <1411098909-23780-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH v2 2/2] vfio: make rom read endian sensitive List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, Alexander Graf , Nikunj A Dadhania From: Nikunj A Dadhania 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 [aik: added commit log] Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * add statement where it was tested --- hw/misc/vfio.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 22ebcbd..d66f3d2 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, -- 2.0.0