@@ -986,6 +986,52 @@ void vb2_discard_done(struct vb2_queue *q)
}
EXPORT_SYMBOL_GPL(vb2_discard_done);
+int vb2_buffer_access_request(struct vb2_buffer *vb)
+{
+ struct vb2_queue *q = vb->vb2_queue;
+ unsigned int plane;
+ int ret;
+
+ /* Only dmabuf-imported buffers need to be mapped before access. */
+ if (q->memory != VB2_MEMORY_DMABUF)
+ return -EINVAL;
+
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ if (vb->planes[plane].dbuf_mapped)
+ continue;
+
+ ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
+ if (ret) {
+ dprintk(1, "failed to map dmabuf for plane %d\n",
+ plane);
+ return ret;
+ }
+ vb->planes[plane].dbuf_mapped = 1;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(vb2_buffer_access_request);
+
+void vb2_buffer_access_release(struct vb2_buffer *vb)
+{
+ struct vb2_queue *q = vb->vb2_queue;
+ unsigned int plane;
+
+ /* Only dmabuf-imported buffers need to be unmapped after access. */
+ if (q->memory != VB2_MEMORY_DMABUF)
+ return;
+
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ if (!vb->planes[plane].dbuf_mapped)
+ continue;
+
+ call_void_memop(vb, unmap_dmabuf, vb->planes[plane].mem_priv);
+ vb->planes[plane].dbuf_mapped = 0;
+ }
+}
+EXPORT_SYMBOL_GPL(vb2_buffer_access_release);
+
/*
* __prepare_mmap() - prepare an MMAP buffer
*/
@@ -1199,4 +1199,19 @@ bool vb2_request_object_is_buffer(struct media_request_object *obj);
*/
unsigned int vb2_request_buffer_cnt(struct media_request *req);
+/**
+ * vb2_buffer_access_request() - request out-of-band data access to a buffer
+ *
+ * @vb: buffer to request data access for
+ */
+int vb2_buffer_access_request(struct vb2_buffer *vb);
+
+
+/**
+ * vb2_buffer_access_release() - release out-of-band data access to a buffer
+ *
+ * @vb: buffer to release data access for
+ */
+void vb2_buffer_access_release(struct vb2_buffer *vb);
+
#endif /* _MEDIA_VIDEOBUF2_CORE_H */
Introduce helpers to request and release access to buffers that are not currently selected as current output or capture buffers. This is useful to ensure proper access to buffers imported via dma-buf that are used as reference and thus require associated map/unmap calls before access. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> --- .../media/common/videobuf2/videobuf2-core.c | 46 +++++++++++++++++++ include/media/videobuf2-core.h | 15 ++++++ 2 files changed, 61 insertions(+)