dvbdev.h 9.4 KB

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