v4l2-dev.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * Video capture interface for Linux version 2
  3. *
  4. * A generic video device interface for the LINUX operating system
  5. * using a set of device structures/vectors for low level operations.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
  13. * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
  14. *
  15. * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
  16. * - Added procfs support
  17. */
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/string.h>
  23. #include <linux/errno.h>
  24. #include <linux/init.h>
  25. #include <linux/kmod.h>
  26. #include <linux/slab.h>
  27. #include <asm/uaccess.h>
  28. #include <media/v4l2-common.h>
  29. #include <media/v4l2-device.h>
  30. #include <media/v4l2-ioctl.h>
  31. #define VIDEO_NUM_DEVICES 256
  32. #define VIDEO_NAME "video4linux"
  33. /*
  34. * sysfs stuff
  35. */
  36. static ssize_t index_show(struct device *cd,
  37. struct device_attribute *attr, char *buf)
  38. {
  39. struct video_device *vdev = to_video_device(cd);
  40. return sprintf(buf, "%i\n", vdev->index);
  41. }
  42. static DEVICE_ATTR_RO(index);
  43. static ssize_t dev_debug_show(struct device *cd,
  44. struct device_attribute *attr, char *buf)
  45. {
  46. struct video_device *vdev = to_video_device(cd);
  47. return sprintf(buf, "%i\n", vdev->dev_debug);
  48. }
  49. static ssize_t dev_debug_store(struct device *cd, struct device_attribute *attr,
  50. const char *buf, size_t len)
  51. {
  52. struct video_device *vdev = to_video_device(cd);
  53. int res = 0;
  54. u16 value;
  55. res = kstrtou16(buf, 0, &value);
  56. if (res)
  57. return res;
  58. vdev->dev_debug = value;
  59. return len;
  60. }
  61. static DEVICE_ATTR_RW(dev_debug);
  62. static ssize_t name_show(struct device *cd,
  63. struct device_attribute *attr, char *buf)
  64. {
  65. struct video_device *vdev = to_video_device(cd);
  66. return sprintf(buf, "%.*s\n", (int)sizeof(vdev->name), vdev->name);
  67. }
  68. static DEVICE_ATTR_RO(name);
  69. static struct attribute *video_device_attrs[] = {
  70. &dev_attr_name.attr,
  71. &dev_attr_dev_debug.attr,
  72. &dev_attr_index.attr,
  73. NULL,
  74. };
  75. ATTRIBUTE_GROUPS(video_device);
  76. /*
  77. * Active devices
  78. */
  79. static struct video_device *video_device[VIDEO_NUM_DEVICES];
  80. static DEFINE_MUTEX(videodev_lock);
  81. static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
  82. /* Device node utility functions */
  83. /* Note: these utility functions all assume that vfl_type is in the range
  84. [0, VFL_TYPE_MAX-1]. */
  85. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  86. /* Return the bitmap corresponding to vfl_type. */
  87. static inline unsigned long *devnode_bits(int vfl_type)
  88. {
  89. /* Any types not assigned to fixed minor ranges must be mapped to
  90. one single bitmap for the purposes of finding a free node number
  91. since all those unassigned types use the same minor range. */
  92. int idx = (vfl_type > VFL_TYPE_RADIO) ? VFL_TYPE_MAX - 1 : vfl_type;
  93. return devnode_nums[idx];
  94. }
  95. #else
  96. /* Return the bitmap corresponding to vfl_type. */
  97. static inline unsigned long *devnode_bits(int vfl_type)
  98. {
  99. return devnode_nums[vfl_type];
  100. }
  101. #endif
  102. /* Mark device node number vdev->num as used */
  103. static inline void devnode_set(struct video_device *vdev)
  104. {
  105. set_bit(vdev->num, devnode_bits(vdev->vfl_type));
  106. }
  107. /* Mark device node number vdev->num as unused */
  108. static inline void devnode_clear(struct video_device *vdev)
  109. {
  110. clear_bit(vdev->num, devnode_bits(vdev->vfl_type));
  111. }
  112. /* Try to find a free device node number in the range [from, to> */
  113. static inline int devnode_find(struct video_device *vdev, int from, int to)
  114. {
  115. return find_next_zero_bit(devnode_bits(vdev->vfl_type), to, from);
  116. }
  117. struct video_device *video_device_alloc(void)
  118. {
  119. return kzalloc(sizeof(struct video_device), GFP_KERNEL);
  120. }
  121. EXPORT_SYMBOL(video_device_alloc);
  122. void video_device_release(struct video_device *vdev)
  123. {
  124. kfree(vdev);
  125. }
  126. EXPORT_SYMBOL(video_device_release);
  127. void video_device_release_empty(struct video_device *vdev)
  128. {
  129. /* Do nothing */
  130. /* Only valid when the video_device struct is a static. */
  131. }
  132. EXPORT_SYMBOL(video_device_release_empty);
  133. static inline void video_get(struct video_device *vdev)
  134. {
  135. get_device(&vdev->dev);
  136. }
  137. static inline void video_put(struct video_device *vdev)
  138. {
  139. put_device(&vdev->dev);
  140. }
  141. /* Called when the last user of the video device exits. */
  142. static void v4l2_device_release(struct device *cd)
  143. {
  144. struct video_device *vdev = to_video_device(cd);
  145. struct v4l2_device *v4l2_dev = vdev->v4l2_dev;
  146. mutex_lock(&videodev_lock);
  147. if (WARN_ON(video_device[vdev->minor] != vdev)) {
  148. /* should not happen */
  149. mutex_unlock(&videodev_lock);
  150. return;
  151. }
  152. /* Free up this device for reuse */
  153. video_device[vdev->minor] = NULL;
  154. /* Delete the cdev on this minor as well */
  155. cdev_del(vdev->cdev);
  156. /* Just in case some driver tries to access this from
  157. the release() callback. */
  158. vdev->cdev = NULL;
  159. /* Mark device node number as free */
  160. devnode_clear(vdev);
  161. mutex_unlock(&videodev_lock);
  162. #if defined(CONFIG_MEDIA_CONTROLLER)
  163. if (v4l2_dev->mdev &&
  164. vdev->vfl_type != VFL_TYPE_SUBDEV)
  165. media_device_unregister_entity(&vdev->entity);
  166. #endif
  167. /* Do not call v4l2_device_put if there is no release callback set.
  168. * Drivers that have no v4l2_device release callback might free the
  169. * v4l2_dev instance in the video_device release callback below, so we
  170. * must perform this check here.
  171. *
  172. * TODO: In the long run all drivers that use v4l2_device should use the
  173. * v4l2_device release callback. This check will then be unnecessary.
  174. */
  175. if (v4l2_dev->release == NULL)
  176. v4l2_dev = NULL;
  177. /* Release video_device and perform other
  178. cleanups as needed. */
  179. vdev->release(vdev);
  180. /* Decrease v4l2_device refcount */
  181. if (v4l2_dev)
  182. v4l2_device_put(v4l2_dev);
  183. }
  184. static struct class video_class = {
  185. .name = VIDEO_NAME,
  186. .dev_groups = video_device_groups,
  187. };
  188. struct video_device *video_devdata(struct file *file)
  189. {
  190. return video_device[iminor(file_inode(file))];
  191. }
  192. EXPORT_SYMBOL(video_devdata);
  193. /* Priority handling */
  194. static inline bool prio_is_valid(enum v4l2_priority prio)
  195. {
  196. return prio == V4L2_PRIORITY_BACKGROUND ||
  197. prio == V4L2_PRIORITY_INTERACTIVE ||
  198. prio == V4L2_PRIORITY_RECORD;
  199. }
  200. void v4l2_prio_init(struct v4l2_prio_state *global)
  201. {
  202. memset(global, 0, sizeof(*global));
  203. }
  204. EXPORT_SYMBOL(v4l2_prio_init);
  205. int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
  206. enum v4l2_priority new)
  207. {
  208. if (!prio_is_valid(new))
  209. return -EINVAL;
  210. if (*local == new)
  211. return 0;
  212. atomic_inc(&global->prios[new]);
  213. if (prio_is_valid(*local))
  214. atomic_dec(&global->prios[*local]);
  215. *local = new;
  216. return 0;
  217. }
  218. EXPORT_SYMBOL(v4l2_prio_change);
  219. void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
  220. {
  221. v4l2_prio_change(global, local, V4L2_PRIORITY_DEFAULT);
  222. }
  223. EXPORT_SYMBOL(v4l2_prio_open);
  224. void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local)
  225. {
  226. if (prio_is_valid(local))
  227. atomic_dec(&global->prios[local]);
  228. }
  229. EXPORT_SYMBOL(v4l2_prio_close);
  230. enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
  231. {
  232. if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
  233. return V4L2_PRIORITY_RECORD;
  234. if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
  235. return V4L2_PRIORITY_INTERACTIVE;
  236. if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
  237. return V4L2_PRIORITY_BACKGROUND;
  238. return V4L2_PRIORITY_UNSET;
  239. }
  240. EXPORT_SYMBOL(v4l2_prio_max);
  241. int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local)
  242. {
  243. return (local < v4l2_prio_max(global)) ? -EBUSY : 0;
  244. }
  245. EXPORT_SYMBOL(v4l2_prio_check);
  246. static ssize_t v4l2_read(struct file *filp, char __user *buf,
  247. size_t sz, loff_t *off)
  248. {
  249. struct video_device *vdev = video_devdata(filp);
  250. int ret = -ENODEV;
  251. if (!vdev->fops->read)
  252. return -EINVAL;
  253. if (video_is_registered(vdev))
  254. ret = vdev->fops->read(filp, buf, sz, off);
  255. if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) &&
  256. (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING))
  257. printk(KERN_DEBUG "%s: read: %zd (%d)\n",
  258. video_device_node_name(vdev), sz, ret);
  259. return ret;
  260. }
  261. static ssize_t v4l2_write(struct file *filp, const char __user *buf,
  262. size_t sz, loff_t *off)
  263. {
  264. struct video_device *vdev = video_devdata(filp);
  265. int ret = -ENODEV;
  266. if (!vdev->fops->write)
  267. return -EINVAL;
  268. if (video_is_registered(vdev))
  269. ret = vdev->fops->write(filp, buf, sz, off);
  270. if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) &&
  271. (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING))
  272. printk(KERN_DEBUG "%s: write: %zd (%d)\n",
  273. video_device_node_name(vdev), sz, ret);
  274. return ret;
  275. }
  276. static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
  277. {
  278. struct video_device *vdev = video_devdata(filp);
  279. unsigned int res = POLLERR | POLLHUP;
  280. if (!vdev->fops->poll)
  281. return DEFAULT_POLLMASK;
  282. if (video_is_registered(vdev))
  283. res = vdev->fops->poll(filp, poll);
  284. if (vdev->dev_debug & V4L2_DEV_DEBUG_POLL)
  285. printk(KERN_DEBUG "%s: poll: %08x\n",
  286. video_device_node_name(vdev), res);
  287. return res;
  288. }
  289. static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  290. {
  291. struct video_device *vdev = video_devdata(filp);
  292. int ret = -ENODEV;
  293. if (vdev->fops->unlocked_ioctl) {
  294. struct mutex *lock = v4l2_ioctl_get_lock(vdev, cmd);
  295. if (lock && mutex_lock_interruptible(lock))
  296. return -ERESTARTSYS;
  297. if (video_is_registered(vdev))
  298. ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
  299. if (lock)
  300. mutex_unlock(lock);
  301. } else
  302. ret = -ENOTTY;
  303. return ret;
  304. }
  305. #ifdef CONFIG_MMU
  306. #define v4l2_get_unmapped_area NULL
  307. #else
  308. static unsigned long v4l2_get_unmapped_area(struct file *filp,
  309. unsigned long addr, unsigned long len, unsigned long pgoff,
  310. unsigned long flags)
  311. {
  312. struct video_device *vdev = video_devdata(filp);
  313. int ret;
  314. if (!vdev->fops->get_unmapped_area)
  315. return -ENOSYS;
  316. if (!video_is_registered(vdev))
  317. return -ENODEV;
  318. ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
  319. if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
  320. printk(KERN_DEBUG "%s: get_unmapped_area (%d)\n",
  321. video_device_node_name(vdev), ret);
  322. return ret;
  323. }
  324. #endif
  325. static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
  326. {
  327. struct video_device *vdev = video_devdata(filp);
  328. int ret = -ENODEV;
  329. if (!vdev->fops->mmap)
  330. return -ENODEV;
  331. if (video_is_registered(vdev))
  332. ret = vdev->fops->mmap(filp, vm);
  333. if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
  334. printk(KERN_DEBUG "%s: mmap (%d)\n",
  335. video_device_node_name(vdev), ret);
  336. return ret;
  337. }
  338. /* Override for the open function */
  339. static int v4l2_open(struct inode *inode, struct file *filp)
  340. {
  341. struct video_device *vdev;
  342. int ret = 0;
  343. /* Check if the video device is available */
  344. mutex_lock(&videodev_lock);
  345. vdev = video_devdata(filp);
  346. /* return ENODEV if the video device has already been removed. */
  347. if (vdev == NULL || !video_is_registered(vdev)) {
  348. mutex_unlock(&videodev_lock);
  349. return -ENODEV;
  350. }
  351. /* and increase the device refcount */
  352. video_get(vdev);
  353. mutex_unlock(&videodev_lock);
  354. if (vdev->fops->open) {
  355. if (video_is_registered(vdev))
  356. ret = vdev->fops->open(filp);
  357. else
  358. ret = -ENODEV;
  359. }
  360. if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
  361. printk(KERN_DEBUG "%s: open (%d)\n",
  362. video_device_node_name(vdev), ret);
  363. /* decrease the refcount in case of an error */
  364. if (ret)
  365. video_put(vdev);
  366. return ret;
  367. }
  368. /* Override for the release function */
  369. static int v4l2_release(struct inode *inode, struct file *filp)
  370. {
  371. struct video_device *vdev = video_devdata(filp);
  372. int ret = 0;
  373. if (vdev->fops->release)
  374. ret = vdev->fops->release(filp);
  375. if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
  376. printk(KERN_DEBUG "%s: release\n",
  377. video_device_node_name(vdev));
  378. /* decrease the refcount unconditionally since the release()
  379. return value is ignored. */
  380. video_put(vdev);
  381. return ret;
  382. }
  383. static const struct file_operations v4l2_fops = {
  384. .owner = THIS_MODULE,
  385. .read = v4l2_read,
  386. .write = v4l2_write,
  387. .open = v4l2_open,
  388. .get_unmapped_area = v4l2_get_unmapped_area,
  389. .mmap = v4l2_mmap,
  390. .unlocked_ioctl = v4l2_ioctl,
  391. #ifdef CONFIG_COMPAT
  392. .compat_ioctl = v4l2_compat_ioctl32,
  393. #endif
  394. .release = v4l2_release,
  395. .poll = v4l2_poll,
  396. .llseek = no_llseek,
  397. };
  398. /**
  399. * get_index - assign stream index number based on v4l2_dev
  400. * @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
  401. *
  402. * Note that when this is called the new device has not yet been registered
  403. * in the video_device array, but it was able to obtain a minor number.
  404. *
  405. * This means that we can always obtain a free stream index number since
  406. * the worst case scenario is that there are VIDEO_NUM_DEVICES - 1 slots in
  407. * use of the video_device array.
  408. *
  409. * Returns a free index number.
  410. */
  411. static int get_index(struct video_device *vdev)
  412. {
  413. /* This can be static since this function is called with the global
  414. videodev_lock held. */
  415. static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
  416. int i;
  417. bitmap_zero(used, VIDEO_NUM_DEVICES);
  418. for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
  419. if (video_device[i] != NULL &&
  420. video_device[i]->v4l2_dev == vdev->v4l2_dev) {
  421. set_bit(video_device[i]->index, used);
  422. }
  423. }
  424. return find_first_zero_bit(used, VIDEO_NUM_DEVICES);
  425. }
  426. #define SET_VALID_IOCTL(ops, cmd, op) \
  427. if (ops->op) \
  428. set_bit(_IOC_NR(cmd), valid_ioctls)
  429. /* This determines which ioctls are actually implemented in the driver.
  430. It's a one-time thing which simplifies video_ioctl2 as it can just do
  431. a bit test.
  432. Note that drivers can override this by setting bits to 1 in
  433. vdev->valid_ioctls. If an ioctl is marked as 1 when this function is
  434. called, then that ioctl will actually be marked as unimplemented.
  435. It does that by first setting up the local valid_ioctls bitmap, and
  436. at the end do a:
  437. vdev->valid_ioctls = valid_ioctls & ~(vdev->valid_ioctls)
  438. */
  439. static void determine_valid_ioctls(struct video_device *vdev)
  440. {
  441. DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
  442. const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops;
  443. bool is_vid = vdev->vfl_type == VFL_TYPE_GRABBER;
  444. bool is_vbi = vdev->vfl_type == VFL_TYPE_VBI;
  445. bool is_radio = vdev->vfl_type == VFL_TYPE_RADIO;
  446. bool is_sdr = vdev->vfl_type == VFL_TYPE_SDR;
  447. bool is_rx = vdev->vfl_dir != VFL_DIR_TX;
  448. bool is_tx = vdev->vfl_dir != VFL_DIR_RX;
  449. bitmap_zero(valid_ioctls, BASE_VIDIOC_PRIVATE);
  450. /* vfl_type and vfl_dir independent ioctls */
  451. SET_VALID_IOCTL(ops, VIDIOC_QUERYCAP, vidioc_querycap);
  452. set_bit(_IOC_NR(VIDIOC_G_PRIORITY), valid_ioctls);
  453. set_bit(_IOC_NR(VIDIOC_S_PRIORITY), valid_ioctls);
  454. /* Note: the control handler can also be passed through the filehandle,
  455. and that can't be tested here. If the bit for these control ioctls
  456. is set, then the ioctl is valid. But if it is 0, then it can still
  457. be valid if the filehandle passed the control handler. */
  458. if (vdev->ctrl_handler || ops->vidioc_queryctrl)
  459. set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
  460. if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
  461. set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
  462. if (vdev->ctrl_handler || ops->vidioc_g_ctrl || ops->vidioc_g_ext_ctrls)
  463. set_bit(_IOC_NR(VIDIOC_G_CTRL), valid_ioctls);
  464. if (vdev->ctrl_handler || ops->vidioc_s_ctrl || ops->vidioc_s_ext_ctrls)
  465. set_bit(_IOC_NR(VIDIOC_S_CTRL), valid_ioctls);
  466. if (vdev->ctrl_handler || ops->vidioc_g_ext_ctrls)
  467. set_bit(_IOC_NR(VIDIOC_G_EXT_CTRLS), valid_ioctls);
  468. if (vdev->ctrl_handler || ops->vidioc_s_ext_ctrls)
  469. set_bit(_IOC_NR(VIDIOC_S_EXT_CTRLS), valid_ioctls);
  470. if (vdev->ctrl_handler || ops->vidioc_try_ext_ctrls)
  471. set_bit(_IOC_NR(VIDIOC_TRY_EXT_CTRLS), valid_ioctls);
  472. if (vdev->ctrl_handler || ops->vidioc_querymenu)
  473. set_bit(_IOC_NR(VIDIOC_QUERYMENU), valid_ioctls);
  474. SET_VALID_IOCTL(ops, VIDIOC_G_FREQUENCY, vidioc_g_frequency);
  475. SET_VALID_IOCTL(ops, VIDIOC_S_FREQUENCY, vidioc_s_frequency);
  476. SET_VALID_IOCTL(ops, VIDIOC_LOG_STATUS, vidioc_log_status);
  477. #ifdef CONFIG_VIDEO_ADV_DEBUG
  478. set_bit(_IOC_NR(VIDIOC_DBG_G_CHIP_INFO), valid_ioctls);
  479. set_bit(_IOC_NR(VIDIOC_DBG_G_REGISTER), valid_ioctls);
  480. set_bit(_IOC_NR(VIDIOC_DBG_S_REGISTER), valid_ioctls);
  481. #endif
  482. /* yes, really vidioc_subscribe_event */
  483. SET_VALID_IOCTL(ops, VIDIOC_DQEVENT, vidioc_subscribe_event);
  484. SET_VALID_IOCTL(ops, VIDIOC_SUBSCRIBE_EVENT, vidioc_subscribe_event);
  485. SET_VALID_IOCTL(ops, VIDIOC_UNSUBSCRIBE_EVENT, vidioc_unsubscribe_event);
  486. if (ops->vidioc_enum_freq_bands || ops->vidioc_g_tuner || ops->vidioc_g_modulator)
  487. set_bit(_IOC_NR(VIDIOC_ENUM_FREQ_BANDS), valid_ioctls);
  488. if (is_vid) {
  489. /* video specific ioctls */
  490. if ((is_rx && (ops->vidioc_enum_fmt_vid_cap ||
  491. ops->vidioc_enum_fmt_vid_cap_mplane ||
  492. ops->vidioc_enum_fmt_vid_overlay)) ||
  493. (is_tx && (ops->vidioc_enum_fmt_vid_out ||
  494. ops->vidioc_enum_fmt_vid_out_mplane)))
  495. set_bit(_IOC_NR(VIDIOC_ENUM_FMT), valid_ioctls);
  496. if ((is_rx && (ops->vidioc_g_fmt_vid_cap ||
  497. ops->vidioc_g_fmt_vid_cap_mplane ||
  498. ops->vidioc_g_fmt_vid_overlay)) ||
  499. (is_tx && (ops->vidioc_g_fmt_vid_out ||
  500. ops->vidioc_g_fmt_vid_out_mplane ||
  501. ops->vidioc_g_fmt_vid_out_overlay)))
  502. set_bit(_IOC_NR(VIDIOC_G_FMT), valid_ioctls);
  503. if ((is_rx && (ops->vidioc_s_fmt_vid_cap ||
  504. ops->vidioc_s_fmt_vid_cap_mplane ||
  505. ops->vidioc_s_fmt_vid_overlay)) ||
  506. (is_tx && (ops->vidioc_s_fmt_vid_out ||
  507. ops->vidioc_s_fmt_vid_out_mplane ||
  508. ops->vidioc_s_fmt_vid_out_overlay)))
  509. set_bit(_IOC_NR(VIDIOC_S_FMT), valid_ioctls);
  510. if ((is_rx && (ops->vidioc_try_fmt_vid_cap ||
  511. ops->vidioc_try_fmt_vid_cap_mplane ||
  512. ops->vidioc_try_fmt_vid_overlay)) ||
  513. (is_tx && (ops->vidioc_try_fmt_vid_out ||
  514. ops->vidioc_try_fmt_vid_out_mplane ||
  515. ops->vidioc_try_fmt_vid_out_overlay)))
  516. set_bit(_IOC_NR(VIDIOC_TRY_FMT), valid_ioctls);
  517. SET_VALID_IOCTL(ops, VIDIOC_OVERLAY, vidioc_overlay);
  518. SET_VALID_IOCTL(ops, VIDIOC_G_FBUF, vidioc_g_fbuf);
  519. SET_VALID_IOCTL(ops, VIDIOC_S_FBUF, vidioc_s_fbuf);
  520. SET_VALID_IOCTL(ops, VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp);
  521. SET_VALID_IOCTL(ops, VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp);
  522. SET_VALID_IOCTL(ops, VIDIOC_G_ENC_INDEX, vidioc_g_enc_index);
  523. SET_VALID_IOCTL(ops, VIDIOC_ENCODER_CMD, vidioc_encoder_cmd);
  524. SET_VALID_IOCTL(ops, VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd);
  525. SET_VALID_IOCTL(ops, VIDIOC_DECODER_CMD, vidioc_decoder_cmd);
  526. SET_VALID_IOCTL(ops, VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd);
  527. SET_VALID_IOCTL(ops, VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes);
  528. SET_VALID_IOCTL(ops, VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals);
  529. if (ops->vidioc_g_crop || ops->vidioc_g_selection)
  530. set_bit(_IOC_NR(VIDIOC_G_CROP), valid_ioctls);
  531. if (ops->vidioc_s_crop || ops->vidioc_s_selection)
  532. set_bit(_IOC_NR(VIDIOC_S_CROP), valid_ioctls);
  533. SET_VALID_IOCTL(ops, VIDIOC_G_SELECTION, vidioc_g_selection);
  534. SET_VALID_IOCTL(ops, VIDIOC_S_SELECTION, vidioc_s_selection);
  535. if (ops->vidioc_cropcap || ops->vidioc_g_selection)
  536. set_bit(_IOC_NR(VIDIOC_CROPCAP), valid_ioctls);
  537. } else if (is_vbi) {
  538. /* vbi specific ioctls */
  539. if ((is_rx && (ops->vidioc_g_fmt_vbi_cap ||
  540. ops->vidioc_g_fmt_sliced_vbi_cap)) ||
  541. (is_tx && (ops->vidioc_g_fmt_vbi_out ||
  542. ops->vidioc_g_fmt_sliced_vbi_out)))
  543. set_bit(_IOC_NR(VIDIOC_G_FMT), valid_ioctls);
  544. if ((is_rx && (ops->vidioc_s_fmt_vbi_cap ||
  545. ops->vidioc_s_fmt_sliced_vbi_cap)) ||
  546. (is_tx && (ops->vidioc_s_fmt_vbi_out ||
  547. ops->vidioc_s_fmt_sliced_vbi_out)))
  548. set_bit(_IOC_NR(VIDIOC_S_FMT), valid_ioctls);
  549. if ((is_rx && (ops->vidioc_try_fmt_vbi_cap ||
  550. ops->vidioc_try_fmt_sliced_vbi_cap)) ||
  551. (is_tx && (ops->vidioc_try_fmt_vbi_out ||
  552. ops->vidioc_try_fmt_sliced_vbi_out)))
  553. set_bit(_IOC_NR(VIDIOC_TRY_FMT), valid_ioctls);
  554. SET_VALID_IOCTL(ops, VIDIOC_G_SLICED_VBI_CAP, vidioc_g_sliced_vbi_cap);
  555. } else if (is_sdr && is_rx) {
  556. /* SDR receiver specific ioctls */
  557. if (ops->vidioc_enum_fmt_sdr_cap)
  558. set_bit(_IOC_NR(VIDIOC_ENUM_FMT), valid_ioctls);
  559. if (ops->vidioc_g_fmt_sdr_cap)
  560. set_bit(_IOC_NR(VIDIOC_G_FMT), valid_ioctls);
  561. if (ops->vidioc_s_fmt_sdr_cap)
  562. set_bit(_IOC_NR(VIDIOC_S_FMT), valid_ioctls);
  563. if (ops->vidioc_try_fmt_sdr_cap)
  564. set_bit(_IOC_NR(VIDIOC_TRY_FMT), valid_ioctls);
  565. } else if (is_sdr && is_tx) {
  566. /* SDR transmitter specific ioctls */
  567. if (ops->vidioc_enum_fmt_sdr_out)
  568. set_bit(_IOC_NR(VIDIOC_ENUM_FMT), valid_ioctls);
  569. if (ops->vidioc_g_fmt_sdr_out)
  570. set_bit(_IOC_NR(VIDIOC_G_FMT), valid_ioctls);
  571. if (ops->vidioc_s_fmt_sdr_out)
  572. set_bit(_IOC_NR(VIDIOC_S_FMT), valid_ioctls);
  573. if (ops->vidioc_try_fmt_sdr_out)
  574. set_bit(_IOC_NR(VIDIOC_TRY_FMT), valid_ioctls);
  575. }
  576. if (is_vid || is_vbi || is_sdr) {
  577. /* ioctls valid for video, vbi or sdr */
  578. SET_VALID_IOCTL(ops, VIDIOC_REQBUFS, vidioc_reqbufs);
  579. SET_VALID_IOCTL(ops, VIDIOC_QUERYBUF, vidioc_querybuf);
  580. SET_VALID_IOCTL(ops, VIDIOC_QBUF, vidioc_qbuf);
  581. SET_VALID_IOCTL(ops, VIDIOC_EXPBUF, vidioc_expbuf);
  582. SET_VALID_IOCTL(ops, VIDIOC_DQBUF, vidioc_dqbuf);
  583. SET_VALID_IOCTL(ops, VIDIOC_CREATE_BUFS, vidioc_create_bufs);
  584. SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf);
  585. SET_VALID_IOCTL(ops, VIDIOC_STREAMON, vidioc_streamon);
  586. SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff);
  587. }
  588. if (is_vid || is_vbi) {
  589. /* ioctls valid for video or vbi */
  590. if (ops->vidioc_s_std)
  591. set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls);
  592. SET_VALID_IOCTL(ops, VIDIOC_S_STD, vidioc_s_std);
  593. SET_VALID_IOCTL(ops, VIDIOC_G_STD, vidioc_g_std);
  594. if (is_rx) {
  595. SET_VALID_IOCTL(ops, VIDIOC_QUERYSTD, vidioc_querystd);
  596. SET_VALID_IOCTL(ops, VIDIOC_ENUMINPUT, vidioc_enum_input);
  597. SET_VALID_IOCTL(ops, VIDIOC_G_INPUT, vidioc_g_input);
  598. SET_VALID_IOCTL(ops, VIDIOC_S_INPUT, vidioc_s_input);
  599. SET_VALID_IOCTL(ops, VIDIOC_ENUMAUDIO, vidioc_enumaudio);
  600. SET_VALID_IOCTL(ops, VIDIOC_G_AUDIO, vidioc_g_audio);
  601. SET_VALID_IOCTL(ops, VIDIOC_S_AUDIO, vidioc_s_audio);
  602. SET_VALID_IOCTL(ops, VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings);
  603. SET_VALID_IOCTL(ops, VIDIOC_S_EDID, vidioc_s_edid);
  604. }
  605. if (is_tx) {
  606. SET_VALID_IOCTL(ops, VIDIOC_ENUMOUTPUT, vidioc_enum_output);
  607. SET_VALID_IOCTL(ops, VIDIOC_G_OUTPUT, vidioc_g_output);
  608. SET_VALID_IOCTL(ops, VIDIOC_S_OUTPUT, vidioc_s_output);
  609. SET_VALID_IOCTL(ops, VIDIOC_ENUMAUDOUT, vidioc_enumaudout);
  610. SET_VALID_IOCTL(ops, VIDIOC_G_AUDOUT, vidioc_g_audout);
  611. SET_VALID_IOCTL(ops, VIDIOC_S_AUDOUT, vidioc_s_audout);
  612. }
  613. if (ops->vidioc_g_parm || (vdev->vfl_type == VFL_TYPE_GRABBER &&
  614. ops->vidioc_g_std))
  615. set_bit(_IOC_NR(VIDIOC_G_PARM), valid_ioctls);
  616. SET_VALID_IOCTL(ops, VIDIOC_S_PARM, vidioc_s_parm);
  617. SET_VALID_IOCTL(ops, VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings);
  618. SET_VALID_IOCTL(ops, VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings);
  619. SET_VALID_IOCTL(ops, VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings);
  620. SET_VALID_IOCTL(ops, VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap);
  621. SET_VALID_IOCTL(ops, VIDIOC_G_EDID, vidioc_g_edid);
  622. }
  623. if (is_tx && (is_radio || is_sdr)) {
  624. /* radio transmitter only ioctls */
  625. SET_VALID_IOCTL(ops, VIDIOC_G_MODULATOR, vidioc_g_modulator);
  626. SET_VALID_IOCTL(ops, VIDIOC_S_MODULATOR, vidioc_s_modulator);
  627. }
  628. if (is_rx) {
  629. /* receiver only ioctls */
  630. SET_VALID_IOCTL(ops, VIDIOC_G_TUNER, vidioc_g_tuner);
  631. SET_VALID_IOCTL(ops, VIDIOC_S_TUNER, vidioc_s_tuner);
  632. SET_VALID_IOCTL(ops, VIDIOC_S_HW_FREQ_SEEK, vidioc_s_hw_freq_seek);
  633. }
  634. bitmap_andnot(vdev->valid_ioctls, valid_ioctls, vdev->valid_ioctls,
  635. BASE_VIDIOC_PRIVATE);
  636. }
  637. /**
  638. * __video_register_device - register video4linux devices
  639. * @vdev: video device structure we want to register
  640. * @type: type of device to register
  641. * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...
  642. * -1 == first free)
  643. * @warn_if_nr_in_use: warn if the desired device node number
  644. * was already in use and another number was chosen instead.
  645. * @owner: module that owns the video device node
  646. *
  647. * The registration code assigns minor numbers and device node numbers
  648. * based on the requested type and registers the new device node with
  649. * the kernel.
  650. *
  651. * This function assumes that struct video_device was zeroed when it
  652. * was allocated and does not contain any stale date.
  653. *
  654. * An error is returned if no free minor or device node number could be
  655. * found, or if the registration of the device node failed.
  656. *
  657. * Zero is returned on success.
  658. *
  659. * Valid types are
  660. *
  661. * %VFL_TYPE_GRABBER - A frame grabber
  662. *
  663. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  664. *
  665. * %VFL_TYPE_RADIO - A radio card
  666. *
  667. * %VFL_TYPE_SUBDEV - A subdevice
  668. *
  669. * %VFL_TYPE_SDR - Software Defined Radio
  670. */
  671. int __video_register_device(struct video_device *vdev, int type, int nr,
  672. int warn_if_nr_in_use, struct module *owner)
  673. {
  674. int i = 0;
  675. int ret;
  676. int minor_offset = 0;
  677. int minor_cnt = VIDEO_NUM_DEVICES;
  678. const char *name_base;
  679. /* A minor value of -1 marks this video device as never
  680. having been registered */
  681. vdev->minor = -1;
  682. /* the release callback MUST be present */
  683. if (WARN_ON(!vdev->release))
  684. return -EINVAL;
  685. /* the v4l2_dev pointer MUST be present */
  686. if (WARN_ON(!vdev->v4l2_dev))
  687. return -EINVAL;
  688. /* v4l2_fh support */
  689. spin_lock_init(&vdev->fh_lock);
  690. INIT_LIST_HEAD(&vdev->fh_list);
  691. /* Part 1: check device type */
  692. switch (type) {
  693. case VFL_TYPE_GRABBER:
  694. name_base = "video";
  695. break;
  696. case VFL_TYPE_VBI:
  697. name_base = "vbi";
  698. break;
  699. case VFL_TYPE_RADIO:
  700. name_base = "radio";
  701. break;
  702. case VFL_TYPE_SUBDEV:
  703. name_base = "v4l-subdev";
  704. break;
  705. case VFL_TYPE_SDR:
  706. /* Use device name 'swradio' because 'sdr' was already taken. */
  707. name_base = "swradio";
  708. break;
  709. default:
  710. printk(KERN_ERR "%s called with unknown type: %d\n",
  711. __func__, type);
  712. return -EINVAL;
  713. }
  714. vdev->vfl_type = type;
  715. vdev->cdev = NULL;
  716. if (vdev->dev_parent == NULL)
  717. vdev->dev_parent = vdev->v4l2_dev->dev;
  718. if (vdev->ctrl_handler == NULL)
  719. vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
  720. /* If the prio state pointer is NULL, then use the v4l2_device
  721. prio state. */
  722. if (vdev->prio == NULL)
  723. vdev->prio = &vdev->v4l2_dev->prio;
  724. /* Part 2: find a free minor, device node number and device index. */
  725. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  726. /* Keep the ranges for the first four types for historical
  727. * reasons.
  728. * Newer devices (not yet in place) should use the range
  729. * of 128-191 and just pick the first free minor there
  730. * (new style). */
  731. switch (type) {
  732. case VFL_TYPE_GRABBER:
  733. minor_offset = 0;
  734. minor_cnt = 64;
  735. break;
  736. case VFL_TYPE_RADIO:
  737. minor_offset = 64;
  738. minor_cnt = 64;
  739. break;
  740. case VFL_TYPE_VBI:
  741. minor_offset = 224;
  742. minor_cnt = 32;
  743. break;
  744. default:
  745. minor_offset = 128;
  746. minor_cnt = 64;
  747. break;
  748. }
  749. #endif
  750. /* Pick a device node number */
  751. mutex_lock(&videodev_lock);
  752. nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
  753. if (nr == minor_cnt)
  754. nr = devnode_find(vdev, 0, minor_cnt);
  755. if (nr == minor_cnt) {
  756. printk(KERN_ERR "could not get a free device node number\n");
  757. mutex_unlock(&videodev_lock);
  758. return -ENFILE;
  759. }
  760. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  761. /* 1-on-1 mapping of device node number to minor number */
  762. i = nr;
  763. #else
  764. /* The device node number and minor numbers are independent, so
  765. we just find the first free minor number. */
  766. for (i = 0; i < VIDEO_NUM_DEVICES; i++)
  767. if (video_device[i] == NULL)
  768. break;
  769. if (i == VIDEO_NUM_DEVICES) {
  770. mutex_unlock(&videodev_lock);
  771. printk(KERN_ERR "could not get a free minor\n");
  772. return -ENFILE;
  773. }
  774. #endif
  775. vdev->minor = i + minor_offset;
  776. vdev->num = nr;
  777. devnode_set(vdev);
  778. /* Should not happen since we thought this minor was free */
  779. WARN_ON(video_device[vdev->minor] != NULL);
  780. vdev->index = get_index(vdev);
  781. video_device[vdev->minor] = vdev;
  782. mutex_unlock(&videodev_lock);
  783. if (vdev->ioctl_ops)
  784. determine_valid_ioctls(vdev);
  785. /* Part 3: Initialize the character device */
  786. vdev->cdev = cdev_alloc();
  787. if (vdev->cdev == NULL) {
  788. ret = -ENOMEM;
  789. goto cleanup;
  790. }
  791. vdev->cdev->ops = &v4l2_fops;
  792. vdev->cdev->owner = owner;
  793. ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1);
  794. if (ret < 0) {
  795. printk(KERN_ERR "%s: cdev_add failed\n", __func__);
  796. kfree(vdev->cdev);
  797. vdev->cdev = NULL;
  798. goto cleanup;
  799. }
  800. /* Part 4: register the device with sysfs */
  801. vdev->dev.class = &video_class;
  802. vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
  803. vdev->dev.parent = vdev->dev_parent;
  804. dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
  805. ret = device_register(&vdev->dev);
  806. if (ret < 0) {
  807. printk(KERN_ERR "%s: device_register failed\n", __func__);
  808. goto cleanup;
  809. }
  810. /* Register the release callback that will be called when the last
  811. reference to the device goes away. */
  812. vdev->dev.release = v4l2_device_release;
  813. if (nr != -1 && nr != vdev->num && warn_if_nr_in_use)
  814. printk(KERN_WARNING "%s: requested %s%d, got %s\n", __func__,
  815. name_base, nr, video_device_node_name(vdev));
  816. /* Increase v4l2_device refcount */
  817. v4l2_device_get(vdev->v4l2_dev);
  818. #if defined(CONFIG_MEDIA_CONTROLLER)
  819. /* Part 5: Register the entity. */
  820. if (vdev->v4l2_dev->mdev &&
  821. vdev->vfl_type != VFL_TYPE_SUBDEV) {
  822. vdev->entity.type = MEDIA_ENT_T_DEVNODE_V4L;
  823. vdev->entity.name = vdev->name;
  824. vdev->entity.info.dev.major = VIDEO_MAJOR;
  825. vdev->entity.info.dev.minor = vdev->minor;
  826. ret = media_device_register_entity(vdev->v4l2_dev->mdev,
  827. &vdev->entity);
  828. if (ret < 0)
  829. printk(KERN_WARNING
  830. "%s: media_device_register_entity failed\n",
  831. __func__);
  832. }
  833. #endif
  834. /* Part 6: Activate this minor. The char device can now be used. */
  835. set_bit(V4L2_FL_REGISTERED, &vdev->flags);
  836. return 0;
  837. cleanup:
  838. mutex_lock(&videodev_lock);
  839. if (vdev->cdev)
  840. cdev_del(vdev->cdev);
  841. video_device[vdev->minor] = NULL;
  842. devnode_clear(vdev);
  843. mutex_unlock(&videodev_lock);
  844. /* Mark this video device as never having been registered. */
  845. vdev->minor = -1;
  846. return ret;
  847. }
  848. EXPORT_SYMBOL(__video_register_device);
  849. /**
  850. * video_unregister_device - unregister a video4linux device
  851. * @vdev: the device to unregister
  852. *
  853. * This unregisters the passed device. Future open calls will
  854. * be met with errors.
  855. */
  856. void video_unregister_device(struct video_device *vdev)
  857. {
  858. /* Check if vdev was ever registered at all */
  859. if (!vdev || !video_is_registered(vdev))
  860. return;
  861. mutex_lock(&videodev_lock);
  862. /* This must be in a critical section to prevent a race with v4l2_open.
  863. * Once this bit has been cleared video_get may never be called again.
  864. */
  865. clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
  866. mutex_unlock(&videodev_lock);
  867. device_unregister(&vdev->dev);
  868. }
  869. EXPORT_SYMBOL(video_unregister_device);
  870. /*
  871. * Initialise video for linux
  872. */
  873. static int __init videodev_init(void)
  874. {
  875. dev_t dev = MKDEV(VIDEO_MAJOR, 0);
  876. int ret;
  877. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  878. ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME);
  879. if (ret < 0) {
  880. printk(KERN_WARNING "videodev: unable to get major %d\n",
  881. VIDEO_MAJOR);
  882. return ret;
  883. }
  884. ret = class_register(&video_class);
  885. if (ret < 0) {
  886. unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
  887. printk(KERN_WARNING "video_dev: class_register failed\n");
  888. return -EIO;
  889. }
  890. return 0;
  891. }
  892. static void __exit videodev_exit(void)
  893. {
  894. dev_t dev = MKDEV(VIDEO_MAJOR, 0);
  895. class_unregister(&video_class);
  896. unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
  897. }
  898. subsys_initcall(videodev_init);
  899. module_exit(videodev_exit)
  900. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  901. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  902. MODULE_LICENSE("GPL");
  903. MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR);