From patchwork Tue Sep 23 17:14:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 392598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EEDCE1400B6 for ; Wed, 24 Sep 2014 03:17:05 +1000 (EST) Received: from localhost ([::1]:54753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWTi3-0004LO-Jg for incoming@patchwork.ozlabs.org; Tue, 23 Sep 2014 13:17:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWTgF-0001mt-Ij for qemu-devel@nongnu.org; Tue, 23 Sep 2014 13:15:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XWTgA-0000Mn-BS for qemu-devel@nongnu.org; Tue, 23 Sep 2014 13:15:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61261) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWTgA-00009f-2t for qemu-devel@nongnu.org; Tue, 23 Sep 2014 13:15:06 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8NHEwiQ012796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Sep 2014 13:14:58 -0400 Received: from bling.home (ovpn-113-65.phx2.redhat.com [10.3.113.65]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8NHEvXc010087; Tue, 23 Sep 2014 13:14:57 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Tue, 23 Sep 2014 11:14:57 -0600 Message-ID: <20140923171457.6258.99078.stgit@bling.home> In-Reply-To: <20140923171355.6258.48511.stgit@bling.home> References: <20140923171355.6258.48511.stgit@bling.home> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Alexey Kardashevskiy , alex.williamson@redhat.com, Nikunj A Dadhania Subject: [Qemu-devel] [PULL 2/2] vfio: make rom read endian sensitive X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Alex Williamson Reviewed-by: David Gibson --- 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,