sde_encoder_dce.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/kthread.h>
  6. #include <linux/debugfs.h>
  7. #include <linux/seq_file.h>
  8. #include <linux/sde_rsc.h>
  9. #include "msm_drv.h"
  10. #include "sde_kms.h"
  11. #include <drm/drm_crtc.h>
  12. #include <drm/drm_crtc_helper.h>
  13. #include "sde_hwio.h"
  14. #include "sde_hw_catalog.h"
  15. #include "sde_hw_intf.h"
  16. #include "sde_hw_ctl.h"
  17. #include "sde_formats.h"
  18. #include "sde_encoder_phys.h"
  19. #include "sde_power_handle.h"
  20. #include "sde_hw_dsc.h"
  21. #include "sde_hw_vdc.h"
  22. #include "sde_crtc.h"
  23. #include "sde_trace.h"
  24. #include "sde_core_irq.h"
  25. #include "sde_dsc_helper.h"
  26. #include "sde_vdc_helper.h"
  27. #define SDE_DEBUG_DCE(e, fmt, ...) SDE_DEBUG("enc%d " fmt,\
  28. (e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
  29. #define SDE_ERROR_DCE(e, fmt, ...) SDE_ERROR("enc%d " fmt,\
  30. (e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
  31. bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc)
  32. {
  33. enum sde_rm_topology_name topology;
  34. struct sde_encoder_virt *sde_enc;
  35. struct drm_connector *drm_conn;
  36. if (!drm_enc)
  37. return false;
  38. sde_enc = to_sde_encoder_virt(drm_enc);
  39. if (!sde_enc->cur_master)
  40. return false;
  41. drm_conn = sde_enc->cur_master->connector;
  42. if (!drm_conn)
  43. return false;
  44. topology = sde_connector_get_topology_name(drm_conn);
  45. if (topology == SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE)
  46. return true;
  47. return false;
  48. }
  49. static int _dce_dsc_update_pic_dim(struct msm_display_dsc_info *dsc,
  50. int pic_width, int pic_height)
  51. {
  52. if (!dsc || !pic_width || !pic_height) {
  53. SDE_ERROR("invalid input: pic_width=%d pic_height=%d\n",
  54. pic_width, pic_height);
  55. return -EINVAL;
  56. }
  57. if ((pic_width % dsc->config.slice_width) ||
  58. (pic_height % dsc->config.slice_height)) {
  59. SDE_ERROR("pic_dim=%dx%d has to be multiple of slice=%dx%d\n",
  60. pic_width, pic_height,
  61. dsc->config.slice_width, dsc->config.slice_height);
  62. return -EINVAL;
  63. }
  64. dsc->config.pic_width = pic_width;
  65. dsc->config.pic_height = pic_height;
  66. return 0;
  67. }
  68. static int _dce_vdc_update_pic_dim(struct msm_display_vdc_info *vdc,
  69. int frame_width, int frame_height)
  70. {
  71. if (!vdc || !frame_width || !frame_height) {
  72. SDE_ERROR("invalid input: frame_width=%d frame_height=%d\n",
  73. frame_width, frame_height);
  74. return -EINVAL;
  75. }
  76. if ((frame_width % vdc->slice_width) ||
  77. (frame_height % vdc->slice_height)) {
  78. SDE_ERROR("pic_dim=%dx%d has to be multiple of slice=%dx%d\n",
  79. frame_width, frame_height,
  80. vdc->slice_width, vdc->slice_height);
  81. return -EINVAL;
  82. }
  83. vdc->frame_width = frame_width;
  84. vdc->frame_height = frame_height;
  85. return 0;
  86. }
  87. static int _dce_dsc_initial_line_calc(struct msm_display_dsc_info *dsc,
  88. int enc_ip_width,
  89. int dsc_cmn_mode)
  90. {
  91. int max_ssm_delay, max_se_size, max_muxword_size;
  92. int compress_bpp_group, obuf_latency, input_ssm_out_latency;
  93. int base_hs_latency, chunk_bits, ob_data_width;
  94. int output_rate_extra_budget_bits, multi_hs_extra_budget_bits;
  95. int multi_hs_extra_latency, mux_word_size;
  96. int ob_data_width_4comps, ob_data_width_3comps;
  97. int output_rate_ratio_complement, container_slice_width;
  98. int rtl_num_components, multi_hs_c, multi_hs_d;
  99. int bpc = dsc->config.bits_per_component;
  100. int bpp = DSC_BPP(dsc->config);
  101. int num_of_active_ss = dsc->config.slice_count;
  102. bool native_422 = dsc->config.native_422;
  103. bool native_420 = dsc->config.native_420;
  104. /* Hardent core config */
  105. int multiplex_mode_enable = 0, split_panel_enable = 0;
  106. int rtl_max_bpc = 10, rtl_output_data_width = 64;
  107. int pipeline_latency = 28;
  108. if (dsc_cmn_mode & DSC_MODE_MULTIPLEX)
  109. multiplex_mode_enable = 1;
  110. if (dsc_cmn_mode & DSC_MODE_SPLIT_PANEL)
  111. split_panel_enable = 0;
  112. container_slice_width = (native_422 ?
  113. dsc->config.slice_width / 2 : dsc->config.slice_width);
  114. max_muxword_size = (rtl_max_bpc >= 12) ? 64 : 48;
  115. max_se_size = 4 * (rtl_max_bpc + 1);
  116. max_ssm_delay = max_se_size + max_muxword_size - 1;
  117. mux_word_size = (bpc >= 12) ? 64 : 48;
  118. compress_bpp_group = native_422 ? (2 * bpp) : bpp;
  119. input_ssm_out_latency = pipeline_latency + 3 * (max_ssm_delay + 2)
  120. * num_of_active_ss;
  121. rtl_num_components = (native_420 || native_422) ? 4 : 3;
  122. ob_data_width_4comps = (rtl_output_data_width >= (2 *
  123. max_muxword_size)) ?
  124. rtl_output_data_width :
  125. (2 * rtl_output_data_width);
  126. ob_data_width_3comps = (rtl_output_data_width >= max_muxword_size) ?
  127. rtl_output_data_width : 2 * rtl_output_data_width;
  128. ob_data_width = (rtl_num_components == 4) ?
  129. ob_data_width_4comps : ob_data_width_3comps;
  130. obuf_latency = DIV_ROUND_UP((9 * ob_data_width + mux_word_size),
  131. compress_bpp_group) + 1;
  132. base_hs_latency = dsc->config.initial_xmit_delay +
  133. input_ssm_out_latency + obuf_latency;
  134. chunk_bits = 8 * dsc->config.slice_chunk_size;
  135. output_rate_ratio_complement = ob_data_width - compress_bpp_group;
  136. output_rate_extra_budget_bits =
  137. (output_rate_ratio_complement * chunk_bits) >>
  138. ((ob_data_width == 128) ? 7 : 6);
  139. multi_hs_c = split_panel_enable * multiplex_mode_enable;
  140. multi_hs_d = (num_of_active_ss > 1) * (ob_data_width >
  141. compress_bpp_group);
  142. multi_hs_extra_budget_bits = multi_hs_c ?
  143. chunk_bits : (multi_hs_d ? chunk_bits :
  144. output_rate_extra_budget_bits);
  145. multi_hs_extra_latency = DIV_ROUND_UP(multi_hs_extra_budget_bits,
  146. compress_bpp_group);
  147. dsc->initial_lines = DIV_ROUND_UP((base_hs_latency +
  148. multi_hs_extra_latency),
  149. container_slice_width);
  150. return 0;
  151. }
  152. static bool _dce_dsc_ich_reset_override_needed(bool pu_en,
  153. struct msm_display_dsc_info *dsc)
  154. {
  155. /*
  156. * As per the DSC spec, ICH_RESET can be either end of the slice line
  157. * or at the end of the slice. HW internally generates ich_reset at
  158. * end of the slice line if DSC_MERGE is used or encoder has two
  159. * soft slices. However, if encoder has only 1 soft slice and DSC_MERGE
  160. * is not used then it will generate ich_reset at the end of slice.
  161. *
  162. * Now as per the spec, during one PPS session, position where
  163. * ich_reset is generated should not change. Now if full-screen frame
  164. * has more than 1 soft slice then HW will automatically generate
  165. * ich_reset at the end of slice_line. But for the same panel, if
  166. * partial frame is enabled and only 1 encoder is used with 1 slice,
  167. * then HW will generate ich_reset at end of the slice. This is a
  168. * mismatch. Prevent this by overriding HW's decision.
  169. */
  170. return pu_en && dsc && (dsc->config.slice_count > 1) &&
  171. (dsc->config.slice_width == dsc->config.pic_width);
  172. }
  173. static void _dce_dsc_pipe_cfg(struct sde_hw_dsc *hw_dsc,
  174. struct sde_hw_pingpong *hw_pp, struct msm_display_dsc_info *dsc,
  175. u32 common_mode, bool ich_reset,
  176. struct sde_hw_pingpong *hw_dsc_pp,
  177. enum sde_3d_blend_mode mode_3d,
  178. bool disable_merge_3d, bool enable)
  179. {
  180. if (!enable) {
  181. if (hw_dsc_pp && hw_dsc_pp->ops.disable_dsc)
  182. hw_dsc_pp->ops.disable_dsc(hw_dsc_pp);
  183. if (hw_dsc && hw_dsc->ops.dsc_disable)
  184. hw_dsc->ops.dsc_disable(hw_dsc);
  185. if (hw_dsc && hw_dsc->ops.bind_pingpong_blk)
  186. hw_dsc->ops.bind_pingpong_blk(hw_dsc, false,
  187. PINGPONG_MAX);
  188. if (mode_3d && hw_pp && hw_pp->ops.reset_3d_mode)
  189. hw_pp->ops.reset_3d_mode(hw_pp);
  190. return;
  191. }
  192. if (!dsc || !hw_dsc || !hw_pp) {
  193. SDE_ERROR("invalid params %d %d %d\n", !dsc, !hw_dsc,
  194. !hw_pp);
  195. return;
  196. }
  197. if (hw_dsc->ops.dsc_config)
  198. hw_dsc->ops.dsc_config(hw_dsc, dsc, common_mode, ich_reset);
  199. if (hw_dsc->ops.dsc_config_thresh)
  200. hw_dsc->ops.dsc_config_thresh(hw_dsc, dsc);
  201. if (hw_dsc_pp && hw_dsc_pp->ops.setup_dsc)
  202. hw_dsc_pp->ops.setup_dsc(hw_dsc_pp);
  203. if (mode_3d && disable_merge_3d && hw_pp->ops.reset_3d_mode) {
  204. SDE_DEBUG("disabling 3d mux \n");
  205. hw_pp->ops.reset_3d_mode(hw_pp);
  206. } else if (mode_3d && disable_merge_3d && hw_pp->ops.setup_3d_mode) {
  207. SDE_DEBUG("enabling 3d mux \n");
  208. hw_pp->ops.setup_3d_mode(hw_pp, mode_3d);
  209. }
  210. if (hw_dsc && hw_dsc->ops.bind_pingpong_blk)
  211. hw_dsc->ops.bind_pingpong_blk(hw_dsc, true, hw_pp->idx);
  212. if (hw_dsc_pp && hw_dsc_pp->ops.enable_dsc)
  213. hw_dsc_pp->ops.enable_dsc(hw_dsc_pp);
  214. }
  215. static void _dce_vdc_pipe_cfg(struct sde_hw_vdc *hw_vdc,
  216. struct sde_hw_pingpong *hw_pp,
  217. struct msm_display_vdc_info *vdc,
  218. enum sde_3d_blend_mode mode_3d,
  219. bool disable_merge_3d, bool enable)
  220. {
  221. if (!vdc || !hw_vdc || !hw_pp) {
  222. SDE_ERROR("invalid params %d %d %d\n", !vdc, !hw_vdc,
  223. !hw_pp);
  224. return;
  225. }
  226. if (!enable) {
  227. if (hw_vdc->ops.vdc_disable)
  228. hw_vdc->ops.vdc_disable(hw_vdc);
  229. if (hw_vdc->ops.bind_pingpong_blk)
  230. hw_vdc->ops.bind_pingpong_blk(hw_vdc, false,
  231. PINGPONG_MAX);
  232. if (mode_3d && hw_pp->ops.reset_3d_mode)
  233. hw_pp->ops.reset_3d_mode(hw_pp);
  234. return;
  235. }
  236. if (hw_vdc->ops.vdc_config)
  237. hw_vdc->ops.vdc_config(hw_vdc, vdc);
  238. if (mode_3d && disable_merge_3d && hw_pp->ops.reset_3d_mode) {
  239. SDE_DEBUG("disabling 3d mux\n");
  240. hw_pp->ops.reset_3d_mode(hw_pp);
  241. }
  242. if (mode_3d && !disable_merge_3d && hw_pp->ops.setup_3d_mode) {
  243. SDE_DEBUG("enabling 3d mux\n");
  244. hw_pp->ops.setup_3d_mode(hw_pp, mode_3d);
  245. }
  246. if (hw_vdc->ops.bind_pingpong_blk)
  247. hw_vdc->ops.bind_pingpong_blk(hw_vdc, true, hw_pp->idx);
  248. }
  249. static inline bool _dce_check_half_panel_update(int num_lm,
  250. unsigned long affected_displays)
  251. {
  252. /**
  253. * partial update logic is currently supported only upto dual
  254. * pipe configurations.
  255. */
  256. return (hweight_long(affected_displays) != num_lm);
  257. }
  258. static int _dce_dsc_setup_single(struct sde_encoder_virt *sde_enc,
  259. struct msm_display_dsc_info *dsc,
  260. unsigned long affected_displays, int index,
  261. const struct sde_rect *roi, int dsc_common_mode,
  262. bool merge_3d, bool disable_merge_3d, bool mode_3d,
  263. bool dsc_4hsmerge, bool half_panel_partial_update,
  264. int ich_res)
  265. {
  266. struct sde_hw_ctl *hw_ctl;
  267. struct sde_hw_dsc *hw_dsc;
  268. struct sde_hw_pingpong *hw_pp;
  269. struct sde_hw_pingpong *hw_dsc_pp;
  270. struct sde_hw_intf_cfg_v1 cfg;
  271. bool active = !!((1 << index) & affected_displays);
  272. hw_ctl = sde_enc->cur_master->hw_ctl;
  273. /*
  274. * in 3d_merge and half_panel partial update dsc should be
  275. * bound to the pp which is driving the update, else in
  276. * 3d_merge dsc should be bound to left side of the pipe
  277. */
  278. if (merge_3d && half_panel_partial_update)
  279. hw_pp = (active) ? sde_enc->hw_pp[0] : sde_enc->hw_pp[1];
  280. else
  281. hw_pp = sde_enc->hw_pp[index];
  282. hw_dsc = sde_enc->hw_dsc[index];
  283. hw_dsc_pp = sde_enc->hw_dsc_pp[index];
  284. if (!hw_pp || !hw_dsc) {
  285. SDE_ERROR_DCE(sde_enc, "DSC: invalid params %d %d\n", !!hw_pp,
  286. !!hw_dsc);
  287. SDE_EVT32(DRMID(&sde_enc->base), !hw_pp, !hw_dsc,
  288. SDE_EVTLOG_ERROR);
  289. return -EINVAL;
  290. }
  291. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h,
  292. dsc_common_mode, index, active, merge_3d,
  293. disable_merge_3d, dsc_4hsmerge);
  294. _dce_dsc_pipe_cfg(hw_dsc, hw_pp, dsc, dsc_common_mode, ich_res,
  295. hw_dsc_pp, mode_3d, disable_merge_3d, active);
  296. memset(&cfg, 0, sizeof(cfg));
  297. cfg.dsc[cfg.dsc_count++] = hw_dsc->idx;
  298. if (hw_ctl->ops.update_intf_cfg)
  299. hw_ctl->ops.update_intf_cfg(hw_ctl, &cfg, active);
  300. if (hw_ctl->ops.update_bitmask)
  301. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_DSC,
  302. hw_dsc->idx, active);
  303. SDE_DEBUG_DCE(sde_enc, "update_intf_cfg hw_ctl[%d], dsc:%d, %s",
  304. hw_ctl->idx, cfg.dsc[0],
  305. active ? "enabled" : "disabled");
  306. if (mode_3d) {
  307. memset(&cfg, 0, sizeof(cfg));
  308. cfg.merge_3d[cfg.merge_3d_count++] = hw_pp->merge_3d->idx;
  309. if (hw_ctl->ops.update_intf_cfg)
  310. hw_ctl->ops.update_intf_cfg(hw_ctl, &cfg,
  311. !disable_merge_3d);
  312. if (hw_ctl->ops.update_bitmask)
  313. hw_ctl->ops.update_bitmask(
  314. hw_ctl, SDE_HW_FLUSH_MERGE_3D,
  315. hw_pp->merge_3d->idx, true);
  316. SDE_DEBUG("mode_3d %s, on CTL_%d PP-%d merge3d:%d\n",
  317. !disable_merge_3d ? "enabled" : "disabled",
  318. hw_ctl->idx - CTL_0, hw_pp->idx - PINGPONG_0,
  319. hw_pp->merge_3d ?
  320. hw_pp->merge_3d->idx - MERGE_3D_0 :
  321. -1);
  322. }
  323. return 0;
  324. }
  325. static int _dce_dsc_setup_helper(struct sde_encoder_virt *sde_enc,
  326. unsigned long affected_displays,
  327. enum sde_rm_topology_name topology)
  328. {
  329. struct sde_kms *sde_kms;
  330. struct sde_encoder_phys *enc_master;
  331. struct msm_display_dsc_info *dsc = NULL;
  332. const struct sde_rm_topology_def *def;
  333. const struct sde_rect *roi;
  334. enum sde_3d_blend_mode mode_3d;
  335. bool half_panel_partial_update, dsc_merge, merge_3d, dsc_4hsmerge;
  336. bool disable_merge_3d = false;
  337. int this_frame_slices;
  338. int intf_ip_w, enc_ip_w;
  339. int num_intf, num_dsc, num_lm;
  340. int ich_res;
  341. int dsc_pic_width;
  342. int dsc_common_mode = 0;
  343. int i, rc = 0;
  344. sde_kms = sde_encoder_get_kms(&sde_enc->base);
  345. def = sde_rm_topology_get_topology_def(&sde_kms->rm, topology);
  346. if (IS_ERR_OR_NULL(def))
  347. return -EINVAL;
  348. enc_master = sde_enc->cur_master;
  349. roi = &sde_enc->cur_conn_roi;
  350. dsc = &sde_enc->mode_info.comp_info.dsc_info;
  351. num_lm = def->num_lm;
  352. num_dsc = def->num_comp_enc;
  353. num_intf = def->num_intf;
  354. mode_3d = (num_lm > num_dsc) ? BLEND_3D_H_ROW_INT : BLEND_3D_NONE;
  355. merge_3d = (mode_3d != BLEND_3D_NONE) ? true : false;
  356. half_panel_partial_update = _dce_check_half_panel_update(num_lm,
  357. affected_displays);
  358. dsc_merge = ((num_dsc > num_intf) && !half_panel_partial_update) ?
  359. true : false;
  360. disable_merge_3d = (merge_3d && half_panel_partial_update) ?
  361. false : true;
  362. dsc_4hsmerge = (dsc_merge && num_dsc == 4 && num_intf == 1) ?
  363. true : false;
  364. /*
  365. * If this encoder is driving more than one DSC encoder, they
  366. * operate in tandem, same pic dimension needs to be used by
  367. * each of them.(pp-split is assumed to be not supported)
  368. *
  369. * If encoder is driving more than 2 DSCs, each DSC pair will operate
  370. * on half of the picture in tandem.
  371. */
  372. if (num_dsc > 2) {
  373. dsc_pic_width = roi->w / 2;
  374. dsc->dsc_4hsmerge_en = dsc_4hsmerge;
  375. } else
  376. dsc_pic_width = roi->w;
  377. _dce_dsc_update_pic_dim(dsc, dsc_pic_width, roi->h);
  378. this_frame_slices = roi->w / dsc->config.slice_width;
  379. intf_ip_w = this_frame_slices * dsc->config.slice_width;
  380. enc_ip_w = intf_ip_w;
  381. if (!half_panel_partial_update)
  382. intf_ip_w /= num_intf;
  383. if (!half_panel_partial_update && (num_dsc > 1))
  384. dsc_common_mode |= DSC_MODE_SPLIT_PANEL;
  385. if (dsc_merge) {
  386. dsc_common_mode |= DSC_MODE_MULTIPLEX;
  387. /*
  388. * in dsc merge case: when using 2 encoders for the same
  389. * stream, no. of slices need to be same on both the
  390. * encoders.
  391. */
  392. enc_ip_w = intf_ip_w / 2;
  393. }
  394. if (enc_master->intf_mode == INTF_MODE_VIDEO)
  395. dsc_common_mode |= DSC_MODE_VIDEO;
  396. sde_dsc_populate_dsc_private_params(dsc, intf_ip_w);
  397. _dce_dsc_initial_line_calc(dsc, enc_ip_w, dsc_common_mode);
  398. /*
  399. * __is_ich_reset_override_needed should be called only after
  400. * updating pic dimension, mdss_panel_dsc_update_pic_dim.
  401. */
  402. ich_res = _dce_dsc_ich_reset_override_needed(
  403. (half_panel_partial_update && !merge_3d), dsc);
  404. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d mode:%d\n",
  405. roi->w, roi->h, dsc_common_mode);
  406. for (i = 0; i < num_dsc; i++) {
  407. rc = _dce_dsc_setup_single(sde_enc, dsc, affected_displays, i,
  408. roi, dsc_common_mode, merge_3d,
  409. disable_merge_3d, mode_3d, dsc_4hsmerge,
  410. half_panel_partial_update, ich_res);
  411. if (rc)
  412. break;
  413. }
  414. return rc;
  415. }
  416. static int _dce_dsc_setup(struct sde_encoder_virt *sde_enc,
  417. struct sde_encoder_kickoff_params *params)
  418. {
  419. struct drm_connector *drm_conn;
  420. enum sde_rm_topology_name topology;
  421. if (!sde_enc || !params || !sde_enc->phys_encs[0] ||
  422. !sde_enc->phys_encs[0]->connector)
  423. return -EINVAL;
  424. drm_conn = sde_enc->phys_encs[0]->connector;
  425. topology = sde_connector_get_topology_name(drm_conn);
  426. if (topology == SDE_RM_TOPOLOGY_NONE) {
  427. SDE_ERROR_DCE(sde_enc, "topology not set yet\n");
  428. return -EINVAL;
  429. }
  430. SDE_DEBUG_DCE(sde_enc, "topology:%d\n", topology);
  431. if (sde_kms_rect_is_equal(&sde_enc->cur_conn_roi,
  432. &sde_enc->prv_conn_roi))
  433. return 0;
  434. SDE_EVT32(DRMID(&sde_enc->base), topology,
  435. sde_enc->cur_conn_roi.x, sde_enc->cur_conn_roi.y,
  436. sde_enc->cur_conn_roi.w, sde_enc->cur_conn_roi.h,
  437. sde_enc->prv_conn_roi.x, sde_enc->prv_conn_roi.y,
  438. sde_enc->prv_conn_roi.w, sde_enc->prv_conn_roi.h,
  439. sde_enc->cur_master->cached_mode.hdisplay,
  440. sde_enc->cur_master->cached_mode.vdisplay);
  441. return _dce_dsc_setup_helper(sde_enc, params->affected_displays,
  442. topology);
  443. }
  444. static int _dce_vdc_setup(struct sde_encoder_virt *sde_enc,
  445. struct sde_encoder_kickoff_params *params)
  446. {
  447. struct drm_connector *drm_conn;
  448. struct sde_kms *sde_kms;
  449. struct sde_encoder_phys *enc_master;
  450. struct sde_hw_vdc *hw_vdc[MAX_CHANNELS_PER_ENC];
  451. struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC];
  452. struct msm_display_vdc_info *vdc = NULL;
  453. enum sde_rm_topology_name topology;
  454. const struct sde_rect *roi;
  455. struct sde_hw_ctl *hw_ctl;
  456. struct sde_hw_intf_cfg_v1 cfg;
  457. enum sde_3d_blend_mode mode_3d;
  458. bool half_panel_partial_update, merge_3d;
  459. bool disable_merge_3d = false;
  460. int this_frame_slices;
  461. int intf_ip_w, enc_ip_w;
  462. const struct sde_rm_topology_def *def;
  463. int num_intf, num_vdc, num_lm;
  464. int i;
  465. int ret = 0;
  466. if (!sde_enc || !params || !sde_enc->phys_encs[0] ||
  467. !sde_enc->phys_encs[0]->connector)
  468. return -EINVAL;
  469. drm_conn = sde_enc->phys_encs[0]->connector;
  470. topology = sde_connector_get_topology_name(drm_conn);
  471. if (topology == SDE_RM_TOPOLOGY_NONE) {
  472. SDE_ERROR_DCE(sde_enc, "topology not set yet\n");
  473. return -EINVAL;
  474. }
  475. SDE_DEBUG_DCE(sde_enc, "topology:%d\n", topology);
  476. SDE_EVT32(DRMID(&sde_enc->base), topology,
  477. sde_enc->cur_conn_roi.x,
  478. sde_enc->cur_conn_roi.y,
  479. sde_enc->cur_conn_roi.w,
  480. sde_enc->cur_conn_roi.h,
  481. sde_enc->prv_conn_roi.x,
  482. sde_enc->prv_conn_roi.y,
  483. sde_enc->prv_conn_roi.w,
  484. sde_enc->prv_conn_roi.h,
  485. sde_enc->cur_master->cached_mode.hdisplay,
  486. sde_enc->cur_master->cached_mode.vdisplay);
  487. if (sde_kms_rect_is_equal(&sde_enc->cur_conn_roi,
  488. &sde_enc->prv_conn_roi))
  489. return ret;
  490. enc_master = sde_enc->cur_master;
  491. roi = &sde_enc->cur_conn_roi;
  492. hw_ctl = enc_master->hw_ctl;
  493. vdc = &sde_enc->mode_info.comp_info.vdc_info;
  494. sde_kms = sde_encoder_get_kms(&sde_enc->base);
  495. def = sde_rm_topology_get_topology_def(&sde_kms->rm, topology);
  496. if (IS_ERR_OR_NULL(def))
  497. return -EINVAL;
  498. num_vdc = def->num_comp_enc;
  499. num_intf = def->num_intf;
  500. mode_3d = (topology == SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_VDC) ?
  501. BLEND_3D_H_ROW_INT : BLEND_3D_NONE;
  502. num_lm = def->num_lm;
  503. /*
  504. * If this encoder is driving more than one VDC encoder, they
  505. * operate in tandem, same pic dimension needs to be used by
  506. * each of them.(pp-split is assumed to be not supported)
  507. */
  508. _dce_vdc_update_pic_dim(vdc, roi->w, roi->h);
  509. merge_3d = (mode_3d != BLEND_3D_NONE) ? true : false;
  510. half_panel_partial_update = _dce_check_half_panel_update(num_lm,
  511. params->affected_displays);
  512. if (half_panel_partial_update && merge_3d)
  513. disable_merge_3d = true;
  514. this_frame_slices = roi->w / vdc->slice_width;
  515. intf_ip_w = this_frame_slices * vdc->slice_width;
  516. sde_vdc_populate_config(vdc, intf_ip_w, vdc->traffic_mode);
  517. enc_ip_w = intf_ip_w;
  518. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d\n",
  519. roi->w, roi->h);
  520. for (i = 0; i < num_vdc; i++) {
  521. bool active = !!((1 << i) & params->affected_displays);
  522. /*
  523. * if half_panel partial update vdc should be bound to the pp
  524. * that is driving the update, in other case when both the
  525. * layer mixers are driving the update, vdc should be bound
  526. * to left side pp
  527. */
  528. if (merge_3d && half_panel_partial_update)
  529. hw_pp[i] = (active) ? sde_enc->hw_pp[0] :
  530. sde_enc->hw_pp[1];
  531. else
  532. hw_pp[i] = sde_enc->hw_pp[i];
  533. hw_vdc[i] = sde_enc->hw_vdc[i];
  534. if (!hw_vdc[i]) {
  535. SDE_ERROR_DCE(sde_enc, "invalid params for VDC\n");
  536. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h,
  537. i, active);
  538. return -EINVAL;
  539. }
  540. _dce_vdc_pipe_cfg(hw_vdc[i], hw_pp[i],
  541. vdc, mode_3d, disable_merge_3d, active);
  542. memset(&cfg, 0, sizeof(cfg));
  543. cfg.vdc[cfg.vdc_count++] = hw_vdc[i]->idx;
  544. if (hw_ctl->ops.update_intf_cfg)
  545. hw_ctl->ops.update_intf_cfg(hw_ctl,
  546. &cfg,
  547. active);
  548. if (hw_ctl->ops.update_bitmask)
  549. hw_ctl->ops.update_bitmask(hw_ctl,
  550. SDE_HW_FLUSH_VDC,
  551. hw_vdc[i]->idx, active);
  552. SDE_DEBUG_DCE(sde_enc,
  553. "update_intf_cfg hw_ctl[%d], vdc:%d, %s",
  554. hw_ctl->idx,
  555. cfg.vdc[0],
  556. active ? "enabled" : "disabled");
  557. if (mode_3d) {
  558. memset(&cfg, 0, sizeof(cfg));
  559. cfg.merge_3d[cfg.merge_3d_count++] =
  560. hw_pp[i]->merge_3d->idx;
  561. if (hw_ctl->ops.update_intf_cfg)
  562. hw_ctl->ops.update_intf_cfg(hw_ctl,
  563. &cfg,
  564. !disable_merge_3d);
  565. if (hw_ctl->ops.update_bitmask)
  566. hw_ctl->ops.update_bitmask(
  567. hw_ctl, SDE_HW_FLUSH_MERGE_3D,
  568. hw_pp[i]->merge_3d->idx, true);
  569. SDE_DEBUG("mode_3d %s, on CTL_%d PP-%d merge3d:%d\n",
  570. disable_merge_3d ?
  571. "disabled" : "enabled",
  572. hw_ctl->idx - CTL_0,
  573. hw_pp[i]->idx - PINGPONG_0,
  574. hw_pp[i]->merge_3d ?
  575. hw_pp[i]->merge_3d->idx - MERGE_3D_0 :
  576. -1);
  577. }
  578. }
  579. return 0;
  580. }
  581. static void _dce_dsc_disable(struct sde_encoder_virt *sde_enc)
  582. {
  583. int i;
  584. struct sde_hw_pingpong *hw_pp = NULL;
  585. struct sde_hw_pingpong *hw_dsc_pp = NULL;
  586. struct sde_hw_dsc *hw_dsc = NULL;
  587. struct sde_hw_ctl *hw_ctl = NULL;
  588. struct sde_hw_intf_cfg_v1 cfg;
  589. if (!sde_enc || !sde_enc->phys_encs[0] ||
  590. !sde_enc->phys_encs[0]->connector) {
  591. SDE_ERROR("invalid params %d %d\n",
  592. !sde_enc, sde_enc ? !sde_enc->phys_encs[0] : -1);
  593. return;
  594. }
  595. if (sde_enc->cur_master)
  596. hw_ctl = sde_enc->cur_master->hw_ctl;
  597. memset(&cfg, 0, sizeof(cfg));
  598. /* Disable DSC for all the pp's present in this topology */
  599. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  600. hw_pp = sde_enc->hw_pp[i];
  601. hw_dsc = sde_enc->hw_dsc[i];
  602. hw_dsc_pp = sde_enc->hw_dsc_pp[i];
  603. _dce_dsc_pipe_cfg(hw_dsc, hw_pp, NULL,
  604. 0, 0, hw_dsc_pp,
  605. BLEND_3D_NONE, false, false);
  606. if (hw_dsc) {
  607. sde_enc->dirty_dsc_ids[i] = hw_dsc->idx;
  608. cfg.dsc[cfg.dsc_count++] = hw_dsc->idx;
  609. }
  610. }
  611. /* Clear the DSC ACTIVE config for this CTL */
  612. if (hw_ctl && hw_ctl->ops.update_intf_cfg)
  613. hw_ctl->ops.update_intf_cfg(hw_ctl, &cfg, false);
  614. /**
  615. * Since pending flushes from previous commit get cleared
  616. * sometime after this point, setting DSC flush bits now
  617. * will have no effect. Therefore dirty_dsc_ids track which
  618. * DSC blocks must be flushed for the next trigger.
  619. */
  620. }
  621. static void _dce_vdc_disable(struct sde_encoder_virt *sde_enc)
  622. {
  623. int i;
  624. struct sde_hw_pingpong *hw_pp = NULL;
  625. struct sde_hw_vdc *hw_vdc = NULL;
  626. struct sde_hw_ctl *hw_ctl = NULL;
  627. struct sde_hw_intf_cfg_v1 cfg;
  628. if (!sde_enc || !sde_enc->phys_encs[0] ||
  629. !sde_enc->phys_encs[0]->connector) {
  630. SDE_ERROR("invalid params %d %d\n",
  631. !sde_enc, sde_enc ? !sde_enc->phys_encs[0] : -1);
  632. return;
  633. }
  634. if (sde_enc->cur_master)
  635. hw_ctl = sde_enc->cur_master->hw_ctl;
  636. memset(&cfg, 0, sizeof(cfg));
  637. /* Disable VDC for all the pp's present in this topology */
  638. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  639. hw_pp = sde_enc->hw_pp[i];
  640. hw_vdc = sde_enc->hw_vdc[i];
  641. _dce_vdc_pipe_cfg(hw_vdc, hw_pp, NULL,
  642. BLEND_3D_NONE, false,
  643. false);
  644. if (hw_vdc) {
  645. sde_enc->dirty_vdc_ids[i] = hw_vdc->idx;
  646. cfg.vdc[cfg.vdc_count++] = hw_vdc->idx;
  647. }
  648. }
  649. /* Clear the VDC ACTIVE config for this CTL */
  650. if (hw_ctl && hw_ctl->ops.update_intf_cfg)
  651. hw_ctl->ops.update_intf_cfg(hw_ctl, &cfg, false);
  652. /**
  653. * Since pending flushes from previous commit get cleared
  654. * sometime after this point, setting VDC flush bits now
  655. * will have no effect. Therefore dirty_vdc_ids track which
  656. * VDC blocks must be flushed for the next trigger.
  657. */
  658. }
  659. bool _dce_dsc_is_dirty(struct sde_encoder_virt *sde_enc)
  660. {
  661. int i;
  662. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  663. /**
  664. * This dirty_dsc_hw field is set during DSC disable to
  665. * indicate which DSC blocks need to be flushed
  666. */
  667. if (sde_enc->dirty_dsc_ids[i])
  668. return true;
  669. }
  670. return false;
  671. }
  672. bool _dce_vdc_is_dirty(struct sde_encoder_virt *sde_enc)
  673. {
  674. int i;
  675. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  676. /**
  677. * This dirty_vdc_hw field is set during VDC disable to
  678. * indicate which VDC blocks need to be flushed
  679. */
  680. if (sde_enc->dirty_vdc_ids[i])
  681. return true;
  682. }
  683. return false;
  684. }
  685. static void _dce_helper_flush_dsc(struct sde_encoder_virt *sde_enc)
  686. {
  687. int i;
  688. struct sde_hw_ctl *hw_ctl = NULL;
  689. enum sde_dsc dsc_idx;
  690. if (sde_enc->cur_master)
  691. hw_ctl = sde_enc->cur_master->hw_ctl;
  692. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  693. dsc_idx = sde_enc->dirty_dsc_ids[i];
  694. if (dsc_idx && hw_ctl && hw_ctl->ops.update_bitmask)
  695. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_DSC,
  696. dsc_idx, 1);
  697. sde_enc->dirty_dsc_ids[i] = DSC_NONE;
  698. }
  699. }
  700. void _dce_helper_flush_vdc(struct sde_encoder_virt *sde_enc)
  701. {
  702. int i;
  703. struct sde_hw_ctl *hw_ctl = NULL;
  704. enum sde_vdc vdc_idx;
  705. if (sde_enc->cur_master)
  706. hw_ctl = sde_enc->cur_master->hw_ctl;
  707. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  708. vdc_idx = sde_enc->dirty_vdc_ids[i];
  709. if (vdc_idx && hw_ctl && hw_ctl->ops.update_bitmask)
  710. hw_ctl->ops.update_bitmask(hw_ctl, SDE_HW_FLUSH_VDC,
  711. vdc_idx, 1);
  712. sde_enc->dirty_vdc_ids[i] = VDC_NONE;
  713. }
  714. }
  715. void sde_encoder_dce_set_bpp(struct msm_mode_info mode_info,
  716. struct drm_crtc *crtc)
  717. {
  718. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  719. enum msm_display_compression_type comp_type;
  720. int src_bpp, target_bpp;
  721. if (!sde_crtc) {
  722. SDE_DEBUG("invalid sde_crtc\n");
  723. return;
  724. }
  725. comp_type = mode_info.comp_info.comp_type;
  726. /**
  727. * In cases where DSC or VDC compression type is not found, set
  728. * src and target bpp to get compression ratio 8/8 (default).
  729. */
  730. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC) {
  731. struct msm_display_dsc_info dsc_info =
  732. mode_info.comp_info.dsc_info;
  733. src_bpp = msm_get_src_bpc(dsc_info.chroma_format,
  734. dsc_info.config.bits_per_component);
  735. target_bpp = dsc_info.config.bits_per_pixel >> 4;
  736. } else if (comp_type == MSM_DISPLAY_COMPRESSION_VDC) {
  737. struct msm_display_vdc_info vdc_info =
  738. mode_info.comp_info.vdc_info;
  739. src_bpp = msm_get_src_bpc(vdc_info.chroma_format,
  740. vdc_info.bits_per_component);
  741. target_bpp = vdc_info.bits_per_pixel >> 4;
  742. } else {
  743. src_bpp = 8;
  744. target_bpp = 8;
  745. }
  746. sde_crtc_set_bpp(sde_crtc, src_bpp, target_bpp);
  747. SDE_DEBUG("sde_crtc src_bpp = %d, target_bpp = %d\n",
  748. sde_crtc->src_bpp, sde_crtc->target_bpp);
  749. }
  750. void sde_encoder_dce_disable(struct sde_encoder_virt *sde_enc)
  751. {
  752. enum msm_display_compression_type comp_type;
  753. if (!sde_enc)
  754. return;
  755. comp_type = sde_enc->mode_info.comp_info.comp_type;
  756. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  757. _dce_dsc_disable(sde_enc);
  758. else if (comp_type == MSM_DISPLAY_COMPRESSION_VDC)
  759. _dce_vdc_disable(sde_enc);
  760. }
  761. int sde_encoder_dce_flush(struct sde_encoder_virt *sde_enc)
  762. {
  763. int rc = 0;
  764. if (!sde_enc)
  765. return -EINVAL;
  766. if (_dce_dsc_is_dirty(sde_enc))
  767. _dce_helper_flush_dsc(sde_enc);
  768. else if (_dce_vdc_is_dirty(sde_enc))
  769. _dce_helper_flush_vdc(sde_enc);
  770. return rc;
  771. }
  772. int sde_encoder_dce_setup(struct sde_encoder_virt *sde_enc,
  773. struct sde_encoder_kickoff_params *params)
  774. {
  775. enum msm_display_compression_type comp_type;
  776. int rc = 0;
  777. if (!sde_enc)
  778. return -EINVAL;
  779. comp_type = sde_enc->mode_info.comp_info.comp_type;
  780. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  781. rc = _dce_dsc_setup(sde_enc, params);
  782. else if (comp_type == MSM_DISPLAY_COMPRESSION_VDC)
  783. rc = _dce_vdc_setup(sde_enc, params);
  784. return rc;
  785. }