v4l2-ioctl.c 60 KB

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