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/mutex.h>
  30. #include <linux/videodev2.h>
  31. #include <linux/wait.h>
  32. struct isp_video_queue;
  33. struct page;
  34. struct scatterlist;
  35. #define ISP_VIDEO_MAX_BUFFERS 16
  36. /**
  37. * enum isp_video_buffer_state - ISP video buffer state
  38. * @ISP_BUF_STATE_IDLE: The buffer is under userspace control (dequeued
  39. * or not queued yet).
  40. * @ISP_BUF_STATE_QUEUED: The buffer has been queued but isn't used by the
  41. * device yet.
  42. * @ISP_BUF_STATE_ACTIVE: The buffer is in use for an active video transfer.
  43. * @ISP_BUF_STATE_ERROR: The device is done with the buffer and an error
  44. * occurred. For capture device the buffer likely contains corrupted data or
  45. * no data at all.
  46. * @ISP_BUF_STATE_DONE: The device is done with the buffer and no error occurred.
  47. * For capture devices the buffer contains valid data.
  48. */
  49. enum isp_video_buffer_state {
  50. ISP_BUF_STATE_IDLE,
  51. ISP_BUF_STATE_QUEUED,
  52. ISP_BUF_STATE_ACTIVE,
  53. ISP_BUF_STATE_ERROR,
  54. ISP_BUF_STATE_DONE,
  55. };
  56. /**
  57. * struct isp_video_buffer - ISP video buffer
  58. * @vma_use_count: Number of times the buffer is mmap'ed to userspace
  59. * @stream: List head for insertion into main queue
  60. * @queue: ISP buffers queue this buffer belongs to
  61. * @prepared: Whether the buffer has been prepared
  62. * @skip_cache: Whether to skip cache management operations for this buffer
  63. * @vaddr: Memory virtual address (for kernel buffers)
  64. * @vm_flags: Buffer VMA flags (for userspace buffers)
  65. * @offset: Offset inside the first page (for userspace buffers)
  66. * @npages: Number of pages (for userspace buffers)
  67. * @pages: Pages table (for userspace non-VM_PFNMAP buffers)
  68. * @paddr: Memory physical address (for userspace VM_PFNMAP buffers)
  69. * @sglen: Number of elements in the scatter list (for non-VM_PFNMAP buffers)
  70. * @sglist: Scatter list (for non-VM_PFNMAP buffers)
  71. * @vbuf: V4L2 buffer
  72. * @irqlist: List head for insertion into IRQ queue
  73. * @state: Current buffer state
  74. * @wait: Wait queue to signal buffer completion
  75. */
  76. struct isp_video_buffer {
  77. unsigned long vma_use_count;
  78. struct list_head stream;
  79. struct isp_video_queue *queue;
  80. unsigned int prepared:1;
  81. bool skip_cache;
  82. /* For kernel buffers. */
  83. void *vaddr;
  84. /* For userspace buffers. */
  85. vm_flags_t vm_flags;
  86. unsigned long offset;
  87. unsigned int npages;
  88. struct page **pages;
  89. dma_addr_t paddr;
  90. /* For all buffers except VM_PFNMAP. */
  91. unsigned int sglen;
  92. struct scatterlist *sglist;
  93. /* Touched by the interrupt handler. */
  94. struct v4l2_buffer vbuf;
  95. struct list_head irqlist;
  96. enum isp_video_buffer_state state;
  97. wait_queue_head_t wait;
  98. };
  99. #define to_isp_video_buffer(vb) container_of(vb, struct isp_video_buffer, vb)
  100. /**
  101. * struct isp_video_queue_operations - Driver-specific operations
  102. * @queue_prepare: Called before allocating buffers. Drivers should clamp the
  103. * number of buffers according to their requirements, and must return the
  104. * buffer size in bytes.
  105. * @buffer_prepare: Called the first time a buffer is queued, or after changing
  106. * the userspace memory address for a USERPTR buffer, with the queue lock
  107. * held. Drivers should perform device-specific buffer preparation (such as
  108. * mapping the buffer memory in an IOMMU). This operation is optional.
  109. * @buffer_queue: Called when a buffer is being added to the queue with the
  110. * queue irqlock spinlock held.
  111. * @buffer_cleanup: Called before freeing buffers, or before changing the
  112. * userspace memory address for a USERPTR buffer, with the queue lock held.
  113. * Drivers must perform cleanup operations required to undo the
  114. * buffer_prepare call. This operation is optional.
  115. */
  116. struct isp_video_queue_operations {
  117. void (*queue_prepare)(struct isp_video_queue *queue,
  118. unsigned int *nbuffers, unsigned int *size);
  119. int (*buffer_prepare)(struct isp_video_buffer *buf);
  120. void (*buffer_queue)(struct isp_video_buffer *buf);
  121. void (*buffer_cleanup)(struct isp_video_buffer *buf);
  122. };
  123. /**
  124. * struct isp_video_queue - ISP video buffers queue
  125. * @type: Type of video buffers handled by this queue
  126. * @ops: Queue operations
  127. * @dev: Device used for DMA operations
  128. * @bufsize: Size of a driver-specific buffer object
  129. * @count: Number of currently allocated buffers
  130. * @buffers: ISP video buffers
  131. * @lock: Mutex to protect access to the buffers, main queue and state
  132. * @irqlock: Spinlock to protect access to the IRQ queue
  133. * @streaming: Queue state, indicates whether the queue is streaming
  134. * @queue: List of all queued buffers
  135. */
  136. struct isp_video_queue {
  137. enum v4l2_buf_type type;
  138. const struct isp_video_queue_operations *ops;
  139. struct device *dev;
  140. unsigned int bufsize;
  141. unsigned int count;
  142. struct isp_video_buffer *buffers[ISP_VIDEO_MAX_BUFFERS];
  143. struct mutex lock;
  144. spinlock_t irqlock;
  145. unsigned int streaming:1;
  146. struct list_head queue;
  147. };
  148. int omap3isp_video_queue_cleanup(struct isp_video_queue *queue);
  149. int omap3isp_video_queue_init(struct isp_video_queue *queue,
  150. enum v4l2_buf_type type,
  151. const struct isp_video_queue_operations *ops,
  152. struct device *dev, unsigned int bufsize);
  153. int omap3isp_video_queue_reqbufs(struct isp_video_queue *queue,
  154. struct v4l2_requestbuffers *rb);
  155. int omap3isp_video_queue_querybuf(struct isp_video_queue *queue,
  156. struct v4l2_buffer *vbuf);
  157. int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
  158. struct v4l2_buffer *vbuf);
  159. int omap3isp_video_queue_dqbuf(struct isp_video_queue *queue,
  160. struct v4l2_buffer *vbuf, int nonblocking);
  161. int omap3isp_video_queue_streamon(struct isp_video_queue *queue);
  162. void omap3isp_video_queue_streamoff(struct isp_video_queue *queue);
  163. void omap3isp_video_queue_discard_done(struct isp_video_queue *queue);
  164. int omap3isp_video_queue_mmap(struct isp_video_queue *queue,
  165. struct vm_area_struct *vma);
  166. unsigned int omap3isp_video_queue_poll(struct isp_video_queue *queue,
  167. struct file *file, poll_table *wait);
  168. #endif /* OMAP3_ISP_QUEUE_H */