v4l2-ioctl.c 60 KB

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