From patchwork Tue Jun 25 11:52:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi DOYU X-Patchwork-Id: 2776211 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 71681C0AB1 for ; Tue, 25 Jun 2013 11:53:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43EF7201CB for ; Tue, 25 Jun 2013 11:53:31 +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 C118F20182 for ; Tue, 25 Jun 2013 11:53:29 +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 1UrRoK-0008C3-BV; Tue, 25 Jun 2013 11:53:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UrRoH-0005Hy-FN; Tue, 25 Jun 2013 11:53:21 +0000 Received: from hqemgate15.nvidia.com ([216.228.121.64]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UrRoE-0005Gd-M7 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2013 11:53:19 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Tue, 25 Jun 2013 04:52:28 -0700 Received: from hqemhub02.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Tue, 25 Jun 2013 04:50:52 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Tue, 25 Jun 2013 04:50:52 -0700 Received: from deemhub02.nvidia.com (10.21.69.138) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server (TLS) id 8.3.298.1; Tue, 25 Jun 2013 04:52:52 -0700 Received: from DEMAIL01.nvidia.com ([10.21.69.139]) by deemhub02.nvidia.com ([10.21.69.138]) with mapi; Tue, 25 Jun 2013 13:52:50 +0200 From: Hiroshi Doyu To: "will.deacon@arm.com" , "m.szyprowski@samsung.com" Date: Tue, 25 Jun 2013 13:52:26 +0200 Subject: Re: [PATCH 3/9] ARM: dma-mapping: convert DMA direction into IOMMU protection attributes Thread-Topic: [PATCH 3/9] ARM: dma-mapping: convert DMA direction into IOMMU protection attributes Thread-Index: Ac5xmoRQ+q6HgmI3TuqN1z//TnK4Pg== Message-ID: <20130625.145226.1632119404634300971.hdoyu@nvidia.com> References: <1370889285-22799-4-git-send-email-will.deacon@arm.com><20130625131215.d3cea2a5668a3d41dbbeb064@nvidia.com><20130625113714.GF31838@mudshark.cambridge.arm.com> In-Reply-To: <20130625113714.GF31838@mudshark.cambridge.arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-nvconfidentiality: public acceptlanguage: en-US MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130625_075318_892143_74318E21 X-CRM114-Status: GOOD ( 18.55 ) X-Spam-Score: -3.2 (---) Cc: "linux-tegra@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "devicetree-discuss@lists.ozlabs.org" , "linux-arm-kernel@lists.infradead.org" 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=-5.5 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 Will Deacon wrote @ Tue, 25 Jun 2013 13:37:14 +0200: ... > > Do we need similar changes for map_sg case as well? They still passes '0' as prot. > > Yes, we could use the same trick there (probably worth moving the logic into > a helper function for translating dma_data_direction into IOMMU_* values). > > There are also iommu_map calls when allocating DMA buffers, but I think 0 is > the right thing to pass there (i.e. no permission until pages have been > explicitly mapped). Although, to be honest, I don't see why we need to map > the buffer at all when we allocate it. Yes, I thought too. I have a patch for that as below. If you like, I'll rebase and send for merge with the one which changes dma-mapping.c. From 699e6bd4fef86383d197775486b47bcbdc594f4a Mon Sep 17 00:00:00 2001 From: Hiroshi Doyu Date: Tue, 25 Jun 2013 13:43:29 +0300 Subject: [PATCH 1/2] iommu/core: convert DMA direction into IOMMU protection attributes Introduce a new function to convert DMA direction into IOMMU protection attributes. Signed-off-by: Hiroshi Doyu --- include/linux/iommu.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 00af00f..ce3be78 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -21,11 +21,26 @@ #include #include +#include #define IOMMU_READ (1) #define IOMMU_WRITE (2) #define IOMMU_CACHE (4) /* DMA cache coherency */ +static inline int to_iommu_prot(enum dma_data_direction dir) +{ + switch (dir) { + case DMA_BIDIRECTIONAL: + return IOMMU_READ | IOMMU_WRITE; + case DMA_TO_DEVICE: + return IOMMU_READ; + case DMA_FROM_DEVICE: + return IOMMU_WRITE; + default: + return 0; + } +} + struct iommu_ops; struct iommu_group; struct bus_type;