sde_encoder_dce.c 28 KB

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