From: Jan Kara <jack@suse.cz>
To: linux-mm@kvack.org
Cc: linux-media@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl>,
dri-devel@lists.freedesktop.org, Pawel Osciak <pawel@osciak.com>,
Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
mgorman@suse.de, Marek Szyprowski <m.szyprowski@samsung.com>,
linux-samsung-soc@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: [PATCH 4/9] vb2: Provide helpers for mapping virtual addresses
Date: Wed, 13 May 2015 15:08:10 +0200 [thread overview]
Message-ID: <1431522495-4692-5-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1431522495-4692-1-git-send-email-jack@suse.cz>
Provide simple helper functions to map virtual address range into an
array of pfns / pages.
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
drivers/media/v4l2-core/videobuf2-memops.c | 58 ++++++++++++++++++++++++++++++
include/media/videobuf2-memops.h | 5 +++
2 files changed, 63 insertions(+)
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.1.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-05-13 13:08 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 13:08 [PATCH 0/9 v5] Helper to abstract vma handling in media layer Jan Kara
2015-05-13 13:08 ` [PATCH 1/9] [media] vb2: Push mmap_sem down to memops Jan Kara
2015-05-13 13:08 ` [PATCH 2/9] mm: Provide new get_vaddr_frames() helper Jan Kara
2015-05-28 23:24 ` Andrew Morton
2015-06-01 12:40 ` Jan Kara
2015-06-01 13:02 ` Hans Verkuil
2015-06-02 15:23 ` Jan Kara
2015-06-02 22:29 ` Andrew Morton
2015-06-03 9:34 ` Jan Kara
2015-05-13 13:08 ` [PATCH 3/9] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() Jan Kara
2015-05-13 13:08 ` Jan Kara [this message]
2015-05-13 13:08 ` [PATCH 5/9] media: vb2: Convert vb2_dma_sg_get_userptr() to use frame vector Jan Kara
2015-05-13 13:08 ` [PATCH 6/9] media: vb2: Convert vb2_vmalloc_get_userptr() " Jan Kara
2015-05-13 13:08 ` [PATCH 7/9] media: vb2: Convert vb2_dc_get_userptr() " Jan Kara
2015-05-13 13:08 ` [PATCH 8/9] media: vb2: Remove unused functions Jan Kara
2015-05-13 13:08 ` [PATCH 9/9] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames() Jan Kara
2015-05-14 10:51 ` Inki Dae
2015-05-14 11:39 ` Jan Kara
2015-06-10 9:07 ` Hans Verkuil
2015-05-25 11:37 ` [PATCH 0/9 v5] Helper to abstract vma handling in media layer Hans Verkuil
2015-05-25 13:55 ` Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2015-07-13 14:55 [PATCH 0/9 v7] " Jan Kara
2015-07-13 14:55 ` [PATCH 4/9] vb2: Provide helpers for mapping virtual addresses Jan Kara
2015-05-06 7:28 [PATCH 0/9 v4] Helper to abstract vma handling in media layer Jan Kara
2015-05-06 7:28 ` [PATCH 4/9] vb2: Provide helpers for mapping virtual addresses Jan Kara
2015-05-05 16:01 [PATCH 0/9 v3] Helper to abstract vma handling in media layer Jan Kara
2015-05-05 16:01 ` [PATCH 4/9] vb2: Provide helpers for mapping virtual addresses Jan Kara
2015-03-17 11:56 [PATCH 0/9 v2] Helper to abstract vma handling in media layer Jan Kara
2015-03-17 11:56 ` [PATCH 4/9] vb2: Provide helpers for mapping virtual addresses Jan Kara
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=1431522495-4692-5-git-send-email-jack@suse.cz \
--to=jack@suse.cz \
--cc=dri-devel@lists.freedesktop.org \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@osg.samsung.com \
--cc=mgorman@suse.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).