msm_vdec.c 64 KB

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