msm_vdec.c 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840
  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. bool session_init = false;
  41. if (!inst->codec)
  42. session_init = true;
  43. if (inst->codec && inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat == v4l2_codec)
  44. return 0;
  45. i_vpr_h(inst, "%s: codec changed from %s to %s\n",
  46. __func__, v4l2_pixelfmt_name(inst, inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat),
  47. v4l2_pixelfmt_name(inst, v4l2_codec));
  48. inst->codec = v4l2_codec_to_driver(inst, v4l2_codec, __func__);
  49. if (!inst->codec) {
  50. i_vpr_e(inst, "%s: invalid codec %#x\n", __func__, v4l2_codec);
  51. rc = -EINVAL;
  52. goto exit;
  53. }
  54. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat = v4l2_codec;
  55. rc = msm_vidc_update_debug_str(inst);
  56. if (rc)
  57. goto exit;
  58. rc = msm_vidc_get_inst_capability(inst);
  59. if (rc)
  60. goto exit;
  61. rc = msm_vidc_ctrl_handler_init(inst, session_init);
  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. if (inst->codec == MSM_VIDC_H264) {
  820. subscribe_prop_size = core->platform->data.dec_input_prop_size_avc;
  821. subcribe_prop = core->platform->data.dec_input_prop_avc;
  822. } else if (inst->codec == MSM_VIDC_HEVC || inst->codec == MSM_VIDC_HEIC) {
  823. subscribe_prop_size = core->platform->data.dec_input_prop_size_hevc;
  824. subcribe_prop = core->platform->data.dec_input_prop_hevc;
  825. } else if (inst->codec == MSM_VIDC_VP9) {
  826. subscribe_prop_size = core->platform->data.dec_input_prop_size_vp9;
  827. subcribe_prop = core->platform->data.dec_input_prop_vp9;
  828. } else if (inst->codec == MSM_VIDC_AV1) {
  829. subscribe_prop_size = core->platform->data.dec_input_prop_size_av1;
  830. subcribe_prop = core->platform->data.dec_input_prop_av1;
  831. } else {
  832. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  833. subcribe_prop = NULL;
  834. return -EINVAL;
  835. }
  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->input_dpb_list_enabled = true;
  845. i_vpr_h(inst, "%s: DPB_LIST suscribed on input port", __func__);
  846. }
  847. }
  848. } else if (port == OUTPUT_PORT) {
  849. if (inst->codec == MSM_VIDC_H264) {
  850. subscribe_prop_size = core->platform->data.dec_output_prop_size_avc;
  851. subcribe_prop = core->platform->data.dec_output_prop_avc;
  852. } else if (inst->codec == MSM_VIDC_HEVC || inst->codec == MSM_VIDC_HEIC) {
  853. subscribe_prop_size = core->platform->data.dec_output_prop_size_hevc;
  854. subcribe_prop = core->platform->data.dec_output_prop_hevc;
  855. } else if (inst->codec == MSM_VIDC_VP9) {
  856. subscribe_prop_size = core->platform->data.dec_output_prop_size_vp9;
  857. subcribe_prop = core->platform->data.dec_output_prop_vp9;
  858. } else if (inst->codec == MSM_VIDC_AV1) {
  859. subscribe_prop_size = core->platform->data.dec_output_prop_size_av1;
  860. subcribe_prop = core->platform->data.dec_output_prop_av1;
  861. } else {
  862. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  863. subcribe_prop = NULL;
  864. return -EINVAL;
  865. }
  866. for (i = 0; i < subscribe_prop_size; i++) {
  867. allow = msm_vidc_allow_property(inst,
  868. subcribe_prop[i]);
  869. if (allow) {
  870. payload[count + 1] = subcribe_prop[i];
  871. count++;
  872. }
  873. if (subcribe_prop[i] == HFI_PROP_DPB_LIST) {
  874. inst->output_dpb_list_enabled = true;
  875. i_vpr_h(inst, "%s: DPB_LIST suscribed on output port", __func__);
  876. }
  877. }
  878. } else {
  879. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  880. return -EINVAL;
  881. }
  882. rc = venus_hfi_session_command(inst,
  883. HFI_CMD_SUBSCRIBE_MODE,
  884. port,
  885. HFI_PAYLOAD_U32_ARRAY,
  886. &payload[0],
  887. (count + 1) * sizeof(u32));
  888. if (rc)
  889. return rc;
  890. return rc;
  891. }
  892. static int msm_vdec_subscribe_metadata(struct msm_vidc_inst *inst,
  893. enum msm_vidc_port_type port)
  894. {
  895. int rc = 0;
  896. u32 payload[32] = {0};
  897. u32 i, count = 0;
  898. if (!inst) {
  899. d_vpr_e("%s: invalid params\n", __func__);
  900. return -EINVAL;
  901. }
  902. i_vpr_h(inst, "%s()\n", __func__);
  903. payload[0] = HFI_MODE_METADATA;
  904. if (port == INPUT_PORT) {
  905. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  906. if (is_meta_rx_inp_enabled(inst, i) &&
  907. msm_vidc_allow_metadata_subscription(
  908. inst, i, port)) {
  909. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  910. i_vpr_e(inst,
  911. "%s: input metadatas (%d) exceeded limit (%d)\n",
  912. __func__, count, sizeof(payload) / sizeof(u32));
  913. return -EINVAL;
  914. }
  915. payload[count + 1] = inst->capabilities[i].hfi_id;
  916. count++;
  917. }
  918. }
  919. } else if (port == OUTPUT_PORT) {
  920. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  921. if (is_meta_rx_out_enabled(inst, i) &&
  922. msm_vidc_allow_metadata_subscription(
  923. inst, i, port)) {
  924. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  925. i_vpr_e(inst,
  926. "%s: input metadatas (%d) exceeded limit (%d)\n",
  927. __func__, count, sizeof(payload) / sizeof(u32));
  928. return -EINVAL;
  929. }
  930. payload[count + 1] = inst->capabilities[i].hfi_id;
  931. count++;
  932. }
  933. }
  934. } else {
  935. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  936. return -EINVAL;
  937. }
  938. rc = venus_hfi_session_command(inst,
  939. HFI_CMD_SUBSCRIBE_MODE,
  940. port,
  941. HFI_PAYLOAD_U32_ARRAY,
  942. &payload[0],
  943. (count + 1) * sizeof(u32));
  944. if (rc)
  945. return rc;
  946. return rc;
  947. }
  948. static int msm_vdec_set_delivery_mode_metadata(struct msm_vidc_inst *inst,
  949. enum msm_vidc_port_type port)
  950. {
  951. int rc = 0;
  952. u32 payload[32] = {0};
  953. u32 i, count = 0;
  954. if (!inst) {
  955. d_vpr_e("%s: invalid params\n", __func__);
  956. return -EINVAL;
  957. }
  958. i_vpr_h(inst, "%s()\n", __func__);
  959. payload[0] = HFI_MODE_METADATA;
  960. if (port == INPUT_PORT) {
  961. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  962. if (is_meta_tx_inp_enabled(inst, i)) {
  963. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  964. i_vpr_e(inst,
  965. "%s: input metadatas (%d) exceeded limit (%d)\n",
  966. __func__, count, sizeof(payload) / sizeof(u32));
  967. return -EINVAL;
  968. }
  969. payload[count + 1] = inst->capabilities[i].hfi_id;
  970. count++;
  971. }
  972. }
  973. } else if (port == OUTPUT_PORT) {
  974. for (i = INST_CAP_NONE + 1; i < INST_CAP_MAX; i++) {
  975. if (is_meta_tx_out_enabled(inst, i) &&
  976. msm_vidc_allow_metadata_delivery(
  977. inst, i, port)) {
  978. if (count + 1 >= sizeof(payload) / sizeof(u32)) {
  979. i_vpr_e(inst,
  980. "%s: input metadatas (%d) exceeded limit (%d)\n",
  981. __func__, count, sizeof(payload) / sizeof(u32));
  982. return -EINVAL;
  983. }
  984. payload[count + 1] = inst->capabilities[i].hfi_id;
  985. count++;
  986. }
  987. }
  988. } else {
  989. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  990. return -EINVAL;
  991. }
  992. rc = venus_hfi_session_command(inst,
  993. HFI_CMD_DELIVERY_MODE,
  994. port,
  995. HFI_PAYLOAD_U32_ARRAY,
  996. &payload[0],
  997. (count + 1) * sizeof(u32));
  998. if (rc)
  999. return rc;
  1000. return rc;
  1001. }
  1002. static int msm_vdec_set_delivery_mode_property(struct msm_vidc_inst *inst,
  1003. enum msm_vidc_port_type port)
  1004. {
  1005. int rc = 0;
  1006. u32 payload[32] = {0};
  1007. u32 i, count = 0;
  1008. static const u32 property_output_list[] = {
  1009. META_OUTBUF_FENCE,
  1010. };
  1011. static const u32 property_input_list[] = {};
  1012. if (!inst) {
  1013. d_vpr_e("%s: invalid params\n", __func__);
  1014. return -EINVAL;
  1015. }
  1016. i_vpr_h(inst, "%s()\n", __func__);
  1017. payload[0] = HFI_MODE_PROPERTY;
  1018. if (port == INPUT_PORT) {
  1019. for (i = 0; i < ARRAY_SIZE(property_input_list); i++) {
  1020. if (inst->capabilities[property_input_list[i]].value) {
  1021. payload[count + 1] =
  1022. inst->capabilities[property_input_list[i]].hfi_id;
  1023. count++;
  1024. }
  1025. }
  1026. } else if (port == OUTPUT_PORT) {
  1027. for (i = 0; i < ARRAY_SIZE(property_output_list); i++) {
  1028. if (property_output_list[i] == META_OUTBUF_FENCE &&
  1029. is_meta_rx_inp_enabled(inst, META_OUTBUF_FENCE)) {
  1030. /*
  1031. * if output buffer fence enabled via
  1032. * META_OUTBUF_FENCE, then driver will send
  1033. * fence id via HFI_PROP_FENCE to firmware.
  1034. * So enable HFI_PROP_FENCE property as
  1035. * delivery mode property.
  1036. */
  1037. payload[count + 1] =
  1038. inst->capabilities[property_output_list[i]].hfi_id;
  1039. count++;
  1040. continue;
  1041. }
  1042. if (inst->capabilities[property_output_list[i]].value) {
  1043. payload[count + 1] =
  1044. inst->capabilities[property_output_list[i]].hfi_id;
  1045. count++;
  1046. }
  1047. }
  1048. } else {
  1049. i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
  1050. return -EINVAL;
  1051. }
  1052. rc = venus_hfi_session_command(inst,
  1053. HFI_CMD_DELIVERY_MODE,
  1054. port,
  1055. HFI_PAYLOAD_U32_ARRAY,
  1056. &payload[0],
  1057. (count + 1) * sizeof(u32));
  1058. if (rc)
  1059. return rc;
  1060. return rc;
  1061. }
  1062. int msm_vdec_init_input_subcr_params(struct msm_vidc_inst *inst)
  1063. {
  1064. struct msm_vidc_subscription_params *subsc_params;
  1065. u32 left_offset, top_offset, right_offset, bottom_offset;
  1066. u32 primaries, matrix_coeff, transfer_char;
  1067. u32 full_range = 0, video_format = 0;
  1068. u32 colour_description_present_flag = 0;
  1069. u32 video_signal_type_present_flag = 0;
  1070. if (!inst) {
  1071. d_vpr_e("%s: invalid params\n", __func__);
  1072. return -EINVAL;
  1073. }
  1074. subsc_params = &inst->subcr_params[INPUT_PORT];
  1075. subsc_params->bitstream_resolution =
  1076. inst->fmts[INPUT_PORT].fmt.pix_mp.width << 16 |
  1077. inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1078. left_offset = inst->crop.left;
  1079. top_offset = inst->crop.top;
  1080. right_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  1081. inst->crop.width);
  1082. bottom_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  1083. inst->crop.height);
  1084. subsc_params->crop_offsets[0] =
  1085. left_offset << 16 | top_offset;
  1086. subsc_params->crop_offsets[1] =
  1087. right_offset << 16 | bottom_offset;
  1088. subsc_params->fw_min_count = inst->buffers.output.min_count;
  1089. primaries = v4l2_color_primaries_to_driver(inst,
  1090. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace, __func__);
  1091. matrix_coeff = v4l2_matrix_coeff_to_driver(inst,
  1092. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc, __func__);
  1093. transfer_char = v4l2_transfer_char_to_driver(inst,
  1094. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func, __func__);
  1095. full_range = inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization ==
  1096. V4L2_QUANTIZATION_FULL_RANGE ? 1 : 0;
  1097. subsc_params->color_info =
  1098. (matrix_coeff & 0xFF) |
  1099. ((transfer_char << 8) & 0xFF00) |
  1100. ((primaries << 16) & 0xFF0000) |
  1101. ((colour_description_present_flag << 24) & 0x1000000) |
  1102. ((full_range << 25) & 0x2000000) |
  1103. ((video_format << 26) & 0x1C000000) |
  1104. ((video_signal_type_present_flag << 29) & 0x20000000);
  1105. subsc_params->profile = inst->capabilities[PROFILE].value;
  1106. subsc_params->level = inst->capabilities[LEVEL].value;
  1107. subsc_params->tier = inst->capabilities[HEVC_TIER].value;
  1108. subsc_params->pic_order_cnt = inst->capabilities[POC].value;
  1109. subsc_params->bit_depth = inst->capabilities[BIT_DEPTH].value;
  1110. if (inst->capabilities[CODED_FRAMES].value ==
  1111. CODED_FRAMES_PROGRESSIVE)
  1112. subsc_params->coded_frames = HFI_BITMASK_FRAME_MBS_ONLY_FLAG;
  1113. else
  1114. subsc_params->coded_frames = 0;
  1115. return 0;
  1116. }
  1117. int msm_vdec_set_num_comv(struct msm_vidc_inst *inst)
  1118. {
  1119. int rc = 0;
  1120. u32 num_comv = 0;
  1121. if (!inst) {
  1122. d_vpr_e("%s: invalid params\n", __func__);
  1123. return -EINVAL;
  1124. }
  1125. num_comv = inst->capabilities[NUM_COMV].value;
  1126. i_vpr_h(inst, "%s: num COMV: %d", __func__, num_comv);
  1127. rc = venus_hfi_session_property(inst,
  1128. HFI_PROP_COMV_BUFFER_COUNT,
  1129. HFI_HOST_FLAGS_NONE,
  1130. get_hfi_port(inst, INPUT_PORT),
  1131. HFI_PAYLOAD_U32,
  1132. &num_comv,
  1133. sizeof(u32));
  1134. if (rc) {
  1135. i_vpr_e(inst, "%s: set property failed\n", __func__);
  1136. return rc;
  1137. }
  1138. return rc;
  1139. }
  1140. static int msm_vdec_read_input_subcr_params(struct msm_vidc_inst *inst)
  1141. {
  1142. struct msm_vidc_subscription_params subsc_params;
  1143. struct msm_vidc_core *core;
  1144. u32 width, height;
  1145. u32 primaries, matrix_coeff, transfer_char;
  1146. u32 full_range = 0;
  1147. u32 colour_description_present_flag = 0;
  1148. u32 video_signal_type_present_flag = 0;
  1149. enum msm_vidc_colorformat_type output_fmt;
  1150. if (!inst || !inst->core) {
  1151. d_vpr_e("%s: invalid params\n", __func__);
  1152. return -EINVAL;
  1153. }
  1154. core = inst->core;
  1155. subsc_params = inst->subcr_params[INPUT_PORT];
  1156. width = (subsc_params.bitstream_resolution &
  1157. HFI_BITMASK_BITSTREAM_WIDTH) >> 16;
  1158. height = subsc_params.bitstream_resolution &
  1159. HFI_BITMASK_BITSTREAM_HEIGHT;
  1160. inst->fmts[INPUT_PORT].fmt.pix_mp.width = width;
  1161. inst->fmts[INPUT_PORT].fmt.pix_mp.height = height;
  1162. output_fmt = v4l2_colorformat_to_driver(inst,
  1163. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, __func__);
  1164. inst->fmts[OUTPUT_PORT].fmt.pix_mp.width = video_y_stride_pix(
  1165. output_fmt, width);
  1166. inst->fmts[OUTPUT_PORT].fmt.pix_mp.height = video_y_scanlines(
  1167. output_fmt, height);
  1168. inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].bytesperline =
  1169. video_y_stride_bytes(output_fmt, width);
  1170. inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage =
  1171. call_session_op(core, buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  1172. //inst->buffers.output.size = inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage;
  1173. matrix_coeff = subsc_params.color_info & 0xFF;
  1174. transfer_char = (subsc_params.color_info & 0xFF00) >> 8;
  1175. primaries = (subsc_params.color_info & 0xFF0000) >> 16;
  1176. colour_description_present_flag =
  1177. (subsc_params.color_info & 0x1000000) >> 24;
  1178. full_range = (subsc_params.color_info & 0x2000000) >> 25;
  1179. video_signal_type_present_flag =
  1180. (subsc_params.color_info & 0x20000000) >> 29;
  1181. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
  1182. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
  1183. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
  1184. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
  1185. if (video_signal_type_present_flag) {
  1186. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization =
  1187. full_range ?
  1188. V4L2_QUANTIZATION_FULL_RANGE :
  1189. V4L2_QUANTIZATION_LIM_RANGE;
  1190. if (colour_description_present_flag) {
  1191. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace =
  1192. v4l2_color_primaries_from_driver(inst, primaries, __func__);
  1193. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func =
  1194. v4l2_transfer_char_from_driver(inst, transfer_char, __func__);
  1195. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc =
  1196. v4l2_matrix_coeff_from_driver(inst, matrix_coeff, __func__);
  1197. } else {
  1198. i_vpr_h(inst,
  1199. "%s: color description flag is not present\n",
  1200. __func__);
  1201. }
  1202. } else {
  1203. i_vpr_h(inst, "%s: video_signal type is not present\n",
  1204. __func__);
  1205. }
  1206. /* align input port color info with output port */
  1207. inst->fmts[INPUT_PORT].fmt.pix_mp.colorspace =
  1208. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace;
  1209. inst->fmts[INPUT_PORT].fmt.pix_mp.xfer_func =
  1210. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func;
  1211. inst->fmts[INPUT_PORT].fmt.pix_mp.ycbcr_enc =
  1212. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc;
  1213. inst->fmts[INPUT_PORT].fmt.pix_mp.quantization =
  1214. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization;
  1215. inst->buffers.output.min_count = subsc_params.fw_min_count;
  1216. inst->fw_min_count = subsc_params.fw_min_count;
  1217. inst->buffers.output.extra_count = call_session_op(core,
  1218. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  1219. inst->buffers.output_meta.min_count = inst->buffers.output.min_count;
  1220. inst->buffers.output_meta.extra_count = inst->buffers.output.extra_count;
  1221. if (is_thumbnail_session(inst) && inst->codec != MSM_VIDC_VP9) {
  1222. if (inst->buffers.output.min_count != 1) {
  1223. i_vpr_e(inst, "%s: invalid min count %d in thumbnail case\n",
  1224. __func__, inst->buffers.output.min_count);
  1225. msm_vidc_change_state(inst, MSM_VIDC_ERROR, __func__);
  1226. }
  1227. }
  1228. inst->crop.top = subsc_params.crop_offsets[0] & 0xFFFF;
  1229. inst->crop.left = (subsc_params.crop_offsets[0] >> 16) & 0xFFFF;
  1230. inst->crop.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  1231. (subsc_params.crop_offsets[1] & 0xFFFF) - inst->crop.top;
  1232. inst->crop.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  1233. ((subsc_params.crop_offsets[1] >> 16) & 0xFFFF) - inst->crop.left;
  1234. msm_vidc_update_cap_value(inst, PROFILE, subsc_params.profile, __func__);
  1235. msm_vidc_update_cap_value(inst, LEVEL, subsc_params.level, __func__);
  1236. msm_vidc_update_cap_value(inst, HEVC_TIER, subsc_params.tier, __func__);
  1237. msm_vidc_update_cap_value(inst, POC, subsc_params.pic_order_cnt, __func__);
  1238. if (subsc_params.bit_depth == BIT_DEPTH_8)
  1239. msm_vidc_update_cap_value(inst, BIT_DEPTH, BIT_DEPTH_8, __func__);
  1240. else
  1241. msm_vidc_update_cap_value(inst, BIT_DEPTH, BIT_DEPTH_10, __func__);
  1242. if (subsc_params.coded_frames & HFI_BITMASK_FRAME_MBS_ONLY_FLAG)
  1243. msm_vidc_update_cap_value(inst, CODED_FRAMES, CODED_FRAMES_PROGRESSIVE, __func__);
  1244. else
  1245. msm_vidc_update_cap_value(inst, CODED_FRAMES, CODED_FRAMES_INTERLACE, __func__);
  1246. if (inst->codec == MSM_VIDC_AV1) {
  1247. msm_vidc_update_cap_value(inst, FILM_GRAIN,
  1248. subsc_params.av1_film_grain_present, __func__);
  1249. msm_vidc_update_cap_value(inst, SUPER_BLOCK,
  1250. subsc_params.av1_super_block_enabled, __func__);
  1251. }
  1252. /* disable META_OUTBUF_FENCE if session is Interlace type */
  1253. if (inst->capabilities[CODED_FRAMES].value ==
  1254. CODED_FRAMES_INTERLACE) {
  1255. msm_vidc_update_cap_value(inst, META_OUTBUF_FENCE,
  1256. MSM_VIDC_META_RX_INPUT |
  1257. MSM_VIDC_META_DISABLE, __func__);
  1258. }
  1259. return 0;
  1260. }
  1261. int msm_vdec_input_port_settings_change(struct msm_vidc_inst *inst)
  1262. {
  1263. u32 rc = 0;
  1264. struct v4l2_event event = {0};
  1265. if (!inst->bufq[INPUT_PORT].vb2q->streaming) {
  1266. i_vpr_e(inst, "%s: input port not streaming\n",
  1267. __func__);
  1268. return 0;
  1269. }
  1270. rc = msm_vdec_read_input_subcr_params(inst);
  1271. if (rc)
  1272. return rc;
  1273. event.type = V4L2_EVENT_SOURCE_CHANGE;
  1274. event.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION;
  1275. v4l2_event_queue_fh(&inst->event_handler, &event);
  1276. return rc;
  1277. }
  1278. int msm_vdec_output_port_settings_change(struct msm_vidc_inst *inst)
  1279. {
  1280. return 0;
  1281. }
  1282. int msm_vdec_streamoff_input(struct msm_vidc_inst *inst)
  1283. {
  1284. int rc = 0;
  1285. if (!inst || !inst->core) {
  1286. d_vpr_e("%s: invalid params\n", __func__);
  1287. return -EINVAL;
  1288. }
  1289. rc = msm_vidc_session_streamoff(inst, INPUT_PORT);
  1290. if (rc)
  1291. return rc;
  1292. return 0;
  1293. }
  1294. int msm_vdec_streamon_input(struct msm_vidc_inst *inst)
  1295. {
  1296. int rc = 0;
  1297. if (!inst || !inst->core) {
  1298. d_vpr_e("%s: invalid params\n", __func__);
  1299. return -EINVAL;
  1300. }
  1301. if (is_input_meta_enabled(inst) &&
  1302. !inst->bufq[INPUT_META_PORT].vb2q->streaming) {
  1303. i_vpr_e(inst,
  1304. "%s: Meta port must be streamed on before data port\n",
  1305. __func__);
  1306. return -EINVAL;
  1307. }
  1308. rc = msm_vidc_check_session_supported(inst);
  1309. if (rc)
  1310. goto error;
  1311. rc = msm_vidc_set_v4l2_properties(inst);
  1312. if (rc)
  1313. goto error;
  1314. /* Decide bse vpp delay after work mode */
  1315. //msm_vidc_set_bse_vpp_delay(inst);
  1316. rc = msm_vdec_get_input_internal_buffers(inst);
  1317. if (rc)
  1318. goto error;
  1319. /* check for memory after all buffers calculation */
  1320. //rc = msm_vidc_check_memory_supported(inst);
  1321. if (rc)
  1322. goto error;
  1323. rc = msm_vdec_destroy_internal_buffers(inst, INPUT_PORT);
  1324. if (rc)
  1325. goto error;
  1326. rc = msm_vdec_create_input_internal_buffers(inst);
  1327. if (rc)
  1328. goto error;
  1329. rc = msm_vdec_queue_input_internal_buffers(inst);
  1330. if (rc)
  1331. goto error;
  1332. if (!inst->ipsc_properties_set) {
  1333. rc = msm_vdec_subscribe_input_port_settings_change(
  1334. inst, INPUT_PORT);
  1335. if (rc)
  1336. goto error;
  1337. inst->ipsc_properties_set = true;
  1338. }
  1339. rc = msm_vdec_subscribe_property(inst, INPUT_PORT);
  1340. if (rc)
  1341. goto error;
  1342. rc = msm_vdec_subscribe_metadata(inst, INPUT_PORT);
  1343. if (rc)
  1344. goto error;
  1345. /*
  1346. * Subscribe output metadatas in input port sequence as well so that
  1347. * metadatas detected in bitstream before output port is started
  1348. * are not missed.
  1349. * Example: AV1 HDR metadata which can be part of
  1350. * first ETB (sequence header OBU + metadata OBU)
  1351. */
  1352. rc = msm_vdec_subscribe_metadata(inst, OUTPUT_PORT);
  1353. if (rc)
  1354. goto error;
  1355. rc = msm_vdec_set_delivery_mode_metadata(inst, INPUT_PORT);
  1356. if (rc)
  1357. goto error;
  1358. rc = msm_vidc_process_streamon_input(inst);
  1359. if (rc)
  1360. goto error;
  1361. rc = msm_vidc_flush_ts(inst);
  1362. if (rc)
  1363. goto error;
  1364. rc = msm_vidc_ts_reorder_flush(inst);
  1365. if (rc)
  1366. goto error;
  1367. return 0;
  1368. error:
  1369. i_vpr_e(inst, "%s: failed\n", __func__);
  1370. msm_vdec_streamoff_input(inst);
  1371. return rc;
  1372. }
  1373. static int schedule_batch_work(struct msm_vidc_inst *inst)
  1374. {
  1375. struct msm_vidc_core *core;
  1376. if (!inst || !inst->core) {
  1377. d_vpr_e("%s: invalid params\n", __func__);
  1378. return -EINVAL;
  1379. }
  1380. core = inst->core;
  1381. mod_delayed_work(core->batch_workq, &inst->decode_batch.work,
  1382. msecs_to_jiffies(core->capabilities[DECODE_BATCH_TIMEOUT].value));
  1383. return 0;
  1384. }
  1385. static int cancel_batch_work(struct msm_vidc_inst *inst)
  1386. {
  1387. if (!inst) {
  1388. d_vpr_e("%s: Invalid arguments\n", __func__);
  1389. return -EINVAL;
  1390. }
  1391. cancel_delayed_work(&inst->decode_batch.work);
  1392. return 0;
  1393. }
  1394. int msm_vdec_streamoff_output(struct msm_vidc_inst *inst)
  1395. {
  1396. int rc = 0;
  1397. if (!inst || !inst->core) {
  1398. d_vpr_e("%s: invalid params\n", __func__);
  1399. return -EINVAL;
  1400. }
  1401. /* cancel pending batch work */
  1402. cancel_batch_work(inst);
  1403. rc = msm_vidc_session_streamoff(inst, OUTPUT_PORT);
  1404. if (rc)
  1405. return rc;
  1406. return 0;
  1407. }
  1408. static int msm_vdec_subscribe_output_port_settings_change(struct msm_vidc_inst *inst,
  1409. enum msm_vidc_port_type port)
  1410. {
  1411. int rc = 0;
  1412. struct msm_vidc_core *core;
  1413. u32 payload[32] = {0};
  1414. u32 prop_type, payload_size, payload_type;
  1415. u32 i;
  1416. struct msm_vidc_subscription_params subsc_params;
  1417. u32 subscribe_psc_size = 0;
  1418. const u32 *psc = NULL;
  1419. if (!inst || !inst->core) {
  1420. d_vpr_e("%s: invalid params\n", __func__);
  1421. return -EINVAL;
  1422. }
  1423. i_vpr_h(inst, "%s()\n", __func__);
  1424. core = inst->core;
  1425. if (!core->platform) {
  1426. d_vpr_e("%s: invalid platform data\n", __func__);
  1427. return -EINVAL;
  1428. }
  1429. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  1430. if (inst->codec == MSM_VIDC_H264) {
  1431. subscribe_psc_size = core->platform->data.psc_avc_tbl_size;
  1432. psc = core->platform->data.psc_avc_tbl;
  1433. } else if (inst->codec == MSM_VIDC_HEVC || inst->codec == MSM_VIDC_HEIC) {
  1434. subscribe_psc_size = core->platform->data.psc_hevc_tbl_size;
  1435. psc = core->platform->data.psc_hevc_tbl;
  1436. } else if (inst->codec == MSM_VIDC_VP9) {
  1437. subscribe_psc_size = core->platform->data.psc_vp9_tbl_size;
  1438. psc = core->platform->data.psc_vp9_tbl;
  1439. } else if (inst->codec == MSM_VIDC_AV1) {
  1440. subscribe_psc_size = core->platform->data.psc_av1_tbl_size;
  1441. psc = core->platform->data.psc_av1_tbl;
  1442. } else {
  1443. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  1444. psc = NULL;
  1445. return -EINVAL;
  1446. }
  1447. if (!psc || !subscribe_psc_size) {
  1448. i_vpr_e(inst, "%s: invalid params\n", __func__);
  1449. return -EINVAL;
  1450. }
  1451. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  1452. for (i = 0; i < subscribe_psc_size; i++)
  1453. payload[i + 1] = psc[i];
  1454. rc = venus_hfi_session_command(inst,
  1455. HFI_CMD_SUBSCRIBE_MODE,
  1456. port,
  1457. HFI_PAYLOAD_U32_ARRAY,
  1458. &payload[0],
  1459. ((subscribe_psc_size + 1) *
  1460. sizeof(u32)));
  1461. subsc_params = inst->subcr_params[port];
  1462. for (i = 0; i < subscribe_psc_size; i++) {
  1463. payload[0] = 0;
  1464. payload[1] = 0;
  1465. payload_size = 0;
  1466. payload_type = 0;
  1467. prop_type = psc[i];
  1468. switch (prop_type) {
  1469. case HFI_PROP_BITSTREAM_RESOLUTION:
  1470. payload[0] = subsc_params.bitstream_resolution;
  1471. payload_size = sizeof(u32);
  1472. payload_type = HFI_PAYLOAD_U32;
  1473. break;
  1474. case HFI_PROP_CROP_OFFSETS:
  1475. payload[0] = subsc_params.crop_offsets[0];
  1476. payload[1] = subsc_params.crop_offsets[1];
  1477. payload_size = sizeof(u64);
  1478. payload_type = HFI_PAYLOAD_64_PACKED;
  1479. break;
  1480. case HFI_PROP_LUMA_CHROMA_BIT_DEPTH:
  1481. payload[0] = subsc_params.bit_depth;
  1482. payload_size = sizeof(u32);
  1483. payload_type = HFI_PAYLOAD_U32;
  1484. break;
  1485. case HFI_PROP_CODED_FRAMES:
  1486. payload[0] = subsc_params.coded_frames;
  1487. payload_size = sizeof(u32);
  1488. payload_type = HFI_PAYLOAD_U32;
  1489. break;
  1490. case HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT:
  1491. payload[0] = subsc_params.fw_min_count;
  1492. payload_size = sizeof(u32);
  1493. payload_type = HFI_PAYLOAD_U32;
  1494. break;
  1495. case HFI_PROP_PIC_ORDER_CNT_TYPE:
  1496. payload[0] = subsc_params.pic_order_cnt;
  1497. payload_size = sizeof(u32);
  1498. payload_type = HFI_PAYLOAD_U32;
  1499. break;
  1500. case HFI_PROP_SIGNAL_COLOR_INFO:
  1501. payload[0] = subsc_params.color_info;
  1502. payload_size = sizeof(u32);
  1503. payload_type = HFI_PAYLOAD_U32;
  1504. break;
  1505. case HFI_PROP_PROFILE:
  1506. payload[0] = subsc_params.profile;
  1507. payload_size = sizeof(u32);
  1508. payload_type = HFI_PAYLOAD_U32;
  1509. break;
  1510. case HFI_PROP_LEVEL:
  1511. payload[0] = subsc_params.level;
  1512. payload_size = sizeof(u32);
  1513. payload_type = HFI_PAYLOAD_U32;
  1514. break;
  1515. case HFI_PROP_TIER:
  1516. payload[0] = subsc_params.tier;
  1517. payload_size = sizeof(u32);
  1518. payload_type = HFI_PAYLOAD_U32;
  1519. break;
  1520. case HFI_PROP_AV1_FILM_GRAIN_PRESENT:
  1521. payload[0] = subsc_params.av1_film_grain_present;
  1522. payload_size = sizeof(u32);
  1523. payload_type = HFI_PAYLOAD_U32;
  1524. break;
  1525. case HFI_PROP_AV1_SUPER_BLOCK_ENABLED:
  1526. payload[0] = subsc_params.av1_super_block_enabled;
  1527. payload_size = sizeof(u32);
  1528. payload_type = HFI_PAYLOAD_U32;
  1529. break;
  1530. default:
  1531. i_vpr_e(inst, "%s: unknown property %#x\n", __func__,
  1532. prop_type);
  1533. prop_type = 0;
  1534. rc = -EINVAL;
  1535. break;
  1536. }
  1537. if (prop_type) {
  1538. rc = venus_hfi_session_property(inst,
  1539. prop_type,
  1540. HFI_HOST_FLAGS_NONE,
  1541. get_hfi_port(inst, port),
  1542. payload_type,
  1543. &payload,
  1544. payload_size);
  1545. if (rc)
  1546. return rc;
  1547. }
  1548. }
  1549. return rc;
  1550. }
  1551. static int msm_vdec_update_max_map_output_count(struct msm_vidc_inst *inst)
  1552. {
  1553. int rc = 0;
  1554. struct v4l2_format *f;
  1555. u32 width, height, count;
  1556. if (!inst) {
  1557. d_vpr_e("%s: invalid params\n", __func__);
  1558. return -EINVAL;
  1559. }
  1560. f = &inst->fmts[OUTPUT_PORT];
  1561. width = f->fmt.pix_mp.width;
  1562. height = f->fmt.pix_mp.height;
  1563. /*
  1564. * adjust max map output count based on resolution
  1565. * to enhance performance.
  1566. * For 8K session: count = 20
  1567. * For 4K session: count = 32
  1568. * For 1080p session: count = 48
  1569. * For all remaining sessions: count = 64
  1570. */
  1571. if (res_is_greater_than(width, height, 4096, 2160))
  1572. count = 20;
  1573. else if (res_is_greater_than(width, height, 1920, 1080))
  1574. count = 32;
  1575. else if (res_is_greater_than(width, height, 1280, 720))
  1576. count = 48;
  1577. else
  1578. count = 64;
  1579. inst->max_map_output_count = count;
  1580. i_vpr_h(inst, "%s: count: %d\n", __func__, inst->max_map_output_count);
  1581. return rc;
  1582. }
  1583. int msm_vdec_streamon_output(struct msm_vidc_inst *inst)
  1584. {
  1585. int rc = 0;
  1586. if (!inst || !inst->core) {
  1587. d_vpr_e("%s: invalid params\n", __func__);
  1588. return -EINVAL;
  1589. }
  1590. if (is_output_meta_enabled(inst) &&
  1591. !inst->bufq[OUTPUT_META_PORT].vb2q->streaming) {
  1592. i_vpr_e(inst,
  1593. "%s: Meta port must be streamed on before data port\n",
  1594. __func__);
  1595. return -EINVAL;
  1596. }
  1597. if (inst->capabilities[CODED_FRAMES].value == CODED_FRAMES_INTERLACE &&
  1598. !is_ubwc_colorformat(inst->capabilities[PIX_FMTS].value)) {
  1599. i_vpr_e(inst,
  1600. "%s: interlace with non-ubwc color format is unsupported\n",
  1601. __func__);
  1602. return -EINVAL;
  1603. }
  1604. rc = msm_vidc_check_session_supported(inst);
  1605. if (rc)
  1606. goto error;
  1607. rc = msm_vdec_update_max_map_output_count(inst);
  1608. if (rc)
  1609. goto error;
  1610. rc = msm_vdec_set_output_properties(inst);
  1611. if (rc)
  1612. goto error;
  1613. if (!inst->opsc_properties_set) {
  1614. memcpy(&inst->subcr_params[OUTPUT_PORT],
  1615. &inst->subcr_params[INPUT_PORT],
  1616. sizeof(inst->subcr_params[INPUT_PORT]));
  1617. rc = msm_vdec_subscribe_output_port_settings_change(inst, OUTPUT_PORT);
  1618. if (rc)
  1619. goto error;
  1620. inst->opsc_properties_set = true;
  1621. }
  1622. rc = msm_vdec_subscribe_property(inst, OUTPUT_PORT);
  1623. if (rc)
  1624. goto error;
  1625. rc = msm_vdec_subscribe_metadata(inst, OUTPUT_PORT);
  1626. if (rc)
  1627. goto error;
  1628. rc = msm_vdec_set_delivery_mode_property(inst, OUTPUT_PORT);
  1629. if (rc)
  1630. goto error;
  1631. rc = msm_vdec_set_delivery_mode_metadata(inst, OUTPUT_PORT);
  1632. if (rc)
  1633. goto error;
  1634. rc = msm_vdec_get_output_internal_buffers(inst);
  1635. if (rc)
  1636. goto error;
  1637. rc = msm_vdec_destroy_internal_buffers(inst, OUTPUT_PORT);
  1638. if (rc)
  1639. goto error;
  1640. rc = msm_vdec_create_output_internal_buffers(inst);
  1641. if (rc)
  1642. goto error;
  1643. rc = msm_vidc_process_streamon_output(inst);
  1644. if (rc)
  1645. goto error;
  1646. rc = msm_vdec_queue_output_internal_buffers(inst);
  1647. if (rc)
  1648. goto error;
  1649. return 0;
  1650. error:
  1651. i_vpr_e(inst, "%s: failed\n", __func__);
  1652. msm_vdec_streamoff_output(inst);
  1653. return rc;
  1654. }
  1655. static inline enum msm_vidc_allow msm_vdec_allow_queue_deferred_buffers(
  1656. struct msm_vidc_inst *inst)
  1657. {
  1658. int count;
  1659. if (!inst) {
  1660. d_vpr_e("%s: invalid params\n", __func__);
  1661. return MSM_VIDC_DISALLOW;
  1662. }
  1663. /* do not defer buffers initially to avoid latency issues */
  1664. if (inst->power.buffer_counter <= SKIP_BATCH_WINDOW)
  1665. return MSM_VIDC_ALLOW;
  1666. /* defer qbuf, if pending buffers count less than batch size */
  1667. count = msm_vidc_num_buffers(inst, MSM_VIDC_BUF_OUTPUT, MSM_VIDC_ATTR_DEFERRED);
  1668. if (count < inst->decode_batch.size)
  1669. return MSM_VIDC_DEFER;
  1670. return MSM_VIDC_ALLOW;
  1671. }
  1672. static int msm_vdec_qbuf_batch(struct msm_vidc_inst *inst,
  1673. struct vb2_buffer *vb2)
  1674. {
  1675. struct msm_vidc_buffer *buf = NULL;
  1676. enum msm_vidc_allow allow;
  1677. int rc;
  1678. if (!inst || !vb2 || !inst->decode_batch.size) {
  1679. d_vpr_e("%s: invalid params\n", __func__);
  1680. return -EINVAL;
  1681. }
  1682. buf = msm_vidc_get_driver_buf(inst, vb2);
  1683. if (!buf)
  1684. return -EINVAL;
  1685. if (is_state(inst, MSM_VIDC_OPEN) ||
  1686. is_state(inst, MSM_VIDC_INPUT_STREAMING)) {
  1687. print_vidc_buffer(VIDC_LOW, "low ", "qbuf deferred", inst, buf);
  1688. return 0;
  1689. }
  1690. allow = msm_vdec_allow_queue_deferred_buffers(inst);
  1691. if (allow == MSM_VIDC_DISALLOW) {
  1692. i_vpr_e(inst, "%s: queue deferred buffers not allowed\n", __func__);
  1693. return -EINVAL;
  1694. } else if (allow == MSM_VIDC_DEFER) {
  1695. print_vidc_buffer(VIDC_LOW, "low ", "batch-qbuf deferred", inst, buf);
  1696. schedule_batch_work(inst);
  1697. return 0;
  1698. }
  1699. cancel_batch_work(inst);
  1700. rc = msm_vidc_queue_deferred_buffers(inst, MSM_VIDC_BUF_OUTPUT);
  1701. if (rc)
  1702. return rc;
  1703. return rc;
  1704. }
  1705. static int msm_vdec_release_eligible_buffers(struct msm_vidc_inst *inst)
  1706. {
  1707. int rc = 0;
  1708. struct msm_vidc_buffer *ro_buf;
  1709. if (!inst) {
  1710. d_vpr_e("%s: invalid params\n", __func__);
  1711. return -EINVAL;
  1712. }
  1713. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1714. /* release only release eligible read-only buffers */
  1715. if (!(ro_buf->attr & MSM_VIDC_ATTR_RELEASE_ELIGIBLE))
  1716. continue;
  1717. /* skip releasing buffers for which release cmd was already sent */
  1718. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1719. continue;
  1720. rc = venus_hfi_release_buffer(inst, ro_buf);
  1721. if (rc)
  1722. return rc;
  1723. ro_buf->attr |= MSM_VIDC_ATTR_PENDING_RELEASE;
  1724. ro_buf->attr &= ~MSM_VIDC_ATTR_RELEASE_ELIGIBLE;
  1725. print_vidc_buffer(VIDC_LOW, "low ", "release buf", inst, ro_buf);
  1726. }
  1727. return rc;
  1728. }
  1729. static int msm_vdec_release_nonref_buffers(struct msm_vidc_inst *inst)
  1730. {
  1731. int rc = 0;
  1732. u32 fw_ro_count = 0, nonref_ro_count = 0;
  1733. struct msm_vidc_buffer *ro_buf;
  1734. int i = 0;
  1735. bool found = false;
  1736. if (!inst) {
  1737. d_vpr_e("%s: invalid params\n", __func__);
  1738. return -EINVAL;
  1739. }
  1740. /*
  1741. * if DPB_LIST subscribed on output port then driver need to
  1742. * hold MAX_BPB_COUNT of read only buffer at least.
  1743. */
  1744. if (!inst->output_dpb_list_enabled)
  1745. goto release_buffers;
  1746. /* count read_only buffers which are not pending release in read_only list */
  1747. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1748. if (!(ro_buf->attr & MSM_VIDC_ATTR_READ_ONLY))
  1749. continue;
  1750. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1751. continue;
  1752. fw_ro_count++;
  1753. }
  1754. if (fw_ro_count <= MAX_DPB_COUNT)
  1755. return 0;
  1756. /*
  1757. * Mark those read only buffers present in read_only list as
  1758. * non-reference if that buffer is not part of dpb_list_payload.
  1759. * count such non-ref read only buffers as nonref_ro_count.
  1760. * dpb_list_payload details:
  1761. * payload[0-1] : 64 bits base_address of DPB-1
  1762. * payload[2] : 32 bits addr_offset of DPB-1
  1763. * payload[3] : 32 bits data_offset of DPB-1
  1764. */
  1765. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1766. found = false;
  1767. if (!(ro_buf->attr & MSM_VIDC_ATTR_READ_ONLY))
  1768. continue;
  1769. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1770. continue;
  1771. for (i = 0; (i + 3) < MAX_DPB_LIST_ARRAY_SIZE; i = i + 4) {
  1772. if (ro_buf->device_addr == inst->dpb_list_payload[i] &&
  1773. ro_buf->data_offset == inst->dpb_list_payload[i + 3]) {
  1774. found = true;
  1775. break;
  1776. }
  1777. }
  1778. if (!found)
  1779. nonref_ro_count++;
  1780. }
  1781. if (nonref_ro_count <= inst->buffers.output.min_count)
  1782. return 0;
  1783. i_vpr_l(inst, "%s: fw ro buf count %d, non-ref ro count %d\n",
  1784. __func__, fw_ro_count, nonref_ro_count);
  1785. release_buffers:
  1786. /* release the eligible buffers as per above condition */
  1787. list_for_each_entry(ro_buf, &inst->buffers.read_only.list, list) {
  1788. found = false;
  1789. if (!(ro_buf->attr & MSM_VIDC_ATTR_READ_ONLY))
  1790. continue;
  1791. if (ro_buf->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
  1792. continue;
  1793. for (i = 0; (i + 3) < MAX_DPB_LIST_ARRAY_SIZE; i = i + 4) {
  1794. if (ro_buf->device_addr == inst->dpb_list_payload[i] &&
  1795. ro_buf->data_offset == inst->dpb_list_payload[i + 3]) {
  1796. found = true;
  1797. break;
  1798. }
  1799. }
  1800. if (!found) {
  1801. ro_buf->attr |= MSM_VIDC_ATTR_PENDING_RELEASE;
  1802. print_vidc_buffer(VIDC_LOW, "low ", "release buf", inst, ro_buf);
  1803. rc = venus_hfi_release_buffer(inst, ro_buf);
  1804. if (rc)
  1805. return rc;
  1806. }
  1807. }
  1808. return rc;
  1809. }
  1810. int msm_vdec_qbuf(struct msm_vidc_inst *inst, struct vb2_buffer *vb2)
  1811. {
  1812. int rc = 0;
  1813. if (!inst || !vb2) {
  1814. d_vpr_e("%s: invalid params\n", __func__);
  1815. return -EINVAL;
  1816. }
  1817. if (inst->adjust_priority) {
  1818. s32 priority = inst->capabilities[PRIORITY].value;
  1819. priority += inst->adjust_priority;
  1820. inst->adjust_priority = 0;
  1821. msm_vidc_update_cap_value(inst, PRIORITY, priority, __func__);
  1822. msm_vidc_set_session_priority(inst, PRIORITY);
  1823. }
  1824. /* batch decoder output & meta buffer only */
  1825. if (inst->decode_batch.enable && vb2->type == OUTPUT_MPLANE)
  1826. rc = msm_vdec_qbuf_batch(inst, vb2);
  1827. else
  1828. rc = msm_vidc_queue_buffer_single(inst, vb2);
  1829. if (rc)
  1830. return rc;
  1831. /*
  1832. * if DPB_LIST property is subscribed on output port, then
  1833. * driver needs to hold at least MAX_BPB_COUNT of read only
  1834. * buffers. So call msm_vdec_release_nonref_buffers() to handle
  1835. * the same.
  1836. */
  1837. if (vb2->type == OUTPUT_MPLANE) {
  1838. if (inst->input_dpb_list_enabled)
  1839. rc = msm_vdec_release_eligible_buffers(inst);
  1840. else if (inst->output_dpb_list_enabled)
  1841. rc = msm_vdec_release_nonref_buffers(inst);
  1842. if (rc)
  1843. return rc;
  1844. }
  1845. return rc;
  1846. }
  1847. static int msm_vdec_alloc_and_queue_additional_dpb_buffers(struct msm_vidc_inst *inst)
  1848. {
  1849. struct msm_vidc_buffers *buffers;
  1850. struct msm_vidc_buffer *buffer = NULL;
  1851. int i, cur_min_count = 0, rc = 0;
  1852. if (!inst) {
  1853. d_vpr_e("%s: invalid params\n", __func__);
  1854. return -EINVAL;
  1855. }
  1856. /* get latest min_count and size */
  1857. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  1858. if (rc)
  1859. return rc;
  1860. buffers = msm_vidc_get_buffers(inst, MSM_VIDC_BUF_DPB, __func__);
  1861. if (!buffers)
  1862. return -EINVAL;
  1863. /* get current min_count */
  1864. list_for_each_entry(buffer, &buffers->list, list)
  1865. cur_min_count++;
  1866. /* skip alloc and queue */
  1867. if (cur_min_count >= buffers->min_count)
  1868. return 0;
  1869. i_vpr_h(inst, "%s: dpb buffer count increased from %u -> %u\n",
  1870. __func__, cur_min_count, buffers->min_count);
  1871. /* allocate additional DPB buffers */
  1872. for (i = cur_min_count; i < buffers->min_count; i++) {
  1873. rc = msm_vidc_create_internal_buffer(inst, MSM_VIDC_BUF_DPB, i);
  1874. if (rc)
  1875. return rc;
  1876. }
  1877. /* queue additional DPB buffers */
  1878. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  1879. if (rc)
  1880. return rc;
  1881. return 0;
  1882. }
  1883. int msm_vdec_stop_cmd(struct msm_vidc_inst *inst)
  1884. {
  1885. int rc = 0;
  1886. i_vpr_h(inst, "received cmd: drain\n");
  1887. rc = msm_vidc_process_drain(inst);
  1888. if (rc)
  1889. return rc;
  1890. return rc;
  1891. }
  1892. int msm_vdec_start_cmd(struct msm_vidc_inst *inst)
  1893. {
  1894. int rc = 0;
  1895. if (!inst) {
  1896. d_vpr_e("%s: invalid params\n", __func__);
  1897. return -EINVAL;
  1898. }
  1899. i_vpr_h(inst, "received cmd: resume\n");
  1900. vb2_clear_last_buffer_dequeued(inst->bufq[OUTPUT_META_PORT].vb2q);
  1901. vb2_clear_last_buffer_dequeued(inst->bufq[OUTPUT_PORT].vb2q);
  1902. if (inst->capabilities[CODED_FRAMES].value == CODED_FRAMES_INTERLACE &&
  1903. !is_ubwc_colorformat(inst->capabilities[PIX_FMTS].value)) {
  1904. i_vpr_e(inst,
  1905. "%s: interlace with non-ubwc color format is unsupported\n",
  1906. __func__);
  1907. return -EINVAL;
  1908. }
  1909. /* tune power features */
  1910. inst->decode_batch.enable = msm_vidc_allow_decode_batch(inst);
  1911. msm_vidc_allow_dcvs(inst);
  1912. msm_vidc_power_data_reset(inst);
  1913. /*
  1914. * client is completing partial port reconfiguration,
  1915. * hence reallocate input internal buffers before input port
  1916. * is resumed.
  1917. */
  1918. if (is_sub_state(inst, MSM_VIDC_DRC) &&
  1919. is_sub_state(inst, MSM_VIDC_DRC_LAST_BUFFER) &&
  1920. is_sub_state(inst, MSM_VIDC_INPUT_PAUSE)) {
  1921. rc = msm_vidc_alloc_and_queue_input_internal_buffers(inst);
  1922. if (rc)
  1923. return rc;
  1924. rc = msm_vidc_set_stage(inst, STAGE);
  1925. if (rc)
  1926. return rc;
  1927. rc = msm_vidc_set_pipe(inst, PIPE);
  1928. if (rc)
  1929. return rc;
  1930. }
  1931. /* allocate and queue extra dpb buffers */
  1932. rc = msm_vdec_alloc_and_queue_additional_dpb_buffers(inst);
  1933. if (rc)
  1934. return rc;
  1935. /* queue pending deferred buffers */
  1936. rc = msm_vidc_queue_deferred_buffers(inst, MSM_VIDC_BUF_OUTPUT);
  1937. if (rc)
  1938. return rc;
  1939. /* print final buffer counts & size details */
  1940. msm_vidc_print_buffer_info(inst);
  1941. /* print internal buffer memory usage stats */
  1942. msm_vidc_print_memory_stats(inst);
  1943. rc = msm_vidc_process_resume(inst);
  1944. if (rc)
  1945. return rc;
  1946. return rc;
  1947. }
  1948. int msm_vdec_try_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  1949. {
  1950. int rc = 0;
  1951. struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
  1952. u32 pix_fmt;
  1953. if (!inst) {
  1954. d_vpr_e("%s: invalid params\n", __func__);
  1955. return -EINVAL;
  1956. }
  1957. memset(pixmp->reserved, 0, sizeof(pixmp->reserved));
  1958. if (f->type == INPUT_MPLANE) {
  1959. pix_fmt = v4l2_codec_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__);
  1960. if (!pix_fmt) {
  1961. i_vpr_e(inst, "%s: unsupported codec, set current params\n", __func__);
  1962. f->fmt.pix_mp.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width;
  1963. f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1964. f->fmt.pix_mp.pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
  1965. pix_fmt = v4l2_codec_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__);
  1966. }
  1967. } else if (f->type == OUTPUT_MPLANE) {
  1968. pix_fmt = v4l2_colorformat_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__);
  1969. if (!pix_fmt) {
  1970. i_vpr_e(inst, "%s: unsupported format, set current params\n", __func__);
  1971. f->fmt.pix_mp.pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  1972. f->fmt.pix_mp.width = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width;
  1973. f->fmt.pix_mp.height = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height;
  1974. }
  1975. if (inst->bufq[INPUT_PORT].vb2q->streaming) {
  1976. f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1977. f->fmt.pix_mp.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width;
  1978. }
  1979. } else if (f->type == INPUT_META_PLANE) {
  1980. f->fmt.meta.dataformat = inst->fmts[INPUT_META_PORT].fmt.meta.dataformat;
  1981. f->fmt.meta.buffersize = inst->fmts[INPUT_META_PORT].fmt.meta.buffersize;
  1982. } else if (f->type == OUTPUT_META_PLANE) {
  1983. f->fmt.meta.dataformat = inst->fmts[OUTPUT_META_PORT].fmt.meta.dataformat;
  1984. f->fmt.meta.buffersize = inst->fmts[OUTPUT_META_PORT].fmt.meta.buffersize;
  1985. } else {
  1986. i_vpr_e(inst, "%s: invalid type %d\n", __func__, f->type);
  1987. return -EINVAL;
  1988. }
  1989. if (pixmp->field == V4L2_FIELD_ANY)
  1990. pixmp->field = V4L2_FIELD_NONE;
  1991. pixmp->num_planes = 1;
  1992. return rc;
  1993. }
  1994. static bool msm_vidc_check_max_sessions_vp9d(struct msm_vidc_core *core)
  1995. {
  1996. u32 vp9d_instance_count = 0;
  1997. struct msm_vidc_inst *inst = NULL;
  1998. core_lock(core, __func__);
  1999. list_for_each_entry(inst, &core->instances, list) {
  2000. if (is_decode_session(inst) &&
  2001. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat ==
  2002. V4L2_PIX_FMT_VP9)
  2003. vp9d_instance_count++;
  2004. }
  2005. core_unlock(core, __func__);
  2006. if (vp9d_instance_count > MAX_VP9D_INST_COUNT)
  2007. return true;
  2008. return false;
  2009. }
  2010. int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  2011. {
  2012. int rc = 0;
  2013. struct msm_vidc_core *core;
  2014. struct v4l2_format *fmt, *output_fmt;
  2015. u32 codec_align;
  2016. enum msm_vidc_colorformat_type colorformat;
  2017. if (!inst || !inst->core) {
  2018. d_vpr_e("%s: invalid params\n", __func__);
  2019. return -EINVAL;
  2020. }
  2021. core = inst->core;
  2022. msm_vdec_try_fmt(inst, f);
  2023. if (f->type == INPUT_MPLANE) {
  2024. if (inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat !=
  2025. f->fmt.pix_mp.pixelformat) {
  2026. rc = msm_vdec_codec_change(inst, f->fmt.pix_mp.pixelformat);
  2027. if (rc)
  2028. goto err_invalid_fmt;
  2029. }
  2030. if (f->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_VP9) {
  2031. if (msm_vidc_check_max_sessions_vp9d(inst->core)) {
  2032. i_vpr_e(inst,
  2033. "%s: vp9d sessions exceeded max limit %d\n",
  2034. __func__, MAX_VP9D_INST_COUNT);
  2035. rc = -ENOMEM;
  2036. goto err_invalid_fmt;
  2037. }
  2038. }
  2039. fmt = &inst->fmts[INPUT_PORT];
  2040. fmt->type = INPUT_MPLANE;
  2041. codec_align = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat ==
  2042. V4L2_PIX_FMT_HEVC ? 32 : 16;
  2043. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, codec_align);
  2044. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, codec_align);
  2045. fmt->fmt.pix_mp.num_planes = 1;
  2046. fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  2047. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2048. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  2049. inst->buffers.input.min_count = call_session_op(core,
  2050. min_count, inst, MSM_VIDC_BUF_INPUT);
  2051. inst->buffers.input.extra_count = call_session_op(core,
  2052. extra_count, inst, MSM_VIDC_BUF_INPUT);
  2053. if (inst->buffers.input.actual_count <
  2054. inst->buffers.input.min_count +
  2055. inst->buffers.input.extra_count) {
  2056. inst->buffers.input.actual_count =
  2057. inst->buffers.input.min_count +
  2058. inst->buffers.input.extra_count;
  2059. }
  2060. inst->buffers.input.size =
  2061. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  2062. /* update input port color info */
  2063. fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
  2064. fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
  2065. fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
  2066. fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
  2067. /* update output port color info */
  2068. output_fmt = &inst->fmts[OUTPUT_PORT];
  2069. output_fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
  2070. output_fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
  2071. output_fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
  2072. output_fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
  2073. /* update crop dimensions */
  2074. inst->crop.left = inst->crop.top = 0;
  2075. inst->crop.width = f->fmt.pix_mp.width;
  2076. inst->crop.height = f->fmt.pix_mp.height;
  2077. i_vpr_h(inst,
  2078. "%s: type: INPUT, codec %s width %d height %d size %u min_count %d extra_count %d\n",
  2079. __func__, v4l2_pixelfmt_name(inst, f->fmt.pix_mp.pixelformat),
  2080. f->fmt.pix_mp.width, f->fmt.pix_mp.height,
  2081. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  2082. inst->buffers.input.min_count,
  2083. inst->buffers.input.extra_count);
  2084. } else if (f->type == INPUT_META_PLANE) {
  2085. fmt = &inst->fmts[INPUT_META_PORT];
  2086. fmt->type = INPUT_META_PLANE;
  2087. fmt->fmt.meta.dataformat =
  2088. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2089. fmt->fmt.meta.buffersize = call_session_op(core,
  2090. buffer_size, inst, MSM_VIDC_BUF_INPUT_META);
  2091. inst->buffers.input_meta.min_count =
  2092. inst->buffers.input.min_count;
  2093. inst->buffers.input_meta.extra_count =
  2094. inst->buffers.input.extra_count;
  2095. inst->buffers.input_meta.actual_count =
  2096. inst->buffers.input.actual_count;
  2097. inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
  2098. i_vpr_h(inst,
  2099. "%s: type: INPUT_META, size %u min_count %d extra_count %d\n",
  2100. __func__, fmt->fmt.meta.buffersize,
  2101. inst->buffers.input_meta.min_count,
  2102. inst->buffers.input_meta.extra_count);
  2103. } else if (f->type == OUTPUT_MPLANE) {
  2104. fmt = &inst->fmts[OUTPUT_PORT];
  2105. fmt->type = OUTPUT_MPLANE;
  2106. if (inst->bufq[INPUT_PORT].vb2q->streaming) {
  2107. f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  2108. f->fmt.pix_mp.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width;
  2109. }
  2110. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  2111. colorformat = v4l2_colorformat_to_driver(inst, fmt->fmt.pix_mp.pixelformat,
  2112. __func__);
  2113. fmt->fmt.pix_mp.width = video_y_stride_pix(
  2114. colorformat, f->fmt.pix_mp.width);
  2115. fmt->fmt.pix_mp.height = video_y_scanlines(
  2116. colorformat, f->fmt.pix_mp.height);
  2117. fmt->fmt.pix_mp.num_planes = 1;
  2118. fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
  2119. video_y_stride_bytes(
  2120. colorformat, f->fmt.pix_mp.width);
  2121. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2122. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  2123. if (!inst->bufq[INPUT_PORT].vb2q->streaming)
  2124. inst->buffers.output.min_count = call_session_op(core,
  2125. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  2126. inst->buffers.output.extra_count = call_session_op(core,
  2127. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  2128. if (inst->buffers.output.actual_count <
  2129. inst->buffers.output.min_count +
  2130. inst->buffers.output.extra_count) {
  2131. inst->buffers.output.actual_count =
  2132. inst->buffers.output.min_count +
  2133. inst->buffers.output.extra_count;
  2134. }
  2135. inst->buffers.output.size =
  2136. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  2137. msm_vidc_update_cap_value(inst, PIX_FMTS, colorformat, __func__);
  2138. /* update crop while input port is not streaming */
  2139. if (!inst->bufq[INPUT_PORT].vb2q->streaming) {
  2140. inst->crop.top = 0;
  2141. inst->crop.left = 0;
  2142. inst->crop.width = f->fmt.pix_mp.width;
  2143. inst->crop.height = f->fmt.pix_mp.height;
  2144. }
  2145. i_vpr_h(inst,
  2146. "%s: type: OUTPUT, format %s width %d height %d size %u min_count %d extra_count %d\n",
  2147. __func__, v4l2_pixelfmt_name(inst, fmt->fmt.pix_mp.pixelformat),
  2148. fmt->fmt.pix_mp.width, fmt->fmt.pix_mp.height,
  2149. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  2150. inst->buffers.output.min_count,
  2151. inst->buffers.output.extra_count);
  2152. } else if (f->type == OUTPUT_META_PLANE) {
  2153. fmt = &inst->fmts[OUTPUT_META_PORT];
  2154. fmt->type = OUTPUT_META_PLANE;
  2155. fmt->fmt.meta.dataformat =
  2156. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2157. fmt->fmt.meta.buffersize = call_session_op(core,
  2158. buffer_size, inst, MSM_VIDC_BUF_OUTPUT_META);
  2159. inst->buffers.output_meta.min_count =
  2160. inst->buffers.output.min_count;
  2161. inst->buffers.output_meta.extra_count =
  2162. inst->buffers.output.extra_count;
  2163. inst->buffers.output_meta.actual_count =
  2164. inst->buffers.output.actual_count;
  2165. inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
  2166. i_vpr_h(inst,
  2167. "%s: type: OUTPUT_META, size %u min_count %d extra_count %d\n",
  2168. __func__, fmt->fmt.meta.buffersize,
  2169. inst->buffers.output_meta.min_count,
  2170. inst->buffers.output_meta.extra_count);
  2171. } else {
  2172. i_vpr_e(inst, "%s: invalid type %d\n", __func__, f->type);
  2173. goto err_invalid_fmt;
  2174. }
  2175. memcpy(f, fmt, sizeof(struct v4l2_format));
  2176. err_invalid_fmt:
  2177. return rc;
  2178. }
  2179. int msm_vdec_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  2180. {
  2181. int rc = 0;
  2182. int port;
  2183. if (!inst) {
  2184. d_vpr_e("%s: invalid params\n", __func__);
  2185. return -EINVAL;
  2186. }
  2187. port = v4l2_type_to_driver_port(inst, f->type, __func__);
  2188. if (port < 0)
  2189. return -EINVAL;
  2190. memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
  2191. return rc;
  2192. }
  2193. int msm_vdec_s_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
  2194. {
  2195. if (!inst || !s) {
  2196. d_vpr_e("%s: invalid params\n", __func__);
  2197. return -EINVAL;
  2198. }
  2199. i_vpr_e(inst, "%s: unsupported\n", __func__);
  2200. return -EINVAL;
  2201. }
  2202. int msm_vdec_g_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
  2203. {
  2204. if (!inst || !s) {
  2205. d_vpr_e("%s: invalid params\n", __func__);
  2206. return -EINVAL;
  2207. }
  2208. if (s->type != OUTPUT_MPLANE && s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  2209. i_vpr_e(inst, "%s: invalid type %d\n", __func__, s->type);
  2210. return -EINVAL;
  2211. }
  2212. switch (s->target) {
  2213. case V4L2_SEL_TGT_CROP_BOUNDS:
  2214. case V4L2_SEL_TGT_CROP_DEFAULT:
  2215. case V4L2_SEL_TGT_CROP:
  2216. case V4L2_SEL_TGT_COMPOSE_BOUNDS:
  2217. case V4L2_SEL_TGT_COMPOSE_PADDED:
  2218. case V4L2_SEL_TGT_COMPOSE_DEFAULT:
  2219. case V4L2_SEL_TGT_COMPOSE:
  2220. s->r.left = inst->crop.left;
  2221. s->r.top = inst->crop.top;
  2222. s->r.width = inst->crop.width;
  2223. s->r.height = inst->crop.height;
  2224. break;
  2225. default:
  2226. i_vpr_e(inst, "%s: invalid target %d\n",
  2227. __func__, s->target);
  2228. return -EINVAL;
  2229. }
  2230. i_vpr_h(inst, "%s: target %d, r [%d, %d, %d, %d]\n",
  2231. __func__, s->target, s->r.top, s->r.left,
  2232. s->r.width, s->r.height);
  2233. return 0;
  2234. }
  2235. int msm_vdec_subscribe_event(struct msm_vidc_inst *inst,
  2236. const struct v4l2_event_subscription *sub)
  2237. {
  2238. int rc = 0;
  2239. if (!inst || !sub) {
  2240. d_vpr_e("%s: invalid params\n", __func__);
  2241. return -EINVAL;
  2242. }
  2243. switch (sub->type) {
  2244. case V4L2_EVENT_EOS:
  2245. rc = v4l2_event_subscribe(&inst->event_handler, sub, MAX_EVENTS, NULL);
  2246. break;
  2247. case V4L2_EVENT_SOURCE_CHANGE:
  2248. rc = v4l2_src_change_event_subscribe(&inst->event_handler, sub);
  2249. break;
  2250. case V4L2_EVENT_CTRL:
  2251. rc = v4l2_ctrl_subscribe_event(&inst->event_handler, sub);
  2252. break;
  2253. default:
  2254. i_vpr_e(inst, "%s: invalid type %d id %d\n", __func__, sub->type, sub->id);
  2255. return -EINVAL;
  2256. }
  2257. if (rc)
  2258. i_vpr_e(inst, "%s: failed, type %d id %d\n",
  2259. __func__, sub->type, sub->id);
  2260. return rc;
  2261. }
  2262. static int msm_vdec_check_colorformat_supported(struct msm_vidc_inst* inst,
  2263. enum msm_vidc_colorformat_type colorformat)
  2264. {
  2265. bool supported = true;
  2266. /* do not reject coloformats before streamon */
  2267. if (!inst->bufq[INPUT_PORT].vb2q->streaming)
  2268. return true;
  2269. /*
  2270. * bit_depth 8 bit supports 8 bit colorformats only
  2271. * bit_depth 10 bit supports 10 bit colorformats only
  2272. * interlace supports ubwc colorformats only
  2273. */
  2274. if (inst->capabilities[BIT_DEPTH].value == BIT_DEPTH_8 &&
  2275. !is_8bit_colorformat(colorformat))
  2276. supported = false;
  2277. if (inst->capabilities[BIT_DEPTH].value == BIT_DEPTH_10 &&
  2278. !is_10bit_colorformat(colorformat))
  2279. supported = false;
  2280. if (inst->capabilities[CODED_FRAMES].value ==
  2281. CODED_FRAMES_INTERLACE &&
  2282. !is_ubwc_colorformat(colorformat))
  2283. supported = false;
  2284. return supported;
  2285. }
  2286. int msm_vdec_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
  2287. {
  2288. int rc = 0;
  2289. struct msm_vidc_core *core;
  2290. u32 array[32] = {0};
  2291. u32 i = 0;
  2292. if (!inst || !inst->core || !f ||
  2293. f->index >= ARRAY_SIZE(array)) {
  2294. d_vpr_e("%s: invalid params\n", __func__);
  2295. return -EINVAL;
  2296. }
  2297. core = inst->core;
  2298. if (f->type == INPUT_MPLANE) {
  2299. u32 codecs = core->capabilities[DEC_CODECS].value;
  2300. u32 idx = 0;
  2301. for (i = 0; i <= 31; i++) {
  2302. if (codecs & BIT(i)) {
  2303. if (idx >= ARRAY_SIZE(array))
  2304. break;
  2305. array[idx] = codecs & BIT(i);
  2306. idx++;
  2307. }
  2308. }
  2309. if (!array[f->index])
  2310. return -EINVAL;
  2311. f->pixelformat = v4l2_codec_from_driver(inst, array[f->index],
  2312. __func__);
  2313. if (!f->pixelformat)
  2314. return -EINVAL;
  2315. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  2316. strlcpy(f->description, "codec", sizeof(f->description));
  2317. } else if (f->type == OUTPUT_MPLANE) {
  2318. u32 formats = inst->capabilities[PIX_FMTS].step_or_mask;
  2319. u32 idx = 0;
  2320. for (i = 0; i <= 31; i++) {
  2321. if (formats & BIT(i)) {
  2322. if (idx >= ARRAY_SIZE(array))
  2323. break;
  2324. if (msm_vdec_check_colorformat_supported(inst,
  2325. formats & BIT(i))) {
  2326. array[idx] = formats & BIT(i);
  2327. idx++;
  2328. }
  2329. }
  2330. }
  2331. if (!array[f->index])
  2332. return -EINVAL;
  2333. f->pixelformat = v4l2_colorformat_from_driver(inst, array[f->index],
  2334. __func__);
  2335. if (!f->pixelformat)
  2336. return -EINVAL;
  2337. strlcpy(f->description, "colorformat", sizeof(f->description));
  2338. } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
  2339. if (!f->index) {
  2340. f->pixelformat =
  2341. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2342. strlcpy(f->description, "metadata", sizeof(f->description));
  2343. } else {
  2344. return -EINVAL;
  2345. }
  2346. }
  2347. memset(f->reserved, 0, sizeof(f->reserved));
  2348. i_vpr_h(inst, "%s: index %d, %s: %s, flags %#x\n",
  2349. __func__, f->index, f->description,
  2350. v4l2_pixelfmt_name(inst, f->pixelformat), f->flags);
  2351. return rc;
  2352. }
  2353. int msm_vdec_inst_init(struct msm_vidc_inst *inst)
  2354. {
  2355. int rc = 0;
  2356. struct msm_vidc_core *core;
  2357. struct v4l2_format *f;
  2358. enum msm_vidc_colorformat_type colorformat;
  2359. if (!inst || !inst->core) {
  2360. d_vpr_e("%s: invalid params\n", __func__);
  2361. return -EINVAL;
  2362. }
  2363. core = inst->core;
  2364. INIT_DELAYED_WORK(&inst->decode_batch.work, msm_vidc_batch_handler);
  2365. if (core->capabilities[DECODE_BATCH].value) {
  2366. inst->decode_batch.enable = true;
  2367. inst->decode_batch.size = MAX_DEC_BATCH_SIZE;
  2368. }
  2369. if (core->capabilities[DCVS].value)
  2370. inst->power.dcvs_mode = true;
  2371. f = &inst->fmts[INPUT_PORT];
  2372. f->type = INPUT_MPLANE;
  2373. f->fmt.pix_mp.width = DEFAULT_WIDTH;
  2374. f->fmt.pix_mp.height = DEFAULT_HEIGHT;
  2375. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
  2376. f->fmt.pix_mp.num_planes = 1;
  2377. f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  2378. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2379. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  2380. f->fmt.pix_mp.field = V4L2_FIELD_NONE;
  2381. inst->buffers.input.min_count = call_session_op(core,
  2382. min_count, inst, MSM_VIDC_BUF_INPUT);
  2383. inst->buffers.input.extra_count = call_session_op(core,
  2384. extra_count, inst, MSM_VIDC_BUF_INPUT);
  2385. inst->buffers.input.actual_count =
  2386. inst->buffers.input.min_count +
  2387. inst->buffers.input.extra_count;
  2388. inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  2389. inst->crop.left = inst->crop.top = 0;
  2390. inst->crop.width = f->fmt.pix_mp.width;
  2391. inst->crop.height = f->fmt.pix_mp.height;
  2392. f = &inst->fmts[INPUT_META_PORT];
  2393. f->type = INPUT_META_PLANE;
  2394. f->fmt.meta.dataformat =
  2395. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);;
  2396. f->fmt.meta.buffersize = MSM_VIDC_METADATA_SIZE;
  2397. inst->buffers.input_meta.min_count = 0;
  2398. inst->buffers.input_meta.extra_count = 0;
  2399. inst->buffers.input_meta.actual_count = 0;
  2400. inst->buffers.input_meta.size = 0;
  2401. f = &inst->fmts[OUTPUT_PORT];
  2402. f->type = OUTPUT_MPLANE;
  2403. f->fmt.pix_mp.pixelformat =
  2404. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_NV12C, __func__);
  2405. colorformat = v4l2_colorformat_to_driver(inst,
  2406. f->fmt.pix_mp.pixelformat, __func__);
  2407. f->fmt.pix_mp.width = video_y_stride_pix(colorformat, DEFAULT_WIDTH);
  2408. f->fmt.pix_mp.height = video_y_scanlines(colorformat, DEFAULT_HEIGHT);
  2409. f->fmt.pix_mp.num_planes = 1;
  2410. f->fmt.pix_mp.plane_fmt[0].bytesperline =
  2411. video_y_stride_bytes(colorformat, DEFAULT_WIDTH);
  2412. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2413. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  2414. f->fmt.pix_mp.field = V4L2_FIELD_NONE;
  2415. f->fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
  2416. f->fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
  2417. f->fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
  2418. f->fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
  2419. inst->buffers.output.min_count = call_session_op(core,
  2420. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  2421. inst->buffers.output.extra_count = call_session_op(core,
  2422. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  2423. inst->buffers.output.actual_count =
  2424. inst->buffers.output.min_count +
  2425. inst->buffers.output.extra_count;
  2426. inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  2427. inst->max_map_output_count = MAX_MAP_OUTPUT_COUNT;
  2428. inst->fw_min_count = 0;
  2429. f = &inst->fmts[OUTPUT_META_PORT];
  2430. f->type = OUTPUT_META_PLANE;
  2431. f->fmt.meta.dataformat =
  2432. v4l2_colorformat_from_driver(inst, MSM_VIDC_FMT_META, __func__);
  2433. f->fmt.meta.buffersize = MSM_VIDC_METADATA_SIZE;
  2434. inst->buffers.output_meta.min_count = 0;
  2435. inst->buffers.output_meta.extra_count = 0;
  2436. inst->buffers.output_meta.actual_count = 0;
  2437. inst->buffers.output_meta.size = 0;
  2438. inst->input_dpb_list_enabled = false;
  2439. inst->output_dpb_list_enabled = false;
  2440. rc = msm_vdec_codec_change(inst,
  2441. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat);
  2442. if (rc)
  2443. return rc;
  2444. return rc;
  2445. }
  2446. int msm_vdec_inst_deinit(struct msm_vidc_inst *inst)
  2447. {
  2448. int rc = 0;
  2449. if (!inst) {
  2450. d_vpr_e("%s: invalid params\n", __func__);
  2451. return -EINVAL;
  2452. }
  2453. /* cancel pending batch work */
  2454. cancel_batch_work(inst);
  2455. rc = msm_vidc_ctrl_handler_deinit(inst);
  2456. if (rc)
  2457. return rc;
  2458. return rc;
  2459. }