xref: /dflybsd-src/sys/dev/drm/amd/display/dc/calcs/dcn_calcs.c (revision 789731325bde747251c28a37e0a00ed4efb88c46)
1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2017 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev  *
4b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10b843c749SSergey Zigachev  *
11b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13b843c749SSergey Zigachev  *
14b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21b843c749SSergey Zigachev  *
22b843c749SSergey Zigachev  * Authors: AMD
23b843c749SSergey Zigachev  *
24b843c749SSergey Zigachev  */
25b843c749SSergey Zigachev 
26b843c749SSergey Zigachev #include "dm_services.h"
27b843c749SSergey Zigachev #include "dcn_calcs.h"
28b843c749SSergey Zigachev #include "dcn_calc_auto.h"
29b843c749SSergey Zigachev #include "dc.h"
30b843c749SSergey Zigachev #include "dal_asic_id.h"
31b843c749SSergey Zigachev 
32b843c749SSergey Zigachev #include "resource.h"
33b843c749SSergey Zigachev #include "dcn10/dcn10_resource.h"
34b843c749SSergey Zigachev #include "dcn10/dcn10_hubbub.h"
35b843c749SSergey Zigachev 
36b843c749SSergey Zigachev #include "dcn_calc_math.h"
37b843c749SSergey Zigachev 
38*78973132SSergey Zigachev 
39b843c749SSergey Zigachev #define DC_LOGGER \
40b843c749SSergey Zigachev 	dc->ctx->logger
41b843c749SSergey Zigachev /*
42b843c749SSergey Zigachev  * NOTE:
43b843c749SSergey Zigachev  *   This file is gcc-parseable HW gospel, coming straight from HW engineers.
44b843c749SSergey Zigachev  *
45b843c749SSergey Zigachev  * It doesn't adhere to Linux kernel style and sometimes will do things in odd
46b843c749SSergey Zigachev  * ways. Unless there is something clearly wrong with it the code should
47b843c749SSergey Zigachev  * remain as-is as it provides us with a guarantee from HW that it is correct.
48b843c749SSergey Zigachev  */
49b843c749SSergey Zigachev 
50b843c749SSergey Zigachev /* Defaults from spreadsheet rev#247 */
51b843c749SSergey Zigachev const struct dcn_soc_bounding_box dcn10_soc_defaults = {
52b843c749SSergey Zigachev 		/* latencies */
53b843c749SSergey Zigachev 		.sr_exit_time = 17, /*us*/
54b843c749SSergey Zigachev 		.sr_enter_plus_exit_time = 19, /*us*/
55b843c749SSergey Zigachev 		.urgent_latency = 4, /*us*/
56b843c749SSergey Zigachev 		.dram_clock_change_latency = 17, /*us*/
57b843c749SSergey Zigachev 		.write_back_latency = 12, /*us*/
58b843c749SSergey Zigachev 		.percent_of_ideal_drambw_received_after_urg_latency = 80, /*%*/
59b843c749SSergey Zigachev 
60b843c749SSergey Zigachev 		/* below default clocks derived from STA target base on
61b843c749SSergey Zigachev 		 * slow-slow corner + 10% margin with voltages aligned to FCLK.
62b843c749SSergey Zigachev 		 *
63b843c749SSergey Zigachev 		 * Use these value if fused value doesn't make sense as earlier
64b843c749SSergey Zigachev 		 * part don't have correct value fused */
65b843c749SSergey Zigachev 		/* default DCF CLK DPM on RV*/
66b843c749SSergey Zigachev 		.dcfclkv_max0p9 = 655,	/* MHz, = 3600/5.5 */
67b843c749SSergey Zigachev 		.dcfclkv_nom0p8 = 626,	/* MHz, = 3600/5.75 */
68b843c749SSergey Zigachev 		.dcfclkv_mid0p72 = 600,	/* MHz, = 3600/6, bypass */
69b843c749SSergey Zigachev 		.dcfclkv_min0p65 = 300,	/* MHz, = 3600/12, bypass */
70b843c749SSergey Zigachev 
71b843c749SSergey Zigachev 		/* default DISP CLK voltage state on RV */
72b843c749SSergey Zigachev 		.max_dispclk_vmax0p9 = 1108,	/* MHz, = 3600/3.25 */
73b843c749SSergey Zigachev 		.max_dispclk_vnom0p8 = 1029,	/* MHz, = 3600/3.5 */
74b843c749SSergey Zigachev 		.max_dispclk_vmid0p72 = 960,	/* MHz, = 3600/3.75 */
75b843c749SSergey Zigachev 		.max_dispclk_vmin0p65 = 626,	/* MHz, = 3600/5.75 */
76b843c749SSergey Zigachev 
77b843c749SSergey Zigachev 		/* default DPP CLK voltage state on RV */
78b843c749SSergey Zigachev 		.max_dppclk_vmax0p9 = 720,	/* MHz, = 3600/5 */
79b843c749SSergey Zigachev 		.max_dppclk_vnom0p8 = 686,	/* MHz, = 3600/5.25 */
80b843c749SSergey Zigachev 		.max_dppclk_vmid0p72 = 626,	/* MHz, = 3600/5.75 */
81b843c749SSergey Zigachev 		.max_dppclk_vmin0p65 = 400,	/* MHz, = 3600/9 */
82b843c749SSergey Zigachev 
83b843c749SSergey Zigachev 		/* default PHY CLK voltage state on RV */
84b843c749SSergey Zigachev 		.phyclkv_max0p9 = 900, /*MHz*/
85b843c749SSergey Zigachev 		.phyclkv_nom0p8 = 847, /*MHz*/
86b843c749SSergey Zigachev 		.phyclkv_mid0p72 = 800, /*MHz*/
87b843c749SSergey Zigachev 		.phyclkv_min0p65 = 600, /*MHz*/
88b843c749SSergey Zigachev 
89b843c749SSergey Zigachev 		/* BW depend on FCLK, MCLK, # of channels */
90b843c749SSergey Zigachev 		/* dual channel BW */
91b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vmax0p9 = 38.4f, /*GB/s*/
92b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vnom0p8 = 34.133f, /*GB/s*/
93b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vmid0p72 = 29.866f, /*GB/s*/
94b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vmin0p65 = 12.8f, /*GB/s*/
95b843c749SSergey Zigachev 		/* single channel BW
96b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vmax0p9 = 19.2f,
97b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vnom0p8 = 17.066f,
98b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vmid0p72 = 14.933f,
99b843c749SSergey Zigachev 		.fabric_and_dram_bandwidth_vmin0p65 = 12.8f,
100b843c749SSergey Zigachev 		*/
101b843c749SSergey Zigachev 
102b843c749SSergey Zigachev 		.number_of_channels = 2,
103b843c749SSergey Zigachev 
104b843c749SSergey Zigachev 		.socclk = 208, /*MHz*/
105b843c749SSergey Zigachev 		.downspreading = 0.5f, /*%*/
106b843c749SSergey Zigachev 		.round_trip_ping_latency_cycles = 128, /*DCFCLK Cycles*/
107b843c749SSergey Zigachev 		.urgent_out_of_order_return_per_channel = 256, /*bytes*/
108b843c749SSergey Zigachev 		.vmm_page_size = 4096, /*bytes*/
109b843c749SSergey Zigachev 		.return_bus_width = 64, /*bytes*/
110b843c749SSergey Zigachev 		.max_request_size = 256, /*bytes*/
111b843c749SSergey Zigachev 
112b843c749SSergey Zigachev 		/* Depends on user class (client vs embedded, workstation, etc) */
113b843c749SSergey Zigachev 		.percent_disp_bw_limit = 0.3f /*%*/
114b843c749SSergey Zigachev };
115b843c749SSergey Zigachev 
116b843c749SSergey Zigachev const struct dcn_ip_params dcn10_ip_defaults = {
117b843c749SSergey Zigachev 		.rob_buffer_size_in_kbyte = 64,
118b843c749SSergey Zigachev 		.det_buffer_size_in_kbyte = 164,
119b843c749SSergey Zigachev 		.dpp_output_buffer_pixels = 2560,
120b843c749SSergey Zigachev 		.opp_output_buffer_lines = 1,
121b843c749SSergey Zigachev 		.pixel_chunk_size_in_kbyte = 8,
122b843c749SSergey Zigachev 		.pte_enable = dcn_bw_yes,
123b843c749SSergey Zigachev 		.pte_chunk_size = 2, /*kbytes*/
124b843c749SSergey Zigachev 		.meta_chunk_size = 2, /*kbytes*/
125b843c749SSergey Zigachev 		.writeback_chunk_size = 2, /*kbytes*/
126b843c749SSergey Zigachev 		.odm_capability = dcn_bw_no,
127b843c749SSergey Zigachev 		.dsc_capability = dcn_bw_no,
128b843c749SSergey Zigachev 		.line_buffer_size = 589824, /*bit*/
129b843c749SSergey Zigachev 		.max_line_buffer_lines = 12,
130b843c749SSergey Zigachev 		.is_line_buffer_bpp_fixed = dcn_bw_no,
131b843c749SSergey Zigachev 		.line_buffer_fixed_bpp = dcn_bw_na,
132b843c749SSergey Zigachev 		.writeback_luma_buffer_size = 12, /*kbytes*/
133b843c749SSergey Zigachev 		.writeback_chroma_buffer_size = 8, /*kbytes*/
134b843c749SSergey Zigachev 		.max_num_dpp = 4,
135b843c749SSergey Zigachev 		.max_num_writeback = 2,
136b843c749SSergey Zigachev 		.max_dchub_topscl_throughput = 4, /*pixels/dppclk*/
137b843c749SSergey Zigachev 		.max_pscl_tolb_throughput = 2, /*pixels/dppclk*/
138b843c749SSergey Zigachev 		.max_lb_tovscl_throughput = 4, /*pixels/dppclk*/
139b843c749SSergey Zigachev 		.max_vscl_tohscl_throughput = 4, /*pixels/dppclk*/
140b843c749SSergey Zigachev 		.max_hscl_ratio = 4,
141b843c749SSergey Zigachev 		.max_vscl_ratio = 4,
142b843c749SSergey Zigachev 		.max_hscl_taps = 8,
143b843c749SSergey Zigachev 		.max_vscl_taps = 8,
144b843c749SSergey Zigachev 		.pte_buffer_size_in_requests = 42,
145b843c749SSergey Zigachev 		.dispclk_ramping_margin = 1, /*%*/
146b843c749SSergey Zigachev 		.under_scan_factor = 1.11f,
147b843c749SSergey Zigachev 		.max_inter_dcn_tile_repeaters = 8,
148b843c749SSergey Zigachev 		.can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one = dcn_bw_no,
149b843c749SSergey Zigachev 		.bug_forcing_luma_and_chroma_request_to_same_size_fixed = dcn_bw_no,
150b843c749SSergey Zigachev 		.dcfclk_cstate_latency = 10 /*TODO clone of something else? sr_enter_plus_exit_time?*/
151b843c749SSergey Zigachev };
152b843c749SSergey Zigachev 
tl_sw_mode_to_bw_defs(enum swizzle_mode_values sw_mode)153b843c749SSergey Zigachev static enum dcn_bw_defs tl_sw_mode_to_bw_defs(enum swizzle_mode_values sw_mode)
154b843c749SSergey Zigachev {
155b843c749SSergey Zigachev 	switch (sw_mode) {
156b843c749SSergey Zigachev 	case DC_SW_LINEAR:
157b843c749SSergey Zigachev 		return dcn_bw_sw_linear;
158b843c749SSergey Zigachev 	case DC_SW_4KB_S:
159b843c749SSergey Zigachev 		return dcn_bw_sw_4_kb_s;
160b843c749SSergey Zigachev 	case DC_SW_4KB_D:
161b843c749SSergey Zigachev 		return dcn_bw_sw_4_kb_d;
162b843c749SSergey Zigachev 	case DC_SW_64KB_S:
163b843c749SSergey Zigachev 		return dcn_bw_sw_64_kb_s;
164b843c749SSergey Zigachev 	case DC_SW_64KB_D:
165b843c749SSergey Zigachev 		return dcn_bw_sw_64_kb_d;
166b843c749SSergey Zigachev 	case DC_SW_VAR_S:
167b843c749SSergey Zigachev 		return dcn_bw_sw_var_s;
168b843c749SSergey Zigachev 	case DC_SW_VAR_D:
169b843c749SSergey Zigachev 		return dcn_bw_sw_var_d;
170b843c749SSergey Zigachev 	case DC_SW_64KB_S_T:
171b843c749SSergey Zigachev 		return dcn_bw_sw_64_kb_s_t;
172b843c749SSergey Zigachev 	case DC_SW_64KB_D_T:
173b843c749SSergey Zigachev 		return dcn_bw_sw_64_kb_d_t;
174b843c749SSergey Zigachev 	case DC_SW_4KB_S_X:
175b843c749SSergey Zigachev 		return dcn_bw_sw_4_kb_s_x;
176b843c749SSergey Zigachev 	case DC_SW_4KB_D_X:
177b843c749SSergey Zigachev 		return dcn_bw_sw_4_kb_d_x;
178b843c749SSergey Zigachev 	case DC_SW_64KB_S_X:
179b843c749SSergey Zigachev 		return dcn_bw_sw_64_kb_s_x;
180b843c749SSergey Zigachev 	case DC_SW_64KB_D_X:
181b843c749SSergey Zigachev 		return dcn_bw_sw_64_kb_d_x;
182b843c749SSergey Zigachev 	case DC_SW_VAR_S_X:
183b843c749SSergey Zigachev 		return dcn_bw_sw_var_s_x;
184b843c749SSergey Zigachev 	case DC_SW_VAR_D_X:
185b843c749SSergey Zigachev 		return dcn_bw_sw_var_d_x;
186b843c749SSergey Zigachev 	case DC_SW_256B_S:
187b843c749SSergey Zigachev 	case DC_SW_256_D:
188b843c749SSergey Zigachev 	case DC_SW_256_R:
189b843c749SSergey Zigachev 	case DC_SW_4KB_R:
190b843c749SSergey Zigachev 	case DC_SW_64KB_R:
191b843c749SSergey Zigachev 	case DC_SW_VAR_R:
192b843c749SSergey Zigachev 	case DC_SW_4KB_R_X:
193b843c749SSergey Zigachev 	case DC_SW_64KB_R_X:
194b843c749SSergey Zigachev 	case DC_SW_VAR_R_X:
195b843c749SSergey Zigachev 	default:
196b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER(); /*not in formula*/
197b843c749SSergey Zigachev 		return dcn_bw_sw_4_kb_s;
198b843c749SSergey Zigachev 	}
199b843c749SSergey Zigachev }
200b843c749SSergey Zigachev 
tl_lb_bpp_to_int(enum lb_pixel_depth depth)201b843c749SSergey Zigachev static int tl_lb_bpp_to_int(enum lb_pixel_depth depth)
202b843c749SSergey Zigachev {
203b843c749SSergey Zigachev 	switch (depth) {
204b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_18BPP:
205b843c749SSergey Zigachev 		return 18;
206b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_24BPP:
207b843c749SSergey Zigachev 		return 24;
208b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_30BPP:
209b843c749SSergey Zigachev 		return 30;
210b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_36BPP:
211b843c749SSergey Zigachev 		return 36;
212b843c749SSergey Zigachev 	default:
213b843c749SSergey Zigachev 		return 30;
214b843c749SSergey Zigachev 	}
215b843c749SSergey Zigachev }
216b843c749SSergey Zigachev 
tl_pixel_format_to_bw_defs(enum surface_pixel_format format)217b843c749SSergey Zigachev static enum dcn_bw_defs tl_pixel_format_to_bw_defs(enum surface_pixel_format format)
218b843c749SSergey Zigachev {
219b843c749SSergey Zigachev 	switch (format) {
220b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
221b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
222b843c749SSergey Zigachev 		return dcn_bw_rgb_sub_16;
223b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
224b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
225b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
226b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
227b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
228b843c749SSergey Zigachev 		return dcn_bw_rgb_sub_32;
229b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
230b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
231b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
232b843c749SSergey Zigachev 		return dcn_bw_rgb_sub_64;
233b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
234b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
235b843c749SSergey Zigachev 		return dcn_bw_yuv420_sub_8;
236b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
237b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
238b843c749SSergey Zigachev 		return dcn_bw_yuv420_sub_10;
239b843c749SSergey Zigachev 	default:
240b843c749SSergey Zigachev 		return dcn_bw_rgb_sub_32;
241b843c749SSergey Zigachev 	}
242b843c749SSergey Zigachev }
243b843c749SSergey Zigachev 
pipe_ctx_to_e2e_pipe_params(const struct pipe_ctx * pipe,struct _vcs_dpi_display_pipe_params_st * input)244b843c749SSergey Zigachev static void pipe_ctx_to_e2e_pipe_params (
245b843c749SSergey Zigachev 		const struct pipe_ctx *pipe,
246b843c749SSergey Zigachev 		struct _vcs_dpi_display_pipe_params_st *input)
247b843c749SSergey Zigachev {
248b843c749SSergey Zigachev 	input->src.is_hsplit = false;
249b843c749SSergey Zigachev 	if (pipe->top_pipe != NULL && pipe->top_pipe->plane_state == pipe->plane_state)
250b843c749SSergey Zigachev 		input->src.is_hsplit = true;
251b843c749SSergey Zigachev 	else if (pipe->bottom_pipe != NULL && pipe->bottom_pipe->plane_state == pipe->plane_state)
252b843c749SSergey Zigachev 		input->src.is_hsplit = true;
253b843c749SSergey Zigachev 
254b843c749SSergey Zigachev 	if (pipe->plane_res.dpp->ctx->dc->debug.optimized_watermark) {
255b843c749SSergey Zigachev 		/*
256b843c749SSergey Zigachev 		 * this method requires us to always re-calculate watermark when dcc change
257b843c749SSergey Zigachev 		 * between flip.
258b843c749SSergey Zigachev 		 */
259b843c749SSergey Zigachev 		input->src.dcc = pipe->plane_state->dcc.enable ? 1 : 0;
260b843c749SSergey Zigachev 	} else {
261b843c749SSergey Zigachev 		/*
262b843c749SSergey Zigachev 		 * allow us to disable dcc on the fly without re-calculating WM
263b843c749SSergey Zigachev 		 *
264b843c749SSergey Zigachev 		 * extra overhead for DCC is quite small.  for 1080p WM without
265b843c749SSergey Zigachev 		 * DCC is only 0.417us lower (urgent goes from 6.979us to 6.562us)
266b843c749SSergey Zigachev 		 */
267b843c749SSergey Zigachev 		unsigned int bpe;
268b843c749SSergey Zigachev 
269b843c749SSergey Zigachev 		input->src.dcc = pipe->plane_res.dpp->ctx->dc->res_pool->hubbub->funcs->
270b843c749SSergey Zigachev 			dcc_support_pixel_format(pipe->plane_state->format, &bpe) ? 1 : 0;
271b843c749SSergey Zigachev 	}
272b843c749SSergey Zigachev 	input->src.dcc_rate            = 1;
273b843c749SSergey Zigachev 	input->src.meta_pitch          = pipe->plane_state->dcc.grph.meta_pitch;
274b843c749SSergey Zigachev 	input->src.source_scan         = dm_horz;
275b843c749SSergey Zigachev 	input->src.sw_mode             = pipe->plane_state->tiling_info.gfx9.swizzle;
276b843c749SSergey Zigachev 
277b843c749SSergey Zigachev 	input->src.viewport_width      = pipe->plane_res.scl_data.viewport.width;
278b843c749SSergey Zigachev 	input->src.viewport_height     = pipe->plane_res.scl_data.viewport.height;
279b843c749SSergey Zigachev 	input->src.data_pitch          = pipe->plane_res.scl_data.viewport.width;
280b843c749SSergey Zigachev 	input->src.data_pitch_c        = pipe->plane_res.scl_data.viewport.width;
281b843c749SSergey Zigachev 	input->src.cur0_src_width      = 128; /* TODO: Cursor calcs, not curently stored */
282b843c749SSergey Zigachev 	input->src.cur0_bpp            = 32;
283b843c749SSergey Zigachev 
284b843c749SSergey Zigachev 	switch (pipe->plane_state->tiling_info.gfx9.swizzle) {
285b843c749SSergey Zigachev 	/* for 4/8/16 high tiles */
286b843c749SSergey Zigachev 	case DC_SW_LINEAR:
287b843c749SSergey Zigachev 		input->src.is_display_sw = 1;
288b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_4k_tile;
289b843c749SSergey Zigachev 		break;
290b843c749SSergey Zigachev 	case DC_SW_4KB_S:
291b843c749SSergey Zigachev 	case DC_SW_4KB_S_X:
292b843c749SSergey Zigachev 		input->src.is_display_sw = 0;
293b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_4k_tile;
294b843c749SSergey Zigachev 		break;
295b843c749SSergey Zigachev 	case DC_SW_64KB_S:
296b843c749SSergey Zigachev 	case DC_SW_64KB_S_X:
297b843c749SSergey Zigachev 	case DC_SW_64KB_S_T:
298b843c749SSergey Zigachev 		input->src.is_display_sw = 0;
299b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_64k_tile;
300b843c749SSergey Zigachev 		break;
301b843c749SSergey Zigachev 	case DC_SW_VAR_S:
302b843c749SSergey Zigachev 	case DC_SW_VAR_S_X:
303b843c749SSergey Zigachev 		input->src.is_display_sw = 0;
304b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_256k_tile;
305b843c749SSergey Zigachev 		break;
306b843c749SSergey Zigachev 
307b843c749SSergey Zigachev 	/* For 64bpp 2 high tiles */
308b843c749SSergey Zigachev 	case DC_SW_4KB_D:
309b843c749SSergey Zigachev 	case DC_SW_4KB_D_X:
310b843c749SSergey Zigachev 		input->src.is_display_sw = 1;
311b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_4k_tile;
312b843c749SSergey Zigachev 		break;
313b843c749SSergey Zigachev 	case DC_SW_64KB_D:
314b843c749SSergey Zigachev 	case DC_SW_64KB_D_X:
315b843c749SSergey Zigachev 	case DC_SW_64KB_D_T:
316b843c749SSergey Zigachev 		input->src.is_display_sw = 1;
317b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_64k_tile;
318b843c749SSergey Zigachev 		break;
319b843c749SSergey Zigachev 	case DC_SW_VAR_D:
320b843c749SSergey Zigachev 	case DC_SW_VAR_D_X:
321b843c749SSergey Zigachev 		input->src.is_display_sw = 1;
322b843c749SSergey Zigachev 		input->src.macro_tile_size = dm_256k_tile;
323b843c749SSergey Zigachev 		break;
324b843c749SSergey Zigachev 
325b843c749SSergey Zigachev 	/* Unsupported swizzle modes for dcn */
326b843c749SSergey Zigachev 	case DC_SW_256B_S:
327b843c749SSergey Zigachev 	default:
328b843c749SSergey Zigachev 		ASSERT(0); /* Not supported */
329b843c749SSergey Zigachev 		break;
330b843c749SSergey Zigachev 	}
331b843c749SSergey Zigachev 
332b843c749SSergey Zigachev 	switch (pipe->plane_state->rotation) {
333b843c749SSergey Zigachev 	case ROTATION_ANGLE_0:
334b843c749SSergey Zigachev 	case ROTATION_ANGLE_180:
335b843c749SSergey Zigachev 		input->src.source_scan = dm_horz;
336b843c749SSergey Zigachev 		break;
337b843c749SSergey Zigachev 	case ROTATION_ANGLE_90:
338b843c749SSergey Zigachev 	case ROTATION_ANGLE_270:
339b843c749SSergey Zigachev 		input->src.source_scan = dm_vert;
340b843c749SSergey Zigachev 		break;
341b843c749SSergey Zigachev 	default:
342b843c749SSergey Zigachev 		ASSERT(0); /* Not supported */
343b843c749SSergey Zigachev 		break;
344b843c749SSergey Zigachev 	}
345b843c749SSergey Zigachev 
346b843c749SSergey Zigachev 	/* TODO: Fix pixel format mappings */
347b843c749SSergey Zigachev 	switch (pipe->plane_state->format) {
348b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
349b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
350b843c749SSergey Zigachev 		input->src.source_format = dm_420_8;
351b843c749SSergey Zigachev 		input->src.viewport_width_c    = input->src.viewport_width / 2;
352b843c749SSergey Zigachev 		input->src.viewport_height_c   = input->src.viewport_height / 2;
353b843c749SSergey Zigachev 		break;
354b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
355b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
356b843c749SSergey Zigachev 		input->src.source_format = dm_420_10;
357b843c749SSergey Zigachev 		input->src.viewport_width_c    = input->src.viewport_width / 2;
358b843c749SSergey Zigachev 		input->src.viewport_height_c   = input->src.viewport_height / 2;
359b843c749SSergey Zigachev 		break;
360b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
361b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
362b843c749SSergey Zigachev 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
363b843c749SSergey Zigachev 		input->src.source_format = dm_444_64;
364b843c749SSergey Zigachev 		input->src.viewport_width_c    = input->src.viewport_width;
365b843c749SSergey Zigachev 		input->src.viewport_height_c   = input->src.viewport_height;
366b843c749SSergey Zigachev 		break;
367b843c749SSergey Zigachev 	default:
368b843c749SSergey Zigachev 		input->src.source_format = dm_444_32;
369b843c749SSergey Zigachev 		input->src.viewport_width_c    = input->src.viewport_width;
370b843c749SSergey Zigachev 		input->src.viewport_height_c   = input->src.viewport_height;
371b843c749SSergey Zigachev 		break;
372b843c749SSergey Zigachev 	}
373b843c749SSergey Zigachev 
374b843c749SSergey Zigachev 	input->scale_taps.htaps                = pipe->plane_res.scl_data.taps.h_taps;
375b843c749SSergey Zigachev 	input->scale_ratio_depth.hscl_ratio    = pipe->plane_res.scl_data.ratios.horz.value/4294967296.0;
376b843c749SSergey Zigachev 	input->scale_ratio_depth.vscl_ratio    = pipe->plane_res.scl_data.ratios.vert.value/4294967296.0;
377b843c749SSergey Zigachev 	input->scale_ratio_depth.vinit =  pipe->plane_res.scl_data.inits.v.value/4294967296.0;
378b843c749SSergey Zigachev 	if (input->scale_ratio_depth.vinit < 1.0)
379b843c749SSergey Zigachev 			input->scale_ratio_depth.vinit = 1;
380b843c749SSergey Zigachev 	input->scale_taps.vtaps = pipe->plane_res.scl_data.taps.v_taps;
381b843c749SSergey Zigachev 	input->scale_taps.vtaps_c = pipe->plane_res.scl_data.taps.v_taps_c;
382b843c749SSergey Zigachev 	input->scale_taps.htaps_c              = pipe->plane_res.scl_data.taps.h_taps_c;
383b843c749SSergey Zigachev 	input->scale_ratio_depth.hscl_ratio_c  = pipe->plane_res.scl_data.ratios.horz_c.value/4294967296.0;
384b843c749SSergey Zigachev 	input->scale_ratio_depth.vscl_ratio_c  = pipe->plane_res.scl_data.ratios.vert_c.value/4294967296.0;
385b843c749SSergey Zigachev 	input->scale_ratio_depth.vinit_c       = pipe->plane_res.scl_data.inits.v_c.value/4294967296.0;
386b843c749SSergey Zigachev 	if (input->scale_ratio_depth.vinit_c < 1.0)
387b843c749SSergey Zigachev 			input->scale_ratio_depth.vinit_c = 1;
388b843c749SSergey Zigachev 	switch (pipe->plane_res.scl_data.lb_params.depth) {
389b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_30BPP:
390b843c749SSergey Zigachev 		input->scale_ratio_depth.lb_depth = 30; break;
391b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_36BPP:
392b843c749SSergey Zigachev 		input->scale_ratio_depth.lb_depth = 36; break;
393b843c749SSergey Zigachev 	default:
394b843c749SSergey Zigachev 		input->scale_ratio_depth.lb_depth = 24; break;
395b843c749SSergey Zigachev 	}
396b843c749SSergey Zigachev 
397b843c749SSergey Zigachev 
398b843c749SSergey Zigachev 	input->dest.vactive        = pipe->stream->timing.v_addressable + pipe->stream->timing.v_border_top
399b843c749SSergey Zigachev 			+ pipe->stream->timing.v_border_bottom;
400b843c749SSergey Zigachev 
401b843c749SSergey Zigachev 	input->dest.recout_width   = pipe->plane_res.scl_data.recout.width;
402b843c749SSergey Zigachev 	input->dest.recout_height  = pipe->plane_res.scl_data.recout.height;
403b843c749SSergey Zigachev 
404b843c749SSergey Zigachev 	input->dest.full_recout_width   = pipe->plane_res.scl_data.recout.width;
405b843c749SSergey Zigachev 	input->dest.full_recout_height  = pipe->plane_res.scl_data.recout.height;
406b843c749SSergey Zigachev 
407b843c749SSergey Zigachev 	input->dest.htotal         = pipe->stream->timing.h_total;
408b843c749SSergey Zigachev 	input->dest.hblank_start   = input->dest.htotal - pipe->stream->timing.h_front_porch;
409b843c749SSergey Zigachev 	input->dest.hblank_end     = input->dest.hblank_start
410b843c749SSergey Zigachev 			- pipe->stream->timing.h_addressable
411b843c749SSergey Zigachev 			- pipe->stream->timing.h_border_left
412b843c749SSergey Zigachev 			- pipe->stream->timing.h_border_right;
413b843c749SSergey Zigachev 
414b843c749SSergey Zigachev 	input->dest.vtotal         = pipe->stream->timing.v_total;
415b843c749SSergey Zigachev 	input->dest.vblank_start   = input->dest.vtotal - pipe->stream->timing.v_front_porch;
416b843c749SSergey Zigachev 	input->dest.vblank_end     = input->dest.vblank_start
417b843c749SSergey Zigachev 			- pipe->stream->timing.v_addressable
418b843c749SSergey Zigachev 			- pipe->stream->timing.v_border_bottom
419b843c749SSergey Zigachev 			- pipe->stream->timing.v_border_top;
420b843c749SSergey Zigachev 	input->dest.pixel_rate_mhz = pipe->stream->timing.pix_clk_khz/1000.0;
421b843c749SSergey Zigachev 	input->dest.vstartup_start = pipe->pipe_dlg_param.vstartup_start;
422b843c749SSergey Zigachev 	input->dest.vupdate_offset = pipe->pipe_dlg_param.vupdate_offset;
423b843c749SSergey Zigachev 	input->dest.vupdate_offset = pipe->pipe_dlg_param.vupdate_offset;
424b843c749SSergey Zigachev 	input->dest.vupdate_width = pipe->pipe_dlg_param.vupdate_width;
425b843c749SSergey Zigachev 
426b843c749SSergey Zigachev }
427b843c749SSergey Zigachev 
dcn_bw_calc_rq_dlg_ttu(const struct dc * dc,const struct dcn_bw_internal_vars * v,struct pipe_ctx * pipe,int in_idx)428b843c749SSergey Zigachev static void dcn_bw_calc_rq_dlg_ttu(
429b843c749SSergey Zigachev 		const struct dc *dc,
430b843c749SSergey Zigachev 		const struct dcn_bw_internal_vars *v,
431b843c749SSergey Zigachev 		struct pipe_ctx *pipe,
432b843c749SSergey Zigachev 		int in_idx)
433b843c749SSergey Zigachev {
434b843c749SSergey Zigachev 	struct display_mode_lib *dml = (struct display_mode_lib *)(&dc->dml);
435b843c749SSergey Zigachev 	struct _vcs_dpi_display_dlg_regs_st *dlg_regs = &pipe->dlg_regs;
436b843c749SSergey Zigachev 	struct _vcs_dpi_display_ttu_regs_st *ttu_regs = &pipe->ttu_regs;
437b843c749SSergey Zigachev 	struct _vcs_dpi_display_rq_regs_st *rq_regs = &pipe->rq_regs;
438b843c749SSergey Zigachev 	struct _vcs_dpi_display_rq_params_st rq_param = {0};
439b843c749SSergey Zigachev 	struct _vcs_dpi_display_dlg_sys_params_st dlg_sys_param = {0};
440b843c749SSergey Zigachev 	struct _vcs_dpi_display_e2e_pipe_params_st input = { { { 0 } } };
441b843c749SSergey Zigachev 	float total_active_bw = 0;
442b843c749SSergey Zigachev 	float total_prefetch_bw = 0;
443b843c749SSergey Zigachev 	int total_flip_bytes = 0;
444b843c749SSergey Zigachev 	int i;
445b843c749SSergey Zigachev 
446b843c749SSergey Zigachev 	memset(dlg_regs, 0, sizeof(*dlg_regs));
447b843c749SSergey Zigachev 	memset(ttu_regs, 0, sizeof(*ttu_regs));
448b843c749SSergey Zigachev 	memset(rq_regs, 0, sizeof(*rq_regs));
449b843c749SSergey Zigachev 
450b843c749SSergey Zigachev 	for (i = 0; i < number_of_planes; i++) {
451b843c749SSergey Zigachev 		total_active_bw += v->read_bandwidth[i];
452b843c749SSergey Zigachev 		total_prefetch_bw += v->prefetch_bandwidth[i];
453b843c749SSergey Zigachev 		total_flip_bytes += v->total_immediate_flip_bytes[i];
454b843c749SSergey Zigachev 	}
455b843c749SSergey Zigachev 	dlg_sys_param.total_flip_bw = v->return_bw - dcn_bw_max2(total_active_bw, total_prefetch_bw);
456b843c749SSergey Zigachev 	if (dlg_sys_param.total_flip_bw < 0.0)
457b843c749SSergey Zigachev 		dlg_sys_param.total_flip_bw = 0;
458b843c749SSergey Zigachev 
459b843c749SSergey Zigachev 	dlg_sys_param.t_mclk_wm_us = v->dram_clock_change_watermark;
460b843c749SSergey Zigachev 	dlg_sys_param.t_sr_wm_us = v->stutter_enter_plus_exit_watermark;
461b843c749SSergey Zigachev 	dlg_sys_param.t_urg_wm_us = v->urgent_watermark;
462b843c749SSergey Zigachev 	dlg_sys_param.t_extra_us = v->urgent_extra_latency;
463b843c749SSergey Zigachev 	dlg_sys_param.deepsleep_dcfclk_mhz = v->dcf_clk_deep_sleep;
464b843c749SSergey Zigachev 	dlg_sys_param.total_flip_bytes = total_flip_bytes;
465b843c749SSergey Zigachev 
466b843c749SSergey Zigachev 	pipe_ctx_to_e2e_pipe_params(pipe, &input.pipe);
467b843c749SSergey Zigachev 	input.clks_cfg.dcfclk_mhz = v->dcfclk;
468b843c749SSergey Zigachev 	input.clks_cfg.dispclk_mhz = v->dispclk;
469b843c749SSergey Zigachev 	input.clks_cfg.dppclk_mhz = v->dppclk;
470b843c749SSergey Zigachev 	input.clks_cfg.refclk_mhz = dc->res_pool->ref_clock_inKhz / 1000.0;
471b843c749SSergey Zigachev 	input.clks_cfg.socclk_mhz = v->socclk;
472b843c749SSergey Zigachev 	input.clks_cfg.voltage = v->voltage_level;
473b843c749SSergey Zigachev //	dc->dml.logger = pool->base.logger;
474b843c749SSergey Zigachev 	input.dout.output_format = (v->output_format[in_idx] == dcn_bw_420) ? dm_420 : dm_444;
475b843c749SSergey Zigachev 	input.dout.output_type  = (v->output[in_idx] == dcn_bw_hdmi) ? dm_hdmi : dm_dp;
476b843c749SSergey Zigachev 	//input[in_idx].dout.output_standard;
477b843c749SSergey Zigachev 
478b843c749SSergey Zigachev 	/*todo: soc->sr_enter_plus_exit_time??*/
479b843c749SSergey Zigachev 	dlg_sys_param.t_srx_delay_us = dc->dcn_ip->dcfclk_cstate_latency / v->dcf_clk_deep_sleep;
480b843c749SSergey Zigachev 
481b843c749SSergey Zigachev 	dml1_rq_dlg_get_rq_params(dml, &rq_param, input.pipe.src);
482b843c749SSergey Zigachev 	dml1_extract_rq_regs(dml, rq_regs, rq_param);
483b843c749SSergey Zigachev 	dml1_rq_dlg_get_dlg_params(
484b843c749SSergey Zigachev 			dml,
485b843c749SSergey Zigachev 			dlg_regs,
486b843c749SSergey Zigachev 			ttu_regs,
487b843c749SSergey Zigachev 			rq_param.dlg,
488b843c749SSergey Zigachev 			dlg_sys_param,
489b843c749SSergey Zigachev 			input,
490b843c749SSergey Zigachev 			true,
491b843c749SSergey Zigachev 			true,
492b843c749SSergey Zigachev 			v->pte_enable == dcn_bw_yes,
493b843c749SSergey Zigachev 			pipe->plane_state->flip_immediate);
494b843c749SSergey Zigachev }
495b843c749SSergey Zigachev 
split_stream_across_pipes(struct resource_context * res_ctx,const struct resource_pool * pool,struct pipe_ctx * primary_pipe,struct pipe_ctx * secondary_pipe)496b843c749SSergey Zigachev static void split_stream_across_pipes(
497b843c749SSergey Zigachev 		struct resource_context *res_ctx,
498b843c749SSergey Zigachev 		const struct resource_pool *pool,
499b843c749SSergey Zigachev 		struct pipe_ctx *primary_pipe,
500b843c749SSergey Zigachev 		struct pipe_ctx *secondary_pipe)
501b843c749SSergey Zigachev {
502b843c749SSergey Zigachev 	int pipe_idx = secondary_pipe->pipe_idx;
503b843c749SSergey Zigachev 
504b843c749SSergey Zigachev 	if (!primary_pipe->plane_state)
505b843c749SSergey Zigachev 		return;
506b843c749SSergey Zigachev 
507b843c749SSergey Zigachev 	*secondary_pipe = *primary_pipe;
508b843c749SSergey Zigachev 
509b843c749SSergey Zigachev 	secondary_pipe->pipe_idx = pipe_idx;
510b843c749SSergey Zigachev 	secondary_pipe->plane_res.mi = pool->mis[secondary_pipe->pipe_idx];
511b843c749SSergey Zigachev 	secondary_pipe->plane_res.hubp = pool->hubps[secondary_pipe->pipe_idx];
512b843c749SSergey Zigachev 	secondary_pipe->plane_res.ipp = pool->ipps[secondary_pipe->pipe_idx];
513b843c749SSergey Zigachev 	secondary_pipe->plane_res.xfm = pool->transforms[secondary_pipe->pipe_idx];
514b843c749SSergey Zigachev 	secondary_pipe->plane_res.dpp = pool->dpps[secondary_pipe->pipe_idx];
515b843c749SSergey Zigachev 	secondary_pipe->plane_res.mpcc_inst = pool->dpps[secondary_pipe->pipe_idx]->inst;
516b843c749SSergey Zigachev 	if (primary_pipe->bottom_pipe) {
517b843c749SSergey Zigachev 		ASSERT(primary_pipe->bottom_pipe != secondary_pipe);
518b843c749SSergey Zigachev 		secondary_pipe->bottom_pipe = primary_pipe->bottom_pipe;
519b843c749SSergey Zigachev 		secondary_pipe->bottom_pipe->top_pipe = secondary_pipe;
520b843c749SSergey Zigachev 	}
521b843c749SSergey Zigachev 	primary_pipe->bottom_pipe = secondary_pipe;
522b843c749SSergey Zigachev 	secondary_pipe->top_pipe = primary_pipe;
523b843c749SSergey Zigachev 
524b843c749SSergey Zigachev 	resource_build_scaling_params(primary_pipe);
525b843c749SSergey Zigachev 	resource_build_scaling_params(secondary_pipe);
526b843c749SSergey Zigachev }
527b843c749SSergey Zigachev 
528b843c749SSergey Zigachev #if 0
529b843c749SSergey Zigachev static void calc_wm_sets_and_perf_params(
530b843c749SSergey Zigachev 		struct dc_state *context,
531b843c749SSergey Zigachev 		struct dcn_bw_internal_vars *v)
532b843c749SSergey Zigachev {
533b843c749SSergey Zigachev 	/* Calculate set A last to keep internal var state consistent for required config */
534b843c749SSergey Zigachev 	if (v->voltage_level < 2) {
535b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth_per_state[1] = v->fabric_and_dram_bandwidth_vnom0p8;
536b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth_per_state[0] = v->fabric_and_dram_bandwidth_vnom0p8;
537b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth = v->fabric_and_dram_bandwidth_vnom0p8;
538b843c749SSergey Zigachev 		dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(v);
539b843c749SSergey Zigachev 
540b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns =
541b843c749SSergey Zigachev 			v->stutter_exit_watermark * 1000;
542b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns =
543b843c749SSergey Zigachev 				v->stutter_enter_plus_exit_watermark * 1000;
544b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns =
545b843c749SSergey Zigachev 				v->dram_clock_change_watermark * 1000;
546b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b.pte_meta_urgent_ns = v->ptemeta_urgent_watermark * 1000;
547b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b.urgent_ns = v->urgent_watermark * 1000;
548b843c749SSergey Zigachev 
549b843c749SSergey Zigachev 		v->dcfclk_per_state[1] = v->dcfclkv_nom0p8;
550b843c749SSergey Zigachev 		v->dcfclk_per_state[0] = v->dcfclkv_nom0p8;
551b843c749SSergey Zigachev 		v->dcfclk = v->dcfclkv_nom0p8;
552b843c749SSergey Zigachev 		dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(v);
553b843c749SSergey Zigachev 
554b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns =
555b843c749SSergey Zigachev 			v->stutter_exit_watermark * 1000;
556b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns =
557b843c749SSergey Zigachev 				v->stutter_enter_plus_exit_watermark * 1000;
558b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns =
559b843c749SSergey Zigachev 				v->dram_clock_change_watermark * 1000;
560b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c.pte_meta_urgent_ns = v->ptemeta_urgent_watermark * 1000;
561b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c.urgent_ns = v->urgent_watermark * 1000;
562b843c749SSergey Zigachev 	}
563b843c749SSergey Zigachev 
564b843c749SSergey Zigachev 	if (v->voltage_level < 3) {
565b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth_per_state[2] = v->fabric_and_dram_bandwidth_vmax0p9;
566b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth_per_state[1] = v->fabric_and_dram_bandwidth_vmax0p9;
567b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth_per_state[0] = v->fabric_and_dram_bandwidth_vmax0p9;
568b843c749SSergey Zigachev 		v->fabric_and_dram_bandwidth = v->fabric_and_dram_bandwidth_vmax0p9;
569b843c749SSergey Zigachev 		v->dcfclk_per_state[2] = v->dcfclkv_max0p9;
570b843c749SSergey Zigachev 		v->dcfclk_per_state[1] = v->dcfclkv_max0p9;
571b843c749SSergey Zigachev 		v->dcfclk_per_state[0] = v->dcfclkv_max0p9;
572b843c749SSergey Zigachev 		v->dcfclk = v->dcfclkv_max0p9;
573b843c749SSergey Zigachev 		dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(v);
574b843c749SSergey Zigachev 
575b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns =
576b843c749SSergey Zigachev 			v->stutter_exit_watermark * 1000;
577b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns =
578b843c749SSergey Zigachev 				v->stutter_enter_plus_exit_watermark * 1000;
579b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns =
580b843c749SSergey Zigachev 				v->dram_clock_change_watermark * 1000;
581b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d.pte_meta_urgent_ns = v->ptemeta_urgent_watermark * 1000;
582b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d.urgent_ns = v->urgent_watermark * 1000;
583b843c749SSergey Zigachev 	}
584b843c749SSergey Zigachev 
585b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[2] = v->fabric_and_dram_bandwidth_vnom0p8;
586b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[1] = v->fabric_and_dram_bandwidth_vmid0p72;
587b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[0] = v->fabric_and_dram_bandwidth_vmin0p65;
588b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth = v->fabric_and_dram_bandwidth_per_state[v->voltage_level];
589b843c749SSergey Zigachev 	v->dcfclk_per_state[2] = v->dcfclkv_nom0p8;
590b843c749SSergey Zigachev 	v->dcfclk_per_state[1] = v->dcfclkv_mid0p72;
591b843c749SSergey Zigachev 	v->dcfclk_per_state[0] = v->dcfclkv_min0p65;
592b843c749SSergey Zigachev 	v->dcfclk = v->dcfclk_per_state[v->voltage_level];
593b843c749SSergey Zigachev 	dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(v);
594b843c749SSergey Zigachev 
595b843c749SSergey Zigachev 	context->bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns =
596b843c749SSergey Zigachev 		v->stutter_exit_watermark * 1000;
597b843c749SSergey Zigachev 	context->bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns =
598b843c749SSergey Zigachev 			v->stutter_enter_plus_exit_watermark * 1000;
599b843c749SSergey Zigachev 	context->bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns =
600b843c749SSergey Zigachev 			v->dram_clock_change_watermark * 1000;
601b843c749SSergey Zigachev 	context->bw.dcn.watermarks.a.pte_meta_urgent_ns = v->ptemeta_urgent_watermark * 1000;
602b843c749SSergey Zigachev 	context->bw.dcn.watermarks.a.urgent_ns = v->urgent_watermark * 1000;
603b843c749SSergey Zigachev 	if (v->voltage_level >= 2) {
604b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b = context->bw.dcn.watermarks.a;
605b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c = context->bw.dcn.watermarks.a;
606b843c749SSergey Zigachev 	}
607b843c749SSergey Zigachev 	if (v->voltage_level >= 3)
608b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d = context->bw.dcn.watermarks.a;
609b843c749SSergey Zigachev }
610b843c749SSergey Zigachev #endif
611b843c749SSergey Zigachev 
dcn_bw_apply_registry_override(struct dc * dc)612b843c749SSergey Zigachev static bool dcn_bw_apply_registry_override(struct dc *dc)
613b843c749SSergey Zigachev {
614b843c749SSergey Zigachev 	bool updated = false;
615b843c749SSergey Zigachev 
616b843c749SSergey Zigachev 	kernel_fpu_begin();
617b843c749SSergey Zigachev 	if ((int)(dc->dcn_soc->sr_exit_time * 1000) != dc->debug.sr_exit_time_ns
618b843c749SSergey Zigachev 			&& dc->debug.sr_exit_time_ns) {
619b843c749SSergey Zigachev 		updated = true;
620b843c749SSergey Zigachev 		dc->dcn_soc->sr_exit_time = dc->debug.sr_exit_time_ns / 1000.0;
621b843c749SSergey Zigachev 	}
622b843c749SSergey Zigachev 
623b843c749SSergey Zigachev 	if ((int)(dc->dcn_soc->sr_enter_plus_exit_time * 1000)
624b843c749SSergey Zigachev 				!= dc->debug.sr_enter_plus_exit_time_ns
625b843c749SSergey Zigachev 			&& dc->debug.sr_enter_plus_exit_time_ns) {
626b843c749SSergey Zigachev 		updated = true;
627b843c749SSergey Zigachev 		dc->dcn_soc->sr_enter_plus_exit_time =
628b843c749SSergey Zigachev 				dc->debug.sr_enter_plus_exit_time_ns / 1000.0;
629b843c749SSergey Zigachev 	}
630b843c749SSergey Zigachev 
631b843c749SSergey Zigachev 	if ((int)(dc->dcn_soc->urgent_latency * 1000) != dc->debug.urgent_latency_ns
632b843c749SSergey Zigachev 			&& dc->debug.urgent_latency_ns) {
633b843c749SSergey Zigachev 		updated = true;
634b843c749SSergey Zigachev 		dc->dcn_soc->urgent_latency = dc->debug.urgent_latency_ns / 1000.0;
635b843c749SSergey Zigachev 	}
636b843c749SSergey Zigachev 
637b843c749SSergey Zigachev 	if ((int)(dc->dcn_soc->percent_of_ideal_drambw_received_after_urg_latency * 1000)
638b843c749SSergey Zigachev 				!= dc->debug.percent_of_ideal_drambw
639b843c749SSergey Zigachev 			&& dc->debug.percent_of_ideal_drambw) {
640b843c749SSergey Zigachev 		updated = true;
641b843c749SSergey Zigachev 		dc->dcn_soc->percent_of_ideal_drambw_received_after_urg_latency =
642b843c749SSergey Zigachev 				dc->debug.percent_of_ideal_drambw;
643b843c749SSergey Zigachev 	}
644b843c749SSergey Zigachev 
645b843c749SSergey Zigachev 	if ((int)(dc->dcn_soc->dram_clock_change_latency * 1000)
646b843c749SSergey Zigachev 				!= dc->debug.dram_clock_change_latency_ns
647b843c749SSergey Zigachev 			&& dc->debug.dram_clock_change_latency_ns) {
648b843c749SSergey Zigachev 		updated = true;
649b843c749SSergey Zigachev 		dc->dcn_soc->dram_clock_change_latency =
650b843c749SSergey Zigachev 				dc->debug.dram_clock_change_latency_ns / 1000.0;
651b843c749SSergey Zigachev 	}
652b843c749SSergey Zigachev 	kernel_fpu_end();
653b843c749SSergey Zigachev 
654b843c749SSergey Zigachev 	return updated;
655b843c749SSergey Zigachev }
656b843c749SSergey Zigachev 
hack_disable_optional_pipe_split(struct dcn_bw_internal_vars * v)657b843c749SSergey Zigachev static void hack_disable_optional_pipe_split(struct dcn_bw_internal_vars *v)
658b843c749SSergey Zigachev {
659b843c749SSergey Zigachev 	/*
660b843c749SSergey Zigachev 	 * disable optional pipe split by lower dispclk bounding box
661b843c749SSergey Zigachev 	 * at DPM0
662b843c749SSergey Zigachev 	 */
663b843c749SSergey Zigachev 	v->max_dispclk[0] = v->max_dppclk_vmin0p65;
664b843c749SSergey Zigachev }
665b843c749SSergey Zigachev 
hack_force_pipe_split(struct dcn_bw_internal_vars * v,unsigned int pixel_rate_khz)666b843c749SSergey Zigachev static void hack_force_pipe_split(struct dcn_bw_internal_vars *v,
667b843c749SSergey Zigachev 		unsigned int pixel_rate_khz)
668b843c749SSergey Zigachev {
669b843c749SSergey Zigachev 	float pixel_rate_mhz = pixel_rate_khz / 1000;
670b843c749SSergey Zigachev 
671b843c749SSergey Zigachev 	/*
672b843c749SSergey Zigachev 	 * force enabling pipe split by lower dpp clock for DPM0 to just
673b843c749SSergey Zigachev 	 * below the specify pixel_rate, so bw calc would split pipe.
674b843c749SSergey Zigachev 	 */
675b843c749SSergey Zigachev 	if (pixel_rate_mhz < v->max_dppclk[0])
676b843c749SSergey Zigachev 		v->max_dppclk[0] = pixel_rate_mhz;
677b843c749SSergey Zigachev }
678b843c749SSergey Zigachev 
hack_bounding_box(struct dcn_bw_internal_vars * v,struct dc_debug_options * dbg,struct dc_state * context)679b843c749SSergey Zigachev static void hack_bounding_box(struct dcn_bw_internal_vars *v,
680b843c749SSergey Zigachev 		struct dc_debug_options *dbg,
681b843c749SSergey Zigachev 		struct dc_state *context)
682b843c749SSergey Zigachev {
683b843c749SSergey Zigachev 	if (dbg->pipe_split_policy == MPC_SPLIT_AVOID)
684b843c749SSergey Zigachev 		hack_disable_optional_pipe_split(v);
685b843c749SSergey Zigachev 
686b843c749SSergey Zigachev 	if (dbg->pipe_split_policy == MPC_SPLIT_AVOID_MULT_DISP &&
687b843c749SSergey Zigachev 		context->stream_count >= 2)
688b843c749SSergey Zigachev 		hack_disable_optional_pipe_split(v);
689b843c749SSergey Zigachev 
690b843c749SSergey Zigachev 	if (context->stream_count == 1 &&
691b843c749SSergey Zigachev 			dbg->force_single_disp_pipe_split)
692b843c749SSergey Zigachev 		hack_force_pipe_split(v, context->streams[0]->timing.pix_clk_khz);
693b843c749SSergey Zigachev }
694b843c749SSergey Zigachev 
dcn_validate_bandwidth(struct dc * dc,struct dc_state * context)695b843c749SSergey Zigachev bool dcn_validate_bandwidth(
696b843c749SSergey Zigachev 		struct dc *dc,
697b843c749SSergey Zigachev 		struct dc_state *context)
698b843c749SSergey Zigachev {
699b843c749SSergey Zigachev 	const struct resource_pool *pool = dc->res_pool;
700b843c749SSergey Zigachev 	struct dcn_bw_internal_vars *v = &context->dcn_bw_vars;
701b843c749SSergey Zigachev 	int i, input_idx;
702b843c749SSergey Zigachev 	int vesa_sync_start, asic_blank_end, asic_blank_start;
703b843c749SSergey Zigachev 	bool bw_limit_pass;
704b843c749SSergey Zigachev 	float bw_limit;
705b843c749SSergey Zigachev 
706b843c749SSergey Zigachev 	PERFORMANCE_TRACE_START();
707b843c749SSergey Zigachev 	if (dcn_bw_apply_registry_override(dc))
708b843c749SSergey Zigachev 		dcn_bw_sync_calcs_and_dml(dc);
709b843c749SSergey Zigachev 
710b843c749SSergey Zigachev 	memset(v, 0, sizeof(*v));
711b843c749SSergey Zigachev 	kernel_fpu_begin();
712b843c749SSergey Zigachev 	v->sr_exit_time = dc->dcn_soc->sr_exit_time;
713b843c749SSergey Zigachev 	v->sr_enter_plus_exit_time = dc->dcn_soc->sr_enter_plus_exit_time;
714b843c749SSergey Zigachev 	v->urgent_latency = dc->dcn_soc->urgent_latency;
715b843c749SSergey Zigachev 	v->write_back_latency = dc->dcn_soc->write_back_latency;
716b843c749SSergey Zigachev 	v->percent_of_ideal_drambw_received_after_urg_latency =
717b843c749SSergey Zigachev 			dc->dcn_soc->percent_of_ideal_drambw_received_after_urg_latency;
718b843c749SSergey Zigachev 
719b843c749SSergey Zigachev 	v->dcfclkv_min0p65 = dc->dcn_soc->dcfclkv_min0p65;
720b843c749SSergey Zigachev 	v->dcfclkv_mid0p72 = dc->dcn_soc->dcfclkv_mid0p72;
721b843c749SSergey Zigachev 	v->dcfclkv_nom0p8 = dc->dcn_soc->dcfclkv_nom0p8;
722b843c749SSergey Zigachev 	v->dcfclkv_max0p9 = dc->dcn_soc->dcfclkv_max0p9;
723b843c749SSergey Zigachev 
724b843c749SSergey Zigachev 	v->max_dispclk_vmin0p65 = dc->dcn_soc->max_dispclk_vmin0p65;
725b843c749SSergey Zigachev 	v->max_dispclk_vmid0p72 = dc->dcn_soc->max_dispclk_vmid0p72;
726b843c749SSergey Zigachev 	v->max_dispclk_vnom0p8 = dc->dcn_soc->max_dispclk_vnom0p8;
727b843c749SSergey Zigachev 	v->max_dispclk_vmax0p9 = dc->dcn_soc->max_dispclk_vmax0p9;
728b843c749SSergey Zigachev 
729b843c749SSergey Zigachev 	v->max_dppclk_vmin0p65 = dc->dcn_soc->max_dppclk_vmin0p65;
730b843c749SSergey Zigachev 	v->max_dppclk_vmid0p72 = dc->dcn_soc->max_dppclk_vmid0p72;
731b843c749SSergey Zigachev 	v->max_dppclk_vnom0p8 = dc->dcn_soc->max_dppclk_vnom0p8;
732b843c749SSergey Zigachev 	v->max_dppclk_vmax0p9 = dc->dcn_soc->max_dppclk_vmax0p9;
733b843c749SSergey Zigachev 
734b843c749SSergey Zigachev 	v->socclk = dc->dcn_soc->socclk;
735b843c749SSergey Zigachev 
736b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_vmin0p65 = dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65;
737b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_vmid0p72 = dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72;
738b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_vnom0p8 = dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8;
739b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_vmax0p9 = dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9;
740b843c749SSergey Zigachev 
741b843c749SSergey Zigachev 	v->phyclkv_min0p65 = dc->dcn_soc->phyclkv_min0p65;
742b843c749SSergey Zigachev 	v->phyclkv_mid0p72 = dc->dcn_soc->phyclkv_mid0p72;
743b843c749SSergey Zigachev 	v->phyclkv_nom0p8 = dc->dcn_soc->phyclkv_nom0p8;
744b843c749SSergey Zigachev 	v->phyclkv_max0p9 = dc->dcn_soc->phyclkv_max0p9;
745b843c749SSergey Zigachev 
746b843c749SSergey Zigachev 	v->downspreading = dc->dcn_soc->downspreading;
747b843c749SSergey Zigachev 	v->round_trip_ping_latency_cycles = dc->dcn_soc->round_trip_ping_latency_cycles;
748b843c749SSergey Zigachev 	v->urgent_out_of_order_return_per_channel = dc->dcn_soc->urgent_out_of_order_return_per_channel;
749b843c749SSergey Zigachev 	v->number_of_channels = dc->dcn_soc->number_of_channels;
750b843c749SSergey Zigachev 	v->vmm_page_size = dc->dcn_soc->vmm_page_size;
751b843c749SSergey Zigachev 	v->dram_clock_change_latency = dc->dcn_soc->dram_clock_change_latency;
752b843c749SSergey Zigachev 	v->return_bus_width = dc->dcn_soc->return_bus_width;
753b843c749SSergey Zigachev 
754b843c749SSergey Zigachev 	v->rob_buffer_size_in_kbyte = dc->dcn_ip->rob_buffer_size_in_kbyte;
755b843c749SSergey Zigachev 	v->det_buffer_size_in_kbyte = dc->dcn_ip->det_buffer_size_in_kbyte;
756b843c749SSergey Zigachev 	v->dpp_output_buffer_pixels = dc->dcn_ip->dpp_output_buffer_pixels;
757b843c749SSergey Zigachev 	v->opp_output_buffer_lines = dc->dcn_ip->opp_output_buffer_lines;
758b843c749SSergey Zigachev 	v->pixel_chunk_size_in_kbyte = dc->dcn_ip->pixel_chunk_size_in_kbyte;
759b843c749SSergey Zigachev 	v->pte_enable = dc->dcn_ip->pte_enable;
760b843c749SSergey Zigachev 	v->pte_chunk_size = dc->dcn_ip->pte_chunk_size;
761b843c749SSergey Zigachev 	v->meta_chunk_size = dc->dcn_ip->meta_chunk_size;
762b843c749SSergey Zigachev 	v->writeback_chunk_size = dc->dcn_ip->writeback_chunk_size;
763b843c749SSergey Zigachev 	v->odm_capability = dc->dcn_ip->odm_capability;
764b843c749SSergey Zigachev 	v->dsc_capability = dc->dcn_ip->dsc_capability;
765b843c749SSergey Zigachev 	v->line_buffer_size = dc->dcn_ip->line_buffer_size;
766b843c749SSergey Zigachev 	v->is_line_buffer_bpp_fixed = dc->dcn_ip->is_line_buffer_bpp_fixed;
767b843c749SSergey Zigachev 	v->line_buffer_fixed_bpp = dc->dcn_ip->line_buffer_fixed_bpp;
768b843c749SSergey Zigachev 	v->max_line_buffer_lines = dc->dcn_ip->max_line_buffer_lines;
769b843c749SSergey Zigachev 	v->writeback_luma_buffer_size = dc->dcn_ip->writeback_luma_buffer_size;
770b843c749SSergey Zigachev 	v->writeback_chroma_buffer_size = dc->dcn_ip->writeback_chroma_buffer_size;
771b843c749SSergey Zigachev 	v->max_num_dpp = dc->dcn_ip->max_num_dpp;
772b843c749SSergey Zigachev 	v->max_num_writeback = dc->dcn_ip->max_num_writeback;
773b843c749SSergey Zigachev 	v->max_dchub_topscl_throughput = dc->dcn_ip->max_dchub_topscl_throughput;
774b843c749SSergey Zigachev 	v->max_pscl_tolb_throughput = dc->dcn_ip->max_pscl_tolb_throughput;
775b843c749SSergey Zigachev 	v->max_lb_tovscl_throughput = dc->dcn_ip->max_lb_tovscl_throughput;
776b843c749SSergey Zigachev 	v->max_vscl_tohscl_throughput = dc->dcn_ip->max_vscl_tohscl_throughput;
777b843c749SSergey Zigachev 	v->max_hscl_ratio = dc->dcn_ip->max_hscl_ratio;
778b843c749SSergey Zigachev 	v->max_vscl_ratio = dc->dcn_ip->max_vscl_ratio;
779b843c749SSergey Zigachev 	v->max_hscl_taps = dc->dcn_ip->max_hscl_taps;
780b843c749SSergey Zigachev 	v->max_vscl_taps = dc->dcn_ip->max_vscl_taps;
781b843c749SSergey Zigachev 	v->under_scan_factor = dc->dcn_ip->under_scan_factor;
782b843c749SSergey Zigachev 	v->pte_buffer_size_in_requests = dc->dcn_ip->pte_buffer_size_in_requests;
783b843c749SSergey Zigachev 	v->dispclk_ramping_margin = dc->dcn_ip->dispclk_ramping_margin;
784b843c749SSergey Zigachev 	v->max_inter_dcn_tile_repeaters = dc->dcn_ip->max_inter_dcn_tile_repeaters;
785b843c749SSergey Zigachev 	v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one =
786b843c749SSergey Zigachev 			dc->dcn_ip->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one;
787b843c749SSergey Zigachev 	v->bug_forcing_luma_and_chroma_request_to_same_size_fixed =
788b843c749SSergey Zigachev 			dc->dcn_ip->bug_forcing_luma_and_chroma_request_to_same_size_fixed;
789b843c749SSergey Zigachev 
790b843c749SSergey Zigachev 	v->voltage[5] = dcn_bw_no_support;
791b843c749SSergey Zigachev 	v->voltage[4] = dcn_bw_v_max0p9;
792b843c749SSergey Zigachev 	v->voltage[3] = dcn_bw_v_max0p9;
793b843c749SSergey Zigachev 	v->voltage[2] = dcn_bw_v_nom0p8;
794b843c749SSergey Zigachev 	v->voltage[1] = dcn_bw_v_mid0p72;
795b843c749SSergey Zigachev 	v->voltage[0] = dcn_bw_v_min0p65;
796b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[5] = v->fabric_and_dram_bandwidth_vmax0p9;
797b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[4] = v->fabric_and_dram_bandwidth_vmax0p9;
798b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[3] = v->fabric_and_dram_bandwidth_vmax0p9;
799b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[2] = v->fabric_and_dram_bandwidth_vnom0p8;
800b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[1] = v->fabric_and_dram_bandwidth_vmid0p72;
801b843c749SSergey Zigachev 	v->fabric_and_dram_bandwidth_per_state[0] = v->fabric_and_dram_bandwidth_vmin0p65;
802b843c749SSergey Zigachev 	v->dcfclk_per_state[5] = v->dcfclkv_max0p9;
803b843c749SSergey Zigachev 	v->dcfclk_per_state[4] = v->dcfclkv_max0p9;
804b843c749SSergey Zigachev 	v->dcfclk_per_state[3] = v->dcfclkv_max0p9;
805b843c749SSergey Zigachev 	v->dcfclk_per_state[2] = v->dcfclkv_nom0p8;
806b843c749SSergey Zigachev 	v->dcfclk_per_state[1] = v->dcfclkv_mid0p72;
807b843c749SSergey Zigachev 	v->dcfclk_per_state[0] = v->dcfclkv_min0p65;
808b843c749SSergey Zigachev 	v->max_dispclk[5] = v->max_dispclk_vmax0p9;
809b843c749SSergey Zigachev 	v->max_dispclk[4] = v->max_dispclk_vmax0p9;
810b843c749SSergey Zigachev 	v->max_dispclk[3] = v->max_dispclk_vmax0p9;
811b843c749SSergey Zigachev 	v->max_dispclk[2] = v->max_dispclk_vnom0p8;
812b843c749SSergey Zigachev 	v->max_dispclk[1] = v->max_dispclk_vmid0p72;
813b843c749SSergey Zigachev 	v->max_dispclk[0] = v->max_dispclk_vmin0p65;
814b843c749SSergey Zigachev 	v->max_dppclk[5] = v->max_dppclk_vmax0p9;
815b843c749SSergey Zigachev 	v->max_dppclk[4] = v->max_dppclk_vmax0p9;
816b843c749SSergey Zigachev 	v->max_dppclk[3] = v->max_dppclk_vmax0p9;
817b843c749SSergey Zigachev 	v->max_dppclk[2] = v->max_dppclk_vnom0p8;
818b843c749SSergey Zigachev 	v->max_dppclk[1] = v->max_dppclk_vmid0p72;
819b843c749SSergey Zigachev 	v->max_dppclk[0] = v->max_dppclk_vmin0p65;
820b843c749SSergey Zigachev 	v->phyclk_per_state[5] = v->phyclkv_max0p9;
821b843c749SSergey Zigachev 	v->phyclk_per_state[4] = v->phyclkv_max0p9;
822b843c749SSergey Zigachev 	v->phyclk_per_state[3] = v->phyclkv_max0p9;
823b843c749SSergey Zigachev 	v->phyclk_per_state[2] = v->phyclkv_nom0p8;
824b843c749SSergey Zigachev 	v->phyclk_per_state[1] = v->phyclkv_mid0p72;
825b843c749SSergey Zigachev 	v->phyclk_per_state[0] = v->phyclkv_min0p65;
826b843c749SSergey Zigachev 	v->synchronized_vblank = dcn_bw_no;
827b843c749SSergey Zigachev 	v->ta_pscalculation = dcn_bw_override;
828b843c749SSergey Zigachev 	v->allow_different_hratio_vratio = dcn_bw_yes;
829b843c749SSergey Zigachev 
830b843c749SSergey Zigachev 	for (i = 0, input_idx = 0; i < pool->pipe_count; i++) {
831b843c749SSergey Zigachev 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
832b843c749SSergey Zigachev 
833b843c749SSergey Zigachev 		if (!pipe->stream)
834b843c749SSergey Zigachev 			continue;
835b843c749SSergey Zigachev 		/* skip all but first of split pipes */
836b843c749SSergey Zigachev 		if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state)
837b843c749SSergey Zigachev 			continue;
838b843c749SSergey Zigachev 
839b843c749SSergey Zigachev 		v->underscan_output[input_idx] = false; /* taken care of in recout already*/
840b843c749SSergey Zigachev 		v->interlace_output[input_idx] = false;
841b843c749SSergey Zigachev 
842b843c749SSergey Zigachev 		v->htotal[input_idx] = pipe->stream->timing.h_total;
843b843c749SSergey Zigachev 		v->vtotal[input_idx] = pipe->stream->timing.v_total;
844b843c749SSergey Zigachev 		v->vactive[input_idx] = pipe->stream->timing.v_addressable +
845b843c749SSergey Zigachev 				pipe->stream->timing.v_border_top + pipe->stream->timing.v_border_bottom;
846b843c749SSergey Zigachev 		v->v_sync_plus_back_porch[input_idx] = pipe->stream->timing.v_total
847b843c749SSergey Zigachev 				- v->vactive[input_idx]
848b843c749SSergey Zigachev 				- pipe->stream->timing.v_front_porch;
849b843c749SSergey Zigachev 		v->pixel_clock[input_idx] = pipe->stream->timing.pix_clk_khz / 1000.0f;
850b843c749SSergey Zigachev 
851b843c749SSergey Zigachev 		if (!pipe->plane_state) {
852b843c749SSergey Zigachev 			v->dcc_enable[input_idx] = dcn_bw_yes;
853b843c749SSergey Zigachev 			v->source_pixel_format[input_idx] = dcn_bw_rgb_sub_32;
854b843c749SSergey Zigachev 			v->source_surface_mode[input_idx] = dcn_bw_sw_4_kb_s;
855b843c749SSergey Zigachev 			v->lb_bit_per_pixel[input_idx] = 30;
856b843c749SSergey Zigachev 			v->viewport_width[input_idx] = pipe->stream->timing.h_addressable;
857b843c749SSergey Zigachev 			v->viewport_height[input_idx] = pipe->stream->timing.v_addressable;
858b843c749SSergey Zigachev 			v->scaler_rec_out_width[input_idx] = pipe->stream->timing.h_addressable;
859b843c749SSergey Zigachev 			v->scaler_recout_height[input_idx] = pipe->stream->timing.v_addressable;
860b843c749SSergey Zigachev 			v->override_hta_ps[input_idx] = 1;
861b843c749SSergey Zigachev 			v->override_vta_ps[input_idx] = 1;
862b843c749SSergey Zigachev 			v->override_hta_pschroma[input_idx] = 1;
863b843c749SSergey Zigachev 			v->override_vta_pschroma[input_idx] = 1;
864b843c749SSergey Zigachev 			v->source_scan[input_idx] = dcn_bw_hor;
865b843c749SSergey Zigachev 
866b843c749SSergey Zigachev 		} else {
867b843c749SSergey Zigachev 			v->viewport_height[input_idx] =  pipe->plane_res.scl_data.viewport.height;
868b843c749SSergey Zigachev 			v->viewport_width[input_idx] = pipe->plane_res.scl_data.viewport.width;
869b843c749SSergey Zigachev 			v->scaler_rec_out_width[input_idx] = pipe->plane_res.scl_data.recout.width;
870b843c749SSergey Zigachev 			v->scaler_recout_height[input_idx] = pipe->plane_res.scl_data.recout.height;
871b843c749SSergey Zigachev 			if (pipe->bottom_pipe && pipe->bottom_pipe->plane_state == pipe->plane_state) {
872b843c749SSergey Zigachev 				if (pipe->plane_state->rotation % 2 == 0) {
873b843c749SSergey Zigachev 					int viewport_end = pipe->plane_res.scl_data.viewport.width
874b843c749SSergey Zigachev 							+ pipe->plane_res.scl_data.viewport.x;
875b843c749SSergey Zigachev 					int viewport_b_end = pipe->bottom_pipe->plane_res.scl_data.viewport.width
876b843c749SSergey Zigachev 							+ pipe->bottom_pipe->plane_res.scl_data.viewport.x;
877b843c749SSergey Zigachev 
878b843c749SSergey Zigachev 					if (viewport_end > viewport_b_end)
879b843c749SSergey Zigachev 						v->viewport_width[input_idx] = viewport_end
880b843c749SSergey Zigachev 							- pipe->bottom_pipe->plane_res.scl_data.viewport.x;
881b843c749SSergey Zigachev 					else
882b843c749SSergey Zigachev 						v->viewport_width[input_idx] = viewport_b_end
883b843c749SSergey Zigachev 									- pipe->plane_res.scl_data.viewport.x;
884b843c749SSergey Zigachev 				} else  {
885b843c749SSergey Zigachev 					int viewport_end = pipe->plane_res.scl_data.viewport.height
886b843c749SSergey Zigachev 						+ pipe->plane_res.scl_data.viewport.y;
887b843c749SSergey Zigachev 					int viewport_b_end = pipe->bottom_pipe->plane_res.scl_data.viewport.height
888b843c749SSergey Zigachev 						+ pipe->bottom_pipe->plane_res.scl_data.viewport.y;
889b843c749SSergey Zigachev 
890b843c749SSergey Zigachev 					if (viewport_end > viewport_b_end)
891b843c749SSergey Zigachev 						v->viewport_height[input_idx] = viewport_end
892b843c749SSergey Zigachev 							- pipe->bottom_pipe->plane_res.scl_data.viewport.y;
893b843c749SSergey Zigachev 					else
894b843c749SSergey Zigachev 						v->viewport_height[input_idx] = viewport_b_end
895b843c749SSergey Zigachev 									- pipe->plane_res.scl_data.viewport.y;
896b843c749SSergey Zigachev 				}
897b843c749SSergey Zigachev 				v->scaler_rec_out_width[input_idx] = pipe->plane_res.scl_data.recout.width
898b843c749SSergey Zigachev 						+ pipe->bottom_pipe->plane_res.scl_data.recout.width;
899b843c749SSergey Zigachev 			}
900b843c749SSergey Zigachev 
901b843c749SSergey Zigachev 			if (pipe->plane_state->rotation % 2 == 0) {
902b843c749SSergey Zigachev 				ASSERT(pipe->plane_res.scl_data.ratios.horz.value != dc_fixpt_one.value
903b843c749SSergey Zigachev 					|| v->scaler_rec_out_width[input_idx] == v->viewport_width[input_idx]);
904b843c749SSergey Zigachev 				ASSERT(pipe->plane_res.scl_data.ratios.vert.value != dc_fixpt_one.value
905b843c749SSergey Zigachev 					|| v->scaler_recout_height[input_idx] == v->viewport_height[input_idx]);
906b843c749SSergey Zigachev 			} else {
907b843c749SSergey Zigachev 				ASSERT(pipe->plane_res.scl_data.ratios.horz.value != dc_fixpt_one.value
908b843c749SSergey Zigachev 					|| v->scaler_recout_height[input_idx] == v->viewport_width[input_idx]);
909b843c749SSergey Zigachev 				ASSERT(pipe->plane_res.scl_data.ratios.vert.value != dc_fixpt_one.value
910b843c749SSergey Zigachev 					|| v->scaler_rec_out_width[input_idx] == v->viewport_height[input_idx]);
911b843c749SSergey Zigachev 			}
912b843c749SSergey Zigachev 
913b843c749SSergey Zigachev 			if (dc->debug.optimized_watermark) {
914b843c749SSergey Zigachev 				/*
915b843c749SSergey Zigachev 				 * this method requires us to always re-calculate watermark when dcc change
916b843c749SSergey Zigachev 				 * between flip.
917b843c749SSergey Zigachev 				 */
918b843c749SSergey Zigachev 				v->dcc_enable[input_idx] = pipe->plane_state->dcc.enable ? dcn_bw_yes : dcn_bw_no;
919b843c749SSergey Zigachev 			} else {
920b843c749SSergey Zigachev 				/*
921b843c749SSergey Zigachev 				 * allow us to disable dcc on the fly without re-calculating WM
922b843c749SSergey Zigachev 				 *
923b843c749SSergey Zigachev 				 * extra overhead for DCC is quite small.  for 1080p WM without
924b843c749SSergey Zigachev 				 * DCC is only 0.417us lower (urgent goes from 6.979us to 6.562us)
925b843c749SSergey Zigachev 				 */
926b843c749SSergey Zigachev 				unsigned int bpe;
927b843c749SSergey Zigachev 
928b843c749SSergey Zigachev 				v->dcc_enable[input_idx] = dc->res_pool->hubbub->funcs->dcc_support_pixel_format(
929b843c749SSergey Zigachev 						pipe->plane_state->format, &bpe) ? dcn_bw_yes : dcn_bw_no;
930b843c749SSergey Zigachev 			}
931b843c749SSergey Zigachev 
932b843c749SSergey Zigachev 			v->source_pixel_format[input_idx] = tl_pixel_format_to_bw_defs(
933b843c749SSergey Zigachev 					pipe->plane_state->format);
934b843c749SSergey Zigachev 			v->source_surface_mode[input_idx] = tl_sw_mode_to_bw_defs(
935b843c749SSergey Zigachev 					pipe->plane_state->tiling_info.gfx9.swizzle);
936b843c749SSergey Zigachev 			v->lb_bit_per_pixel[input_idx] = tl_lb_bpp_to_int(pipe->plane_res.scl_data.lb_params.depth);
937b843c749SSergey Zigachev 			v->override_hta_ps[input_idx] = pipe->plane_res.scl_data.taps.h_taps;
938b843c749SSergey Zigachev 			v->override_vta_ps[input_idx] = pipe->plane_res.scl_data.taps.v_taps;
939b843c749SSergey Zigachev 			v->override_hta_pschroma[input_idx] = pipe->plane_res.scl_data.taps.h_taps_c;
940b843c749SSergey Zigachev 			v->override_vta_pschroma[input_idx] = pipe->plane_res.scl_data.taps.v_taps_c;
941b843c749SSergey Zigachev 			/*
942b843c749SSergey Zigachev 			 * Spreadsheet doesn't handle taps_c is one properly,
943b843c749SSergey Zigachev 			 * need to force Chroma to always be scaled to pass
944b843c749SSergey Zigachev 			 * bandwidth validation.
945b843c749SSergey Zigachev 			 */
946b843c749SSergey Zigachev 			if (v->override_hta_pschroma[input_idx] == 1)
947b843c749SSergey Zigachev 				v->override_hta_pschroma[input_idx] = 2;
948b843c749SSergey Zigachev 			if (v->override_vta_pschroma[input_idx] == 1)
949b843c749SSergey Zigachev 				v->override_vta_pschroma[input_idx] = 2;
950b843c749SSergey Zigachev 			v->source_scan[input_idx] = (pipe->plane_state->rotation % 2) ? dcn_bw_vert : dcn_bw_hor;
951b843c749SSergey Zigachev 		}
952b843c749SSergey Zigachev 		if (v->is_line_buffer_bpp_fixed == dcn_bw_yes)
953b843c749SSergey Zigachev 			v->lb_bit_per_pixel[input_idx] = v->line_buffer_fixed_bpp;
954b843c749SSergey Zigachev 		v->dcc_rate[input_idx] = 1; /*TODO: Worst case? does this change?*/
955b843c749SSergey Zigachev 		v->output_format[input_idx] = pipe->stream->timing.pixel_encoding ==
956b843c749SSergey Zigachev 				PIXEL_ENCODING_YCBCR420 ? dcn_bw_420 : dcn_bw_444;
957b843c749SSergey Zigachev 		v->output[input_idx] = pipe->stream->sink->sink_signal ==
958b843c749SSergey Zigachev 				SIGNAL_TYPE_HDMI_TYPE_A ? dcn_bw_hdmi : dcn_bw_dp;
959b843c749SSergey Zigachev 		v->output_deep_color[input_idx] = dcn_bw_encoder_8bpc;
960b843c749SSergey Zigachev 		if (v->output[input_idx] == dcn_bw_hdmi) {
961b843c749SSergey Zigachev 			switch (pipe->stream->timing.display_color_depth) {
962b843c749SSergey Zigachev 			case COLOR_DEPTH_101010:
963b843c749SSergey Zigachev 				v->output_deep_color[input_idx] = dcn_bw_encoder_10bpc;
964b843c749SSergey Zigachev 				break;
965b843c749SSergey Zigachev 			case COLOR_DEPTH_121212:
966b843c749SSergey Zigachev 				v->output_deep_color[input_idx]  = dcn_bw_encoder_12bpc;
967b843c749SSergey Zigachev 				break;
968b843c749SSergey Zigachev 			case COLOR_DEPTH_161616:
969b843c749SSergey Zigachev 				v->output_deep_color[input_idx]  = dcn_bw_encoder_16bpc;
970b843c749SSergey Zigachev 				break;
971b843c749SSergey Zigachev 			default:
972b843c749SSergey Zigachev 				break;
973b843c749SSergey Zigachev 			}
974b843c749SSergey Zigachev 		}
975b843c749SSergey Zigachev 
976b843c749SSergey Zigachev 		input_idx++;
977b843c749SSergey Zigachev 	}
978b843c749SSergey Zigachev 	v->number_of_active_planes = input_idx;
979b843c749SSergey Zigachev 
980b843c749SSergey Zigachev 	scaler_settings_calculation(v);
981b843c749SSergey Zigachev 
982b843c749SSergey Zigachev 	hack_bounding_box(v, &dc->debug, context);
983b843c749SSergey Zigachev 
984b843c749SSergey Zigachev 	mode_support_and_system_configuration(v);
985b843c749SSergey Zigachev 
986b843c749SSergey Zigachev 	/* Unhack dppclk: dont bother with trying to pipe split if we cannot maintain dpm0 */
987b843c749SSergey Zigachev 	if (v->voltage_level != 0
988b843c749SSergey Zigachev 			&& context->stream_count == 1
989b843c749SSergey Zigachev 			&& dc->debug.force_single_disp_pipe_split) {
990b843c749SSergey Zigachev 		v->max_dppclk[0] = v->max_dppclk_vmin0p65;
991b843c749SSergey Zigachev 		mode_support_and_system_configuration(v);
992b843c749SSergey Zigachev 	}
993b843c749SSergey Zigachev 
994b843c749SSergey Zigachev 	if (v->voltage_level == 0 &&
995b843c749SSergey Zigachev 			(dc->debug.sr_exit_time_dpm0_ns
996b843c749SSergey Zigachev 				|| dc->debug.sr_enter_plus_exit_time_dpm0_ns)) {
997b843c749SSergey Zigachev 
998b843c749SSergey Zigachev 		if (dc->debug.sr_enter_plus_exit_time_dpm0_ns)
999b843c749SSergey Zigachev 			v->sr_enter_plus_exit_time =
1000b843c749SSergey Zigachev 				dc->debug.sr_enter_plus_exit_time_dpm0_ns / 1000.0f;
1001b843c749SSergey Zigachev 		if (dc->debug.sr_exit_time_dpm0_ns)
1002b843c749SSergey Zigachev 			v->sr_exit_time =  dc->debug.sr_exit_time_dpm0_ns / 1000.0f;
1003b843c749SSergey Zigachev 		dc->dml.soc.sr_enter_plus_exit_time_us = v->sr_enter_plus_exit_time;
1004b843c749SSergey Zigachev 		dc->dml.soc.sr_exit_time_us = v->sr_exit_time;
1005b843c749SSergey Zigachev 		mode_support_and_system_configuration(v);
1006b843c749SSergey Zigachev 	}
1007b843c749SSergey Zigachev 
1008b843c749SSergey Zigachev 	if (v->voltage_level != 5) {
1009b843c749SSergey Zigachev 		float bw_consumed = v->total_bandwidth_consumed_gbyte_per_second;
1010b843c749SSergey Zigachev 		if (bw_consumed < v->fabric_and_dram_bandwidth_vmin0p65)
1011b843c749SSergey Zigachev 			bw_consumed = v->fabric_and_dram_bandwidth_vmin0p65;
1012b843c749SSergey Zigachev 		else if (bw_consumed < v->fabric_and_dram_bandwidth_vmid0p72)
1013b843c749SSergey Zigachev 			bw_consumed = v->fabric_and_dram_bandwidth_vmid0p72;
1014b843c749SSergey Zigachev 		else if (bw_consumed < v->fabric_and_dram_bandwidth_vnom0p8)
1015b843c749SSergey Zigachev 			bw_consumed = v->fabric_and_dram_bandwidth_vnom0p8;
1016b843c749SSergey Zigachev 		else
1017b843c749SSergey Zigachev 			bw_consumed = v->fabric_and_dram_bandwidth_vmax0p9;
1018b843c749SSergey Zigachev 
1019b843c749SSergey Zigachev 		if (bw_consumed < v->fabric_and_dram_bandwidth)
1020b843c749SSergey Zigachev 			if (dc->debug.voltage_align_fclk)
1021b843c749SSergey Zigachev 				bw_consumed = v->fabric_and_dram_bandwidth;
1022b843c749SSergey Zigachev 
1023b843c749SSergey Zigachev 		display_pipe_configuration(v);
1024b843c749SSergey Zigachev 		/*calc_wm_sets_and_perf_params(context, v);*/
1025b843c749SSergey Zigachev 		/* Only 1 set is used by dcn since no noticeable
1026b843c749SSergey Zigachev 		 * performance improvement was measured and due to hw bug DEGVIDCN10-254
1027b843c749SSergey Zigachev 		 */
1028b843c749SSergey Zigachev 		dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(v);
1029b843c749SSergey Zigachev 
1030b843c749SSergey Zigachev 		context->bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns =
1031b843c749SSergey Zigachev 			v->stutter_exit_watermark * 1000;
1032b843c749SSergey Zigachev 		context->bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns =
1033b843c749SSergey Zigachev 				v->stutter_enter_plus_exit_watermark * 1000;
1034b843c749SSergey Zigachev 		context->bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns =
1035b843c749SSergey Zigachev 				v->dram_clock_change_watermark * 1000;
1036b843c749SSergey Zigachev 		context->bw.dcn.watermarks.a.pte_meta_urgent_ns = v->ptemeta_urgent_watermark * 1000;
1037b843c749SSergey Zigachev 		context->bw.dcn.watermarks.a.urgent_ns = v->urgent_watermark * 1000;
1038b843c749SSergey Zigachev 		context->bw.dcn.watermarks.b = context->bw.dcn.watermarks.a;
1039b843c749SSergey Zigachev 		context->bw.dcn.watermarks.c = context->bw.dcn.watermarks.a;
1040b843c749SSergey Zigachev 		context->bw.dcn.watermarks.d = context->bw.dcn.watermarks.a;
1041b843c749SSergey Zigachev 
1042b843c749SSergey Zigachev 		context->bw.dcn.clk.fclk_khz = (int)(bw_consumed * 1000000 /
1043b843c749SSergey Zigachev 				(ddr4_dram_factor_single_Channel * v->number_of_channels));
1044b843c749SSergey Zigachev 		if (bw_consumed == v->fabric_and_dram_bandwidth_vmin0p65) {
1045b843c749SSergey Zigachev 			context->bw.dcn.clk.fclk_khz = (int)(bw_consumed * 1000000 / 32);
1046b843c749SSergey Zigachev 		}
1047b843c749SSergey Zigachev 
1048b843c749SSergey Zigachev 		context->bw.dcn.clk.dcfclk_deep_sleep_khz = (int)(v->dcf_clk_deep_sleep * 1000);
1049b843c749SSergey Zigachev 		context->bw.dcn.clk.dcfclk_khz = (int)(v->dcfclk * 1000);
1050b843c749SSergey Zigachev 
1051b843c749SSergey Zigachev 		context->bw.dcn.clk.dispclk_khz = (int)(v->dispclk * 1000);
1052b843c749SSergey Zigachev 		if (dc->debug.max_disp_clk == true)
1053b843c749SSergey Zigachev 			context->bw.dcn.clk.dispclk_khz = (int)(dc->dcn_soc->max_dispclk_vmax0p9 * 1000);
1054b843c749SSergey Zigachev 
1055b843c749SSergey Zigachev 		if (context->bw.dcn.clk.dispclk_khz <
1056b843c749SSergey Zigachev 				dc->debug.min_disp_clk_khz) {
1057b843c749SSergey Zigachev 			context->bw.dcn.clk.dispclk_khz =
1058b843c749SSergey Zigachev 					dc->debug.min_disp_clk_khz;
1059b843c749SSergey Zigachev 		}
1060b843c749SSergey Zigachev 
1061b843c749SSergey Zigachev 		context->bw.dcn.clk.dppclk_khz = context->bw.dcn.clk.dispclk_khz / v->dispclk_dppclk_ratio;
1062b843c749SSergey Zigachev 		context->bw.dcn.clk.phyclk_khz = v->phyclk_per_state[v->voltage_level];
1063b843c749SSergey Zigachev 		switch (v->voltage_level) {
1064b843c749SSergey Zigachev 		case 0:
1065b843c749SSergey Zigachev 			context->bw.dcn.clk.max_supported_dppclk_khz =
1066b843c749SSergey Zigachev 					(int)(dc->dcn_soc->max_dppclk_vmin0p65 * 1000);
1067b843c749SSergey Zigachev 			break;
1068b843c749SSergey Zigachev 		case 1:
1069b843c749SSergey Zigachev 			context->bw.dcn.clk.max_supported_dppclk_khz =
1070b843c749SSergey Zigachev 					(int)(dc->dcn_soc->max_dppclk_vmid0p72 * 1000);
1071b843c749SSergey Zigachev 			break;
1072b843c749SSergey Zigachev 		case 2:
1073b843c749SSergey Zigachev 			context->bw.dcn.clk.max_supported_dppclk_khz =
1074b843c749SSergey Zigachev 					(int)(dc->dcn_soc->max_dppclk_vnom0p8 * 1000);
1075b843c749SSergey Zigachev 			break;
1076b843c749SSergey Zigachev 		default:
1077b843c749SSergey Zigachev 			context->bw.dcn.clk.max_supported_dppclk_khz =
1078b843c749SSergey Zigachev 					(int)(dc->dcn_soc->max_dppclk_vmax0p9 * 1000);
1079b843c749SSergey Zigachev 			break;
1080b843c749SSergey Zigachev 		}
1081b843c749SSergey Zigachev 
1082b843c749SSergey Zigachev 		for (i = 0, input_idx = 0; i < pool->pipe_count; i++) {
1083b843c749SSergey Zigachev 			struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1084b843c749SSergey Zigachev 
1085b843c749SSergey Zigachev 			/* skip inactive pipe */
1086b843c749SSergey Zigachev 			if (!pipe->stream)
1087b843c749SSergey Zigachev 				continue;
1088b843c749SSergey Zigachev 			/* skip all but first of split pipes */
1089b843c749SSergey Zigachev 			if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state)
1090b843c749SSergey Zigachev 				continue;
1091b843c749SSergey Zigachev 
1092b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vupdate_width = v->v_update_width[input_idx][v->dpp_per_plane[input_idx] == 2 ? 1 : 0];
1093b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vupdate_offset = v->v_update_offset[input_idx][v->dpp_per_plane[input_idx] == 2 ? 1 : 0];
1094b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vready_offset = v->v_ready_offset[input_idx][v->dpp_per_plane[input_idx] == 2 ? 1 : 0];
1095b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vstartup_start = v->v_startup[input_idx];
1096b843c749SSergey Zigachev 
1097b843c749SSergey Zigachev 			pipe->pipe_dlg_param.htotal = pipe->stream->timing.h_total;
1098b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vtotal = pipe->stream->timing.v_total;
1099b843c749SSergey Zigachev 			vesa_sync_start = pipe->stream->timing.v_addressable +
1100b843c749SSergey Zigachev 						pipe->stream->timing.v_border_bottom +
1101b843c749SSergey Zigachev 						pipe->stream->timing.v_front_porch;
1102b843c749SSergey Zigachev 
1103b843c749SSergey Zigachev 			asic_blank_end = (pipe->stream->timing.v_total -
1104b843c749SSergey Zigachev 						vesa_sync_start -
1105b843c749SSergey Zigachev 						pipe->stream->timing.v_border_top)
1106b843c749SSergey Zigachev 			* (pipe->stream->timing.flags.INTERLACE ? 1 : 0);
1107b843c749SSergey Zigachev 
1108b843c749SSergey Zigachev 			asic_blank_start = asic_blank_end +
1109b843c749SSergey Zigachev 						(pipe->stream->timing.v_border_top +
1110b843c749SSergey Zigachev 						pipe->stream->timing.v_addressable +
1111b843c749SSergey Zigachev 						pipe->stream->timing.v_border_bottom)
1112b843c749SSergey Zigachev 			* (pipe->stream->timing.flags.INTERLACE ? 1 : 0);
1113b843c749SSergey Zigachev 
1114b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vblank_start = asic_blank_start;
1115b843c749SSergey Zigachev 			pipe->pipe_dlg_param.vblank_end = asic_blank_end;
1116b843c749SSergey Zigachev 
1117b843c749SSergey Zigachev 			if (pipe->plane_state) {
1118b843c749SSergey Zigachev 				struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe;
1119b843c749SSergey Zigachev 
1120b843c749SSergey Zigachev 				pipe->plane_state->update_flags.bits.full_update = 1;
1121b843c749SSergey Zigachev 
1122b843c749SSergey Zigachev 				if (v->dpp_per_plane[input_idx] == 2 ||
1123b843c749SSergey Zigachev 					((pipe->stream->view_format ==
1124b843c749SSergey Zigachev 					  VIEW_3D_FORMAT_SIDE_BY_SIDE ||
1125b843c749SSergey Zigachev 					  pipe->stream->view_format ==
1126b843c749SSergey Zigachev 					  VIEW_3D_FORMAT_TOP_AND_BOTTOM) &&
1127b843c749SSergey Zigachev 					(pipe->stream->timing.timing_3d_format ==
1128b843c749SSergey Zigachev 					 TIMING_3D_FORMAT_TOP_AND_BOTTOM ||
1129b843c749SSergey Zigachev 					 pipe->stream->timing.timing_3d_format ==
1130b843c749SSergey Zigachev 					 TIMING_3D_FORMAT_SIDE_BY_SIDE))) {
1131b843c749SSergey Zigachev 					if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) {
1132b843c749SSergey Zigachev 						/* update previously split pipe */
1133b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vupdate_width = v->v_update_width[input_idx][v->dpp_per_plane[input_idx] == 2 ? 1 : 0];
1134b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vupdate_offset = v->v_update_offset[input_idx][v->dpp_per_plane[input_idx] == 2 ? 1 : 0];
1135b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vready_offset = v->v_ready_offset[input_idx][v->dpp_per_plane[input_idx] == 2 ? 1 : 0];
1136b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vstartup_start = v->v_startup[input_idx];
1137b843c749SSergey Zigachev 
1138b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.htotal = pipe->stream->timing.h_total;
1139b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vtotal = pipe->stream->timing.v_total;
1140b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vblank_start = pipe->pipe_dlg_param.vblank_start;
1141b843c749SSergey Zigachev 						hsplit_pipe->pipe_dlg_param.vblank_end = pipe->pipe_dlg_param.vblank_end;
1142b843c749SSergey Zigachev 					} else {
1143b843c749SSergey Zigachev 						/* pipe not split previously needs split */
1144b843c749SSergey Zigachev 						hsplit_pipe = find_idle_secondary_pipe(&context->res_ctx, pool);
1145b843c749SSergey Zigachev 						ASSERT(hsplit_pipe);
1146b843c749SSergey Zigachev 						split_stream_across_pipes(
1147b843c749SSergey Zigachev 							&context->res_ctx, pool,
1148b843c749SSergey Zigachev 							pipe, hsplit_pipe);
1149b843c749SSergey Zigachev 					}
1150b843c749SSergey Zigachev 
1151b843c749SSergey Zigachev 					dcn_bw_calc_rq_dlg_ttu(dc, v, hsplit_pipe, input_idx);
1152b843c749SSergey Zigachev 				} else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) {
1153b843c749SSergey Zigachev 					/* merge previously split pipe */
1154b843c749SSergey Zigachev 					pipe->bottom_pipe = hsplit_pipe->bottom_pipe;
1155b843c749SSergey Zigachev 					if (hsplit_pipe->bottom_pipe)
1156b843c749SSergey Zigachev 						hsplit_pipe->bottom_pipe->top_pipe = pipe;
1157b843c749SSergey Zigachev 					hsplit_pipe->plane_state = NULL;
1158b843c749SSergey Zigachev 					hsplit_pipe->stream = NULL;
1159b843c749SSergey Zigachev 					hsplit_pipe->top_pipe = NULL;
1160b843c749SSergey Zigachev 					hsplit_pipe->bottom_pipe = NULL;
1161b843c749SSergey Zigachev 					/* Clear plane_res and stream_res */
1162b843c749SSergey Zigachev 					memset(&hsplit_pipe->plane_res, 0, sizeof(hsplit_pipe->plane_res));
1163b843c749SSergey Zigachev 					memset(&hsplit_pipe->stream_res, 0, sizeof(hsplit_pipe->stream_res));
1164b843c749SSergey Zigachev 					resource_build_scaling_params(pipe);
1165b843c749SSergey Zigachev 				}
1166b843c749SSergey Zigachev 				/* for now important to do this after pipe split for building e2e params */
1167b843c749SSergey Zigachev 				dcn_bw_calc_rq_dlg_ttu(dc, v, pipe, input_idx);
1168b843c749SSergey Zigachev 			}
1169b843c749SSergey Zigachev 
1170b843c749SSergey Zigachev 			input_idx++;
1171b843c749SSergey Zigachev 		}
1172b843c749SSergey Zigachev 	}
1173b843c749SSergey Zigachev 
1174b843c749SSergey Zigachev 	if (v->voltage_level == 0) {
1175b843c749SSergey Zigachev 
1176b843c749SSergey Zigachev 		dc->dml.soc.sr_enter_plus_exit_time_us =
1177b843c749SSergey Zigachev 				dc->dcn_soc->sr_enter_plus_exit_time;
1178b843c749SSergey Zigachev 		dc->dml.soc.sr_exit_time_us = dc->dcn_soc->sr_exit_time;
1179b843c749SSergey Zigachev 	}
1180b843c749SSergey Zigachev 
1181b843c749SSergey Zigachev 	/*
1182b843c749SSergey Zigachev 	 * BW limit is set to prevent display from impacting other system functions
1183b843c749SSergey Zigachev 	 */
1184b843c749SSergey Zigachev 
1185b843c749SSergey Zigachev 	bw_limit = dc->dcn_soc->percent_disp_bw_limit * v->fabric_and_dram_bandwidth_vmax0p9;
1186b843c749SSergey Zigachev 	bw_limit_pass = (v->total_data_read_bandwidth / 1000.0) < bw_limit;
1187b843c749SSergey Zigachev 
1188b843c749SSergey Zigachev 	kernel_fpu_end();
1189b843c749SSergey Zigachev 
1190b843c749SSergey Zigachev 	PERFORMANCE_TRACE_END();
1191b843c749SSergey Zigachev 
1192b843c749SSergey Zigachev 	if (bw_limit_pass && v->voltage_level != 5)
1193b843c749SSergey Zigachev 		return true;
1194b843c749SSergey Zigachev 	else
1195b843c749SSergey Zigachev 		return false;
1196b843c749SSergey Zigachev }
1197b843c749SSergey Zigachev 
dcn_find_normalized_clock_vdd_Level(const struct dc * dc,enum dm_pp_clock_type clocks_type,int clocks_in_khz)1198b843c749SSergey Zigachev static unsigned int dcn_find_normalized_clock_vdd_Level(
1199b843c749SSergey Zigachev 	const struct dc *dc,
1200b843c749SSergey Zigachev 	enum dm_pp_clock_type clocks_type,
1201b843c749SSergey Zigachev 	int clocks_in_khz)
1202b843c749SSergey Zigachev {
1203b843c749SSergey Zigachev 	int vdd_level = dcn_bw_v_min0p65;
1204b843c749SSergey Zigachev 
1205b843c749SSergey Zigachev 	if (clocks_in_khz == 0)/*todo some clock not in the considerations*/
1206b843c749SSergey Zigachev 		return vdd_level;
1207b843c749SSergey Zigachev 
1208b843c749SSergey Zigachev 	switch (clocks_type) {
1209b843c749SSergey Zigachev 	case DM_PP_CLOCK_TYPE_DISPLAY_CLK:
1210b843c749SSergey Zigachev 		if (clocks_in_khz > dc->dcn_soc->max_dispclk_vmax0p9*1000) {
1211b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p91;
1212b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1213b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->max_dispclk_vnom0p8*1000) {
1214b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p9;
1215b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->max_dispclk_vmid0p72*1000) {
1216b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_nom0p8;
1217b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->max_dispclk_vmin0p65*1000) {
1218b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_mid0p72;
1219b843c749SSergey Zigachev 		} else
1220b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_min0p65;
1221b843c749SSergey Zigachev 		break;
1222b843c749SSergey Zigachev 	case DM_PP_CLOCK_TYPE_DISPLAYPHYCLK:
1223b843c749SSergey Zigachev 		if (clocks_in_khz > dc->dcn_soc->phyclkv_max0p9*1000) {
1224b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p91;
1225b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1226b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->phyclkv_nom0p8*1000) {
1227b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p9;
1228b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->phyclkv_mid0p72*1000) {
1229b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_nom0p8;
1230b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->phyclkv_min0p65*1000) {
1231b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_mid0p72;
1232b843c749SSergey Zigachev 		} else
1233b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_min0p65;
1234b843c749SSergey Zigachev 		break;
1235b843c749SSergey Zigachev 
1236b843c749SSergey Zigachev 	case DM_PP_CLOCK_TYPE_DPPCLK:
1237b843c749SSergey Zigachev 		if (clocks_in_khz > dc->dcn_soc->max_dppclk_vmax0p9*1000) {
1238b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p91;
1239b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1240b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->max_dppclk_vnom0p8*1000) {
1241b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p9;
1242b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->max_dppclk_vmid0p72*1000) {
1243b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_nom0p8;
1244b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->max_dppclk_vmin0p65*1000) {
1245b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_mid0p72;
1246b843c749SSergey Zigachev 		} else
1247b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_min0p65;
1248b843c749SSergey Zigachev 		break;
1249b843c749SSergey Zigachev 
1250b843c749SSergey Zigachev 	case DM_PP_CLOCK_TYPE_MEMORY_CLK:
1251b843c749SSergey Zigachev 		{
1252b843c749SSergey Zigachev 			unsigned factor = (ddr4_dram_factor_single_Channel * dc->dcn_soc->number_of_channels);
1253b843c749SSergey Zigachev 
1254b843c749SSergey Zigachev 			if (clocks_in_khz > dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9*1000000/factor) {
1255b843c749SSergey Zigachev 				vdd_level = dcn_bw_v_max0p91;
1256b843c749SSergey Zigachev 				BREAK_TO_DEBUGGER();
1257b843c749SSergey Zigachev 			} else if (clocks_in_khz > dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8*1000000/factor) {
1258b843c749SSergey Zigachev 				vdd_level = dcn_bw_v_max0p9;
1259b843c749SSergey Zigachev 			} else if (clocks_in_khz > dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72*1000000/factor) {
1260b843c749SSergey Zigachev 				vdd_level = dcn_bw_v_nom0p8;
1261b843c749SSergey Zigachev 			} else if (clocks_in_khz > dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65*1000000/factor) {
1262b843c749SSergey Zigachev 				vdd_level = dcn_bw_v_mid0p72;
1263b843c749SSergey Zigachev 			} else
1264b843c749SSergey Zigachev 				vdd_level = dcn_bw_v_min0p65;
1265b843c749SSergey Zigachev 		}
1266b843c749SSergey Zigachev 		break;
1267b843c749SSergey Zigachev 
1268b843c749SSergey Zigachev 	case DM_PP_CLOCK_TYPE_DCFCLK:
1269b843c749SSergey Zigachev 		if (clocks_in_khz > dc->dcn_soc->dcfclkv_max0p9*1000) {
1270b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p91;
1271b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1272b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->dcfclkv_nom0p8*1000) {
1273b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_max0p9;
1274b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->dcfclkv_mid0p72*1000) {
1275b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_nom0p8;
1276b843c749SSergey Zigachev 		} else if (clocks_in_khz > dc->dcn_soc->dcfclkv_min0p65*1000) {
1277b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_mid0p72;
1278b843c749SSergey Zigachev 		} else
1279b843c749SSergey Zigachev 			vdd_level = dcn_bw_v_min0p65;
1280b843c749SSergey Zigachev 		break;
1281b843c749SSergey Zigachev 
1282b843c749SSergey Zigachev 	default:
1283b843c749SSergey Zigachev 		 break;
1284b843c749SSergey Zigachev 	}
1285b843c749SSergey Zigachev 	return vdd_level;
1286b843c749SSergey Zigachev }
1287b843c749SSergey Zigachev 
dcn_find_dcfclk_suits_all(const struct dc * dc,struct dc_clocks * clocks)1288b843c749SSergey Zigachev unsigned int dcn_find_dcfclk_suits_all(
1289b843c749SSergey Zigachev 	const struct dc *dc,
1290b843c749SSergey Zigachev 	struct dc_clocks *clocks)
1291b843c749SSergey Zigachev {
1292b843c749SSergey Zigachev 	unsigned vdd_level, vdd_level_temp;
1293b843c749SSergey Zigachev 	unsigned dcf_clk;
1294b843c749SSergey Zigachev 
1295b843c749SSergey Zigachev 	/*find a common supported voltage level*/
1296b843c749SSergey Zigachev 	vdd_level = dcn_find_normalized_clock_vdd_Level(
1297b843c749SSergey Zigachev 		dc, DM_PP_CLOCK_TYPE_DISPLAY_CLK, clocks->dispclk_khz);
1298b843c749SSergey Zigachev 	vdd_level_temp = dcn_find_normalized_clock_vdd_Level(
1299b843c749SSergey Zigachev 		dc, DM_PP_CLOCK_TYPE_DISPLAYPHYCLK, clocks->phyclk_khz);
1300b843c749SSergey Zigachev 
1301b843c749SSergey Zigachev 	vdd_level = dcn_bw_max(vdd_level, vdd_level_temp);
1302b843c749SSergey Zigachev 	vdd_level_temp = dcn_find_normalized_clock_vdd_Level(
1303b843c749SSergey Zigachev 		dc, DM_PP_CLOCK_TYPE_DPPCLK, clocks->dppclk_khz);
1304b843c749SSergey Zigachev 	vdd_level = dcn_bw_max(vdd_level, vdd_level_temp);
1305b843c749SSergey Zigachev 
1306b843c749SSergey Zigachev 	vdd_level_temp = dcn_find_normalized_clock_vdd_Level(
1307b843c749SSergey Zigachev 		dc, DM_PP_CLOCK_TYPE_MEMORY_CLK, clocks->fclk_khz);
1308b843c749SSergey Zigachev 	vdd_level = dcn_bw_max(vdd_level, vdd_level_temp);
1309b843c749SSergey Zigachev 	vdd_level_temp = dcn_find_normalized_clock_vdd_Level(
1310b843c749SSergey Zigachev 		dc, DM_PP_CLOCK_TYPE_DCFCLK, clocks->dcfclk_khz);
1311b843c749SSergey Zigachev 
1312b843c749SSergey Zigachev 	/*find that level conresponding dcfclk*/
1313b843c749SSergey Zigachev 	vdd_level = dcn_bw_max(vdd_level, vdd_level_temp);
1314b843c749SSergey Zigachev 	if (vdd_level == dcn_bw_v_max0p91) {
1315b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1316b843c749SSergey Zigachev 		dcf_clk = dc->dcn_soc->dcfclkv_max0p9*1000;
1317b843c749SSergey Zigachev 	} else if (vdd_level == dcn_bw_v_max0p9)
1318b843c749SSergey Zigachev 		dcf_clk =  dc->dcn_soc->dcfclkv_max0p9*1000;
1319b843c749SSergey Zigachev 	else if (vdd_level == dcn_bw_v_nom0p8)
1320b843c749SSergey Zigachev 		dcf_clk =  dc->dcn_soc->dcfclkv_nom0p8*1000;
1321b843c749SSergey Zigachev 	else if (vdd_level == dcn_bw_v_mid0p72)
1322b843c749SSergey Zigachev 		dcf_clk =  dc->dcn_soc->dcfclkv_mid0p72*1000;
1323b843c749SSergey Zigachev 	else
1324b843c749SSergey Zigachev 		dcf_clk =  dc->dcn_soc->dcfclkv_min0p65*1000;
1325b843c749SSergey Zigachev 
1326b843c749SSergey Zigachev 	DC_LOG_BANDWIDTH_CALCS("\tdcf_clk for voltage = %d\n", dcf_clk);
1327b843c749SSergey Zigachev 	return dcf_clk;
1328b843c749SSergey Zigachev }
1329b843c749SSergey Zigachev 
verify_clock_values(struct dm_pp_clock_levels_with_voltage * clks)1330b843c749SSergey Zigachev static bool verify_clock_values(struct dm_pp_clock_levels_with_voltage *clks)
1331b843c749SSergey Zigachev {
1332b843c749SSergey Zigachev 	int i;
1333b843c749SSergey Zigachev 
1334b843c749SSergey Zigachev 	if (clks->num_levels == 0)
1335b843c749SSergey Zigachev 		return false;
1336b843c749SSergey Zigachev 
1337b843c749SSergey Zigachev 	for (i = 0; i < clks->num_levels; i++)
1338b843c749SSergey Zigachev 		/* Ensure that the result is sane */
1339b843c749SSergey Zigachev 		if (clks->data[i].clocks_in_khz == 0)
1340b843c749SSergey Zigachev 			return false;
1341b843c749SSergey Zigachev 
1342b843c749SSergey Zigachev 	return true;
1343b843c749SSergey Zigachev }
1344b843c749SSergey Zigachev 
dcn_bw_update_from_pplib(struct dc * dc)1345b843c749SSergey Zigachev void dcn_bw_update_from_pplib(struct dc *dc)
1346b843c749SSergey Zigachev {
1347b843c749SSergey Zigachev 	struct dc_context *ctx = dc->ctx;
1348b843c749SSergey Zigachev 	struct dm_pp_clock_levels_with_voltage fclks = {0}, dcfclks = {0};
1349b843c749SSergey Zigachev 	bool res;
1350b843c749SSergey Zigachev 	unsigned vmin0p65_idx, vmid0p72_idx, vnom0p8_idx, vmax0p9_idx;
1351b843c749SSergey Zigachev 
1352b843c749SSergey Zigachev 	/* TODO: This is not the proper way to obtain fabric_and_dram_bandwidth, should be min(fclk, memclk) */
1353b843c749SSergey Zigachev 	res = dm_pp_get_clock_levels_by_type_with_voltage(
1354b843c749SSergey Zigachev 			ctx, DM_PP_CLOCK_TYPE_FCLK, &fclks);
1355b843c749SSergey Zigachev 
1356b843c749SSergey Zigachev 	kernel_fpu_begin();
1357b843c749SSergey Zigachev 
1358b843c749SSergey Zigachev 	if (res)
1359b843c749SSergey Zigachev 		res = verify_clock_values(&fclks);
1360b843c749SSergey Zigachev 
1361b843c749SSergey Zigachev 	if (res) {
1362b843c749SSergey Zigachev 		ASSERT(fclks.num_levels);
1363b843c749SSergey Zigachev 
1364b843c749SSergey Zigachev 		vmin0p65_idx = 0;
1365b843c749SSergey Zigachev 		vmid0p72_idx = fclks.num_levels -
1366b843c749SSergey Zigachev 			(fclks.num_levels > 2 ? 3 : (fclks.num_levels > 1 ? 2 : 1));
1367b843c749SSergey Zigachev 		vnom0p8_idx = fclks.num_levels - (fclks.num_levels > 1 ? 2 : 1);
1368b843c749SSergey Zigachev 		vmax0p9_idx = fclks.num_levels - 1;
1369b843c749SSergey Zigachev 
1370b843c749SSergey Zigachev 		dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 =
1371b843c749SSergey Zigachev 			32 * (fclks.data[vmin0p65_idx].clocks_in_khz / 1000.0) / 1000.0;
1372b843c749SSergey Zigachev 		dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 =
1373b843c749SSergey Zigachev 			dc->dcn_soc->number_of_channels *
1374b843c749SSergey Zigachev 			(fclks.data[vmid0p72_idx].clocks_in_khz / 1000.0)
1375b843c749SSergey Zigachev 			* ddr4_dram_factor_single_Channel / 1000.0;
1376b843c749SSergey Zigachev 		dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 =
1377b843c749SSergey Zigachev 			dc->dcn_soc->number_of_channels *
1378b843c749SSergey Zigachev 			(fclks.data[vnom0p8_idx].clocks_in_khz / 1000.0)
1379b843c749SSergey Zigachev 			* ddr4_dram_factor_single_Channel / 1000.0;
1380b843c749SSergey Zigachev 		dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 =
1381b843c749SSergey Zigachev 			dc->dcn_soc->number_of_channels *
1382b843c749SSergey Zigachev 			(fclks.data[vmax0p9_idx].clocks_in_khz / 1000.0)
1383b843c749SSergey Zigachev 			* ddr4_dram_factor_single_Channel / 1000.0;
1384b843c749SSergey Zigachev 	} else
1385b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1386b843c749SSergey Zigachev 
1387b843c749SSergey Zigachev 	kernel_fpu_end();
1388b843c749SSergey Zigachev 
1389b843c749SSergey Zigachev 	res = dm_pp_get_clock_levels_by_type_with_voltage(
1390b843c749SSergey Zigachev 			ctx, DM_PP_CLOCK_TYPE_DCFCLK, &dcfclks);
1391b843c749SSergey Zigachev 
1392b843c749SSergey Zigachev 	kernel_fpu_begin();
1393b843c749SSergey Zigachev 
1394b843c749SSergey Zigachev 	if (res)
1395b843c749SSergey Zigachev 		res = verify_clock_values(&dcfclks);
1396b843c749SSergey Zigachev 
1397b843c749SSergey Zigachev 	if (res && dcfclks.num_levels >= 3) {
1398b843c749SSergey Zigachev 		dc->dcn_soc->dcfclkv_min0p65 = dcfclks.data[0].clocks_in_khz / 1000.0;
1399b843c749SSergey Zigachev 		dc->dcn_soc->dcfclkv_mid0p72 = dcfclks.data[dcfclks.num_levels - 3].clocks_in_khz / 1000.0;
1400b843c749SSergey Zigachev 		dc->dcn_soc->dcfclkv_nom0p8 = dcfclks.data[dcfclks.num_levels - 2].clocks_in_khz / 1000.0;
1401b843c749SSergey Zigachev 		dc->dcn_soc->dcfclkv_max0p9 = dcfclks.data[dcfclks.num_levels - 1].clocks_in_khz / 1000.0;
1402b843c749SSergey Zigachev 	} else
1403b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1404b843c749SSergey Zigachev 
1405b843c749SSergey Zigachev 	kernel_fpu_end();
1406b843c749SSergey Zigachev }
1407b843c749SSergey Zigachev 
dcn_bw_notify_pplib_of_wm_ranges(struct dc * dc)1408b843c749SSergey Zigachev void dcn_bw_notify_pplib_of_wm_ranges(struct dc *dc)
1409b843c749SSergey Zigachev {
1410b843c749SSergey Zigachev 	struct pp_smu_funcs_rv *pp = dc->res_pool->pp_smu;
1411b843c749SSergey Zigachev 	struct pp_smu_wm_range_sets ranges = {0};
1412b843c749SSergey Zigachev 	int min_fclk_khz, min_dcfclk_khz, socclk_khz;
1413b843c749SSergey Zigachev 	const int overdrive = 5000000; /* 5 GHz to cover Overdrive */
1414b843c749SSergey Zigachev 
1415b843c749SSergey Zigachev 	if (!pp->set_wm_ranges)
1416b843c749SSergey Zigachev 		return;
1417b843c749SSergey Zigachev 
1418b843c749SSergey Zigachev 	kernel_fpu_begin();
1419b843c749SSergey Zigachev 	min_fclk_khz = dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 * 1000000 / 32;
1420b843c749SSergey Zigachev 	min_dcfclk_khz = dc->dcn_soc->dcfclkv_min0p65 * 1000;
1421b843c749SSergey Zigachev 	socclk_khz = dc->dcn_soc->socclk * 1000;
1422b843c749SSergey Zigachev 	kernel_fpu_end();
1423b843c749SSergey Zigachev 
1424b843c749SSergey Zigachev 	/* Now notify PPLib/SMU about which Watermarks sets they should select
1425b843c749SSergey Zigachev 	 * depending on DPM state they are in. And update BW MGR GFX Engine and
1426b843c749SSergey Zigachev 	 * Memory clock member variables for Watermarks calculations for each
1427b843c749SSergey Zigachev 	 * Watermark Set. Only one watermark set for dcn1 due to hw bug DEGVIDCN10-254.
1428b843c749SSergey Zigachev 	 */
1429b843c749SSergey Zigachev 	/* SOCCLK does not affect anytihng but writeback for DCN so for now we dont
1430b843c749SSergey Zigachev 	 * care what the value is, hence min to overdrive level
1431b843c749SSergey Zigachev 	 */
1432b843c749SSergey Zigachev 	ranges.num_reader_wm_sets = WM_SET_COUNT;
1433b843c749SSergey Zigachev 	ranges.num_writer_wm_sets = WM_SET_COUNT;
1434b843c749SSergey Zigachev 	ranges.reader_wm_sets[0].wm_inst = WM_A;
1435b843c749SSergey Zigachev 	ranges.reader_wm_sets[0].min_drain_clk_khz = min_dcfclk_khz;
1436b843c749SSergey Zigachev 	ranges.reader_wm_sets[0].max_drain_clk_khz = overdrive;
1437b843c749SSergey Zigachev 	ranges.reader_wm_sets[0].min_fill_clk_khz = min_fclk_khz;
1438b843c749SSergey Zigachev 	ranges.reader_wm_sets[0].max_fill_clk_khz = overdrive;
1439b843c749SSergey Zigachev 	ranges.writer_wm_sets[0].wm_inst = WM_A;
1440b843c749SSergey Zigachev 	ranges.writer_wm_sets[0].min_fill_clk_khz = socclk_khz;
1441b843c749SSergey Zigachev 	ranges.writer_wm_sets[0].max_fill_clk_khz = overdrive;
1442b843c749SSergey Zigachev 	ranges.writer_wm_sets[0].min_drain_clk_khz = min_fclk_khz;
1443b843c749SSergey Zigachev 	ranges.writer_wm_sets[0].max_drain_clk_khz = overdrive;
1444b843c749SSergey Zigachev 
1445b843c749SSergey Zigachev 	if (dc->debug.pplib_wm_report_mode == WM_REPORT_OVERRIDE) {
1446b843c749SSergey Zigachev 		ranges.reader_wm_sets[0].wm_inst = WM_A;
1447b843c749SSergey Zigachev 		ranges.reader_wm_sets[0].min_drain_clk_khz = 300000;
1448b843c749SSergey Zigachev 		ranges.reader_wm_sets[0].max_drain_clk_khz = 5000000;
1449b843c749SSergey Zigachev 		ranges.reader_wm_sets[0].min_fill_clk_khz = 800000;
1450b843c749SSergey Zigachev 		ranges.reader_wm_sets[0].max_fill_clk_khz = 5000000;
1451b843c749SSergey Zigachev 		ranges.writer_wm_sets[0].wm_inst = WM_A;
1452b843c749SSergey Zigachev 		ranges.writer_wm_sets[0].min_fill_clk_khz = 200000;
1453b843c749SSergey Zigachev 		ranges.writer_wm_sets[0].max_fill_clk_khz = 5000000;
1454b843c749SSergey Zigachev 		ranges.writer_wm_sets[0].min_drain_clk_khz = 800000;
1455b843c749SSergey Zigachev 		ranges.writer_wm_sets[0].max_drain_clk_khz = 5000000;
1456b843c749SSergey Zigachev 	}
1457b843c749SSergey Zigachev 
1458b843c749SSergey Zigachev 	ranges.reader_wm_sets[1] = ranges.writer_wm_sets[0];
1459b843c749SSergey Zigachev 	ranges.reader_wm_sets[1].wm_inst = WM_B;
1460b843c749SSergey Zigachev 
1461b843c749SSergey Zigachev 	ranges.reader_wm_sets[2] = ranges.writer_wm_sets[0];
1462b843c749SSergey Zigachev 	ranges.reader_wm_sets[2].wm_inst = WM_C;
1463b843c749SSergey Zigachev 
1464b843c749SSergey Zigachev 	ranges.reader_wm_sets[3] = ranges.writer_wm_sets[0];
1465b843c749SSergey Zigachev 	ranges.reader_wm_sets[3].wm_inst = WM_D;
1466b843c749SSergey Zigachev 
1467b843c749SSergey Zigachev 	/* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
1468b843c749SSergey Zigachev 	pp->set_wm_ranges(&pp->pp_smu, &ranges);
1469b843c749SSergey Zigachev }
1470b843c749SSergey Zigachev 
dcn_bw_sync_calcs_and_dml(struct dc * dc)1471b843c749SSergey Zigachev void dcn_bw_sync_calcs_and_dml(struct dc *dc)
1472b843c749SSergey Zigachev {
1473b843c749SSergey Zigachev 	kernel_fpu_begin();
1474b843c749SSergey Zigachev 	DC_LOG_BANDWIDTH_CALCS("sr_exit_time: %f ns\n"
1475b843c749SSergey Zigachev 			"sr_enter_plus_exit_time: %f ns\n"
1476b843c749SSergey Zigachev 			"urgent_latency: %f ns\n"
1477b843c749SSergey Zigachev 			"write_back_latency: %f ns\n"
1478b843c749SSergey Zigachev 			"percent_of_ideal_drambw_received_after_urg_latency: %f %%\n"
1479b843c749SSergey Zigachev 			"max_request_size: %d bytes\n"
1480b843c749SSergey Zigachev 			"dcfclkv_max0p9: %f kHz\n"
1481b843c749SSergey Zigachev 			"dcfclkv_nom0p8: %f kHz\n"
1482b843c749SSergey Zigachev 			"dcfclkv_mid0p72: %f kHz\n"
1483b843c749SSergey Zigachev 			"dcfclkv_min0p65: %f kHz\n"
1484b843c749SSergey Zigachev 			"max_dispclk_vmax0p9: %f kHz\n"
1485b843c749SSergey Zigachev 			"max_dispclk_vnom0p8: %f kHz\n"
1486b843c749SSergey Zigachev 			"max_dispclk_vmid0p72: %f kHz\n"
1487b843c749SSergey Zigachev 			"max_dispclk_vmin0p65: %f kHz\n"
1488b843c749SSergey Zigachev 			"max_dppclk_vmax0p9: %f kHz\n"
1489b843c749SSergey Zigachev 			"max_dppclk_vnom0p8: %f kHz\n"
1490b843c749SSergey Zigachev 			"max_dppclk_vmid0p72: %f kHz\n"
1491b843c749SSergey Zigachev 			"max_dppclk_vmin0p65: %f kHz\n"
1492b843c749SSergey Zigachev 			"socclk: %f kHz\n"
1493b843c749SSergey Zigachev 			"fabric_and_dram_bandwidth_vmax0p9: %f MB/s\n"
1494b843c749SSergey Zigachev 			"fabric_and_dram_bandwidth_vnom0p8: %f MB/s\n"
1495b843c749SSergey Zigachev 			"fabric_and_dram_bandwidth_vmid0p72: %f MB/s\n"
1496b843c749SSergey Zigachev 			"fabric_and_dram_bandwidth_vmin0p65: %f MB/s\n"
1497b843c749SSergey Zigachev 			"phyclkv_max0p9: %f kHz\n"
1498b843c749SSergey Zigachev 			"phyclkv_nom0p8: %f kHz\n"
1499b843c749SSergey Zigachev 			"phyclkv_mid0p72: %f kHz\n"
1500b843c749SSergey Zigachev 			"phyclkv_min0p65: %f kHz\n"
1501b843c749SSergey Zigachev 			"downspreading: %f %%\n"
1502b843c749SSergey Zigachev 			"round_trip_ping_latency_cycles: %d DCFCLK Cycles\n"
1503b843c749SSergey Zigachev 			"urgent_out_of_order_return_per_channel: %d Bytes\n"
1504b843c749SSergey Zigachev 			"number_of_channels: %d\n"
1505b843c749SSergey Zigachev 			"vmm_page_size: %d Bytes\n"
1506b843c749SSergey Zigachev 			"dram_clock_change_latency: %f ns\n"
1507b843c749SSergey Zigachev 			"return_bus_width: %d Bytes\n",
1508b843c749SSergey Zigachev 			dc->dcn_soc->sr_exit_time * 1000,
1509b843c749SSergey Zigachev 			dc->dcn_soc->sr_enter_plus_exit_time * 1000,
1510b843c749SSergey Zigachev 			dc->dcn_soc->urgent_latency * 1000,
1511b843c749SSergey Zigachev 			dc->dcn_soc->write_back_latency * 1000,
1512b843c749SSergey Zigachev 			dc->dcn_soc->percent_of_ideal_drambw_received_after_urg_latency,
1513b843c749SSergey Zigachev 			dc->dcn_soc->max_request_size,
1514b843c749SSergey Zigachev 			dc->dcn_soc->dcfclkv_max0p9 * 1000,
1515b843c749SSergey Zigachev 			dc->dcn_soc->dcfclkv_nom0p8 * 1000,
1516b843c749SSergey Zigachev 			dc->dcn_soc->dcfclkv_mid0p72 * 1000,
1517b843c749SSergey Zigachev 			dc->dcn_soc->dcfclkv_min0p65 * 1000,
1518b843c749SSergey Zigachev 			dc->dcn_soc->max_dispclk_vmax0p9 * 1000,
1519b843c749SSergey Zigachev 			dc->dcn_soc->max_dispclk_vnom0p8 * 1000,
1520b843c749SSergey Zigachev 			dc->dcn_soc->max_dispclk_vmid0p72 * 1000,
1521b843c749SSergey Zigachev 			dc->dcn_soc->max_dispclk_vmin0p65 * 1000,
1522b843c749SSergey Zigachev 			dc->dcn_soc->max_dppclk_vmax0p9 * 1000,
1523b843c749SSergey Zigachev 			dc->dcn_soc->max_dppclk_vnom0p8 * 1000,
1524b843c749SSergey Zigachev 			dc->dcn_soc->max_dppclk_vmid0p72 * 1000,
1525b843c749SSergey Zigachev 			dc->dcn_soc->max_dppclk_vmin0p65 * 1000,
1526b843c749SSergey Zigachev 			dc->dcn_soc->socclk * 1000,
1527b843c749SSergey Zigachev 			dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 * 1000,
1528b843c749SSergey Zigachev 			dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 * 1000,
1529b843c749SSergey Zigachev 			dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 * 1000,
1530b843c749SSergey Zigachev 			dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 * 1000,
1531b843c749SSergey Zigachev 			dc->dcn_soc->phyclkv_max0p9 * 1000,
1532b843c749SSergey Zigachev 			dc->dcn_soc->phyclkv_nom0p8 * 1000,
1533b843c749SSergey Zigachev 			dc->dcn_soc->phyclkv_mid0p72 * 1000,
1534b843c749SSergey Zigachev 			dc->dcn_soc->phyclkv_min0p65 * 1000,
1535b843c749SSergey Zigachev 			dc->dcn_soc->downspreading * 100,
1536b843c749SSergey Zigachev 			dc->dcn_soc->round_trip_ping_latency_cycles,
1537b843c749SSergey Zigachev 			dc->dcn_soc->urgent_out_of_order_return_per_channel,
1538b843c749SSergey Zigachev 			dc->dcn_soc->number_of_channels,
1539b843c749SSergey Zigachev 			dc->dcn_soc->vmm_page_size,
1540b843c749SSergey Zigachev 			dc->dcn_soc->dram_clock_change_latency * 1000,
1541b843c749SSergey Zigachev 			dc->dcn_soc->return_bus_width);
1542b843c749SSergey Zigachev 	DC_LOG_BANDWIDTH_CALCS("rob_buffer_size_in_kbyte: %f\n"
1543b843c749SSergey Zigachev 			"det_buffer_size_in_kbyte: %f\n"
1544b843c749SSergey Zigachev 			"dpp_output_buffer_pixels: %f\n"
1545b843c749SSergey Zigachev 			"opp_output_buffer_lines: %f\n"
1546b843c749SSergey Zigachev 			"pixel_chunk_size_in_kbyte: %f\n"
1547b843c749SSergey Zigachev 			"pte_enable: %d\n"
1548b843c749SSergey Zigachev 			"pte_chunk_size: %d kbytes\n"
1549b843c749SSergey Zigachev 			"meta_chunk_size: %d kbytes\n"
1550b843c749SSergey Zigachev 			"writeback_chunk_size: %d kbytes\n"
1551b843c749SSergey Zigachev 			"odm_capability: %d\n"
1552b843c749SSergey Zigachev 			"dsc_capability: %d\n"
1553b843c749SSergey Zigachev 			"line_buffer_size: %d bits\n"
1554b843c749SSergey Zigachev 			"max_line_buffer_lines: %d\n"
1555b843c749SSergey Zigachev 			"is_line_buffer_bpp_fixed: %d\n"
1556b843c749SSergey Zigachev 			"line_buffer_fixed_bpp: %d\n"
1557b843c749SSergey Zigachev 			"writeback_luma_buffer_size: %d kbytes\n"
1558b843c749SSergey Zigachev 			"writeback_chroma_buffer_size: %d kbytes\n"
1559b843c749SSergey Zigachev 			"max_num_dpp: %d\n"
1560b843c749SSergey Zigachev 			"max_num_writeback: %d\n"
1561b843c749SSergey Zigachev 			"max_dchub_topscl_throughput: %d pixels/dppclk\n"
1562b843c749SSergey Zigachev 			"max_pscl_tolb_throughput: %d pixels/dppclk\n"
1563b843c749SSergey Zigachev 			"max_lb_tovscl_throughput: %d pixels/dppclk\n"
1564b843c749SSergey Zigachev 			"max_vscl_tohscl_throughput: %d pixels/dppclk\n"
1565b843c749SSergey Zigachev 			"max_hscl_ratio: %f\n"
1566b843c749SSergey Zigachev 			"max_vscl_ratio: %f\n"
1567b843c749SSergey Zigachev 			"max_hscl_taps: %d\n"
1568b843c749SSergey Zigachev 			"max_vscl_taps: %d\n"
1569b843c749SSergey Zigachev 			"pte_buffer_size_in_requests: %d\n"
1570b843c749SSergey Zigachev 			"dispclk_ramping_margin: %f %%\n"
1571b843c749SSergey Zigachev 			"under_scan_factor: %f %%\n"
1572b843c749SSergey Zigachev 			"max_inter_dcn_tile_repeaters: %d\n"
1573b843c749SSergey Zigachev 			"can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one: %d\n"
1574b843c749SSergey Zigachev 			"bug_forcing_luma_and_chroma_request_to_same_size_fixed: %d\n"
1575b843c749SSergey Zigachev 			"dcfclk_cstate_latency: %d\n",
1576b843c749SSergey Zigachev 			dc->dcn_ip->rob_buffer_size_in_kbyte,
1577b843c749SSergey Zigachev 			dc->dcn_ip->det_buffer_size_in_kbyte,
1578b843c749SSergey Zigachev 			dc->dcn_ip->dpp_output_buffer_pixels,
1579b843c749SSergey Zigachev 			dc->dcn_ip->opp_output_buffer_lines,
1580b843c749SSergey Zigachev 			dc->dcn_ip->pixel_chunk_size_in_kbyte,
1581b843c749SSergey Zigachev 			dc->dcn_ip->pte_enable,
1582b843c749SSergey Zigachev 			dc->dcn_ip->pte_chunk_size,
1583b843c749SSergey Zigachev 			dc->dcn_ip->meta_chunk_size,
1584b843c749SSergey Zigachev 			dc->dcn_ip->writeback_chunk_size,
1585b843c749SSergey Zigachev 			dc->dcn_ip->odm_capability,
1586b843c749SSergey Zigachev 			dc->dcn_ip->dsc_capability,
1587b843c749SSergey Zigachev 			dc->dcn_ip->line_buffer_size,
1588b843c749SSergey Zigachev 			dc->dcn_ip->max_line_buffer_lines,
1589b843c749SSergey Zigachev 			dc->dcn_ip->is_line_buffer_bpp_fixed,
1590b843c749SSergey Zigachev 			dc->dcn_ip->line_buffer_fixed_bpp,
1591b843c749SSergey Zigachev 			dc->dcn_ip->writeback_luma_buffer_size,
1592b843c749SSergey Zigachev 			dc->dcn_ip->writeback_chroma_buffer_size,
1593b843c749SSergey Zigachev 			dc->dcn_ip->max_num_dpp,
1594b843c749SSergey Zigachev 			dc->dcn_ip->max_num_writeback,
1595b843c749SSergey Zigachev 			dc->dcn_ip->max_dchub_topscl_throughput,
1596b843c749SSergey Zigachev 			dc->dcn_ip->max_pscl_tolb_throughput,
1597b843c749SSergey Zigachev 			dc->dcn_ip->max_lb_tovscl_throughput,
1598b843c749SSergey Zigachev 			dc->dcn_ip->max_vscl_tohscl_throughput,
1599b843c749SSergey Zigachev 			dc->dcn_ip->max_hscl_ratio,
1600b843c749SSergey Zigachev 			dc->dcn_ip->max_vscl_ratio,
1601b843c749SSergey Zigachev 			dc->dcn_ip->max_hscl_taps,
1602b843c749SSergey Zigachev 			dc->dcn_ip->max_vscl_taps,
1603b843c749SSergey Zigachev 			dc->dcn_ip->pte_buffer_size_in_requests,
1604b843c749SSergey Zigachev 			dc->dcn_ip->dispclk_ramping_margin,
1605b843c749SSergey Zigachev 			dc->dcn_ip->under_scan_factor * 100,
1606b843c749SSergey Zigachev 			dc->dcn_ip->max_inter_dcn_tile_repeaters,
1607b843c749SSergey Zigachev 			dc->dcn_ip->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one,
1608b843c749SSergey Zigachev 			dc->dcn_ip->bug_forcing_luma_and_chroma_request_to_same_size_fixed,
1609b843c749SSergey Zigachev 			dc->dcn_ip->dcfclk_cstate_latency);
1610b843c749SSergey Zigachev 
1611b843c749SSergey Zigachev 	dc->dml.soc.sr_exit_time_us = dc->dcn_soc->sr_exit_time;
1612b843c749SSergey Zigachev 	dc->dml.soc.sr_enter_plus_exit_time_us = dc->dcn_soc->sr_enter_plus_exit_time;
1613b843c749SSergey Zigachev 	dc->dml.soc.urgent_latency_us = dc->dcn_soc->urgent_latency;
1614b843c749SSergey Zigachev 	dc->dml.soc.writeback_latency_us = dc->dcn_soc->write_back_latency;
1615b843c749SSergey Zigachev 	dc->dml.soc.ideal_dram_bw_after_urgent_percent =
1616b843c749SSergey Zigachev 			dc->dcn_soc->percent_of_ideal_drambw_received_after_urg_latency;
1617b843c749SSergey Zigachev 	dc->dml.soc.max_request_size_bytes = dc->dcn_soc->max_request_size;
1618b843c749SSergey Zigachev 	dc->dml.soc.downspread_percent = dc->dcn_soc->downspreading;
1619b843c749SSergey Zigachev 	dc->dml.soc.round_trip_ping_latency_dcfclk_cycles =
1620b843c749SSergey Zigachev 			dc->dcn_soc->round_trip_ping_latency_cycles;
1621b843c749SSergey Zigachev 	dc->dml.soc.urgent_out_of_order_return_per_channel_bytes =
1622b843c749SSergey Zigachev 			dc->dcn_soc->urgent_out_of_order_return_per_channel;
1623b843c749SSergey Zigachev 	dc->dml.soc.num_chans = dc->dcn_soc->number_of_channels;
1624b843c749SSergey Zigachev 	dc->dml.soc.vmm_page_size_bytes = dc->dcn_soc->vmm_page_size;
1625b843c749SSergey Zigachev 	dc->dml.soc.dram_clock_change_latency_us = dc->dcn_soc->dram_clock_change_latency;
1626b843c749SSergey Zigachev 	dc->dml.soc.return_bus_width_bytes = dc->dcn_soc->return_bus_width;
1627b843c749SSergey Zigachev 
1628b843c749SSergey Zigachev 	dc->dml.ip.rob_buffer_size_kbytes = dc->dcn_ip->rob_buffer_size_in_kbyte;
1629b843c749SSergey Zigachev 	dc->dml.ip.det_buffer_size_kbytes = dc->dcn_ip->det_buffer_size_in_kbyte;
1630b843c749SSergey Zigachev 	dc->dml.ip.dpp_output_buffer_pixels = dc->dcn_ip->dpp_output_buffer_pixels;
1631b843c749SSergey Zigachev 	dc->dml.ip.opp_output_buffer_lines = dc->dcn_ip->opp_output_buffer_lines;
1632b843c749SSergey Zigachev 	dc->dml.ip.pixel_chunk_size_kbytes = dc->dcn_ip->pixel_chunk_size_in_kbyte;
1633b843c749SSergey Zigachev 	dc->dml.ip.pte_enable = dc->dcn_ip->pte_enable == dcn_bw_yes;
1634b843c749SSergey Zigachev 	dc->dml.ip.pte_chunk_size_kbytes = dc->dcn_ip->pte_chunk_size;
1635b843c749SSergey Zigachev 	dc->dml.ip.meta_chunk_size_kbytes = dc->dcn_ip->meta_chunk_size;
1636b843c749SSergey Zigachev 	dc->dml.ip.writeback_chunk_size_kbytes = dc->dcn_ip->writeback_chunk_size;
1637b843c749SSergey Zigachev 	dc->dml.ip.line_buffer_size_bits = dc->dcn_ip->line_buffer_size;
1638b843c749SSergey Zigachev 	dc->dml.ip.max_line_buffer_lines = dc->dcn_ip->max_line_buffer_lines;
1639b843c749SSergey Zigachev 	dc->dml.ip.IsLineBufferBppFixed = dc->dcn_ip->is_line_buffer_bpp_fixed == dcn_bw_yes;
1640b843c749SSergey Zigachev 	dc->dml.ip.LineBufferFixedBpp = dc->dcn_ip->line_buffer_fixed_bpp;
1641b843c749SSergey Zigachev 	dc->dml.ip.writeback_luma_buffer_size_kbytes = dc->dcn_ip->writeback_luma_buffer_size;
1642b843c749SSergey Zigachev 	dc->dml.ip.writeback_chroma_buffer_size_kbytes = dc->dcn_ip->writeback_chroma_buffer_size;
1643b843c749SSergey Zigachev 	dc->dml.ip.max_num_dpp = dc->dcn_ip->max_num_dpp;
1644b843c749SSergey Zigachev 	dc->dml.ip.max_num_wb = dc->dcn_ip->max_num_writeback;
1645b843c749SSergey Zigachev 	dc->dml.ip.max_dchub_pscl_bw_pix_per_clk = dc->dcn_ip->max_dchub_topscl_throughput;
1646b843c749SSergey Zigachev 	dc->dml.ip.max_pscl_lb_bw_pix_per_clk = dc->dcn_ip->max_pscl_tolb_throughput;
1647b843c749SSergey Zigachev 	dc->dml.ip.max_lb_vscl_bw_pix_per_clk = dc->dcn_ip->max_lb_tovscl_throughput;
1648b843c749SSergey Zigachev 	dc->dml.ip.max_vscl_hscl_bw_pix_per_clk = dc->dcn_ip->max_vscl_tohscl_throughput;
1649b843c749SSergey Zigachev 	dc->dml.ip.max_hscl_ratio = dc->dcn_ip->max_hscl_ratio;
1650b843c749SSergey Zigachev 	dc->dml.ip.max_vscl_ratio = dc->dcn_ip->max_vscl_ratio;
1651b843c749SSergey Zigachev 	dc->dml.ip.max_hscl_taps = dc->dcn_ip->max_hscl_taps;
1652b843c749SSergey Zigachev 	dc->dml.ip.max_vscl_taps = dc->dcn_ip->max_vscl_taps;
1653b843c749SSergey Zigachev 	/*pte_buffer_size_in_requests missing in dml*/
1654b843c749SSergey Zigachev 	dc->dml.ip.dispclk_ramp_margin_percent = dc->dcn_ip->dispclk_ramping_margin;
1655b843c749SSergey Zigachev 	dc->dml.ip.underscan_factor = dc->dcn_ip->under_scan_factor;
1656b843c749SSergey Zigachev 	dc->dml.ip.max_inter_dcn_tile_repeaters = dc->dcn_ip->max_inter_dcn_tile_repeaters;
1657b843c749SSergey Zigachev 	dc->dml.ip.can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one =
1658b843c749SSergey Zigachev 		dc->dcn_ip->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes;
1659b843c749SSergey Zigachev 	dc->dml.ip.bug_forcing_LC_req_same_size_fixed =
1660b843c749SSergey Zigachev 		dc->dcn_ip->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes;
1661b843c749SSergey Zigachev 	dc->dml.ip.dcfclk_cstate_latency = dc->dcn_ip->dcfclk_cstate_latency;
1662b843c749SSergey Zigachev 	kernel_fpu_end();
1663b843c749SSergey Zigachev }
1664