aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-09-08 12:34:37 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-09-09 09:14:50 -0400
commit88b7eb092efb8197d29d5202d77d1fb919419ec5 (patch)
tree73e5b438b8b22bd3b264a59f17abd0c2d07aecc9
parentbcb53f07080bb3413f00e2e95c2c6f56eb20c9e5 (diff)
[media] videobuf2-core.h: move function descriptions from c file
There are several functions that were documented at the .c file. As we only include the headers, we need to move them to there, in order to have documentation. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c254
-rw-r--r--include/media/videobuf2-core.h269
2 files changed, 269 insertions, 254 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index bfe85879c563..21900202ff83 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -528,10 +528,6 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
528 return 0; 528 return 0;
529} 529}
530 530
531/**
532 * vb2_buffer_in_use() - return true if the buffer is in use and
533 * the queue cannot be freed (by the means of REQBUFS(0)) call
534 */
535bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb) 531bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
536{ 532{
537 unsigned int plane; 533 unsigned int plane;
@@ -564,16 +560,6 @@ static bool __buffers_in_use(struct vb2_queue *q)
564 return false; 560 return false;
565} 561}
566 562
567/**
568 * vb2_core_querybuf() - query video buffer information
569 * @q: videobuf queue
570 * @index: id number of the buffer
571 * @pb: buffer struct passed from userspace
572 *
573 * Should be called from vidioc_querybuf ioctl handler in driver.
574 * The passed buffer should have been verified.
575 * This function fills the relevant information for the userspace.
576 */
577void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb) 563void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb)
578{ 564{
579 call_void_bufop(q, fill_user_buffer, q->bufs[index], pb); 565 call_void_bufop(q, fill_user_buffer, q->bufs[index], pb);
@@ -620,10 +606,6 @@ static int __verify_dmabuf_ops(struct vb2_queue *q)
620 return 0; 606 return 0;
621} 607}
622 608
623/**
624 * vb2_verify_memory_type() - Check whether the memory type and buffer type
625 * passed to a buffer operation are compatible with the queue.
626 */
627int vb2_verify_memory_type(struct vb2_queue *q, 609int vb2_verify_memory_type(struct vb2_queue *q,
628 enum vb2_memory memory, unsigned int type) 610 enum vb2_memory memory, unsigned int type)
629{ 611{
@@ -670,30 +652,6 @@ int vb2_verify_memory_type(struct vb2_queue *q,
670} 652}
671EXPORT_SYMBOL(vb2_verify_memory_type); 653EXPORT_SYMBOL(vb2_verify_memory_type);
672 654
673/**
674 * vb2_core_reqbufs() - Initiate streaming
675 * @q: videobuf2 queue
676 * @memory: memory type
677 * @count: requested buffer count
678 *
679 * Should be called from vidioc_reqbufs ioctl handler of a driver.
680 * This function:
681 * 1) verifies streaming parameters passed from the userspace,
682 * 2) sets up the queue,
683 * 3) negotiates number of buffers and planes per buffer with the driver
684 * to be used during streaming,
685 * 4) allocates internal buffer structures (struct vb2_buffer), according to
686 * the agreed parameters,
687 * 5) for MMAP memory type, allocates actual video memory, using the
688 * memory handling/allocation routines provided during queue initialization
689 *
690 * If req->count is 0, all the memory will be freed instead.
691 * If the queue has been allocated previously (by a previous vb2_reqbufs) call
692 * and the queue is not busy, memory will be reallocated.
693 *
694 * The return values from this function are intended to be directly returned
695 * from vidioc_reqbufs handler in driver.
696 */
697int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, 655int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
698 unsigned int *count) 656 unsigned int *count)
699{ 657{
@@ -819,22 +777,6 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
819} 777}
820EXPORT_SYMBOL_GPL(vb2_core_reqbufs); 778EXPORT_SYMBOL_GPL(vb2_core_reqbufs);
821 779
822/**
823 * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
824 * @q: videobuf2 queue
825 * @memory: memory type
826 * @count: requested buffer count
827 * @parg: parameter passed to device driver
828 *
829 * Should be called from vidioc_create_bufs ioctl handler of a driver.
830 * This function:
831 * 1) verifies parameter sanity
832 * 2) calls the .queue_setup() queue operation
833 * 3) performs any necessary memory allocations
834 *
835 * The return values from this function are intended to be directly returned
836 * from vidioc_create_bufs handler in driver.
837 */
838int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, 780int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
839 unsigned int *count, unsigned requested_planes, 781 unsigned int *count, unsigned requested_planes,
840 const unsigned requested_sizes[]) 782 const unsigned requested_sizes[])
@@ -924,14 +866,6 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
924} 866}
925EXPORT_SYMBOL_GPL(vb2_core_create_bufs); 867EXPORT_SYMBOL_GPL(vb2_core_create_bufs);
926 868
927/**
928 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
929 * @vb: vb2_buffer to which the plane in question belongs to
930 * @plane_no: plane number for which the address is to be returned
931 *
932 * This function returns a kernel virtual address of a given plane if
933 * such a mapping exist, NULL otherwise.
934 */
935void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no) 869void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
936{ 870{
937 if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv) 871 if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
@@ -942,17 +876,6 @@ void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
942} 876}
943EXPORT_SYMBOL_GPL(vb2_plane_vaddr); 877EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
944 878
945/**
946 * vb2_plane_cookie() - Return allocator specific cookie for the given plane
947 * @vb: vb2_buffer to which the plane in question belongs to
948 * @plane_no: plane number for which the cookie is to be returned
949 *
950 * This function returns an allocator specific cookie for a given plane if
951 * available, NULL otherwise. The allocator should provide some simple static
952 * inline function, which would convert this cookie to the allocator specific
953 * type that can be used directly by the driver to access the buffer. This can
954 * be for example physical address, pointer to scatter list or IOMMU mapping.
955 */
956void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no) 879void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
957{ 880{
958 if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv) 881 if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
@@ -962,26 +885,6 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
962} 885}
963EXPORT_SYMBOL_GPL(vb2_plane_cookie); 886EXPORT_SYMBOL_GPL(vb2_plane_cookie);
964 887
965/**
966 * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
967 * @vb: vb2_buffer returned from the driver
968 * @state: either VB2_BUF_STATE_DONE if the operation finished successfully,
969 * VB2_BUF_STATE_ERROR if the operation finished with an error or
970 * VB2_BUF_STATE_QUEUED if the driver wants to requeue buffers.
971 * If start_streaming fails then it should return buffers with state
972 * VB2_BUF_STATE_QUEUED to put them back into the queue.
973 *
974 * This function should be called by the driver after a hardware operation on
975 * a buffer is finished and the buffer may be returned to userspace. The driver
976 * cannot use this buffer anymore until it is queued back to it by videobuf
977 * by the means of buf_queue callback. Only buffers previously queued to the
978 * driver by buf_queue can be passed to this function.
979 *
980 * While streaming a buffer can only be returned in state DONE or ERROR.
981 * The start_streaming op can also return them in case the DMA engine cannot
982 * be started for some reason. In that case the buffers should be returned with
983 * state QUEUED.
984 */
985void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) 888void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
986{ 889{
987 struct vb2_queue *q = vb->vb2_queue; 890 struct vb2_queue *q = vb->vb2_queue;
@@ -1040,18 +943,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
1040} 943}
1041EXPORT_SYMBOL_GPL(vb2_buffer_done); 944EXPORT_SYMBOL_GPL(vb2_buffer_done);
1042 945
1043/**
1044 * vb2_discard_done() - discard all buffers marked as DONE
1045 * @q: videobuf2 queue
1046 *
1047 * This function is intended to be used with suspend/resume operations. It
1048 * discards all 'done' buffers as they would be too old to be requested after
1049 * resume.
1050 *
1051 * Drivers must stop the hardware and synchronize with interrupt handlers and/or
1052 * delayed works before calling this function to make sure no buffer will be
1053 * touched by the driver and/or hardware.
1054 */
1055void vb2_discard_done(struct vb2_queue *q) 946void vb2_discard_done(struct vb2_queue *q)
1056{ 947{
1057 struct vb2_buffer *vb; 948 struct vb2_buffer *vb;
@@ -1384,22 +1275,6 @@ static int __buf_prepare(struct vb2_buffer *vb, const void *pb)
1384 return ret; 1275 return ret;
1385} 1276}
1386 1277
1387/**
1388 * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace
1389 * to the kernel
1390 * @q: videobuf2 queue
1391 * @index: id number of the buffer
1392 * @pb: buffer structure passed from userspace to vidioc_prepare_buf
1393 * handler in driver
1394 *
1395 * Should be called from vidioc_prepare_buf ioctl handler of a driver.
1396 * The passed buffer should have been verified.
1397 * This function calls buf_prepare callback in the driver (if provided),
1398 * in which driver-specific buffer initialization can be performed,
1399 *
1400 * The return values from this function are intended to be directly returned
1401 * from vidioc_prepare_buf handler in driver.
1402 */
1403int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) 1278int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb)
1404{ 1279{
1405 struct vb2_buffer *vb; 1280 struct vb2_buffer *vb;
@@ -1488,24 +1363,6 @@ static int vb2_start_streaming(struct vb2_queue *q)
1488 return ret; 1363 return ret;
1489} 1364}
1490 1365
1491/**
1492 * vb2_core_qbuf() - Queue a buffer from userspace
1493 * @q: videobuf2 queue
1494 * @index: id number of the buffer
1495 * @pb: buffer structure passed from userspace to vidioc_qbuf handler
1496 * in driver
1497 *
1498 * Should be called from vidioc_qbuf ioctl handler of a driver.
1499 * The passed buffer should have been verified.
1500 * This function:
1501 * 1) if necessary, calls buf_prepare callback in the driver (if provided), in
1502 * which driver-specific buffer initialization can be performed,
1503 * 2) if streaming is on, queues the buffer in driver by the means of buf_queue
1504 * callback for processing.
1505 *
1506 * The return values from this function are intended to be directly returned
1507 * from vidioc_qbuf handler in driver.
1508 */
1509int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) 1366int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb)
1510{ 1367{
1511 struct vb2_buffer *vb; 1368 struct vb2_buffer *vb;
@@ -1686,15 +1543,6 @@ static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
1686 return ret; 1543 return ret;
1687} 1544}
1688 1545
1689/**
1690 * vb2_wait_for_all_buffers() - wait until all buffers are given back to vb2
1691 * @q: videobuf2 queue
1692 *
1693 * This function will wait until all buffers that have been given to the driver
1694 * by buf_queue() are given back to vb2 with vb2_buffer_done(). It doesn't call
1695 * wait_prepare, wait_finish pair. It is intended to be called with all locks
1696 * taken, for example from stop_streaming() callback.
1697 */
1698int vb2_wait_for_all_buffers(struct vb2_queue *q) 1546int vb2_wait_for_all_buffers(struct vb2_queue *q)
1699{ 1547{
1700 if (!q->streaming) { 1548 if (!q->streaming) {
@@ -1732,28 +1580,6 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
1732 } 1580 }
1733} 1581}
1734 1582
1735/**
1736 * vb2_core_dqbuf() - Dequeue a buffer to the userspace
1737 * @q: videobuf2 queue
1738 * @pindex: pointer to the buffer index. May be NULL
1739 * @pb: buffer structure passed from userspace to vidioc_dqbuf handler
1740 * in driver
1741 * @nonblocking: if true, this call will not sleep waiting for a buffer if no
1742 * buffers ready for dequeuing are present. Normally the driver
1743 * would be passing (file->f_flags & O_NONBLOCK) here
1744 *
1745 * Should be called from vidioc_dqbuf ioctl handler of a driver.
1746 * The passed buffer should have been verified.
1747 * This function:
1748 * 1) calls buf_finish callback in the driver (if provided), in which
1749 * driver can perform any additional operations that may be required before
1750 * returning the buffer to userspace, such as cache sync,
1751 * 2) the buffer struct members are filled with relevant information for
1752 * the userspace.
1753 *
1754 * The return values from this function are intended to be directly returned
1755 * from vidioc_dqbuf handler in driver.
1756 */
1757int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, 1583int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
1758 bool nonblocking) 1584 bool nonblocking)
1759{ 1585{
@@ -1917,19 +1743,6 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
1917} 1743}
1918EXPORT_SYMBOL_GPL(vb2_core_streamon); 1744EXPORT_SYMBOL_GPL(vb2_core_streamon);
1919 1745
1920/**
1921 * vb2_queue_error() - signal a fatal error on the queue
1922 * @q: videobuf2 queue
1923 *
1924 * Flag that a fatal unrecoverable error has occurred and wake up all processes
1925 * waiting on the queue. Polling will now set POLLERR and queuing and dequeuing
1926 * buffers will return -EIO.
1927 *
1928 * The error flag will be cleared when cancelling the queue, either from
1929 * vb2_streamoff or vb2_queue_release. Drivers should thus not call this
1930 * function before starting the stream, otherwise the error flag will remain set
1931 * until the queue is released when closing the device node.
1932 */
1933void vb2_queue_error(struct vb2_queue *q) 1746void vb2_queue_error(struct vb2_queue *q)
1934{ 1747{
1935 q->error = 1; 1748 q->error = 1;
@@ -1992,19 +1805,6 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
1992 return -EINVAL; 1805 return -EINVAL;
1993} 1806}
1994 1807
1995/**
1996 * vb2_core_expbuf() - Export a buffer as a file descriptor
1997 * @q: videobuf2 queue
1998 * @fd: file descriptor associated with DMABUF (set by driver) *
1999 * @type: buffer type
2000 * @index: id number of the buffer
2001 * @plane: index of the plane to be exported, 0 for single plane queues
2002 * @flags: flags for newly created file, currently only O_CLOEXEC is
2003 * supported, refer to manual of open syscall for more details
2004 *
2005 * The return values from this function are intended to be directly returned
2006 * from vidioc_expbuf handler in driver.
2007 */
2008int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, 1808int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2009 unsigned int index, unsigned int plane, unsigned int flags) 1809 unsigned int index, unsigned int plane, unsigned int flags)
2010{ 1810{
@@ -2076,25 +1876,6 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
2076} 1876}
2077EXPORT_SYMBOL_GPL(vb2_core_expbuf); 1877EXPORT_SYMBOL_GPL(vb2_core_expbuf);
2078 1878
2079/**
2080 * vb2_mmap() - map video buffers into application address space
2081 * @q: videobuf2 queue
2082 * @vma: vma passed to the mmap file operation handler in the driver
2083 *
2084 * Should be called from mmap file operation handler of a driver.
2085 * This function maps one plane of one of the available video buffers to
2086 * userspace. To map whole video memory allocated on reqbufs, this function
2087 * has to be called once per each plane per each buffer previously allocated.
2088 *
2089 * When the userspace application calls mmap, it passes to it an offset returned
2090 * to it earlier by the means of vidioc_querybuf handler. That offset acts as
2091 * a "cookie", which is then used to identify the plane to be mapped.
2092 * This function finds a plane with a matching offset and a mapping is performed
2093 * by the means of a provided memory operation.
2094 *
2095 * The return values from this function are intended to be directly returned
2096 * from the mmap handler in driver.
2097 */
2098int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) 1879int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
2099{ 1880{
2100 unsigned long off = vma->vm_pgoff << PAGE_SHIFT; 1881 unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
@@ -2196,17 +1977,6 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
2196EXPORT_SYMBOL_GPL(vb2_get_unmapped_area); 1977EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
2197#endif 1978#endif
2198 1979
2199/**
2200 * vb2_core_queue_init() - initialize a videobuf2 queue
2201 * @q: videobuf2 queue; this structure should be allocated in driver
2202 *
2203 * The vb2_queue structure should be allocated by the driver. The driver is
2204 * responsible of clearing it's content and setting initial values for some
2205 * required entries before calling this function.
2206 * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer
2207 * to the struct vb2_queue description in include/media/videobuf2-core.h
2208 * for more information.
2209 */
2210int vb2_core_queue_init(struct vb2_queue *q) 1980int vb2_core_queue_init(struct vb2_queue *q)
2211{ 1981{
2212 /* 1982 /*
@@ -2236,14 +2006,6 @@ EXPORT_SYMBOL_GPL(vb2_core_queue_init);
2236 2006
2237static int __vb2_init_fileio(struct vb2_queue *q, int read); 2007static int __vb2_init_fileio(struct vb2_queue *q, int read);
2238static int __vb2_cleanup_fileio(struct vb2_queue *q); 2008static int __vb2_cleanup_fileio(struct vb2_queue *q);
2239/**
2240 * vb2_core_queue_release() - stop streaming, release the queue and free memory
2241 * @q: videobuf2 queue
2242 *
2243 * This function stops streaming and performs necessary clean ups, including
2244 * freeing video buffer memory. The driver is responsible for freeing
2245 * the vb2_queue structure itself.
2246 */
2247void vb2_core_queue_release(struct vb2_queue *q) 2009void vb2_core_queue_release(struct vb2_queue *q)
2248{ 2010{
2249 __vb2_cleanup_fileio(q); 2011 __vb2_cleanup_fileio(q);
@@ -2254,22 +2016,6 @@ void vb2_core_queue_release(struct vb2_queue *q)
2254} 2016}
2255EXPORT_SYMBOL_GPL(vb2_core_queue_release); 2017EXPORT_SYMBOL_GPL(vb2_core_queue_release);
2256 2018
2257/**
2258 * vb2_core_poll() - implements poll userspace operation
2259 * @q: videobuf2 queue
2260 * @file: file argument passed to the poll file operation handler
2261 * @wait: wait argument passed to the poll file operation handler
2262 *
2263 * This function implements poll file operation handler for a driver.
2264 * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will
2265 * be informed that the file descriptor of a video device is available for
2266 * reading.
2267 * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
2268 * will be reported as available for writing.
2269 *
2270 * The return values from this function are intended to be directly returned
2271 * from poll handler in driver.
2272 */
2273unsigned int vb2_core_poll(struct vb2_queue *q, struct file *file, 2019unsigned int vb2_core_poll(struct vb2_queue *q, struct file *file,
2274 poll_table *wait) 2020 poll_table *wait)
2275{ 2021{
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index b6546db670ca..68f93dacb38f 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -536,35 +536,274 @@ struct vb2_queue {
536#endif 536#endif
537}; 537};
538 538
539/**
540 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
541 * @vb: vb2_buffer to which the plane in question belongs to
542 * @plane_no: plane number for which the address is to be returned
543 *
544 * This function returns a kernel virtual address of a given plane if
545 * such a mapping exist, NULL otherwise.
546 */
539void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no); 547void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
548
549/**
550 * vb2_plane_cookie() - Return allocator specific cookie for the given plane
551 * @vb: vb2_buffer to which the plane in question belongs to
552 * @plane_no: plane number for which the cookie is to be returned
553 *
554 * This function returns an allocator specific cookie for a given plane if
555 * available, NULL otherwise. The allocator should provide some simple static
556 * inline function, which would convert this cookie to the allocator specific
557 * type that can be used directly by the driver to access the buffer. This can
558 * be for example physical address, pointer to scatter list or IOMMU mapping.
559 */
540void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no); 560void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
541 561
562/**
563 * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
564 * @vb: vb2_buffer returned from the driver
565 * @state: either %VB2_BUF_STATE_DONE if the operation finished successfully,
566 * %VB2_BUF_STATE_ERROR if the operation finished with an error or
567 * %VB2_BUF_STATE_QUEUED if the driver wants to requeue buffers.
568 * If start_streaming fails then it should return buffers with state
569 * %VB2_BUF_STATE_QUEUED to put them back into the queue.
570 *
571 * This function should be called by the driver after a hardware operation on
572 * a buffer is finished and the buffer may be returned to userspace. The driver
573 * cannot use this buffer anymore until it is queued back to it by videobuf
574 * by the means of buf_queue callback. Only buffers previously queued to the
575 * driver by buf_queue can be passed to this function.
576 *
577 * While streaming a buffer can only be returned in state DONE or ERROR.
578 * The start_streaming op can also return them in case the DMA engine cannot
579 * be started for some reason. In that case the buffers should be returned with
580 * state QUEUED.
581 */
542void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state); 582void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
583
584/**
585 * vb2_discard_done() - discard all buffers marked as DONE
586 * @q: videobuf2 queue
587 *
588 * This function is intended to be used with suspend/resume operations. It
589 * discards all 'done' buffers as they would be too old to be requested after
590 * resume.
591 *
592 * Drivers must stop the hardware and synchronize with interrupt handlers and/or
593 * delayed works before calling this function to make sure no buffer will be
594 * touched by the driver and/or hardware.
595 */
543void vb2_discard_done(struct vb2_queue *q); 596void vb2_discard_done(struct vb2_queue *q);
597
598/**
599 * vb2_wait_for_all_buffers() - wait until all buffers are given back to vb2
600 * @q: videobuf2 queue
601 *
602 * This function will wait until all buffers that have been given to the driver
603 * by buf_queue() are given back to vb2 with vb2_buffer_done(). It doesn't call
604 * wait_prepare, wait_finish pair. It is intended to be called with all locks
605 * taken, for example from stop_streaming() callback.
606 */
544int vb2_wait_for_all_buffers(struct vb2_queue *q); 607int vb2_wait_for_all_buffers(struct vb2_queue *q);
545 608
609/**
610 * vb2_core_querybuf() - query video buffer information
611 * @q: videobuf queue
612 * @index: id number of the buffer
613 * @pb: buffer struct passed from userspace
614 *
615 * Should be called from vidioc_querybuf ioctl handler in driver.
616 * The passed buffer should have been verified.
617 * This function fills the relevant information for the userspace.
618 */
546void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); 619void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb);
620
621/**
622 * vb2_core_reqbufs() - Initiate streaming
623 * @q: videobuf2 queue
624 * @memory: memory type
625 * @count: requested buffer count
626 *
627 * Should be called from vidioc_reqbufs ioctl handler of a driver.
628 * This function:
629 * 1) verifies streaming parameters passed from the userspace,
630 * 2) sets up the queue,
631 * 3) negotiates number of buffers and planes per buffer with the driver
632 * to be used during streaming,
633 * 4) allocates internal buffer structures (struct vb2_buffer), according to
634 * the agreed parameters,
635 * 5) for MMAP memory type, allocates actual video memory, using the
636 * memory handling/allocation routines provided during queue initialization
637 *
638 * If req->count is 0, all the memory will be freed instead.
639 * If the queue has been allocated previously (by a previous vb2_reqbufs) call
640 * and the queue is not busy, memory will be reallocated.
641 *
642 * The return values from this function are intended to be directly returned
643 * from vidioc_reqbufs handler in driver.
644 */
547int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, 645int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
548 unsigned int *count); 646 unsigned int *count);
647
648/**
649 * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
650 * @q: videobuf2 queue
651 * @memory: memory type
652 * @count: requested buffer count
653 * @parg: parameter passed to device driver
654 *
655 * Should be called from vidioc_create_bufs ioctl handler of a driver.
656 * This function:
657 * 1) verifies parameter sanity
658 * 2) calls the .queue_setup() queue operation
659 * 3) performs any necessary memory allocations
660 *
661 * The return values from this function are intended to be directly returned
662 * from vidioc_create_bufs handler in driver.
663 */
549int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, 664int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
550 unsigned int *count, unsigned requested_planes, 665 unsigned int *count, unsigned requested_planes,
551 const unsigned int requested_sizes[]); 666 const unsigned int requested_sizes[]);
667
668/**
669 * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace
670 * to the kernel
671 * @q: videobuf2 queue
672 * @index: id number of the buffer
673 * @pb: buffer structure passed from userspace to vidioc_prepare_buf
674 * handler in driver
675 *
676 * Should be called from vidioc_prepare_buf ioctl handler of a driver.
677 * The passed buffer should have been verified.
678 * This function calls buf_prepare callback in the driver (if provided),
679 * in which driver-specific buffer initialization can be performed,
680 *
681 * The return values from this function are intended to be directly returned
682 * from vidioc_prepare_buf handler in driver.
683 */
552int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); 684int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb);
685
686/**
687 * vb2_core_qbuf() - Queue a buffer from userspace
688 * @q: videobuf2 queue
689 * @index: id number of the buffer
690 * @pb: buffer structure passed from userspace to vidioc_qbuf handler
691 * in driver
692 *
693 * Should be called from vidioc_qbuf ioctl handler of a driver.
694 * The passed buffer should have been verified.
695 * This function:
696 * 1) if necessary, calls buf_prepare callback in the driver (if provided), in
697 * which driver-specific buffer initialization can be performed,
698 * 2) if streaming is on, queues the buffer in driver by the means of buf_queue
699 * callback for processing.
700 *
701 * The return values from this function are intended to be directly returned
702 * from vidioc_qbuf handler in driver.
703 */
553int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb); 704int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb);
705
706/**
707 * vb2_core_dqbuf() - Dequeue a buffer to the userspace
708 * @q: videobuf2 queue
709 * @pindex: pointer to the buffer index. May be NULL
710 * @pb: buffer structure passed from userspace to vidioc_dqbuf handler
711 * in driver
712 * @nonblocking: if true, this call will not sleep waiting for a buffer if no
713 * buffers ready for dequeuing are present. Normally the driver
714 * would be passing (file->f_flags & O_NONBLOCK) here
715 *
716 * Should be called from vidioc_dqbuf ioctl handler of a driver.
717 * The passed buffer should have been verified.
718 * This function:
719 * 1) calls buf_finish callback in the driver (if provided), in which
720 * driver can perform any additional operations that may be required before
721 * returning the buffer to userspace, such as cache sync,
722 * 2) the buffer struct members are filled with relevant information for
723 * the userspace.
724 *
725 * The return values from this function are intended to be directly returned
726 * from vidioc_dqbuf handler in driver.
727 */
554int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, 728int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
555 bool nonblocking); 729 bool nonblocking);
556 730
557int vb2_core_streamon(struct vb2_queue *q, unsigned int type); 731int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
558int vb2_core_streamoff(struct vb2_queue *q, unsigned int type); 732int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
559 733
734/**
735 * vb2_core_expbuf() - Export a buffer as a file descriptor
736 * @q: videobuf2 queue
737 * @fd: file descriptor associated with DMABUF (set by driver) *
738 * @type: buffer type
739 * @index: id number of the buffer
740 * @plane: index of the plane to be exported, 0 for single plane queues
741 * @flags: flags for newly created file, currently only O_CLOEXEC is
742 * supported, refer to manual of open syscall for more details
743 *
744 * The return values from this function are intended to be directly returned
745 * from vidioc_expbuf handler in driver.
746 */
560int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, 747int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
561 unsigned int index, unsigned int plane, unsigned int flags); 748 unsigned int index, unsigned int plane, unsigned int flags);
562 749
750/**
751 * vb2_core_queue_init() - initialize a videobuf2 queue
752 * @q: videobuf2 queue; this structure should be allocated in driver
753 *
754 * The vb2_queue structure should be allocated by the driver. The driver is
755 * responsible of clearing it's content and setting initial values for some
756 * required entries before calling this function.
757 * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer
758 * to the struct vb2_queue description in include/media/videobuf2-core.h
759 * for more information.
760 */
563int vb2_core_queue_init(struct vb2_queue *q); 761int vb2_core_queue_init(struct vb2_queue *q);
762
763/**
764 * vb2_core_queue_release() - stop streaming, release the queue and free memory
765 * @q: videobuf2 queue
766 *
767 * This function stops streaming and performs necessary clean ups, including
768 * freeing video buffer memory. The driver is responsible for freeing
769 * the vb2_queue structure itself.
770 */
564void vb2_core_queue_release(struct vb2_queue *q); 771void vb2_core_queue_release(struct vb2_queue *q);
565 772
773/**
774 * vb2_queue_error() - signal a fatal error on the queue
775 * @q: videobuf2 queue
776 *
777 * Flag that a fatal unrecoverable error has occurred and wake up all processes
778 * waiting on the queue. Polling will now set POLLERR and queuing and dequeuing
779 * buffers will return -EIO.
780 *
781 * The error flag will be cleared when cancelling the queue, either from
782 * vb2_streamoff or vb2_queue_release. Drivers should thus not call this
783 * function before starting the stream, otherwise the error flag will remain set
784 * until the queue is released when closing the device node.
785 */
566void vb2_queue_error(struct vb2_queue *q); 786void vb2_queue_error(struct vb2_queue *q);
567 787
788/**
789 * vb2_mmap() - map video buffers into application address space
790 * @q: videobuf2 queue
791 * @vma: vma passed to the mmap file operation handler in the driver
792 *
793 * Should be called from mmap file operation handler of a driver.
794 * This function maps one plane of one of the available video buffers to
795 * userspace. To map whole video memory allocated on reqbufs, this function
796 * has to be called once per each plane per each buffer previously allocated.
797 *
798 * When the userspace application calls mmap, it passes to it an offset returned
799 * to it earlier by the means of vidioc_querybuf handler. That offset acts as
800 * a "cookie", which is then used to identify the plane to be mapped.
801 * This function finds a plane with a matching offset and a mapping is performed
802 * by the means of a provided memory operation.
803 *
804 * The return values from this function are intended to be directly returned
805 * from the mmap handler in driver.
806 */
568int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma); 807int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
569#ifndef CONFIG_MMU 808#ifndef CONFIG_MMU
570unsigned long vb2_get_unmapped_area(struct vb2_queue *q, 809unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
@@ -573,6 +812,23 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
573 unsigned long pgoff, 812 unsigned long pgoff,
574 unsigned long flags); 813 unsigned long flags);
575#endif 814#endif
815
816/**
817 * vb2_core_poll() - implements poll userspace operation
818 * @q: videobuf2 queue
819 * @file: file argument passed to the poll file operation handler
820 * @wait: wait argument passed to the poll file operation handler
821 *
822 * This function implements poll file operation handler for a driver.
823 * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will
824 * be informed that the file descriptor of a video device is available for
825 * reading.
826 * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
827 * will be reported as available for writing.
828 *
829 * The return values from this function are intended to be directly returned
830 * from poll handler in driver.
831 */
576unsigned int vb2_core_poll(struct vb2_queue *q, struct file *file, 832unsigned int vb2_core_poll(struct vb2_queue *q, struct file *file,
577 poll_table *wait); 833 poll_table *wait);
578size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count, 834size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
@@ -717,7 +973,20 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
717 * The following functions are not part of the vb2 core API, but are useful 973 * The following functions are not part of the vb2 core API, but are useful
718 * functions for videobuf2-*. 974 * functions for videobuf2-*.
719 */ 975 */
976
977/**
978 * vb2_buffer_in_use() - return true if the buffer is in use and
979 * the queue cannot be freed (by the means of REQBUFS(0)) call
980 *
981 * @vb: buffer for which plane size should be returned
982 * @q: videobuf queue
983 */
720bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb); 984bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
985
986/**
987 * vb2_verify_memory_type() - Check whether the memory type and buffer type
988 * passed to a buffer operation are compatible with the queue.
989 */
721int vb2_verify_memory_type(struct vb2_queue *q, 990int vb2_verify_memory_type(struct vb2_queue *q,
722 enum vb2_memory memory, unsigned int type); 991 enum vb2_memory memory, unsigned int type);
723#endif /* _MEDIA_VIDEOBUF2_CORE_H */ 992#endif /* _MEDIA_VIDEOBUF2_CORE_H */