msm_vdec.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <media/msm_vidc_utils.h>
  6. #include <media/msm_media_info.h>
  7. #include "msm_vdec.h"
  8. #include "msm_vidc_core.h"
  9. #include "msm_vidc_inst.h"
  10. #include "msm_vidc_driver.h"
  11. #include "msm_vidc_internal.h"
  12. #include "msm_vidc_platform.h"
  13. #include "msm_vidc_debug.h"
  14. #include "venus_hfi.h"
  15. #include "hfi_packet.h"
  16. u32 msm_vdec_subscribe_for_port_settings_change[] = {
  17. HFI_PROP_ALIGN_RESOLUTION,
  18. HFI_PROP_CROP_COORDINATE_TOP_LEFT,
  19. HFI_PROP_CROP_RESOLUTION,
  20. HFI_PROP_LUMA_CHROMA_BIT_DEPTH,
  21. HFI_PROP_CABAC_SESSION,
  22. HFI_PROP_CODED_FRAMES,
  23. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  24. HFI_PROP_PIC_ORDER_CNT_TYPE,
  25. HFI_PROP_SIGNAL_COLOR_INFO,
  26. };
  27. u32 msm_vdec_subscribe_for_properties[] = {
  28. HFI_PROP_TAG_NOT_PROPAGATED_TO_OUTPUT,
  29. };
  30. u32 msm_vdec_subscribe_for_metadata[] = {
  31. HFI_PROP_BUFFER_TAG,
  32. };
  33. u32 msm_vdec_deliver_as_metadata[] = {
  34. HFI_PROP_BUFFER_TAG,
  35. };
  36. static int msm_vdec_codec_change(struct msm_vidc_inst *inst, u32 codec)
  37. {
  38. int rc = 0;
  39. d_vpr_h("%s()\n", __func__);
  40. inst->codec = v4l2_codec_to_driver(codec, __func__);
  41. rc = msm_vidc_get_inst_capability(inst);
  42. if (rc)
  43. return rc;
  44. return 0;
  45. }
  46. static int msm_vdec_set_resolution(struct msm_vidc_inst *inst,
  47. enum msm_vidc_port_type port)
  48. {
  49. int rc = 0;
  50. u32 resolution;
  51. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  52. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  53. return -EINVAL;
  54. }
  55. resolution = inst->fmts[port].fmt.pix_mp.width << 16 |
  56. inst->fmts[port].fmt.pix_mp.height;
  57. rc = venus_hfi_session_property(inst,
  58. HFI_PROP_ALIGN_RESOLUTION,
  59. HFI_HOST_FLAGS_NONE,
  60. get_hfi_port(inst, port),
  61. HFI_PAYLOAD_U32,
  62. &resolution,
  63. sizeof(u32));
  64. if (rc)
  65. return rc;
  66. return 0;
  67. }
  68. static int msm_vdec_set_crop_top_left(struct msm_vidc_inst *inst,
  69. enum msm_vidc_port_type port)
  70. {
  71. int rc = 0;
  72. u32 crop_top_left;
  73. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  74. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  75. return -EINVAL;
  76. }
  77. crop_top_left = 0;
  78. rc = venus_hfi_session_property(inst,
  79. HFI_PROP_CROP_COORDINATE_TOP_LEFT,
  80. HFI_HOST_FLAGS_NONE,
  81. get_hfi_port(inst, port),
  82. HFI_PAYLOAD_U32,
  83. &crop_top_left,
  84. sizeof(u32));
  85. if (rc)
  86. return rc;
  87. return 0;
  88. }
  89. static int msm_vdec_set_crop_resolution(struct msm_vidc_inst *inst,
  90. enum msm_vidc_port_type port)
  91. {
  92. int rc = 0;
  93. u32 crop;
  94. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  95. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  96. return -EINVAL;
  97. }
  98. /* output buffer resolution is nothing but crop */
  99. crop = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width << 16 |
  100. inst->fmts[OUTPUT_PORT].fmt.pix_mp.height;
  101. rc = venus_hfi_session_property(inst,
  102. HFI_PROP_CROP_RESOLUTION,
  103. HFI_HOST_FLAGS_NONE,
  104. get_hfi_port(inst, port),
  105. HFI_PAYLOAD_U32,
  106. &crop,
  107. sizeof(u32));
  108. if (rc)
  109. return rc;
  110. return 0;
  111. }
  112. static int msm_vdec_set_bit_depth(struct msm_vidc_inst *inst,
  113. enum msm_vidc_port_type port)
  114. {
  115. int rc = 0;
  116. u32 colorformat;
  117. u32 bitdepth = 8 << 16 | 8;
  118. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  119. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  120. return -EINVAL;
  121. }
  122. colorformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  123. if (colorformat == V4L2_PIX_FMT_NV12_P010 ||
  124. colorformat == V4L2_PIX_FMT_NV12_TP10_UBWC)
  125. bitdepth = 10 << 16 | 10;
  126. rc = venus_hfi_session_property(inst,
  127. HFI_PROP_LUMA_CHROMA_BIT_DEPTH,
  128. HFI_HOST_FLAGS_NONE,
  129. get_hfi_port(inst, port),
  130. HFI_PAYLOAD_U32,
  131. &bitdepth,
  132. sizeof(u32));
  133. if (rc)
  134. return rc;
  135. return 0;
  136. }
  137. static int msm_vdec_set_cabac(struct msm_vidc_inst *inst,
  138. enum msm_vidc_port_type port)
  139. {
  140. int rc = 0;
  141. u32 cabac = 0;
  142. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  143. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  144. return -EINVAL;
  145. }
  146. rc = venus_hfi_session_property(inst,
  147. HFI_PROP_CABAC_SESSION,
  148. HFI_HOST_FLAGS_NONE,
  149. get_hfi_port(inst, port),
  150. HFI_PAYLOAD_U32,
  151. &cabac,
  152. sizeof(u32));
  153. if (rc)
  154. return rc;
  155. return 0;
  156. }
  157. static int msm_vdec_set_coded_frames(struct msm_vidc_inst *inst,
  158. enum msm_vidc_port_type port)
  159. {
  160. int rc = 0;
  161. u32 coded_frames;
  162. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  163. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  164. return -EINVAL;
  165. }
  166. /* (mb_adaptive_frame_field_flag << 1) | frame_mbs_only_flag */
  167. coded_frames = 1;
  168. rc = venus_hfi_session_property(inst,
  169. HFI_PROP_CODED_FRAMES,
  170. HFI_HOST_FLAGS_NONE,
  171. get_hfi_port(inst, port),
  172. HFI_PAYLOAD_U32,
  173. &coded_frames,
  174. sizeof(u32));
  175. if (rc)
  176. return rc;
  177. return 0;
  178. }
  179. static int msm_vdec_set_min_output_count(struct msm_vidc_inst *inst,
  180. enum msm_vidc_port_type port)
  181. {
  182. int rc = 0;
  183. u32 min_output;
  184. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  185. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  186. return -EINVAL;
  187. }
  188. min_output = inst->buffers.output.min_count;
  189. rc = venus_hfi_session_property(inst,
  190. HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT,
  191. HFI_HOST_FLAGS_NONE,
  192. get_hfi_port(inst, port),
  193. HFI_PAYLOAD_U32,
  194. &min_output,
  195. sizeof(u32));
  196. if (rc)
  197. return rc;
  198. return 0;
  199. }
  200. static int msm_vdec_set_picture_order_count(struct msm_vidc_inst *inst,
  201. enum msm_vidc_port_type port)
  202. {
  203. int rc = 0;
  204. u32 poc = 1;
  205. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  206. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  207. return -EINVAL;
  208. }
  209. rc = venus_hfi_session_property(inst,
  210. HFI_PROP_PIC_ORDER_CNT_TYPE,
  211. HFI_HOST_FLAGS_NONE,
  212. get_hfi_port(inst, port),
  213. HFI_PAYLOAD_U32,
  214. &poc,
  215. sizeof(u32));
  216. if (rc)
  217. return rc;
  218. return 0;
  219. }
  220. static int msm_vdec_set_colorspace(struct msm_vidc_inst *inst,
  221. enum msm_vidc_port_type port)
  222. {
  223. int rc = 0;
  224. u32 colorspace;
  225. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  226. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  227. return -EINVAL;
  228. }
  229. colorspace = inst->fmts[OUTPUT_PORT].fmt.pix_mp.colorspace;
  230. rc = venus_hfi_session_property(inst,
  231. HFI_PROP_SIGNAL_COLOR_INFO,
  232. HFI_HOST_FLAGS_NONE,
  233. get_hfi_port(inst, port),
  234. HFI_PAYLOAD_U32,
  235. &colorspace,
  236. sizeof(u32));
  237. if (rc)
  238. return rc;
  239. return 0;
  240. }
  241. static int msm_vdec_set_colorformat(struct msm_vidc_inst *inst,
  242. enum msm_vidc_port_type port)
  243. {
  244. int rc = 0;
  245. u32 pixelformat;
  246. enum msm_vidc_colorformat_type colorformat;
  247. u32 hfi_colorformat;
  248. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  249. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  250. return -EINVAL;
  251. }
  252. pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat;
  253. if (pixelformat != V4L2_PIX_FMT_NV12_UBWC &&
  254. pixelformat != V4L2_PIX_FMT_NV12_TP10_UBWC) {
  255. s_vpr_e(inst->sid, "%s: invalid pixelformat %#x\n",
  256. __func__, pixelformat);
  257. return -EINVAL;
  258. }
  259. colorformat = v4l2_colorformat_to_driver(pixelformat, __func__);
  260. hfi_colorformat = get_hfi_colorformat(inst, colorformat);
  261. rc = venus_hfi_session_property(inst,
  262. HFI_PROP_COLOR_FORMAT,
  263. HFI_HOST_FLAGS_NONE,
  264. get_hfi_port(inst, port),
  265. HFI_PAYLOAD_U32,
  266. &hfi_colorformat,
  267. sizeof(u32));
  268. if (rc)
  269. return rc;
  270. return 0;
  271. }
  272. static int msm_vdec_set_stage(struct msm_vidc_inst *inst,
  273. enum msm_vidc_port_type port)
  274. {
  275. int rc = 0;
  276. struct msm_vidc_core *core = inst->core;
  277. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  278. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  279. return -EINVAL;
  280. }
  281. rc = call_session_op(core, decide_work_mode, inst);
  282. if (rc) {
  283. s_vpr_e(inst->sid, "%s: decide_work_mode failed %d\n",
  284. __func__, port);
  285. return -EINVAL;
  286. }
  287. rc = venus_hfi_session_property(inst,
  288. HFI_PROP_STAGE,
  289. HFI_HOST_FLAGS_NONE,
  290. get_hfi_port(inst, port),
  291. HFI_PAYLOAD_U32,
  292. &inst->stage,
  293. sizeof(u32));
  294. if (rc)
  295. return rc;
  296. return 0;
  297. }
  298. static int msm_vdec_set_pipe(struct msm_vidc_inst *inst,
  299. enum msm_vidc_port_type port)
  300. {
  301. int rc = 0;
  302. struct msm_vidc_core *core = inst->core;
  303. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  304. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  305. return -EINVAL;
  306. }
  307. rc = call_session_op(core, decide_work_route, inst);
  308. if (rc) {
  309. s_vpr_e(inst->sid, "%s: decide_work_route failed %d\n",
  310. __func__, port);
  311. return -EINVAL;
  312. }
  313. rc = venus_hfi_session_property(inst,
  314. HFI_PROP_PIPE,
  315. HFI_HOST_FLAGS_NONE,
  316. get_hfi_port(inst, port),
  317. HFI_PAYLOAD_U32,
  318. &inst->pipe,
  319. sizeof(u32));
  320. if (rc)
  321. return rc;
  322. return 0;
  323. }
  324. static int msm_vdec_set_input_properties(struct msm_vidc_inst *inst)
  325. {
  326. int rc = 0;
  327. int i = 0;
  328. d_vpr_h("%s()\n", __func__);
  329. if (!inst) {
  330. d_vpr_e("%s: invalid params\n", __func__);
  331. return -EINVAL;
  332. }
  333. for (i = 0; i < ARRAY_SIZE(msm_vdec_subscribe_for_port_settings_change);
  334. i++) {
  335. switch (msm_vdec_subscribe_for_port_settings_change[i]) {
  336. case HFI_PROP_ALIGN_RESOLUTION:
  337. rc = msm_vdec_set_resolution(inst, INPUT_PORT);
  338. break;
  339. case HFI_PROP_CROP_COORDINATE_TOP_LEFT:
  340. rc = msm_vdec_set_crop_top_left(inst, INPUT_PORT);
  341. break;
  342. case HFI_PROP_CROP_RESOLUTION:
  343. rc = msm_vdec_set_crop_resolution(inst, INPUT_PORT);
  344. break;
  345. case HFI_PROP_LUMA_CHROMA_BIT_DEPTH:
  346. rc = msm_vdec_set_bit_depth(inst, INPUT_PORT);
  347. break;
  348. case HFI_PROP_CABAC_SESSION:
  349. rc = msm_vdec_set_cabac(inst, INPUT_PORT);
  350. break;
  351. case HFI_PROP_CODED_FRAMES:
  352. rc = msm_vdec_set_coded_frames(inst, INPUT_PORT);
  353. break;
  354. case HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT:
  355. rc = msm_vdec_set_min_output_count(inst, INPUT_PORT);
  356. break;
  357. case HFI_PROP_PIC_ORDER_CNT_TYPE:
  358. rc = msm_vdec_set_picture_order_count(inst, INPUT_PORT);
  359. break;
  360. case HFI_PROP_SIGNAL_COLOR_INFO:
  361. rc = msm_vdec_set_colorspace(inst, INPUT_PORT);
  362. break;
  363. default:
  364. d_vpr_e("%s: unknown property %#x\n", __func__,
  365. msm_vdec_subscribe_for_port_settings_change[i]);
  366. rc = -EINVAL;
  367. break;
  368. }
  369. }
  370. return rc;
  371. }
  372. static int msm_vdec_set_output_properties(struct msm_vidc_inst *inst)
  373. {
  374. int rc = 0;
  375. int i = 0;
  376. d_vpr_h("%s()\n", __func__);
  377. if (!inst) {
  378. d_vpr_e("%s: invalid params\n", __func__);
  379. return -EINVAL;
  380. }
  381. rc = msm_vdec_set_colorformat(inst, OUTPUT_PORT);
  382. if (rc)
  383. return rc;
  384. rc = msm_vdec_set_stage(inst, OUTPUT_PORT);
  385. if (rc)
  386. return rc;
  387. rc = msm_vdec_set_pipe(inst, OUTPUT_PORT);
  388. if (rc)
  389. return rc;
  390. for (i = 0; i < ARRAY_SIZE(msm_vdec_subscribe_for_port_settings_change);
  391. i++) {
  392. switch (msm_vdec_subscribe_for_port_settings_change[i]) {
  393. case HFI_PROP_ALIGN_RESOLUTION:
  394. rc = msm_vdec_set_resolution(inst, OUTPUT_PORT);
  395. break;
  396. case HFI_PROP_CROP_COORDINATE_TOP_LEFT:
  397. rc = msm_vdec_set_crop_top_left(inst, OUTPUT_PORT);
  398. break;
  399. case HFI_PROP_CROP_RESOLUTION:
  400. rc = msm_vdec_set_crop_resolution(inst, OUTPUT_PORT);
  401. break;
  402. case HFI_PROP_LUMA_CHROMA_BIT_DEPTH:
  403. rc = msm_vdec_set_bit_depth(inst, OUTPUT_PORT);
  404. break;
  405. case HFI_PROP_CABAC_SESSION:
  406. rc = msm_vdec_set_cabac(inst, OUTPUT_PORT);
  407. break;
  408. case HFI_PROP_CODED_FRAMES:
  409. rc = msm_vdec_set_coded_frames(inst, OUTPUT_PORT);
  410. break;
  411. case HFI_PROP_BUFFER_FW_MIN_OUTPUT_COUNT:
  412. rc = msm_vdec_set_min_output_count(inst, OUTPUT_PORT);
  413. break;
  414. case HFI_PROP_PIC_ORDER_CNT_TYPE:
  415. rc = msm_vdec_set_picture_order_count(inst, OUTPUT_PORT);
  416. break;
  417. case HFI_PROP_SIGNAL_COLOR_INFO:
  418. rc = msm_vdec_set_colorspace(inst, OUTPUT_PORT);
  419. break;
  420. default:
  421. d_vpr_e("%s: unknown property %#x\n", __func__,
  422. msm_vdec_subscribe_for_port_settings_change[i]);
  423. rc = -EINVAL;
  424. break;
  425. }
  426. }
  427. return rc;
  428. }
  429. static int msm_vdec_get_input_internal_buffers(struct msm_vidc_inst *inst)
  430. {
  431. int rc = 0;
  432. struct msm_vidc_core *core;
  433. if (!inst || !inst->core) {
  434. d_vpr_e("%s: invalid params\n", __func__);
  435. return -EINVAL;
  436. }
  437. core = inst->core;
  438. inst->buffers.bin.size = call_session_op(core, buffer_size,
  439. inst, MSM_VIDC_BUF_BIN);
  440. inst->buffers.comv.size = call_session_op(core, buffer_size,
  441. inst, MSM_VIDC_BUF_COMV);
  442. inst->buffers.non_comv.size = call_session_op(core, buffer_size,
  443. inst, MSM_VIDC_BUF_NON_COMV);
  444. inst->buffers.line.size = call_session_op(core, buffer_size,
  445. inst, MSM_VIDC_BUF_LINE);
  446. inst->buffers.persist.size = call_session_op(core, buffer_size,
  447. inst, MSM_VIDC_BUF_PERSIST);
  448. inst->buffers.bin.min_count = call_session_op(core, min_count,
  449. inst, MSM_VIDC_BUF_BIN);
  450. inst->buffers.comv.min_count = call_session_op(core, min_count,
  451. inst, MSM_VIDC_BUF_COMV);
  452. inst->buffers.non_comv.min_count = call_session_op(core, min_count,
  453. inst, MSM_VIDC_BUF_NON_COMV);
  454. inst->buffers.line.min_count = call_session_op(core, min_count,
  455. inst, MSM_VIDC_BUF_LINE);
  456. inst->buffers.persist.min_count = call_session_op(core, min_count,
  457. inst, MSM_VIDC_BUF_PERSIST);
  458. s_vpr_h(inst->sid, "internal buffer: min size\n");
  459. s_vpr_h(inst->sid, "bin buffer: %d %d\n",
  460. inst->buffers.bin.min_count,
  461. inst->buffers.bin.size);
  462. s_vpr_h(inst->sid, "comv buffer: %d %d\n",
  463. inst->buffers.comv.min_count,
  464. inst->buffers.comv.size);
  465. s_vpr_h(inst->sid, "non_comv buffer: %d %d\n",
  466. inst->buffers.non_comv.min_count,
  467. inst->buffers.non_comv.size);
  468. s_vpr_h(inst->sid, "line buffer: %d %d\n",
  469. inst->buffers.line.min_count,
  470. inst->buffers.line.size);
  471. s_vpr_h(inst->sid, "persist buffer: %d %d\n",
  472. inst->buffers.persist.min_count,
  473. inst->buffers.persist.size);
  474. return rc;
  475. }
  476. static int msm_vdec_create_input_internal_buffers(struct msm_vidc_inst *inst)
  477. {
  478. int rc = 0;
  479. d_vpr_h("%s()\n", __func__);
  480. if (!inst || !inst->core) {
  481. d_vpr_e("%s: invalid params\n", __func__);
  482. return -EINVAL;
  483. }
  484. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  485. if (rc)
  486. return rc;
  487. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  488. if (rc)
  489. return rc;
  490. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  491. if (rc)
  492. return rc;
  493. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  494. if (rc)
  495. return rc;
  496. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
  497. if (rc)
  498. return rc;
  499. return 0;
  500. }
  501. static int msm_vdec_queue_input_internal_buffers(struct msm_vidc_inst *inst)
  502. {
  503. int rc = 0;
  504. d_vpr_h("%s()\n", __func__);
  505. if (!inst || !inst->core) {
  506. d_vpr_e("%s: invalid params\n", __func__);
  507. return -EINVAL;
  508. }
  509. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  510. if (rc)
  511. return rc;
  512. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  513. if (rc)
  514. return rc;
  515. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  516. if (rc)
  517. return rc;
  518. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  519. if (rc)
  520. return rc;
  521. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
  522. if (rc)
  523. return rc;
  524. return 0;
  525. }
  526. /*
  527. static int msm_vdec_release_input_internal_buffers(struct msm_vidc_inst *inst)
  528. {
  529. int rc = 0;
  530. d_vpr_h("%s()\n", __func__);
  531. if (!inst || !inst->core) {
  532. d_vpr_e("%s: invalid params\n", __func__);
  533. return -EINVAL;
  534. }
  535. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_SCRATCH);
  536. if (rc)
  537. return rc;
  538. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_SCRATCH_1);
  539. if (rc)
  540. return rc;
  541. rc = msm_vidc_release_internal_buffers(inst, MSM_VIDC_BUF_PERSIST_1);
  542. if (rc)
  543. return rc;
  544. return 0;
  545. }
  546. */
  547. static int msm_vdec_port_settings_subscription(struct msm_vidc_inst *inst,
  548. enum msm_vidc_port_type port)
  549. {
  550. int rc = 0;
  551. struct msm_vidc_core *core;
  552. u32 payload[32] = {0};
  553. u32 i;
  554. if (!inst || !inst->core) {
  555. d_vpr_e("%s: invalid params\n", __func__);
  556. return -EINVAL;
  557. }
  558. core = inst->core;
  559. d_vpr_h("%s()\n", __func__);
  560. payload[0] = HFI_MODE_PORT_SETTINGS_CHANGE;
  561. for (i = 0; i < ARRAY_SIZE(msm_vdec_subscribe_for_port_settings_change);
  562. i++)
  563. payload[i + 1] = msm_vdec_subscribe_for_port_settings_change[i];
  564. rc = venus_hfi_session_command(inst,
  565. HFI_CMD_SUBSCRIBE_MODE,
  566. port,
  567. HFI_PAYLOAD_U32_ARRAY,
  568. &payload[0],
  569. (ARRAY_SIZE(msm_vdec_subscribe_for_port_settings_change) + 1) *
  570. sizeof(u32));
  571. return rc;
  572. }
  573. static int msm_vdec_property_subscription(struct msm_vidc_inst *inst,
  574. enum msm_vidc_port_type port)
  575. {
  576. int rc = 0;
  577. struct msm_vidc_core *core;
  578. u32 payload[32] = {0};
  579. u32 i;
  580. if (!inst || !inst->core) {
  581. d_vpr_e("%s: invalid params\n", __func__);
  582. return -EINVAL;
  583. }
  584. core = inst->core;
  585. d_vpr_h("%s()\n", __func__);
  586. payload[0] = HFI_MODE_PROPERTY;
  587. for (i = 0; i < ARRAY_SIZE(msm_vdec_subscribe_for_properties); i++)
  588. payload[i + 1] = msm_vdec_subscribe_for_properties[i];
  589. rc = venus_hfi_session_command(inst,
  590. HFI_CMD_SUBSCRIBE_MODE,
  591. port,
  592. HFI_PAYLOAD_U32_ARRAY,
  593. &payload[0],
  594. (ARRAY_SIZE(msm_vdec_subscribe_for_properties) + 1) *
  595. sizeof(u32));
  596. return rc;
  597. }
  598. static int msm_vdec_metadata_subscription(struct msm_vidc_inst *inst,
  599. enum msm_vidc_port_type port)
  600. {
  601. int rc = 0;
  602. struct msm_vidc_core *core;
  603. u32 payload[32] = {0};
  604. u32 i;
  605. if (!inst || !inst->core) {
  606. d_vpr_e("%s: invalid params\n", __func__);
  607. return -EINVAL;
  608. }
  609. core = inst->core;
  610. d_vpr_h("%s()\n", __func__);
  611. payload[0] = HFI_MODE_METADATA;
  612. for (i = 0; i < ARRAY_SIZE(msm_vdec_subscribe_for_metadata); i++)
  613. payload[i + 1] = msm_vdec_subscribe_for_metadata[i];
  614. rc = venus_hfi_session_command(inst,
  615. HFI_CMD_SUBSCRIBE_MODE,
  616. port,
  617. HFI_PAYLOAD_U32_ARRAY,
  618. &payload[0],
  619. (ARRAY_SIZE(msm_vdec_subscribe_for_metadata) + 1) *
  620. sizeof(u32));
  621. return rc;
  622. }
  623. static int msm_vdec_metadata_delivery(struct msm_vidc_inst *inst,
  624. enum msm_vidc_port_type port)
  625. {
  626. int rc = 0;
  627. struct msm_vidc_core *core;
  628. u32 payload[32] = {0};
  629. u32 i;
  630. if (!inst || !inst->core) {
  631. d_vpr_e("%s: invalid params\n", __func__);
  632. return -EINVAL;
  633. }
  634. core = inst->core;
  635. d_vpr_h("%s()\n", __func__);
  636. payload[0] = HFI_MODE_METADATA;
  637. for (i = 0; i < ARRAY_SIZE(msm_vdec_deliver_as_metadata); i++)
  638. payload[i + 1] = msm_vdec_deliver_as_metadata[i];
  639. rc = venus_hfi_session_command(inst,
  640. HFI_CMD_DELIVERY_MODE,
  641. port,
  642. HFI_PAYLOAD_U32_ARRAY,
  643. &payload[0],
  644. (ARRAY_SIZE(msm_vdec_deliver_as_metadata) + 1) *
  645. sizeof(u32));
  646. return rc;
  647. }
  648. int msm_vdec_stop_input(struct msm_vidc_inst *inst)
  649. {
  650. int rc = 0;
  651. if (!inst || !inst->core) {
  652. d_vpr_e("%s: invalid params\n", __func__);
  653. return -EINVAL;
  654. }
  655. rc = msm_vidc_session_stop(inst, INPUT_PORT);
  656. if (rc)
  657. return rc;
  658. return 0;
  659. }
  660. int msm_vdec_start_input(struct msm_vidc_inst *inst)
  661. {
  662. int rc = 0;
  663. struct msm_vidc_core *core;
  664. if (!inst || !inst->core) {
  665. d_vpr_e("%s: invalid params\n", __func__);
  666. return -EINVAL;
  667. }
  668. core = inst->core;
  669. s_vpr_h(inst->sid, "%s()\n", __func__);
  670. //rc = msm_vidc_check_session_supported(inst);
  671. if (rc)
  672. goto error;
  673. //rc = msm_vidc_check_scaling_supported(inst);
  674. if (rc)
  675. goto error;
  676. rc = msm_vdec_set_input_properties(inst);
  677. if (rc)
  678. goto error;
  679. /* Decide bse vpp delay after work mode */
  680. //msm_vidc_set_bse_vpp_delay(inst);
  681. rc = msm_vdec_get_input_internal_buffers(inst);
  682. if (rc)
  683. goto error;
  684. /* check for memory after all buffers calculation */
  685. //rc = msm_vidc_check_memory_supported(inst);
  686. if (rc)
  687. goto error;
  688. //msm_vidc_update_dcvs(inst);
  689. //msm_vidc_update_batching(inst);
  690. //msm_vidc_scale_power(inst);
  691. rc = msm_vdec_create_input_internal_buffers(inst);
  692. rc = 0; // TODO
  693. if (rc)
  694. goto error;
  695. rc = msm_vdec_queue_input_internal_buffers(inst);
  696. rc = 0; // TODO
  697. if (rc)
  698. goto error;
  699. rc = msm_vdec_port_settings_subscription(inst, INPUT_PORT);
  700. if (rc)
  701. return rc;
  702. rc = msm_vdec_property_subscription(inst, INPUT_PORT);
  703. if (rc)
  704. return rc;
  705. rc = msm_vdec_metadata_delivery(inst, INPUT_PORT);
  706. if (rc)
  707. return rc;
  708. rc = venus_hfi_start(inst, INPUT_PORT);
  709. if (rc)
  710. goto error;
  711. s_vpr_h(inst->sid, "%s: done\n", __func__);
  712. return 0;
  713. error:
  714. s_vpr_e(inst->sid, "%s: failed\n", __func__);
  715. msm_vdec_stop_input(inst);
  716. return rc;
  717. }
  718. int msm_vdec_stop_output(struct msm_vidc_inst *inst)
  719. {
  720. int rc = 0;
  721. if (!inst || !inst->core) {
  722. d_vpr_e("%s: invalid params\n", __func__);
  723. return -EINVAL;
  724. }
  725. rc = msm_vidc_session_stop(inst, OUTPUT_PORT);
  726. if (rc)
  727. return rc;
  728. return 0;
  729. }
  730. int msm_vdec_start_output(struct msm_vidc_inst *inst)
  731. {
  732. int rc = 0;
  733. d_vpr_h("%s()\n", __func__);
  734. if (!inst || !inst->core) {
  735. d_vpr_e("%s: invalid params\n", __func__);
  736. return -EINVAL;
  737. }
  738. rc = msm_vdec_set_output_properties(inst);
  739. if (rc)
  740. goto error;
  741. rc = msm_vdec_port_settings_subscription(inst, OUTPUT_PORT);
  742. if (rc)
  743. return rc;
  744. rc = msm_vdec_metadata_subscription(inst, OUTPUT_PORT);
  745. if (rc)
  746. return rc;
  747. rc = venus_hfi_start(inst, OUTPUT_PORT);
  748. if (rc)
  749. goto error;
  750. d_vpr_h("%s: done\n", __func__);
  751. return 0;
  752. error:
  753. msm_vdec_stop_output(inst);
  754. return rc;
  755. }
  756. static int msm_vdec_qbuf_batch(struct msm_vidc_inst *inst,
  757. struct vb2_buffer *vb2)
  758. {
  759. int rc = 0;
  760. if (!inst || !vb2) {
  761. d_vpr_e("%s: invalid params\n", __func__);
  762. return -EINVAL;
  763. }
  764. d_vpr_h("%s()\n", __func__);
  765. return rc;
  766. }
  767. int msm_vdec_qbuf(struct msm_vidc_inst *inst, struct vb2_buffer *vb2)
  768. {
  769. int rc = 0;
  770. if (inst->decode_batch.enable)
  771. rc = msm_vdec_qbuf_batch(inst, vb2);
  772. else
  773. rc = msm_vidc_queue_buffer(inst, vb2);
  774. return rc;
  775. }
  776. int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  777. {
  778. int rc = 0;
  779. struct msm_vidc_core *core;
  780. struct v4l2_format *fmt;
  781. d_vpr_h("%s()\n", __func__);
  782. if (!inst || !inst->core) {
  783. d_vpr_e("%s: invalid params\n", __func__);
  784. return -EINVAL;
  785. }
  786. core = inst->core;
  787. if (inst->state == MSM_VIDC_START) {
  788. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  789. return -EINVAL;
  790. }
  791. if (f->type == INPUT_MPLANE) {
  792. if (inst->state == MSM_VIDC_START_INPUT) {
  793. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  794. return -EINVAL;
  795. }
  796. if (inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat !=
  797. f->fmt.pix_mp.pixelformat) {
  798. s_vpr_e(inst->sid,
  799. "%s: codec changed from %#x to %#x\n", __func__,
  800. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat,
  801. f->fmt.pix_mp.pixelformat);
  802. rc = msm_vdec_codec_change(inst, f->fmt.pix_mp.pixelformat);
  803. if (rc)
  804. goto err_invalid_fmt;
  805. }
  806. fmt = &inst->fmts[INPUT_PORT];
  807. fmt->type = INPUT_MPLANE;
  808. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, 16);
  809. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, 16);
  810. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  811. fmt->fmt.pix_mp.num_planes = 1;
  812. fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  813. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  814. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  815. inst->buffers.input.min_count = call_session_op(core,
  816. min_count, inst, MSM_VIDC_BUF_INPUT);
  817. inst->buffers.input.extra_count = call_session_op(core,
  818. extra_count, inst, MSM_VIDC_BUF_INPUT);
  819. if (inst->buffers.input.actual_count <
  820. inst->buffers.input.min_count +
  821. inst->buffers.input.extra_count) {
  822. inst->buffers.input.actual_count =
  823. inst->buffers.input.min_count +
  824. inst->buffers.input.extra_count;
  825. }
  826. inst->buffers.input.size =
  827. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  828. /* update crop dimensions */
  829. inst->crop.x = inst->crop.y = 0;
  830. inst->crop.width = f->fmt.pix_mp.width;
  831. inst->crop.height = f->fmt.pix_mp.height;
  832. //rc = msm_vidc_check_session_supported(inst);
  833. if (rc)
  834. goto err_invalid_fmt;
  835. //update_log_ctxt(inst->sid, inst->session_type,
  836. // mplane->pixelformat);
  837. s_vpr_h(inst->sid,
  838. "%s: input: codec %#x width %d height %d size %d min_count %d extra_count %d\n",
  839. __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width,
  840. f->fmt.pix_mp.height,
  841. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  842. inst->buffers.input.min_count,
  843. inst->buffers.input.extra_count);
  844. //msm_vidc_update_dcvs(inst);
  845. //msm_vidc_update_batching(inst);
  846. } else if (f->type == INPUT_META_PLANE) {
  847. if (inst->state == MSM_VIDC_START_INPUT) {
  848. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  849. return -EINVAL;
  850. }
  851. fmt = &inst->fmts[INPUT_META_PORT];
  852. fmt->type = INPUT_META_PLANE;
  853. fmt->fmt.meta.dataformat = V4L2_PIX_FMT_VIDC_META;
  854. fmt->fmt.meta.buffersize = call_session_op(core, buffer_size,
  855. inst, MSM_VIDC_BUF_INPUT_META);
  856. inst->buffers.input_meta.min_count =
  857. inst->buffers.input.min_count;
  858. inst->buffers.input_meta.extra_count =
  859. inst->buffers.input.extra_count;
  860. inst->buffers.input_meta.actual_count =
  861. inst->buffers.input.actual_count;
  862. inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
  863. s_vpr_h(inst->sid,
  864. "%s: input meta: size %d min_count %d extra_count %d\n",
  865. __func__, fmt->fmt.meta.buffersize,
  866. inst->buffers.input_meta.min_count,
  867. inst->buffers.input_meta.extra_count);
  868. } else if (f->type == OUTPUT_MPLANE) {
  869. if (inst->state == MSM_VIDC_START_OUTPUT) {
  870. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  871. return -EINVAL;
  872. }
  873. fmt = &inst->fmts[OUTPUT_PORT];
  874. fmt->type = OUTPUT_MPLANE;
  875. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  876. fmt->fmt.pix_mp.width = VENUS_Y_STRIDE(
  877. v4l2_colorformat_to_media(
  878. fmt->fmt.pix_mp.pixelformat, __func__),
  879. f->fmt.pix_mp.width);
  880. fmt->fmt.pix_mp.height = VENUS_Y_SCANLINES(
  881. v4l2_colorformat_to_media(
  882. fmt->fmt.pix_mp.pixelformat, __func__),
  883. f->fmt.pix_mp.height);
  884. fmt->fmt.pix_mp.num_planes = 1;
  885. fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
  886. fmt->fmt.pix_mp.width;
  887. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  888. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  889. inst->buffers.output.min_count = call_session_op(core,
  890. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  891. inst->buffers.output.extra_count = call_session_op(core,
  892. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  893. if (inst->buffers.output.actual_count <
  894. inst->buffers.output.min_count +
  895. inst->buffers.output.extra_count) {
  896. inst->buffers.output.actual_count =
  897. inst->buffers.output.min_count +
  898. inst->buffers.output.extra_count;
  899. }
  900. inst->buffers.output.size =
  901. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  902. //rc = msm_vidc_check_session_supported(inst);
  903. if (rc)
  904. goto err_invalid_fmt;
  905. s_vpr_h(inst->sid,
  906. "%s: output: format %#x width %d height %d size %d min_count %d extra_count %d\n",
  907. __func__, fmt->fmt.pix_mp.pixelformat, fmt->fmt.pix_mp.width,
  908. fmt->fmt.pix_mp.height,
  909. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  910. inst->buffers.output.min_count,
  911. inst->buffers.output.extra_count);
  912. } else if (f->type == OUTPUT_META_PLANE) {
  913. if (inst->state == MSM_VIDC_START_OUTPUT) {
  914. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  915. return -EINVAL;
  916. }
  917. fmt = &inst->fmts[OUTPUT_META_PORT];
  918. fmt->type = OUTPUT_META_PLANE;
  919. fmt->fmt.meta.dataformat = V4L2_PIX_FMT_VIDC_META;
  920. fmt->fmt.meta.buffersize = call_session_op(core, buffer_size,
  921. inst, MSM_VIDC_BUF_OUTPUT_META);
  922. inst->buffers.output_meta.min_count =
  923. inst->buffers.output.min_count;
  924. inst->buffers.output_meta.extra_count =
  925. inst->buffers.output.extra_count;
  926. inst->buffers.output_meta.actual_count =
  927. inst->buffers.output.actual_count;
  928. inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
  929. s_vpr_h(inst->sid,
  930. "%s: output meta: size %d min_count %d extra_count %d\n",
  931. __func__, fmt->fmt.meta.buffersize,
  932. inst->buffers.output_meta.min_count,
  933. inst->buffers.output_meta.extra_count);
  934. } else {
  935. s_vpr_e(inst->sid, "%s: invalid type %d\n", __func__, f->type);
  936. goto err_invalid_fmt;
  937. }
  938. memcpy(f, fmt, sizeof(struct v4l2_format));
  939. err_invalid_fmt:
  940. return rc;
  941. }
  942. int msm_vdec_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  943. {
  944. int rc = 0;
  945. int port;
  946. d_vpr_h("%s()\n", __func__);
  947. if (!inst) {
  948. d_vpr_e("%s: invalid params\n", __func__);
  949. return -EINVAL;
  950. }
  951. port = v4l2_type_to_driver_port(inst, f->type, __func__);
  952. if (port < 0)
  953. return -EINVAL;
  954. memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
  955. return rc;
  956. }
  957. int msm_vdec_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
  958. {
  959. int rc = 0;
  960. struct msm_vidc_core *core;
  961. u32 array[32] = {0};
  962. u32 i = 0, idx = 0;
  963. if (!inst || !inst->core || !inst->capabilities || !f) {
  964. d_vpr_e("%s: invalid params\n", __func__);
  965. return -EINVAL;
  966. }
  967. core = inst->core;
  968. if (f->type == INPUT_MPLANE) {
  969. u32 codecs = core->capabilities[DEC_CODECS].value;
  970. while (codecs) {
  971. if (idx > 31)
  972. break;
  973. if (codecs & BIT(i)) {
  974. array[idx] = codecs & BIT(i);
  975. idx++;
  976. }
  977. i++;
  978. codecs >>= 1;
  979. }
  980. f->pixelformat = v4l2_codec_from_driver(array[f->index],
  981. __func__);
  982. if (!f->pixelformat)
  983. return -EINVAL;
  984. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  985. strlcpy(f->description, "codec", sizeof(f->description));
  986. } else if (f->type == OUTPUT_MPLANE) {
  987. u32 formats = inst->capabilities->cap[PIX_FMTS].step_or_mask;
  988. while (formats) {
  989. if (idx > 31)
  990. break;
  991. if (formats & BIT(i)) {
  992. array[idx] = formats & BIT(i);
  993. idx++;
  994. }
  995. i++;
  996. formats >>= 1;
  997. }
  998. f->pixelformat = v4l2_colorformat_from_driver(array[f->index],
  999. __func__);
  1000. if (!f->pixelformat)
  1001. return -EINVAL;
  1002. strlcpy(f->description, "colorformat", sizeof(f->description));
  1003. } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
  1004. if (!f->index) {
  1005. f->pixelformat = V4L2_PIX_FMT_VIDC_META;
  1006. strlcpy(f->description, "metadata", sizeof(f->description));
  1007. } else {
  1008. return -EINVAL;
  1009. }
  1010. }
  1011. memset(f->reserved, 0, sizeof(f->reserved));
  1012. s_vpr_h(inst->sid, "%s: index %d, %s : %#x, flags %#x\n",
  1013. __func__, f->index, f->description, f->pixelformat, f->flags);
  1014. return rc;
  1015. }
  1016. int msm_vdec_inst_init(struct msm_vidc_inst *inst)
  1017. {
  1018. int rc = 0;
  1019. struct msm_vidc_core *core;
  1020. struct v4l2_format *f;
  1021. d_vpr_h("%s()\n", __func__);
  1022. if (!inst || !inst->core) {
  1023. d_vpr_e("%s: invalid params\n", __func__);
  1024. return -EINVAL;
  1025. }
  1026. core = inst->core;
  1027. INIT_DELAYED_WORK(&inst->decode_batch.work, msm_vidc_batch_handler);
  1028. f = &inst->fmts[INPUT_PORT];
  1029. f->type = INPUT_MPLANE;
  1030. f->fmt.pix_mp.width = DEFAULT_WIDTH;
  1031. f->fmt.pix_mp.height = DEFAULT_HEIGHT;
  1032. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
  1033. f->fmt.pix_mp.num_planes = 1;
  1034. f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  1035. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1036. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  1037. inst->buffers.input.min_count = call_session_op(core,
  1038. min_count, inst, MSM_VIDC_BUF_INPUT);
  1039. inst->buffers.input.extra_count = call_session_op(core,
  1040. extra_count, inst, MSM_VIDC_BUF_INPUT);
  1041. inst->buffers.input.actual_count =
  1042. inst->buffers.input.min_count +
  1043. inst->buffers.input.extra_count;
  1044. inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  1045. inst->crop.x = inst->crop.y = 0;
  1046. inst->crop.width = f->fmt.pix_mp.width;
  1047. inst->crop.height = f->fmt.pix_mp.height;
  1048. f = &inst->fmts[INPUT_META_PORT];
  1049. f->type = INPUT_META_PLANE;
  1050. f->fmt.meta.dataformat = V4L2_PIX_FMT_VIDC_META;
  1051. f->fmt.meta.buffersize = call_session_op(core, buffer_size,
  1052. inst, MSM_VIDC_BUF_INPUT_META);
  1053. inst->buffers.input_meta.min_count = inst->buffers.input.min_count;
  1054. inst->buffers.input_meta.extra_count = inst->buffers.input.extra_count;
  1055. inst->buffers.input_meta.actual_count = inst->buffers.input.actual_count;
  1056. inst->buffers.input_meta.size = f->fmt.meta.buffersize;
  1057. f = &inst->fmts[OUTPUT_PORT];
  1058. f->type = OUTPUT_MPLANE;
  1059. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12_UBWC;
  1060. f->fmt.pix_mp.width = VENUS_Y_STRIDE(
  1061. v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
  1062. DEFAULT_WIDTH);
  1063. f->fmt.pix_mp.height = VENUS_Y_SCANLINES(
  1064. v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
  1065. DEFAULT_HEIGHT);
  1066. f->fmt.pix_mp.num_planes = 1;
  1067. f->fmt.pix_mp.plane_fmt[0].bytesperline = f->fmt.pix_mp.width;
  1068. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1069. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  1070. inst->buffers.output.min_count = call_session_op(core,
  1071. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  1072. inst->buffers.output.extra_count = call_session_op(core,
  1073. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  1074. inst->buffers.output.actual_count =
  1075. inst->buffers.output.min_count +
  1076. inst->buffers.output.extra_count;
  1077. inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  1078. f = &inst->fmts[OUTPUT_META_PORT];
  1079. f->type = OUTPUT_META_PLANE;
  1080. f->fmt.meta.dataformat = V4L2_PIX_FMT_VIDC_META;
  1081. f->fmt.meta.buffersize = call_session_op(core, buffer_size,
  1082. inst, MSM_VIDC_BUF_OUTPUT_META);
  1083. inst->buffers.output_meta.min_count = inst->buffers.output.min_count;
  1084. inst->buffers.output_meta.extra_count = inst->buffers.output.extra_count;
  1085. inst->buffers.output_meta.actual_count = inst->buffers.output.actual_count;
  1086. inst->buffers.output_meta.size = f->fmt.meta.buffersize;
  1087. inst->prop.frame_rate = DEFAULT_FPS << 16;
  1088. inst->prop.operating_rate = DEFAULT_FPS << 16;
  1089. inst->stage = MSM_VIDC_STAGE_2;
  1090. inst->pipe = MSM_VIDC_PIPE_4;
  1091. rc = msm_vdec_codec_change(inst,
  1092. inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat);
  1093. return rc;
  1094. }