v4l2-ioctl.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  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 ((vfd->debug & V4L2_DEBUG_IOCTL) &&
  563. !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
  564. v4l_print_ioctl(vfd->name, cmd);
  565. printk(KERN_CONT "\n");
  566. }
  567. if (ops == NULL) {
  568. printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
  569. vfd->name);
  570. return -EINVAL;
  571. }
  572. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  573. /***********************************************************
  574. Handles calls to the obsoleted V4L1 API
  575. Due to the nature of VIDIOCGMBUF, each driver that supports
  576. V4L1 should implement its own handler for this ioctl.
  577. ***********************************************************/
  578. /* --- streaming capture ------------------------------------- */
  579. if (cmd == VIDIOCGMBUF) {
  580. struct video_mbuf *p = arg;
  581. if (!ops->vidiocgmbuf)
  582. return ret;
  583. ret = ops->vidiocgmbuf(file, fh, p);
  584. if (!ret)
  585. dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
  586. p->size, p->frames,
  587. (unsigned long)p->offsets);
  588. return ret;
  589. }
  590. /********************************************************
  591. All other V4L1 calls are handled by v4l1_compat module.
  592. Those calls will be translated into V4L2 calls, and
  593. __video_do_ioctl will be called again, with one or more
  594. V4L2 ioctls.
  595. ********************************************************/
  596. if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
  597. return v4l_compat_translate_ioctl(file, cmd, arg,
  598. __video_do_ioctl);
  599. #endif
  600. switch (cmd) {
  601. /* --- capabilities ------------------------------------------ */
  602. case VIDIOC_QUERYCAP:
  603. {
  604. struct v4l2_capability *cap = (struct v4l2_capability *)arg;
  605. if (!ops->vidioc_querycap)
  606. break;
  607. ret = ops->vidioc_querycap(file, fh, cap);
  608. if (!ret)
  609. dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
  610. "version=0x%08x, "
  611. "capabilities=0x%08x\n",
  612. cap->driver, cap->card, cap->bus_info,
  613. cap->version,
  614. cap->capabilities);
  615. break;
  616. }
  617. /* --- priority ------------------------------------------ */
  618. case VIDIOC_G_PRIORITY:
  619. {
  620. enum v4l2_priority *p = arg;
  621. if (!ops->vidioc_g_priority)
  622. break;
  623. ret = ops->vidioc_g_priority(file, fh, p);
  624. if (!ret)
  625. dbgarg(cmd, "priority is %d\n", *p);
  626. break;
  627. }
  628. case VIDIOC_S_PRIORITY:
  629. {
  630. enum v4l2_priority *p = arg;
  631. if (!ops->vidioc_s_priority)
  632. break;
  633. dbgarg(cmd, "setting priority to %d\n", *p);
  634. ret = ops->vidioc_s_priority(file, fh, *p);
  635. break;
  636. }
  637. /* --- capture ioctls ---------------------------------------- */
  638. case VIDIOC_ENUM_FMT:
  639. {
  640. struct v4l2_fmtdesc *f = arg;
  641. switch (f->type) {
  642. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  643. if (ops->vidioc_enum_fmt_vid_cap)
  644. ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
  645. break;
  646. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  647. if (ops->vidioc_enum_fmt_vid_overlay)
  648. ret = ops->vidioc_enum_fmt_vid_overlay(file,
  649. fh, f);
  650. break;
  651. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  652. if (ops->vidioc_enum_fmt_vid_out)
  653. ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
  654. break;
  655. case V4L2_BUF_TYPE_PRIVATE:
  656. if (ops->vidioc_enum_fmt_type_private)
  657. ret = ops->vidioc_enum_fmt_type_private(file,
  658. fh, f);
  659. break;
  660. default:
  661. break;
  662. }
  663. if (!ret)
  664. dbgarg(cmd, "index=%d, type=%d, flags=%d, "
  665. "pixelformat=%c%c%c%c, description='%s'\n",
  666. f->index, f->type, f->flags,
  667. (f->pixelformat & 0xff),
  668. (f->pixelformat >> 8) & 0xff,
  669. (f->pixelformat >> 16) & 0xff,
  670. (f->pixelformat >> 24) & 0xff,
  671. f->description);
  672. break;
  673. }
  674. case VIDIOC_G_FMT:
  675. {
  676. struct v4l2_format *f = (struct v4l2_format *)arg;
  677. /* FIXME: Should be one dump per type */
  678. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  679. switch (f->type) {
  680. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  681. if (ops->vidioc_g_fmt_vid_cap)
  682. ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
  683. if (!ret)
  684. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  685. break;
  686. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  687. if (ops->vidioc_g_fmt_vid_overlay)
  688. ret = ops->vidioc_g_fmt_vid_overlay(file,
  689. fh, f);
  690. break;
  691. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  692. if (ops->vidioc_g_fmt_vid_out)
  693. ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
  694. if (!ret)
  695. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  696. break;
  697. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  698. if (ops->vidioc_g_fmt_vid_out_overlay)
  699. ret = ops->vidioc_g_fmt_vid_out_overlay(file,
  700. fh, f);
  701. break;
  702. case V4L2_BUF_TYPE_VBI_CAPTURE:
  703. if (ops->vidioc_g_fmt_vbi_cap)
  704. ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
  705. break;
  706. case V4L2_BUF_TYPE_VBI_OUTPUT:
  707. if (ops->vidioc_g_fmt_vbi_out)
  708. ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
  709. break;
  710. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  711. if (ops->vidioc_g_fmt_sliced_vbi_cap)
  712. ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
  713. fh, f);
  714. break;
  715. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  716. if (ops->vidioc_g_fmt_sliced_vbi_out)
  717. ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
  718. fh, f);
  719. break;
  720. case V4L2_BUF_TYPE_PRIVATE:
  721. if (ops->vidioc_g_fmt_type_private)
  722. ret = ops->vidioc_g_fmt_type_private(file,
  723. fh, f);
  724. break;
  725. }
  726. break;
  727. }
  728. case VIDIOC_S_FMT:
  729. {
  730. struct v4l2_format *f = (struct v4l2_format *)arg;
  731. /* FIXME: Should be one dump per type */
  732. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  733. switch (f->type) {
  734. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  735. CLEAR_AFTER_FIELD(f, fmt.pix);
  736. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  737. if (ops->vidioc_s_fmt_vid_cap)
  738. ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
  739. break;
  740. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  741. CLEAR_AFTER_FIELD(f, fmt.win);
  742. if (ops->vidioc_s_fmt_vid_overlay)
  743. ret = ops->vidioc_s_fmt_vid_overlay(file,
  744. fh, f);
  745. break;
  746. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  747. CLEAR_AFTER_FIELD(f, fmt.pix);
  748. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  749. if (ops->vidioc_s_fmt_vid_out)
  750. ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
  751. break;
  752. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  753. CLEAR_AFTER_FIELD(f, fmt.win);
  754. if (ops->vidioc_s_fmt_vid_out_overlay)
  755. ret = ops->vidioc_s_fmt_vid_out_overlay(file,
  756. fh, f);
  757. break;
  758. case V4L2_BUF_TYPE_VBI_CAPTURE:
  759. CLEAR_AFTER_FIELD(f, fmt.vbi);
  760. if (ops->vidioc_s_fmt_vbi_cap)
  761. ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
  762. break;
  763. case V4L2_BUF_TYPE_VBI_OUTPUT:
  764. CLEAR_AFTER_FIELD(f, fmt.vbi);
  765. if (ops->vidioc_s_fmt_vbi_out)
  766. ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
  767. break;
  768. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  769. CLEAR_AFTER_FIELD(f, fmt.sliced);
  770. if (ops->vidioc_s_fmt_sliced_vbi_cap)
  771. ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
  772. fh, f);
  773. break;
  774. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  775. CLEAR_AFTER_FIELD(f, fmt.sliced);
  776. if (ops->vidioc_s_fmt_sliced_vbi_out)
  777. ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
  778. fh, f);
  779. break;
  780. case V4L2_BUF_TYPE_PRIVATE:
  781. /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
  782. if (ops->vidioc_s_fmt_type_private)
  783. ret = ops->vidioc_s_fmt_type_private(file,
  784. fh, f);
  785. break;
  786. }
  787. break;
  788. }
  789. case VIDIOC_TRY_FMT:
  790. {
  791. struct v4l2_format *f = (struct v4l2_format *)arg;
  792. /* FIXME: Should be one dump per type */
  793. dbgarg(cmd, "type=%s\n", prt_names(f->type,
  794. v4l2_type_names));
  795. switch (f->type) {
  796. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  797. CLEAR_AFTER_FIELD(f, fmt.pix);
  798. if (ops->vidioc_try_fmt_vid_cap)
  799. ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
  800. if (!ret)
  801. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  802. break;
  803. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  804. CLEAR_AFTER_FIELD(f, fmt.win);
  805. if (ops->vidioc_try_fmt_vid_overlay)
  806. ret = ops->vidioc_try_fmt_vid_overlay(file,
  807. fh, f);
  808. break;
  809. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  810. CLEAR_AFTER_FIELD(f, fmt.pix);
  811. if (ops->vidioc_try_fmt_vid_out)
  812. ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
  813. if (!ret)
  814. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  815. break;
  816. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  817. CLEAR_AFTER_FIELD(f, fmt.win);
  818. if (ops->vidioc_try_fmt_vid_out_overlay)
  819. ret = ops->vidioc_try_fmt_vid_out_overlay(file,
  820. fh, f);
  821. break;
  822. case V4L2_BUF_TYPE_VBI_CAPTURE:
  823. CLEAR_AFTER_FIELD(f, fmt.vbi);
  824. if (ops->vidioc_try_fmt_vbi_cap)
  825. ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
  826. break;
  827. case V4L2_BUF_TYPE_VBI_OUTPUT:
  828. CLEAR_AFTER_FIELD(f, fmt.vbi);
  829. if (ops->vidioc_try_fmt_vbi_out)
  830. ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
  831. break;
  832. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  833. CLEAR_AFTER_FIELD(f, fmt.sliced);
  834. if (ops->vidioc_try_fmt_sliced_vbi_cap)
  835. ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
  836. fh, f);
  837. break;
  838. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  839. CLEAR_AFTER_FIELD(f, fmt.sliced);
  840. if (ops->vidioc_try_fmt_sliced_vbi_out)
  841. ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
  842. fh, f);
  843. break;
  844. case V4L2_BUF_TYPE_PRIVATE:
  845. /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
  846. if (ops->vidioc_try_fmt_type_private)
  847. ret = ops->vidioc_try_fmt_type_private(file,
  848. fh, f);
  849. break;
  850. }
  851. break;
  852. }
  853. /* FIXME: Those buf reqs could be handled here,
  854. with some changes on videobuf to allow its header to be included at
  855. videodev2.h or being merged at videodev2.
  856. */
  857. case VIDIOC_REQBUFS:
  858. {
  859. struct v4l2_requestbuffers *p = arg;
  860. if (!ops->vidioc_reqbufs)
  861. break;
  862. ret = check_fmt(ops, p->type);
  863. if (ret)
  864. break;
  865. if (p->type < V4L2_BUF_TYPE_PRIVATE)
  866. CLEAR_AFTER_FIELD(p, memory);
  867. ret = ops->vidioc_reqbufs(file, fh, p);
  868. dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
  869. p->count,
  870. prt_names(p->type, v4l2_type_names),
  871. prt_names(p->memory, v4l2_memory_names));
  872. break;
  873. }
  874. case VIDIOC_QUERYBUF:
  875. {
  876. struct v4l2_buffer *p = arg;
  877. if (!ops->vidioc_querybuf)
  878. break;
  879. ret = check_fmt(ops, p->type);
  880. if (ret)
  881. break;
  882. ret = ops->vidioc_querybuf(file, fh, p);
  883. if (!ret)
  884. dbgbuf(cmd, vfd, p);
  885. break;
  886. }
  887. case VIDIOC_QBUF:
  888. {
  889. struct v4l2_buffer *p = arg;
  890. if (!ops->vidioc_qbuf)
  891. break;
  892. ret = check_fmt(ops, p->type);
  893. if (ret)
  894. break;
  895. ret = ops->vidioc_qbuf(file, fh, p);
  896. if (!ret)
  897. dbgbuf(cmd, vfd, p);
  898. break;
  899. }
  900. case VIDIOC_DQBUF:
  901. {
  902. struct v4l2_buffer *p = arg;
  903. if (!ops->vidioc_dqbuf)
  904. break;
  905. ret = check_fmt(ops, p->type);
  906. if (ret)
  907. break;
  908. ret = ops->vidioc_dqbuf(file, fh, p);
  909. if (!ret)
  910. dbgbuf(cmd, vfd, p);
  911. break;
  912. }
  913. case VIDIOC_OVERLAY:
  914. {
  915. int *i = arg;
  916. if (!ops->vidioc_overlay)
  917. break;
  918. dbgarg(cmd, "value=%d\n", *i);
  919. ret = ops->vidioc_overlay(file, fh, *i);
  920. break;
  921. }
  922. case VIDIOC_G_FBUF:
  923. {
  924. struct v4l2_framebuffer *p = arg;
  925. if (!ops->vidioc_g_fbuf)
  926. break;
  927. ret = ops->vidioc_g_fbuf(file, fh, arg);
  928. if (!ret) {
  929. dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
  930. p->capability, p->flags,
  931. (unsigned long)p->base);
  932. v4l_print_pix_fmt(vfd, &p->fmt);
  933. }
  934. break;
  935. }
  936. case VIDIOC_S_FBUF:
  937. {
  938. struct v4l2_framebuffer *p = arg;
  939. if (!ops->vidioc_s_fbuf)
  940. break;
  941. dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
  942. p->capability, p->flags, (unsigned long)p->base);
  943. v4l_print_pix_fmt(vfd, &p->fmt);
  944. ret = ops->vidioc_s_fbuf(file, fh, arg);
  945. break;
  946. }
  947. case VIDIOC_STREAMON:
  948. {
  949. enum v4l2_buf_type i = *(int *)arg;
  950. if (!ops->vidioc_streamon)
  951. break;
  952. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  953. ret = ops->vidioc_streamon(file, fh, i);
  954. break;
  955. }
  956. case VIDIOC_STREAMOFF:
  957. {
  958. enum v4l2_buf_type i = *(int *)arg;
  959. if (!ops->vidioc_streamoff)
  960. break;
  961. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  962. ret = ops->vidioc_streamoff(file, fh, i);
  963. break;
  964. }
  965. /* ---------- tv norms ---------- */
  966. case VIDIOC_ENUMSTD:
  967. {
  968. struct v4l2_standard *p = arg;
  969. v4l2_std_id id = vfd->tvnorms, curr_id = 0;
  970. unsigned int index = p->index, i, j = 0;
  971. const char *descr = "";
  972. /* Return norm array in a canonical way */
  973. for (i = 0; i <= index && id; i++) {
  974. /* last std value in the standards array is 0, so this
  975. while always ends there since (id & 0) == 0. */
  976. while ((id & standards[j].std) != standards[j].std)
  977. j++;
  978. curr_id = standards[j].std;
  979. descr = standards[j].descr;
  980. j++;
  981. if (curr_id == 0)
  982. break;
  983. if (curr_id != V4L2_STD_PAL &&
  984. curr_id != V4L2_STD_SECAM &&
  985. curr_id != V4L2_STD_NTSC)
  986. id &= ~curr_id;
  987. }
  988. if (i <= index)
  989. return -EINVAL;
  990. v4l2_video_std_construct(p, curr_id, descr);
  991. dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
  992. "framelines=%d\n", p->index,
  993. (unsigned long long)p->id, p->name,
  994. p->frameperiod.numerator,
  995. p->frameperiod.denominator,
  996. p->framelines);
  997. ret = 0;
  998. break;
  999. }
  1000. case VIDIOC_G_STD:
  1001. {
  1002. v4l2_std_id *id = arg;
  1003. ret = 0;
  1004. /* Calls the specific handler */
  1005. if (ops->vidioc_g_std)
  1006. ret = ops->vidioc_g_std(file, fh, id);
  1007. else if (vfd->current_norm)
  1008. *id = vfd->current_norm;
  1009. else
  1010. ret = -EINVAL;
  1011. if (!ret)
  1012. dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
  1013. break;
  1014. }
  1015. case VIDIOC_S_STD:
  1016. {
  1017. v4l2_std_id *id = arg, norm;
  1018. dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
  1019. norm = (*id) & vfd->tvnorms;
  1020. if (vfd->tvnorms && !norm) /* Check if std is supported */
  1021. break;
  1022. /* Calls the specific handler */
  1023. if (ops->vidioc_s_std)
  1024. ret = ops->vidioc_s_std(file, fh, &norm);
  1025. else
  1026. ret = -EINVAL;
  1027. /* Updates standard information */
  1028. if (ret >= 0)
  1029. vfd->current_norm = norm;
  1030. break;
  1031. }
  1032. case VIDIOC_QUERYSTD:
  1033. {
  1034. v4l2_std_id *p = arg;
  1035. if (!ops->vidioc_querystd)
  1036. break;
  1037. ret = ops->vidioc_querystd(file, fh, arg);
  1038. if (!ret)
  1039. dbgarg(cmd, "detected std=%08Lx\n",
  1040. (unsigned long long)*p);
  1041. break;
  1042. }
  1043. /* ------ input switching ---------- */
  1044. /* FIXME: Inputs can be handled inside videodev2 */
  1045. case VIDIOC_ENUMINPUT:
  1046. {
  1047. struct v4l2_input *p = arg;
  1048. /*
  1049. * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
  1050. * CAP_STD here based on ioctl handler provided by the
  1051. * driver. If the driver doesn't support these
  1052. * for a specific input, it must override these flags.
  1053. */
  1054. if (ops->vidioc_s_std)
  1055. p->capabilities |= V4L2_IN_CAP_STD;
  1056. if (ops->vidioc_s_dv_preset)
  1057. p->capabilities |= V4L2_IN_CAP_PRESETS;
  1058. if (ops->vidioc_s_dv_timings)
  1059. p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
  1060. if (!ops->vidioc_enum_input)
  1061. break;
  1062. ret = ops->vidioc_enum_input(file, fh, p);
  1063. if (!ret)
  1064. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1065. "audioset=%d, "
  1066. "tuner=%d, std=%08Lx, status=%d\n",
  1067. p->index, p->name, p->type, p->audioset,
  1068. p->tuner,
  1069. (unsigned long long)p->std,
  1070. p->status);
  1071. break;
  1072. }
  1073. case VIDIOC_G_INPUT:
  1074. {
  1075. unsigned int *i = arg;
  1076. if (!ops->vidioc_g_input)
  1077. break;
  1078. ret = ops->vidioc_g_input(file, fh, i);
  1079. if (!ret)
  1080. dbgarg(cmd, "value=%d\n", *i);
  1081. break;
  1082. }
  1083. case VIDIOC_S_INPUT:
  1084. {
  1085. unsigned int *i = arg;
  1086. if (!ops->vidioc_s_input)
  1087. break;
  1088. dbgarg(cmd, "value=%d\n", *i);
  1089. ret = ops->vidioc_s_input(file, fh, *i);
  1090. break;
  1091. }
  1092. /* ------ output switching ---------- */
  1093. case VIDIOC_ENUMOUTPUT:
  1094. {
  1095. struct v4l2_output *p = arg;
  1096. if (!ops->vidioc_enum_output)
  1097. break;
  1098. /*
  1099. * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
  1100. * CAP_STD here based on ioctl handler provided by the
  1101. * driver. If the driver doesn't support these
  1102. * for a specific output, it must override these flags.
  1103. */
  1104. if (ops->vidioc_s_std)
  1105. p->capabilities |= V4L2_OUT_CAP_STD;
  1106. if (ops->vidioc_s_dv_preset)
  1107. p->capabilities |= V4L2_OUT_CAP_PRESETS;
  1108. if (ops->vidioc_s_dv_timings)
  1109. p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
  1110. ret = ops->vidioc_enum_output(file, fh, p);
  1111. if (!ret)
  1112. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1113. "audioset=0x%x, "
  1114. "modulator=%d, std=0x%08Lx\n",
  1115. p->index, p->name, p->type, p->audioset,
  1116. p->modulator, (unsigned long long)p->std);
  1117. break;
  1118. }
  1119. case VIDIOC_G_OUTPUT:
  1120. {
  1121. unsigned int *i = arg;
  1122. if (!ops->vidioc_g_output)
  1123. break;
  1124. ret = ops->vidioc_g_output(file, fh, i);
  1125. if (!ret)
  1126. dbgarg(cmd, "value=%d\n", *i);
  1127. break;
  1128. }
  1129. case VIDIOC_S_OUTPUT:
  1130. {
  1131. unsigned int *i = arg;
  1132. if (!ops->vidioc_s_output)
  1133. break;
  1134. dbgarg(cmd, "value=%d\n", *i);
  1135. ret = ops->vidioc_s_output(file, fh, *i);
  1136. break;
  1137. }
  1138. /* --- controls ---------------------------------------------- */
  1139. case VIDIOC_QUERYCTRL:
  1140. {
  1141. struct v4l2_queryctrl *p = arg;
  1142. if (!ops->vidioc_queryctrl)
  1143. break;
  1144. ret = ops->vidioc_queryctrl(file, fh, p);
  1145. if (!ret)
  1146. dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
  1147. "step=%d, default=%d, flags=0x%08x\n",
  1148. p->id, p->type, p->name,
  1149. p->minimum, p->maximum,
  1150. p->step, p->default_value, p->flags);
  1151. else
  1152. dbgarg(cmd, "id=0x%x\n", p->id);
  1153. break;
  1154. }
  1155. case VIDIOC_G_CTRL:
  1156. {
  1157. struct v4l2_control *p = arg;
  1158. if (ops->vidioc_g_ctrl)
  1159. ret = ops->vidioc_g_ctrl(file, fh, p);
  1160. else if (ops->vidioc_g_ext_ctrls) {
  1161. struct v4l2_ext_controls ctrls;
  1162. struct v4l2_ext_control ctrl;
  1163. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1164. ctrls.count = 1;
  1165. ctrls.controls = &ctrl;
  1166. ctrl.id = p->id;
  1167. ctrl.value = p->value;
  1168. if (check_ext_ctrls(&ctrls, 1)) {
  1169. ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
  1170. if (ret == 0)
  1171. p->value = ctrl.value;
  1172. }
  1173. } else
  1174. break;
  1175. if (!ret)
  1176. dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
  1177. else
  1178. dbgarg(cmd, "id=0x%x\n", p->id);
  1179. break;
  1180. }
  1181. case VIDIOC_S_CTRL:
  1182. {
  1183. struct v4l2_control *p = arg;
  1184. struct v4l2_ext_controls ctrls;
  1185. struct v4l2_ext_control ctrl;
  1186. if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
  1187. break;
  1188. dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
  1189. if (ops->vidioc_s_ctrl) {
  1190. ret = ops->vidioc_s_ctrl(file, fh, p);
  1191. break;
  1192. }
  1193. if (!ops->vidioc_s_ext_ctrls)
  1194. break;
  1195. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1196. ctrls.count = 1;
  1197. ctrls.controls = &ctrl;
  1198. ctrl.id = p->id;
  1199. ctrl.value = p->value;
  1200. if (check_ext_ctrls(&ctrls, 1))
  1201. ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
  1202. break;
  1203. }
  1204. case VIDIOC_G_EXT_CTRLS:
  1205. {
  1206. struct v4l2_ext_controls *p = arg;
  1207. p->error_idx = p->count;
  1208. if (!ops->vidioc_g_ext_ctrls)
  1209. break;
  1210. if (check_ext_ctrls(p, 0))
  1211. ret = ops->vidioc_g_ext_ctrls(file, fh, p);
  1212. v4l_print_ext_ctrls(cmd, vfd, p, !ret);
  1213. break;
  1214. }
  1215. case VIDIOC_S_EXT_CTRLS:
  1216. {
  1217. struct v4l2_ext_controls *p = arg;
  1218. p->error_idx = p->count;
  1219. if (!ops->vidioc_s_ext_ctrls)
  1220. break;
  1221. v4l_print_ext_ctrls(cmd, vfd, p, 1);
  1222. if (check_ext_ctrls(p, 0))
  1223. ret = ops->vidioc_s_ext_ctrls(file, fh, p);
  1224. break;
  1225. }
  1226. case VIDIOC_TRY_EXT_CTRLS:
  1227. {
  1228. struct v4l2_ext_controls *p = arg;
  1229. p->error_idx = p->count;
  1230. if (!ops->vidioc_try_ext_ctrls)
  1231. break;
  1232. v4l_print_ext_ctrls(cmd, vfd, p, 1);
  1233. if (check_ext_ctrls(p, 0))
  1234. ret = ops->vidioc_try_ext_ctrls(file, fh, p);
  1235. break;
  1236. }
  1237. case VIDIOC_QUERYMENU:
  1238. {
  1239. struct v4l2_querymenu *p = arg;
  1240. if (!ops->vidioc_querymenu)
  1241. break;
  1242. ret = ops->vidioc_querymenu(file, fh, p);
  1243. if (!ret)
  1244. dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
  1245. p->id, p->index, p->name);
  1246. else
  1247. dbgarg(cmd, "id=0x%x, index=%d\n",
  1248. p->id, p->index);
  1249. break;
  1250. }
  1251. /* --- audio ---------------------------------------------- */
  1252. case VIDIOC_ENUMAUDIO:
  1253. {
  1254. struct v4l2_audio *p = arg;
  1255. if (!ops->vidioc_enumaudio)
  1256. break;
  1257. ret = ops->vidioc_enumaudio(file, fh, p);
  1258. if (!ret)
  1259. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1260. "mode=0x%x\n", p->index, p->name,
  1261. p->capability, p->mode);
  1262. else
  1263. dbgarg(cmd, "index=%d\n", p->index);
  1264. break;
  1265. }
  1266. case VIDIOC_G_AUDIO:
  1267. {
  1268. struct v4l2_audio *p = arg;
  1269. if (!ops->vidioc_g_audio)
  1270. break;
  1271. ret = ops->vidioc_g_audio(file, fh, p);
  1272. if (!ret)
  1273. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1274. "mode=0x%x\n", p->index,
  1275. p->name, p->capability, p->mode);
  1276. else
  1277. dbgarg(cmd, "index=%d\n", p->index);
  1278. break;
  1279. }
  1280. case VIDIOC_S_AUDIO:
  1281. {
  1282. struct v4l2_audio *p = arg;
  1283. if (!ops->vidioc_s_audio)
  1284. break;
  1285. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1286. "mode=0x%x\n", p->index, p->name,
  1287. p->capability, p->mode);
  1288. ret = ops->vidioc_s_audio(file, fh, p);
  1289. break;
  1290. }
  1291. case VIDIOC_ENUMAUDOUT:
  1292. {
  1293. struct v4l2_audioout *p = arg;
  1294. if (!ops->vidioc_enumaudout)
  1295. break;
  1296. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1297. ret = ops->vidioc_enumaudout(file, fh, p);
  1298. if (!ret)
  1299. dbgarg2("index=%d, name=%s, capability=%d, "
  1300. "mode=%d\n", p->index, p->name,
  1301. p->capability, p->mode);
  1302. break;
  1303. }
  1304. case VIDIOC_G_AUDOUT:
  1305. {
  1306. struct v4l2_audioout *p = arg;
  1307. if (!ops->vidioc_g_audout)
  1308. break;
  1309. ret = ops->vidioc_g_audout(file, fh, p);
  1310. if (!ret)
  1311. dbgarg2("index=%d, name=%s, capability=%d, "
  1312. "mode=%d\n", p->index, p->name,
  1313. p->capability, p->mode);
  1314. break;
  1315. }
  1316. case VIDIOC_S_AUDOUT:
  1317. {
  1318. struct v4l2_audioout *p = arg;
  1319. if (!ops->vidioc_s_audout)
  1320. break;
  1321. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1322. "mode=%d\n", p->index, p->name,
  1323. p->capability, p->mode);
  1324. ret = ops->vidioc_s_audout(file, fh, p);
  1325. break;
  1326. }
  1327. case VIDIOC_G_MODULATOR:
  1328. {
  1329. struct v4l2_modulator *p = arg;
  1330. if (!ops->vidioc_g_modulator)
  1331. break;
  1332. ret = ops->vidioc_g_modulator(file, fh, p);
  1333. if (!ret)
  1334. dbgarg(cmd, "index=%d, name=%s, "
  1335. "capability=%d, rangelow=%d,"
  1336. " rangehigh=%d, txsubchans=%d\n",
  1337. p->index, p->name, p->capability,
  1338. p->rangelow, p->rangehigh,
  1339. p->txsubchans);
  1340. break;
  1341. }
  1342. case VIDIOC_S_MODULATOR:
  1343. {
  1344. struct v4l2_modulator *p = arg;
  1345. if (!ops->vidioc_s_modulator)
  1346. break;
  1347. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1348. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1349. p->index, p->name, p->capability, p->rangelow,
  1350. p->rangehigh, p->txsubchans);
  1351. ret = ops->vidioc_s_modulator(file, fh, p);
  1352. break;
  1353. }
  1354. case VIDIOC_G_CROP:
  1355. {
  1356. struct v4l2_crop *p = arg;
  1357. if (!ops->vidioc_g_crop)
  1358. break;
  1359. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1360. ret = ops->vidioc_g_crop(file, fh, p);
  1361. if (!ret)
  1362. dbgrect(vfd, "", &p->c);
  1363. break;
  1364. }
  1365. case VIDIOC_S_CROP:
  1366. {
  1367. struct v4l2_crop *p = arg;
  1368. if (!ops->vidioc_s_crop)
  1369. break;
  1370. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1371. dbgrect(vfd, "", &p->c);
  1372. ret = ops->vidioc_s_crop(file, fh, p);
  1373. break;
  1374. }
  1375. case VIDIOC_CROPCAP:
  1376. {
  1377. struct v4l2_cropcap *p = arg;
  1378. /*FIXME: Should also show v4l2_fract pixelaspect */
  1379. if (!ops->vidioc_cropcap)
  1380. break;
  1381. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1382. ret = ops->vidioc_cropcap(file, fh, p);
  1383. if (!ret) {
  1384. dbgrect(vfd, "bounds ", &p->bounds);
  1385. dbgrect(vfd, "defrect ", &p->defrect);
  1386. }
  1387. break;
  1388. }
  1389. case VIDIOC_G_JPEGCOMP:
  1390. {
  1391. struct v4l2_jpegcompression *p = arg;
  1392. if (!ops->vidioc_g_jpegcomp)
  1393. break;
  1394. ret = ops->vidioc_g_jpegcomp(file, fh, p);
  1395. if (!ret)
  1396. dbgarg(cmd, "quality=%d, APPn=%d, "
  1397. "APP_len=%d, COM_len=%d, "
  1398. "jpeg_markers=%d\n",
  1399. p->quality, p->APPn, p->APP_len,
  1400. p->COM_len, p->jpeg_markers);
  1401. break;
  1402. }
  1403. case VIDIOC_S_JPEGCOMP:
  1404. {
  1405. struct v4l2_jpegcompression *p = arg;
  1406. if (!ops->vidioc_g_jpegcomp)
  1407. break;
  1408. dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1409. "COM_len=%d, jpeg_markers=%d\n",
  1410. p->quality, p->APPn, p->APP_len,
  1411. p->COM_len, p->jpeg_markers);
  1412. ret = ops->vidioc_s_jpegcomp(file, fh, p);
  1413. break;
  1414. }
  1415. case VIDIOC_G_ENC_INDEX:
  1416. {
  1417. struct v4l2_enc_idx *p = arg;
  1418. if (!ops->vidioc_g_enc_index)
  1419. break;
  1420. ret = ops->vidioc_g_enc_index(file, fh, p);
  1421. if (!ret)
  1422. dbgarg(cmd, "entries=%d, entries_cap=%d\n",
  1423. p->entries, p->entries_cap);
  1424. break;
  1425. }
  1426. case VIDIOC_ENCODER_CMD:
  1427. {
  1428. struct v4l2_encoder_cmd *p = arg;
  1429. if (!ops->vidioc_encoder_cmd)
  1430. break;
  1431. ret = ops->vidioc_encoder_cmd(file, fh, p);
  1432. if (!ret)
  1433. dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
  1434. break;
  1435. }
  1436. case VIDIOC_TRY_ENCODER_CMD:
  1437. {
  1438. struct v4l2_encoder_cmd *p = arg;
  1439. if (!ops->vidioc_try_encoder_cmd)
  1440. break;
  1441. ret = ops->vidioc_try_encoder_cmd(file, fh, p);
  1442. if (!ret)
  1443. dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
  1444. break;
  1445. }
  1446. case VIDIOC_G_PARM:
  1447. {
  1448. struct v4l2_streamparm *p = arg;
  1449. if (ops->vidioc_g_parm) {
  1450. ret = check_fmt(ops, p->type);
  1451. if (ret)
  1452. break;
  1453. ret = ops->vidioc_g_parm(file, fh, p);
  1454. } else {
  1455. v4l2_std_id std = vfd->current_norm;
  1456. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1457. return -EINVAL;
  1458. ret = 0;
  1459. if (ops->vidioc_g_std)
  1460. ret = ops->vidioc_g_std(file, fh, &std);
  1461. else if (std == 0)
  1462. ret = -EINVAL;
  1463. if (ret == 0)
  1464. v4l2_video_std_frame_period(std,
  1465. &p->parm.capture.timeperframe);
  1466. }
  1467. dbgarg(cmd, "type=%d\n", p->type);
  1468. break;
  1469. }
  1470. case VIDIOC_S_PARM:
  1471. {
  1472. struct v4l2_streamparm *p = arg;
  1473. if (!ops->vidioc_s_parm)
  1474. break;
  1475. ret = check_fmt(ops, p->type);
  1476. if (ret)
  1477. break;
  1478. dbgarg(cmd, "type=%d\n", p->type);
  1479. ret = ops->vidioc_s_parm(file, fh, p);
  1480. break;
  1481. }
  1482. case VIDIOC_G_TUNER:
  1483. {
  1484. struct v4l2_tuner *p = arg;
  1485. if (!ops->vidioc_g_tuner)
  1486. break;
  1487. ret = ops->vidioc_g_tuner(file, fh, p);
  1488. if (!ret)
  1489. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1490. "capability=0x%x, rangelow=%d, "
  1491. "rangehigh=%d, signal=%d, afc=%d, "
  1492. "rxsubchans=0x%x, audmode=%d\n",
  1493. p->index, p->name, p->type,
  1494. p->capability, p->rangelow,
  1495. p->rangehigh, p->signal, p->afc,
  1496. p->rxsubchans, p->audmode);
  1497. break;
  1498. }
  1499. case VIDIOC_S_TUNER:
  1500. {
  1501. struct v4l2_tuner *p = arg;
  1502. if (!ops->vidioc_s_tuner)
  1503. break;
  1504. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1505. "capability=0x%x, rangelow=%d, "
  1506. "rangehigh=%d, signal=%d, afc=%d, "
  1507. "rxsubchans=0x%x, audmode=%d\n",
  1508. p->index, p->name, p->type,
  1509. p->capability, p->rangelow,
  1510. p->rangehigh, p->signal, p->afc,
  1511. p->rxsubchans, p->audmode);
  1512. ret = ops->vidioc_s_tuner(file, fh, p);
  1513. break;
  1514. }
  1515. case VIDIOC_G_FREQUENCY:
  1516. {
  1517. struct v4l2_frequency *p = arg;
  1518. if (!ops->vidioc_g_frequency)
  1519. break;
  1520. ret = ops->vidioc_g_frequency(file, fh, p);
  1521. if (!ret)
  1522. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1523. p->tuner, p->type, p->frequency);
  1524. break;
  1525. }
  1526. case VIDIOC_S_FREQUENCY:
  1527. {
  1528. struct v4l2_frequency *p = arg;
  1529. if (!ops->vidioc_s_frequency)
  1530. break;
  1531. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1532. p->tuner, p->type, p->frequency);
  1533. ret = ops->vidioc_s_frequency(file, fh, p);
  1534. break;
  1535. }
  1536. case VIDIOC_G_SLICED_VBI_CAP:
  1537. {
  1538. struct v4l2_sliced_vbi_cap *p = arg;
  1539. if (!ops->vidioc_g_sliced_vbi_cap)
  1540. break;
  1541. /* Clear up to type, everything after type is zerod already */
  1542. memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
  1543. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1544. ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
  1545. if (!ret)
  1546. dbgarg2("service_set=%d\n", p->service_set);
  1547. break;
  1548. }
  1549. case VIDIOC_LOG_STATUS:
  1550. {
  1551. if (!ops->vidioc_log_status)
  1552. break;
  1553. ret = ops->vidioc_log_status(file, fh);
  1554. break;
  1555. }
  1556. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1557. case VIDIOC_DBG_G_REGISTER:
  1558. {
  1559. struct v4l2_dbg_register *p = arg;
  1560. if (!capable(CAP_SYS_ADMIN))
  1561. ret = -EPERM;
  1562. else if (ops->vidioc_g_register)
  1563. ret = ops->vidioc_g_register(file, fh, p);
  1564. break;
  1565. }
  1566. case VIDIOC_DBG_S_REGISTER:
  1567. {
  1568. struct v4l2_dbg_register *p = arg;
  1569. if (!capable(CAP_SYS_ADMIN))
  1570. ret = -EPERM;
  1571. else if (ops->vidioc_s_register)
  1572. ret = ops->vidioc_s_register(file, fh, p);
  1573. break;
  1574. }
  1575. #endif
  1576. case VIDIOC_DBG_G_CHIP_IDENT:
  1577. {
  1578. struct v4l2_dbg_chip_ident *p = arg;
  1579. if (!ops->vidioc_g_chip_ident)
  1580. break;
  1581. p->ident = V4L2_IDENT_NONE;
  1582. p->revision = 0;
  1583. ret = ops->vidioc_g_chip_ident(file, fh, p);
  1584. if (!ret)
  1585. dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
  1586. break;
  1587. }
  1588. case VIDIOC_S_HW_FREQ_SEEK:
  1589. {
  1590. struct v4l2_hw_freq_seek *p = arg;
  1591. if (!ops->vidioc_s_hw_freq_seek)
  1592. break;
  1593. dbgarg(cmd,
  1594. "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
  1595. p->tuner, p->type, p->seek_upward, p->wrap_around);
  1596. ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
  1597. break;
  1598. }
  1599. case VIDIOC_ENUM_FRAMESIZES:
  1600. {
  1601. struct v4l2_frmsizeenum *p = arg;
  1602. if (!ops->vidioc_enum_framesizes)
  1603. break;
  1604. ret = ops->vidioc_enum_framesizes(file, fh, p);
  1605. dbgarg(cmd,
  1606. "index=%d, pixelformat=%c%c%c%c, type=%d ",
  1607. p->index,
  1608. (p->pixel_format & 0xff),
  1609. (p->pixel_format >> 8) & 0xff,
  1610. (p->pixel_format >> 16) & 0xff,
  1611. (p->pixel_format >> 24) & 0xff,
  1612. p->type);
  1613. switch (p->type) {
  1614. case V4L2_FRMSIZE_TYPE_DISCRETE:
  1615. dbgarg3("width = %d, height=%d\n",
  1616. p->discrete.width, p->discrete.height);
  1617. break;
  1618. case V4L2_FRMSIZE_TYPE_STEPWISE:
  1619. dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
  1620. p->stepwise.min_width, p->stepwise.min_height,
  1621. p->stepwise.step_width, p->stepwise.step_height,
  1622. p->stepwise.max_width, p->stepwise.max_height);
  1623. break;
  1624. case V4L2_FRMSIZE_TYPE_CONTINUOUS:
  1625. dbgarg3("continuous\n");
  1626. break;
  1627. default:
  1628. dbgarg3("- Unknown type!\n");
  1629. }
  1630. break;
  1631. }
  1632. case VIDIOC_ENUM_FRAMEINTERVALS:
  1633. {
  1634. struct v4l2_frmivalenum *p = arg;
  1635. if (!ops->vidioc_enum_frameintervals)
  1636. break;
  1637. ret = ops->vidioc_enum_frameintervals(file, fh, p);
  1638. dbgarg(cmd,
  1639. "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
  1640. p->index, p->pixel_format,
  1641. p->width, p->height, p->type);
  1642. switch (p->type) {
  1643. case V4L2_FRMIVAL_TYPE_DISCRETE:
  1644. dbgarg2("fps=%d/%d\n",
  1645. p->discrete.numerator,
  1646. p->discrete.denominator);
  1647. break;
  1648. case V4L2_FRMIVAL_TYPE_STEPWISE:
  1649. dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
  1650. p->stepwise.min.numerator,
  1651. p->stepwise.min.denominator,
  1652. p->stepwise.max.numerator,
  1653. p->stepwise.max.denominator,
  1654. p->stepwise.step.numerator,
  1655. p->stepwise.step.denominator);
  1656. break;
  1657. case V4L2_FRMIVAL_TYPE_CONTINUOUS:
  1658. dbgarg2("continuous\n");
  1659. break;
  1660. default:
  1661. dbgarg2("- Unknown type!\n");
  1662. }
  1663. break;
  1664. }
  1665. case VIDIOC_ENUM_DV_PRESETS:
  1666. {
  1667. struct v4l2_dv_enum_preset *p = arg;
  1668. if (!ops->vidioc_enum_dv_presets)
  1669. break;
  1670. ret = ops->vidioc_enum_dv_presets(file, fh, p);
  1671. if (!ret)
  1672. dbgarg(cmd,
  1673. "index=%d, preset=%d, name=%s, width=%d,"
  1674. " height=%d ",
  1675. p->index, p->preset, p->name, p->width,
  1676. p->height);
  1677. break;
  1678. }
  1679. case VIDIOC_S_DV_PRESET:
  1680. {
  1681. struct v4l2_dv_preset *p = arg;
  1682. if (!ops->vidioc_s_dv_preset)
  1683. break;
  1684. dbgarg(cmd, "preset=%d\n", p->preset);
  1685. ret = ops->vidioc_s_dv_preset(file, fh, p);
  1686. break;
  1687. }
  1688. case VIDIOC_G_DV_PRESET:
  1689. {
  1690. struct v4l2_dv_preset *p = arg;
  1691. if (!ops->vidioc_g_dv_preset)
  1692. break;
  1693. ret = ops->vidioc_g_dv_preset(file, fh, p);
  1694. if (!ret)
  1695. dbgarg(cmd, "preset=%d\n", p->preset);
  1696. break;
  1697. }
  1698. case VIDIOC_QUERY_DV_PRESET:
  1699. {
  1700. struct v4l2_dv_preset *p = arg;
  1701. if (!ops->vidioc_query_dv_preset)
  1702. break;
  1703. ret = ops->vidioc_query_dv_preset(file, fh, p);
  1704. if (!ret)
  1705. dbgarg(cmd, "preset=%d\n", p->preset);
  1706. break;
  1707. }
  1708. case VIDIOC_S_DV_TIMINGS:
  1709. {
  1710. struct v4l2_dv_timings *p = arg;
  1711. if (!ops->vidioc_s_dv_timings)
  1712. break;
  1713. switch (p->type) {
  1714. case V4L2_DV_BT_656_1120:
  1715. dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
  1716. " width=%d, height=%d, polarities=%x,"
  1717. " hfrontporch=%d, hsync=%d, hbackporch=%d,"
  1718. " vfrontporch=%d, vsync=%d, vbackporch=%d,"
  1719. " il_vfrontporch=%d, il_vsync=%d,"
  1720. " il_vbackporch=%d\n",
  1721. p->bt.interlaced, p->bt.pixelclock,
  1722. p->bt.width, p->bt.height, p->bt.polarities,
  1723. p->bt.hfrontporch, p->bt.hsync,
  1724. p->bt.hbackporch, p->bt.vfrontporch,
  1725. p->bt.vsync, p->bt.vbackporch,
  1726. p->bt.il_vfrontporch, p->bt.il_vsync,
  1727. p->bt.il_vbackporch);
  1728. ret = ops->vidioc_s_dv_timings(file, fh, p);
  1729. break;
  1730. default:
  1731. dbgarg2("Unknown type %d!\n", p->type);
  1732. break;
  1733. }
  1734. break;
  1735. }
  1736. case VIDIOC_G_DV_TIMINGS:
  1737. {
  1738. struct v4l2_dv_timings *p = arg;
  1739. if (!ops->vidioc_g_dv_timings)
  1740. break;
  1741. ret = ops->vidioc_g_dv_timings(file, fh, p);
  1742. if (!ret) {
  1743. switch (p->type) {
  1744. case V4L2_DV_BT_656_1120:
  1745. dbgarg2("bt-656/1120:interlaced=%d,"
  1746. " pixelclock=%lld,"
  1747. " width=%d, height=%d, polarities=%x,"
  1748. " hfrontporch=%d, hsync=%d,"
  1749. " hbackporch=%d, vfrontporch=%d,"
  1750. " vsync=%d, vbackporch=%d,"
  1751. " il_vfrontporch=%d, il_vsync=%d,"
  1752. " il_vbackporch=%d\n",
  1753. p->bt.interlaced, p->bt.pixelclock,
  1754. p->bt.width, p->bt.height,
  1755. p->bt.polarities, p->bt.hfrontporch,
  1756. p->bt.hsync, p->bt.hbackporch,
  1757. p->bt.vfrontporch, p->bt.vsync,
  1758. p->bt.vbackporch, p->bt.il_vfrontporch,
  1759. p->bt.il_vsync, p->bt.il_vbackporch);
  1760. break;
  1761. default:
  1762. dbgarg2("Unknown type %d!\n", p->type);
  1763. break;
  1764. }
  1765. }
  1766. break;
  1767. }
  1768. default:
  1769. {
  1770. if (!ops->vidioc_default)
  1771. break;
  1772. ret = ops->vidioc_default(file, fh, cmd, arg);
  1773. break;
  1774. }
  1775. } /* switch */
  1776. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1777. if (ret < 0) {
  1778. v4l_print_ioctl(vfd->name, cmd);
  1779. printk(KERN_CONT " error %ld\n", ret);
  1780. }
  1781. }
  1782. return ret;
  1783. }
  1784. /* In some cases, only a few fields are used as input, i.e. when the app sets
  1785. * "index" and then the driver fills in the rest of the structure for the thing
  1786. * with that index. We only need to copy up the first non-input field. */
  1787. static unsigned long cmd_input_size(unsigned int cmd)
  1788. {
  1789. /* Size of structure up to and including 'field' */
  1790. #define CMDINSIZE(cmd, type, field) \
  1791. case VIDIOC_##cmd: \
  1792. return offsetof(struct v4l2_##type, field) + \
  1793. sizeof(((struct v4l2_##type *)0)->field);
  1794. switch (cmd) {
  1795. CMDINSIZE(ENUM_FMT, fmtdesc, type);
  1796. CMDINSIZE(G_FMT, format, type);
  1797. CMDINSIZE(QUERYBUF, buffer, type);
  1798. CMDINSIZE(G_PARM, streamparm, type);
  1799. CMDINSIZE(ENUMSTD, standard, index);
  1800. CMDINSIZE(ENUMINPUT, input, index);
  1801. CMDINSIZE(G_CTRL, control, id);
  1802. CMDINSIZE(G_TUNER, tuner, index);
  1803. CMDINSIZE(QUERYCTRL, queryctrl, id);
  1804. CMDINSIZE(QUERYMENU, querymenu, index);
  1805. CMDINSIZE(ENUMOUTPUT, output, index);
  1806. CMDINSIZE(G_MODULATOR, modulator, index);
  1807. CMDINSIZE(G_FREQUENCY, frequency, tuner);
  1808. CMDINSIZE(CROPCAP, cropcap, type);
  1809. CMDINSIZE(G_CROP, crop, type);
  1810. CMDINSIZE(ENUMAUDIO, audio, index);
  1811. CMDINSIZE(ENUMAUDOUT, audioout, index);
  1812. CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
  1813. CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
  1814. CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
  1815. CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
  1816. CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
  1817. default:
  1818. return _IOC_SIZE(cmd);
  1819. }
  1820. }
  1821. long video_ioctl2(struct file *file,
  1822. unsigned int cmd, unsigned long arg)
  1823. {
  1824. char sbuf[128];
  1825. void *mbuf = NULL;
  1826. void *parg = NULL;
  1827. long err = -EINVAL;
  1828. int is_ext_ctrl;
  1829. size_t ctrls_size = 0;
  1830. void __user *user_ptr = NULL;
  1831. #ifdef __OLD_VIDIOC_
  1832. cmd = video_fix_command(cmd);
  1833. #endif
  1834. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1835. cmd == VIDIOC_TRY_EXT_CTRLS);
  1836. /* Copy arguments into temp kernel buffer */
  1837. if (_IOC_DIR(cmd) != _IOC_NONE) {
  1838. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1839. parg = sbuf;
  1840. } else {
  1841. /* too big to allocate from stack */
  1842. mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
  1843. if (NULL == mbuf)
  1844. return -ENOMEM;
  1845. parg = mbuf;
  1846. }
  1847. err = -EFAULT;
  1848. if (_IOC_DIR(cmd) & _IOC_WRITE) {
  1849. unsigned long n = cmd_input_size(cmd);
  1850. if (copy_from_user(parg, (void __user *)arg, n))
  1851. goto out;
  1852. /* zero out anything we don't copy from userspace */
  1853. if (n < _IOC_SIZE(cmd))
  1854. memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
  1855. } else {
  1856. /* read-only ioctl */
  1857. memset(parg, 0, _IOC_SIZE(cmd));
  1858. }
  1859. }
  1860. if (is_ext_ctrl) {
  1861. struct v4l2_ext_controls *p = parg;
  1862. /* In case of an error, tell the caller that it wasn't
  1863. a specific control that caused it. */
  1864. p->error_idx = p->count;
  1865. user_ptr = (void __user *)p->controls;
  1866. if (p->count) {
  1867. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1868. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1869. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1870. err = -ENOMEM;
  1871. if (NULL == mbuf)
  1872. goto out_ext_ctrl;
  1873. err = -EFAULT;
  1874. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1875. goto out_ext_ctrl;
  1876. p->controls = mbuf;
  1877. }
  1878. }
  1879. /* Handles IOCTL */
  1880. err = __video_do_ioctl(file, cmd, parg);
  1881. if (err == -ENOIOCTLCMD)
  1882. err = -EINVAL;
  1883. if (is_ext_ctrl) {
  1884. struct v4l2_ext_controls *p = parg;
  1885. p->controls = (void *)user_ptr;
  1886. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1887. err = -EFAULT;
  1888. goto out_ext_ctrl;
  1889. }
  1890. if (err < 0)
  1891. goto out;
  1892. out_ext_ctrl:
  1893. /* Copy results into user buffer */
  1894. switch (_IOC_DIR(cmd)) {
  1895. case _IOC_READ:
  1896. case (_IOC_WRITE | _IOC_READ):
  1897. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1898. err = -EFAULT;
  1899. break;
  1900. }
  1901. out:
  1902. kfree(mbuf);
  1903. return err;
  1904. }
  1905. EXPORT_SYMBOL(video_ioctl2);