dvbdev.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. /* List of DVB device types */
  33. /**
  34. * enum dvb_device_type - type of the Digital TV device
  35. *
  36. * @DVB_DEVICE_SEC: Digital TV standalone Common Interface (CI)
  37. * @DVB_DEVICE_FRONTEND: Digital TV frontend.
  38. * @DVB_DEVICE_DEMUX: Digital TV demux.
  39. * @DVB_DEVICE_DVR: Digital TV digital video record (DVR).
  40. * @DVB_DEVICE_CA: Digital TV Conditional Access (CA).
  41. * @DVB_DEVICE_NET: Digital TV network.
  42. *
  43. * @DVB_DEVICE_VIDEO: Digital TV video decoder.
  44. * Deprecated. Used only on av7110-av.
  45. * @DVB_DEVICE_AUDIO: Digital TV audio decoder.
  46. * Deprecated. Used only on av7110-av.
  47. * @DVB_DEVICE_OSD: Digital TV On Screen Display (OSD).
  48. * Deprecated. Used only on av7110.
  49. */
  50. enum dvb_device_type {
  51. DVB_DEVICE_SEC,
  52. DVB_DEVICE_FRONTEND,
  53. DVB_DEVICE_DEMUX,
  54. DVB_DEVICE_DVR,
  55. DVB_DEVICE_CA,
  56. DVB_DEVICE_NET,
  57. DVB_DEVICE_VIDEO,
  58. DVB_DEVICE_AUDIO,
  59. DVB_DEVICE_OSD,
  60. };
  61. #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \
  62. static short adapter_nr[] = \
  63. {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \
  64. module_param_array(adapter_nr, short, NULL, 0444); \
  65. MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")
  66. struct dvb_frontend;
  67. /**
  68. * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API
  69. *
  70. * @num: Number of the adapter
  71. * @list_head: List with the DVB adapters
  72. * @device_list: List with the DVB devices
  73. * @name: Name of the adapter
  74. * @proposed_mac: proposed MAC address for the adapter
  75. * @priv: private data
  76. * @device: pointer to struct device
  77. * @module: pointer to struct module
  78. * @mfe_shared: mfe shared: indicates mutually exclusive frontends
  79. * Thie usage of this flag is currently deprecated
  80. * @mfe_dvbdev: Frontend device in use, in the case of MFE
  81. * @mfe_lock: Lock to prevent using the other frontends when MFE is
  82. * used.
  83. * @mdev_lock: Protect access to the mdev pointer.
  84. * @mdev: pointer to struct media_device, used when the media
  85. * controller is used.
  86. * @conn: RF connector. Used only if the device has no separate
  87. * tuner.
  88. * @conn_pads: pointer to struct media_pad associated with @conn;
  89. */
  90. struct dvb_adapter {
  91. int num;
  92. struct list_head list_head;
  93. struct list_head device_list;
  94. const char *name;
  95. u8 proposed_mac [6];
  96. void* priv;
  97. struct device *device;
  98. struct module *module;
  99. int mfe_shared; /* indicates mutually exclusive frontends */
  100. struct dvb_device *mfe_dvbdev; /* frontend device in use */
  101. struct mutex mfe_lock; /* access lock for thread creation */
  102. #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
  103. struct mutex mdev_lock;
  104. struct media_device *mdev;
  105. struct media_entity *conn;
  106. struct media_pad *conn_pads;
  107. #endif
  108. };
  109. /**
  110. * struct dvb_device - represents a DVB device node
  111. *
  112. * @list_head: List head with all DVB devices
  113. * @fops: pointer to struct file_operations
  114. * @adapter: pointer to the adapter that holds this device node
  115. * @type: type of the device, as defined by &enum dvb_device_type.
  116. * @minor: devnode minor number. Major number is always DVB_MAJOR.
  117. * @id: device ID number, inside the adapter
  118. * @readers: Initialized by the caller. Each call to open() in Read Only mode
  119. * decreases this counter by one.
  120. * @writers: Initialized by the caller. Each call to open() in Read/Write
  121. * mode decreases this counter by one.
  122. * @users: Initialized by the caller. Each call to open() in any mode
  123. * decreases this counter by one.
  124. * @wait_queue: wait queue, used to wait for certain events inside one of
  125. * the DVB API callers
  126. * @kernel_ioctl: callback function used to handle ioctl calls from userspace.
  127. * @name: Name to be used for the device at the Media Controller
  128. * @entity: pointer to struct media_entity associated with the device node
  129. * @pads: pointer to struct media_pad associated with @entity;
  130. * @priv: private data
  131. * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to
  132. * store the MC device node interface
  133. * @tsout_num_entities: Number of Transport Stream output entities
  134. * @tsout_entity: array with MC entities associated to each TS output node
  135. * @tsout_pads: array with the source pads for each @tsout_entity
  136. *
  137. * This structure is used by the DVB core (frontend, CA, net, demux) in
  138. * order to create the device nodes. Usually, driver should not initialize
  139. * this struct diretly.
  140. */
  141. struct dvb_device {
  142. struct list_head list_head;
  143. const struct file_operations *fops;
  144. struct dvb_adapter *adapter;
  145. enum dvb_device_type type;
  146. int minor;
  147. u32 id;
  148. /* in theory, 'users' can vanish now,
  149. but I don't want to change too much now... */
  150. int readers;
  151. int writers;
  152. int users;
  153. wait_queue_head_t wait_queue;
  154. /* don't really need those !? -- FIXME: use video_usercopy */
  155. int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);
  156. /* Needed for media controller register/unregister */
  157. #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
  158. const char *name;
  159. /* Allocated and filled inside dvbdev.c */
  160. struct media_intf_devnode *intf_devnode;
  161. unsigned tsout_num_entities;
  162. struct media_entity *entity, *tsout_entity;
  163. struct media_pad *pads, *tsout_pads;
  164. #endif
  165. void *priv;
  166. };
  167. /**
  168. * dvb_register_adapter - Registers a new DVB adapter
  169. *
  170. * @adap: pointer to struct dvb_adapter
  171. * @name: Adapter's name
  172. * @module: initialized with THIS_MODULE at the caller
  173. * @device: pointer to struct device that corresponds to the device driver
  174. * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;
  175. * to select among them. Typically, initialized with:
  176. * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)
  177. */
  178. int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
  179. struct module *module, struct device *device,
  180. short *adapter_nums);
  181. /**
  182. * dvb_unregister_adapter - Unregisters a DVB adapter
  183. *
  184. * @adap: pointer to struct dvb_adapter
  185. */
  186. int dvb_unregister_adapter(struct dvb_adapter *adap);
  187. /**
  188. * dvb_register_device - Registers a new DVB device
  189. *
  190. * @adap: pointer to struct dvb_adapter
  191. * @pdvbdev: pointer to the place where the new struct dvb_device will be
  192. * stored
  193. * @template: Template used to create &pdvbdev;
  194. * @priv: private data
  195. * @type: type of the device, as defined by &enum dvb_device_type.
  196. * @demux_sink_pads: Number of demux outputs, to be used to create the TS
  197. * outputs via the Media Controller.
  198. */
  199. int dvb_register_device(struct dvb_adapter *adap,
  200. struct dvb_device **pdvbdev,
  201. const struct dvb_device *template,
  202. void *priv,
  203. enum dvb_device_type type,
  204. int demux_sink_pads);
  205. /**
  206. * dvb_remove_device - Remove a registered DVB device
  207. *
  208. * This does not free memory. To do that, call dvb_free_device().
  209. *
  210. * @dvbdev: pointer to struct dvb_device
  211. */
  212. void dvb_remove_device(struct dvb_device *dvbdev);
  213. /**
  214. * dvb_free_device - Free memory occupied by a DVB device.
  215. *
  216. * Call dvb_unregister_device() before calling this function.
  217. *
  218. * @dvbdev: pointer to struct dvb_device
  219. */
  220. void dvb_free_device(struct dvb_device *dvbdev);
  221. /**
  222. * dvb_unregister_device - Unregisters a DVB device
  223. *
  224. * This is a combination of dvb_remove_device() and dvb_free_device().
  225. * Using this function is usually a mistake, and is often an indicator
  226. * for a use-after-free bug (when a userspace process keeps a file
  227. * handle to a detached device).
  228. *
  229. * @dvbdev: pointer to struct dvb_device
  230. */
  231. void dvb_unregister_device(struct dvb_device *dvbdev);
  232. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  233. /**
  234. * dvb_create_media_graph - Creates media graph for the Digital TV part of the
  235. * device.
  236. *
  237. * @adap: pointer to &struct dvb_adapter
  238. * @create_rf_connector: if true, it creates the RF connector too
  239. *
  240. * This function checks all DVB-related functions at the media controller
  241. * entities and creates the needed links for the media graph. It is
  242. * capable of working with multiple tuners or multiple frontends, but it
  243. * won't create links if the device has multiple tuners and multiple frontends
  244. * or if the device has multiple muxes. In such case, the caller driver should
  245. * manually create the remaining links.
  246. */
  247. __must_check int dvb_create_media_graph(struct dvb_adapter *adap,
  248. bool create_rf_connector);
  249. /**
  250. * dvb_register_media_controller - registers a media controller at DVB adapter
  251. *
  252. * @adap: pointer to &struct dvb_adapter
  253. * @mdev: pointer to &struct media_device
  254. */
  255. static inline void dvb_register_media_controller(struct dvb_adapter *adap,
  256. struct media_device *mdev)
  257. {
  258. adap->mdev = mdev;
  259. }
  260. /**
  261. * dvb_get_media_controller - gets the associated media controller
  262. *
  263. * @adap: pointer to &struct dvb_adapter
  264. */
  265. static inline struct media_device
  266. *dvb_get_media_controller(struct dvb_adapter *adap)
  267. {
  268. return adap->mdev;
  269. }
  270. #else
  271. static inline
  272. int dvb_create_media_graph(struct dvb_adapter *adap,
  273. bool create_rf_connector)
  274. {
  275. return 0;
  276. };
  277. #define dvb_register_media_controller(a, b) {}
  278. #define dvb_get_media_controller(a) NULL
  279. #endif
  280. /**
  281. * dvb_generic_open - Digital TV open function, used by DVB devices
  282. *
  283. * @inode: pointer to &struct inode.
  284. * @file: pointer to &struct file.
  285. *
  286. * Checks if a DVB devnode is still valid, and if the permissions are
  287. * OK and increment negative use count.
  288. */
  289. int dvb_generic_open(struct inode *inode, struct file *file);
  290. /**
  291. * dvb_generic_close - Digital TV close function, used by DVB devices
  292. *
  293. * @inode: pointer to &struct inode.
  294. * @file: pointer to &struct file.
  295. *
  296. * Checks if a DVB devnode is still valid, and if the permissions are
  297. * OK and decrement negative use count.
  298. */
  299. int dvb_generic_release(struct inode *inode, struct file *file);
  300. /**
  301. * dvb_generic_ioctl - Digital TV close function, used by DVB devices
  302. *
  303. * @file: pointer to &struct file.
  304. * @cmd: Ioctl name.
  305. * @arg: Ioctl argument.
  306. *
  307. * Checks if a DVB devnode and struct dvbdev.kernel_ioctl is still valid.
  308. * If so, calls dvb_usercopy().
  309. */
  310. long dvb_generic_ioctl(struct file *file,
  311. unsigned int cmd, unsigned long arg);
  312. /**
  313. * dvb_usercopy - copies data from/to userspace memory when an ioctl is
  314. * issued.
  315. *
  316. * @file: Pointer to struct &file.
  317. * @cmd: Ioctl name.
  318. * @arg: Ioctl argument.
  319. * @func: function that will actually handle the ioctl
  320. *
  321. * Ancillary function that uses ioctl direction and size to copy from
  322. * userspace. Then, it calls @func, and, if needed, data is copied back
  323. * to userspace.
  324. */
  325. int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
  326. int (*func)(struct file *file, unsigned int cmd, void *arg));
  327. #if IS_ENABLED(CONFIG_I2C)
  328. struct i2c_adapter;
  329. struct i2c_client;
  330. /**
  331. * dvb_module_probe - helper routine to probe an I2C module
  332. *
  333. * @module_name:
  334. * Name of the I2C module to be probed
  335. * @name:
  336. * Optional name for the I2C module. Used for debug purposes.
  337. * If %NULL, defaults to @module_name.
  338. * @adap:
  339. * pointer to &struct i2c_adapter that describes the I2C adapter where
  340. * the module will be bound.
  341. * @addr:
  342. * I2C address of the adapter, in 7-bit notation.
  343. * @platform_data:
  344. * Platform data to be passed to the I2C module probed.
  345. *
  346. * This function binds an I2C device into the DVB core. Should be used by
  347. * all drivers that use I2C bus to control the hardware. A module bound
  348. * with dvb_module_probe() should use dvb_module_release() to unbind.
  349. *
  350. * Return:
  351. * On success, return an &struct i2c_client, pointing the the bound
  352. * I2C device. %NULL otherwise.
  353. *
  354. * .. note::
  355. *
  356. * In the past, DVB modules (mainly, frontends) were bound via dvb_attach()
  357. * macro, with does an ugly hack, using I2C low level functions. Such
  358. * usage is deprecated and will be removed soon. Instead, use this routine.
  359. */
  360. struct i2c_client *dvb_module_probe(const char *module_name,
  361. const char *name,
  362. struct i2c_adapter *adap,
  363. unsigned char addr,
  364. void *platform_data);
  365. /**
  366. * dvb_module_release - releases an I2C device allocated with
  367. * dvb_module_probe().
  368. *
  369. * @client: pointer to &struct i2c_client with the I2C client to be released.
  370. * can be %NULL.
  371. *
  372. * This function should be used to free all resources reserved by
  373. * dvb_module_probe() and unbinding the I2C hardware.
  374. */
  375. void dvb_module_release(struct i2c_client *client);
  376. #endif /* CONFIG_I2C */
  377. /* Legacy generic DVB attach function. */
  378. #ifdef CONFIG_MEDIA_ATTACH
  379. /**
  380. * dvb_attach - attaches a DVB frontend into the DVB core.
  381. *
  382. * @FUNCTION: function on a frontend module to be called.
  383. * @ARGS...: @FUNCTION arguments.
  384. *
  385. * This ancillary function loads a frontend module in runtime and runs
  386. * the @FUNCTION function there, with @ARGS.
  387. * As it increments symbol usage cont, at unregister, dvb_detach()
  388. * should be called.
  389. *
  390. * .. note::
  391. *
  392. * In the past, DVB modules (mainly, frontends) were bound via dvb_attach()
  393. * macro, with does an ugly hack, using I2C low level functions. Such
  394. * usage is deprecated and will be removed soon. Instead, you should use
  395. * dvb_module_probe().
  396. */
  397. #define dvb_attach(FUNCTION, ARGS...) ({ \
  398. void *__r = NULL; \
  399. typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
  400. if (__a) { \
  401. __r = (void *) __a(ARGS); \
  402. if (__r == NULL) \
  403. symbol_put(FUNCTION); \
  404. } else { \
  405. printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
  406. } \
  407. __r; \
  408. })
  409. /**
  410. * dvb_detach - detaches a DVB frontend loaded via dvb_attach()
  411. *
  412. * @FUNC: attach function
  413. *
  414. * Decrements usage count for a function previously called via dvb_attach().
  415. */
  416. #define dvb_detach(FUNC) symbol_put_addr(FUNC)
  417. #else
  418. #define dvb_attach(FUNCTION, ARGS...) ({ \
  419. FUNCTION(ARGS); \
  420. })
  421. #define dvb_detach(FUNC) {}
  422. #endif /* CONFIG_MEDIA_ATTACH */
  423. #endif /* #ifndef _DVBDEV_H_ */