All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Kara <jack@suse.cz>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Pawel Osciak <pawel@osciak.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Subject: [PATCH 3/9] [media] vb2: Provide helpers for mapping virtual addresses
Date: Wed, 10 Jun 2015 06:20:46 -0300	[thread overview]
Message-ID: <76f634393be69e0852566d910d46145f33649ce1.1433927458.git.mchehab@osg.samsung.com> (raw)
In-Reply-To: <cover.1433927458.git.mchehab@osg.samsung.com>
In-Reply-To: <cover.1433927458.git.mchehab@osg.samsung.com>

From: Jan Kara <jack@suse.cz>

Provide simple helper functions to map virtual address range into an
array of pfns / pages.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/v4l2-core/videobuf2-memops.c b/drivers/media/v4l2-core/videobuf2-memops.c
index 81c1ad8b2cf1..0ec186d41b9b 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -137,6 +137,64 @@ int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
 EXPORT_SYMBOL_GPL(vb2_get_contig_userptr);
 
 /**
+ * vb2_create_framevec() - map virtual addresses to pfns
+ * @start:	Virtual user address where we start mapping
+ * @length:	Length of a range to map
+ * @write:	Should we map for writing into the area
+ *
+ * This function allocates and fills in a vector with pfns corresponding to
+ * virtual address range passed in arguments. If pfns have corresponding pages,
+ * page references are also grabbed to pin pages in memory. The function
+ * returns pointer to the vector on success and error pointer in case of
+ * failure. Returned vector needs to be freed via vb2_destroy_pfnvec().
+ */
+struct frame_vector *vb2_create_framevec(unsigned long start,
+					 unsigned long length,
+					 bool write)
+{
+	int ret;
+	unsigned long first, last;
+	unsigned long nr;
+	struct frame_vector *vec;
+
+	first = start >> PAGE_SHIFT;
+	last = (start + length - 1) >> PAGE_SHIFT;
+	nr = last - first + 1;
+	vec = frame_vector_create(nr);
+	if (!vec)
+		return ERR_PTR(-ENOMEM);
+	ret = get_vaddr_frames(start, nr, write, 1, vec);
+	if (ret < 0)
+		goto out_destroy;
+	/* We accept only complete set of PFNs */
+	if (ret != nr) {
+		ret = -EFAULT;
+		goto out_release;
+	}
+	return vec;
+out_release:
+	put_vaddr_frames(vec);
+out_destroy:
+	frame_vector_destroy(vec);
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL(vb2_create_framevec);
+
+/**
+ * vb2_destroy_framevec() - release vector of mapped pfns
+ * @vec:	vector of pfns / pages to release
+ *
+ * This releases references to all pages in the vector @vec (if corresponding
+ * pfns are backed by pages) and frees the passed vector.
+ */
+void vb2_destroy_framevec(struct frame_vector *vec)
+{
+	put_vaddr_frames(vec);
+	frame_vector_destroy(vec);
+}
+EXPORT_SYMBOL(vb2_destroy_framevec);
+
+/**
  * vb2_common_vm_open() - increase refcount of the vma
  * @vma:	virtual memory region for the mapping
  *
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index f05444ca8c0c..2f0564ff5f31 100644
--- a/include/media/videobuf2-memops.h
+++ b/include/media/videobuf2-memops.h
@@ -15,6 +15,7 @@
 #define _MEDIA_VIDEOBUF2_MEMOPS_H
 
 #include <media/videobuf2-core.h>
+#include <linux/mm.h>
 
 /**
  * vb2_vmarea_handler - common vma refcount tracking handler
@@ -36,5 +37,9 @@ int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
 struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma);
 void vb2_put_vma(struct vm_area_struct *vma);
 
+struct frame_vector *vb2_create_framevec(unsigned long start,
+					 unsigned long length,
+					 bool write);
+void vb2_destroy_framevec(struct frame_vector *vec);
 
 #endif
-- 
2.4.2


  parent reply	other threads:[~2015-06-10  9:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10  9:20 [PATCH 0/9] Helper to abstract vma handling in media layer Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 1/9] mm: Provide new get_vaddr_frames() helper Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-11  8:01   ` Sergey Senozhatsky
2015-06-11  8:01     ` Sergey Senozhatsky
2015-06-10  9:20 ` [PATCH 2/9] [media] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() Mauro Carvalho Chehab
2015-06-11  4:21   ` Laurent Pinchart
2015-06-11 17:23     ` Hans Verkuil
2015-06-12  9:21     ` Tomi Valkeinen
2015-06-12  9:26       ` Laurent Pinchart
2015-06-12  9:44         ` Tomi Valkeinen
2015-06-10  9:20 ` Mauro Carvalho Chehab [this message]
2015-06-10  9:20 ` [PATCH 4/9] [media] media: vb2: Convert vb2_dma_sg_get_userptr() to use frame vector Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 5/9] [media] media: vb2: Convert vb2_vmalloc_get_userptr() " Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 6/9] [media] media: vb2: Convert vb2_dc_get_userptr() " Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 7/9] [media] media: vb2: Remove unused functions Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 8/9] [media] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames() Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 9/9] [media] mm: Move get_vaddr_frames() behind a config option Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10 16:37   ` Josh Triplett
2015-06-10 16:37     ` Josh Triplett
2015-06-10 16:37     ` Josh Triplett
2015-06-10 16:37     ` Josh Triplett
2015-06-18 13:44     ` Jan Kara
2015-06-18 13:44       ` Jan Kara
2015-06-18 13:44       ` Jan Kara
2015-06-18 13:44       ` Jan Kara
2015-06-11  9:08 ` [PATCH 0/9] Helper to abstract vma handling in media layer Hans Verkuil
2015-06-11 18:54   ` Andrew Morton
2015-06-11 19:51     ` Hans Verkuil
2015-06-15  7:41 ` Hans Verkuil
2015-06-22 22:04 ` Andrew Morton

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=76f634393be69e0852566d910d46145f33649ce1.1433927458.git.mchehab@osg.samsung.com \
    --to=mchehab@osg.samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=hans.verkuil@cisco.com \
    --cc=jack@suse.cz \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@infradead.org \
    --cc=pawel@osciak.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.