msm_vdec.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <media/v4l2_vidc_extensions.h>
  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_platform.h"
  14. #include "msm_vidc_control.h"
  15. #include "msm_vidc_debug.h"
  16. #include "msm_vidc_control.h"
  17. #include "venus_hfi.h"
  18. #include "hfi_packet.h"
  19. u32 msm_vdec_subscribe_for_psc_avc[] = {
  20. HFI_PROP_BITSTREAM_RESOLUTION,
  21. HFI_PROP_CROP_OFFSETS,
  22. HFI_PROP_CODED_FRAMES,
  23. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  24. HFI_PROP_PIC_ORDER_CNT_TYPE,
  25. HFI_PROP_PROFILE,
  26. HFI_PROP_LEVEL,
  27. HFI_PROP_SIGNAL_COLOR_INFO,
  28. };
  29. u32 msm_vdec_subscribe_for_psc_hevc[] = {
  30. HFI_PROP_BITSTREAM_RESOLUTION,
  31. HFI_PROP_CROP_OFFSETS,
  32. HFI_PROP_LUMA_CHROMA_BIT_DEPTH,
  33. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  34. HFI_PROP_PROFILE,
  35. HFI_PROP_LEVEL,
  36. HFI_PROP_TIER,
  37. HFI_PROP_SIGNAL_COLOR_INFO,
  38. };
  39. u32 msm_vdec_subscribe_for_psc_vp9[] = {
  40. HFI_PROP_BITSTREAM_RESOLUTION,
  41. HFI_PROP_CROP_OFFSETS,
  42. HFI_PROP_LUMA_CHROMA_BIT_DEPTH,
  43. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  44. HFI_PROP_PROFILE,
  45. HFI_PROP_LEVEL,
  46. };
  47. u32 msm_vdec_subscribe_for_properties[] = {
  48. HFI_PROP_NO_OUTPUT,
  49. HFI_PROP_CABAC_SESSION,
  50. };
  51. static int msm_vdec_codec_change(struct msm_vidc_inst *inst, u32 v4l2_codec)
  52. {
  53. int rc = 0;
  54. if (inst->codec && inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat == v4l2_codec)
  55. return 0;
  56. i_vpr_h(inst, "%s: codec changed from %#x to %#x\n",
  57. __func__, inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat, v4l2_codec);
  58. inst->codec = v4l2_codec_to_driver(v4l2_codec, __func__);
  59. rc = msm_vidc_update_debug_str(inst);
  60. if (rc)
  61. goto exit;
  62. rc = msm_vidc_get_inst_capability(inst);
  63. if (rc)
  64. goto exit;
  65. rc = msm_vidc_ctrl_deinit(inst);
  66. if (rc)
  67. goto exit;
  68. rc = msm_vidc_ctrl_init(inst);
  69. if(rc)
  70. goto exit;
  71. exit:
  72. return rc;
  73. }
  74. static int msm_vdec_set_bitstream_resolution(struct msm_vidc_inst *inst,
  75. enum msm_vidc_port_type port)
  76. {
  77. int rc = 0;
  78. u32 resolution;
  79. resolution = inst->fmts[INPUT_PORT].fmt.pix_mp.width << 16 |
  80. inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  81. i_vpr_h(inst, "%s: width: %d height: %d\n", __func__,
  82. inst->fmts[INPUT_PORT].fmt.pix_mp.width,
  83. inst->fmts[INPUT_PORT].fmt.pix_mp.height);
  84. inst->subcr_params[port].bitstream_resolution = resolution;
  85. rc = venus_hfi_session_property(inst,
  86. HFI_PROP_BITSTREAM_RESOLUTION,
  87. HFI_HOST_FLAGS_NONE,
  88. get_hfi_port(inst, port),
  89. HFI_PAYLOAD_U32,
  90. &resolution,
  91. sizeof(u32));
  92. if (rc)
  93. i_vpr_e(inst, "%s: set property failed\n", __func__);
  94. return rc;
  95. }
  96. static int msm_vdec_set_linear_stride_scanline(struct msm_vidc_inst *inst)
  97. {
  98. int rc = 0;
  99. u32 stride_y, scanline_y, stride_uv, scanline_uv;
  100. u32 payload[2];
  101. if (inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat !=
  102. V4L2_PIX_FMT_NV12 &&
  103. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat !=
  104. V4L2_PIX_FMT_VIDC_P010)
  105. return 0;
  106. stride_y = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width;
  107. scanline_y = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height;
  108. stride_uv = stride_y;
  109. scanline_uv = scanline_y / 2;
  110. payload[0] = stride_y << 16 | scanline_y;
  111. payload[1] = stride_uv << 16 | scanline_uv;
  112. i_vpr_h(inst, "%s: stride_y: %d scanline_y: %d "
  113. "stride_uv: %d, scanline_uv: %d", __func__,
  114. stride_y, scanline_y, stride_uv, scanline_uv);
  115. rc = venus_hfi_session_property(inst,
  116. HFI_PROP_LINEAR_STRIDE_SCANLINE,
  117. HFI_HOST_FLAGS_NONE,
  118. get_hfi_port(inst, OUTPUT_PORT),
  119. HFI_PAYLOAD_U64,
  120. &payload,
  121. sizeof(u64));
  122. if (rc)
  123. i_vpr_e(inst, "%s: set property failed\n", __func__);
  124. return rc;
  125. }
  126. static int msm_vdec_set_crop_offsets(struct msm_vidc_inst *inst,
  127. enum msm_vidc_port_type port)
  128. {
  129. int rc = 0;
  130. u32 left_offset, top_offset, right_offset, bottom_offset;
  131. u32 payload[2] = {0};
  132. if (inst->fmts[INPUT_PORT].fmt.pix_mp.width <
  133. inst->crop.width)
  134. return -EINVAL;
  135. if (inst->fmts[INPUT_PORT].fmt.pix_mp.height <
  136. inst->crop.height)
  137. return -EINVAL;
  138. left_offset = inst->crop.left;
  139. top_offset = inst->crop.top;
  140. right_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  141. inst->crop.width);
  142. bottom_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  143. inst->crop.height);
  144. payload[0] = left_offset << 16 | top_offset;
  145. payload[1] = right_offset << 16 | bottom_offset;
  146. i_vpr_h(inst, "%s: left_offset: %d top_offset: %d "
  147. "right_offset: %d bottom_offset: %d", __func__,
  148. left_offset, top_offset, right_offset, bottom_offset);
  149. inst->subcr_params[port].crop_offsets[0] = payload[0];
  150. inst->subcr_params[port].crop_offsets[1] = payload[1];
  151. rc = venus_hfi_session_property(inst,
  152. HFI_PROP_CROP_OFFSETS,
  153. HFI_HOST_FLAGS_NONE,
  154. get_hfi_port(inst, port),
  155. HFI_PAYLOAD_64_PACKED,
  156. &payload,
  157. sizeof(u64));
  158. if (rc)
  159. i_vpr_e(inst, "%s: set property failed\n", __func__);
  160. return rc;
  161. }
  162. static int msm_vdec_set_bit_depth(struct msm_vidc_inst *inst,
  163. enum msm_vidc_port_type port)
  164. {
  165. int rc = 0;
  166. u32 colorformat;
  167. u32 bitdepth = 8 << 16 | 8;
  168. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  169. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  170. return -EINVAL;
  171. }
  172. colorformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  173. if (colorformat == V4L2_PIX_FMT_VIDC_P010 ||
  174. colorformat == V4L2_PIX_FMT_VIDC_TP10C)
  175. bitdepth = 10 << 16 | 10;
  176. inst->subcr_params[port].bit_depth = bitdepth;
  177. inst->capabilities->cap[BIT_DEPTH].value = bitdepth;
  178. i_vpr_h(inst, "%s: bit depth: %d", __func__, bitdepth);
  179. rc = venus_hfi_session_property(inst,
  180. HFI_PROP_LUMA_CHROMA_BIT_DEPTH,
  181. HFI_HOST_FLAGS_NONE,
  182. get_hfi_port(inst, port),
  183. HFI_PAYLOAD_U32,
  184. &bitdepth,
  185. sizeof(u32));
  186. if (rc)
  187. i_vpr_e(inst, "%s: set property failed\n", __func__);
  188. return rc;
  189. }
  190. //todo: enable when needed
  191. /*
  192. static int msm_vdec_set_cabac(struct msm_vidc_inst *inst,
  193. enum msm_vidc_port_type port)
  194. {
  195. int rc = 0;
  196. u32 cabac = 0;
  197. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  198. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  199. return -EINVAL;
  200. }
  201. cabac = inst->capabilities->cap[ENTROPY_MODE].value;
  202. inst->subcr_params[port].cabac = cabac;
  203. i_vpr_h(inst, "%s: entropy mode: %d", __func__, cabac);
  204. rc = venus_hfi_session_property(inst,
  205. HFI_PROP_CABAC_SESSION,
  206. HFI_HOST_FLAGS_NONE,
  207. get_hfi_port(inst, port),
  208. HFI_PAYLOAD_U32,
  209. &cabac,
  210. sizeof(u32));
  211. if (rc)
  212. i_vpr_e(inst, "%s: set property failed\n", __func__);
  213. return rc;
  214. }
  215. */
  216. static int msm_vdec_set_coded_frames(struct msm_vidc_inst *inst,
  217. enum msm_vidc_port_type port)
  218. {
  219. int rc = 0;
  220. u32 coded_frames = 0;
  221. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  222. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  223. return -EINVAL;
  224. }
  225. if (inst->capabilities->cap[CODED_FRAMES].value ==
  226. CODED_FRAMES_PROGRESSIVE)
  227. coded_frames = HFI_BITMASK_FRAME_MBS_ONLY_FLAG;
  228. inst->subcr_params[port].coded_frames = coded_frames;
  229. i_vpr_h(inst, "%s: coded frames: %d", __func__, coded_frames);
  230. rc = venus_hfi_session_property(inst,
  231. HFI_PROP_CODED_FRAMES,
  232. HFI_HOST_FLAGS_NONE,
  233. get_hfi_port(inst, port),
  234. HFI_PAYLOAD_U32,
  235. &coded_frames,
  236. sizeof(u32));
  237. if (rc)
  238. i_vpr_e(inst, "%s: set property failed\n", __func__);
  239. return rc;
  240. }
  241. static int msm_vdec_set_min_output_count(struct msm_vidc_inst *inst,
  242. enum msm_vidc_port_type port)
  243. {
  244. int rc = 0;
  245. u32 min_output;
  246. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  247. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  248. return -EINVAL;
  249. }
  250. min_output = inst->buffers.output.min_count;
  251. inst->subcr_params[port].fw_min_count = min_output;
  252. i_vpr_h(inst, "%s: firmware min output count: %d",
  253. __func__, min_output);
  254. rc = venus_hfi_session_property(inst,
  255. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  256. HFI_HOST_FLAGS_NONE,
  257. get_hfi_port(inst, port),
  258. HFI_PAYLOAD_U32,
  259. &min_output,
  260. sizeof(u32));
  261. if (rc)
  262. i_vpr_e(inst, "%s: set property failed\n", __func__);
  263. return rc;
  264. }
  265. static int msm_vdec_set_picture_order_count(struct msm_vidc_inst *inst,
  266. enum msm_vidc_port_type port)
  267. {
  268. int rc = 0;
  269. u32 poc = 0;
  270. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  271. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  272. return -EINVAL;
  273. }
  274. inst->subcr_params[port].pic_order_cnt = poc;
  275. i_vpr_h(inst, "%s: picture order count: %d", __func__, poc);
  276. rc = venus_hfi_session_property(inst,
  277. HFI_PROP_PIC_ORDER_CNT_TYPE,
  278. HFI_HOST_FLAGS_NONE,
  279. get_hfi_port(inst, port),
  280. HFI_PAYLOAD_U32,
  281. &poc,
  282. sizeof(u32));
  283. if (rc)
  284. i_vpr_e(inst, "%s: set property failed\n", __func__);
  285. return rc;
  286. }
  287. static int msm_vdec_set_colorspace(struct msm_vidc_inst *inst,
  288. enum msm_vidc_port_type port)
  289. {
  290. int rc = 0;
  291. u32 primaries = MSM_VIDC_PRIMARIES_RESERVED;
  292. u32 matrix_coeff = MSM_VIDC_MATRIX_COEFF_RESERVED;
  293. u32 transfer_char = MSM_VIDC_TRANSFER_RESERVED;
  294. u32 full_range = V4L2_QUANTIZATION_DEFAULT;
  295. u32 colour_description_present_flag = 0;
  296. u32 video_signal_type_present_flag = 0, color_info = 0;
  297. /* Unspecified video format */
  298. u32 video_format = 5;
  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. if (inst->codec != MSM_VIDC_H264 && inst->codec != MSM_VIDC_HEVC)
  304. return 0;
  305. if (inst->fmts[port].fmt.pix_mp.colorspace != V4L2_COLORSPACE_DEFAULT ||
  306. inst->fmts[port].fmt.pix_mp.ycbcr_enc != V4L2_XFER_FUNC_DEFAULT ||
  307. inst->fmts[port].fmt.pix_mp.xfer_func != V4L2_YCBCR_ENC_DEFAULT) {
  308. colour_description_present_flag = 1;
  309. video_signal_type_present_flag = 1;
  310. primaries = v4l2_color_primaries_to_driver(inst,
  311. inst->fmts[port].fmt.pix_mp.colorspace);
  312. matrix_coeff = v4l2_matrix_coeff_to_driver(inst,
  313. inst->fmts[port].fmt.pix_mp.ycbcr_enc);
  314. transfer_char = v4l2_transfer_char_to_driver(inst,
  315. inst->fmts[port].fmt.pix_mp.xfer_func);
  316. }
  317. if (inst->fmts[port].fmt.pix_mp.quantization !=
  318. V4L2_QUANTIZATION_DEFAULT) {
  319. video_signal_type_present_flag = 1;
  320. full_range = inst->fmts[port].fmt.pix_mp.quantization ==
  321. V4L2_QUANTIZATION_FULL_RANGE ? 1 : 0;
  322. }
  323. color_info = (matrix_coeff & 0xFF) |
  324. ((transfer_char << 8) & 0xFF00) |
  325. ((primaries << 16) & 0xFF0000) |
  326. ((colour_description_present_flag << 24) & 0x1000000) |
  327. ((full_range << 25) & 0x2000000) |
  328. ((video_format << 26) & 0x1C000000) |
  329. ((video_signal_type_present_flag << 29) & 0x20000000);
  330. inst->subcr_params[port].color_info = color_info;
  331. i_vpr_h(inst, "%s: color info: %#x\n", __func__, color_info);
  332. rc = venus_hfi_session_property(inst,
  333. HFI_PROP_SIGNAL_COLOR_INFO,
  334. HFI_HOST_FLAGS_NONE,
  335. get_hfi_port(inst, port),
  336. HFI_PAYLOAD_32_PACKED,
  337. &color_info,
  338. sizeof(u32));
  339. if (rc)
  340. i_vpr_e(inst, "%s: set property failed\n", __func__);
  341. return rc;
  342. }
  343. static int msm_vdec_set_profile(struct msm_vidc_inst *inst,
  344. enum msm_vidc_port_type port)
  345. {
  346. int rc = 0;
  347. u32 profile;
  348. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  349. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  350. return -EINVAL;
  351. }
  352. profile = inst->capabilities->cap[PROFILE].value;
  353. inst->subcr_params[port].profile = profile;
  354. i_vpr_h(inst, "%s: profile: %d", __func__, profile);
  355. rc = venus_hfi_session_property(inst,
  356. HFI_PROP_PROFILE,
  357. HFI_HOST_FLAGS_NONE,
  358. get_hfi_port(inst, port),
  359. HFI_PAYLOAD_U32_ENUM,
  360. &profile,
  361. sizeof(u32));
  362. if (rc)
  363. i_vpr_e(inst, "%s: set property failed\n", __func__);
  364. return rc;
  365. }
  366. static int msm_vdec_set_level(struct msm_vidc_inst *inst,
  367. enum msm_vidc_port_type port)
  368. {
  369. int rc = 0;
  370. u32 level;
  371. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  372. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  373. return -EINVAL;
  374. }
  375. level = inst->capabilities->cap[LEVEL].value;
  376. inst->subcr_params[port].level = level;
  377. i_vpr_h(inst, "%s: level: %d", __func__, level);
  378. rc = venus_hfi_session_property(inst,
  379. HFI_PROP_LEVEL,
  380. HFI_HOST_FLAGS_NONE,
  381. get_hfi_port(inst, port),
  382. HFI_PAYLOAD_U32_ENUM,
  383. &level,
  384. sizeof(u32));
  385. if (rc)
  386. i_vpr_e(inst, "%s: set property failed\n", __func__);
  387. return rc;
  388. }
  389. static int msm_vdec_set_tier(struct msm_vidc_inst *inst,
  390. enum msm_vidc_port_type port)
  391. {
  392. int rc = 0;
  393. u32 tier;
  394. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  395. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  396. return -EINVAL;
  397. }
  398. tier = inst->capabilities->cap[HEVC_TIER].value;
  399. inst->subcr_params[port].tier = tier;
  400. i_vpr_h(inst, "%s: tier: %d", __func__, tier);
  401. rc = venus_hfi_session_property(inst,
  402. HFI_PROP_TIER,
  403. HFI_HOST_FLAGS_NONE,
  404. get_hfi_port(inst, port),
  405. HFI_PAYLOAD_U32_ENUM,
  406. &tier,
  407. sizeof(u32));
  408. if (rc)
  409. i_vpr_e(inst, "%s: set property failed\n", __func__);
  410. return rc;
  411. }
  412. static int msm_vdec_set_colorformat(struct msm_vidc_inst *inst)
  413. {
  414. int rc = 0;
  415. u32 pixelformat;
  416. enum msm_vidc_colorformat_type colorformat;
  417. u32 hfi_colorformat;
  418. pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  419. colorformat = v4l2_colorformat_to_driver(pixelformat, __func__);
  420. hfi_colorformat = get_hfi_colorformat(inst, colorformat);
  421. i_vpr_h(inst, "%s: hfi colorformat: %d",
  422. __func__, hfi_colorformat);
  423. rc = venus_hfi_session_property(inst,
  424. HFI_PROP_COLOR_FORMAT,
  425. HFI_HOST_FLAGS_NONE,
  426. get_hfi_port(inst, OUTPUT_PORT),
  427. HFI_PAYLOAD_U32,
  428. &hfi_colorformat,
  429. sizeof(u32));
  430. if (rc)
  431. i_vpr_e(inst, "%s: set property failed\n", __func__);
  432. return rc;
  433. }
  434. static int msm_vdec_set_stage(struct msm_vidc_inst *inst)
  435. {
  436. int rc = 0;
  437. u32 stage = 0;
  438. struct msm_vidc_core *core = inst->core;
  439. struct msm_vidc_inst_capability *capability = inst->capabilities;
  440. rc = call_session_op(core, decide_work_mode, inst);
  441. if (rc) {
  442. i_vpr_e(inst, "%s: decide_work_mode failed %d\n",
  443. __func__);
  444. return -EINVAL;
  445. }
  446. stage = capability->cap[STAGE].value;
  447. i_vpr_h(inst, "%s: stage: %d", __func__, stage);
  448. rc = venus_hfi_session_property(inst,
  449. HFI_PROP_STAGE,
  450. HFI_HOST_FLAGS_NONE,
  451. HFI_PORT_NONE,
  452. HFI_PAYLOAD_U32,
  453. &stage,
  454. sizeof(u32));
  455. if (rc)
  456. i_vpr_e(inst, "%s: set property failed\n", __func__);
  457. return rc;
  458. }
  459. static int msm_vdec_set_pipe(struct msm_vidc_inst *inst)
  460. {
  461. int rc = 0;
  462. u32 pipe;
  463. struct msm_vidc_core *core = inst->core;
  464. struct msm_vidc_inst_capability *capability = inst->capabilities;
  465. rc = call_session_op(core, decide_work_route, inst);
  466. if (rc) {
  467. i_vpr_e(inst, "%s: decide_work_route failed\n",
  468. __func__);
  469. return -EINVAL;
  470. }
  471. pipe = capability->cap[PIPE].value;
  472. i_vpr_h(inst, "%s: pipe: %d", __func__, pipe);
  473. rc = venus_hfi_session_property(inst,
  474. HFI_PROP_PIPE,
  475. HFI_HOST_FLAGS_NONE,
  476. HFI_PORT_NONE,
  477. HFI_PAYLOAD_U32,
  478. &pipe,
  479. sizeof(u32));
  480. if (rc)
  481. i_vpr_e(inst, "%s: set property failed\n", __func__);
  482. return rc;
  483. }
  484. static int msm_vdec_set_output_order(struct msm_vidc_inst *inst,
  485. enum msm_vidc_port_type port)
  486. {
  487. int rc = 0;
  488. u32 output_order;
  489. if (port != INPUT_PORT) {
  490. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  491. return -EINVAL;
  492. }
  493. output_order = inst->capabilities->cap[DISPLAY_DELAY_ENABLE].value;
  494. i_vpr_h(inst, "%s: output order: %d", __func__, output_order);
  495. rc = venus_hfi_session_property(inst,
  496. HFI_PROP_DECODE_ORDER_OUTPUT,
  497. HFI_HOST_FLAGS_NONE,
  498. get_hfi_port(inst, port),
  499. HFI_PAYLOAD_U32,
  500. &output_order,
  501. sizeof(u32));
  502. if (rc)
  503. i_vpr_e(inst, "%s: set property failed\n", __func__);
  504. return rc;
  505. }
  506. static int msm_vdec_set_secure_mode(struct msm_vidc_inst *inst,
  507. enum msm_vidc_port_type port)
  508. {
  509. int rc = 0;
  510. u32 secure_mode;
  511. secure_mode = inst->capabilities->cap[SECURE_MODE].value;
  512. i_vpr_h(inst, "%s: secure mode: %d", __func__, secure_mode);
  513. rc = venus_hfi_session_property(inst,
  514. HFI_PROP_SECURE,
  515. HFI_HOST_FLAGS_NONE,
  516. HFI_PORT_NONE,
  517. HFI_PAYLOAD_U32,
  518. &secure_mode,
  519. sizeof(u32));
  520. if (rc)
  521. i_vpr_e(inst, "%s: set property failed\n", __func__);
  522. return rc;
  523. }
  524. static int msm_vdec_set_rap_frame(struct msm_vidc_inst *inst,
  525. enum msm_vidc_port_type port)
  526. {
  527. int rc = 0;
  528. u32 rap_frame = true;
  529. if (port != INPUT_PORT) {
  530. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  531. return -EINVAL;
  532. }
  533. rap_frame = inst->capabilities->cap[RAP_FRAME].value;
  534. i_vpr_h(inst, "%s: start from rap frame: %d", __func__, rap_frame);
  535. rc = venus_hfi_session_property(inst,
  536. HFI_PROP_DEC_START_FROM_RAP_FRAME,
  537. HFI_HOST_FLAGS_NONE,
  538. get_hfi_port(inst, port),
  539. HFI_PAYLOAD_U32,
  540. &rap_frame,
  541. sizeof(u32));
  542. if (rc)
  543. i_vpr_e(inst, "%s: set property failed\n", __func__);
  544. return rc;
  545. }
  546. static int msm_vdec_set_thumbnail_mode(struct msm_vidc_inst *inst,
  547. enum msm_vidc_port_type port)
  548. {
  549. int rc = 0;
  550. u32 thumbnail_mode = 0;
  551. if (port != INPUT_PORT) {
  552. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  553. return -EINVAL;
  554. }
  555. thumbnail_mode = inst->capabilities->cap[THUMBNAIL_MODE].value;
  556. i_vpr_h(inst, "%s: thumbnail mode: %d", __func__, thumbnail_mode);
  557. rc = venus_hfi_session_property(inst,
  558. HFI_PROP_THUMBNAIL_MODE,
  559. HFI_HOST_FLAGS_NONE,
  560. get_hfi_port(inst, port),
  561. HFI_PAYLOAD_U32,
  562. &thumbnail_mode,
  563. sizeof(u32));
  564. if (rc)
  565. i_vpr_e(inst, "%s: set property failed\n", __func__);
  566. return rc;
  567. }
  568. static int msm_vdec_set_realtime(struct msm_vidc_inst *inst,
  569. enum msm_vidc_port_type port)
  570. {
  571. int rc = 0;
  572. u32 realtime = 1; //todo
  573. if (port != INPUT_PORT) {
  574. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  575. return -EINVAL;
  576. }
  577. realtime = inst->capabilities->cap[PRIORITY].value;
  578. i_vpr_h(inst, "%s: priority: %d", __func__, realtime);
  579. rc = venus_hfi_session_property(inst,
  580. HFI_PROP_REALTIME,
  581. HFI_HOST_FLAGS_NONE,
  582. get_hfi_port(inst, port),
  583. HFI_PAYLOAD_U32,
  584. &realtime,
  585. sizeof(u32));
  586. if (rc)
  587. i_vpr_e(inst, "%s: set property failed\n", __func__);
  588. return rc;
  589. }
  590. static int msm_vdec_set_conceal_color_8bit(struct msm_vidc_inst *inst,
  591. enum msm_vidc_port_type port)
  592. {
  593. int rc = 0;
  594. u32 conceal_color_8bit;
  595. if (port != INPUT_PORT) {
  596. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  597. return -EINVAL;
  598. }
  599. conceal_color_8bit = inst->capabilities->cap[CONCEAL_COLOR_8BIT].value;
  600. i_vpr_h(inst, "%s: conceal color 8bit: %#x",
  601. __func__, conceal_color_8bit);
  602. rc = venus_hfi_session_property(inst,
  603. HFI_PROP_CONCEAL_COLOR_8BIT,
  604. HFI_HOST_FLAGS_NONE,
  605. get_hfi_port(inst, port),
  606. HFI_PAYLOAD_32_PACKED,
  607. &conceal_color_8bit,
  608. sizeof(u32));
  609. if (rc)
  610. i_vpr_e(inst, "%s: set property failed\n", __func__);
  611. return rc;
  612. }
  613. static int msm_vdec_set_conceal_color_10bit(struct msm_vidc_inst *inst,
  614. enum msm_vidc_port_type port)
  615. {
  616. int rc = 0;
  617. u32 conceal_color_10bit;
  618. if (port != INPUT_PORT) {
  619. i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
  620. return -EINVAL;
  621. }
  622. conceal_color_10bit = inst->capabilities->cap[CONCEAL_COLOR_8BIT].value;
  623. i_vpr_h(inst, "%s: conceal color 10bit: %#x",
  624. __func__, conceal_color_10bit);
  625. rc = venus_hfi_session_property(inst,
  626. HFI_PROP_CONCEAL_COLOR_10BIT,
  627. HFI_HOST_FLAGS_NONE,
  628. get_hfi_port(inst, port),
  629. HFI_PAYLOAD_32_PACKED,
  630. &conceal_color_10bit,
  631. sizeof(u32));
  632. if (rc)
  633. i_vpr_e(inst, "%s: set property failed\n", __func__);
  634. return rc;
  635. }
  636. static int msm_vdec_set_input_properties(struct msm_vidc_inst *inst)
  637. {
  638. int rc = 0;
  639. if (!inst) {
  640. d_vpr_e("%s: invalid params\n", __func__);
  641. return -EINVAL;
  642. }
  643. rc = msm_vdec_set_output_order(inst, INPUT_PORT);
  644. if (rc)
  645. return rc;
  646. rc = msm_vdec_set_secure_mode(inst, INPUT_PORT);
  647. if (rc)
  648. return rc;
  649. rc = msm_vdec_set_thumbnail_mode(inst, INPUT_PORT);
  650. if (rc)
  651. return rc;
  652. rc = msm_vdec_set_rap_frame(inst, INPUT_PORT);
  653. if (rc)
  654. return rc;
  655. rc = msm_vdec_set_realtime(inst, INPUT_PORT);
  656. if (rc)
  657. return rc;
  658. rc = msm_vdec_set_conceal_color_8bit(inst, INPUT_PORT);
  659. if (rc)
  660. return rc;
  661. rc = msm_vdec_set_conceal_color_10bit(inst, INPUT_PORT);
  662. if (rc)
  663. return rc;
  664. return rc;
  665. }
  666. static int msm_vdec_set_output_properties(struct msm_vidc_inst *inst)
  667. {
  668. int rc = 0;
  669. if (!inst) {
  670. d_vpr_e("%s: invalid params\n", __func__);
  671. return -EINVAL;
  672. }
  673. rc = msm_vdec_set_colorformat(inst);
  674. if (rc)
  675. return rc;
  676. rc = msm_vdec_set_stage(inst);
  677. if (rc)
  678. return rc;
  679. rc = msm_vdec_set_pipe(inst);
  680. if (rc)
  681. return rc;
  682. rc = msm_vdec_set_linear_stride_scanline(inst);
  683. if (rc)
  684. return rc;
  685. return rc;
  686. }
  687. static int msm_vdec_get_input_internal_buffers(struct msm_vidc_inst *inst)
  688. {
  689. int rc = 0;
  690. if (!inst) {
  691. d_vpr_e("%s: invalid params\n", __func__);
  692. return -EINVAL;
  693. }
  694. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  695. if (rc)
  696. return rc;
  697. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  698. if (rc)
  699. return rc;
  700. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  701. if (rc)
  702. return rc;
  703. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  704. if (rc)
  705. return rc;
  706. i_vpr_h(inst, "input internal buffer: min size reuse\n");
  707. i_vpr_h(inst, "bin buffer: %d %d %d\n",
  708. inst->buffers.bin.min_count,
  709. inst->buffers.bin.size,
  710. inst->buffers.bin.reuse);
  711. i_vpr_h(inst, "comv buffer: %d %d %d\n",
  712. inst->buffers.comv.min_count,
  713. inst->buffers.comv.size,
  714. inst->buffers.comv.reuse);
  715. i_vpr_h(inst, "non_comv buffer: %d %d %d\n",
  716. inst->buffers.non_comv.min_count,
  717. inst->buffers.non_comv.size,
  718. inst->buffers.non_comv.reuse);
  719. i_vpr_h(inst, "line buffer: %d %d %d\n",
  720. inst->buffers.line.min_count,
  721. inst->buffers.line.size,
  722. inst->buffers.line.reuse);
  723. return rc;
  724. }
  725. static int msm_vdec_get_output_internal_buffers(struct msm_vidc_inst *inst)
  726. {
  727. int rc = 0;
  728. if (!inst) {
  729. d_vpr_e("%s: invalid params\n", __func__);
  730. return -EINVAL;
  731. }
  732. rc = msm_vidc_get_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  733. if (rc)
  734. return rc;
  735. i_vpr_h(inst, "output internal buffer: min size reuse\n");
  736. i_vpr_h(inst, "dpb buffer: %d %d %d\n",
  737. inst->buffers.dpb.min_count,
  738. inst->buffers.dpb.size,
  739. inst->buffers.dpb.reuse);
  740. return rc;
  741. }
  742. static int msm_vdec_create_input_internal_buffers(struct msm_vidc_inst *inst)
  743. {
  744. int rc = 0;
  745. if (!inst || !inst->core) {
  746. d_vpr_e("%s: invalid params\n", __func__);
  747. return -EINVAL;
  748. }
  749. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  750. if (rc)
  751. return rc;
  752. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  753. if (rc)
  754. return rc;
  755. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  756. if (rc)
  757. return rc;
  758. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  759. if (rc)
  760. return rc;
  761. return 0;
  762. }
  763. static int msm_vdec_create_output_internal_buffers(struct msm_vidc_inst *inst)
  764. {
  765. int rc = 0;
  766. if (!inst || !inst->core) {
  767. d_vpr_e("%s: invalid params\n", __func__);
  768. return -EINVAL;
  769. }
  770. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  771. if (rc)
  772. return rc;
  773. return 0;
  774. }
  775. static int msm_vdec_queue_input_internal_buffers(struct msm_vidc_inst *inst)
  776. {
  777. int rc = 0;
  778. if (!inst || !inst->core) {
  779. d_vpr_e("%s: invalid params\n", __func__);
  780. return -EINVAL;
  781. }
  782. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  783. if (rc)
  784. return rc;
  785. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  786. if (rc)
  787. return rc;
  788. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  789. if (rc)
  790. return rc;
  791. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  792. if (rc)
  793. return rc;
  794. return 0;
  795. }
  796. static int msm_vdec_queue_output_internal_buffers(struct msm_vidc_inst *inst)
  797. {
  798. int rc = 0;
  799. if (!inst || !inst->core) {
  800. d_vpr_e("%s: invalid params\n", __func__);
  801. return -EINVAL;
  802. }
  803. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  804. if (rc)
  805. return rc;
  806. return 0;
  807. }
  808. static int msm_vdec_release_input_internal_buffers(struct msm_vidc_inst *inst)
  809. {
  810. int rc = 0;
  811. if (!inst || !inst->core) {
  812. d_vpr_e("%s: invalid params\n", __func__);
  813. return -EINVAL;
  814. }
  815. i_vpr_h(inst, "%s()\n",__func__);
  816. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  817. if (rc)
  818. return rc;
  819. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  820. if (rc)
  821. return rc;
  822. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  823. if (rc)
  824. return rc;
  825. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  826. if (rc)
  827. return rc;
  828. return 0;
  829. }
  830. static int msm_vdec_release_output_internal_buffers(struct msm_vidc_inst *inst)
  831. {
  832. int rc = 0;
  833. if (!inst || !inst->core) {
  834. d_vpr_e("%s: invalid params\n", __func__);
  835. return -EINVAL;
  836. }
  837. i_vpr_h(inst, "%s()\n",__func__);
  838. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  839. if (rc)
  840. return rc;
  841. return 0;
  842. }
  843. static int msm_vdec_subscribe_input_port_settings_change(struct msm_vidc_inst *inst,
  844. enum msm_vidc_port_type port)
  845. {
  846. int rc = 0;
  847. struct msm_vidc_core *core;
  848. u32 payload[32] = {0};
  849. u32 i;
  850. u32 subscribe_psc_size = 0;
  851. u32 *psc = NULL;
  852. if (!inst || !inst->core) {
  853. d_vpr_e("%s: invalid params\n", __func__);
  854. return -EINVAL;
  855. }
  856. core = inst->core;
  857. i_vpr_h(inst, "%s()\n", __func__);
  858. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  859. if (inst->codec == MSM_VIDC_H264) {
  860. subscribe_psc_size = ARRAY_SIZE(msm_vdec_subscribe_for_psc_avc);
  861. psc = msm_vdec_subscribe_for_psc_avc;
  862. } else if (inst->codec == MSM_VIDC_HEVC) {
  863. subscribe_psc_size = ARRAY_SIZE(msm_vdec_subscribe_for_psc_hevc);
  864. psc = msm_vdec_subscribe_for_psc_hevc;
  865. } else if (inst->codec == MSM_VIDC_VP9) {
  866. subscribe_psc_size = ARRAY_SIZE(msm_vdec_subscribe_for_psc_vp9);
  867. psc = msm_vdec_subscribe_for_psc_vp9;
  868. } else {
  869. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  870. psc = NULL;
  871. return -EINVAL;
  872. }
  873. if (!psc || !subscribe_psc_size) {
  874. i_vpr_e(inst, "%s: invalid params\n", __func__);
  875. return -EINVAL;
  876. }
  877. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  878. for (i = 0; i < subscribe_psc_size; i++)
  879. payload[i + 1] = psc[i];
  880. rc = venus_hfi_session_command(inst,
  881. HFI_CMD_SUBSCRIBE_MODE,
  882. port,
  883. HFI_PAYLOAD_U32_ARRAY,
  884. &payload[0],
  885. ((subscribe_psc_size + 1) *
  886. sizeof(u32)));
  887. for (i = 0; i < subscribe_psc_size; i++) {
  888. switch (psc[i]) {
  889. case HFI_PROP_BITSTREAM_RESOLUTION:
  890. rc = msm_vdec_set_bitstream_resolution(inst, port);
  891. break;
  892. case HFI_PROP_CROP_OFFSETS:
  893. rc = msm_vdec_set_crop_offsets(inst, port);
  894. break;
  895. case HFI_PROP_LUMA_CHROMA_BIT_DEPTH:
  896. rc = msm_vdec_set_bit_depth(inst, port);
  897. break;
  898. case HFI_PROP_CODED_FRAMES:
  899. rc = msm_vdec_set_coded_frames(inst, port);
  900. break;
  901. case HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT:
  902. rc = msm_vdec_set_min_output_count(inst, port);
  903. break;
  904. case HFI_PROP_PIC_ORDER_CNT_TYPE:
  905. rc = msm_vdec_set_picture_order_count(inst, port);
  906. break;
  907. case HFI_PROP_SIGNAL_COLOR_INFO:
  908. rc = msm_vdec_set_colorspace(inst, port);
  909. break;
  910. case HFI_PROP_PROFILE:
  911. rc = msm_vdec_set_profile(inst, port);
  912. break;
  913. case HFI_PROP_LEVEL:
  914. rc = msm_vdec_set_level(inst, port);
  915. break;
  916. case HFI_PROP_TIER:
  917. rc = msm_vdec_set_tier(inst, port);
  918. break;
  919. default:
  920. i_vpr_e(inst, "%s: unknown property %#x\n", __func__,
  921. psc[i]);
  922. rc = -EINVAL;
  923. break;
  924. }
  925. if (rc)
  926. goto exit;
  927. }
  928. exit:
  929. return rc;
  930. }
  931. static int msm_vdec_subscribe_property(struct msm_vidc_inst *inst,
  932. enum msm_vidc_port_type port)
  933. {
  934. int rc = 0;
  935. struct msm_vidc_core *core;
  936. u32 payload[32] = {0};
  937. u32 i;
  938. if (!inst || !inst->core) {
  939. d_vpr_e("%s: invalid params\n", __func__);
  940. return -EINVAL;
  941. }
  942. core = inst->core;
  943. i_vpr_h(inst, "%s()\n", __func__);
  944. payload[0] = HFI_MODE_PROPERTY;
  945. for (i = 0; i < ARRAY_SIZE(msm_vdec_subscribe_for_properties); i++)
  946. payload[i + 1] = msm_vdec_subscribe_for_properties[i];
  947. rc = venus_hfi_session_command(inst,
  948. HFI_CMD_SUBSCRIBE_MODE,
  949. port,
  950. HFI_PAYLOAD_U32_ARRAY,
  951. &payload[0],
  952. (ARRAY_SIZE(msm_vdec_subscribe_for_properties) + 1) *
  953. sizeof(u32));
  954. return rc;
  955. }
  956. static int msm_vdec_subscribe_metadata(struct msm_vidc_inst *inst,
  957. enum msm_vidc_port_type port)
  958. {
  959. int rc = 0;
  960. struct msm_vidc_core *core;
  961. u32 payload[32] = {0};
  962. u32 i, count = 0;
  963. struct msm_vidc_inst_capability *capability;
  964. u32 metadata_list[] = {
  965. META_DPB_MISR,
  966. META_OPB_MISR,
  967. META_INTERLACE,
  968. META_TIMESTAMP,
  969. META_CONCEALED_MB_CNT,
  970. META_HIST_INFO,
  971. META_SEI_MASTERING_DISP,
  972. META_SEI_CLL,
  973. META_HDR10PLUS,
  974. META_BUF_TAG,
  975. META_SUBFRAME_OUTPUT,
  976. };
  977. if (!inst || !inst->core) {
  978. d_vpr_e("%s: invalid params\n", __func__);
  979. return -EINVAL;
  980. }
  981. core = inst->core;
  982. i_vpr_h(inst, "%s()\n", __func__);
  983. capability = inst->capabilities;
  984. payload[0] = HFI_MODE_METADATA;
  985. for (i = 0; i < ARRAY_SIZE(metadata_list); i++) {
  986. if (capability->cap[metadata_list[i]].value) {
  987. payload[count + 1] =
  988. capability->cap[metadata_list[i]].hfi_id;
  989. count++;
  990. }
  991. };
  992. if (!count)
  993. return 0;
  994. rc = venus_hfi_session_command(inst,
  995. HFI_CMD_SUBSCRIBE_MODE,
  996. port,
  997. HFI_PAYLOAD_U32_ARRAY,
  998. &payload[0],
  999. (count + 1) * sizeof(u32));
  1000. return rc;
  1001. }
  1002. static int msm_vdec_set_delivery_mode_metadata(struct msm_vidc_inst *inst,
  1003. enum msm_vidc_port_type port)
  1004. {
  1005. int rc = 0;
  1006. struct msm_vidc_core *core;
  1007. u32 payload[32] = {0};
  1008. u32 i, count = 0;
  1009. struct msm_vidc_inst_capability *capability;
  1010. u32 metadata_list[] = {
  1011. META_BUF_TAG,
  1012. };
  1013. if (!inst || !inst->core) {
  1014. d_vpr_e("%s: invalid params\n", __func__);
  1015. return -EINVAL;
  1016. }
  1017. core = inst->core;
  1018. i_vpr_h(inst, "%s()\n", __func__);
  1019. capability = inst->capabilities;
  1020. payload[0] = HFI_MODE_METADATA;
  1021. for (i = 0; i < ARRAY_SIZE(metadata_list); i++) {
  1022. if (capability->cap[metadata_list[i]].value) {
  1023. payload[count + 1] =
  1024. capability->cap[metadata_list[i]].hfi_id;
  1025. count++;
  1026. }
  1027. };
  1028. if (!count)
  1029. return 0;
  1030. rc = venus_hfi_session_command(inst,
  1031. HFI_CMD_DELIVERY_MODE,
  1032. port,
  1033. HFI_PAYLOAD_U32_ARRAY,
  1034. &payload[0],
  1035. (count + 1) * sizeof(u32));
  1036. return rc;
  1037. }
  1038. static int msm_vdec_session_resume(struct msm_vidc_inst *inst,
  1039. enum msm_vidc_port_type port)
  1040. {
  1041. int rc = 0;
  1042. if (!inst) {
  1043. d_vpr_e("%s: invalid params\n", __func__);
  1044. return -EINVAL;
  1045. }
  1046. i_vpr_h(inst, "%s()\n", __func__);
  1047. rc = venus_hfi_session_command(inst,
  1048. HFI_CMD_RESUME,
  1049. port,
  1050. HFI_PAYLOAD_NONE,
  1051. NULL,
  1052. 0);
  1053. return rc;
  1054. }
  1055. int msm_vdec_init_input_subcr_params(struct msm_vidc_inst *inst)
  1056. {
  1057. struct msm_vidc_subscription_params *subsc_params;
  1058. struct msm_vidc_core *core;
  1059. u32 left_offset, top_offset, right_offset, bottom_offset;
  1060. u32 primaries, matrix_coeff, transfer_char;
  1061. u32 full_range = 0, video_format = 0;
  1062. u32 colour_description_present_flag = 0;
  1063. u32 video_signal_type_present_flag = 0;
  1064. if (!inst || !inst->core || !inst->capabilities) {
  1065. d_vpr_e("%s: invalid params\n", __func__);
  1066. return -EINVAL;
  1067. }
  1068. core = inst->core;
  1069. subsc_params = &inst->subcr_params[INPUT_PORT];
  1070. subsc_params->bitstream_resolution =
  1071. inst->fmts[INPUT_PORT].fmt.pix_mp.width << 16 |
  1072. inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  1073. left_offset = inst->crop.left;
  1074. top_offset = inst->crop.top;
  1075. right_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  1076. inst->crop.width);
  1077. bottom_offset = (inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  1078. inst->crop.height);
  1079. subsc_params->crop_offsets[0] =
  1080. left_offset << 16 | top_offset;
  1081. subsc_params->crop_offsets[1] =
  1082. right_offset << 16 | bottom_offset;
  1083. subsc_params->fw_min_count = inst->buffers.output.min_count;
  1084. primaries = v4l2_color_primaries_from_driver(inst,
  1085. inst->fmts[INPUT_PORT].fmt.pix_mp.colorspace);
  1086. matrix_coeff = v4l2_matrix_coeff_from_driver(inst,
  1087. inst->fmts[INPUT_PORT].fmt.pix_mp.ycbcr_enc);
  1088. transfer_char = v4l2_transfer_char_from_driver(inst,
  1089. inst->fmts[INPUT_PORT].fmt.pix_mp.xfer_func);
  1090. full_range = inst->fmts[INPUT_PORT].fmt.pix_mp.quantization ==
  1091. V4L2_QUANTIZATION_FULL_RANGE ? 1 : 0;
  1092. subsc_params->color_info =
  1093. (matrix_coeff & 0xFF) |
  1094. ((transfer_char << 8) & 0xFF00) |
  1095. ((primaries << 16) & 0xFF0000) |
  1096. ((colour_description_present_flag << 24) & 0x1000000) |
  1097. ((full_range << 25) & 0x2000000) |
  1098. ((video_format << 26) & 0x1C000000) |
  1099. ((video_signal_type_present_flag << 29) & 0x20000000);
  1100. subsc_params->profile = inst->capabilities->cap[PROFILE].value;
  1101. subsc_params->level = inst->capabilities->cap[LEVEL].value;
  1102. subsc_params->tier = inst->capabilities->cap[HEVC_TIER].value;
  1103. subsc_params->pic_order_cnt = inst->capabilities->cap[POC].value;
  1104. subsc_params->bit_depth = inst->capabilities->cap[BIT_DEPTH].value;
  1105. if (inst->capabilities->cap[CODED_FRAMES].value ==
  1106. CODED_FRAMES_PROGRESSIVE)
  1107. subsc_params->coded_frames = HFI_BITMASK_FRAME_MBS_ONLY_FLAG;
  1108. else
  1109. subsc_params->coded_frames = 0;
  1110. return 0;
  1111. }
  1112. static int msm_vdec_read_input_subcr_params(struct msm_vidc_inst *inst)
  1113. {
  1114. struct msm_vidc_subscription_params subsc_params;
  1115. struct msm_vidc_core *core;
  1116. u32 width, height;
  1117. u32 primaries, matrix_coeff, transfer_char;
  1118. u32 full_range = 0, video_format = 0;
  1119. u32 colour_description_present_flag = 0;
  1120. u32 video_signal_type_present_flag = 0;
  1121. if (!inst || !inst->core) {
  1122. d_vpr_e("%s: invalid params\n", __func__);
  1123. return -EINVAL;
  1124. }
  1125. core = inst->core;
  1126. subsc_params = inst->subcr_params[INPUT_PORT];
  1127. width = (subsc_params.bitstream_resolution &
  1128. HFI_BITMASK_BITSTREAM_WIDTH) >> 16;
  1129. height = subsc_params.bitstream_resolution &
  1130. HFI_BITMASK_BITSTREAM_HEIGHT;
  1131. inst->fmts[INPUT_PORT].fmt.pix_mp.width = width;
  1132. inst->fmts[INPUT_PORT].fmt.pix_mp.height = height;
  1133. inst->fmts[OUTPUT_PORT].fmt.pix_mp.width = VIDEO_Y_STRIDE_PIX(
  1134. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, width);
  1135. inst->fmts[OUTPUT_PORT].fmt.pix_mp.height = VIDEO_Y_SCANLINES(
  1136. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, height);
  1137. inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].bytesperline =
  1138. VIDEO_Y_STRIDE_BYTES(
  1139. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, width);
  1140. inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage =
  1141. call_session_op(core, buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  1142. //inst->buffers.output.size = inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage;
  1143. matrix_coeff = subsc_params.color_info & 0xFF;
  1144. transfer_char = (subsc_params.color_info & 0xFF00) >> 8;
  1145. primaries = (subsc_params.color_info & 0xFF0000) >> 16;
  1146. colour_description_present_flag =
  1147. (subsc_params.color_info & 0x1000000) >> 24;
  1148. full_range = (subsc_params.color_info & 0x2000000) >> 25;
  1149. video_signal_type_present_flag =
  1150. (subsc_params.color_info & 0x20000000) >> 29;
  1151. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
  1152. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
  1153. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
  1154. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
  1155. if (video_signal_type_present_flag) {
  1156. video_format = (subsc_params.color_info & 0x1C000000) >> 26;
  1157. inst->fmts[OUTPUT_PORT].fmt.pix_mp.quantization =
  1158. full_range ?
  1159. V4L2_QUANTIZATION_FULL_RANGE :
  1160. V4L2_QUANTIZATION_LIM_RANGE;
  1161. if (colour_description_present_flag) {
  1162. inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace =
  1163. v4l2_color_primaries_from_driver(inst, primaries);
  1164. inst->fmts[OUTPUT_PORT].fmt.pix_mp.xfer_func =
  1165. v4l2_transfer_char_from_driver(inst, transfer_char);
  1166. inst->fmts[OUTPUT_PORT].fmt.pix_mp.ycbcr_enc =
  1167. v4l2_matrix_coeff_from_driver(inst, matrix_coeff);
  1168. } else {
  1169. i_vpr_h(inst,
  1170. "%s: color description flag is not present\n",
  1171. __func__);
  1172. }
  1173. } else {
  1174. i_vpr_h(inst, "%s: video_signal type is not present\n",
  1175. __func__);
  1176. }
  1177. inst->buffers.output.min_count = subsc_params.fw_min_count;
  1178. if (is_thumbnail_session(inst) && inst->codec != MSM_VIDC_VP9) {
  1179. if (inst->buffers.output.min_count != 1) {
  1180. i_vpr_e(inst, "%s: invalid min count %d in thumbnail case\n",
  1181. __func__, inst->buffers.output.min_count);
  1182. msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
  1183. }
  1184. }
  1185. inst->crop.top = subsc_params.crop_offsets[0] & 0xFFFF;
  1186. inst->crop.left = (subsc_params.crop_offsets[0] >> 16) & 0xFFFF;
  1187. inst->crop.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height -
  1188. (subsc_params.crop_offsets[1] & 0xFFFF);
  1189. inst->crop.width = inst->fmts[INPUT_PORT].fmt.pix_mp.width -
  1190. ((subsc_params.crop_offsets[1] >> 16) & 0xFFFF);
  1191. inst->capabilities->cap[PROFILE].value = subsc_params.profile;
  1192. inst->capabilities->cap[LEVEL].value = subsc_params.level;
  1193. inst->capabilities->cap[HEVC_TIER].value = subsc_params.tier;
  1194. inst->capabilities->cap[POC].value = subsc_params.pic_order_cnt;
  1195. inst->capabilities->cap[BIT_DEPTH].value = subsc_params.bit_depth;
  1196. if (subsc_params.coded_frames & HFI_BITMASK_FRAME_MBS_ONLY_FLAG)
  1197. inst->capabilities->cap[CODED_FRAMES].value =
  1198. CODED_FRAMES_PROGRESSIVE;
  1199. else
  1200. inst->capabilities->cap[CODED_FRAMES].value =
  1201. CODED_FRAMES_INTERLACE;
  1202. return 0;
  1203. }
  1204. int msm_vdec_input_port_settings_change(struct msm_vidc_inst *inst)
  1205. {
  1206. u32 rc = 0;
  1207. struct v4l2_event event = {0};
  1208. if (!inst->vb2q[INPUT_PORT].streaming) {
  1209. i_vpr_e(inst, "%s: input port not streaming\n",
  1210. __func__);
  1211. return 0;
  1212. }
  1213. rc = msm_vdec_read_input_subcr_params(inst);
  1214. if (rc)
  1215. return rc;
  1216. event.type = V4L2_EVENT_SOURCE_CHANGE;
  1217. event.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION;
  1218. v4l2_event_queue_fh(&inst->event_handler, &event);
  1219. rc = msm_vdec_get_input_internal_buffers(inst);
  1220. if (rc)
  1221. return rc;
  1222. rc = msm_vdec_release_input_internal_buffers(inst);
  1223. if (rc)
  1224. return rc;
  1225. rc = msm_vdec_create_input_internal_buffers(inst);
  1226. if (rc)
  1227. return rc;
  1228. rc = msm_vdec_queue_input_internal_buffers(inst);
  1229. if (rc)
  1230. return rc;
  1231. rc = msm_vdec_session_resume(inst, INPUT_PORT);
  1232. if (rc)
  1233. return rc;
  1234. return rc;
  1235. }
  1236. int msm_vdec_output_port_settings_change(struct msm_vidc_inst *inst)
  1237. {
  1238. //todo
  1239. return 0;
  1240. }
  1241. int msm_vdec_streamoff_input(struct msm_vidc_inst *inst)
  1242. {
  1243. int rc = 0;
  1244. if (!inst || !inst->core) {
  1245. d_vpr_e("%s: invalid params\n", __func__);
  1246. return -EINVAL;
  1247. }
  1248. rc = msm_vidc_session_streamoff(inst, INPUT_PORT);
  1249. if (rc)
  1250. return rc;
  1251. return 0;
  1252. }
  1253. int msm_vdec_streamon_input(struct msm_vidc_inst *inst)
  1254. {
  1255. int rc = 0;
  1256. if (!inst || !inst->core) {
  1257. d_vpr_e("%s: invalid params\n", __func__);
  1258. return -EINVAL;
  1259. }
  1260. if (is_input_meta_enabled(inst) &&
  1261. !inst->vb2q[INPUT_META_PORT].streaming) {
  1262. i_vpr_e(inst,
  1263. "%s: Meta port must be streamed on before data port\n",
  1264. __func__);
  1265. return -EINVAL;
  1266. }
  1267. //rc = msm_vidc_check_session_supported(inst);
  1268. if (rc)
  1269. goto error;
  1270. //rc = msm_vidc_check_scaling_supported(inst);
  1271. if (rc)
  1272. goto error;
  1273. rc = msm_vdec_set_input_properties(inst);
  1274. if (rc)
  1275. goto error;
  1276. /* Decide bse vpp delay after work mode */
  1277. //msm_vidc_set_bse_vpp_delay(inst);
  1278. rc = msm_vdec_get_input_internal_buffers(inst);
  1279. if (rc)
  1280. goto error;
  1281. /* check for memory after all buffers calculation */
  1282. //rc = msm_vidc_check_memory_supported(inst);
  1283. if (rc)
  1284. goto error;
  1285. //msm_vidc_update_dcvs(inst);
  1286. //msm_vidc_update_batching(inst);
  1287. //msm_vidc_scale_power(inst);
  1288. rc = msm_vdec_create_input_internal_buffers(inst);
  1289. if (rc)
  1290. goto error;
  1291. rc = msm_vdec_queue_input_internal_buffers(inst);
  1292. if (rc)
  1293. goto error;
  1294. if (!inst->ipsc_properties_set) {
  1295. rc = msm_vdec_subscribe_input_port_settings_change(
  1296. inst, INPUT_PORT);
  1297. if (rc)
  1298. return rc;
  1299. inst->ipsc_properties_set = true;
  1300. }
  1301. rc = msm_vdec_subscribe_property(inst, INPUT_PORT);
  1302. if (rc)
  1303. return rc;
  1304. rc = msm_vdec_set_delivery_mode_metadata(inst, INPUT_PORT);
  1305. if (rc)
  1306. return rc;
  1307. rc = msm_vidc_session_streamon(inst, INPUT_PORT);
  1308. if (rc)
  1309. goto error;
  1310. return 0;
  1311. error:
  1312. i_vpr_e(inst, "%s: failed\n", __func__);
  1313. msm_vdec_streamoff_input(inst);
  1314. return rc;
  1315. }
  1316. int msm_vdec_streamoff_output(struct msm_vidc_inst *inst)
  1317. {
  1318. int rc = 0;
  1319. if (!inst || !inst->core) {
  1320. d_vpr_e("%s: invalid params\n", __func__);
  1321. return -EINVAL;
  1322. }
  1323. rc = msm_vidc_session_streamoff(inst, OUTPUT_PORT);
  1324. if (rc)
  1325. return rc;
  1326. return 0;
  1327. }
  1328. static int msm_vdec_subscribe_output_port_settings_change(struct msm_vidc_inst *inst,
  1329. enum msm_vidc_port_type port)
  1330. {
  1331. int rc = 0;
  1332. u32 payload[32] = {0};
  1333. u32 prop_type, payload_size, payload_type;
  1334. u32 i;
  1335. struct msm_vidc_subscription_params subsc_params;
  1336. u32 subscribe_psc_size = 0;
  1337. u32 *psc = NULL;
  1338. if (!inst) {
  1339. d_vpr_e("%s: invalid params\n", __func__);
  1340. return -EINVAL;
  1341. }
  1342. i_vpr_h(inst, "%s()\n", __func__);
  1343. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  1344. if (inst->codec == MSM_VIDC_H264) {
  1345. subscribe_psc_size = ARRAY_SIZE(msm_vdec_subscribe_for_psc_avc);
  1346. psc = msm_vdec_subscribe_for_psc_avc;
  1347. } else if (inst->codec == MSM_VIDC_HEVC) {
  1348. subscribe_psc_size = ARRAY_SIZE(msm_vdec_subscribe_for_psc_hevc);
  1349. psc = msm_vdec_subscribe_for_psc_hevc;
  1350. } else if (inst->codec == MSM_VIDC_VP9) {
  1351. subscribe_psc_size = ARRAY_SIZE(msm_vdec_subscribe_for_psc_vp9);
  1352. psc = msm_vdec_subscribe_for_psc_vp9;
  1353. } else {
  1354. i_vpr_e(inst, "%s: unsupported codec: %d\n", __func__, inst->codec);
  1355. psc = NULL;
  1356. return -EINVAL;
  1357. }
  1358. if (!psc || !subscribe_psc_size) {
  1359. i_vpr_e(inst, "%s: invalid params\n", __func__);
  1360. return -EINVAL;
  1361. }
  1362. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  1363. for (i = 0; i < subscribe_psc_size; i++)
  1364. payload[i + 1] = psc[i];
  1365. rc = venus_hfi_session_command(inst,
  1366. HFI_CMD_SUBSCRIBE_MODE,
  1367. port,
  1368. HFI_PAYLOAD_U32_ARRAY,
  1369. &payload[0],
  1370. ((subscribe_psc_size + 1) *
  1371. sizeof(u32)));
  1372. subsc_params = inst->subcr_params[port];
  1373. for (i = 0; i < subscribe_psc_size; i++) {
  1374. payload[0] = 0;
  1375. payload[1] = 0;
  1376. payload_size = 0;
  1377. payload_type = 0;
  1378. prop_type = psc[i];
  1379. switch (prop_type) {
  1380. case HFI_PROP_BITSTREAM_RESOLUTION:
  1381. payload[0] = subsc_params.bitstream_resolution;
  1382. payload_size = sizeof(u32);
  1383. payload_type = HFI_PAYLOAD_U32;
  1384. break;
  1385. case HFI_PROP_CROP_OFFSETS:
  1386. payload[0] = subsc_params.crop_offsets[0];
  1387. payload[1] = subsc_params.crop_offsets[1];
  1388. payload_size = sizeof(u64);
  1389. payload_type = HFI_PAYLOAD_64_PACKED;
  1390. break;
  1391. case HFI_PROP_LUMA_CHROMA_BIT_DEPTH:
  1392. payload[0] = subsc_params.bit_depth;
  1393. payload_size = sizeof(u32);
  1394. payload_type = HFI_PAYLOAD_U32;
  1395. break;
  1396. case HFI_PROP_CODED_FRAMES:
  1397. payload[0] = subsc_params.coded_frames;
  1398. payload_size = sizeof(u32);
  1399. payload_type = HFI_PAYLOAD_U32;
  1400. break;
  1401. case HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT:
  1402. payload[0] = subsc_params.fw_min_count;
  1403. payload_size = sizeof(u32);
  1404. payload_type = HFI_PAYLOAD_U32;
  1405. break;
  1406. case HFI_PROP_PIC_ORDER_CNT_TYPE:
  1407. payload[0] = subsc_params.pic_order_cnt;
  1408. payload_size = sizeof(u32);
  1409. payload_type = HFI_PAYLOAD_U32;
  1410. break;
  1411. case HFI_PROP_SIGNAL_COLOR_INFO:
  1412. payload[0] = subsc_params.color_info;
  1413. payload_size = sizeof(u32);
  1414. payload_type = HFI_PAYLOAD_U32;
  1415. break;
  1416. case HFI_PROP_PROFILE:
  1417. payload[0] = subsc_params.profile;
  1418. payload_size = sizeof(u32);
  1419. payload_type = HFI_PAYLOAD_U32;
  1420. break;
  1421. case HFI_PROP_LEVEL:
  1422. payload[0] = subsc_params.level;
  1423. payload_size = sizeof(u32);
  1424. payload_type = HFI_PAYLOAD_U32;
  1425. break;
  1426. case HFI_PROP_TIER:
  1427. payload[0] = subsc_params.tier;
  1428. payload_size = sizeof(u32);
  1429. payload_type = HFI_PAYLOAD_U32;
  1430. break;
  1431. default:
  1432. i_vpr_e(inst, "%s: unknown property %#x\n", __func__,
  1433. prop_type);
  1434. prop_type = 0;
  1435. rc = -EINVAL;
  1436. break;
  1437. }
  1438. if (prop_type) {
  1439. rc = venus_hfi_session_property(inst,
  1440. prop_type,
  1441. HFI_HOST_FLAGS_NONE,
  1442. get_hfi_port(inst, port),
  1443. payload_type,
  1444. &payload,
  1445. payload_size);
  1446. if (rc)
  1447. return rc;
  1448. }
  1449. }
  1450. return rc;
  1451. }
  1452. int msm_vdec_streamon_output(struct msm_vidc_inst *inst)
  1453. {
  1454. int rc = 0;
  1455. if (!inst || !inst->core) {
  1456. d_vpr_e("%s: invalid params\n", __func__);
  1457. return -EINVAL;
  1458. }
  1459. if (is_output_meta_enabled(inst) &&
  1460. !inst->vb2q[OUTPUT_META_PORT].streaming) {
  1461. i_vpr_e(inst,
  1462. "%s: Meta port must be streamed on before data port\n",
  1463. __func__);
  1464. return -EINVAL;
  1465. }
  1466. rc = msm_vdec_set_output_properties(inst);
  1467. if (rc)
  1468. goto error;
  1469. if (!inst->opsc_properties_set) {
  1470. memcpy(&inst->subcr_params[OUTPUT_PORT],
  1471. &inst->subcr_params[INPUT_PORT],
  1472. sizeof(inst->subcr_params[INPUT_PORT]));
  1473. rc = msm_vdec_subscribe_output_port_settings_change(inst, OUTPUT_PORT);
  1474. if (rc)
  1475. goto error;
  1476. inst->opsc_properties_set = true;
  1477. }
  1478. rc = msm_vdec_subscribe_metadata(inst, OUTPUT_PORT);
  1479. if (rc)
  1480. goto error;
  1481. rc = msm_vdec_get_output_internal_buffers(inst);
  1482. if (rc)
  1483. goto error;
  1484. rc = msm_vdec_release_output_internal_buffers(inst);
  1485. if (rc)
  1486. goto error;
  1487. rc = msm_vdec_create_output_internal_buffers(inst);
  1488. if (rc)
  1489. goto error;
  1490. rc = msm_vidc_session_streamon(inst, OUTPUT_PORT);
  1491. if (rc)
  1492. goto error;
  1493. rc = msm_vdec_queue_output_internal_buffers(inst);
  1494. if (rc)
  1495. goto error;
  1496. return 0;
  1497. error:
  1498. i_vpr_e(inst, "%s: failed\n", __func__);
  1499. msm_vdec_streamoff_output(inst);
  1500. return rc;
  1501. }
  1502. static int msm_vdec_qbuf_batch(struct msm_vidc_inst *inst,
  1503. struct vb2_buffer *vb2)
  1504. {
  1505. int rc = 0;
  1506. if (!inst || !vb2) {
  1507. d_vpr_e("%s: invalid params\n", __func__);
  1508. return -EINVAL;
  1509. }
  1510. i_vpr_h(inst, "%s()\n", __func__);
  1511. return rc;
  1512. }
  1513. int msm_vdec_qbuf(struct msm_vidc_inst *inst, struct vb2_buffer *vb2)
  1514. {
  1515. int rc = 0;
  1516. if (inst->decode_batch.enable)
  1517. rc = msm_vdec_qbuf_batch(inst, vb2);
  1518. else
  1519. rc = msm_vidc_queue_buffer(inst, vb2);
  1520. return rc;
  1521. }
  1522. int msm_vdec_process_cmd(struct msm_vidc_inst *inst, u32 cmd)
  1523. {
  1524. int rc = 0;
  1525. enum msm_vidc_allow allow = MSM_VIDC_DISALLOW;
  1526. enum msm_vidc_port_type port;
  1527. if (!inst || !inst->core) {
  1528. d_vpr_e("%s: invalid params\n", __func__);
  1529. return -EINVAL;
  1530. }
  1531. if (cmd == V4L2_DEC_CMD_STOP) {
  1532. allow = msm_vidc_allow_stop(inst);
  1533. if (allow == MSM_VIDC_DISALLOW)
  1534. return -EBUSY;
  1535. else if (allow == MSM_VIDC_IGNORE)
  1536. return 0;
  1537. else if (allow != MSM_VIDC_ALLOW)
  1538. return -EINVAL;
  1539. rc = venus_hfi_session_command(inst,
  1540. HFI_CMD_DRAIN,
  1541. INPUT_PORT,
  1542. HFI_PAYLOAD_NONE,
  1543. NULL,
  1544. 0);
  1545. if (rc)
  1546. return rc;
  1547. rc = msm_vidc_state_change_stop(inst);
  1548. if (rc)
  1549. return rc;
  1550. } else if (cmd == V4L2_DEC_CMD_START) {
  1551. if (!msm_vidc_allow_start(inst))
  1552. return -EBUSY;
  1553. port = (inst->state == MSM_VIDC_DRAIN_LAST_FLAG) ? INPUT_PORT : OUTPUT_PORT;
  1554. vb2_clear_last_buffer_dequeued(&inst->vb2q[OUTPUT_META_PORT]);
  1555. vb2_clear_last_buffer_dequeued(&inst->vb2q[OUTPUT_PORT]);
  1556. rc = msm_vidc_state_change_start(inst);
  1557. if (rc)
  1558. return rc;
  1559. rc = venus_hfi_session_command(inst,
  1560. HFI_CMD_RESUME,
  1561. port,
  1562. HFI_PAYLOAD_NONE,
  1563. NULL,
  1564. 0);
  1565. if (rc)
  1566. return rc;
  1567. } else {
  1568. i_vpr_e(inst, "%s: unknown cmd %d\n", __func__, cmd);
  1569. return -EINVAL;
  1570. }
  1571. return 0;
  1572. }
  1573. int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  1574. {
  1575. int rc = 0;
  1576. struct msm_vidc_core *core;
  1577. struct v4l2_format *fmt;
  1578. u32 codec_align;
  1579. if (!inst || !inst->core) {
  1580. d_vpr_e("%s: invalid params\n", __func__);
  1581. return -EINVAL;
  1582. }
  1583. core = inst->core;
  1584. if (f->type == INPUT_MPLANE) {
  1585. if (inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat !=
  1586. f->fmt.pix_mp.pixelformat) {
  1587. i_vpr_h(inst,
  1588. "%s: codec changed from %#x to %#x\n", __func__,
  1589. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat,
  1590. f->fmt.pix_mp.pixelformat);
  1591. rc = msm_vdec_codec_change(inst, f->fmt.pix_mp.pixelformat);
  1592. if (rc)
  1593. goto err_invalid_fmt;
  1594. }
  1595. fmt = &inst->fmts[INPUT_PORT];
  1596. fmt->type = INPUT_MPLANE;
  1597. codec_align = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat ==
  1598. V4L2_PIX_FMT_HEVC ? 32 : 16;
  1599. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, codec_align);
  1600. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, codec_align);
  1601. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  1602. fmt->fmt.pix_mp.num_planes = 1;
  1603. fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  1604. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1605. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  1606. inst->buffers.input.min_count = call_session_op(core,
  1607. min_count, inst, MSM_VIDC_BUF_INPUT);
  1608. inst->buffers.input.extra_count = call_session_op(core,
  1609. extra_count, inst, MSM_VIDC_BUF_INPUT);
  1610. if (inst->buffers.input.actual_count <
  1611. inst->buffers.input.min_count +
  1612. inst->buffers.input.extra_count) {
  1613. inst->buffers.input.actual_count =
  1614. inst->buffers.input.min_count +
  1615. inst->buffers.input.extra_count;
  1616. }
  1617. inst->buffers.input.size =
  1618. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  1619. /* update crop dimensions */
  1620. inst->crop.left = inst->crop.top = 0;
  1621. inst->crop.width = f->fmt.pix_mp.width;
  1622. inst->crop.height = f->fmt.pix_mp.height;
  1623. //rc = msm_vidc_check_session_supported(inst);
  1624. if (rc)
  1625. goto err_invalid_fmt;
  1626. //update_log_ctxt(inst->sid, inst->session_type,
  1627. // mplane->pixelformat);
  1628. i_vpr_h(inst,
  1629. "%s: input: codec %#x width %d height %d size %d min_count %d extra_count %d\n",
  1630. __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width,
  1631. f->fmt.pix_mp.height,
  1632. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  1633. inst->buffers.input.min_count,
  1634. inst->buffers.input.extra_count);
  1635. //msm_vidc_update_dcvs(inst);
  1636. //msm_vidc_update_batching(inst);
  1637. } else if (f->type == INPUT_META_PLANE) {
  1638. fmt = &inst->fmts[INPUT_META_PORT];
  1639. fmt->type = INPUT_META_PLANE;
  1640. fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  1641. if (is_input_meta_enabled(inst)) {
  1642. fmt->fmt.meta.buffersize = call_session_op(core,
  1643. buffer_size, inst, MSM_VIDC_BUF_INPUT_META);
  1644. inst->buffers.input_meta.min_count =
  1645. inst->buffers.input.min_count;
  1646. inst->buffers.input_meta.extra_count =
  1647. inst->buffers.input.extra_count;
  1648. inst->buffers.input_meta.actual_count =
  1649. inst->buffers.input.actual_count;
  1650. inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
  1651. } else {
  1652. fmt->fmt.meta.buffersize = 0;
  1653. inst->buffers.input_meta.min_count = 0;
  1654. inst->buffers.input_meta.extra_count = 0;
  1655. inst->buffers.input_meta.actual_count = 0;
  1656. inst->buffers.input_meta.size = 0;
  1657. }
  1658. i_vpr_h(inst,
  1659. "%s: input meta: size %d min_count %d extra_count %d\n",
  1660. __func__, fmt->fmt.meta.buffersize,
  1661. inst->buffers.input_meta.min_count,
  1662. inst->buffers.input_meta.extra_count);
  1663. } else if (f->type == OUTPUT_MPLANE) {
  1664. fmt = &inst->fmts[OUTPUT_PORT];
  1665. fmt->type = OUTPUT_MPLANE;
  1666. if (inst->vb2q[INPUT_PORT].streaming) {
  1667. f->fmt.pix_mp.height = fmt->fmt.pix_mp.height;
  1668. f->fmt.pix_mp.width = fmt->fmt.pix_mp.width;
  1669. }
  1670. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  1671. fmt->fmt.pix_mp.width = VIDEO_Y_STRIDE_PIX(
  1672. fmt->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width);
  1673. fmt->fmt.pix_mp.height = VIDEO_Y_SCANLINES(
  1674. fmt->fmt.pix_mp.pixelformat,
  1675. f->fmt.pix_mp.height);
  1676. fmt->fmt.pix_mp.num_planes = 1;
  1677. fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
  1678. VIDEO_Y_STRIDE_BYTES(
  1679. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat,
  1680. f->fmt.pix_mp.width);
  1681. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1682. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  1683. if (!inst->vb2q[INPUT_PORT].streaming)
  1684. inst->buffers.output.min_count = call_session_op(core,
  1685. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  1686. inst->buffers.output.extra_count = call_session_op(core,
  1687. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  1688. if (inst->buffers.output.actual_count <
  1689. inst->buffers.output.min_count +
  1690. inst->buffers.output.extra_count) {
  1691. inst->buffers.output.actual_count =
  1692. inst->buffers.output.min_count +
  1693. inst->buffers.output.extra_count;
  1694. }
  1695. inst->buffers.output.size =
  1696. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  1697. inst->capabilities->cap[PIX_FMTS].value =
  1698. v4l2_colorformat_to_driver(f->fmt.pix_mp.pixelformat, __func__);
  1699. //rc = msm_vidc_check_session_supported(inst);
  1700. if (rc)
  1701. goto err_invalid_fmt;
  1702. i_vpr_h(inst,
  1703. "%s: output: format %#x width %d height %d size %d min_count %d extra_count %d\n",
  1704. __func__, fmt->fmt.pix_mp.pixelformat, fmt->fmt.pix_mp.width,
  1705. fmt->fmt.pix_mp.height,
  1706. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  1707. inst->buffers.output.min_count,
  1708. inst->buffers.output.extra_count);
  1709. } else if (f->type == OUTPUT_META_PLANE) {
  1710. fmt = &inst->fmts[OUTPUT_META_PORT];
  1711. fmt->type = OUTPUT_META_PLANE;
  1712. fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  1713. if (is_output_meta_enabled(inst)) {
  1714. fmt->fmt.meta.buffersize = call_session_op(core,
  1715. buffer_size, inst, MSM_VIDC_BUF_OUTPUT_META);
  1716. inst->buffers.output_meta.min_count =
  1717. inst->buffers.output.min_count;
  1718. inst->buffers.output_meta.extra_count =
  1719. inst->buffers.output.extra_count;
  1720. inst->buffers.output_meta.actual_count =
  1721. inst->buffers.output.actual_count;
  1722. inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
  1723. } else {
  1724. fmt->fmt.meta.buffersize = 0;
  1725. inst->buffers.output_meta.min_count = 0;
  1726. inst->buffers.output_meta.extra_count = 0;
  1727. inst->buffers.output_meta.actual_count = 0;
  1728. inst->buffers.output_meta.size = 0;
  1729. }
  1730. i_vpr_h(inst,
  1731. "%s: output meta: size %d min_count %d extra_count %d\n",
  1732. __func__, fmt->fmt.meta.buffersize,
  1733. inst->buffers.output_meta.min_count,
  1734. inst->buffers.output_meta.extra_count);
  1735. } else {
  1736. i_vpr_e(inst, "%s: invalid type %d\n", __func__, f->type);
  1737. goto err_invalid_fmt;
  1738. }
  1739. memcpy(f, fmt, sizeof(struct v4l2_format));
  1740. err_invalid_fmt:
  1741. return rc;
  1742. }
  1743. int msm_vdec_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  1744. {
  1745. int rc = 0;
  1746. int port;
  1747. if (!inst) {
  1748. d_vpr_e("%s: invalid params\n", __func__);
  1749. return -EINVAL;
  1750. }
  1751. port = v4l2_type_to_driver_port(inst, f->type, __func__);
  1752. if (port < 0)
  1753. return -EINVAL;
  1754. memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
  1755. return rc;
  1756. }
  1757. int msm_vdec_s_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
  1758. {
  1759. if (!inst || !s) {
  1760. d_vpr_e("%s: invalid params\n", __func__);
  1761. return -EINVAL;
  1762. }
  1763. i_vpr_e(inst, "%s: unsupported\n", __func__);
  1764. return -EINVAL;
  1765. }
  1766. int msm_vdec_g_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
  1767. {
  1768. if (!inst || !s) {
  1769. d_vpr_e("%s: invalid params\n", __func__);
  1770. return -EINVAL;
  1771. }
  1772. switch (s->target) {
  1773. case V4L2_SEL_TGT_CROP_BOUNDS:
  1774. case V4L2_SEL_TGT_CROP_DEFAULT:
  1775. case V4L2_SEL_TGT_CROP:
  1776. case V4L2_SEL_TGT_COMPOSE_BOUNDS:
  1777. case V4L2_SEL_TGT_COMPOSE_PADDED:
  1778. case V4L2_SEL_TGT_COMPOSE_DEFAULT:
  1779. case V4L2_SEL_TGT_COMPOSE:
  1780. default:
  1781. s->r.left = inst->crop.left;
  1782. s->r.top = inst->crop.top;
  1783. s->r.width = inst->crop.width;
  1784. s->r.height = inst->crop.height;
  1785. break;
  1786. }
  1787. i_vpr_h(inst, "%s: type %d target %d, r [%d, %d, %d, %d]\n",
  1788. __func__, s->type, s->target, s->r.top, s->r.left,
  1789. s->r.width, s->r.height);
  1790. return 0;
  1791. }
  1792. int msm_vdec_s_param(struct msm_vidc_inst *inst,
  1793. struct v4l2_streamparm *s_parm)
  1794. {
  1795. int rc = 0;
  1796. struct msm_vidc_inst_capability *capability = NULL;
  1797. struct v4l2_fract *timeperframe = NULL;
  1798. u32 q16_rate, max_rate, default_rate;
  1799. u64 us_per_frame = 0, input_rate = 0;
  1800. bool is_frame_rate = false;
  1801. if (!inst || !s_parm) {
  1802. d_vpr_e("%s: invalid params\n", __func__);
  1803. return -EINVAL;
  1804. }
  1805. capability = inst->capabilities;
  1806. if (s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  1807. timeperframe = &s_parm->parm.output.timeperframe;
  1808. max_rate = capability->cap[FRAME_RATE].max >> 16;
  1809. default_rate = capability->cap[FRAME_RATE].value >> 16;
  1810. is_frame_rate = true;
  1811. } else {
  1812. timeperframe = &s_parm->parm.capture.timeperframe;
  1813. max_rate = capability->cap[OPERATING_RATE].max;
  1814. default_rate = capability->cap[OPERATING_RATE].value >> 16;
  1815. }
  1816. if (!timeperframe->denominator || !timeperframe->numerator) {
  1817. i_vpr_e(inst,
  1818. "%s: invalid rate for type %u\n",
  1819. __func__, s_parm->type);
  1820. input_rate = default_rate;
  1821. goto set_default;
  1822. }
  1823. us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC;
  1824. do_div(us_per_frame, timeperframe->denominator);
  1825. if (!us_per_frame) {
  1826. i_vpr_e(inst, "%s: us_per_frame is zero\n",
  1827. __func__);
  1828. rc = -EINVAL;
  1829. goto exit;
  1830. }
  1831. input_rate = (u64)USEC_PER_SEC;
  1832. do_div(input_rate, us_per_frame);
  1833. /* Check max allowed rate */
  1834. if (input_rate > max_rate) {
  1835. i_vpr_e(inst,
  1836. "%s: Unsupported rate %llu, max_fps %u, type: %u\n",
  1837. __func__, input_rate, max_rate, s_parm->type);
  1838. rc = -ENOTSUPP;
  1839. goto exit;
  1840. }
  1841. set_default:
  1842. q16_rate = (u32)input_rate << 16;
  1843. i_vpr_h(inst, "%s: type %u value %#x\n",
  1844. __func__, s_parm->type, q16_rate);
  1845. if (is_frame_rate) {
  1846. capability->cap[FRAME_RATE].value = q16_rate;
  1847. } else {
  1848. capability->cap[OPERATING_RATE].value = q16_rate;
  1849. }
  1850. exit:
  1851. return rc;
  1852. }
  1853. int msm_vdec_g_param(struct msm_vidc_inst *inst,
  1854. struct v4l2_streamparm *s_parm)
  1855. {
  1856. struct msm_vidc_inst_capability *capability = NULL;
  1857. struct v4l2_fract *timeperframe = NULL;
  1858. if (!inst || !s_parm) {
  1859. d_vpr_e("%s: invalid params\n", __func__);
  1860. return -EINVAL;
  1861. }
  1862. capability = inst->capabilities;
  1863. if (s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  1864. timeperframe = &s_parm->parm.output.timeperframe;
  1865. timeperframe->numerator = 1;
  1866. timeperframe->denominator =
  1867. capability->cap[FRAME_RATE].value >> 16;
  1868. } else {
  1869. timeperframe = &s_parm->parm.capture.timeperframe;
  1870. timeperframe->numerator = 1;
  1871. timeperframe->denominator =
  1872. capability->cap[OPERATING_RATE].value >> 16;
  1873. }
  1874. i_vpr_h(inst, "%s: type %u, num %u denom %u\n",
  1875. __func__, s_parm->type, timeperframe->numerator,
  1876. timeperframe->denominator);
  1877. return 0;
  1878. }
  1879. static int msm_vdec_check_colorformat_supported(struct msm_vidc_inst* inst,
  1880. enum msm_vidc_colorformat_type colorformat)
  1881. {
  1882. bool supported = true;
  1883. /* do not reject coloformats before streamon */
  1884. if (!inst->vb2q[INPUT_PORT].streaming)
  1885. return true;
  1886. /*
  1887. * bit_depth 8 bit supports 8 bit colorformats only
  1888. * bit_depth 10 bit supports 10 bit colorformats only
  1889. * interlace supports ubwc colorformats only
  1890. */
  1891. if (inst->capabilities->cap[BIT_DEPTH].value == BIT_DEPTH_8 &&
  1892. !is_8bit_colorformat(colorformat))
  1893. supported = false;
  1894. if (inst->capabilities->cap[BIT_DEPTH].value == BIT_DEPTH_10 &&
  1895. !is_10bit_colorformat(colorformat))
  1896. supported = false;
  1897. if (inst->capabilities->cap[CODED_FRAMES].value ==
  1898. CODED_FRAMES_INTERLACE &&
  1899. !is_ubwc_colorformat(colorformat))
  1900. supported = false;
  1901. return supported;
  1902. }
  1903. int msm_vdec_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
  1904. {
  1905. int rc = 0;
  1906. struct msm_vidc_core *core;
  1907. u32 array[32] = {0};
  1908. u32 i = 0, idx = 0;
  1909. if (!inst || !inst->core || !inst->capabilities || !f) {
  1910. d_vpr_e("%s: invalid params\n", __func__);
  1911. return -EINVAL;
  1912. }
  1913. core = inst->core;
  1914. if (f->type == INPUT_MPLANE) {
  1915. u32 codecs = core->capabilities[DEC_CODECS].value;
  1916. while (codecs) {
  1917. if (i > 31)
  1918. break;
  1919. if (codecs & BIT(i)) {
  1920. array[idx] = codecs & BIT(i);
  1921. idx++;
  1922. }
  1923. i++;
  1924. }
  1925. f->pixelformat = v4l2_codec_from_driver(array[f->index],
  1926. __func__);
  1927. if (!f->pixelformat)
  1928. return -EINVAL;
  1929. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  1930. strlcpy(f->description, "codec", sizeof(f->description));
  1931. } else if (f->type == OUTPUT_MPLANE) {
  1932. u32 formats = inst->capabilities->cap[PIX_FMTS].step_or_mask;
  1933. while (formats) {
  1934. if (i > 31)
  1935. break;
  1936. if (formats & BIT(i)) {
  1937. if (msm_vdec_check_colorformat_supported(inst,
  1938. formats & BIT(i))) {
  1939. array[idx] = formats & BIT(i);
  1940. idx++;
  1941. }
  1942. }
  1943. i++;
  1944. }
  1945. f->pixelformat = v4l2_colorformat_from_driver(array[f->index],
  1946. __func__);
  1947. if (!f->pixelformat)
  1948. return -EINVAL;
  1949. strlcpy(f->description, "colorformat", sizeof(f->description));
  1950. } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
  1951. if (!f->index) {
  1952. f->pixelformat = V4L2_META_FMT_VIDC;
  1953. strlcpy(f->description, "metadata", sizeof(f->description));
  1954. } else {
  1955. return -EINVAL;
  1956. }
  1957. }
  1958. memset(f->reserved, 0, sizeof(f->reserved));
  1959. i_vpr_h(inst, "%s: index %d, %s : %#x, flags %#x, driver colorfmt %#x\n",
  1960. __func__, f->index, f->description, f->pixelformat, f->flags,
  1961. v4l2_colorformat_to_driver(f->pixelformat, __func__));
  1962. return rc;
  1963. }
  1964. int msm_vdec_inst_init(struct msm_vidc_inst *inst)
  1965. {
  1966. int rc = 0;
  1967. struct msm_vidc_core *core;
  1968. struct v4l2_format *f;
  1969. if (!inst || !inst->core) {
  1970. d_vpr_e("%s: invalid params\n", __func__);
  1971. return -EINVAL;
  1972. }
  1973. core = inst->core;
  1974. INIT_DELAYED_WORK(&inst->decode_batch.work, msm_vidc_batch_handler);
  1975. f = &inst->fmts[INPUT_PORT];
  1976. f->type = INPUT_MPLANE;
  1977. f->fmt.pix_mp.width = DEFAULT_WIDTH;
  1978. f->fmt.pix_mp.height = DEFAULT_HEIGHT;
  1979. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
  1980. f->fmt.pix_mp.num_planes = 1;
  1981. f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  1982. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1983. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  1984. inst->buffers.input.min_count = call_session_op(core,
  1985. min_count, inst, MSM_VIDC_BUF_INPUT);
  1986. inst->buffers.input.extra_count = call_session_op(core,
  1987. extra_count, inst, MSM_VIDC_BUF_INPUT);
  1988. inst->buffers.input.actual_count =
  1989. inst->buffers.input.min_count +
  1990. inst->buffers.input.extra_count;
  1991. inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  1992. inst->crop.left = inst->crop.top = 0;
  1993. inst->crop.width = f->fmt.pix_mp.width;
  1994. inst->crop.height = f->fmt.pix_mp.height;
  1995. f = &inst->fmts[INPUT_META_PORT];
  1996. f->type = INPUT_META_PLANE;
  1997. f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  1998. f->fmt.meta.buffersize = 0;
  1999. inst->buffers.input_meta.min_count = 0;
  2000. inst->buffers.input_meta.extra_count = 0;
  2001. inst->buffers.input_meta.actual_count = 0;
  2002. inst->buffers.input_meta.size = 0;
  2003. f = &inst->fmts[OUTPUT_PORT];
  2004. f->type = OUTPUT_MPLANE;
  2005. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_VIDC_NV12C;
  2006. f->fmt.pix_mp.width = VIDEO_Y_STRIDE_PIX(f->fmt.pix_mp.pixelformat,
  2007. DEFAULT_WIDTH);
  2008. f->fmt.pix_mp.height = VIDEO_Y_SCANLINES(f->fmt.pix_mp.pixelformat,
  2009. DEFAULT_HEIGHT);
  2010. f->fmt.pix_mp.num_planes = 1;
  2011. f->fmt.pix_mp.plane_fmt[0].bytesperline =
  2012. VIDEO_Y_STRIDE_BYTES(
  2013. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat,
  2014. DEFAULT_WIDTH);
  2015. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  2016. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  2017. f->fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
  2018. f->fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
  2019. f->fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
  2020. f->fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
  2021. inst->buffers.output.min_count = call_session_op(core,
  2022. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  2023. inst->buffers.output.extra_count = call_session_op(core,
  2024. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  2025. inst->buffers.output.actual_count =
  2026. inst->buffers.output.min_count +
  2027. inst->buffers.output.extra_count;
  2028. inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  2029. f = &inst->fmts[OUTPUT_META_PORT];
  2030. f->type = OUTPUT_META_PLANE;
  2031. f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  2032. f->fmt.meta.buffersize = 0;
  2033. inst->buffers.output_meta.min_count = 0;
  2034. inst->buffers.output_meta.extra_count = 0;
  2035. inst->buffers.output_meta.actual_count = 0;
  2036. inst->buffers.output_meta.size = 0;
  2037. rc = msm_vdec_codec_change(inst,
  2038. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat);
  2039. return rc;
  2040. }
  2041. int msm_vdec_inst_deinit(struct msm_vidc_inst *inst)
  2042. {
  2043. int rc = 0;
  2044. if (!inst) {
  2045. d_vpr_e("%s: invalid params\n", __func__);
  2046. return -EINVAL;
  2047. }
  2048. rc = msm_vidc_ctrl_deinit(inst);
  2049. return rc;
  2050. }