xref: /dflybsd-src/sys/dev/drm/amd/display/dc/dce100/dce100_hw_sequencer.c (revision b843c749addef9340ee7d4e250b09fdd492602a1)
1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev  * Copyright 2015 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 #include "dm_services.h"
26*b843c749SSergey Zigachev #include "dc.h"
27*b843c749SSergey Zigachev #include "core_types.h"
28*b843c749SSergey Zigachev #include "hw_sequencer.h"
29*b843c749SSergey Zigachev #include "dce100_hw_sequencer.h"
30*b843c749SSergey Zigachev #include "resource.h"
31*b843c749SSergey Zigachev 
32*b843c749SSergey Zigachev #include "dce110/dce110_hw_sequencer.h"
33*b843c749SSergey Zigachev 
34*b843c749SSergey Zigachev /* include DCE10 register header files */
35*b843c749SSergey Zigachev #include "dce/dce_10_0_d.h"
36*b843c749SSergey Zigachev #include "dce/dce_10_0_sh_mask.h"
37*b843c749SSergey Zigachev 
38*b843c749SSergey Zigachev struct dce100_hw_seq_reg_offsets {
39*b843c749SSergey Zigachev 	uint32_t blnd;
40*b843c749SSergey Zigachev 	uint32_t crtc;
41*b843c749SSergey Zigachev };
42*b843c749SSergey Zigachev 
43*b843c749SSergey Zigachev static const struct dce100_hw_seq_reg_offsets reg_offsets[] = {
44*b843c749SSergey Zigachev {
45*b843c749SSergey Zigachev 	.crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
46*b843c749SSergey Zigachev },
47*b843c749SSergey Zigachev {
48*b843c749SSergey Zigachev 	.crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
49*b843c749SSergey Zigachev },
50*b843c749SSergey Zigachev {
51*b843c749SSergey Zigachev 	.crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
52*b843c749SSergey Zigachev },
53*b843c749SSergey Zigachev {
54*b843c749SSergey Zigachev 	.crtc = (mmCRTC3_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
55*b843c749SSergey Zigachev },
56*b843c749SSergey Zigachev {
57*b843c749SSergey Zigachev 	.crtc = (mmCRTC4_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
58*b843c749SSergey Zigachev },
59*b843c749SSergey Zigachev {
60*b843c749SSergey Zigachev 	.crtc = (mmCRTC5_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
61*b843c749SSergey Zigachev }
62*b843c749SSergey Zigachev };
63*b843c749SSergey Zigachev 
64*b843c749SSergey Zigachev #define HW_REG_CRTC(reg, id)\
65*b843c749SSergey Zigachev 	(reg + reg_offsets[id].crtc)
66*b843c749SSergey Zigachev 
67*b843c749SSergey Zigachev /*******************************************************************************
68*b843c749SSergey Zigachev  * Private definitions
69*b843c749SSergey Zigachev  ******************************************************************************/
70*b843c749SSergey Zigachev /***************************PIPE_CONTROL***********************************/
71*b843c749SSergey Zigachev 
dce100_enable_display_power_gating(struct dc * dc,uint8_t controller_id,struct dc_bios * dcb,enum pipe_gating_control power_gating)72*b843c749SSergey Zigachev bool dce100_enable_display_power_gating(
73*b843c749SSergey Zigachev 	struct dc *dc,
74*b843c749SSergey Zigachev 	uint8_t controller_id,
75*b843c749SSergey Zigachev 	struct dc_bios *dcb,
76*b843c749SSergey Zigachev 	enum pipe_gating_control power_gating)
77*b843c749SSergey Zigachev {
78*b843c749SSergey Zigachev 	enum bp_result bp_result = BP_RESULT_OK;
79*b843c749SSergey Zigachev 	enum bp_pipe_control_action cntl;
80*b843c749SSergey Zigachev 	struct dc_context *ctx = dc->ctx;
81*b843c749SSergey Zigachev 
82*b843c749SSergey Zigachev 	if (power_gating == PIPE_GATING_CONTROL_INIT)
83*b843c749SSergey Zigachev 		cntl = ASIC_PIPE_INIT;
84*b843c749SSergey Zigachev 	else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
85*b843c749SSergey Zigachev 		cntl = ASIC_PIPE_ENABLE;
86*b843c749SSergey Zigachev 	else
87*b843c749SSergey Zigachev 		cntl = ASIC_PIPE_DISABLE;
88*b843c749SSergey Zigachev 
89*b843c749SSergey Zigachev 	if (!(power_gating == PIPE_GATING_CONTROL_INIT && controller_id != 0)){
90*b843c749SSergey Zigachev 
91*b843c749SSergey Zigachev 		bp_result = dcb->funcs->enable_disp_power_gating(
92*b843c749SSergey Zigachev 						dcb, controller_id + 1, cntl);
93*b843c749SSergey Zigachev 
94*b843c749SSergey Zigachev 		/* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
95*b843c749SSergey Zigachev 		 * by default when command table is called
96*b843c749SSergey Zigachev 		 */
97*b843c749SSergey Zigachev 		dm_write_reg(ctx,
98*b843c749SSergey Zigachev 			HW_REG_CRTC(mmMASTER_UPDATE_MODE, controller_id),
99*b843c749SSergey Zigachev 			0);
100*b843c749SSergey Zigachev 	}
101*b843c749SSergey Zigachev 
102*b843c749SSergey Zigachev 	if (bp_result == BP_RESULT_OK)
103*b843c749SSergey Zigachev 		return true;
104*b843c749SSergey Zigachev 	else
105*b843c749SSergey Zigachev 		return false;
106*b843c749SSergey Zigachev }
107*b843c749SSergey Zigachev 
dce100_pplib_apply_display_requirements(struct dc * dc,struct dc_state * context)108*b843c749SSergey Zigachev static void dce100_pplib_apply_display_requirements(
109*b843c749SSergey Zigachev 	struct dc *dc,
110*b843c749SSergey Zigachev 	struct dc_state *context)
111*b843c749SSergey Zigachev {
112*b843c749SSergey Zigachev 	struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
113*b843c749SSergey Zigachev 
114*b843c749SSergey Zigachev 	pp_display_cfg->avail_mclk_switch_time_us =
115*b843c749SSergey Zigachev 						dce110_get_min_vblank_time_us(context);
116*b843c749SSergey Zigachev 	/*pp_display_cfg->min_memory_clock_khz = context->bw.dce.yclk_khz
117*b843c749SSergey Zigachev 		/ MEMORY_TYPE_MULTIPLIER;*/
118*b843c749SSergey Zigachev 
119*b843c749SSergey Zigachev 	dce110_fill_display_configs(context, pp_display_cfg);
120*b843c749SSergey Zigachev 
121*b843c749SSergey Zigachev 	if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof(
122*b843c749SSergey Zigachev 			struct dm_pp_display_configuration)) !=  0)
123*b843c749SSergey Zigachev 		dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
124*b843c749SSergey Zigachev 
125*b843c749SSergey Zigachev 	dc->prev_display_config = *pp_display_cfg;
126*b843c749SSergey Zigachev }
127*b843c749SSergey Zigachev 
128*b843c749SSergey Zigachev /* unit: in_khz before mode set, get pixel clock from context. ASIC register
129*b843c749SSergey Zigachev  * may not be programmed yet
130*b843c749SSergey Zigachev  */
get_max_pixel_clock_for_all_paths(struct dc * dc,struct dc_state * context)131*b843c749SSergey Zigachev static uint32_t get_max_pixel_clock_for_all_paths(
132*b843c749SSergey Zigachev 	struct dc *dc,
133*b843c749SSergey Zigachev 	struct dc_state *context)
134*b843c749SSergey Zigachev {
135*b843c749SSergey Zigachev 	uint32_t max_pix_clk = 0;
136*b843c749SSergey Zigachev 	int i;
137*b843c749SSergey Zigachev 
138*b843c749SSergey Zigachev 	for (i = 0; i < MAX_PIPES; i++) {
139*b843c749SSergey Zigachev 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
140*b843c749SSergey Zigachev 
141*b843c749SSergey Zigachev 		if (pipe_ctx->stream == NULL)
142*b843c749SSergey Zigachev 			continue;
143*b843c749SSergey Zigachev 
144*b843c749SSergey Zigachev 		/* do not check under lay */
145*b843c749SSergey Zigachev 		if (pipe_ctx->top_pipe)
146*b843c749SSergey Zigachev 			continue;
147*b843c749SSergey Zigachev 
148*b843c749SSergey Zigachev 		if (pipe_ctx->stream_res.pix_clk_params.requested_pix_clk > max_pix_clk)
149*b843c749SSergey Zigachev 			max_pix_clk =
150*b843c749SSergey Zigachev 				pipe_ctx->stream_res.pix_clk_params.requested_pix_clk;
151*b843c749SSergey Zigachev 	}
152*b843c749SSergey Zigachev 	return max_pix_clk;
153*b843c749SSergey Zigachev }
154*b843c749SSergey Zigachev 
dce100_set_bandwidth(struct dc * dc,struct dc_state * context,bool decrease_allowed)155*b843c749SSergey Zigachev void dce100_set_bandwidth(
156*b843c749SSergey Zigachev 		struct dc *dc,
157*b843c749SSergey Zigachev 		struct dc_state *context,
158*b843c749SSergey Zigachev 		bool decrease_allowed)
159*b843c749SSergey Zigachev {
160*b843c749SSergey Zigachev 	struct dc_clocks req_clks;
161*b843c749SSergey Zigachev 
162*b843c749SSergey Zigachev 	req_clks.dispclk_khz = context->bw.dce.dispclk_khz * 115 / 100;
163*b843c749SSergey Zigachev 	req_clks.phyclk_khz = get_max_pixel_clock_for_all_paths(dc, context);
164*b843c749SSergey Zigachev 
165*b843c749SSergey Zigachev 	dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
166*b843c749SSergey Zigachev 
167*b843c749SSergey Zigachev 	dc->res_pool->dccg->funcs->update_clocks(
168*b843c749SSergey Zigachev 			dc->res_pool->dccg,
169*b843c749SSergey Zigachev 			&req_clks,
170*b843c749SSergey Zigachev 			decrease_allowed);
171*b843c749SSergey Zigachev 
172*b843c749SSergey Zigachev 	dce100_pplib_apply_display_requirements(dc, context);
173*b843c749SSergey Zigachev }
174*b843c749SSergey Zigachev 
175*b843c749SSergey Zigachev 
176*b843c749SSergey Zigachev /**************************************************************************/
177*b843c749SSergey Zigachev 
dce100_hw_sequencer_construct(struct dc * dc)178*b843c749SSergey Zigachev void dce100_hw_sequencer_construct(struct dc *dc)
179*b843c749SSergey Zigachev {
180*b843c749SSergey Zigachev 	dce110_hw_sequencer_construct(dc);
181*b843c749SSergey Zigachev 
182*b843c749SSergey Zigachev 	dc->hwss.enable_display_power_gating = dce100_enable_display_power_gating;
183*b843c749SSergey Zigachev 	dc->hwss.set_bandwidth = dce100_set_bandwidth;
184*b843c749SSergey Zigachev 	dc->hwss.pplib_apply_display_requirements =
185*b843c749SSergey Zigachev 			dce100_pplib_apply_display_requirements;
186*b843c749SSergey Zigachev }
187*b843c749SSergey Zigachev 
188