From patchwork Thu Aug 29 18:32:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 2851560 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AEC2B9F3DC for ; Thu, 29 Aug 2013 18:42:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EAB952058E for ; Thu, 29 Aug 2013 18:42:15 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A27A420586 for ; Thu, 29 Aug 2013 18:42:14 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VF7Aa-0000v4-37; Thu, 29 Aug 2013 18:42:12 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VF7AX-00050e-Qe; Thu, 29 Aug 2013 18:42:09 +0000 Received: from smtp02.citrix.com ([66.165.176.63]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VF7AV-0004zz-6B for linux-arm-kernel@lists.infradead.org; Thu, 29 Aug 2013 18:42:07 +0000 X-IronPort-AV: E=Sophos;i="4.89,984,1367971200"; d="scan'208";a="46546631" Received: from accessns.citrite.net (HELO FTLPEX01CL01.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 29 Aug 2013 18:41:46 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.2.342.4; Thu, 29 Aug 2013 14:41:44 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1VF71S-0008Qk-UJ; Thu, 29 Aug 2013 19:32:46 +0100 From: Stefano Stabellini To: Subject: [PATCH v5 13/13] swiotlb: don't assume that io_tlb_start-io_tlb_end is coherent Date: Thu, 29 Aug 2013 19:32:34 +0100 Message-ID: <1377801154-29215-13-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130829_144207_438755_A0A602F0 X-CRM114-Status: GOOD ( 10.52 ) X-Spam-Score: -5.1 (-----) Cc: Ian.Campbell@citrix.com, Stefano Stabellini , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, konrad.wilk@oracle.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 The swiotlb code has appropriate calls to dma_mark_clean in place for buffers passed to swiotlb_map_page as an argument. However it assumes that the swiotlb bounce buffer (io_tlb_start-io_tlb_end) is already coherent and doesn't need any calls to dma_mark_clean. On ARM the swiotlb bounce buffer is not coherent (the memory is writealloc while it should be bufferable) and therefore we need to call dma_mark_clean appropriately on the bounce buffer code paths too. Note that most architecures have an empty dma_mark_clean implementation anyway. Signed-off-by: Stefano Stabellini --- lib/swiotlb.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 4e8686c..b1f43f6 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -547,7 +547,10 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, * First, sync the memory before unmapping the entry */ if (orig_addr && ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))) + { + dma_mark_clean(phys_to_virt(tlb_addr), size); swiotlb_bounce(orig_addr, tlb_addr, size, DMA_FROM_DEVICE); + } /* * Return the buffer to the free list by setting the corresponding @@ -587,17 +590,20 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, switch (target) { case SYNC_FOR_CPU: - if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)) + if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)) { + dma_mark_clean(phys_to_virt(tlb_addr), size); swiotlb_bounce(orig_addr, tlb_addr, size, DMA_FROM_DEVICE); + } else BUG_ON(dir != DMA_TO_DEVICE); break; case SYNC_FOR_DEVICE: - if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) + if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) { swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE); - else + dma_mark_clean(phys_to_virt(tlb_addr), size); + } else BUG_ON(dir != DMA_FROM_DEVICE); break; default: