v4l2-ioctl.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  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/types.h>
  16. #include <linux/kernel.h>
  17. #define __OLD_VIDIOC_ /* To allow fixing old calls */
  18. #include <linux/videodev.h>
  19. #include <linux/videodev2.h>
  20. #ifdef CONFIG_VIDEO_V4L1
  21. #include <linux/videodev.h>
  22. #endif
  23. #include <media/v4l2-common.h>
  24. #include <media/v4l2-ioctl.h>
  25. #include <media/v4l2-chip-ident.h>
  26. #define dbgarg(cmd, fmt, arg...) \
  27. do { \
  28. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
  29. printk(KERN_DEBUG "%s: ", vfd->name); \
  30. v4l_printk_ioctl(cmd); \
  31. printk(" " fmt, ## arg); \
  32. } \
  33. } while (0)
  34. #define dbgarg2(fmt, arg...) \
  35. do { \
  36. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
  37. printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
  38. } while (0)
  39. /* Zero out the end of the struct pointed to by p. Everthing after, but
  40. * not including, the specified field is cleared. */
  41. #define CLEAR_AFTER_FIELD(p, field) \
  42. memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
  43. 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
  44. struct std_descr {
  45. v4l2_std_id std;
  46. const char *descr;
  47. };
  48. static const struct std_descr standards[] = {
  49. { V4L2_STD_NTSC, "NTSC" },
  50. { V4L2_STD_NTSC_M, "NTSC-M" },
  51. { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
  52. { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
  53. { V4L2_STD_NTSC_443, "NTSC-443" },
  54. { V4L2_STD_PAL, "PAL" },
  55. { V4L2_STD_PAL_BG, "PAL-BG" },
  56. { V4L2_STD_PAL_B, "PAL-B" },
  57. { V4L2_STD_PAL_B1, "PAL-B1" },
  58. { V4L2_STD_PAL_G, "PAL-G" },
  59. { V4L2_STD_PAL_H, "PAL-H" },
  60. { V4L2_STD_PAL_I, "PAL-I" },
  61. { V4L2_STD_PAL_DK, "PAL-DK" },
  62. { V4L2_STD_PAL_D, "PAL-D" },
  63. { V4L2_STD_PAL_D1, "PAL-D1" },
  64. { V4L2_STD_PAL_K, "PAL-K" },
  65. { V4L2_STD_PAL_M, "PAL-M" },
  66. { V4L2_STD_PAL_N, "PAL-N" },
  67. { V4L2_STD_PAL_Nc, "PAL-Nc" },
  68. { V4L2_STD_PAL_60, "PAL-60" },
  69. { V4L2_STD_SECAM, "SECAM" },
  70. { V4L2_STD_SECAM_B, "SECAM-B" },
  71. { V4L2_STD_SECAM_G, "SECAM-G" },
  72. { V4L2_STD_SECAM_H, "SECAM-H" },
  73. { V4L2_STD_SECAM_DK, "SECAM-DK" },
  74. { V4L2_STD_SECAM_D, "SECAM-D" },
  75. { V4L2_STD_SECAM_K, "SECAM-K" },
  76. { V4L2_STD_SECAM_K1, "SECAM-K1" },
  77. { V4L2_STD_SECAM_L, "SECAM-L" },
  78. { V4L2_STD_SECAM_LC, "SECAM-Lc" },
  79. { 0, "Unknown" }
  80. };
  81. /* video4linux standard ID conversion to standard name
  82. */
  83. const char *v4l2_norm_to_name(v4l2_std_id id)
  84. {
  85. u32 myid = id;
  86. int i;
  87. /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
  88. 64 bit comparations. So, on that architecture, with some gcc
  89. variants, compilation fails. Currently, the max value is 30bit wide.
  90. */
  91. BUG_ON(myid != id);
  92. for (i = 0; standards[i].std; i++)
  93. if (myid == standards[i].std)
  94. break;
  95. return standards[i].descr;
  96. }
  97. EXPORT_SYMBOL(v4l2_norm_to_name);
  98. /* Returns frame period for the given standard */
  99. void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
  100. {
  101. if (id & V4L2_STD_525_60) {
  102. frameperiod->numerator = 1001;
  103. frameperiod->denominator = 30000;
  104. } else {
  105. frameperiod->numerator = 1;
  106. frameperiod->denominator = 25;
  107. }
  108. }
  109. EXPORT_SYMBOL(v4l2_video_std_frame_period);
  110. /* Fill in the fields of a v4l2_standard structure according to the
  111. 'id' and 'transmission' parameters. Returns negative on error. */
  112. int v4l2_video_std_construct(struct v4l2_standard *vs,
  113. int id, const char *name)
  114. {
  115. vs->id = id;
  116. v4l2_video_std_frame_period(id, &vs->frameperiod);
  117. vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
  118. strlcpy(vs->name, name, sizeof(vs->name));
  119. return 0;
  120. }
  121. EXPORT_SYMBOL(v4l2_video_std_construct);
  122. /* ----------------------------------------------------------------- */
  123. /* some arrays for pretty-printing debug messages of enum types */
  124. const char *v4l2_field_names[] = {
  125. [V4L2_FIELD_ANY] = "any",
  126. [V4L2_FIELD_NONE] = "none",
  127. [V4L2_FIELD_TOP] = "top",
  128. [V4L2_FIELD_BOTTOM] = "bottom",
  129. [V4L2_FIELD_INTERLACED] = "interlaced",
  130. [V4L2_FIELD_SEQ_TB] = "seq-tb",
  131. [V4L2_FIELD_SEQ_BT] = "seq-bt",
  132. [V4L2_FIELD_ALTERNATE] = "alternate",
  133. [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
  134. [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
  135. };
  136. EXPORT_SYMBOL(v4l2_field_names);
  137. const char *v4l2_type_names[] = {
  138. [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
  139. [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
  140. [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
  141. [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
  142. [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
  143. [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
  144. [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
  145. [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
  146. };
  147. EXPORT_SYMBOL(v4l2_type_names);
  148. static const char *v4l2_memory_names[] = {
  149. [V4L2_MEMORY_MMAP] = "mmap",
  150. [V4L2_MEMORY_USERPTR] = "userptr",
  151. [V4L2_MEMORY_OVERLAY] = "overlay",
  152. };
  153. #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
  154. arr[a] : "unknown")
  155. /* ------------------------------------------------------------------ */
  156. /* debug help functions */
  157. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  158. static const char *v4l1_ioctls[] = {
  159. [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
  160. [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
  161. [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
  162. [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
  163. [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
  164. [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
  165. [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
  166. [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
  167. [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
  168. [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
  169. [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
  170. [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
  171. [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
  172. [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
  173. [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
  174. [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
  175. [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
  176. [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
  177. [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
  178. [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
  179. [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
  180. [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
  181. [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
  182. [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
  183. [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
  184. [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
  185. [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
  186. [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
  187. [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
  188. };
  189. #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
  190. #endif
  191. static const char *v4l2_ioctls[] = {
  192. [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
  193. [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
  194. [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
  195. [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
  196. [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
  197. [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
  198. [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
  199. [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
  200. [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
  201. [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
  202. [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
  203. [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
  204. [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
  205. [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
  206. [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
  207. [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
  208. [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
  209. [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
  210. [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
  211. [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
  212. [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
  213. [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
  214. [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
  215. [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
  216. [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
  217. [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
  218. [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
  219. [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
  220. [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
  221. [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
  222. [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
  223. [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
  224. [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
  225. [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
  226. [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
  227. [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
  228. [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
  229. [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
  230. [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
  231. [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
  232. [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
  233. [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
  234. [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
  235. [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
  236. [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
  237. [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
  238. [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
  239. [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
  240. [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
  241. [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
  242. [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
  243. [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
  244. [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
  245. [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
  246. [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
  247. #if 1
  248. [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
  249. [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
  250. [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
  251. [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
  252. [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
  253. [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
  254. [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
  255. [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
  256. [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
  257. #endif
  258. };
  259. #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
  260. /* Common ioctl debug function. This function can be used by
  261. external ioctl messages as well as internal V4L ioctl */
  262. void v4l_printk_ioctl(unsigned int cmd)
  263. {
  264. char *dir, *type;
  265. switch (_IOC_TYPE(cmd)) {
  266. case 'd':
  267. type = "v4l2_int";
  268. break;
  269. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  270. case 'v':
  271. if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
  272. type = "v4l1";
  273. break;
  274. }
  275. printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
  276. return;
  277. #endif
  278. case 'V':
  279. if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
  280. type = "v4l2";
  281. break;
  282. }
  283. printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
  284. return;
  285. default:
  286. type = "unknown";
  287. }
  288. switch (_IOC_DIR(cmd)) {
  289. case _IOC_NONE: dir = "--"; break;
  290. case _IOC_READ: dir = "r-"; break;
  291. case _IOC_WRITE: dir = "-w"; break;
  292. case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
  293. default: dir = "*ERR*"; break;
  294. }
  295. printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
  296. type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
  297. }
  298. EXPORT_SYMBOL(v4l_printk_ioctl);
  299. /*
  300. * helper function -- handles userspace copying for ioctl arguments
  301. */
  302. #ifdef __OLD_VIDIOC_
  303. static unsigned int
  304. video_fix_command(unsigned int cmd)
  305. {
  306. switch (cmd) {
  307. case VIDIOC_OVERLAY_OLD:
  308. cmd = VIDIOC_OVERLAY;
  309. break;
  310. case VIDIOC_S_PARM_OLD:
  311. cmd = VIDIOC_S_PARM;
  312. break;
  313. case VIDIOC_S_CTRL_OLD:
  314. cmd = VIDIOC_S_CTRL;
  315. break;
  316. case VIDIOC_G_AUDIO_OLD:
  317. cmd = VIDIOC_G_AUDIO;
  318. break;
  319. case VIDIOC_G_AUDOUT_OLD:
  320. cmd = VIDIOC_G_AUDOUT;
  321. break;
  322. case VIDIOC_CROPCAP_OLD:
  323. cmd = VIDIOC_CROPCAP;
  324. break;
  325. }
  326. return cmd;
  327. }
  328. #endif
  329. /*
  330. * Obsolete usercopy function - Should be removed soon
  331. */
  332. long
  333. video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
  334. v4l2_kioctl func)
  335. {
  336. char sbuf[128];
  337. void *mbuf = NULL;
  338. void *parg = NULL;
  339. long err = -EINVAL;
  340. int is_ext_ctrl;
  341. size_t ctrls_size = 0;
  342. void __user *user_ptr = NULL;
  343. #ifdef __OLD_VIDIOC_
  344. cmd = video_fix_command(cmd);
  345. #endif
  346. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  347. cmd == VIDIOC_TRY_EXT_CTRLS);
  348. /* Copy arguments into temp kernel buffer */
  349. switch (_IOC_DIR(cmd)) {
  350. case _IOC_NONE:
  351. parg = NULL;
  352. break;
  353. case _IOC_READ:
  354. case _IOC_WRITE:
  355. case (_IOC_WRITE | _IOC_READ):
  356. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  357. parg = sbuf;
  358. } else {
  359. /* too big to allocate from stack */
  360. mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
  361. if (NULL == mbuf)
  362. return -ENOMEM;
  363. parg = mbuf;
  364. }
  365. err = -EFAULT;
  366. if (_IOC_DIR(cmd) & _IOC_WRITE)
  367. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  368. goto out;
  369. break;
  370. }
  371. if (is_ext_ctrl) {
  372. struct v4l2_ext_controls *p = parg;
  373. /* In case of an error, tell the caller that it wasn't
  374. a specific control that caused it. */
  375. p->error_idx = p->count;
  376. user_ptr = (void __user *)p->controls;
  377. if (p->count) {
  378. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  379. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  380. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  381. err = -ENOMEM;
  382. if (NULL == mbuf)
  383. goto out_ext_ctrl;
  384. err = -EFAULT;
  385. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  386. goto out_ext_ctrl;
  387. p->controls = mbuf;
  388. }
  389. }
  390. /* call driver */
  391. err = func(file, cmd, parg);
  392. if (err == -ENOIOCTLCMD)
  393. err = -EINVAL;
  394. if (is_ext_ctrl) {
  395. struct v4l2_ext_controls *p = parg;
  396. p->controls = (void *)user_ptr;
  397. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  398. err = -EFAULT;
  399. goto out_ext_ctrl;
  400. }
  401. if (err < 0)
  402. goto out;
  403. out_ext_ctrl:
  404. /* Copy results into user buffer */
  405. switch (_IOC_DIR(cmd)) {
  406. case _IOC_READ:
  407. case (_IOC_WRITE | _IOC_READ):
  408. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  409. err = -EFAULT;
  410. break;
  411. }
  412. out:
  413. kfree(mbuf);
  414. return err;
  415. }
  416. EXPORT_SYMBOL(video_usercopy);
  417. static void dbgbuf(unsigned int cmd, struct video_device *vfd,
  418. struct v4l2_buffer *p)
  419. {
  420. struct v4l2_timecode *tc = &p->timecode;
  421. dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
  422. "bytesused=%d, flags=0x%08d, "
  423. "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
  424. p->timestamp.tv_sec / 3600,
  425. (int)(p->timestamp.tv_sec / 60) % 60,
  426. (int)(p->timestamp.tv_sec % 60),
  427. (long)p->timestamp.tv_usec,
  428. p->index,
  429. prt_names(p->type, v4l2_type_names),
  430. p->bytesused, p->flags,
  431. p->field, p->sequence,
  432. prt_names(p->memory, v4l2_memory_names),
  433. p->m.userptr, p->length);
  434. dbgarg2("timecode=%02d:%02d:%02d type=%d, "
  435. "flags=0x%08d, frames=%d, userbits=0x%08x\n",
  436. tc->hours, tc->minutes, tc->seconds,
  437. tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
  438. }
  439. static inline void dbgrect(struct video_device *vfd, char *s,
  440. struct v4l2_rect *r)
  441. {
  442. dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
  443. r->width, r->height);
  444. };
  445. static inline void v4l_print_pix_fmt(struct video_device *vfd,
  446. struct v4l2_pix_format *fmt)
  447. {
  448. dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
  449. "bytesperline=%d sizeimage=%d, colorspace=%d\n",
  450. fmt->width, fmt->height,
  451. (fmt->pixelformat & 0xff),
  452. (fmt->pixelformat >> 8) & 0xff,
  453. (fmt->pixelformat >> 16) & 0xff,
  454. (fmt->pixelformat >> 24) & 0xff,
  455. prt_names(fmt->field, v4l2_field_names),
  456. fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
  457. };
  458. static inline void v4l_print_ext_ctrls(unsigned int cmd,
  459. struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
  460. {
  461. __u32 i;
  462. if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
  463. return;
  464. dbgarg(cmd, "");
  465. printk(KERN_CONT "class=0x%x", c->ctrl_class);
  466. for (i = 0; i < c->count; i++) {
  467. if (show_vals)
  468. printk(KERN_CONT " id/val=0x%x/0x%x",
  469. c->controls[i].id, c->controls[i].value);
  470. else
  471. printk(KERN_CONT " id=0x%x", c->controls[i].id);
  472. }
  473. printk(KERN_CONT "\n");
  474. };
  475. static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
  476. {
  477. __u32 i;
  478. /* zero the reserved fields */
  479. c->reserved[0] = c->reserved[1] = 0;
  480. for (i = 0; i < c->count; i++) {
  481. c->controls[i].reserved2[0] = 0;
  482. c->controls[i].reserved2[1] = 0;
  483. }
  484. /* V4L2_CID_PRIVATE_BASE cannot be used as control class
  485. when using extended controls.
  486. Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
  487. is it allowed for backwards compatibility.
  488. */
  489. if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
  490. return 0;
  491. /* Check that all controls are from the same control class. */
  492. for (i = 0; i < c->count; i++) {
  493. if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
  494. c->error_idx = i;
  495. return 0;
  496. }
  497. }
  498. return 1;
  499. }
  500. static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
  501. {
  502. if (ops == NULL)
  503. return -EINVAL;
  504. switch (type) {
  505. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  506. if (ops->vidioc_g_fmt_vid_cap)
  507. return 0;
  508. break;
  509. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  510. if (ops->vidioc_g_fmt_vid_overlay)
  511. return 0;
  512. break;
  513. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  514. if (ops->vidioc_g_fmt_vid_out)
  515. return 0;
  516. break;
  517. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  518. if (ops->vidioc_g_fmt_vid_out_overlay)
  519. return 0;
  520. break;
  521. case V4L2_BUF_TYPE_VBI_CAPTURE:
  522. if (ops->vidioc_g_fmt_vbi_cap)
  523. return 0;
  524. break;
  525. case V4L2_BUF_TYPE_VBI_OUTPUT:
  526. if (ops->vidioc_g_fmt_vbi_out)
  527. return 0;
  528. break;
  529. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  530. if (ops->vidioc_g_fmt_sliced_vbi_cap)
  531. return 0;
  532. break;
  533. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  534. if (ops->vidioc_g_fmt_sliced_vbi_out)
  535. return 0;
  536. break;
  537. case V4L2_BUF_TYPE_PRIVATE:
  538. if (ops->vidioc_g_fmt_type_private)
  539. return 0;
  540. break;
  541. }
  542. return -EINVAL;
  543. }
  544. static long __video_do_ioctl(struct file *file,
  545. unsigned int cmd, void *arg)
  546. {
  547. struct video_device *vfd = video_devdata(file);
  548. const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
  549. void *fh = file->private_data;
  550. long ret = -EINVAL;
  551. if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
  552. !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
  553. v4l_print_ioctl(vfd->name, cmd);
  554. printk(KERN_CONT "\n");
  555. }
  556. if (ops == NULL) {
  557. printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
  558. vfd->name);
  559. return -EINVAL;
  560. }
  561. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  562. /***********************************************************
  563. Handles calls to the obsoleted V4L1 API
  564. Due to the nature of VIDIOCGMBUF, each driver that supports
  565. V4L1 should implement its own handler for this ioctl.
  566. ***********************************************************/
  567. /* --- streaming capture ------------------------------------- */
  568. if (cmd == VIDIOCGMBUF) {
  569. struct video_mbuf *p = arg;
  570. if (!ops->vidiocgmbuf)
  571. return ret;
  572. ret = ops->vidiocgmbuf(file, fh, p);
  573. if (!ret)
  574. dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
  575. p->size, p->frames,
  576. (unsigned long)p->offsets);
  577. return ret;
  578. }
  579. /********************************************************
  580. All other V4L1 calls are handled by v4l1_compat module.
  581. Those calls will be translated into V4L2 calls, and
  582. __video_do_ioctl will be called again, with one or more
  583. V4L2 ioctls.
  584. ********************************************************/
  585. if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
  586. return v4l_compat_translate_ioctl(file, cmd, arg,
  587. __video_do_ioctl);
  588. #endif
  589. switch (cmd) {
  590. /* --- capabilities ------------------------------------------ */
  591. case VIDIOC_QUERYCAP:
  592. {
  593. struct v4l2_capability *cap = (struct v4l2_capability *)arg;
  594. if (!ops->vidioc_querycap)
  595. break;
  596. ret = ops->vidioc_querycap(file, fh, cap);
  597. if (!ret)
  598. dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
  599. "version=0x%08x, "
  600. "capabilities=0x%08x\n",
  601. cap->driver, cap->card, cap->bus_info,
  602. cap->version,
  603. cap->capabilities);
  604. break;
  605. }
  606. /* --- priority ------------------------------------------ */
  607. case VIDIOC_G_PRIORITY:
  608. {
  609. enum v4l2_priority *p = arg;
  610. if (!ops->vidioc_g_priority)
  611. break;
  612. ret = ops->vidioc_g_priority(file, fh, p);
  613. if (!ret)
  614. dbgarg(cmd, "priority is %d\n", *p);
  615. break;
  616. }
  617. case VIDIOC_S_PRIORITY:
  618. {
  619. enum v4l2_priority *p = arg;
  620. if (!ops->vidioc_s_priority)
  621. break;
  622. dbgarg(cmd, "setting priority to %d\n", *p);
  623. ret = ops->vidioc_s_priority(file, fh, *p);
  624. break;
  625. }
  626. /* --- capture ioctls ---------------------------------------- */
  627. case VIDIOC_ENUM_FMT:
  628. {
  629. struct v4l2_fmtdesc *f = arg;
  630. switch (f->type) {
  631. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  632. if (ops->vidioc_enum_fmt_vid_cap)
  633. ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
  634. break;
  635. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  636. if (ops->vidioc_enum_fmt_vid_overlay)
  637. ret = ops->vidioc_enum_fmt_vid_overlay(file,
  638. fh, f);
  639. break;
  640. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  641. if (ops->vidioc_enum_fmt_vid_out)
  642. ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
  643. break;
  644. case V4L2_BUF_TYPE_PRIVATE:
  645. if (ops->vidioc_enum_fmt_type_private)
  646. ret = ops->vidioc_enum_fmt_type_private(file,
  647. fh, f);
  648. break;
  649. default:
  650. break;
  651. }
  652. if (!ret)
  653. dbgarg(cmd, "index=%d, type=%d, flags=%d, "
  654. "pixelformat=%c%c%c%c, description='%s'\n",
  655. f->index, f->type, f->flags,
  656. (f->pixelformat & 0xff),
  657. (f->pixelformat >> 8) & 0xff,
  658. (f->pixelformat >> 16) & 0xff,
  659. (f->pixelformat >> 24) & 0xff,
  660. f->description);
  661. break;
  662. }
  663. case VIDIOC_G_FMT:
  664. {
  665. struct v4l2_format *f = (struct v4l2_format *)arg;
  666. /* FIXME: Should be one dump per type */
  667. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  668. switch (f->type) {
  669. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  670. if (ops->vidioc_g_fmt_vid_cap)
  671. ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
  672. if (!ret)
  673. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  674. break;
  675. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  676. if (ops->vidioc_g_fmt_vid_overlay)
  677. ret = ops->vidioc_g_fmt_vid_overlay(file,
  678. fh, f);
  679. break;
  680. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  681. if (ops->vidioc_g_fmt_vid_out)
  682. ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
  683. if (!ret)
  684. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  685. break;
  686. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  687. if (ops->vidioc_g_fmt_vid_out_overlay)
  688. ret = ops->vidioc_g_fmt_vid_out_overlay(file,
  689. fh, f);
  690. break;
  691. case V4L2_BUF_TYPE_VBI_CAPTURE:
  692. if (ops->vidioc_g_fmt_vbi_cap)
  693. ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
  694. break;
  695. case V4L2_BUF_TYPE_VBI_OUTPUT:
  696. if (ops->vidioc_g_fmt_vbi_out)
  697. ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
  698. break;
  699. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  700. if (ops->vidioc_g_fmt_sliced_vbi_cap)
  701. ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
  702. fh, f);
  703. break;
  704. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  705. if (ops->vidioc_g_fmt_sliced_vbi_out)
  706. ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
  707. fh, f);
  708. break;
  709. case V4L2_BUF_TYPE_PRIVATE:
  710. if (ops->vidioc_g_fmt_type_private)
  711. ret = ops->vidioc_g_fmt_type_private(file,
  712. fh, f);
  713. break;
  714. }
  715. break;
  716. }
  717. case VIDIOC_S_FMT:
  718. {
  719. struct v4l2_format *f = (struct v4l2_format *)arg;
  720. /* FIXME: Should be one dump per type */
  721. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  722. switch (f->type) {
  723. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  724. CLEAR_AFTER_FIELD(f, fmt.pix);
  725. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  726. if (ops->vidioc_s_fmt_vid_cap)
  727. ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
  728. break;
  729. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  730. CLEAR_AFTER_FIELD(f, fmt.win);
  731. if (ops->vidioc_s_fmt_vid_overlay)
  732. ret = ops->vidioc_s_fmt_vid_overlay(file,
  733. fh, f);
  734. break;
  735. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  736. CLEAR_AFTER_FIELD(f, fmt.pix);
  737. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  738. if (ops->vidioc_s_fmt_vid_out)
  739. ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
  740. break;
  741. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  742. CLEAR_AFTER_FIELD(f, fmt.win);
  743. if (ops->vidioc_s_fmt_vid_out_overlay)
  744. ret = ops->vidioc_s_fmt_vid_out_overlay(file,
  745. fh, f);
  746. break;
  747. case V4L2_BUF_TYPE_VBI_CAPTURE:
  748. CLEAR_AFTER_FIELD(f, fmt.vbi);
  749. if (ops->vidioc_s_fmt_vbi_cap)
  750. ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
  751. break;
  752. case V4L2_BUF_TYPE_VBI_OUTPUT:
  753. CLEAR_AFTER_FIELD(f, fmt.vbi);
  754. if (ops->vidioc_s_fmt_vbi_out)
  755. ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
  756. break;
  757. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  758. CLEAR_AFTER_FIELD(f, fmt.sliced);
  759. if (ops->vidioc_s_fmt_sliced_vbi_cap)
  760. ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
  761. fh, f);
  762. break;
  763. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  764. CLEAR_AFTER_FIELD(f, fmt.sliced);
  765. if (ops->vidioc_s_fmt_sliced_vbi_out)
  766. ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
  767. fh, f);
  768. break;
  769. case V4L2_BUF_TYPE_PRIVATE:
  770. /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
  771. if (ops->vidioc_s_fmt_type_private)
  772. ret = ops->vidioc_s_fmt_type_private(file,
  773. fh, f);
  774. break;
  775. }
  776. break;
  777. }
  778. case VIDIOC_TRY_FMT:
  779. {
  780. struct v4l2_format *f = (struct v4l2_format *)arg;
  781. /* FIXME: Should be one dump per type */
  782. dbgarg(cmd, "type=%s\n", prt_names(f->type,
  783. v4l2_type_names));
  784. switch (f->type) {
  785. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  786. CLEAR_AFTER_FIELD(f, fmt.pix);
  787. if (ops->vidioc_try_fmt_vid_cap)
  788. ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
  789. if (!ret)
  790. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  791. break;
  792. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  793. CLEAR_AFTER_FIELD(f, fmt.win);
  794. if (ops->vidioc_try_fmt_vid_overlay)
  795. ret = ops->vidioc_try_fmt_vid_overlay(file,
  796. fh, f);
  797. break;
  798. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  799. CLEAR_AFTER_FIELD(f, fmt.pix);
  800. if (ops->vidioc_try_fmt_vid_out)
  801. ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
  802. if (!ret)
  803. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  804. break;
  805. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  806. CLEAR_AFTER_FIELD(f, fmt.win);
  807. if (ops->vidioc_try_fmt_vid_out_overlay)
  808. ret = ops->vidioc_try_fmt_vid_out_overlay(file,
  809. fh, f);
  810. break;
  811. case V4L2_BUF_TYPE_VBI_CAPTURE:
  812. CLEAR_AFTER_FIELD(f, fmt.vbi);
  813. if (ops->vidioc_try_fmt_vbi_cap)
  814. ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
  815. break;
  816. case V4L2_BUF_TYPE_VBI_OUTPUT:
  817. CLEAR_AFTER_FIELD(f, fmt.vbi);
  818. if (ops->vidioc_try_fmt_vbi_out)
  819. ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
  820. break;
  821. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  822. CLEAR_AFTER_FIELD(f, fmt.sliced);
  823. if (ops->vidioc_try_fmt_sliced_vbi_cap)
  824. ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
  825. fh, f);
  826. break;
  827. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  828. CLEAR_AFTER_FIELD(f, fmt.sliced);
  829. if (ops->vidioc_try_fmt_sliced_vbi_out)
  830. ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
  831. fh, f);
  832. break;
  833. case V4L2_BUF_TYPE_PRIVATE:
  834. /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
  835. if (ops->vidioc_try_fmt_type_private)
  836. ret = ops->vidioc_try_fmt_type_private(file,
  837. fh, f);
  838. break;
  839. }
  840. break;
  841. }
  842. /* FIXME: Those buf reqs could be handled here,
  843. with some changes on videobuf to allow its header to be included at
  844. videodev2.h or being merged at videodev2.
  845. */
  846. case VIDIOC_REQBUFS:
  847. {
  848. struct v4l2_requestbuffers *p = arg;
  849. if (!ops->vidioc_reqbufs)
  850. break;
  851. ret = check_fmt(ops, p->type);
  852. if (ret)
  853. break;
  854. if (p->type < V4L2_BUF_TYPE_PRIVATE)
  855. CLEAR_AFTER_FIELD(p, memory);
  856. ret = ops->vidioc_reqbufs(file, fh, p);
  857. dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
  858. p->count,
  859. prt_names(p->type, v4l2_type_names),
  860. prt_names(p->memory, v4l2_memory_names));
  861. break;
  862. }
  863. case VIDIOC_QUERYBUF:
  864. {
  865. struct v4l2_buffer *p = arg;
  866. if (!ops->vidioc_querybuf)
  867. break;
  868. ret = check_fmt(ops, p->type);
  869. if (ret)
  870. break;
  871. ret = ops->vidioc_querybuf(file, fh, p);
  872. if (!ret)
  873. dbgbuf(cmd, vfd, p);
  874. break;
  875. }
  876. case VIDIOC_QBUF:
  877. {
  878. struct v4l2_buffer *p = arg;
  879. if (!ops->vidioc_qbuf)
  880. break;
  881. ret = check_fmt(ops, p->type);
  882. if (ret)
  883. break;
  884. ret = ops->vidioc_qbuf(file, fh, p);
  885. if (!ret)
  886. dbgbuf(cmd, vfd, p);
  887. break;
  888. }
  889. case VIDIOC_DQBUF:
  890. {
  891. struct v4l2_buffer *p = arg;
  892. if (!ops->vidioc_dqbuf)
  893. break;
  894. ret = check_fmt(ops, p->type);
  895. if (ret)
  896. break;
  897. ret = ops->vidioc_dqbuf(file, fh, p);
  898. if (!ret)
  899. dbgbuf(cmd, vfd, p);
  900. break;
  901. }
  902. case VIDIOC_OVERLAY:
  903. {
  904. int *i = arg;
  905. if (!ops->vidioc_overlay)
  906. break;
  907. dbgarg(cmd, "value=%d\n", *i);
  908. ret = ops->vidioc_overlay(file, fh, *i);
  909. break;
  910. }
  911. case VIDIOC_G_FBUF:
  912. {
  913. struct v4l2_framebuffer *p = arg;
  914. if (!ops->vidioc_g_fbuf)
  915. break;
  916. ret = ops->vidioc_g_fbuf(file, fh, arg);
  917. if (!ret) {
  918. dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
  919. p->capability, p->flags,
  920. (unsigned long)p->base);
  921. v4l_print_pix_fmt(vfd, &p->fmt);
  922. }
  923. break;
  924. }
  925. case VIDIOC_S_FBUF:
  926. {
  927. struct v4l2_framebuffer *p = arg;
  928. if (!ops->vidioc_s_fbuf)
  929. break;
  930. dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
  931. p->capability, p->flags, (unsigned long)p->base);
  932. v4l_print_pix_fmt(vfd, &p->fmt);
  933. ret = ops->vidioc_s_fbuf(file, fh, arg);
  934. break;
  935. }
  936. case VIDIOC_STREAMON:
  937. {
  938. enum v4l2_buf_type i = *(int *)arg;
  939. if (!ops->vidioc_streamon)
  940. break;
  941. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  942. ret = ops->vidioc_streamon(file, fh, i);
  943. break;
  944. }
  945. case VIDIOC_STREAMOFF:
  946. {
  947. enum v4l2_buf_type i = *(int *)arg;
  948. if (!ops->vidioc_streamoff)
  949. break;
  950. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  951. ret = ops->vidioc_streamoff(file, fh, i);
  952. break;
  953. }
  954. /* ---------- tv norms ---------- */
  955. case VIDIOC_ENUMSTD:
  956. {
  957. struct v4l2_standard *p = arg;
  958. v4l2_std_id id = vfd->tvnorms, curr_id = 0;
  959. unsigned int index = p->index, i, j = 0;
  960. const char *descr = "";
  961. /* Return norm array in a canonical way */
  962. for (i = 0; i <= index && id; i++) {
  963. /* last std value in the standards array is 0, so this
  964. while always ends there since (id & 0) == 0. */
  965. while ((id & standards[j].std) != standards[j].std)
  966. j++;
  967. curr_id = standards[j].std;
  968. descr = standards[j].descr;
  969. j++;
  970. if (curr_id == 0)
  971. break;
  972. if (curr_id != V4L2_STD_PAL &&
  973. curr_id != V4L2_STD_SECAM &&
  974. curr_id != V4L2_STD_NTSC)
  975. id &= ~curr_id;
  976. }
  977. if (i <= index)
  978. return -EINVAL;
  979. v4l2_video_std_construct(p, curr_id, descr);
  980. dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
  981. "framelines=%d\n", p->index,
  982. (unsigned long long)p->id, p->name,
  983. p->frameperiod.numerator,
  984. p->frameperiod.denominator,
  985. p->framelines);
  986. ret = 0;
  987. break;
  988. }
  989. case VIDIOC_G_STD:
  990. {
  991. v4l2_std_id *id = arg;
  992. ret = 0;
  993. /* Calls the specific handler */
  994. if (ops->vidioc_g_std)
  995. ret = ops->vidioc_g_std(file, fh, id);
  996. else if (vfd->current_norm)
  997. *id = vfd->current_norm;
  998. else
  999. ret = -EINVAL;
  1000. if (!ret)
  1001. dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
  1002. break;
  1003. }
  1004. case VIDIOC_S_STD:
  1005. {
  1006. v4l2_std_id *id = arg, norm;
  1007. dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
  1008. norm = (*id) & vfd->tvnorms;
  1009. if (vfd->tvnorms && !norm) /* Check if std is supported */
  1010. break;
  1011. /* Calls the specific handler */
  1012. if (ops->vidioc_s_std)
  1013. ret = ops->vidioc_s_std(file, fh, &norm);
  1014. else
  1015. ret = -EINVAL;
  1016. /* Updates standard information */
  1017. if (ret >= 0)
  1018. vfd->current_norm = norm;
  1019. break;
  1020. }
  1021. case VIDIOC_QUERYSTD:
  1022. {
  1023. v4l2_std_id *p = arg;
  1024. if (!ops->vidioc_querystd)
  1025. break;
  1026. ret = ops->vidioc_querystd(file, fh, arg);
  1027. if (!ret)
  1028. dbgarg(cmd, "detected std=%08Lx\n",
  1029. (unsigned long long)*p);
  1030. break;
  1031. }
  1032. /* ------ input switching ---------- */
  1033. /* FIXME: Inputs can be handled inside videodev2 */
  1034. case VIDIOC_ENUMINPUT:
  1035. {
  1036. struct v4l2_input *p = arg;
  1037. if (!ops->vidioc_enum_input)
  1038. break;
  1039. ret = ops->vidioc_enum_input(file, fh, p);
  1040. if (!ret)
  1041. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1042. "audioset=%d, "
  1043. "tuner=%d, std=%08Lx, status=%d\n",
  1044. p->index, p->name, p->type, p->audioset,
  1045. p->tuner,
  1046. (unsigned long long)p->std,
  1047. p->status);
  1048. break;
  1049. }
  1050. case VIDIOC_G_INPUT:
  1051. {
  1052. unsigned int *i = arg;
  1053. if (!ops->vidioc_g_input)
  1054. break;
  1055. ret = ops->vidioc_g_input(file, fh, i);
  1056. if (!ret)
  1057. dbgarg(cmd, "value=%d\n", *i);
  1058. break;
  1059. }
  1060. case VIDIOC_S_INPUT:
  1061. {
  1062. unsigned int *i = arg;
  1063. if (!ops->vidioc_s_input)
  1064. break;
  1065. dbgarg(cmd, "value=%d\n", *i);
  1066. ret = ops->vidioc_s_input(file, fh, *i);
  1067. break;
  1068. }
  1069. /* ------ output switching ---------- */
  1070. case VIDIOC_ENUMOUTPUT:
  1071. {
  1072. struct v4l2_output *p = arg;
  1073. if (!ops->vidioc_enum_output)
  1074. break;
  1075. ret = ops->vidioc_enum_output(file, fh, p);
  1076. if (!ret)
  1077. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1078. "audioset=0x%x, "
  1079. "modulator=%d, std=0x%08Lx\n",
  1080. p->index, p->name, p->type, p->audioset,
  1081. p->modulator, (unsigned long long)p->std);
  1082. break;
  1083. }
  1084. case VIDIOC_G_OUTPUT:
  1085. {
  1086. unsigned int *i = arg;
  1087. if (!ops->vidioc_g_output)
  1088. break;
  1089. ret = ops->vidioc_g_output(file, fh, i);
  1090. if (!ret)
  1091. dbgarg(cmd, "value=%d\n", *i);
  1092. break;
  1093. }
  1094. case VIDIOC_S_OUTPUT:
  1095. {
  1096. unsigned int *i = arg;
  1097. if (!ops->vidioc_s_output)
  1098. break;
  1099. dbgarg(cmd, "value=%d\n", *i);
  1100. ret = ops->vidioc_s_output(file, fh, *i);
  1101. break;
  1102. }
  1103. /* --- controls ---------------------------------------------- */
  1104. case VIDIOC_QUERYCTRL:
  1105. {
  1106. struct v4l2_queryctrl *p = arg;
  1107. if (!ops->vidioc_queryctrl)
  1108. break;
  1109. ret = ops->vidioc_queryctrl(file, fh, p);
  1110. if (!ret)
  1111. dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
  1112. "step=%d, default=%d, flags=0x%08x\n",
  1113. p->id, p->type, p->name,
  1114. p->minimum, p->maximum,
  1115. p->step, p->default_value, p->flags);
  1116. else
  1117. dbgarg(cmd, "id=0x%x\n", p->id);
  1118. break;
  1119. }
  1120. case VIDIOC_G_CTRL:
  1121. {
  1122. struct v4l2_control *p = arg;
  1123. if (ops->vidioc_g_ctrl)
  1124. ret = ops->vidioc_g_ctrl(file, fh, p);
  1125. else if (ops->vidioc_g_ext_ctrls) {
  1126. struct v4l2_ext_controls ctrls;
  1127. struct v4l2_ext_control ctrl;
  1128. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1129. ctrls.count = 1;
  1130. ctrls.controls = &ctrl;
  1131. ctrl.id = p->id;
  1132. ctrl.value = p->value;
  1133. if (check_ext_ctrls(&ctrls, 1)) {
  1134. ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
  1135. if (ret == 0)
  1136. p->value = ctrl.value;
  1137. }
  1138. } else
  1139. break;
  1140. if (!ret)
  1141. dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
  1142. else
  1143. dbgarg(cmd, "id=0x%x\n", p->id);
  1144. break;
  1145. }
  1146. case VIDIOC_S_CTRL:
  1147. {
  1148. struct v4l2_control *p = arg;
  1149. struct v4l2_ext_controls ctrls;
  1150. struct v4l2_ext_control ctrl;
  1151. if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
  1152. break;
  1153. dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
  1154. if (ops->vidioc_s_ctrl) {
  1155. ret = ops->vidioc_s_ctrl(file, fh, p);
  1156. break;
  1157. }
  1158. if (!ops->vidioc_s_ext_ctrls)
  1159. break;
  1160. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1161. ctrls.count = 1;
  1162. ctrls.controls = &ctrl;
  1163. ctrl.id = p->id;
  1164. ctrl.value = p->value;
  1165. if (check_ext_ctrls(&ctrls, 1))
  1166. ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
  1167. break;
  1168. }
  1169. case VIDIOC_G_EXT_CTRLS:
  1170. {
  1171. struct v4l2_ext_controls *p = arg;
  1172. p->error_idx = p->count;
  1173. if (!ops->vidioc_g_ext_ctrls)
  1174. break;
  1175. if (check_ext_ctrls(p, 0))
  1176. ret = ops->vidioc_g_ext_ctrls(file, fh, p);
  1177. v4l_print_ext_ctrls(cmd, vfd, p, !ret);
  1178. break;
  1179. }
  1180. case VIDIOC_S_EXT_CTRLS:
  1181. {
  1182. struct v4l2_ext_controls *p = arg;
  1183. p->error_idx = p->count;
  1184. if (!ops->vidioc_s_ext_ctrls)
  1185. break;
  1186. v4l_print_ext_ctrls(cmd, vfd, p, 1);
  1187. if (check_ext_ctrls(p, 0))
  1188. ret = ops->vidioc_s_ext_ctrls(file, fh, p);
  1189. break;
  1190. }
  1191. case VIDIOC_TRY_EXT_CTRLS:
  1192. {
  1193. struct v4l2_ext_controls *p = arg;
  1194. p->error_idx = p->count;
  1195. if (!ops->vidioc_try_ext_ctrls)
  1196. break;
  1197. v4l_print_ext_ctrls(cmd, vfd, p, 1);
  1198. if (check_ext_ctrls(p, 0))
  1199. ret = ops->vidioc_try_ext_ctrls(file, fh, p);
  1200. break;
  1201. }
  1202. case VIDIOC_QUERYMENU:
  1203. {
  1204. struct v4l2_querymenu *p = arg;
  1205. if (!ops->vidioc_querymenu)
  1206. break;
  1207. ret = ops->vidioc_querymenu(file, fh, p);
  1208. if (!ret)
  1209. dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
  1210. p->id, p->index, p->name);
  1211. else
  1212. dbgarg(cmd, "id=0x%x, index=%d\n",
  1213. p->id, p->index);
  1214. break;
  1215. }
  1216. /* --- audio ---------------------------------------------- */
  1217. case VIDIOC_ENUMAUDIO:
  1218. {
  1219. struct v4l2_audio *p = arg;
  1220. if (!ops->vidioc_enumaudio)
  1221. break;
  1222. ret = ops->vidioc_enumaudio(file, fh, p);
  1223. if (!ret)
  1224. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1225. "mode=0x%x\n", p->index, p->name,
  1226. p->capability, p->mode);
  1227. else
  1228. dbgarg(cmd, "index=%d\n", p->index);
  1229. break;
  1230. }
  1231. case VIDIOC_G_AUDIO:
  1232. {
  1233. struct v4l2_audio *p = arg;
  1234. if (!ops->vidioc_g_audio)
  1235. break;
  1236. ret = ops->vidioc_g_audio(file, fh, p);
  1237. if (!ret)
  1238. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1239. "mode=0x%x\n", p->index,
  1240. p->name, p->capability, p->mode);
  1241. else
  1242. dbgarg(cmd, "index=%d\n", p->index);
  1243. break;
  1244. }
  1245. case VIDIOC_S_AUDIO:
  1246. {
  1247. struct v4l2_audio *p = arg;
  1248. if (!ops->vidioc_s_audio)
  1249. break;
  1250. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1251. "mode=0x%x\n", p->index, p->name,
  1252. p->capability, p->mode);
  1253. ret = ops->vidioc_s_audio(file, fh, p);
  1254. break;
  1255. }
  1256. case VIDIOC_ENUMAUDOUT:
  1257. {
  1258. struct v4l2_audioout *p = arg;
  1259. if (!ops->vidioc_enumaudout)
  1260. break;
  1261. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1262. ret = ops->vidioc_enumaudout(file, fh, p);
  1263. if (!ret)
  1264. dbgarg2("index=%d, name=%s, capability=%d, "
  1265. "mode=%d\n", p->index, p->name,
  1266. p->capability, p->mode);
  1267. break;
  1268. }
  1269. case VIDIOC_G_AUDOUT:
  1270. {
  1271. struct v4l2_audioout *p = arg;
  1272. if (!ops->vidioc_g_audout)
  1273. break;
  1274. ret = ops->vidioc_g_audout(file, fh, p);
  1275. if (!ret)
  1276. dbgarg2("index=%d, name=%s, capability=%d, "
  1277. "mode=%d\n", p->index, p->name,
  1278. p->capability, p->mode);
  1279. break;
  1280. }
  1281. case VIDIOC_S_AUDOUT:
  1282. {
  1283. struct v4l2_audioout *p = arg;
  1284. if (!ops->vidioc_s_audout)
  1285. break;
  1286. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1287. "mode=%d\n", p->index, p->name,
  1288. p->capability, p->mode);
  1289. ret = ops->vidioc_s_audout(file, fh, p);
  1290. break;
  1291. }
  1292. case VIDIOC_G_MODULATOR:
  1293. {
  1294. struct v4l2_modulator *p = arg;
  1295. if (!ops->vidioc_g_modulator)
  1296. break;
  1297. ret = ops->vidioc_g_modulator(file, fh, p);
  1298. if (!ret)
  1299. dbgarg(cmd, "index=%d, name=%s, "
  1300. "capability=%d, rangelow=%d,"
  1301. " rangehigh=%d, txsubchans=%d\n",
  1302. p->index, p->name, p->capability,
  1303. p->rangelow, p->rangehigh,
  1304. p->txsubchans);
  1305. break;
  1306. }
  1307. case VIDIOC_S_MODULATOR:
  1308. {
  1309. struct v4l2_modulator *p = arg;
  1310. if (!ops->vidioc_s_modulator)
  1311. break;
  1312. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1313. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1314. p->index, p->name, p->capability, p->rangelow,
  1315. p->rangehigh, p->txsubchans);
  1316. ret = ops->vidioc_s_modulator(file, fh, p);
  1317. break;
  1318. }
  1319. case VIDIOC_G_CROP:
  1320. {
  1321. struct v4l2_crop *p = arg;
  1322. if (!ops->vidioc_g_crop)
  1323. break;
  1324. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1325. ret = ops->vidioc_g_crop(file, fh, p);
  1326. if (!ret)
  1327. dbgrect(vfd, "", &p->c);
  1328. break;
  1329. }
  1330. case VIDIOC_S_CROP:
  1331. {
  1332. struct v4l2_crop *p = arg;
  1333. if (!ops->vidioc_s_crop)
  1334. break;
  1335. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1336. dbgrect(vfd, "", &p->c);
  1337. ret = ops->vidioc_s_crop(file, fh, p);
  1338. break;
  1339. }
  1340. case VIDIOC_CROPCAP:
  1341. {
  1342. struct v4l2_cropcap *p = arg;
  1343. /*FIXME: Should also show v4l2_fract pixelaspect */
  1344. if (!ops->vidioc_cropcap)
  1345. break;
  1346. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1347. ret = ops->vidioc_cropcap(file, fh, p);
  1348. if (!ret) {
  1349. dbgrect(vfd, "bounds ", &p->bounds);
  1350. dbgrect(vfd, "defrect ", &p->defrect);
  1351. }
  1352. break;
  1353. }
  1354. case VIDIOC_G_JPEGCOMP:
  1355. {
  1356. struct v4l2_jpegcompression *p = arg;
  1357. if (!ops->vidioc_g_jpegcomp)
  1358. break;
  1359. ret = ops->vidioc_g_jpegcomp(file, fh, p);
  1360. if (!ret)
  1361. dbgarg(cmd, "quality=%d, APPn=%d, "
  1362. "APP_len=%d, COM_len=%d, "
  1363. "jpeg_markers=%d\n",
  1364. p->quality, p->APPn, p->APP_len,
  1365. p->COM_len, p->jpeg_markers);
  1366. break;
  1367. }
  1368. case VIDIOC_S_JPEGCOMP:
  1369. {
  1370. struct v4l2_jpegcompression *p = arg;
  1371. if (!ops->vidioc_g_jpegcomp)
  1372. break;
  1373. dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1374. "COM_len=%d, jpeg_markers=%d\n",
  1375. p->quality, p->APPn, p->APP_len,
  1376. p->COM_len, p->jpeg_markers);
  1377. ret = ops->vidioc_s_jpegcomp(file, fh, p);
  1378. break;
  1379. }
  1380. case VIDIOC_G_ENC_INDEX:
  1381. {
  1382. struct v4l2_enc_idx *p = arg;
  1383. if (!ops->vidioc_g_enc_index)
  1384. break;
  1385. ret = ops->vidioc_g_enc_index(file, fh, p);
  1386. if (!ret)
  1387. dbgarg(cmd, "entries=%d, entries_cap=%d\n",
  1388. p->entries, p->entries_cap);
  1389. break;
  1390. }
  1391. case VIDIOC_ENCODER_CMD:
  1392. {
  1393. struct v4l2_encoder_cmd *p = arg;
  1394. if (!ops->vidioc_encoder_cmd)
  1395. break;
  1396. ret = ops->vidioc_encoder_cmd(file, fh, p);
  1397. if (!ret)
  1398. dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
  1399. break;
  1400. }
  1401. case VIDIOC_TRY_ENCODER_CMD:
  1402. {
  1403. struct v4l2_encoder_cmd *p = arg;
  1404. if (!ops->vidioc_try_encoder_cmd)
  1405. break;
  1406. ret = ops->vidioc_try_encoder_cmd(file, fh, p);
  1407. if (!ret)
  1408. dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
  1409. break;
  1410. }
  1411. case VIDIOC_G_PARM:
  1412. {
  1413. struct v4l2_streamparm *p = arg;
  1414. if (ops->vidioc_g_parm) {
  1415. ret = check_fmt(ops, p->type);
  1416. if (ret)
  1417. break;
  1418. ret = ops->vidioc_g_parm(file, fh, p);
  1419. } else {
  1420. v4l2_std_id std = vfd->current_norm;
  1421. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1422. return -EINVAL;
  1423. ret = 0;
  1424. if (ops->vidioc_g_std)
  1425. ret = ops->vidioc_g_std(file, fh, &std);
  1426. else if (std == 0)
  1427. ret = -EINVAL;
  1428. if (ret == 0)
  1429. v4l2_video_std_frame_period(std,
  1430. &p->parm.capture.timeperframe);
  1431. }
  1432. dbgarg(cmd, "type=%d\n", p->type);
  1433. break;
  1434. }
  1435. case VIDIOC_S_PARM:
  1436. {
  1437. struct v4l2_streamparm *p = arg;
  1438. if (!ops->vidioc_s_parm)
  1439. break;
  1440. ret = check_fmt(ops, p->type);
  1441. if (ret)
  1442. break;
  1443. dbgarg(cmd, "type=%d\n", p->type);
  1444. ret = ops->vidioc_s_parm(file, fh, p);
  1445. break;
  1446. }
  1447. case VIDIOC_G_TUNER:
  1448. {
  1449. struct v4l2_tuner *p = arg;
  1450. if (!ops->vidioc_g_tuner)
  1451. break;
  1452. ret = ops->vidioc_g_tuner(file, fh, p);
  1453. if (!ret)
  1454. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1455. "capability=0x%x, rangelow=%d, "
  1456. "rangehigh=%d, signal=%d, afc=%d, "
  1457. "rxsubchans=0x%x, audmode=%d\n",
  1458. p->index, p->name, p->type,
  1459. p->capability, p->rangelow,
  1460. p->rangehigh, p->signal, p->afc,
  1461. p->rxsubchans, p->audmode);
  1462. break;
  1463. }
  1464. case VIDIOC_S_TUNER:
  1465. {
  1466. struct v4l2_tuner *p = arg;
  1467. if (!ops->vidioc_s_tuner)
  1468. break;
  1469. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1470. "capability=0x%x, rangelow=%d, "
  1471. "rangehigh=%d, signal=%d, afc=%d, "
  1472. "rxsubchans=0x%x, audmode=%d\n",
  1473. p->index, p->name, p->type,
  1474. p->capability, p->rangelow,
  1475. p->rangehigh, p->signal, p->afc,
  1476. p->rxsubchans, p->audmode);
  1477. ret = ops->vidioc_s_tuner(file, fh, p);
  1478. break;
  1479. }
  1480. case VIDIOC_G_FREQUENCY:
  1481. {
  1482. struct v4l2_frequency *p = arg;
  1483. if (!ops->vidioc_g_frequency)
  1484. break;
  1485. ret = ops->vidioc_g_frequency(file, fh, p);
  1486. if (!ret)
  1487. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1488. p->tuner, p->type, p->frequency);
  1489. break;
  1490. }
  1491. case VIDIOC_S_FREQUENCY:
  1492. {
  1493. struct v4l2_frequency *p = arg;
  1494. if (!ops->vidioc_s_frequency)
  1495. break;
  1496. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1497. p->tuner, p->type, p->frequency);
  1498. ret = ops->vidioc_s_frequency(file, fh, p);
  1499. break;
  1500. }
  1501. case VIDIOC_G_SLICED_VBI_CAP:
  1502. {
  1503. struct v4l2_sliced_vbi_cap *p = arg;
  1504. if (!ops->vidioc_g_sliced_vbi_cap)
  1505. break;
  1506. /* Clear up to type, everything after type is zerod already */
  1507. memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
  1508. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1509. ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
  1510. if (!ret)
  1511. dbgarg2("service_set=%d\n", p->service_set);
  1512. break;
  1513. }
  1514. case VIDIOC_LOG_STATUS:
  1515. {
  1516. if (!ops->vidioc_log_status)
  1517. break;
  1518. ret = ops->vidioc_log_status(file, fh);
  1519. break;
  1520. }
  1521. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1522. case VIDIOC_DBG_G_REGISTER:
  1523. {
  1524. struct v4l2_dbg_register *p = arg;
  1525. if (!capable(CAP_SYS_ADMIN))
  1526. ret = -EPERM;
  1527. else if (ops->vidioc_g_register)
  1528. ret = ops->vidioc_g_register(file, fh, p);
  1529. break;
  1530. }
  1531. case VIDIOC_DBG_S_REGISTER:
  1532. {
  1533. struct v4l2_dbg_register *p = arg;
  1534. if (!capable(CAP_SYS_ADMIN))
  1535. ret = -EPERM;
  1536. else if (ops->vidioc_s_register)
  1537. ret = ops->vidioc_s_register(file, fh, p);
  1538. break;
  1539. }
  1540. #endif
  1541. case VIDIOC_DBG_G_CHIP_IDENT:
  1542. {
  1543. struct v4l2_dbg_chip_ident *p = arg;
  1544. if (!ops->vidioc_g_chip_ident)
  1545. break;
  1546. p->ident = V4L2_IDENT_NONE;
  1547. p->revision = 0;
  1548. ret = ops->vidioc_g_chip_ident(file, fh, p);
  1549. if (!ret)
  1550. dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
  1551. break;
  1552. }
  1553. case VIDIOC_S_HW_FREQ_SEEK:
  1554. {
  1555. struct v4l2_hw_freq_seek *p = arg;
  1556. if (!ops->vidioc_s_hw_freq_seek)
  1557. break;
  1558. dbgarg(cmd,
  1559. "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
  1560. p->tuner, p->type, p->seek_upward, p->wrap_around);
  1561. ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
  1562. break;
  1563. }
  1564. case VIDIOC_ENUM_FRAMESIZES:
  1565. {
  1566. struct v4l2_frmsizeenum *p = arg;
  1567. if (!ops->vidioc_enum_framesizes)
  1568. break;
  1569. ret = ops->vidioc_enum_framesizes(file, fh, p);
  1570. dbgarg(cmd,
  1571. "index=%d, pixelformat=%c%c%c%c, type=%d ",
  1572. p->index,
  1573. (p->pixel_format & 0xff),
  1574. (p->pixel_format >> 8) & 0xff,
  1575. (p->pixel_format >> 16) & 0xff,
  1576. (p->pixel_format >> 24) & 0xff,
  1577. p->type);
  1578. switch (p->type) {
  1579. case V4L2_FRMSIZE_TYPE_DISCRETE:
  1580. printk("width = %d, height=%d\n",
  1581. p->discrete.width, p->discrete.height);
  1582. break;
  1583. case V4L2_FRMSIZE_TYPE_STEPWISE:
  1584. printk("min %dx%d, max %dx%d, step %dx%d\n",
  1585. p->stepwise.min_width, p->stepwise.min_height,
  1586. p->stepwise.step_width, p->stepwise.step_height,
  1587. p->stepwise.max_width, p->stepwise.max_height);
  1588. break;
  1589. case V4L2_FRMSIZE_TYPE_CONTINUOUS:
  1590. printk("continuous\n");
  1591. break;
  1592. default:
  1593. printk("- Unknown type!\n");
  1594. }
  1595. break;
  1596. }
  1597. case VIDIOC_ENUM_FRAMEINTERVALS:
  1598. {
  1599. struct v4l2_frmivalenum *p = arg;
  1600. if (!ops->vidioc_enum_frameintervals)
  1601. break;
  1602. ret = ops->vidioc_enum_frameintervals(file, fh, p);
  1603. dbgarg(cmd,
  1604. "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
  1605. p->index, p->pixel_format,
  1606. p->width, p->height, p->type);
  1607. switch (p->type) {
  1608. case V4L2_FRMIVAL_TYPE_DISCRETE:
  1609. dbgarg2("fps=%d/%d\n",
  1610. p->discrete.numerator,
  1611. p->discrete.denominator);
  1612. break;
  1613. case V4L2_FRMIVAL_TYPE_STEPWISE:
  1614. dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
  1615. p->stepwise.min.numerator,
  1616. p->stepwise.min.denominator,
  1617. p->stepwise.max.numerator,
  1618. p->stepwise.max.denominator,
  1619. p->stepwise.step.numerator,
  1620. p->stepwise.step.denominator);
  1621. break;
  1622. case V4L2_FRMIVAL_TYPE_CONTINUOUS:
  1623. dbgarg2("continuous\n");
  1624. break;
  1625. default:
  1626. dbgarg2("- Unknown type!\n");
  1627. }
  1628. break;
  1629. }
  1630. default:
  1631. {
  1632. if (!ops->vidioc_default)
  1633. break;
  1634. ret = ops->vidioc_default(file, fh, cmd, arg);
  1635. break;
  1636. }
  1637. } /* switch */
  1638. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1639. if (ret < 0) {
  1640. v4l_print_ioctl(vfd->name, cmd);
  1641. printk(KERN_CONT " error %ld\n", ret);
  1642. }
  1643. }
  1644. return ret;
  1645. }
  1646. /* In some cases, only a few fields are used as input, i.e. when the app sets
  1647. * "index" and then the driver fills in the rest of the structure for the thing
  1648. * with that index. We only need to copy up the first non-input field. */
  1649. static unsigned long cmd_input_size(unsigned int cmd)
  1650. {
  1651. /* Size of structure up to and including 'field' */
  1652. #define CMDINSIZE(cmd, type, field) \
  1653. case VIDIOC_##cmd: \
  1654. return offsetof(struct v4l2_##type, field) + \
  1655. sizeof(((struct v4l2_##type *)0)->field);
  1656. switch (cmd) {
  1657. CMDINSIZE(ENUM_FMT, fmtdesc, type);
  1658. CMDINSIZE(G_FMT, format, type);
  1659. CMDINSIZE(QUERYBUF, buffer, type);
  1660. CMDINSIZE(G_PARM, streamparm, type);
  1661. CMDINSIZE(ENUMSTD, standard, index);
  1662. CMDINSIZE(ENUMINPUT, input, index);
  1663. CMDINSIZE(G_CTRL, control, id);
  1664. CMDINSIZE(G_TUNER, tuner, index);
  1665. CMDINSIZE(QUERYCTRL, queryctrl, id);
  1666. CMDINSIZE(QUERYMENU, querymenu, index);
  1667. CMDINSIZE(ENUMOUTPUT, output, index);
  1668. CMDINSIZE(G_MODULATOR, modulator, index);
  1669. CMDINSIZE(G_FREQUENCY, frequency, tuner);
  1670. CMDINSIZE(CROPCAP, cropcap, type);
  1671. CMDINSIZE(G_CROP, crop, type);
  1672. CMDINSIZE(ENUMAUDIO, audio, index);
  1673. CMDINSIZE(ENUMAUDOUT, audioout, index);
  1674. CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
  1675. CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
  1676. CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
  1677. CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
  1678. CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
  1679. default:
  1680. return _IOC_SIZE(cmd);
  1681. }
  1682. }
  1683. long video_ioctl2(struct file *file,
  1684. unsigned int cmd, unsigned long arg)
  1685. {
  1686. char sbuf[128];
  1687. void *mbuf = NULL;
  1688. void *parg = NULL;
  1689. long err = -EINVAL;
  1690. int is_ext_ctrl;
  1691. size_t ctrls_size = 0;
  1692. void __user *user_ptr = NULL;
  1693. #ifdef __OLD_VIDIOC_
  1694. cmd = video_fix_command(cmd);
  1695. #endif
  1696. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1697. cmd == VIDIOC_TRY_EXT_CTRLS);
  1698. /* Copy arguments into temp kernel buffer */
  1699. if (_IOC_DIR(cmd) != _IOC_NONE) {
  1700. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1701. parg = sbuf;
  1702. } else {
  1703. /* too big to allocate from stack */
  1704. mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
  1705. if (NULL == mbuf)
  1706. return -ENOMEM;
  1707. parg = mbuf;
  1708. }
  1709. err = -EFAULT;
  1710. if (_IOC_DIR(cmd) & _IOC_WRITE) {
  1711. unsigned long n = cmd_input_size(cmd);
  1712. if (copy_from_user(parg, (void __user *)arg, n))
  1713. goto out;
  1714. /* zero out anything we don't copy from userspace */
  1715. if (n < _IOC_SIZE(cmd))
  1716. memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
  1717. } else {
  1718. /* read-only ioctl */
  1719. memset(parg, 0, _IOC_SIZE(cmd));
  1720. }
  1721. }
  1722. if (is_ext_ctrl) {
  1723. struct v4l2_ext_controls *p = parg;
  1724. /* In case of an error, tell the caller that it wasn't
  1725. a specific control that caused it. */
  1726. p->error_idx = p->count;
  1727. user_ptr = (void __user *)p->controls;
  1728. if (p->count) {
  1729. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1730. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1731. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1732. err = -ENOMEM;
  1733. if (NULL == mbuf)
  1734. goto out_ext_ctrl;
  1735. err = -EFAULT;
  1736. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1737. goto out_ext_ctrl;
  1738. p->controls = mbuf;
  1739. }
  1740. }
  1741. /* Handles IOCTL */
  1742. err = __video_do_ioctl(file, cmd, parg);
  1743. if (err == -ENOIOCTLCMD)
  1744. err = -EINVAL;
  1745. if (is_ext_ctrl) {
  1746. struct v4l2_ext_controls *p = parg;
  1747. p->controls = (void *)user_ptr;
  1748. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1749. err = -EFAULT;
  1750. goto out_ext_ctrl;
  1751. }
  1752. if (err < 0)
  1753. goto out;
  1754. out_ext_ctrl:
  1755. /* Copy results into user buffer */
  1756. switch (_IOC_DIR(cmd)) {
  1757. case _IOC_READ:
  1758. case (_IOC_WRITE | _IOC_READ):
  1759. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1760. err = -EFAULT;
  1761. break;
  1762. }
  1763. out:
  1764. kfree(mbuf);
  1765. return err;
  1766. }
  1767. EXPORT_SYMBOL(video_ioctl2);