Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1649466

[PATCH v5 2/7] dma: Add simple dma_noop_mmap

From Vladimir Murzin <vladimir.murzin@arm.com>
Newsgroups linux.kernel
Subject [PATCH v5 2/7] dma: Add simple dma_noop_mmap
Date 2017-05-24 13:10 +0200
Message-ID <tKCkV-1Ap-5@gated-at.bofh.it> (permalink)
References <tKBIe-15d-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch adds a simple implementation of mmap to dma_noop_ops.

Cc: Joerg Roedel <jroedel@suse.de>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Reported-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Tested-by: Andras Szemzo <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
---
 lib/dma-noop.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/dma-noop.c b/lib/dma-noop.c
index ff4ef5e..0acc3f6 100644
--- a/lib/dma-noop.c
+++ b/lib/dma-noop.c
@@ -66,6 +66,26 @@ static int dma_noop_supported(struct device *dev, u64 mask)
 	return 1;
 }
 
+static int dma_noop_mmap(struct device *dev, struct vm_area_struct *vma,
+			 void *cpu_addr, dma_addr_t dma_addr, size_t size,
+			 unsigned long attrs)
+{
+	unsigned long user_count = vma_pages(vma);
+	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
+	unsigned long pfn = page_to_pfn(virt_to_page(cpu_addr));
+	unsigned long off = vma->vm_pgoff;
+	int ret = -ENXIO;
+
+	if (off < count && user_count <= (count - off)) {
+		ret = remap_pfn_range(vma, vma->vm_start,
+				      pfn + off,
+				      user_count << PAGE_SHIFT,
+				      vma->vm_page_prot);
+	}
+
+	return ret;
+}
+
 const struct dma_map_ops dma_noop_ops = {
 	.alloc			= dma_noop_alloc,
 	.free			= dma_noop_free,
@@ -73,6 +93,7 @@ const struct dma_map_ops dma_noop_ops = {
 	.map_sg			= dma_noop_map_sg,
 	.mapping_error		= dma_noop_mapping_error,
 	.dma_supported		= dma_noop_supported,
+	.mmap			= dma_noop_mmap,
 };
 
 EXPORT_SYMBOL(dma_noop_ops);
-- 
2.0.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v5 0/7] ARM: Fix dma_alloc_coherent() and friends for NOMMU Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 12:30 +0200
  [PATCH v5 6/7] ARM: NOMMU: Set ARM_DMA_MEM_BUFFERABLE for M-class cpus Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 12:30 +0200
  [PATCH v5 2/7] dma: Add simple dma_noop_mmap Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 13:10 +0200
  [PATCH v5 4/7] drivers: dma-coherent: Introduce default DMA pool Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 13:10 +0200
  [PATCH v5 7/7] ARM: dma-mapping: Remove traces of NOMMU code Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 13:10 +0200
  [PATCH v5 3/7] drivers: dma-coherent: Account dma_pfn_offset when used with device tree Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 13:10 +0200
  [PATCH v5 5/7] ARM: NOMMU: Introduce dma operations for noMMU Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 13:10 +0200
  [PATCH v5 1/7] dma: Take into account dma_pfn_offset Vladimir Murzin <vladimir.murzin@arm.com> - 2017-05-24 13:10 +0200

csiph-web