dvbdev.h 15 KB

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