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