msm_vdec.c 53 KB

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