public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
From: Hiroshi Doyu <hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: [RFC 2/3] ARM: dma-mapping: Pass DMA attrs as IOMMU prot
Date: Thu, 20 Jun 2013 08:49:43 +0300	[thread overview]
Message-ID: <1371707384-30037-3-git-send-email-hdoyu@nvidia.com> (raw)
In-Reply-To: <1371707384-30037-1-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

Pass DMA attribute as IOMMU property, which can be proccessed in the
backend implementation of IOMMU. For example, DMA_ATTR_READ_ONLY can
be translated into each IOMMU H/W implementaion.

Signed-off-by: Hiroshi Doyu <hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 arch/arm/mm/dma-mapping.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 4152ed6..cbc6768 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1254,7 +1254,8 @@ err:
  */
 static dma_addr_t
 ____iommu_create_mapping(struct device *dev, dma_addr_t *req,
-			 struct page **pages, size_t size)
+			 struct page **pages, size_t size,
+			 struct dma_attrs *attrs)
 {
 	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
 	unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
@@ -1280,7 +1281,7 @@ ____iommu_create_mapping(struct device *dev, dma_addr_t *req,
 				break;
 
 		len = (j - i) << PAGE_SHIFT;
-		ret = iommu_map(mapping->domain, iova, phys, len, 0);
+		ret = iommu_map(mapping->domain, iova, phys, len, (int)attrs);
 		if (ret < 0)
 			goto fail;
 		iova += len;
@@ -1294,9 +1295,10 @@ fail:
 }
 
 static dma_addr_t
-__iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
+__iommu_create_mapping(struct device *dev, struct page **pages, size_t size,
+		       struct dma_attrs *attrs)
 {
-	return ____iommu_create_mapping(dev, NULL, pages, size);
+	return ____iommu_create_mapping(dev, NULL, pages, size, attrs);
 }
 
 static int __iommu_remove_mapping(struct device *dev, dma_addr_t iova, size_t size)
@@ -1332,7 +1334,7 @@ static struct page **__iommu_get_pages(void *cpu_addr, struct dma_attrs *attrs)
 }
 
 static void *__iommu_alloc_atomic(struct device *dev, size_t size,
-				  dma_addr_t *handle)
+				  dma_addr_t *handle, struct dma_attrs *attrs)
 {
 	struct page *page;
 	void *addr;
@@ -1341,7 +1343,7 @@ static void *__iommu_alloc_atomic(struct device *dev, size_t size,
 	if (!addr)
 		return NULL;
 
-	*handle = __iommu_create_mapping(dev, &page, size);
+	*handle = __iommu_create_mapping(dev, &page, size, attrs);
 	if (*handle == DMA_ERROR_CODE)
 		goto err_mapping;
 
@@ -1378,17 +1380,20 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,
 	size = PAGE_ALIGN(size);
 
 	if (gfp & GFP_ATOMIC)
-		return __iommu_alloc_atomic(dev, size, handle);
+
+		return __iommu_alloc_atomic(dev, size, handle, attrs);
 
 	pages = __iommu_alloc_buffer(dev, size, gfp);
 	if (!pages)
 		return NULL;
 
 	if (*handle == DMA_ERROR_CODE)
-		*handle = __iommu_create_mapping(dev, pages, size);
+		*handle = __iommu_create_mapping(dev, pages, size, attrs);
 	else
-		*handle = ____iommu_create_mapping(dev, handle, pages, size);
+		*handle = ____iommu_create_mapping(dev, handle, pages, size,
+						   attrs);
 
+	*handle = __iommu_create_mapping(dev, pages, size, attrs);
 	if (*handle == DMA_ERROR_CODE)
 		goto err_buffer;
 
@@ -1513,7 +1518,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
 
 skip_cmaint:
 	count = size >> PAGE_SHIFT;
-	ret = iommu_map_sg(mapping->domain, iova_base, sg, count, 0);
+	ret = iommu_map_sg(mapping->domain, iova_base, sg, count, (int)attrs);
 	if (WARN_ON(ret < 0))
 		goto fail;
 
@@ -1716,7 +1721,8 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
 	if (dma_addr == DMA_ERROR_CODE)
 		return dma_addr;
 
-	ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, 0);
+	ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len,
+			(int)attrs);
 	if (ret < 0)
 		goto fail;
 
