v4l2-ioctl.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374
  1. /*
  2. * Video capture interface for Linux version 2
  3. *
  4. * A generic framework to process V4L2 ioctl commands.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
  12. * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
  13. */
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/version.h>
  19. #include <linux/videodev2.h>
  20. #include <media/v4l2-common.h>
  21. #include <media/v4l2-ioctl.h>
  22. #include <media/v4l2-ctrls.h>
  23. #include <media/v4l2-fh.h>
  24. #include <media/v4l2-event.h>
  25. #include <media/v4l2-device.h>
  26. #include <media/v4l2-chip-ident.h>
  27. #include <media/videobuf2-core.h>
  28. /* Zero out the end of the struct pointed to by p. Everything after, but
  29. * not including, the specified field is cleared. */
  30. #define CLEAR_AFTER_FIELD(p, field) \
  31. memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
  32. 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
  33. #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls)
  34. struct std_descr {
  35. v4l2_std_id std;
  36. const char *descr;
  37. };
  38. static const struct std_descr standards[] = {
  39. { V4L2_STD_NTSC, "NTSC" },
  40. { V4L2_STD_NTSC_M, "NTSC-M" },
  41. { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
  42. { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
  43. { V4L2_STD_NTSC_443, "NTSC-443" },
  44. { V4L2_STD_PAL, "PAL" },
  45. { V4L2_STD_PAL_BG, "PAL-BG" },
  46. { V4L2_STD_PAL_B, "PAL-B" },
  47. { V4L2_STD_PAL_B1, "PAL-B1" },
  48. { V4L2_STD_PAL_G, "PAL-G" },
  49. { V4L2_STD_PAL_H, "PAL-H" },
  50. { V4L2_STD_PAL_I, "PAL-I" },
  51. { V4L2_STD_PAL_DK, "PAL-DK" },
  52. { V4L2_STD_PAL_D, "PAL-D" },
  53. { V4L2_STD_PAL_D1, "PAL-D1" },
  54. { V4L2_STD_PAL_K, "PAL-K" },
  55. { V4L2_STD_PAL_M, "PAL-M" },
  56. { V4L2_STD_PAL_N, "PAL-N" },
  57. { V4L2_STD_PAL_Nc, "PAL-Nc" },
  58. { V4L2_STD_PAL_60, "PAL-60" },
  59. { V4L2_STD_SECAM, "SECAM" },
  60. { V4L2_STD_SECAM_B, "SECAM-B" },
  61. { V4L2_STD_SECAM_G, "SECAM-G" },
  62. { V4L2_STD_SECAM_H, "SECAM-H" },
  63. { V4L2_STD_SECAM_DK, "SECAM-DK" },
  64. { V4L2_STD_SECAM_D, "SECAM-D" },
  65. { V4L2_STD_SECAM_K, "SECAM-K" },
  66. { V4L2_STD_SECAM_K1, "SECAM-K1" },
  67. { V4L2_STD_SECAM_L, "SECAM-L" },
  68. { V4L2_STD_SECAM_LC, "SECAM-Lc" },
  69. { 0, "Unknown" }
  70. };
  71. /* video4linux standard ID conversion to standard name
  72. */
  73. const char *v4l2_norm_to_name(v4l2_std_id id)
  74. {
  75. u32 myid = id;
  76. int i;
  77. /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
  78. 64 bit comparations. So, on that architecture, with some gcc
  79. variants, compilation fails. Currently, the max value is 30bit wide.
  80. */
  81. BUG_ON(myid != id);
  82. for (i = 0; standards[i].std; i++)
  83. if (myid == standards[i].std)
  84. break;
  85. return standards[i].descr;
  86. }
  87. EXPORT_SYMBOL(v4l2_norm_to_name);
  88. /* Returns frame period for the given standard */
  89. void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
  90. {
  91. if (id & V4L2_STD_525_60) {
  92. frameperiod->numerator = 1001;
  93. frameperiod->denominator = 30000;
  94. } else {
  95. frameperiod->numerator = 1;
  96. frameperiod->denominator = 25;
  97. }
  98. }
  99. EXPORT_SYMBOL(v4l2_video_std_frame_period);
  100. /* Fill in the fields of a v4l2_standard structure according to the
  101. 'id' and 'transmission' parameters. Returns negative on error. */
  102. int v4l2_video_std_construct(struct v4l2_standard *vs,
  103. int id, const char *name)
  104. {
  105. vs->id = id;
  106. v4l2_video_std_frame_period(id, &vs->frameperiod);
  107. vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
  108. strlcpy(vs->name, name, sizeof(vs->name));
  109. return 0;
  110. }
  111. EXPORT_SYMBOL(v4l2_video_std_construct);
  112. /* ----------------------------------------------------------------- */
  113. /* some arrays for pretty-printing debug messages of enum types */
  114. const char *v4l2_field_names[] = {
  115. [V4L2_FIELD_ANY] = "any",
  116. [V4L2_FIELD_NONE] = "none",
  117. [V4L2_FIELD_TOP] = "top",
  118. [V4L2_FIELD_BOTTOM] = "bottom",
  119. [V4L2_FIELD_INTERLACED] = "interlaced",
  120. [V4L2_FIELD_SEQ_TB] = "seq-tb",
  121. [V4L2_FIELD_SEQ_BT] = "seq-bt",
  122. [V4L2_FIELD_ALTERNATE] = "alternate",
  123. [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
  124. [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
  125. };
  126. EXPORT_SYMBOL(v4l2_field_names);
  127. const char *v4l2_type_names[] = {
  128. [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
  129. [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
  130. [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
  131. [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
  132. [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
  133. [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
  134. [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
  135. [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
  136. [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
  137. [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
  138. };
  139. EXPORT_SYMBOL(v4l2_type_names);
  140. static const char *v4l2_memory_names[] = {
  141. [V4L2_MEMORY_MMAP] = "mmap",
  142. [V4L2_MEMORY_USERPTR] = "userptr",
  143. [V4L2_MEMORY_OVERLAY] = "overlay",
  144. [V4L2_MEMORY_DMABUF] = "dmabuf",
  145. };
  146. #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
  147. /* ------------------------------------------------------------------ */
  148. /* debug help functions */
  149. static void v4l_print_querycap(const void *arg, bool write_only)
  150. {
  151. const struct v4l2_capability *p = arg;
  152. pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, "
  153. "capabilities=0x%08x, device_caps=0x%08x\n",
  154. (int)sizeof(p->driver), p->driver,
  155. (int)sizeof(p->card), p->card,
  156. (int)sizeof(p->bus_info), p->bus_info,
  157. p->version, p->capabilities, p->device_caps);
  158. }
  159. static void v4l_print_enuminput(const void *arg, bool write_only)
  160. {
  161. const struct v4l2_input *p = arg;
  162. pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, "
  163. "std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
  164. p->index, (int)sizeof(p->name), p->name, p->type, p->audioset,
  165. p->tuner, (unsigned long long)p->std, p->status,
  166. p->capabilities);
  167. }
  168. static void v4l_print_enumoutput(const void *arg, bool write_only)
  169. {
  170. const struct v4l2_output *p = arg;
  171. pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, "
  172. "modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
  173. p->index, (int)sizeof(p->name), p->name, p->type, p->audioset,
  174. p->modulator, (unsigned long long)p->std, p->capabilities);
  175. }
  176. static void v4l_print_audio(const void *arg, bool write_only)
  177. {
  178. const struct v4l2_audio *p = arg;
  179. if (write_only)
  180. pr_cont("index=%u, mode=0x%x\n", p->index, p->mode);
  181. else
  182. pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
  183. p->index, (int)sizeof(p->name), p->name,
  184. p->capability, p->mode);
  185. }
  186. static void v4l_print_audioout(const void *arg, bool write_only)
  187. {
  188. const struct v4l2_audioout *p = arg;
  189. if (write_only)
  190. pr_cont("index=%u\n", p->index);
  191. else
  192. pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
  193. p->index, (int)sizeof(p->name), p->name,
  194. p->capability, p->mode);
  195. }
  196. static void v4l_print_fmtdesc(const void *arg, bool write_only)
  197. {
  198. const struct v4l2_fmtdesc *p = arg;
  199. pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
  200. p->index, prt_names(p->type, v4l2_type_names),
  201. p->flags, (p->pixelformat & 0xff),
  202. (p->pixelformat >> 8) & 0xff,
  203. (p->pixelformat >> 16) & 0xff,
  204. (p->pixelformat >> 24) & 0xff,
  205. (int)sizeof(p->description), p->description);
  206. }
  207. static void v4l_print_format(const void *arg, bool write_only)
  208. {
  209. const struct v4l2_format *p = arg;
  210. const struct v4l2_pix_format *pix;
  211. const struct v4l2_pix_format_mplane *mp;
  212. const struct v4l2_vbi_format *vbi;
  213. const struct v4l2_sliced_vbi_format *sliced;
  214. const struct v4l2_window *win;
  215. const struct v4l2_clip *clip;
  216. unsigned i;
  217. pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
  218. switch (p->type) {
  219. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  220. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  221. pix = &p->fmt.pix;
  222. pr_cont(", width=%u, height=%u, "
  223. "pixelformat=%c%c%c%c, field=%s, "
  224. "bytesperline=%u sizeimage=%u, colorspace=%d\n",
  225. pix->width, pix->height,
  226. (pix->pixelformat & 0xff),
  227. (pix->pixelformat >> 8) & 0xff,
  228. (pix->pixelformat >> 16) & 0xff,
  229. (pix->pixelformat >> 24) & 0xff,
  230. prt_names(pix->field, v4l2_field_names),
  231. pix->bytesperline, pix->sizeimage,
  232. pix->colorspace);
  233. break;
  234. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  235. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  236. mp = &p->fmt.pix_mp;
  237. pr_cont(", width=%u, height=%u, "
  238. "format=%c%c%c%c, field=%s, "
  239. "colorspace=%d, num_planes=%u\n",
  240. mp->width, mp->height,
  241. (mp->pixelformat & 0xff),
  242. (mp->pixelformat >> 8) & 0xff,
  243. (mp->pixelformat >> 16) & 0xff,
  244. (mp->pixelformat >> 24) & 0xff,
  245. prt_names(mp->field, v4l2_field_names),
  246. mp->colorspace, mp->num_planes);
  247. for (i = 0; i < mp->num_planes; i++)
  248. printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i,
  249. mp->plane_fmt[i].bytesperline,
  250. mp->plane_fmt[i].sizeimage);
  251. break;
  252. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  253. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  254. win = &p->fmt.win;
  255. pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, "
  256. "chromakey=0x%08x, bitmap=%p, "
  257. "global_alpha=0x%02x\n",
  258. win->w.width, win->w.height,
  259. win->w.left, win->w.top,
  260. prt_names(win->field, v4l2_field_names),
  261. win->chromakey, win->bitmap, win->global_alpha);
  262. clip = win->clips;
  263. for (i = 0; i < win->clipcount; i++) {
  264. printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n",
  265. i, clip->c.width, clip->c.height,
  266. clip->c.left, clip->c.top);
  267. clip = clip->next;
  268. }
  269. break;
  270. case V4L2_BUF_TYPE_VBI_CAPTURE:
  271. case V4L2_BUF_TYPE_VBI_OUTPUT:
  272. vbi = &p->fmt.vbi;
  273. pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, "
  274. "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
  275. vbi->sampling_rate, vbi->offset,
  276. vbi->samples_per_line,
  277. (vbi->sample_format & 0xff),
  278. (vbi->sample_format >> 8) & 0xff,
  279. (vbi->sample_format >> 16) & 0xff,
  280. (vbi->sample_format >> 24) & 0xff,
  281. vbi->start[0], vbi->start[1],
  282. vbi->count[0], vbi->count[1]);
  283. break;
  284. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  285. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  286. sliced = &p->fmt.sliced;
  287. pr_cont(", service_set=0x%08x, io_size=%d\n",
  288. sliced->service_set, sliced->io_size);
  289. for (i = 0; i < 24; i++)
  290. printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
  291. sliced->service_lines[0][i],
  292. sliced->service_lines[1][i]);
  293. break;
  294. }
  295. }
  296. static void v4l_print_framebuffer(const void *arg, bool write_only)
  297. {
  298. const struct v4l2_framebuffer *p = arg;
  299. pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, "
  300. "height=%u, pixelformat=%c%c%c%c, "
  301. "bytesperline=%u sizeimage=%u, colorspace=%d\n",
  302. p->capability, p->flags, p->base,
  303. p->fmt.width, p->fmt.height,
  304. (p->fmt.pixelformat & 0xff),
  305. (p->fmt.pixelformat >> 8) & 0xff,
  306. (p->fmt.pixelformat >> 16) & 0xff,
  307. (p->fmt.pixelformat >> 24) & 0xff,
  308. p->fmt.bytesperline, p->fmt.sizeimage,
  309. p->fmt.colorspace);
  310. }
  311. static void v4l_print_buftype(const void *arg, bool write_only)
  312. {
  313. pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names));
  314. }
  315. static void v4l_print_modulator(const void *arg, bool write_only)
  316. {
  317. const struct v4l2_modulator *p = arg;
  318. if (write_only)
  319. pr_cont("index=%u, txsubchans=0x%x", p->index, p->txsubchans);
  320. else
  321. pr_cont("index=%u, name=%.*s, capability=0x%x, "
  322. "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
  323. p->index, (int)sizeof(p->name), p->name, p->capability,
  324. p->rangelow, p->rangehigh, p->txsubchans);
  325. }
  326. static void v4l_print_tuner(const void *arg, bool write_only)
  327. {
  328. const struct v4l2_tuner *p = arg;
  329. if (write_only)
  330. pr_cont("index=%u, audmode=%u\n", p->index, p->audmode);
  331. else
  332. pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, "
  333. "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, "
  334. "rxsubchans=0x%x, audmode=%u\n",
  335. p->index, (int)sizeof(p->name), p->name, p->type,
  336. p->capability, p->rangelow,
  337. p->rangehigh, p->signal, p->afc,
  338. p->rxsubchans, p->audmode);
  339. }
  340. static void v4l_print_frequency(const void *arg, bool write_only)
  341. {
  342. const struct v4l2_frequency *p = arg;
  343. pr_cont("tuner=%u, type=%u, frequency=%u\n",
  344. p->tuner, p->type, p->frequency);
  345. }
  346. static void v4l_print_standard(const void *arg, bool write_only)
  347. {
  348. const struct v4l2_standard *p = arg;
  349. pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, "
  350. "framelines=%u\n", p->index,
  351. (unsigned long long)p->id, (int)sizeof(p->name), p->name,
  352. p->frameperiod.numerator,
  353. p->frameperiod.denominator,
  354. p->framelines);
  355. }
  356. static void v4l_print_std(const void *arg, bool write_only)
  357. {
  358. pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg);
  359. }
  360. static void v4l_print_hw_freq_seek(const void *arg, bool write_only)
  361. {
  362. const struct v4l2_hw_freq_seek *p = arg;
  363. pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, "
  364. "rangelow=%u, rangehigh=%u\n",
  365. p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing,
  366. p->rangelow, p->rangehigh);
  367. }
  368. static void v4l_print_requestbuffers(const void *arg, bool write_only)
  369. {
  370. const struct v4l2_requestbuffers *p = arg;
  371. pr_cont("count=%d, type=%s, memory=%s\n",
  372. p->count,
  373. prt_names(p->type, v4l2_type_names),
  374. prt_names(p->memory, v4l2_memory_names));
  375. }
  376. static void v4l_print_buffer(const void *arg, bool write_only)
  377. {
  378. const struct v4l2_buffer *p = arg;
  379. const struct v4l2_timecode *tc = &p->timecode;
  380. const struct v4l2_plane *plane;
  381. int i;
  382. pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, "
  383. "flags=0x%08x, field=%s, sequence=%d, memory=%s",
  384. p->timestamp.tv_sec / 3600,
  385. (int)(p->timestamp.tv_sec / 60) % 60,
  386. (int)(p->timestamp.tv_sec % 60),
  387. (long)p->timestamp.tv_usec,
  388. p->index,
  389. prt_names(p->type, v4l2_type_names),
  390. p->flags, prt_names(p->field, v4l2_field_names),
  391. p->sequence, prt_names(p->memory, v4l2_memory_names));
  392. if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
  393. pr_cont("\n");
  394. for (i = 0; i < p->length; ++i) {
  395. plane = &p->m.planes[i];
  396. printk(KERN_DEBUG
  397. "plane %d: bytesused=%d, data_offset=0x%08x "
  398. "offset/userptr=0x%lx, length=%d\n",
  399. i, plane->bytesused, plane->data_offset,
  400. plane->m.userptr, plane->length);
  401. }
  402. } else {
  403. pr_cont("bytesused=%d, offset/userptr=0x%lx, length=%d\n",
  404. p->bytesused, p->m.userptr, p->length);
  405. }
  406. printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, "
  407. "flags=0x%08x, frames=%d, userbits=0x%08x\n",
  408. tc->hours, tc->minutes, tc->seconds,
  409. tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
  410. }
  411. static void v4l_print_exportbuffer(const void *arg, bool write_only)
  412. {
  413. const struct v4l2_exportbuffer *p = arg;
  414. pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n",
  415. p->fd, prt_names(p->type, v4l2_type_names),
  416. p->index, p->plane, p->flags);
  417. }
  418. static void v4l_print_create_buffers(const void *arg, bool write_only)
  419. {
  420. const struct v4l2_create_buffers *p = arg;
  421. pr_cont("index=%d, count=%d, memory=%s, ",
  422. p->index, p->count,
  423. prt_names(p->memory, v4l2_memory_names));
  424. v4l_print_format(&p->format, write_only);
  425. }
  426. static void v4l_print_streamparm(const void *arg, bool write_only)
  427. {
  428. const struct v4l2_streamparm *p = arg;
  429. pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
  430. if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  431. p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  432. const struct v4l2_captureparm *c = &p->parm.capture;
  433. pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, "
  434. "extendedmode=%d, readbuffers=%d\n",
  435. c->capability, c->capturemode,
  436. c->timeperframe.numerator, c->timeperframe.denominator,
  437. c->extendedmode, c->readbuffers);
  438. } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
  439. p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  440. const struct v4l2_outputparm *c = &p->parm.output;
  441. pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, "
  442. "extendedmode=%d, writebuffers=%d\n",
  443. c->capability, c->outputmode,
  444. c->timeperframe.numerator, c->timeperframe.denominator,
  445. c->extendedmode, c->writebuffers);
  446. }
  447. }
  448. static void v4l_print_queryctrl(const void *arg, bool write_only)
  449. {
  450. const struct v4l2_queryctrl *p = arg;
  451. pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, "
  452. "step=%d, default=%d, flags=0x%08x\n",
  453. p->id, p->type, (int)sizeof(p->name), p->name,
  454. p->minimum, p->maximum,
  455. p->step, p->default_value, p->flags);
  456. }
  457. static void v4l_print_querymenu(const void *arg, bool write_only)
  458. {
  459. const struct v4l2_querymenu *p = arg;
  460. pr_cont("id=0x%x, index=%d\n", p->id, p->index);
  461. }
  462. static void v4l_print_control(const void *arg, bool write_only)
  463. {
  464. const struct v4l2_control *p = arg;
  465. pr_cont("id=0x%x, value=%d\n", p->id, p->value);
  466. }
  467. static void v4l_print_ext_controls(const void *arg, bool write_only)
  468. {
  469. const struct v4l2_ext_controls *p = arg;
  470. int i;
  471. pr_cont("class=0x%x, count=%d, error_idx=%d",
  472. p->ctrl_class, p->count, p->error_idx);
  473. for (i = 0; i < p->count; i++) {
  474. if (p->controls[i].size)
  475. pr_cont(", id/val=0x%x/0x%x",
  476. p->controls[i].id, p->controls[i].value);
  477. else
  478. pr_cont(", id/size=0x%x/%u",
  479. p->controls[i].id, p->controls[i].size);
  480. }
  481. pr_cont("\n");
  482. }
  483. static void v4l_print_cropcap(const void *arg, bool write_only)
  484. {
  485. const struct v4l2_cropcap *p = arg;
  486. pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, "
  487. "defrect wxh=%dx%d, x,y=%d,%d\n, "
  488. "pixelaspect %d/%d\n",
  489. prt_names(p->type, v4l2_type_names),
  490. p->bounds.width, p->bounds.height,
  491. p->bounds.left, p->bounds.top,
  492. p->defrect.width, p->defrect.height,
  493. p->defrect.left, p->defrect.top,
  494. p->pixelaspect.numerator, p->pixelaspect.denominator);
  495. }
  496. static void v4l_print_crop(const void *arg, bool write_only)
  497. {
  498. const struct v4l2_crop *p = arg;
  499. pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
  500. prt_names(p->type, v4l2_type_names),
  501. p->c.width, p->c.height,
  502. p->c.left, p->c.top);
  503. }
  504. static void v4l_print_selection(const void *arg, bool write_only)
  505. {
  506. const struct v4l2_selection *p = arg;
  507. pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
  508. prt_names(p->type, v4l2_type_names),
  509. p->target, p->flags,
  510. p->r.width, p->r.height, p->r.left, p->r.top);
  511. }
  512. static void v4l_print_jpegcompression(const void *arg, bool write_only)
  513. {
  514. const struct v4l2_jpegcompression *p = arg;
  515. pr_cont("quality=%d, APPn=%d, APP_len=%d, "
  516. "COM_len=%d, jpeg_markers=0x%x\n",
  517. p->quality, p->APPn, p->APP_len,
  518. p->COM_len, p->jpeg_markers);
  519. }
  520. static void v4l_print_enc_idx(const void *arg, bool write_only)
  521. {
  522. const struct v4l2_enc_idx *p = arg;
  523. pr_cont("entries=%d, entries_cap=%d\n",
  524. p->entries, p->entries_cap);
  525. }
  526. static void v4l_print_encoder_cmd(const void *arg, bool write_only)
  527. {
  528. const struct v4l2_encoder_cmd *p = arg;
  529. pr_cont("cmd=%d, flags=0x%x\n",
  530. p->cmd, p->flags);
  531. }
  532. static void v4l_print_decoder_cmd(const void *arg, bool write_only)
  533. {
  534. const struct v4l2_decoder_cmd *p = arg;
  535. pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags);
  536. if (p->cmd == V4L2_DEC_CMD_START)
  537. pr_info("speed=%d, format=%u\n",
  538. p->start.speed, p->start.format);
  539. else if (p->cmd == V4L2_DEC_CMD_STOP)
  540. pr_info("pts=%llu\n", p->stop.pts);
  541. }
  542. static void v4l_print_dbg_chip_ident(const void *arg, bool write_only)
  543. {
  544. const struct v4l2_dbg_chip_ident *p = arg;
  545. pr_cont("type=%u, ", p->match.type);
  546. if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
  547. pr_cont("name=%.*s, ",
  548. (int)sizeof(p->match.name), p->match.name);
  549. else
  550. pr_cont("addr=%u, ", p->match.addr);
  551. pr_cont("chip_ident=%u, revision=0x%x\n",
  552. p->ident, p->revision);
  553. }
  554. static void v4l_print_dbg_register(const void *arg, bool write_only)
  555. {
  556. const struct v4l2_dbg_register *p = arg;
  557. pr_cont("type=%u, ", p->match.type);
  558. if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
  559. pr_cont("name=%.*s, ",
  560. (int)sizeof(p->match.name), p->match.name);
  561. else
  562. pr_cont("addr=%u, ", p->match.addr);
  563. pr_cont("reg=0x%llx, val=0x%llx\n",
  564. p->reg, p->val);
  565. }
  566. static void v4l_print_dv_enum_presets(const void *arg, bool write_only)
  567. {
  568. const struct v4l2_dv_enum_preset *p = arg;
  569. pr_cont("index=%u, preset=%u, name=%.*s, width=%u, height=%u\n",
  570. p->index, p->preset,
  571. (int)sizeof(p->name), p->name, p->width, p->height);
  572. }
  573. static void v4l_print_dv_preset(const void *arg, bool write_only)
  574. {
  575. const struct v4l2_dv_preset *p = arg;
  576. pr_cont("preset=%u\n", p->preset);
  577. }
  578. static void v4l_print_dv_timings(const void *arg, bool write_only)
  579. {
  580. const struct v4l2_dv_timings *p = arg;
  581. switch (p->type) {
  582. case V4L2_DV_BT_656_1120:
  583. pr_cont("type=bt-656/1120, interlaced=%u, "
  584. "pixelclock=%llu, "
  585. "width=%u, height=%u, polarities=0x%x, "
  586. "hfrontporch=%u, hsync=%u, "
  587. "hbackporch=%u, vfrontporch=%u, "
  588. "vsync=%u, vbackporch=%u, "
  589. "il_vfrontporch=%u, il_vsync=%u, "
  590. "il_vbackporch=%u, standards=0x%x, flags=0x%x\n",
  591. p->bt.interlaced, p->bt.pixelclock,
  592. p->bt.width, p->bt.height,
  593. p->bt.polarities, p->bt.hfrontporch,
  594. p->bt.hsync, p->bt.hbackporch,
  595. p->bt.vfrontporch, p->bt.vsync,
  596. p->bt.vbackporch, p->bt.il_vfrontporch,
  597. p->bt.il_vsync, p->bt.il_vbackporch,
  598. p->bt.standards, p->bt.flags);
  599. break;
  600. default:
  601. pr_cont("type=%d\n", p->type);
  602. break;
  603. }
  604. }
  605. static void v4l_print_enum_dv_timings(const void *arg, bool write_only)
  606. {
  607. const struct v4l2_enum_dv_timings *p = arg;
  608. pr_cont("index=%u, ", p->index);
  609. v4l_print_dv_timings(&p->timings, write_only);
  610. }
  611. static void v4l_print_dv_timings_cap(const void *arg, bool write_only)
  612. {
  613. const struct v4l2_dv_timings_cap *p = arg;
  614. switch (p->type) {
  615. case V4L2_DV_BT_656_1120:
  616. pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, "
  617. "pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
  618. p->bt.min_width, p->bt.max_width,
  619. p->bt.min_height, p->bt.max_height,
  620. p->bt.min_pixelclock, p->bt.max_pixelclock,
  621. p->bt.standards, p->bt.capabilities);
  622. break;
  623. default:
  624. pr_cont("type=%u\n", p->type);
  625. break;
  626. }
  627. }
  628. static void v4l_print_frmsizeenum(const void *arg, bool write_only)
  629. {
  630. const struct v4l2_frmsizeenum *p = arg;
  631. pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
  632. p->index,
  633. (p->pixel_format & 0xff),
  634. (p->pixel_format >> 8) & 0xff,
  635. (p->pixel_format >> 16) & 0xff,
  636. (p->pixel_format >> 24) & 0xff,
  637. p->type);
  638. switch (p->type) {
  639. case V4L2_FRMSIZE_TYPE_DISCRETE:
  640. pr_cont(" wxh=%ux%u\n",
  641. p->discrete.width, p->discrete.height);
  642. break;
  643. case V4L2_FRMSIZE_TYPE_STEPWISE:
  644. pr_cont(" min=%ux%u, max=%ux%u, step=%ux%u\n",
  645. p->stepwise.min_width, p->stepwise.min_height,
  646. p->stepwise.step_width, p->stepwise.step_height,
  647. p->stepwise.max_width, p->stepwise.max_height);
  648. break;
  649. case V4L2_FRMSIZE_TYPE_CONTINUOUS:
  650. /* fall through */
  651. default:
  652. pr_cont("\n");
  653. break;
  654. }
  655. }
  656. static void v4l_print_frmivalenum(const void *arg, bool write_only)
  657. {
  658. const struct v4l2_frmivalenum *p = arg;
  659. pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
  660. p->index,
  661. (p->pixel_format & 0xff),
  662. (p->pixel_format >> 8) & 0xff,
  663. (p->pixel_format >> 16) & 0xff,
  664. (p->pixel_format >> 24) & 0xff,
  665. p->width, p->height, p->type);
  666. switch (p->type) {
  667. case V4L2_FRMIVAL_TYPE_DISCRETE:
  668. pr_cont(" fps=%d/%d\n",
  669. p->discrete.numerator,
  670. p->discrete.denominator);
  671. break;
  672. case V4L2_FRMIVAL_TYPE_STEPWISE:
  673. pr_cont(" min=%d/%d, max=%d/%d, step=%d/%d\n",
  674. p->stepwise.min.numerator,
  675. p->stepwise.min.denominator,
  676. p->stepwise.max.numerator,
  677. p->stepwise.max.denominator,
  678. p->stepwise.step.numerator,
  679. p->stepwise.step.denominator);
  680. break;
  681. case V4L2_FRMIVAL_TYPE_CONTINUOUS:
  682. /* fall through */
  683. default:
  684. pr_cont("\n");
  685. break;
  686. }
  687. }
  688. static void v4l_print_event(const void *arg, bool write_only)
  689. {
  690. const struct v4l2_event *p = arg;
  691. const struct v4l2_event_ctrl *c;
  692. pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, "
  693. "timestamp=%lu.%9.9lu\n",
  694. p->type, p->pending, p->sequence, p->id,
  695. p->timestamp.tv_sec, p->timestamp.tv_nsec);
  696. switch (p->type) {
  697. case V4L2_EVENT_VSYNC:
  698. printk(KERN_DEBUG "field=%s\n",
  699. prt_names(p->u.vsync.field, v4l2_field_names));
  700. break;
  701. case V4L2_EVENT_CTRL:
  702. c = &p->u.ctrl;
  703. printk(KERN_DEBUG "changes=0x%x, type=%u, ",
  704. c->changes, c->type);
  705. if (c->type == V4L2_CTRL_TYPE_INTEGER64)
  706. pr_cont("value64=%lld, ", c->value64);
  707. else
  708. pr_cont("value=%d, ", c->value);
  709. pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d,"
  710. " default_value=%d\n",
  711. c->flags, c->minimum, c->maximum,
  712. c->step, c->default_value);
  713. break;
  714. case V4L2_EVENT_FRAME_SYNC:
  715. pr_cont("frame_sequence=%u\n",
  716. p->u.frame_sync.frame_sequence);
  717. break;
  718. }
  719. }
  720. static void v4l_print_event_subscription(const void *arg, bool write_only)
  721. {
  722. const struct v4l2_event_subscription *p = arg;
  723. pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
  724. p->type, p->id, p->flags);
  725. }
  726. static void v4l_print_sliced_vbi_cap(const void *arg, bool write_only)
  727. {
  728. const struct v4l2_sliced_vbi_cap *p = arg;
  729. int i;
  730. pr_cont("type=%s, service_set=0x%08x\n",
  731. prt_names(p->type, v4l2_type_names), p->service_set);
  732. for (i = 0; i < 24; i++)
  733. printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
  734. p->service_lines[0][i],
  735. p->service_lines[1][i]);
  736. }
  737. static void v4l_print_freq_band(const void *arg, bool write_only)
  738. {
  739. const struct v4l2_frequency_band *p = arg;
  740. pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, "
  741. "rangelow=%u, rangehigh=%u, modulation=0x%x\n",
  742. p->tuner, p->type, p->index,
  743. p->capability, p->rangelow,
  744. p->rangehigh, p->modulation);
  745. }
  746. static void v4l_print_u32(const void *arg, bool write_only)
  747. {
  748. pr_cont("value=%u\n", *(const u32 *)arg);
  749. }
  750. static void v4l_print_newline(const void *arg, bool write_only)
  751. {
  752. pr_cont("\n");
  753. }
  754. static void v4l_print_default(const void *arg, bool write_only)
  755. {
  756. pr_cont("driver-specific ioctl\n");
  757. }
  758. static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
  759. {
  760. __u32 i;
  761. /* zero the reserved fields */
  762. c->reserved[0] = c->reserved[1] = 0;
  763. for (i = 0; i < c->count; i++)
  764. c->controls[i].reserved2[0] = 0;
  765. /* V4L2_CID_PRIVATE_BASE cannot be used as control class
  766. when using extended controls.
  767. Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
  768. is it allowed for backwards compatibility.
  769. */
  770. if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
  771. return 0;
  772. /* Check that all controls are from the same control class. */
  773. for (i = 0; i < c->count; i++) {
  774. if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
  775. c->error_idx = i;
  776. return 0;
  777. }
  778. }
  779. return 1;
  780. }
  781. static int check_fmt(struct file *file, enum v4l2_buf_type type)
  782. {
  783. struct video_device *vfd = video_devdata(file);
  784. const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
  785. bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
  786. bool is_vbi = vfd->vfl_type == VFL_TYPE_VBI;
  787. bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
  788. bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
  789. if (ops == NULL)
  790. return -EINVAL;
  791. switch (type) {
  792. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  793. if (is_vid && is_rx &&
  794. (ops->vidioc_g_fmt_vid_cap || ops->vidioc_g_fmt_vid_cap_mplane))
  795. return 0;
  796. break;
  797. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  798. if (is_vid && is_rx && ops->vidioc_g_fmt_vid_cap_mplane)
  799. return 0;
  800. break;
  801. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  802. if (is_vid && is_rx && ops->vidioc_g_fmt_vid_overlay)
  803. return 0;
  804. break;
  805. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  806. if (is_vid && is_tx &&
  807. (ops->vidioc_g_fmt_vid_out || ops->vidioc_g_fmt_vid_out_mplane))
  808. return 0;
  809. break;
  810. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  811. if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_mplane)
  812. return 0;
  813. break;
  814. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  815. if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_overlay)
  816. return 0;
  817. break;
  818. case V4L2_BUF_TYPE_VBI_CAPTURE:
  819. if (is_vbi && is_rx && ops->vidioc_g_fmt_vbi_cap)
  820. return 0;
  821. break;
  822. case V4L2_BUF_TYPE_VBI_OUTPUT:
  823. if (is_vbi && is_tx && ops->vidioc_g_fmt_vbi_out)
  824. return 0;
  825. break;
  826. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  827. if (is_vbi && is_rx && ops->vidioc_g_fmt_sliced_vbi_cap)
  828. return 0;
  829. break;
  830. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  831. if (is_vbi && is_tx && ops->vidioc_g_fmt_sliced_vbi_out)
  832. return 0;
  833. break;
  834. default:
  835. break;
  836. }
  837. return -EINVAL;
  838. }
  839. static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
  840. struct file *file, void *fh, void *arg)
  841. {
  842. struct v4l2_capability *cap = (struct v4l2_capability *)arg;
  843. cap->version = LINUX_VERSION_CODE;
  844. return ops->vidioc_querycap(file, fh, cap);
  845. }
  846. static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
  847. struct file *file, void *fh, void *arg)
  848. {
  849. return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
  850. }
  851. static int v4l_s_output(const struct v4l2_ioctl_ops *ops,
  852. struct file *file, void *fh, void *arg)
  853. {
  854. return ops->vidioc_s_output(file, fh, *(unsigned int *)arg);
  855. }
  856. static int v4l_g_priority(const struct v4l2_ioctl_ops *ops,
  857. struct file *file, void *fh, void *arg)
  858. {
  859. struct video_device *vfd;
  860. u32 *p = arg;
  861. if (ops->vidioc_g_priority)
  862. return ops->vidioc_g_priority(file, fh, arg);
  863. vfd = video_devdata(file);
  864. *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
  865. return 0;
  866. }
  867. static int v4l_s_priority(const struct v4l2_ioctl_ops *ops,
  868. struct file *file, void *fh, void *arg)
  869. {
  870. struct video_device *vfd;
  871. struct v4l2_fh *vfh;
  872. u32 *p = arg;
  873. if (ops->vidioc_s_priority)
  874. return ops->vidioc_s_priority(file, fh, *p);
  875. vfd = video_devdata(file);
  876. vfh = file->private_data;
  877. return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
  878. }
  879. static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
  880. struct file *file, void *fh, void *arg)
  881. {
  882. struct video_device *vfd = video_devdata(file);
  883. struct v4l2_input *p = arg;
  884. /*
  885. * We set the flags for CAP_PRESETS, CAP_DV_TIMINGS &
  886. * CAP_STD here based on ioctl handler provided by the
  887. * driver. If the driver doesn't support these
  888. * for a specific input, it must override these flags.
  889. */
  890. if (is_valid_ioctl(vfd, VIDIOC_S_STD))
  891. p->capabilities |= V4L2_IN_CAP_STD;
  892. if (is_valid_ioctl(vfd, VIDIOC_S_DV_PRESET))
  893. p->capabilities |= V4L2_IN_CAP_PRESETS;
  894. if (is_valid_ioctl(vfd, VIDIOC_S_DV_TIMINGS))
  895. p->capabilities |= V4L2_IN_CAP_DV_TIMINGS;
  896. return ops->vidioc_enum_input(file, fh, p);
  897. }
  898. static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
  899. struct file *file, void *fh, void *arg)
  900. {
  901. struct video_device *vfd = video_devdata(file);
  902. struct v4l2_output *p = arg;
  903. /*
  904. * We set the flags for CAP_PRESETS, CAP_DV_TIMINGS &
  905. * CAP_STD here based on ioctl handler provided by the
  906. * driver. If the driver doesn't support these
  907. * for a specific output, it must override these flags.
  908. */
  909. if (is_valid_ioctl(vfd, VIDIOC_S_STD))
  910. p->capabilities |= V4L2_OUT_CAP_STD;
  911. if (is_valid_ioctl(vfd, VIDIOC_S_DV_PRESET))
  912. p->capabilities |= V4L2_OUT_CAP_PRESETS;
  913. if (is_valid_ioctl(vfd, VIDIOC_S_DV_TIMINGS))
  914. p->capabilities |= V4L2_OUT_CAP_DV_TIMINGS;
  915. return ops->vidioc_enum_output(file, fh, p);
  916. }
  917. static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
  918. struct file *file, void *fh, void *arg)
  919. {
  920. struct v4l2_fmtdesc *p = arg;
  921. struct video_device *vfd = video_devdata(file);
  922. bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
  923. bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
  924. switch (p->type) {
  925. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  926. if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_cap))
  927. break;
  928. return ops->vidioc_enum_fmt_vid_cap(file, fh, arg);
  929. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  930. if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_cap_mplane))
  931. break;
  932. return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg);
  933. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  934. if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_overlay))
  935. break;
  936. return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg);
  937. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  938. if (unlikely(!is_tx || !ops->vidioc_enum_fmt_vid_out))
  939. break;
  940. return ops->vidioc_enum_fmt_vid_out(file, fh, arg);
  941. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  942. if (unlikely(!is_tx || !ops->vidioc_enum_fmt_vid_out_mplane))
  943. break;
  944. return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg);
  945. }
  946. return -EINVAL;
  947. }
  948. static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
  949. struct file *file, void *fh, void *arg)
  950. {
  951. struct v4l2_format *p = arg;
  952. struct video_device *vfd = video_devdata(file);
  953. bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
  954. bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
  955. bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
  956. switch (p->type) {
  957. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  958. if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap))
  959. break;
  960. return ops->vidioc_g_fmt_vid_cap(file, fh, arg);
  961. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  962. if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap_mplane))
  963. break;
  964. return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
  965. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  966. if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_overlay))
  967. break;
  968. return ops->vidioc_g_fmt_vid_overlay(file, fh, arg);
  969. case V4L2_BUF_TYPE_VBI_CAPTURE:
  970. if (unlikely(!is_rx || is_vid || !ops->vidioc_g_fmt_vbi_cap))
  971. break;
  972. return ops->vidioc_g_fmt_vbi_cap(file, fh, arg);
  973. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  974. if (unlikely(!is_rx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_cap))
  975. break;
  976. return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg);
  977. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  978. if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out))
  979. break;
  980. return ops->vidioc_g_fmt_vid_out(file, fh, arg);
  981. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  982. if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_mplane))
  983. break;
  984. return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg);
  985. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  986. if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_overlay))
  987. break;
  988. return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg);
  989. case V4L2_BUF_TYPE_VBI_OUTPUT:
  990. if (unlikely(!is_tx || is_vid || !ops->vidioc_g_fmt_vbi_out))
  991. break;
  992. return ops->vidioc_g_fmt_vbi_out(file, fh, arg);
  993. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  994. if (unlikely(!is_tx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_out))
  995. break;
  996. return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg);
  997. }
  998. return -EINVAL;
  999. }
  1000. static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
  1001. struct file *file, void *fh, void *arg)
  1002. {
  1003. struct v4l2_format *p = arg;
  1004. struct video_device *vfd = video_devdata(file);
  1005. bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
  1006. bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
  1007. bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
  1008. switch (p->type) {
  1009. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  1010. if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap))
  1011. break;
  1012. CLEAR_AFTER_FIELD(p, fmt.pix);
  1013. return ops->vidioc_s_fmt_vid_cap(file, fh, arg);
  1014. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  1015. if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap_mplane))
  1016. break;
  1017. CLEAR_AFTER_FIELD(p, fmt.pix_mp);
  1018. return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
  1019. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  1020. if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_overlay))
  1021. break;
  1022. CLEAR_AFTER_FIELD(p, fmt.win);
  1023. return ops->vidioc_s_fmt_vid_overlay(file, fh, arg);
  1024. case V4L2_BUF_TYPE_VBI_CAPTURE:
  1025. if (unlikely(!is_rx || is_vid || !ops->vidioc_s_fmt_vbi_cap))
  1026. break;
  1027. CLEAR_AFTER_FIELD(p, fmt.vbi);
  1028. return ops->vidioc_s_fmt_vbi_cap(file, fh, arg);
  1029. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  1030. if (unlikely(!is_rx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_cap))
  1031. break;
  1032. CLEAR_AFTER_FIELD(p, fmt.sliced);
  1033. return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg);
  1034. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  1035. if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out))
  1036. break;
  1037. CLEAR_AFTER_FIELD(p, fmt.pix);
  1038. return ops->vidioc_s_fmt_vid_out(file, fh, arg);
  1039. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  1040. if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_mplane))
  1041. break;
  1042. CLEAR_AFTER_FIELD(p, fmt.pix_mp);
  1043. return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
  1044. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  1045. if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_overlay))
  1046. break;
  1047. CLEAR_AFTER_FIELD(p, fmt.win);
  1048. return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg);
  1049. case V4L2_BUF_TYPE_VBI_OUTPUT:
  1050. if (unlikely(!is_tx || is_vid || !ops->vidioc_s_fmt_vbi_out))
  1051. break;
  1052. CLEAR_AFTER_FIELD(p, fmt.vbi);
  1053. return ops->vidioc_s_fmt_vbi_out(file, fh, arg);
  1054. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  1055. if (unlikely(!is_tx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_out))
  1056. break;
  1057. CLEAR_AFTER_FIELD(p, fmt.sliced);
  1058. return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg);
  1059. }
  1060. return -EINVAL;
  1061. }
  1062. static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
  1063. struct file *file, void *fh, void *arg)
  1064. {
  1065. struct v4l2_format *p = arg;
  1066. struct video_device *vfd = video_devdata(file);
  1067. bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
  1068. bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
  1069. bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
  1070. switch (p->type) {
  1071. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  1072. if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap))
  1073. break;
  1074. CLEAR_AFTER_FIELD(p, fmt.pix);
  1075. return ops->vidioc_try_fmt_vid_cap(file, fh, arg);
  1076. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  1077. if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap_mplane))
  1078. break;
  1079. CLEAR_AFTER_FIELD(p, fmt.pix_mp);
  1080. return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg);
  1081. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  1082. if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_overlay))
  1083. break;
  1084. CLEAR_AFTER_FIELD(p, fmt.win);
  1085. return ops->vidioc_try_fmt_vid_overlay(file, fh, arg);
  1086. case V4L2_BUF_TYPE_VBI_CAPTURE:
  1087. if (unlikely(!is_rx || is_vid || !ops->vidioc_try_fmt_vbi_cap))
  1088. break;
  1089. CLEAR_AFTER_FIELD(p, fmt.vbi);
  1090. return ops->vidioc_try_fmt_vbi_cap(file, fh, arg);
  1091. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  1092. if (unlikely(!is_rx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_cap))
  1093. break;
  1094. CLEAR_AFTER_FIELD(p, fmt.sliced);
  1095. return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg);
  1096. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  1097. if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out))
  1098. break;
  1099. CLEAR_AFTER_FIELD(p, fmt.pix);
  1100. return ops->vidioc_try_fmt_vid_out(file, fh, arg);
  1101. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  1102. if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_mplane))
  1103. break;
  1104. CLEAR_AFTER_FIELD(p, fmt.pix_mp);
  1105. return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg);
  1106. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  1107. if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_overlay))
  1108. break;
  1109. CLEAR_AFTER_FIELD(p, fmt.win);
  1110. return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg);
  1111. case V4L2_BUF_TYPE_VBI_OUTPUT:
  1112. if (unlikely(!is_tx || is_vid || !ops->vidioc_try_fmt_vbi_out))
  1113. break;
  1114. CLEAR_AFTER_FIELD(p, fmt.vbi);
  1115. return ops->vidioc_try_fmt_vbi_out(file, fh, arg);
  1116. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  1117. if (unlikely(!is_tx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_out))
  1118. break;
  1119. CLEAR_AFTER_FIELD(p, fmt.sliced);
  1120. return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg);
  1121. }
  1122. return -EINVAL;
  1123. }
  1124. static int v4l_streamon(const struct v4l2_ioctl_ops *ops,
  1125. struct file *file, void *fh, void *arg)
  1126. {
  1127. return ops->vidioc_streamon(file, fh, *(unsigned int *)arg);
  1128. }
  1129. static int v4l_streamoff(const struct v4l2_ioctl_ops *ops,
  1130. struct file *file, void *fh, void *arg)
  1131. {
  1132. return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg);
  1133. }
  1134. static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops,
  1135. struct file *file, void *fh, void *arg)
  1136. {
  1137. struct video_device *vfd = video_devdata(file);
  1138. struct v4l2_tuner *p = arg;
  1139. int err;
  1140. p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1141. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1142. err = ops->vidioc_g_tuner(file, fh, p);
  1143. if (!err)
  1144. p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
  1145. return err;
  1146. }
  1147. static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
  1148. struct file *file, void *fh, void *arg)
  1149. {
  1150. struct video_device *vfd = video_devdata(file);
  1151. struct v4l2_tuner *p = arg;
  1152. p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1153. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1154. return ops->vidioc_s_tuner(file, fh, p);
  1155. }
  1156. static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
  1157. struct file *file, void *fh, void *arg)
  1158. {
  1159. struct v4l2_modulator *p = arg;
  1160. int err;
  1161. err = ops->vidioc_g_modulator(file, fh, p);
  1162. if (!err)
  1163. p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
  1164. return err;
  1165. }
  1166. static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
  1167. struct file *file, void *fh, void *arg)
  1168. {
  1169. struct video_device *vfd = video_devdata(file);
  1170. struct v4l2_frequency *p = arg;
  1171. p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1172. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1173. return ops->vidioc_g_frequency(file, fh, p);
  1174. }
  1175. static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
  1176. struct file *file, void *fh, void *arg)
  1177. {
  1178. struct video_device *vfd = video_devdata(file);
  1179. const struct v4l2_frequency *p = arg;
  1180. enum v4l2_tuner_type type;
  1181. type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1182. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1183. if (p->type != type)
  1184. return -EINVAL;
  1185. return ops->vidioc_s_frequency(file, fh, p);
  1186. }
  1187. static int v4l_enumstd(const struct v4l2_ioctl_ops *ops,
  1188. struct file *file, void *fh, void *arg)
  1189. {
  1190. struct video_device *vfd = video_devdata(file);
  1191. struct v4l2_standard *p = arg;
  1192. v4l2_std_id id = vfd->tvnorms, curr_id = 0;
  1193. unsigned int index = p->index, i, j = 0;
  1194. const char *descr = "";
  1195. /* Return -ENODATA if the tvnorms for the current input
  1196. or output is 0, meaning that it doesn't support this API. */
  1197. if (id == 0)
  1198. return -ENODATA;
  1199. /* Return norm array in a canonical way */
  1200. for (i = 0; i <= index && id; i++) {
  1201. /* last std value in the standards array is 0, so this
  1202. while always ends there since (id & 0) == 0. */
  1203. while ((id & standards[j].std) != standards[j].std)
  1204. j++;
  1205. curr_id = standards[j].std;
  1206. descr = standards[j].descr;
  1207. j++;
  1208. if (curr_id == 0)
  1209. break;
  1210. if (curr_id != V4L2_STD_PAL &&
  1211. curr_id != V4L2_STD_SECAM &&
  1212. curr_id != V4L2_STD_NTSC)
  1213. id &= ~curr_id;
  1214. }
  1215. if (i <= index)
  1216. return -EINVAL;
  1217. v4l2_video_std_construct(p, curr_id, descr);
  1218. return 0;
  1219. }
  1220. static int v4l_g_std(const struct v4l2_ioctl_ops *ops,
  1221. struct file *file, void *fh, void *arg)
  1222. {
  1223. struct video_device *vfd = video_devdata(file);
  1224. v4l2_std_id *id = arg;
  1225. /* Calls the specific handler */
  1226. if (ops->vidioc_g_std)
  1227. return ops->vidioc_g_std(file, fh, arg);
  1228. if (vfd->current_norm) {
  1229. *id = vfd->current_norm;
  1230. return 0;
  1231. }
  1232. return -ENOTTY;
  1233. }
  1234. static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
  1235. struct file *file, void *fh, void *arg)
  1236. {
  1237. struct video_device *vfd = video_devdata(file);
  1238. v4l2_std_id id = *(v4l2_std_id *)arg, norm;
  1239. int ret;
  1240. norm = id & vfd->tvnorms;
  1241. if (vfd->tvnorms && !norm) /* Check if std is supported */
  1242. return -EINVAL;
  1243. /* Calls the specific handler */
  1244. ret = ops->vidioc_s_std(file, fh, norm);
  1245. /* Updates standard information */
  1246. if (ret >= 0)
  1247. vfd->current_norm = norm;
  1248. return ret;
  1249. }
  1250. static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
  1251. struct file *file, void *fh, void *arg)
  1252. {
  1253. struct video_device *vfd = video_devdata(file);
  1254. v4l2_std_id *p = arg;
  1255. /*
  1256. * If nothing detected, it should return all supported
  1257. * standard.
  1258. * Drivers just need to mask the std argument, in order
  1259. * to remove the standards that don't apply from the mask.
  1260. * This means that tuners, audio and video decoders can join
  1261. * their efforts to improve the standards detection.
  1262. */
  1263. *p = vfd->tvnorms;
  1264. return ops->vidioc_querystd(file, fh, arg);
  1265. }
  1266. static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
  1267. struct file *file, void *fh, void *arg)
  1268. {
  1269. struct video_device *vfd = video_devdata(file);
  1270. struct v4l2_hw_freq_seek *p = arg;
  1271. enum v4l2_tuner_type type;
  1272. type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1273. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1274. if (p->type != type)
  1275. return -EINVAL;
  1276. return ops->vidioc_s_hw_freq_seek(file, fh, p);
  1277. }
  1278. static int v4l_overlay(const struct v4l2_ioctl_ops *ops,
  1279. struct file *file, void *fh, void *arg)
  1280. {
  1281. return ops->vidioc_overlay(file, fh, *(unsigned int *)arg);
  1282. }
  1283. static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops,
  1284. struct file *file, void *fh, void *arg)
  1285. {
  1286. struct v4l2_requestbuffers *p = arg;
  1287. int ret = check_fmt(file, p->type);
  1288. if (ret)
  1289. return ret;
  1290. CLEAR_AFTER_FIELD(p, memory);
  1291. return ops->vidioc_reqbufs(file, fh, p);
  1292. }
  1293. static int v4l_querybuf(const struct v4l2_ioctl_ops *ops,
  1294. struct file *file, void *fh, void *arg)
  1295. {
  1296. struct v4l2_buffer *p = arg;
  1297. int ret = check_fmt(file, p->type);
  1298. return ret ? ret : ops->vidioc_querybuf(file, fh, p);
  1299. }
  1300. static int v4l_qbuf(const struct v4l2_ioctl_ops *ops,
  1301. struct file *file, void *fh, void *arg)
  1302. {
  1303. struct v4l2_buffer *p = arg;
  1304. int ret = check_fmt(file, p->type);
  1305. return ret ? ret : ops->vidioc_qbuf(file, fh, p);
  1306. }
  1307. static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops,
  1308. struct file *file, void *fh, void *arg)
  1309. {
  1310. struct v4l2_buffer *p = arg;
  1311. int ret = check_fmt(file, p->type);
  1312. return ret ? ret : ops->vidioc_dqbuf(file, fh, p);
  1313. }
  1314. static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
  1315. struct file *file, void *fh, void *arg)
  1316. {
  1317. struct v4l2_create_buffers *create = arg;
  1318. int ret = check_fmt(file, create->format.type);
  1319. return ret ? ret : ops->vidioc_create_bufs(file, fh, create);
  1320. }
  1321. static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
  1322. struct file *file, void *fh, void *arg)
  1323. {
  1324. struct v4l2_buffer *b = arg;
  1325. int ret = check_fmt(file, b->type);
  1326. return ret ? ret : ops->vidioc_prepare_buf(file, fh, b);
  1327. }
  1328. static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
  1329. struct file *file, void *fh, void *arg)
  1330. {
  1331. struct video_device *vfd = video_devdata(file);
  1332. struct v4l2_streamparm *p = arg;
  1333. v4l2_std_id std;
  1334. int ret = check_fmt(file, p->type);
  1335. if (ret)
  1336. return ret;
  1337. if (ops->vidioc_g_parm)
  1338. return ops->vidioc_g_parm(file, fh, p);
  1339. std = vfd->current_norm;
  1340. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
  1341. p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  1342. return -EINVAL;
  1343. p->parm.capture.readbuffers = 2;
  1344. if (is_valid_ioctl(vfd, VIDIOC_G_STD) && ops->vidioc_g_std)
  1345. ret = ops->vidioc_g_std(file, fh, &std);
  1346. if (ret == 0)
  1347. v4l2_video_std_frame_period(std,
  1348. &p->parm.capture.timeperframe);
  1349. return ret;
  1350. }
  1351. static int v4l_s_parm(const struct v4l2_ioctl_ops *ops,
  1352. struct file *file, void *fh, void *arg)
  1353. {
  1354. struct v4l2_streamparm *p = arg;
  1355. int ret = check_fmt(file, p->type);
  1356. return ret ? ret : ops->vidioc_s_parm(file, fh, p);
  1357. }
  1358. static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
  1359. struct file *file, void *fh, void *arg)
  1360. {
  1361. struct video_device *vfd = video_devdata(file);
  1362. struct v4l2_queryctrl *p = arg;
  1363. struct v4l2_fh *vfh =
  1364. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1365. if (vfh && vfh->ctrl_handler)
  1366. return v4l2_queryctrl(vfh->ctrl_handler, p);
  1367. if (vfd->ctrl_handler)
  1368. return v4l2_queryctrl(vfd->ctrl_handler, p);
  1369. if (ops->vidioc_queryctrl)
  1370. return ops->vidioc_queryctrl(file, fh, p);
  1371. return -ENOTTY;
  1372. }
  1373. static int v4l_querymenu(const struct v4l2_ioctl_ops *ops,
  1374. struct file *file, void *fh, void *arg)
  1375. {
  1376. struct video_device *vfd = video_devdata(file);
  1377. struct v4l2_querymenu *p = arg;
  1378. struct v4l2_fh *vfh =
  1379. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1380. if (vfh && vfh->ctrl_handler)
  1381. return v4l2_querymenu(vfh->ctrl_handler, p);
  1382. if (vfd->ctrl_handler)
  1383. return v4l2_querymenu(vfd->ctrl_handler, p);
  1384. if (ops->vidioc_querymenu)
  1385. return ops->vidioc_querymenu(file, fh, p);
  1386. return -ENOTTY;
  1387. }
  1388. static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
  1389. struct file *file, void *fh, void *arg)
  1390. {
  1391. struct video_device *vfd = video_devdata(file);
  1392. struct v4l2_control *p = arg;
  1393. struct v4l2_fh *vfh =
  1394. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1395. struct v4l2_ext_controls ctrls;
  1396. struct v4l2_ext_control ctrl;
  1397. if (vfh && vfh->ctrl_handler)
  1398. return v4l2_g_ctrl(vfh->ctrl_handler, p);
  1399. if (vfd->ctrl_handler)
  1400. return v4l2_g_ctrl(vfd->ctrl_handler, p);
  1401. if (ops->vidioc_g_ctrl)
  1402. return ops->vidioc_g_ctrl(file, fh, p);
  1403. if (ops->vidioc_g_ext_ctrls == NULL)
  1404. return -ENOTTY;
  1405. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1406. ctrls.count = 1;
  1407. ctrls.controls = &ctrl;
  1408. ctrl.id = p->id;
  1409. ctrl.value = p->value;
  1410. if (check_ext_ctrls(&ctrls, 1)) {
  1411. int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
  1412. if (ret == 0)
  1413. p->value = ctrl.value;
  1414. return ret;
  1415. }
  1416. return -EINVAL;
  1417. }
  1418. static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
  1419. struct file *file, void *fh, void *arg)
  1420. {
  1421. struct video_device *vfd = video_devdata(file);
  1422. struct v4l2_control *p = arg;
  1423. struct v4l2_fh *vfh =
  1424. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1425. struct v4l2_ext_controls ctrls;
  1426. struct v4l2_ext_control ctrl;
  1427. if (vfh && vfh->ctrl_handler)
  1428. return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
  1429. if (vfd->ctrl_handler)
  1430. return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
  1431. if (ops->vidioc_s_ctrl)
  1432. return ops->vidioc_s_ctrl(file, fh, p);
  1433. if (ops->vidioc_s_ext_ctrls == NULL)
  1434. return -ENOTTY;
  1435. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1436. ctrls.count = 1;
  1437. ctrls.controls = &ctrl;
  1438. ctrl.id = p->id;
  1439. ctrl.value = p->value;
  1440. if (check_ext_ctrls(&ctrls, 1))
  1441. return ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
  1442. return -EINVAL;
  1443. }
  1444. static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
  1445. struct file *file, void *fh, void *arg)
  1446. {
  1447. struct video_device *vfd = video_devdata(file);
  1448. struct v4l2_ext_controls *p = arg;
  1449. struct v4l2_fh *vfh =
  1450. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1451. p->error_idx = p->count;
  1452. if (vfh && vfh->ctrl_handler)
  1453. return v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
  1454. if (vfd->ctrl_handler)
  1455. return v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
  1456. if (ops->vidioc_g_ext_ctrls == NULL)
  1457. return -ENOTTY;
  1458. return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
  1459. -EINVAL;
  1460. }
  1461. static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
  1462. struct file *file, void *fh, void *arg)
  1463. {
  1464. struct video_device *vfd = video_devdata(file);
  1465. struct v4l2_ext_controls *p = arg;
  1466. struct v4l2_fh *vfh =
  1467. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1468. p->error_idx = p->count;
  1469. if (vfh && vfh->ctrl_handler)
  1470. return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
  1471. if (vfd->ctrl_handler)
  1472. return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
  1473. if (ops->vidioc_s_ext_ctrls == NULL)
  1474. return -ENOTTY;
  1475. return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
  1476. -EINVAL;
  1477. }
  1478. static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
  1479. struct file *file, void *fh, void *arg)
  1480. {
  1481. struct video_device *vfd = video_devdata(file);
  1482. struct v4l2_ext_controls *p = arg;
  1483. struct v4l2_fh *vfh =
  1484. test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
  1485. p->error_idx = p->count;
  1486. if (vfh && vfh->ctrl_handler)
  1487. return v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
  1488. if (vfd->ctrl_handler)
  1489. return v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
  1490. if (ops->vidioc_try_ext_ctrls == NULL)
  1491. return -ENOTTY;
  1492. return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
  1493. -EINVAL;
  1494. }
  1495. static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
  1496. struct file *file, void *fh, void *arg)
  1497. {
  1498. struct v4l2_crop *p = arg;
  1499. struct v4l2_selection s = {
  1500. .type = p->type,
  1501. };
  1502. int ret;
  1503. if (ops->vidioc_g_crop)
  1504. return ops->vidioc_g_crop(file, fh, p);
  1505. /* simulate capture crop using selection api */
  1506. /* crop means compose for output devices */
  1507. if (V4L2_TYPE_IS_OUTPUT(p->type))
  1508. s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
  1509. else
  1510. s.target = V4L2_SEL_TGT_CROP_ACTIVE;
  1511. ret = ops->vidioc_g_selection(file, fh, &s);
  1512. /* copying results to old structure on success */
  1513. if (!ret)
  1514. p->c = s.r;
  1515. return ret;
  1516. }
  1517. static int v4l_s_crop(const struct v4l2_ioctl_ops *ops,
  1518. struct file *file, void *fh, void *arg)
  1519. {
  1520. struct v4l2_crop *p = arg;
  1521. struct v4l2_selection s = {
  1522. .type = p->type,
  1523. .r = p->c,
  1524. };
  1525. if (ops->vidioc_s_crop)
  1526. return ops->vidioc_s_crop(file, fh, p);
  1527. /* simulate capture crop using selection api */
  1528. /* crop means compose for output devices */
  1529. if (V4L2_TYPE_IS_OUTPUT(p->type))
  1530. s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
  1531. else
  1532. s.target = V4L2_SEL_TGT_CROP_ACTIVE;
  1533. return ops->vidioc_s_selection(file, fh, &s);
  1534. }
  1535. static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
  1536. struct file *file, void *fh, void *arg)
  1537. {
  1538. struct v4l2_cropcap *p = arg;
  1539. struct v4l2_selection s = { .type = p->type };
  1540. int ret;
  1541. if (ops->vidioc_cropcap)
  1542. return ops->vidioc_cropcap(file, fh, p);
  1543. /* obtaining bounds */
  1544. if (V4L2_TYPE_IS_OUTPUT(p->type))
  1545. s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
  1546. else
  1547. s.target = V4L2_SEL_TGT_CROP_BOUNDS;
  1548. ret = ops->vidioc_g_selection(file, fh, &s);
  1549. if (ret)
  1550. return ret;
  1551. p->bounds = s.r;
  1552. /* obtaining defrect */
  1553. if (V4L2_TYPE_IS_OUTPUT(p->type))
  1554. s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
  1555. else
  1556. s.target = V4L2_SEL_TGT_CROP_DEFAULT;
  1557. ret = ops->vidioc_g_selection(file, fh, &s);
  1558. if (ret)
  1559. return ret;
  1560. p->defrect = s.r;
  1561. /* setting trivial pixelaspect */
  1562. p->pixelaspect.numerator = 1;
  1563. p->pixelaspect.denominator = 1;
  1564. return 0;
  1565. }
  1566. static int v4l_log_status(const struct v4l2_ioctl_ops *ops,
  1567. struct file *file, void *fh, void *arg)
  1568. {
  1569. struct video_device *vfd = video_devdata(file);
  1570. int ret;
  1571. if (vfd->v4l2_dev)
  1572. pr_info("%s: ================= START STATUS =================\n",
  1573. vfd->v4l2_dev->name);
  1574. ret = ops->vidioc_log_status(file, fh);
  1575. if (vfd->v4l2_dev)
  1576. pr_info("%s: ================== END STATUS ==================\n",
  1577. vfd->v4l2_dev->name);
  1578. return ret;
  1579. }
  1580. static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
  1581. struct file *file, void *fh, void *arg)
  1582. {
  1583. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1584. struct v4l2_dbg_register *p = arg;
  1585. if (!capable(CAP_SYS_ADMIN))
  1586. return -EPERM;
  1587. return ops->vidioc_g_register(file, fh, p);
  1588. #else
  1589. return -ENOTTY;
  1590. #endif
  1591. }
  1592. static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
  1593. struct file *file, void *fh, void *arg)
  1594. {
  1595. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1596. const struct v4l2_dbg_register *p = arg;
  1597. if (!capable(CAP_SYS_ADMIN))
  1598. return -EPERM;
  1599. return ops->vidioc_s_register(file, fh, p);
  1600. #else
  1601. return -ENOTTY;
  1602. #endif
  1603. }
  1604. static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops,
  1605. struct file *file, void *fh, void *arg)
  1606. {
  1607. struct v4l2_dbg_chip_ident *p = arg;
  1608. p->ident = V4L2_IDENT_NONE;
  1609. p->revision = 0;
  1610. return ops->vidioc_g_chip_ident(file, fh, p);
  1611. }
  1612. static int v4l_dqevent(const struct v4l2_ioctl_ops *ops,
  1613. struct file *file, void *fh, void *arg)
  1614. {
  1615. return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK);
  1616. }
  1617. static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
  1618. struct file *file, void *fh, void *arg)
  1619. {
  1620. return ops->vidioc_subscribe_event(fh, arg);
  1621. }
  1622. static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
  1623. struct file *file, void *fh, void *arg)
  1624. {
  1625. return ops->vidioc_unsubscribe_event(fh, arg);
  1626. }
  1627. static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
  1628. struct file *file, void *fh, void *arg)
  1629. {
  1630. struct v4l2_sliced_vbi_cap *p = arg;
  1631. int ret = check_fmt(file, p->type);
  1632. if (ret)
  1633. return ret;
  1634. /* Clear up to type, everything after type is zeroed already */
  1635. memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
  1636. return ops->vidioc_g_sliced_vbi_cap(file, fh, p);
  1637. }
  1638. static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
  1639. struct file *file, void *fh, void *arg)
  1640. {
  1641. struct video_device *vfd = video_devdata(file);
  1642. struct v4l2_frequency_band *p = arg;
  1643. enum v4l2_tuner_type type;
  1644. int err;
  1645. type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1646. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1647. if (type != p->type)
  1648. return -EINVAL;
  1649. if (ops->vidioc_enum_freq_bands)
  1650. return ops->vidioc_enum_freq_bands(file, fh, p);
  1651. if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) {
  1652. struct v4l2_tuner t = {
  1653. .index = p->tuner,
  1654. .type = type,
  1655. };
  1656. if (p->index)
  1657. return -EINVAL;
  1658. err = ops->vidioc_g_tuner(file, fh, &t);
  1659. if (err)
  1660. return err;
  1661. p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS;
  1662. p->rangelow = t.rangelow;
  1663. p->rangehigh = t.rangehigh;
  1664. p->modulation = (type == V4L2_TUNER_RADIO) ?
  1665. V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB;
  1666. return 0;
  1667. }
  1668. if (is_valid_ioctl(vfd, VIDIOC_G_MODULATOR)) {
  1669. struct v4l2_modulator m = {
  1670. .index = p->tuner,
  1671. };
  1672. if (type != V4L2_TUNER_RADIO)
  1673. return -EINVAL;
  1674. if (p->index)
  1675. return -EINVAL;
  1676. err = ops->vidioc_g_modulator(file, fh, &m);
  1677. if (err)
  1678. return err;
  1679. p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS;
  1680. p->rangelow = m.rangelow;
  1681. p->rangehigh = m.rangehigh;
  1682. p->modulation = (type == V4L2_TUNER_RADIO) ?
  1683. V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB;
  1684. return 0;
  1685. }
  1686. return -ENOTTY;
  1687. }
  1688. struct v4l2_ioctl_info {
  1689. unsigned int ioctl;
  1690. u32 flags;
  1691. const char * const name;
  1692. union {
  1693. u32 offset;
  1694. int (*func)(const struct v4l2_ioctl_ops *ops,
  1695. struct file *file, void *fh, void *p);
  1696. } u;
  1697. void (*debug)(const void *arg, bool write_only);
  1698. };
  1699. /* This control needs a priority check */
  1700. #define INFO_FL_PRIO (1 << 0)
  1701. /* This control can be valid if the filehandle passes a control handler. */
  1702. #define INFO_FL_CTRL (1 << 1)
  1703. /* This is a standard ioctl, no need for special code */
  1704. #define INFO_FL_STD (1 << 2)
  1705. /* This is ioctl has its own function */
  1706. #define INFO_FL_FUNC (1 << 3)
  1707. /* Queuing ioctl */
  1708. #define INFO_FL_QUEUE (1 << 4)
  1709. /* Zero struct from after the field to the end */
  1710. #define INFO_FL_CLEAR(v4l2_struct, field) \
  1711. ((offsetof(struct v4l2_struct, field) + \
  1712. sizeof(((struct v4l2_struct *)0)->field)) << 16)
  1713. #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
  1714. #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
  1715. [_IOC_NR(_ioctl)] = { \
  1716. .ioctl = _ioctl, \
  1717. .flags = _flags | INFO_FL_STD, \
  1718. .name = #_ioctl, \
  1719. .u.offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
  1720. .debug = _debug, \
  1721. }
  1722. #define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
  1723. [_IOC_NR(_ioctl)] = { \
  1724. .ioctl = _ioctl, \
  1725. .flags = _flags | INFO_FL_FUNC, \
  1726. .name = #_ioctl, \
  1727. .u.func = _func, \
  1728. .debug = _debug, \
  1729. }
  1730. static struct v4l2_ioctl_info v4l2_ioctls[] = {
  1731. IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
  1732. IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
  1733. IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
  1734. IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
  1735. IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
  1736. IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)),
  1737. IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
  1738. IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
  1739. IOCTL_INFO_FNC(VIDIOC_OVERLAY, v4l_overlay, v4l_print_u32, INFO_FL_PRIO),
  1740. IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE),
  1741. IOCTL_INFO_STD(VIDIOC_EXPBUF, vidioc_expbuf, v4l_print_exportbuffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_exportbuffer, flags)),
  1742. IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE),
  1743. IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
  1744. IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
  1745. IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
  1746. IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
  1747. IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
  1748. IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
  1749. IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
  1750. IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
  1751. IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
  1752. IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL),
  1753. IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
  1754. IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO),
  1755. IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
  1756. IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_audio, INFO_FL_PRIO),
  1757. IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
  1758. IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
  1759. IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
  1760. IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
  1761. IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
  1762. IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO),
  1763. IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
  1764. IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
  1765. IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO),
  1766. IOCTL_INFO_FNC(VIDIOC_G_MODULATOR, v4l_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
  1767. IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_modulator, INFO_FL_PRIO),
  1768. IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
  1769. IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
  1770. IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
  1771. IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
  1772. IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
  1773. IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
  1774. IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
  1775. IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0),
  1776. IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO),
  1777. IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
  1778. IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
  1779. IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
  1780. IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
  1781. IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
  1782. IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
  1783. IOCTL_INFO_FNC(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
  1784. IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0),
  1785. IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
  1786. IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
  1787. IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
  1788. IOCTL_INFO_STD(VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
  1789. IOCTL_INFO_STD(VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
  1790. IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0),
  1791. IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
  1792. IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
  1793. IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO),
  1794. IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
  1795. IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0),
  1796. IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
  1797. IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
  1798. IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
  1799. IOCTL_INFO_STD(VIDIOC_ENUM_DV_PRESETS, vidioc_enum_dv_presets, v4l_print_dv_enum_presets, 0),
  1800. IOCTL_INFO_STD(VIDIOC_S_DV_PRESET, vidioc_s_dv_preset, v4l_print_dv_preset, INFO_FL_PRIO),
  1801. IOCTL_INFO_STD(VIDIOC_G_DV_PRESET, vidioc_g_dv_preset, v4l_print_dv_preset, 0),
  1802. IOCTL_INFO_STD(VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset, v4l_print_dv_preset, 0),
  1803. IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
  1804. IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
  1805. IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
  1806. IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0),
  1807. IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0),
  1808. IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE),
  1809. IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE),
  1810. IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
  1811. IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
  1812. IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, type)),
  1813. IOCTL_INFO_FNC(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0),
  1814. };
  1815. #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
  1816. bool v4l2_is_known_ioctl(unsigned int cmd)
  1817. {
  1818. if (_IOC_NR(cmd) >= V4L2_IOCTLS)
  1819. return false;
  1820. return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
  1821. }
  1822. struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd)
  1823. {
  1824. if (_IOC_NR(cmd) >= V4L2_IOCTLS)
  1825. return vdev->lock;
  1826. if (test_bit(_IOC_NR(cmd), vdev->disable_locking))
  1827. return NULL;
  1828. if (vdev->queue && vdev->queue->lock &&
  1829. (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE))
  1830. return vdev->queue->lock;
  1831. return vdev->lock;
  1832. }
  1833. /* Common ioctl debug function. This function can be used by
  1834. external ioctl messages as well as internal V4L ioctl */
  1835. void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
  1836. {
  1837. const char *dir, *type;
  1838. if (prefix)
  1839. printk(KERN_DEBUG "%s: ", prefix);
  1840. switch (_IOC_TYPE(cmd)) {
  1841. case 'd':
  1842. type = "v4l2_int";
  1843. break;
  1844. case 'V':
  1845. if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
  1846. type = "v4l2";
  1847. break;
  1848. }
  1849. pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
  1850. return;
  1851. default:
  1852. type = "unknown";
  1853. break;
  1854. }
  1855. switch (_IOC_DIR(cmd)) {
  1856. case _IOC_NONE: dir = "--"; break;
  1857. case _IOC_READ: dir = "r-"; break;
  1858. case _IOC_WRITE: dir = "-w"; break;
  1859. case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
  1860. default: dir = "*ERR*"; break;
  1861. }
  1862. pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
  1863. type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
  1864. }
  1865. EXPORT_SYMBOL(v4l_printk_ioctl);
  1866. static long __video_do_ioctl(struct file *file,
  1867. unsigned int cmd, void *arg)
  1868. {
  1869. struct video_device *vfd = video_devdata(file);
  1870. const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
  1871. bool write_only = false;
  1872. struct v4l2_ioctl_info default_info;
  1873. const struct v4l2_ioctl_info *info;
  1874. void *fh = file->private_data;
  1875. struct v4l2_fh *vfh = NULL;
  1876. int use_fh_prio = 0;
  1877. int debug = vfd->debug;
  1878. long ret = -ENOTTY;
  1879. if (ops == NULL) {
  1880. pr_warn("%s: has no ioctl_ops.\n",
  1881. video_device_node_name(vfd));
  1882. return ret;
  1883. }
  1884. if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
  1885. vfh = file->private_data;
  1886. use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  1887. }
  1888. if (v4l2_is_known_ioctl(cmd)) {
  1889. info = &v4l2_ioctls[_IOC_NR(cmd)];
  1890. if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
  1891. !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
  1892. goto done;
  1893. if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
  1894. ret = v4l2_prio_check(vfd->prio, vfh->prio);
  1895. if (ret)
  1896. goto done;
  1897. }
  1898. } else {
  1899. default_info.ioctl = cmd;
  1900. default_info.flags = 0;
  1901. default_info.debug = v4l_print_default;
  1902. info = &default_info;
  1903. }
  1904. write_only = _IOC_DIR(cmd) == _IOC_WRITE;
  1905. if (info->flags & INFO_FL_STD) {
  1906. typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
  1907. const void *p = vfd->ioctl_ops;
  1908. const vidioc_op *vidioc = p + info->u.offset;
  1909. ret = (*vidioc)(file, fh, arg);
  1910. } else if (info->flags & INFO_FL_FUNC) {
  1911. ret = info->u.func(ops, file, fh, arg);
  1912. } else if (!ops->vidioc_default) {
  1913. ret = -ENOTTY;
  1914. } else {
  1915. ret = ops->vidioc_default(file, fh,
  1916. use_fh_prio ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
  1917. cmd, arg);
  1918. }
  1919. done:
  1920. if (debug) {
  1921. v4l_printk_ioctl(video_device_node_name(vfd), cmd);
  1922. if (ret < 0)
  1923. pr_cont(": error %ld", ret);
  1924. if (debug == V4L2_DEBUG_IOCTL)
  1925. pr_cont("\n");
  1926. else if (_IOC_DIR(cmd) == _IOC_NONE)
  1927. info->debug(arg, write_only);
  1928. else {
  1929. pr_cont(": ");
  1930. info->debug(arg, write_only);
  1931. }
  1932. }
  1933. return ret;
  1934. }
  1935. static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
  1936. void * __user *user_ptr, void ***kernel_ptr)
  1937. {
  1938. int ret = 0;
  1939. switch (cmd) {
  1940. case VIDIOC_PREPARE_BUF:
  1941. case VIDIOC_QUERYBUF:
  1942. case VIDIOC_QBUF:
  1943. case VIDIOC_DQBUF: {
  1944. struct v4l2_buffer *buf = parg;
  1945. if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
  1946. if (buf->length > VIDEO_MAX_PLANES) {
  1947. ret = -EINVAL;
  1948. break;
  1949. }
  1950. *user_ptr = (void __user *)buf->m.planes;
  1951. *kernel_ptr = (void *)&buf->m.planes;
  1952. *array_size = sizeof(struct v4l2_plane) * buf->length;
  1953. ret = 1;
  1954. }
  1955. break;
  1956. }
  1957. case VIDIOC_SUBDEV_G_EDID:
  1958. case VIDIOC_SUBDEV_S_EDID: {
  1959. struct v4l2_subdev_edid *edid = parg;
  1960. if (edid->blocks) {
  1961. if (edid->blocks > 256) {
  1962. ret = -EINVAL;
  1963. break;
  1964. }
  1965. *user_ptr = (void __user *)edid->edid;
  1966. *kernel_ptr = (void *)&edid->edid;
  1967. *array_size = edid->blocks * 128;
  1968. ret = 1;
  1969. }
  1970. break;
  1971. }
  1972. case VIDIOC_S_EXT_CTRLS:
  1973. case VIDIOC_G_EXT_CTRLS:
  1974. case VIDIOC_TRY_EXT_CTRLS: {
  1975. struct v4l2_ext_controls *ctrls = parg;
  1976. if (ctrls->count != 0) {
  1977. if (ctrls->count > V4L2_CID_MAX_CTRLS) {
  1978. ret = -EINVAL;
  1979. break;
  1980. }
  1981. *user_ptr = (void __user *)ctrls->controls;
  1982. *kernel_ptr = (void *)&ctrls->controls;
  1983. *array_size = sizeof(struct v4l2_ext_control)
  1984. * ctrls->count;
  1985. ret = 1;
  1986. }
  1987. break;
  1988. }
  1989. }
  1990. return ret;
  1991. }
  1992. long
  1993. video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
  1994. v4l2_kioctl func)
  1995. {
  1996. char sbuf[128];
  1997. void *mbuf = NULL;
  1998. void *parg = (void *)arg;
  1999. long err = -EINVAL;
  2000. bool has_array_args;
  2001. size_t array_size = 0;
  2002. void __user *user_ptr = NULL;
  2003. void **kernel_ptr = NULL;
  2004. /* Copy arguments into temp kernel buffer */
  2005. if (_IOC_DIR(cmd) != _IOC_NONE) {
  2006. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  2007. parg = sbuf;
  2008. } else {
  2009. /* too big to allocate from stack */
  2010. mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
  2011. if (NULL == mbuf)
  2012. return -ENOMEM;
  2013. parg = mbuf;
  2014. }
  2015. err = -EFAULT;
  2016. if (_IOC_DIR(cmd) & _IOC_WRITE) {
  2017. unsigned int n = _IOC_SIZE(cmd);
  2018. /*
  2019. * In some cases, only a few fields are used as input,
  2020. * i.e. when the app sets "index" and then the driver
  2021. * fills in the rest of the structure for the thing
  2022. * with that index. We only need to copy up the first
  2023. * non-input field.
  2024. */
  2025. if (v4l2_is_known_ioctl(cmd)) {
  2026. u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
  2027. if (flags & INFO_FL_CLEAR_MASK)
  2028. n = (flags & INFO_FL_CLEAR_MASK) >> 16;
  2029. }
  2030. if (copy_from_user(parg, (void __user *)arg, n))
  2031. goto out;
  2032. /* zero out anything we don't copy from userspace */
  2033. if (n < _IOC_SIZE(cmd))
  2034. memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
  2035. } else {
  2036. /* read-only ioctl */
  2037. memset(parg, 0, _IOC_SIZE(cmd));
  2038. }
  2039. }
  2040. err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
  2041. if (err < 0)
  2042. goto out;
  2043. has_array_args = err;
  2044. if (has_array_args) {
  2045. /*
  2046. * When adding new types of array args, make sure that the
  2047. * parent argument to ioctl (which contains the pointer to the
  2048. * array) fits into sbuf (so that mbuf will still remain
  2049. * unused up to here).
  2050. */
  2051. mbuf = kmalloc(array_size, GFP_KERNEL);
  2052. err = -ENOMEM;
  2053. if (NULL == mbuf)
  2054. goto out_array_args;
  2055. err = -EFAULT;
  2056. if (copy_from_user(mbuf, user_ptr, array_size))
  2057. goto out_array_args;
  2058. *kernel_ptr = mbuf;
  2059. }
  2060. /* Handles IOCTL */
  2061. err = func(file, cmd, parg);
  2062. if (err == -ENOIOCTLCMD)
  2063. err = -ENOTTY;
  2064. if (has_array_args) {
  2065. *kernel_ptr = user_ptr;
  2066. if (copy_to_user(user_ptr, mbuf, array_size))
  2067. err = -EFAULT;
  2068. goto out_array_args;
  2069. }
  2070. /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
  2071. results that must be returned. */
  2072. if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
  2073. goto out;
  2074. out_array_args:
  2075. /* Copy results into user buffer */
  2076. switch (_IOC_DIR(cmd)) {
  2077. case _IOC_READ:
  2078. case (_IOC_WRITE | _IOC_READ):
  2079. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  2080. err = -EFAULT;
  2081. break;
  2082. }
  2083. out:
  2084. kfree(mbuf);
  2085. return err;
  2086. }
  2087. EXPORT_SYMBOL(video_usercopy);
  2088. long video_ioctl2(struct file *file,
  2089. unsigned int cmd, unsigned long arg)
  2090. {
  2091. return video_usercopy(file, cmd, arg, __video_do_ioctl);
  2092. }
  2093. EXPORT_SYMBOL(video_ioctl2);