imx-ipu-image-convert.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2012-2016 Mentor Graphics Inc.
  4. *
  5. * i.MX Queued image conversion support, with tiling and rotation.
  6. */
  7. #ifndef __IMX_IPU_IMAGE_CONVERT_H__
  8. #define __IMX_IPU_IMAGE_CONVERT_H__
  9. #include <video/imx-ipu-v3.h>
  10. struct ipu_image_convert_ctx;
  11. /**
  12. * struct ipu_image_convert_run - image conversion run request struct
  13. *
  14. * @ctx: the conversion context
  15. * @in_phys: dma addr of input image buffer for this run
  16. * @out_phys: dma addr of output image buffer for this run
  17. * @status: completion status of this run
  18. */
  19. struct ipu_image_convert_run {
  20. struct ipu_image_convert_ctx *ctx;
  21. dma_addr_t in_phys;
  22. dma_addr_t out_phys;
  23. int status;
  24. /* internal to image converter, callers don't touch */
  25. struct list_head list;
  26. };
  27. /**
  28. * ipu_image_convert_cb_t - conversion callback function prototype
  29. *
  30. * @run: the completed conversion run pointer
  31. * @ctx: a private context pointer for the callback
  32. */
  33. typedef void (*ipu_image_convert_cb_t)(struct ipu_image_convert_run *run,
  34. void *ctx);
  35. /**
  36. * ipu_image_convert_enum_format() - enumerate the image converter's
  37. * supported input and output pixel formats.
  38. *
  39. * @index: pixel format index
  40. * @fourcc: v4l2 fourcc for this index
  41. *
  42. * Returns 0 with a valid index and fills in v4l2 fourcc, -EINVAL otherwise.
  43. *
  44. * In V4L2, drivers can call ipu_image_enum_format() in .enum_fmt.
  45. */
  46. int ipu_image_convert_enum_format(int index, u32 *fourcc);
  47. /**
  48. * ipu_image_convert_adjust() - adjust input/output images to IPU restrictions.
  49. *
  50. * @in: input image format, adjusted on return
  51. * @out: output image format, adjusted on return
  52. * @rot_mode: rotation mode
  53. *
  54. * In V4L2, drivers can call ipu_image_convert_adjust() in .try_fmt.
  55. */
  56. void ipu_image_convert_adjust(struct ipu_image *in, struct ipu_image *out,
  57. enum ipu_rotate_mode rot_mode);
  58. /**
  59. * ipu_image_convert_verify() - verify that input/output image formats
  60. * and rotation mode meet IPU restrictions.
  61. *
  62. * @in: input image format
  63. * @out: output image format
  64. * @rot_mode: rotation mode
  65. *
  66. * Returns 0 if the formats and rotation mode meet IPU restrictions,
  67. * -EINVAL otherwise.
  68. */
  69. int ipu_image_convert_verify(struct ipu_image *in, struct ipu_image *out,
  70. enum ipu_rotate_mode rot_mode);
  71. /**
  72. * ipu_image_convert_prepare() - prepare a conversion context.
  73. *
  74. * @ipu: the IPU handle to use for the conversions
  75. * @ic_task: the IC task to use for the conversions
  76. * @in: input image format
  77. * @out: output image format
  78. * @rot_mode: rotation mode
  79. * @complete: run completion callback
  80. * @complete_context: a context pointer for the completion callback
  81. *
  82. * Returns an opaque conversion context pointer on success, error pointer
  83. * on failure. The input/output formats and rotation mode must already meet
  84. * IPU retrictions.
  85. *
  86. * In V4L2, drivers should call ipu_image_convert_prepare() at streamon.
  87. */
  88. struct ipu_image_convert_ctx *
  89. ipu_image_convert_prepare(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
  90. struct ipu_image *in, struct ipu_image *out,
  91. enum ipu_rotate_mode rot_mode,
  92. ipu_image_convert_cb_t complete,
  93. void *complete_context);
  94. /**
  95. * ipu_image_convert_unprepare() - unprepare a conversion context.
  96. *
  97. * @ctx: the conversion context pointer to unprepare
  98. *
  99. * Aborts any active or pending conversions for this context and
  100. * frees the context. Any currently active or pending runs belonging
  101. * to this context are returned via the completion callback with an
  102. * error run status.
  103. *
  104. * In V4L2, drivers should call ipu_image_convert_unprepare() at
  105. * streamoff.
  106. */
  107. void ipu_image_convert_unprepare(struct ipu_image_convert_ctx *ctx);
  108. /**
  109. * ipu_image_convert_queue() - queue a conversion run
  110. *
  111. * @run: the run request pointer
  112. *
  113. * ipu_image_convert_run must be dynamically allocated (_not_ as a local
  114. * var) by callers and filled in with a previously prepared conversion
  115. * context handle and the dma addr's of the input and output image buffers
  116. * for this conversion run.
  117. *
  118. * When this conversion completes, the run pointer is returned via the
  119. * completion callback. The caller is responsible for freeing the run
  120. * object after it completes.
  121. *
  122. * In V4L2, drivers should call ipu_image_convert_queue() while
  123. * streaming to queue the conversion of a received input buffer.
  124. * For example mem2mem devices this would be called in .device_run.
  125. */
  126. int ipu_image_convert_queue(struct ipu_image_convert_run *run);
  127. /**
  128. * ipu_image_convert_abort() - abort conversions
  129. *
  130. * @ctx: the conversion context pointer
  131. *
  132. * This will abort any active or pending conversions for this context.
  133. * Any currently active or pending runs belonging to this context are
  134. * returned via the completion callback with an error run status.
  135. */
  136. void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx);
  137. /**
  138. * ipu_image_convert() - asynchronous image conversion request
  139. *
  140. * @ipu: the IPU handle to use for the conversion
  141. * @ic_task: the IC task to use for the conversion
  142. * @in: input image format
  143. * @out: output image format
  144. * @rot_mode: rotation mode
  145. * @complete: run completion callback
  146. * @complete_context: a context pointer for the completion callback
  147. *
  148. * Request a single image conversion. Returns the run that has been queued.
  149. * A conversion context is automatically created and is available in run->ctx.
  150. * As with ipu_image_convert_prepare(), the input/output formats and rotation
  151. * mode must already meet IPU retrictions.
  152. *
  153. * On successful return the caller can queue more run requests if needed, using
  154. * the prepared context in run->ctx. The caller is responsible for unpreparing
  155. * the context when no more conversion requests are needed.
  156. */
  157. struct ipu_image_convert_run *
  158. ipu_image_convert(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
  159. struct ipu_image *in, struct ipu_image *out,
  160. enum ipu_rotate_mode rot_mode,
  161. ipu_image_convert_cb_t complete,
  162. void *complete_context);
  163. /**
  164. * ipu_image_convert_sync() - synchronous single image conversion request
  165. *
  166. * @ipu: the IPU handle to use for the conversion
  167. * @ic_task: the IC task to use for the conversion
  168. * @in: input image format
  169. * @out: output image format
  170. * @rot_mode: rotation mode
  171. *
  172. * Carry out a single image conversion. Returns when the conversion
  173. * completes. The input/output formats and rotation mode must already
  174. * meet IPU retrictions. The created context is automatically unprepared
  175. * and the run freed on return.
  176. */
  177. int ipu_image_convert_sync(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
  178. struct ipu_image *in, struct ipu_image *out,
  179. enum ipu_rotate_mode rot_mode);
  180. #endif /* __IMX_IPU_IMAGE_CONVERT_H__ */