@@ -1756,7 +1762,8 @@ static dma_addr_t arm_iommu_map_page_at(struct device *dev, struct page *page,
 	if (!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
 		__dma_page_cpu_to_dev(page, offset, size, dir);
 
-	ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, 0);
+	ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len,
+			(int)attrs);
 	if (ret < 0)
 		return DMA_ERROR_CODE;
 
@@ -1778,7 +1785,8 @@ static dma_addr_t arm_iommu_map_pages(struct device *dev, struct page **pages,
 			__dma_page_cpu_to_dev(pages[i], 0, PAGE_SIZE, dir);
 	}
 
-	ret = iommu_map_pages(mapping->domain, dma_handle, pages, count, 0);
+	ret = iommu_map_pages(mapping->domain, dma_handle, pages, count,
+			      (int)attrs);
 	if (ret < 0)
 		return DMA_ERROR_CODE;
 
-- 
1.8.1.5

  parent reply	other threads:[~2013-06-20  5:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20  5:49 [RFC 0/3] How to pass IOMMU map attr via DMA API? Hiroshi Doyu
     [not found] ` <1371707384-30037-1-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20  5:49   ` [RFC 1/3] common: DMA-mapping: add DMA_ATTR_READ_ONLY attribute Hiroshi Doyu
2013-06-20  5:49   ` Hiroshi Doyu [this message]
     [not found]     ` <1371707384-30037-3-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20  8:07       ` [Linaro-mm-sig] [RFC 2/3] ARM: dma-mapping: Pass DMA attrs as IOMMU prot Nishanth Peethambaran
     [not found]         ` <CAMcxFTRnnCnPnvMi89r7rUsN4xeYzZGqy9s5v5ukm_fJ_d_RGg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-20  8:24           ` Hiroshi Doyu
     [not found]             ` <20130620.112439.1330557591655135630.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20  8:55               ` Nishanth Peethambaran
     [not found]                 ` <CAMcxFTS0dUUEfGj-=-cb_rdfy+qWvtsaoR6Tv+-x05XX0mZmmw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-20  9:54                   ` Hiroshi Doyu
     [not found]                     ` <20130620.125431.1161068035083905855.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20 10:13                       ` Arnd Bergmann
     [not found]                         ` <201306201213.13644.arnd-r2nGTMty4D4@public.gmane.org>
2013-06-20 10:34                           ` Hiroshi Doyu
     [not found]                             ` <20130620.133407.798194318297047071.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20 10:57                               ` Arnd Bergmann
     [not found]                                 ` <201306201257.58419.arnd-r2nGTMty4D4@public.gmane.org>
2013-06-20 12:49                                   ` Nishanth Peethambaran
2013-06-20  5:49   ` [RFC 3/3] iommu/tegra: smmu: Support read-only mapping Hiroshi Doyu
     [not found]     ` <1371707384-30037-4-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20  6:50       ` [Linaro-mm-sig] " Kyungmin Park
     [not found]         ` <CAH9JG2VUCJErBNwT0_u_9niaSWUza5gJ-+q8OOJhrrdw5D-hUg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-20  7:27           ` Hiroshi Doyu
2013-06-20  9:31   ` [RFC 0/3] How to pass IOMMU map attr via DMA API? Will Deacon
     [not found]     ` <20130620093152.GE2842-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-06-20  9:59       ` Hiroshi Doyu
     [not found]         ` <20130620.125929.2250094502232662356.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-20 10:11           ` Catalin Marinas
     [not found]             ` <20130620101110.GB18536-5wv7dgnIgG8@public.gmane.org>
2013-06-20 11:00               ` Hiroshi Doyu
2013-06-20 10:12           ` Will Deacon
2013-06-21  7:17   ` Marek Szyprowski
     [not found]     ` <51C3FE27.5070702-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-06-21 16:03       ` Joerg Roedel
     [not found]         ` <20130621160344.GM11309-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2013-06-24  5:17           ` Hiroshi Doyu
     [not found]             ` <20130624081759.76e66d42bbf7c2c54ed1975c-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-06-24  7:21               ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1371707384-30037-3-git-send-email-hdoyu@nvidia.com \
    --to=hdoyu-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox