dvbdev.h 14 KB

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