From patchwork Mon Jun 15 22:22:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 484612 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 B99A2140281 for ; Tue, 16 Jun 2015 08:23:35 +1000 (AEST) Received: from localhost ([::1]:36676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4cmz-0001VA-Kf for incoming@patchwork.ozlabs.org; Mon, 15 Jun 2015 18:23:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4cmM-0000Nb-R7 for qemu-devel@nongnu.org; Mon, 15 Jun 2015 18:22:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4cmL-0002po-PA for qemu-devel@nongnu.org; Mon, 15 Jun 2015 18:22:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49611) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4cmH-0002jB-7o; Mon, 15 Jun 2015 18:22:49 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id E4AA5AC7C8; Mon, 15 Jun 2015 22:22:48 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-29.bos.redhat.com [10.18.17.29]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5FMMljP015733; Mon, 15 Jun 2015 18:22:48 -0400 From: John Snow To: qemu-block@nongnu.org Date: Mon, 15 Jun 2015 18:22:42 -0400 Message-Id: <1434406965-30883-2-git-send-email-jsnow@redhat.com> In-Reply-To: <1434406965-30883-1-git-send-email-jsnow@redhat.com> References: <1434406965-30883-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, John Snow , qemu-devel@nongnu.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 1/4] ahci: Do not ignore memory access read size 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 The only guidance the AHCI specification gives on memory access is: "Register accesses shall have a maximum size of 64-bits; 64-bit access must not cross an 8-byte alignment boundary." In practice, a real Q35/ICH9 responds to 1, 2, 4 and 8 byte reads regardless of alignment. Windows 7 can also be observed making 1 byte reads to the middle of 32 bit registers. Introduce a wrapper to supper unaligned accesses to AHCI. This wrapper will support aligned 8 byte reads, but will make no effort to support unaligned 8 byte reads, which although they will work on real hardware, are not guaranteed to work and do not appear to be used by either Windows or Linux. Signed-off-by: John Snow --- hw/ide/ahci.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 9e5d862..55779fb 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -331,8 +331,7 @@ static void ahci_port_write(AHCIState *s, int port, int offset, uint32_t val) } } -static uint64_t ahci_mem_read(void *opaque, hwaddr addr, - unsigned size) +static uint64_t ahci_mem_read_32(void *opaque, hwaddr addr) { AHCIState *s = opaque; uint32_t val = 0; @@ -368,6 +367,24 @@ static uint64_t ahci_mem_read(void *opaque, hwaddr addr, } +static uint64_t ahci_mem_read(void *opaque, hwaddr addr, unsigned size) +{ + hwaddr aligned = addr & ~0x3; + int ofst = addr - aligned; + uint64_t lo = ahci_mem_read_32(opaque, aligned); + uint64_t hi; + + /* if 1/2/4 byte read does not cross 4 byte boundary */ + if (ofst + size <= 4) { + return lo >> (ofst * 8); + } + + /* If the 64bit read is unaligned, we will produce undefined + * results. AHCI does not support unaligned 64bit reads. */ + hi = ahci_mem_read_32(opaque, aligned + 4); + return (hi << 32) | lo; +} + static void ahci_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)