sde_encoder_dce.c 28 KB

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