4 * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
5 * for convergence integrated media GmbH
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.
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.
22 #include <linux/types.h>
23 #include <linux/poll.h>
25 #include <linux/list.h>
26 #include <media/media-device.h>
30 #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0
31 #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS
33 #define DVB_MAX_ADAPTERS 16
36 #define DVB_UNSET (-1)
38 /* List of DVB device types */
41 * enum dvb_device_type - type of the Digital TV device
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.
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.
57 enum dvb_device_type
{
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")
79 * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API
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
87 * @device: pointer to struct device
88 * @module: pointer to struct module
89 * @mfe_shared: mfe shared: indicates mutually exclusive frontends
90 * Thie usage of this flag is currently deprecated
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
94 * @mdev: pointer to struct media_device, used when the media
96 * @conn: RF connector. Used only if the device has no separate
98 * @conn_pads: pointer to struct media_pad associated with @conn;
102 struct list_head list_head
;
103 struct list_head device_list
;
108 struct device
*device
;
110 struct module
*module
;
112 int mfe_shared
; /* indicates mutually exclusive frontends */
113 struct dvb_device
*mfe_dvbdev
; /* frontend device in use */
114 struct mutex mfe_lock
; /* access lock for thread creation */
116 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
117 struct media_device
*mdev
;
118 struct media_entity
*conn
;
119 struct media_pad
*conn_pads
;
124 * struct dvb_device - represents a DVB device node
126 * @list_head: List head with all DVB devices
127 * @fops: pointer to struct file_operations
128 * @adapter: pointer to the adapter that holds this device node
129 * @type: type of the device, as defined by &enum dvb_device_type.
130 * @minor: devnode minor number. Major number is always DVB_MAJOR.
131 * @id: device ID number, inside the adapter
132 * @readers: Initialized by the caller. Each call to open() in Read Only mode
133 * decreases this counter by one.
134 * @writers: Initialized by the caller. Each call to open() in Read/Write
135 * mode decreases this counter by one.
136 * @users: Initialized by the caller. Each call to open() in any mode
137 * decreases this counter by one.
138 * @wait_queue: wait queue, used to wait for certain events inside one of
139 * the DVB API callers
140 * @kernel_ioctl: callback function used to handle ioctl calls from userspace.
141 * @name: Name to be used for the device at the Media Controller
142 * @entity: pointer to struct media_entity associated with the device node
143 * @pads: pointer to struct media_pad associated with @entity;
144 * @priv: private data
145 * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to
146 * store the MC device node interface
147 * @tsout_num_entities: Number of Transport Stream output entities
148 * @tsout_entity: array with MC entities associated to each TS output node
149 * @tsout_pads: array with the source pads for each @tsout_entity
151 * This structure is used by the DVB core (frontend, CA, net, demux) in
152 * order to create the device nodes. Usually, driver should not initialize
153 * this struct diretly.
156 struct list_head list_head
;
157 const struct file_operations
*fops
;
158 struct dvb_adapter
*adapter
;
159 enum dvb_device_type type
;
163 /* in theory, 'users' can vanish now,
164 but I don't want to change too much now... */
169 wait_queue_head_t wait_queue
;
170 /* don't really need those !? -- FIXME: use video_usercopy */
171 int (*kernel_ioctl
)(struct file
*file
, unsigned int cmd
, void *arg
);
173 /* Needed for media controller register/unregister */
174 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
177 /* Allocated and filled inside dvbdev.c */
178 struct media_intf_devnode
*intf_devnode
;
180 unsigned tsout_num_entities
;
181 struct media_entity
*entity
, *tsout_entity
;
182 struct media_pad
*pads
, *tsout_pads
;
189 * dvb_register_adapter - Registers a new DVB adapter
191 * @adap: pointer to struct dvb_adapter
192 * @name: Adapter's name
193 * @module: initialized with THIS_MODULE at the caller
194 * @device: pointer to struct device that corresponds to the device driver
195 * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;
196 * to select among them. Typically, initialized with:
197 * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)
199 int dvb_register_adapter(struct dvb_adapter
*adap
, const char *name
,
200 struct module
*module
, struct device
*device
,
201 short *adapter_nums
);
204 * dvb_unregister_adapter - Unregisters a DVB adapter
206 * @adap: pointer to struct dvb_adapter
208 int dvb_unregister_adapter(struct dvb_adapter
*adap
);
211 * dvb_register_device - Registers a new DVB device
213 * @adap: pointer to struct dvb_adapter
214 * @pdvbdev: pointer to the place where the new struct dvb_device will be
216 * @template: Template used to create &pdvbdev;
217 * @priv: private data
218 * @type: type of the device, as defined by &enum dvb_device_type.
219 * @demux_sink_pads: Number of demux outputs, to be used to create the TS
220 * outputs via the Media Controller.
222 int dvb_register_device(struct dvb_adapter
*adap
,
223 struct dvb_device
**pdvbdev
,
224 const struct dvb_device
*template,
226 enum dvb_device_type type
,
227 int demux_sink_pads
);
230 * dvb_remove_device - Remove a registered DVB device
232 * This does not free memory. To do that, call dvb_free_device().
234 * @dvbdev: pointer to struct dvb_device
236 void dvb_remove_device(struct dvb_device
*dvbdev
);
239 * dvb_free_device - Free memory occupied by a DVB device.
241 * Call dvb_unregister_device() before calling this function.
243 * @dvbdev: pointer to struct dvb_device
245 void dvb_free_device(struct dvb_device
*dvbdev
);
248 * dvb_unregister_device - Unregisters a DVB device
250 * This is a combination of dvb_remove_device() and dvb_free_device().
251 * Using this function is usually a mistake, and is often an indicator
252 * for a use-after-free bug (when a userspace process keeps a file
253 * handle to a detached device).
255 * @dvbdev: pointer to struct dvb_device
257 void dvb_unregister_device(struct dvb_device
*dvbdev
);
259 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
261 * dvb_create_media_graph - Creates media graph for the Digital TV part of the
264 * @adap: pointer to &struct dvb_adapter
265 * @create_rf_connector: if true, it creates the RF connector too
267 * This function checks all DVB-related functions at the media controller
268 * entities and creates the needed links for the media graph. It is
269 * capable of working with multiple tuners or multiple frontends, but it
270 * won't create links if the device has multiple tuners and multiple frontends
271 * or if the device has multiple muxes. In such case, the caller driver should
272 * manually create the remaining links.
274 __must_check
int dvb_create_media_graph(struct dvb_adapter
*adap
,
275 bool create_rf_connector
);
278 * dvb_register_media_controller - registers a media controller at DVB adapter
280 * @adap: pointer to &struct dvb_adapter
281 * @mdev: pointer to &struct media_device
283 static inline void dvb_register_media_controller(struct dvb_adapter
*adap
,
284 struct media_device
*mdev
)
290 * dvb_get_media_controller - gets the associated media controller
292 * @adap: pointer to &struct dvb_adapter
294 static inline struct media_device
295 *dvb_get_media_controller(struct dvb_adapter
*adap
)
301 int dvb_create_media_graph(struct dvb_adapter
*adap
,
302 bool create_rf_connector
)
306 #define dvb_register_media_controller(a, b) {}
307 #define dvb_get_media_controller(a) NULL
311 * dvb_generic_open - Digital TV open function, used by DVB devices
313 * @inode: pointer to &struct inode.
314 * @file: pointer to &struct file.
316 * Checks if a DVB devnode is still valid, and if the permissions are
317 * OK and increment negative use count.
319 int dvb_generic_open(struct inode
*inode
, struct file
*file
);
322 * dvb_generic_close - Digital TV close function, used by DVB devices
324 * @inode: pointer to &struct inode.
325 * @file: pointer to &struct file.
327 * Checks if a DVB devnode is still valid, and if the permissions are
328 * OK and decrement negative use count.
330 int dvb_generic_release(struct inode
*inode
, struct file
*file
);
333 * dvb_generic_ioctl - Digital TV close function, used by DVB devices
335 * @file: pointer to &struct file.
337 * @arg: Ioctl argument.
339 * Checks if a DVB devnode and struct dvbdev.kernel_ioctl is still valid.
340 * If so, calls dvb_usercopy().
342 long dvb_generic_ioctl(struct file
*file
,
343 unsigned int cmd
, unsigned long arg
);
346 * dvb_usercopy - copies data from/to userspace memory when an ioctl is
349 * @file: Pointer to struct &file.
351 * @arg: Ioctl argument.
352 * @func: function that will actually handle the ioctl
354 * Ancillary function that uses ioctl direction and size to copy from
355 * userspace. Then, it calls @func, and, if needed, data is copied back
358 int dvb_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
359 int (*func
)(struct file
*file
, unsigned int cmd
, void *arg
));
361 /** generic DVB attach function. */
362 #ifdef CONFIG_MEDIA_ATTACH
365 * dvb_attach - attaches a DVB frontend into the DVB core.
367 * @FUNCTION: function on a frontend module to be called.
368 * @ARGS...: @FUNCTION arguments.
370 * This ancillary function loads a frontend module in runtime and runs
371 * the @FUNCTION function there, with @ARGS.
372 * As it increments symbol usage cont, at unregister, dvb_detach()
375 #define dvb_attach(FUNCTION, ARGS...) ({ \
377 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
379 __r = (void *) __a(ARGS); \
381 symbol_put(FUNCTION); \
383 printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
389 * dvb_detach - detaches a DVB frontend loaded via dvb_attach()
391 * @FUNC: attach function
393 * Decrements usage count for a function previously called via dvb_attach().
396 #define dvb_detach(FUNC) symbol_put_addr(FUNC)
399 #define dvb_attach(FUNCTION, ARGS...) ({ \
403 #define dvb_detach(FUNC) {}
407 #endif /* #ifndef _DVBDEV_H_ */