dvbdev.h 9.8 KB

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