msm_vdec.c 77 KB

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