msm_venc.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <media/v4l2_vidc_extensions.h>
  6. #include <media/msm_media_info.h>
  7. #include "msm_venc.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_control.h"
  14. #include "msm_vidc_debug.h"
  15. #include "venus_hfi.h"
  16. #include "hfi_packet.h"
  17. u32 msm_venc_input_set_prop[] = {
  18. HFI_PROP_COLOR_FORMAT,
  19. HFI_PROP_ALIGN_RESOLUTION,
  20. HFI_PROP_CROP_COORDINATE_TOP_LEFT,
  21. HFI_PROP_CROP_RESOLUTION,
  22. };
  23. u32 msm_venc_output_set_prop[] = {
  24. HFI_PROP_ALIGN_RESOLUTION,
  25. HFI_PROP_CROP_COORDINATE_TOP_LEFT,
  26. HFI_PROP_CROP_RESOLUTION,
  27. };
  28. u32 msm_venc_input_subscribe_for_properties[] = {
  29. HFI_PROP_TAG_NOT_PROPAGATED_TO_OUTPUT,
  30. };
  31. u32 msm_venc_deliver_as_metadata[] = {
  32. HFI_PROP_BUFFER_TAG,
  33. HFI_PROP_SEI_MASTERING_DISPLAY_COLOUR,
  34. HFI_PROP_SEI_CONTENT_LIGHT_LEVEL,
  35. HFI_PROP_SEI_HDR10PLUS_USERDATA,
  36. HFI_PROP_CVP_STAT_INFO,
  37. };
  38. u32 msm_venc_subscribe_for_metadata[] = {
  39. HFI_PROP_BUFFER_TAG,
  40. HFI_PROP_METADATA_SEQ_HEADER_NAL,
  41. HFI_PROP_TIMESTAMP,
  42. HFI_PROP_LTR_MARK_USE_DETAILS,
  43. HFI_PROP_SUBFRAME_OUTPUT,
  44. HFI_PROP_ENC_QP_METADATA,
  45. };
  46. u32 msm_venc_output_subscribe_for_properties[] = {
  47. HFI_PROP_PICTURE_TYPE,
  48. HFI_PROP_BUFFER_MARK,
  49. };
  50. static int msm_venc_codec_change(struct msm_vidc_inst *inst, u32 v4l2_codec)
  51. {
  52. int rc = 0;
  53. if (inst->codec && inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat == v4l2_codec)
  54. return 0;
  55. s_vpr_h(inst->sid, "%s: codec changed from %#x to %#x\n",
  56. __func__, inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, v4l2_codec);
  57. inst->codec = v4l2_codec_to_driver(v4l2_codec, __func__);
  58. rc = msm_vidc_get_inst_capability(inst);
  59. if (rc)
  60. goto exit;
  61. rc = msm_vidc_ctrl_deinit(inst);
  62. if (rc)
  63. goto exit;
  64. rc = msm_vidc_ctrl_init(inst);
  65. if (rc)
  66. goto exit;
  67. exit:
  68. return rc;
  69. }
  70. static int msm_venc_set_colorformat(struct msm_vidc_inst *inst,
  71. enum msm_vidc_port_type port)
  72. {
  73. int rc = 0;
  74. u32 pixelformat;
  75. enum msm_vidc_colorformat_type colorformat;
  76. u32 hfi_colorformat;
  77. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  78. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  79. return -EINVAL;
  80. }
  81. pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
  82. if (pixelformat != V4L2_PIX_FMT_VIDC_NV12C &&
  83. pixelformat != V4L2_PIX_FMT_VIDC_TP10C) {
  84. s_vpr_e(inst->sid, "%s: invalid pixelformat %#x\n",
  85. __func__, pixelformat);
  86. return -EINVAL;
  87. }
  88. colorformat = v4l2_colorformat_to_driver(pixelformat, __func__);
  89. hfi_colorformat = get_hfi_colorformat(inst, colorformat);
  90. rc = venus_hfi_session_property(inst,
  91. HFI_PROP_COLOR_FORMAT,
  92. HFI_HOST_FLAGS_NONE,
  93. get_hfi_port(inst, port),
  94. HFI_PAYLOAD_U32_ENUM,
  95. &hfi_colorformat,
  96. sizeof(u32));
  97. if (rc)
  98. return rc;
  99. return 0;
  100. }
  101. static int msm_venc_set_resolution(struct msm_vidc_inst *inst,
  102. enum msm_vidc_port_type port)
  103. {
  104. int rc = 0;
  105. u32 resolution;
  106. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  107. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  108. return -EINVAL;
  109. }
  110. resolution = inst->fmts[port].fmt.pix_mp.width << 16 |
  111. inst->fmts[port].fmt.pix_mp.height;
  112. rc = venus_hfi_session_property(inst,
  113. HFI_PROP_ALIGN_RESOLUTION,
  114. HFI_HOST_FLAGS_NONE,
  115. get_hfi_port(inst, port),
  116. HFI_PAYLOAD_32_PACKED,
  117. &resolution,
  118. sizeof(u32));
  119. if (rc)
  120. return rc;
  121. return 0;
  122. }
  123. static int msm_venc_set_crop_top_left(struct msm_vidc_inst *inst,
  124. enum msm_vidc_port_type port)
  125. {
  126. int rc = 0;
  127. u32 crop_top_left;
  128. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  129. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  130. return -EINVAL;
  131. }
  132. crop_top_left = 0;
  133. rc = venus_hfi_session_property(inst,
  134. HFI_PROP_CROP_COORDINATE_TOP_LEFT,
  135. HFI_HOST_FLAGS_NONE,
  136. get_hfi_port(inst, port),
  137. HFI_PAYLOAD_32_PACKED,
  138. &crop_top_left,
  139. sizeof(u32));
  140. if (rc)
  141. return rc;
  142. return 0;
  143. }
  144. static int msm_venc_set_crop_resolution(struct msm_vidc_inst *inst,
  145. enum msm_vidc_port_type port)
  146. {
  147. int rc = 0;
  148. u32 crop;
  149. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  150. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  151. return -EINVAL;
  152. }
  153. /* output buffer resolution is nothing but crop */
  154. crop = inst->fmts[INPUT_PORT].fmt.pix_mp.width << 16 |
  155. inst->fmts[INPUT_PORT].fmt.pix_mp.height;
  156. rc = venus_hfi_session_property(inst,
  157. HFI_PROP_CROP_RESOLUTION,
  158. HFI_HOST_FLAGS_NONE,
  159. get_hfi_port(inst, port),
  160. HFI_PAYLOAD_32_PACKED,
  161. &crop,
  162. sizeof(u32));
  163. if (rc)
  164. return rc;
  165. return 0;
  166. }
  167. static int msm_venc_set_stage(struct msm_vidc_inst *inst)
  168. {
  169. int rc = 0;
  170. struct msm_vidc_core *core = inst->core;
  171. rc = call_session_op(core, decide_work_mode, inst);
  172. if (rc) {
  173. s_vpr_e(inst->sid, "%s: decide_work_mode failed\n",
  174. __func__);
  175. return -EINVAL;
  176. }
  177. rc = venus_hfi_session_property(inst,
  178. HFI_PROP_STAGE,
  179. HFI_HOST_FLAGS_NONE,
  180. HFI_PORT_NONE,
  181. HFI_PAYLOAD_U32,
  182. &inst->stage,
  183. sizeof(u32));
  184. if (rc)
  185. return rc;
  186. return 0;
  187. }
  188. static int msm_venc_set_pipe(struct msm_vidc_inst *inst)
  189. {
  190. int rc = 0;
  191. struct msm_vidc_core *core = inst->core;
  192. rc = call_session_op(core, decide_work_route, inst);
  193. if (rc) {
  194. s_vpr_e(inst->sid, "%s: decide_work_route failed\n",
  195. __func__);
  196. return -EINVAL;
  197. }
  198. rc = venus_hfi_session_property(inst,
  199. HFI_PROP_PIPE,
  200. HFI_HOST_FLAGS_NONE,
  201. HFI_PORT_NONE,
  202. HFI_PAYLOAD_U32,
  203. &inst->pipe,
  204. sizeof(u32));
  205. if (rc)
  206. return rc;
  207. return 0;
  208. }
  209. static int msm_venc_set_input_properties(struct msm_vidc_inst *inst)
  210. {
  211. int rc = 0;
  212. int i = 0;
  213. d_vpr_h("%s()\n", __func__);
  214. if (!inst) {
  215. d_vpr_e("%s: invalid params\n", __func__);
  216. return -EINVAL;
  217. }
  218. for (i = 0; i < ARRAY_SIZE(msm_venc_input_set_prop);
  219. i++) {
  220. switch (msm_venc_input_set_prop[i]) {
  221. case HFI_PROP_COLOR_FORMAT:
  222. rc = msm_venc_set_colorformat(inst, INPUT_PORT);
  223. break;
  224. case HFI_PROP_ALIGN_RESOLUTION:
  225. rc = msm_venc_set_resolution(inst, INPUT_PORT);
  226. break;
  227. case HFI_PROP_CROP_COORDINATE_TOP_LEFT:
  228. rc = msm_venc_set_crop_top_left(inst, INPUT_PORT);
  229. break;
  230. case HFI_PROP_CROP_RESOLUTION:
  231. rc = msm_venc_set_crop_resolution(inst, INPUT_PORT);
  232. break;
  233. default:
  234. d_vpr_e("%s: unknown property %#x\n", __func__,
  235. msm_venc_input_set_prop[i]);
  236. rc = -EINVAL;
  237. break;
  238. }
  239. }
  240. return rc;
  241. }
  242. static int msm_venc_set_output_properties(struct msm_vidc_inst *inst)
  243. {
  244. int rc = 0;
  245. int i = 0;
  246. d_vpr_h("%s()\n", __func__);
  247. if (!inst) {
  248. d_vpr_e("%s: invalid params\n", __func__);
  249. return -EINVAL;
  250. }
  251. //TODO: set HFI_PORT_NONE properties at master port streamon.
  252. rc = msm_venc_set_stage(inst);
  253. if (rc)
  254. return rc;
  255. rc = msm_venc_set_pipe(inst);
  256. if (rc)
  257. return rc;
  258. for (i = 0; i < ARRAY_SIZE(msm_venc_output_set_prop);
  259. i++) {
  260. switch (msm_venc_output_set_prop[i]) {
  261. case HFI_PROP_ALIGN_RESOLUTION:
  262. rc = msm_venc_set_resolution(inst, OUTPUT_PORT);
  263. break;
  264. case HFI_PROP_CROP_COORDINATE_TOP_LEFT:
  265. rc = msm_venc_set_crop_top_left(inst, OUTPUT_PORT);
  266. break;
  267. case HFI_PROP_CROP_RESOLUTION:
  268. rc = msm_venc_set_crop_resolution(inst, OUTPUT_PORT);
  269. break;
  270. default:
  271. d_vpr_e("%s: unknown property %#x\n", __func__,
  272. msm_venc_output_set_prop[i]);
  273. rc = -EINVAL;
  274. break;
  275. }
  276. }
  277. return rc;
  278. }
  279. static int msm_venc_get_input_internal_buffers(struct msm_vidc_inst *inst)
  280. {
  281. int rc = 0;
  282. struct msm_vidc_core *core;
  283. if (!inst || !inst->core) {
  284. d_vpr_e("%s: invalid params\n", __func__);
  285. return -EINVAL;
  286. }
  287. core = inst->core;
  288. inst->buffers.arp.size = call_session_op(core, buffer_size,
  289. inst, MSM_VIDC_BUF_ARP);
  290. inst->buffers.bin.size = call_session_op(core, buffer_size,
  291. inst, MSM_VIDC_BUF_BIN);
  292. /* inst->buffers.comv.size = call_session_op(core, buffer_size,
  293. inst, MSM_VIDC_BUF_COMV);
  294. inst->buffers.non_comv.size = call_session_op(core, buffer_size,
  295. inst, MSM_VIDC_BUF_NON_COMV); */
  296. inst->buffers.line.size = call_session_op(core, buffer_size,
  297. inst, MSM_VIDC_BUF_LINE);
  298. inst->buffers.dpb.size = call_session_op(core, buffer_size,
  299. inst, MSM_VIDC_BUF_DPB);
  300. /* inst->buffers.persist.size = call_session_op(core, buffer_size,
  301. inst, MSM_VIDC_BUF_PERSIST); */
  302. inst->buffers.arp.min_count = call_session_op(core, min_count,
  303. inst, MSM_VIDC_BUF_ARP);
  304. inst->buffers.bin.min_count = call_session_op(core, min_count,
  305. inst, MSM_VIDC_BUF_BIN);
  306. /* inst->buffers.comv.min_count = call_session_op(core, min_count,
  307. inst, MSM_VIDC_BUF_COMV);
  308. inst->buffers.non_comv.min_count = call_session_op(core, min_count,
  309. inst, MSM_VIDC_BUF_NON_COMV); */
  310. inst->buffers.line.min_count = call_session_op(core, min_count,
  311. inst, MSM_VIDC_BUF_LINE);
  312. inst->buffers.dpb.min_count = call_session_op(core, min_count,
  313. inst, MSM_VIDC_BUF_DPB);
  314. /* inst->buffers.persist.min_count = call_session_op(core, min_count,
  315. inst, MSM_VIDC_BUF_PERSIST); */
  316. s_vpr_h(inst->sid, "internal buffer: min size\n");
  317. s_vpr_h(inst->sid, "arp buffer: %d %d\n",
  318. inst->buffers.arp.min_count,
  319. inst->buffers.arp.size);
  320. s_vpr_h(inst->sid, "bin buffer: %d %d\n",
  321. inst->buffers.bin.min_count,
  322. inst->buffers.bin.size);
  323. /* s_vpr_h(inst->sid, "comv buffer: %d %d\n",
  324. inst->buffers.comv.min_count,
  325. inst->buffers.comv.size);
  326. s_vpr_h(inst->sid, "non_comv buffer: %d %d\n",
  327. inst->buffers.non_comv.min_count,
  328. inst->buffers.non_comv.size); */
  329. s_vpr_h(inst->sid, "line buffer: %d %d\n",
  330. inst->buffers.line.min_count,
  331. inst->buffers.line.size);
  332. s_vpr_h(inst->sid, "dpb buffer: %d %d\n",
  333. inst->buffers.dpb.min_count,
  334. inst->buffers.dpb.size);
  335. /* s_vpr_h(inst->sid, "persist buffer: %d %d\n",
  336. inst->buffers.persist.min_count,
  337. inst->buffers.persist.size); */
  338. return rc;
  339. }
  340. static int msm_venc_create_input_internal_buffers(struct msm_vidc_inst *inst)
  341. {
  342. int rc = 0;
  343. d_vpr_h("%s()\n", __func__);
  344. if (!inst || !inst->core) {
  345. d_vpr_e("%s: invalid params\n", __func__);
  346. return -EINVAL;
  347. }
  348. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_ARP);
  349. if (rc)
  350. return rc;
  351. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  352. if (rc)
  353. return rc;
  354. /* rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  355. if (rc)
  356. return rc;
  357. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  358. if (rc)
  359. return rc; */
  360. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  361. if (rc)
  362. return rc;
  363. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  364. if (rc)
  365. return rc;
  366. /* rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
  367. if (rc)
  368. return rc; */
  369. return 0;
  370. }
  371. static int msm_venc_queue_input_internal_buffers(struct msm_vidc_inst *inst)
  372. {
  373. int rc = 0;
  374. d_vpr_h("%s()\n", __func__);
  375. if (!inst || !inst->core) {
  376. d_vpr_e("%s: invalid params\n", __func__);
  377. return -EINVAL;
  378. }
  379. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_ARP);
  380. if (rc)
  381. return rc;
  382. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  383. if (rc)
  384. return rc;
  385. /* rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  386. if (rc)
  387. return rc;
  388. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  389. if (rc)
  390. return rc; */
  391. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  392. if (rc)
  393. return rc;
  394. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  395. if (rc)
  396. return rc;
  397. // TODO: fw is not accepting persist buffer and returning session error.
  398. //rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
  399. if (rc)
  400. return rc;
  401. return 0;
  402. }
  403. static int msm_venc_property_subscription(struct msm_vidc_inst *inst,
  404. enum msm_vidc_port_type port)
  405. {
  406. int rc = 0;
  407. struct msm_vidc_core *core;
  408. u32 payload[32] = {0};
  409. u32 i;
  410. u32 payload_size = 0;
  411. if (!inst || !inst->core) {
  412. d_vpr_e("%s: invalid params\n", __func__);
  413. return -EINVAL;
  414. }
  415. core = inst->core;
  416. d_vpr_h("%s()\n", __func__);
  417. payload[0] = HFI_MODE_PROPERTY;
  418. if (port == INPUT_PORT) {
  419. for (i = 0; i < ARRAY_SIZE(msm_venc_input_subscribe_for_properties); i++)
  420. payload[i + 1] = msm_venc_input_subscribe_for_properties[i];
  421. payload_size = (ARRAY_SIZE(msm_venc_input_subscribe_for_properties) + 1) *
  422. sizeof(u32);
  423. } else if (port == OUTPUT_PORT) {
  424. for (i = 0; i < ARRAY_SIZE(msm_venc_output_subscribe_for_properties); i++)
  425. payload[i + 1] = msm_venc_output_subscribe_for_properties[i];
  426. payload_size = (ARRAY_SIZE(msm_venc_output_subscribe_for_properties) + 1) *
  427. sizeof(u32);
  428. } else {
  429. s_vpr_e(inst->sid, "%s: invalid port: %d\n", __func__, port);
  430. return -EINVAL;
  431. }
  432. rc = venus_hfi_session_command(inst,
  433. HFI_CMD_SUBSCRIBE_MODE,
  434. port,
  435. HFI_PAYLOAD_U32_ARRAY,
  436. &payload[0],
  437. payload_size);
  438. return rc;
  439. }
  440. static int msm_venc_metadata_delivery(struct msm_vidc_inst *inst,
  441. enum msm_vidc_port_type port)
  442. {
  443. int rc = 0;
  444. struct msm_vidc_core *core;
  445. u32 payload[32] = {0};
  446. u32 i;
  447. if (!inst || !inst->core) {
  448. d_vpr_e("%s: invalid params\n", __func__);
  449. return -EINVAL;
  450. }
  451. core = inst->core;
  452. d_vpr_h("%s()\n", __func__);
  453. payload[0] = HFI_MODE_METADATA;
  454. for (i = 0; i < ARRAY_SIZE(msm_venc_deliver_as_metadata); i++)
  455. payload[i + 1] = msm_venc_deliver_as_metadata[i];
  456. rc = venus_hfi_session_command(inst,
  457. HFI_CMD_DELIVERY_MODE,
  458. port,
  459. HFI_PAYLOAD_U32_ARRAY,
  460. &payload[0],
  461. (ARRAY_SIZE(msm_venc_deliver_as_metadata) + 1) *
  462. sizeof(u32));
  463. return rc;
  464. }
  465. static int msm_venc_metadata_subscription(struct msm_vidc_inst *inst,
  466. enum msm_vidc_port_type port)
  467. {
  468. int rc = 0;
  469. struct msm_vidc_core *core;
  470. u32 payload[32] = {0};
  471. u32 i;
  472. if (!inst || !inst->core) {
  473. d_vpr_e("%s: invalid params\n", __func__);
  474. return -EINVAL;
  475. }
  476. core = inst->core;
  477. d_vpr_h("%s()\n", __func__);
  478. payload[0] = HFI_MODE_METADATA;
  479. for (i = 0; i < ARRAY_SIZE(msm_venc_subscribe_for_metadata); i++)
  480. payload[i + 1] = msm_venc_subscribe_for_metadata[i];
  481. rc = venus_hfi_session_command(inst,
  482. HFI_CMD_SUBSCRIBE_MODE,
  483. port,
  484. HFI_PAYLOAD_U32_ARRAY,
  485. &payload[0],
  486. (ARRAY_SIZE(msm_venc_subscribe_for_metadata) + 1) *
  487. sizeof(u32));
  488. return rc;
  489. }
  490. int msm_venc_stop_input(struct msm_vidc_inst *inst)
  491. {
  492. int rc = 0;
  493. if (!inst || !inst->core) {
  494. d_vpr_e("%s: invalid params\n", __func__);
  495. return -EINVAL;
  496. }
  497. rc = msm_vidc_session_stop(inst, INPUT_PORT);
  498. if (rc)
  499. return rc;
  500. return 0;
  501. }
  502. int msm_venc_start_input(struct msm_vidc_inst *inst)
  503. {
  504. int rc = 0;
  505. struct msm_vidc_core *core;
  506. if (!inst || !inst->core) {
  507. d_vpr_e("%s: invalid params\n", __func__);
  508. return -EINVAL;
  509. }
  510. core = inst->core;
  511. s_vpr_h(inst->sid, "%s()\n", __func__);
  512. //rc = msm_vidc_check_session_supported(inst);
  513. if (rc)
  514. goto error;
  515. //rc = msm_vidc_check_scaling_supported(inst);
  516. if (rc)
  517. goto error;
  518. rc = msm_venc_set_input_properties(inst);
  519. if (rc)
  520. goto error;
  521. /* Decide bse vpp delay after work mode */
  522. //msm_vidc_set_bse_vpp_delay(inst);
  523. rc = msm_venc_get_input_internal_buffers(inst);
  524. if (rc)
  525. goto error;
  526. /* check for memory after all buffers calculation */
  527. //rc = msm_vidc_check_memory_supported(inst);
  528. if (rc)
  529. goto error;
  530. //msm_vidc_update_dcvs(inst);
  531. //msm_vidc_update_batching(inst);
  532. //msm_vidc_scale_power(inst);
  533. rc = msm_venc_create_input_internal_buffers(inst);
  534. rc = 0; // TODO
  535. if (rc)
  536. goto error;
  537. rc = msm_venc_queue_input_internal_buffers(inst);
  538. rc = 0; // TODO
  539. if (rc)
  540. goto error;
  541. rc = msm_venc_property_subscription(inst, INPUT_PORT);
  542. if (rc)
  543. return rc;
  544. rc = msm_venc_metadata_delivery(inst, INPUT_PORT);
  545. if (rc)
  546. return rc;
  547. rc = venus_hfi_start(inst, INPUT_PORT);
  548. if (rc)
  549. goto error;
  550. s_vpr_h(inst->sid, "%s: done\n", __func__);
  551. return 0;
  552. error:
  553. s_vpr_e(inst->sid, "%s: failed\n", __func__);
  554. msm_venc_stop_input(inst);
  555. return rc;
  556. }
  557. int msm_venc_stop_output(struct msm_vidc_inst *inst)
  558. {
  559. int rc = 0;
  560. if (!inst || !inst->core) {
  561. d_vpr_e("%s: invalid params\n", __func__);
  562. return -EINVAL;
  563. }
  564. rc = msm_vidc_session_stop(inst, OUTPUT_PORT);
  565. if (rc)
  566. return rc;
  567. return 0;
  568. }
  569. int msm_venc_start_output(struct msm_vidc_inst *inst)
  570. {
  571. int rc = 0;
  572. d_vpr_h("%s()\n", __func__);
  573. if (!inst || !inst->core) {
  574. d_vpr_e("%s: invalid params\n", __func__);
  575. return -EINVAL;
  576. }
  577. rc = msm_venc_set_output_properties(inst);
  578. if (rc)
  579. goto error;
  580. rc = msm_venc_property_subscription(inst, OUTPUT_PORT);
  581. if (rc)
  582. return rc;
  583. rc = msm_venc_metadata_subscription(inst, OUTPUT_PORT);
  584. if (rc)
  585. return rc;
  586. rc = venus_hfi_start(inst, OUTPUT_PORT);
  587. if (rc)
  588. goto error;
  589. d_vpr_h("%s: done\n", __func__);
  590. return 0;
  591. error:
  592. msm_venc_stop_output(inst);
  593. return rc;
  594. }
  595. int msm_venc_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  596. {
  597. int rc = 0;
  598. struct msm_vidc_core *core;
  599. struct v4l2_format *fmt;
  600. d_vpr_h("%s()\n", __func__);
  601. if (!inst || !inst->core) {
  602. d_vpr_e("%s: invalid params\n", __func__);
  603. return -EINVAL;
  604. }
  605. core = inst->core;
  606. if (inst->state == MSM_VIDC_START) {
  607. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  608. return -EINVAL;
  609. }
  610. if (f->type == INPUT_MPLANE) {
  611. if (inst->state == MSM_VIDC_START_INPUT) {
  612. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  613. return -EINVAL;
  614. }
  615. fmt = &inst->fmts[INPUT_PORT];
  616. fmt->type = INPUT_MPLANE;
  617. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  618. fmt->fmt.pix_mp.width = VENUS_Y_STRIDE(
  619. v4l2_colorformat_to_media(fmt->fmt.pix_mp.pixelformat,
  620. __func__),
  621. f->fmt.pix_mp.width);
  622. fmt->fmt.pix_mp.height = VENUS_Y_SCANLINES(
  623. v4l2_colorformat_to_media(fmt->fmt.pix_mp.pixelformat,
  624. __func__),
  625. f->fmt.pix_mp.height);
  626. fmt->fmt.pix_mp.num_planes = 1;
  627. fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
  628. fmt->fmt.pix_mp.width;
  629. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  630. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  631. inst->buffers.input.min_count = call_session_op(core,
  632. min_count, inst, MSM_VIDC_BUF_INPUT);
  633. inst->buffers.input.extra_count = call_session_op(core,
  634. extra_count, inst, MSM_VIDC_BUF_INPUT);
  635. if (inst->buffers.input.actual_count <
  636. inst->buffers.input.min_count +
  637. inst->buffers.input.extra_count) {
  638. inst->buffers.input.actual_count =
  639. inst->buffers.input.min_count +
  640. inst->buffers.input.extra_count;
  641. }
  642. inst->buffers.input.size =
  643. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  644. //rc = msm_vidc_check_session_supported(inst);
  645. if (rc)
  646. goto err_invalid_fmt;
  647. //update_log_ctxt(inst->sid, inst->session_type,
  648. // mplane->pixelformat);
  649. s_vpr_h(inst->sid,
  650. "%s: input: codec %#x width %d height %d size %d min_count %d extra_count %d\n",
  651. __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width,
  652. f->fmt.pix_mp.height,
  653. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  654. inst->buffers.input.min_count,
  655. inst->buffers.input.extra_count);
  656. //msm_vidc_update_dcvs(inst);
  657. //msm_vidc_update_batching(inst);
  658. } else if (f->type == INPUT_META_PLANE) {
  659. if (inst->state == MSM_VIDC_START_INPUT) {
  660. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  661. return -EINVAL;
  662. }
  663. fmt = &inst->fmts[INPUT_META_PORT];
  664. fmt->type = INPUT_META_PLANE;
  665. fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  666. fmt->fmt.meta.buffersize = call_session_op(core, buffer_size,
  667. inst, MSM_VIDC_BUF_INPUT_META);
  668. inst->buffers.input_meta.min_count =
  669. inst->buffers.input.min_count;
  670. inst->buffers.input_meta.extra_count =
  671. inst->buffers.input.extra_count;
  672. inst->buffers.input_meta.actual_count =
  673. inst->buffers.input.actual_count;
  674. inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
  675. s_vpr_h(inst->sid,
  676. "%s: input meta: size %d min_count %d extra_count %d\n",
  677. __func__, fmt->fmt.meta.buffersize,
  678. inst->buffers.input_meta.min_count,
  679. inst->buffers.input_meta.extra_count);
  680. } else if (f->type == OUTPUT_MPLANE) {
  681. if (inst->state == MSM_VIDC_START_OUTPUT) {
  682. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  683. return -EINVAL;
  684. }
  685. fmt = &inst->fmts[OUTPUT_PORT];
  686. if (fmt->fmt.pix_mp.pixelformat != f->fmt.pix_mp.pixelformat) {
  687. s_vpr_e(inst->sid,
  688. "%s: codec changed from %#x to %#x\n", __func__,
  689. fmt->fmt.pix_mp.pixelformat, f->fmt.pix_mp.pixelformat);
  690. rc = msm_venc_codec_change(inst, f->fmt.pix_mp.pixelformat);
  691. if (rc)
  692. goto err_invalid_fmt;
  693. }
  694. fmt->type = OUTPUT_MPLANE;
  695. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, 16);
  696. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, 16);
  697. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  698. fmt->fmt.pix_mp.num_planes = 1;
  699. fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  700. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  701. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  702. inst->buffers.output.min_count = call_session_op(core,
  703. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  704. inst->buffers.output.extra_count = call_session_op(core,
  705. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  706. if (inst->buffers.output.actual_count <
  707. inst->buffers.output.min_count +
  708. inst->buffers.output.extra_count) {
  709. inst->buffers.output.actual_count =
  710. inst->buffers.output.min_count +
  711. inst->buffers.output.extra_count;
  712. }
  713. inst->buffers.output.size =
  714. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  715. //rc = msm_vidc_check_session_supported(inst);
  716. if (rc)
  717. goto err_invalid_fmt;
  718. /* update crop dimensions */
  719. inst->crop.x = inst->crop.y = 0;
  720. inst->crop.width = f->fmt.pix_mp.width;
  721. inst->crop.height = f->fmt.pix_mp.height;
  722. //update_log_ctxt(inst->sid, inst->session_type,
  723. // mplane->pixelformat);
  724. s_vpr_h(inst->sid,
  725. "%s: output: format %#x width %d height %d size %d min_count %d extra_count %d\n",
  726. __func__, fmt->fmt.pix_mp.pixelformat, fmt->fmt.pix_mp.width,
  727. fmt->fmt.pix_mp.height,
  728. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  729. inst->buffers.output.min_count,
  730. inst->buffers.output.extra_count);
  731. } else if (f->type == OUTPUT_META_PLANE) {
  732. if (inst->state == MSM_VIDC_START_OUTPUT) {
  733. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  734. return -EINVAL;
  735. }
  736. fmt = &inst->fmts[OUTPUT_META_PORT];
  737. fmt->type = OUTPUT_META_PLANE;
  738. fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  739. fmt->fmt.meta.buffersize = call_session_op(core, buffer_size,
  740. inst, MSM_VIDC_BUF_OUTPUT_META);
  741. inst->buffers.output_meta.min_count =
  742. inst->buffers.output.min_count;
  743. inst->buffers.output_meta.extra_count =
  744. inst->buffers.output.extra_count;
  745. inst->buffers.output_meta.actual_count =
  746. inst->buffers.output.actual_count;
  747. inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
  748. s_vpr_h(inst->sid,
  749. "%s: output meta: size %d min_count %d extra_count %d\n",
  750. __func__, fmt->fmt.meta.buffersize,
  751. inst->buffers.output_meta.min_count,
  752. inst->buffers.output_meta.extra_count);
  753. } else {
  754. s_vpr_e(inst->sid, "%s: invalid type %d\n", __func__, f->type);
  755. goto err_invalid_fmt;
  756. }
  757. memcpy(f, fmt, sizeof(struct v4l2_format));
  758. err_invalid_fmt:
  759. return rc;
  760. }
  761. int msm_venc_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  762. {
  763. int rc = 0;
  764. int port;
  765. d_vpr_h("%s()\n", __func__);
  766. if (!inst) {
  767. d_vpr_e("%s: invalid params\n", __func__);
  768. return -EINVAL;
  769. }
  770. port = v4l2_type_to_driver_port(inst, f->type, __func__);
  771. if (port < 0)
  772. return -EINVAL;
  773. memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
  774. return rc;
  775. }
  776. int msm_venc_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
  777. {
  778. int rc = 0;
  779. struct msm_vidc_core *core;
  780. u32 array[32] = {0};
  781. u32 i = 0, idx = 0;
  782. if (!inst || !inst->core || !inst->capabilities || !f) {
  783. d_vpr_e("%s: invalid params\n", __func__);
  784. return -EINVAL;
  785. }
  786. core = inst->core;
  787. if (f->type == OUTPUT_MPLANE) {
  788. u32 codecs = core->capabilities[DEC_CODECS].value;
  789. while (codecs) {
  790. if (idx > 31)
  791. break;
  792. if (codecs & BIT(i)) {
  793. array[idx] = codecs & BIT(i);
  794. idx++;
  795. }
  796. i++;
  797. codecs >>= 1;
  798. }
  799. f->pixelformat = v4l2_codec_from_driver(array[f->index],
  800. __func__);
  801. if (!f->pixelformat)
  802. return -EINVAL;
  803. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  804. strlcpy(f->description, "codec", sizeof(f->description));
  805. } else if (f->type == INPUT_MPLANE) {
  806. u32 formats = inst->capabilities->cap[PIX_FMTS].step_or_mask;
  807. while (formats) {
  808. if (idx > 31)
  809. break;
  810. if (formats & BIT(i)) {
  811. array[idx] = formats & BIT(i);
  812. idx++;
  813. }
  814. i++;
  815. formats >>= 1;
  816. }
  817. f->pixelformat = v4l2_colorformat_from_driver(array[f->index],
  818. __func__);
  819. if (!f->pixelformat)
  820. return -EINVAL;
  821. strlcpy(f->description, "colorformat", sizeof(f->description));
  822. } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
  823. if (!f->index) {
  824. f->pixelformat = V4L2_META_FMT_VIDC;
  825. strlcpy(f->description, "metadata", sizeof(f->description));
  826. } else {
  827. return -EINVAL;
  828. }
  829. }
  830. memset(f->reserved, 0, sizeof(f->reserved));
  831. s_vpr_h(inst->sid, "%s: index %d, %s : %#x, flags %#x\n",
  832. __func__, f->index, f->description, f->pixelformat, f->flags);
  833. return rc;
  834. }
  835. int msm_venc_inst_init(struct msm_vidc_inst *inst)
  836. {
  837. int rc = 0;
  838. struct msm_vidc_core *core;
  839. struct v4l2_format *f;
  840. d_vpr_h("%s()\n", __func__);
  841. if (!inst || !inst->core) {
  842. d_vpr_e("%s: invalid params\n", __func__);
  843. return -EINVAL;
  844. }
  845. core = inst->core;
  846. f = &inst->fmts[OUTPUT_PORT];
  847. f->type = OUTPUT_MPLANE;
  848. f->fmt.pix_mp.width = DEFAULT_WIDTH;
  849. f->fmt.pix_mp.height = DEFAULT_HEIGHT;
  850. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
  851. f->fmt.pix_mp.num_planes = 1;
  852. f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  853. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  854. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  855. inst->buffers.output.min_count = call_session_op(core,
  856. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  857. inst->buffers.output.extra_count = call_session_op(core,
  858. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  859. inst->buffers.output.actual_count =
  860. inst->buffers.output.min_count +
  861. inst->buffers.output.extra_count;
  862. inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  863. inst->crop.x = inst->crop.y = 0;
  864. inst->crop.width = f->fmt.pix_mp.width;
  865. inst->crop.height = f->fmt.pix_mp.height;
  866. f = &inst->fmts[OUTPUT_META_PORT];
  867. f->type = OUTPUT_META_PLANE;
  868. f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  869. f->fmt.meta.buffersize = call_session_op(core, buffer_size,
  870. inst, MSM_VIDC_BUF_OUTPUT_META);
  871. inst->buffers.output_meta.min_count = inst->buffers.output.min_count;
  872. inst->buffers.output_meta.extra_count = inst->buffers.output.extra_count;
  873. inst->buffers.output_meta.actual_count = inst->buffers.output.actual_count;
  874. inst->buffers.output_meta.size = f->fmt.meta.buffersize;
  875. f = &inst->fmts[INPUT_PORT];
  876. f->type = INPUT_MPLANE;
  877. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_VIDC_NV12C;
  878. f->fmt.pix_mp.width = VENUS_Y_STRIDE(
  879. v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
  880. DEFAULT_WIDTH);
  881. f->fmt.pix_mp.height = VENUS_Y_SCANLINES(
  882. v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
  883. DEFAULT_HEIGHT);
  884. f->fmt.pix_mp.num_planes = 1;
  885. f->fmt.pix_mp.plane_fmt[0].bytesperline = f->fmt.pix_mp.width;
  886. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  887. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  888. inst->buffers.input.min_count = call_session_op(core,
  889. min_count, inst, MSM_VIDC_BUF_INPUT);
  890. inst->buffers.input.extra_count = call_session_op(core,
  891. extra_count, inst, MSM_VIDC_BUF_INPUT);
  892. inst->buffers.input.actual_count =
  893. inst->buffers.input.min_count +
  894. inst->buffers.input.extra_count;
  895. inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  896. f = &inst->fmts[INPUT_META_PORT];
  897. f->type = INPUT_META_PLANE;
  898. f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  899. f->fmt.meta.buffersize = call_session_op(core, buffer_size,
  900. inst, MSM_VIDC_BUF_INPUT_META);
  901. inst->buffers.input_meta.min_count = inst->buffers.input.min_count;
  902. inst->buffers.input_meta.extra_count = inst->buffers.input.extra_count;
  903. inst->buffers.input_meta.actual_count = inst->buffers.input.actual_count;
  904. inst->buffers.input_meta.size = f->fmt.meta.buffersize;
  905. inst->prop.frame_rate = DEFAULT_FPS << 16;
  906. inst->prop.operating_rate = DEFAULT_FPS << 16;
  907. inst->stage = MSM_VIDC_STAGE_2;
  908. inst->pipe = MSM_VIDC_PIPE_4;
  909. rc = msm_venc_codec_change(inst,
  910. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat);
  911. return rc;
  912. }