sde_encoder_dce.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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 _dce_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 _dce_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 _dce_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 _dce_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 _dce_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 _dce_dsc_setup(struct sde_encoder_virt *sde_enc,
  169. struct sde_encoder_kickoff_params *params)
  170. {
  171. struct sde_kms *sde_kms;
  172. struct msm_drm_private *priv;
  173. struct drm_encoder *drm_enc;
  174. struct drm_connector *drm_conn;
  175. struct sde_encoder_phys *enc_master;
  176. struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC];
  177. struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC];
  178. struct sde_hw_pingpong *hw_dsc_pp[MAX_CHANNELS_PER_ENC];
  179. struct msm_display_dsc_info *dsc = NULL;
  180. enum sde_rm_topology_name topology;
  181. const struct sde_rm_topology_def *def;
  182. const struct sde_rect *roi;
  183. struct sde_hw_ctl *hw_ctl;
  184. struct sde_ctl_dsc_cfg cfg;
  185. bool half_panel_partial_update, dsc_merge;
  186. int this_frame_slices;
  187. int intf_ip_w, enc_ip_w;
  188. int num_intf, num_dsc;
  189. int ich_res;
  190. int dsc_common_mode = 0;
  191. int i;
  192. if (!sde_enc || !params || !sde_enc->phys_encs[0] ||
  193. !sde_enc->phys_encs[0]->connector)
  194. return -EINVAL;
  195. drm_conn = sde_enc->phys_encs[0]->connector;
  196. drm_enc = &sde_enc->base;
  197. priv = drm_enc->dev->dev_private;
  198. sde_kms = to_sde_kms(priv->kms);
  199. topology = sde_connector_get_topology_name(drm_conn);
  200. if (topology == SDE_RM_TOPOLOGY_NONE) {
  201. SDE_ERROR_DCE(sde_enc, "topology not set yet\n");
  202. return -EINVAL;
  203. }
  204. SDE_DEBUG_DCE(sde_enc, "topology:%d\n", topology);
  205. if (sde_kms_rect_is_equal(&sde_enc->cur_conn_roi,
  206. &sde_enc->prv_conn_roi))
  207. return 0;
  208. SDE_EVT32(DRMID(&sde_enc->base), topology,
  209. sde_enc->cur_conn_roi.x,
  210. sde_enc->cur_conn_roi.y,
  211. sde_enc->cur_conn_roi.w,
  212. sde_enc->cur_conn_roi.h,
  213. sde_enc->prv_conn_roi.x,
  214. sde_enc->prv_conn_roi.y,
  215. sde_enc->prv_conn_roi.w,
  216. sde_enc->prv_conn_roi.h,
  217. sde_enc->cur_master->cached_mode.hdisplay,
  218. sde_enc->cur_master->cached_mode.vdisplay);
  219. memset(&cfg, 0, sizeof(cfg));
  220. enc_master = sde_enc->cur_master;
  221. roi = &sde_enc->cur_conn_roi;
  222. hw_ctl = enc_master->hw_ctl;
  223. dsc = &sde_enc->mode_info.comp_info.dsc_info;
  224. def = sde_rm_topology_get_topology_def(&sde_kms->rm, topology);
  225. if (IS_ERR_OR_NULL(def))
  226. return -EINVAL;
  227. num_dsc = def->num_comp_enc;
  228. num_intf = def->num_intf;
  229. /*
  230. * If this encoder is driving more than one DSC encoder, they
  231. * operate in tandem, same pic dimension needs to be used by
  232. * each of them.(pp-split is assumed to be not supported)
  233. */
  234. _dce_dsc_update_pic_dim(dsc, roi->w, roi->h);
  235. half_panel_partial_update = (num_dsc > 1) ?
  236. (hweight_long(params->affected_displays) != num_dsc) :
  237. false;
  238. dsc_merge = (num_dsc > num_intf) ? true : false;
  239. if (!half_panel_partial_update)
  240. dsc_common_mode |= DSC_MODE_SPLIT_PANEL;
  241. if (dsc_merge)
  242. dsc_common_mode |= DSC_MODE_MULTIPLEX;
  243. if (enc_master->intf_mode == INTF_MODE_VIDEO)
  244. dsc_common_mode |= DSC_MODE_VIDEO;
  245. this_frame_slices = roi->w / dsc->slice_width;
  246. intf_ip_w = this_frame_slices * dsc->slice_width;
  247. if ((!half_panel_partial_update) && (num_intf > 1))
  248. intf_ip_w /= 2;
  249. _dce_dsc_pclk_param_calc(dsc, intf_ip_w);
  250. /*
  251. * in dsc merge case: when using 2 encoders for the same stream,
  252. * no. of slices need to be same on both the encoders.
  253. */
  254. enc_ip_w = intf_ip_w;
  255. if (dsc_merge)
  256. enc_ip_w = intf_ip_w / 2;
  257. _dce_dsc_initial_line_calc(dsc, enc_ip_w);
  258. /*
  259. * __is_ich_reset_override_needed should be called only after
  260. * updating pic dimension, mdss_panel_dsc_update_pic_dim.
  261. */
  262. ich_res = _dce_dsc_ich_reset_override_needed(
  263. half_panel_partial_update, dsc);
  264. SDE_DEBUG_DCE(sde_enc, "pic_w: %d pic_h: %d mode:%d\n",
  265. roi->w, roi->h, dsc_common_mode);
  266. for (i = 0; i < num_dsc; i++) {
  267. bool active = !!((1 << i) & params->affected_displays);
  268. hw_pp[i] = sde_enc->hw_pp[i];
  269. hw_dsc[i] = sde_enc->hw_dsc[i];
  270. hw_dsc_pp[i] = sde_enc->hw_dsc_pp[i];
  271. if (!hw_pp[i] || !hw_dsc[i] || !hw_dsc_pp[i]) {
  272. SDE_ERROR_DCE(sde_enc, "invalid params for DSC\n");
  273. SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h,
  274. dsc_common_mode, i, active);
  275. return -EINVAL;
  276. }
  277. _dce_dsc_pipe_cfg(hw_dsc[i], hw_pp[i], dsc,
  278. dsc_common_mode, ich_res, active, hw_dsc_pp[i]);
  279. if (active) {
  280. if (cfg.dsc_count >= MAX_DSC_PER_CTL_V1) {
  281. pr_err("Invalid dsc count:%d\n",
  282. cfg.dsc_count);
  283. return -EINVAL;
  284. }
  285. cfg.dsc[cfg.dsc_count++] = hw_dsc[i]->idx;
  286. if (hw_ctl->ops.update_bitmask_dsc)
  287. hw_ctl->ops.update_bitmask_dsc(hw_ctl,
  288. hw_dsc[i]->idx, 1);
  289. }
  290. }
  291. /* setup dsc active configuration in the control path */
  292. if (hw_ctl->ops.setup_dsc_cfg) {
  293. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  294. SDE_DEBUG_DCE(sde_enc,
  295. "setup dsc_cfg hw_ctl[%d], count:%d,dsc[0]:%d, dsc[1]:%d\n",
  296. hw_ctl->idx,
  297. cfg.dsc_count,
  298. cfg.dsc[0],
  299. cfg.dsc[1]);
  300. }
  301. return 0;
  302. }
  303. static void _dce_dsc_disable(struct sde_encoder_virt *sde_enc)
  304. {
  305. int i;
  306. struct sde_hw_pingpong *hw_pp = NULL;
  307. struct sde_hw_pingpong *hw_dsc_pp = NULL;
  308. struct sde_hw_dsc *hw_dsc = NULL;
  309. struct sde_hw_ctl *hw_ctl = NULL;
  310. struct sde_ctl_dsc_cfg cfg;
  311. if (!sde_enc || !sde_enc->phys_encs[0] ||
  312. !sde_enc->phys_encs[0]->connector) {
  313. SDE_ERROR("invalid params %d %d\n",
  314. !sde_enc, sde_enc ? !sde_enc->phys_encs[0] : -1);
  315. return;
  316. }
  317. if (sde_enc->cur_master)
  318. hw_ctl = sde_enc->cur_master->hw_ctl;
  319. /* Disable DSC for all the pp's present in this topology */
  320. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  321. hw_pp = sde_enc->hw_pp[i];
  322. hw_dsc = sde_enc->hw_dsc[i];
  323. hw_dsc_pp = sde_enc->hw_dsc_pp[i];
  324. _dce_dsc_pipe_cfg(hw_dsc, hw_pp, NULL,
  325. 0, 0, 0, hw_dsc_pp);
  326. if (hw_dsc)
  327. sde_enc->dirty_dsc_ids[i] = hw_dsc->idx;
  328. }
  329. /* Clear the DSC ACTIVE config for this CTL */
  330. if (hw_ctl && hw_ctl->ops.setup_dsc_cfg) {
  331. memset(&cfg, 0, sizeof(cfg));
  332. hw_ctl->ops.setup_dsc_cfg(hw_ctl, &cfg);
  333. }
  334. /**
  335. * Since pending flushes from previous commit get cleared
  336. * sometime after this point, setting DSC flush bits now
  337. * will have no effect. Therefore dirty_dsc_ids track which
  338. * DSC blocks must be flushed for the next trigger.
  339. */
  340. }
  341. static bool _dce_dsc_is_dirty(struct sde_encoder_virt *sde_enc)
  342. {
  343. int i;
  344. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  345. /**
  346. * This dirty_dsc_hw field is set during DSC disable to
  347. * indicate which DSC blocks need to be flushed
  348. */
  349. if (sde_enc->dirty_dsc_ids[i])
  350. return true;
  351. }
  352. return false;
  353. }
  354. static void _dce_helper_flush_dsc(struct sde_encoder_virt *sde_enc)
  355. {
  356. int i;
  357. struct sde_hw_ctl *hw_ctl = NULL;
  358. enum sde_dsc dsc_idx;
  359. if (sde_enc->cur_master)
  360. hw_ctl = sde_enc->cur_master->hw_ctl;
  361. for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
  362. dsc_idx = sde_enc->dirty_dsc_ids[i];
  363. if (dsc_idx && hw_ctl && hw_ctl->ops.update_bitmask_dsc)
  364. hw_ctl->ops.update_bitmask_dsc(hw_ctl, dsc_idx, 1);
  365. sde_enc->dirty_dsc_ids[i] = DSC_NONE;
  366. }
  367. }
  368. void sde_encoder_dce_disable(struct sde_encoder_virt *sde_enc)
  369. {
  370. enum msm_display_compression_type comp_type;
  371. if (!sde_enc)
  372. return;
  373. comp_type = sde_enc->mode_info.comp_info.comp_type;
  374. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  375. _dce_dsc_disable(sde_enc);
  376. }
  377. int sde_encoder_dce_flush(struct sde_encoder_virt *sde_enc)
  378. {
  379. int rc = 0;
  380. if (!sde_enc)
  381. return -EINVAL;
  382. if (_dce_dsc_is_dirty(sde_enc))
  383. _dce_helper_flush_dsc(sde_enc);
  384. return rc;
  385. }
  386. int sde_encoder_dce_setup(struct sde_encoder_virt *sde_enc,
  387. struct sde_encoder_kickoff_params *params)
  388. {
  389. enum msm_display_compression_type comp_type;
  390. int rc = 0;
  391. if (!sde_enc)
  392. return -EINVAL;
  393. comp_type = sde_enc->mode_info.comp_info.comp_type;
  394. if (comp_type == MSM_DISPLAY_COMPRESSION_DSC)
  395. rc = _dce_dsc_setup(sde_enc, params);
  396. return rc;
  397. }