Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[sfrench/cifs-2.6.git] / drivers / media / dvb / 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  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *
21  */
22
23 #ifndef _DVBDEV_H_
24 #define _DVBDEV_H_
25
26 #include <linux/types.h>
27 #include <linux/poll.h>
28 #include <linux/fs.h>
29 #include <linux/list.h>
30
31 #define DVB_MAJOR 212
32
33 #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0
34   #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS
35 #else
36   #define DVB_MAX_ADAPTERS 8
37 #endif
38
39 #define DVB_UNSET (-1)
40
41 #define DVB_DEVICE_VIDEO      0
42 #define DVB_DEVICE_AUDIO      1
43 #define DVB_DEVICE_SEC        2
44 #define DVB_DEVICE_FRONTEND   3
45 #define DVB_DEVICE_DEMUX      4
46 #define DVB_DEVICE_DVR        5
47 #define DVB_DEVICE_CA         6
48 #define DVB_DEVICE_NET        7
49 #define DVB_DEVICE_OSD        8
50
51 #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \
52         static short adapter_nr[] = \
53                 {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \
54         module_param_array(adapter_nr, short, NULL, 0444); \
55         MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")
56
57 struct dvb_frontend;
58
59 struct dvb_adapter {
60         int num;
61         struct list_head list_head;
62         struct list_head device_list;
63         const char *name;
64         u8 proposed_mac [6];
65         void* priv;
66
67         struct device *device;
68
69         struct module *module;
70
71         int mfe_shared;                 /* indicates mutually exclusive frontends */
72         struct dvb_device *mfe_dvbdev;  /* frontend device in use */
73         struct mutex mfe_lock;          /* access lock for thread creation */
74
75         /* Allow the adapter/bridge driver to perform an action before and/or
76          * after the core handles an ioctl:
77          *
78          * DVB_FE_IOCTL_PRE indicates that the ioctl has not yet been handled.
79          * DVB_FE_IOCTL_POST indicates that the ioctl has been handled.
80          *
81          * When DVB_FE_IOCTL_PRE is passed to the callback as the stage arg:
82          *
83          * return 0 to allow dvb-core to handle the ioctl.
84          * return a positive int to prevent dvb-core from handling the ioctl,
85          *      and exit without error.
86          * return a negative int to prevent dvb-core from handling the ioctl,
87          *      and return that value as an error.
88          *
89          * When DVB_FE_IOCTL_POST is passed to the callback as the stage arg:
90          *
91          * return 0 to allow the dvb_frontend ioctl handler to exit normally.
92          * return a negative int to cause the dvb_frontend ioctl handler to
93          *      return that value as an error.
94          */
95 #define DVB_FE_IOCTL_PRE 0
96 #define DVB_FE_IOCTL_POST 1
97         int (*fe_ioctl_override)(struct dvb_frontend *fe,
98                                  unsigned int cmd, void *parg,
99                                  unsigned int stage);
100 };
101
102
103 struct dvb_device {
104         struct list_head list_head;
105         const struct file_operations *fops;
106         struct dvb_adapter *adapter;
107         int type;
108         int minor;
109         u32 id;
110
111         /* in theory, 'users' can vanish now,
112            but I don't want to change too much now... */
113         int readers;
114         int writers;
115         int users;
116
117         wait_queue_head_t         wait_queue;
118         /* don't really need those !? -- FIXME: use video_usercopy  */
119         int (*kernel_ioctl)(struct inode *inode, struct file *file,
120                             unsigned int cmd, void *arg);
121
122         void *priv;
123 };
124
125
126 extern int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
127                                 struct module *module, struct device *device,
128                                 short *adapter_nums);
129 extern int dvb_unregister_adapter (struct dvb_adapter *adap);
130
131 extern int dvb_register_device (struct dvb_adapter *adap,
132                                 struct dvb_device **pdvbdev,
133                                 const struct dvb_device *template,
134                                 void *priv,
135                                 int type);
136
137 extern void dvb_unregister_device (struct dvb_device *dvbdev);
138
139 extern int dvb_generic_open (struct inode *inode, struct file *file);
140 extern int dvb_generic_release (struct inode *inode, struct file *file);
141 extern int dvb_generic_ioctl (struct inode *inode, struct file *file,
142                               unsigned int cmd, unsigned long arg);
143
144 /* we don't mess with video_usercopy() any more,
145 we simply define out own dvb_usercopy(), which will hopefully become
146 generic_usercopy()  someday... */
147
148 extern int dvb_usercopy(struct inode *inode, struct file *file,
149                             unsigned int cmd, unsigned long arg,
150                             int (*func)(struct inode *inode, struct file *file,
151                             unsigned int cmd, void *arg));
152
153 /** generic DVB attach function. */
154 #ifdef CONFIG_MEDIA_ATTACH
155 #define dvb_attach(FUNCTION, ARGS...) ({ \
156         void *__r = NULL; \
157         typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
158         if (__a) { \
159                 __r = (void *) __a(ARGS); \
160                 if (__r == NULL) \
161                         symbol_put(FUNCTION); \
162         } else { \
163                 printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
164         } \
165         __r; \
166 })
167
168 #else
169 #define dvb_attach(FUNCTION, ARGS...) ({ \
170         FUNCTION(ARGS); \
171 })
172
173 #endif
174
175 #endif /* #ifndef _DVBDEV_H_ */