aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Semwal <sumit.semwal@ti.com>2012-06-14 09:37:35 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-11-25 14:10:36 -0500
commit051c7788bcb92f2e98ef86e86651e0420765b121 (patch)
tree4ebf8044c62975ff4a0613fcf8ec1aca84910a97
parent1323024fd3296537dd34da70fe70b4df12a308ec (diff)
[media] v4l: Add DMABUF as a memory type
Adds DMABUF memory type to v4l framework. Also adds the related file descriptor in v4l2_plane and v4l2_buffer. [original work in the PoC for buffer sharing] Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com> Signed-off-by: Sumit Semwal <sumit.semwal@ti.com> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Tested-by: Mauro Carvalho Chehab <mchehab@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/v4l2-core/v4l2-compat-ioctl32.c18
-rw-r--r--drivers/media/v4l2-core/v4l2-ioctl.c1
-rw-r--r--include/uapi/linux/videodev2.h7
3 files changed, 26 insertions, 0 deletions
diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 83ffb6436baf..cc5998b31463 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -297,6 +297,7 @@ struct v4l2_plane32 {
297 union { 297 union {
298 __u32 mem_offset; 298 __u32 mem_offset;
299 compat_long_t userptr; 299 compat_long_t userptr;
300 __s32 fd;
300 } m; 301 } m;
301 __u32 data_offset; 302 __u32 data_offset;
302 __u32 reserved[11]; 303 __u32 reserved[11];
@@ -318,6 +319,7 @@ struct v4l2_buffer32 {
318 __u32 offset; 319 __u32 offset;
319 compat_long_t userptr; 320 compat_long_t userptr;
320 compat_caddr_t planes; 321 compat_caddr_t planes;
322 __s32 fd;
321 } m; 323 } m;
322 __u32 length; 324 __u32 length;
323 __u32 reserved2; 325 __u32 reserved2;
@@ -341,6 +343,9 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
341 up_pln = compat_ptr(p); 343 up_pln = compat_ptr(p);
342 if (put_user((unsigned long)up_pln, &up->m.userptr)) 344 if (put_user((unsigned long)up_pln, &up->m.userptr))
343 return -EFAULT; 345 return -EFAULT;
346 } else if (memory == V4L2_MEMORY_DMABUF) {
347 if (copy_in_user(&up->m.fd, &up32->m.fd, sizeof(int)))
348 return -EFAULT;
344 } else { 349 } else {
345 if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset, 350 if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset,
346 sizeof(__u32))) 351 sizeof(__u32)))
@@ -364,6 +369,11 @@ static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
364 if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset, 369 if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset,
365 sizeof(__u32))) 370 sizeof(__u32)))
366 return -EFAULT; 371 return -EFAULT;
372 /* For DMABUF, driver might've set up the fd, so copy it back. */
373 if (memory == V4L2_MEMORY_DMABUF)
374 if (copy_in_user(&up32->m.fd, &up->m.fd,
375 sizeof(int)))
376 return -EFAULT;
367 377
368 return 0; 378 return 0;
369} 379}
@@ -446,6 +456,10 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
446 if (get_user(kp->m.offset, &up->m.offset)) 456 if (get_user(kp->m.offset, &up->m.offset))
447 return -EFAULT; 457 return -EFAULT;
448 break; 458 break;
459 case V4L2_MEMORY_DMABUF:
460 if (get_user(kp->m.fd, &up->m.fd))
461 return -EFAULT;
462 break;
449 } 463 }
450 } 464 }
451 465
@@ -510,6 +524,10 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
510 if (put_user(kp->m.offset, &up->m.offset)) 524 if (put_user(kp->m.offset, &up->m.offset))
511 return -EFAULT; 525 return -EFAULT;
512 break; 526 break;
527 case V4L2_MEMORY_DMABUF:
528 if (put_user(kp->m.fd, &up->m.fd))
529 return -EFAULT;
530 break;
513 } 531 }
514 } 532 }
515 533
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 8f388ff31ebb..530a67e3fe0e 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -155,6 +155,7 @@ static const char *v4l2_memory_names[] = {
155 [V4L2_MEMORY_MMAP] = "mmap", 155 [V4L2_MEMORY_MMAP] = "mmap",
156 [V4L2_MEMORY_USERPTR] = "userptr", 156 [V4L2_MEMORY_USERPTR] = "userptr",
157 [V4L2_MEMORY_OVERLAY] = "overlay", 157 [V4L2_MEMORY_OVERLAY] = "overlay",
158 [V4L2_MEMORY_DMABUF] = "dmabuf",
158}; 159};
159 160
160#define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown") 161#define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 2fff7ff3e05b..91ac83b21c20 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -186,6 +186,7 @@ enum v4l2_memory {
186 V4L2_MEMORY_MMAP = 1, 186 V4L2_MEMORY_MMAP = 1,
187 V4L2_MEMORY_USERPTR = 2, 187 V4L2_MEMORY_USERPTR = 2,
188 V4L2_MEMORY_OVERLAY = 3, 188 V4L2_MEMORY_OVERLAY = 3,
189 V4L2_MEMORY_DMABUF = 4,
189}; 190};
190 191
191/* see also http://vektor.theorem.ca/graphics/ycbcr/ */ 192/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
@@ -602,6 +603,8 @@ struct v4l2_requestbuffers {
602 * should be passed to mmap() called on the video node) 603 * should be passed to mmap() called on the video node)
603 * @userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer 604 * @userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer
604 * pointing to this plane 605 * pointing to this plane
606 * @fd: when memory is V4L2_MEMORY_DMABUF, a userspace file
607 * descriptor associated with this plane
605 * @data_offset: offset in the plane to the start of data; usually 0, 608 * @data_offset: offset in the plane to the start of data; usually 0,
606 * unless there is a header in front of the data 609 * unless there is a header in front of the data
607 * 610 *
@@ -616,6 +619,7 @@ struct v4l2_plane {
616 union { 619 union {
617 __u32 mem_offset; 620 __u32 mem_offset;
618 unsigned long userptr; 621 unsigned long userptr;
622 __s32 fd;
619 } m; 623 } m;
620 __u32 data_offset; 624 __u32 data_offset;
621 __u32 reserved[11]; 625 __u32 reserved[11];
@@ -640,6 +644,8 @@ struct v4l2_plane {
640 * (or a "cookie" that should be passed to mmap() as offset) 644 * (or a "cookie" that should be passed to mmap() as offset)
641 * @userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR; 645 * @userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR;
642 * a userspace pointer pointing to this buffer 646 * a userspace pointer pointing to this buffer
647 * @fd: for non-multiplanar buffers with memory == V4L2_MEMORY_DMABUF;
648 * a userspace file descriptor associated with this buffer
643 * @planes: for multiplanar buffers; userspace pointer to the array of plane 649 * @planes: for multiplanar buffers; userspace pointer to the array of plane
644 * info structs for this buffer 650 * info structs for this buffer
645 * @length: size in bytes of the buffer (NOT its payload) for single-plane 651 * @length: size in bytes of the buffer (NOT its payload) for single-plane
@@ -666,6 +672,7 @@ struct v4l2_buffer {
666 __u32 offset; 672 __u32 offset;
667 unsigned long userptr; 673 unsigned long userptr;
668 struct v4l2_plane *planes; 674 struct v4l2_plane *planes;
675 __s32 fd;
669 } m; 676 } m;
670 __u32 length; 677 __u32 length;
671 __u32 reserved2; 678 __u32 reserved2;