v4l2-ioctl.c 72 KB

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