uvc_v4l2.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. /*
  2. * uvc_v4l2.c -- USB Video Class driver - V4L2 API
  3. *
  4. * Copyright (C) 2005-2010
  5. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <linux/compat.h>
  14. #include <linux/kernel.h>
  15. #include <linux/version.h>
  16. #include <linux/list.h>
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  19. #include <linux/usb.h>
  20. #include <linux/videodev2.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/mm.h>
  23. #include <linux/wait.h>
  24. #include <linux/atomic.h>
  25. #include <media/v4l2-common.h>
  26. #include <media/v4l2-ctrls.h>
  27. #include <media/v4l2-event.h>
  28. #include <media/v4l2-ioctl.h>
  29. #include "uvcvideo.h"
  30. /* ------------------------------------------------------------------------
  31. * UVC ioctls
  32. */
  33. static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
  34. struct uvc_xu_control_mapping *xmap)
  35. {
  36. struct uvc_control_mapping *map;
  37. unsigned int size;
  38. int ret;
  39. map = kzalloc(sizeof *map, GFP_KERNEL);
  40. if (map == NULL)
  41. return -ENOMEM;
  42. map->id = xmap->id;
  43. memcpy(map->name, xmap->name, sizeof map->name);
  44. memcpy(map->entity, xmap->entity, sizeof map->entity);
  45. map->selector = xmap->selector;
  46. map->size = xmap->size;
  47. map->offset = xmap->offset;
  48. map->v4l2_type = xmap->v4l2_type;
  49. map->data_type = xmap->data_type;
  50. switch (xmap->v4l2_type) {
  51. case V4L2_CTRL_TYPE_INTEGER:
  52. case V4L2_CTRL_TYPE_BOOLEAN:
  53. case V4L2_CTRL_TYPE_BUTTON:
  54. break;
  55. case V4L2_CTRL_TYPE_MENU:
  56. /* Prevent excessive memory consumption, as well as integer
  57. * overflows.
  58. */
  59. if (xmap->menu_count == 0 ||
  60. xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) {
  61. ret = -EINVAL;
  62. goto done;
  63. }
  64. size = xmap->menu_count * sizeof(*map->menu_info);
  65. map->menu_info = kmalloc(size, GFP_KERNEL);
  66. if (map->menu_info == NULL) {
  67. ret = -ENOMEM;
  68. goto done;
  69. }
  70. if (copy_from_user(map->menu_info, xmap->menu_info, size)) {
  71. ret = -EFAULT;
  72. goto done;
  73. }
  74. map->menu_count = xmap->menu_count;
  75. break;
  76. default:
  77. uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type "
  78. "%u.\n", xmap->v4l2_type);
  79. ret = -ENOTTY;
  80. goto done;
  81. }
  82. ret = uvc_ctrl_add_mapping(chain, map);
  83. done:
  84. kfree(map->menu_info);
  85. kfree(map);
  86. return ret;
  87. }
  88. /* ------------------------------------------------------------------------
  89. * V4L2 interface
  90. */
  91. /*
  92. * Find the frame interval closest to the requested frame interval for the
  93. * given frame format and size. This should be done by the device as part of
  94. * the Video Probe and Commit negotiation, but some hardware don't implement
  95. * that feature.
  96. */
  97. static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval)
  98. {
  99. unsigned int i;
  100. if (frame->bFrameIntervalType) {
  101. __u32 best = -1, dist;
  102. for (i = 0; i < frame->bFrameIntervalType; ++i) {
  103. dist = interval > frame->dwFrameInterval[i]
  104. ? interval - frame->dwFrameInterval[i]
  105. : frame->dwFrameInterval[i] - interval;
  106. if (dist > best)
  107. break;
  108. best = dist;
  109. }
  110. interval = frame->dwFrameInterval[i-1];
  111. } else {
  112. const __u32 min = frame->dwFrameInterval[0];
  113. const __u32 max = frame->dwFrameInterval[1];
  114. const __u32 step = frame->dwFrameInterval[2];
  115. interval = min + (interval - min + step/2) / step * step;
  116. if (interval > max)
  117. interval = max;
  118. }
  119. return interval;
  120. }
  121. static int uvc_v4l2_try_format(struct uvc_streaming *stream,
  122. struct v4l2_format *fmt, struct uvc_streaming_control *probe,
  123. struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
  124. {
  125. struct uvc_format *format = NULL;
  126. struct uvc_frame *frame = NULL;
  127. __u16 rw, rh;
  128. unsigned int d, maxd;
  129. unsigned int i;
  130. __u32 interval;
  131. int ret = 0;
  132. __u8 *fcc;
  133. if (fmt->type != stream->type)
  134. return -EINVAL;
  135. fcc = (__u8 *)&fmt->fmt.pix.pixelformat;
  136. uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n",
  137. fmt->fmt.pix.pixelformat,
  138. fcc[0], fcc[1], fcc[2], fcc[3],
  139. fmt->fmt.pix.width, fmt->fmt.pix.height);
  140. /* Check if the hardware supports the requested format, use the default
  141. * format otherwise.
  142. */
  143. for (i = 0; i < stream->nformats; ++i) {
  144. format = &stream->format[i];
  145. if (format->fcc == fmt->fmt.pix.pixelformat)
  146. break;
  147. }
  148. if (i == stream->nformats) {
  149. format = stream->def_format;
  150. fmt->fmt.pix.pixelformat = format->fcc;
  151. }
  152. /* Find the closest image size. The distance between image sizes is
  153. * the size in pixels of the non-overlapping regions between the
  154. * requested size and the frame-specified size.
  155. */
  156. rw = fmt->fmt.pix.width;
  157. rh = fmt->fmt.pix.height;
  158. maxd = (unsigned int)-1;
  159. for (i = 0; i < format->nframes; ++i) {
  160. __u16 w = format->frame[i].wWidth;
  161. __u16 h = format->frame[i].wHeight;
  162. d = min(w, rw) * min(h, rh);
  163. d = w*h + rw*rh - 2*d;
  164. if (d < maxd) {
  165. maxd = d;
  166. frame = &format->frame[i];
  167. }
  168. if (maxd == 0)
  169. break;
  170. }
  171. if (frame == NULL) {
  172. uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n",
  173. fmt->fmt.pix.width, fmt->fmt.pix.height);
  174. return -EINVAL;
  175. }
  176. /* Use the default frame interval. */
  177. interval = frame->dwDefaultFrameInterval;
  178. uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us "
  179. "(%u.%u fps).\n", interval/10, interval%10, 10000000/interval,
  180. (100000000/interval)%10);
  181. /* Set the format index, frame index and frame interval. */
  182. memset(probe, 0, sizeof *probe);
  183. probe->bmHint = 1; /* dwFrameInterval */
  184. probe->bFormatIndex = format->index;
  185. probe->bFrameIndex = frame->bFrameIndex;
  186. probe->dwFrameInterval = uvc_try_frame_interval(frame, interval);
  187. /* Some webcams stall the probe control set request when the
  188. * dwMaxVideoFrameSize field is set to zero. The UVC specification
  189. * clearly states that the field is read-only from the host, so this
  190. * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by
  191. * the webcam to work around the problem.
  192. *
  193. * The workaround could probably be enabled for all webcams, so the
  194. * quirk can be removed if needed. It's currently useful to detect
  195. * webcam bugs and fix them before they hit the market (providing
  196. * developers test their webcams with the Linux driver as well as with
  197. * the Windows driver).
  198. */
  199. mutex_lock(&stream->mutex);
  200. if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
  201. probe->dwMaxVideoFrameSize =
  202. stream->ctrl.dwMaxVideoFrameSize;
  203. /* Probe the device. */
  204. ret = uvc_probe_video(stream, probe);
  205. mutex_unlock(&stream->mutex);
  206. if (ret < 0)
  207. goto done;
  208. fmt->fmt.pix.width = frame->wWidth;
  209. fmt->fmt.pix.height = frame->wHeight;
  210. fmt->fmt.pix.field = V4L2_FIELD_NONE;
  211. fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
  212. fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
  213. fmt->fmt.pix.colorspace = format->colorspace;
  214. fmt->fmt.pix.priv = 0;
  215. if (uvc_format != NULL)
  216. *uvc_format = format;
  217. if (uvc_frame != NULL)
  218. *uvc_frame = frame;
  219. done:
  220. return ret;
  221. }
  222. static int uvc_v4l2_get_format(struct uvc_streaming *stream,
  223. struct v4l2_format *fmt)
  224. {
  225. struct uvc_format *format;
  226. struct uvc_frame *frame;
  227. int ret = 0;
  228. if (fmt->type != stream->type)
  229. return -EINVAL;
  230. mutex_lock(&stream->mutex);
  231. format = stream->cur_format;
  232. frame = stream->cur_frame;
  233. if (format == NULL || frame == NULL) {
  234. ret = -EINVAL;
  235. goto done;
  236. }
  237. fmt->fmt.pix.pixelformat = format->fcc;
  238. fmt->fmt.pix.width = frame->wWidth;
  239. fmt->fmt.pix.height = frame->wHeight;
  240. fmt->fmt.pix.field = V4L2_FIELD_NONE;
  241. fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
  242. fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize;
  243. fmt->fmt.pix.colorspace = format->colorspace;
  244. fmt->fmt.pix.priv = 0;
  245. done:
  246. mutex_unlock(&stream->mutex);
  247. return ret;
  248. }
  249. static int uvc_v4l2_set_format(struct uvc_streaming *stream,
  250. struct v4l2_format *fmt)
  251. {
  252. struct uvc_streaming_control probe;
  253. struct uvc_format *format;
  254. struct uvc_frame *frame;
  255. int ret;
  256. if (fmt->type != stream->type)
  257. return -EINVAL;
  258. ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);
  259. if (ret < 0)
  260. return ret;
  261. mutex_lock(&stream->mutex);
  262. if (uvc_queue_allocated(&stream->queue)) {
  263. ret = -EBUSY;
  264. goto done;
  265. }
  266. stream->ctrl = probe;
  267. stream->cur_format = format;
  268. stream->cur_frame = frame;
  269. done:
  270. mutex_unlock(&stream->mutex);
  271. return ret;
  272. }
  273. static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
  274. struct v4l2_streamparm *parm)
  275. {
  276. uint32_t numerator, denominator;
  277. if (parm->type != stream->type)
  278. return -EINVAL;
  279. mutex_lock(&stream->mutex);
  280. numerator = stream->ctrl.dwFrameInterval;
  281. mutex_unlock(&stream->mutex);
  282. denominator = 10000000;
  283. uvc_simplify_fraction(&numerator, &denominator, 8, 333);
  284. memset(parm, 0, sizeof *parm);
  285. parm->type = stream->type;
  286. if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  287. parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  288. parm->parm.capture.capturemode = 0;
  289. parm->parm.capture.timeperframe.numerator = numerator;
  290. parm->parm.capture.timeperframe.denominator = denominator;
  291. parm->parm.capture.extendedmode = 0;
  292. parm->parm.capture.readbuffers = 0;
  293. } else {
  294. parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
  295. parm->parm.output.outputmode = 0;
  296. parm->parm.output.timeperframe.numerator = numerator;
  297. parm->parm.output.timeperframe.denominator = denominator;
  298. }
  299. return 0;
  300. }
  301. static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
  302. struct v4l2_streamparm *parm)
  303. {
  304. struct uvc_streaming_control probe;
  305. struct v4l2_fract timeperframe;
  306. uint32_t interval;
  307. int ret;
  308. if (parm->type != stream->type)
  309. return -EINVAL;
  310. if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  311. timeperframe = parm->parm.capture.timeperframe;
  312. else
  313. timeperframe = parm->parm.output.timeperframe;
  314. interval = uvc_fraction_to_interval(timeperframe.numerator,
  315. timeperframe.denominator);
  316. uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n",
  317. timeperframe.numerator, timeperframe.denominator, interval);
  318. mutex_lock(&stream->mutex);
  319. if (uvc_queue_streaming(&stream->queue)) {
  320. mutex_unlock(&stream->mutex);
  321. return -EBUSY;
  322. }
  323. probe = stream->ctrl;
  324. probe.dwFrameInterval =
  325. uvc_try_frame_interval(stream->cur_frame, interval);
  326. /* Probe the device with the new settings. */
  327. ret = uvc_probe_video(stream, &probe);
  328. if (ret < 0) {
  329. mutex_unlock(&stream->mutex);
  330. return ret;
  331. }
  332. stream->ctrl = probe;
  333. mutex_unlock(&stream->mutex);
  334. /* Return the actual frame period. */
  335. timeperframe.numerator = probe.dwFrameInterval;
  336. timeperframe.denominator = 10000000;
  337. uvc_simplify_fraction(&timeperframe.numerator,
  338. &timeperframe.denominator, 8, 333);
  339. if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  340. parm->parm.capture.timeperframe = timeperframe;
  341. else
  342. parm->parm.output.timeperframe = timeperframe;
  343. return 0;
  344. }
  345. /* ------------------------------------------------------------------------
  346. * Privilege management
  347. */
  348. /*
  349. * Privilege management is the multiple-open implementation basis. The current
  350. * implementation is completely transparent for the end-user and doesn't
  351. * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls.
  352. * Those ioctls enable finer control on the device (by making possible for a
  353. * user to request exclusive access to a device), but are not mature yet.
  354. * Switching to the V4L2 priority mechanism might be considered in the future
  355. * if this situation changes.
  356. *
  357. * Each open instance of a UVC device can either be in a privileged or
  358. * unprivileged state. Only a single instance can be in a privileged state at
  359. * a given time. Trying to perform an operation that requires privileges will
  360. * automatically acquire the required privileges if possible, or return -EBUSY
  361. * otherwise. Privileges are dismissed when closing the instance or when
  362. * freeing the video buffers using VIDIOC_REQBUFS.
  363. *
  364. * Operations that require privileges are:
  365. *
  366. * - VIDIOC_S_INPUT
  367. * - VIDIOC_S_PARM
  368. * - VIDIOC_S_FMT
  369. * - VIDIOC_REQBUFS
  370. */
  371. static int uvc_acquire_privileges(struct uvc_fh *handle)
  372. {
  373. /* Always succeed if the handle is already privileged. */
  374. if (handle->state == UVC_HANDLE_ACTIVE)
  375. return 0;
  376. /* Check if the device already has a privileged handle. */
  377. if (atomic_inc_return(&handle->stream->active) != 1) {
  378. atomic_dec(&handle->stream->active);
  379. return -EBUSY;
  380. }
  381. handle->state = UVC_HANDLE_ACTIVE;
  382. return 0;
  383. }
  384. static void uvc_dismiss_privileges(struct uvc_fh *handle)
  385. {
  386. if (handle->state == UVC_HANDLE_ACTIVE)
  387. atomic_dec(&handle->stream->active);
  388. handle->state = UVC_HANDLE_PASSIVE;
  389. }
  390. static int uvc_has_privileges(struct uvc_fh *handle)
  391. {
  392. return handle->state == UVC_HANDLE_ACTIVE;
  393. }
  394. /* ------------------------------------------------------------------------
  395. * V4L2 file operations
  396. */
  397. static int uvc_v4l2_open(struct file *file)
  398. {
  399. struct uvc_streaming *stream;
  400. struct uvc_fh *handle;
  401. int ret = 0;
  402. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
  403. stream = video_drvdata(file);
  404. if (stream->dev->state & UVC_DEV_DISCONNECTED)
  405. return -ENODEV;
  406. ret = usb_autopm_get_interface(stream->dev->intf);
  407. if (ret < 0)
  408. return ret;
  409. /* Create the device handle. */
  410. handle = kzalloc(sizeof *handle, GFP_KERNEL);
  411. if (handle == NULL) {
  412. usb_autopm_put_interface(stream->dev->intf);
  413. return -ENOMEM;
  414. }
  415. if (atomic_inc_return(&stream->dev->users) == 1) {
  416. ret = uvc_status_start(stream->dev);
  417. if (ret < 0) {
  418. atomic_dec(&stream->dev->users);
  419. usb_autopm_put_interface(stream->dev->intf);
  420. kfree(handle);
  421. return ret;
  422. }
  423. }
  424. v4l2_fh_init(&handle->vfh, stream->vdev);
  425. v4l2_fh_add(&handle->vfh);
  426. handle->chain = stream->chain;
  427. handle->stream = stream;
  428. handle->state = UVC_HANDLE_PASSIVE;
  429. file->private_data = handle;
  430. return 0;
  431. }
  432. static int uvc_v4l2_release(struct file *file)
  433. {
  434. struct uvc_fh *handle = file->private_data;
  435. struct uvc_streaming *stream = handle->stream;
  436. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
  437. /* Only free resources if this is a privileged handle. */
  438. if (uvc_has_privileges(handle)) {
  439. uvc_video_enable(stream, 0);
  440. uvc_free_buffers(&stream->queue);
  441. }
  442. /* Release the file handle. */
  443. uvc_dismiss_privileges(handle);
  444. v4l2_fh_del(&handle->vfh);
  445. v4l2_fh_exit(&handle->vfh);
  446. kfree(handle);
  447. file->private_data = NULL;
  448. if (atomic_dec_return(&stream->dev->users) == 0)
  449. uvc_status_stop(stream->dev);
  450. usb_autopm_put_interface(stream->dev->intf);
  451. return 0;
  452. }
  453. static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
  454. {
  455. struct video_device *vdev = video_devdata(file);
  456. struct uvc_fh *handle = file->private_data;
  457. struct uvc_video_chain *chain = handle->chain;
  458. struct uvc_streaming *stream = handle->stream;
  459. long ret = 0;
  460. switch (cmd) {
  461. /* Query capabilities */
  462. case VIDIOC_QUERYCAP:
  463. {
  464. struct v4l2_capability *cap = arg;
  465. memset(cap, 0, sizeof *cap);
  466. strlcpy(cap->driver, "uvcvideo", sizeof cap->driver);
  467. strlcpy(cap->card, vdev->name, sizeof cap->card);
  468. usb_make_path(stream->dev->udev,
  469. cap->bus_info, sizeof(cap->bus_info));
  470. cap->version = LINUX_VERSION_CODE;
  471. cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
  472. | chain->caps;
  473. if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  474. cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
  475. | V4L2_CAP_STREAMING;
  476. else
  477. cap->device_caps = V4L2_CAP_VIDEO_OUTPUT
  478. | V4L2_CAP_STREAMING;
  479. break;
  480. }
  481. /* Priority */
  482. case VIDIOC_G_PRIORITY:
  483. *(u32 *)arg = v4l2_prio_max(vdev->prio);
  484. break;
  485. case VIDIOC_S_PRIORITY:
  486. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  487. if (ret < 0)
  488. return ret;
  489. return v4l2_prio_change(vdev->prio, &handle->vfh.prio,
  490. *(u32 *)arg);
  491. /* Get, Set & Query control */
  492. case VIDIOC_QUERYCTRL:
  493. return uvc_query_v4l2_ctrl(chain, arg);
  494. case VIDIOC_G_CTRL:
  495. {
  496. struct v4l2_control *ctrl = arg;
  497. struct v4l2_ext_control xctrl;
  498. memset(&xctrl, 0, sizeof xctrl);
  499. xctrl.id = ctrl->id;
  500. ret = uvc_ctrl_begin(chain);
  501. if (ret < 0)
  502. return ret;
  503. ret = uvc_ctrl_get(chain, &xctrl);
  504. uvc_ctrl_rollback(handle);
  505. if (ret >= 0)
  506. ctrl->value = xctrl.value;
  507. break;
  508. }
  509. case VIDIOC_S_CTRL:
  510. {
  511. struct v4l2_control *ctrl = arg;
  512. struct v4l2_ext_control xctrl;
  513. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  514. if (ret < 0)
  515. return ret;
  516. memset(&xctrl, 0, sizeof xctrl);
  517. xctrl.id = ctrl->id;
  518. xctrl.value = ctrl->value;
  519. ret = uvc_ctrl_begin(chain);
  520. if (ret < 0)
  521. return ret;
  522. ret = uvc_ctrl_set(chain, &xctrl);
  523. if (ret < 0) {
  524. uvc_ctrl_rollback(handle);
  525. return ret;
  526. }
  527. ret = uvc_ctrl_commit(handle, &xctrl, 1);
  528. if (ret == 0)
  529. ctrl->value = xctrl.value;
  530. break;
  531. }
  532. case VIDIOC_QUERYMENU:
  533. return uvc_query_v4l2_menu(chain, arg);
  534. case VIDIOC_G_EXT_CTRLS:
  535. {
  536. struct v4l2_ext_controls *ctrls = arg;
  537. struct v4l2_ext_control *ctrl = ctrls->controls;
  538. unsigned int i;
  539. ret = uvc_ctrl_begin(chain);
  540. if (ret < 0)
  541. return ret;
  542. for (i = 0; i < ctrls->count; ++ctrl, ++i) {
  543. ret = uvc_ctrl_get(chain, ctrl);
  544. if (ret < 0) {
  545. uvc_ctrl_rollback(handle);
  546. ctrls->error_idx = i;
  547. return ret;
  548. }
  549. }
  550. ctrls->error_idx = 0;
  551. ret = uvc_ctrl_rollback(handle);
  552. break;
  553. }
  554. case VIDIOC_S_EXT_CTRLS:
  555. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  556. if (ret < 0)
  557. return ret;
  558. /* Fall through */
  559. case VIDIOC_TRY_EXT_CTRLS:
  560. {
  561. struct v4l2_ext_controls *ctrls = arg;
  562. struct v4l2_ext_control *ctrl = ctrls->controls;
  563. unsigned int i;
  564. ret = uvc_ctrl_begin(chain);
  565. if (ret < 0)
  566. return ret;
  567. for (i = 0; i < ctrls->count; ++ctrl, ++i) {
  568. ret = uvc_ctrl_set(chain, ctrl);
  569. if (ret < 0) {
  570. uvc_ctrl_rollback(handle);
  571. ctrls->error_idx = cmd == VIDIOC_S_EXT_CTRLS
  572. ? ctrls->count : i;
  573. return ret;
  574. }
  575. }
  576. ctrls->error_idx = 0;
  577. if (cmd == VIDIOC_S_EXT_CTRLS)
  578. ret = uvc_ctrl_commit(handle,
  579. ctrls->controls, ctrls->count);
  580. else
  581. ret = uvc_ctrl_rollback(handle);
  582. break;
  583. }
  584. /* Get, Set & Enum input */
  585. case VIDIOC_ENUMINPUT:
  586. {
  587. const struct uvc_entity *selector = chain->selector;
  588. struct v4l2_input *input = arg;
  589. struct uvc_entity *iterm = NULL;
  590. u32 index = input->index;
  591. int pin = 0;
  592. if (selector == NULL ||
  593. (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
  594. if (index != 0)
  595. return -EINVAL;
  596. list_for_each_entry(iterm, &chain->entities, chain) {
  597. if (UVC_ENTITY_IS_ITERM(iterm))
  598. break;
  599. }
  600. pin = iterm->id;
  601. } else if (index < selector->bNrInPins) {
  602. pin = selector->baSourceID[index];
  603. list_for_each_entry(iterm, &chain->entities, chain) {
  604. if (!UVC_ENTITY_IS_ITERM(iterm))
  605. continue;
  606. if (iterm->id == pin)
  607. break;
  608. }
  609. }
  610. if (iterm == NULL || iterm->id != pin)
  611. return -EINVAL;
  612. memset(input, 0, sizeof *input);
  613. input->index = index;
  614. strlcpy(input->name, iterm->name, sizeof input->name);
  615. if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA)
  616. input->type = V4L2_INPUT_TYPE_CAMERA;
  617. break;
  618. }
  619. case VIDIOC_G_INPUT:
  620. {
  621. u8 input;
  622. if (chain->selector == NULL ||
  623. (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
  624. *(int *)arg = 0;
  625. break;
  626. }
  627. ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
  628. chain->selector->id, chain->dev->intfnum,
  629. UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
  630. if (ret < 0)
  631. return ret;
  632. *(int *)arg = input - 1;
  633. break;
  634. }
  635. case VIDIOC_S_INPUT:
  636. {
  637. u32 input = *(u32 *)arg + 1;
  638. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  639. if (ret < 0)
  640. return ret;
  641. if ((ret = uvc_acquire_privileges(handle)) < 0)
  642. return ret;
  643. if (chain->selector == NULL ||
  644. (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
  645. if (input != 1)
  646. return -EINVAL;
  647. break;
  648. }
  649. if (input == 0 || input > chain->selector->bNrInPins)
  650. return -EINVAL;
  651. return uvc_query_ctrl(chain->dev, UVC_SET_CUR,
  652. chain->selector->id, chain->dev->intfnum,
  653. UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
  654. }
  655. /* Try, Get, Set & Enum format */
  656. case VIDIOC_ENUM_FMT:
  657. {
  658. struct v4l2_fmtdesc *fmt = arg;
  659. struct uvc_format *format;
  660. enum v4l2_buf_type type = fmt->type;
  661. __u32 index = fmt->index;
  662. if (fmt->type != stream->type ||
  663. fmt->index >= stream->nformats)
  664. return -EINVAL;
  665. memset(fmt, 0, sizeof(*fmt));
  666. fmt->index = index;
  667. fmt->type = type;
  668. format = &stream->format[fmt->index];
  669. fmt->flags = 0;
  670. if (format->flags & UVC_FMT_FLAG_COMPRESSED)
  671. fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
  672. strlcpy(fmt->description, format->name,
  673. sizeof fmt->description);
  674. fmt->description[sizeof fmt->description - 1] = 0;
  675. fmt->pixelformat = format->fcc;
  676. break;
  677. }
  678. case VIDIOC_TRY_FMT:
  679. {
  680. struct uvc_streaming_control probe;
  681. return uvc_v4l2_try_format(stream, arg, &probe, NULL, NULL);
  682. }
  683. case VIDIOC_S_FMT:
  684. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  685. if (ret < 0)
  686. return ret;
  687. if ((ret = uvc_acquire_privileges(handle)) < 0)
  688. return ret;
  689. return uvc_v4l2_set_format(stream, arg);
  690. case VIDIOC_G_FMT:
  691. return uvc_v4l2_get_format(stream, arg);
  692. /* Frame size enumeration */
  693. case VIDIOC_ENUM_FRAMESIZES:
  694. {
  695. struct v4l2_frmsizeenum *fsize = arg;
  696. struct uvc_format *format = NULL;
  697. struct uvc_frame *frame;
  698. int i;
  699. /* Look for the given pixel format */
  700. for (i = 0; i < stream->nformats; i++) {
  701. if (stream->format[i].fcc ==
  702. fsize->pixel_format) {
  703. format = &stream->format[i];
  704. break;
  705. }
  706. }
  707. if (format == NULL)
  708. return -EINVAL;
  709. if (fsize->index >= format->nframes)
  710. return -EINVAL;
  711. frame = &format->frame[fsize->index];
  712. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  713. fsize->discrete.width = frame->wWidth;
  714. fsize->discrete.height = frame->wHeight;
  715. break;
  716. }
  717. /* Frame interval enumeration */
  718. case VIDIOC_ENUM_FRAMEINTERVALS:
  719. {
  720. struct v4l2_frmivalenum *fival = arg;
  721. struct uvc_format *format = NULL;
  722. struct uvc_frame *frame = NULL;
  723. int i;
  724. /* Look for the given pixel format and frame size */
  725. for (i = 0; i < stream->nformats; i++) {
  726. if (stream->format[i].fcc ==
  727. fival->pixel_format) {
  728. format = &stream->format[i];
  729. break;
  730. }
  731. }
  732. if (format == NULL)
  733. return -EINVAL;
  734. for (i = 0; i < format->nframes; i++) {
  735. if (format->frame[i].wWidth == fival->width &&
  736. format->frame[i].wHeight == fival->height) {
  737. frame = &format->frame[i];
  738. break;
  739. }
  740. }
  741. if (frame == NULL)
  742. return -EINVAL;
  743. if (frame->bFrameIntervalType) {
  744. if (fival->index >= frame->bFrameIntervalType)
  745. return -EINVAL;
  746. fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  747. fival->discrete.numerator =
  748. frame->dwFrameInterval[fival->index];
  749. fival->discrete.denominator = 10000000;
  750. uvc_simplify_fraction(&fival->discrete.numerator,
  751. &fival->discrete.denominator, 8, 333);
  752. } else {
  753. fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
  754. fival->stepwise.min.numerator =
  755. frame->dwFrameInterval[0];
  756. fival->stepwise.min.denominator = 10000000;
  757. fival->stepwise.max.numerator =
  758. frame->dwFrameInterval[1];
  759. fival->stepwise.max.denominator = 10000000;
  760. fival->stepwise.step.numerator =
  761. frame->dwFrameInterval[2];
  762. fival->stepwise.step.denominator = 10000000;
  763. uvc_simplify_fraction(&fival->stepwise.min.numerator,
  764. &fival->stepwise.min.denominator, 8, 333);
  765. uvc_simplify_fraction(&fival->stepwise.max.numerator,
  766. &fival->stepwise.max.denominator, 8, 333);
  767. uvc_simplify_fraction(&fival->stepwise.step.numerator,
  768. &fival->stepwise.step.denominator, 8, 333);
  769. }
  770. break;
  771. }
  772. /* Get & Set streaming parameters */
  773. case VIDIOC_G_PARM:
  774. return uvc_v4l2_get_streamparm(stream, arg);
  775. case VIDIOC_S_PARM:
  776. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  777. if (ret < 0)
  778. return ret;
  779. if ((ret = uvc_acquire_privileges(handle)) < 0)
  780. return ret;
  781. return uvc_v4l2_set_streamparm(stream, arg);
  782. /* Cropping and scaling */
  783. case VIDIOC_CROPCAP:
  784. {
  785. struct v4l2_cropcap *ccap = arg;
  786. if (ccap->type != stream->type)
  787. return -EINVAL;
  788. ccap->bounds.left = 0;
  789. ccap->bounds.top = 0;
  790. mutex_lock(&stream->mutex);
  791. ccap->bounds.width = stream->cur_frame->wWidth;
  792. ccap->bounds.height = stream->cur_frame->wHeight;
  793. mutex_unlock(&stream->mutex);
  794. ccap->defrect = ccap->bounds;
  795. ccap->pixelaspect.numerator = 1;
  796. ccap->pixelaspect.denominator = 1;
  797. break;
  798. }
  799. case VIDIOC_G_CROP:
  800. case VIDIOC_S_CROP:
  801. return -ENOTTY;
  802. /* Buffers & streaming */
  803. case VIDIOC_REQBUFS:
  804. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  805. if (ret < 0)
  806. return ret;
  807. if ((ret = uvc_acquire_privileges(handle)) < 0)
  808. return ret;
  809. mutex_lock(&stream->mutex);
  810. ret = uvc_alloc_buffers(&stream->queue, arg);
  811. mutex_unlock(&stream->mutex);
  812. if (ret < 0)
  813. return ret;
  814. if (ret == 0)
  815. uvc_dismiss_privileges(handle);
  816. ret = 0;
  817. break;
  818. case VIDIOC_QUERYBUF:
  819. {
  820. struct v4l2_buffer *buf = arg;
  821. if (!uvc_has_privileges(handle))
  822. return -EBUSY;
  823. return uvc_query_buffer(&stream->queue, buf);
  824. }
  825. case VIDIOC_QBUF:
  826. if (!uvc_has_privileges(handle))
  827. return -EBUSY;
  828. return uvc_queue_buffer(&stream->queue, arg);
  829. case VIDIOC_DQBUF:
  830. if (!uvc_has_privileges(handle))
  831. return -EBUSY;
  832. return uvc_dequeue_buffer(&stream->queue, arg,
  833. file->f_flags & O_NONBLOCK);
  834. case VIDIOC_STREAMON:
  835. {
  836. int *type = arg;
  837. if (*type != stream->type)
  838. return -EINVAL;
  839. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  840. if (ret < 0)
  841. return ret;
  842. if (!uvc_has_privileges(handle))
  843. return -EBUSY;
  844. mutex_lock(&stream->mutex);
  845. ret = uvc_video_enable(stream, 1);
  846. mutex_unlock(&stream->mutex);
  847. if (ret < 0)
  848. return ret;
  849. break;
  850. }
  851. case VIDIOC_STREAMOFF:
  852. {
  853. int *type = arg;
  854. if (*type != stream->type)
  855. return -EINVAL;
  856. ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
  857. if (ret < 0)
  858. return ret;
  859. if (!uvc_has_privileges(handle))
  860. return -EBUSY;
  861. return uvc_video_enable(stream, 0);
  862. }
  863. case VIDIOC_SUBSCRIBE_EVENT:
  864. {
  865. struct v4l2_event_subscription *sub = arg;
  866. switch (sub->type) {
  867. case V4L2_EVENT_CTRL:
  868. return v4l2_event_subscribe(&handle->vfh, sub, 0,
  869. &uvc_ctrl_sub_ev_ops);
  870. default:
  871. return -EINVAL;
  872. }
  873. }
  874. case VIDIOC_UNSUBSCRIBE_EVENT:
  875. return v4l2_event_unsubscribe(&handle->vfh, arg);
  876. case VIDIOC_DQEVENT:
  877. return v4l2_event_dequeue(&handle->vfh, arg,
  878. file->f_flags & O_NONBLOCK);
  879. /* Analog video standards make no sense for digital cameras. */
  880. case VIDIOC_ENUMSTD:
  881. case VIDIOC_QUERYSTD:
  882. case VIDIOC_G_STD:
  883. case VIDIOC_S_STD:
  884. case VIDIOC_OVERLAY:
  885. case VIDIOC_ENUMAUDIO:
  886. case VIDIOC_ENUMAUDOUT:
  887. case VIDIOC_ENUMOUTPUT:
  888. uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd);
  889. return -ENOTTY;
  890. case UVCIOC_CTRL_MAP:
  891. return uvc_ioctl_ctrl_map(chain, arg);
  892. case UVCIOC_CTRL_QUERY:
  893. return uvc_xu_ctrl_query(chain, arg);
  894. default:
  895. uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n", cmd);
  896. return -ENOTTY;
  897. }
  898. return ret;
  899. }
  900. static long uvc_v4l2_ioctl(struct file *file,
  901. unsigned int cmd, unsigned long arg)
  902. {
  903. if (uvc_trace_param & UVC_TRACE_IOCTL) {
  904. uvc_printk(KERN_DEBUG, "uvc_v4l2_ioctl(");
  905. v4l_printk_ioctl(NULL, cmd);
  906. printk(")\n");
  907. }
  908. return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl);
  909. }
  910. #ifdef CONFIG_COMPAT
  911. struct uvc_xu_control_mapping32 {
  912. __u32 id;
  913. __u8 name[32];
  914. __u8 entity[16];
  915. __u8 selector;
  916. __u8 size;
  917. __u8 offset;
  918. __u32 v4l2_type;
  919. __u32 data_type;
  920. compat_caddr_t menu_info;
  921. __u32 menu_count;
  922. __u32 reserved[4];
  923. };
  924. static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
  925. const struct uvc_xu_control_mapping32 __user *up)
  926. {
  927. struct uvc_menu_info __user *umenus;
  928. struct uvc_menu_info __user *kmenus;
  929. compat_caddr_t p;
  930. if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
  931. __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) ||
  932. __get_user(kp->menu_count, &up->menu_count))
  933. return -EFAULT;
  934. memset(kp->reserved, 0, sizeof(kp->reserved));
  935. if (kp->menu_count == 0) {
  936. kp->menu_info = NULL;
  937. return 0;
  938. }
  939. if (__get_user(p, &up->menu_info))
  940. return -EFAULT;
  941. umenus = compat_ptr(p);
  942. if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus)))
  943. return -EFAULT;
  944. kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus));
  945. if (kmenus == NULL)
  946. return -EFAULT;
  947. kp->menu_info = kmenus;
  948. if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus)))
  949. return -EFAULT;
  950. return 0;
  951. }
  952. static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
  953. struct uvc_xu_control_mapping32 __user *up)
  954. {
  955. struct uvc_menu_info __user *umenus;
  956. struct uvc_menu_info __user *kmenus = kp->menu_info;
  957. compat_caddr_t p;
  958. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
  959. __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
  960. __put_user(kp->menu_count, &up->menu_count))
  961. return -EFAULT;
  962. if (__clear_user(up->reserved, sizeof(up->reserved)))
  963. return -EFAULT;
  964. if (kp->menu_count == 0)
  965. return 0;
  966. if (get_user(p, &up->menu_info))
  967. return -EFAULT;
  968. umenus = compat_ptr(p);
  969. if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus)))
  970. return -EFAULT;
  971. return 0;
  972. }
  973. struct uvc_xu_control_query32 {
  974. __u8 unit;
  975. __u8 selector;
  976. __u8 query;
  977. __u16 size;
  978. compat_caddr_t data;
  979. };
  980. static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
  981. const struct uvc_xu_control_query32 __user *up)
  982. {
  983. u8 __user *udata;
  984. u8 __user *kdata;
  985. compat_caddr_t p;
  986. if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
  987. __copy_from_user(kp, up, offsetof(typeof(*up), data)))
  988. return -EFAULT;
  989. if (kp->size == 0) {
  990. kp->data = NULL;
  991. return 0;
  992. }
  993. if (__get_user(p, &up->data))
  994. return -EFAULT;
  995. udata = compat_ptr(p);
  996. if (!access_ok(VERIFY_READ, udata, kp->size))
  997. return -EFAULT;
  998. kdata = compat_alloc_user_space(kp->size);
  999. if (kdata == NULL)
  1000. return -EFAULT;
  1001. kp->data = kdata;
  1002. if (copy_in_user(kdata, udata, kp->size))
  1003. return -EFAULT;
  1004. return 0;
  1005. }
  1006. static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
  1007. struct uvc_xu_control_query32 __user *up)
  1008. {
  1009. u8 __user *udata;
  1010. u8 __user *kdata = kp->data;
  1011. compat_caddr_t p;
  1012. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
  1013. __copy_to_user(up, kp, offsetof(typeof(*up), data)))
  1014. return -EFAULT;
  1015. if (kp->size == 0)
  1016. return 0;
  1017. if (get_user(p, &up->data))
  1018. return -EFAULT;
  1019. udata = compat_ptr(p);
  1020. if (!access_ok(VERIFY_READ, udata, kp->size))
  1021. return -EFAULT;
  1022. if (copy_in_user(udata, kdata, kp->size))
  1023. return -EFAULT;
  1024. return 0;
  1025. }
  1026. #define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32)
  1027. #define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32)
  1028. static long uvc_v4l2_compat_ioctl32(struct file *file,
  1029. unsigned int cmd, unsigned long arg)
  1030. {
  1031. union {
  1032. struct uvc_xu_control_mapping xmap;
  1033. struct uvc_xu_control_query xqry;
  1034. } karg;
  1035. void __user *up = compat_ptr(arg);
  1036. mm_segment_t old_fs;
  1037. long ret;
  1038. switch (cmd) {
  1039. case UVCIOC_CTRL_MAP32:
  1040. cmd = UVCIOC_CTRL_MAP;
  1041. ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
  1042. break;
  1043. case UVCIOC_CTRL_QUERY32:
  1044. cmd = UVCIOC_CTRL_QUERY;
  1045. ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
  1046. break;
  1047. default:
  1048. return -ENOIOCTLCMD;
  1049. }
  1050. old_fs = get_fs();
  1051. set_fs(KERNEL_DS);
  1052. ret = uvc_v4l2_ioctl(file, cmd, (unsigned long)&karg);
  1053. set_fs(old_fs);
  1054. if (ret < 0)
  1055. return ret;
  1056. switch (cmd) {
  1057. case UVCIOC_CTRL_MAP:
  1058. ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up);
  1059. break;
  1060. case UVCIOC_CTRL_QUERY:
  1061. ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
  1062. break;
  1063. }
  1064. return ret;
  1065. }
  1066. #endif
  1067. static ssize_t uvc_v4l2_read(struct file *file, char __user *data,
  1068. size_t count, loff_t *ppos)
  1069. {
  1070. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n");
  1071. return -EINVAL;
  1072. }
  1073. static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
  1074. {
  1075. struct uvc_fh *handle = file->private_data;
  1076. struct uvc_streaming *stream = handle->stream;
  1077. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n");
  1078. return uvc_queue_mmap(&stream->queue, vma);
  1079. }
  1080. static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
  1081. {
  1082. struct uvc_fh *handle = file->private_data;
  1083. struct uvc_streaming *stream = handle->stream;
  1084. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
  1085. return uvc_queue_poll(&stream->queue, file, wait);
  1086. }
  1087. #ifndef CONFIG_MMU
  1088. static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
  1089. unsigned long addr, unsigned long len, unsigned long pgoff,
  1090. unsigned long flags)
  1091. {
  1092. struct uvc_fh *handle = file->private_data;
  1093. struct uvc_streaming *stream = handle->stream;
  1094. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n");
  1095. return uvc_queue_get_unmapped_area(&stream->queue, pgoff);
  1096. }
  1097. #endif
  1098. const struct v4l2_file_operations uvc_fops = {
  1099. .owner = THIS_MODULE,
  1100. .open = uvc_v4l2_open,
  1101. .release = uvc_v4l2_release,
  1102. .unlocked_ioctl = uvc_v4l2_ioctl,
  1103. #ifdef CONFIG_COMPAT
  1104. .compat_ioctl32 = uvc_v4l2_compat_ioctl32,
  1105. #endif
  1106. .read = uvc_v4l2_read,
  1107. .mmap = uvc_v4l2_mmap,
  1108. .poll = uvc_v4l2_poll,
  1109. #ifndef CONFIG_MMU
  1110. .get_unmapped_area = uvc_v4l2_get_unmapped_area,
  1111. #endif
  1112. };