sde_encoder_dce.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. #include "sde_dsc_helper.h"
  25. #define SDE_DEBUG_DCE(e, fmt, ...) SDE_DEBUG("enc%d " fmt,\
  26. (e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
  27. #define SDE_ERROR_DCE(e, fmt, ...) SDE_ERROR("enc%d " fmt,\
  28. (e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
  29. bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc)
  30. {
  31. enum sde_rm_topology_name topology;
  32. struct sde_encoder_virt *sde_enc;
  33. struct drm_connector *drm_conn;
  34. if (!drm_enc)
  35. return false;
  36. sde_enc = to_sde_encoder_virt(drm_enc);
  37. if (!sde_enc->cur_master)
  38. return false;
  39. drm_conn = sde_enc->cur_master->connector;
  40. if (!drm_conn)
  41. return false;
  42. topology = sde_connector_get_topology_name(drm_conn);
  43. if (topology == SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE)
  44. return true;
  45. return false;
  46. }
  47. static int _dce_dsc_update_pic_dim(struct msm_display_dsc_info *dsc,
  48. int pic_width, int pic_height)
  49. {
  50. if (!dsc || !pic_width || !pic_height) {
  51. SDE_ERROR("invalid input: pic_width=%d pic_height=%d\n",
  52. pic_width, pic_height);
  53. return -EINVAL;
  54. }
  55. if ((pic_width % dsc->config.slice_width) ||
  56. (pic_height % dsc->config.slice_height)) {
  57. SDE_ERROR("pic_dim=%dx%d has to be multiple of slice=%dx%d\n",
  58. pic_width, pic_height,
  59. dsc->config.slice_width, dsc->config.slice_height);
  60. return -EINVAL;
  61. }
  62. dsc->config.pic_width = pic_width;
  63. dsc->config.pic_height = pic_height;
  64. return 0;
  65. }
  66. static int _dce_dsc_initial_line_calc(struct msm_display_dsc_info *dsc,
  67. int enc_ip_width,
  68. int dsc_cmn_mode)
  69. {
  70. int max_ssm_delay, max_se_size, max_muxword_size;
  71. int compress_bpp_group, obuf_latency, input_ssm_out_latency;
  72. int base_hs_latency, chunk_bits, ob_data_width;
  73. int output_rate_extra_budget_bits, multi_hs_extra_budget_bits;
  74. int multi_hs_extra_latency, mux_word_size;
  75. int ob_data_width_4comps, ob_data_width_3comps;
  76. int output_rate_ratio_complement, container_slice_width;
  77. int rtl_num_components, multi_hs_c, multi_hs_d;
  78. int bpc = dsc->config.bits_per_component;
  79. int bpp = DSC_BPP(dsc->config);
  80. int num_of_active_ss = dsc->config.slice_count;
  81. bool native_422 = dsc->config.native_422;
  82. bool native_420 = dsc->config.native_420;
  83. /* Hardent core config */
  84. int multiplex_mode_enable = 0, split_panel_enable = 0;
  85. int rtl_max_bpc = 10, rtl_output_data_width = 64;
  86. int pipeline_latency = 28;
  87. if (dsc_cmn_mode & DSC_MODE_MULTIPLEX)
  88. multiplex_mode_enable = 1;
  89. if (dsc_cmn_mode & DSC_MODE_SPLIT_PANEL)
  90. split_panel_enable = 0;
  91. container_slice_width = (native_422 ?
  92. dsc->config.slice_width / 2 : dsc->config.slice_width);
  93. max_muxword_size = ((rtl_max_bpc >= 12) ? 64 : 48);
  94. max_se_size = 4 * (rtl_max_bpc + 1);
  95. max_ssm_delay = max_se_size + max_muxword_size - 1;
  96. mux_word_size = (bpc >= 12 ? 64 : 48);
  97. compress_bpp_group = (native_422 ? 2 * bpp : bpp);
  98. input_ssm_out_latency = pipeline_latency + (3 * (max_ssm_delay + 2)
  99. * num_of_active_ss);
  100. rtl_num_components = (native_420 | native_422 ? 4 : 3);
  101. ob_data_width_4comps = ((rtl_output_data_width >= (2 *
  102. max_muxword_size)) ?
  103. rtl_output_data_width :
  104. (2 * rtl_output_data_width));
  105. ob_data_width_3comps = (rtl_output_data_width >= max_muxword_size ?
  106. rtl_output_data_width : 2 * rtl_output_data_width);
  107. ob_data_width = (rtl_num_components == 4 ?
  108. ob_data_width_4comps : ob_data_width_3comps);
  109. obuf_latency = DIV_ROUND_UP((9 * ob_data_width + mux_word_size),
  110. compress_bpp_group) + 1;
  111. base_hs_latency = dsc->config.initial_xmit_delay +
  112. input_ssm_out_latency + obuf_latency;
  113. chunk_bits = 8 * dsc->config.slice_chunk_size;
  114. output_rate_ratio_complement = ob_data_width - compress_bpp_group;
  115. output_rate_extra_budget_bits =
  116. (output_rate_ratio_complement * chunk_bits) >>
  117. (ob_data_width == 128 ? 7 : 6);
  118. multi_hs_c = split_panel_enable * multiplex_mode_enable;
  119. multi_hs_d = (num_of_active_ss > 1) * (ob_data_width >
  120. compress_bpp_group);
  121. multi_hs_extra_budget_bits = (multi_hs_c ?
  122. chunk_bits : (multi_hs_d ? chunk_bits :
  123. output_rate_extra_budget_bits));
  124. multi_hs_extra_latency = DIV_ROUND_UP(multi_hs_extra_budget_bits,
  125. compress_bpp_group);
  126. dsc->initial_lines = DIV_ROUND_UP((base_hs_latency +
  127. multi_hs_extra_latency),
  128. container_slice_width);
  129. return 0;
  130. }
  131. static bool _dce_dsc_ich_reset_override_needed(bool pu_en,
  132. struct msm_display_dsc_info *dsc)
  133. {
  134. /*
  135. * As per the DSC spec, ICH_RESET can be either end of the slice line
  136. * or at the end of the slice. HW internally generates ich_reset at
  137. * end of the slice line if DSC_MERGE is used or encoder has two
  138. * soft slices. However, if encoder has only 1 soft slice and DSC_MERGE
  139. * is not used then it will generate ich_reset at the end of slice.
  140. *
  141. * Now as per the spec, during one PPS session, position where
  142. * ich_reset is generated should not change. Now if full-screen frame
  143. * has more than 1 soft slice then HW will automatically generate
  144. * ich_reset at the end of slice_line. But for the same panel, if
  145. * partial frame is enabled and only 1 encoder is used with 1 slice,
  146. * then HW will generate ich_reset at end of the slice. This is a
  147. * mismatch. Prevent this by overriding HW's decision.
  148. */
  149. return pu_en && dsc && (dsc->config.slice_count > 1) &&
  150. (dsc->config.slice_width == dsc->config.pic_width);
  151. }
  152. static void _dce_dsc_pipe_cfg(struct sde_hw_dsc *hw_dsc,
  153. struct sde_hw_pingpong *hw_pp, struct msm_display_dsc_info *dsc,
  154. u32 common_mode, bool ich_reset, bool enable,
  155. struct sde_hw_pingpong *hw_dsc_pp)
  156. {
  157. if (!enable) {
  158. if (hw_dsc_pp && hw_dsc_pp->ops.disable_dsc)
  159. hw_dsc_pp->ops.disable_dsc(hw_dsc_pp);
  160. if (hw_dsc && hw_dsc->ops.dsc_disable)
  161. hw_dsc->ops.dsc_disable(hw_dsc);
  162. if (hw_dsc && hw_dsc->ops.bind_pingpong_blk)
  163. hw_dsc->ops.bind_pingpong_blk(hw_dsc, false,
  164. PINGPONG_MAX);
  165. return;
  166. }
  167. if (!dsc || !hw_dsc || !hw_pp) {
  168. SDE_ERROR("invalid params %d %d %d\n", !dsc, !hw_dsc,
  169. !hw_pp);
  170. return;
  171. }
  172. if (hw_dsc->ops.dsc_config)
  173. hw_dsc->ops.dsc_config(hw_dsc, dsc, common_mode, ich_reset);
  174. if (hw_dsc->ops.dsc_config_thresh)
  175. hw_dsc->ops.dsc_config_thresh(hw_dsc, dsc);
  176. if (hw_dsc_pp && hw_dsc_pp->ops.setup_dsc)
  177. hw_dsc_pp->ops.setup_dsc(hw_dsc_pp);
  178. if (hw_dsc->ops.bind_pingpong_blk)
  179. hw_dsc->ops.bind_pingpong_blk(hw_dsc, true, hw_pp->idx);
  180. if (hw_dsc_pp && hw_dsc_pp->ops.enable_dsc)
  181. hw_dsc_pp->ops.enable_dsc(hw_dsc_pp);
  182. }
  183. static int _dce_dsc_setup(struct sde_encoder_virt *sde_enc,
  184. struct sde_encoder_kickoff_params *params)
  185. {
  186. struct sde_kms *sde_kms;
  187. struct msm_drm_private *priv;
  188. struct drm_encoder *drm_enc;
  189. struct drm_connector *drm_conn;
  190. struct sde_encoder_phys *enc_master;
  191. struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC];
  192. struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC];
  193. struct sde_hw_pingpong *hw_dsc_pp[MAX_CHANNELS_PER_ENC];
  194. struct msm_display_dsc_info *dsc = NULL;
  195. enum sde_rm_topology_name topology;
  196. const struct sde_rm_topology_def *def;
  197. const struct sde_rect *roi;
  198. struct sde_hw_ctl *hw_ctl;
  199. struct sde_ctl_dsc_cfg cfg;
  200. bool half_panel_partial_update, dsc_merge;
  201. int this_frame_slices;
  202. int intf_ip_w, enc_ip_w;
  203. int num_intf, num_dsc;
  204. int ich_res;
  205. int dsc_common_mode = 0;
  206. int i;
  207. if (!sde_enc || !params || !sde_enc->phys_encs[0] ||
  208. !sde_enc->phys_encs[0]->connector)
  209. return -EINVAL;
  210. drm_conn = sde_enc->phys_encs[0]->connector;
  211. drm_enc = &sde_enc->base;
  212. priv = drm_enc->dev->dev_private;
  213. sde_kms = to_sde_kms(priv->kms);
  214. topology = sde_connector_get_topology_name(drm_conn);
  215. if (topology == SDE_RM_TOPOLOGY_NONE) {
  216. SDE_ERROR_DCE(sde_enc, "topology not set yet\n");
  217. return -EINVAL;
  218. }
  219. SDE_DEBUG_DCE(sde_enc, "topology:%d\n", topology);
  220. if (sde_kms_rect_is_equal(&sde_enc->cur_conn_roi,
  221. &sde_enc->prv_conn_roi))
  222. return 0;
  223. SDE_EVT32(DRMID(&sde_enc->base), topology,
  224. sde_enc->cur_conn_roi.x,
  225. sde_enc->cur_conn_roi.y,
  226. sde_enc->cur_conn_roi.w,
  227. sde_enc->cur_conn_roi.h,
  228. sde_enc->prv_conn_roi.x,
  229. sde_enc->prv_conn_roi.y,
  230. sde_enc->prv_conn_roi.w,
  231. sde_enc->prv_conn_roi.h,
  232. sde_enc->cur_master->cached_mode.hdisplay,
  233. sde_enc->cur_master->cached_mode.vdisplay);
  234. memset(&cfg, 0, sizeof(cfg));
  235. enc_master = sde_enc->cur_master;
  236. roi = &sde_enc->cur_conn_roi;
  237. hw_ctl = enc_master->hw_ctl;
  238. dsc = &sde_enc->mode_info.comp_info.dsc_info;
  239. def = sde_rm_topology_get_topology_def(&sde_kms->rm, topology);
  240. if (IS_ERR_OR_NULL(def))
  241. return -EINVAL;
  242. num_dsc = def->num_comp_enc;
  243. num_intf = def->num_intf;
  244. /*
  245. * If this encoder is driving more than one DSC encoder, they
  246. * operate in tandem, same pic dimension needs to be used by
  247. * each of them.(pp-split is assumed to be not supported)
  248. */
  249. _dce_dsc_update_pic_dim(dsc, roi->w, roi->h);
  250. half_panel_partial_update = (num_dsc > 1) ?
  251. (hweight_long(params->affected_displays) != num_dsc) :
  252. false;
  253. dsc_merge = (num_dsc > num_intf) ? true : false;
  254. if (!half_panel_partial_update)
  255. dsc_common_mode |= DSC_MODE_SPLIT_PANEL;
  256. if (dsc_merge)
  257. dsc_common_mode |= DSC_MODE_MULTIPLEX;
  258. if (enc_master->intf_mode == INTF_MODE_VIDEO)
  259. dsc_common_mode |= DSC_MODE_VIDEO;
  260. this_frame_slices = roi->w / dsc->config.slice_width;
  261. intf_ip_w = this_frame_slices * dsc->config.slice_width;
  262. if ((!half_panel_partial_update) && (num_intf > 1))
  263. intf_ip_w /= 2;
  264. sde_dsc_populate_dsc_private_params(dsc, intf_ip_w);
  265. /*
  266. * in dsc merge case: when using 2 encoders for the same stream,
  267. * no. of slices need to be same on both the encoders.
  268. */
  269. enc_ip_w = intf_ip_w;
  270. if (dsc_merge)
  271. enc_ip_w = intf_ip_w / 2;
  272. _dce_dsc_initial_line_calc(dsc, enc_ip_w, dsc_common_mode);
  273. /*
  274. * __is_ich_reset_override_needed should be called only after
  275. * updating pic dimension, mdss_panel_dsc_update_pic_dim.
  276. */
  277. ich_res = _dce_dsc_ich_reset_override_needed(
  278. half_panel_partial_update, dsc);
  279. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d mode:%d\n",
  280. roi->w, roi->h, dsc_common_mode);
  281. for (i = 0; i < num_dsc; i++) {
  282. bool active = !!((1 << i) & params->affected_displays);
  283. hw_pp[i] = sde_enc->hw_pp[i];
  284. hw_dsc[i] = sde_enc->hw_dsc[i];
  285. hw_dsc_pp[i] = sde_enc->hw_dsc_pp[i];
  286. if (!hw_pp[i] || !hw_dsc[i]) {
  287. SDE_ERROR_DCE(sde_enc, "invalid params for DSC\n");
  288. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h,
  289. dsc_common_mode, i, active);
  290. return -EINVAL;
  291. }
  292. _dce_dsc_pipe_cfg(hw_dsc[i], hw_pp[i], dsc,
  293. dsc_common_mode, ich_res, active, hw_dsc_pp[i]);
  294. if (active) {
  295. if (cfg.dsc_count >= MAX_DSC_PER_CTL_V1) {
  296. pr_err("Invalid dsc count:%d\n",
  297. cfg.dsc_count);
  298. return -EINVAL;
  299. }
  300. cfg.dsc[cfg.dsc_count++] = hw_dsc[i]->idx;
  301. if (hw_ctl->ops.update_bitmask_dsc)
  302. hw_ctl->ops.update_bitmask_dsc(hw_ctl,
  303. hw_dsc[i]->idx, 1);
  304. }
  305. }
  306. /* setup dsc active configuration in the control path */
  307. if (hw_ctl->ops.setup_dsc_cfg) {
  308. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  309. SDE_DEBUG_DCE(sde_enc,
  310. "setup dsc_cfg hw_ctl[%d], count:%d,dsc[0]:%d, dsc[1]:%d\n",
  311. hw_ctl->idx,
  312. cfg.dsc_count,
  313. cfg.dsc[0],
  314. cfg.dsc[1]);
  315. }
  316. return 0;
  317. }
  318. static void _dce_dsc_disable(struct sde_encoder_virt *sde_enc)
  319. {
  320. int i;
  321. struct sde_hw_pingpong *hw_pp = NULL;
  322. struct sde_hw_pingpong *hw_dsc_pp = NULL;
  323. struct sde_hw_dsc *hw_dsc = NULL;
  324. struct sde_hw_ctl *hw_ctl = NULL;
  325. struct sde_ctl_dsc_cfg cfg;
  326. if (!sde_enc || !sde_enc->phys_encs[0] ||
  327. !sde_enc->phys_encs[0]->connector) {
  328. SDE_ERROR("invalid params %d %d\n",
  329. !sde_enc, sde_enc ? !sde_enc->phys_encs[0] : -1);
  330. return;
  331. }
  332. if (sde_enc->cur_master)
  333. hw_ctl = sde_enc->cur_master->hw_ctl;
  334. /* Disable DSC for all the pp's present in this topology */
  335. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  336. hw_pp = sde_enc->hw_pp[i];
  337. hw_dsc = sde_enc->hw_dsc[i];
  338. hw_dsc_pp = sde_enc->hw_dsc_pp[i];
  339. _dce_dsc_pipe_cfg(hw_dsc, hw_pp, NULL,
  340. 0, 0, 0, hw_dsc_pp);
  341. if (hw_dsc)
  342. sde_enc->dirty_dsc_ids[i] = hw_dsc->idx;
  343. }
  344. /* Clear the DSC ACTIVE config for this CTL */
  345. if (hw_ctl && hw_ctl->ops.setup_dsc_cfg) {
  346. memset(&cfg, 0, sizeof(cfg));
  347. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  348. }
  349. /**
  350. * Since pending flushes from previous commit get cleared
  351. * sometime after this point, setting DSC flush bits now
  352. * will have no effect. Therefore dirty_dsc_ids track which
  353. * DSC blocks must be flushed for the next trigger.
  354. */
  355. }
  356. static bool _dce_dsc_is_dirty(struct sde_encoder_virt *sde_enc)
  357. {
  358. int i;
  359. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  360. /**
  361. * This dirty_dsc_hw field is set during DSC disable to
  362. * indicate which DSC blocks need to be flushed
  363. */
  364. if (sde_enc->dirty_dsc_ids[i])
  365. return true;
  366. }
  367. return false;
  368. }
  369. static void _dce_helper_flush_dsc(struct sde_encoder_virt *sde_enc)
  370. {
  371. int i;
  372. struct sde_hw_ctl *hw_ctl = NULL;
  373. enum sde_dsc dsc_idx;
  374. if (sde_enc->cur_master)
  375. hw_ctl = sde_enc->cur_master->hw_ctl;
  376. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  377. dsc_idx = sde_enc->dirty_dsc_ids[i];
  378. if (dsc_idx && hw_ctl && hw_ctl->ops.update_bitmask_dsc)
  379. hw_ctl->ops.update_bitmask_dsc(hw_ctl, dsc_idx, 1);
  380. sde_enc->dirty_dsc_ids[i] = DSC_NONE;
  381. }
  382. }
  383. void sde_encoder_dce_disable(struct sde_encoder_virt *sde_enc)
  384. {
  385. enum msm_display_compression_type comp_type;
  386. if (!sde_enc)
  387. return;
  388. comp_type = sde_enc->mode_info.comp_info.comp_type;
  389. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  390. _dce_dsc_disable(sde_enc);
  391. }
  392. int sde_encoder_dce_flush(struct sde_encoder_virt *sde_enc)
  393. {
  394. int rc = 0;
  395. if (!sde_enc)
  396. return -EINVAL;
  397. if (_dce_dsc_is_dirty(sde_enc))
  398. _dce_helper_flush_dsc(sde_enc);
  399. return rc;
  400. }
  401. int sde_encoder_dce_setup(struct sde_encoder_virt *sde_enc,
  402. struct sde_encoder_kickoff_params *params)
  403. {
  404. enum msm_display_compression_type comp_type;
  405. int rc = 0;
  406. if (!sde_enc)
  407. return -EINVAL;
  408. comp_type = sde_enc->mode_info.comp_info.comp_type;
  409. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  410. rc = _dce_dsc_setup(sde_enc, params);
  411. return rc;
  412. }