1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2012-16 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev  *
4b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10b843c749SSergey Zigachev  *
11b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13b843c749SSergey Zigachev  *
14b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21b843c749SSergey Zigachev  *
22b843c749SSergey Zigachev  * Authors: AMD
23b843c749SSergey Zigachev  *
24b843c749SSergey Zigachev  */
25b843c749SSergey Zigachev #include "dm_services.h"
26b843c749SSergey Zigachev 
27b843c749SSergey Zigachev #include "dce/dce_11_0_d.h"
28b843c749SSergey Zigachev #include "dce/dce_11_0_sh_mask.h"
29b843c749SSergey Zigachev /* TODO: this needs to be looked at, used by Stella's workaround*/
30b843c749SSergey Zigachev #include "gmc/gmc_8_2_d.h"
31b843c749SSergey Zigachev #include "gmc/gmc_8_2_sh_mask.h"
32b843c749SSergey Zigachev 
33b843c749SSergey Zigachev #include "include/logger_interface.h"
34b843c749SSergey Zigachev #include "inc/dce_calcs.h"
35b843c749SSergey Zigachev 
36b843c749SSergey Zigachev #include "dce/dce_mem_input.h"
37b843c749SSergey Zigachev 
38*78973132SSergey Zigachev #include "dce110/dce110_mem_input_v.h"
39*78973132SSergey Zigachev 
set_flip_control(struct dce_mem_input * mem_input110,bool immediate)40b843c749SSergey Zigachev static void set_flip_control(
41b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
42b843c749SSergey Zigachev 	bool immediate)
43b843c749SSergey Zigachev {
44b843c749SSergey Zigachev 	uint32_t value = 0;
45b843c749SSergey Zigachev 
46b843c749SSergey Zigachev 	value = dm_read_reg(
47b843c749SSergey Zigachev 			mem_input110->base.ctx,
48b843c749SSergey Zigachev 			mmUNP_FLIP_CONTROL);
49b843c749SSergey Zigachev 
50b843c749SSergey Zigachev 	set_reg_field_value(value, 1,
51b843c749SSergey Zigachev 			UNP_FLIP_CONTROL,
52b843c749SSergey Zigachev 			GRPH_SURFACE_UPDATE_PENDING_MODE);
53b843c749SSergey Zigachev 
54b843c749SSergey Zigachev 	dm_write_reg(
55b843c749SSergey Zigachev 			mem_input110->base.ctx,
56b843c749SSergey Zigachev 			mmUNP_FLIP_CONTROL,
57b843c749SSergey Zigachev 			value);
58b843c749SSergey Zigachev }
59b843c749SSergey Zigachev 
60b843c749SSergey Zigachev /* chroma part */
program_pri_addr_c(struct dce_mem_input * mem_input110,PHYSICAL_ADDRESS_LOC address)61b843c749SSergey Zigachev static void program_pri_addr_c(
62b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
63b843c749SSergey Zigachev 	PHYSICAL_ADDRESS_LOC address)
64b843c749SSergey Zigachev {
65b843c749SSergey Zigachev 	uint32_t value = 0;
66b843c749SSergey Zigachev 	uint32_t temp = 0;
67b843c749SSergey Zigachev 	/*high register MUST be programmed first*/
68b843c749SSergey Zigachev 	temp = address.high_part &
69b843c749SSergey Zigachev UNP_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_C__GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_C_MASK;
70b843c749SSergey Zigachev 
71b843c749SSergey Zigachev 	set_reg_field_value(value, temp,
72b843c749SSergey Zigachev 		UNP_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_C,
73b843c749SSergey Zigachev 		GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_C);
74b843c749SSergey Zigachev 
75b843c749SSergey Zigachev 	dm_write_reg(
76b843c749SSergey Zigachev 		mem_input110->base.ctx,
77b843c749SSergey Zigachev 		mmUNP_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_C,
78b843c749SSergey Zigachev 		value);
79b843c749SSergey Zigachev 
80b843c749SSergey Zigachev 	temp = 0;
81b843c749SSergey Zigachev 	value = 0;
82b843c749SSergey Zigachev 	temp = address.low_part >>
83b843c749SSergey Zigachev 	UNP_GRPH_PRIMARY_SURFACE_ADDRESS_C__GRPH_PRIMARY_SURFACE_ADDRESS_C__SHIFT;
84b843c749SSergey Zigachev 
85b843c749SSergey Zigachev 	set_reg_field_value(value, temp,
86b843c749SSergey Zigachev 		UNP_GRPH_PRIMARY_SURFACE_ADDRESS_C,
87b843c749SSergey Zigachev 		GRPH_PRIMARY_SURFACE_ADDRESS_C);
88b843c749SSergey Zigachev 
89b843c749SSergey Zigachev 	dm_write_reg(
90b843c749SSergey Zigachev 		mem_input110->base.ctx,
91b843c749SSergey Zigachev 		mmUNP_GRPH_PRIMARY_SURFACE_ADDRESS_C,
92b843c749SSergey Zigachev 		value);
93b843c749SSergey Zigachev }
94b843c749SSergey Zigachev 
95b843c749SSergey Zigachev /* luma part */
program_pri_addr_l(struct dce_mem_input * mem_input110,PHYSICAL_ADDRESS_LOC address)96b843c749SSergey Zigachev static void program_pri_addr_l(
97b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
98b843c749SSergey Zigachev 	PHYSICAL_ADDRESS_LOC address)
99b843c749SSergey Zigachev {
100b843c749SSergey Zigachev 	uint32_t value = 0;
101b843c749SSergey Zigachev 	uint32_t temp = 0;
102b843c749SSergey Zigachev 
103b843c749SSergey Zigachev 	/*high register MUST be programmed first*/
104b843c749SSergey Zigachev 	temp = address.high_part &
105b843c749SSergey Zigachev UNP_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_L__GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_L_MASK;
106b843c749SSergey Zigachev 
107b843c749SSergey Zigachev 	set_reg_field_value(value, temp,
108b843c749SSergey Zigachev 		UNP_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_L,
109b843c749SSergey Zigachev 		GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_L);
110b843c749SSergey Zigachev 
111b843c749SSergey Zigachev 	dm_write_reg(
112b843c749SSergey Zigachev 		mem_input110->base.ctx,
113b843c749SSergey Zigachev 		mmUNP_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH_L,
114b843c749SSergey Zigachev 		value);
115b843c749SSergey Zigachev 
116b843c749SSergey Zigachev 	temp = 0;
117b843c749SSergey Zigachev 	value = 0;
118b843c749SSergey Zigachev 	temp = address.low_part >>
119b843c749SSergey Zigachev 	UNP_GRPH_PRIMARY_SURFACE_ADDRESS_L__GRPH_PRIMARY_SURFACE_ADDRESS_L__SHIFT;
120b843c749SSergey Zigachev 
121b843c749SSergey Zigachev 	set_reg_field_value(value, temp,
122b843c749SSergey Zigachev 		UNP_GRPH_PRIMARY_SURFACE_ADDRESS_L,
123b843c749SSergey Zigachev 		GRPH_PRIMARY_SURFACE_ADDRESS_L);
124b843c749SSergey Zigachev 
125b843c749SSergey Zigachev 	dm_write_reg(
126b843c749SSergey Zigachev 		mem_input110->base.ctx,
127b843c749SSergey Zigachev 		mmUNP_GRPH_PRIMARY_SURFACE_ADDRESS_L,
128b843c749SSergey Zigachev 		value);
129b843c749SSergey Zigachev }
130b843c749SSergey Zigachev 
program_addr(struct dce_mem_input * mem_input110,const struct dc_plane_address * addr)131b843c749SSergey Zigachev static void program_addr(
132b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
133b843c749SSergey Zigachev 	const struct dc_plane_address *addr)
134b843c749SSergey Zigachev {
135b843c749SSergey Zigachev 	switch (addr->type) {
136b843c749SSergey Zigachev 	case PLN_ADDR_TYPE_GRAPHICS:
137b843c749SSergey Zigachev 		program_pri_addr_l(
138b843c749SSergey Zigachev 			mem_input110,
139b843c749SSergey Zigachev 			addr->grph.addr);
140b843c749SSergey Zigachev 		break;
141b843c749SSergey Zigachev 	case PLN_ADDR_TYPE_VIDEO_PROGRESSIVE:
142b843c749SSergey Zigachev 		program_pri_addr_c(
143b843c749SSergey Zigachev 			mem_input110,
144b843c749SSergey Zigachev 			addr->video_progressive.chroma_addr);
145b843c749SSergey Zigachev 		program_pri_addr_l(
146b843c749SSergey Zigachev 			mem_input110,
147b843c749SSergey Zigachev 			addr->video_progressive.luma_addr);
148b843c749SSergey Zigachev 		break;
149b843c749SSergey Zigachev 	default:
150b843c749SSergey Zigachev 		/* not supported */
151b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
152b843c749SSergey Zigachev 	}
153b843c749SSergey Zigachev }
154b843c749SSergey Zigachev 
enable(struct dce_mem_input * mem_input110)155b843c749SSergey Zigachev static void enable(struct dce_mem_input *mem_input110)
156b843c749SSergey Zigachev {
157b843c749SSergey Zigachev 	uint32_t value = 0;
158b843c749SSergey Zigachev 
159b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_GRPH_ENABLE);
160b843c749SSergey Zigachev 	set_reg_field_value(value, 1, UNP_GRPH_ENABLE, GRPH_ENABLE);
161b843c749SSergey Zigachev 	dm_write_reg(mem_input110->base.ctx,
162b843c749SSergey Zigachev 		mmUNP_GRPH_ENABLE,
163b843c749SSergey Zigachev 		value);
164b843c749SSergey Zigachev }
165b843c749SSergey Zigachev 
program_tiling(struct dce_mem_input * mem_input110,const union dc_tiling_info * info,const enum surface_pixel_format pixel_format)166b843c749SSergey Zigachev static void program_tiling(
167b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
168b843c749SSergey Zigachev 	const union dc_tiling_info *info,
169b843c749SSergey Zigachev 	const enum surface_pixel_format pixel_format)
170b843c749SSergey Zigachev {
171b843c749SSergey Zigachev 	uint32_t value = 0;
172b843c749SSergey Zigachev 
173b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.num_banks,
174b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_NUM_BANKS);
175b843c749SSergey Zigachev 
176b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.bank_width,
177b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_BANK_WIDTH_L);
178b843c749SSergey Zigachev 
179b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.bank_height,
180b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_BANK_HEIGHT_L);
181b843c749SSergey Zigachev 
182b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.tile_aspect,
183b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_MACRO_TILE_ASPECT_L);
184b843c749SSergey Zigachev 
185b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.tile_split,
186b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_TILE_SPLIT_L);
187b843c749SSergey Zigachev 
188b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.tile_mode,
189b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_MICRO_TILE_MODE_L);
190b843c749SSergey Zigachev 
191b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.pipe_config,
192b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_PIPE_CONFIG);
193b843c749SSergey Zigachev 
194b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.array_mode,
195b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_ARRAY_MODE);
196b843c749SSergey Zigachev 
197b843c749SSergey Zigachev 	set_reg_field_value(value, 1,
198b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_COLOR_EXPANSION_MODE);
199b843c749SSergey Zigachev 
200b843c749SSergey Zigachev 	set_reg_field_value(value, 0,
201b843c749SSergey Zigachev 		UNP_GRPH_CONTROL, GRPH_Z);
202b843c749SSergey Zigachev 
203b843c749SSergey Zigachev 	dm_write_reg(
204b843c749SSergey Zigachev 		mem_input110->base.ctx,
205b843c749SSergey Zigachev 		mmUNP_GRPH_CONTROL,
206b843c749SSergey Zigachev 		value);
207b843c749SSergey Zigachev 
208b843c749SSergey Zigachev 	value = 0;
209b843c749SSergey Zigachev 
210b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.bank_width_c,
211b843c749SSergey Zigachev 		UNP_GRPH_CONTROL_C, GRPH_BANK_WIDTH_C);
212b843c749SSergey Zigachev 
213b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.bank_height_c,
214b843c749SSergey Zigachev 		UNP_GRPH_CONTROL_C, GRPH_BANK_HEIGHT_C);
215b843c749SSergey Zigachev 
216b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.tile_aspect_c,
217b843c749SSergey Zigachev 		UNP_GRPH_CONTROL_C, GRPH_MACRO_TILE_ASPECT_C);
218b843c749SSergey Zigachev 
219b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.tile_split_c,
220b843c749SSergey Zigachev 		UNP_GRPH_CONTROL_C, GRPH_TILE_SPLIT_C);
221b843c749SSergey Zigachev 
222b843c749SSergey Zigachev 	set_reg_field_value(value, info->gfx8.tile_mode_c,
223b843c749SSergey Zigachev 		UNP_GRPH_CONTROL_C, GRPH_MICRO_TILE_MODE_C);
224b843c749SSergey Zigachev 
225b843c749SSergey Zigachev 	dm_write_reg(
226b843c749SSergey Zigachev 		mem_input110->base.ctx,
227b843c749SSergey Zigachev 		mmUNP_GRPH_CONTROL_C,
228b843c749SSergey Zigachev 		value);
229b843c749SSergey Zigachev }
230b843c749SSergey Zigachev 
program_size_and_rotation(struct dce_mem_input * mem_input110,enum dc_rotation_angle rotation,const union plane_size * plane_size)231b843c749SSergey Zigachev static void program_size_and_rotation(
232b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
233b843c749SSergey Zigachev 	enum dc_rotation_angle rotation,
234b843c749SSergey Zigachev 	const union plane_size *plane_size)
235b843c749SSergey Zigachev {
236b843c749SSergey Zigachev 	uint32_t value = 0;
237b843c749SSergey Zigachev 	union plane_size local_size = *plane_size;
238b843c749SSergey Zigachev 
239b843c749SSergey Zigachev 	if (rotation == ROTATION_ANGLE_90 ||
240b843c749SSergey Zigachev 		rotation == ROTATION_ANGLE_270) {
241b843c749SSergey Zigachev 
242b843c749SSergey Zigachev 		swap(local_size.video.luma_size.x,
243b843c749SSergey Zigachev 		     local_size.video.luma_size.y);
244b843c749SSergey Zigachev 		swap(local_size.video.luma_size.width,
245b843c749SSergey Zigachev 		     local_size.video.luma_size.height);
246b843c749SSergey Zigachev 		swap(local_size.video.chroma_size.x,
247b843c749SSergey Zigachev 		     local_size.video.chroma_size.y);
248b843c749SSergey Zigachev 		swap(local_size.video.chroma_size.width,
249b843c749SSergey Zigachev 		     local_size.video.chroma_size.height);
250b843c749SSergey Zigachev 	}
251b843c749SSergey Zigachev 
252b843c749SSergey Zigachev 	value = 0;
253b843c749SSergey Zigachev 	set_reg_field_value(value, local_size.video.luma_pitch,
254b843c749SSergey Zigachev 			UNP_GRPH_PITCH_L, GRPH_PITCH_L);
255b843c749SSergey Zigachev 
256b843c749SSergey Zigachev 	dm_write_reg(
257b843c749SSergey Zigachev 		mem_input110->base.ctx,
258b843c749SSergey Zigachev 		mmUNP_GRPH_PITCH_L,
259b843c749SSergey Zigachev 		value);
260b843c749SSergey Zigachev 
261b843c749SSergey Zigachev 	value = 0;
262b843c749SSergey Zigachev 	set_reg_field_value(value, local_size.video.chroma_pitch,
263b843c749SSergey Zigachev 			UNP_GRPH_PITCH_C, GRPH_PITCH_C);
264b843c749SSergey Zigachev 	dm_write_reg(
265b843c749SSergey Zigachev 		mem_input110->base.ctx,
266b843c749SSergey Zigachev 		mmUNP_GRPH_PITCH_C,
267b843c749SSergey Zigachev 		value);
268b843c749SSergey Zigachev 
269b843c749SSergey Zigachev 	value = 0;
270b843c749SSergey Zigachev 	set_reg_field_value(value, 0,
271b843c749SSergey Zigachev 			UNP_GRPH_X_START_L, GRPH_X_START_L);
272b843c749SSergey Zigachev 	dm_write_reg(
273b843c749SSergey Zigachev 		mem_input110->base.ctx,
274b843c749SSergey Zigachev 		mmUNP_GRPH_X_START_L,
275b843c749SSergey Zigachev 		value);
276b843c749SSergey Zigachev 
277b843c749SSergey Zigachev 	value = 0;
278b843c749SSergey Zigachev 	set_reg_field_value(value, 0,
279b843c749SSergey Zigachev 			UNP_GRPH_X_START_C, GRPH_X_START_C);
280b843c749SSergey Zigachev 	dm_write_reg(
281b843c749SSergey Zigachev 		mem_input110->base.ctx,
282b843c749SSergey Zigachev 		mmUNP_GRPH_X_START_C,
283b843c749SSergey Zigachev 		value);
284b843c749SSergey Zigachev 
285b843c749SSergey Zigachev 	value = 0;
286b843c749SSergey Zigachev 	set_reg_field_value(value, 0,
287b843c749SSergey Zigachev 			UNP_GRPH_Y_START_L, GRPH_Y_START_L);
288b843c749SSergey Zigachev 	dm_write_reg(
289b843c749SSergey Zigachev 		mem_input110->base.ctx,
290b843c749SSergey Zigachev 		mmUNP_GRPH_Y_START_L,
291b843c749SSergey Zigachev 		value);
292b843c749SSergey Zigachev 
293b843c749SSergey Zigachev 	value = 0;
294b843c749SSergey Zigachev 	set_reg_field_value(value, 0,
295b843c749SSergey Zigachev 			UNP_GRPH_Y_START_C, GRPH_Y_START_C);
296b843c749SSergey Zigachev 	dm_write_reg(
297b843c749SSergey Zigachev 		mem_input110->base.ctx,
298b843c749SSergey Zigachev 		mmUNP_GRPH_Y_START_C,
299b843c749SSergey Zigachev 		value);
300b843c749SSergey Zigachev 
301b843c749SSergey Zigachev 	value = 0;
302b843c749SSergey Zigachev 	set_reg_field_value(value, local_size.video.luma_size.x +
303b843c749SSergey Zigachev 			local_size.video.luma_size.width,
304b843c749SSergey Zigachev 			UNP_GRPH_X_END_L, GRPH_X_END_L);
305b843c749SSergey Zigachev 	dm_write_reg(
306b843c749SSergey Zigachev 		mem_input110->base.ctx,
307b843c749SSergey Zigachev 		mmUNP_GRPH_X_END_L,
308b843c749SSergey Zigachev 		value);
309b843c749SSergey Zigachev 
310b843c749SSergey Zigachev 	value = 0;
311b843c749SSergey Zigachev 	set_reg_field_value(value, local_size.video.chroma_size.x +
312b843c749SSergey Zigachev 			local_size.video.chroma_size.width,
313b843c749SSergey Zigachev 			UNP_GRPH_X_END_C, GRPH_X_END_C);
314b843c749SSergey Zigachev 	dm_write_reg(
315b843c749SSergey Zigachev 		mem_input110->base.ctx,
316b843c749SSergey Zigachev 		mmUNP_GRPH_X_END_C,
317b843c749SSergey Zigachev 		value);
318b843c749SSergey Zigachev 
319b843c749SSergey Zigachev 	value = 0;
320b843c749SSergey Zigachev 	set_reg_field_value(value, local_size.video.luma_size.y +
321b843c749SSergey Zigachev 			local_size.video.luma_size.height,
322b843c749SSergey Zigachev 			UNP_GRPH_Y_END_L, GRPH_Y_END_L);
323b843c749SSergey Zigachev 	dm_write_reg(
324b843c749SSergey Zigachev 		mem_input110->base.ctx,
325b843c749SSergey Zigachev 		mmUNP_GRPH_Y_END_L,
326b843c749SSergey Zigachev 		value);
327b843c749SSergey Zigachev 
328b843c749SSergey Zigachev 	value = 0;
329b843c749SSergey Zigachev 	set_reg_field_value(value, local_size.video.chroma_size.y +
330b843c749SSergey Zigachev 			local_size.video.chroma_size.height,
331b843c749SSergey Zigachev 			UNP_GRPH_Y_END_C, GRPH_Y_END_C);
332b843c749SSergey Zigachev 	dm_write_reg(
333b843c749SSergey Zigachev 		mem_input110->base.ctx,
334b843c749SSergey Zigachev 		mmUNP_GRPH_Y_END_C,
335b843c749SSergey Zigachev 		value);
336b843c749SSergey Zigachev 
337b843c749SSergey Zigachev 	value = 0;
338b843c749SSergey Zigachev 	switch (rotation) {
339b843c749SSergey Zigachev 	case ROTATION_ANGLE_90:
340b843c749SSergey Zigachev 		set_reg_field_value(value, 3,
341b843c749SSergey Zigachev 			UNP_HW_ROTATION, ROTATION_ANGLE);
342b843c749SSergey Zigachev 		break;
343b843c749SSergey Zigachev 	case ROTATION_ANGLE_180:
344b843c749SSergey Zigachev 		set_reg_field_value(value, 2,
345b843c749SSergey Zigachev 			UNP_HW_ROTATION, ROTATION_ANGLE);
346b843c749SSergey Zigachev 		break;
347b843c749SSergey Zigachev 	case ROTATION_ANGLE_270:
348b843c749SSergey Zigachev 		set_reg_field_value(value, 1,
349b843c749SSergey Zigachev 			UNP_HW_ROTATION, ROTATION_ANGLE);
350b843c749SSergey Zigachev 		break;
351b843c749SSergey Zigachev 	default:
352b843c749SSergey Zigachev 		set_reg_field_value(value, 0,
353b843c749SSergey Zigachev 			UNP_HW_ROTATION, ROTATION_ANGLE);
354b843c749SSergey Zigachev 		break;
355b843c749SSergey Zigachev 	}
356b843c749SSergey Zigachev 
357b843c749SSergey Zigachev 	dm_write_reg(
358b843c749SSergey Zigachev 		mem_input110->base.ctx,
359b843c749SSergey Zigachev 		mmUNP_HW_ROTATION,
360b843c749SSergey Zigachev 		value);
361b843c749SSergey Zigachev }
362b843c749SSergey Zigachev 
program_pixel_format(struct dce_mem_input * mem_input110,enum surface_pixel_format format)363b843c749SSergey Zigachev static void program_pixel_format(
364b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110,
365b843c749SSergey Zigachev 	enum surface_pixel_format format)
366b843c749SSergey Zigachev {
367b843c749SSergey Zigachev 	if (format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) {
368b843c749SSergey Zigachev 		uint32_t value;
369b843c749SSergey Zigachev 		uint8_t grph_depth;
370b843c749SSergey Zigachev 		uint8_t grph_format;
371b843c749SSergey Zigachev 
372b843c749SSergey Zigachev 		value =	dm_read_reg(
373b843c749SSergey Zigachev 				mem_input110->base.ctx,
374b843c749SSergey Zigachev 				mmUNP_GRPH_CONTROL);
375b843c749SSergey Zigachev 
376b843c749SSergey Zigachev 		switch (format) {
377b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
378b843c749SSergey Zigachev 			grph_depth = 0;
379b843c749SSergey Zigachev 			grph_format = 0;
380b843c749SSergey Zigachev 			break;
381b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
382b843c749SSergey Zigachev 			grph_depth = 1;
383b843c749SSergey Zigachev 			grph_format = 1;
384b843c749SSergey Zigachev 			break;
385b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
386b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
387b843c749SSergey Zigachev 			grph_depth = 2;
388b843c749SSergey Zigachev 			grph_format = 0;
389b843c749SSergey Zigachev 			break;
390b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
391b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
392b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
393b843c749SSergey Zigachev 			grph_depth = 2;
394b843c749SSergey Zigachev 			grph_format = 1;
395b843c749SSergey Zigachev 			break;
396b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
397b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
398b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
399b843c749SSergey Zigachev 			grph_depth = 3;
400b843c749SSergey Zigachev 			grph_format = 0;
401b843c749SSergey Zigachev 			break;
402b843c749SSergey Zigachev 		default:
403b843c749SSergey Zigachev 			grph_depth = 2;
404b843c749SSergey Zigachev 			grph_format = 0;
405b843c749SSergey Zigachev 			break;
406b843c749SSergey Zigachev 		}
407b843c749SSergey Zigachev 
408b843c749SSergey Zigachev 		set_reg_field_value(
409b843c749SSergey Zigachev 				value,
410b843c749SSergey Zigachev 				grph_depth,
411b843c749SSergey Zigachev 				UNP_GRPH_CONTROL,
412b843c749SSergey Zigachev 				GRPH_DEPTH);
413b843c749SSergey Zigachev 		set_reg_field_value(
414b843c749SSergey Zigachev 				value,
415b843c749SSergey Zigachev 				grph_format,
416b843c749SSergey Zigachev 				UNP_GRPH_CONTROL,
417b843c749SSergey Zigachev 				GRPH_FORMAT);
418b843c749SSergey Zigachev 
419b843c749SSergey Zigachev 		dm_write_reg(
420b843c749SSergey Zigachev 				mem_input110->base.ctx,
421b843c749SSergey Zigachev 				mmUNP_GRPH_CONTROL,
422b843c749SSergey Zigachev 				value);
423b843c749SSergey Zigachev 
424b843c749SSergey Zigachev 		value =	dm_read_reg(
425b843c749SSergey Zigachev 				mem_input110->base.ctx,
426b843c749SSergey Zigachev 				mmUNP_GRPH_CONTROL_EXP);
427b843c749SSergey Zigachev 
428b843c749SSergey Zigachev 		/* VIDEO FORMAT 0 */
429b843c749SSergey Zigachev 		set_reg_field_value(
430b843c749SSergey Zigachev 				value,
431b843c749SSergey Zigachev 				0,
432b843c749SSergey Zigachev 				UNP_GRPH_CONTROL_EXP,
433b843c749SSergey Zigachev 				VIDEO_FORMAT);
434b843c749SSergey Zigachev 		dm_write_reg(
435b843c749SSergey Zigachev 				mem_input110->base.ctx,
436b843c749SSergey Zigachev 				mmUNP_GRPH_CONTROL_EXP,
437b843c749SSergey Zigachev 				value);
438b843c749SSergey Zigachev 
439b843c749SSergey Zigachev 	} else {
440b843c749SSergey Zigachev 		/* Video 422 and 420 needs UNP_GRPH_CONTROL_EXP programmed */
441b843c749SSergey Zigachev 		uint32_t value;
442b843c749SSergey Zigachev 		uint8_t video_format;
443b843c749SSergey Zigachev 
444b843c749SSergey Zigachev 		value =	dm_read_reg(
445b843c749SSergey Zigachev 				mem_input110->base.ctx,
446b843c749SSergey Zigachev 				mmUNP_GRPH_CONTROL_EXP);
447b843c749SSergey Zigachev 
448b843c749SSergey Zigachev 		switch (format) {
449b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
450b843c749SSergey Zigachev 			video_format = 2;
451b843c749SSergey Zigachev 			break;
452b843c749SSergey Zigachev 		case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
453b843c749SSergey Zigachev 			video_format = 3;
454b843c749SSergey Zigachev 			break;
455b843c749SSergey Zigachev 		default:
456b843c749SSergey Zigachev 			video_format = 0;
457b843c749SSergey Zigachev 			break;
458b843c749SSergey Zigachev 		}
459b843c749SSergey Zigachev 
460b843c749SSergey Zigachev 		set_reg_field_value(
461b843c749SSergey Zigachev 			value,
462b843c749SSergey Zigachev 			video_format,
463b843c749SSergey Zigachev 			UNP_GRPH_CONTROL_EXP,
464b843c749SSergey Zigachev 			VIDEO_FORMAT);
465b843c749SSergey Zigachev 
466b843c749SSergey Zigachev 		dm_write_reg(
467b843c749SSergey Zigachev 			mem_input110->base.ctx,
468b843c749SSergey Zigachev 			mmUNP_GRPH_CONTROL_EXP,
469b843c749SSergey Zigachev 			value);
470b843c749SSergey Zigachev 	}
471b843c749SSergey Zigachev }
472b843c749SSergey Zigachev 
473*78973132SSergey Zigachev static
dce_mem_input_v_is_surface_pending(struct mem_input * mem_input)474b843c749SSergey Zigachev bool dce_mem_input_v_is_surface_pending(struct mem_input *mem_input)
475b843c749SSergey Zigachev {
476b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110 = TO_DCE_MEM_INPUT(mem_input);
477b843c749SSergey Zigachev 	uint32_t value;
478b843c749SSergey Zigachev 
479b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_GRPH_UPDATE);
480b843c749SSergey Zigachev 
481b843c749SSergey Zigachev 	if (get_reg_field_value(value, UNP_GRPH_UPDATE,
482b843c749SSergey Zigachev 			GRPH_SURFACE_UPDATE_PENDING))
483b843c749SSergey Zigachev 		return true;
484b843c749SSergey Zigachev 
485b843c749SSergey Zigachev 	mem_input->current_address = mem_input->request_address;
486b843c749SSergey Zigachev 	return false;
487b843c749SSergey Zigachev }
488b843c749SSergey Zigachev 
489*78973132SSergey Zigachev static
dce_mem_input_v_program_surface_flip_and_addr(struct mem_input * mem_input,const struct dc_plane_address * address,bool flip_immediate)490b843c749SSergey Zigachev bool dce_mem_input_v_program_surface_flip_and_addr(
491b843c749SSergey Zigachev 	struct mem_input *mem_input,
492b843c749SSergey Zigachev 	const struct dc_plane_address *address,
493b843c749SSergey Zigachev 	bool flip_immediate)
494b843c749SSergey Zigachev {
495b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110 = TO_DCE_MEM_INPUT(mem_input);
496b843c749SSergey Zigachev 
497b843c749SSergey Zigachev 	set_flip_control(mem_input110, flip_immediate);
498b843c749SSergey Zigachev 	program_addr(mem_input110,
499b843c749SSergey Zigachev 		address);
500b843c749SSergey Zigachev 
501b843c749SSergey Zigachev 	mem_input->request_address = *address;
502b843c749SSergey Zigachev 
503b843c749SSergey Zigachev 	return true;
504b843c749SSergey Zigachev }
505b843c749SSergey Zigachev 
506b843c749SSergey Zigachev /* Scatter Gather param tables */
507b843c749SSergey Zigachev static const unsigned int dvmm_Hw_Setting_2DTiling[4][9] = {
508b843c749SSergey Zigachev 		{  8, 64, 64,  8,  8, 1, 4, 0, 0},
509b843c749SSergey Zigachev 		{ 16, 64, 32,  8, 16, 1, 8, 0, 0},
510b843c749SSergey Zigachev 		{ 32, 32, 32, 16, 16, 1, 8, 0, 0},
511b843c749SSergey Zigachev 		{ 64,  8, 32, 16, 16, 1, 8, 0, 0}, /* fake */
512b843c749SSergey Zigachev };
513b843c749SSergey Zigachev 
514b843c749SSergey Zigachev static const unsigned int dvmm_Hw_Setting_1DTiling[4][9] = {
515b843c749SSergey Zigachev 		{  8, 512, 8, 1, 0, 1, 0, 0, 0},  /* 0 for invalid */
516b843c749SSergey Zigachev 		{ 16, 256, 8, 2, 0, 1, 0, 0, 0},
517b843c749SSergey Zigachev 		{ 32, 128, 8, 4, 0, 1, 0, 0, 0},
518b843c749SSergey Zigachev 		{ 64,  64, 8, 4, 0, 1, 0, 0, 0}, /* fake */
519b843c749SSergey Zigachev };
520b843c749SSergey Zigachev 
521b843c749SSergey Zigachev static const unsigned int dvmm_Hw_Setting_Linear[4][9] = {
522b843c749SSergey Zigachev 		{  8, 4096, 1, 8, 0, 1, 0, 0, 0},
523b843c749SSergey Zigachev 		{ 16, 2048, 1, 8, 0, 1, 0, 0, 0},
524b843c749SSergey Zigachev 		{ 32, 1024, 1, 8, 0, 1, 0, 0, 0},
525b843c749SSergey Zigachev 		{ 64,  512, 1, 8, 0, 1, 0, 0, 0}, /* new for 64bpp from HW */
526b843c749SSergey Zigachev };
527b843c749SSergey Zigachev 
528b843c749SSergey Zigachev /* Helper to get table entry from surface info */
get_dvmm_hw_setting(union dc_tiling_info * tiling_info,enum surface_pixel_format format,bool chroma)529b843c749SSergey Zigachev static const unsigned int *get_dvmm_hw_setting(
530b843c749SSergey Zigachev 		union dc_tiling_info *tiling_info,
531b843c749SSergey Zigachev 		enum surface_pixel_format format,
532b843c749SSergey Zigachev 		bool chroma)
533b843c749SSergey Zigachev {
534b843c749SSergey Zigachev 	enum bits_per_pixel {
535b843c749SSergey Zigachev 		bpp_8 = 0,
536b843c749SSergey Zigachev 		bpp_16,
537b843c749SSergey Zigachev 		bpp_32,
538b843c749SSergey Zigachev 		bpp_64
539b843c749SSergey Zigachev 	} bpp;
540b843c749SSergey Zigachev 
541b843c749SSergey Zigachev 	if (format >= SURFACE_PIXEL_FORMAT_INVALID)
542b843c749SSergey Zigachev 		bpp = bpp_32;
543b843c749SSergey Zigachev 	else if (format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
544b843c749SSergey Zigachev 		bpp = chroma ? bpp_16 : bpp_8;
545b843c749SSergey Zigachev 	else
546b843c749SSergey Zigachev 		bpp = bpp_8;
547b843c749SSergey Zigachev 
548b843c749SSergey Zigachev 	switch (tiling_info->gfx8.array_mode) {
549b843c749SSergey Zigachev 	case DC_ARRAY_1D_TILED_THIN1:
550b843c749SSergey Zigachev 	case DC_ARRAY_1D_TILED_THICK:
551b843c749SSergey Zigachev 	case DC_ARRAY_PRT_TILED_THIN1:
552b843c749SSergey Zigachev 		return dvmm_Hw_Setting_1DTiling[bpp];
553b843c749SSergey Zigachev 	case DC_ARRAY_2D_TILED_THIN1:
554b843c749SSergey Zigachev 	case DC_ARRAY_2D_TILED_THICK:
555b843c749SSergey Zigachev 	case DC_ARRAY_2D_TILED_X_THICK:
556b843c749SSergey Zigachev 	case DC_ARRAY_PRT_2D_TILED_THIN1:
557b843c749SSergey Zigachev 	case DC_ARRAY_PRT_2D_TILED_THICK:
558b843c749SSergey Zigachev 		return dvmm_Hw_Setting_2DTiling[bpp];
559b843c749SSergey Zigachev 	case DC_ARRAY_LINEAR_GENERAL:
560b843c749SSergey Zigachev 	case DC_ARRAY_LINEAR_ALLIGNED:
561b843c749SSergey Zigachev 		return dvmm_Hw_Setting_Linear[bpp];
562b843c749SSergey Zigachev 	default:
563b843c749SSergey Zigachev 		return dvmm_Hw_Setting_2DTiling[bpp];
564b843c749SSergey Zigachev 	}
565b843c749SSergey Zigachev }
566b843c749SSergey Zigachev 
567*78973132SSergey Zigachev static
dce_mem_input_v_program_pte_vm(struct mem_input * mem_input,enum surface_pixel_format format,union dc_tiling_info * tiling_info,enum dc_rotation_angle rotation)568b843c749SSergey Zigachev void dce_mem_input_v_program_pte_vm(
569b843c749SSergey Zigachev 		struct mem_input *mem_input,
570b843c749SSergey Zigachev 		enum surface_pixel_format format,
571b843c749SSergey Zigachev 		union dc_tiling_info *tiling_info,
572b843c749SSergey Zigachev 		enum dc_rotation_angle rotation)
573b843c749SSergey Zigachev {
574b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110 = TO_DCE_MEM_INPUT(mem_input);
575b843c749SSergey Zigachev 	const unsigned int *pte = get_dvmm_hw_setting(tiling_info, format, false);
576b843c749SSergey Zigachev 	const unsigned int *pte_chroma = get_dvmm_hw_setting(tiling_info, format, true);
577b843c749SSergey Zigachev 
578b843c749SSergey Zigachev 	unsigned int page_width = 0;
579b843c749SSergey Zigachev 	unsigned int page_height = 0;
580b843c749SSergey Zigachev 	unsigned int page_width_chroma = 0;
581b843c749SSergey Zigachev 	unsigned int page_height_chroma = 0;
582b843c749SSergey Zigachev 	unsigned int temp_page_width = pte[1];
583b843c749SSergey Zigachev 	unsigned int temp_page_height = pte[2];
584b843c749SSergey Zigachev 	unsigned int min_pte_before_flip = 0;
585b843c749SSergey Zigachev 	unsigned int min_pte_before_flip_chroma = 0;
586b843c749SSergey Zigachev 	uint32_t value = 0;
587b843c749SSergey Zigachev 
588b843c749SSergey Zigachev 	while ((temp_page_width >>= 1) != 0)
589b843c749SSergey Zigachev 		page_width++;
590b843c749SSergey Zigachev 	while ((temp_page_height >>= 1) != 0)
591b843c749SSergey Zigachev 		page_height++;
592b843c749SSergey Zigachev 
593b843c749SSergey Zigachev 	temp_page_width = pte_chroma[1];
594b843c749SSergey Zigachev 	temp_page_height = pte_chroma[2];
595b843c749SSergey Zigachev 	while ((temp_page_width >>= 1) != 0)
596b843c749SSergey Zigachev 		page_width_chroma++;
597b843c749SSergey Zigachev 	while ((temp_page_height >>= 1) != 0)
598b843c749SSergey Zigachev 		page_height_chroma++;
599b843c749SSergey Zigachev 
600b843c749SSergey Zigachev 	switch (rotation) {
601b843c749SSergey Zigachev 	case ROTATION_ANGLE_90:
602b843c749SSergey Zigachev 	case ROTATION_ANGLE_270:
603b843c749SSergey Zigachev 		min_pte_before_flip = pte[4];
604b843c749SSergey Zigachev 		min_pte_before_flip_chroma = pte_chroma[4];
605b843c749SSergey Zigachev 		break;
606b843c749SSergey Zigachev 	default:
607b843c749SSergey Zigachev 		min_pte_before_flip = pte[3];
608b843c749SSergey Zigachev 		min_pte_before_flip_chroma = pte_chroma[3];
609b843c749SSergey Zigachev 		break;
610b843c749SSergey Zigachev 	}
611b843c749SSergey Zigachev 
612b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_PIPE_OUTSTANDING_REQUEST_LIMIT);
613b843c749SSergey Zigachev 	/* TODO: un-hardcode requestlimit */
614b843c749SSergey Zigachev 	set_reg_field_value(value, 0xff, UNP_PIPE_OUTSTANDING_REQUEST_LIMIT, UNP_PIPE_OUTSTANDING_REQUEST_LIMIT_L);
615b843c749SSergey Zigachev 	set_reg_field_value(value, 0xff, UNP_PIPE_OUTSTANDING_REQUEST_LIMIT, UNP_PIPE_OUTSTANDING_REQUEST_LIMIT_C);
616b843c749SSergey Zigachev 	dm_write_reg(mem_input110->base.ctx, mmUNP_PIPE_OUTSTANDING_REQUEST_LIMIT, value);
617b843c749SSergey Zigachev 
618b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_CONTROL);
619b843c749SSergey Zigachev 	set_reg_field_value(value, page_width, UNP_DVMM_PTE_CONTROL, DVMM_PAGE_WIDTH);
620b843c749SSergey Zigachev 	set_reg_field_value(value, page_height, UNP_DVMM_PTE_CONTROL, DVMM_PAGE_HEIGHT);
621b843c749SSergey Zigachev 	set_reg_field_value(value, min_pte_before_flip, UNP_DVMM_PTE_CONTROL, DVMM_MIN_PTE_BEFORE_FLIP);
622b843c749SSergey Zigachev 	dm_write_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_CONTROL, value);
623b843c749SSergey Zigachev 
624b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_ARB_CONTROL);
625b843c749SSergey Zigachev 	set_reg_field_value(value, pte[5], UNP_DVMM_PTE_ARB_CONTROL, DVMM_PTE_REQ_PER_CHUNK);
626b843c749SSergey Zigachev 	set_reg_field_value(value, 0xff, UNP_DVMM_PTE_ARB_CONTROL, DVMM_MAX_PTE_REQ_OUTSTANDING);
627b843c749SSergey Zigachev 	dm_write_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_ARB_CONTROL, value);
628b843c749SSergey Zigachev 
629b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_CONTROL_C);
630b843c749SSergey Zigachev 	set_reg_field_value(value, page_width_chroma, UNP_DVMM_PTE_CONTROL_C, DVMM_PAGE_WIDTH_C);
631b843c749SSergey Zigachev 	set_reg_field_value(value, page_height_chroma, UNP_DVMM_PTE_CONTROL_C, DVMM_PAGE_HEIGHT_C);
632b843c749SSergey Zigachev 	set_reg_field_value(value, min_pte_before_flip_chroma, UNP_DVMM_PTE_CONTROL_C, DVMM_MIN_PTE_BEFORE_FLIP_C);
633b843c749SSergey Zigachev 	dm_write_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_CONTROL_C, value);
634b843c749SSergey Zigachev 
635b843c749SSergey Zigachev 	value = dm_read_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_ARB_CONTROL_C);
636b843c749SSergey Zigachev 	set_reg_field_value(value, pte_chroma[5], UNP_DVMM_PTE_ARB_CONTROL_C, DVMM_PTE_REQ_PER_CHUNK_C);
637b843c749SSergey Zigachev 	set_reg_field_value(value, 0xff, UNP_DVMM_PTE_ARB_CONTROL_C, DVMM_MAX_PTE_REQ_OUTSTANDING_C);
638b843c749SSergey Zigachev 	dm_write_reg(mem_input110->base.ctx, mmUNP_DVMM_PTE_ARB_CONTROL_C, value);
639b843c749SSergey Zigachev }
640b843c749SSergey Zigachev 
641*78973132SSergey Zigachev static
dce_mem_input_v_program_surface_config(struct mem_input * mem_input,enum surface_pixel_format format,union dc_tiling_info * tiling_info,union plane_size * plane_size,enum dc_rotation_angle rotation,struct dc_plane_dcc_param * dcc,bool horizotal_mirror)642b843c749SSergey Zigachev void dce_mem_input_v_program_surface_config(
643b843c749SSergey Zigachev 	struct mem_input *mem_input,
644b843c749SSergey Zigachev 	enum surface_pixel_format format,
645b843c749SSergey Zigachev 	union dc_tiling_info *tiling_info,
646b843c749SSergey Zigachev 	union plane_size *plane_size,
647b843c749SSergey Zigachev 	enum dc_rotation_angle rotation,
648b843c749SSergey Zigachev 	struct dc_plane_dcc_param *dcc,
649b843c749SSergey Zigachev 	bool horizotal_mirror)
650b843c749SSergey Zigachev {
651b843c749SSergey Zigachev 	struct dce_mem_input *mem_input110 = TO_DCE_MEM_INPUT(mem_input);
652b843c749SSergey Zigachev 
653b843c749SSergey Zigachev 	enable(mem_input110);
654b843c749SSergey Zigachev 	program_tiling(mem_input110, tiling_info, format);
655b843c749SSergey Zigachev 	program_size_and_rotation(mem_input110, rotation, plane_size);
656b843c749SSergey Zigachev 	program_pixel_format(mem_input110, format);
657b843c749SSergey Zigachev }
658b843c749SSergey Zigachev 
program_urgency_watermark(const struct dc_context * ctx,const uint32_t urgency_addr,const uint32_t wm_addr,struct dce_watermarks marks_low,uint32_t total_dest_line_time_ns)659b843c749SSergey Zigachev static void program_urgency_watermark(
660b843c749SSergey Zigachev 	const struct dc_context *ctx,
661b843c749SSergey Zigachev 	const uint32_t urgency_addr,
662b843c749SSergey Zigachev 	const uint32_t wm_addr,
663b843c749SSergey Zigachev 	struct dce_watermarks marks_low,
664b843c749SSergey Zigachev 	uint32_t total_dest_line_time_ns)
665b843c749SSergey Zigachev {
666b843c749SSergey Zigachev 	/* register value */
667b843c749SSergey Zigachev 	uint32_t urgency_cntl = 0;
668b843c749SSergey Zigachev 	uint32_t wm_mask_cntl = 0;
669b843c749SSergey Zigachev 
670b843c749SSergey Zigachev 	/*Write mask to enable reading/writing of watermark set A*/
671b843c749SSergey Zigachev 	wm_mask_cntl = dm_read_reg(ctx, wm_addr);
672b843c749SSergey Zigachev 	set_reg_field_value(wm_mask_cntl,
673b843c749SSergey Zigachev 			1,
674b843c749SSergey Zigachev 			DPGV0_WATERMARK_MASK_CONTROL,
675b843c749SSergey Zigachev 			URGENCY_WATERMARK_MASK);
676b843c749SSergey Zigachev 	dm_write_reg(ctx, wm_addr, wm_mask_cntl);
677b843c749SSergey Zigachev 
678b843c749SSergey Zigachev 	urgency_cntl = dm_read_reg(ctx, urgency_addr);
679b843c749SSergey Zigachev 
680b843c749SSergey Zigachev 	set_reg_field_value(
681b843c749SSergey Zigachev 		urgency_cntl,
682b843c749SSergey Zigachev 		marks_low.a_mark,
683b843c749SSergey Zigachev 		DPGV0_PIPE_URGENCY_CONTROL,
684b843c749SSergey Zigachev 		URGENCY_LOW_WATERMARK);
685b843c749SSergey Zigachev 
686b843c749SSergey Zigachev 	set_reg_field_value(
687b843c749SSergey Zigachev 		urgency_cntl,
688b843c749SSergey Zigachev 		total_dest_line_time_ns,
689b843c749SSergey Zigachev 		DPGV0_PIPE_URGENCY_CONTROL,
690b843c749SSergey Zigachev 		URGENCY_HIGH_WATERMARK);
691b843c749SSergey Zigachev 	dm_write_reg(ctx, urgency_addr, urgency_cntl);
692b843c749SSergey Zigachev 
693b843c749SSergey Zigachev 	/*Write mask to enable reading/writing of watermark set B*/
694b843c749SSergey Zigachev 	wm_mask_cntl = dm_read_reg(ctx, wm_addr);
695b843c749SSergey Zigachev 	set_reg_field_value(wm_mask_cntl,
696b843c749SSergey Zigachev 			2,
697b843c749SSergey Zigachev 			DPGV0_WATERMARK_MASK_CONTROL,
698b843c749SSergey Zigachev 			URGENCY_WATERMARK_MASK);
699b843c749SSergey Zigachev 	dm_write_reg(ctx, wm_addr, wm_mask_cntl);
700b843c749SSergey Zigachev 
701b843c749SSergey Zigachev 	urgency_cntl = dm_read_reg(ctx, urgency_addr);
702b843c749SSergey Zigachev 
703b843c749SSergey Zigachev 	set_reg_field_value(urgency_cntl,
704b843c749SSergey Zigachev 		marks_low.b_mark,
705b843c749SSergey Zigachev 		DPGV0_PIPE_URGENCY_CONTROL,
706b843c749SSergey Zigachev 		URGENCY_LOW_WATERMARK);
707b843c749SSergey Zigachev 
708b843c749SSergey Zigachev 	set_reg_field_value(urgency_cntl,
709b843c749SSergey Zigachev 		total_dest_line_time_ns,
710b843c749SSergey Zigachev 		DPGV0_PIPE_URGENCY_CONTROL,
711b843c749SSergey Zigachev 		URGENCY_HIGH_WATERMARK);
712b843c749SSergey Zigachev 
713b843c749SSergey Zigachev 	dm_write_reg(ctx, urgency_addr, urgency_cntl);
714b843c749SSergey Zigachev }
715b843c749SSergey Zigachev 
program_urgency_watermark_l(const struct dc_context * ctx,struct dce_watermarks marks_low,uint32_t total_dest_line_time_ns)716b843c749SSergey Zigachev static void program_urgency_watermark_l(
717b843c749SSergey Zigachev 	const struct dc_context *ctx,
718b843c749SSergey Zigachev 	struct dce_watermarks marks_low,
719b843c749SSergey Zigachev 	uint32_t total_dest_line_time_ns)
720b843c749SSergey Zigachev {
721b843c749SSergey Zigachev 	program_urgency_watermark(
722b843c749SSergey Zigachev 		ctx,
723b843c749SSergey Zigachev 		mmDPGV0_PIPE_URGENCY_CONTROL,
724b843c749SSergey Zigachev 		mmDPGV0_WATERMARK_MASK_CONTROL,
725b843c749SSergey Zigachev 		marks_low,
726b843c749SSergey Zigachev 		total_dest_line_time_ns);
727b843c749SSergey Zigachev }
728b843c749SSergey Zigachev 
program_urgency_watermark_c(const struct dc_context * ctx,struct dce_watermarks marks_low,uint32_t total_dest_line_time_ns)729b843c749SSergey Zigachev static void program_urgency_watermark_c(
730b843c749SSergey Zigachev 	const struct dc_context *ctx,
731b843c749SSergey Zigachev 	struct dce_watermarks marks_low,
732b843c749SSergey Zigachev 	uint32_t total_dest_line_time_ns)
733b843c749SSergey Zigachev {
734b843c749SSergey Zigachev 	program_urgency_watermark(
735b843c749SSergey Zigachev 		ctx,
736b843c749SSergey Zigachev 		mmDPGV1_PIPE_URGENCY_CONTROL,
737b843c749SSergey Zigachev 		mmDPGV1_WATERMARK_MASK_CONTROL,
738b843c749SSergey Zigachev 		marks_low,
739b843c749SSergey Zigachev 		total_dest_line_time_ns);
740b843c749SSergey Zigachev }
741b843c749SSergey Zigachev 
program_stutter_watermark(const struct dc_context * ctx,const uint32_t stutter_addr,const uint32_t wm_addr,struct dce_watermarks marks)742b843c749SSergey Zigachev static void program_stutter_watermark(
743b843c749SSergey Zigachev 	const struct dc_context *ctx,
744b843c749SSergey Zigachev 	const uint32_t stutter_addr,
745b843c749SSergey Zigachev 	const uint32_t wm_addr,
746b843c749SSergey Zigachev 	struct dce_watermarks marks)
747b843c749SSergey Zigachev {
748b843c749SSergey Zigachev 	/* register value */
749b843c749SSergey Zigachev 	uint32_t stutter_cntl = 0;
750b843c749SSergey Zigachev 	uint32_t wm_mask_cntl = 0;
751b843c749SSergey Zigachev 
752b843c749SSergey Zigachev 	/*Write mask to enable reading/writing of watermark set A*/
753b843c749SSergey Zigachev 
754b843c749SSergey Zigachev 	wm_mask_cntl = dm_read_reg(ctx, wm_addr);
755b843c749SSergey Zigachev 	set_reg_field_value(wm_mask_cntl,
756b843c749SSergey Zigachev 		1,
757b843c749SSergey Zigachev 		DPGV0_WATERMARK_MASK_CONTROL,
758b843c749SSergey Zigachev 		STUTTER_EXIT_SELF_REFRESH_WATERMARK_MASK);
759b843c749SSergey Zigachev 	dm_write_reg(ctx, wm_addr, wm_mask_cntl);
760b843c749SSergey Zigachev 
761b843c749SSergey Zigachev 	stutter_cntl = dm_read_reg(ctx, stutter_addr);
762b843c749SSergey Zigachev 
763b843c749SSergey Zigachev 	if (ctx->dc->debug.disable_stutter) {
764b843c749SSergey Zigachev 		set_reg_field_value(stutter_cntl,
765b843c749SSergey Zigachev 			0,
766b843c749SSergey Zigachev 			DPGV0_PIPE_STUTTER_CONTROL,
767b843c749SSergey Zigachev 			STUTTER_ENABLE);
768b843c749SSergey Zigachev 	} else {
769b843c749SSergey Zigachev 		set_reg_field_value(stutter_cntl,
770b843c749SSergey Zigachev 			1,
771b843c749SSergey Zigachev 			DPGV0_PIPE_STUTTER_CONTROL,
772b843c749SSergey Zigachev 			STUTTER_ENABLE);
773b843c749SSergey Zigachev 	}
774b843c749SSergey Zigachev 
775b843c749SSergey Zigachev 	set_reg_field_value(stutter_cntl,
776b843c749SSergey Zigachev 		1,
777b843c749SSergey Zigachev 		DPGV0_PIPE_STUTTER_CONTROL,
778b843c749SSergey Zigachev 		STUTTER_IGNORE_FBC);
779b843c749SSergey Zigachev 
780b843c749SSergey Zigachev 	/*Write watermark set A*/
781b843c749SSergey Zigachev 	set_reg_field_value(stutter_cntl,
782b843c749SSergey Zigachev 		marks.a_mark,
783b843c749SSergey Zigachev 		DPGV0_PIPE_STUTTER_CONTROL,
784b843c749SSergey Zigachev 		STUTTER_EXIT_SELF_REFRESH_WATERMARK);
785b843c749SSergey Zigachev 	dm_write_reg(ctx, stutter_addr, stutter_cntl);
786b843c749SSergey Zigachev 
787b843c749SSergey Zigachev 	/*Write mask to enable reading/writing of watermark set B*/
788b843c749SSergey Zigachev 	wm_mask_cntl = dm_read_reg(ctx, wm_addr);
789b843c749SSergey Zigachev 	set_reg_field_value(wm_mask_cntl,
790b843c749SSergey Zigachev 		2,
791b843c749SSergey Zigachev 		DPGV0_WATERMARK_MASK_CONTROL,
792b843c749SSergey Zigachev 		STUTTER_EXIT_SELF_REFRESH_WATERMARK_MASK);
793b843c749SSergey Zigachev 	dm_write_reg(ctx, wm_addr, wm_mask_cntl);
794b843c749SSergey Zigachev 
795b843c749SSergey Zigachev 	stutter_cntl = dm_read_reg(ctx, stutter_addr);
796b843c749SSergey Zigachev 	/*Write watermark set B*/
797b843c749SSergey Zigachev 	set_reg_field_value(stutter_cntl,
798b843c749SSergey Zigachev 		marks.b_mark,
799b843c749SSergey Zigachev 		DPGV0_PIPE_STUTTER_CONTROL,
800b843c749SSergey Zigachev 		STUTTER_EXIT_SELF_REFRESH_WATERMARK);
801b843c749SSergey Zigachev 	dm_write_reg(ctx, stutter_addr, stutter_cntl);
802b843c749SSergey Zigachev }
803b843c749SSergey Zigachev 
program_stutter_watermark_l(const struct dc_context * ctx,struct dce_watermarks marks)804b843c749SSergey Zigachev static void program_stutter_watermark_l(
805b843c749SSergey Zigachev 	const struct dc_context *ctx,
806b843c749SSergey Zigachev 	struct dce_watermarks marks)
807b843c749SSergey Zigachev {
808b843c749SSergey Zigachev 	program_stutter_watermark(ctx,
809b843c749SSergey Zigachev 			mmDPGV0_PIPE_STUTTER_CONTROL,
810b843c749SSergey Zigachev 			mmDPGV0_WATERMARK_MASK_CONTROL,
811b843c749SSergey Zigachev 			marks);
812b843c749SSergey Zigachev }
813b843c749SSergey Zigachev 
program_stutter_watermark_c(const struct dc_context * ctx,struct dce_watermarks marks)814b843c749SSergey Zigachev static void program_stutter_watermark_c(
815b843c749SSergey Zigachev 	const struct dc_context *ctx,
816b843c749SSergey Zigachev 	struct dce_watermarks marks)
817b843c749SSergey Zigachev {
818b843c749SSergey Zigachev 	program_stutter_watermark(ctx,
819b843c749SSergey Zigachev 			mmDPGV1_PIPE_STUTTER_CONTROL,
820b843c749SSergey Zigachev 			mmDPGV1_WATERMARK_MASK_CONTROL,
821b843c749SSergey Zigachev 			marks);
822b843c749SSergey Zigachev }
823b843c749SSergey Zigachev 
program_nbp_watermark(const struct dc_context * ctx,const uint32_t wm_mask_ctrl_addr,const uint32_t nbp_pstate_ctrl_addr,struct dce_watermarks marks)824b843c749SSergey Zigachev static void program_nbp_watermark(
825b843c749SSergey Zigachev 	const struct dc_context *ctx,
826b843c749SSergey Zigachev 	const uint32_t wm_mask_ctrl_addr,
827b843c749SSergey Zigachev 	const uint32_t nbp_pstate_ctrl_addr,
828b843c749SSergey Zigachev 	struct dce_watermarks marks)
829b843c749SSergey Zigachev {
830b843c749SSergey Zigachev 	uint32_t value;
831b843c749SSergey Zigachev 
832b843c749SSergey Zigachev 	/* Write mask to enable reading/writing of watermark set A */
833b843c749SSergey Zigachev 
834b843c749SSergey Zigachev 	value = dm_read_reg(ctx, wm_mask_ctrl_addr);
835b843c749SSergey Zigachev 
836b843c749SSergey Zigachev 	set_reg_field_value(
837b843c749SSergey Zigachev 		value,
838b843c749SSergey Zigachev 		1,
839b843c749SSergey Zigachev 		DPGV0_WATERMARK_MASK_CONTROL,
840b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_WATERMARK_MASK);
841b843c749SSergey Zigachev 	dm_write_reg(ctx, wm_mask_ctrl_addr, value);
842b843c749SSergey Zigachev 
843b843c749SSergey Zigachev 	value = dm_read_reg(ctx, nbp_pstate_ctrl_addr);
844b843c749SSergey Zigachev 
845b843c749SSergey Zigachev 	set_reg_field_value(
846b843c749SSergey Zigachev 		value,
847b843c749SSergey Zigachev 		1,
848b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
849b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_ENABLE);
850b843c749SSergey Zigachev 	set_reg_field_value(
851b843c749SSergey Zigachev 		value,
852b843c749SSergey Zigachev 		1,
853b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
854b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_URGENT_DURING_REQUEST);
855b843c749SSergey Zigachev 	set_reg_field_value(
856b843c749SSergey Zigachev 		value,
857b843c749SSergey Zigachev 		1,
858b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
859b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_NOT_SELF_REFRESH_DURING_REQUEST);
860b843c749SSergey Zigachev 	dm_write_reg(ctx, nbp_pstate_ctrl_addr, value);
861b843c749SSergey Zigachev 
862b843c749SSergey Zigachev 	/* Write watermark set A */
863b843c749SSergey Zigachev 	value = dm_read_reg(ctx, nbp_pstate_ctrl_addr);
864b843c749SSergey Zigachev 	set_reg_field_value(
865b843c749SSergey Zigachev 		value,
866b843c749SSergey Zigachev 		marks.a_mark,
867b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
868b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_WATERMARK);
869b843c749SSergey Zigachev 	dm_write_reg(ctx, nbp_pstate_ctrl_addr, value);
870b843c749SSergey Zigachev 
871b843c749SSergey Zigachev 	/* Write mask to enable reading/writing of watermark set B */
872b843c749SSergey Zigachev 	value = dm_read_reg(ctx, wm_mask_ctrl_addr);
873b843c749SSergey Zigachev 	set_reg_field_value(
874b843c749SSergey Zigachev 		value,
875b843c749SSergey Zigachev 		2,
876b843c749SSergey Zigachev 		DPGV0_WATERMARK_MASK_CONTROL,
877b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_WATERMARK_MASK);
878b843c749SSergey Zigachev 	dm_write_reg(ctx, wm_mask_ctrl_addr, value);
879b843c749SSergey Zigachev 
880b843c749SSergey Zigachev 	value = dm_read_reg(ctx, nbp_pstate_ctrl_addr);
881b843c749SSergey Zigachev 	set_reg_field_value(
882b843c749SSergey Zigachev 		value,
883b843c749SSergey Zigachev 		1,
884b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
885b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_ENABLE);
886b843c749SSergey Zigachev 	set_reg_field_value(
887b843c749SSergey Zigachev 		value,
888b843c749SSergey Zigachev 		1,
889b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
890b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_URGENT_DURING_REQUEST);
891b843c749SSergey Zigachev 	set_reg_field_value(
892b843c749SSergey Zigachev 		value,
893b843c749SSergey Zigachev 		1,
894b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
895b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_NOT_SELF_REFRESH_DURING_REQUEST);
896b843c749SSergey Zigachev 	dm_write_reg(ctx, nbp_pstate_ctrl_addr, value);
897b843c749SSergey Zigachev 
898b843c749SSergey Zigachev 	/* Write watermark set B */
899b843c749SSergey Zigachev 	value = dm_read_reg(ctx, nbp_pstate_ctrl_addr);
900b843c749SSergey Zigachev 	set_reg_field_value(
901b843c749SSergey Zigachev 		value,
902b843c749SSergey Zigachev 		marks.b_mark,
903b843c749SSergey Zigachev 		DPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
904b843c749SSergey Zigachev 		NB_PSTATE_CHANGE_WATERMARK);
905b843c749SSergey Zigachev 	dm_write_reg(ctx, nbp_pstate_ctrl_addr, value);
906b843c749SSergey Zigachev }
907b843c749SSergey Zigachev 
program_nbp_watermark_l(const struct dc_context * ctx,struct dce_watermarks marks)908b843c749SSergey Zigachev static void program_nbp_watermark_l(
909b843c749SSergey Zigachev 	const struct dc_context *ctx,
910b843c749SSergey Zigachev 	struct dce_watermarks marks)
911b843c749SSergey Zigachev {
912b843c749SSergey Zigachev 	program_nbp_watermark(ctx,
913b843c749SSergey Zigachev 			mmDPGV0_WATERMARK_MASK_CONTROL,
914b843c749SSergey Zigachev 			mmDPGV0_PIPE_NB_PSTATE_CHANGE_CONTROL,
915b843c749SSergey Zigachev 			marks);
916b843c749SSergey Zigachev }
917b843c749SSergey Zigachev 
program_nbp_watermark_c(const struct dc_context * ctx,struct dce_watermarks marks)918b843c749SSergey Zigachev static void program_nbp_watermark_c(
919b843c749SSergey Zigachev 	const struct dc_context *ctx,
920b843c749SSergey Zigachev 	struct dce_watermarks marks)
921b843c749SSergey Zigachev {
922b843c749SSergey Zigachev 	program_nbp_watermark(ctx,
923b843c749SSergey Zigachev 			mmDPGV1_WATERMARK_MASK_CONTROL,
924b843c749SSergey Zigachev 			mmDPGV1_PIPE_NB_PSTATE_CHANGE_CONTROL,
925b843c749SSergey Zigachev 			marks);
926b843c749SSergey Zigachev }
927b843c749SSergey Zigachev 
928*78973132SSergey Zigachev static
dce_mem_input_v_program_display_marks(struct mem_input * mem_input,struct dce_watermarks nbp,struct dce_watermarks stutter,struct dce_watermarks stutter_enter,struct dce_watermarks urgent,uint32_t total_dest_line_time_ns)929b843c749SSergey Zigachev void dce_mem_input_v_program_display_marks(
930b843c749SSergey Zigachev 	struct mem_input *mem_input,
931b843c749SSergey Zigachev 	struct dce_watermarks nbp,
932b843c749SSergey Zigachev 	struct dce_watermarks stutter,
933b843c749SSergey Zigachev 	struct dce_watermarks stutter_enter,
934b843c749SSergey Zigachev 	struct dce_watermarks urgent,
935b843c749SSergey Zigachev 	uint32_t total_dest_line_time_ns)
936b843c749SSergey Zigachev {
937b843c749SSergey Zigachev 	program_urgency_watermark_l(
938b843c749SSergey Zigachev 		mem_input->ctx,
939b843c749SSergey Zigachev 		urgent,
940b843c749SSergey Zigachev 		total_dest_line_time_ns);
941b843c749SSergey Zigachev 
942b843c749SSergey Zigachev 	program_nbp_watermark_l(
943b843c749SSergey Zigachev 		mem_input->ctx,
944b843c749SSergey Zigachev 		nbp);
945b843c749SSergey Zigachev 
946b843c749SSergey Zigachev 	program_stutter_watermark_l(
947b843c749SSergey Zigachev 		mem_input->ctx,
948b843c749SSergey Zigachev 		stutter);
949b843c749SSergey Zigachev 
950b843c749SSergey Zigachev }
951b843c749SSergey Zigachev 
952*78973132SSergey Zigachev static
dce_mem_input_program_chroma_display_marks(struct mem_input * mem_input,struct dce_watermarks nbp,struct dce_watermarks stutter,struct dce_watermarks urgent,uint32_t total_dest_line_time_ns)953b843c749SSergey Zigachev void dce_mem_input_program_chroma_display_marks(
954b843c749SSergey Zigachev 	struct mem_input *mem_input,
955b843c749SSergey Zigachev 	struct dce_watermarks nbp,
956b843c749SSergey Zigachev 	struct dce_watermarks stutter,
957b843c749SSergey Zigachev 	struct dce_watermarks urgent,
958b843c749SSergey Zigachev 	uint32_t total_dest_line_time_ns)
959b843c749SSergey Zigachev {
960b843c749SSergey Zigachev 	program_urgency_watermark_c(
961b843c749SSergey Zigachev 		mem_input->ctx,
962b843c749SSergey Zigachev 		urgent,
963b843c749SSergey Zigachev 		total_dest_line_time_ns);
964b843c749SSergey Zigachev 
965b843c749SSergey Zigachev 	program_nbp_watermark_c(
966b843c749SSergey Zigachev 		mem_input->ctx,
967b843c749SSergey Zigachev 		nbp);
968b843c749SSergey Zigachev 
969b843c749SSergey Zigachev 	program_stutter_watermark_c(
970b843c749SSergey Zigachev 		mem_input->ctx,
971b843c749SSergey Zigachev 		stutter);
972b843c749SSergey Zigachev }
973b843c749SSergey Zigachev 
974*78973132SSergey Zigachev static
dce110_allocate_mem_input_v(struct mem_input * mi,uint32_t h_total,uint32_t v_total,uint32_t pix_clk_khz,uint32_t total_stream_num)975b843c749SSergey Zigachev void dce110_allocate_mem_input_v(
976b843c749SSergey Zigachev 	struct mem_input *mi,
977b843c749SSergey Zigachev 	uint32_t h_total,/* for current stream */
978b843c749SSergey Zigachev 	uint32_t v_total,/* for current stream */
979b843c749SSergey Zigachev 	uint32_t pix_clk_khz,/* for current stream */
980b843c749SSergey Zigachev 	uint32_t total_stream_num)
981b843c749SSergey Zigachev {
982b843c749SSergey Zigachev 	uint32_t addr;
983b843c749SSergey Zigachev 	uint32_t value;
984b843c749SSergey Zigachev 	uint32_t pix_dur;
985b843c749SSergey Zigachev 	if (pix_clk_khz != 0) {
986b843c749SSergey Zigachev 		addr = mmDPGV0_PIPE_ARBITRATION_CONTROL1;
987b843c749SSergey Zigachev 		value = dm_read_reg(mi->ctx, addr);
988b843c749SSergey Zigachev 		pix_dur = 1000000000ULL / pix_clk_khz;
989b843c749SSergey Zigachev 		set_reg_field_value(
990b843c749SSergey Zigachev 			value,
991b843c749SSergey Zigachev 			pix_dur,
992b843c749SSergey Zigachev 			DPGV0_PIPE_ARBITRATION_CONTROL1,
993b843c749SSergey Zigachev 			PIXEL_DURATION);
994b843c749SSergey Zigachev 		dm_write_reg(mi->ctx, addr, value);
995b843c749SSergey Zigachev 
996b843c749SSergey Zigachev 		addr = mmDPGV1_PIPE_ARBITRATION_CONTROL1;
997b843c749SSergey Zigachev 		value = dm_read_reg(mi->ctx, addr);
998b843c749SSergey Zigachev 		pix_dur = 1000000000ULL / pix_clk_khz;
999b843c749SSergey Zigachev 		set_reg_field_value(
1000b843c749SSergey Zigachev 			value,
1001b843c749SSergey Zigachev 			pix_dur,
1002b843c749SSergey Zigachev 			DPGV1_PIPE_ARBITRATION_CONTROL1,
1003b843c749SSergey Zigachev 			PIXEL_DURATION);
1004b843c749SSergey Zigachev 		dm_write_reg(mi->ctx, addr, value);
1005b843c749SSergey Zigachev 
1006b843c749SSergey Zigachev 		addr = mmDPGV0_PIPE_ARBITRATION_CONTROL2;
1007b843c749SSergey Zigachev 		value = 0x4000800;
1008b843c749SSergey Zigachev 		dm_write_reg(mi->ctx, addr, value);
1009b843c749SSergey Zigachev 
1010b843c749SSergey Zigachev 		addr = mmDPGV1_PIPE_ARBITRATION_CONTROL2;
1011b843c749SSergey Zigachev 		value = 0x4000800;
1012b843c749SSergey Zigachev 		dm_write_reg(mi->ctx, addr, value);
1013b843c749SSergey Zigachev 	}
1014b843c749SSergey Zigachev 
1015b843c749SSergey Zigachev }
1016b843c749SSergey Zigachev 
1017*78973132SSergey Zigachev static
dce110_free_mem_input_v(struct mem_input * mi,uint32_t total_stream_num)1018b843c749SSergey Zigachev void dce110_free_mem_input_v(
1019b843c749SSergey Zigachev 	struct mem_input *mi,
1020b843c749SSergey Zigachev 	uint32_t total_stream_num)
1021b843c749SSergey Zigachev {
1022b843c749SSergey Zigachev }
1023b843c749SSergey Zigachev 
1024b843c749SSergey Zigachev static const struct mem_input_funcs dce110_mem_input_v_funcs = {
1025b843c749SSergey Zigachev 	.mem_input_program_display_marks =
1026b843c749SSergey Zigachev 			dce_mem_input_v_program_display_marks,
1027b843c749SSergey Zigachev 	.mem_input_program_chroma_display_marks =
1028b843c749SSergey Zigachev 			dce_mem_input_program_chroma_display_marks,
1029b843c749SSergey Zigachev 	.allocate_mem_input = dce110_allocate_mem_input_v,
1030b843c749SSergey Zigachev 	.free_mem_input = dce110_free_mem_input_v,
1031b843c749SSergey Zigachev 	.mem_input_program_surface_flip_and_addr =
1032b843c749SSergey Zigachev 			dce_mem_input_v_program_surface_flip_and_addr,
1033b843c749SSergey Zigachev 	.mem_input_program_pte_vm =
1034b843c749SSergey Zigachev 			dce_mem_input_v_program_pte_vm,
1035b843c749SSergey Zigachev 	.mem_input_program_surface_config =
1036b843c749SSergey Zigachev 			dce_mem_input_v_program_surface_config,
1037b843c749SSergey Zigachev 	.mem_input_is_flip_pending =
1038b843c749SSergey Zigachev 			dce_mem_input_v_is_surface_pending
1039b843c749SSergey Zigachev };
1040b843c749SSergey Zigachev /*****************************************/
1041b843c749SSergey Zigachev /* Constructor, Destructor               */
1042b843c749SSergey Zigachev /*****************************************/
1043b843c749SSergey Zigachev 
dce110_mem_input_v_construct(struct dce_mem_input * dce_mi,struct dc_context * ctx)1044b843c749SSergey Zigachev void dce110_mem_input_v_construct(
1045b843c749SSergey Zigachev 	struct dce_mem_input *dce_mi,
1046b843c749SSergey Zigachev 	struct dc_context *ctx)
1047b843c749SSergey Zigachev {
1048b843c749SSergey Zigachev 	dce_mi->base.funcs = &dce110_mem_input_v_funcs;
1049b843c749SSergey Zigachev 	dce_mi->base.ctx = ctx;
1050b843c749SSergey Zigachev }
1051b843c749SSergey Zigachev 
1052