1 /* 1 /* 2 * SPDX-License-Identifier: GPL-2.0 2 * SPDX-License-Identifier: GPL-2.0 3 * 3 * 4 * dvb-vb2.h - DVB driver helper framework for 4 * dvb-vb2.h - DVB driver helper framework for streaming I/O 5 * 5 * 6 * Copyright (C) 2015 Samsung Electronics 6 * Copyright (C) 2015 Samsung Electronics 7 * 7 * 8 * Author: jh1009.sung@samsung.com 8 * Author: jh1009.sung@samsung.com 9 * 9 * 10 * This program is free software; you can redi 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Publi 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation. 12 * the Free Software Foundation. 13 */ 13 */ 14 14 15 #ifndef _DVB_VB2_H 15 #ifndef _DVB_VB2_H 16 #define _DVB_VB2_H 16 #define _DVB_VB2_H 17 17 18 #include <linux/mutex.h> 18 #include <linux/mutex.h> 19 #include <linux/poll.h> 19 #include <linux/poll.h> 20 #include <linux/dvb/dmx.h> 20 #include <linux/dvb/dmx.h> 21 #include <media/videobuf2-core.h> 21 #include <media/videobuf2-core.h> 22 #include <media/videobuf2-dma-contig.h> 22 #include <media/videobuf2-dma-contig.h> 23 #include <media/videobuf2-vmalloc.h> 23 #include <media/videobuf2-vmalloc.h> 24 24 25 /** 25 /** 26 * enum dvb_buf_type - types of Digital TV mem 26 * enum dvb_buf_type - types of Digital TV memory-mapped buffers 27 * 27 * 28 * @DVB_BUF_TYPE_CAPTURE: buffer is filled by 28 * @DVB_BUF_TYPE_CAPTURE: buffer is filled by the Kernel, 29 * with a received Digi 29 * with a received Digital TV stream 30 */ 30 */ 31 enum dvb_buf_type { 31 enum dvb_buf_type { 32 DVB_BUF_TYPE_CAPTURE = 1, 32 DVB_BUF_TYPE_CAPTURE = 1, 33 }; 33 }; 34 34 35 /** 35 /** 36 * enum dvb_vb2_states - states to control VB2 36 * enum dvb_vb2_states - states to control VB2 state machine 37 * @DVB_VB2_STATE_NONE: 37 * @DVB_VB2_STATE_NONE: 38 * VB2 engine not initialized yet, init f 38 * VB2 engine not initialized yet, init failed or VB2 was released. 39 * @DVB_VB2_STATE_INIT: 39 * @DVB_VB2_STATE_INIT: 40 * VB2 engine initialized. 40 * VB2 engine initialized. 41 * @DVB_VB2_STATE_REQBUFS: 41 * @DVB_VB2_STATE_REQBUFS: 42 * Buffers were requested 42 * Buffers were requested 43 * @DVB_VB2_STATE_STREAMON: 43 * @DVB_VB2_STATE_STREAMON: 44 * VB2 is streaming. Callers should not c 44 * VB2 is streaming. Callers should not check it directly. Instead, 45 * they should use dvb_vb2_is_streaming() 45 * they should use dvb_vb2_is_streaming(). 46 * 46 * 47 * Note: 47 * Note: 48 * 48 * 49 * Callers should not touch at the state machi 49 * Callers should not touch at the state machine directly. This 50 * is handled inside dvb_vb2.c. 50 * is handled inside dvb_vb2.c. 51 */ 51 */ 52 enum dvb_vb2_states { 52 enum dvb_vb2_states { 53 DVB_VB2_STATE_NONE = 0x0, 53 DVB_VB2_STATE_NONE = 0x0, 54 DVB_VB2_STATE_INIT = 0x1, 54 DVB_VB2_STATE_INIT = 0x1, 55 DVB_VB2_STATE_REQBUFS = 0x2, 55 DVB_VB2_STATE_REQBUFS = 0x2, 56 DVB_VB2_STATE_STREAMON = 0x4, 56 DVB_VB2_STATE_STREAMON = 0x4, 57 }; 57 }; 58 58 59 #define DVB_VB2_NAME_MAX (20) 59 #define DVB_VB2_NAME_MAX (20) 60 60 61 /** 61 /** 62 * struct dvb_buffer - video buffer informatio 62 * struct dvb_buffer - video buffer information for v4l2. 63 * 63 * 64 * @vb: embedded struct &vb2_buffer. 64 * @vb: embedded struct &vb2_buffer. 65 * @list: list of &struct dvb_buffer. 65 * @list: list of &struct dvb_buffer. 66 */ 66 */ 67 struct dvb_buffer { 67 struct dvb_buffer { 68 struct vb2_buffer vb; 68 struct vb2_buffer vb; 69 struct list_head list; 69 struct list_head list; 70 }; 70 }; 71 71 72 /** 72 /** 73 * struct dvb_vb2_ctx - control struct for VB2 73 * struct dvb_vb2_ctx - control struct for VB2 handler 74 * @vb_q: pointer to &struct vb2_queue w 74 * @vb_q: pointer to &struct vb2_queue with videobuf2 queue. 75 * @mutex: mutex to serialize vb2 operati 75 * @mutex: mutex to serialize vb2 operations. Used by 76 * vb2 core %wait_prepare and %wa 76 * vb2 core %wait_prepare and %wait_finish operations. 77 * @slock: spin lock used to protect buff 77 * @slock: spin lock used to protect buffer filling at dvb_vb2.c. 78 * @dvb_q: List of buffers that are not f 78 * @dvb_q: List of buffers that are not filled yet. 79 * @buf: Pointer to the buffer that are 79 * @buf: Pointer to the buffer that are currently being filled. 80 * @offset: index to the next position at 80 * @offset: index to the next position at the @buf to be filled. 81 * @remain: How many bytes are left to be 81 * @remain: How many bytes are left to be filled at @buf. 82 * @state: bitmask of buffer states as de 82 * @state: bitmask of buffer states as defined by &enum dvb_vb2_states. 83 * @buf_siz: size of each VB2 buffer. 83 * @buf_siz: size of each VB2 buffer. 84 * @buf_cnt: number of VB2 buffers. 84 * @buf_cnt: number of VB2 buffers. 85 * @nonblocking: 85 * @nonblocking: 86 * If different than zero, device 86 * If different than zero, device is operating on non-blocking 87 * mode. 87 * mode. 88 * @flags: buffer flags as defined by &en 88 * @flags: buffer flags as defined by &enum dmx_buffer_flags. 89 * Filled only at &DMX_DQBUF. &DM 89 * Filled only at &DMX_DQBUF. &DMX_QBUF should zero this field. 90 * @count: monotonic counter for filled b 90 * @count: monotonic counter for filled buffers. Helps to identify 91 * data stream loses. Filled only 91 * data stream loses. Filled only at &DMX_DQBUF. &DMX_QBUF should 92 * zero this field. 92 * zero this field. 93 * 93 * 94 * @name: name of the device type. Curre 94 * @name: name of the device type. Currently, it can either be 95 * "dvr" or "demux_filter". 95 * "dvr" or "demux_filter". 96 */ 96 */ 97 struct dvb_vb2_ctx { 97 struct dvb_vb2_ctx { 98 struct vb2_queue vb_q; 98 struct vb2_queue vb_q; 99 struct mutex mutex; 99 struct mutex mutex; 100 spinlock_t slock; 100 spinlock_t slock; 101 struct list_head dvb_q; 101 struct list_head dvb_q; 102 struct dvb_buffer *buf; 102 struct dvb_buffer *buf; 103 int offset; 103 int offset; 104 int remain; 104 int remain; 105 int state; 105 int state; 106 int buf_siz; 106 int buf_siz; 107 int buf_cnt; 107 int buf_cnt; 108 int nonblocking; 108 int nonblocking; 109 109 110 enum dmx_buffer_flags flags; 110 enum dmx_buffer_flags flags; 111 u32 count; 111 u32 count; 112 112 113 char name[DVB_VB2_NAME_MAX + 1]; 113 char name[DVB_VB2_NAME_MAX + 1]; 114 }; 114 }; 115 115 116 #ifndef CONFIG_DVB_MMAP 116 #ifndef CONFIG_DVB_MMAP 117 static inline int dvb_vb2_init(struct dvb_vb2_ 117 static inline int dvb_vb2_init(struct dvb_vb2_ctx *ctx, 118 const char *nam 118 const char *name, int non_blocking) 119 { 119 { 120 return 0; 120 return 0; 121 }; 121 }; 122 static inline int dvb_vb2_release(struct dvb_v 122 static inline int dvb_vb2_release(struct dvb_vb2_ctx *ctx) 123 { 123 { 124 return 0; 124 return 0; 125 }; 125 }; 126 #define dvb_vb2_is_streaming(ctx) (0) 126 #define dvb_vb2_is_streaming(ctx) (0) 127 #define dvb_vb2_fill_buffer(ctx, file, wait, f 127 #define dvb_vb2_fill_buffer(ctx, file, wait, flags) (0) 128 128 129 static inline __poll_t dvb_vb2_poll(struct dvb 129 static inline __poll_t dvb_vb2_poll(struct dvb_vb2_ctx *ctx, 130 struct fil 130 struct file *file, 131 poll_table 131 poll_table *wait) 132 { 132 { 133 return 0; 133 return 0; 134 } 134 } 135 #else 135 #else 136 /** 136 /** 137 * dvb_vb2_init - initializes VB2 handler 137 * dvb_vb2_init - initializes VB2 handler 138 * 138 * 139 * @ctx: control struct for VB2 handler 139 * @ctx: control struct for VB2 handler 140 * @name: name for the VB2 handler 140 * @name: name for the VB2 handler 141 * @non_blocking: 141 * @non_blocking: 142 * if not zero, it means that the 142 * if not zero, it means that the device is at non-blocking mode 143 */ 143 */ 144 int dvb_vb2_init(struct dvb_vb2_ctx *ctx, cons 144 int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int non_blocking); 145 145 146 /** 146 /** 147 * dvb_vb2_release - Releases the VB2 handler 147 * dvb_vb2_release - Releases the VB2 handler allocated resources and 148 * put @ctx at DVB_VB2_STATE_NONE state. 148 * put @ctx at DVB_VB2_STATE_NONE state. 149 * @ctx: control struct for VB2 handler 149 * @ctx: control struct for VB2 handler 150 */ 150 */ 151 int dvb_vb2_release(struct dvb_vb2_ctx *ctx); 151 int dvb_vb2_release(struct dvb_vb2_ctx *ctx); 152 152 153 /** 153 /** 154 * dvb_vb2_is_streaming - checks if the VB2 ha 154 * dvb_vb2_is_streaming - checks if the VB2 handler is streaming 155 * @ctx: control struct for VB2 handler 155 * @ctx: control struct for VB2 handler 156 * 156 * 157 * Return: 0 if not streaming, 1 otherwise. 157 * Return: 0 if not streaming, 1 otherwise. 158 */ 158 */ 159 int dvb_vb2_is_streaming(struct dvb_vb2_ctx *c 159 int dvb_vb2_is_streaming(struct dvb_vb2_ctx *ctx); 160 160 161 /** 161 /** 162 * dvb_vb2_fill_buffer - fills a VB2 buffer 162 * dvb_vb2_fill_buffer - fills a VB2 buffer 163 * @ctx: control struct for VB2 handler 163 * @ctx: control struct for VB2 handler 164 * @src: place where the data is stored 164 * @src: place where the data is stored 165 * @len: number of bytes to be copied f 165 * @len: number of bytes to be copied from @src 166 * @buffer_flags: 166 * @buffer_flags: 167 * pointer to buffer flags as def 167 * pointer to buffer flags as defined by &enum dmx_buffer_flags. 168 * can be NULL. 168 * can be NULL. 169 */ 169 */ 170 int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ct 170 int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx, 171 const unsigned char *s 171 const unsigned char *src, int len, 172 enum dmx_buffer_flags 172 enum dmx_buffer_flags *buffer_flags); 173 173 174 /** 174 /** 175 * dvb_vb2_poll - Wrapper to vb2_core_streamon 175 * dvb_vb2_poll - Wrapper to vb2_core_streamon() for Digital TV 176 * buffer handling. 176 * buffer handling. 177 * 177 * 178 * @ctx: control struct for VB2 handler 178 * @ctx: control struct for VB2 handler 179 * @file: &struct file argument passed t 179 * @file: &struct file argument passed to the poll 180 * file operation handler. 180 * file operation handler. 181 * @wait: &poll_table wait argument pass 181 * @wait: &poll_table wait argument passed to the poll 182 * file operation handler. 182 * file operation handler. 183 * 183 * 184 * Implements poll syscall() logic. 184 * Implements poll syscall() logic. 185 */ 185 */ 186 __poll_t dvb_vb2_poll(struct dvb_vb2_ctx *ctx, 186 __poll_t dvb_vb2_poll(struct dvb_vb2_ctx *ctx, struct file *file, 187 poll_table *wait); 187 poll_table *wait); 188 #endif 188 #endif 189 189 190 /** 190 /** 191 * dvb_vb2_stream_on() - Wrapper to vb2_core_s 191 * dvb_vb2_stream_on() - Wrapper to vb2_core_streamon() for Digital TV 192 * buffer handling. 192 * buffer handling. 193 * 193 * 194 * @ctx: control struct for VB2 handler 194 * @ctx: control struct for VB2 handler 195 * 195 * 196 * Starts dvb streaming 196 * Starts dvb streaming 197 */ 197 */ 198 int dvb_vb2_stream_on(struct dvb_vb2_ctx *ctx) 198 int dvb_vb2_stream_on(struct dvb_vb2_ctx *ctx); 199 /** 199 /** 200 * dvb_vb2_stream_off() - Wrapper to vb2_core_ 200 * dvb_vb2_stream_off() - Wrapper to vb2_core_streamoff() for Digital TV 201 * buffer handling. 201 * buffer handling. 202 * 202 * 203 * @ctx: control struct for VB2 handler 203 * @ctx: control struct for VB2 handler 204 * 204 * 205 * Stops dvb streaming 205 * Stops dvb streaming 206 */ 206 */ 207 int dvb_vb2_stream_off(struct dvb_vb2_ctx *ctx 207 int dvb_vb2_stream_off(struct dvb_vb2_ctx *ctx); 208 208 209 /** 209 /** 210 * dvb_vb2_reqbufs() - Wrapper to vb2_core_req 210 * dvb_vb2_reqbufs() - Wrapper to vb2_core_reqbufs() for Digital TV 211 * buffer handling. 211 * buffer handling. 212 * 212 * 213 * @ctx: control struct for VB2 handler 213 * @ctx: control struct for VB2 handler 214 * @req: &struct dmx_requestbuffers pas 214 * @req: &struct dmx_requestbuffers passed from userspace in 215 * order to handle &DMX_REQBUFS. 215 * order to handle &DMX_REQBUFS. 216 * 216 * 217 * Initiate streaming by requesting a number o 217 * Initiate streaming by requesting a number of buffers. Also used to 218 * free previously requested buffers, is ``req 218 * free previously requested buffers, is ``req->count`` is zero. 219 */ 219 */ 220 int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, s 220 int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req); 221 221 222 /** 222 /** 223 * dvb_vb2_querybuf() - Wrapper to vb2_core_qu 223 * dvb_vb2_querybuf() - Wrapper to vb2_core_querybuf() for Digital TV 224 * buffer handling. 224 * buffer handling. 225 * 225 * 226 * @ctx: control struct for VB2 handler 226 * @ctx: control struct for VB2 handler 227 * @b: &struct dmx_buffer passed from 227 * @b: &struct dmx_buffer passed from userspace in 228 * order to handle &DMX_QUERYBUF. 228 * order to handle &DMX_QUERYBUF. 229 * 229 * 230 * 230 * 231 */ 231 */ 232 int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, 232 int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b); 233 233 234 /** 234 /** 235 * dvb_vb2_expbuf() - Wrapper to vb2_core_expb 235 * dvb_vb2_expbuf() - Wrapper to vb2_core_expbuf() for Digital TV 236 * buffer handling. 236 * buffer handling. 237 * 237 * 238 * @ctx: control struct for VB2 handler 238 * @ctx: control struct for VB2 handler 239 * @exp: &struct dmx_exportbuffer passe 239 * @exp: &struct dmx_exportbuffer passed from userspace in 240 * order to handle &DMX_EXPBUF. 240 * order to handle &DMX_EXPBUF. 241 * 241 * 242 * Export a buffer as a file descriptor. 242 * Export a buffer as a file descriptor. 243 */ 243 */ 244 int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, st 244 int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp); 245 245 246 /** 246 /** 247 * dvb_vb2_qbuf() - Wrapper to vb2_core_qbuf() 247 * dvb_vb2_qbuf() - Wrapper to vb2_core_qbuf() for Digital TV buffer handling. 248 * 248 * 249 * @ctx: control struct for VB2 handler 249 * @ctx: control struct for VB2 handler 250 * @b: &struct dmx_buffer passed from 250 * @b: &struct dmx_buffer passed from userspace in 251 * order to handle &DMX_QBUF. 251 * order to handle &DMX_QBUF. 252 * 252 * 253 * Queue a Digital TV buffer as requested by u 253 * Queue a Digital TV buffer as requested by userspace 254 */ 254 */ 255 int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, stru 255 int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b); 256 256 257 /** 257 /** 258 * dvb_vb2_dqbuf() - Wrapper to vb2_core_dqbuf 258 * dvb_vb2_dqbuf() - Wrapper to vb2_core_dqbuf() for Digital TV 259 * buffer handling. 259 * buffer handling. 260 * 260 * 261 * @ctx: control struct for VB2 handler 261 * @ctx: control struct for VB2 handler 262 * @b: &struct dmx_buffer passed from 262 * @b: &struct dmx_buffer passed from userspace in 263 * order to handle &DMX_DQBUF. 263 * order to handle &DMX_DQBUF. 264 * 264 * 265 * Dequeue a Digital TV buffer to the userspac 265 * Dequeue a Digital TV buffer to the userspace 266 */ 266 */ 267 int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, str 267 int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b); 268 268 269 /** 269 /** 270 * dvb_vb2_mmap() - Wrapper to vb2_mmap() for 270 * dvb_vb2_mmap() - Wrapper to vb2_mmap() for Digital TV buffer handling. 271 * 271 * 272 * @ctx: control struct for VB2 handler 272 * @ctx: control struct for VB2 handler 273 * @vma: pointer to &struct vm_area_str 273 * @vma: pointer to &struct vm_area_struct with the vma passed 274 * to the mmap file operation han 274 * to the mmap file operation handler in the driver. 275 * 275 * 276 * map Digital TV video buffers into applicati 276 * map Digital TV video buffers into application address space. 277 */ 277 */ 278 int dvb_vb2_mmap(struct dvb_vb2_ctx *ctx, stru 278 int dvb_vb2_mmap(struct dvb_vb2_ctx *ctx, struct vm_area_struct *vma); 279 279 280 #endif /* _DVB_VB2_H */ 280 #endif /* _DVB_VB2_H */ 281 281
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.