sde_encoder_dce.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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_crtc.h"
  22. #include "sde_trace.h"
  23. #include "sde_core_irq.h"
  24. #define SDE_DEBUG_DCE(e, fmt, ...) SDE_DEBUG("enc%d " fmt,\
  25. (e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
  26. #define SDE_ERROR_DCE(e, fmt, ...) SDE_ERROR("enc%d " fmt,\
  27. (e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
  28. bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc)
  29. {
  30. enum sde_rm_topology_name topology;
  31. struct sde_encoder_virt *sde_enc;
  32. struct drm_connector *drm_conn;
  33. if (!drm_enc)
  34. return false;
  35. sde_enc = to_sde_encoder_virt(drm_enc);
  36. if (!sde_enc->cur_master)
  37. return false;
  38. drm_conn = sde_enc->cur_master->connector;
  39. if (!drm_conn)
  40. return false;
  41. topology = sde_connector_get_topology_name(drm_conn);
  42. if (topology == SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE)
  43. return true;
  44. return false;
  45. }
  46. static int _sde_encoder_dsc_update_pic_dim(struct msm_display_dsc_info *dsc,
  47. int pic_width, int pic_height)
  48. {
  49. if (!dsc || !pic_width || !pic_height) {
  50. SDE_ERROR("invalid input: pic_width=%d pic_height=%d\n",
  51. pic_width, pic_height);
  52. return -EINVAL;
  53. }
  54. if ((pic_width % dsc->slice_width) ||
  55. (pic_height % dsc->slice_height)) {
  56. SDE_ERROR("pic_dim=%dx%d has to be multiple of slice=%dx%d\n",
  57. pic_width, pic_height,
  58. dsc->slice_width, dsc->slice_height);
  59. return -EINVAL;
  60. }
  61. dsc->pic_width = pic_width;
  62. dsc->pic_height = pic_height;
  63. return 0;
  64. }
  65. static void _sde_encoder_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc,
  66. int intf_width)
  67. {
  68. int slice_per_pkt, slice_per_intf;
  69. int bytes_in_slice, total_bytes_per_intf;
  70. if (!dsc || !dsc->slice_width || !dsc->slice_per_pkt ||
  71. (intf_width < dsc->slice_width)) {
  72. SDE_ERROR("invalid input: intf_width=%d slice_width=%d\n",
  73. intf_width, dsc ? dsc->slice_width : -1);
  74. return;
  75. }
  76. slice_per_pkt = dsc->slice_per_pkt;
  77. slice_per_intf = DIV_ROUND_UP(intf_width, dsc->slice_width);
  78. /*
  79. * If slice_per_pkt is greater than slice_per_intf then default to 1.
  80. * This can happen during partial update.
  81. */
  82. if (slice_per_pkt > slice_per_intf)
  83. slice_per_pkt = 1;
  84. bytes_in_slice = DIV_ROUND_UP(dsc->slice_width * dsc->bpp, 8);
  85. total_bytes_per_intf = bytes_in_slice * slice_per_intf;
  86. dsc->eol_byte_num = total_bytes_per_intf % 3;
  87. dsc->pclk_per_line = DIV_ROUND_UP(total_bytes_per_intf, 3);
  88. dsc->bytes_in_slice = bytes_in_slice;
  89. dsc->bytes_per_pkt = bytes_in_slice * slice_per_pkt;
  90. dsc->pkt_per_line = slice_per_intf / slice_per_pkt;
  91. }
  92. static int _sde_encoder_dsc_initial_line_calc(struct msm_display_dsc_info *dsc,
  93. int enc_ip_width)
  94. {
  95. int max_ssm_delay, max_se_size, obuf_latency;
  96. int input_ssm_out_latency, base_hs_latency;
  97. int multi_hs_extra_latency, mux_word_size;
  98. /* Hardent core config */
  99. int max_muxword_size = 48;
  100. int output_rate = 64;
  101. int rtl_max_bpc = 10;
  102. int pipeline_latency = 28;
  103. max_se_size = 4 * (rtl_max_bpc + 1);
  104. max_ssm_delay = max_se_size + max_muxword_size - 1;
  105. mux_word_size = (dsc->bpc >= 12 ? 64 : 48);
  106. input_ssm_out_latency = pipeline_latency + (3 * (max_ssm_delay + 2));
  107. obuf_latency = DIV_ROUND_UP((9 * output_rate +
  108. mux_word_size), dsc->bpp) + 1;
  109. base_hs_latency = dsc->initial_xmit_delay + input_ssm_out_latency
  110. + obuf_latency;
  111. multi_hs_extra_latency = DIV_ROUND_UP((8 * dsc->chunk_size), dsc->bpp);
  112. dsc->initial_lines = DIV_ROUND_UP((base_hs_latency +
  113. multi_hs_extra_latency), dsc->slice_width);
  114. return 0;
  115. }
  116. static bool _sde_encoder_dsc_ich_reset_override_needed(bool pu_en,
  117. struct msm_display_dsc_info *dsc)
  118. {
  119. /*
  120. * As per the DSC spec, ICH_RESET can be either end of the slice line
  121. * or at the end of the slice. HW internally generates ich_reset at
  122. * end of the slice line if DSC_MERGE is used or encoder has two
  123. * soft slices. However, if encoder has only 1 soft slice and DSC_MERGE
  124. * is not used then it will generate ich_reset at the end of slice.
  125. *
  126. * Now as per the spec, during one PPS session, position where
  127. * ich_reset is generated should not change. Now if full-screen frame
  128. * has more than 1 soft slice then HW will automatically generate
  129. * ich_reset at the end of slice_line. But for the same panel, if
  130. * partial frame is enabled and only 1 encoder is used with 1 slice,
  131. * then HW will generate ich_reset at end of the slice. This is a
  132. * mismatch. Prevent this by overriding HW's decision.
  133. */
  134. return pu_en && dsc && (dsc->full_frame_slices > 1) &&
  135. (dsc->slice_width == dsc->pic_width);
  136. }
  137. static void _sde_encoder_dsc_pipe_cfg(struct sde_hw_dsc *hw_dsc,
  138. struct sde_hw_pingpong *hw_pp, struct msm_display_dsc_info *dsc,
  139. u32 common_mode, bool ich_reset, bool enable,
  140. struct sde_hw_pingpong *hw_dsc_pp)
  141. {
  142. if (!enable) {
  143. if (hw_dsc_pp && hw_dsc_pp->ops.disable_dsc)
  144. hw_dsc_pp->ops.disable_dsc(hw_dsc_pp);
  145. if (hw_dsc && hw_dsc->ops.dsc_disable)
  146. hw_dsc->ops.dsc_disable(hw_dsc);
  147. if (hw_dsc && hw_dsc->ops.bind_pingpong_blk)
  148. hw_dsc->ops.bind_pingpong_blk(hw_dsc, false,
  149. PINGPONG_MAX);
  150. return;
  151. }
  152. if (!dsc || !hw_dsc || !hw_pp || !hw_dsc_pp) {
  153. SDE_ERROR("invalid params %d %d %d %d\n", !dsc, !hw_dsc,
  154. !hw_pp, !hw_dsc_pp);
  155. return;
  156. }
  157. if (hw_dsc->ops.dsc_config)
  158. hw_dsc->ops.dsc_config(hw_dsc, dsc, common_mode, ich_reset);
  159. if (hw_dsc->ops.dsc_config_thresh)
  160. hw_dsc->ops.dsc_config_thresh(hw_dsc, dsc);
  161. if (hw_dsc_pp->ops.setup_dsc)
  162. hw_dsc_pp->ops.setup_dsc(hw_dsc_pp);
  163. if (hw_dsc->ops.bind_pingpong_blk)
  164. hw_dsc->ops.bind_pingpong_blk(hw_dsc, true, hw_pp->idx);
  165. if (hw_dsc_pp->ops.enable_dsc)
  166. hw_dsc_pp->ops.enable_dsc(hw_dsc_pp);
  167. }
  168. static int _sde_encoder_dsc_n_lm_1_enc_1_intf(struct sde_encoder_virt *sde_enc)
  169. {
  170. int this_frame_slices;
  171. int intf_ip_w, enc_ip_w;
  172. int ich_res, dsc_common_mode = 0;
  173. struct sde_hw_pingpong *hw_pp = sde_enc->hw_pp[0];
  174. struct sde_hw_pingpong *hw_dsc_pp = sde_enc->hw_dsc_pp[0];
  175. struct sde_hw_dsc *hw_dsc = sde_enc->hw_dsc[0];
  176. struct sde_encoder_phys *enc_master = sde_enc->cur_master;
  177. const struct sde_rect *roi = &sde_enc->cur_conn_roi;
  178. struct msm_display_dsc_info *dsc = NULL;
  179. struct sde_hw_ctl *hw_ctl;
  180. struct sde_ctl_dsc_cfg cfg;
  181. if (hw_dsc == NULL || hw_pp == NULL || !enc_master) {
  182. SDE_ERROR_DCE(sde_enc, "invalid params for DSC\n");
  183. return -EINVAL;
  184. }
  185. hw_ctl = enc_master->hw_ctl;
  186. memset(&cfg, 0, sizeof(cfg));
  187. dsc = &sde_enc->mode_info.comp_info.dsc_info;
  188. _sde_encoder_dsc_update_pic_dim(dsc, roi->w, roi->h);
  189. this_frame_slices = roi->w / dsc->slice_width;
  190. intf_ip_w = this_frame_slices * dsc->slice_width;
  191. _sde_encoder_dsc_pclk_param_calc(dsc, intf_ip_w);
  192. enc_ip_w = intf_ip_w;
  193. _sde_encoder_dsc_initial_line_calc(dsc, enc_ip_w);
  194. ich_res = _sde_encoder_dsc_ich_reset_override_needed(false, dsc);
  195. if (enc_master->intf_mode == INTF_MODE_VIDEO)
  196. dsc_common_mode = DSC_MODE_VIDEO;
  197. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d mode:%d\n",
  198. roi->w, roi->h, dsc_common_mode);
  199. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h, dsc_common_mode);
  200. _sde_encoder_dsc_pipe_cfg(hw_dsc, hw_pp, dsc, dsc_common_mode,
  201. ich_res, true, hw_dsc_pp);
  202. cfg.dsc[cfg.dsc_count++] = hw_dsc->idx;
  203. /* setup dsc active configuration in the control path */
  204. if (hw_ctl->ops.setup_dsc_cfg) {
  205. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  206. SDE_DEBUG_DCE(sde_enc,
  207. "setup dsc_cfg hw_ctl[%d], count:%d,dsc[0]:%d, dsc[1]:%d\n",
  208. hw_ctl->idx,
  209. cfg.dsc_count,
  210. cfg.dsc[0],
  211. cfg.dsc[1]);
  212. }
  213. if (hw_ctl->ops.update_bitmask_dsc)
  214. hw_ctl->ops.update_bitmask_dsc(hw_ctl, hw_dsc->idx, 1);
  215. return 0;
  216. }
  217. static int _sde_encoder_dsc_2_lm_2_enc_2_intf(struct sde_encoder_virt *sde_enc,
  218. struct sde_encoder_kickoff_params *params)
  219. {
  220. int this_frame_slices;
  221. int intf_ip_w, enc_ip_w;
  222. int ich_res, dsc_common_mode;
  223. struct sde_encoder_phys *enc_master = sde_enc->cur_master;
  224. const struct sde_rect *roi = &sde_enc->cur_conn_roi;
  225. struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC];
  226. struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC];
  227. struct sde_hw_pingpong *hw_dsc_pp[MAX_CHANNELS_PER_ENC];
  228. struct msm_display_dsc_info dsc[MAX_CHANNELS_PER_ENC];
  229. bool half_panel_partial_update;
  230. struct sde_hw_ctl *hw_ctl = enc_master->hw_ctl;
  231. struct sde_ctl_dsc_cfg cfg;
  232. int i;
  233. memset(&cfg, 0, sizeof(cfg));
  234. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  235. hw_pp[i] = sde_enc->hw_pp[i];
  236. hw_dsc[i] = sde_enc->hw_dsc[i];
  237. hw_dsc_pp[i] = sde_enc->hw_dsc_pp[i];
  238. if (!hw_pp[i] || !hw_dsc[i] || !hw_dsc_pp[i]) {
  239. SDE_ERROR_DCE(sde_enc, "invalid params for DSC\n");
  240. return -EINVAL;
  241. }
  242. }
  243. half_panel_partial_update =
  244. hweight_long(params->affected_displays) == 1;
  245. dsc_common_mode = 0;
  246. if (!half_panel_partial_update)
  247. dsc_common_mode |= DSC_MODE_SPLIT_PANEL;
  248. if (enc_master->intf_mode == INTF_MODE_VIDEO)
  249. dsc_common_mode |= DSC_MODE_VIDEO;
  250. memcpy(&dsc[0], &sde_enc->mode_info.comp_info.dsc_info, sizeof(dsc[0]));
  251. memcpy(&dsc[1], &sde_enc->mode_info.comp_info.dsc_info, sizeof(dsc[1]));
  252. /*
  253. * Since both DSC use same pic dimension, set same pic dimension
  254. * to both DSC structures.
  255. */
  256. _sde_encoder_dsc_update_pic_dim(&dsc[0], roi->w, roi->h);
  257. _sde_encoder_dsc_update_pic_dim(&dsc[1], roi->w, roi->h);
  258. this_frame_slices = roi->w / dsc[0].slice_width;
  259. intf_ip_w = this_frame_slices * dsc[0].slice_width;
  260. if (!half_panel_partial_update)
  261. intf_ip_w /= 2;
  262. /*
  263. * In this topology when both interfaces are active, they have same
  264. * load so intf_ip_w will be same.
  265. */
  266. _sde_encoder_dsc_pclk_param_calc(&dsc[0], intf_ip_w);
  267. _sde_encoder_dsc_pclk_param_calc(&dsc[1], intf_ip_w);
  268. /*
  269. * In this topology, since there is no dsc_merge, uncompressed input
  270. * to encoder and interface is same.
  271. */
  272. enc_ip_w = intf_ip_w;
  273. _sde_encoder_dsc_initial_line_calc(&dsc[0], enc_ip_w);
  274. _sde_encoder_dsc_initial_line_calc(&dsc[1], enc_ip_w);
  275. /*
  276. * __is_ich_reset_override_needed should be called only after
  277. * updating pic dimension, mdss_panel_dsc_update_pic_dim.
  278. */
  279. ich_res = _sde_encoder_dsc_ich_reset_override_needed(
  280. half_panel_partial_update, &dsc[0]);
  281. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d mode:%d\n",
  282. roi->w, roi->h, dsc_common_mode);
  283. for (i = 0; i < sde_enc->num_phys_encs; i++) {
  284. bool active = !!((1 << i) & params->affected_displays);
  285. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h,
  286. dsc_common_mode, i, active);
  287. _sde_encoder_dsc_pipe_cfg(hw_dsc[i], hw_pp[i], &dsc[i],
  288. dsc_common_mode, ich_res, active, hw_dsc_pp[i]);
  289. if (active) {
  290. if (cfg.dsc_count >= MAX_DSC_PER_CTL_V1) {
  291. pr_err("Invalid dsc count:%d\n",
  292. cfg.dsc_count);
  293. return -EINVAL;
  294. }
  295. cfg.dsc[cfg.dsc_count++] = hw_dsc[i]->idx;
  296. if (hw_ctl->ops.update_bitmask_dsc)
  297. hw_ctl->ops.update_bitmask_dsc(hw_ctl,
  298. hw_dsc[i]->idx, 1);
  299. }
  300. }
  301. /* setup dsc active configuration in the control path */
  302. if (hw_ctl->ops.setup_dsc_cfg) {
  303. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  304. SDE_DEBUG_DCE(sde_enc,
  305. "setup dsc_cfg hw_ctl[%d], count:%d,dsc[0]:%d, dsc[1]:%d\n",
  306. hw_ctl->idx,
  307. cfg.dsc_count,
  308. cfg.dsc[0],
  309. cfg.dsc[1]);
  310. }
  311. return 0;
  312. }
  313. static int _sde_encoder_dsc_2_lm_2_enc_1_intf(struct sde_encoder_virt *sde_enc,
  314. struct sde_encoder_kickoff_params *params)
  315. {
  316. int this_frame_slices;
  317. int intf_ip_w, enc_ip_w;
  318. int ich_res, dsc_common_mode;
  319. struct sde_encoder_phys *enc_master = sde_enc->cur_master;
  320. const struct sde_rect *roi = &sde_enc->cur_conn_roi;
  321. struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC];
  322. struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC];
  323. struct sde_hw_pingpong *hw_dsc_pp[MAX_CHANNELS_PER_ENC];
  324. struct msm_display_dsc_info *dsc = NULL;
  325. bool half_panel_partial_update;
  326. struct sde_hw_ctl *hw_ctl = enc_master->hw_ctl;
  327. struct sde_ctl_dsc_cfg cfg;
  328. int i;
  329. memset(&cfg, 0, sizeof(cfg));
  330. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  331. hw_pp[i] = sde_enc->hw_pp[i];
  332. hw_dsc[i] = sde_enc->hw_dsc[i];
  333. hw_dsc_pp[i] = sde_enc->hw_dsc_pp[i];
  334. if (!hw_pp[i] || !hw_dsc[i] || !hw_dsc_pp[i]) {
  335. SDE_ERROR_DCE(sde_enc, "invalid params for DSC\n");
  336. return -EINVAL;
  337. }
  338. }
  339. dsc = &sde_enc->mode_info.comp_info.dsc_info;
  340. half_panel_partial_update =
  341. hweight_long(params->affected_displays) == 1;
  342. dsc_common_mode = 0;
  343. if (!half_panel_partial_update)
  344. dsc_common_mode |= DSC_MODE_SPLIT_PANEL | DSC_MODE_MULTIPLEX;
  345. if (enc_master->intf_mode == INTF_MODE_VIDEO)
  346. dsc_common_mode |= DSC_MODE_VIDEO;
  347. _sde_encoder_dsc_update_pic_dim(dsc, roi->w, roi->h);
  348. this_frame_slices = roi->w / dsc->slice_width;
  349. intf_ip_w = this_frame_slices * dsc->slice_width;
  350. _sde_encoder_dsc_pclk_param_calc(dsc, intf_ip_w);
  351. /*
  352. * dsc merge case: when using 2 encoders for the same stream,
  353. * no. of slices need to be same on both the encoders.
  354. */
  355. enc_ip_w = intf_ip_w / 2;
  356. _sde_encoder_dsc_initial_line_calc(dsc, enc_ip_w);
  357. ich_res = _sde_encoder_dsc_ich_reset_override_needed(
  358. half_panel_partial_update, dsc);
  359. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d mode:%d\n",
  360. roi->w, roi->h, dsc_common_mode);
  361. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h,
  362. dsc_common_mode, i, params->affected_displays);
  363. _sde_encoder_dsc_pipe_cfg(hw_dsc[0], hw_pp[0], dsc, dsc_common_mode,
  364. ich_res, true, hw_dsc_pp[0]);
  365. cfg.dsc[0] = hw_dsc[0]->idx;
  366. cfg.dsc_count++;
  367. if (hw_ctl->ops.update_bitmask_dsc)
  368. hw_ctl->ops.update_bitmask_dsc(hw_ctl, hw_dsc[0]->idx, 1);
  369. _sde_encoder_dsc_pipe_cfg(hw_dsc[1], hw_pp[1], dsc, dsc_common_mode,
  370. ich_res, !half_panel_partial_update, hw_dsc_pp[1]);
  371. if (!half_panel_partial_update) {
  372. cfg.dsc[1] = hw_dsc[1]->idx;
  373. cfg.dsc_count++;
  374. if (hw_ctl->ops.update_bitmask_dsc)
  375. hw_ctl->ops.update_bitmask_dsc(hw_ctl, hw_dsc[1]->idx,
  376. 1);
  377. }
  378. /* setup dsc active configuration in the control path */
  379. if (hw_ctl->ops.setup_dsc_cfg) {
  380. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  381. SDE_DEBUG_DCE(sde_enc,
  382. "setup_dsc_cfg hw_ctl[%d], count:%d,dsc[0]:%d, dsc[1]:%d\n",
  383. hw_ctl->idx,
  384. cfg.dsc_count,
  385. cfg.dsc[0],
  386. cfg.dsc[1]);
  387. }
  388. return 0;
  389. }
  390. static int _dce_dsc_setup(struct sde_encoder_virt *sde_enc,
  391. struct sde_encoder_kickoff_params *params)
  392. {
  393. enum sde_rm_topology_name topology;
  394. struct drm_connector *drm_conn;
  395. int ret = 0;
  396. if (!sde_enc || !params || !sde_enc->phys_encs[0] ||
  397. !sde_enc->phys_encs[0]->connector)
  398. return -EINVAL;
  399. drm_conn = sde_enc->phys_encs[0]->connector;
  400. topology = sde_connector_get_topology_name(drm_conn);
  401. if (topology == SDE_RM_TOPOLOGY_NONE) {
  402. SDE_ERROR_DCE(sde_enc, "topology not set yet\n");
  403. return -EINVAL;
  404. }
  405. SDE_DEBUG_DCE(sde_enc, "topology:%d\n", topology);
  406. SDE_EVT32(DRMID(&sde_enc->base), topology,
  407. sde_enc->cur_conn_roi.x,
  408. sde_enc->cur_conn_roi.y,
  409. sde_enc->cur_conn_roi.w,
  410. sde_enc->cur_conn_roi.h,
  411. sde_enc->prv_conn_roi.x,
  412. sde_enc->prv_conn_roi.y,
  413. sde_enc->prv_conn_roi.w,
  414. sde_enc->prv_conn_roi.h,
  415. sde_enc->cur_master->cached_mode.hdisplay,
  416. sde_enc->cur_master->cached_mode.vdisplay);
  417. if (sde_kms_rect_is_equal(&sde_enc->cur_conn_roi,
  418. &sde_enc->prv_conn_roi))
  419. return ret;
  420. switch (topology) {
  421. case SDE_RM_TOPOLOGY_SINGLEPIPE_DSC:
  422. case SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC:
  423. ret = _sde_encoder_dsc_n_lm_1_enc_1_intf(sde_enc);
  424. break;
  425. case SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE:
  426. ret = _sde_encoder_dsc_2_lm_2_enc_1_intf(sde_enc, params);
  427. break;
  428. case SDE_RM_TOPOLOGY_DUALPIPE_DSC:
  429. ret = _sde_encoder_dsc_2_lm_2_enc_2_intf(sde_enc, params);
  430. break;
  431. default:
  432. SDE_ERROR_DCE(sde_enc, "No DSC support for topology %d",
  433. topology);
  434. return -EINVAL;
  435. }
  436. return ret;
  437. }
  438. static void _dce_dsc_disable(struct sde_encoder_virt *sde_enc)
  439. {
  440. int i;
  441. struct sde_hw_pingpong *hw_pp = NULL;
  442. struct sde_hw_pingpong *hw_dsc_pp = NULL;
  443. struct sde_hw_dsc *hw_dsc = NULL;
  444. struct sde_hw_ctl *hw_ctl = NULL;
  445. struct sde_ctl_dsc_cfg cfg;
  446. if (!sde_enc || !sde_enc->phys_encs[0] ||
  447. !sde_enc->phys_encs[0]->connector) {
  448. SDE_ERROR("invalid params %d %d\n",
  449. !sde_enc, sde_enc ? !sde_enc->phys_encs[0] : -1);
  450. return;
  451. }
  452. if (sde_enc->cur_master)
  453. hw_ctl = sde_enc->cur_master->hw_ctl;
  454. /* Disable DSC for all the pp's present in this topology */
  455. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  456. hw_pp = sde_enc->hw_pp[i];
  457. hw_dsc = sde_enc->hw_dsc[i];
  458. hw_dsc_pp = sde_enc->hw_dsc_pp[i];
  459. _sde_encoder_dsc_pipe_cfg(hw_dsc, hw_pp, NULL,
  460. 0, 0, 0, hw_dsc_pp);
  461. if (hw_dsc)
  462. sde_enc->dirty_dsc_ids[i] = hw_dsc->idx;
  463. }
  464. /* Clear the DSC ACTIVE config for this CTL */
  465. if (hw_ctl && hw_ctl->ops.setup_dsc_cfg) {
  466. memset(&cfg, 0, sizeof(cfg));
  467. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  468. }
  469. /**
  470. * Since pending flushes from previous commit get cleared
  471. * sometime after this point, setting DSC flush bits now
  472. * will have no effect. Therefore dirty_dsc_ids track which
  473. * DSC blocks must be flushed for the next trigger.
  474. */
  475. }
  476. static bool _dce_dsc_is_dirty(struct sde_encoder_virt *sde_enc)
  477. {
  478. int i;
  479. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  480. /**
  481. * This dirty_dsc_hw field is set during DSC disable to
  482. * indicate which DSC blocks need to be flushed
  483. */
  484. if (sde_enc->dirty_dsc_ids[i])
  485. return true;
  486. }
  487. return false;
  488. }
  489. static void _dce_helper_flush_dsc(struct sde_encoder_virt *sde_enc)
  490. {
  491. int i;
  492. struct sde_hw_ctl *hw_ctl = NULL;
  493. enum sde_dsc dsc_idx;
  494. if (sde_enc->cur_master)
  495. hw_ctl = sde_enc->cur_master->hw_ctl;
  496. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  497. dsc_idx = sde_enc->dirty_dsc_ids[i];
  498. if (dsc_idx && hw_ctl && hw_ctl->ops.update_bitmask_dsc)
  499. hw_ctl->ops.update_bitmask_dsc(hw_ctl, dsc_idx, 1);
  500. sde_enc->dirty_dsc_ids[i] = DSC_NONE;
  501. }
  502. }
  503. void sde_encoder_dce_disable(struct sde_encoder_virt *sde_enc)
  504. {
  505. enum msm_display_compression_type comp_type;
  506. if (!sde_enc)
  507. return;
  508. comp_type = sde_enc->mode_info.comp_info.comp_type;
  509. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  510. _dce_dsc_disable(sde_enc);
  511. }
  512. int sde_encoder_dce_flush(struct sde_encoder_virt *sde_enc)
  513. {
  514. int rc = 0;
  515. if (!sde_enc)
  516. return -EINVAL;
  517. if (_dce_dsc_is_dirty(sde_enc))
  518. _dce_helper_flush_dsc(sde_enc);
  519. return rc;
  520. }
  521. int sde_encoder_dce_setup(struct sde_encoder_virt *sde_enc,
  522. struct sde_encoder_kickoff_params *params)
  523. {
  524. enum msm_display_compression_type comp_type;
  525. int rc = 0;
  526. if (!sde_enc)
  527. return -EINVAL;
  528. comp_type = sde_enc->mode_info.comp_info.comp_type;
  529. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  530. rc = _dce_dsc_setup(sde_enc, params);
  531. return rc;
  532. }