v4l2-ioctl.c 62 KB

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