]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * dvbdev.h | |
3 | * | |
4 | * Copyright (C) 2000 Ralph Metzler & Marcus Metzler | |
5 | * for convergence integrated media GmbH | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Lesser Public License | |
9 | * as published by the Free Software Foundation; either version 2.1 | |
10 | * of the License, or (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
1da177e4 LT |
17 | */ |
18 | ||
19 | #ifndef _DVBDEV_H_ | |
20 | #define _DVBDEV_H_ | |
21 | ||
22 | #include <linux/types.h> | |
23 | #include <linux/poll.h> | |
24 | #include <linux/fs.h> | |
25 | #include <linux/list.h> | |
a0246e02 | 26 | #include <media/media-device.h> |
1da177e4 LT |
27 | |
28 | #define DVB_MAJOR 212 | |
29 | ||
4457ef1d | 30 | #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0 |
d4c02ef9 | 31 | #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS |
4457ef1d | 32 | #else |
90866b3a | 33 | #define DVB_MAX_ADAPTERS 16 |
4457ef1d | 34 | #endif |
78e92006 JG |
35 | |
36 | #define DVB_UNSET (-1) | |
37 | ||
6bbf7a85 MCC |
38 | /* List of DVB device types */ |
39 | ||
40 | /** | |
41 | * enum dvb_device_type - type of the Digital TV device | |
42 | * | |
43 | * @DVB_DEVICE_SEC: Digital TV standalone Common Interface (CI) | |
44 | * @DVB_DEVICE_FRONTEND: Digital TV frontend. | |
45 | * @DVB_DEVICE_DEMUX: Digital TV demux. | |
46 | * @DVB_DEVICE_DVR: Digital TV digital video record (DVR). | |
47 | * @DVB_DEVICE_CA: Digital TV Conditional Access (CA). | |
48 | * @DVB_DEVICE_NET: Digital TV network. | |
49 | * | |
50 | * @DVB_DEVICE_VIDEO: Digital TV video decoder. | |
51 | * Deprecated. Used only on av7110-av. | |
52 | * @DVB_DEVICE_AUDIO: Digital TV audio decoder. | |
53 | * Deprecated. Used only on av7110-av. | |
54 | * @DVB_DEVICE_OSD: Digital TV On Screen Display (OSD). | |
55 | * Deprecated. Used only on av7110. | |
56 | */ | |
57 | enum dvb_device_type { | |
58 | DVB_DEVICE_SEC, | |
59 | DVB_DEVICE_FRONTEND, | |
60 | DVB_DEVICE_DEMUX, | |
61 | DVB_DEVICE_DVR, | |
62 | DVB_DEVICE_CA, | |
63 | DVB_DEVICE_NET, | |
64 | ||
65 | DVB_DEVICE_VIDEO, | |
66 | DVB_DEVICE_AUDIO, | |
67 | DVB_DEVICE_OSD, | |
68 | }; | |
1da177e4 | 69 | |
78e92006 JG |
70 | #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \ |
71 | static short adapter_nr[] = \ | |
72 | {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \ | |
73 | module_param_array(adapter_nr, short, NULL, 0444); \ | |
74 | MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers") | |
1da177e4 | 75 | |
9133aee0 MK |
76 | struct dvb_frontend; |
77 | ||
d071c833 MCC |
78 | /** |
79 | * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API | |
80 | * | |
81 | * @num: Number of the adapter | |
82 | * @list_head: List with the DVB adapters | |
83 | * @device_list: List with the DVB devices | |
84 | * @name: Name of the adapter | |
85 | * @proposed_mac: proposed MAC address for the adapter | |
86 | * @priv: private data | |
87 | * @device: pointer to struct device | |
88 | * @module: pointer to struct module | |
e96a8819 MG |
89 | * @mfe_shared: indicates mutually exclusive frontends. |
90 | * Use of this flag is currently deprecated. | |
d071c833 MCC |
91 | * @mfe_dvbdev: Frontend device in use, in the case of MFE |
92 | * @mfe_lock: Lock to prevent using the other frontends when MFE is | |
93 | * used. | |
f17c403a | 94 | * @mdev_lock: Protect access to the mdev pointer. |
d071c833 MCC |
95 | * @mdev: pointer to struct media_device, used when the media |
96 | * controller is used. | |
0230d60e MCC |
97 | * @conn: RF connector. Used only if the device has no separate |
98 | * tuner. | |
99 | * @conn_pads: pointer to struct media_pad associated with @conn; | |
d071c833 | 100 | */ |
1da177e4 LT |
101 | struct dvb_adapter { |
102 | int num; | |
103 | struct list_head list_head; | |
104 | struct list_head device_list; | |
105 | const char *name; | |
106 | u8 proposed_mac [6]; | |
107 | void* priv; | |
108 | ||
d09dbf92 AQ |
109 | struct device *device; |
110 | ||
1da177e4 | 111 | struct module *module; |
59b1842d DB |
112 | |
113 | int mfe_shared; /* indicates mutually exclusive frontends */ | |
114 | struct dvb_device *mfe_dvbdev; /* frontend device in use */ | |
115 | struct mutex mfe_lock; /* access lock for thread creation */ | |
a0246e02 MCC |
116 | |
117 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) | |
f17c403a | 118 | struct mutex mdev_lock; |
a0246e02 | 119 | struct media_device *mdev; |
0230d60e MCC |
120 | struct media_entity *conn; |
121 | struct media_pad *conn_pads; | |
a0246e02 | 122 | #endif |
1da177e4 LT |
123 | }; |
124 | ||
d071c833 MCC |
125 | /** |
126 | * struct dvb_device - represents a DVB device node | |
127 | * | |
128 | * @list_head: List head with all DVB devices | |
129 | * @fops: pointer to struct file_operations | |
130 | * @adapter: pointer to the adapter that holds this device node | |
6bbf7a85 | 131 | * @type: type of the device, as defined by &enum dvb_device_type. |
d071c833 MCC |
132 | * @minor: devnode minor number. Major number is always DVB_MAJOR. |
133 | * @id: device ID number, inside the adapter | |
134 | * @readers: Initialized by the caller. Each call to open() in Read Only mode | |
135 | * decreases this counter by one. | |
136 | * @writers: Initialized by the caller. Each call to open() in Read/Write | |
137 | * mode decreases this counter by one. | |
138 | * @users: Initialized by the caller. Each call to open() in any mode | |
139 | * decreases this counter by one. | |
140 | * @wait_queue: wait queue, used to wait for certain events inside one of | |
141 | * the DVB API callers | |
142 | * @kernel_ioctl: callback function used to handle ioctl calls from userspace. | |
143 | * @name: Name to be used for the device at the Media Controller | |
144 | * @entity: pointer to struct media_entity associated with the device node | |
145 | * @pads: pointer to struct media_pad associated with @entity; | |
146 | * @priv: private data | |
fdc40b5e MCC |
147 | * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to |
148 | * store the MC device node interface | |
149 | * @tsout_num_entities: Number of Transport Stream output entities | |
150 | * @tsout_entity: array with MC entities associated to each TS output node | |
151 | * @tsout_pads: array with the source pads for each @tsout_entity | |
d071c833 MCC |
152 | * |
153 | * This structure is used by the DVB core (frontend, CA, net, demux) in | |
154 | * order to create the device nodes. Usually, driver should not initialize | |
155 | * this struct diretly. | |
156 | */ | |
1da177e4 LT |
157 | struct dvb_device { |
158 | struct list_head list_head; | |
784e29d2 | 159 | const struct file_operations *fops; |
1da177e4 | 160 | struct dvb_adapter *adapter; |
6bbf7a85 | 161 | enum dvb_device_type type; |
5dd3f307 | 162 | int minor; |
1da177e4 LT |
163 | u32 id; |
164 | ||
165 | /* in theory, 'users' can vanish now, | |
166 | but I don't want to change too much now... */ | |
167 | int readers; | |
168 | int writers; | |
169 | int users; | |
170 | ||
ca5be9cd | 171 | wait_queue_head_t wait_queue; |
afd1a0c9 | 172 | /* don't really need those !? -- FIXME: use video_usercopy */ |
16ef8def | 173 | int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg); |
1da177e4 | 174 | |
a0246e02 MCC |
175 | /* Needed for media controller register/unregister */ |
176 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) | |
177 | const char *name; | |
178 | ||
172e9d3c | 179 | /* Allocated and filled inside dvbdev.c */ |
8211b187 | 180 | struct media_intf_devnode *intf_devnode; |
df2f94e5 MCC |
181 | |
182 | unsigned tsout_num_entities; | |
183 | struct media_entity *entity, *tsout_entity; | |
184 | struct media_pad *pads, *tsout_pads; | |
a0246e02 MCC |
185 | #endif |
186 | ||
1da177e4 LT |
187 | void *priv; |
188 | }; | |
189 | ||
d071c833 MCC |
190 | /** |
191 | * dvb_register_adapter - Registers a new DVB adapter | |
192 | * | |
193 | * @adap: pointer to struct dvb_adapter | |
194 | * @name: Adapter's name | |
195 | * @module: initialized with THIS_MODULE at the caller | |
196 | * @device: pointer to struct device that corresponds to the device driver | |
197 | * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter; | |
4a3fad70 | 198 | * to select among them. Typically, initialized with: |
d071c833 MCC |
199 | * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums) |
200 | */ | |
201 | int dvb_register_adapter(struct dvb_adapter *adap, const char *name, | |
202 | struct module *module, struct device *device, | |
203 | short *adapter_nums); | |
1da177e4 | 204 | |
d071c833 MCC |
205 | /** |
206 | * dvb_unregister_adapter - Unregisters a DVB adapter | |
207 | * | |
208 | * @adap: pointer to struct dvb_adapter | |
209 | */ | |
210 | int dvb_unregister_adapter(struct dvb_adapter *adap); | |
1da177e4 | 211 | |
d071c833 MCC |
212 | /** |
213 | * dvb_register_device - Registers a new DVB device | |
214 | * | |
215 | * @adap: pointer to struct dvb_adapter | |
216 | * @pdvbdev: pointer to the place where the new struct dvb_device will be | |
217 | * stored | |
218 | * @template: Template used to create &pdvbdev; | |
d071c833 | 219 | * @priv: private data |
6bbf7a85 | 220 | * @type: type of the device, as defined by &enum dvb_device_type. |
fdc40b5e MCC |
221 | * @demux_sink_pads: Number of demux outputs, to be used to create the TS |
222 | * outputs via the Media Controller. | |
d071c833 MCC |
223 | */ |
224 | int dvb_register_device(struct dvb_adapter *adap, | |
225 | struct dvb_device **pdvbdev, | |
226 | const struct dvb_device *template, | |
227 | void *priv, | |
6bbf7a85 | 228 | enum dvb_device_type type, |
df2f94e5 | 229 | int demux_sink_pads); |
d071c833 | 230 | |
1f4ed6cd MK |
231 | /** |
232 | * dvb_remove_device - Remove a registered DVB device | |
233 | * | |
234 | * This does not free memory. To do that, call dvb_free_device(). | |
235 | * | |
236 | * @dvbdev: pointer to struct dvb_device | |
237 | */ | |
238 | void dvb_remove_device(struct dvb_device *dvbdev); | |
239 | ||
240 | /** | |
241 | * dvb_free_device - Free memory occupied by a DVB device. | |
242 | * | |
243 | * Call dvb_unregister_device() before calling this function. | |
244 | * | |
245 | * @dvbdev: pointer to struct dvb_device | |
246 | */ | |
247 | void dvb_free_device(struct dvb_device *dvbdev); | |
248 | ||
d071c833 MCC |
249 | /** |
250 | * dvb_unregister_device - Unregisters a DVB device | |
251 | * | |
1f4ed6cd MK |
252 | * This is a combination of dvb_remove_device() and dvb_free_device(). |
253 | * Using this function is usually a mistake, and is often an indicator | |
254 | * for a use-after-free bug (when a userspace process keeps a file | |
255 | * handle to a detached device). | |
256 | * | |
d071c833 MCC |
257 | * @dvbdev: pointer to struct dvb_device |
258 | */ | |
259 | void dvb_unregister_device(struct dvb_device *dvbdev); | |
480884b6 MCC |
260 | |
261 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB | |
0230d60e MCC |
262 | /** |
263 | * dvb_create_media_graph - Creates media graph for the Digital TV part of the | |
4a3fad70 | 264 | * device. |
0230d60e | 265 | * |
400efa8e | 266 | * @adap: pointer to &struct dvb_adapter |
0230d60e | 267 | * @create_rf_connector: if true, it creates the RF connector too |
a0cce2a0 MCC |
268 | * |
269 | * This function checks all DVB-related functions at the media controller | |
270 | * entities and creates the needed links for the media graph. It is | |
271 | * capable of working with multiple tuners or multiple frontends, but it | |
272 | * won't create links if the device has multiple tuners and multiple frontends | |
273 | * or if the device has multiple muxes. In such case, the caller driver should | |
274 | * manually create the remaining links. | |
0230d60e MCC |
275 | */ |
276 | __must_check int dvb_create_media_graph(struct dvb_adapter *adap, | |
277 | bool create_rf_connector); | |
278 | ||
400efa8e MCC |
279 | /** |
280 | * dvb_register_media_controller - registers a media controller at DVB adapter | |
281 | * | |
282 | * @adap: pointer to &struct dvb_adapter | |
283 | * @mdev: pointer to &struct media_device | |
284 | */ | |
89a2c1d6 MCC |
285 | static inline void dvb_register_media_controller(struct dvb_adapter *adap, |
286 | struct media_device *mdev) | |
287 | { | |
288 | adap->mdev = mdev; | |
289 | } | |
290 | ||
400efa8e MCC |
291 | /** |
292 | * dvb_get_media_controller - gets the associated media controller | |
293 | * | |
294 | * @adap: pointer to &struct dvb_adapter | |
295 | */ | |
8f2a4a9d HV |
296 | static inline struct media_device * |
297 | dvb_get_media_controller(struct dvb_adapter *adap) | |
ce084d48 MCC |
298 | { |
299 | return adap->mdev; | |
300 | } | |
480884b6 | 301 | #else |
0230d60e MCC |
302 | static inline |
303 | int dvb_create_media_graph(struct dvb_adapter *adap, | |
304 | bool create_rf_connector) | |
f50d5166 MCC |
305 | { |
306 | return 0; | |
307 | }; | |
89a2c1d6 | 308 | #define dvb_register_media_controller(a, b) {} |
ce084d48 | 309 | #define dvb_get_media_controller(a) NULL |
480884b6 | 310 | #endif |
1da177e4 | 311 | |
400efa8e MCC |
312 | /** |
313 | * dvb_generic_open - Digital TV open function, used by DVB devices | |
314 | * | |
315 | * @inode: pointer to &struct inode. | |
316 | * @file: pointer to &struct file. | |
317 | * | |
318 | * Checks if a DVB devnode is still valid, and if the permissions are | |
319 | * OK and increment negative use count. | |
320 | */ | |
321 | int dvb_generic_open(struct inode *inode, struct file *file); | |
1da177e4 | 322 | |
400efa8e | 323 | /** |
b0649455 | 324 | * dvb_generic_release - Digital TV close function, used by DVB devices |
400efa8e MCC |
325 | * |
326 | * @inode: pointer to &struct inode. | |
327 | * @file: pointer to &struct file. | |
328 | * | |
329 | * Checks if a DVB devnode is still valid, and if the permissions are | |
330 | * OK and decrement negative use count. | |
331 | */ | |
332 | int dvb_generic_release(struct inode *inode, struct file *file); | |
1da177e4 | 333 | |
400efa8e MCC |
334 | /** |
335 | * dvb_generic_ioctl - Digital TV close function, used by DVB devices | |
336 | * | |
337 | * @file: pointer to &struct file. | |
338 | * @cmd: Ioctl name. | |
339 | * @arg: Ioctl argument. | |
340 | * | |
341 | * Checks if a DVB devnode and struct dvbdev.kernel_ioctl is still valid. | |
342 | * If so, calls dvb_usercopy(). | |
343 | */ | |
344 | long dvb_generic_ioctl(struct file *file, | |
345 | unsigned int cmd, unsigned long arg); | |
346 | ||
347 | /** | |
348 | * dvb_usercopy - copies data from/to userspace memory when an ioctl is | |
349 | * issued. | |
350 | * | |
351 | * @file: Pointer to struct &file. | |
352 | * @cmd: Ioctl name. | |
353 | * @arg: Ioctl argument. | |
354 | * @func: function that will actually handle the ioctl | |
355 | * | |
356 | * Ancillary function that uses ioctl direction and size to copy from | |
357 | * userspace. Then, it calls @func, and, if needed, data is copied back | |
358 | * to userspace. | |
359 | */ | |
d071c833 MCC |
360 | int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg, |
361 | int (*func)(struct file *file, unsigned int cmd, void *arg)); | |
1da177e4 | 362 | |
1980bfa6 | 363 | #if IS_ENABLED(CONFIG_I2C) |
8f569c0b MCC |
364 | |
365 | struct i2c_adapter; | |
366 | struct i2c_client; | |
367 | /** | |
368 | * dvb_module_probe - helper routine to probe an I2C module | |
369 | * | |
370 | * @module_name: | |
371 | * Name of the I2C module to be probed | |
372 | * @name: | |
373 | * Optional name for the I2C module. Used for debug purposes. | |
374 | * If %NULL, defaults to @module_name. | |
375 | * @adap: | |
376 | * pointer to &struct i2c_adapter that describes the I2C adapter where | |
377 | * the module will be bound. | |
378 | * @addr: | |
379 | * I2C address of the adapter, in 7-bit notation. | |
380 | * @platform_data: | |
381 | * Platform data to be passed to the I2C module probed. | |
382 | * | |
383 | * This function binds an I2C device into the DVB core. Should be used by | |
384 | * all drivers that use I2C bus to control the hardware. A module bound | |
385 | * with dvb_module_probe() should use dvb_module_release() to unbind. | |
386 | * | |
387 | * Return: | |
ffb18971 | 388 | * On success, return an &struct i2c_client, pointing to the bound |
8f569c0b MCC |
389 | * I2C device. %NULL otherwise. |
390 | * | |
391 | * .. note:: | |
392 | * | |
393 | * In the past, DVB modules (mainly, frontends) were bound via dvb_attach() | |
394 | * macro, with does an ugly hack, using I2C low level functions. Such | |
395 | * usage is deprecated and will be removed soon. Instead, use this routine. | |
396 | */ | |
397 | struct i2c_client *dvb_module_probe(const char *module_name, | |
398 | const char *name, | |
399 | struct i2c_adapter *adap, | |
400 | unsigned char addr, | |
401 | void *platform_data); | |
402 | ||
403 | /** | |
404 | * dvb_module_release - releases an I2C device allocated with | |
405 | * dvb_module_probe(). | |
406 | * | |
407 | * @client: pointer to &struct i2c_client with the I2C client to be released. | |
408 | * can be %NULL. | |
409 | * | |
410 | * This function should be used to free all resources reserved by | |
411 | * dvb_module_probe() and unbinding the I2C hardware. | |
412 | */ | |
413 | void dvb_module_release(struct i2c_client *client); | |
414 | ||
415 | #endif /* CONFIG_I2C */ | |
416 | ||
417 | /* Legacy generic DVB attach function. */ | |
149ef72d | 418 | #ifdef CONFIG_MEDIA_ATTACH |
400efa8e MCC |
419 | |
420 | /** | |
421 | * dvb_attach - attaches a DVB frontend into the DVB core. | |
422 | * | |
423 | * @FUNCTION: function on a frontend module to be called. | |
6f097ddb | 424 | * @ARGS: @FUNCTION arguments. |
400efa8e MCC |
425 | * |
426 | * This ancillary function loads a frontend module in runtime and runs | |
427 | * the @FUNCTION function there, with @ARGS. | |
428 | * As it increments symbol usage cont, at unregister, dvb_detach() | |
429 | * should be called. | |
8f569c0b MCC |
430 | * |
431 | * .. note:: | |
432 | * | |
433 | * In the past, DVB modules (mainly, frontends) were bound via dvb_attach() | |
434 | * macro, with does an ugly hack, using I2C low level functions. Such | |
435 | * usage is deprecated and will be removed soon. Instead, you should use | |
436 | * dvb_module_probe(). | |
400efa8e | 437 | */ |
d9955060 AQ |
438 | #define dvb_attach(FUNCTION, ARGS...) ({ \ |
439 | void *__r = NULL; \ | |
440 | typeof(&FUNCTION) __a = symbol_request(FUNCTION); \ | |
441 | if (__a) { \ | |
442 | __r = (void *) __a(ARGS); \ | |
443 | if (__r == NULL) \ | |
444 | symbol_put(FUNCTION); \ | |
445 | } else { \ | |
446 | printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \ | |
447 | } \ | |
448 | __r; \ | |
449 | }) | |
450 | ||
400efa8e MCC |
451 | /** |
452 | * dvb_detach - detaches a DVB frontend loaded via dvb_attach() | |
453 | * | |
454 | * @FUNC: attach function | |
455 | * | |
456 | * Decrements usage count for a function previously called via dvb_attach(). | |
457 | */ | |
458 | ||
4647f487 MCC |
459 | #define dvb_detach(FUNC) symbol_put_addr(FUNC) |
460 | ||
d9955060 AQ |
461 | #else |
462 | #define dvb_attach(FUNCTION, ARGS...) ({ \ | |
463 | FUNCTION(ARGS); \ | |
464 | }) | |
465 | ||
4647f487 MCC |
466 | #define dvb_detach(FUNC) {} |
467 | ||
8f569c0b | 468 | #endif /* CONFIG_MEDIA_ATTACH */ |
d9955060 | 469 | |
1da177e4 | 470 | #endif /* #ifndef _DVBDEV_H_ */ |