v4l2-ioctl.c 54 KB

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