From patchwork Wed Feb 10 19:38:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 8274291 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 994959F38B for ; Wed, 10 Feb 2016 19:42:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E66C3203A4 for ; Wed, 10 Feb 2016 19:42:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 26F90201EF for ; Wed, 10 Feb 2016 19:42:35 +0000 (UTC) Received: from localhost ([::1]:42474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTaeo-000724-G9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Feb 2016 14:42:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTaap-0008GG-UI for qemu-devel@nongnu.org; Wed, 10 Feb 2016 14:38:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTaal-0003Bm-TO for qemu-devel@nongnu.org; Wed, 10 Feb 2016 14:38:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTaal-0003Bi-Lh for qemu-devel@nongnu.org; Wed, 10 Feb 2016 14:38:23 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 492D98E748; Wed, 10 Feb 2016 19:38:23 +0000 (UTC) Received: from scv.usersys.redhat.com (vpn-56-231.rdu2.redhat.com [10.10.56.231]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1AJc9AH016300; Wed, 10 Feb 2016 14:38:22 -0500 From: John Snow To: qemu-devel@nongnu.org Date: Wed, 10 Feb 2016 14:38:07 -0500 Message-Id: <1455133089-31903-11-git-send-email-jsnow@redhat.com> In-Reply-To: <1455133089-31903-1-git-send-email-jsnow@redhat.com> References: <1455133089-31903-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, jsnow@redhat.com Subject: [Qemu-devel] [PULL 09/11] ahci: handle LIST_ON and FIS_ON in map helpers 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of relying on ahci_cond_start_engines to maintain the engine status indicators itself, have the lower-layer CLB and FIS mapper helpers do it themselves. This makes the cond_start routine slightly nicer to read, and makes sure that the status indicators will always be correct. Signed-off-by: John Snow Message-id: 1454103689-13042-3-git-send-email-jsnow@redhat.com --- hw/ide/ahci.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 3a95dad..ff338fe 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -210,9 +210,7 @@ static int ahci_cond_start_engines(AHCIDevice *ad, bool allow_stop) AHCIPortRegs *pr = &ad->port_regs; if (pr->cmd & PORT_CMD_START) { - if (ahci_map_clb_address(ad)) { - pr->cmd |= PORT_CMD_LIST_ON; - } else { + if (!ahci_map_clb_address(ad)) { error_report("AHCI: Failed to start DMA engine: " "bad command list buffer address"); return -1; @@ -220,7 +218,6 @@ static int ahci_cond_start_engines(AHCIDevice *ad, bool allow_stop) } else if (pr->cmd & PORT_CMD_LIST_ON) { if (allow_stop) { ahci_unmap_clb_address(ad); - pr->cmd = pr->cmd & ~(PORT_CMD_LIST_ON); } else { error_report("AHCI: DMA engine should be off, " "but appears to still be running"); @@ -229,9 +226,7 @@ static int ahci_cond_start_engines(AHCIDevice *ad, bool allow_stop) } if (pr->cmd & PORT_CMD_FIS_RX) { - if (ahci_map_fis_address(ad)) { - pr->cmd |= PORT_CMD_FIS_ON; - } else { + if (!ahci_map_fis_address(ad)) { error_report("AHCI: Failed to start FIS receive engine: " "bad FIS receive buffer address"); return -1; @@ -239,7 +234,6 @@ static int ahci_cond_start_engines(AHCIDevice *ad, bool allow_stop) } else if (pr->cmd & PORT_CMD_FIS_ON) { if (allow_stop) { ahci_unmap_fis_address(ad); - pr->cmd = pr->cmd & ~(PORT_CMD_FIS_ON); } else { error_report("AHCI: FIS receive engine should be off, " "but appears to still be running"); @@ -657,7 +651,13 @@ static bool ahci_map_fis_address(AHCIDevice *ad) AHCIPortRegs *pr = &ad->port_regs; map_page(ad->hba->as, &ad->res_fis, ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr, 256); - return ad->res_fis != NULL; + if (ad->res_fis != NULL) { + pr->cmd |= PORT_CMD_FIS_ON; + return true; + } + + pr->cmd &= ~PORT_CMD_FIS_ON; + return false; } static void ahci_unmap_fis_address(AHCIDevice *ad) @@ -666,6 +666,7 @@ static void ahci_unmap_fis_address(AHCIDevice *ad) DPRINTF(ad->port_no, "Attempt to unmap NULL FIS address\n"); return; } + ad->port_regs.cmd &= ~PORT_CMD_FIS_ON; dma_memory_unmap(ad->hba->as, ad->res_fis, 256, DMA_DIRECTION_FROM_DEVICE, 256); ad->res_fis = NULL; @@ -677,7 +678,13 @@ static bool ahci_map_clb_address(AHCIDevice *ad) ad->cur_cmd = NULL; map_page(ad->hba->as, &ad->lst, ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 1024); - return ad->lst != NULL; + if (ad->lst != NULL) { + pr->cmd |= PORT_CMD_LIST_ON; + return true; + } + + pr->cmd &= ~PORT_CMD_LIST_ON; + return false; } static void ahci_unmap_clb_address(AHCIDevice *ad) @@ -686,6 +693,7 @@ static void ahci_unmap_clb_address(AHCIDevice *ad) DPRINTF(ad->port_no, "Attempt to unmap NULL CLB address\n"); return; } + ad->port_regs.cmd &= ~PORT_CMD_LIST_ON; dma_memory_unmap(ad->hba->as, ad->lst, 1024, DMA_DIRECTION_FROM_DEVICE, 1024); ad->lst = NULL;