v4l2-mem2mem.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Memory-to-memory device framework for Video for Linux 2.
  3. *
  4. * Helper functions for devices that use memory buffers for both source
  5. * and destination.
  6. *
  7. * Copyright (c) 2009 Samsung Electronics Co., Ltd.
  8. * Pawel Osciak, <p.osciak@samsung.com>
  9. * Marek Szyprowski, <m.szyprowski@samsung.com>
  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 as published by the
  13. * Free Software Foundation; either version 2 of the
  14. * License, or (at your option) any later version
  15. */
  16. #ifndef _MEDIA_V4L2_MEM2MEM_H
  17. #define _MEDIA_V4L2_MEM2MEM_H
  18. #include <media/videobuf-core.h>
  19. /**
  20. * struct v4l2_m2m_ops - mem-to-mem device driver callbacks
  21. * @device_run: required. Begin the actual job (transaction) inside this
  22. * callback.
  23. * The job does NOT have to end before this callback returns
  24. * (and it will be the usual case). When the job finishes,
  25. * v4l2_m2m_job_finish() has to be called.
  26. * @job_ready: optional. Should return 0 if the driver does not have a job
  27. * fully prepared to run yet (i.e. it will not be able to finish a
  28. * transaction without sleeping). If not provided, it will be
  29. * assumed that one source and one destination buffer are all
  30. * that is required for the driver to perform one full transaction.
  31. * This method may not sleep.
  32. * @job_abort: required. Informs the driver that it has to abort the currently
  33. * running transaction as soon as possible (i.e. as soon as it can
  34. * stop the device safely; e.g. in the next interrupt handler),
  35. * even if the transaction would not have been finished by then.
  36. * After the driver performs the necessary steps, it has to call
  37. * v4l2_m2m_job_finish() (as if the transaction ended normally).
  38. * This function does not have to (and will usually not) wait
  39. * until the device enters a state when it can be stopped.
  40. */
  41. struct v4l2_m2m_ops {
  42. void (*device_run)(void *priv);
  43. int (*job_ready)(void *priv);
  44. void (*job_abort)(void *priv);
  45. };
  46. struct v4l2_m2m_dev;
  47. struct v4l2_m2m_queue_ctx {
  48. /* private: internal use only */
  49. struct videobuf_queue q;
  50. /* Queue for buffers ready to be processed as soon as this
  51. * instance receives access to the device */
  52. struct list_head rdy_queue;
  53. u8 num_rdy;
  54. };
  55. struct v4l2_m2m_ctx {
  56. /* private: internal use only */
  57. struct v4l2_m2m_dev *m2m_dev;
  58. /* Capture (output to memory) queue context */
  59. struct v4l2_m2m_queue_ctx cap_q_ctx;
  60. /* Output (input from memory) queue context */
  61. struct v4l2_m2m_queue_ctx out_q_ctx;
  62. /* For device job queue */
  63. struct list_head queue;
  64. unsigned long job_flags;
  65. /* Instance private data */
  66. void *priv;
  67. };
  68. void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
  69. struct videobuf_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
  70. enum v4l2_buf_type type);
  71. void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
  72. struct v4l2_m2m_ctx *m2m_ctx);
  73. int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  74. struct v4l2_requestbuffers *reqbufs);
  75. int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  76. struct v4l2_buffer *buf);
  77. int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  78. struct v4l2_buffer *buf);
  79. int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  80. struct v4l2_buffer *buf);
  81. int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  82. enum v4l2_buf_type type);
  83. int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  84. enum v4l2_buf_type type);
  85. unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  86. struct poll_table_struct *wait);
  87. int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
  88. struct vm_area_struct *vma);
  89. struct v4l2_m2m_dev *v4l2_m2m_init(struct v4l2_m2m_ops *m2m_ops);
  90. void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev);
  91. struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(void *priv, struct v4l2_m2m_dev *m2m_dev,
  92. void (*vq_init)(void *priv, struct videobuf_queue *,
  93. enum v4l2_buf_type));
  94. void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx);
  95. void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct videobuf_queue *vq,
  96. struct videobuf_buffer *vb);
  97. /**
  98. * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for
  99. * use
  100. */
  101. static inline
  102. unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
  103. {
  104. return m2m_ctx->cap_q_ctx.num_rdy;
  105. }
  106. /**
  107. * v4l2_m2m_num_src_bufs_ready() - return the number of destination buffers
  108. * ready for use
  109. */
  110. static inline
  111. unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
  112. {
  113. return m2m_ctx->out_q_ctx.num_rdy;
  114. }
  115. void *v4l2_m2m_next_buf(struct v4l2_m2m_ctx *m2m_ctx, enum v4l2_buf_type type);
  116. /**
  117. * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready
  118. * buffers
  119. */
  120. static inline void *v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx)
  121. {
  122. return v4l2_m2m_next_buf(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
  123. }
  124. /**
  125. * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of
  126. * ready buffers
  127. */
  128. static inline void *v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx)
  129. {
  130. return v4l2_m2m_next_buf(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
  131. }
  132. /**
  133. * v4l2_m2m_get_src_vq() - return videobuf_queue for source buffers
  134. */
  135. static inline
  136. struct videobuf_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx)
  137. {
  138. return v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
  139. }
  140. /**
  141. * v4l2_m2m_get_dst_vq() - return videobuf_queue for destination buffers
  142. */
  143. static inline
  144. struct videobuf_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx)
  145. {
  146. return v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
  147. }
  148. void *v4l2_m2m_buf_remove(struct v4l2_m2m_ctx *m2m_ctx,
  149. enum v4l2_buf_type type);
  150. /**
  151. * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready
  152. * buffers and return it
  153. */
  154. static inline void *v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
  155. {
  156. return v4l2_m2m_buf_remove(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
  157. }
  158. /**
  159. * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of
  160. * ready buffers and return it
  161. */
  162. static inline void *v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
  163. {
  164. return v4l2_m2m_buf_remove(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
  165. }
  166. #endif /* _MEDIA_V4L2_MEM2MEM_H */