1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev  * Copyright 2017 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev  *
4*b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev  *
11*b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev  *
14*b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev  *
22*b843c749SSergey Zigachev  * Authors: AMD
23*b843c749SSergey Zigachev  *
24*b843c749SSergey Zigachev  */
25*b843c749SSergey Zigachev 
26*b843c749SSergey Zigachev #include "dml1_display_rq_dlg_calc.h"
27*b843c749SSergey Zigachev #include "display_mode_lib.h"
28*b843c749SSergey Zigachev 
29*b843c749SSergey Zigachev #include "dml_inline_defs.h"
30*b843c749SSergey Zigachev 
31*b843c749SSergey Zigachev /*
32*b843c749SSergey Zigachev  * NOTE:
33*b843c749SSergey Zigachev  *   This file is gcc-parseable HW gospel, coming straight from HW engineers.
34*b843c749SSergey Zigachev  *
35*b843c749SSergey Zigachev  * It doesn't adhere to Linux kernel style and sometimes will do things in odd
36*b843c749SSergey Zigachev  * ways. Unless there is something clearly wrong with it the code should
37*b843c749SSergey Zigachev  * remain as-is as it provides us with a guarantee from HW that it is correct.
38*b843c749SSergey Zigachev  */
39*b843c749SSergey Zigachev 
get_bytes_per_element(enum source_format_class source_format,bool is_chroma)40*b843c749SSergey Zigachev static unsigned int get_bytes_per_element(enum source_format_class source_format, bool is_chroma)
41*b843c749SSergey Zigachev {
42*b843c749SSergey Zigachev 	unsigned int ret_val = 0;
43*b843c749SSergey Zigachev 
44*b843c749SSergey Zigachev 	if (source_format == dm_444_16) {
45*b843c749SSergey Zigachev 		if (!is_chroma)
46*b843c749SSergey Zigachev 			ret_val = 2;
47*b843c749SSergey Zigachev 	} else if (source_format == dm_444_32) {
48*b843c749SSergey Zigachev 		if (!is_chroma)
49*b843c749SSergey Zigachev 			ret_val = 4;
50*b843c749SSergey Zigachev 	} else if (source_format == dm_444_64) {
51*b843c749SSergey Zigachev 		if (!is_chroma)
52*b843c749SSergey Zigachev 			ret_val = 8;
53*b843c749SSergey Zigachev 	} else if (source_format == dm_420_8) {
54*b843c749SSergey Zigachev 		if (is_chroma)
55*b843c749SSergey Zigachev 			ret_val = 2;
56*b843c749SSergey Zigachev 		else
57*b843c749SSergey Zigachev 			ret_val = 1;
58*b843c749SSergey Zigachev 	} else if (source_format == dm_420_10) {
59*b843c749SSergey Zigachev 		if (is_chroma)
60*b843c749SSergey Zigachev 			ret_val = 4;
61*b843c749SSergey Zigachev 		else
62*b843c749SSergey Zigachev 			ret_val = 2;
63*b843c749SSergey Zigachev 	}
64*b843c749SSergey Zigachev 	return ret_val;
65*b843c749SSergey Zigachev }
66*b843c749SSergey Zigachev 
is_dual_plane(enum source_format_class source_format)67*b843c749SSergey Zigachev static bool is_dual_plane(enum source_format_class source_format)
68*b843c749SSergey Zigachev {
69*b843c749SSergey Zigachev 	bool ret_val = 0;
70*b843c749SSergey Zigachev 
71*b843c749SSergey Zigachev 	if ((source_format == dm_420_8) || (source_format == dm_420_10))
72*b843c749SSergey Zigachev 		ret_val = 1;
73*b843c749SSergey Zigachev 
74*b843c749SSergey Zigachev 	return ret_val;
75*b843c749SSergey Zigachev }
76*b843c749SSergey Zigachev 
get_blk256_size(unsigned int * blk256_width,unsigned int * blk256_height,unsigned int bytes_per_element)77*b843c749SSergey Zigachev static void get_blk256_size(
78*b843c749SSergey Zigachev 		unsigned int *blk256_width,
79*b843c749SSergey Zigachev 		unsigned int *blk256_height,
80*b843c749SSergey Zigachev 		unsigned int bytes_per_element)
81*b843c749SSergey Zigachev {
82*b843c749SSergey Zigachev 	if (bytes_per_element == 1) {
83*b843c749SSergey Zigachev 		*blk256_width = 16;
84*b843c749SSergey Zigachev 		*blk256_height = 16;
85*b843c749SSergey Zigachev 	} else if (bytes_per_element == 2) {
86*b843c749SSergey Zigachev 		*blk256_width = 16;
87*b843c749SSergey Zigachev 		*blk256_height = 8;
88*b843c749SSergey Zigachev 	} else if (bytes_per_element == 4) {
89*b843c749SSergey Zigachev 		*blk256_width = 8;
90*b843c749SSergey Zigachev 		*blk256_height = 8;
91*b843c749SSergey Zigachev 	} else if (bytes_per_element == 8) {
92*b843c749SSergey Zigachev 		*blk256_width = 8;
93*b843c749SSergey Zigachev 		*blk256_height = 4;
94*b843c749SSergey Zigachev 	}
95*b843c749SSergey Zigachev }
96*b843c749SSergey Zigachev 
get_refcyc_per_delivery(struct display_mode_lib * mode_lib,double refclk_freq_in_mhz,double pclk_freq_in_mhz,unsigned int recout_width,double vratio,double hscale_pixel_rate,unsigned int delivery_width,unsigned int req_per_swath_ub)97*b843c749SSergey Zigachev static double get_refcyc_per_delivery(
98*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
99*b843c749SSergey Zigachev 		double refclk_freq_in_mhz,
100*b843c749SSergey Zigachev 		double pclk_freq_in_mhz,
101*b843c749SSergey Zigachev 		unsigned int recout_width,
102*b843c749SSergey Zigachev 		double vratio,
103*b843c749SSergey Zigachev 		double hscale_pixel_rate,
104*b843c749SSergey Zigachev 		unsigned int delivery_width,
105*b843c749SSergey Zigachev 		unsigned int req_per_swath_ub)
106*b843c749SSergey Zigachev {
107*b843c749SSergey Zigachev 	double refcyc_per_delivery = 0.0;
108*b843c749SSergey Zigachev 
109*b843c749SSergey Zigachev 	if (vratio <= 1.0) {
110*b843c749SSergey Zigachev 		refcyc_per_delivery = (double) refclk_freq_in_mhz * (double) recout_width
111*b843c749SSergey Zigachev 				/ pclk_freq_in_mhz / (double) req_per_swath_ub;
112*b843c749SSergey Zigachev 	} else {
113*b843c749SSergey Zigachev 		refcyc_per_delivery = (double) refclk_freq_in_mhz * (double) delivery_width
114*b843c749SSergey Zigachev 				/ (double) hscale_pixel_rate / (double) req_per_swath_ub;
115*b843c749SSergey Zigachev 	}
116*b843c749SSergey Zigachev 
117*b843c749SSergey Zigachev 	DTRACE("DLG: %s: refclk_freq_in_mhz = %3.2f", __func__, refclk_freq_in_mhz);
118*b843c749SSergey Zigachev 	DTRACE("DLG: %s: pclk_freq_in_mhz   = %3.2f", __func__, pclk_freq_in_mhz);
119*b843c749SSergey Zigachev 	DTRACE("DLG: %s: recout_width       = %d", __func__, recout_width);
120*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vratio             = %3.2f", __func__, vratio);
121*b843c749SSergey Zigachev 	DTRACE("DLG: %s: req_per_swath_ub   = %d", __func__, req_per_swath_ub);
122*b843c749SSergey Zigachev 	DTRACE("DLG: %s: refcyc_per_delivery= %3.2f", __func__, refcyc_per_delivery);
123*b843c749SSergey Zigachev 
124*b843c749SSergey Zigachev 	return refcyc_per_delivery;
125*b843c749SSergey Zigachev 
126*b843c749SSergey Zigachev }
127*b843c749SSergey Zigachev 
get_vratio_pre(struct display_mode_lib * mode_lib,unsigned int max_num_sw,unsigned int max_partial_sw,unsigned int swath_height,double vinit,double l_sw)128*b843c749SSergey Zigachev static double get_vratio_pre(
129*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
130*b843c749SSergey Zigachev 		unsigned int max_num_sw,
131*b843c749SSergey Zigachev 		unsigned int max_partial_sw,
132*b843c749SSergey Zigachev 		unsigned int swath_height,
133*b843c749SSergey Zigachev 		double vinit,
134*b843c749SSergey Zigachev 		double l_sw)
135*b843c749SSergey Zigachev {
136*b843c749SSergey Zigachev 	double prefill = dml_floor(vinit, 1);
137*b843c749SSergey Zigachev 	double vratio_pre = 1.0;
138*b843c749SSergey Zigachev 
139*b843c749SSergey Zigachev 	vratio_pre = (max_num_sw * swath_height + max_partial_sw) / l_sw;
140*b843c749SSergey Zigachev 
141*b843c749SSergey Zigachev 	if (swath_height > 4) {
142*b843c749SSergey Zigachev 		double tmp0 = (max_num_sw * swath_height) / (l_sw - (prefill - 3.0) / 2.0);
143*b843c749SSergey Zigachev 
144*b843c749SSergey Zigachev 		if (tmp0 > vratio_pre)
145*b843c749SSergey Zigachev 			vratio_pre = tmp0;
146*b843c749SSergey Zigachev 	}
147*b843c749SSergey Zigachev 
148*b843c749SSergey Zigachev 	DTRACE("DLG: %s: max_num_sw        = %0d", __func__, max_num_sw);
149*b843c749SSergey Zigachev 	DTRACE("DLG: %s: max_partial_sw    = %0d", __func__, max_partial_sw);
150*b843c749SSergey Zigachev 	DTRACE("DLG: %s: swath_height      = %0d", __func__, swath_height);
151*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vinit             = %3.2f", __func__, vinit);
152*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vratio_pre        = %3.2f", __func__, vratio_pre);
153*b843c749SSergey Zigachev 
154*b843c749SSergey Zigachev 	if (vratio_pre < 1.0) {
155*b843c749SSergey Zigachev 		DTRACE("WARNING_DLG: %s:  vratio_pre=%3.2f < 1.0, set to 1.0", __func__, vratio_pre);
156*b843c749SSergey Zigachev 		vratio_pre = 1.0;
157*b843c749SSergey Zigachev 	}
158*b843c749SSergey Zigachev 
159*b843c749SSergey Zigachev 	if (vratio_pre > 4.0) {
160*b843c749SSergey Zigachev 		DTRACE(
161*b843c749SSergey Zigachev 				"WARNING_DLG: %s:  vratio_pre=%3.2f > 4.0 (max scaling ratio). set to 4.0",
162*b843c749SSergey Zigachev 				__func__,
163*b843c749SSergey Zigachev 				vratio_pre);
164*b843c749SSergey Zigachev 		vratio_pre = 4.0;
165*b843c749SSergey Zigachev 	}
166*b843c749SSergey Zigachev 
167*b843c749SSergey Zigachev 	return vratio_pre;
168*b843c749SSergey Zigachev }
169*b843c749SSergey Zigachev 
get_swath_need(struct display_mode_lib * mode_lib,unsigned int * max_num_sw,unsigned int * max_partial_sw,unsigned int swath_height,double vinit)170*b843c749SSergey Zigachev static void get_swath_need(
171*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
172*b843c749SSergey Zigachev 		unsigned int *max_num_sw,
173*b843c749SSergey Zigachev 		unsigned int *max_partial_sw,
174*b843c749SSergey Zigachev 		unsigned int swath_height,
175*b843c749SSergey Zigachev 		double vinit)
176*b843c749SSergey Zigachev {
177*b843c749SSergey Zigachev 	double prefill = dml_floor(vinit, 1);
178*b843c749SSergey Zigachev 	unsigned int max_partial_sw_int;
179*b843c749SSergey Zigachev 
180*b843c749SSergey Zigachev 	DTRACE("DLG: %s: swath_height      = %0d", __func__, swath_height);
181*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vinit             = %3.2f", __func__, vinit);
182*b843c749SSergey Zigachev 
183*b843c749SSergey Zigachev 	ASSERT(prefill > 0.0 && prefill <= 8.0);
184*b843c749SSergey Zigachev 
185*b843c749SSergey Zigachev 	*max_num_sw = (unsigned int) (dml_ceil((prefill - 1.0) / (double) swath_height, 1) + 1.0); /* prefill has to be >= 1 */
186*b843c749SSergey Zigachev 	max_partial_sw_int =
187*b843c749SSergey Zigachev 			(prefill == 1) ?
188*b843c749SSergey Zigachev 					(swath_height - 1) :
189*b843c749SSergey Zigachev 					((unsigned int) (prefill - 2.0) % swath_height);
190*b843c749SSergey Zigachev 	*max_partial_sw = (max_partial_sw_int < 1) ? 1 : max_partial_sw_int; /* ensure minimum of 1 is used */
191*b843c749SSergey Zigachev 
192*b843c749SSergey Zigachev 	DTRACE("DLG: %s: max_num_sw        = %0d", __func__, *max_num_sw);
193*b843c749SSergey Zigachev 	DTRACE("DLG: %s: max_partial_sw    = %0d", __func__, *max_partial_sw);
194*b843c749SSergey Zigachev }
195*b843c749SSergey Zigachev 
get_blk_size_bytes(const enum source_macro_tile_size tile_size)196*b843c749SSergey Zigachev static unsigned int get_blk_size_bytes(const enum source_macro_tile_size tile_size)
197*b843c749SSergey Zigachev {
198*b843c749SSergey Zigachev 	if (tile_size == dm_256k_tile)
199*b843c749SSergey Zigachev 		return (256 * 1024);
200*b843c749SSergey Zigachev 	else if (tile_size == dm_64k_tile)
201*b843c749SSergey Zigachev 		return (64 * 1024);
202*b843c749SSergey Zigachev 	else
203*b843c749SSergey Zigachev 		return (4 * 1024);
204*b843c749SSergey Zigachev }
205*b843c749SSergey Zigachev 
extract_rq_sizing_regs(struct display_mode_lib * mode_lib,struct _vcs_dpi_display_data_rq_regs_st * rq_regs,const struct _vcs_dpi_display_data_rq_sizing_params_st rq_sizing)206*b843c749SSergey Zigachev static void extract_rq_sizing_regs(
207*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
208*b843c749SSergey Zigachev 		struct _vcs_dpi_display_data_rq_regs_st *rq_regs,
209*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_data_rq_sizing_params_st rq_sizing)
210*b843c749SSergey Zigachev {
211*b843c749SSergey Zigachev 	DTRACE("DLG: %s: rq_sizing param", __func__);
212*b843c749SSergey Zigachev 	print__data_rq_sizing_params_st(mode_lib, rq_sizing);
213*b843c749SSergey Zigachev 
214*b843c749SSergey Zigachev 	rq_regs->chunk_size = dml_log2(rq_sizing.chunk_bytes) - 10;
215*b843c749SSergey Zigachev 
216*b843c749SSergey Zigachev 	if (rq_sizing.min_chunk_bytes == 0)
217*b843c749SSergey Zigachev 		rq_regs->min_chunk_size = 0;
218*b843c749SSergey Zigachev 	else
219*b843c749SSergey Zigachev 		rq_regs->min_chunk_size = dml_log2(rq_sizing.min_chunk_bytes) - 8 + 1;
220*b843c749SSergey Zigachev 
221*b843c749SSergey Zigachev 	rq_regs->meta_chunk_size = dml_log2(rq_sizing.meta_chunk_bytes) - 10;
222*b843c749SSergey Zigachev 	if (rq_sizing.min_meta_chunk_bytes == 0)
223*b843c749SSergey Zigachev 		rq_regs->min_meta_chunk_size = 0;
224*b843c749SSergey Zigachev 	else
225*b843c749SSergey Zigachev 		rq_regs->min_meta_chunk_size = dml_log2(rq_sizing.min_meta_chunk_bytes) - 6 + 1;
226*b843c749SSergey Zigachev 
227*b843c749SSergey Zigachev 	rq_regs->dpte_group_size = dml_log2(rq_sizing.dpte_group_bytes) - 6;
228*b843c749SSergey Zigachev 	rq_regs->mpte_group_size = dml_log2(rq_sizing.mpte_group_bytes) - 6;
229*b843c749SSergey Zigachev }
230*b843c749SSergey Zigachev 
dml1_extract_rq_regs(struct display_mode_lib * mode_lib,struct _vcs_dpi_display_rq_regs_st * rq_regs,const struct _vcs_dpi_display_rq_params_st rq_param)231*b843c749SSergey Zigachev void dml1_extract_rq_regs(
232*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
233*b843c749SSergey Zigachev 		struct _vcs_dpi_display_rq_regs_st *rq_regs,
234*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_rq_params_st rq_param)
235*b843c749SSergey Zigachev {
236*b843c749SSergey Zigachev 	unsigned int detile_buf_size_in_bytes = mode_lib->ip.det_buffer_size_kbytes * 1024;
237*b843c749SSergey Zigachev 	unsigned int detile_buf_plane1_addr = 0;
238*b843c749SSergey Zigachev 
239*b843c749SSergey Zigachev 	extract_rq_sizing_regs(mode_lib, &(rq_regs->rq_regs_l), rq_param.sizing.rq_l);
240*b843c749SSergey Zigachev 	if (rq_param.yuv420)
241*b843c749SSergey Zigachev 		extract_rq_sizing_regs(mode_lib, &(rq_regs->rq_regs_c), rq_param.sizing.rq_c);
242*b843c749SSergey Zigachev 
243*b843c749SSergey Zigachev 	rq_regs->rq_regs_l.swath_height = dml_log2(rq_param.dlg.rq_l.swath_height);
244*b843c749SSergey Zigachev 	rq_regs->rq_regs_c.swath_height = dml_log2(rq_param.dlg.rq_c.swath_height);
245*b843c749SSergey Zigachev 
246*b843c749SSergey Zigachev 	/* FIXME: take the max between luma, chroma chunk size?
247*b843c749SSergey Zigachev 	 * okay for now, as we are setting chunk_bytes to 8kb anyways
248*b843c749SSergey Zigachev 	 */
249*b843c749SSergey Zigachev 	if (rq_param.sizing.rq_l.chunk_bytes >= 32 * 1024) { /*32kb */
250*b843c749SSergey Zigachev 		rq_regs->drq_expansion_mode = 0;
251*b843c749SSergey Zigachev 	} else {
252*b843c749SSergey Zigachev 		rq_regs->drq_expansion_mode = 2;
253*b843c749SSergey Zigachev 	}
254*b843c749SSergey Zigachev 	rq_regs->prq_expansion_mode = 1;
255*b843c749SSergey Zigachev 	rq_regs->mrq_expansion_mode = 1;
256*b843c749SSergey Zigachev 	rq_regs->crq_expansion_mode = 1;
257*b843c749SSergey Zigachev 
258*b843c749SSergey Zigachev 	if (rq_param.yuv420) {
259*b843c749SSergey Zigachev 		if ((double) rq_param.misc.rq_l.stored_swath_bytes
260*b843c749SSergey Zigachev 				/ (double) rq_param.misc.rq_c.stored_swath_bytes <= 1.5) {
261*b843c749SSergey Zigachev 			detile_buf_plane1_addr = (detile_buf_size_in_bytes / 2.0 / 64.0); /* half to chroma */
262*b843c749SSergey Zigachev 		} else {
263*b843c749SSergey Zigachev 			detile_buf_plane1_addr = dml_round_to_multiple(
264*b843c749SSergey Zigachev 					(unsigned int) ((2.0 * detile_buf_size_in_bytes) / 3.0),
265*b843c749SSergey Zigachev 					256,
266*b843c749SSergey Zigachev 					0) / 64.0; /* 2/3 to chroma */
267*b843c749SSergey Zigachev 		}
268*b843c749SSergey Zigachev 	}
269*b843c749SSergey Zigachev 	rq_regs->plane1_base_address = detile_buf_plane1_addr;
270*b843c749SSergey Zigachev }
271*b843c749SSergey Zigachev 
handle_det_buf_split(struct display_mode_lib * mode_lib,struct _vcs_dpi_display_rq_params_st * rq_param,const struct _vcs_dpi_display_pipe_source_params_st pipe_src_param)272*b843c749SSergey Zigachev static void handle_det_buf_split(
273*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
274*b843c749SSergey Zigachev 		struct _vcs_dpi_display_rq_params_st *rq_param,
275*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_pipe_source_params_st pipe_src_param)
276*b843c749SSergey Zigachev {
277*b843c749SSergey Zigachev 	unsigned int total_swath_bytes = 0;
278*b843c749SSergey Zigachev 	unsigned int swath_bytes_l = 0;
279*b843c749SSergey Zigachev 	unsigned int swath_bytes_c = 0;
280*b843c749SSergey Zigachev 	unsigned int full_swath_bytes_packed_l = 0;
281*b843c749SSergey Zigachev 	unsigned int full_swath_bytes_packed_c = 0;
282*b843c749SSergey Zigachev 	bool req128_l = 0;
283*b843c749SSergey Zigachev 	bool req128_c = 0;
284*b843c749SSergey Zigachev 	bool surf_linear = (pipe_src_param.sw_mode == dm_sw_linear);
285*b843c749SSergey Zigachev 	bool surf_vert = (pipe_src_param.source_scan == dm_vert);
286*b843c749SSergey Zigachev 	unsigned int log2_swath_height_l = 0;
287*b843c749SSergey Zigachev 	unsigned int log2_swath_height_c = 0;
288*b843c749SSergey Zigachev 	unsigned int detile_buf_size_in_bytes = mode_lib->ip.det_buffer_size_kbytes * 1024;
289*b843c749SSergey Zigachev 
290*b843c749SSergey Zigachev 	full_swath_bytes_packed_l = rq_param->misc.rq_l.full_swath_bytes;
291*b843c749SSergey Zigachev 	full_swath_bytes_packed_c = rq_param->misc.rq_c.full_swath_bytes;
292*b843c749SSergey Zigachev 
293*b843c749SSergey Zigachev 	if (rq_param->yuv420_10bpc) {
294*b843c749SSergey Zigachev 		full_swath_bytes_packed_l = dml_round_to_multiple(
295*b843c749SSergey Zigachev 				rq_param->misc.rq_l.full_swath_bytes * 2 / 3,
296*b843c749SSergey Zigachev 				256,
297*b843c749SSergey Zigachev 				1) + 256;
298*b843c749SSergey Zigachev 		full_swath_bytes_packed_c = dml_round_to_multiple(
299*b843c749SSergey Zigachev 				rq_param->misc.rq_c.full_swath_bytes * 2 / 3,
300*b843c749SSergey Zigachev 				256,
301*b843c749SSergey Zigachev 				1) + 256;
302*b843c749SSergey Zigachev 	}
303*b843c749SSergey Zigachev 
304*b843c749SSergey Zigachev 	if (rq_param->yuv420) {
305*b843c749SSergey Zigachev 		total_swath_bytes = 2 * full_swath_bytes_packed_l + 2 * full_swath_bytes_packed_c;
306*b843c749SSergey Zigachev 
307*b843c749SSergey Zigachev 		if (total_swath_bytes <= detile_buf_size_in_bytes) { /*full 256b request */
308*b843c749SSergey Zigachev 			req128_l = 0;
309*b843c749SSergey Zigachev 			req128_c = 0;
310*b843c749SSergey Zigachev 			swath_bytes_l = full_swath_bytes_packed_l;
311*b843c749SSergey Zigachev 			swath_bytes_c = full_swath_bytes_packed_c;
312*b843c749SSergey Zigachev 		} else { /*128b request (for luma only for yuv420 8bpc) */
313*b843c749SSergey Zigachev 			req128_l = 1;
314*b843c749SSergey Zigachev 			req128_c = 0;
315*b843c749SSergey Zigachev 			swath_bytes_l = full_swath_bytes_packed_l / 2;
316*b843c749SSergey Zigachev 			swath_bytes_c = full_swath_bytes_packed_c;
317*b843c749SSergey Zigachev 		}
318*b843c749SSergey Zigachev 
319*b843c749SSergey Zigachev 		/* Bug workaround, luma and chroma req size needs to be the same. (see: DEGVIDCN10-137)
320*b843c749SSergey Zigachev 		 * TODO: Remove after rtl fix
321*b843c749SSergey Zigachev 		 */
322*b843c749SSergey Zigachev 		if (req128_l == 1) {
323*b843c749SSergey Zigachev 			req128_c = 1;
324*b843c749SSergey Zigachev 			DTRACE("DLG: %s: bug workaround DEGVIDCN10-137", __func__);
325*b843c749SSergey Zigachev 		}
326*b843c749SSergey Zigachev 
327*b843c749SSergey Zigachev 		/* Note: assumption, the config that pass in will fit into
328*b843c749SSergey Zigachev 		 *       the detiled buffer.
329*b843c749SSergey Zigachev 		 */
330*b843c749SSergey Zigachev 	} else {
331*b843c749SSergey Zigachev 		total_swath_bytes = 2 * full_swath_bytes_packed_l;
332*b843c749SSergey Zigachev 
333*b843c749SSergey Zigachev 		if (total_swath_bytes <= detile_buf_size_in_bytes)
334*b843c749SSergey Zigachev 			req128_l = 0;
335*b843c749SSergey Zigachev 		else
336*b843c749SSergey Zigachev 			req128_l = 1;
337*b843c749SSergey Zigachev 
338*b843c749SSergey Zigachev 		swath_bytes_l = total_swath_bytes;
339*b843c749SSergey Zigachev 		swath_bytes_c = 0;
340*b843c749SSergey Zigachev 	}
341*b843c749SSergey Zigachev 	rq_param->misc.rq_l.stored_swath_bytes = swath_bytes_l;
342*b843c749SSergey Zigachev 	rq_param->misc.rq_c.stored_swath_bytes = swath_bytes_c;
343*b843c749SSergey Zigachev 
344*b843c749SSergey Zigachev 	if (surf_linear) {
345*b843c749SSergey Zigachev 		log2_swath_height_l = 0;
346*b843c749SSergey Zigachev 		log2_swath_height_c = 0;
347*b843c749SSergey Zigachev 	} else if (!surf_vert) {
348*b843c749SSergey Zigachev 		log2_swath_height_l = dml_log2(rq_param->misc.rq_l.blk256_height) - req128_l;
349*b843c749SSergey Zigachev 		log2_swath_height_c = dml_log2(rq_param->misc.rq_c.blk256_height) - req128_c;
350*b843c749SSergey Zigachev 	} else {
351*b843c749SSergey Zigachev 		log2_swath_height_l = dml_log2(rq_param->misc.rq_l.blk256_width) - req128_l;
352*b843c749SSergey Zigachev 		log2_swath_height_c = dml_log2(rq_param->misc.rq_c.blk256_width) - req128_c;
353*b843c749SSergey Zigachev 	}
354*b843c749SSergey Zigachev 	rq_param->dlg.rq_l.swath_height = 1 << log2_swath_height_l;
355*b843c749SSergey Zigachev 	rq_param->dlg.rq_c.swath_height = 1 << log2_swath_height_c;
356*b843c749SSergey Zigachev 
357*b843c749SSergey Zigachev 	DTRACE("DLG: %s: req128_l = %0d", __func__, req128_l);
358*b843c749SSergey Zigachev 	DTRACE("DLG: %s: req128_c = %0d", __func__, req128_c);
359*b843c749SSergey Zigachev 	DTRACE("DLG: %s: full_swath_bytes_packed_l = %0d", __func__, full_swath_bytes_packed_l);
360*b843c749SSergey Zigachev 	DTRACE("DLG: %s: full_swath_bytes_packed_c = %0d", __func__, full_swath_bytes_packed_c);
361*b843c749SSergey Zigachev }
362*b843c749SSergey Zigachev 
363*b843c749SSergey Zigachev /* Need refactor. */
dml1_rq_dlg_get_row_heights(struct display_mode_lib * mode_lib,unsigned int * o_dpte_row_height,unsigned int * o_meta_row_height,unsigned int vp_width,unsigned int data_pitch,int source_format,int tiling,int macro_tile_size,int source_scan,int is_chroma)364*b843c749SSergey Zigachev static void dml1_rq_dlg_get_row_heights(
365*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
366*b843c749SSergey Zigachev 		unsigned int *o_dpte_row_height,
367*b843c749SSergey Zigachev 		unsigned int *o_meta_row_height,
368*b843c749SSergey Zigachev 		unsigned int vp_width,
369*b843c749SSergey Zigachev 		unsigned int data_pitch,
370*b843c749SSergey Zigachev 		int source_format,
371*b843c749SSergey Zigachev 		int tiling,
372*b843c749SSergey Zigachev 		int macro_tile_size,
373*b843c749SSergey Zigachev 		int source_scan,
374*b843c749SSergey Zigachev 		int is_chroma)
375*b843c749SSergey Zigachev {
376*b843c749SSergey Zigachev 	bool surf_linear = (tiling == dm_sw_linear);
377*b843c749SSergey Zigachev 	bool surf_vert = (source_scan == dm_vert);
378*b843c749SSergey Zigachev 
379*b843c749SSergey Zigachev 	unsigned int bytes_per_element = get_bytes_per_element(
380*b843c749SSergey Zigachev 			(enum source_format_class) source_format,
381*b843c749SSergey Zigachev 			is_chroma);
382*b843c749SSergey Zigachev 	unsigned int log2_bytes_per_element = dml_log2(bytes_per_element);
383*b843c749SSergey Zigachev 	unsigned int blk256_width = 0;
384*b843c749SSergey Zigachev 	unsigned int blk256_height = 0;
385*b843c749SSergey Zigachev 
386*b843c749SSergey Zigachev 	unsigned int log2_blk256_height;
387*b843c749SSergey Zigachev 	unsigned int blk_bytes;
388*b843c749SSergey Zigachev 	unsigned int log2_blk_bytes;
389*b843c749SSergey Zigachev 	unsigned int log2_blk_height;
390*b843c749SSergey Zigachev 	unsigned int log2_blk_width;
391*b843c749SSergey Zigachev 	unsigned int log2_meta_req_bytes;
392*b843c749SSergey Zigachev 	unsigned int log2_meta_req_height;
393*b843c749SSergey Zigachev 	unsigned int log2_meta_req_width;
394*b843c749SSergey Zigachev 	unsigned int log2_meta_row_height;
395*b843c749SSergey Zigachev 	unsigned int log2_vmpg_bytes;
396*b843c749SSergey Zigachev 	unsigned int dpte_buf_in_pte_reqs;
397*b843c749SSergey Zigachev 	unsigned int log2_vmpg_height;
398*b843c749SSergey Zigachev 	unsigned int log2_vmpg_width;
399*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_height_ptes;
400*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_width_ptes;
401*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_height;
402*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_width;
403*b843c749SSergey Zigachev 	unsigned int log2_dpte_row_height_linear;
404*b843c749SSergey Zigachev 	unsigned int log2_dpte_row_height;
405*b843c749SSergey Zigachev 	unsigned int dpte_req_width;
406*b843c749SSergey Zigachev 
407*b843c749SSergey Zigachev 	if (surf_linear) {
408*b843c749SSergey Zigachev 		blk256_width = 256;
409*b843c749SSergey Zigachev 		blk256_height = 1;
410*b843c749SSergey Zigachev 	} else {
411*b843c749SSergey Zigachev 		get_blk256_size(&blk256_width, &blk256_height, bytes_per_element);
412*b843c749SSergey Zigachev 	}
413*b843c749SSergey Zigachev 
414*b843c749SSergey Zigachev 	log2_blk256_height = dml_log2((double) blk256_height);
415*b843c749SSergey Zigachev 	blk_bytes = surf_linear ?
416*b843c749SSergey Zigachev 			256 : get_blk_size_bytes((enum source_macro_tile_size) macro_tile_size);
417*b843c749SSergey Zigachev 	log2_blk_bytes = dml_log2((double) blk_bytes);
418*b843c749SSergey Zigachev 	log2_blk_height = 0;
419*b843c749SSergey Zigachev 	log2_blk_width = 0;
420*b843c749SSergey Zigachev 
421*b843c749SSergey Zigachev 	/* remember log rule
422*b843c749SSergey Zigachev 	 * "+" in log is multiply
423*b843c749SSergey Zigachev 	 * "-" in log is divide
424*b843c749SSergey Zigachev 	 * "/2" is like square root
425*b843c749SSergey Zigachev 	 * blk is vertical biased
426*b843c749SSergey Zigachev 	 */
427*b843c749SSergey Zigachev 	if (tiling != dm_sw_linear)
428*b843c749SSergey Zigachev 		log2_blk_height = log2_blk256_height
429*b843c749SSergey Zigachev 				+ dml_ceil((double) (log2_blk_bytes - 8) / 2.0, 1);
430*b843c749SSergey Zigachev 	else
431*b843c749SSergey Zigachev 		log2_blk_height = 0; /* blk height of 1 */
432*b843c749SSergey Zigachev 
433*b843c749SSergey Zigachev 	log2_blk_width = log2_blk_bytes - log2_bytes_per_element - log2_blk_height;
434*b843c749SSergey Zigachev 
435*b843c749SSergey Zigachev 	/* ------- */
436*b843c749SSergey Zigachev 	/* meta    */
437*b843c749SSergey Zigachev 	/* ------- */
438*b843c749SSergey Zigachev 	log2_meta_req_bytes = 6; /* meta request is 64b and is 8x8byte meta element */
439*b843c749SSergey Zigachev 
440*b843c749SSergey Zigachev 	/* each 64b meta request for dcn is 8x8 meta elements and
441*b843c749SSergey Zigachev 	 * a meta element covers one 256b block of the the data surface.
442*b843c749SSergey Zigachev 	 */
443*b843c749SSergey Zigachev 	log2_meta_req_height = log2_blk256_height + 3; /* meta req is 8x8 */
444*b843c749SSergey Zigachev 	log2_meta_req_width = log2_meta_req_bytes + 8 - log2_bytes_per_element
445*b843c749SSergey Zigachev 			- log2_meta_req_height;
446*b843c749SSergey Zigachev 	log2_meta_row_height = 0;
447*b843c749SSergey Zigachev 
448*b843c749SSergey Zigachev 	/* the dimensions of a meta row are meta_row_width x meta_row_height in elements.
449*b843c749SSergey Zigachev 	 * calculate upper bound of the meta_row_width
450*b843c749SSergey Zigachev 	 */
451*b843c749SSergey Zigachev 	if (!surf_vert)
452*b843c749SSergey Zigachev 		log2_meta_row_height = log2_meta_req_height;
453*b843c749SSergey Zigachev 	else
454*b843c749SSergey Zigachev 		log2_meta_row_height = log2_meta_req_width;
455*b843c749SSergey Zigachev 
456*b843c749SSergey Zigachev 	*o_meta_row_height = 1 << log2_meta_row_height;
457*b843c749SSergey Zigachev 
458*b843c749SSergey Zigachev 	/* ------ */
459*b843c749SSergey Zigachev 	/* dpte   */
460*b843c749SSergey Zigachev 	/* ------ */
461*b843c749SSergey Zigachev 	log2_vmpg_bytes = dml_log2(mode_lib->soc.vmm_page_size_bytes);
462*b843c749SSergey Zigachev 	dpte_buf_in_pte_reqs = mode_lib->ip.dpte_buffer_size_in_pte_reqs;
463*b843c749SSergey Zigachev 
464*b843c749SSergey Zigachev 	log2_vmpg_height = 0;
465*b843c749SSergey Zigachev 	log2_vmpg_width = 0;
466*b843c749SSergey Zigachev 	log2_dpte_req_height_ptes = 0;
467*b843c749SSergey Zigachev 	log2_dpte_req_width_ptes = 0;
468*b843c749SSergey Zigachev 	log2_dpte_req_height = 0;
469*b843c749SSergey Zigachev 	log2_dpte_req_width = 0;
470*b843c749SSergey Zigachev 	log2_dpte_row_height_linear = 0;
471*b843c749SSergey Zigachev 	log2_dpte_row_height = 0;
472*b843c749SSergey Zigachev 	dpte_req_width = 0; /* 64b dpte req width in data element */
473*b843c749SSergey Zigachev 
474*b843c749SSergey Zigachev 	if (surf_linear)
475*b843c749SSergey Zigachev 		log2_vmpg_height = 0; /* one line high */
476*b843c749SSergey Zigachev 	else
477*b843c749SSergey Zigachev 		log2_vmpg_height = (log2_vmpg_bytes - 8) / 2 + log2_blk256_height;
478*b843c749SSergey Zigachev 	log2_vmpg_width = log2_vmpg_bytes - log2_bytes_per_element - log2_vmpg_height;
479*b843c749SSergey Zigachev 
480*b843c749SSergey Zigachev 	/* only 3 possible shapes for dpte request in dimensions of ptes: 8x1, 4x2, 2x4. */
481*b843c749SSergey Zigachev 	if (log2_blk_bytes <= log2_vmpg_bytes)
482*b843c749SSergey Zigachev 		log2_dpte_req_height_ptes = 0;
483*b843c749SSergey Zigachev 	else if (log2_blk_height - log2_vmpg_height >= 2)
484*b843c749SSergey Zigachev 		log2_dpte_req_height_ptes = 2;
485*b843c749SSergey Zigachev 	else
486*b843c749SSergey Zigachev 		log2_dpte_req_height_ptes = log2_blk_height - log2_vmpg_height;
487*b843c749SSergey Zigachev 	log2_dpte_req_width_ptes = 3 - log2_dpte_req_height_ptes;
488*b843c749SSergey Zigachev 
489*b843c749SSergey Zigachev 	ASSERT((log2_dpte_req_width_ptes == 3 && log2_dpte_req_height_ptes == 0) || /* 8x1 */
490*b843c749SSergey Zigachev 			(log2_dpte_req_width_ptes == 2 && log2_dpte_req_height_ptes == 1) || /* 4x2 */
491*b843c749SSergey Zigachev 			(log2_dpte_req_width_ptes == 1 && log2_dpte_req_height_ptes == 2)); /* 2x4 */
492*b843c749SSergey Zigachev 
493*b843c749SSergey Zigachev 	/* the dpte request dimensions in data elements is dpte_req_width x dpte_req_height
494*b843c749SSergey Zigachev 	 * log2_wmpg_width is how much 1 pte represent, now trying to calculate how much 64b pte req represent
495*b843c749SSergey Zigachev 	 */
496*b843c749SSergey Zigachev 	log2_dpte_req_height = log2_vmpg_height + log2_dpte_req_height_ptes;
497*b843c749SSergey Zigachev 	log2_dpte_req_width = log2_vmpg_width + log2_dpte_req_width_ptes;
498*b843c749SSergey Zigachev 	dpte_req_width = 1 << log2_dpte_req_width;
499*b843c749SSergey Zigachev 
500*b843c749SSergey Zigachev 	/* calculate pitch dpte row buffer can hold
501*b843c749SSergey Zigachev 	 * round the result down to a power of two.
502*b843c749SSergey Zigachev 	 */
503*b843c749SSergey Zigachev 	if (surf_linear) {
504*b843c749SSergey Zigachev 		log2_dpte_row_height_linear = dml_floor(
505*b843c749SSergey Zigachev 				dml_log2(dpte_buf_in_pte_reqs * dpte_req_width / data_pitch),
506*b843c749SSergey Zigachev 				1);
507*b843c749SSergey Zigachev 
508*b843c749SSergey Zigachev 		ASSERT(log2_dpte_row_height_linear >= 3);
509*b843c749SSergey Zigachev 
510*b843c749SSergey Zigachev 		if (log2_dpte_row_height_linear > 7)
511*b843c749SSergey Zigachev 			log2_dpte_row_height_linear = 7;
512*b843c749SSergey Zigachev 
513*b843c749SSergey Zigachev 		log2_dpte_row_height = log2_dpte_row_height_linear;
514*b843c749SSergey Zigachev 	} else {
515*b843c749SSergey Zigachev 		/* the upper bound of the dpte_row_width without dependency on viewport position follows.  */
516*b843c749SSergey Zigachev 		if (!surf_vert)
517*b843c749SSergey Zigachev 			log2_dpte_row_height = log2_dpte_req_height;
518*b843c749SSergey Zigachev 		else
519*b843c749SSergey Zigachev 			log2_dpte_row_height =
520*b843c749SSergey Zigachev 					(log2_blk_width < log2_dpte_req_width) ?
521*b843c749SSergey Zigachev 							log2_blk_width : log2_dpte_req_width;
522*b843c749SSergey Zigachev 	}
523*b843c749SSergey Zigachev 
524*b843c749SSergey Zigachev 	/* From programming guide:
525*b843c749SSergey Zigachev 	 * There is a special case of saving only half of ptes returned due to buffer space limits.
526*b843c749SSergey Zigachev 	 * this case applies to 4 and 8bpe in horizontal access of a vp_width greater than 2560+16
527*b843c749SSergey Zigachev 	 * when the pte request is 2x4 ptes (which happens when vmpg_bytes =4kb and tile blk_bytes >=64kb).
528*b843c749SSergey Zigachev 	 */
529*b843c749SSergey Zigachev 	if (!surf_vert && vp_width > (2560 + 16) && bytes_per_element >= 4 && log2_vmpg_bytes == 12
530*b843c749SSergey Zigachev 			&& log2_blk_bytes >= 16)
531*b843c749SSergey Zigachev 		log2_dpte_row_height = log2_dpte_row_height - 1; /*half of the full height */
532*b843c749SSergey Zigachev 
533*b843c749SSergey Zigachev 	*o_dpte_row_height = 1 << log2_dpte_row_height;
534*b843c749SSergey Zigachev }
535*b843c749SSergey Zigachev 
get_surf_rq_param(struct display_mode_lib * mode_lib,struct _vcs_dpi_display_data_rq_sizing_params_st * rq_sizing_param,struct _vcs_dpi_display_data_rq_dlg_params_st * rq_dlg_param,struct _vcs_dpi_display_data_rq_misc_params_st * rq_misc_param,const struct _vcs_dpi_display_pipe_source_params_st pipe_src_param,bool is_chroma)536*b843c749SSergey Zigachev static void get_surf_rq_param(
537*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
538*b843c749SSergey Zigachev 		struct _vcs_dpi_display_data_rq_sizing_params_st *rq_sizing_param,
539*b843c749SSergey Zigachev 		struct _vcs_dpi_display_data_rq_dlg_params_st *rq_dlg_param,
540*b843c749SSergey Zigachev 		struct _vcs_dpi_display_data_rq_misc_params_st *rq_misc_param,
541*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_pipe_source_params_st pipe_src_param,
542*b843c749SSergey Zigachev 		bool is_chroma)
543*b843c749SSergey Zigachev {
544*b843c749SSergey Zigachev 	bool mode_422 = 0;
545*b843c749SSergey Zigachev 	unsigned int vp_width = 0;
546*b843c749SSergey Zigachev 	unsigned int vp_height = 0;
547*b843c749SSergey Zigachev 	unsigned int data_pitch = 0;
548*b843c749SSergey Zigachev 	unsigned int meta_pitch = 0;
549*b843c749SSergey Zigachev 	unsigned int ppe = mode_422 ? 2 : 1;
550*b843c749SSergey Zigachev 	bool surf_linear;
551*b843c749SSergey Zigachev 	bool surf_vert;
552*b843c749SSergey Zigachev 	unsigned int bytes_per_element;
553*b843c749SSergey Zigachev 	unsigned int log2_bytes_per_element;
554*b843c749SSergey Zigachev 	unsigned int blk256_width;
555*b843c749SSergey Zigachev 	unsigned int blk256_height;
556*b843c749SSergey Zigachev 	unsigned int log2_blk256_width;
557*b843c749SSergey Zigachev 	unsigned int log2_blk256_height;
558*b843c749SSergey Zigachev 	unsigned int blk_bytes;
559*b843c749SSergey Zigachev 	unsigned int log2_blk_bytes;
560*b843c749SSergey Zigachev 	unsigned int log2_blk_height;
561*b843c749SSergey Zigachev 	unsigned int log2_blk_width;
562*b843c749SSergey Zigachev 	unsigned int log2_meta_req_bytes;
563*b843c749SSergey Zigachev 	unsigned int log2_meta_req_height;
564*b843c749SSergey Zigachev 	unsigned int log2_meta_req_width;
565*b843c749SSergey Zigachev 	unsigned int meta_req_width;
566*b843c749SSergey Zigachev 	unsigned int meta_req_height;
567*b843c749SSergey Zigachev 	unsigned int log2_meta_row_height;
568*b843c749SSergey Zigachev 	unsigned int meta_row_width_ub;
569*b843c749SSergey Zigachev 	unsigned int log2_meta_chunk_bytes;
570*b843c749SSergey Zigachev 	unsigned int log2_meta_chunk_height;
571*b843c749SSergey Zigachev 	unsigned int log2_meta_chunk_width;
572*b843c749SSergey Zigachev 	unsigned int log2_min_meta_chunk_bytes;
573*b843c749SSergey Zigachev 	unsigned int min_meta_chunk_width;
574*b843c749SSergey Zigachev 	unsigned int meta_chunk_width;
575*b843c749SSergey Zigachev 	unsigned int meta_chunk_per_row_int;
576*b843c749SSergey Zigachev 	unsigned int meta_row_remainder;
577*b843c749SSergey Zigachev 	unsigned int meta_chunk_threshold;
578*b843c749SSergey Zigachev 	unsigned int meta_blk_bytes;
579*b843c749SSergey Zigachev 	unsigned int meta_blk_height;
580*b843c749SSergey Zigachev 	unsigned int meta_blk_width;
581*b843c749SSergey Zigachev 	unsigned int meta_surface_bytes;
582*b843c749SSergey Zigachev 	unsigned int vmpg_bytes;
583*b843c749SSergey Zigachev 	unsigned int meta_pte_req_per_frame_ub;
584*b843c749SSergey Zigachev 	unsigned int meta_pte_bytes_per_frame_ub;
585*b843c749SSergey Zigachev 	unsigned int log2_vmpg_bytes;
586*b843c749SSergey Zigachev 	unsigned int dpte_buf_in_pte_reqs;
587*b843c749SSergey Zigachev 	unsigned int log2_vmpg_height;
588*b843c749SSergey Zigachev 	unsigned int log2_vmpg_width;
589*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_height_ptes;
590*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_width_ptes;
591*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_height;
592*b843c749SSergey Zigachev 	unsigned int log2_dpte_req_width;
593*b843c749SSergey Zigachev 	unsigned int log2_dpte_row_height_linear;
594*b843c749SSergey Zigachev 	unsigned int log2_dpte_row_height;
595*b843c749SSergey Zigachev 	unsigned int log2_dpte_group_width;
596*b843c749SSergey Zigachev 	unsigned int dpte_row_width_ub;
597*b843c749SSergey Zigachev 	unsigned int dpte_row_height;
598*b843c749SSergey Zigachev 	unsigned int dpte_req_height;
599*b843c749SSergey Zigachev 	unsigned int dpte_req_width;
600*b843c749SSergey Zigachev 	unsigned int dpte_group_width;
601*b843c749SSergey Zigachev 	unsigned int log2_dpte_group_bytes;
602*b843c749SSergey Zigachev 	unsigned int log2_dpte_group_length;
603*b843c749SSergey Zigachev 	unsigned int func_meta_row_height, func_dpte_row_height;
604*b843c749SSergey Zigachev 
605*b843c749SSergey Zigachev 	/* FIXME check if ppe apply for both luma and chroma in 422 case */
606*b843c749SSergey Zigachev 	if (is_chroma) {
607*b843c749SSergey Zigachev 		vp_width = pipe_src_param.viewport_width_c / ppe;
608*b843c749SSergey Zigachev 		vp_height = pipe_src_param.viewport_height_c;
609*b843c749SSergey Zigachev 		data_pitch = pipe_src_param.data_pitch_c;
610*b843c749SSergey Zigachev 		meta_pitch = pipe_src_param.meta_pitch_c;
611*b843c749SSergey Zigachev 	} else {
612*b843c749SSergey Zigachev 		vp_width = pipe_src_param.viewport_width / ppe;
613*b843c749SSergey Zigachev 		vp_height = pipe_src_param.viewport_height;
614*b843c749SSergey Zigachev 		data_pitch = pipe_src_param.data_pitch;
615*b843c749SSergey Zigachev 		meta_pitch = pipe_src_param.meta_pitch;
616*b843c749SSergey Zigachev 	}
617*b843c749SSergey Zigachev 
618*b843c749SSergey Zigachev 	rq_sizing_param->chunk_bytes = 8192;
619*b843c749SSergey Zigachev 
620*b843c749SSergey Zigachev 	if (rq_sizing_param->chunk_bytes == 64 * 1024)
621*b843c749SSergey Zigachev 		rq_sizing_param->min_chunk_bytes = 0;
622*b843c749SSergey Zigachev 	else
623*b843c749SSergey Zigachev 		rq_sizing_param->min_chunk_bytes = 1024;
624*b843c749SSergey Zigachev 
625*b843c749SSergey Zigachev 	rq_sizing_param->meta_chunk_bytes = 2048;
626*b843c749SSergey Zigachev 	rq_sizing_param->min_meta_chunk_bytes = 256;
627*b843c749SSergey Zigachev 
628*b843c749SSergey Zigachev 	rq_sizing_param->mpte_group_bytes = 2048;
629*b843c749SSergey Zigachev 
630*b843c749SSergey Zigachev 	surf_linear = (pipe_src_param.sw_mode == dm_sw_linear);
631*b843c749SSergey Zigachev 	surf_vert = (pipe_src_param.source_scan == dm_vert);
632*b843c749SSergey Zigachev 
633*b843c749SSergey Zigachev 	bytes_per_element = get_bytes_per_element(
634*b843c749SSergey Zigachev 			(enum source_format_class) pipe_src_param.source_format,
635*b843c749SSergey Zigachev 			is_chroma);
636*b843c749SSergey Zigachev 	log2_bytes_per_element = dml_log2(bytes_per_element);
637*b843c749SSergey Zigachev 	blk256_width = 0;
638*b843c749SSergey Zigachev 	blk256_height = 0;
639*b843c749SSergey Zigachev 
640*b843c749SSergey Zigachev 	if (surf_linear) {
641*b843c749SSergey Zigachev 		blk256_width = 256 / bytes_per_element;
642*b843c749SSergey Zigachev 		blk256_height = 1;
643*b843c749SSergey Zigachev 	} else {
644*b843c749SSergey Zigachev 		get_blk256_size(&blk256_width, &blk256_height, bytes_per_element);
645*b843c749SSergey Zigachev 	}
646*b843c749SSergey Zigachev 
647*b843c749SSergey Zigachev 	DTRACE("DLG: %s: surf_linear        = %d", __func__, surf_linear);
648*b843c749SSergey Zigachev 	DTRACE("DLG: %s: surf_vert          = %d", __func__, surf_vert);
649*b843c749SSergey Zigachev 	DTRACE("DLG: %s: blk256_width       = %d", __func__, blk256_width);
650*b843c749SSergey Zigachev 	DTRACE("DLG: %s: blk256_height      = %d", __func__, blk256_height);
651*b843c749SSergey Zigachev 
652*b843c749SSergey Zigachev 	log2_blk256_width = dml_log2((double) blk256_width);
653*b843c749SSergey Zigachev 	log2_blk256_height = dml_log2((double) blk256_height);
654*b843c749SSergey Zigachev 	blk_bytes =
655*b843c749SSergey Zigachev 			surf_linear ? 256 : get_blk_size_bytes(
656*b843c749SSergey Zigachev 							(enum source_macro_tile_size) pipe_src_param.macro_tile_size);
657*b843c749SSergey Zigachev 	log2_blk_bytes = dml_log2((double) blk_bytes);
658*b843c749SSergey Zigachev 	log2_blk_height = 0;
659*b843c749SSergey Zigachev 	log2_blk_width = 0;
660*b843c749SSergey Zigachev 
661*b843c749SSergey Zigachev 	/* remember log rule
662*b843c749SSergey Zigachev 	 * "+" in log is multiply
663*b843c749SSergey Zigachev 	 * "-" in log is divide
664*b843c749SSergey Zigachev 	 * "/2" is like square root
665*b843c749SSergey Zigachev 	 * blk is vertical biased
666*b843c749SSergey Zigachev 	 */
667*b843c749SSergey Zigachev 	if (pipe_src_param.sw_mode != dm_sw_linear)
668*b843c749SSergey Zigachev 		log2_blk_height = log2_blk256_height
669*b843c749SSergey Zigachev 				+ dml_ceil((double) (log2_blk_bytes - 8) / 2.0, 1);
670*b843c749SSergey Zigachev 	else
671*b843c749SSergey Zigachev 		log2_blk_height = 0; /* blk height of 1 */
672*b843c749SSergey Zigachev 
673*b843c749SSergey Zigachev 	log2_blk_width = log2_blk_bytes - log2_bytes_per_element - log2_blk_height;
674*b843c749SSergey Zigachev 
675*b843c749SSergey Zigachev 	if (!surf_vert) {
676*b843c749SSergey Zigachev 		rq_dlg_param->swath_width_ub = dml_round_to_multiple(vp_width - 1, blk256_width, 1)
677*b843c749SSergey Zigachev 				+ blk256_width;
678*b843c749SSergey Zigachev 		rq_dlg_param->req_per_swath_ub = rq_dlg_param->swath_width_ub >> log2_blk256_width;
679*b843c749SSergey Zigachev 	} else {
680*b843c749SSergey Zigachev 		rq_dlg_param->swath_width_ub = dml_round_to_multiple(
681*b843c749SSergey Zigachev 				vp_height - 1,
682*b843c749SSergey Zigachev 				blk256_height,
683*b843c749SSergey Zigachev 				1) + blk256_height;
684*b843c749SSergey Zigachev 		rq_dlg_param->req_per_swath_ub = rq_dlg_param->swath_width_ub >> log2_blk256_height;
685*b843c749SSergey Zigachev 	}
686*b843c749SSergey Zigachev 
687*b843c749SSergey Zigachev 	if (!surf_vert)
688*b843c749SSergey Zigachev 		rq_misc_param->full_swath_bytes = rq_dlg_param->swath_width_ub * blk256_height
689*b843c749SSergey Zigachev 				* bytes_per_element;
690*b843c749SSergey Zigachev 	else
691*b843c749SSergey Zigachev 		rq_misc_param->full_swath_bytes = rq_dlg_param->swath_width_ub * blk256_width
692*b843c749SSergey Zigachev 				* bytes_per_element;
693*b843c749SSergey Zigachev 
694*b843c749SSergey Zigachev 	rq_misc_param->blk256_height = blk256_height;
695*b843c749SSergey Zigachev 	rq_misc_param->blk256_width = blk256_width;
696*b843c749SSergey Zigachev 
697*b843c749SSergey Zigachev 	/* -------  */
698*b843c749SSergey Zigachev 	/* meta     */
699*b843c749SSergey Zigachev 	/* -------  */
700*b843c749SSergey Zigachev 	log2_meta_req_bytes = 6; /* meta request is 64b and is 8x8byte meta element */
701*b843c749SSergey Zigachev 
702*b843c749SSergey Zigachev 	/* each 64b meta request for dcn is 8x8 meta elements and
703*b843c749SSergey Zigachev 	 * a meta element covers one 256b block of the the data surface.
704*b843c749SSergey Zigachev 	 */
705*b843c749SSergey Zigachev 	log2_meta_req_height = log2_blk256_height + 3; /* meta req is 8x8 byte, each byte represent 1 blk256 */
706*b843c749SSergey Zigachev 	log2_meta_req_width = log2_meta_req_bytes + 8 - log2_bytes_per_element
707*b843c749SSergey Zigachev 			- log2_meta_req_height;
708*b843c749SSergey Zigachev 	meta_req_width = 1 << log2_meta_req_width;
709*b843c749SSergey Zigachev 	meta_req_height = 1 << log2_meta_req_height;
710*b843c749SSergey Zigachev 	log2_meta_row_height = 0;
711*b843c749SSergey Zigachev 	meta_row_width_ub = 0;
712*b843c749SSergey Zigachev 
713*b843c749SSergey Zigachev 	/* the dimensions of a meta row are meta_row_width x meta_row_height in elements.
714*b843c749SSergey Zigachev 	 * calculate upper bound of the meta_row_width
715*b843c749SSergey Zigachev 	 */
716*b843c749SSergey Zigachev 	if (!surf_vert) {
717*b843c749SSergey Zigachev 		log2_meta_row_height = log2_meta_req_height;
718*b843c749SSergey Zigachev 		meta_row_width_ub = dml_round_to_multiple(vp_width - 1, meta_req_width, 1)
719*b843c749SSergey Zigachev 				+ meta_req_width;
720*b843c749SSergey Zigachev 		rq_dlg_param->meta_req_per_row_ub = meta_row_width_ub / meta_req_width;
721*b843c749SSergey Zigachev 	} else {
722*b843c749SSergey Zigachev 		log2_meta_row_height = log2_meta_req_width;
723*b843c749SSergey Zigachev 		meta_row_width_ub = dml_round_to_multiple(vp_height - 1, meta_req_height, 1)
724*b843c749SSergey Zigachev 				+ meta_req_height;
725*b843c749SSergey Zigachev 		rq_dlg_param->meta_req_per_row_ub = meta_row_width_ub / meta_req_height;
726*b843c749SSergey Zigachev 	}
727*b843c749SSergey Zigachev 	rq_dlg_param->meta_bytes_per_row_ub = rq_dlg_param->meta_req_per_row_ub * 64;
728*b843c749SSergey Zigachev 
729*b843c749SSergey Zigachev 	log2_meta_chunk_bytes = dml_log2(rq_sizing_param->meta_chunk_bytes);
730*b843c749SSergey Zigachev 	log2_meta_chunk_height = log2_meta_row_height;
731*b843c749SSergey Zigachev 
732*b843c749SSergey Zigachev 	/*full sized meta chunk width in unit of data elements */
733*b843c749SSergey Zigachev 	log2_meta_chunk_width = log2_meta_chunk_bytes + 8 - log2_bytes_per_element
734*b843c749SSergey Zigachev 			- log2_meta_chunk_height;
735*b843c749SSergey Zigachev 	log2_min_meta_chunk_bytes = dml_log2(rq_sizing_param->min_meta_chunk_bytes);
736*b843c749SSergey Zigachev 	min_meta_chunk_width = 1
737*b843c749SSergey Zigachev 			<< (log2_min_meta_chunk_bytes + 8 - log2_bytes_per_element
738*b843c749SSergey Zigachev 					- log2_meta_chunk_height);
739*b843c749SSergey Zigachev 	meta_chunk_width = 1 << log2_meta_chunk_width;
740*b843c749SSergey Zigachev 	meta_chunk_per_row_int = (unsigned int) (meta_row_width_ub / meta_chunk_width);
741*b843c749SSergey Zigachev 	meta_row_remainder = meta_row_width_ub % meta_chunk_width;
742*b843c749SSergey Zigachev 	meta_chunk_threshold = 0;
743*b843c749SSergey Zigachev 	meta_blk_bytes = 4096;
744*b843c749SSergey Zigachev 	meta_blk_height = blk256_height * 64;
745*b843c749SSergey Zigachev 	meta_blk_width = meta_blk_bytes * 256 / bytes_per_element / meta_blk_height;
746*b843c749SSergey Zigachev 	meta_surface_bytes = meta_pitch
747*b843c749SSergey Zigachev 			* (dml_round_to_multiple(vp_height - 1, meta_blk_height, 1)
748*b843c749SSergey Zigachev 					+ meta_blk_height) * bytes_per_element / 256;
749*b843c749SSergey Zigachev 	vmpg_bytes = mode_lib->soc.vmm_page_size_bytes;
750*b843c749SSergey Zigachev 	meta_pte_req_per_frame_ub = (dml_round_to_multiple(
751*b843c749SSergey Zigachev 			meta_surface_bytes - vmpg_bytes,
752*b843c749SSergey Zigachev 			8 * vmpg_bytes,
753*b843c749SSergey Zigachev 			1) + 8 * vmpg_bytes) / (8 * vmpg_bytes);
754*b843c749SSergey Zigachev 	meta_pte_bytes_per_frame_ub = meta_pte_req_per_frame_ub * 64; /*64B mpte request */
755*b843c749SSergey Zigachev 	rq_dlg_param->meta_pte_bytes_per_frame_ub = meta_pte_bytes_per_frame_ub;
756*b843c749SSergey Zigachev 
757*b843c749SSergey Zigachev 	DTRACE("DLG: %s: meta_blk_height             = %d", __func__, meta_blk_height);
758*b843c749SSergey Zigachev 	DTRACE("DLG: %s: meta_blk_width              = %d", __func__, meta_blk_width);
759*b843c749SSergey Zigachev 	DTRACE("DLG: %s: meta_surface_bytes          = %d", __func__, meta_surface_bytes);
760*b843c749SSergey Zigachev 	DTRACE("DLG: %s: meta_pte_req_per_frame_ub   = %d", __func__, meta_pte_req_per_frame_ub);
761*b843c749SSergey Zigachev 	DTRACE("DLG: %s: meta_pte_bytes_per_frame_ub = %d", __func__, meta_pte_bytes_per_frame_ub);
762*b843c749SSergey Zigachev 
763*b843c749SSergey Zigachev 	if (!surf_vert)
764*b843c749SSergey Zigachev 		meta_chunk_threshold = 2 * min_meta_chunk_width - meta_req_width;
765*b843c749SSergey Zigachev 	else
766*b843c749SSergey Zigachev 		meta_chunk_threshold = 2 * min_meta_chunk_width - meta_req_height;
767*b843c749SSergey Zigachev 
768*b843c749SSergey Zigachev 	if (meta_row_remainder <= meta_chunk_threshold)
769*b843c749SSergey Zigachev 		rq_dlg_param->meta_chunks_per_row_ub = meta_chunk_per_row_int + 1;
770*b843c749SSergey Zigachev 	else
771*b843c749SSergey Zigachev 		rq_dlg_param->meta_chunks_per_row_ub = meta_chunk_per_row_int + 2;
772*b843c749SSergey Zigachev 
773*b843c749SSergey Zigachev 	rq_dlg_param->meta_row_height = 1 << log2_meta_row_height;
774*b843c749SSergey Zigachev 
775*b843c749SSergey Zigachev 	/* ------ */
776*b843c749SSergey Zigachev 	/* dpte   */
777*b843c749SSergey Zigachev 	/* ------ */
778*b843c749SSergey Zigachev 	log2_vmpg_bytes = dml_log2(mode_lib->soc.vmm_page_size_bytes);
779*b843c749SSergey Zigachev 	dpte_buf_in_pte_reqs = mode_lib->ip.dpte_buffer_size_in_pte_reqs;
780*b843c749SSergey Zigachev 
781*b843c749SSergey Zigachev 	log2_vmpg_height = 0;
782*b843c749SSergey Zigachev 	log2_vmpg_width = 0;
783*b843c749SSergey Zigachev 	log2_dpte_req_height_ptes = 0;
784*b843c749SSergey Zigachev 	log2_dpte_req_width_ptes = 0;
785*b843c749SSergey Zigachev 	log2_dpte_req_height = 0;
786*b843c749SSergey Zigachev 	log2_dpte_req_width = 0;
787*b843c749SSergey Zigachev 	log2_dpte_row_height_linear = 0;
788*b843c749SSergey Zigachev 	log2_dpte_row_height = 0;
789*b843c749SSergey Zigachev 	log2_dpte_group_width = 0;
790*b843c749SSergey Zigachev 	dpte_row_width_ub = 0;
791*b843c749SSergey Zigachev 	dpte_row_height = 0;
792*b843c749SSergey Zigachev 	dpte_req_height = 0; /* 64b dpte req height in data element */
793*b843c749SSergey Zigachev 	dpte_req_width = 0; /* 64b dpte req width in data element */
794*b843c749SSergey Zigachev 	dpte_group_width = 0;
795*b843c749SSergey Zigachev 	log2_dpte_group_bytes = 0;
796*b843c749SSergey Zigachev 	log2_dpte_group_length = 0;
797*b843c749SSergey Zigachev 
798*b843c749SSergey Zigachev 	if (surf_linear)
799*b843c749SSergey Zigachev 		log2_vmpg_height = 0; /* one line high */
800*b843c749SSergey Zigachev 	else
801*b843c749SSergey Zigachev 		log2_vmpg_height = (log2_vmpg_bytes - 8) / 2 + log2_blk256_height;
802*b843c749SSergey Zigachev 	log2_vmpg_width = log2_vmpg_bytes - log2_bytes_per_element - log2_vmpg_height;
803*b843c749SSergey Zigachev 
804*b843c749SSergey Zigachev 	/* only 3 possible shapes for dpte request in dimensions of ptes: 8x1, 4x2, 2x4. */
805*b843c749SSergey Zigachev 	if (log2_blk_bytes <= log2_vmpg_bytes)
806*b843c749SSergey Zigachev 		log2_dpte_req_height_ptes = 0;
807*b843c749SSergey Zigachev 	else if (log2_blk_height - log2_vmpg_height >= 2)
808*b843c749SSergey Zigachev 		log2_dpte_req_height_ptes = 2;
809*b843c749SSergey Zigachev 	else
810*b843c749SSergey Zigachev 		log2_dpte_req_height_ptes = log2_blk_height - log2_vmpg_height;
811*b843c749SSergey Zigachev 	log2_dpte_req_width_ptes = 3 - log2_dpte_req_height_ptes;
812*b843c749SSergey Zigachev 
813*b843c749SSergey Zigachev 	/* Ensure we only have the 3 shapes */
814*b843c749SSergey Zigachev 	ASSERT((log2_dpte_req_width_ptes == 3 && log2_dpte_req_height_ptes == 0) || /* 8x1 */
815*b843c749SSergey Zigachev 			(log2_dpte_req_width_ptes == 2 && log2_dpte_req_height_ptes == 1) || /* 4x2 */
816*b843c749SSergey Zigachev 			(log2_dpte_req_width_ptes == 1 && log2_dpte_req_height_ptes == 2)); /* 2x4 */
817*b843c749SSergey Zigachev 
818*b843c749SSergey Zigachev 	/* The dpte request dimensions in data elements is dpte_req_width x dpte_req_height
819*b843c749SSergey Zigachev 	 * log2_vmpg_width is how much 1 pte represent, now calculating how much a 64b pte req represent
820*b843c749SSergey Zigachev 	 * That depends on the pte shape (i.e. 8x1, 4x2, 2x4)
821*b843c749SSergey Zigachev 	 */
822*b843c749SSergey Zigachev 	log2_dpte_req_height = log2_vmpg_height + log2_dpte_req_height_ptes;
823*b843c749SSergey Zigachev 	log2_dpte_req_width = log2_vmpg_width + log2_dpte_req_width_ptes;
824*b843c749SSergey Zigachev 	dpte_req_height = 1 << log2_dpte_req_height;
825*b843c749SSergey Zigachev 	dpte_req_width = 1 << log2_dpte_req_width;
826*b843c749SSergey Zigachev 
827*b843c749SSergey Zigachev 	/* calculate pitch dpte row buffer can hold
828*b843c749SSergey Zigachev 	 * round the result down to a power of two.
829*b843c749SSergey Zigachev 	 */
830*b843c749SSergey Zigachev 	if (surf_linear) {
831*b843c749SSergey Zigachev 		log2_dpte_row_height_linear = dml_floor(
832*b843c749SSergey Zigachev 				dml_log2(dpte_buf_in_pte_reqs * dpte_req_width / data_pitch),
833*b843c749SSergey Zigachev 				1);
834*b843c749SSergey Zigachev 
835*b843c749SSergey Zigachev 		ASSERT(log2_dpte_row_height_linear >= 3);
836*b843c749SSergey Zigachev 
837*b843c749SSergey Zigachev 		if (log2_dpte_row_height_linear > 7)
838*b843c749SSergey Zigachev 			log2_dpte_row_height_linear = 7;
839*b843c749SSergey Zigachev 
840*b843c749SSergey Zigachev 		log2_dpte_row_height = log2_dpte_row_height_linear;
841*b843c749SSergey Zigachev 		rq_dlg_param->dpte_row_height = 1 << log2_dpte_row_height;
842*b843c749SSergey Zigachev 
843*b843c749SSergey Zigachev 		/* For linear, the dpte row is pitch dependent and the pte requests wrap at the pitch boundary.
844*b843c749SSergey Zigachev 		 * the dpte_row_width_ub is the upper bound of data_pitch*dpte_row_height in elements with this unique buffering.
845*b843c749SSergey Zigachev 		 */
846*b843c749SSergey Zigachev 		dpte_row_width_ub = dml_round_to_multiple(
847*b843c749SSergey Zigachev 				data_pitch * dpte_row_height - 1,
848*b843c749SSergey Zigachev 				dpte_req_width,
849*b843c749SSergey Zigachev 				1) + dpte_req_width;
850*b843c749SSergey Zigachev 		rq_dlg_param->dpte_req_per_row_ub = dpte_row_width_ub / dpte_req_width;
851*b843c749SSergey Zigachev 	} else {
852*b843c749SSergey Zigachev 		/* for tiled mode, row height is the same as req height and row store up to vp size upper bound */
853*b843c749SSergey Zigachev 		if (!surf_vert) {
854*b843c749SSergey Zigachev 			log2_dpte_row_height = log2_dpte_req_height;
855*b843c749SSergey Zigachev 			dpte_row_width_ub = dml_round_to_multiple(vp_width - 1, dpte_req_width, 1)
856*b843c749SSergey Zigachev 					+ dpte_req_width;
857*b843c749SSergey Zigachev 			rq_dlg_param->dpte_req_per_row_ub = dpte_row_width_ub / dpte_req_width;
858*b843c749SSergey Zigachev 		} else {
859*b843c749SSergey Zigachev 			log2_dpte_row_height =
860*b843c749SSergey Zigachev 					(log2_blk_width < log2_dpte_req_width) ?
861*b843c749SSergey Zigachev 							log2_blk_width : log2_dpte_req_width;
862*b843c749SSergey Zigachev 			dpte_row_width_ub = dml_round_to_multiple(vp_height - 1, dpte_req_height, 1)
863*b843c749SSergey Zigachev 					+ dpte_req_height;
864*b843c749SSergey Zigachev 			rq_dlg_param->dpte_req_per_row_ub = dpte_row_width_ub / dpte_req_height;
865*b843c749SSergey Zigachev 		}
866*b843c749SSergey Zigachev 		rq_dlg_param->dpte_row_height = 1 << log2_dpte_row_height;
867*b843c749SSergey Zigachev 	}
868*b843c749SSergey Zigachev 	rq_dlg_param->dpte_bytes_per_row_ub = rq_dlg_param->dpte_req_per_row_ub * 64;
869*b843c749SSergey Zigachev 
870*b843c749SSergey Zigachev 	/* From programming guide:
871*b843c749SSergey Zigachev 	 * There is a special case of saving only half of ptes returned due to buffer space limits.
872*b843c749SSergey Zigachev 	 * this case applies to 4 and 8bpe in horizontal access of a vp_width greater than 2560+16
873*b843c749SSergey Zigachev 	 * when the pte request is 2x4 ptes (which happens when vmpg_bytes =4kb and tile blk_bytes >=64kb).
874*b843c749SSergey Zigachev 	 */
875*b843c749SSergey Zigachev 	if (!surf_vert && vp_width > (2560 + 16) && bytes_per_element >= 4 && log2_vmpg_bytes == 12
876*b843c749SSergey Zigachev 			&& log2_blk_bytes >= 16) {
877*b843c749SSergey Zigachev 		log2_dpte_row_height = log2_dpte_row_height - 1; /*half of the full height */
878*b843c749SSergey Zigachev 		rq_dlg_param->dpte_row_height = 1 << log2_dpte_row_height;
879*b843c749SSergey Zigachev 	}
880*b843c749SSergey Zigachev 
881*b843c749SSergey Zigachev 	/* the dpte_group_bytes is reduced for the specific case of vertical
882*b843c749SSergey Zigachev 	 * access of a tile surface that has dpte request of 8x1 ptes.
883*b843c749SSergey Zigachev 	 */
884*b843c749SSergey Zigachev 	if (!surf_linear & (log2_dpte_req_height_ptes == 0) & surf_vert) /*reduced, in this case, will have page fault within a group */
885*b843c749SSergey Zigachev 		rq_sizing_param->dpte_group_bytes = 512;
886*b843c749SSergey Zigachev 	else
887*b843c749SSergey Zigachev 		/*full size */
888*b843c749SSergey Zigachev 		rq_sizing_param->dpte_group_bytes = 2048;
889*b843c749SSergey Zigachev 
890*b843c749SSergey Zigachev 	/*since pte request size is 64byte, the number of data pte requests per full sized group is as follows.  */
891*b843c749SSergey Zigachev 	log2_dpte_group_bytes = dml_log2(rq_sizing_param->dpte_group_bytes);
892*b843c749SSergey Zigachev 	log2_dpte_group_length = log2_dpte_group_bytes - 6; /*length in 64b requests  */
893*b843c749SSergey Zigachev 
894*b843c749SSergey Zigachev 	/* full sized data pte group width in elements */
895*b843c749SSergey Zigachev 	if (!surf_vert)
896*b843c749SSergey Zigachev 		log2_dpte_group_width = log2_dpte_group_length + log2_dpte_req_width;
897*b843c749SSergey Zigachev 	else
898*b843c749SSergey Zigachev 		log2_dpte_group_width = log2_dpte_group_length + log2_dpte_req_height;
899*b843c749SSergey Zigachev 
900*b843c749SSergey Zigachev 	dpte_group_width = 1 << log2_dpte_group_width;
901*b843c749SSergey Zigachev 
902*b843c749SSergey Zigachev 	/* since dpte groups are only aligned to dpte_req_width and not dpte_group_width,
903*b843c749SSergey Zigachev 	 * the upper bound for the dpte groups per row is as follows.
904*b843c749SSergey Zigachev 	 */
905*b843c749SSergey Zigachev 	rq_dlg_param->dpte_groups_per_row_ub = dml_ceil(
906*b843c749SSergey Zigachev 			(double) dpte_row_width_ub / dpte_group_width,
907*b843c749SSergey Zigachev 			1);
908*b843c749SSergey Zigachev 
909*b843c749SSergey Zigachev 	dml1_rq_dlg_get_row_heights(
910*b843c749SSergey Zigachev 			mode_lib,
911*b843c749SSergey Zigachev 			&func_dpte_row_height,
912*b843c749SSergey Zigachev 			&func_meta_row_height,
913*b843c749SSergey Zigachev 			vp_width,
914*b843c749SSergey Zigachev 			data_pitch,
915*b843c749SSergey Zigachev 			pipe_src_param.source_format,
916*b843c749SSergey Zigachev 			pipe_src_param.sw_mode,
917*b843c749SSergey Zigachev 			pipe_src_param.macro_tile_size,
918*b843c749SSergey Zigachev 			pipe_src_param.source_scan,
919*b843c749SSergey Zigachev 			is_chroma);
920*b843c749SSergey Zigachev 
921*b843c749SSergey Zigachev 	/* Just a check to make sure this function and the new one give the same
922*b843c749SSergey Zigachev 	 * result. The standalone get_row_heights() function is based off of the
923*b843c749SSergey Zigachev 	 * code in this function so the same changes need to be made to both.
924*b843c749SSergey Zigachev 	 */
925*b843c749SSergey Zigachev 	if (rq_dlg_param->meta_row_height != func_meta_row_height) {
926*b843c749SSergey Zigachev 		DTRACE(
927*b843c749SSergey Zigachev 				"MISMATCH: rq_dlg_param->meta_row_height = %d",
928*b843c749SSergey Zigachev 				rq_dlg_param->meta_row_height);
929*b843c749SSergey Zigachev 		DTRACE("MISMATCH: func_meta_row_height = %d", func_meta_row_height);
930*b843c749SSergey Zigachev 		ASSERT(0);
931*b843c749SSergey Zigachev 	}
932*b843c749SSergey Zigachev 
933*b843c749SSergey Zigachev 	if (rq_dlg_param->dpte_row_height != func_dpte_row_height) {
934*b843c749SSergey Zigachev 		DTRACE(
935*b843c749SSergey Zigachev 				"MISMATCH: rq_dlg_param->dpte_row_height = %d",
936*b843c749SSergey Zigachev 				rq_dlg_param->dpte_row_height);
937*b843c749SSergey Zigachev 		DTRACE("MISMATCH: func_dpte_row_height = %d", func_dpte_row_height);
938*b843c749SSergey Zigachev 		ASSERT(0);
939*b843c749SSergey Zigachev 	}
940*b843c749SSergey Zigachev }
941*b843c749SSergey Zigachev 
dml1_rq_dlg_get_rq_params(struct display_mode_lib * mode_lib,struct _vcs_dpi_display_rq_params_st * rq_param,const struct _vcs_dpi_display_pipe_source_params_st pipe_src_param)942*b843c749SSergey Zigachev void dml1_rq_dlg_get_rq_params(
943*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
944*b843c749SSergey Zigachev 		struct _vcs_dpi_display_rq_params_st *rq_param,
945*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_pipe_source_params_st pipe_src_param)
946*b843c749SSergey Zigachev {
947*b843c749SSergey Zigachev 	/* get param for luma surface */
948*b843c749SSergey Zigachev 	rq_param->yuv420 = pipe_src_param.source_format == dm_420_8
949*b843c749SSergey Zigachev 			|| pipe_src_param.source_format == dm_420_10;
950*b843c749SSergey Zigachev 	rq_param->yuv420_10bpc = pipe_src_param.source_format == dm_420_10;
951*b843c749SSergey Zigachev 
952*b843c749SSergey Zigachev 	get_surf_rq_param(
953*b843c749SSergey Zigachev 			mode_lib,
954*b843c749SSergey Zigachev 			&(rq_param->sizing.rq_l),
955*b843c749SSergey Zigachev 			&(rq_param->dlg.rq_l),
956*b843c749SSergey Zigachev 			&(rq_param->misc.rq_l),
957*b843c749SSergey Zigachev 			pipe_src_param,
958*b843c749SSergey Zigachev 			0);
959*b843c749SSergey Zigachev 
960*b843c749SSergey Zigachev 	if (is_dual_plane((enum source_format_class) pipe_src_param.source_format)) {
961*b843c749SSergey Zigachev 		/* get param for chroma surface */
962*b843c749SSergey Zigachev 		get_surf_rq_param(
963*b843c749SSergey Zigachev 				mode_lib,
964*b843c749SSergey Zigachev 				&(rq_param->sizing.rq_c),
965*b843c749SSergey Zigachev 				&(rq_param->dlg.rq_c),
966*b843c749SSergey Zigachev 				&(rq_param->misc.rq_c),
967*b843c749SSergey Zigachev 				pipe_src_param,
968*b843c749SSergey Zigachev 				1);
969*b843c749SSergey Zigachev 	}
970*b843c749SSergey Zigachev 
971*b843c749SSergey Zigachev 	/* calculate how to split the det buffer space between luma and chroma */
972*b843c749SSergey Zigachev 	handle_det_buf_split(mode_lib, rq_param, pipe_src_param);
973*b843c749SSergey Zigachev 	print__rq_params_st(mode_lib, *rq_param);
974*b843c749SSergey Zigachev }
975*b843c749SSergey Zigachev 
976*b843c749SSergey Zigachev /* Note: currently taken in as is.
977*b843c749SSergey Zigachev  * Nice to decouple code from hw register implement and extract code that are repeated for luma and chroma.
978*b843c749SSergey Zigachev  */
dml1_rq_dlg_get_dlg_params(struct display_mode_lib * mode_lib,struct _vcs_dpi_display_dlg_regs_st * disp_dlg_regs,struct _vcs_dpi_display_ttu_regs_st * disp_ttu_regs,const struct _vcs_dpi_display_rq_dlg_params_st rq_dlg_param,const struct _vcs_dpi_display_dlg_sys_params_st dlg_sys_param,const struct _vcs_dpi_display_e2e_pipe_params_st e2e_pipe_param,const bool cstate_en,const bool pstate_en,const bool vm_en,const bool iflip_en)979*b843c749SSergey Zigachev void dml1_rq_dlg_get_dlg_params(
980*b843c749SSergey Zigachev 		struct display_mode_lib *mode_lib,
981*b843c749SSergey Zigachev 		struct _vcs_dpi_display_dlg_regs_st *disp_dlg_regs,
982*b843c749SSergey Zigachev 		struct _vcs_dpi_display_ttu_regs_st *disp_ttu_regs,
983*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_rq_dlg_params_st rq_dlg_param,
984*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_dlg_sys_params_st dlg_sys_param,
985*b843c749SSergey Zigachev 		const struct _vcs_dpi_display_e2e_pipe_params_st e2e_pipe_param,
986*b843c749SSergey Zigachev 		const bool cstate_en,
987*b843c749SSergey Zigachev 		const bool pstate_en,
988*b843c749SSergey Zigachev 		const bool vm_en,
989*b843c749SSergey Zigachev 		const bool iflip_en)
990*b843c749SSergey Zigachev {
991*b843c749SSergey Zigachev 	/* Timing */
992*b843c749SSergey Zigachev 	unsigned int htotal = e2e_pipe_param.pipe.dest.htotal;
993*b843c749SSergey Zigachev 	unsigned int hblank_end = e2e_pipe_param.pipe.dest.hblank_end;
994*b843c749SSergey Zigachev 	unsigned int vblank_start = e2e_pipe_param.pipe.dest.vblank_start;
995*b843c749SSergey Zigachev 	unsigned int vblank_end = e2e_pipe_param.pipe.dest.vblank_end;
996*b843c749SSergey Zigachev 	bool interlaced = e2e_pipe_param.pipe.dest.interlaced;
997*b843c749SSergey Zigachev 	unsigned int min_vblank = mode_lib->ip.min_vblank_lines;
998*b843c749SSergey Zigachev 
999*b843c749SSergey Zigachev 	double pclk_freq_in_mhz = e2e_pipe_param.pipe.dest.pixel_rate_mhz;
1000*b843c749SSergey Zigachev 	double refclk_freq_in_mhz = e2e_pipe_param.clks_cfg.refclk_mhz;
1001*b843c749SSergey Zigachev 	double dppclk_freq_in_mhz = e2e_pipe_param.clks_cfg.dppclk_mhz;
1002*b843c749SSergey Zigachev 	double dispclk_freq_in_mhz = e2e_pipe_param.clks_cfg.dispclk_mhz;
1003*b843c749SSergey Zigachev 
1004*b843c749SSergey Zigachev 	double ref_freq_to_pix_freq;
1005*b843c749SSergey Zigachev 	double prefetch_xy_calc_in_dcfclk;
1006*b843c749SSergey Zigachev 	double min_dcfclk_mhz;
1007*b843c749SSergey Zigachev 	double t_calc_us;
1008*b843c749SSergey Zigachev 	double min_ttu_vblank;
1009*b843c749SSergey Zigachev 	double min_dst_y_ttu_vblank;
1010*b843c749SSergey Zigachev 	unsigned int dlg_vblank_start;
1011*b843c749SSergey Zigachev 	bool dcc_en;
1012*b843c749SSergey Zigachev 	bool dual_plane;
1013*b843c749SSergey Zigachev 	bool mode_422;
1014*b843c749SSergey Zigachev 	unsigned int access_dir;
1015*b843c749SSergey Zigachev 	unsigned int bytes_per_element_l;
1016*b843c749SSergey Zigachev 	unsigned int bytes_per_element_c;
1017*b843c749SSergey Zigachev 	unsigned int vp_height_l;
1018*b843c749SSergey Zigachev 	unsigned int vp_width_l;
1019*b843c749SSergey Zigachev 	unsigned int vp_height_c;
1020*b843c749SSergey Zigachev 	unsigned int vp_width_c;
1021*b843c749SSergey Zigachev 	unsigned int htaps_l;
1022*b843c749SSergey Zigachev 	unsigned int htaps_c;
1023*b843c749SSergey Zigachev 	double hratios_l;
1024*b843c749SSergey Zigachev 	double hratios_c;
1025*b843c749SSergey Zigachev 	double vratio_l;
1026*b843c749SSergey Zigachev 	double vratio_c;
1027*b843c749SSergey Zigachev 	double line_time_in_us;
1028*b843c749SSergey Zigachev 	double vinit_l;
1029*b843c749SSergey Zigachev 	double vinit_c;
1030*b843c749SSergey Zigachev 	double vinit_bot_l;
1031*b843c749SSergey Zigachev 	double vinit_bot_c;
1032*b843c749SSergey Zigachev 	unsigned int swath_height_l;
1033*b843c749SSergey Zigachev 	unsigned int swath_width_ub_l;
1034*b843c749SSergey Zigachev 	unsigned int dpte_bytes_per_row_ub_l;
1035*b843c749SSergey Zigachev 	unsigned int dpte_groups_per_row_ub_l;
1036*b843c749SSergey Zigachev 	unsigned int meta_pte_bytes_per_frame_ub_l;
1037*b843c749SSergey Zigachev 	unsigned int meta_bytes_per_row_ub_l;
1038*b843c749SSergey Zigachev 	unsigned int swath_height_c;
1039*b843c749SSergey Zigachev 	unsigned int swath_width_ub_c;
1040*b843c749SSergey Zigachev 	unsigned int dpte_bytes_per_row_ub_c;
1041*b843c749SSergey Zigachev 	unsigned int dpte_groups_per_row_ub_c;
1042*b843c749SSergey Zigachev 	unsigned int meta_chunks_per_row_ub_l;
1043*b843c749SSergey Zigachev 	unsigned int vupdate_offset;
1044*b843c749SSergey Zigachev 	unsigned int vupdate_width;
1045*b843c749SSergey Zigachev 	unsigned int vready_offset;
1046*b843c749SSergey Zigachev 	unsigned int dppclk_delay_subtotal;
1047*b843c749SSergey Zigachev 	unsigned int dispclk_delay_subtotal;
1048*b843c749SSergey Zigachev 	unsigned int pixel_rate_delay_subtotal;
1049*b843c749SSergey Zigachev 	unsigned int vstartup_start;
1050*b843c749SSergey Zigachev 	unsigned int dst_x_after_scaler;
1051*b843c749SSergey Zigachev 	unsigned int dst_y_after_scaler;
1052*b843c749SSergey Zigachev 	double line_wait;
1053*b843c749SSergey Zigachev 	double line_o;
1054*b843c749SSergey Zigachev 	double line_setup;
1055*b843c749SSergey Zigachev 	double line_calc;
1056*b843c749SSergey Zigachev 	double dst_y_prefetch;
1057*b843c749SSergey Zigachev 	double t_pre_us;
1058*b843c749SSergey Zigachev 	unsigned int vm_bytes;
1059*b843c749SSergey Zigachev 	unsigned int meta_row_bytes;
1060*b843c749SSergey Zigachev 	unsigned int max_num_sw_l;
1061*b843c749SSergey Zigachev 	unsigned int max_num_sw_c;
1062*b843c749SSergey Zigachev 	unsigned int max_partial_sw_l;
1063*b843c749SSergey Zigachev 	unsigned int max_partial_sw_c;
1064*b843c749SSergey Zigachev 	double max_vinit_l;
1065*b843c749SSergey Zigachev 	double max_vinit_c;
1066*b843c749SSergey Zigachev 	unsigned int lsw_l;
1067*b843c749SSergey Zigachev 	unsigned int lsw_c;
1068*b843c749SSergey Zigachev 	unsigned int sw_bytes_ub_l;
1069*b843c749SSergey Zigachev 	unsigned int sw_bytes_ub_c;
1070*b843c749SSergey Zigachev 	unsigned int sw_bytes;
1071*b843c749SSergey Zigachev 	unsigned int dpte_row_bytes;
1072*b843c749SSergey Zigachev 	double prefetch_bw;
1073*b843c749SSergey Zigachev 	double flip_bw;
1074*b843c749SSergey Zigachev 	double t_vm_us;
1075*b843c749SSergey Zigachev 	double t_r0_us;
1076*b843c749SSergey Zigachev 	double dst_y_per_vm_vblank;
1077*b843c749SSergey Zigachev 	double dst_y_per_row_vblank;
1078*b843c749SSergey Zigachev 	double min_dst_y_per_vm_vblank;
1079*b843c749SSergey Zigachev 	double min_dst_y_per_row_vblank;
1080*b843c749SSergey Zigachev 	double lsw;
1081*b843c749SSergey Zigachev 	double vratio_pre_l;
1082*b843c749SSergey Zigachev 	double vratio_pre_c;
1083*b843c749SSergey Zigachev 	unsigned int req_per_swath_ub_l;
1084*b843c749SSergey Zigachev 	unsigned int req_per_swath_ub_c;
1085*b843c749SSergey Zigachev 	unsigned int meta_row_height_l;
1086*b843c749SSergey Zigachev 	unsigned int swath_width_pixels_ub_l;
1087*b843c749SSergey Zigachev 	unsigned int swath_width_pixels_ub_c;
1088*b843c749SSergey Zigachev 	unsigned int scaler_rec_in_width_l;
1089*b843c749SSergey Zigachev 	unsigned int scaler_rec_in_width_c;
1090*b843c749SSergey Zigachev 	unsigned int dpte_row_height_l;
1091*b843c749SSergey Zigachev 	unsigned int dpte_row_height_c;
1092*b843c749SSergey Zigachev 	double hscale_pixel_rate_l;
1093*b843c749SSergey Zigachev 	double hscale_pixel_rate_c;
1094*b843c749SSergey Zigachev 	double min_hratio_fact_l;
1095*b843c749SSergey Zigachev 	double min_hratio_fact_c;
1096*b843c749SSergey Zigachev 	double refcyc_per_line_delivery_pre_l;
1097*b843c749SSergey Zigachev 	double refcyc_per_line_delivery_pre_c;
1098*b843c749SSergey Zigachev 	double refcyc_per_line_delivery_l;
1099*b843c749SSergey Zigachev 	double refcyc_per_line_delivery_c;
1100*b843c749SSergey Zigachev 	double refcyc_per_req_delivery_pre_l;
1101*b843c749SSergey Zigachev 	double refcyc_per_req_delivery_pre_c;
1102*b843c749SSergey Zigachev 	double refcyc_per_req_delivery_l;
1103*b843c749SSergey Zigachev 	double refcyc_per_req_delivery_c;
1104*b843c749SSergey Zigachev 	double refcyc_per_req_delivery_pre_cur0;
1105*b843c749SSergey Zigachev 	double refcyc_per_req_delivery_cur0;
1106*b843c749SSergey Zigachev 	unsigned int full_recout_width;
1107*b843c749SSergey Zigachev 	double hratios_cur0;
1108*b843c749SSergey Zigachev 	unsigned int cur0_src_width;
1109*b843c749SSergey Zigachev 	enum cursor_bpp cur0_bpp;
1110*b843c749SSergey Zigachev 	unsigned int cur0_req_size;
1111*b843c749SSergey Zigachev 	unsigned int cur0_req_width;
1112*b843c749SSergey Zigachev 	double cur0_width_ub;
1113*b843c749SSergey Zigachev 	double cur0_req_per_width;
1114*b843c749SSergey Zigachev 	double hactive_cur0;
1115*b843c749SSergey Zigachev 
1116*b843c749SSergey Zigachev 	memset(disp_dlg_regs, 0, sizeof(*disp_dlg_regs));
1117*b843c749SSergey Zigachev 	memset(disp_ttu_regs, 0, sizeof(*disp_ttu_regs));
1118*b843c749SSergey Zigachev 
1119*b843c749SSergey Zigachev 	DTRACE("DLG: %s: cstate_en = %d", __func__, cstate_en);
1120*b843c749SSergey Zigachev 	DTRACE("DLG: %s: pstate_en = %d", __func__, pstate_en);
1121*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vm_en     = %d", __func__, vm_en);
1122*b843c749SSergey Zigachev 	DTRACE("DLG: %s: iflip_en  = %d", __func__, iflip_en);
1123*b843c749SSergey Zigachev 
1124*b843c749SSergey Zigachev 	/* ------------------------- */
1125*b843c749SSergey Zigachev 	/* Section 1.5.2.1: OTG dependent Params */
1126*b843c749SSergey Zigachev 	/* ------------------------- */
1127*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dppclk_freq_in_mhz     = %3.2f", __func__, dppclk_freq_in_mhz);
1128*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dispclk_freq_in_mhz    = %3.2f", __func__, dispclk_freq_in_mhz);
1129*b843c749SSergey Zigachev 	DTRACE("DLG: %s: refclk_freq_in_mhz     = %3.2f", __func__, refclk_freq_in_mhz);
1130*b843c749SSergey Zigachev 	DTRACE("DLG: %s: pclk_freq_in_mhz       = %3.2f", __func__, pclk_freq_in_mhz);
1131*b843c749SSergey Zigachev 	DTRACE("DLG: %s: interlaced             = %d", __func__, interlaced);
1132*b843c749SSergey Zigachev 
1133*b843c749SSergey Zigachev 	ref_freq_to_pix_freq = refclk_freq_in_mhz / pclk_freq_in_mhz;
1134*b843c749SSergey Zigachev 	ASSERT(ref_freq_to_pix_freq < 4.0);
1135*b843c749SSergey Zigachev 	disp_dlg_regs->ref_freq_to_pix_freq =
1136*b843c749SSergey Zigachev 			(unsigned int) (ref_freq_to_pix_freq * dml_pow(2, 19));
1137*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_htotal = (unsigned int) (ref_freq_to_pix_freq * (double) htotal
1138*b843c749SSergey Zigachev 			* dml_pow(2, 8));
1139*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_h_blank_end = (unsigned int) ((double) hblank_end
1140*b843c749SSergey Zigachev 			* (double) ref_freq_to_pix_freq);
1141*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_h_blank_end < (unsigned int) dml_pow(2, 13));
1142*b843c749SSergey Zigachev 	disp_dlg_regs->dlg_vblank_end = interlaced ? (vblank_end / 2) : vblank_end; /* 15 bits */
1143*b843c749SSergey Zigachev 
1144*b843c749SSergey Zigachev 	prefetch_xy_calc_in_dcfclk = 24.0; /* FIXME: ip_param */
1145*b843c749SSergey Zigachev 	min_dcfclk_mhz = dlg_sys_param.deepsleep_dcfclk_mhz;
1146*b843c749SSergey Zigachev 	t_calc_us = prefetch_xy_calc_in_dcfclk / min_dcfclk_mhz;
1147*b843c749SSergey Zigachev 	min_ttu_vblank = dlg_sys_param.t_urg_wm_us;
1148*b843c749SSergey Zigachev 	if (cstate_en)
1149*b843c749SSergey Zigachev 		min_ttu_vblank = dml_max(dlg_sys_param.t_sr_wm_us, min_ttu_vblank);
1150*b843c749SSergey Zigachev 	if (pstate_en)
1151*b843c749SSergey Zigachev 		min_ttu_vblank = dml_max(dlg_sys_param.t_mclk_wm_us, min_ttu_vblank);
1152*b843c749SSergey Zigachev 	min_ttu_vblank = min_ttu_vblank + t_calc_us;
1153*b843c749SSergey Zigachev 
1154*b843c749SSergey Zigachev 	min_dst_y_ttu_vblank = min_ttu_vblank * pclk_freq_in_mhz / (double) htotal;
1155*b843c749SSergey Zigachev 	dlg_vblank_start = interlaced ? (vblank_start / 2) : vblank_start;
1156*b843c749SSergey Zigachev 
1157*b843c749SSergey Zigachev 	disp_dlg_regs->min_dst_y_next_start = (unsigned int) (((double) dlg_vblank_start
1158*b843c749SSergey Zigachev 			+ min_dst_y_ttu_vblank) * dml_pow(2, 2));
1159*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->min_dst_y_next_start < (unsigned int) dml_pow(2, 18));
1160*b843c749SSergey Zigachev 
1161*b843c749SSergey Zigachev 	DTRACE("DLG: %s: min_dcfclk_mhz                         = %3.2f", __func__, min_dcfclk_mhz);
1162*b843c749SSergey Zigachev 	DTRACE("DLG: %s: min_ttu_vblank                         = %3.2f", __func__, min_ttu_vblank);
1163*b843c749SSergey Zigachev 	DTRACE(
1164*b843c749SSergey Zigachev 			"DLG: %s: min_dst_y_ttu_vblank                   = %3.2f",
1165*b843c749SSergey Zigachev 			__func__,
1166*b843c749SSergey Zigachev 			min_dst_y_ttu_vblank);
1167*b843c749SSergey Zigachev 	DTRACE("DLG: %s: t_calc_us                              = %3.2f", __func__, t_calc_us);
1168*b843c749SSergey Zigachev 	DTRACE(
1169*b843c749SSergey Zigachev 			"DLG: %s: disp_dlg_regs->min_dst_y_next_start    = 0x%0x",
1170*b843c749SSergey Zigachev 			__func__,
1171*b843c749SSergey Zigachev 			disp_dlg_regs->min_dst_y_next_start);
1172*b843c749SSergey Zigachev 	DTRACE(
1173*b843c749SSergey Zigachev 			"DLG: %s: ref_freq_to_pix_freq                   = %3.2f",
1174*b843c749SSergey Zigachev 			__func__,
1175*b843c749SSergey Zigachev 			ref_freq_to_pix_freq);
1176*b843c749SSergey Zigachev 
1177*b843c749SSergey Zigachev 	/* ------------------------- */
1178*b843c749SSergey Zigachev 	/* Section 1.5.2.2: Prefetch, Active and TTU  */
1179*b843c749SSergey Zigachev 	/* ------------------------- */
1180*b843c749SSergey Zigachev 	/* Prefetch Calc */
1181*b843c749SSergey Zigachev 	/* Source */
1182*b843c749SSergey Zigachev 	dcc_en = e2e_pipe_param.pipe.src.dcc;
1183*b843c749SSergey Zigachev 	dual_plane = is_dual_plane(
1184*b843c749SSergey Zigachev 			(enum source_format_class) e2e_pipe_param.pipe.src.source_format);
1185*b843c749SSergey Zigachev 	mode_422 = 0; /* FIXME */
1186*b843c749SSergey Zigachev 	access_dir = (e2e_pipe_param.pipe.src.source_scan == dm_vert); /* vp access direction: horizontal or vertical accessed */
1187*b843c749SSergey Zigachev 	bytes_per_element_l = get_bytes_per_element(
1188*b843c749SSergey Zigachev 			(enum source_format_class) e2e_pipe_param.pipe.src.source_format,
1189*b843c749SSergey Zigachev 			0);
1190*b843c749SSergey Zigachev 	bytes_per_element_c = get_bytes_per_element(
1191*b843c749SSergey Zigachev 			(enum source_format_class) e2e_pipe_param.pipe.src.source_format,
1192*b843c749SSergey Zigachev 			1);
1193*b843c749SSergey Zigachev 	vp_height_l = e2e_pipe_param.pipe.src.viewport_height;
1194*b843c749SSergey Zigachev 	vp_width_l = e2e_pipe_param.pipe.src.viewport_width;
1195*b843c749SSergey Zigachev 	vp_height_c = e2e_pipe_param.pipe.src.viewport_height_c;
1196*b843c749SSergey Zigachev 	vp_width_c = e2e_pipe_param.pipe.src.viewport_width_c;
1197*b843c749SSergey Zigachev 
1198*b843c749SSergey Zigachev 	/* Scaling */
1199*b843c749SSergey Zigachev 	htaps_l = e2e_pipe_param.pipe.scale_taps.htaps;
1200*b843c749SSergey Zigachev 	htaps_c = e2e_pipe_param.pipe.scale_taps.htaps_c;
1201*b843c749SSergey Zigachev 	hratios_l = e2e_pipe_param.pipe.scale_ratio_depth.hscl_ratio;
1202*b843c749SSergey Zigachev 	hratios_c = e2e_pipe_param.pipe.scale_ratio_depth.hscl_ratio_c;
1203*b843c749SSergey Zigachev 	vratio_l = e2e_pipe_param.pipe.scale_ratio_depth.vscl_ratio;
1204*b843c749SSergey Zigachev 	vratio_c = e2e_pipe_param.pipe.scale_ratio_depth.vscl_ratio_c;
1205*b843c749SSergey Zigachev 
1206*b843c749SSergey Zigachev 	line_time_in_us = (htotal / pclk_freq_in_mhz);
1207*b843c749SSergey Zigachev 	vinit_l = e2e_pipe_param.pipe.scale_ratio_depth.vinit;
1208*b843c749SSergey Zigachev 	vinit_c = e2e_pipe_param.pipe.scale_ratio_depth.vinit_c;
1209*b843c749SSergey Zigachev 	vinit_bot_l = e2e_pipe_param.pipe.scale_ratio_depth.vinit_bot;
1210*b843c749SSergey Zigachev 	vinit_bot_c = e2e_pipe_param.pipe.scale_ratio_depth.vinit_bot_c;
1211*b843c749SSergey Zigachev 
1212*b843c749SSergey Zigachev 	swath_height_l = rq_dlg_param.rq_l.swath_height;
1213*b843c749SSergey Zigachev 	swath_width_ub_l = rq_dlg_param.rq_l.swath_width_ub;
1214*b843c749SSergey Zigachev 	dpte_bytes_per_row_ub_l = rq_dlg_param.rq_l.dpte_bytes_per_row_ub;
1215*b843c749SSergey Zigachev 	dpte_groups_per_row_ub_l = rq_dlg_param.rq_l.dpte_groups_per_row_ub;
1216*b843c749SSergey Zigachev 	meta_pte_bytes_per_frame_ub_l = rq_dlg_param.rq_l.meta_pte_bytes_per_frame_ub;
1217*b843c749SSergey Zigachev 	meta_bytes_per_row_ub_l = rq_dlg_param.rq_l.meta_bytes_per_row_ub;
1218*b843c749SSergey Zigachev 
1219*b843c749SSergey Zigachev 	swath_height_c = rq_dlg_param.rq_c.swath_height;
1220*b843c749SSergey Zigachev 	swath_width_ub_c = rq_dlg_param.rq_c.swath_width_ub;
1221*b843c749SSergey Zigachev 	dpte_bytes_per_row_ub_c = rq_dlg_param.rq_c.dpte_bytes_per_row_ub;
1222*b843c749SSergey Zigachev 	dpte_groups_per_row_ub_c = rq_dlg_param.rq_c.dpte_groups_per_row_ub;
1223*b843c749SSergey Zigachev 
1224*b843c749SSergey Zigachev 	meta_chunks_per_row_ub_l = rq_dlg_param.rq_l.meta_chunks_per_row_ub;
1225*b843c749SSergey Zigachev 	vupdate_offset = e2e_pipe_param.pipe.dest.vupdate_offset;
1226*b843c749SSergey Zigachev 	vupdate_width = e2e_pipe_param.pipe.dest.vupdate_width;
1227*b843c749SSergey Zigachev 	vready_offset = e2e_pipe_param.pipe.dest.vready_offset;
1228*b843c749SSergey Zigachev 
1229*b843c749SSergey Zigachev 	dppclk_delay_subtotal = mode_lib->ip.dppclk_delay_subtotal;
1230*b843c749SSergey Zigachev 	dispclk_delay_subtotal = mode_lib->ip.dispclk_delay_subtotal;
1231*b843c749SSergey Zigachev 	pixel_rate_delay_subtotal = dppclk_delay_subtotal * pclk_freq_in_mhz / dppclk_freq_in_mhz
1232*b843c749SSergey Zigachev 			+ dispclk_delay_subtotal * pclk_freq_in_mhz / dispclk_freq_in_mhz;
1233*b843c749SSergey Zigachev 
1234*b843c749SSergey Zigachev 	vstartup_start = e2e_pipe_param.pipe.dest.vstartup_start;
1235*b843c749SSergey Zigachev 
1236*b843c749SSergey Zigachev 	if (interlaced)
1237*b843c749SSergey Zigachev 		vstartup_start = vstartup_start / 2;
1238*b843c749SSergey Zigachev 
1239*b843c749SSergey Zigachev 	if (vstartup_start >= min_vblank) {
1240*b843c749SSergey Zigachev 		DTRACE(
1241*b843c749SSergey Zigachev 				"WARNING_DLG: %s:  vblank_start=%d vblank_end=%d",
1242*b843c749SSergey Zigachev 				__func__,
1243*b843c749SSergey Zigachev 				vblank_start,
1244*b843c749SSergey Zigachev 				vblank_end);
1245*b843c749SSergey Zigachev 		DTRACE(
1246*b843c749SSergey Zigachev 				"WARNING_DLG: %s:  vstartup_start=%d should be less than min_vblank=%d",
1247*b843c749SSergey Zigachev 				__func__,
1248*b843c749SSergey Zigachev 				vstartup_start,
1249*b843c749SSergey Zigachev 				min_vblank);
1250*b843c749SSergey Zigachev 		min_vblank = vstartup_start + 1;
1251*b843c749SSergey Zigachev 		DTRACE(
1252*b843c749SSergey Zigachev 				"WARNING_DLG: %s:  vstartup_start=%d should be less than min_vblank=%d",
1253*b843c749SSergey Zigachev 				__func__,
1254*b843c749SSergey Zigachev 				vstartup_start,
1255*b843c749SSergey Zigachev 				min_vblank);
1256*b843c749SSergey Zigachev 	}
1257*b843c749SSergey Zigachev 
1258*b843c749SSergey Zigachev 	dst_x_after_scaler = 0;
1259*b843c749SSergey Zigachev 	dst_y_after_scaler = 0;
1260*b843c749SSergey Zigachev 
1261*b843c749SSergey Zigachev 	if (e2e_pipe_param.pipe.src.is_hsplit)
1262*b843c749SSergey Zigachev 		dst_x_after_scaler = pixel_rate_delay_subtotal
1263*b843c749SSergey Zigachev 				+ e2e_pipe_param.pipe.dest.recout_width;
1264*b843c749SSergey Zigachev 	else
1265*b843c749SSergey Zigachev 		dst_x_after_scaler = pixel_rate_delay_subtotal;
1266*b843c749SSergey Zigachev 
1267*b843c749SSergey Zigachev 	if (e2e_pipe_param.dout.output_format == dm_420)
1268*b843c749SSergey Zigachev 		dst_y_after_scaler = 1;
1269*b843c749SSergey Zigachev 	else
1270*b843c749SSergey Zigachev 		dst_y_after_scaler = 0;
1271*b843c749SSergey Zigachev 
1272*b843c749SSergey Zigachev 	if (dst_x_after_scaler >= htotal) {
1273*b843c749SSergey Zigachev 		dst_x_after_scaler = dst_x_after_scaler - htotal;
1274*b843c749SSergey Zigachev 		dst_y_after_scaler = dst_y_after_scaler + 1;
1275*b843c749SSergey Zigachev 	}
1276*b843c749SSergey Zigachev 
1277*b843c749SSergey Zigachev 	DTRACE("DLG: %s: htotal                                 = %d", __func__, htotal);
1278*b843c749SSergey Zigachev 	DTRACE(
1279*b843c749SSergey Zigachev 			"DLG: %s: pixel_rate_delay_subtotal              = %d",
1280*b843c749SSergey Zigachev 			__func__,
1281*b843c749SSergey Zigachev 			pixel_rate_delay_subtotal);
1282*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_x_after_scaler                     = %d", __func__, dst_x_after_scaler);
1283*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_y_after_scaler                     = %d", __func__, dst_y_after_scaler);
1284*b843c749SSergey Zigachev 
1285*b843c749SSergey Zigachev 	line_wait = mode_lib->soc.urgent_latency_us;
1286*b843c749SSergey Zigachev 	if (cstate_en)
1287*b843c749SSergey Zigachev 		line_wait = dml_max(mode_lib->soc.sr_enter_plus_exit_time_us, line_wait);
1288*b843c749SSergey Zigachev 	if (pstate_en)
1289*b843c749SSergey Zigachev 		line_wait = dml_max(
1290*b843c749SSergey Zigachev 				mode_lib->soc.dram_clock_change_latency_us
1291*b843c749SSergey Zigachev 						+ mode_lib->soc.urgent_latency_us,
1292*b843c749SSergey Zigachev 				line_wait);
1293*b843c749SSergey Zigachev 	line_wait = line_wait / line_time_in_us;
1294*b843c749SSergey Zigachev 
1295*b843c749SSergey Zigachev 	line_o = (double) dst_y_after_scaler + dst_x_after_scaler / (double) htotal;
1296*b843c749SSergey Zigachev 	line_setup = (double) (vupdate_offset + vupdate_width + vready_offset) / (double) htotal;
1297*b843c749SSergey Zigachev 	line_calc = t_calc_us / line_time_in_us;
1298*b843c749SSergey Zigachev 
1299*b843c749SSergey Zigachev 	DTRACE(
1300*b843c749SSergey Zigachev 			"DLG: %s: soc.sr_enter_plus_exit_time_us     = %3.2f",
1301*b843c749SSergey Zigachev 			__func__,
1302*b843c749SSergey Zigachev 			(double) mode_lib->soc.sr_enter_plus_exit_time_us);
1303*b843c749SSergey Zigachev 	DTRACE(
1304*b843c749SSergey Zigachev 			"DLG: %s: soc.dram_clock_change_latency_us   = %3.2f",
1305*b843c749SSergey Zigachev 			__func__,
1306*b843c749SSergey Zigachev 			(double) mode_lib->soc.dram_clock_change_latency_us);
1307*b843c749SSergey Zigachev 	DTRACE(
1308*b843c749SSergey Zigachev 			"DLG: %s: soc.urgent_latency_us              = %3.2f",
1309*b843c749SSergey Zigachev 			__func__,
1310*b843c749SSergey Zigachev 			mode_lib->soc.urgent_latency_us);
1311*b843c749SSergey Zigachev 
1312*b843c749SSergey Zigachev 	DTRACE("DLG: %s: swath_height_l     = %d", __func__, swath_height_l);
1313*b843c749SSergey Zigachev 	if (dual_plane)
1314*b843c749SSergey Zigachev 		DTRACE("DLG: %s: swath_height_c     = %d", __func__, swath_height_c);
1315*b843c749SSergey Zigachev 
1316*b843c749SSergey Zigachev 	DTRACE(
1317*b843c749SSergey Zigachev 			"DLG: %s: t_srx_delay_us     = %3.2f",
1318*b843c749SSergey Zigachev 			__func__,
1319*b843c749SSergey Zigachev 			(double) dlg_sys_param.t_srx_delay_us);
1320*b843c749SSergey Zigachev 	DTRACE("DLG: %s: line_time_in_us    = %3.2f", __func__, (double) line_time_in_us);
1321*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vupdate_offset     = %d", __func__, vupdate_offset);
1322*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vupdate_width      = %d", __func__, vupdate_width);
1323*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vready_offset      = %d", __func__, vready_offset);
1324*b843c749SSergey Zigachev 	DTRACE("DLG: %s: line_time_in_us    = %3.2f", __func__, line_time_in_us);
1325*b843c749SSergey Zigachev 	DTRACE("DLG: %s: line_wait          = %3.2f", __func__, line_wait);
1326*b843c749SSergey Zigachev 	DTRACE("DLG: %s: line_o             = %3.2f", __func__, line_o);
1327*b843c749SSergey Zigachev 	DTRACE("DLG: %s: line_setup         = %3.2f", __func__, line_setup);
1328*b843c749SSergey Zigachev 	DTRACE("DLG: %s: line_calc          = %3.2f", __func__, line_calc);
1329*b843c749SSergey Zigachev 
1330*b843c749SSergey Zigachev 	dst_y_prefetch = ((double) min_vblank - 1.0)
1331*b843c749SSergey Zigachev 			- (line_setup + line_calc + line_wait + line_o);
1332*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_y_prefetch (before rnd) = %3.2f", __func__, dst_y_prefetch);
1333*b843c749SSergey Zigachev 	ASSERT(dst_y_prefetch >= 2.0);
1334*b843c749SSergey Zigachev 
1335*b843c749SSergey Zigachev 	dst_y_prefetch = dml_floor(4.0 * (dst_y_prefetch + 0.125), 1) / 4;
1336*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_y_prefetch (after rnd) = %3.2f", __func__, dst_y_prefetch);
1337*b843c749SSergey Zigachev 
1338*b843c749SSergey Zigachev 	t_pre_us = dst_y_prefetch * line_time_in_us;
1339*b843c749SSergey Zigachev 	vm_bytes = 0;
1340*b843c749SSergey Zigachev 	meta_row_bytes = 0;
1341*b843c749SSergey Zigachev 
1342*b843c749SSergey Zigachev 	if (dcc_en && vm_en)
1343*b843c749SSergey Zigachev 		vm_bytes = meta_pte_bytes_per_frame_ub_l;
1344*b843c749SSergey Zigachev 	if (dcc_en)
1345*b843c749SSergey Zigachev 		meta_row_bytes = meta_bytes_per_row_ub_l;
1346*b843c749SSergey Zigachev 
1347*b843c749SSergey Zigachev 	max_num_sw_l = 0;
1348*b843c749SSergey Zigachev 	max_num_sw_c = 0;
1349*b843c749SSergey Zigachev 	max_partial_sw_l = 0;
1350*b843c749SSergey Zigachev 	max_partial_sw_c = 0;
1351*b843c749SSergey Zigachev 
1352*b843c749SSergey Zigachev 	max_vinit_l = interlaced ? dml_max(vinit_l, vinit_bot_l) : vinit_l;
1353*b843c749SSergey Zigachev 	max_vinit_c = interlaced ? dml_max(vinit_c, vinit_bot_c) : vinit_c;
1354*b843c749SSergey Zigachev 
1355*b843c749SSergey Zigachev 	get_swath_need(mode_lib, &max_num_sw_l, &max_partial_sw_l, swath_height_l, max_vinit_l);
1356*b843c749SSergey Zigachev 	if (dual_plane)
1357*b843c749SSergey Zigachev 		get_swath_need(
1358*b843c749SSergey Zigachev 				mode_lib,
1359*b843c749SSergey Zigachev 				&max_num_sw_c,
1360*b843c749SSergey Zigachev 				&max_partial_sw_c,
1361*b843c749SSergey Zigachev 				swath_height_c,
1362*b843c749SSergey Zigachev 				max_vinit_c);
1363*b843c749SSergey Zigachev 
1364*b843c749SSergey Zigachev 	lsw_l = max_num_sw_l * swath_height_l + max_partial_sw_l;
1365*b843c749SSergey Zigachev 	lsw_c = max_num_sw_c * swath_height_c + max_partial_sw_c;
1366*b843c749SSergey Zigachev 	sw_bytes_ub_l = lsw_l * swath_width_ub_l * bytes_per_element_l;
1367*b843c749SSergey Zigachev 	sw_bytes_ub_c = lsw_c * swath_width_ub_c * bytes_per_element_c;
1368*b843c749SSergey Zigachev 	sw_bytes = 0;
1369*b843c749SSergey Zigachev 	dpte_row_bytes = 0;
1370*b843c749SSergey Zigachev 
1371*b843c749SSergey Zigachev 	if (vm_en) {
1372*b843c749SSergey Zigachev 		if (dual_plane)
1373*b843c749SSergey Zigachev 			dpte_row_bytes = dpte_bytes_per_row_ub_l + dpte_bytes_per_row_ub_c;
1374*b843c749SSergey Zigachev 		else
1375*b843c749SSergey Zigachev 			dpte_row_bytes = dpte_bytes_per_row_ub_l;
1376*b843c749SSergey Zigachev 	} else {
1377*b843c749SSergey Zigachev 		dpte_row_bytes = 0;
1378*b843c749SSergey Zigachev 	}
1379*b843c749SSergey Zigachev 
1380*b843c749SSergey Zigachev 	if (dual_plane)
1381*b843c749SSergey Zigachev 		sw_bytes = sw_bytes_ub_l + sw_bytes_ub_c;
1382*b843c749SSergey Zigachev 	else
1383*b843c749SSergey Zigachev 		sw_bytes = sw_bytes_ub_l;
1384*b843c749SSergey Zigachev 
1385*b843c749SSergey Zigachev 	DTRACE("DLG: %s: sw_bytes_ub_l           = %d", __func__, sw_bytes_ub_l);
1386*b843c749SSergey Zigachev 	DTRACE("DLG: %s: sw_bytes_ub_c           = %d", __func__, sw_bytes_ub_c);
1387*b843c749SSergey Zigachev 	DTRACE("DLG: %s: sw_bytes                = %d", __func__, sw_bytes);
1388*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vm_bytes                = %d", __func__, vm_bytes);
1389*b843c749SSergey Zigachev 	DTRACE("DLG: %s: meta_row_bytes          = %d", __func__, meta_row_bytes);
1390*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dpte_row_bytes          = %d", __func__, dpte_row_bytes);
1391*b843c749SSergey Zigachev 
1392*b843c749SSergey Zigachev 	prefetch_bw = (vm_bytes + 2 * dpte_row_bytes + 2 * meta_row_bytes + sw_bytes) / t_pre_us;
1393*b843c749SSergey Zigachev 	flip_bw = ((vm_bytes + dpte_row_bytes + meta_row_bytes) * dlg_sys_param.total_flip_bw)
1394*b843c749SSergey Zigachev 			/ (double) dlg_sys_param.total_flip_bytes;
1395*b843c749SSergey Zigachev 	t_vm_us = line_time_in_us / 4.0;
1396*b843c749SSergey Zigachev 	if (vm_en && dcc_en) {
1397*b843c749SSergey Zigachev 		t_vm_us = dml_max(
1398*b843c749SSergey Zigachev 				dlg_sys_param.t_extra_us,
1399*b843c749SSergey Zigachev 				dml_max((double) vm_bytes / prefetch_bw, t_vm_us));
1400*b843c749SSergey Zigachev 
1401*b843c749SSergey Zigachev 		if (iflip_en && !dual_plane) {
1402*b843c749SSergey Zigachev 			t_vm_us = dml_max(mode_lib->soc.urgent_latency_us, t_vm_us);
1403*b843c749SSergey Zigachev 			if (flip_bw > 0.)
1404*b843c749SSergey Zigachev 				t_vm_us = dml_max(vm_bytes / flip_bw, t_vm_us);
1405*b843c749SSergey Zigachev 		}
1406*b843c749SSergey Zigachev 	}
1407*b843c749SSergey Zigachev 
1408*b843c749SSergey Zigachev 	t_r0_us = dml_max(dlg_sys_param.t_extra_us - t_vm_us, line_time_in_us - t_vm_us);
1409*b843c749SSergey Zigachev 
1410*b843c749SSergey Zigachev 	if (vm_en || dcc_en) {
1411*b843c749SSergey Zigachev 		t_r0_us = dml_max(
1412*b843c749SSergey Zigachev 				(double) (dpte_row_bytes + meta_row_bytes) / prefetch_bw,
1413*b843c749SSergey Zigachev 				dlg_sys_param.t_extra_us);
1414*b843c749SSergey Zigachev 		t_r0_us = dml_max((double) (line_time_in_us - t_vm_us), t_r0_us);
1415*b843c749SSergey Zigachev 
1416*b843c749SSergey Zigachev 		if (iflip_en && !dual_plane) {
1417*b843c749SSergey Zigachev 			t_r0_us = dml_max(mode_lib->soc.urgent_latency_us * 2.0, t_r0_us);
1418*b843c749SSergey Zigachev 			if (flip_bw > 0.)
1419*b843c749SSergey Zigachev 				t_r0_us = dml_max(
1420*b843c749SSergey Zigachev 						(dpte_row_bytes + meta_row_bytes) / flip_bw,
1421*b843c749SSergey Zigachev 						t_r0_us);
1422*b843c749SSergey Zigachev 		}
1423*b843c749SSergey Zigachev 	}
1424*b843c749SSergey Zigachev 
1425*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_after_scaler = dst_y_after_scaler; /* in terms of line */
1426*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_x_after_scaler = dst_x_after_scaler * ref_freq_to_pix_freq; /* in terms of refclk */
1427*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_x_after_scaler < (unsigned int) dml_pow(2, 13));
1428*b843c749SSergey Zigachev 	DTRACE(
1429*b843c749SSergey Zigachev 			"DLG: %s: disp_dlg_regs->dst_y_after_scaler      = 0x%0x",
1430*b843c749SSergey Zigachev 			__func__,
1431*b843c749SSergey Zigachev 			disp_dlg_regs->dst_y_after_scaler);
1432*b843c749SSergey Zigachev 	DTRACE(
1433*b843c749SSergey Zigachev 			"DLG: %s: disp_dlg_regs->refcyc_x_after_scaler   = 0x%0x",
1434*b843c749SSergey Zigachev 			__func__,
1435*b843c749SSergey Zigachev 			disp_dlg_regs->refcyc_x_after_scaler);
1436*b843c749SSergey Zigachev 
1437*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_prefetch = (unsigned int) (dst_y_prefetch * dml_pow(2, 2));
1438*b843c749SSergey Zigachev 	DTRACE(
1439*b843c749SSergey Zigachev 			"DLG: %s: disp_dlg_regs->dst_y_prefetch  = %d",
1440*b843c749SSergey Zigachev 			__func__,
1441*b843c749SSergey Zigachev 			disp_dlg_regs->dst_y_prefetch);
1442*b843c749SSergey Zigachev 
1443*b843c749SSergey Zigachev 	dst_y_per_vm_vblank = 0.0;
1444*b843c749SSergey Zigachev 	dst_y_per_row_vblank = 0.0;
1445*b843c749SSergey Zigachev 
1446*b843c749SSergey Zigachev 	dst_y_per_vm_vblank = t_vm_us / line_time_in_us;
1447*b843c749SSergey Zigachev 	dst_y_per_vm_vblank = dml_floor(4.0 * (dst_y_per_vm_vblank + 0.125), 1) / 4.0;
1448*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_per_vm_vblank = (unsigned int) (dst_y_per_vm_vblank * dml_pow(2, 2));
1449*b843c749SSergey Zigachev 
1450*b843c749SSergey Zigachev 	dst_y_per_row_vblank = t_r0_us / line_time_in_us;
1451*b843c749SSergey Zigachev 	dst_y_per_row_vblank = dml_floor(4.0 * (dst_y_per_row_vblank + 0.125), 1) / 4.0;
1452*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_per_row_vblank = (unsigned int) (dst_y_per_row_vblank * dml_pow(2, 2));
1453*b843c749SSergey Zigachev 
1454*b843c749SSergey Zigachev 	DTRACE("DLG: %s: lsw_l                   = %d", __func__, lsw_l);
1455*b843c749SSergey Zigachev 	DTRACE("DLG: %s: lsw_c                   = %d", __func__, lsw_c);
1456*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dpte_bytes_per_row_ub_l = %d", __func__, dpte_bytes_per_row_ub_l);
1457*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dpte_bytes_per_row_ub_c = %d", __func__, dpte_bytes_per_row_ub_c);
1458*b843c749SSergey Zigachev 
1459*b843c749SSergey Zigachev 	DTRACE("DLG: %s: prefetch_bw            = %3.2f", __func__, prefetch_bw);
1460*b843c749SSergey Zigachev 	DTRACE("DLG: %s: flip_bw                = %3.2f", __func__, flip_bw);
1461*b843c749SSergey Zigachev 	DTRACE("DLG: %s: t_pre_us               = %3.2f", __func__, t_pre_us);
1462*b843c749SSergey Zigachev 	DTRACE("DLG: %s: t_vm_us                = %3.2f", __func__, t_vm_us);
1463*b843c749SSergey Zigachev 	DTRACE("DLG: %s: t_r0_us                = %3.2f", __func__, t_r0_us);
1464*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_y_per_vm_vblank    = %3.2f", __func__, dst_y_per_vm_vblank);
1465*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_y_per_row_vblank   = %3.2f", __func__, dst_y_per_row_vblank);
1466*b843c749SSergey Zigachev 	DTRACE("DLG: %s: dst_y_prefetch         = %3.2f", __func__, dst_y_prefetch);
1467*b843c749SSergey Zigachev 
1468*b843c749SSergey Zigachev 	min_dst_y_per_vm_vblank = 8.0;
1469*b843c749SSergey Zigachev 	min_dst_y_per_row_vblank = 16.0;
1470*b843c749SSergey Zigachev 	if (htotal <= 75) {
1471*b843c749SSergey Zigachev 		min_vblank = 300;
1472*b843c749SSergey Zigachev 		min_dst_y_per_vm_vblank = 100.0;
1473*b843c749SSergey Zigachev 		min_dst_y_per_row_vblank = 100.0;
1474*b843c749SSergey Zigachev 	}
1475*b843c749SSergey Zigachev 
1476*b843c749SSergey Zigachev 	ASSERT(dst_y_per_vm_vblank < min_dst_y_per_vm_vblank);
1477*b843c749SSergey Zigachev 	ASSERT(dst_y_per_row_vblank < min_dst_y_per_row_vblank);
1478*b843c749SSergey Zigachev 
1479*b843c749SSergey Zigachev 	ASSERT(dst_y_prefetch > (dst_y_per_vm_vblank + dst_y_per_row_vblank));
1480*b843c749SSergey Zigachev 	lsw = dst_y_prefetch - (dst_y_per_vm_vblank + dst_y_per_row_vblank);
1481*b843c749SSergey Zigachev 
1482*b843c749SSergey Zigachev 	DTRACE("DLG: %s: lsw = %3.2f", __func__, lsw);
1483*b843c749SSergey Zigachev 
1484*b843c749SSergey Zigachev 	vratio_pre_l = get_vratio_pre(
1485*b843c749SSergey Zigachev 			mode_lib,
1486*b843c749SSergey Zigachev 			max_num_sw_l,
1487*b843c749SSergey Zigachev 			max_partial_sw_l,
1488*b843c749SSergey Zigachev 			swath_height_l,
1489*b843c749SSergey Zigachev 			max_vinit_l,
1490*b843c749SSergey Zigachev 			lsw);
1491*b843c749SSergey Zigachev 	vratio_pre_c = 1.0;
1492*b843c749SSergey Zigachev 	if (dual_plane)
1493*b843c749SSergey Zigachev 		vratio_pre_c = get_vratio_pre(
1494*b843c749SSergey Zigachev 				mode_lib,
1495*b843c749SSergey Zigachev 				max_num_sw_c,
1496*b843c749SSergey Zigachev 				max_partial_sw_c,
1497*b843c749SSergey Zigachev 				swath_height_c,
1498*b843c749SSergey Zigachev 				max_vinit_c,
1499*b843c749SSergey Zigachev 				lsw);
1500*b843c749SSergey Zigachev 
1501*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vratio_pre_l=%3.2f", __func__, vratio_pre_l);
1502*b843c749SSergey Zigachev 	DTRACE("DLG: %s: vratio_pre_c=%3.2f", __func__, vratio_pre_c);
1503*b843c749SSergey Zigachev 
1504*b843c749SSergey Zigachev 	ASSERT(vratio_pre_l <= 4.0);
1505*b843c749SSergey Zigachev 	if (vratio_pre_l >= 4.0)
1506*b843c749SSergey Zigachev 		disp_dlg_regs->vratio_prefetch = (unsigned int) dml_pow(2, 21) - 1;
1507*b843c749SSergey Zigachev 	else
1508*b843c749SSergey Zigachev 		disp_dlg_regs->vratio_prefetch = (unsigned int) (vratio_pre_l * dml_pow(2, 19));
1509*b843c749SSergey Zigachev 
1510*b843c749SSergey Zigachev 	ASSERT(vratio_pre_c <= 4.0);
1511*b843c749SSergey Zigachev 	if (vratio_pre_c >= 4.0)
1512*b843c749SSergey Zigachev 		disp_dlg_regs->vratio_prefetch_c = (unsigned int) dml_pow(2, 21) - 1;
1513*b843c749SSergey Zigachev 	else
1514*b843c749SSergey Zigachev 		disp_dlg_regs->vratio_prefetch_c = (unsigned int) (vratio_pre_c * dml_pow(2, 19));
1515*b843c749SSergey Zigachev 
1516*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_pte_group_vblank_l =
1517*b843c749SSergey Zigachev 			(unsigned int) (dst_y_per_row_vblank * (double) htotal
1518*b843c749SSergey Zigachev 					* ref_freq_to_pix_freq / (double) dpte_groups_per_row_ub_l);
1519*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_per_pte_group_vblank_l < (unsigned int) dml_pow(2, 13));
1520*b843c749SSergey Zigachev 
1521*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_pte_group_vblank_c =
1522*b843c749SSergey Zigachev 			(unsigned int) (dst_y_per_row_vblank * (double) htotal
1523*b843c749SSergey Zigachev 					* ref_freq_to_pix_freq / (double) dpte_groups_per_row_ub_c);
1524*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_per_pte_group_vblank_c < (unsigned int) dml_pow(2, 13));
1525*b843c749SSergey Zigachev 
1526*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_meta_chunk_vblank_l =
1527*b843c749SSergey Zigachev 			(unsigned int) (dst_y_per_row_vblank * (double) htotal
1528*b843c749SSergey Zigachev 					* ref_freq_to_pix_freq / (double) meta_chunks_per_row_ub_l);
1529*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_per_meta_chunk_vblank_l < (unsigned int) dml_pow(2, 13));
1530*b843c749SSergey Zigachev 
1531*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_meta_chunk_vblank_c =
1532*b843c749SSergey Zigachev 			disp_dlg_regs->refcyc_per_meta_chunk_vblank_l;/* dcc for 4:2:0 is not supported in dcn1.0.  assigned to be the same as _l for now */
1533*b843c749SSergey Zigachev 
1534*b843c749SSergey Zigachev 	/* Active */
1535*b843c749SSergey Zigachev 	req_per_swath_ub_l = rq_dlg_param.rq_l.req_per_swath_ub;
1536*b843c749SSergey Zigachev 	req_per_swath_ub_c = rq_dlg_param.rq_c.req_per_swath_ub;
1537*b843c749SSergey Zigachev 	meta_row_height_l = rq_dlg_param.rq_l.meta_row_height;
1538*b843c749SSergey Zigachev 	swath_width_pixels_ub_l = 0;
1539*b843c749SSergey Zigachev 	swath_width_pixels_ub_c = 0;
1540*b843c749SSergey Zigachev 	scaler_rec_in_width_l = 0;
1541*b843c749SSergey Zigachev 	scaler_rec_in_width_c = 0;
1542*b843c749SSergey Zigachev 	dpte_row_height_l = rq_dlg_param.rq_l.dpte_row_height;
1543*b843c749SSergey Zigachev 	dpte_row_height_c = rq_dlg_param.rq_c.dpte_row_height;
1544*b843c749SSergey Zigachev 
1545*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_per_pte_row_nom_l = (unsigned int) ((double) dpte_row_height_l
1546*b843c749SSergey Zigachev 			/ (double) vratio_l * dml_pow(2, 2));
1547*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->dst_y_per_pte_row_nom_l < (unsigned int) dml_pow(2, 17));
1548*b843c749SSergey Zigachev 
1549*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_per_pte_row_nom_c = (unsigned int) ((double) dpte_row_height_c
1550*b843c749SSergey Zigachev 			/ (double) vratio_c * dml_pow(2, 2));
1551*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->dst_y_per_pte_row_nom_c < (unsigned int) dml_pow(2, 17));
1552*b843c749SSergey Zigachev 
1553*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_per_meta_row_nom_l = (unsigned int) ((double) meta_row_height_l
1554*b843c749SSergey Zigachev 			/ (double) vratio_l * dml_pow(2, 2));
1555*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->dst_y_per_meta_row_nom_l < (unsigned int) dml_pow(2, 17));
1556*b843c749SSergey Zigachev 
1557*b843c749SSergey Zigachev 	disp_dlg_regs->dst_y_per_meta_row_nom_c = disp_dlg_regs->dst_y_per_meta_row_nom_l; /* dcc for 4:2:0 is not supported in dcn1.0.  assigned to be the same as _l for now */
1558*b843c749SSergey Zigachev 
1559*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_pte_group_nom_l = (unsigned int) ((double) dpte_row_height_l
1560*b843c749SSergey Zigachev 			/ (double) vratio_l * (double) htotal * ref_freq_to_pix_freq
1561*b843c749SSergey Zigachev 			/ (double) dpte_groups_per_row_ub_l);
1562*b843c749SSergey Zigachev 	if (disp_dlg_regs->refcyc_per_pte_group_nom_l >= (unsigned int) dml_pow(2, 23))
1563*b843c749SSergey Zigachev 		disp_dlg_regs->refcyc_per_pte_group_nom_l = dml_pow(2, 23) - 1;
1564*b843c749SSergey Zigachev 
1565*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_pte_group_nom_c = (unsigned int) ((double) dpte_row_height_c
1566*b843c749SSergey Zigachev 			/ (double) vratio_c * (double) htotal * ref_freq_to_pix_freq
1567*b843c749SSergey Zigachev 			/ (double) dpte_groups_per_row_ub_c);
1568*b843c749SSergey Zigachev 	if (disp_dlg_regs->refcyc_per_pte_group_nom_c >= (unsigned int) dml_pow(2, 23))
1569*b843c749SSergey Zigachev 		disp_dlg_regs->refcyc_per_pte_group_nom_c = dml_pow(2, 23) - 1;
1570*b843c749SSergey Zigachev 
1571*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_meta_chunk_nom_l = (unsigned int) ((double) meta_row_height_l
1572*b843c749SSergey Zigachev 			/ (double) vratio_l * (double) htotal * ref_freq_to_pix_freq
1573*b843c749SSergey Zigachev 			/ (double) meta_chunks_per_row_ub_l);
1574*b843c749SSergey Zigachev 	if (disp_dlg_regs->refcyc_per_meta_chunk_nom_l >= (unsigned int) dml_pow(2, 23))
1575*b843c749SSergey Zigachev 		disp_dlg_regs->refcyc_per_meta_chunk_nom_l = dml_pow(2, 23) - 1;
1576*b843c749SSergey Zigachev 
1577*b843c749SSergey Zigachev 	if (mode_422) {
1578*b843c749SSergey Zigachev 		swath_width_pixels_ub_l = swath_width_ub_l * 2; /* *2 for 2 pixel per element */
1579*b843c749SSergey Zigachev 		swath_width_pixels_ub_c = swath_width_ub_c * 2;
1580*b843c749SSergey Zigachev 	} else {
1581*b843c749SSergey Zigachev 		swath_width_pixels_ub_l = swath_width_ub_l * 1;
1582*b843c749SSergey Zigachev 		swath_width_pixels_ub_c = swath_width_ub_c * 1;
1583*b843c749SSergey Zigachev 	}
1584*b843c749SSergey Zigachev 
1585*b843c749SSergey Zigachev 	hscale_pixel_rate_l = 0.;
1586*b843c749SSergey Zigachev 	hscale_pixel_rate_c = 0.;
1587*b843c749SSergey Zigachev 	min_hratio_fact_l = 1.0;
1588*b843c749SSergey Zigachev 	min_hratio_fact_c = 1.0;
1589*b843c749SSergey Zigachev 
1590*b843c749SSergey Zigachev 	if (htaps_l <= 1)
1591*b843c749SSergey Zigachev 		min_hratio_fact_l = 2.0;
1592*b843c749SSergey Zigachev 	else if (htaps_l <= 6) {
1593*b843c749SSergey Zigachev 		if ((hratios_l * 2.0) > 4.0)
1594*b843c749SSergey Zigachev 			min_hratio_fact_l = 4.0;
1595*b843c749SSergey Zigachev 		else
1596*b843c749SSergey Zigachev 			min_hratio_fact_l = hratios_l * 2.0;
1597*b843c749SSergey Zigachev 	} else {
1598*b843c749SSergey Zigachev 		if (hratios_l > 4.0)
1599*b843c749SSergey Zigachev 			min_hratio_fact_l = 4.0;
1600*b843c749SSergey Zigachev 		else
1601*b843c749SSergey Zigachev 			min_hratio_fact_l = hratios_l;
1602*b843c749SSergey Zigachev 	}
1603*b843c749SSergey Zigachev 
1604*b843c749SSergey Zigachev 	hscale_pixel_rate_l = min_hratio_fact_l * dppclk_freq_in_mhz;
1605*b843c749SSergey Zigachev 
1606*b843c749SSergey Zigachev 	if (htaps_c <= 1)
1607*b843c749SSergey Zigachev 		min_hratio_fact_c = 2.0;
1608*b843c749SSergey Zigachev 	else if (htaps_c <= 6) {
1609*b843c749SSergey Zigachev 		if ((hratios_c * 2.0) > 4.0)
1610*b843c749SSergey Zigachev 			min_hratio_fact_c = 4.0;
1611*b843c749SSergey Zigachev 		else
1612*b843c749SSergey Zigachev 			min_hratio_fact_c = hratios_c * 2.0;
1613*b843c749SSergey Zigachev 	} else {
1614*b843c749SSergey Zigachev 		if (hratios_c > 4.0)
1615*b843c749SSergey Zigachev 			min_hratio_fact_c = 4.0;
1616*b843c749SSergey Zigachev 		else
1617*b843c749SSergey Zigachev 			min_hratio_fact_c = hratios_c;
1618*b843c749SSergey Zigachev 	}
1619*b843c749SSergey Zigachev 
1620*b843c749SSergey Zigachev 	hscale_pixel_rate_c = min_hratio_fact_c * dppclk_freq_in_mhz;
1621*b843c749SSergey Zigachev 
1622*b843c749SSergey Zigachev 	refcyc_per_line_delivery_pre_l = 0.;
1623*b843c749SSergey Zigachev 	refcyc_per_line_delivery_pre_c = 0.;
1624*b843c749SSergey Zigachev 	refcyc_per_line_delivery_l = 0.;
1625*b843c749SSergey Zigachev 	refcyc_per_line_delivery_c = 0.;
1626*b843c749SSergey Zigachev 
1627*b843c749SSergey Zigachev 	refcyc_per_req_delivery_pre_l = 0.;
1628*b843c749SSergey Zigachev 	refcyc_per_req_delivery_pre_c = 0.;
1629*b843c749SSergey Zigachev 	refcyc_per_req_delivery_l = 0.;
1630*b843c749SSergey Zigachev 	refcyc_per_req_delivery_c = 0.;
1631*b843c749SSergey Zigachev 	refcyc_per_req_delivery_pre_cur0 = 0.;
1632*b843c749SSergey Zigachev 	refcyc_per_req_delivery_cur0 = 0.;
1633*b843c749SSergey Zigachev 
1634*b843c749SSergey Zigachev 	full_recout_width = 0;
1635*b843c749SSergey Zigachev 	if (e2e_pipe_param.pipe.src.is_hsplit) {
1636*b843c749SSergey Zigachev 		if (e2e_pipe_param.pipe.dest.full_recout_width == 0) {
1637*b843c749SSergey Zigachev 			DTRACE("DLG: %s: Warningfull_recout_width not set in hsplit mode", __func__);
1638*b843c749SSergey Zigachev 			full_recout_width = e2e_pipe_param.pipe.dest.recout_width * 2; /* assume half split for dcn1 */
1639*b843c749SSergey Zigachev 		} else
1640*b843c749SSergey Zigachev 			full_recout_width = e2e_pipe_param.pipe.dest.full_recout_width;
1641*b843c749SSergey Zigachev 	} else
1642*b843c749SSergey Zigachev 		full_recout_width = e2e_pipe_param.pipe.dest.recout_width;
1643*b843c749SSergey Zigachev 
1644*b843c749SSergey Zigachev 	refcyc_per_line_delivery_pre_l = get_refcyc_per_delivery(
1645*b843c749SSergey Zigachev 			mode_lib,
1646*b843c749SSergey Zigachev 			refclk_freq_in_mhz,
1647*b843c749SSergey Zigachev 			pclk_freq_in_mhz,
1648*b843c749SSergey Zigachev 			full_recout_width,
1649*b843c749SSergey Zigachev 			vratio_pre_l,
1650*b843c749SSergey Zigachev 			hscale_pixel_rate_l,
1651*b843c749SSergey Zigachev 			swath_width_pixels_ub_l,
1652*b843c749SSergey Zigachev 			1); /* per line */
1653*b843c749SSergey Zigachev 
1654*b843c749SSergey Zigachev 	refcyc_per_line_delivery_l = get_refcyc_per_delivery(
1655*b843c749SSergey Zigachev 			mode_lib,
1656*b843c749SSergey Zigachev 			refclk_freq_in_mhz,
1657*b843c749SSergey Zigachev 			pclk_freq_in_mhz,
1658*b843c749SSergey Zigachev 			full_recout_width,
1659*b843c749SSergey Zigachev 			vratio_l,
1660*b843c749SSergey Zigachev 			hscale_pixel_rate_l,
1661*b843c749SSergey Zigachev 			swath_width_pixels_ub_l,
1662*b843c749SSergey Zigachev 			1); /* per line */
1663*b843c749SSergey Zigachev 
1664*b843c749SSergey Zigachev 	DTRACE("DLG: %s: full_recout_width              = %d", __func__, full_recout_width);
1665*b843c749SSergey Zigachev 	DTRACE("DLG: %s: hscale_pixel_rate_l            = %3.2f", __func__, hscale_pixel_rate_l);
1666*b843c749SSergey Zigachev 	DTRACE(
1667*b843c749SSergey Zigachev 			"DLG: %s: refcyc_per_line_delivery_pre_l = %3.2f",
1668*b843c749SSergey Zigachev 			__func__,
1669*b843c749SSergey Zigachev 			refcyc_per_line_delivery_pre_l);
1670*b843c749SSergey Zigachev 	DTRACE(
1671*b843c749SSergey Zigachev 			"DLG: %s: refcyc_per_line_delivery_l     = %3.2f",
1672*b843c749SSergey Zigachev 			__func__,
1673*b843c749SSergey Zigachev 			refcyc_per_line_delivery_l);
1674*b843c749SSergey Zigachev 
1675*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_line_delivery_pre_l = (unsigned int) dml_floor(
1676*b843c749SSergey Zigachev 			refcyc_per_line_delivery_pre_l,
1677*b843c749SSergey Zigachev 			1);
1678*b843c749SSergey Zigachev 	disp_dlg_regs->refcyc_per_line_delivery_l = (unsigned int) dml_floor(
1679*b843c749SSergey Zigachev 			refcyc_per_line_delivery_l,
1680*b843c749SSergey Zigachev 			1);
1681*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_per_line_delivery_pre_l < (unsigned int) dml_pow(2, 13));
1682*b843c749SSergey Zigachev 	ASSERT(disp_dlg_regs->refcyc_per_line_delivery_l < (unsigned int) dml_pow(2, 13));
1683*b843c749SSergey Zigachev 
1684*b843c749SSergey Zigachev 	if (dual_plane) {
1685*b843c749SSergey Zigachev 		refcyc_per_line_delivery_pre_c = get_refcyc_per_delivery(
1686*b843c749SSergey Zigachev 				mode_lib,
1687*b843c749SSergey Zigachev 				refclk_freq_in_mhz,
1688*b843c749SSergey Zigachev 				pclk_freq_in_mhz,
1689*b843c749SSergey Zigachev 				full_recout_width,
1690*b843c749SSergey Zigachev 				vratio_pre_c,
1691*b843c749SSergey Zigachev 				hscale_pixel_rate_c,
1692*b843c749SSergey Zigachev 				swath_width_pixels_ub_c,
1693*b843c749SSergey Zigachev 				1); /* per line */
1694*b843c749SSergey Zigachev 
1695*b843c749SSergey Zigachev 		refcyc_per_line_delivery_c = get_refcyc_per_delivery(
1696*b843c749SSergey Zigachev 				mode_lib,
1697*b843c749SSergey Zigachev 				refclk_freq_in_mhz,
1698*b843c749SSergey Zigachev 				pclk_freq_in_mhz,
1699*b843c749SSergey Zigachev 				full_recout_width,
1700*b843c749SSergey Zigachev 				vratio_c,
1701*b843c749SSergey Zigachev 				hscale_pixel_rate_c,
1702*b843c749SSergey Zigachev 				swath_width_pixels_ub_c,
1703*b843c749SSergey Zigachev 				1); /* per line */
1704*b843c749SSergey Zigachev 
1705*b843c749SSergey Zigachev 		DTRACE(
1706*b843c749SSergey Zigachev 				"DLG: %s: refcyc_per_line_delivery_pre_c = %3.2f",
1707*b843c749SSergey Zigachev 				__func__,
1708*b843c749SSergey Zigachev 				refcyc_per_line_delivery_pre_c);
1709*b843c749SSergey Zigachev 		DTRACE(
1710*b843c749SSergey Zigachev 				"DLG: %s: refcyc_per_line_delivery_c     = %3.2f",
1711*b843c749SSergey Zigachev 				__func__,
1712*b843c749SSergey Zigachev 				refcyc_per_line_delivery_c);
1713*b843c749SSergey Zigachev 
1714*b843c749SSergey Zigachev 		disp_dlg_regs->refcyc_per_line_delivery_pre_c = (unsigned int) dml_floor(
1715*b843c749SSergey Zigachev 				refcyc_per_line_delivery_pre_c,
1716*b843c749SSergey Zigachev 				1);
1717*b843c749SSergey Zigachev 		disp_dlg_regs->refcyc_per_line_delivery_c = (unsigned int) dml_floor(
1718*b843c749SSergey Zigachev 				refcyc_per_line_delivery_c,
1719*b843c749SSergey Zigachev 				1);
1720*b843c749SSergey Zigachev 		ASSERT(disp_dlg_regs->refcyc_per_line_delivery_pre_c < (unsigned int) dml_pow(2, 13));
1721*b843c749SSergey Zigachev 		ASSERT(disp_dlg_regs->refcyc_per_line_delivery_c < (unsigned int) dml_pow(2, 13));
1722*b843c749SSergey Zigachev 	}
1723*b843c749SSergey Zigachev 	disp_dlg_regs->chunk_hdl_adjust_cur0 = 3;
1724*b843c749SSergey Zigachev 
1725*b843c749SSergey Zigachev 	/* TTU - Luma / Chroma */
1726*b843c749SSergey Zigachev 	if (access_dir) { /* vertical access */
1727*b843c749SSergey Zigachev 		scaler_rec_in_width_l = vp_height_l;
1728*b843c749SSergey Zigachev 		scaler_rec_in_width_c = vp_height_c;
1729*b843c749SSergey Zigachev 	} else {
1730*b843c749SSergey Zigachev 		scaler_rec_in_width_l = vp_width_l;
1731*b843c749SSergey Zigachev 		scaler_rec_in_width_c = vp_width_c;
1732*b843c749SSergey Zigachev 	}
1733*b843c749SSergey Zigachev 
1734*b843c749SSergey Zigachev 	refcyc_per_req_delivery_pre_l = get_refcyc_per_delivery(
1735*b843c749SSergey Zigachev 			mode_lib,
1736*b843c749SSergey Zigachev 			refclk_freq_in_mhz,
1737*b843c749SSergey Zigachev 			pclk_freq_in_mhz,
1738*b843c749SSergey Zigachev 			full_recout_width,
1739*b843c749SSergey Zigachev 			vratio_pre_l,
1740*b843c749SSergey Zigachev 			hscale_pixel_rate_l,
1741*b843c749SSergey Zigachev 			scaler_rec_in_width_l,
1742*b843c749SSergey Zigachev 			req_per_swath_ub_l); /* per req */
1743*b843c749SSergey Zigachev 	refcyc_per_req_delivery_l = get_refcyc_per_delivery(
1744*b843c749SSergey Zigachev 			mode_lib,
1745*b843c749SSergey Zigachev 			refclk_freq_in_mhz,
1746*b843c749SSergey Zigachev 			pclk_freq_in_mhz,
1747*b843c749SSergey Zigachev 			full_recout_width,
1748*b843c749SSergey Zigachev 			vratio_l,
1749*b843c749SSergey Zigachev 			hscale_pixel_rate_l,
1750*b843c749SSergey Zigachev 			scaler_rec_in_width_l,
1751*b843c749SSergey Zigachev 			req_per_swath_ub_l); /* per req */
1752*b843c749SSergey Zigachev 
1753*b843c749SSergey Zigachev 	DTRACE(
1754*b843c749SSergey Zigachev 			"DLG: %s: refcyc_per_req_delivery_pre_l = %3.2f",
1755*b843c749SSergey Zigachev 			__func__,
1756*b843c749SSergey Zigachev 			refcyc_per_req_delivery_pre_l);
1757*b843c749SSergey Zigachev 	DTRACE(
1758*b843c749SSergey Zigachev 			"DLG: %s: refcyc_per_req_delivery_l     = %3.2f",
1759*b843c749SSergey Zigachev 			__func__,
1760*b843c749SSergey Zigachev 			refcyc_per_req_delivery_l);
1761*b843c749SSergey Zigachev 
1762*b843c749SSergey Zigachev 	disp_ttu_regs->refcyc_per_req_delivery_pre_l = (unsigned int) (refcyc_per_req_delivery_pre_l
1763*b843c749SSergey Zigachev 			* dml_pow(2, 10));
1764*b843c749SSergey Zigachev 	disp_ttu_regs->refcyc_per_req_delivery_l = (unsigned int) (refcyc_per_req_delivery_l
1765*b843c749SSergey Zigachev 			* dml_pow(2, 10));
1766*b843c749SSergey Zigachev 
1767*b843c749SSergey Zigachev 	ASSERT(refcyc_per_req_delivery_pre_l < dml_pow(2, 13));
1768*b843c749SSergey Zigachev 	ASSERT(refcyc_per_req_delivery_l < dml_pow(2, 13));
1769*b843c749SSergey Zigachev 
1770*b843c749SSergey Zigachev 	if (dual_plane) {
1771*b843c749SSergey Zigachev 		refcyc_per_req_delivery_pre_c = get_refcyc_per_delivery(
1772*b843c749SSergey Zigachev 				mode_lib,
1773*b843c749SSergey Zigachev 				refclk_freq_in_mhz,
1774*b843c749SSergey Zigachev 				pclk_freq_in_mhz,
1775*b843c749SSergey Zigachev 				full_recout_width,
1776*b843c749SSergey Zigachev 				vratio_pre_c,
1777*b843c749SSergey Zigachev 				hscale_pixel_rate_c,
1778*b843c749SSergey Zigachev 				scaler_rec_in_width_c,
1779*b843c749SSergey Zigachev 				req_per_swath_ub_c); /* per req  */
1780*b843c749SSergey Zigachev 		refcyc_per_req_delivery_c = get_refcyc_per_delivery(
1781*b843c749SSergey Zigachev 				mode_lib,
1782*b843c749SSergey Zigachev 				refclk_freq_in_mhz,
1783*b843c749SSergey Zigachev 				pclk_freq_in_mhz,
1784*b843c749SSergey Zigachev 				full_recout_width,
1785*b843c749SSergey Zigachev 				vratio_c,
1786*b843c749SSergey Zigachev 				hscale_pixel_rate_c,
1787*b843c749SSergey Zigachev 				scaler_rec_in_width_c,
1788*b843c749SSergey Zigachev 				req_per_swath_ub_c); /* per req */
1789*b843c749SSergey Zigachev 
1790*b843c749SSergey Zigachev 		DTRACE(
1791*b843c749SSergey Zigachev 				"DLG: %s: refcyc_per_req_delivery_pre_c = %3.2f",
1792*b843c749SSergey Zigachev 				__func__,
1793*b843c749SSergey Zigachev 				refcyc_per_req_delivery_pre_c);
1794*b843c749SSergey Zigachev 		DTRACE(
1795*b843c749SSergey Zigachev 				"DLG: %s: refcyc_per_req_delivery_c     = %3.2f",
1796*b843c749SSergey Zigachev 				__func__,
1797*b843c749SSergey Zigachev 				refcyc_per_req_delivery_c);
1798*b843c749SSergey Zigachev 
1799*b843c749SSergey Zigachev 		disp_ttu_regs->refcyc_per_req_delivery_pre_c =
1800*b843c749SSergey Zigachev 				(unsigned int) (refcyc_per_req_delivery_pre_c * dml_pow(2, 10));
1801*b843c749SSergey Zigachev 		disp_ttu_regs->refcyc_per_req_delivery_c = (unsigned int) (refcyc_per_req_delivery_c
1802*b843c749SSergey Zigachev 				* dml_pow(2, 10));
1803*b843c749SSergey Zigachev 
1804*b843c749SSergey Zigachev 		ASSERT(refcyc_per_req_delivery_pre_c < dml_pow(2, 13));
1805*b843c749SSergey Zigachev 		ASSERT(refcyc_per_req_delivery_c < dml_pow(2, 13));
1806*b843c749SSergey Zigachev 	}
1807*b843c749SSergey Zigachev 
1808*b843c749SSergey Zigachev 	/* TTU - Cursor */
1809*b843c749SSergey Zigachev 	hratios_cur0 = e2e_pipe_param.pipe.scale_ratio_depth.hscl_ratio;
1810*b843c749SSergey Zigachev 	cur0_src_width = e2e_pipe_param.pipe.src.cur0_src_width; /* cursor source width */
1811*b843c749SSergey Zigachev 	cur0_bpp = (enum cursor_bpp) e2e_pipe_param.pipe.src.cur0_bpp;
1812*b843c749SSergey Zigachev 	cur0_req_size = 0;
1813*b843c749SSergey Zigachev 	cur0_req_width = 0;
1814*b843c749SSergey Zigachev 	cur0_width_ub = 0.0;
1815*b843c749SSergey Zigachev 	cur0_req_per_width = 0.0;
1816*b843c749SSergey Zigachev 	hactive_cur0 = 0.0;
1817*b843c749SSergey Zigachev 
1818*b843c749SSergey Zigachev 	ASSERT(cur0_src_width <= 256);
1819*b843c749SSergey Zigachev 
1820*b843c749SSergey Zigachev 	if (cur0_src_width > 0) {
1821*b843c749SSergey Zigachev 		unsigned int cur0_bit_per_pixel = 0;
1822*b843c749SSergey Zigachev 
1823*b843c749SSergey Zigachev 		if (cur0_bpp == dm_cur_2bit) {
1824*b843c749SSergey Zigachev 			cur0_req_size = 64; /* byte */
1825*b843c749SSergey Zigachev 			cur0_bit_per_pixel = 2;
1826*b843c749SSergey Zigachev 		} else { /* 32bit */
1827*b843c749SSergey Zigachev 			cur0_bit_per_pixel = 32;
1828*b843c749SSergey Zigachev 			if (cur0_src_width >= 1 && cur0_src_width <= 16)
1829*b843c749SSergey Zigachev 				cur0_req_size = 64;
1830*b843c749SSergey Zigachev 			else if (cur0_src_width >= 17 && cur0_src_width <= 31)
1831*b843c749SSergey Zigachev 				cur0_req_size = 128;
1832*b843c749SSergey Zigachev 			else
1833*b843c749SSergey Zigachev 				cur0_req_size = 256;
1834*b843c749SSergey Zigachev 		}
1835*b843c749SSergey Zigachev 
1836*b843c749SSergey Zigachev 		cur0_req_width = (double) cur0_req_size / ((double) cur0_bit_per_pixel / 8.0);
1837*b843c749SSergey Zigachev 		cur0_width_ub = dml_ceil((double) cur0_src_width / (double) cur0_req_width, 1)
1838*b843c749SSergey Zigachev 				* (double) cur0_req_width;
1839*b843c749SSergey Zigachev 		cur0_req_per_width = cur0_width_ub / (double) cur0_req_width;
1840*b843c749SSergey Zigachev 		hactive_cur0 = (double) cur0_src_width / hratios_cur0; /* FIXME: oswin to think about what to do for cursor */
1841*b843c749SSergey Zigachev 
1842*b843c749SSergey Zigachev 		if (vratio_pre_l <= 1.0) {
1843*b843c749SSergey Zigachev 			refcyc_per_req_delivery_pre_cur0 = hactive_cur0 * ref_freq_to_pix_freq
1844*b843c749SSergey Zigachev 					/ (double) cur0_req_per_width;
1845*b843c749SSergey Zigachev 		} else {
1846*b843c749SSergey Zigachev 			refcyc_per_req_delivery_pre_cur0 = (double) refclk_freq_in_mhz
1847*b843c749SSergey Zigachev 					* (double) cur0_src_width / hscale_pixel_rate_l
1848*b843c749SSergey Zigachev 					/ (double) cur0_req_per_width;
1849*b843c749SSergey Zigachev 		}
1850*b843c749SSergey Zigachev 
1851*b843c749SSergey Zigachev 		disp_ttu_regs->refcyc_per_req_delivery_pre_cur0 =
1852*b843c749SSergey Zigachev 				(unsigned int) (refcyc_per_req_delivery_pre_cur0 * dml_pow(2, 10));
1853*b843c749SSergey Zigachev 		ASSERT(refcyc_per_req_delivery_pre_cur0 < dml_pow(2, 13));
1854*b843c749SSergey Zigachev 
1855*b843c749SSergey Zigachev 		if (vratio_l <= 1.0) {
1856*b843c749SSergey Zigachev 			refcyc_per_req_delivery_cur0 = hactive_cur0 * ref_freq_to_pix_freq
1857*b843c749SSergey Zigachev 					/ (double) cur0_req_per_width;
1858*b843c749SSergey Zigachev 		} else {
1859*b843c749SSergey Zigachev 			refcyc_per_req_delivery_cur0 = (double) refclk_freq_in_mhz
1860*b843c749SSergey Zigachev 					* (double) cur0_src_width / hscale_pixel_rate_l
1861*b843c749SSergey Zigachev 					/ (double) cur0_req_per_width;
1862*b843c749SSergey Zigachev 		}
1863*b843c749SSergey Zigachev 
1864*b843c749SSergey Zigachev 		DTRACE("DLG: %s: cur0_req_width                     = %d", __func__, cur0_req_width);
1865*b843c749SSergey Zigachev 		DTRACE(
1866*b843c749SSergey Zigachev 				"DLG: %s: cur0_width_ub                      = %3.2f",
1867*b843c749SSergey Zigachev 				__func__,
1868*b843c749SSergey Zigachev 				cur0_width_ub);
1869*b843c749SSergey Zigachev 		DTRACE(
1870*b843c749SSergey Zigachev 				"DLG: %s: cur0_req_per_width                 = %3.2f",
1871*b843c749SSergey Zigachev 				__func__,
1872*b843c749SSergey Zigachev 				cur0_req_per_width);
1873*b843c749SSergey Zigachev 		DTRACE(
1874*b843c749SSergey Zigachev 				"DLG: %s: hactive_cur0                       = %3.2f",
1875*b843c749SSergey Zigachev 				__func__,
1876*b843c749SSergey Zigachev 				hactive_cur0);
1877*b843c749SSergey Zigachev 		DTRACE(
1878*b843c749SSergey Zigachev 				"DLG: %s: refcyc_per_req_delivery_pre_cur0   = %3.2f",
1879*b843c749SSergey Zigachev 				__func__,
1880*b843c749SSergey Zigachev 				refcyc_per_req_delivery_pre_cur0);
1881*b843c749SSergey Zigachev 		DTRACE(
1882*b843c749SSergey Zigachev 				"DLG: %s: refcyc_per_req_delivery_cur0       = %3.2f",
1883*b843c749SSergey Zigachev 				__func__,
1884*b843c749SSergey Zigachev 				refcyc_per_req_delivery_cur0);
1885*b843c749SSergey Zigachev 
1886*b843c749SSergey Zigachev 		disp_ttu_regs->refcyc_per_req_delivery_cur0 =
1887*b843c749SSergey Zigachev 				(unsigned int) (refcyc_per_req_delivery_cur0 * dml_pow(2, 10));
1888*b843c749SSergey Zigachev 		ASSERT(refcyc_per_req_delivery_cur0 < dml_pow(2, 13));
1889*b843c749SSergey Zigachev 	} else {
1890*b843c749SSergey Zigachev 		disp_ttu_regs->refcyc_per_req_delivery_pre_cur0 = 0;
1891*b843c749SSergey Zigachev 		disp_ttu_regs->refcyc_per_req_delivery_cur0 = 0;
1892*b843c749SSergey Zigachev 	}
1893*b843c749SSergey Zigachev 
1894*b843c749SSergey Zigachev 	/* TTU - Misc */
1895*b843c749SSergey Zigachev 	disp_ttu_regs->qos_level_low_wm = 0;
1896*b843c749SSergey Zigachev 	ASSERT(disp_ttu_regs->qos_level_low_wm < dml_pow(2, 14));
1897*b843c749SSergey Zigachev 	disp_ttu_regs->qos_level_high_wm = (unsigned int) (4.0 * (double) htotal
1898*b843c749SSergey Zigachev 			* ref_freq_to_pix_freq);
1899*b843c749SSergey Zigachev 	ASSERT(disp_ttu_regs->qos_level_high_wm < dml_pow(2, 14));
1900*b843c749SSergey Zigachev 
1901*b843c749SSergey Zigachev 	disp_ttu_regs->qos_level_flip = 14;
1902*b843c749SSergey Zigachev 	disp_ttu_regs->qos_level_fixed_l = 8;
1903*b843c749SSergey Zigachev 	disp_ttu_regs->qos_level_fixed_c = 8;
1904*b843c749SSergey Zigachev 	disp_ttu_regs->qos_level_fixed_cur0 = 8;
1905*b843c749SSergey Zigachev 	disp_ttu_regs->qos_ramp_disable_l = 0;
1906*b843c749SSergey Zigachev 	disp_ttu_regs->qos_ramp_disable_c = 0;
1907*b843c749SSergey Zigachev 	disp_ttu_regs->qos_ramp_disable_cur0 = 0;
1908*b843c749SSergey Zigachev 
1909*b843c749SSergey Zigachev 	disp_ttu_regs->min_ttu_vblank = min_ttu_vblank * refclk_freq_in_mhz;
1910*b843c749SSergey Zigachev 	ASSERT(disp_ttu_regs->min_ttu_vblank < dml_pow(2, 24));
1911*b843c749SSergey Zigachev 
1912*b843c749SSergey Zigachev 	print__ttu_regs_st(mode_lib, *disp_ttu_regs);
1913*b843c749SSergey Zigachev 	print__dlg_regs_st(mode_lib, *disp_dlg_regs);
1914*b843c749SSergey Zigachev }
1915