GNU Linux-libre 4.14.328-gnu1
[releases.git] / drivers / media / dvb-core / dvbdev.h
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  *
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>
26 #include <media/media-device.h>
27
28 #define DVB_MAJOR 212
29
30 #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0
31   #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS
32 #else
33   #define DVB_MAX_ADAPTERS 16
34 #endif
35
36 #define DVB_UNSET (-1)
37
38 #define DVB_DEVICE_VIDEO      0
39 #define DVB_DEVICE_AUDIO      1
40 #define DVB_DEVICE_SEC        2
41 #define DVB_DEVICE_FRONTEND   3
42 #define DVB_DEVICE_DEMUX      4
43 #define DVB_DEVICE_DVR        5
44 #define DVB_DEVICE_CA         6
45 #define DVB_DEVICE_NET        7
46 #define DVB_DEVICE_OSD        8
47
48 #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \
49         static short adapter_nr[] = \
50                 {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \
51         module_param_array(adapter_nr, short, NULL, 0444); \
52         MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")
53
54 struct dvb_frontend;
55
56 /**
57  * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API
58  *
59  * @num:                Number of the adapter
60  * @list_head:          List with the DVB adapters
61  * @device_list:        List with the DVB devices
62  * @name:               Name of the adapter
63  * @proposed_mac:       proposed MAC address for the adapter
64  * @priv:               private data
65  * @device:             pointer to struct device
66  * @module:             pointer to struct module
67  * @mfe_shared:         mfe shared: indicates mutually exclusive frontends
68  *                      Thie usage of this flag is currently deprecated
69  * @mfe_dvbdev:         Frontend device in use, in the case of MFE
70  * @mfe_lock:           Lock to prevent using the other frontends when MFE is
71  *                      used.
72  * @mdev:               pointer to struct media_device, used when the media
73  *                      controller is used.
74  * @conn:               RF connector. Used only if the device has no separate
75  *                      tuner.
76  * @conn_pads:          pointer to struct media_pad associated with @conn;
77  */
78 struct dvb_adapter {
79         int num;
80         struct list_head list_head;
81         struct list_head device_list;
82         const char *name;
83         u8 proposed_mac [6];
84         void* priv;
85
86         struct device *device;
87
88         struct module *module;
89
90         int mfe_shared;                 /* indicates mutually exclusive frontends */
91         struct dvb_device *mfe_dvbdev;  /* frontend device in use */
92         struct mutex mfe_lock;          /* access lock for thread creation */
93
94 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
95         struct media_device *mdev;
96         struct media_entity *conn;
97         struct media_pad *conn_pads;
98 #endif
99 };
100
101 /**
102  * struct dvb_device - represents a DVB device node
103  *
104  * @list_head:  List head with all DVB devices
105  * @fops:       pointer to struct file_operations
106  * @adapter:    pointer to the adapter that holds this device node
107  * @type:       type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND,
108  *              DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET
109  * @minor:      devnode minor number. Major number is always DVB_MAJOR.
110  * @id:         device ID number, inside the adapter
111  * @readers:    Initialized by the caller. Each call to open() in Read Only mode
112  *              decreases this counter by one.
113  * @writers:    Initialized by the caller. Each call to open() in Read/Write
114  *              mode decreases this counter by one.
115  * @users:      Initialized by the caller. Each call to open() in any mode
116  *              decreases this counter by one.
117  * @wait_queue: wait queue, used to wait for certain events inside one of
118  *              the DVB API callers
119  * @kernel_ioctl: callback function used to handle ioctl calls from userspace.
120  * @name:       Name to be used for the device at the Media Controller
121  * @entity:     pointer to struct media_entity associated with the device node
122  * @pads:       pointer to struct media_pad associated with @entity;
123  * @priv:       private data
124  * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to
125  *              store the MC device node interface
126  * @tsout_num_entities: Number of Transport Stream output entities
127  * @tsout_entity: array with MC entities associated to each TS output node
128  * @tsout_pads: array with the source pads for each @tsout_entity
129  *
130  * This structure is used by the DVB core (frontend, CA, net, demux) in
131  * order to create the device nodes. Usually, driver should not initialize
132  * this struct diretly.
133  */
134 struct dvb_device {
135         struct list_head list_head;
136         struct kref ref;
137         const struct file_operations *fops;
138         struct dvb_adapter *adapter;
139         int type;
140         int minor;
141         u32 id;
142
143         /* in theory, 'users' can vanish now,
144            but I don't want to change too much now... */
145         int readers;
146         int writers;
147         int users;
148
149         wait_queue_head_t         wait_queue;
150         /* don't really need those !? -- FIXME: use video_usercopy  */
151         int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);
152
153         /* Needed for media controller register/unregister */
154 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
155         const char *name;
156
157         /* Allocated and filled inside dvbdev.c */
158         struct media_intf_devnode *intf_devnode;
159
160         unsigned tsout_num_entities;
161         struct media_entity *entity, *tsout_entity;
162         struct media_pad *pads, *tsout_pads;
163 #endif
164
165         void *priv;
166 };
167
168 /**
169  * dvb_device_get - Increase dvb_device reference
170  *
171  * @dvbdev:     pointer to struct dvb_device
172  */
173 struct dvb_device *dvb_device_get(struct dvb_device *dvbdev);
174
175 /**
176  * dvb_device_get - Decrease dvb_device reference
177  *
178  * @dvbdev:     pointer to struct dvb_device
179  */
180 void dvb_device_put(struct dvb_device *dvbdev);
181
182 /**
183  * dvb_register_adapter - Registers a new DVB adapter
184  *
185  * @adap:       pointer to struct dvb_adapter
186  * @name:       Adapter's name
187  * @module:     initialized with THIS_MODULE at the caller
188  * @device:     pointer to struct device that corresponds to the device driver
189  * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;
190  *              to select among them. Typically, initialized with:
191  *              DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)
192  */
193 int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
194                          struct module *module, struct device *device,
195                          short *adapter_nums);
196
197 /**
198  * dvb_unregister_adapter - Unregisters a DVB adapter
199  *
200  * @adap:       pointer to struct dvb_adapter
201  */
202 int dvb_unregister_adapter(struct dvb_adapter *adap);
203
204 /**
205  * dvb_register_device - Registers a new DVB device
206  *
207  * @adap:       pointer to struct dvb_adapter
208  * @pdvbdev:    pointer to the place where the new struct dvb_device will be
209  *              stored
210  * @template:   Template used to create &pdvbdev;
211  * @priv:       private data
212  * @type:       type of the device: %DVB_DEVICE_SEC, %DVB_DEVICE_FRONTEND,
213  *              %DVB_DEVICE_DEMUX, %DVB_DEVICE_DVR, %DVB_DEVICE_CA,
214  *              %DVB_DEVICE_NET
215  * @demux_sink_pads: Number of demux outputs, to be used to create the TS
216  *              outputs via the Media Controller.
217  */
218 int dvb_register_device(struct dvb_adapter *adap,
219                         struct dvb_device **pdvbdev,
220                         const struct dvb_device *template,
221                         void *priv,
222                         int type,
223                         int demux_sink_pads);
224
225 /**
226  * dvb_remove_device - Remove a registered DVB device
227  *
228  * This does not free memory. dvb_free_device() will do that when
229  * reference counter is empty
230  *
231  * @dvbdev:     pointer to struct dvb_device
232  */
233 void dvb_remove_device(struct dvb_device *dvbdev);
234
235
236 /**
237  * dvb_unregister_device - Unregisters a DVB device
238  *
239  * @dvbdev:     pointer to struct dvb_device
240  */
241 void dvb_unregister_device(struct dvb_device *dvbdev);
242
243 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
244 /**
245  * dvb_create_media_graph - Creates media graph for the Digital TV part of the
246  *                              device.
247  *
248  * @adap:                       pointer to struct dvb_adapter
249  * @create_rf_connector:        if true, it creates the RF connector too
250  *
251  * This function checks all DVB-related functions at the media controller
252  * entities and creates the needed links for the media graph. It is
253  * capable of working with multiple tuners or multiple frontends, but it
254  * won't create links if the device has multiple tuners and multiple frontends
255  * or if the device has multiple muxes. In such case, the caller driver should
256  * manually create the remaining links.
257  */
258 __must_check int dvb_create_media_graph(struct dvb_adapter *adap,
259                                         bool create_rf_connector);
260
261 static inline void dvb_register_media_controller(struct dvb_adapter *adap,
262                                                  struct media_device *mdev)
263 {
264         adap->mdev = mdev;
265 }
266
267 static inline struct media_device
268 *dvb_get_media_controller(struct dvb_adapter *adap)
269 {
270         return adap->mdev;
271 }
272 #else
273 static inline
274 int dvb_create_media_graph(struct dvb_adapter *adap,
275                            bool create_rf_connector)
276 {
277         return 0;
278 };
279 #define dvb_register_media_controller(a, b) {}
280 #define dvb_get_media_controller(a) NULL
281 #endif
282
283 int dvb_generic_open (struct inode *inode, struct file *file);
284 int dvb_generic_release (struct inode *inode, struct file *file);
285 long dvb_generic_ioctl (struct file *file,
286                               unsigned int cmd, unsigned long arg);
287
288 /* we don't mess with video_usercopy() any more,
289 we simply define out own dvb_usercopy(), which will hopefully become
290 generic_usercopy()  someday... */
291
292 int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
293                  int (*func)(struct file *file, unsigned int cmd, void *arg));
294
295 /** generic DVB attach function. */
296 #ifdef CONFIG_MEDIA_ATTACH
297 #define dvb_attach(FUNCTION, ARGS...) ({ \
298         void *__r = NULL; \
299         typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
300         if (__a) { \
301                 __r = (void *) __a(ARGS); \
302                 if (__r == NULL) \
303                         symbol_put(FUNCTION); \
304         } else { \
305                 printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
306         } \
307         __r; \
308 })
309
310 #define dvb_detach(FUNC)        symbol_put_addr(FUNC)
311
312 #else
313 #define dvb_attach(FUNCTION, ARGS...) ({ \
314         FUNCTION(ARGS); \
315 })
316
317 #define dvb_detach(FUNC)        {}
318
319 #endif
320
321 #endif /* #ifndef _DVBDEV_H_ */