videobuf2-internal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifndef _MEDIA_VIDEOBUF2_INTERNAL_H
  2. #define _MEDIA_VIDEOBUF2_INTERNAL_H
  3. #include <linux/err.h>
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <media/videobuf2-core.h>
  7. extern int vb2_debug;
  8. #define dprintk(level, fmt, arg...) \
  9. do { \
  10. if (vb2_debug >= level) \
  11. pr_info("vb2: %s: " fmt, __func__, ## arg); \
  12. } while (0)
  13. #ifdef CONFIG_VIDEO_ADV_DEBUG
  14. /*
  15. * If advanced debugging is on, then count how often each op is called
  16. * successfully, which can either be per-buffer or per-queue.
  17. *
  18. * This makes it easy to check that the 'init' and 'cleanup'
  19. * (and variations thereof) stay balanced.
  20. */
  21. #define log_memop(vb, op) \
  22. dprintk(2, "call_memop(%p, %d, %s)%s\n", \
  23. (vb)->vb2_queue, (vb)->index, #op, \
  24. (vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
  25. #define call_memop(vb, op, args...) \
  26. ({ \
  27. struct vb2_queue *_q = (vb)->vb2_queue; \
  28. int err; \
  29. \
  30. log_memop(vb, op); \
  31. err = _q->mem_ops->op ? _q->mem_ops->op(args) : 0; \
  32. if (!err) \
  33. (vb)->cnt_mem_ ## op++; \
  34. err; \
  35. })
  36. #define call_ptr_memop(vb, op, args...) \
  37. ({ \
  38. struct vb2_queue *_q = (vb)->vb2_queue; \
  39. void *ptr; \
  40. \
  41. log_memop(vb, op); \
  42. ptr = _q->mem_ops->op ? _q->mem_ops->op(args) : NULL; \
  43. if (!IS_ERR_OR_NULL(ptr)) \
  44. (vb)->cnt_mem_ ## op++; \
  45. ptr; \
  46. })
  47. #define call_void_memop(vb, op, args...) \
  48. ({ \
  49. struct vb2_queue *_q = (vb)->vb2_queue; \
  50. \
  51. log_memop(vb, op); \
  52. if (_q->mem_ops->op) \
  53. _q->mem_ops->op(args); \
  54. (vb)->cnt_mem_ ## op++; \
  55. })
  56. #define log_qop(q, op) \
  57. dprintk(2, "call_qop(%p, %s)%s\n", q, #op, \
  58. (q)->ops->op ? "" : " (nop)")
  59. #define call_qop(q, op, args...) \
  60. ({ \
  61. int err; \
  62. \
  63. log_qop(q, op); \
  64. err = (q)->ops->op ? (q)->ops->op(args) : 0; \
  65. if (!err) \
  66. (q)->cnt_ ## op++; \
  67. err; \
  68. })
  69. #define call_void_qop(q, op, args...) \
  70. ({ \
  71. log_qop(q, op); \
  72. if ((q)->ops->op) \
  73. (q)->ops->op(args); \
  74. (q)->cnt_ ## op++; \
  75. })
  76. #define log_vb_qop(vb, op, args...) \
  77. dprintk(2, "call_vb_qop(%p, %d, %s)%s\n", \
  78. (vb)->vb2_queue, (vb)->index, #op, \
  79. (vb)->vb2_queue->ops->op ? "" : " (nop)")
  80. #define call_vb_qop(vb, op, args...) \
  81. ({ \
  82. int err; \
  83. \
  84. log_vb_qop(vb, op); \
  85. err = (vb)->vb2_queue->ops->op ? \
  86. (vb)->vb2_queue->ops->op(args) : 0; \
  87. if (!err) \
  88. (vb)->cnt_ ## op++; \
  89. err; \
  90. })
  91. #define call_void_vb_qop(vb, op, args...) \
  92. ({ \
  93. log_vb_qop(vb, op); \
  94. if ((vb)->vb2_queue->ops->op) \
  95. (vb)->vb2_queue->ops->op(args); \
  96. (vb)->cnt_ ## op++; \
  97. })
  98. #else
  99. #define call_memop(vb, op, args...) \
  100. ((vb)->vb2_queue->mem_ops->op ? \
  101. (vb)->vb2_queue->mem_ops->op(args) : 0)
  102. #define call_ptr_memop(vb, op, args...) \
  103. ((vb)->vb2_queue->mem_ops->op ? \
  104. (vb)->vb2_queue->mem_ops->op(args) : NULL)
  105. #define call_void_memop(vb, op, args...) \
  106. do { \
  107. if ((vb)->vb2_queue->mem_ops->op) \
  108. (vb)->vb2_queue->mem_ops->op(args); \
  109. } while (0)
  110. #define call_qop(q, op, args...) \
  111. ((q)->ops->op ? (q)->ops->op(args) : 0)
  112. #define call_void_qop(q, op, args...) \
  113. do { \
  114. if ((q)->ops->op) \
  115. (q)->ops->op(args); \
  116. } while (0)
  117. #define call_vb_qop(vb, op, args...) \
  118. ((vb)->vb2_queue->ops->op ? (vb)->vb2_queue->ops->op(args) : 0)
  119. #define call_void_vb_qop(vb, op, args...) \
  120. do { \
  121. if ((vb)->vb2_queue->ops->op) \
  122. (vb)->vb2_queue->ops->op(args); \
  123. } while (0)
  124. #endif
  125. #define call_bufop(q, op, args...) \
  126. ({ \
  127. int ret = 0; \
  128. if (q && q->buf_ops && q->buf_ops->op) \
  129. ret = q->buf_ops->op(args); \
  130. ret; \
  131. })
  132. bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
  133. int vb2_verify_memory_type(struct vb2_queue *q,
  134. enum vb2_memory memory, unsigned int type);
  135. #endif /* _MEDIA_VIDEOBUF2_INTERNAL_H */