xref: /dflybsd-src/sys/dev/drm/amd/display/dc/dce80/dce80_resource.c (revision 789731325bde747251c28a37e0a00ed4efb88c46)
1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2012-15 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev  *
4b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10b843c749SSergey Zigachev  *
11b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13b843c749SSergey Zigachev  *
14b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21b843c749SSergey Zigachev  *
22b843c749SSergey Zigachev  * Authors: AMD
23b843c749SSergey Zigachev  *
24b843c749SSergey Zigachev  */
25b843c749SSergey Zigachev 
26b843c749SSergey Zigachev #include "dce/dce_8_0_d.h"
27b843c749SSergey Zigachev #include "dce/dce_8_0_sh_mask.h"
28b843c749SSergey Zigachev 
29b843c749SSergey Zigachev #include "dm_services.h"
30b843c749SSergey Zigachev 
31b843c749SSergey Zigachev #include "link_encoder.h"
32b843c749SSergey Zigachev #include "stream_encoder.h"
33b843c749SSergey Zigachev 
34b843c749SSergey Zigachev #include "resource.h"
35b843c749SSergey Zigachev #include "include/irq_service_interface.h"
36b843c749SSergey Zigachev #include "irq/dce80/irq_service_dce80.h"
37b843c749SSergey Zigachev #include "dce110/dce110_timing_generator.h"
38b843c749SSergey Zigachev #include "dce110/dce110_resource.h"
39b843c749SSergey Zigachev #include "dce80/dce80_timing_generator.h"
40b843c749SSergey Zigachev #include "dce/dce_mem_input.h"
41b843c749SSergey Zigachev #include "dce/dce_link_encoder.h"
42b843c749SSergey Zigachev #include "dce/dce_stream_encoder.h"
43b843c749SSergey Zigachev #include "dce/dce_mem_input.h"
44b843c749SSergey Zigachev #include "dce/dce_ipp.h"
45b843c749SSergey Zigachev #include "dce/dce_transform.h"
46b843c749SSergey Zigachev #include "dce/dce_opp.h"
47b843c749SSergey Zigachev #include "dce/dce_clocks.h"
48b843c749SSergey Zigachev #include "dce/dce_clock_source.h"
49b843c749SSergey Zigachev #include "dce/dce_audio.h"
50b843c749SSergey Zigachev #include "dce/dce_hwseq.h"
51b843c749SSergey Zigachev #include "dce80/dce80_hw_sequencer.h"
52b843c749SSergey Zigachev #include "dce100/dce100_resource.h"
53b843c749SSergey Zigachev 
54b843c749SSergey Zigachev #include "reg_helper.h"
55b843c749SSergey Zigachev 
56b843c749SSergey Zigachev #include "dce/dce_dmcu.h"
57b843c749SSergey Zigachev #include "dce/dce_aux.h"
58b843c749SSergey Zigachev #include "dce/dce_abm.h"
59b843c749SSergey Zigachev /* TODO remove this include */
60b843c749SSergey Zigachev 
61b843c749SSergey Zigachev #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
62b843c749SSergey Zigachev #include "gmc/gmc_7_1_d.h"
63b843c749SSergey Zigachev #include "gmc/gmc_7_1_sh_mask.h"
64b843c749SSergey Zigachev #endif
65b843c749SSergey Zigachev 
66*78973132SSergey Zigachev #include "dce80/dce80_resource.h"
67*78973132SSergey Zigachev 
68b843c749SSergey Zigachev #ifndef mmDP_DPHY_INTERNAL_CTRL
69b843c749SSergey Zigachev #define mmDP_DPHY_INTERNAL_CTRL                         0x1CDE
70b843c749SSergey Zigachev #define mmDP0_DP_DPHY_INTERNAL_CTRL                     0x1CDE
71b843c749SSergey Zigachev #define mmDP1_DP_DPHY_INTERNAL_CTRL                     0x1FDE
72b843c749SSergey Zigachev #define mmDP2_DP_DPHY_INTERNAL_CTRL                     0x42DE
73b843c749SSergey Zigachev #define mmDP3_DP_DPHY_INTERNAL_CTRL                     0x45DE
74b843c749SSergey Zigachev #define mmDP4_DP_DPHY_INTERNAL_CTRL                     0x48DE
75b843c749SSergey Zigachev #define mmDP5_DP_DPHY_INTERNAL_CTRL                     0x4BDE
76b843c749SSergey Zigachev #define mmDP6_DP_DPHY_INTERNAL_CTRL                     0x4EDE
77b843c749SSergey Zigachev #endif
78b843c749SSergey Zigachev 
79b843c749SSergey Zigachev 
80b843c749SSergey Zigachev #ifndef mmBIOS_SCRATCH_2
81b843c749SSergey Zigachev 	#define mmBIOS_SCRATCH_2 0x05CB
82b843c749SSergey Zigachev 	#define mmBIOS_SCRATCH_6 0x05CF
83b843c749SSergey Zigachev #endif
84b843c749SSergey Zigachev 
85b843c749SSergey Zigachev #ifndef mmDP_DPHY_FAST_TRAINING
86b843c749SSergey Zigachev 	#define mmDP_DPHY_FAST_TRAINING                         0x1CCE
87b843c749SSergey Zigachev 	#define mmDP0_DP_DPHY_FAST_TRAINING                     0x1CCE
88b843c749SSergey Zigachev 	#define mmDP1_DP_DPHY_FAST_TRAINING                     0x1FCE
89b843c749SSergey Zigachev 	#define mmDP2_DP_DPHY_FAST_TRAINING                     0x42CE
90b843c749SSergey Zigachev 	#define mmDP3_DP_DPHY_FAST_TRAINING                     0x45CE
91b843c749SSergey Zigachev 	#define mmDP4_DP_DPHY_FAST_TRAINING                     0x48CE
92b843c749SSergey Zigachev 	#define mmDP5_DP_DPHY_FAST_TRAINING                     0x4BCE
93b843c749SSergey Zigachev 	#define mmDP6_DP_DPHY_FAST_TRAINING                     0x4ECE
94b843c749SSergey Zigachev #endif
95b843c749SSergey Zigachev 
96b843c749SSergey Zigachev 
97b843c749SSergey Zigachev #ifndef mmHPD_DC_HPD_CONTROL
98b843c749SSergey Zigachev 	#define mmHPD_DC_HPD_CONTROL                            0x189A
99b843c749SSergey Zigachev 	#define mmHPD0_DC_HPD_CONTROL                           0x189A
100b843c749SSergey Zigachev 	#define mmHPD1_DC_HPD_CONTROL                           0x18A2
101b843c749SSergey Zigachev 	#define mmHPD2_DC_HPD_CONTROL                           0x18AA
102b843c749SSergey Zigachev 	#define mmHPD3_DC_HPD_CONTROL                           0x18B2
103b843c749SSergey Zigachev 	#define mmHPD4_DC_HPD_CONTROL                           0x18BA
104b843c749SSergey Zigachev 	#define mmHPD5_DC_HPD_CONTROL                           0x18C2
105b843c749SSergey Zigachev #endif
106b843c749SSergey Zigachev 
107b843c749SSergey Zigachev #define DCE11_DIG_FE_CNTL 0x4a00
108b843c749SSergey Zigachev #define DCE11_DIG_BE_CNTL 0x4a47
109b843c749SSergey Zigachev #define DCE11_DP_SEC 0x4ac3
110b843c749SSergey Zigachev 
111b843c749SSergey Zigachev static const struct dce110_timing_generator_offsets dce80_tg_offsets[] = {
112b843c749SSergey Zigachev 		{
113b843c749SSergey Zigachev 			.crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
114b843c749SSergey Zigachev 			.dcp =  (mmGRPH_CONTROL - mmGRPH_CONTROL),
115b843c749SSergey Zigachev 			.dmif = (mmDMIF_PG0_DPG_WATERMARK_MASK_CONTROL
116b843c749SSergey Zigachev 					- mmDPG_WATERMARK_MASK_CONTROL),
117b843c749SSergey Zigachev 		},
118b843c749SSergey Zigachev 		{
119b843c749SSergey Zigachev 			.crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
120b843c749SSergey Zigachev 			.dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
121b843c749SSergey Zigachev 			.dmif = (mmDMIF_PG1_DPG_WATERMARK_MASK_CONTROL
122b843c749SSergey Zigachev 					- mmDPG_WATERMARK_MASK_CONTROL),
123b843c749SSergey Zigachev 		},
124b843c749SSergey Zigachev 		{
125b843c749SSergey Zigachev 			.crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
126b843c749SSergey Zigachev 			.dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
127b843c749SSergey Zigachev 			.dmif = (mmDMIF_PG2_DPG_WATERMARK_MASK_CONTROL
128b843c749SSergey Zigachev 					- mmDPG_WATERMARK_MASK_CONTROL),
129b843c749SSergey Zigachev 		},
130b843c749SSergey Zigachev 		{
131b843c749SSergey Zigachev 			.crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
132b843c749SSergey Zigachev 			.dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
133b843c749SSergey Zigachev 			.dmif = (mmDMIF_PG3_DPG_WATERMARK_MASK_CONTROL
134b843c749SSergey Zigachev 					- mmDPG_WATERMARK_MASK_CONTROL),
135b843c749SSergey Zigachev 		},
136b843c749SSergey Zigachev 		{
137b843c749SSergey Zigachev 			.crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
138b843c749SSergey Zigachev 			.dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
139b843c749SSergey Zigachev 			.dmif = (mmDMIF_PG4_DPG_WATERMARK_MASK_CONTROL
140b843c749SSergey Zigachev 					- mmDPG_WATERMARK_MASK_CONTROL),
141b843c749SSergey Zigachev 		},
142b843c749SSergey Zigachev 		{
143b843c749SSergey Zigachev 			.crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
144b843c749SSergey Zigachev 			.dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
145b843c749SSergey Zigachev 			.dmif = (mmDMIF_PG5_DPG_WATERMARK_MASK_CONTROL
146b843c749SSergey Zigachev 					- mmDPG_WATERMARK_MASK_CONTROL),
147b843c749SSergey Zigachev 		}
148b843c749SSergey Zigachev };
149b843c749SSergey Zigachev 
150b843c749SSergey Zigachev /* set register offset */
151b843c749SSergey Zigachev #define SR(reg_name)\
152b843c749SSergey Zigachev 	.reg_name = mm ## reg_name
153b843c749SSergey Zigachev 
154b843c749SSergey Zigachev /* set register offset with instance */
155b843c749SSergey Zigachev #define SRI(reg_name, block, id)\
156b843c749SSergey Zigachev 	.reg_name = mm ## block ## id ## _ ## reg_name
157b843c749SSergey Zigachev 
158b843c749SSergey Zigachev 
159b843c749SSergey Zigachev static const struct dccg_registers disp_clk_regs = {
160b843c749SSergey Zigachev 		CLK_COMMON_REG_LIST_DCE_BASE()
161b843c749SSergey Zigachev };
162b843c749SSergey Zigachev 
163b843c749SSergey Zigachev static const struct dccg_shift disp_clk_shift = {
164b843c749SSergey Zigachev 		CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
165b843c749SSergey Zigachev };
166b843c749SSergey Zigachev 
167b843c749SSergey Zigachev static const struct dccg_mask disp_clk_mask = {
168b843c749SSergey Zigachev 		CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
169b843c749SSergey Zigachev };
170b843c749SSergey Zigachev 
171b843c749SSergey Zigachev #define ipp_regs(id)\
172b843c749SSergey Zigachev [id] = {\
173b843c749SSergey Zigachev 		IPP_COMMON_REG_LIST_DCE_BASE(id)\
174b843c749SSergey Zigachev }
175b843c749SSergey Zigachev 
176b843c749SSergey Zigachev static const struct dce_ipp_registers ipp_regs[] = {
177b843c749SSergey Zigachev 		ipp_regs(0),
178b843c749SSergey Zigachev 		ipp_regs(1),
179b843c749SSergey Zigachev 		ipp_regs(2),
180b843c749SSergey Zigachev 		ipp_regs(3),
181b843c749SSergey Zigachev 		ipp_regs(4),
182b843c749SSergey Zigachev 		ipp_regs(5)
183b843c749SSergey Zigachev };
184b843c749SSergey Zigachev 
185b843c749SSergey Zigachev static const struct dce_ipp_shift ipp_shift = {
186b843c749SSergey Zigachev 		IPP_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
187b843c749SSergey Zigachev };
188b843c749SSergey Zigachev 
189b843c749SSergey Zigachev static const struct dce_ipp_mask ipp_mask = {
190b843c749SSergey Zigachev 		IPP_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
191b843c749SSergey Zigachev };
192b843c749SSergey Zigachev 
193b843c749SSergey Zigachev #define transform_regs(id)\
194b843c749SSergey Zigachev [id] = {\
195b843c749SSergey Zigachev 		XFM_COMMON_REG_LIST_DCE80(id)\
196b843c749SSergey Zigachev }
197b843c749SSergey Zigachev 
198b843c749SSergey Zigachev static const struct dce_transform_registers xfm_regs[] = {
199b843c749SSergey Zigachev 		transform_regs(0),
200b843c749SSergey Zigachev 		transform_regs(1),
201b843c749SSergey Zigachev 		transform_regs(2),
202b843c749SSergey Zigachev 		transform_regs(3),
203b843c749SSergey Zigachev 		transform_regs(4),
204b843c749SSergey Zigachev 		transform_regs(5)
205b843c749SSergey Zigachev };
206b843c749SSergey Zigachev 
207b843c749SSergey Zigachev static const struct dce_transform_shift xfm_shift = {
208b843c749SSergey Zigachev 		XFM_COMMON_MASK_SH_LIST_DCE80(__SHIFT)
209b843c749SSergey Zigachev };
210b843c749SSergey Zigachev 
211b843c749SSergey Zigachev static const struct dce_transform_mask xfm_mask = {
212b843c749SSergey Zigachev 		XFM_COMMON_MASK_SH_LIST_DCE80(_MASK)
213b843c749SSergey Zigachev };
214b843c749SSergey Zigachev 
215b843c749SSergey Zigachev #define aux_regs(id)\
216b843c749SSergey Zigachev [id] = {\
217b843c749SSergey Zigachev 	AUX_REG_LIST(id)\
218b843c749SSergey Zigachev }
219b843c749SSergey Zigachev 
220b843c749SSergey Zigachev static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
221b843c749SSergey Zigachev 	aux_regs(0),
222b843c749SSergey Zigachev 	aux_regs(1),
223b843c749SSergey Zigachev 	aux_regs(2),
224b843c749SSergey Zigachev 	aux_regs(3),
225b843c749SSergey Zigachev 	aux_regs(4),
226b843c749SSergey Zigachev 	aux_regs(5)
227b843c749SSergey Zigachev };
228b843c749SSergey Zigachev 
229b843c749SSergey Zigachev #define hpd_regs(id)\
230b843c749SSergey Zigachev [id] = {\
231b843c749SSergey Zigachev 	HPD_REG_LIST(id)\
232b843c749SSergey Zigachev }
233b843c749SSergey Zigachev 
234b843c749SSergey Zigachev static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
235b843c749SSergey Zigachev 		hpd_regs(0),
236b843c749SSergey Zigachev 		hpd_regs(1),
237b843c749SSergey Zigachev 		hpd_regs(2),
238b843c749SSergey Zigachev 		hpd_regs(3),
239b843c749SSergey Zigachev 		hpd_regs(4),
240b843c749SSergey Zigachev 		hpd_regs(5)
241b843c749SSergey Zigachev };
242b843c749SSergey Zigachev 
243b843c749SSergey Zigachev #define link_regs(id)\
244b843c749SSergey Zigachev [id] = {\
245b843c749SSergey Zigachev 	LE_DCE80_REG_LIST(id)\
246b843c749SSergey Zigachev }
247b843c749SSergey Zigachev 
248b843c749SSergey Zigachev static const struct dce110_link_enc_registers link_enc_regs[] = {
249b843c749SSergey Zigachev 	link_regs(0),
250b843c749SSergey Zigachev 	link_regs(1),
251b843c749SSergey Zigachev 	link_regs(2),
252b843c749SSergey Zigachev 	link_regs(3),
253b843c749SSergey Zigachev 	link_regs(4),
254b843c749SSergey Zigachev 	link_regs(5),
255b843c749SSergey Zigachev 	link_regs(6),
256b843c749SSergey Zigachev };
257b843c749SSergey Zigachev 
258b843c749SSergey Zigachev #define stream_enc_regs(id)\
259b843c749SSergey Zigachev [id] = {\
260b843c749SSergey Zigachev 	SE_COMMON_REG_LIST_DCE_BASE(id),\
261b843c749SSergey Zigachev 	.AFMT_CNTL = 0,\
262b843c749SSergey Zigachev }
263b843c749SSergey Zigachev 
264b843c749SSergey Zigachev static const struct dce110_stream_enc_registers stream_enc_regs[] = {
265b843c749SSergey Zigachev 	stream_enc_regs(0),
266b843c749SSergey Zigachev 	stream_enc_regs(1),
267b843c749SSergey Zigachev 	stream_enc_regs(2),
268b843c749SSergey Zigachev 	stream_enc_regs(3),
269b843c749SSergey Zigachev 	stream_enc_regs(4),
270b843c749SSergey Zigachev 	stream_enc_regs(5),
271b843c749SSergey Zigachev 	stream_enc_regs(6)
272b843c749SSergey Zigachev };
273b843c749SSergey Zigachev 
274b843c749SSergey Zigachev static const struct dce_stream_encoder_shift se_shift = {
275b843c749SSergey Zigachev 		SE_COMMON_MASK_SH_LIST_DCE80_100(__SHIFT)
276b843c749SSergey Zigachev };
277b843c749SSergey Zigachev 
278b843c749SSergey Zigachev static const struct dce_stream_encoder_mask se_mask = {
279b843c749SSergey Zigachev 		SE_COMMON_MASK_SH_LIST_DCE80_100(_MASK)
280b843c749SSergey Zigachev };
281b843c749SSergey Zigachev 
282b843c749SSergey Zigachev #define opp_regs(id)\
283b843c749SSergey Zigachev [id] = {\
284b843c749SSergey Zigachev 	OPP_DCE_80_REG_LIST(id),\
285b843c749SSergey Zigachev }
286b843c749SSergey Zigachev 
287b843c749SSergey Zigachev static const struct dce_opp_registers opp_regs[] = {
288b843c749SSergey Zigachev 	opp_regs(0),
289b843c749SSergey Zigachev 	opp_regs(1),
290b843c749SSergey Zigachev 	opp_regs(2),
291b843c749SSergey Zigachev 	opp_regs(3),
292b843c749SSergey Zigachev 	opp_regs(4),
293b843c749SSergey Zigachev 	opp_regs(5)
294b843c749SSergey Zigachev };
295b843c749SSergey Zigachev 
296b843c749SSergey Zigachev static const struct dce_opp_shift opp_shift = {
297b843c749SSergey Zigachev 	OPP_COMMON_MASK_SH_LIST_DCE_80(__SHIFT)
298b843c749SSergey Zigachev };
299b843c749SSergey Zigachev 
300b843c749SSergey Zigachev static const struct dce_opp_mask opp_mask = {
301b843c749SSergey Zigachev 	OPP_COMMON_MASK_SH_LIST_DCE_80(_MASK)
302b843c749SSergey Zigachev };
303b843c749SSergey Zigachev 
304b843c749SSergey Zigachev #define aux_engine_regs(id)\
305b843c749SSergey Zigachev [id] = {\
306b843c749SSergey Zigachev 	AUX_COMMON_REG_LIST(id), \
307b843c749SSergey Zigachev 	.AUX_RESET_MASK = 0 \
308b843c749SSergey Zigachev }
309b843c749SSergey Zigachev 
310b843c749SSergey Zigachev static const struct dce110_aux_registers aux_engine_regs[] = {
311b843c749SSergey Zigachev 		aux_engine_regs(0),
312b843c749SSergey Zigachev 		aux_engine_regs(1),
313b843c749SSergey Zigachev 		aux_engine_regs(2),
314b843c749SSergey Zigachev 		aux_engine_regs(3),
315b843c749SSergey Zigachev 		aux_engine_regs(4),
316b843c749SSergey Zigachev 		aux_engine_regs(5)
317b843c749SSergey Zigachev };
318b843c749SSergey Zigachev 
319b843c749SSergey Zigachev #define audio_regs(id)\
320b843c749SSergey Zigachev [id] = {\
321b843c749SSergey Zigachev 	AUD_COMMON_REG_LIST(id)\
322b843c749SSergey Zigachev }
323b843c749SSergey Zigachev 
324b843c749SSergey Zigachev static const struct dce_audio_registers audio_regs[] = {
325b843c749SSergey Zigachev 	audio_regs(0),
326b843c749SSergey Zigachev 	audio_regs(1),
327b843c749SSergey Zigachev 	audio_regs(2),
328b843c749SSergey Zigachev 	audio_regs(3),
329b843c749SSergey Zigachev 	audio_regs(4),
330b843c749SSergey Zigachev 	audio_regs(5),
331b843c749SSergey Zigachev 	audio_regs(6),
332b843c749SSergey Zigachev };
333b843c749SSergey Zigachev 
334b843c749SSergey Zigachev static const struct dce_audio_shift audio_shift = {
335b843c749SSergey Zigachev 		AUD_COMMON_MASK_SH_LIST(__SHIFT)
336b843c749SSergey Zigachev };
337b843c749SSergey Zigachev 
338b843c749SSergey Zigachev static const struct dce_aduio_mask audio_mask = {
339b843c749SSergey Zigachev 		AUD_COMMON_MASK_SH_LIST(_MASK)
340b843c749SSergey Zigachev };
341b843c749SSergey Zigachev 
342b843c749SSergey Zigachev #define clk_src_regs(id)\
343b843c749SSergey Zigachev [id] = {\
344b843c749SSergey Zigachev 	CS_COMMON_REG_LIST_DCE_80(id),\
345b843c749SSergey Zigachev }
346b843c749SSergey Zigachev 
347b843c749SSergey Zigachev 
348b843c749SSergey Zigachev static const struct dce110_clk_src_regs clk_src_regs[] = {
349b843c749SSergey Zigachev 	clk_src_regs(0),
350b843c749SSergey Zigachev 	clk_src_regs(1),
351b843c749SSergey Zigachev 	clk_src_regs(2)
352b843c749SSergey Zigachev };
353b843c749SSergey Zigachev 
354b843c749SSergey Zigachev static const struct dce110_clk_src_shift cs_shift = {
355b843c749SSergey Zigachev 		CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
356b843c749SSergey Zigachev };
357b843c749SSergey Zigachev 
358b843c749SSergey Zigachev static const struct dce110_clk_src_mask cs_mask = {
359b843c749SSergey Zigachev 		CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
360b843c749SSergey Zigachev };
361b843c749SSergey Zigachev 
362b843c749SSergey Zigachev static const struct bios_registers bios_regs = {
363b843c749SSergey Zigachev 	.BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
364b843c749SSergey Zigachev };
365b843c749SSergey Zigachev 
366b843c749SSergey Zigachev static const struct resource_caps res_cap = {
367b843c749SSergey Zigachev 		.num_timing_generator = 6,
368b843c749SSergey Zigachev 		.num_audio = 6,
369b843c749SSergey Zigachev 		.num_stream_encoder = 6,
370b843c749SSergey Zigachev 		.num_pll = 3,
371b843c749SSergey Zigachev };
372b843c749SSergey Zigachev 
373b843c749SSergey Zigachev static const struct resource_caps res_cap_81 = {
374b843c749SSergey Zigachev 		.num_timing_generator = 4,
375b843c749SSergey Zigachev 		.num_audio = 7,
376b843c749SSergey Zigachev 		.num_stream_encoder = 7,
377b843c749SSergey Zigachev 		.num_pll = 3,
378b843c749SSergey Zigachev };
379b843c749SSergey Zigachev 
380b843c749SSergey Zigachev static const struct resource_caps res_cap_83 = {
381b843c749SSergey Zigachev 		.num_timing_generator = 2,
382b843c749SSergey Zigachev 		.num_audio = 6,
383b843c749SSergey Zigachev 		.num_stream_encoder = 6,
384b843c749SSergey Zigachev 		.num_pll = 2,
385b843c749SSergey Zigachev };
386b843c749SSergey Zigachev 
387b843c749SSergey Zigachev static const struct dce_dmcu_registers dmcu_regs = {
388b843c749SSergey Zigachev 		DMCU_DCE80_REG_LIST()
389b843c749SSergey Zigachev };
390b843c749SSergey Zigachev 
391b843c749SSergey Zigachev static const struct dce_dmcu_shift dmcu_shift = {
392b843c749SSergey Zigachev 		DMCU_MASK_SH_LIST_DCE80(__SHIFT)
393b843c749SSergey Zigachev };
394b843c749SSergey Zigachev 
395b843c749SSergey Zigachev static const struct dce_dmcu_mask dmcu_mask = {
396b843c749SSergey Zigachev 		DMCU_MASK_SH_LIST_DCE80(_MASK)
397b843c749SSergey Zigachev };
398b843c749SSergey Zigachev static const struct dce_abm_registers abm_regs = {
399b843c749SSergey Zigachev 		ABM_DCE110_COMMON_REG_LIST()
400b843c749SSergey Zigachev };
401b843c749SSergey Zigachev 
402b843c749SSergey Zigachev static const struct dce_abm_shift abm_shift = {
403b843c749SSergey Zigachev 		ABM_MASK_SH_LIST_DCE110(__SHIFT)
404b843c749SSergey Zigachev };
405b843c749SSergey Zigachev 
406b843c749SSergey Zigachev static const struct dce_abm_mask abm_mask = {
407b843c749SSergey Zigachev 		ABM_MASK_SH_LIST_DCE110(_MASK)
408b843c749SSergey Zigachev };
409b843c749SSergey Zigachev 
410b843c749SSergey Zigachev #define CTX  ctx
411b843c749SSergey Zigachev #define REG(reg) mm ## reg
412b843c749SSergey Zigachev 
413b843c749SSergey Zigachev #ifndef mmCC_DC_HDMI_STRAPS
414b843c749SSergey Zigachev #define mmCC_DC_HDMI_STRAPS 0x1918
415b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
416b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
417b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
418b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
419b843c749SSergey Zigachev #endif
420b843c749SSergey Zigachev 
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)421b843c749SSergey Zigachev static void read_dce_straps(
422b843c749SSergey Zigachev 	struct dc_context *ctx,
423b843c749SSergey Zigachev 	struct resource_straps *straps)
424b843c749SSergey Zigachev {
425b843c749SSergey Zigachev 	REG_GET_2(CC_DC_HDMI_STRAPS,
426b843c749SSergey Zigachev 			HDMI_DISABLE, &straps->hdmi_disable,
427b843c749SSergey Zigachev 			AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
428b843c749SSergey Zigachev 
429b843c749SSergey Zigachev 	REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
430b843c749SSergey Zigachev }
431b843c749SSergey Zigachev 
create_audio(struct dc_context * ctx,unsigned int inst)432b843c749SSergey Zigachev static struct audio *create_audio(
433b843c749SSergey Zigachev 		struct dc_context *ctx, unsigned int inst)
434b843c749SSergey Zigachev {
435b843c749SSergey Zigachev 	return dce_audio_create(ctx, inst,
436b843c749SSergey Zigachev 			&audio_regs[inst], &audio_shift, &audio_mask);
437b843c749SSergey Zigachev }
438b843c749SSergey Zigachev 
dce80_timing_generator_create(struct dc_context * ctx,uint32_t instance,const struct dce110_timing_generator_offsets * offsets)439b843c749SSergey Zigachev static struct timing_generator *dce80_timing_generator_create(
440b843c749SSergey Zigachev 		struct dc_context *ctx,
441b843c749SSergey Zigachev 		uint32_t instance,
442b843c749SSergey Zigachev 		const struct dce110_timing_generator_offsets *offsets)
443b843c749SSergey Zigachev {
444b843c749SSergey Zigachev 	struct dce110_timing_generator *tg110 =
445b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
446b843c749SSergey Zigachev 
447b843c749SSergey Zigachev 	if (!tg110)
448b843c749SSergey Zigachev 		return NULL;
449b843c749SSergey Zigachev 
450b843c749SSergey Zigachev 	dce80_timing_generator_construct(tg110, ctx, instance, offsets);
451b843c749SSergey Zigachev 	return &tg110->base;
452b843c749SSergey Zigachev }
453b843c749SSergey Zigachev 
dce80_opp_create(struct dc_context * ctx,uint32_t inst)454b843c749SSergey Zigachev static struct output_pixel_processor *dce80_opp_create(
455b843c749SSergey Zigachev 	struct dc_context *ctx,
456b843c749SSergey Zigachev 	uint32_t inst)
457b843c749SSergey Zigachev {
458b843c749SSergey Zigachev 	struct dce110_opp *opp =
459b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
460b843c749SSergey Zigachev 
461b843c749SSergey Zigachev 	if (!opp)
462b843c749SSergey Zigachev 		return NULL;
463b843c749SSergey Zigachev 
464b843c749SSergey Zigachev 	dce110_opp_construct(opp,
465b843c749SSergey Zigachev 			     ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
466b843c749SSergey Zigachev 	return &opp->base;
467b843c749SSergey Zigachev }
468b843c749SSergey Zigachev 
469*78973132SSergey Zigachev static
dce80_aux_engine_create(struct dc_context * ctx,uint32_t inst)470b843c749SSergey Zigachev struct aux_engine *dce80_aux_engine_create(
471b843c749SSergey Zigachev 	struct dc_context *ctx,
472b843c749SSergey Zigachev 	uint32_t inst)
473b843c749SSergey Zigachev {
474b843c749SSergey Zigachev 	struct aux_engine_dce110 *aux_engine =
475b843c749SSergey Zigachev 		kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
476b843c749SSergey Zigachev 
477b843c749SSergey Zigachev 	if (!aux_engine)
478b843c749SSergey Zigachev 		return NULL;
479b843c749SSergey Zigachev 
480b843c749SSergey Zigachev 	dce110_aux_engine_construct(aux_engine, ctx, inst,
481b843c749SSergey Zigachev 				    SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
482b843c749SSergey Zigachev 				    &aux_engine_regs[inst]);
483b843c749SSergey Zigachev 
484b843c749SSergey Zigachev 	return &aux_engine->base;
485b843c749SSergey Zigachev }
486b843c749SSergey Zigachev 
dce80_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)487b843c749SSergey Zigachev static struct stream_encoder *dce80_stream_encoder_create(
488b843c749SSergey Zigachev 	enum engine_id eng_id,
489b843c749SSergey Zigachev 	struct dc_context *ctx)
490b843c749SSergey Zigachev {
491b843c749SSergey Zigachev 	struct dce110_stream_encoder *enc110 =
492b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
493b843c749SSergey Zigachev 
494b843c749SSergey Zigachev 	if (!enc110)
495b843c749SSergey Zigachev 		return NULL;
496b843c749SSergey Zigachev 
497b843c749SSergey Zigachev 	dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
498b843c749SSergey Zigachev 					&stream_enc_regs[eng_id],
499b843c749SSergey Zigachev 					&se_shift, &se_mask);
500b843c749SSergey Zigachev 	return &enc110->base;
501b843c749SSergey Zigachev }
502b843c749SSergey Zigachev 
503b843c749SSergey Zigachev #define SRII(reg_name, block, id)\
504b843c749SSergey Zigachev 	.reg_name[id] = mm ## block ## id ## _ ## reg_name
505b843c749SSergey Zigachev 
506b843c749SSergey Zigachev static const struct dce_hwseq_registers hwseq_reg = {
507b843c749SSergey Zigachev 		HWSEQ_DCE8_REG_LIST()
508b843c749SSergey Zigachev };
509b843c749SSergey Zigachev 
510b843c749SSergey Zigachev static const struct dce_hwseq_shift hwseq_shift = {
511b843c749SSergey Zigachev 		HWSEQ_DCE8_MASK_SH_LIST(__SHIFT)
512b843c749SSergey Zigachev };
513b843c749SSergey Zigachev 
514b843c749SSergey Zigachev static const struct dce_hwseq_mask hwseq_mask = {
515b843c749SSergey Zigachev 		HWSEQ_DCE8_MASK_SH_LIST(_MASK)
516b843c749SSergey Zigachev };
517b843c749SSergey Zigachev 
dce80_hwseq_create(struct dc_context * ctx)518b843c749SSergey Zigachev static struct dce_hwseq *dce80_hwseq_create(
519b843c749SSergey Zigachev 	struct dc_context *ctx)
520b843c749SSergey Zigachev {
521b843c749SSergey Zigachev 	struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
522b843c749SSergey Zigachev 
523b843c749SSergey Zigachev 	if (hws) {
524b843c749SSergey Zigachev 		hws->ctx = ctx;
525b843c749SSergey Zigachev 		hws->regs = &hwseq_reg;
526b843c749SSergey Zigachev 		hws->shifts = &hwseq_shift;
527b843c749SSergey Zigachev 		hws->masks = &hwseq_mask;
528b843c749SSergey Zigachev 	}
529b843c749SSergey Zigachev 	return hws;
530b843c749SSergey Zigachev }
531b843c749SSergey Zigachev 
532b843c749SSergey Zigachev static const struct resource_create_funcs res_create_funcs = {
533b843c749SSergey Zigachev 	.read_dce_straps = read_dce_straps,
534b843c749SSergey Zigachev 	.create_audio = create_audio,
535b843c749SSergey Zigachev 	.create_stream_encoder = dce80_stream_encoder_create,
536b843c749SSergey Zigachev 	.create_hwseq = dce80_hwseq_create,
537b843c749SSergey Zigachev };
538b843c749SSergey Zigachev 
539b843c749SSergey Zigachev #define mi_inst_regs(id) { \
540b843c749SSergey Zigachev 	MI_DCE8_REG_LIST(id), \
541b843c749SSergey Zigachev 	.MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
542b843c749SSergey Zigachev }
543b843c749SSergey Zigachev static const struct dce_mem_input_registers mi_regs[] = {
544b843c749SSergey Zigachev 		mi_inst_regs(0),
545b843c749SSergey Zigachev 		mi_inst_regs(1),
546b843c749SSergey Zigachev 		mi_inst_regs(2),
547b843c749SSergey Zigachev 		mi_inst_regs(3),
548b843c749SSergey Zigachev 		mi_inst_regs(4),
549b843c749SSergey Zigachev 		mi_inst_regs(5),
550b843c749SSergey Zigachev };
551b843c749SSergey Zigachev 
552b843c749SSergey Zigachev static const struct dce_mem_input_shift mi_shifts = {
553b843c749SSergey Zigachev 		MI_DCE8_MASK_SH_LIST(__SHIFT),
554b843c749SSergey Zigachev 		.ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
555b843c749SSergey Zigachev };
556b843c749SSergey Zigachev 
557b843c749SSergey Zigachev static const struct dce_mem_input_mask mi_masks = {
558b843c749SSergey Zigachev 		MI_DCE8_MASK_SH_LIST(_MASK),
559b843c749SSergey Zigachev 		.ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
560b843c749SSergey Zigachev };
561b843c749SSergey Zigachev 
dce80_mem_input_create(struct dc_context * ctx,uint32_t inst)562b843c749SSergey Zigachev static struct mem_input *dce80_mem_input_create(
563b843c749SSergey Zigachev 	struct dc_context *ctx,
564b843c749SSergey Zigachev 	uint32_t inst)
565b843c749SSergey Zigachev {
566b843c749SSergey Zigachev 	struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
567b843c749SSergey Zigachev 					       GFP_KERNEL);
568b843c749SSergey Zigachev 
569b843c749SSergey Zigachev 	if (!dce_mi) {
570b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
571b843c749SSergey Zigachev 		return NULL;
572b843c749SSergey Zigachev 	}
573b843c749SSergey Zigachev 
574b843c749SSergey Zigachev 	dce_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
575b843c749SSergey Zigachev 	dce_mi->wa.single_head_rdreq_dmif_limit = 2;
576b843c749SSergey Zigachev 	return &dce_mi->base;
577b843c749SSergey Zigachev }
578b843c749SSergey Zigachev 
dce80_transform_destroy(struct transform ** xfm)579b843c749SSergey Zigachev static void dce80_transform_destroy(struct transform **xfm)
580b843c749SSergey Zigachev {
581b843c749SSergey Zigachev 	kfree(TO_DCE_TRANSFORM(*xfm));
582b843c749SSergey Zigachev 	*xfm = NULL;
583b843c749SSergey Zigachev }
584b843c749SSergey Zigachev 
dce80_transform_create(struct dc_context * ctx,uint32_t inst)585b843c749SSergey Zigachev static struct transform *dce80_transform_create(
586b843c749SSergey Zigachev 	struct dc_context *ctx,
587b843c749SSergey Zigachev 	uint32_t inst)
588b843c749SSergey Zigachev {
589b843c749SSergey Zigachev 	struct dce_transform *transform =
590b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
591b843c749SSergey Zigachev 
592b843c749SSergey Zigachev 	if (!transform)
593b843c749SSergey Zigachev 		return NULL;
594b843c749SSergey Zigachev 
595b843c749SSergey Zigachev 	dce_transform_construct(transform, ctx, inst,
596b843c749SSergey Zigachev 				&xfm_regs[inst], &xfm_shift, &xfm_mask);
597b843c749SSergey Zigachev 	transform->prescaler_on = false;
598b843c749SSergey Zigachev 	return &transform->base;
599b843c749SSergey Zigachev }
600b843c749SSergey Zigachev 
601b843c749SSergey Zigachev static const struct encoder_feature_support link_enc_feature = {
602b843c749SSergey Zigachev 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
603b843c749SSergey Zigachev 		.max_hdmi_pixel_clock = 297000,
604b843c749SSergey Zigachev 		.flags.bits.IS_HBR2_CAPABLE = true,
605b843c749SSergey Zigachev 		.flags.bits.IS_TPS3_CAPABLE = true,
606b843c749SSergey Zigachev 		.flags.bits.IS_YCBCR_CAPABLE = true
607b843c749SSergey Zigachev };
608b843c749SSergey Zigachev 
609*78973132SSergey Zigachev static
dce80_link_encoder_create(const struct encoder_init_data * enc_init_data)610b843c749SSergey Zigachev struct link_encoder *dce80_link_encoder_create(
611b843c749SSergey Zigachev 	const struct encoder_init_data *enc_init_data)
612b843c749SSergey Zigachev {
613b843c749SSergey Zigachev 	struct dce110_link_encoder *enc110 =
614b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
615b843c749SSergey Zigachev 
616b843c749SSergey Zigachev 	if (!enc110)
617b843c749SSergey Zigachev 		return NULL;
618b843c749SSergey Zigachev 
619b843c749SSergey Zigachev 	dce110_link_encoder_construct(enc110,
620b843c749SSergey Zigachev 				      enc_init_data,
621b843c749SSergey Zigachev 				      &link_enc_feature,
622b843c749SSergey Zigachev 				      &link_enc_regs[enc_init_data->transmitter],
623b843c749SSergey Zigachev 				      &link_enc_aux_regs[enc_init_data->channel - 1],
624b843c749SSergey Zigachev 				      &link_enc_hpd_regs[enc_init_data->hpd_source]);
625b843c749SSergey Zigachev 	return &enc110->base;
626b843c749SSergey Zigachev }
627b843c749SSergey Zigachev 
628*78973132SSergey Zigachev static
dce80_clock_source_create(struct dc_context * ctx,struct dc_bios * bios,enum clock_source_id id,const struct dce110_clk_src_regs * regs,bool dp_clk_src)629b843c749SSergey Zigachev struct clock_source *dce80_clock_source_create(
630b843c749SSergey Zigachev 	struct dc_context *ctx,
631b843c749SSergey Zigachev 	struct dc_bios *bios,
632b843c749SSergey Zigachev 	enum clock_source_id id,
633b843c749SSergey Zigachev 	const struct dce110_clk_src_regs *regs,
634b843c749SSergey Zigachev 	bool dp_clk_src)
635b843c749SSergey Zigachev {
636b843c749SSergey Zigachev 	struct dce110_clk_src *clk_src =
637b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
638b843c749SSergey Zigachev 
639b843c749SSergey Zigachev 	if (!clk_src)
640b843c749SSergey Zigachev 		return NULL;
641b843c749SSergey Zigachev 
642b843c749SSergey Zigachev 	if (dce110_clk_src_construct(clk_src, ctx, bios, id,
643b843c749SSergey Zigachev 			regs, &cs_shift, &cs_mask)) {
644b843c749SSergey Zigachev 		clk_src->base.dp_clk_src = dp_clk_src;
645b843c749SSergey Zigachev 		return &clk_src->base;
646b843c749SSergey Zigachev 	}
647b843c749SSergey Zigachev 
648b843c749SSergey Zigachev 	BREAK_TO_DEBUGGER();
649b843c749SSergey Zigachev 	return NULL;
650b843c749SSergey Zigachev }
651b843c749SSergey Zigachev 
652*78973132SSergey Zigachev static
dce80_clock_source_destroy(struct clock_source ** clk_src)653b843c749SSergey Zigachev void dce80_clock_source_destroy(struct clock_source **clk_src)
654b843c749SSergey Zigachev {
655b843c749SSergey Zigachev 	kfree(TO_DCE110_CLK_SRC(*clk_src));
656b843c749SSergey Zigachev 	*clk_src = NULL;
657b843c749SSergey Zigachev }
658b843c749SSergey Zigachev 
dce80_ipp_create(struct dc_context * ctx,uint32_t inst)659b843c749SSergey Zigachev static struct input_pixel_processor *dce80_ipp_create(
660b843c749SSergey Zigachev 	struct dc_context *ctx, uint32_t inst)
661b843c749SSergey Zigachev {
662b843c749SSergey Zigachev 	struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
663b843c749SSergey Zigachev 
664b843c749SSergey Zigachev 	if (!ipp) {
665b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
666b843c749SSergey Zigachev 		return NULL;
667b843c749SSergey Zigachev 	}
668b843c749SSergey Zigachev 
669b843c749SSergey Zigachev 	dce_ipp_construct(ipp, ctx, inst,
670b843c749SSergey Zigachev 			&ipp_regs[inst], &ipp_shift, &ipp_mask);
671b843c749SSergey Zigachev 	return &ipp->base;
672b843c749SSergey Zigachev }
673b843c749SSergey Zigachev 
destruct(struct dce110_resource_pool * pool)674b843c749SSergey Zigachev static void destruct(struct dce110_resource_pool *pool)
675b843c749SSergey Zigachev {
676b843c749SSergey Zigachev 	unsigned int i;
677b843c749SSergey Zigachev 
678b843c749SSergey Zigachev 	for (i = 0; i < pool->base.pipe_count; i++) {
679b843c749SSergey Zigachev 		if (pool->base.opps[i] != NULL)
680b843c749SSergey Zigachev 			dce110_opp_destroy(&pool->base.opps[i]);
681b843c749SSergey Zigachev 
682b843c749SSergey Zigachev 		if (pool->base.transforms[i] != NULL)
683b843c749SSergey Zigachev 			dce80_transform_destroy(&pool->base.transforms[i]);
684b843c749SSergey Zigachev 
685b843c749SSergey Zigachev 		if (pool->base.ipps[i] != NULL)
686b843c749SSergey Zigachev 			dce_ipp_destroy(&pool->base.ipps[i]);
687b843c749SSergey Zigachev 
688b843c749SSergey Zigachev 		if (pool->base.mis[i] != NULL) {
689b843c749SSergey Zigachev 			kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
690b843c749SSergey Zigachev 			pool->base.mis[i] = NULL;
691b843c749SSergey Zigachev 		}
692b843c749SSergey Zigachev 
693b843c749SSergey Zigachev 		if (pool->base.timing_generators[i] != NULL)	{
694b843c749SSergey Zigachev 			kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
695b843c749SSergey Zigachev 			pool->base.timing_generators[i] = NULL;
696b843c749SSergey Zigachev 		}
697b843c749SSergey Zigachev 
698b843c749SSergey Zigachev 		if (pool->base.engines[i] != NULL)
699b843c749SSergey Zigachev 			dce110_engine_destroy(&pool->base.engines[i]);
700b843c749SSergey Zigachev 	}
701b843c749SSergey Zigachev 
702b843c749SSergey Zigachev 	for (i = 0; i < pool->base.stream_enc_count; i++) {
703b843c749SSergey Zigachev 		if (pool->base.stream_enc[i] != NULL)
704b843c749SSergey Zigachev 			kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
705b843c749SSergey Zigachev 	}
706b843c749SSergey Zigachev 
707b843c749SSergey Zigachev 	for (i = 0; i < pool->base.clk_src_count; i++) {
708b843c749SSergey Zigachev 		if (pool->base.clock_sources[i] != NULL) {
709b843c749SSergey Zigachev 			dce80_clock_source_destroy(&pool->base.clock_sources[i]);
710b843c749SSergey Zigachev 		}
711b843c749SSergey Zigachev 	}
712b843c749SSergey Zigachev 
713b843c749SSergey Zigachev 	if (pool->base.abm != NULL)
714b843c749SSergey Zigachev 			dce_abm_destroy(&pool->base.abm);
715b843c749SSergey Zigachev 
716b843c749SSergey Zigachev 	if (pool->base.dmcu != NULL)
717b843c749SSergey Zigachev 			dce_dmcu_destroy(&pool->base.dmcu);
718b843c749SSergey Zigachev 
719b843c749SSergey Zigachev 	if (pool->base.dp_clock_source != NULL)
720b843c749SSergey Zigachev 		dce80_clock_source_destroy(&pool->base.dp_clock_source);
721b843c749SSergey Zigachev 
722b843c749SSergey Zigachev 	for (i = 0; i < pool->base.audio_count; i++)	{
723b843c749SSergey Zigachev 		if (pool->base.audios[i] != NULL) {
724b843c749SSergey Zigachev 			dce_aud_destroy(&pool->base.audios[i]);
725b843c749SSergey Zigachev 		}
726b843c749SSergey Zigachev 	}
727b843c749SSergey Zigachev 
728b843c749SSergey Zigachev 	if (pool->base.dccg != NULL)
729b843c749SSergey Zigachev 		dce_dccg_destroy(&pool->base.dccg);
730b843c749SSergey Zigachev 
731b843c749SSergey Zigachev 	if (pool->base.irqs != NULL) {
732b843c749SSergey Zigachev 		dal_irq_service_destroy(&pool->base.irqs);
733b843c749SSergey Zigachev 	}
734b843c749SSergey Zigachev }
735b843c749SSergey Zigachev 
736*78973132SSergey Zigachev static
dce80_validate_bandwidth(struct dc * dc,struct dc_state * context)737b843c749SSergey Zigachev bool dce80_validate_bandwidth(
738b843c749SSergey Zigachev 	struct dc *dc,
739b843c749SSergey Zigachev 	struct dc_state *context)
740b843c749SSergey Zigachev {
741b843c749SSergey Zigachev 	/* TODO implement when needed but for now hardcode max value*/
742b843c749SSergey Zigachev 	context->bw.dce.dispclk_khz = 681000;
743b843c749SSergey Zigachev 	context->bw.dce.yclk_khz = 250000 * MEMORY_TYPE_MULTIPLIER;
744b843c749SSergey Zigachev 
745b843c749SSergey Zigachev 	return true;
746b843c749SSergey Zigachev }
747b843c749SSergey Zigachev 
dce80_validate_surface_sets(struct dc_state * context)748b843c749SSergey Zigachev static bool dce80_validate_surface_sets(
749b843c749SSergey Zigachev 		struct dc_state *context)
750b843c749SSergey Zigachev {
751b843c749SSergey Zigachev 	int i;
752b843c749SSergey Zigachev 
753b843c749SSergey Zigachev 	for (i = 0; i < context->stream_count; i++) {
754b843c749SSergey Zigachev 		if (context->stream_status[i].plane_count == 0)
755b843c749SSergey Zigachev 			continue;
756b843c749SSergey Zigachev 
757b843c749SSergey Zigachev 		if (context->stream_status[i].plane_count > 1)
758b843c749SSergey Zigachev 			return false;
759b843c749SSergey Zigachev 
760b843c749SSergey Zigachev 		if (context->stream_status[i].plane_states[0]->format
761b843c749SSergey Zigachev 				>= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
762b843c749SSergey Zigachev 			return false;
763b843c749SSergey Zigachev 	}
764b843c749SSergey Zigachev 
765b843c749SSergey Zigachev 	return true;
766b843c749SSergey Zigachev }
767b843c749SSergey Zigachev 
768*78973132SSergey Zigachev static
dce80_validate_global(struct dc * dc,struct dc_state * context)769b843c749SSergey Zigachev enum dc_status dce80_validate_global(
770b843c749SSergey Zigachev 		struct dc *dc,
771b843c749SSergey Zigachev 		struct dc_state *context)
772b843c749SSergey Zigachev {
773b843c749SSergey Zigachev 	if (!dce80_validate_surface_sets(context))
774b843c749SSergey Zigachev 		return DC_FAIL_SURFACE_VALIDATE;
775b843c749SSergey Zigachev 
776b843c749SSergey Zigachev 	return DC_OK;
777b843c749SSergey Zigachev }
778b843c749SSergey Zigachev 
dce80_destroy_resource_pool(struct resource_pool ** pool)779b843c749SSergey Zigachev static void dce80_destroy_resource_pool(struct resource_pool **pool)
780b843c749SSergey Zigachev {
781b843c749SSergey Zigachev 	struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
782b843c749SSergey Zigachev 
783b843c749SSergey Zigachev 	destruct(dce110_pool);
784b843c749SSergey Zigachev 	kfree(dce110_pool);
785b843c749SSergey Zigachev 	*pool = NULL;
786b843c749SSergey Zigachev }
787b843c749SSergey Zigachev 
788b843c749SSergey Zigachev static const struct resource_funcs dce80_res_pool_funcs = {
789b843c749SSergey Zigachev 	.destroy = dce80_destroy_resource_pool,
790b843c749SSergey Zigachev 	.link_enc_create = dce80_link_encoder_create,
791b843c749SSergey Zigachev 	.validate_bandwidth = dce80_validate_bandwidth,
792b843c749SSergey Zigachev 	.validate_plane = dce100_validate_plane,
793b843c749SSergey Zigachev 	.add_stream_to_ctx = dce100_add_stream_to_ctx,
794b843c749SSergey Zigachev 	.validate_global = dce80_validate_global
795b843c749SSergey Zigachev };
796b843c749SSergey Zigachev 
dce80_construct(uint8_t num_virtual_links,struct dc * dc,struct dce110_resource_pool * pool)797b843c749SSergey Zigachev static bool dce80_construct(
798b843c749SSergey Zigachev 	uint8_t num_virtual_links,
799b843c749SSergey Zigachev 	struct dc *dc,
800b843c749SSergey Zigachev 	struct dce110_resource_pool *pool)
801b843c749SSergey Zigachev {
802b843c749SSergey Zigachev 	unsigned int i;
803b843c749SSergey Zigachev 	struct dc_context *ctx = dc->ctx;
804b843c749SSergey Zigachev 	struct dc_firmware_info info;
805b843c749SSergey Zigachev 	struct dc_bios *bp;
806b843c749SSergey Zigachev 	struct dm_pp_static_clock_info static_clk_info = {0};
807b843c749SSergey Zigachev 
808b843c749SSergey Zigachev 	ctx->dc_bios->regs = &bios_regs;
809b843c749SSergey Zigachev 
810b843c749SSergey Zigachev 	pool->base.res_cap = &res_cap;
811b843c749SSergey Zigachev 	pool->base.funcs = &dce80_res_pool_funcs;
812b843c749SSergey Zigachev 
813b843c749SSergey Zigachev 
814b843c749SSergey Zigachev 	/*************************************************
815b843c749SSergey Zigachev 	 *  Resource + asic cap harcoding                *
816b843c749SSergey Zigachev 	 *************************************************/
817b843c749SSergey Zigachev 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
818b843c749SSergey Zigachev 	pool->base.pipe_count = res_cap.num_timing_generator;
819b843c749SSergey Zigachev 	pool->base.timing_generator_count = res_cap.num_timing_generator;
820b843c749SSergey Zigachev 	dc->caps.max_downscale_ratio = 200;
821b843c749SSergey Zigachev 	dc->caps.i2c_speed_in_khz = 40;
822b843c749SSergey Zigachev 	dc->caps.max_cursor_size = 128;
823b843c749SSergey Zigachev 	dc->caps.dual_link_dvi = true;
824b843c749SSergey Zigachev 
825b843c749SSergey Zigachev 	/*************************************************
826b843c749SSergey Zigachev 	 *  Create resources                             *
827b843c749SSergey Zigachev 	 *************************************************/
828b843c749SSergey Zigachev 
829b843c749SSergey Zigachev 	bp = ctx->dc_bios;
830b843c749SSergey Zigachev 
831b843c749SSergey Zigachev 	if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
832b843c749SSergey Zigachev 		info.external_clock_source_frequency_for_dp != 0) {
833b843c749SSergey Zigachev 		pool->base.dp_clock_source =
834b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
835b843c749SSergey Zigachev 
836b843c749SSergey Zigachev 		pool->base.clock_sources[0] =
837b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
838b843c749SSergey Zigachev 		pool->base.clock_sources[1] =
839b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
840b843c749SSergey Zigachev 		pool->base.clock_sources[2] =
841b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
842b843c749SSergey Zigachev 		pool->base.clk_src_count = 3;
843b843c749SSergey Zigachev 
844b843c749SSergey Zigachev 	} else {
845b843c749SSergey Zigachev 		pool->base.dp_clock_source =
846b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
847b843c749SSergey Zigachev 
848b843c749SSergey Zigachev 		pool->base.clock_sources[0] =
849b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
850b843c749SSergey Zigachev 		pool->base.clock_sources[1] =
851b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
852b843c749SSergey Zigachev 		pool->base.clk_src_count = 2;
853b843c749SSergey Zigachev 	}
854b843c749SSergey Zigachev 
855b843c749SSergey Zigachev 	if (pool->base.dp_clock_source == NULL) {
856b843c749SSergey Zigachev 		dm_error("DC: failed to create dp clock source!\n");
857b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
858b843c749SSergey Zigachev 		goto res_create_fail;
859b843c749SSergey Zigachev 	}
860b843c749SSergey Zigachev 
861b843c749SSergey Zigachev 	for (i = 0; i < pool->base.clk_src_count; i++) {
862b843c749SSergey Zigachev 		if (pool->base.clock_sources[i] == NULL) {
863b843c749SSergey Zigachev 			dm_error("DC: failed to create clock sources!\n");
864b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
865b843c749SSergey Zigachev 			goto res_create_fail;
866b843c749SSergey Zigachev 		}
867b843c749SSergey Zigachev 	}
868b843c749SSergey Zigachev 
869b843c749SSergey Zigachev 	pool->base.dccg = dce_dccg_create(ctx,
870b843c749SSergey Zigachev 			&disp_clk_regs,
871b843c749SSergey Zigachev 			&disp_clk_shift,
872b843c749SSergey Zigachev 			&disp_clk_mask);
873b843c749SSergey Zigachev 	if (pool->base.dccg == NULL) {
874b843c749SSergey Zigachev 		dm_error("DC: failed to create display clock!\n");
875b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
876b843c749SSergey Zigachev 		goto res_create_fail;
877b843c749SSergey Zigachev 	}
878b843c749SSergey Zigachev 
879b843c749SSergey Zigachev 	pool->base.dmcu = dce_dmcu_create(ctx,
880b843c749SSergey Zigachev 			&dmcu_regs,
881b843c749SSergey Zigachev 			&dmcu_shift,
882b843c749SSergey Zigachev 			&dmcu_mask);
883b843c749SSergey Zigachev 	if (pool->base.dmcu == NULL) {
884b843c749SSergey Zigachev 		dm_error("DC: failed to create dmcu!\n");
885b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
886b843c749SSergey Zigachev 		goto res_create_fail;
887b843c749SSergey Zigachev 	}
888b843c749SSergey Zigachev 
889b843c749SSergey Zigachev 	pool->base.abm = dce_abm_create(ctx,
890b843c749SSergey Zigachev 			&abm_regs,
891b843c749SSergey Zigachev 			&abm_shift,
892b843c749SSergey Zigachev 			&abm_mask);
893b843c749SSergey Zigachev 	if (pool->base.abm == NULL) {
894b843c749SSergey Zigachev 		dm_error("DC: failed to create abm!\n");
895b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
896b843c749SSergey Zigachev 		goto res_create_fail;
897b843c749SSergey Zigachev 	}
898b843c749SSergey Zigachev 	if (dm_pp_get_static_clocks(ctx, &static_clk_info))
899b843c749SSergey Zigachev 		pool->base.dccg->max_clks_state =
900b843c749SSergey Zigachev 					static_clk_info.max_clocks_state;
901b843c749SSergey Zigachev 
902b843c749SSergey Zigachev 	{
903b843c749SSergey Zigachev 		struct irq_service_init_data init_data;
904b843c749SSergey Zigachev 		init_data.ctx = dc->ctx;
905b843c749SSergey Zigachev 		pool->base.irqs = dal_irq_service_dce80_create(&init_data);
906b843c749SSergey Zigachev 		if (!pool->base.irqs)
907b843c749SSergey Zigachev 			goto res_create_fail;
908b843c749SSergey Zigachev 	}
909b843c749SSergey Zigachev 
910b843c749SSergey Zigachev 	for (i = 0; i < pool->base.pipe_count; i++) {
911b843c749SSergey Zigachev 		pool->base.timing_generators[i] = dce80_timing_generator_create(
912b843c749SSergey Zigachev 				ctx, i, &dce80_tg_offsets[i]);
913b843c749SSergey Zigachev 		if (pool->base.timing_generators[i] == NULL) {
914b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
915b843c749SSergey Zigachev 			dm_error("DC: failed to create tg!\n");
916b843c749SSergey Zigachev 			goto res_create_fail;
917b843c749SSergey Zigachev 		}
918b843c749SSergey Zigachev 
919b843c749SSergey Zigachev 		pool->base.mis[i] = dce80_mem_input_create(ctx, i);
920b843c749SSergey Zigachev 		if (pool->base.mis[i] == NULL) {
921b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
922b843c749SSergey Zigachev 			dm_error("DC: failed to create memory input!\n");
923b843c749SSergey Zigachev 			goto res_create_fail;
924b843c749SSergey Zigachev 		}
925b843c749SSergey Zigachev 
926b843c749SSergey Zigachev 		pool->base.ipps[i] = dce80_ipp_create(ctx, i);
927b843c749SSergey Zigachev 		if (pool->base.ipps[i] == NULL) {
928b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
929b843c749SSergey Zigachev 			dm_error("DC: failed to create input pixel processor!\n");
930b843c749SSergey Zigachev 			goto res_create_fail;
931b843c749SSergey Zigachev 		}
932b843c749SSergey Zigachev 
933b843c749SSergey Zigachev 		pool->base.transforms[i] = dce80_transform_create(ctx, i);
934b843c749SSergey Zigachev 		if (pool->base.transforms[i] == NULL) {
935b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
936b843c749SSergey Zigachev 			dm_error("DC: failed to create transform!\n");
937b843c749SSergey Zigachev 			goto res_create_fail;
938b843c749SSergey Zigachev 		}
939b843c749SSergey Zigachev 
940b843c749SSergey Zigachev 		pool->base.opps[i] = dce80_opp_create(ctx, i);
941b843c749SSergey Zigachev 		if (pool->base.opps[i] == NULL) {
942b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
943b843c749SSergey Zigachev 			dm_error("DC: failed to create output pixel processor!\n");
944b843c749SSergey Zigachev 			goto res_create_fail;
945b843c749SSergey Zigachev 		}
946b843c749SSergey Zigachev 
947b843c749SSergey Zigachev 		pool->base.engines[i] = dce80_aux_engine_create(ctx, i);
948b843c749SSergey Zigachev 		if (pool->base.engines[i] == NULL) {
949b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
950b843c749SSergey Zigachev 			dm_error(
951b843c749SSergey Zigachev 				"DC:failed to create aux engine!!\n");
952b843c749SSergey Zigachev 			goto res_create_fail;
953b843c749SSergey Zigachev 		}
954b843c749SSergey Zigachev 	}
955b843c749SSergey Zigachev 
956b843c749SSergey Zigachev 	dc->caps.max_planes =  pool->base.pipe_count;
957b843c749SSergey Zigachev 	dc->caps.disable_dp_clk_share = true;
958b843c749SSergey Zigachev 
959b843c749SSergey Zigachev 	if (!resource_construct(num_virtual_links, dc, &pool->base,
960b843c749SSergey Zigachev 			&res_create_funcs))
961b843c749SSergey Zigachev 		goto res_create_fail;
962b843c749SSergey Zigachev 
963b843c749SSergey Zigachev 	/* Create hardware sequencer */
964b843c749SSergey Zigachev 	dce80_hw_sequencer_construct(dc);
965b843c749SSergey Zigachev 
966b843c749SSergey Zigachev 	return true;
967b843c749SSergey Zigachev 
968b843c749SSergey Zigachev res_create_fail:
969b843c749SSergey Zigachev 	destruct(pool);
970b843c749SSergey Zigachev 	return false;
971b843c749SSergey Zigachev }
972b843c749SSergey Zigachev 
dce80_create_resource_pool(uint8_t num_virtual_links,struct dc * dc)973b843c749SSergey Zigachev struct resource_pool *dce80_create_resource_pool(
974b843c749SSergey Zigachev 	uint8_t num_virtual_links,
975b843c749SSergey Zigachev 	struct dc *dc)
976b843c749SSergey Zigachev {
977b843c749SSergey Zigachev 	struct dce110_resource_pool *pool =
978b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
979b843c749SSergey Zigachev 
980b843c749SSergey Zigachev 	if (!pool)
981b843c749SSergey Zigachev 		return NULL;
982b843c749SSergey Zigachev 
983b843c749SSergey Zigachev 	if (dce80_construct(num_virtual_links, dc, pool))
984b843c749SSergey Zigachev 		return &pool->base;
985b843c749SSergey Zigachev 
986b843c749SSergey Zigachev 	BREAK_TO_DEBUGGER();
987b843c749SSergey Zigachev 	return NULL;
988b843c749SSergey Zigachev }
989b843c749SSergey Zigachev 
dce81_construct(uint8_t num_virtual_links,struct dc * dc,struct dce110_resource_pool * pool)990b843c749SSergey Zigachev static bool dce81_construct(
991b843c749SSergey Zigachev 	uint8_t num_virtual_links,
992b843c749SSergey Zigachev 	struct dc *dc,
993b843c749SSergey Zigachev 	struct dce110_resource_pool *pool)
994b843c749SSergey Zigachev {
995b843c749SSergey Zigachev 	unsigned int i;
996b843c749SSergey Zigachev 	struct dc_context *ctx = dc->ctx;
997b843c749SSergey Zigachev 	struct dc_firmware_info info;
998b843c749SSergey Zigachev 	struct dc_bios *bp;
999b843c749SSergey Zigachev 	struct dm_pp_static_clock_info static_clk_info = {0};
1000b843c749SSergey Zigachev 
1001b843c749SSergey Zigachev 	ctx->dc_bios->regs = &bios_regs;
1002b843c749SSergey Zigachev 
1003b843c749SSergey Zigachev 	pool->base.res_cap = &res_cap_81;
1004b843c749SSergey Zigachev 	pool->base.funcs = &dce80_res_pool_funcs;
1005b843c749SSergey Zigachev 
1006b843c749SSergey Zigachev 
1007b843c749SSergey Zigachev 	/*************************************************
1008b843c749SSergey Zigachev 	 *  Resource + asic cap harcoding                *
1009b843c749SSergey Zigachev 	 *************************************************/
1010b843c749SSergey Zigachev 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1011b843c749SSergey Zigachev 	pool->base.pipe_count = res_cap_81.num_timing_generator;
1012b843c749SSergey Zigachev 	pool->base.timing_generator_count = res_cap_81.num_timing_generator;
1013b843c749SSergey Zigachev 	dc->caps.max_downscale_ratio = 200;
1014b843c749SSergey Zigachev 	dc->caps.i2c_speed_in_khz = 40;
1015b843c749SSergey Zigachev 	dc->caps.max_cursor_size = 128;
1016b843c749SSergey Zigachev 	dc->caps.is_apu = true;
1017b843c749SSergey Zigachev 
1018b843c749SSergey Zigachev 	/*************************************************
1019b843c749SSergey Zigachev 	 *  Create resources                             *
1020b843c749SSergey Zigachev 	 *************************************************/
1021b843c749SSergey Zigachev 
1022b843c749SSergey Zigachev 	bp = ctx->dc_bios;
1023b843c749SSergey Zigachev 
1024b843c749SSergey Zigachev 	if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
1025b843c749SSergey Zigachev 		info.external_clock_source_frequency_for_dp != 0) {
1026b843c749SSergey Zigachev 		pool->base.dp_clock_source =
1027b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1028b843c749SSergey Zigachev 
1029b843c749SSergey Zigachev 		pool->base.clock_sources[0] =
1030b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
1031b843c749SSergey Zigachev 		pool->base.clock_sources[1] =
1032b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1033b843c749SSergey Zigachev 		pool->base.clock_sources[2] =
1034b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1035b843c749SSergey Zigachev 		pool->base.clk_src_count = 3;
1036b843c749SSergey Zigachev 
1037b843c749SSergey Zigachev 	} else {
1038b843c749SSergey Zigachev 		pool->base.dp_clock_source =
1039b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
1040b843c749SSergey Zigachev 
1041b843c749SSergey Zigachev 		pool->base.clock_sources[0] =
1042b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
1043b843c749SSergey Zigachev 		pool->base.clock_sources[1] =
1044b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
1045b843c749SSergey Zigachev 		pool->base.clk_src_count = 2;
1046b843c749SSergey Zigachev 	}
1047b843c749SSergey Zigachev 
1048b843c749SSergey Zigachev 	if (pool->base.dp_clock_source == NULL) {
1049b843c749SSergey Zigachev 		dm_error("DC: failed to create dp clock source!\n");
1050b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1051b843c749SSergey Zigachev 		goto res_create_fail;
1052b843c749SSergey Zigachev 	}
1053b843c749SSergey Zigachev 
1054b843c749SSergey Zigachev 	for (i = 0; i < pool->base.clk_src_count; i++) {
1055b843c749SSergey Zigachev 		if (pool->base.clock_sources[i] == NULL) {
1056b843c749SSergey Zigachev 			dm_error("DC: failed to create clock sources!\n");
1057b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1058b843c749SSergey Zigachev 			goto res_create_fail;
1059b843c749SSergey Zigachev 		}
1060b843c749SSergey Zigachev 	}
1061b843c749SSergey Zigachev 
1062b843c749SSergey Zigachev 	pool->base.dccg = dce_dccg_create(ctx,
1063b843c749SSergey Zigachev 			&disp_clk_regs,
1064b843c749SSergey Zigachev 			&disp_clk_shift,
1065b843c749SSergey Zigachev 			&disp_clk_mask);
1066b843c749SSergey Zigachev 	if (pool->base.dccg == NULL) {
1067b843c749SSergey Zigachev 		dm_error("DC: failed to create display clock!\n");
1068b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1069b843c749SSergey Zigachev 		goto res_create_fail;
1070b843c749SSergey Zigachev 	}
1071b843c749SSergey Zigachev 
1072b843c749SSergey Zigachev 	pool->base.dmcu = dce_dmcu_create(ctx,
1073b843c749SSergey Zigachev 			&dmcu_regs,
1074b843c749SSergey Zigachev 			&dmcu_shift,
1075b843c749SSergey Zigachev 			&dmcu_mask);
1076b843c749SSergey Zigachev 	if (pool->base.dmcu == NULL) {
1077b843c749SSergey Zigachev 		dm_error("DC: failed to create dmcu!\n");
1078b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1079b843c749SSergey Zigachev 		goto res_create_fail;
1080b843c749SSergey Zigachev 	}
1081b843c749SSergey Zigachev 
1082b843c749SSergey Zigachev 	pool->base.abm = dce_abm_create(ctx,
1083b843c749SSergey Zigachev 			&abm_regs,
1084b843c749SSergey Zigachev 			&abm_shift,
1085b843c749SSergey Zigachev 			&abm_mask);
1086b843c749SSergey Zigachev 	if (pool->base.abm == NULL) {
1087b843c749SSergey Zigachev 		dm_error("DC: failed to create abm!\n");
1088b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1089b843c749SSergey Zigachev 		goto res_create_fail;
1090b843c749SSergey Zigachev 	}
1091b843c749SSergey Zigachev 
1092b843c749SSergey Zigachev 	if (dm_pp_get_static_clocks(ctx, &static_clk_info))
1093b843c749SSergey Zigachev 		pool->base.dccg->max_clks_state =
1094b843c749SSergey Zigachev 					static_clk_info.max_clocks_state;
1095b843c749SSergey Zigachev 
1096b843c749SSergey Zigachev 	{
1097b843c749SSergey Zigachev 		struct irq_service_init_data init_data;
1098b843c749SSergey Zigachev 		init_data.ctx = dc->ctx;
1099b843c749SSergey Zigachev 		pool->base.irqs = dal_irq_service_dce80_create(&init_data);
1100b843c749SSergey Zigachev 		if (!pool->base.irqs)
1101b843c749SSergey Zigachev 			goto res_create_fail;
1102b843c749SSergey Zigachev 	}
1103b843c749SSergey Zigachev 
1104b843c749SSergey Zigachev 	for (i = 0; i < pool->base.pipe_count; i++) {
1105b843c749SSergey Zigachev 		pool->base.timing_generators[i] = dce80_timing_generator_create(
1106b843c749SSergey Zigachev 				ctx, i, &dce80_tg_offsets[i]);
1107b843c749SSergey Zigachev 		if (pool->base.timing_generators[i] == NULL) {
1108b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1109b843c749SSergey Zigachev 			dm_error("DC: failed to create tg!\n");
1110b843c749SSergey Zigachev 			goto res_create_fail;
1111b843c749SSergey Zigachev 		}
1112b843c749SSergey Zigachev 
1113b843c749SSergey Zigachev 		pool->base.mis[i] = dce80_mem_input_create(ctx, i);
1114b843c749SSergey Zigachev 		if (pool->base.mis[i] == NULL) {
1115b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1116b843c749SSergey Zigachev 			dm_error("DC: failed to create memory input!\n");
1117b843c749SSergey Zigachev 			goto res_create_fail;
1118b843c749SSergey Zigachev 		}
1119b843c749SSergey Zigachev 
1120b843c749SSergey Zigachev 		pool->base.ipps[i] = dce80_ipp_create(ctx, i);
1121b843c749SSergey Zigachev 		if (pool->base.ipps[i] == NULL) {
1122b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1123b843c749SSergey Zigachev 			dm_error("DC: failed to create input pixel processor!\n");
1124b843c749SSergey Zigachev 			goto res_create_fail;
1125b843c749SSergey Zigachev 		}
1126b843c749SSergey Zigachev 
1127b843c749SSergey Zigachev 		pool->base.transforms[i] = dce80_transform_create(ctx, i);
1128b843c749SSergey Zigachev 		if (pool->base.transforms[i] == NULL) {
1129b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1130b843c749SSergey Zigachev 			dm_error("DC: failed to create transform!\n");
1131b843c749SSergey Zigachev 			goto res_create_fail;
1132b843c749SSergey Zigachev 		}
1133b843c749SSergey Zigachev 
1134b843c749SSergey Zigachev 		pool->base.opps[i] = dce80_opp_create(ctx, i);
1135b843c749SSergey Zigachev 		if (pool->base.opps[i] == NULL) {
1136b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1137b843c749SSergey Zigachev 			dm_error("DC: failed to create output pixel processor!\n");
1138b843c749SSergey Zigachev 			goto res_create_fail;
1139b843c749SSergey Zigachev 		}
1140b843c749SSergey Zigachev 	}
1141b843c749SSergey Zigachev 
1142b843c749SSergey Zigachev 	dc->caps.max_planes =  pool->base.pipe_count;
1143b843c749SSergey Zigachev 	dc->caps.disable_dp_clk_share = true;
1144b843c749SSergey Zigachev 
1145b843c749SSergey Zigachev 	if (!resource_construct(num_virtual_links, dc, &pool->base,
1146b843c749SSergey Zigachev 			&res_create_funcs))
1147b843c749SSergey Zigachev 		goto res_create_fail;
1148b843c749SSergey Zigachev 
1149b843c749SSergey Zigachev 	/* Create hardware sequencer */
1150b843c749SSergey Zigachev 	dce80_hw_sequencer_construct(dc);
1151b843c749SSergey Zigachev 
1152b843c749SSergey Zigachev 	return true;
1153b843c749SSergey Zigachev 
1154b843c749SSergey Zigachev res_create_fail:
1155b843c749SSergey Zigachev 	destruct(pool);
1156b843c749SSergey Zigachev 	return false;
1157b843c749SSergey Zigachev }
1158b843c749SSergey Zigachev 
dce81_create_resource_pool(uint8_t num_virtual_links,struct dc * dc)1159b843c749SSergey Zigachev struct resource_pool *dce81_create_resource_pool(
1160b843c749SSergey Zigachev 	uint8_t num_virtual_links,
1161b843c749SSergey Zigachev 	struct dc *dc)
1162b843c749SSergey Zigachev {
1163b843c749SSergey Zigachev 	struct dce110_resource_pool *pool =
1164b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1165b843c749SSergey Zigachev 
1166b843c749SSergey Zigachev 	if (!pool)
1167b843c749SSergey Zigachev 		return NULL;
1168b843c749SSergey Zigachev 
1169b843c749SSergey Zigachev 	if (dce81_construct(num_virtual_links, dc, pool))
1170b843c749SSergey Zigachev 		return &pool->base;
1171b843c749SSergey Zigachev 
1172b843c749SSergey Zigachev 	BREAK_TO_DEBUGGER();
1173b843c749SSergey Zigachev 	return NULL;
1174b843c749SSergey Zigachev }
1175b843c749SSergey Zigachev 
dce83_construct(uint8_t num_virtual_links,struct dc * dc,struct dce110_resource_pool * pool)1176b843c749SSergey Zigachev static bool dce83_construct(
1177b843c749SSergey Zigachev 	uint8_t num_virtual_links,
1178b843c749SSergey Zigachev 	struct dc *dc,
1179b843c749SSergey Zigachev 	struct dce110_resource_pool *pool)
1180b843c749SSergey Zigachev {
1181b843c749SSergey Zigachev 	unsigned int i;
1182b843c749SSergey Zigachev 	struct dc_context *ctx = dc->ctx;
1183b843c749SSergey Zigachev 	struct dc_firmware_info info;
1184b843c749SSergey Zigachev 	struct dc_bios *bp;
1185b843c749SSergey Zigachev 	struct dm_pp_static_clock_info static_clk_info = {0};
1186b843c749SSergey Zigachev 
1187b843c749SSergey Zigachev 	ctx->dc_bios->regs = &bios_regs;
1188b843c749SSergey Zigachev 
1189b843c749SSergey Zigachev 	pool->base.res_cap = &res_cap_83;
1190b843c749SSergey Zigachev 	pool->base.funcs = &dce80_res_pool_funcs;
1191b843c749SSergey Zigachev 
1192b843c749SSergey Zigachev 
1193b843c749SSergey Zigachev 	/*************************************************
1194b843c749SSergey Zigachev 	 *  Resource + asic cap harcoding                *
1195b843c749SSergey Zigachev 	 *************************************************/
1196b843c749SSergey Zigachev 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1197b843c749SSergey Zigachev 	pool->base.pipe_count = res_cap_83.num_timing_generator;
1198b843c749SSergey Zigachev 	pool->base.timing_generator_count = res_cap_83.num_timing_generator;
1199b843c749SSergey Zigachev 	dc->caps.max_downscale_ratio = 200;
1200b843c749SSergey Zigachev 	dc->caps.i2c_speed_in_khz = 40;
1201b843c749SSergey Zigachev 	dc->caps.max_cursor_size = 128;
1202b843c749SSergey Zigachev 	dc->caps.is_apu = true;
1203b843c749SSergey Zigachev 
1204b843c749SSergey Zigachev 	/*************************************************
1205b843c749SSergey Zigachev 	 *  Create resources                             *
1206b843c749SSergey Zigachev 	 *************************************************/
1207b843c749SSergey Zigachev 
1208b843c749SSergey Zigachev 	bp = ctx->dc_bios;
1209b843c749SSergey Zigachev 
1210b843c749SSergey Zigachev 	if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
1211b843c749SSergey Zigachev 		info.external_clock_source_frequency_for_dp != 0) {
1212b843c749SSergey Zigachev 		pool->base.dp_clock_source =
1213b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
1214b843c749SSergey Zigachev 
1215b843c749SSergey Zigachev 		pool->base.clock_sources[0] =
1216b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[0], false);
1217b843c749SSergey Zigachev 		pool->base.clock_sources[1] =
1218b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[1], false);
1219b843c749SSergey Zigachev 		pool->base.clk_src_count = 2;
1220b843c749SSergey Zigachev 
1221b843c749SSergey Zigachev 	} else {
1222b843c749SSergey Zigachev 		pool->base.dp_clock_source =
1223b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[0], true);
1224b843c749SSergey Zigachev 
1225b843c749SSergey Zigachev 		pool->base.clock_sources[0] =
1226b843c749SSergey Zigachev 				dce80_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[1], false);
1227b843c749SSergey Zigachev 		pool->base.clk_src_count = 1;
1228b843c749SSergey Zigachev 	}
1229b843c749SSergey Zigachev 
1230b843c749SSergey Zigachev 	if (pool->base.dp_clock_source == NULL) {
1231b843c749SSergey Zigachev 		dm_error("DC: failed to create dp clock source!\n");
1232b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1233b843c749SSergey Zigachev 		goto res_create_fail;
1234b843c749SSergey Zigachev 	}
1235b843c749SSergey Zigachev 
1236b843c749SSergey Zigachev 	for (i = 0; i < pool->base.clk_src_count; i++) {
1237b843c749SSergey Zigachev 		if (pool->base.clock_sources[i] == NULL) {
1238b843c749SSergey Zigachev 			dm_error("DC: failed to create clock sources!\n");
1239b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1240b843c749SSergey Zigachev 			goto res_create_fail;
1241b843c749SSergey Zigachev 		}
1242b843c749SSergey Zigachev 	}
1243b843c749SSergey Zigachev 
1244b843c749SSergey Zigachev 	pool->base.dccg = dce_dccg_create(ctx,
1245b843c749SSergey Zigachev 			&disp_clk_regs,
1246b843c749SSergey Zigachev 			&disp_clk_shift,
1247b843c749SSergey Zigachev 			&disp_clk_mask);
1248b843c749SSergey Zigachev 	if (pool->base.dccg == NULL) {
1249b843c749SSergey Zigachev 		dm_error("DC: failed to create display clock!\n");
1250b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1251b843c749SSergey Zigachev 		goto res_create_fail;
1252b843c749SSergey Zigachev 	}
1253b843c749SSergey Zigachev 
1254b843c749SSergey Zigachev 	pool->base.dmcu = dce_dmcu_create(ctx,
1255b843c749SSergey Zigachev 			&dmcu_regs,
1256b843c749SSergey Zigachev 			&dmcu_shift,
1257b843c749SSergey Zigachev 			&dmcu_mask);
1258b843c749SSergey Zigachev 	if (pool->base.dmcu == NULL) {
1259b843c749SSergey Zigachev 		dm_error("DC: failed to create dmcu!\n");
1260b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1261b843c749SSergey Zigachev 		goto res_create_fail;
1262b843c749SSergey Zigachev 	}
1263b843c749SSergey Zigachev 
1264b843c749SSergey Zigachev 	pool->base.abm = dce_abm_create(ctx,
1265b843c749SSergey Zigachev 			&abm_regs,
1266b843c749SSergey Zigachev 			&abm_shift,
1267b843c749SSergey Zigachev 			&abm_mask);
1268b843c749SSergey Zigachev 	if (pool->base.abm == NULL) {
1269b843c749SSergey Zigachev 		dm_error("DC: failed to create abm!\n");
1270b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
1271b843c749SSergey Zigachev 		goto res_create_fail;
1272b843c749SSergey Zigachev 	}
1273b843c749SSergey Zigachev 
1274b843c749SSergey Zigachev 	if (dm_pp_get_static_clocks(ctx, &static_clk_info))
1275b843c749SSergey Zigachev 		pool->base.dccg->max_clks_state =
1276b843c749SSergey Zigachev 					static_clk_info.max_clocks_state;
1277b843c749SSergey Zigachev 
1278b843c749SSergey Zigachev 	{
1279b843c749SSergey Zigachev 		struct irq_service_init_data init_data;
1280b843c749SSergey Zigachev 		init_data.ctx = dc->ctx;
1281b843c749SSergey Zigachev 		pool->base.irqs = dal_irq_service_dce80_create(&init_data);
1282b843c749SSergey Zigachev 		if (!pool->base.irqs)
1283b843c749SSergey Zigachev 			goto res_create_fail;
1284b843c749SSergey Zigachev 	}
1285b843c749SSergey Zigachev 
1286b843c749SSergey Zigachev 	for (i = 0; i < pool->base.pipe_count; i++) {
1287b843c749SSergey Zigachev 		pool->base.timing_generators[i] = dce80_timing_generator_create(
1288b843c749SSergey Zigachev 				ctx, i, &dce80_tg_offsets[i]);
1289b843c749SSergey Zigachev 		if (pool->base.timing_generators[i] == NULL) {
1290b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1291b843c749SSergey Zigachev 			dm_error("DC: failed to create tg!\n");
1292b843c749SSergey Zigachev 			goto res_create_fail;
1293b843c749SSergey Zigachev 		}
1294b843c749SSergey Zigachev 
1295b843c749SSergey Zigachev 		pool->base.mis[i] = dce80_mem_input_create(ctx, i);
1296b843c749SSergey Zigachev 		if (pool->base.mis[i] == NULL) {
1297b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1298b843c749SSergey Zigachev 			dm_error("DC: failed to create memory input!\n");
1299b843c749SSergey Zigachev 			goto res_create_fail;
1300b843c749SSergey Zigachev 		}
1301b843c749SSergey Zigachev 
1302b843c749SSergey Zigachev 		pool->base.ipps[i] = dce80_ipp_create(ctx, i);
1303b843c749SSergey Zigachev 		if (pool->base.ipps[i] == NULL) {
1304b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1305b843c749SSergey Zigachev 			dm_error("DC: failed to create input pixel processor!\n");
1306b843c749SSergey Zigachev 			goto res_create_fail;
1307b843c749SSergey Zigachev 		}
1308b843c749SSergey Zigachev 
1309b843c749SSergey Zigachev 		pool->base.transforms[i] = dce80_transform_create(ctx, i);
1310b843c749SSergey Zigachev 		if (pool->base.transforms[i] == NULL) {
1311b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1312b843c749SSergey Zigachev 			dm_error("DC: failed to create transform!\n");
1313b843c749SSergey Zigachev 			goto res_create_fail;
1314b843c749SSergey Zigachev 		}
1315b843c749SSergey Zigachev 
1316b843c749SSergey Zigachev 		pool->base.opps[i] = dce80_opp_create(ctx, i);
1317b843c749SSergey Zigachev 		if (pool->base.opps[i] == NULL) {
1318b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
1319b843c749SSergey Zigachev 			dm_error("DC: failed to create output pixel processor!\n");
1320b843c749SSergey Zigachev 			goto res_create_fail;
1321b843c749SSergey Zigachev 		}
1322b843c749SSergey Zigachev 	}
1323b843c749SSergey Zigachev 
1324b843c749SSergey Zigachev 	dc->caps.max_planes =  pool->base.pipe_count;
1325b843c749SSergey Zigachev 	dc->caps.disable_dp_clk_share = true;
1326b843c749SSergey Zigachev 
1327b843c749SSergey Zigachev 	if (!resource_construct(num_virtual_links, dc, &pool->base,
1328b843c749SSergey Zigachev 			&res_create_funcs))
1329b843c749SSergey Zigachev 		goto res_create_fail;
1330b843c749SSergey Zigachev 
1331b843c749SSergey Zigachev 	/* Create hardware sequencer */
1332b843c749SSergey Zigachev 	dce80_hw_sequencer_construct(dc);
1333b843c749SSergey Zigachev 
1334b843c749SSergey Zigachev 	return true;
1335b843c749SSergey Zigachev 
1336b843c749SSergey Zigachev res_create_fail:
1337b843c749SSergey Zigachev 	destruct(pool);
1338b843c749SSergey Zigachev 	return false;
1339b843c749SSergey Zigachev }
1340b843c749SSergey Zigachev 
dce83_create_resource_pool(uint8_t num_virtual_links,struct dc * dc)1341b843c749SSergey Zigachev struct resource_pool *dce83_create_resource_pool(
1342b843c749SSergey Zigachev 	uint8_t num_virtual_links,
1343b843c749SSergey Zigachev 	struct dc *dc)
1344b843c749SSergey Zigachev {
1345b843c749SSergey Zigachev 	struct dce110_resource_pool *pool =
1346b843c749SSergey Zigachev 		kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1347b843c749SSergey Zigachev 
1348b843c749SSergey Zigachev 	if (!pool)
1349b843c749SSergey Zigachev 		return NULL;
1350b843c749SSergey Zigachev 
1351b843c749SSergey Zigachev 	if (dce83_construct(num_virtual_links, dc, pool))
1352b843c749SSergey Zigachev 		return &pool->base;
1353b843c749SSergey Zigachev 
1354b843c749SSergey Zigachev 	BREAK_TO_DEBUGGER();
1355b843c749SSergey Zigachev 	return NULL;
1356b843c749SSergey Zigachev }
1357