ispqueue.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * ispqueue.h
  3. *
  4. * TI OMAP3 ISP - Video buffers queue handling
  5. *
  6. * Copyright (C) 2010 Nokia Corporation
  7. *
  8. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  9. * Sakari Ailus <sakari.ailus@iki.fi>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  23. * 02110-1301 USA
  24. */
  25. #ifndef OMAP3_ISP_QUEUE_H
  26. #define OMAP3_ISP_QUEUE_H
  27. #include <linux/kernel.h>
  28. #include <linux/list.h>
  29. #include <linux/mm_types.h>
  30. #include <linux/mutex.h>
  31. #include <linux/videodev2.h>
  32. #include <linux/wait.h>
  33. struct isp_video_queue;
  34. struct page;
  35. struct scatterlist;
  36. #define ISP_VIDEO_MAX_BUFFERS 16
  37. /**
  38. * enum isp_video_buffer_state - ISP video buffer state
  39. * @ISP_BUF_STATE_IDLE: The buffer is under userspace control (dequeued
  40. * or not queued yet).
  41. * @ISP_BUF_STATE_QUEUED: The buffer has been queued but isn't used by the
  42. * device yet.
  43. * @ISP_BUF_STATE_ACTIVE: The buffer is in use for an active video transfer.
  44. * @ISP_BUF_STATE_ERROR: The device is done with the buffer and an error
  45. * occurred. For capture device the buffer likely contains corrupted data or
  46. * no data at all.
  47. * @ISP_BUF_STATE_DONE: The device is done with the buffer and no error occurred.
  48. * For capture devices the buffer contains valid data.
  49. */
  50. enum isp_video_buffer_state {
  51. ISP_BUF_STATE_IDLE,
  52. ISP_BUF_STATE_QUEUED,
  53. ISP_BUF_STATE_ACTIVE,
  54. ISP_BUF_STATE_ERROR,
  55. ISP_BUF_STATE_DONE,
  56. };
  57. /**
  58. * struct isp_video_buffer - ISP video buffer
  59. * @vma_use_count: Number of times the buffer is mmap'ed to userspace
  60. * @stream: List head for insertion into main queue
  61. * @queue: ISP buffers queue this buffer belongs to
  62. * @prepared: Whether the buffer has been prepared
  63. * @skip_cache: Whether to skip cache management operations for this buffer
  64. * @vaddr: Memory virtual address (for kernel buffers)
  65. * @vm_flags: Buffer VMA flags (for userspace buffers)
  66. * @offset: Offset inside the first page (for userspace buffers)
  67. * @npages: Number of pages (for userspace buffers)
  68. * @pages: Pages table (for userspace non-VM_PFNMAP buffers)
  69. * @paddr: Memory physical address (for userspace VM_PFNMAP buffers)
  70. * @sglen: Number of elements in the scatter list (for non-VM_PFNMAP buffers)
  71. * @sglist: Scatter list (for non-VM_PFNMAP buffers)
  72. * @vbuf: V4L2 buffer
  73. * @irqlist: List head for insertion into IRQ queue
  74. * @state: Current buffer state
  75. * @wait: Wait queue to signal buffer completion
  76. */
  77. struct isp_video_buffer {
  78. unsigned long vma_use_count;
  79. struct list_head stream;
  80. struct isp_video_queue *queue;
  81. unsigned int prepared:1;
  82. bool skip_cache;
  83. /* For kernel buffers. */
  84. void *vaddr;
  85. /* For userspace buffers. */
  86. vm_flags_t vm_flags;
  87. unsigned long offset;
  88. unsigned int npages;
  89. struct page **pages;
  90. dma_addr_t paddr;
  91. /* For all buffers except VM_PFNMAP. */
  92. unsigned int sglen;
  93. struct scatterlist *sglist;
  94. /* Touched by the interrupt handler. */
  95. struct v4l2_buffer vbuf;
  96. struct list_head irqlist;
  97. enum isp_video_buffer_state state;
  98. wait_queue_head_t wait;
  99. };
  100. #define to_isp_video_buffer(vb) container_of(vb, struct isp_video_buffer, vb)
  101. /**
  102. * struct isp_video_queue_operations - Driver-specific operations
  103. * @queue_prepare: Called before allocating buffers. Drivers should clamp the
  104. * number of buffers according to their requirements, and must return the
  105. * buffer size in bytes.
  106. * @buffer_prepare: Called the first time a buffer is queued, or after changing
  107. * the userspace memory address for a USERPTR buffer, with the queue lock
  108. * held. Drivers should perform device-specific buffer preparation (such as
  109. * mapping the buffer memory in an IOMMU). This operation is optional.
  110. * @buffer_queue: Called when a buffer is being added to the queue with the
  111. * queue irqlock spinlock held.
  112. * @buffer_cleanup: Called before freeing buffers, or before changing the
  113. * userspace memory address for a USERPTR buffer, with the queue lock held.
  114. * Drivers must perform cleanup operations required to undo the
  115. * buffer_prepare call. This operation is optional.
  116. */
  117. struct isp_video_queue_operations {
  118. void (*queue_prepare)(struct isp_video_queue *queue,
  119. unsigned int *nbuffers, unsigned int *size);
  120. int (*buffer_prepare)(struct isp_video_buffer *buf);
  121. void (*buffer_queue)(struct isp_video_buffer *buf);
  122. void (*buffer_cleanup)(struct isp_video_buffer *buf);
  123. };
  124. /**
  125. * struct isp_video_queue - ISP video buffers queue
  126. * @type: Type of video buffers handled by this queue
  127. * @ops: Queue operations
  128. * @dev: Device used for DMA operations
  129. * @bufsize: Size of a driver-specific buffer object
  130. * @count: Number of currently allocated buffers
  131. * @buffers: ISP video buffers
  132. * @lock: Mutex to protect access to the buffers, main queue and state
  133. * @irqlock: Spinlock to protect access to the IRQ queue
  134. * @streaming: Queue state, indicates whether the queue is streaming
  135. * @queue: List of all queued buffers
  136. */
  137. struct isp_video_queue {
  138. enum v4l2_buf_type type;
  139. const struct isp_video_queue_operations *ops;
  140. struct device *dev;
  141. unsigned int bufsize;
  142. unsigned int count;
  143. struct isp_video_buffer *buffers[ISP_VIDEO_MAX_BUFFERS];
  144. struct mutex lock;
  145. spinlock_t irqlock;
  146. unsigned int streaming:1;
  147. struct list_head queue;
  148. };
  149. int omap3isp_video_queue_cleanup(struct isp_video_queue *queue);
  150. int omap3isp_video_queue_init(struct isp_video_queue *queue,
  151. enum v4l2_buf_type type,
  152. const struct isp_video_queue_operations *ops,
  153. struct device *dev, unsigned int bufsize);
  154. int omap3isp_video_queue_reqbufs(struct isp_video_queue *queue,
  155. struct v4l2_requestbuffers *rb);
  156. int omap3isp_video_queue_querybuf(struct isp_video_queue *queue,
  157. struct v4l2_buffer *vbuf);
  158. int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
  159. struct v4l2_buffer *vbuf);
  160. int omap3isp_video_queue_dqbuf(struct isp_video_queue *queue,
  161. struct v4l2_buffer *vbuf, int nonblocking);
  162. int omap3isp_video_queue_streamon(struct isp_video_queue *queue);
  163. void omap3isp_video_queue_streamoff(struct isp_video_queue *queue);
  164. void omap3isp_video_queue_discard_done(struct isp_video_queue *queue);
  165. int omap3isp_video_queue_mmap(struct isp_video_queue *queue,
  166. struct vm_area_struct *vma);
  167. unsigned int omap3isp_video_queue_poll(struct isp_video_queue *queue,
  168. struct file *file, poll_table *wait);
  169. #endif /* OMAP3_ISP_QUEUE_H */