v4l2-ioctl.c 49 KB

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