msm_vdec.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. /* Copyright (c) 2022-2023. Qualcomm Innovation Center, Inc. All rights reserved. */
  6. #include "msm_media_info.h"
  7. #include <linux/v4l2-common.h>
  8. #include "msm_vdec.h"
  9. #include "msm_vidc_core.h"
  10. #include "msm_vidc_inst.h"
  11. #include "msm_vidc_driver.h"
  12. #include "msm_vidc_internal.h"
  13. #include "msm_vidc_control.h"
  14. #include "msm_vidc_debug.h"
  15. #include "msm_vidc_power.h"
  16. #include "msm_vidc_platform.h"
  17. #include "msm_vidc_memory.h"
  18. #include "venus_hfi.h"
  19. #include "hfi_packet.h"
  20. /* TODO: update based on clips */
  21. #define MAX_DEC_BATCH_SIZE 6
  22. #define SKIP_BATCH_WINDOW 100
  23. static const u32 msm_vdec_internal_buffer_type[] = {
  24. MSM_VIDC_BUF_BIN,
  25. MSM_VIDC_BUF_COMV,
  26. MSM_VIDC_BUF_NON_COMV,
  27. MSM_VIDC_BUF_LINE,
  28. MSM_VIDC_BUF_PARTIAL_DATA,
  29. };
  30. static const u32 msm_vdec_output_internal_buffer_type[] = {
  31. MSM_VIDC_BUF_DPB,
  32. };
  33. struct msm_vdec_prop_type_handle {
  34. u32 type;
  35. int (*handle)(struct msm_vidc_inst *inst, enum msm_vidc_port_type port);
  36. };
  37. static int msm_vdec_codec_change(struct msm_vidc_inst *inst, u32 v4l2_codec)
  38. {
  39. int rc = 0;
  40. if (inst->codec && inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat == v4l2_codec)
  41. return 0;
  42. i_vpr_h(inst, "%s: codec changed from %s to %s\n",
  43. __func__, v4l2_pixelfmt_name(inst, inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat),
  44. v4l2_pixelfmt_name(inst, v4l2_codec));
  45. inst->codec = v4l2_codec_to_driver(inst, v4l2_codec, __func__);
  46. if (!inst->codec) {
  47. i_vpr_e(inst, "%s: invalid codec %#x\n", __func__, v4l2_codec);
  48. rc = -EINVAL;
  49. goto exit;
  50. }
  51. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat = v4l2_codec;
  52. rc = msm_vidc_update_debug_str(inst);
  53. if (rc)
  54. goto exit;
  55. rc = msm_vidc_get_inst_capability(inst);
  56. if (rc)
  57. goto exit;
  58. rc = msm_vidc_ctrl_deinit(inst);
  59. if (rc)
  60. goto exit;
  61. rc = msm_vidc_ctrl_init(inst);
  62. if(rc)
  63. goto exit;
  64. rc = msm_vidc_update_buffer_count(inst, INPUT_PORT);
  65. if (rc)
  66. goto exit;
  67. rc = msm_vidc_update_buffer_count(inst, OUTPUT_PORT);
  68. if (rc)
  69. goto exit;
  70. exit:
  71. return rc;
  72. }
  73. static int msm_vdec_set_bitstream_resolution(struct msm_vidc_inst *inst,
  74. enum msm_vidc_port_type port)
  75. {
  76. int rc = 0;
  77. u32 resolution;
  78. resolution = inst->fmts[INPUT_PORT].fmt.pix_mp.width << 16 |
  79. inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  80. i_vpr_h(inst, "%s: width: %d height: %d\n", __func__,
  81. inst->fmts[INPUT_PORT].fmt.pix_mp.width,
  82. inst->fmts[INPUT_PORT].fmt.pix_mp.height);
  83. inst->subcr_params[port].bitstream_resolution = resolution;
  84. rc = venus_hfi_session_property(inst,
  85. HFI_PROP_BITSTREAM_RESOLUTION,
  86. HFI_HOST_FLAGS_NONE,
  87. get_hfi_port(inst, port),
  88. HFI_PAYLOAD_U32,
  89. &resolution,
  90. sizeof(u32));
  91. if (rc) {
  92. i_vpr_e(inst, "%s: set property failed\n", __func__);
  93. return rc;
  94. }
  95. return rc;
  96. }
  97. static int msm_vdec_set_linear_stride_scanline(struct msm_vidc_inst *inst)
  98. {
  99. int rc = 0;
  100. u32 stride_y, scanline_y, stride_uv, scanline_uv;
  101. u32 payload[2];
  102. enum msm_vidc_colorformat_type colorformat;
  103. colorformat = v4l2_colorformat_to_driver(inst,
  104. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, __func__);
  105. if (!is_linear_yuv_colorformat(colorformat))
  106. return 0;
  107. stride_y = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width;
  108. scanline_y = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height;
  109. stride_uv = stride_y;
  110. scanline_uv = scanline_y / 2;
  111. payload[0] = stride_y << 16 | scanline_y;
  112. payload[1] = stride_uv << 16 | scanline_uv;
  113. i_vpr_h(inst, "%s: stride_y: %d scanline_y: %d "
  114. "stride_uv: %d, scanline_uv: %d", __func__,
  115. stride_y, scanline_y, stride_uv, scanline_uv);
  116. rc = venus_hfi_session_property(inst,
  117. HFI_PROP_LINEAR_STRIDE_SCANLINE,
  118. HFI_HOST_FLAGS_NONE,
  119. get_hfi_port(inst, OUTPUT_PORT),
  120. HFI_PAYLOAD_U64,
  121. &payload,
  122. sizeof(u64));
  123. if (rc) {
  124. i_vpr_e(inst, "%s: set property failed\n", __func__);
  125. return rc;
  126. }
  127. return rc;
  128. }
  129. static int msm_vdec_set_ubwc_stride_scanline(struct msm_vidc_inst *inst)
  130. {
  131. int rc = 0;
  132. u32 stride_y, scanline_y, stride_uv, scanline_uv;
  133. u32 meta_stride_y, meta_scanline_y, meta_stride_uv, meta_scanline_uv;
  134. u32 payload[4];
  135. struct v4l2_format *f;
  136. u32 pix_fmt, width, height, colorformat;
  137. f = &inst->fmts[OUTPUT_PORT];
  138. pix_fmt = f->fmt.pix_mp.pixelformat;
  139. width = f->fmt.pix_mp.width;
  140. height = f->fmt.pix_mp.height;
  141. colorformat = v4l2_colorformat_to_driver(inst, pix_fmt, __func__);
  142. if (inst->codec != MSM_VIDC_AV1 ||
  143. (!is_ubwc_colorformat(colorformat)))
  144. return 0;
  145. stride_y = video_y_stride_bytes(colorformat, width);
  146. scanline_y = video_y_scanlines(colorformat, height);
  147. stride_uv = video_uv_stride_bytes(colorformat, width);
  148. scanline_uv = video_uv_scanlines(colorformat, height);
  149. meta_stride_y = video_y_meta_stride(colorformat, width);
  150. meta_scanline_y = video_y_meta_scanlines(colorformat, height);
  151. meta_stride_uv = video_uv_meta_stride(colorformat, width);
  152. meta_scanline_uv = video_uv_meta_scanlines(colorformat, height);
  153. payload[0] = stride_y << 16 | scanline_y;
  154. payload[1] = stride_uv << 16 | scanline_uv;
  155. payload[2] = meta_stride_y << 16 | meta_scanline_y;
  156. payload[3] = meta_stride_uv << 16 | meta_scanline_uv;
  157. i_vpr_h(inst, "%s: stride_y: %d scanline_y: %d "
  158. "stride_uv: %d scanline_uv: %d "
  159. "meta_stride_y: %d meta_scanline_y: %d "
  160. "meta_stride_uv: %d, meta_scanline_uv: %d",
  161. __func__,
  162. stride_y, scanline_y, stride_uv, scanline_uv,
  163. meta_stride_y, meta_scanline_y,
  164. meta_stride_uv, meta_scanline_uv);
  165. rc = venus_hfi_session_property(inst,
  166. HFI_PROP_UBWC_STRIDE_SCANLINE,
  167. HFI_HOST_FLAGS_NONE,
  168. get_hfi_port(inst, OUTPUT_PORT),
  169. HFI_PAYLOAD_U32_ARRAY,
  170. &payload[0],
  171. sizeof(u32) * 4);
  172. if (rc) {
  173. i_vpr_e(inst, "%s: set property failed\n", __func__);
  174. return rc;
  175. }
  176. return rc;
  177. }
  178. static int msm_vdec_set_crop_offsets(struct msm_vidc_inst *inst,
  179. enum msm_vidc_port_type port)
  180. {
  181. int rc = 0;
  182. u32 left_offset, top_offset, right_offset, bottom_offset;
  183. u32 payload[2] = {0};
  184. left_offset = inst->crop.left;
  185. top_offset = inst->crop.top;
  186. right_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  187. inst->crop.width);
  188. bottom_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  189. inst->crop.height);
  190. payload[0] = left_offset << 16 | top_offset;
  191. payload[1] = right_offset << 16 | bottom_offset;
  192. i_vpr_h(inst, "%s: left_offset: %d top_offset: %d "
  193. "right_offset: %d bottom_offset: %d", __func__,
  194. left_offset, top_offset, right_offset, bottom_offset);
  195. inst->subcr_params[port].crop_offsets[0] = payload[0];
  196. inst->subcr_params[port].crop_offsets[1] = payload[1];
  197. rc = venus_hfi_session_property(inst,
  198. HFI_PROP_CROP_OFFSETS,
  199. HFI_HOST_FLAGS_NONE,
  200. get_hfi_port(inst, port),
  201. HFI_PAYLOAD_64_PACKED,
  202. &payload,
  203. sizeof(u64));
  204. if (rc) {
  205. i_vpr_e(inst, "%s: set property failed\n", __func__);
  206. return rc;
  207. }
  208. return rc;
  209. }
  210. static int msm_vdec_set_bit_depth(struct msm_vidc_inst *inst,
  211. enum msm_vidc_port_type port)
  212. {
  213. int rc = 0;
  214. u32 pix_fmt;
  215. u32 bitdepth = 8 << 16 | 8;
  216. enum msm_vidc_colorformat_type colorformat;
  217. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  218. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  219. return -EINVAL;
  220. }
  221. pix_fmt = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  222. colorformat = v4l2_colorformat_to_driver(inst, pix_fmt, __func__);
  223. if (is_10bit_colorformat(colorformat))
  224. bitdepth = 10 << 16 | 10;
  225. inst->subcr_params[port].bit_depth = bitdepth;
  226. msm_vidc_update_cap_value(inst, BIT_DEPTH, bitdepth, __func__);
  227. i_vpr_h(inst, "%s: bit depth: %#x", __func__, bitdepth);
  228. rc = venus_hfi_session_property(inst,
  229. HFI_PROP_LUMA_CHROMA_BIT_DEPTH,
  230. HFI_HOST_FLAGS_NONE,
  231. get_hfi_port(inst, port),
  232. HFI_PAYLOAD_U32,
  233. &bitdepth,
  234. sizeof(u32));
  235. if (rc) {
  236. i_vpr_e(inst, "%s: set property failed\n", __func__);
  237. return rc;
  238. }
  239. return rc;
  240. }
  241. //todo: enable when needed
  242. /*
  243. static int msm_vdec_set_cabac(struct msm_vidc_inst *inst,
  244. enum msm_vidc_port_type port)
  245. {
  246. int rc = 0;
  247. u32 cabac = 0;
  248. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  249. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  250. return -EINVAL;
  251. }
  252. cabac = inst->capabilities[ENTROPY_MODE].value;
  253. inst->subcr_params[port].cabac = cabac;
  254. i_vpr_h(inst, "%s: entropy mode: %d", __func__, cabac);
  255. rc = venus_hfi_session_property(inst,
  256. HFI_PROP_CABAC_SESSION,
  257. HFI_HOST_FLAGS_NONE,
  258. get_hfi_port(inst, port),
  259. HFI_PAYLOAD_U32,
  260. &cabac,
  261. sizeof(u32));
  262. if (rc)
  263. i_vpr_e(inst, "%s: set property failed\n", __func__);
  264. return rc;
  265. }
  266. */
  267. static int msm_vdec_set_coded_frames(struct msm_vidc_inst *inst,
  268. enum msm_vidc_port_type port)
  269. {
  270. int rc = 0;
  271. u32 coded_frames = 0;
  272. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  273. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  274. return -EINVAL;
  275. }
  276. if (inst->capabilities[CODED_FRAMES].value ==
  277. CODED_FRAMES_PROGRESSIVE)
  278. coded_frames = HFI_BITMASK_FRAME_MBS_ONLY_FLAG;
  279. inst->subcr_params[port].coded_frames = coded_frames;
  280. i_vpr_h(inst, "%s: coded frames: %d", __func__, coded_frames);
  281. rc = venus_hfi_session_property(inst,
  282. HFI_PROP_CODED_FRAMES,
  283. HFI_HOST_FLAGS_NONE,
  284. get_hfi_port(inst, port),
  285. HFI_PAYLOAD_U32,
  286. &coded_frames,
  287. sizeof(u32));
  288. if (rc) {
  289. i_vpr_e(inst, "%s: set property failed\n", __func__);
  290. return rc;
  291. }
  292. return rc;
  293. }
  294. static int msm_vdec_set_min_output_count(struct msm_vidc_inst *inst,
  295. enum msm_vidc_port_type port)
  296. {
  297. int rc = 0;
  298. u32 min_output;
  299. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  300. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  301. return -EINVAL;
  302. }
  303. min_output = inst->buffers.output.min_count;
  304. inst->subcr_params[port].fw_min_count = min_output;
  305. i_vpr_h(inst, "%s: firmware min output count: %d",
  306. __func__, min_output);
  307. rc = venus_hfi_session_property(inst,
  308. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  309. HFI_HOST_FLAGS_NONE,
  310. get_hfi_port(inst, port),
  311. HFI_PAYLOAD_U32,
  312. &min_output,
  313. sizeof(u32));
  314. if (rc) {
  315. i_vpr_e(inst, "%s: set property failed\n", __func__);
  316. return rc;
  317. }
  318. return rc;
  319. }
  320. static int msm_vdec_set_picture_order_count(struct msm_vidc_inst *inst,
  321. enum msm_vidc_port_type port)
  322. {
  323. int rc = 0;
  324. u32 poc = 0;
  325. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  326. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  327. return -EINVAL;
  328. }
  329. inst->subcr_params[port].pic_order_cnt = poc;
  330. i_vpr_h(inst, "%s: picture order count: %d", __func__, poc);
  331. rc = venus_hfi_session_property(inst,
  332. HFI_PROP_PIC_ORDER_CNT_TYPE,
  333. HFI_HOST_FLAGS_NONE,
  334. get_hfi_port(inst, port),
  335. HFI_PAYLOAD_U32,
  336. &poc,
  337. sizeof(u32));
  338. if (rc) {
  339. i_vpr_e(inst, "%s: set property failed\n", __func__);
  340. return rc;
  341. }
  342. return rc;
  343. }
  344. static int msm_vdec_set_colorspace(struct msm_vidc_inst *inst,
  345. enum msm_vidc_port_type port)
  346. {
  347. int rc = 0;
  348. u32 primaries = MSM_VIDC_PRIMARIES_RESERVED;
  349. u32 matrix_coeff = MSM_VIDC_MATRIX_COEFF_RESERVED;
  350. u32 transfer_char = MSM_VIDC_TRANSFER_RESERVED;
  351. u32 full_range = V4L2_QUANTIZATION_DEFAULT;
  352. u32 colour_description_present_flag = 0;
  353. u32 video_signal_type_present_flag = 0, color_info = 0;
  354. /* Unspecified video format */
  355. u32 video_format = 5;
  356. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  357. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  358. return -EINVAL;
  359. }
  360. if (inst->codec == MSM_VIDC_VP9)
  361. return 0;
  362. if (inst->fmts[port].fmt.pix_mp.colorspace != V4L2_COLORSPACE_DEFAULT ||
  363. inst->fmts[port].fmt.pix_mp.ycbcr_enc != V4L2_YCBCR_ENC_DEFAULT ||
  364. inst->fmts[port].fmt.pix_mp.xfer_func != V4L2_XFER_FUNC_DEFAULT) {
  365. colour_description_present_flag = 1;
  366. video_signal_type_present_flag = 1;
  367. primaries = v4l2_color_primaries_to_driver(inst,
  368. inst->fmts[port].fmt.pix_mp.colorspace, __func__);
  369. matrix_coeff = v4l2_matrix_coeff_to_driver(inst,
  370. inst->fmts[port].fmt.pix_mp.ycbcr_enc, __func__);
  371. transfer_char = v4l2_transfer_char_to_driver(inst,
  372. inst->fmts[port].fmt.pix_mp.xfer_func, __func__);
  373. }
  374. if (inst->fmts[port].fmt.pix_mp.quantization !=
  375. V4L2_QUANTIZATION_DEFAULT) {
  376. video_signal_type_present_flag = 1;
  377. full_range = inst->fmts[port].fmt.pix_mp.quantization ==
  378. V4L2_QUANTIZATION_FULL_RANGE ? 1 : 0;
  379. }
  380. color_info = (matrix_coeff & 0xFF) |
  381. ((transfer_char << 8) & 0xFF00) |
  382. ((primaries << 16) & 0xFF0000) |
  383. ((colour_description_present_flag << 24) & 0x1000000) |
  384. ((full_range << 25) & 0x2000000) |
  385. ((video_format << 26) & 0x1C000000) |
  386. ((video_signal_type_present_flag << 29) & 0x20000000);
  387. inst->subcr_params[port].color_info = color_info;
  388. i_vpr_h(inst, "%s: color info: %#x\n", __func__, color_info);
  389. rc = venus_hfi_session_property(inst,
  390. HFI_PROP_SIGNAL_COLOR_INFO,
  391. HFI_HOST_FLAGS_NONE,
  392. get_hfi_port(inst, port),
  393. HFI_PAYLOAD_32_PACKED,
  394. &color_info,
  395. sizeof(u32));
  396. if (rc) {
  397. i_vpr_e(inst, "%s: set property failed\n", __func__);
  398. return rc;
  399. }
  400. return rc;
  401. }
  402. static int msm_vdec_set_profile(struct msm_vidc_inst *inst,
  403. enum msm_vidc_port_type port)
  404. {
  405. int rc = 0;
  406. u32 profile;
  407. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  408. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  409. return -EINVAL;
  410. }
  411. profile = inst->capabilities[PROFILE].value;
  412. inst->subcr_params[port].profile = profile;
  413. i_vpr_h(inst, "%s: profile: %d", __func__, profile);
  414. rc = venus_hfi_session_property(inst,
  415. HFI_PROP_PROFILE,
  416. HFI_HOST_FLAGS_NONE,
  417. get_hfi_port(inst, port),
  418. HFI_PAYLOAD_U32_ENUM,
  419. &profile,
  420. sizeof(u32));
  421. if (rc) {
  422. i_vpr_e(inst, "%s: set property failed\n", __func__);
  423. return rc;
  424. }
  425. return rc;
  426. }
  427. static int msm_vdec_set_level(struct msm_vidc_inst *inst,
  428. enum msm_vidc_port_type port)
  429. {
  430. int rc = 0;
  431. u32 level;
  432. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  433. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  434. return -EINVAL;
  435. }
  436. level = inst->capabilities[LEVEL].value;
  437. inst->subcr_params[port].level = level;
  438. i_vpr_h(inst, "%s: level: %d", __func__, level);
  439. rc = venus_hfi_session_property(inst,
  440. HFI_PROP_LEVEL,
  441. HFI_HOST_FLAGS_NONE,
  442. get_hfi_port(inst, port),
  443. HFI_PAYLOAD_U32_ENUM,
  444. &level,
  445. sizeof(u32));
  446. if (rc) {
  447. i_vpr_e(inst, "%s: set property failed\n", __func__);
  448. return rc;
  449. }
  450. return rc;
  451. }
  452. static int msm_vdec_set_tier(struct msm_vidc_inst *inst,
  453. enum msm_vidc_port_type port)
  454. {
  455. int rc = 0;
  456. u32 tier;
  457. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  458. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  459. return -EINVAL;
  460. }
  461. tier = inst->capabilities[HEVC_TIER].value;
  462. inst->subcr_params[port].tier = tier;
  463. i_vpr_h(inst, "%s: tier: %d", __func__, tier);
  464. rc = venus_hfi_session_property(inst,
  465. HFI_PROP_TIER,
  466. HFI_HOST_FLAGS_NONE,
  467. get_hfi_port(inst, port),
  468. HFI_PAYLOAD_U32_ENUM,
  469. &tier,
  470. sizeof(u32));
  471. if (rc) {
  472. i_vpr_e(inst, "%s: set property failed\n", __func__);
  473. return rc;
  474. }
  475. return rc;
  476. }
  477. static int msm_vdec_set_av1_film_grain_present(struct msm_vidc_inst *inst,
  478. enum msm_vidc_port_type port)
  479. {
  480. int rc = 0;
  481. u32 fg_present;
  482. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  483. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  484. return -EINVAL;
  485. }
  486. inst->subcr_params[port].av1_film_grain_present =
  487. inst->capabilities[FILM_GRAIN].value;
  488. fg_present = inst->subcr_params[port].av1_film_grain_present;
  489. i_vpr_h(inst, "%s: film grain present: %d", __func__, fg_present);
  490. rc = venus_hfi_session_property(inst,
  491. HFI_PROP_AV1_FILM_GRAIN_PRESENT,
  492. HFI_HOST_FLAGS_NONE,
  493. get_hfi_port(inst, port),
  494. HFI_PAYLOAD_U32_ENUM,
  495. &fg_present,
  496. sizeof(u32));
  497. if (rc) {
  498. i_vpr_e(inst, "%s: set property failed\n", __func__);
  499. return rc;
  500. }
  501. return rc;
  502. }
  503. static int msm_vdec_set_av1_superblock_enabled(struct msm_vidc_inst *inst,
  504. enum msm_vidc_port_type port)
  505. {
  506. int rc = 0;
  507. u32 sb_enabled;
  508. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  509. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  510. return -EINVAL;
  511. }
  512. inst->subcr_params[port].av1_super_block_enabled =
  513. inst->capabilities[SUPER_BLOCK].value;
  514. sb_enabled = inst->subcr_params[port].av1_super_block_enabled;
  515. i_vpr_h(inst, "%s: super block enabled: %d", __func__, sb_enabled);
  516. rc = venus_hfi_session_property(inst,
  517. HFI_PROP_AV1_SUPER_BLOCK_ENABLED,
  518. HFI_HOST_FLAGS_NONE,
  519. get_hfi_port(inst, port),
  520. HFI_PAYLOAD_U32_ENUM,
  521. &sb_enabled,
  522. sizeof(u32));
  523. if (rc) {
  524. i_vpr_e(inst, "%s: set property failed\n", __func__);
  525. return rc;
  526. }
  527. return rc;
  528. }
  529. static int msm_vdec_set_opb_enable(struct msm_vidc_inst *inst)
  530. {
  531. int rc = 0;
  532. u32 color_fmt;
  533. u32 opb_enable = 0;
  534. if (inst->codec != MSM_VIDC_AV1)
  535. return 0;
  536. color_fmt = inst->capabilities[PIX_FMTS].value;
  537. if (is_linear_colorformat(color_fmt) ||
  538. inst->capabilities[FILM_GRAIN].value)
  539. opb_enable = 1;
  540. i_vpr_h(inst, "%s: OPB enable: %d", __func__, opb_enable);
  541. rc = venus_hfi_session_property(inst,
  542. HFI_PROP_OPB_ENABLE,
  543. HFI_HOST_FLAGS_NONE,
  544. get_hfi_port(inst, OUTPUT_PORT),
  545. HFI_PAYLOAD_U32,
  546. &opb_enable,
  547. sizeof(u32));
  548. if (rc) {
  549. i_vpr_e(inst, "%s: set property failed\n", __func__);
  550. return rc;
  551. }
  552. return rc;
  553. }
  554. static int msm_vdec_set_colorformat(struct msm_vidc_inst *inst)
  555. {
  556. int rc = 0;
  557. u32 pixelformat;
  558. enum msm_vidc_colorformat_type colorformat;
  559. u32 hfi_colorformat;
  560. pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  561. colorformat = v4l2_colorformat_to_driver(inst, pixelformat, __func__);
  562. hfi_colorformat = get_hfi_colorformat(inst, colorformat);
  563. i_vpr_h(inst, "%s: hfi colorformat: %d",
  564. __func__, hfi_colorformat);
  565. rc = venus_hfi_session_property(inst,
  566. HFI_PROP_COLOR_FORMAT,
  567. HFI_HOST_FLAGS_NONE,
  568. get_hfi_port(inst, OUTPUT_PORT),
  569. HFI_PAYLOAD_U32,
  570. &hfi_colorformat,
  571. sizeof(u32));
  572. if (rc) {
  573. i_vpr_e(inst, "%s: set property failed\n", __func__);
  574. return rc;
  575. }
  576. return rc;
  577. }
  578. static int msm_vdec_set_output_properties(struct msm_vidc_inst *inst)
  579. {
  580. int rc = 0;
  581. if (!inst) {
  582. d_vpr_e("%s: invalid params\n", __func__);
  583. return -EINVAL;
  584. }
  585. rc = msm_vdec_set_opb_enable(inst);
  586. if (rc)
  587. return rc;
  588. rc = msm_vdec_set_colorformat(inst);
  589. if (rc)
  590. return rc;
  591. rc = msm_vdec_set_linear_stride_scanline(inst);
  592. if (rc)
  593. return rc;
  594. rc = msm_vdec_set_ubwc_stride_scanline(inst);
  595. if (rc)
  596. return rc;
  597. rc = msm_vidc_set_session_priority(inst, PRIORITY);
  598. if (rc)
  599. return rc;
  600. return rc;
  601. }
  602. int msm_vdec_get_input_internal_buffers(struct msm_vidc_inst *inst)
  603. {
  604. int rc = 0;
  605. u32 i = 0;
  606. if (!inst) {
  607. d_vpr_e("%s: invalid params\n", __func__);
  608. return -EINVAL;
  609. }
  610. for (i = 0; i < ARRAY_SIZE(msm_vdec_internal_buffer_type); i++) {
  611. rc = msm_vidc_get_internal_buffers(inst, msm_vdec_internal_buffer_type[i]);
  612. if (rc)
  613. return rc;
  614. }
  615. return rc;
  616. }
  617. static int msm_vdec_get_output_internal_buffers(struct msm_vidc_inst *inst)
  618. {
  619. int rc = 0;
  620. if (!inst) {
  621. d_vpr_e("%s: invalid params\n", __func__);
  622. return -EINVAL;
  623. }
  624. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  625. if (rc)
  626. return rc;
  627. return rc;
  628. }
  629. static int msm_vdec_destroy_internal_buffers(struct msm_vidc_inst *inst,
  630. enum msm_vidc_port_type port)
  631. {
  632. int rc = 0;
  633. struct msm_vidc_buffers *buffers;
  634. struct msm_vidc_buffer *buf, *dummy;
  635. const u32 *internal_buf_type;
  636. u32 i, len;
  637. if (port == INPUT_PORT) {
  638. internal_buf_type = msm_vdec_internal_buffer_type;
  639. len = ARRAY_SIZE(msm_vdec_internal_buffer_type);
  640. } else {
  641. internal_buf_type = msm_vdec_output_internal_buffer_type;
  642. len = ARRAY_SIZE(msm_vdec_output_internal_buffer_type);
  643. }
  644. for (i = 0; i < len; i++) {
  645. buffers = msm_vidc_get_buffers(inst, internal_buf_type[i], __func__);
  646. if (!buffers)
  647. return -EINVAL;
  648. if (buffers->reuse) {
  649. i_vpr_l(inst, "%s: reuse enabled for %s\n", __func__,
  650. buf_name(internal_buf_type[i]));
  651. continue;
  652. }
  653. list_for_each_entry_safe(buf, dummy, &buffers->list, list) {
  654. i_vpr_h(inst,
  655. "%s: destroying internal buffer: type %d idx %d fd %d addr %#llx size %d\n",
  656. __func__, buf->type, buf->index, buf->fd,
  657. buf->device_addr, buf->buffer_size);
  658. rc = msm_vidc_destroy_internal_buffer(inst, buf);
  659. if (rc)
  660. return rc;
  661. }
  662. }
  663. return 0;
  664. }
  665. int msm_vdec_create_input_internal_buffers(struct msm_vidc_inst *inst)
  666. {
  667. int rc = 0;
  668. u32 i = 0;
  669. for (i = 0; i < ARRAY_SIZE(msm_vdec_internal_buffer_type); i++) {
  670. rc = msm_vidc_create_internal_buffers(inst, msm_vdec_internal_buffer_type[i]);
  671. if (rc)
  672. return rc;
  673. }
  674. return 0;
  675. }
  676. static int msm_vdec_create_output_internal_buffers(struct msm_vidc_inst *inst)
  677. {
  678. int rc = 0;
  679. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  680. if (rc)
  681. return rc;
  682. return 0;
  683. }
  684. int msm_vdec_queue_input_internal_buffers(struct msm_vidc_inst *inst)
  685. {
  686. int rc = 0;
  687. u32 i = 0;
  688. for (i = 0; i < ARRAY_SIZE(msm_vdec_internal_buffer_type); i++) {
  689. rc = msm_vidc_queue_internal_buffers(inst, msm_vdec_internal_buffer_type[i]);
  690. if (rc)
  691. return rc;
  692. }
  693. return 0;
  694. }
  695. static int msm_vdec_queue_output_internal_buffers(struct msm_vidc_inst *inst)
  696. {
  697. int rc = 0;
  698. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  699. if (rc)
  700. return rc;
  701. return 0;
  702. }
  703. int msm_vdec_release_input_internal_buffers(struct msm_vidc_inst *inst)
  704. {
  705. int rc = 0;
  706. u32 i = 0;
  707. i_vpr_h(inst, "%s()\n",__func__);
  708. for (i = 0; i < ARRAY_SIZE(msm_vdec_internal_buffer_type); i++) {
  709. rc = msm_vidc_release_internal_buffers(inst, msm_vdec_internal_buffer_type[i]);
  710. if (rc)
  711. return rc;
  712. }
  713. return 0;
  714. }
  715. static int msm_vdec_subscribe_input_port_settings_change(struct msm_vidc_inst *inst,
  716. enum msm_vidc_port_type port)
  717. {
  718. int rc = 0;
  719. struct msm_vidc_core *core;
  720. u32 payload[32] = {0};
  721. u32 i, j;
  722. u32 subscribe_psc_size;
  723. const u32 *psc;
  724. static const struct msm_vdec_prop_type_handle prop_type_handle_arr[] = {
  725. {HFI_PROP_BITSTREAM_RESOLUTION, msm_vdec_set_bitstream_resolution },
  726. {HFI_PROP_CROP_OFFSETS, msm_vdec_set_crop_offsets },
  727. {HFI_PROP_LUMA_CHROMA_BIT_DEPTH, msm_vdec_set_bit_depth },
  728. {HFI_PROP_CODED_FRAMES, msm_vdec_set_coded_frames },
  729. {HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT, msm_vdec_set_min_output_count },
  730. {HFI_PROP_PIC_ORDER_CNT_TYPE, msm_vdec_set_picture_order_count },
  731. {HFI_PROP_SIGNAL_COLOR_INFO, msm_vdec_set_colorspace },
  732. {HFI_PROP_PROFILE, msm_vdec_set_profile },
  733. {HFI_PROP_LEVEL, msm_vdec_set_level },
  734. {HFI_PROP_TIER, msm_vdec_set_tier },
  735. {HFI_PROP_AV1_FILM_GRAIN_PRESENT, msm_vdec_set_av1_film_grain_present },
  736. {HFI_PROP_AV1_SUPER_BLOCK_ENABLED, msm_vdec_set_av1_superblock_enabled },
  737. };
  738. if (!inst || !inst->core) {
  739. d_vpr_e("%s: invalid params\n", __func__);
  740. return -EINVAL;
  741. }
  742. i_vpr_h(inst, "%s()\n", __func__);
  743. core = inst->core;
  744. if (!core->platform) {
  745. d_vpr_e("%s: invalid platform data\n", __func__);
  746. return -EINVAL;
  747. }
  748. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  749. if (inst->codec == MSM_VIDC_H264) {
  750. subscribe_psc_size = core->platform->data.psc_avc_tbl_size;
  751. psc = core->platform->data.psc_avc_tbl;
  752. } else if (inst->codec == MSM_VIDC_HEVC || inst->codec == MSM_VIDC_HEIC) {
  753. subscribe_psc_size = core->platform->data.psc_hevc_tbl_size;
  754. psc = core->platform->data.psc_hevc_tbl;
  755. } else if (inst->codec == MSM_VIDC_VP9) {
  756. subscribe_psc_size = core->platform->data.psc_vp9_tbl_size;
  757. psc = core->platform->data.psc_vp9_tbl;
  758. } else if (inst->codec == MSM_VIDC_AV1) {
  759. subscribe_psc_size = core->platform->data.psc_av1_tbl_size;
  760. psc = core->platform->data.psc_av1_tbl;
  761. } else {
  762. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  763. psc = NULL;
  764. return -EINVAL;
  765. }
  766. if (!psc || !subscribe_psc_size) {
  767. i_vpr_e(inst, "%s: invalid params\n", __func__);
  768. return -EINVAL;
  769. }
  770. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  771. for (i = 0; i < subscribe_psc_size; i++)
  772. payload[i + 1] = psc[i];
  773. rc = venus_hfi_session_command(inst,
  774. HFI_CMD_SUBSCRIBE_MODE,
  775. port,
  776. HFI_PAYLOAD_U32_ARRAY,
  777. &payload[0],
  778. ((subscribe_psc_size + 1) *
  779. sizeof(u32)));
  780. for (i = 0; i < subscribe_psc_size; i++) {
  781. /* set session properties */
  782. for (j = 0; j < ARRAY_SIZE(prop_type_handle_arr); j++) {
  783. if (prop_type_handle_arr[j].type == psc[i]) {
  784. rc = prop_type_handle_arr[j].handle(inst, port);
  785. if (rc)
  786. goto exit;
  787. break;
  788. }
  789. }
  790. /* is property type unknown ? */
  791. if (j == ARRAY_SIZE(prop_type_handle_arr))
  792. i_vpr_e(inst, "%s: unknown property %#x\n", __func__, psc[i]);
  793. }
  794. exit:
  795. return rc;
  796. }
  797. static int msm_vdec_subscribe_property(struct msm_vidc_inst *inst,
  798. enum msm_vidc_port_type port)
  799. {
  800. int rc = 0;
  801. u32 payload[32] = {0};
  802. u32 i, count = 0;
  803. bool allow = false;
  804. struct msm_vidc_core *core;
  805. u32 subscribe_prop_size;
  806. const u32 *subcribe_prop;
  807. if (!inst || !inst->core) {
  808. d_vpr_e("%s: invalid params\n", __func__);
  809. return -EINVAL;
  810. }
  811. core = inst->core;
  812. i_vpr_h(inst, "%s()\n", __func__);
  813. if (!core->platform) {
  814. d_vpr_e("%s: invalid platform data\n", __func__);
  815. return -EINVAL;
  816. }
  817. payload[0] = HFI_MODE_PROPERTY;
  818. if (port == INPUT_PORT) {
  819. subscribe_prop_size = core->platform->data.dec_input_prop_size;
  820. subcribe_prop = core->platform->data.dec_input_prop;
  821. for (i = 0; i < subscribe_prop_size; i++) {
  822. allow = msm_vidc_allow_property(inst,
  823. subcribe_prop[i]);
  824. if (allow) {
  825. payload[count + 1] = subcribe_prop[i];
  826. count++;
  827. }
  828. if (subcribe_prop[i] == HFI_PROP_DPB_LIST) {
  829. inst->subcr_params[port].dpb_list_enabled = true;
  830. i_vpr_h(inst, "%s: DPB_LIST suscribed on input port", __func__);
  831. }
  832. }
  833. } else if (port == OUTPUT_PORT) {
  834. subscribe_prop_size = core->platform->data.dec_output_prop_size;
  835. subcribe_prop = core->platform->data.dec_output_prop;
  836. for (i = 0; i < subscribe_prop_size; i++) {
  837. allow = msm_vidc_allow_property(inst,
  838. subcribe_prop[i]);
  839. if (allow) {
  840. payload[count + 1] = subcribe_prop[i];
  841. count++;
  842. }
  843. if (subcribe_prop[i] == HFI_PROP_DPB_LIST) {
  844. inst->subcr_params[port].dpb_list_enabled = true;
  845. i_vpr_h(inst, "%s: DPB_LIST suscribed on output port", __func__);
  846. }
  847. }
  848. } else {
  849. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  850. return -EINVAL;
  851. }
  852. rc = venus_hfi_session_command(inst,
  853. HFI_CMD_SUBSCRIBE_MODE,
  854. port,
  855. HFI_PAYLOAD_U32_ARRAY,
  856. &payload[0],
  857. (count + 1) * sizeof(u32));
  858. if (rc)
  859. return rc;
  860. return rc;
  861. }
  862. static int msm_vdec_subscribe_metadata(struct msm_vidc_inst *inst,
  863. enum msm_vidc_port_type port)
  864. {
  865. int rc = 0;
  866. u32 payload[32] = {0};
  867. u32 i, count = 0;
  868. if (!inst) {
  869. d_vpr_e("%s: invalid params\n", __func__);
  870. return -EINVAL;
  871. }
  872. i_vpr_h(inst, "%s()\n", __func__);
  873. payload[0] = HFI_MODE_METADATA;
  874. if (port == INPUT_PORT) {
  875. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  876. if (is_meta_rx_inp_enabled(inst, i) &&
  877. msm_vidc_allow_metadata_subscription(
  878. inst, i, port)) {
  879. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  880. i_vpr_e(inst,
  881. "%s: input metadatas (%d) exceeded limit (%d)\n",
  882. __func__, count, sizeof(payload) / sizeof(u32));
  883. return -EINVAL;
  884. }
  885. payload[count + 1] = inst->capabilities[i].hfi_id;
  886. count++;
  887. }
  888. }
  889. } else if (port == OUTPUT_PORT) {
  890. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  891. if (is_meta_rx_out_enabled(inst, i) &&
  892. msm_vidc_allow_metadata_subscription(
  893. inst, i, port)) {
  894. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  895. i_vpr_e(inst,
  896. "%s: input metadatas (%d) exceeded limit (%d)\n",
  897. __func__, count, sizeof(payload) / sizeof(u32));
  898. return -EINVAL;
  899. }
  900. payload[count + 1] = inst->capabilities[i].hfi_id;
  901. count++;
  902. }
  903. }
  904. } else {
  905. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  906. return -EINVAL;
  907. }
  908. rc = venus_hfi_session_command(inst,
  909. HFI_CMD_SUBSCRIBE_MODE,
  910. port,
  911. HFI_PAYLOAD_U32_ARRAY,
  912. &payload[0],
  913. (count + 1) * sizeof(u32));
  914. if (rc)
  915. return rc;
  916. return rc;
  917. }
  918. static int msm_vdec_set_delivery_mode_metadata(struct msm_vidc_inst *inst,
  919. enum msm_vidc_port_type port)
  920. {
  921. int rc = 0;
  922. u32 payload[32] = {0};
  923. u32 i, count = 0;
  924. if (!inst) {
  925. d_vpr_e("%s: invalid params\n", __func__);
  926. return -EINVAL;
  927. }
  928. i_vpr_h(inst, "%s()\n", __func__);
  929. payload[0] = HFI_MODE_METADATA;
  930. if (port == INPUT_PORT) {
  931. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  932. if (is_meta_tx_inp_enabled(inst, i)) {
  933. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  934. i_vpr_e(inst,
  935. "%s: input metadatas (%d) exceeded limit (%d)\n",
  936. __func__, count, sizeof(payload) / sizeof(u32));
  937. return -EINVAL;
  938. }
  939. payload[count + 1] = inst->capabilities[i].hfi_id;
  940. count++;
  941. }
  942. }
  943. } else if (port == OUTPUT_PORT) {
  944. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  945. if (is_meta_tx_out_enabled(inst, i) &&
  946. msm_vidc_allow_metadata_delivery(
  947. inst, i, port)) {
  948. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  949. i_vpr_e(inst,
  950. "%s: input metadatas (%d) exceeded limit (%d)\n",
  951. __func__, count, sizeof(payload) / sizeof(u32));
  952. return -EINVAL;
  953. }
  954. payload[count + 1] = inst->capabilities[i].hfi_id;
  955. count++;
  956. }
  957. }
  958. } else {
  959. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  960. return -EINVAL;
  961. }
  962. rc = venus_hfi_session_command(inst,
  963. HFI_CMD_DELIVERY_MODE,
  964. port,
  965. HFI_PAYLOAD_U32_ARRAY,
  966. &payload[0],
  967. (count + 1) * sizeof(u32));
  968. if (rc)
  969. return rc;
  970. return rc;
  971. }
  972. static int msm_vdec_set_delivery_mode_property(struct msm_vidc_inst *inst,
  973. enum msm_vidc_port_type port)
  974. {
  975. int rc = 0;
  976. u32 payload[32] = {0};
  977. u32 i, count = 0;
  978. static const u32 property_output_list[] = {
  979. META_OUTBUF_FENCE,
  980. };
  981. static const u32 property_input_list[] = {};
  982. if (!inst) {
  983. d_vpr_e("%s: invalid params\n", __func__);
  984. return -EINVAL;
  985. }
  986. i_vpr_h(inst, "%s()\n", __func__);
  987. payload[0] = HFI_MODE_PROPERTY;
  988. if (port == INPUT_PORT) {
  989. for (i = 0; i < ARRAY_SIZE(property_input_list); i++) {
  990. if (inst->capabilities[property_input_list[i]].value) {
  991. payload[count + 1] =
  992. inst->capabilities[property_input_list[i]].hfi_id;
  993. count++;
  994. }
  995. }
  996. } else if (port == OUTPUT_PORT) {
  997. for (i = 0; i < ARRAY_SIZE(property_output_list); i++) {
  998. if (property_output_list[i] == META_OUTBUF_FENCE &&
  999. is_meta_rx_inp_enabled(inst, META_OUTBUF_FENCE)) {
  1000. /*
  1001. * if output buffer fence enabled via
  1002. * META_OUTBUF_FENCE, then driver will send
  1003. * fence id via HFI_PROP_FENCE to firmware.
  1004. * So enable HFI_PROP_FENCE property as
  1005. * delivery mode property.
  1006. */
  1007. payload[count + 1] =
  1008. inst->capabilities[property_output_list[i]].hfi_id;
  1009. count++;
  1010. continue;
  1011. }
  1012. if (inst->capabilities[property_output_list[i]].value) {
  1013. payload[count + 1] =
  1014. inst->capabilities[property_output_list[i]].hfi_id;
  1015. count++;
  1016. }
  1017. }
  1018. } else {
  1019. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  1020. return -EINVAL;
  1021. }
  1022. rc = venus_hfi_session_command(inst,
  1023. HFI_CMD_DELIVERY_MODE,
  1024. port,
  1025. HFI_PAYLOAD_U32_ARRAY,
  1026. &payload[0],
  1027. (count + 1) * sizeof(u32));
  1028. if (rc)
  1029. return rc;
  1030. return rc;
  1031. }
  1032. int msm_vdec_init_input_subcr_params(struct msm_vidc_inst *inst)
  1033. {
  1034. struct msm_vidc_subscription_params *subsc_params;
  1035. u32 left_offset, top_offset, right_offset, bottom_offset;
  1036. u32 primaries, matrix_coeff, transfer_char;
  1037. u32 full_range = 0, video_format = 0;
  1038. u32 colour_description_present_flag = 0;
  1039. u32 video_signal_type_present_flag = 0;
  1040. if (!inst) {
  1041. d_vpr_e("%s: invalid params\n", __func__);
  1042. return -EINVAL;
  1043. }
  1044. subsc_params = &inst->subcr_params[INPUT_PORT];
  1045. subsc_params->bitstream_resolution =
  1046. inst->fmts[INPUT_PORT].fmt.pix_mp.width << 16 |
  1047. inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1048. left_offset = inst->crop.left;
  1049. top_offset = inst->crop.top;
  1050. right_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  1051. inst->crop.width);
  1052. bottom_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  1053. inst->crop.height);
  1054. subsc_params->crop_offsets[0] =
  1055. left_offset << 16 | top_offset;
  1056. subsc_params->crop_offsets[1] =
  1057. right_offset << 16 | bottom_offset;
  1058. subsc_params->fw_min_count = inst->buffers.output.min_count;
  1059. primaries = v4l2_color_primaries_to_driver(inst,
  1060. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace, __func__);
  1061. matrix_coeff = v4l2_matrix_coeff_to_driver(inst,
  1062. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc, __func__);
  1063. transfer_char = v4l2_transfer_char_to_driver(inst,
  1064. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func, __func__);
  1065. full_range = inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization ==
  1066. V4L2_QUANTIZATION_FULL_RANGE ? 1 : 0;
  1067. subsc_params->color_info =
  1068. (matrix_coeff & 0xFF) |
  1069. ((transfer_char << 8) & 0xFF00) |
  1070. ((primaries << 16) & 0xFF0000) |
  1071. ((colour_description_present_flag << 24) & 0x1000000) |
  1072. ((full_range << 25) & 0x2000000) |
  1073. ((video_format << 26) & 0x1C000000) |
  1074. ((video_signal_type_present_flag << 29) & 0x20000000);
  1075. subsc_params->profile = inst->capabilities[PROFILE].value;
  1076. subsc_params->level = inst->capabilities[LEVEL].value;
  1077. subsc_params->tier = inst->capabilities[HEVC_TIER].value;
  1078. subsc_params->pic_order_cnt = inst->capabilities[POC].value;
  1079. subsc_params->bit_depth = inst->capabilities[BIT_DEPTH].value;
  1080. if (inst->capabilities[CODED_FRAMES].value ==
  1081. CODED_FRAMES_PROGRESSIVE)
  1082. subsc_params->coded_frames = HFI_BITMASK_FRAME_MBS_ONLY_FLAG;
  1083. else
  1084. subsc_params->coded_frames = 0;
  1085. return 0;
  1086. }
  1087. int msm_vdec_set_num_comv(struct msm_vidc_inst *inst)
  1088. {
  1089. int rc = 0;
  1090. u32 num_comv = 0;
  1091. if (!inst) {
  1092. d_vpr_e("%s: invalid params\n", __func__);
  1093. return -EINVAL;
  1094. }
  1095. num_comv = inst->capabilities[NUM_COMV].value;
  1096. i_vpr_h(inst, "%s: num COMV: %d", __func__, num_comv);
  1097. rc = venus_hfi_session_property(inst,
  1098. HFI_PROP_COMV_BUFFER_COUNT,
  1099. HFI_HOST_FLAGS_NONE,
  1100. get_hfi_port(inst, INPUT_PORT),
  1101. HFI_PAYLOAD_U32,
  1102. &num_comv,
  1103. sizeof(u32));
  1104. if (rc) {
  1105. i_vpr_e(inst, "%s: set property failed\n", __func__);
  1106. return rc;
  1107. }
  1108. return rc;
  1109. }
  1110. static int msm_vdec_read_input_subcr_params(struct msm_vidc_inst *inst)
  1111. {
  1112. struct msm_vidc_subscription_params subsc_params;
  1113. struct msm_vidc_core *core;
  1114. u32 width, height;
  1115. u32 primaries, matrix_coeff, transfer_char;
  1116. u32 full_range = 0;
  1117. u32 colour_description_present_flag = 0;
  1118. u32 video_signal_type_present_flag = 0;
  1119. enum msm_vidc_colorformat_type output_fmt;
  1120. if (!inst || !inst->core) {
  1121. d_vpr_e("%s: invalid params\n", __func__);
  1122. return -EINVAL;
  1123. }
  1124. core = inst->core;
  1125. subsc_params = inst->subcr_params[INPUT_PORT];
  1126. width = (subsc_params.bitstream_resolution &
  1127. HFI_BITMASK_BITSTREAM_WIDTH) >> 16;
  1128. height = subsc_params.bitstream_resolution &
  1129. HFI_BITMASK_BITSTREAM_HEIGHT;
  1130. inst->fmts[INPUT_PORT].fmt.pix_mp.width = width;
  1131. inst->fmts[INPUT_PORT].fmt.pix_mp.height = height;
  1132. output_fmt = v4l2_colorformat_to_driver(inst,
  1133. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, __func__);
  1134. inst->fmts[OUTPUT_PORT].fmt.pix_mp.width = video_y_stride_pix(
  1135. output_fmt, width);
  1136. inst->fmts[OUTPUT_PORT].fmt.pix_mp.height = video_y_scanlines(
  1137. output_fmt, height);
  1138. inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].bytesperline =
  1139. video_y_stride_bytes(output_fmt, width);
  1140. inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage =
  1141. call_session_op(core, buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  1142. //inst->buffers.output.size = inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage;
  1143. matrix_coeff = subsc_params.color_info & 0xFF;
  1144. transfer_char = (subsc_params.color_info & 0xFF00) >> 8;
  1145. primaries = (subsc_params.color_info & 0xFF0000) >> 16;
  1146. colour_description_present_flag =
  1147. (subsc_params.color_info & 0x1000000) >> 24;
  1148. full_range = (subsc_params.color_info & 0x2000000) >> 25;
  1149. video_signal_type_present_flag =
  1150. (subsc_params.color_info & 0x20000000) >> 29;
  1151. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
  1152. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
  1153. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
  1154. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
  1155. if (video_signal_type_present_flag) {
  1156. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization =
  1157. full_range ?
  1158. V4L2_QUANTIZATION_FULL_RANGE :
  1159. V4L2_QUANTIZATION_LIM_RANGE;
  1160. if (colour_description_present_flag) {
  1161. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace =
  1162. v4l2_color_primaries_from_driver(inst, primaries, __func__);
  1163. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func =
  1164. v4l2_transfer_char_from_driver(inst, transfer_char, __func__);
  1165. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc =
  1166. v4l2_matrix_coeff_from_driver(inst, matrix_coeff, __func__);
  1167. } else {
  1168. i_vpr_h(inst,
  1169. "%s: color description flag is not present\n",
  1170. __func__);
  1171. }
  1172. } else {
  1173. i_vpr_h(inst, "%s: video_signal type is not present\n",
  1174. __func__);
  1175. }
  1176. /* align input port color info with output port */
  1177. inst->fmts[INPUT_PORT].fmt.pix_mp.colorspace =
  1178. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace;
  1179. inst->fmts[INPUT_PORT].fmt.pix_mp.xfer_func =
  1180. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func;
  1181. inst->fmts[INPUT_PORT].fmt.pix_mp.ycbcr_enc =
  1182. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc;
  1183. inst->fmts[INPUT_PORT].fmt.pix_mp.quantization =
  1184. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization;
  1185. inst->buffers.output.min_count = subsc_params.fw_min_count;
  1186. inst->fw_min_count = subsc_params.fw_min_count;
  1187. inst->buffers.output.extra_count = call_session_op(core,
  1188. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  1189. inst->buffers.output_meta.min_count = inst->buffers.output.min_count;
  1190. inst->buffers.output_meta.extra_count = inst->buffers.output.extra_count;
  1191. if (is_thumbnail_session(inst) && inst->codec != MSM_VIDC_VP9) {
  1192. if (inst->buffers.output.min_count != 1) {
  1193. i_vpr_e(inst, "%s: invalid min count %d in thumbnail case\n",
  1194. __func__, inst->buffers.output.min_count);
  1195. msm_vidc_change_state(inst, MSM_VIDC_ERROR, __func__);
  1196. }
  1197. }
  1198. inst->crop.top = subsc_params.crop_offsets[0] & 0xFFFF;
  1199. inst->crop.left = (subsc_params.crop_offsets[0] >> 16) & 0xFFFF;
  1200. inst->crop.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  1201. (subsc_params.crop_offsets[1] & 0xFFFF) - inst->crop.top;
  1202. inst->crop.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  1203. ((subsc_params.crop_offsets[1] >> 16) & 0xFFFF) - inst->crop.left;
  1204. msm_vidc_update_cap_value(inst, PROFILE, subsc_params.profile, __func__);
  1205. msm_vidc_update_cap_value(inst, LEVEL, subsc_params.level, __func__);
  1206. msm_vidc_update_cap_value(inst, HEVC_TIER, subsc_params.tier, __func__);
  1207. msm_vidc_update_cap_value(inst, POC, subsc_params.pic_order_cnt, __func__);
  1208. if (subsc_params.bit_depth == BIT_DEPTH_8)
  1209. msm_vidc_update_cap_value(inst, BIT_DEPTH, BIT_DEPTH_8, __func__);
  1210. else
  1211. msm_vidc_update_cap_value(inst, BIT_DEPTH, BIT_DEPTH_10, __func__);
  1212. if (subsc_params.coded_frames & HFI_BITMASK_FRAME_MBS_ONLY_FLAG)
  1213. msm_vidc_update_cap_value(inst, CODED_FRAMES, CODED_FRAMES_PROGRESSIVE, __func__);
  1214. else
  1215. msm_vidc_update_cap_value(inst, CODED_FRAMES, CODED_FRAMES_INTERLACE, __func__);
  1216. if (inst->codec == MSM_VIDC_AV1) {
  1217. msm_vidc_update_cap_value(inst, FILM_GRAIN,
  1218. subsc_params.av1_film_grain_present, __func__);
  1219. msm_vidc_update_cap_value(inst, SUPER_BLOCK,
  1220. subsc_params.av1_super_block_enabled, __func__);
  1221. }
  1222. /* disable META_OUTBUF_FENCE if session is Interlace type */
  1223. if (inst->capabilities[CODED_FRAMES].value ==
  1224. CODED_FRAMES_INTERLACE) {
  1225. msm_vidc_update_cap_value(inst, META_OUTBUF_FENCE,
  1226. MSM_VIDC_META_RX_INPUT |
  1227. MSM_VIDC_META_DISABLE, __func__);
  1228. }
  1229. return 0;
  1230. }
  1231. int msm_vdec_input_port_settings_change(struct msm_vidc_inst *inst)
  1232. {
  1233. u32 rc = 0;
  1234. struct v4l2_event event = {0};
  1235. if (!inst->bufq[INPUT_PORT].vb2q->streaming) {
  1236. i_vpr_e(inst, "%s: input port not streaming\n",
  1237. __func__);
  1238. return 0;
  1239. }
  1240. rc = msm_vdec_read_input_subcr_params(inst);
  1241. if (rc)
  1242. return rc;
  1243. event.type = V4L2_EVENT_SOURCE_CHANGE;
  1244. event.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION;
  1245. v4l2_event_queue_fh(&inst->event_handler, &event);
  1246. return rc;
  1247. }
  1248. int msm_vdec_output_port_settings_change(struct msm_vidc_inst *inst)
  1249. {
  1250. return 0;
  1251. }
  1252. int msm_vdec_streamoff_input(struct msm_vidc_inst *inst)
  1253. {
  1254. int rc = 0;
  1255. if (!inst || !inst->core) {
  1256. d_vpr_e("%s: invalid params\n", __func__);
  1257. return -EINVAL;
  1258. }
  1259. rc = msm_vidc_session_streamoff(inst, INPUT_PORT);
  1260. if (rc)
  1261. return rc;
  1262. return 0;
  1263. }
  1264. int msm_vdec_streamon_input(struct msm_vidc_inst *inst)
  1265. {
  1266. int rc = 0;
  1267. if (!inst || !inst->core) {
  1268. d_vpr_e("%s: invalid params\n", __func__);
  1269. return -EINVAL;
  1270. }
  1271. if (is_input_meta_enabled(inst) &&
  1272. !inst->bufq[INPUT_META_PORT].vb2q->streaming) {
  1273. i_vpr_e(inst,
  1274. "%s: Meta port must be streamed on before data port\n",
  1275. __func__);
  1276. return -EINVAL;
  1277. }
  1278. rc = msm_vidc_check_session_supported(inst);
  1279. if (rc)
  1280. goto error;
  1281. rc = msm_vidc_set_v4l2_properties(inst);
  1282. if (rc)
  1283. goto error;
  1284. /* Decide bse vpp delay after work mode */
  1285. //msm_vidc_set_bse_vpp_delay(inst);
  1286. rc = msm_vdec_get_input_internal_buffers(inst);
  1287. if (rc)
  1288. goto error;
  1289. /* check for memory after all buffers calculation */
  1290. //rc = msm_vidc_check_memory_supported(inst);
  1291. if (rc)
  1292. goto error;
  1293. rc = msm_vdec_destroy_internal_buffers(inst, INPUT_PORT);
  1294. if (rc)
  1295. goto error;
  1296. rc = msm_vdec_create_input_internal_buffers(inst);
  1297. if (rc)
  1298. goto error;
  1299. rc = msm_vdec_queue_input_internal_buffers(inst);
  1300. if (rc)
  1301. goto error;
  1302. if (!inst->ipsc_properties_set) {
  1303. rc = msm_vdec_subscribe_input_port_settings_change(
  1304. inst, INPUT_PORT);
  1305. if (rc)
  1306. goto error;
  1307. inst->ipsc_properties_set = true;
  1308. }
  1309. rc = msm_vdec_subscribe_property(inst, INPUT_PORT);
  1310. if (rc)
  1311. goto error;
  1312. rc = msm_vdec_subscribe_metadata(inst, INPUT_PORT);
  1313. if (rc)
  1314. goto error;
  1315. /*
  1316. * Subscribe output metadatas in input port sequence as well so that
  1317. * metadatas detected in bitstream before output port is started
  1318. * are not missed.
  1319. * Example: AV1 HDR metadata which can be part of
  1320. * first ETB (sequence header OBU + metadata OBU)
  1321. */
  1322. rc = msm_vdec_subscribe_metadata(inst, OUTPUT_PORT);
  1323. if (rc)
  1324. goto error;
  1325. rc = msm_vdec_set_delivery_mode_metadata(inst, INPUT_PORT);
  1326. if (rc)
  1327. goto error;
  1328. rc = msm_vidc_process_streamon_input(inst);
  1329. if (rc)
  1330. goto error;
  1331. rc = msm_vidc_flush_ts(inst);
  1332. if (rc)
  1333. goto error;
  1334. rc = msm_vidc_ts_reorder_flush(inst);
  1335. if (rc)
  1336. goto error;
  1337. return 0;
  1338. error:
  1339. i_vpr_e(inst, "%s: failed\n", __func__);
  1340. msm_vdec_streamoff_input(inst);
  1341. return rc;
  1342. }
  1343. static int schedule_batch_work(struct msm_vidc_inst *inst)
  1344. {
  1345. struct msm_vidc_core *core;
  1346. if (!inst || !inst->core) {
  1347. d_vpr_e("%s: invalid params\n", __func__);
  1348. return -EINVAL;
  1349. }
  1350. core = inst->core;
  1351. mod_delayed_work(core->batch_workq, &inst->decode_batch.work,
  1352. msecs_to_jiffies(core->capabilities[DECODE_BATCH_TIMEOUT].value));
  1353. return 0;
  1354. }
  1355. static int cancel_batch_work(struct msm_vidc_inst *inst)
  1356. {
  1357. if (!inst) {
  1358. d_vpr_e("%s: Invalid arguments\n", __func__);
  1359. return -EINVAL;
  1360. }
  1361. cancel_delayed_work(&inst->decode_batch.work);
  1362. return 0;
  1363. }
  1364. int msm_vdec_streamoff_output(struct msm_vidc_inst *inst)
  1365. {
  1366. int rc = 0;
  1367. if (!inst || !inst->core) {
  1368. d_vpr_e("%s: invalid params\n", __func__);
  1369. return -EINVAL;
  1370. }
  1371. /* cancel pending batch work */
  1372. cancel_batch_work(inst);
  1373. rc = msm_vidc_session_streamoff(inst, OUTPUT_PORT);
  1374. if (rc)
  1375. return rc;
  1376. return 0;
  1377. }
  1378. static int msm_vdec_subscribe_output_port_settings_change(struct msm_vidc_inst *inst,
  1379. enum msm_vidc_port_type port)
  1380. {
  1381. int rc = 0;
  1382. struct msm_vidc_core *core;
  1383. u32 payload[32] = {0};
  1384. u32 prop_type, payload_size, payload_type;
  1385. u32 i;
  1386. struct msm_vidc_subscription_params subsc_params;
  1387. u32 subscribe_psc_size = 0;
  1388. const u32 *psc = NULL;
  1389. if (!inst || !inst->core) {
  1390. d_vpr_e("%s: invalid params\n", __func__);
  1391. return -EINVAL;
  1392. }
  1393. i_vpr_h(inst, "%s()\n", __func__);
  1394. core = inst->core;
  1395. if (!core->platform) {
  1396. d_vpr_e("%s: invalid platform data\n", __func__);
  1397. return -EINVAL;
  1398. }
  1399. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  1400. if (inst->codec == MSM_VIDC_H264) {
  1401. subscribe_psc_size = core->platform->data.psc_avc_tbl_size;
  1402. psc = core->platform->data.psc_avc_tbl;
  1403. } else if (inst->codec == MSM_VIDC_HEVC || inst->codec == MSM_VIDC_HEIC) {
  1404. subscribe_psc_size = core->platform->data.psc_hevc_tbl_size;
  1405. psc = core->platform->data.psc_hevc_tbl;
  1406. } else if (inst->codec == MSM_VIDC_VP9) {
  1407. subscribe_psc_size = core->platform->data.psc_vp9_tbl_size;
  1408. psc = core->platform->data.psc_vp9_tbl;
  1409. } else if (inst->codec == MSM_VIDC_AV1) {
  1410. subscribe_psc_size = core->platform->data.psc_av1_tbl_size;
  1411. psc = core->platform->data.psc_av1_tbl;
  1412. } else {
  1413. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  1414. psc = NULL;
  1415. return -EINVAL;
  1416. }
  1417. if (!psc || !subscribe_psc_size) {
  1418. i_vpr_e(inst, "%s: invalid params\n", __func__);
  1419. return -EINVAL;
  1420. }
  1421. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  1422. for (i = 0; i < subscribe_psc_size; i++)
  1423. payload[i + 1] = psc[i];
  1424. rc = venus_hfi_session_command(inst,
  1425. HFI_CMD_SUBSCRIBE_MODE,
  1426. port,
  1427. HFI_PAYLOAD_U32_ARRAY,
  1428. &payload[0],
  1429. ((subscribe_psc_size + 1) *
  1430. sizeof(u32)));
  1431. subsc_params = inst->subcr_params[port];
  1432. for (i = 0; i < subscribe_psc_size; i++) {
  1433. payload[0] = 0;
  1434. payload[1] = 0;
  1435. payload_size = 0;
  1436. payload_type = 0;
  1437. prop_type = psc[i];
  1438. switch (prop_type) {
  1439. case HFI_PROP_BITSTREAM_RESOLUTION:
  1440. payload[0] = subsc_params.bitstream_resolution;
  1441. payload_size = sizeof(u32);
  1442. payload_type = HFI_PAYLOAD_U32;
  1443. break;
  1444. case HFI_PROP_CROP_OFFSETS:
  1445. payload[0] = subsc_params.crop_offsets[0];
  1446. payload[1] = subsc_params.crop_offsets[1];
  1447. payload_size = sizeof(u64);
  1448. payload_type = HFI_PAYLOAD_64_PACKED;
  1449. break;
  1450. case HFI_PROP_LUMA_CHROMA_BIT_DEPTH:
  1451. payload[0] = subsc_params.bit_depth;
  1452. payload_size = sizeof(u32);
  1453. payload_type = HFI_PAYLOAD_U32;
  1454. break;
  1455. case HFI_PROP_CODED_FRAMES:
  1456. payload[0] = subsc_params.coded_frames;
  1457. payload_size = sizeof(u32);
  1458. payload_type = HFI_PAYLOAD_U32;
  1459. break;
  1460. case HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT:
  1461. payload[0] = subsc_params.fw_min_count;
  1462. payload_size = sizeof(u32);
  1463. payload_type = HFI_PAYLOAD_U32;
  1464. break;
  1465. case HFI_PROP_PIC_ORDER_CNT_TYPE:
  1466. payload[0] = subsc_params.pic_order_cnt;
  1467. payload_size = sizeof(u32);
  1468. payload_type = HFI_PAYLOAD_U32;
  1469. break;
  1470. case HFI_PROP_SIGNAL_COLOR_INFO:
  1471. payload[0] = subsc_params.color_info;
  1472. payload_size = sizeof(u32);
  1473. payload_type = HFI_PAYLOAD_U32;
  1474. break;
  1475. case HFI_PROP_PROFILE:
  1476. payload[0] = subsc_params.profile;
  1477. payload_size = sizeof(u32);
  1478. payload_type = HFI_PAYLOAD_U32;
  1479. break;
  1480. case HFI_PROP_LEVEL:
  1481. payload[0] = subsc_params.level;
  1482. payload_size = sizeof(u32);
  1483. payload_type = HFI_PAYLOAD_U32;
  1484. break;
  1485. case HFI_PROP_TIER:
  1486. payload[0] = subsc_params.tier;
  1487. payload_size = sizeof(u32);
  1488. payload_type = HFI_PAYLOAD_U32;
  1489. break;
  1490. case HFI_PROP_AV1_FILM_GRAIN_PRESENT:
  1491. payload[0] = subsc_params.av1_film_grain_present;
  1492. payload_size = sizeof(u32);
  1493. payload_type = HFI_PAYLOAD_U32;
  1494. break;
  1495. case HFI_PROP_AV1_SUPER_BLOCK_ENABLED:
  1496. payload[0] = subsc_params.av1_super_block_enabled;
  1497. payload_size = sizeof(u32);
  1498. payload_type = HFI_PAYLOAD_U32;
  1499. break;
  1500. default:
  1501. i_vpr_e(inst, "%s: unknown property %#x\n", __func__,
  1502. prop_type);
  1503. prop_type = 0;
  1504. rc = -EINVAL;
  1505. break;
  1506. }
  1507. if (prop_type) {
  1508. rc = venus_hfi_session_property(inst,
  1509. prop_type,
  1510. HFI_HOST_FLAGS_NONE,
  1511. get_hfi_port(inst, port),
  1512. payload_type,
  1513. &payload,
  1514. payload_size);
  1515. if (rc)
  1516. return rc;
  1517. }
  1518. }
  1519. return rc;
  1520. }
  1521. static int msm_vdec_update_max_map_output_count(struct msm_vidc_inst *inst)
  1522. {
  1523. int rc = 0;
  1524. struct v4l2_format *f;
  1525. u32 width, height, count;
  1526. if (!inst) {
  1527. d_vpr_e("%s: invalid params\n", __func__);
  1528. return -EINVAL;
  1529. }
  1530. f = &inst->fmts[OUTPUT_PORT];
  1531. width = f->fmt.pix_mp.width;
  1532. height = f->fmt.pix_mp.height;
  1533. /*
  1534. * adjust max map output count based on resolution
  1535. * to enhance performance.
  1536. * For 8K session: count = 20
  1537. * For 4K session: count = 32
  1538. * For 1080p session: count = 48
  1539. * For all remaining sessions: count = 64
  1540. */
  1541. if (res_is_greater_than(width, height, 4096, 2160))
  1542. count = 20;
  1543. else if (res_is_greater_than(width, height, 1920, 1080))
  1544. count = 32;
  1545. else if (res_is_greater_than(width, height, 1280, 720))
  1546. count = 48;
  1547. else
  1548. count = 64;
  1549. inst->max_map_output_count = count;
  1550. i_vpr_h(inst, "%s: count: %d\n", __func__, inst->max_map_output_count);
  1551. return rc;
  1552. }
  1553. int msm_vdec_streamon_output(struct msm_vidc_inst *inst)
  1554. {
  1555. int rc = 0;
  1556. if (!inst || !inst->core) {
  1557. d_vpr_e("%s: invalid params\n", __func__);
  1558. return -EINVAL;
  1559. }
  1560. if (is_output_meta_enabled(inst) &&
  1561. !inst->bufq[OUTPUT_META_PORT].vb2q->streaming) {
  1562. i_vpr_e(inst,
  1563. "%s: Meta port must be streamed on before data port\n",
  1564. __func__);
  1565. return -EINVAL;
  1566. }
  1567. if (inst->capabilities[CODED_FRAMES].value == CODED_FRAMES_INTERLACE &&
  1568. !is_ubwc_colorformat(inst->capabilities[PIX_FMTS].value)) {
  1569. i_vpr_e(inst,
  1570. "%s: interlace with non-ubwc color format is unsupported\n",
  1571. __func__);
  1572. return -EINVAL;
  1573. }
  1574. rc = msm_vidc_check_session_supported(inst);
  1575. if (rc)
  1576. goto error;
  1577. rc = msm_vdec_update_max_map_output_count(inst);
  1578. if (rc)
  1579. goto error;
  1580. rc = msm_vdec_set_output_properties(inst);
  1581. if (rc)
  1582. goto error;
  1583. if (!inst->opsc_properties_set) {
  1584. memcpy(&inst->subcr_params[OUTPUT_PORT],
  1585. &inst->subcr_params[INPUT_PORT],
  1586. sizeof(inst->subcr_params[INPUT_PORT]));
  1587. rc = msm_vdec_subscribe_output_port_settings_change(inst, OUTPUT_PORT);
  1588. if (rc)
  1589. goto error;
  1590. inst->opsc_properties_set = true;
  1591. }
  1592. rc = msm_vdec_subscribe_property(inst, OUTPUT_PORT);
  1593. if (rc)
  1594. goto error;
  1595. rc = msm_vdec_subscribe_metadata(inst, OUTPUT_PORT);
  1596. if (rc)
  1597. goto error;
  1598. rc = msm_vdec_set_delivery_mode_property(inst, OUTPUT_PORT);
  1599. if (rc)
  1600. goto error;
  1601. rc = msm_vdec_set_delivery_mode_metadata(inst, OUTPUT_PORT);
  1602. if (rc)
  1603. goto error;
  1604. rc = msm_vdec_get_output_internal_buffers(inst);
  1605. if (rc)
  1606. goto error;
  1607. rc = msm_vdec_destroy_internal_buffers(inst, OUTPUT_PORT);
  1608. if (rc)
  1609. goto error;
  1610. rc = msm_vdec_create_output_internal_buffers(inst);
  1611. if (rc)
  1612. goto error;
  1613. rc = msm_vidc_process_streamon_output(inst);
  1614. if (rc)
  1615. goto error;
  1616. rc = msm_vdec_queue_output_internal_buffers(inst);
  1617. if (rc)
  1618. goto error;
  1619. return 0;
  1620. error:
  1621. i_vpr_e(inst, "%s: failed\n", __func__);
  1622. msm_vdec_streamoff_output(inst);
  1623. return rc;
  1624. }
  1625. static inline enum msm_vidc_allow msm_vdec_allow_queue_deferred_buffers(
  1626. struct msm_vidc_inst *inst)
  1627. {
  1628. int count;
  1629. if (!inst) {
  1630. d_vpr_e("%s: invalid params\n", __func__);
  1631. return MSM_VIDC_DISALLOW;
  1632. }
  1633. /* do not defer buffers initially to avoid latency issues */
  1634. if (inst->power.buffer_counter <= SKIP_BATCH_WINDOW)
  1635. return MSM_VIDC_ALLOW;
  1636. /* defer qbuf, if pending buffers count less than batch size */
  1637. count = msm_vidc_num_buffers(inst, MSM_VIDC_BUF_OUTPUT, MSM_VIDC_ATTR_DEFERRED);
  1638. if (count < inst->decode_batch.size)
  1639. return MSM_VIDC_DEFER;
  1640. return MSM_VIDC_ALLOW;
  1641. }
  1642. static int msm_vdec_qbuf_batch(struct msm_vidc_inst *inst,
  1643. struct vb2_buffer *vb2)
  1644. {
  1645. struct msm_vidc_buffer *buf = NULL;
  1646. enum msm_vidc_allow allow;
  1647. int rc;
  1648. if (!inst || !vb2 || !inst->decode_batch.size) {
  1649. d_vpr_e("%s: invalid params\n", __func__);
  1650. return -EINVAL;
  1651. }
  1652. buf = msm_vidc_get_driver_buf(inst, vb2);
  1653. if (!buf)
  1654. return -EINVAL;
  1655. if (is_state(inst, MSM_VIDC_OPEN) ||
  1656. is_state(inst, MSM_VIDC_INPUT_STREAMING)) {
  1657. print_vidc_buffer(VIDC_LOW, "low ", "qbuf deferred", inst, buf);
  1658. return 0;
  1659. }
  1660. allow = msm_vdec_allow_queue_deferred_buffers(inst);
  1661. if (allow == MSM_VIDC_DISALLOW) {
  1662. i_vpr_e(inst, "%s: queue deferred buffers not allowed\n", __func__);
  1663. return -EINVAL;
  1664. } else if (allow == MSM_VIDC_DEFER) {
  1665. print_vidc_buffer(VIDC_LOW, "low ", "batch-qbuf deferred", inst, buf);
  1666. schedule_batch_work(inst);
  1667. return 0;
  1668. }
  1669. cancel_batch_work(inst);
  1670. rc = msm_vidc_queue_deferred_buffers(inst, MSM_VIDC_BUF_OUTPUT);
  1671. if (rc)
  1672. return rc;
  1673. return rc;
  1674. }
  1675. static int msm_vdec_release_nonref_buffers(struct msm_vidc_inst *inst)
  1676. {
  1677. int rc = 0;
  1678. u32 fw_ro_count = 0, nonref_ro_count = 0;
  1679. struct msm_vidc_buffer *ro_buf;
  1680. int i = 0;
  1681. bool found = false;
  1682. if (!inst) {
  1683. d_vpr_e("%s: invalid params\n", __func__);
  1684. return -EINVAL;
  1685. }
  1686. /*
  1687. * if DPB_LIST subscribed on output port then driver need to
  1688. * hold MAX_BPB_COUNT of read only buffer at least.
  1689. */
  1690. if (!inst->subcr_params[OUTPUT_PORT].dpb_list_enabled)
  1691. goto release_buffers;
  1692. /* count read_only buffers which are not pending release in read_only list */
  1693. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1694. if (!(ro_buf->attr & MSM_VIDC_ATTR_READ_ONLY))
  1695. continue;
  1696. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1697. continue;
  1698. fw_ro_count++;
  1699. }
  1700. if (fw_ro_count <= MAX_DPB_COUNT)
  1701. return 0;
  1702. /*
  1703. * Mark those read only buffers present in read_only list as
  1704. * non-reference if that buffer is not part of dpb_list_payload.
  1705. * count such non-ref read only buffers as nonref_ro_count.
  1706. * dpb_list_payload details:
  1707. * payload[0-1] : 64 bits base_address of DPB-1
  1708. * payload[2] : 32 bits addr_offset of DPB-1
  1709. * payload[3] : 32 bits data_offset of DPB-1
  1710. */
  1711. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1712. found = false;
  1713. if (!(ro_buf->attr & MSM_VIDC_ATTR_READ_ONLY))
  1714. continue;
  1715. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1716. continue;
  1717. for (i = 0; (i + 3) < MAX_DPB_LIST_ARRAY_SIZE; i = i + 4) {
  1718. if (ro_buf->device_addr == inst->dpb_list_payload[i] &&
  1719. ro_buf->data_offset == inst->dpb_list_payload[i + 3]) {
  1720. found = true;
  1721. break;
  1722. }
  1723. }
  1724. if (!found)
  1725. nonref_ro_count++;
  1726. }
  1727. if (nonref_ro_count <= inst->buffers.output.min_count)
  1728. return 0;
  1729. i_vpr_l(inst, "%s: fw ro buf count %d, non-ref ro count %d\n",
  1730. __func__, fw_ro_count, nonref_ro_count);
  1731. release_buffers:
  1732. /* release the eligible buffers as per above condition */
  1733. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1734. found = false;
  1735. if (!(ro_buf->attr & MSM_VIDC_ATTR_READ_ONLY))
  1736. continue;
  1737. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1738. continue;
  1739. for (i = 0; (i + 3) < MAX_DPB_LIST_ARRAY_SIZE; i = i + 4) {
  1740. if (ro_buf->device_addr == inst->dpb_list_payload[i] &&
  1741. ro_buf->data_offset == inst->dpb_list_payload[i + 3]) {
  1742. found = true;
  1743. break;
  1744. }
  1745. }
  1746. if (!found) {
  1747. ro_buf->attr |= MSM_VIDC_ATTR_PENDING_RELEASE;
  1748. print_vidc_buffer(VIDC_LOW, "low ", "release buf", inst, ro_buf);
  1749. rc = venus_hfi_release_buffer(inst, ro_buf);
  1750. if (rc)
  1751. return rc;
  1752. }
  1753. }
  1754. return rc;
  1755. }
  1756. int msm_vdec_qbuf(struct msm_vidc_inst *inst, struct vb2_buffer *vb2)
  1757. {
  1758. int rc = 0;
  1759. if (!inst || !vb2) {
  1760. d_vpr_e("%s: invalid params\n", __func__);
  1761. return -EINVAL;
  1762. }
  1763. if (inst->adjust_priority) {
  1764. s32 priority = inst->capabilities[PRIORITY].value;
  1765. priority += inst->adjust_priority;
  1766. inst->adjust_priority = 0;
  1767. msm_vidc_update_cap_value(inst, PRIORITY, priority, __func__);
  1768. msm_vidc_set_session_priority(inst, PRIORITY);
  1769. }
  1770. /* batch decoder output & meta buffer only */
  1771. if (inst->decode_batch.enable && vb2->type == OUTPUT_MPLANE)
  1772. rc = msm_vdec_qbuf_batch(inst, vb2);
  1773. else
  1774. rc = msm_vidc_queue_buffer_single(inst, vb2);
  1775. if (rc)
  1776. return rc;
  1777. if (vb2->type == OUTPUT_MPLANE) {
  1778. rc = msm_vdec_release_nonref_buffers(inst);
  1779. if (rc)
  1780. return rc;
  1781. }
  1782. return rc;
  1783. }
  1784. static int msm_vdec_alloc_and_queue_additional_dpb_buffers(struct msm_vidc_inst *inst)
  1785. {
  1786. struct msm_vidc_buffers *buffers;
  1787. struct msm_vidc_buffer *buffer = NULL;
  1788. int i, cur_min_count = 0, rc = 0;
  1789. if (!inst) {
  1790. d_vpr_e("%s: invalid params\n", __func__);
  1791. return -EINVAL;
  1792. }
  1793. /* get latest min_count and size */
  1794. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  1795. if (rc)
  1796. return rc;
  1797. buffers = msm_vidc_get_buffers(inst, MSM_VIDC_BUF_DPB, __func__);
  1798. if (!buffers)
  1799. return -EINVAL;
  1800. /* get current min_count */
  1801. list_for_each_entry(buffer, &buffers->list, list)
  1802. cur_min_count++;
  1803. /* skip alloc and queue */
  1804. if (cur_min_count >= buffers->min_count)
  1805. return 0;
  1806. i_vpr_h(inst, "%s: dpb buffer count increased from %u -> %u\n",
  1807. __func__, cur_min_count, buffers->min_count);
  1808. /* allocate additional DPB buffers */
  1809. for (i = cur_min_count; i < buffers->min_count; i++) {
  1810. rc = msm_vidc_create_internal_buffer(inst, MSM_VIDC_BUF_DPB, i);
  1811. if (rc)
  1812. return rc;
  1813. }
  1814. /* queue additional DPB buffers */
  1815. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  1816. if (rc)
  1817. return rc;
  1818. return 0;
  1819. }
  1820. int msm_vdec_stop_cmd(struct msm_vidc_inst *inst)
  1821. {
  1822. int rc = 0;
  1823. i_vpr_h(inst, "received cmd: drain\n");
  1824. rc = msm_vidc_process_drain(inst);
  1825. if (rc)
  1826. return rc;
  1827. return rc;
  1828. }
  1829. int msm_vdec_start_cmd(struct msm_vidc_inst *inst)
  1830. {
  1831. int rc = 0;
  1832. if (!inst) {
  1833. d_vpr_e("%s: invalid params\n", __func__);
  1834. return -EINVAL;
  1835. }
  1836. i_vpr_h(inst, "received cmd: resume\n");
  1837. vb2_clear_last_buffer_dequeued(inst->bufq[OUTPUT_META_PORT].vb2q);
  1838. vb2_clear_last_buffer_dequeued(inst->bufq[OUTPUT_PORT].vb2q);
  1839. if (inst->capabilities[CODED_FRAMES].value == CODED_FRAMES_INTERLACE &&
  1840. !is_ubwc_colorformat(inst->capabilities[PIX_FMTS].value)) {
  1841. i_vpr_e(inst,
  1842. "%s: interlace with non-ubwc color format is unsupported\n",
  1843. __func__);
  1844. return -EINVAL;
  1845. }
  1846. /* tune power features */
  1847. inst->decode_batch.enable = msm_vidc_allow_decode_batch(inst);
  1848. msm_vidc_allow_dcvs(inst);
  1849. msm_vidc_power_data_reset(inst);
  1850. /*
  1851. * client is completing partial port reconfiguration,
  1852. * hence reallocate input internal buffers before input port
  1853. * is resumed.
  1854. */
  1855. if (is_sub_state(inst, MSM_VIDC_DRC) &&
  1856. is_sub_state(inst, MSM_VIDC_DRC_LAST_BUFFER) &&
  1857. is_sub_state(inst, MSM_VIDC_INPUT_PAUSE)) {
  1858. rc = msm_vidc_alloc_and_queue_input_internal_buffers(inst);
  1859. if (rc)
  1860. return rc;
  1861. rc = msm_vidc_set_stage(inst, STAGE);
  1862. if (rc)
  1863. return rc;
  1864. rc = msm_vidc_set_pipe(inst, PIPE);
  1865. if (rc)
  1866. return rc;
  1867. }
  1868. /* allocate and queue extra dpb buffers */
  1869. rc = msm_vdec_alloc_and_queue_additional_dpb_buffers(inst);
  1870. if (rc)
  1871. return rc;
  1872. /* queue pending deferred buffers */
  1873. rc = msm_vidc_queue_deferred_buffers(inst, MSM_VIDC_BUF_OUTPUT);
  1874. if (rc)
  1875. return rc;
  1876. /* print final buffer counts & size details */
  1877. msm_vidc_print_buffer_info(inst);
  1878. /* print internal buffer memory usage stats */
  1879. msm_vidc_print_memory_stats(inst);
  1880. rc = msm_vidc_process_resume(inst);
  1881. if (rc)
  1882. return rc;
  1883. return rc;
  1884. }
  1885. int msm_vdec_try_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  1886. {
  1887. int rc = 0;
  1888. struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
  1889. u32 pix_fmt;
  1890. if (!inst) {
  1891. d_vpr_e("%s: invalid params\n", __func__);
  1892. return -EINVAL;
  1893. }
  1894. memset(pixmp->reserved, 0, sizeof(pixmp->reserved));
  1895. if (f->type == INPUT_MPLANE) {
  1896. pix_fmt = v4l2_codec_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__);
  1897. if (!pix_fmt) {
  1898. i_vpr_e(inst, "%s: unsupported codec, set current params\n", __func__);
  1899. f->fmt.pix_mp.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width;
  1900. f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1901. f->fmt.pix_mp.pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
  1902. pix_fmt = v4l2_codec_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__);
  1903. }
  1904. } else if (f->type == OUTPUT_MPLANE) {
  1905. pix_fmt = v4l2_colorformat_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__);
  1906. if (!pix_fmt) {
  1907. i_vpr_e(inst, "%s: unsupported format, set current params\n", __func__);
  1908. f->fmt.pix_mp.pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  1909. f->fmt.pix_mp.width = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width;
  1910. f->fmt.pix_mp.height = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height;
  1911. }
  1912. if (inst->bufq[INPUT_PORT].vb2q->streaming) {
  1913. f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1914. f->fmt.pix_mp.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width;
  1915. }
  1916. } else if (f->type == INPUT_META_PLANE) {
  1917. f->fmt.meta.dataformat = inst->fmts[INPUT_META_PORT].fmt.meta.dataformat;
  1918. f->fmt.meta.buffersize = inst->fmts[INPUT_META_PORT].fmt.meta.buffersize;
  1919. } else if (f->type == OUTPUT_META_PLANE) {
  1920. f->fmt.meta.dataformat = inst->fmts[OUTPUT_META_PORT].fmt.meta.dataformat;
  1921. f->fmt.meta.buffersize = inst->fmts[OUTPUT_META_PORT].fmt.meta.buffersize;
  1922. } else {
  1923. i_vpr_e(inst, "%s: invalid type %d\n", __func__, f->type);
  1924. return -EINVAL;
  1925. }
  1926. if (pixmp->field == V4L2_FIELD_ANY)
  1927. pixmp->field = V4L2_FIELD_NONE;
  1928. pixmp->num_planes = 1;
  1929. return rc;
  1930. }
  1931. static bool msm_vidc_check_max_sessions_vp9d(struct msm_vidc_core *core)
  1932. {
  1933. u32 vp9d_instance_count = 0;
  1934. struct msm_vidc_inst *inst = NULL;
  1935. core_lock(core, __func__);
  1936. list_for_each_entry(inst, &core->instances, list) {
  1937. if (is_decode_session(inst) &&
  1938. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat ==
  1939. V4L2_PIX_FMT_VP9)
  1940. vp9d_instance_count++;
  1941. }
  1942. core_unlock(core, __func__);
  1943. if (vp9d_instance_count > MAX_VP9D_INST_COUNT)
  1944. return true;
  1945. return false;
  1946. }
  1947. int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  1948. {
  1949. int rc = 0;
  1950. struct msm_vidc_core *core;
  1951. struct v4l2_format *fmt, *output_fmt;
  1952. u32 codec_align;
  1953. enum msm_vidc_colorformat_type colorformat;
  1954. if (!inst || !inst->core) {
  1955. d_vpr_e("%s: invalid params\n", __func__);
  1956. return -EINVAL;
  1957. }
  1958. core = inst->core;
  1959. msm_vdec_try_fmt(inst, f);
  1960. if (f->type == INPUT_MPLANE) {
  1961. if (inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat !=
  1962. f->fmt.pix_mp.pixelformat) {
  1963. rc = msm_vdec_codec_change(inst, f->fmt.pix_mp.pixelformat);
  1964. if (rc)
  1965. goto err_invalid_fmt;
  1966. }
  1967. if (f->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_VP9) {
  1968. if (msm_vidc_check_max_sessions_vp9d(inst->core)) {
  1969. i_vpr_e(inst,
  1970. "%s: vp9d sessions exceeded max limit %d\n",
  1971. __func__, MAX_VP9D_INST_COUNT);
  1972. rc = -ENOMEM;
  1973. goto err_invalid_fmt;
  1974. }
  1975. }
  1976. fmt = &inst->fmts[INPUT_PORT];
  1977. fmt->type = INPUT_MPLANE;
  1978. codec_align = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat ==
  1979. V4L2_PIX_FMT_HEVC ? 32 : 16;
  1980. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, codec_align);
  1981. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, codec_align);
  1982. fmt->fmt.pix_mp.num_planes = 1;
  1983. fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  1984. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1985. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  1986. inst->buffers.input.min_count = call_session_op(core,
  1987. min_count, inst, MSM_VIDC_BUF_INPUT);
  1988. inst->buffers.input.extra_count = call_session_op(core,
  1989. extra_count, inst, MSM_VIDC_BUF_INPUT);
  1990. if (inst->buffers.input.actual_count <
  1991. inst->buffers.input.min_count +
  1992. inst->buffers.input.extra_count) {
  1993. inst->buffers.input.actual_count =
  1994. inst->buffers.input.min_count +
  1995. inst->buffers.input.extra_count;
  1996. }
  1997. inst->buffers.input.size =
  1998. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  1999. /* update input port color info */
  2000. fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
  2001. fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
  2002. fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
  2003. fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
  2004. /* update output port color info */
  2005. output_fmt = &inst->fmts[OUTPUT_PORT];
  2006. output_fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
  2007. output_fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
  2008. output_fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
  2009. output_fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
  2010. /* update crop dimensions */
  2011. inst->crop.left = inst->crop.top = 0;
  2012. inst->crop.width = f->fmt.pix_mp.width;
  2013. inst->crop.height = f->fmt.pix_mp.height;
  2014. i_vpr_h(inst,
  2015. "%s: type: INPUT, codec %s width %d height %d size %u min_count %d extra_count %d\n",
  2016. __func__, v4l2_pixelfmt_name(inst, f->fmt.pix_mp.pixelformat),
  2017. f->fmt.pix_mp.width, f->fmt.pix_mp.height,
  2018. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  2019. inst->buffers.input.min_count,
  2020. inst->buffers.input.extra_count);
  2021. } else if (f->type == INPUT_META_PLANE) {
  2022. fmt = &inst->fmts[INPUT_META_PORT];
  2023. fmt->type = INPUT_META_PLANE;
  2024. fmt->fmt.meta.dataformat =
  2025. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2026. fmt->fmt.meta.buffersize = call_session_op(core,
  2027. buffer_size, inst, MSM_VIDC_BUF_INPUT_META);
  2028. inst->buffers.input_meta.min_count =
  2029. inst->buffers.input.min_count;
  2030. inst->buffers.input_meta.extra_count =
  2031. inst->buffers.input.extra_count;
  2032. inst->buffers.input_meta.actual_count =
  2033. inst->buffers.input.actual_count;
  2034. inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
  2035. i_vpr_h(inst,
  2036. "%s: type: INPUT_META, size %u min_count %d extra_count %d\n",
  2037. __func__, fmt->fmt.meta.buffersize,
  2038. inst->buffers.input_meta.min_count,
  2039. inst->buffers.input_meta.extra_count);
  2040. } else if (f->type == OUTPUT_MPLANE) {
  2041. fmt = &inst->fmts[OUTPUT_PORT];
  2042. fmt->type = OUTPUT_MPLANE;
  2043. if (inst->bufq[INPUT_PORT].vb2q->streaming) {
  2044. f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  2045. f->fmt.pix_mp.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width;
  2046. }
  2047. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  2048. colorformat = v4l2_colorformat_to_driver(inst, fmt->fmt.pix_mp.pixelformat,
  2049. __func__);
  2050. fmt->fmt.pix_mp.width = video_y_stride_pix(
  2051. colorformat, f->fmt.pix_mp.width);
  2052. fmt->fmt.pix_mp.height = video_y_scanlines(
  2053. colorformat, f->fmt.pix_mp.height);
  2054. fmt->fmt.pix_mp.num_planes = 1;
  2055. fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
  2056. video_y_stride_bytes(
  2057. colorformat, f->fmt.pix_mp.width);
  2058. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2059. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  2060. if (!inst->bufq[INPUT_PORT].vb2q->streaming)
  2061. inst->buffers.output.min_count = call_session_op(core,
  2062. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  2063. inst->buffers.output.extra_count = call_session_op(core,
  2064. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  2065. if (inst->buffers.output.actual_count <
  2066. inst->buffers.output.min_count +
  2067. inst->buffers.output.extra_count) {
  2068. inst->buffers.output.actual_count =
  2069. inst->buffers.output.min_count +
  2070. inst->buffers.output.extra_count;
  2071. }
  2072. inst->buffers.output.size =
  2073. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  2074. msm_vidc_update_cap_value(inst, PIX_FMTS, colorformat, __func__);
  2075. /* update crop while input port is not streaming */
  2076. if (!inst->bufq[INPUT_PORT].vb2q->streaming) {
  2077. inst->crop.top = 0;
  2078. inst->crop.left = 0;
  2079. inst->crop.width = f->fmt.pix_mp.width;
  2080. inst->crop.height = f->fmt.pix_mp.height;
  2081. }
  2082. i_vpr_h(inst,
  2083. "%s: type: OUTPUT, format %s width %d height %d size %u min_count %d extra_count %d\n",
  2084. __func__, v4l2_pixelfmt_name(inst, fmt->fmt.pix_mp.pixelformat),
  2085. fmt->fmt.pix_mp.width, fmt->fmt.pix_mp.height,
  2086. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  2087. inst->buffers.output.min_count,
  2088. inst->buffers.output.extra_count);
  2089. } else if (f->type == OUTPUT_META_PLANE) {
  2090. fmt = &inst->fmts[OUTPUT_META_PORT];
  2091. fmt->type = OUTPUT_META_PLANE;
  2092. fmt->fmt.meta.dataformat =
  2093. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2094. fmt->fmt.meta.buffersize = call_session_op(core,
  2095. buffer_size, inst, MSM_VIDC_BUF_OUTPUT_META);
  2096. inst->buffers.output_meta.min_count =
  2097. inst->buffers.output.min_count;
  2098. inst->buffers.output_meta.extra_count =
  2099. inst->buffers.output.extra_count;
  2100. inst->buffers.output_meta.actual_count =
  2101. inst->buffers.output.actual_count;
  2102. inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
  2103. i_vpr_h(inst,
  2104. "%s: type: OUTPUT_META, size %u min_count %d extra_count %d\n",
  2105. __func__, fmt->fmt.meta.buffersize,
  2106. inst->buffers.output_meta.min_count,
  2107. inst->buffers.output_meta.extra_count);
  2108. } else {
  2109. i_vpr_e(inst, "%s: invalid type %d\n", __func__, f->type);
  2110. goto err_invalid_fmt;
  2111. }
  2112. memcpy(f, fmt, sizeof(struct v4l2_format));
  2113. err_invalid_fmt:
  2114. return rc;
  2115. }
  2116. int msm_vdec_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  2117. {
  2118. int rc = 0;
  2119. int port;
  2120. if (!inst) {
  2121. d_vpr_e("%s: invalid params\n", __func__);
  2122. return -EINVAL;
  2123. }
  2124. port = v4l2_type_to_driver_port(inst, f->type, __func__);
  2125. if (port < 0)
  2126. return -EINVAL;
  2127. memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
  2128. return rc;
  2129. }
  2130. int msm_vdec_s_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
  2131. {
  2132. if (!inst || !s) {
  2133. d_vpr_e("%s: invalid params\n", __func__);
  2134. return -EINVAL;
  2135. }
  2136. i_vpr_e(inst, "%s: unsupported\n", __func__);
  2137. return -EINVAL;
  2138. }
  2139. int msm_vdec_g_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
  2140. {
  2141. if (!inst || !s) {
  2142. d_vpr_e("%s: invalid params\n", __func__);
  2143. return -EINVAL;
  2144. }
  2145. if (s->type != OUTPUT_MPLANE && s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  2146. i_vpr_e(inst, "%s: invalid type %d\n", __func__, s->type);
  2147. return -EINVAL;
  2148. }
  2149. switch (s->target) {
  2150. case V4L2_SEL_TGT_CROP_BOUNDS:
  2151. case V4L2_SEL_TGT_CROP_DEFAULT:
  2152. case V4L2_SEL_TGT_CROP:
  2153. case V4L2_SEL_TGT_COMPOSE_BOUNDS:
  2154. case V4L2_SEL_TGT_COMPOSE_PADDED:
  2155. case V4L2_SEL_TGT_COMPOSE_DEFAULT:
  2156. case V4L2_SEL_TGT_COMPOSE:
  2157. s->r.left = inst->crop.left;
  2158. s->r.top = inst->crop.top;
  2159. s->r.width = inst->crop.width;
  2160. s->r.height = inst->crop.height;
  2161. break;
  2162. default:
  2163. i_vpr_e(inst, "%s: invalid target %d\n",
  2164. __func__, s->target);
  2165. return -EINVAL;
  2166. }
  2167. i_vpr_h(inst, "%s: target %d, r [%d, %d, %d, %d]\n",
  2168. __func__, s->target, s->r.top, s->r.left,
  2169. s->r.width, s->r.height);
  2170. return 0;
  2171. }
  2172. int msm_vdec_subscribe_event(struct msm_vidc_inst *inst,
  2173. const struct v4l2_event_subscription *sub)
  2174. {
  2175. int rc = 0;
  2176. if (!inst || !sub) {
  2177. d_vpr_e("%s: invalid params\n", __func__);
  2178. return -EINVAL;
  2179. }
  2180. switch (sub->type) {
  2181. case V4L2_EVENT_EOS:
  2182. rc = v4l2_event_subscribe(&inst->event_handler, sub, MAX_EVENTS, NULL);
  2183. break;
  2184. case V4L2_EVENT_SOURCE_CHANGE:
  2185. rc = v4l2_src_change_event_subscribe(&inst->event_handler, sub);
  2186. break;
  2187. case V4L2_EVENT_CTRL:
  2188. rc = v4l2_ctrl_subscribe_event(&inst->event_handler, sub);
  2189. break;
  2190. default:
  2191. i_vpr_e(inst, "%s: invalid type %d id %d\n", __func__, sub->type, sub->id);
  2192. return -EINVAL;
  2193. }
  2194. if (rc)
  2195. i_vpr_e(inst, "%s: failed, type %d id %d\n",
  2196. __func__, sub->type, sub->id);
  2197. return rc;
  2198. }
  2199. static int msm_vdec_check_colorformat_supported(struct msm_vidc_inst* inst,
  2200. enum msm_vidc_colorformat_type colorformat)
  2201. {
  2202. bool supported = true;
  2203. /* do not reject coloformats before streamon */
  2204. if (!inst->bufq[INPUT_PORT].vb2q->streaming)
  2205. return true;
  2206. /*
  2207. * bit_depth 8 bit supports 8 bit colorformats only
  2208. * bit_depth 10 bit supports 10 bit colorformats only
  2209. * interlace supports ubwc colorformats only
  2210. */
  2211. if (inst->capabilities[BIT_DEPTH].value == BIT_DEPTH_8 &&
  2212. !is_8bit_colorformat(colorformat))
  2213. supported = false;
  2214. if (inst->capabilities[BIT_DEPTH].value == BIT_DEPTH_10 &&
  2215. !is_10bit_colorformat(colorformat))
  2216. supported = false;
  2217. if (inst->capabilities[CODED_FRAMES].value ==
  2218. CODED_FRAMES_INTERLACE &&
  2219. !is_ubwc_colorformat(colorformat))
  2220. supported = false;
  2221. return supported;
  2222. }
  2223. int msm_vdec_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
  2224. {
  2225. int rc = 0;
  2226. struct msm_vidc_core *core;
  2227. u32 array[32] = {0};
  2228. u32 i = 0;
  2229. if (!inst || !inst->core || !f ||
  2230. f->index >= ARRAY_SIZE(array)) {
  2231. d_vpr_e("%s: invalid params\n", __func__);
  2232. return -EINVAL;
  2233. }
  2234. core = inst->core;
  2235. if (f->type == INPUT_MPLANE) {
  2236. u32 codecs = core->capabilities[DEC_CODECS].value;
  2237. u32 idx = 0;
  2238. for (i = 0; i <= 31; i++) {
  2239. if (codecs & BIT(i)) {
  2240. if (idx >= ARRAY_SIZE(array))
  2241. break;
  2242. array[idx] = codecs & BIT(i);
  2243. idx++;
  2244. }
  2245. }
  2246. if (!array[f->index])
  2247. return -EINVAL;
  2248. f->pixelformat = v4l2_codec_from_driver(inst, array[f->index],
  2249. __func__);
  2250. if (!f->pixelformat)
  2251. return -EINVAL;
  2252. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  2253. strlcpy(f->description, "codec", sizeof(f->description));
  2254. } else if (f->type == OUTPUT_MPLANE) {
  2255. u32 formats = inst->capabilities[PIX_FMTS].step_or_mask;
  2256. u32 idx = 0;
  2257. for (i = 0; i <= 31; i++) {
  2258. if (formats & BIT(i)) {
  2259. if (idx >= ARRAY_SIZE(array))
  2260. break;
  2261. if (msm_vdec_check_colorformat_supported(inst,
  2262. formats & BIT(i))) {
  2263. array[idx] = formats & BIT(i);
  2264. idx++;
  2265. }
  2266. }
  2267. }
  2268. if (!array[f->index])
  2269. return -EINVAL;
  2270. f->pixelformat = v4l2_colorformat_from_driver(inst, array[f->index],
  2271. __func__);
  2272. if (!f->pixelformat)
  2273. return -EINVAL;
  2274. strlcpy(f->description, "colorformat", sizeof(f->description));
  2275. } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
  2276. if (!f->index) {
  2277. f->pixelformat =
  2278. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2279. strlcpy(f->description, "metadata", sizeof(f->description));
  2280. } else {
  2281. return -EINVAL;
  2282. }
  2283. }
  2284. memset(f->reserved, 0, sizeof(f->reserved));
  2285. i_vpr_h(inst, "%s: index %d, %s: %s, flags %#x\n",
  2286. __func__, f->index, f->description,
  2287. v4l2_pixelfmt_name(inst, f->pixelformat), f->flags);
  2288. return rc;
  2289. }
  2290. int msm_vdec_inst_init(struct msm_vidc_inst *inst)
  2291. {
  2292. int rc = 0;
  2293. struct msm_vidc_core *core;
  2294. struct v4l2_format *f;
  2295. enum msm_vidc_colorformat_type colorformat;
  2296. if (!inst || !inst->core) {
  2297. d_vpr_e("%s: invalid params\n", __func__);
  2298. return -EINVAL;
  2299. }
  2300. core = inst->core;
  2301. INIT_DELAYED_WORK(&inst->decode_batch.work, msm_vidc_batch_handler);
  2302. if (core->capabilities[DECODE_BATCH].value) {
  2303. inst->decode_batch.enable = true;
  2304. inst->decode_batch.size = MAX_DEC_BATCH_SIZE;
  2305. }
  2306. if (core->capabilities[DCVS].value)
  2307. inst->power.dcvs_mode = true;
  2308. f = &inst->fmts[INPUT_PORT];
  2309. f->type = INPUT_MPLANE;
  2310. f->fmt.pix_mp.width = DEFAULT_WIDTH;
  2311. f->fmt.pix_mp.height = DEFAULT_HEIGHT;
  2312. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
  2313. f->fmt.pix_mp.num_planes = 1;
  2314. f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  2315. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2316. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  2317. f->fmt.pix_mp.field = V4L2_FIELD_NONE;
  2318. inst->buffers.input.min_count = call_session_op(core,
  2319. min_count, inst, MSM_VIDC_BUF_INPUT);
  2320. inst->buffers.input.extra_count = call_session_op(core,
  2321. extra_count, inst, MSM_VIDC_BUF_INPUT);
  2322. inst->buffers.input.actual_count =
  2323. inst->buffers.input.min_count +
  2324. inst->buffers.input.extra_count;
  2325. inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  2326. inst->crop.left = inst->crop.top = 0;
  2327. inst->crop.width = f->fmt.pix_mp.width;
  2328. inst->crop.height = f->fmt.pix_mp.height;
  2329. f = &inst->fmts[INPUT_META_PORT];
  2330. f->type = INPUT_META_PLANE;
  2331. f->fmt.meta.dataformat =
  2332. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);;
  2333. f->fmt.meta.buffersize = MSM_VIDC_METADATA_SIZE;
  2334. inst->buffers.input_meta.min_count = 0;
  2335. inst->buffers.input_meta.extra_count = 0;
  2336. inst->buffers.input_meta.actual_count = 0;
  2337. inst->buffers.input_meta.size = 0;
  2338. f = &inst->fmts[OUTPUT_PORT];
  2339. f->type = OUTPUT_MPLANE;
  2340. f->fmt.pix_mp.pixelformat =
  2341. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_NV12C, __func__);
  2342. colorformat = v4l2_colorformat_to_driver(inst,
  2343. f->fmt.pix_mp.pixelformat, __func__);
  2344. f->fmt.pix_mp.width = video_y_stride_pix(colorformat, DEFAULT_WIDTH);
  2345. f->fmt.pix_mp.height = video_y_scanlines(colorformat, DEFAULT_HEIGHT);
  2346. f->fmt.pix_mp.num_planes = 1;
  2347. f->fmt.pix_mp.plane_fmt[0].bytesperline =
  2348. video_y_stride_bytes(colorformat, DEFAULT_WIDTH);
  2349. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2350. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  2351. f->fmt.pix_mp.field = V4L2_FIELD_NONE;
  2352. f->fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
  2353. f->fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
  2354. f->fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
  2355. f->fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
  2356. inst->buffers.output.min_count = call_session_op(core,
  2357. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  2358. inst->buffers.output.extra_count = call_session_op(core,
  2359. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  2360. inst->buffers.output.actual_count =
  2361. inst->buffers.output.min_count +
  2362. inst->buffers.output.extra_count;
  2363. inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  2364. inst->max_map_output_count = MAX_MAP_OUTPUT_COUNT;
  2365. inst->fw_min_count = 0;
  2366. f = &inst->fmts[OUTPUT_META_PORT];
  2367. f->type = OUTPUT_META_PLANE;
  2368. f->fmt.meta.dataformat =
  2369. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2370. f->fmt.meta.buffersize = MSM_VIDC_METADATA_SIZE;
  2371. inst->buffers.output_meta.min_count = 0;
  2372. inst->buffers.output_meta.extra_count = 0;
  2373. inst->buffers.output_meta.actual_count = 0;
  2374. inst->buffers.output_meta.size = 0;
  2375. inst->subcr_params[INPUT_PORT].dpb_list_enabled = 0;
  2376. inst->subcr_params[OUTPUT_PORT].dpb_list_enabled = 0;
  2377. rc = msm_vdec_codec_change(inst,
  2378. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat);
  2379. if (rc)
  2380. return rc;
  2381. return rc;
  2382. }
  2383. int msm_vdec_inst_deinit(struct msm_vidc_inst *inst)
  2384. {
  2385. int rc = 0;
  2386. if (!inst) {
  2387. d_vpr_e("%s: invalid params\n", __func__);
  2388. return -EINVAL;
  2389. }
  2390. /* cancel pending batch work */
  2391. cancel_batch_work(inst);
  2392. rc = msm_vidc_ctrl_deinit(inst);
  2393. if (rc)
  2394. return rc;
  2395. return rc;
  2396. }