msm_vdec.c 79 KB

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