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 #include "dm_services.h"
26b843c749SSergey Zigachev
27b843c749SSergey Zigachev #include "link_encoder.h"
28b843c749SSergey Zigachev #include "stream_encoder.h"
29b843c749SSergey Zigachev
30b843c749SSergey Zigachev #include "resource.h"
31b843c749SSergey Zigachev #include "include/irq_service_interface.h"
32b843c749SSergey Zigachev #include "../virtual/virtual_stream_encoder.h"
33b843c749SSergey Zigachev #include "dce110/dce110_resource.h"
34b843c749SSergey Zigachev #include "dce110/dce110_timing_generator.h"
35b843c749SSergey Zigachev #include "irq/dce110/irq_service_dce110.h"
36b843c749SSergey Zigachev #include "dce/dce_link_encoder.h"
37b843c749SSergey Zigachev #include "dce/dce_stream_encoder.h"
38b843c749SSergey Zigachev
39b843c749SSergey Zigachev #include "dce/dce_mem_input.h"
40b843c749SSergey Zigachev #include "dce/dce_ipp.h"
41b843c749SSergey Zigachev #include "dce/dce_transform.h"
42b843c749SSergey Zigachev #include "dce/dce_opp.h"
43b843c749SSergey Zigachev #include "dce/dce_clocks.h"
44b843c749SSergey Zigachev #include "dce/dce_clock_source.h"
45b843c749SSergey Zigachev #include "dce/dce_audio.h"
46b843c749SSergey Zigachev #include "dce/dce_hwseq.h"
47b843c749SSergey Zigachev #include "dce100/dce100_hw_sequencer.h"
48b843c749SSergey Zigachev
49b843c749SSergey Zigachev #include "reg_helper.h"
50b843c749SSergey Zigachev
51b843c749SSergey Zigachev #include "dce/dce_10_0_d.h"
52b843c749SSergey Zigachev #include "dce/dce_10_0_sh_mask.h"
53b843c749SSergey Zigachev
54b843c749SSergey Zigachev #include "dce/dce_dmcu.h"
55b843c749SSergey Zigachev #include "dce/dce_aux.h"
56b843c749SSergey Zigachev #include "dce/dce_abm.h"
57b843c749SSergey Zigachev
58b843c749SSergey Zigachev #ifndef mmMC_HUB_RDREQ_DMIF_LIMIT
59b843c749SSergey Zigachev #include "gmc/gmc_8_2_d.h"
60b843c749SSergey Zigachev #include "gmc/gmc_8_2_sh_mask.h"
61b843c749SSergey Zigachev #endif
62b843c749SSergey Zigachev
63*78973132SSergey Zigachev #include "dce100/dce100_resource.h"
64*78973132SSergey Zigachev
65b843c749SSergey Zigachev #ifndef mmDP_DPHY_INTERNAL_CTRL
66b843c749SSergey Zigachev #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
67b843c749SSergey Zigachev #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
68b843c749SSergey Zigachev #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
69b843c749SSergey Zigachev #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
70b843c749SSergey Zigachev #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
71b843c749SSergey Zigachev #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
72b843c749SSergey Zigachev #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
73b843c749SSergey Zigachev #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
74b843c749SSergey Zigachev #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
75b843c749SSergey Zigachev #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
76b843c749SSergey Zigachev #endif
77b843c749SSergey Zigachev
78b843c749SSergey Zigachev #ifndef mmBIOS_SCRATCH_2
79b843c749SSergey Zigachev #define mmBIOS_SCRATCH_2 0x05CB
80b843c749SSergey Zigachev #define mmBIOS_SCRATCH_6 0x05CF
81b843c749SSergey Zigachev #endif
82b843c749SSergey Zigachev
83b843c749SSergey Zigachev #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
84b843c749SSergey Zigachev #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
85b843c749SSergey Zigachev #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
86b843c749SSergey Zigachev #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
87b843c749SSergey Zigachev #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
88b843c749SSergey Zigachev #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
89b843c749SSergey Zigachev #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
90b843c749SSergey Zigachev #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
91b843c749SSergey Zigachev #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
92b843c749SSergey Zigachev #endif
93b843c749SSergey Zigachev
94b843c749SSergey Zigachev #ifndef mmDP_DPHY_FAST_TRAINING
95b843c749SSergey Zigachev #define mmDP_DPHY_FAST_TRAINING 0x4ABC
96b843c749SSergey Zigachev #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
97b843c749SSergey Zigachev #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
98b843c749SSergey Zigachev #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
99b843c749SSergey Zigachev #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
100b843c749SSergey Zigachev #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
101b843c749SSergey Zigachev #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
102b843c749SSergey Zigachev #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
103b843c749SSergey Zigachev #endif
104b843c749SSergey Zigachev
105b843c749SSergey Zigachev static const struct dce110_timing_generator_offsets dce100_tg_offsets[] = {
106b843c749SSergey Zigachev {
107b843c749SSergey Zigachev .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
108b843c749SSergey Zigachev .dcp = (mmDCP0_GRPH_CONTROL - mmGRPH_CONTROL),
109b843c749SSergey Zigachev },
110b843c749SSergey Zigachev {
111b843c749SSergey Zigachev .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
112b843c749SSergey Zigachev .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
113b843c749SSergey Zigachev },
114b843c749SSergey Zigachev {
115b843c749SSergey Zigachev .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
116b843c749SSergey Zigachev .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
117b843c749SSergey Zigachev },
118b843c749SSergey Zigachev {
119b843c749SSergey Zigachev .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
120b843c749SSergey Zigachev .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
121b843c749SSergey Zigachev },
122b843c749SSergey Zigachev {
123b843c749SSergey Zigachev .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
124b843c749SSergey Zigachev .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
125b843c749SSergey Zigachev },
126b843c749SSergey Zigachev {
127b843c749SSergey Zigachev .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
128b843c749SSergey Zigachev .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
129b843c749SSergey Zigachev }
130b843c749SSergey Zigachev };
131b843c749SSergey Zigachev
132b843c749SSergey Zigachev /* set register offset */
133b843c749SSergey Zigachev #define SR(reg_name)\
134b843c749SSergey Zigachev .reg_name = mm ## reg_name
135b843c749SSergey Zigachev
136b843c749SSergey Zigachev /* set register offset with instance */
137b843c749SSergey Zigachev #define SRI(reg_name, block, id)\
138b843c749SSergey Zigachev .reg_name = mm ## block ## id ## _ ## reg_name
139b843c749SSergey Zigachev
140b843c749SSergey Zigachev
141b843c749SSergey Zigachev static const struct dccg_registers disp_clk_regs = {
142b843c749SSergey Zigachev CLK_COMMON_REG_LIST_DCE_BASE()
143b843c749SSergey Zigachev };
144b843c749SSergey Zigachev
145b843c749SSergey Zigachev static const struct dccg_shift disp_clk_shift = {
146b843c749SSergey Zigachev CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
147b843c749SSergey Zigachev };
148b843c749SSergey Zigachev
149b843c749SSergey Zigachev static const struct dccg_mask disp_clk_mask = {
150b843c749SSergey Zigachev CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
151b843c749SSergey Zigachev };
152b843c749SSergey Zigachev
153b843c749SSergey Zigachev #define ipp_regs(id)\
154b843c749SSergey Zigachev [id] = {\
155b843c749SSergey Zigachev IPP_DCE100_REG_LIST_DCE_BASE(id)\
156b843c749SSergey Zigachev }
157b843c749SSergey Zigachev
158b843c749SSergey Zigachev static const struct dce_ipp_registers ipp_regs[] = {
159b843c749SSergey Zigachev ipp_regs(0),
160b843c749SSergey Zigachev ipp_regs(1),
161b843c749SSergey Zigachev ipp_regs(2),
162b843c749SSergey Zigachev ipp_regs(3),
163b843c749SSergey Zigachev ipp_regs(4),
164b843c749SSergey Zigachev ipp_regs(5)
165b843c749SSergey Zigachev };
166b843c749SSergey Zigachev
167b843c749SSergey Zigachev static const struct dce_ipp_shift ipp_shift = {
168b843c749SSergey Zigachev IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
169b843c749SSergey Zigachev };
170b843c749SSergey Zigachev
171b843c749SSergey Zigachev static const struct dce_ipp_mask ipp_mask = {
172b843c749SSergey Zigachev IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
173b843c749SSergey Zigachev };
174b843c749SSergey Zigachev
175b843c749SSergey Zigachev #define transform_regs(id)\
176b843c749SSergey Zigachev [id] = {\
177b843c749SSergey Zigachev XFM_COMMON_REG_LIST_DCE100(id)\
178b843c749SSergey Zigachev }
179b843c749SSergey Zigachev
180b843c749SSergey Zigachev static const struct dce_transform_registers xfm_regs[] = {
181b843c749SSergey Zigachev transform_regs(0),
182b843c749SSergey Zigachev transform_regs(1),
183b843c749SSergey Zigachev transform_regs(2),
184b843c749SSergey Zigachev transform_regs(3),
185b843c749SSergey Zigachev transform_regs(4),
186b843c749SSergey Zigachev transform_regs(5)
187b843c749SSergey Zigachev };
188b843c749SSergey Zigachev
189b843c749SSergey Zigachev static const struct dce_transform_shift xfm_shift = {
190b843c749SSergey Zigachev XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
191b843c749SSergey Zigachev };
192b843c749SSergey Zigachev
193b843c749SSergey Zigachev static const struct dce_transform_mask xfm_mask = {
194b843c749SSergey Zigachev XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
195b843c749SSergey Zigachev };
196b843c749SSergey Zigachev
197b843c749SSergey Zigachev #define aux_regs(id)\
198b843c749SSergey Zigachev [id] = {\
199b843c749SSergey Zigachev AUX_REG_LIST(id)\
200b843c749SSergey Zigachev }
201b843c749SSergey Zigachev
202b843c749SSergey Zigachev static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
203b843c749SSergey Zigachev aux_regs(0),
204b843c749SSergey Zigachev aux_regs(1),
205b843c749SSergey Zigachev aux_regs(2),
206b843c749SSergey Zigachev aux_regs(3),
207b843c749SSergey Zigachev aux_regs(4),
208b843c749SSergey Zigachev aux_regs(5)
209b843c749SSergey Zigachev };
210b843c749SSergey Zigachev
211b843c749SSergey Zigachev #define hpd_regs(id)\
212b843c749SSergey Zigachev [id] = {\
213b843c749SSergey Zigachev HPD_REG_LIST(id)\
214b843c749SSergey Zigachev }
215b843c749SSergey Zigachev
216b843c749SSergey Zigachev static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
217b843c749SSergey Zigachev hpd_regs(0),
218b843c749SSergey Zigachev hpd_regs(1),
219b843c749SSergey Zigachev hpd_regs(2),
220b843c749SSergey Zigachev hpd_regs(3),
221b843c749SSergey Zigachev hpd_regs(4),
222b843c749SSergey Zigachev hpd_regs(5)
223b843c749SSergey Zigachev };
224b843c749SSergey Zigachev
225b843c749SSergey Zigachev #define link_regs(id)\
226b843c749SSergey Zigachev [id] = {\
227b843c749SSergey Zigachev LE_DCE100_REG_LIST(id)\
228b843c749SSergey Zigachev }
229b843c749SSergey Zigachev
230b843c749SSergey Zigachev static const struct dce110_link_enc_registers link_enc_regs[] = {
231b843c749SSergey Zigachev link_regs(0),
232b843c749SSergey Zigachev link_regs(1),
233b843c749SSergey Zigachev link_regs(2),
234b843c749SSergey Zigachev link_regs(3),
235b843c749SSergey Zigachev link_regs(4),
236b843c749SSergey Zigachev link_regs(5),
237b843c749SSergey Zigachev link_regs(6),
238b843c749SSergey Zigachev };
239b843c749SSergey Zigachev
240b843c749SSergey Zigachev #define stream_enc_regs(id)\
241b843c749SSergey Zigachev [id] = {\
242b843c749SSergey Zigachev SE_COMMON_REG_LIST_DCE_BASE(id),\
243b843c749SSergey Zigachev .AFMT_CNTL = 0,\
244b843c749SSergey Zigachev }
245b843c749SSergey Zigachev
246b843c749SSergey Zigachev static const struct dce110_stream_enc_registers stream_enc_regs[] = {
247b843c749SSergey Zigachev stream_enc_regs(0),
248b843c749SSergey Zigachev stream_enc_regs(1),
249b843c749SSergey Zigachev stream_enc_regs(2),
250b843c749SSergey Zigachev stream_enc_regs(3),
251b843c749SSergey Zigachev stream_enc_regs(4),
252b843c749SSergey Zigachev stream_enc_regs(5),
253b843c749SSergey Zigachev stream_enc_regs(6)
254b843c749SSergey Zigachev };
255b843c749SSergey Zigachev
256b843c749SSergey Zigachev static const struct dce_stream_encoder_shift se_shift = {
257b843c749SSergey Zigachev SE_COMMON_MASK_SH_LIST_DCE80_100(__SHIFT)
258b843c749SSergey Zigachev };
259b843c749SSergey Zigachev
260b843c749SSergey Zigachev static const struct dce_stream_encoder_mask se_mask = {
261b843c749SSergey Zigachev SE_COMMON_MASK_SH_LIST_DCE80_100(_MASK)
262b843c749SSergey Zigachev };
263b843c749SSergey Zigachev
264b843c749SSergey Zigachev #define opp_regs(id)\
265b843c749SSergey Zigachev [id] = {\
266b843c749SSergey Zigachev OPP_DCE_100_REG_LIST(id),\
267b843c749SSergey Zigachev }
268b843c749SSergey Zigachev
269b843c749SSergey Zigachev static const struct dce_opp_registers opp_regs[] = {
270b843c749SSergey Zigachev opp_regs(0),
271b843c749SSergey Zigachev opp_regs(1),
272b843c749SSergey Zigachev opp_regs(2),
273b843c749SSergey Zigachev opp_regs(3),
274b843c749SSergey Zigachev opp_regs(4),
275b843c749SSergey Zigachev opp_regs(5)
276b843c749SSergey Zigachev };
277b843c749SSergey Zigachev
278b843c749SSergey Zigachev static const struct dce_opp_shift opp_shift = {
279b843c749SSergey Zigachev OPP_COMMON_MASK_SH_LIST_DCE_100(__SHIFT)
280b843c749SSergey Zigachev };
281b843c749SSergey Zigachev
282b843c749SSergey Zigachev static const struct dce_opp_mask opp_mask = {
283b843c749SSergey Zigachev OPP_COMMON_MASK_SH_LIST_DCE_100(_MASK)
284b843c749SSergey Zigachev };
285b843c749SSergey Zigachev #define aux_engine_regs(id)\
286b843c749SSergey Zigachev [id] = {\
287b843c749SSergey Zigachev AUX_COMMON_REG_LIST(id), \
288b843c749SSergey Zigachev .AUX_RESET_MASK = 0 \
289b843c749SSergey Zigachev }
290b843c749SSergey Zigachev
291b843c749SSergey Zigachev static const struct dce110_aux_registers aux_engine_regs[] = {
292b843c749SSergey Zigachev aux_engine_regs(0),
293b843c749SSergey Zigachev aux_engine_regs(1),
294b843c749SSergey Zigachev aux_engine_regs(2),
295b843c749SSergey Zigachev aux_engine_regs(3),
296b843c749SSergey Zigachev aux_engine_regs(4),
297b843c749SSergey Zigachev aux_engine_regs(5)
298b843c749SSergey Zigachev };
299b843c749SSergey Zigachev
300b843c749SSergey Zigachev #define audio_regs(id)\
301b843c749SSergey Zigachev [id] = {\
302b843c749SSergey Zigachev AUD_COMMON_REG_LIST(id)\
303b843c749SSergey Zigachev }
304b843c749SSergey Zigachev
305b843c749SSergey Zigachev static const struct dce_audio_registers audio_regs[] = {
306b843c749SSergey Zigachev audio_regs(0),
307b843c749SSergey Zigachev audio_regs(1),
308b843c749SSergey Zigachev audio_regs(2),
309b843c749SSergey Zigachev audio_regs(3),
310b843c749SSergey Zigachev audio_regs(4),
311b843c749SSergey Zigachev audio_regs(5),
312b843c749SSergey Zigachev audio_regs(6),
313b843c749SSergey Zigachev };
314b843c749SSergey Zigachev
315b843c749SSergey Zigachev static const struct dce_audio_shift audio_shift = {
316b843c749SSergey Zigachev AUD_COMMON_MASK_SH_LIST(__SHIFT)
317b843c749SSergey Zigachev };
318b843c749SSergey Zigachev
319b843c749SSergey Zigachev static const struct dce_aduio_mask audio_mask = {
320b843c749SSergey Zigachev AUD_COMMON_MASK_SH_LIST(_MASK)
321b843c749SSergey Zigachev };
322b843c749SSergey Zigachev
323b843c749SSergey Zigachev #define clk_src_regs(id)\
324b843c749SSergey Zigachev [id] = {\
325b843c749SSergey Zigachev CS_COMMON_REG_LIST_DCE_100_110(id),\
326b843c749SSergey Zigachev }
327b843c749SSergey Zigachev
328b843c749SSergey Zigachev static const struct dce110_clk_src_regs clk_src_regs[] = {
329b843c749SSergey Zigachev clk_src_regs(0),
330b843c749SSergey Zigachev clk_src_regs(1),
331b843c749SSergey Zigachev clk_src_regs(2)
332b843c749SSergey Zigachev };
333b843c749SSergey Zigachev
334b843c749SSergey Zigachev static const struct dce110_clk_src_shift cs_shift = {
335b843c749SSergey Zigachev CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
336b843c749SSergey Zigachev };
337b843c749SSergey Zigachev
338b843c749SSergey Zigachev static const struct dce110_clk_src_mask cs_mask = {
339b843c749SSergey Zigachev CS_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
340b843c749SSergey Zigachev };
341b843c749SSergey Zigachev
342b843c749SSergey Zigachev static const struct dce_dmcu_registers dmcu_regs = {
343b843c749SSergey Zigachev DMCU_DCE110_COMMON_REG_LIST()
344b843c749SSergey Zigachev };
345b843c749SSergey Zigachev
346b843c749SSergey Zigachev static const struct dce_dmcu_shift dmcu_shift = {
347b843c749SSergey Zigachev DMCU_MASK_SH_LIST_DCE110(__SHIFT)
348b843c749SSergey Zigachev };
349b843c749SSergey Zigachev
350b843c749SSergey Zigachev static const struct dce_dmcu_mask dmcu_mask = {
351b843c749SSergey Zigachev DMCU_MASK_SH_LIST_DCE110(_MASK)
352b843c749SSergey Zigachev };
353b843c749SSergey Zigachev
354b843c749SSergey Zigachev static const struct dce_abm_registers abm_regs = {
355b843c749SSergey Zigachev ABM_DCE110_COMMON_REG_LIST()
356b843c749SSergey Zigachev };
357b843c749SSergey Zigachev
358b843c749SSergey Zigachev static const struct dce_abm_shift abm_shift = {
359b843c749SSergey Zigachev ABM_MASK_SH_LIST_DCE110(__SHIFT)
360b843c749SSergey Zigachev };
361b843c749SSergey Zigachev
362b843c749SSergey Zigachev static const struct dce_abm_mask abm_mask = {
363b843c749SSergey Zigachev ABM_MASK_SH_LIST_DCE110(_MASK)
364b843c749SSergey Zigachev };
365b843c749SSergey Zigachev
366b843c749SSergey Zigachev #define DCFE_MEM_PWR_CTRL_REG_BASE 0x1b03
367b843c749SSergey Zigachev
368b843c749SSergey Zigachev static const struct bios_registers bios_regs = {
369b843c749SSergey Zigachev .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
370b843c749SSergey Zigachev };
371b843c749SSergey Zigachev
372b843c749SSergey Zigachev static const struct resource_caps res_cap = {
373b843c749SSergey Zigachev .num_timing_generator = 6,
374b843c749SSergey Zigachev .num_audio = 6,
375b843c749SSergey Zigachev .num_stream_encoder = 6,
376b843c749SSergey Zigachev .num_pll = 3
377b843c749SSergey Zigachev };
378b843c749SSergey Zigachev
379b843c749SSergey Zigachev #define CTX ctx
380b843c749SSergey Zigachev #define REG(reg) mm ## reg
381b843c749SSergey Zigachev
382b843c749SSergey Zigachev #ifndef mmCC_DC_HDMI_STRAPS
383b843c749SSergey Zigachev #define mmCC_DC_HDMI_STRAPS 0x1918
384b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
385b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
386b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
387b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
388b843c749SSergey Zigachev #endif
389b843c749SSergey Zigachev
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)390b843c749SSergey Zigachev static void read_dce_straps(
391b843c749SSergey Zigachev struct dc_context *ctx,
392b843c749SSergey Zigachev struct resource_straps *straps)
393b843c749SSergey Zigachev {
394b843c749SSergey Zigachev REG_GET_2(CC_DC_HDMI_STRAPS,
395b843c749SSergey Zigachev HDMI_DISABLE, &straps->hdmi_disable,
396b843c749SSergey Zigachev AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
397b843c749SSergey Zigachev
398b843c749SSergey Zigachev REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
399b843c749SSergey Zigachev }
400b843c749SSergey Zigachev
create_audio(struct dc_context * ctx,unsigned int inst)401b843c749SSergey Zigachev static struct audio *create_audio(
402b843c749SSergey Zigachev struct dc_context *ctx, unsigned int inst)
403b843c749SSergey Zigachev {
404b843c749SSergey Zigachev return dce_audio_create(ctx, inst,
405b843c749SSergey Zigachev &audio_regs[inst], &audio_shift, &audio_mask);
406b843c749SSergey Zigachev }
407b843c749SSergey Zigachev
dce100_timing_generator_create(struct dc_context * ctx,uint32_t instance,const struct dce110_timing_generator_offsets * offsets)408b843c749SSergey Zigachev static struct timing_generator *dce100_timing_generator_create(
409b843c749SSergey Zigachev struct dc_context *ctx,
410b843c749SSergey Zigachev uint32_t instance,
411b843c749SSergey Zigachev const struct dce110_timing_generator_offsets *offsets)
412b843c749SSergey Zigachev {
413b843c749SSergey Zigachev struct dce110_timing_generator *tg110 =
414b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
415b843c749SSergey Zigachev
416b843c749SSergey Zigachev if (!tg110)
417b843c749SSergey Zigachev return NULL;
418b843c749SSergey Zigachev
419b843c749SSergey Zigachev dce110_timing_generator_construct(tg110, ctx, instance, offsets);
420b843c749SSergey Zigachev return &tg110->base;
421b843c749SSergey Zigachev }
422b843c749SSergey Zigachev
dce100_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)423b843c749SSergey Zigachev static struct stream_encoder *dce100_stream_encoder_create(
424b843c749SSergey Zigachev enum engine_id eng_id,
425b843c749SSergey Zigachev struct dc_context *ctx)
426b843c749SSergey Zigachev {
427b843c749SSergey Zigachev struct dce110_stream_encoder *enc110 =
428b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
429b843c749SSergey Zigachev
430b843c749SSergey Zigachev if (!enc110)
431b843c749SSergey Zigachev return NULL;
432b843c749SSergey Zigachev
433b843c749SSergey Zigachev dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
434b843c749SSergey Zigachev &stream_enc_regs[eng_id], &se_shift, &se_mask);
435b843c749SSergey Zigachev return &enc110->base;
436b843c749SSergey Zigachev }
437b843c749SSergey Zigachev
438b843c749SSergey Zigachev #define SRII(reg_name, block, id)\
439b843c749SSergey Zigachev .reg_name[id] = mm ## block ## id ## _ ## reg_name
440b843c749SSergey Zigachev
441b843c749SSergey Zigachev static const struct dce_hwseq_registers hwseq_reg = {
442b843c749SSergey Zigachev HWSEQ_DCE10_REG_LIST()
443b843c749SSergey Zigachev };
444b843c749SSergey Zigachev
445b843c749SSergey Zigachev static const struct dce_hwseq_shift hwseq_shift = {
446b843c749SSergey Zigachev HWSEQ_DCE10_MASK_SH_LIST(__SHIFT)
447b843c749SSergey Zigachev };
448b843c749SSergey Zigachev
449b843c749SSergey Zigachev static const struct dce_hwseq_mask hwseq_mask = {
450b843c749SSergey Zigachev HWSEQ_DCE10_MASK_SH_LIST(_MASK)
451b843c749SSergey Zigachev };
452b843c749SSergey Zigachev
dce100_hwseq_create(struct dc_context * ctx)453b843c749SSergey Zigachev static struct dce_hwseq *dce100_hwseq_create(
454b843c749SSergey Zigachev struct dc_context *ctx)
455b843c749SSergey Zigachev {
456b843c749SSergey Zigachev struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
457b843c749SSergey Zigachev
458b843c749SSergey Zigachev if (hws) {
459b843c749SSergey Zigachev hws->ctx = ctx;
460b843c749SSergey Zigachev hws->regs = &hwseq_reg;
461b843c749SSergey Zigachev hws->shifts = &hwseq_shift;
462b843c749SSergey Zigachev hws->masks = &hwseq_mask;
463b843c749SSergey Zigachev }
464b843c749SSergey Zigachev return hws;
465b843c749SSergey Zigachev }
466b843c749SSergey Zigachev
467b843c749SSergey Zigachev static const struct resource_create_funcs res_create_funcs = {
468b843c749SSergey Zigachev .read_dce_straps = read_dce_straps,
469b843c749SSergey Zigachev .create_audio = create_audio,
470b843c749SSergey Zigachev .create_stream_encoder = dce100_stream_encoder_create,
471b843c749SSergey Zigachev .create_hwseq = dce100_hwseq_create,
472b843c749SSergey Zigachev };
473b843c749SSergey Zigachev
474b843c749SSergey Zigachev #define mi_inst_regs(id) { \
475b843c749SSergey Zigachev MI_DCE8_REG_LIST(id), \
476b843c749SSergey Zigachev .MC_HUB_RDREQ_DMIF_LIMIT = mmMC_HUB_RDREQ_DMIF_LIMIT \
477b843c749SSergey Zigachev }
478b843c749SSergey Zigachev static const struct dce_mem_input_registers mi_regs[] = {
479b843c749SSergey Zigachev mi_inst_regs(0),
480b843c749SSergey Zigachev mi_inst_regs(1),
481b843c749SSergey Zigachev mi_inst_regs(2),
482b843c749SSergey Zigachev mi_inst_regs(3),
483b843c749SSergey Zigachev mi_inst_regs(4),
484b843c749SSergey Zigachev mi_inst_regs(5),
485b843c749SSergey Zigachev };
486b843c749SSergey Zigachev
487b843c749SSergey Zigachev static const struct dce_mem_input_shift mi_shifts = {
488b843c749SSergey Zigachev MI_DCE8_MASK_SH_LIST(__SHIFT),
489b843c749SSergey Zigachev .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE__SHIFT
490b843c749SSergey Zigachev };
491b843c749SSergey Zigachev
492b843c749SSergey Zigachev static const struct dce_mem_input_mask mi_masks = {
493b843c749SSergey Zigachev MI_DCE8_MASK_SH_LIST(_MASK),
494b843c749SSergey Zigachev .ENABLE = MC_HUB_RDREQ_DMIF_LIMIT__ENABLE_MASK
495b843c749SSergey Zigachev };
496b843c749SSergey Zigachev
dce100_mem_input_create(struct dc_context * ctx,uint32_t inst)497b843c749SSergey Zigachev static struct mem_input *dce100_mem_input_create(
498b843c749SSergey Zigachev struct dc_context *ctx,
499b843c749SSergey Zigachev uint32_t inst)
500b843c749SSergey Zigachev {
501b843c749SSergey Zigachev struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
502b843c749SSergey Zigachev GFP_KERNEL);
503b843c749SSergey Zigachev
504b843c749SSergey Zigachev if (!dce_mi) {
505b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
506b843c749SSergey Zigachev return NULL;
507b843c749SSergey Zigachev }
508b843c749SSergey Zigachev
509b843c749SSergey Zigachev dce_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
510b843c749SSergey Zigachev dce_mi->wa.single_head_rdreq_dmif_limit = 2;
511b843c749SSergey Zigachev return &dce_mi->base;
512b843c749SSergey Zigachev }
513b843c749SSergey Zigachev
dce100_transform_destroy(struct transform ** xfm)514b843c749SSergey Zigachev static void dce100_transform_destroy(struct transform **xfm)
515b843c749SSergey Zigachev {
516b843c749SSergey Zigachev kfree(TO_DCE_TRANSFORM(*xfm));
517b843c749SSergey Zigachev *xfm = NULL;
518b843c749SSergey Zigachev }
519b843c749SSergey Zigachev
dce100_transform_create(struct dc_context * ctx,uint32_t inst)520b843c749SSergey Zigachev static struct transform *dce100_transform_create(
521b843c749SSergey Zigachev struct dc_context *ctx,
522b843c749SSergey Zigachev uint32_t inst)
523b843c749SSergey Zigachev {
524b843c749SSergey Zigachev struct dce_transform *transform =
525b843c749SSergey Zigachev kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
526b843c749SSergey Zigachev
527b843c749SSergey Zigachev if (!transform)
528b843c749SSergey Zigachev return NULL;
529b843c749SSergey Zigachev
530b843c749SSergey Zigachev dce_transform_construct(transform, ctx, inst,
531b843c749SSergey Zigachev &xfm_regs[inst], &xfm_shift, &xfm_mask);
532b843c749SSergey Zigachev return &transform->base;
533b843c749SSergey Zigachev }
534b843c749SSergey Zigachev
dce100_ipp_create(struct dc_context * ctx,uint32_t inst)535b843c749SSergey Zigachev static struct input_pixel_processor *dce100_ipp_create(
536b843c749SSergey Zigachev struct dc_context *ctx, uint32_t inst)
537b843c749SSergey Zigachev {
538b843c749SSergey Zigachev struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
539b843c749SSergey Zigachev
540b843c749SSergey Zigachev if (!ipp) {
541b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
542b843c749SSergey Zigachev return NULL;
543b843c749SSergey Zigachev }
544b843c749SSergey Zigachev
545b843c749SSergey Zigachev dce_ipp_construct(ipp, ctx, inst,
546b843c749SSergey Zigachev &ipp_regs[inst], &ipp_shift, &ipp_mask);
547b843c749SSergey Zigachev return &ipp->base;
548b843c749SSergey Zigachev }
549b843c749SSergey Zigachev
550b843c749SSergey Zigachev static const struct encoder_feature_support link_enc_feature = {
551b843c749SSergey Zigachev .max_hdmi_deep_color = COLOR_DEPTH_121212,
552b843c749SSergey Zigachev .max_hdmi_pixel_clock = 300000,
553b843c749SSergey Zigachev .flags.bits.IS_HBR2_CAPABLE = true,
554b843c749SSergey Zigachev .flags.bits.IS_TPS3_CAPABLE = true,
555b843c749SSergey Zigachev .flags.bits.IS_YCBCR_CAPABLE = true
556b843c749SSergey Zigachev };
557b843c749SSergey Zigachev
558*78973132SSergey Zigachev static
dce100_link_encoder_create(const struct encoder_init_data * enc_init_data)559b843c749SSergey Zigachev struct link_encoder *dce100_link_encoder_create(
560b843c749SSergey Zigachev const struct encoder_init_data *enc_init_data)
561b843c749SSergey Zigachev {
562b843c749SSergey Zigachev struct dce110_link_encoder *enc110 =
563b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
564b843c749SSergey Zigachev
565b843c749SSergey Zigachev if (!enc110)
566b843c749SSergey Zigachev return NULL;
567b843c749SSergey Zigachev
568b843c749SSergey Zigachev dce110_link_encoder_construct(enc110,
569b843c749SSergey Zigachev enc_init_data,
570b843c749SSergey Zigachev &link_enc_feature,
571b843c749SSergey Zigachev &link_enc_regs[enc_init_data->transmitter],
572b843c749SSergey Zigachev &link_enc_aux_regs[enc_init_data->channel - 1],
573b843c749SSergey Zigachev &link_enc_hpd_regs[enc_init_data->hpd_source]);
574b843c749SSergey Zigachev return &enc110->base;
575b843c749SSergey Zigachev }
576b843c749SSergey Zigachev
577*78973132SSergey Zigachev static
dce100_opp_create(struct dc_context * ctx,uint32_t inst)578b843c749SSergey Zigachev struct output_pixel_processor *dce100_opp_create(
579b843c749SSergey Zigachev struct dc_context *ctx,
580b843c749SSergey Zigachev uint32_t inst)
581b843c749SSergey Zigachev {
582b843c749SSergey Zigachev struct dce110_opp *opp =
583b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
584b843c749SSergey Zigachev
585b843c749SSergey Zigachev if (!opp)
586b843c749SSergey Zigachev return NULL;
587b843c749SSergey Zigachev
588b843c749SSergey Zigachev dce110_opp_construct(opp,
589b843c749SSergey Zigachev ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
590b843c749SSergey Zigachev return &opp->base;
591b843c749SSergey Zigachev }
592b843c749SSergey Zigachev
593*78973132SSergey Zigachev static
dce100_aux_engine_create(struct dc_context * ctx,uint32_t inst)594b843c749SSergey Zigachev struct aux_engine *dce100_aux_engine_create(
595b843c749SSergey Zigachev struct dc_context *ctx,
596b843c749SSergey Zigachev uint32_t inst)
597b843c749SSergey Zigachev {
598b843c749SSergey Zigachev struct aux_engine_dce110 *aux_engine =
599b843c749SSergey Zigachev kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
600b843c749SSergey Zigachev
601b843c749SSergey Zigachev if (!aux_engine)
602b843c749SSergey Zigachev return NULL;
603b843c749SSergey Zigachev
604b843c749SSergey Zigachev dce110_aux_engine_construct(aux_engine, ctx, inst,
605b843c749SSergey Zigachev SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
606b843c749SSergey Zigachev &aux_engine_regs[inst]);
607b843c749SSergey Zigachev
608b843c749SSergey Zigachev return &aux_engine->base;
609b843c749SSergey Zigachev }
610b843c749SSergey Zigachev
611*78973132SSergey Zigachev static
dce100_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)612b843c749SSergey Zigachev struct clock_source *dce100_clock_source_create(
613b843c749SSergey Zigachev struct dc_context *ctx,
614b843c749SSergey Zigachev struct dc_bios *bios,
615b843c749SSergey Zigachev enum clock_source_id id,
616b843c749SSergey Zigachev const struct dce110_clk_src_regs *regs,
617b843c749SSergey Zigachev bool dp_clk_src)
618b843c749SSergey Zigachev {
619b843c749SSergey Zigachev struct dce110_clk_src *clk_src =
620b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
621b843c749SSergey Zigachev
622b843c749SSergey Zigachev if (!clk_src)
623b843c749SSergey Zigachev return NULL;
624b843c749SSergey Zigachev
625b843c749SSergey Zigachev if (dce110_clk_src_construct(clk_src, ctx, bios, id,
626b843c749SSergey Zigachev regs, &cs_shift, &cs_mask)) {
627b843c749SSergey Zigachev clk_src->base.dp_clk_src = dp_clk_src;
628b843c749SSergey Zigachev return &clk_src->base;
629b843c749SSergey Zigachev }
630b843c749SSergey Zigachev
631b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
632b843c749SSergey Zigachev return NULL;
633b843c749SSergey Zigachev }
634b843c749SSergey Zigachev
635*78973132SSergey Zigachev static
dce100_clock_source_destroy(struct clock_source ** clk_src)636b843c749SSergey Zigachev void dce100_clock_source_destroy(struct clock_source **clk_src)
637b843c749SSergey Zigachev {
638b843c749SSergey Zigachev kfree(TO_DCE110_CLK_SRC(*clk_src));
639b843c749SSergey Zigachev *clk_src = NULL;
640b843c749SSergey Zigachev }
641b843c749SSergey Zigachev
destruct(struct dce110_resource_pool * pool)642b843c749SSergey Zigachev static void destruct(struct dce110_resource_pool *pool)
643b843c749SSergey Zigachev {
644b843c749SSergey Zigachev unsigned int i;
645b843c749SSergey Zigachev
646b843c749SSergey Zigachev for (i = 0; i < pool->base.pipe_count; i++) {
647b843c749SSergey Zigachev if (pool->base.opps[i] != NULL)
648b843c749SSergey Zigachev dce110_opp_destroy(&pool->base.opps[i]);
649b843c749SSergey Zigachev
650b843c749SSergey Zigachev if (pool->base.transforms[i] != NULL)
651b843c749SSergey Zigachev dce100_transform_destroy(&pool->base.transforms[i]);
652b843c749SSergey Zigachev
653b843c749SSergey Zigachev if (pool->base.ipps[i] != NULL)
654b843c749SSergey Zigachev dce_ipp_destroy(&pool->base.ipps[i]);
655b843c749SSergey Zigachev
656b843c749SSergey Zigachev if (pool->base.mis[i] != NULL) {
657b843c749SSergey Zigachev kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
658b843c749SSergey Zigachev pool->base.mis[i] = NULL;
659b843c749SSergey Zigachev }
660b843c749SSergey Zigachev
661b843c749SSergey Zigachev if (pool->base.timing_generators[i] != NULL) {
662b843c749SSergey Zigachev kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
663b843c749SSergey Zigachev pool->base.timing_generators[i] = NULL;
664b843c749SSergey Zigachev }
665b843c749SSergey Zigachev
666b843c749SSergey Zigachev if (pool->base.engines[i] != NULL)
667b843c749SSergey Zigachev dce110_engine_destroy(&pool->base.engines[i]);
668b843c749SSergey Zigachev
669b843c749SSergey Zigachev }
670b843c749SSergey Zigachev
671b843c749SSergey Zigachev for (i = 0; i < pool->base.stream_enc_count; i++) {
672b843c749SSergey Zigachev if (pool->base.stream_enc[i] != NULL)
673b843c749SSergey Zigachev kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
674b843c749SSergey Zigachev }
675b843c749SSergey Zigachev
676b843c749SSergey Zigachev for (i = 0; i < pool->base.clk_src_count; i++) {
677b843c749SSergey Zigachev if (pool->base.clock_sources[i] != NULL)
678b843c749SSergey Zigachev dce100_clock_source_destroy(&pool->base.clock_sources[i]);
679b843c749SSergey Zigachev }
680b843c749SSergey Zigachev
681b843c749SSergey Zigachev if (pool->base.dp_clock_source != NULL)
682b843c749SSergey Zigachev dce100_clock_source_destroy(&pool->base.dp_clock_source);
683b843c749SSergey Zigachev
684b843c749SSergey Zigachev for (i = 0; i < pool->base.audio_count; i++) {
685b843c749SSergey Zigachev if (pool->base.audios[i] != NULL)
686b843c749SSergey Zigachev dce_aud_destroy(&pool->base.audios[i]);
687b843c749SSergey Zigachev }
688b843c749SSergey Zigachev
689b843c749SSergey Zigachev if (pool->base.dccg != NULL)
690b843c749SSergey Zigachev dce_dccg_destroy(&pool->base.dccg);
691b843c749SSergey Zigachev
692b843c749SSergey Zigachev if (pool->base.abm != NULL)
693b843c749SSergey Zigachev dce_abm_destroy(&pool->base.abm);
694b843c749SSergey Zigachev
695b843c749SSergey Zigachev if (pool->base.dmcu != NULL)
696b843c749SSergey Zigachev dce_dmcu_destroy(&pool->base.dmcu);
697b843c749SSergey Zigachev
698b843c749SSergey Zigachev if (pool->base.irqs != NULL)
699b843c749SSergey Zigachev dal_irq_service_destroy(&pool->base.irqs);
700b843c749SSergey Zigachev }
701b843c749SSergey Zigachev
build_mapped_resource(const struct dc * dc,struct dc_state * context,struct dc_stream_state * stream)702b843c749SSergey Zigachev static enum dc_status build_mapped_resource(
703b843c749SSergey Zigachev const struct dc *dc,
704b843c749SSergey Zigachev struct dc_state *context,
705b843c749SSergey Zigachev struct dc_stream_state *stream)
706b843c749SSergey Zigachev {
707b843c749SSergey Zigachev struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
708b843c749SSergey Zigachev
709b843c749SSergey Zigachev if (!pipe_ctx)
710b843c749SSergey Zigachev return DC_ERROR_UNEXPECTED;
711b843c749SSergey Zigachev
712b843c749SSergey Zigachev dce110_resource_build_pipe_hw_param(pipe_ctx);
713b843c749SSergey Zigachev
714b843c749SSergey Zigachev resource_build_info_frame(pipe_ctx);
715b843c749SSergey Zigachev
716b843c749SSergey Zigachev return DC_OK;
717b843c749SSergey Zigachev }
718b843c749SSergey Zigachev
719*78973132SSergey Zigachev static
dce100_validate_bandwidth(struct dc * dc,struct dc_state * context)720b843c749SSergey Zigachev bool dce100_validate_bandwidth(
721b843c749SSergey Zigachev struct dc *dc,
722b843c749SSergey Zigachev struct dc_state *context)
723b843c749SSergey Zigachev {
724b843c749SSergey Zigachev int i;
725b843c749SSergey Zigachev bool at_least_one_pipe = false;
726b843c749SSergey Zigachev
727b843c749SSergey Zigachev for (i = 0; i < dc->res_pool->pipe_count; i++) {
728b843c749SSergey Zigachev if (context->res_ctx.pipe_ctx[i].stream)
729b843c749SSergey Zigachev at_least_one_pipe = true;
730b843c749SSergey Zigachev }
731b843c749SSergey Zigachev
732b843c749SSergey Zigachev if (at_least_one_pipe) {
733b843c749SSergey Zigachev /* TODO implement when needed but for now hardcode max value*/
734b843c749SSergey Zigachev context->bw.dce.dispclk_khz = 681000;
735b843c749SSergey Zigachev context->bw.dce.yclk_khz = 250000 * MEMORY_TYPE_MULTIPLIER;
736b843c749SSergey Zigachev } else {
737b843c749SSergey Zigachev context->bw.dce.dispclk_khz = 0;
738b843c749SSergey Zigachev context->bw.dce.yclk_khz = 0;
739b843c749SSergey Zigachev }
740b843c749SSergey Zigachev
741b843c749SSergey Zigachev return true;
742b843c749SSergey Zigachev }
743b843c749SSergey Zigachev
dce100_validate_surface_sets(struct dc_state * context)744b843c749SSergey Zigachev static bool dce100_validate_surface_sets(
745b843c749SSergey Zigachev struct dc_state *context)
746b843c749SSergey Zigachev {
747b843c749SSergey Zigachev int i;
748b843c749SSergey Zigachev
749b843c749SSergey Zigachev for (i = 0; i < context->stream_count; i++) {
750b843c749SSergey Zigachev if (context->stream_status[i].plane_count == 0)
751b843c749SSergey Zigachev continue;
752b843c749SSergey Zigachev
753b843c749SSergey Zigachev if (context->stream_status[i].plane_count > 1)
754b843c749SSergey Zigachev return false;
755b843c749SSergey Zigachev
756b843c749SSergey Zigachev if (context->stream_status[i].plane_states[0]->format
757b843c749SSergey Zigachev >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
758b843c749SSergey Zigachev return false;
759b843c749SSergey Zigachev }
760b843c749SSergey Zigachev
761b843c749SSergey Zigachev return true;
762b843c749SSergey Zigachev }
763b843c749SSergey Zigachev
764*78973132SSergey Zigachev static
dce100_validate_global(struct dc * dc,struct dc_state * context)765b843c749SSergey Zigachev enum dc_status dce100_validate_global(
766b843c749SSergey Zigachev struct dc *dc,
767b843c749SSergey Zigachev struct dc_state *context)
768b843c749SSergey Zigachev {
769b843c749SSergey Zigachev if (!dce100_validate_surface_sets(context))
770b843c749SSergey Zigachev return DC_FAIL_SURFACE_VALIDATE;
771b843c749SSergey Zigachev
772b843c749SSergey Zigachev return DC_OK;
773b843c749SSergey Zigachev }
774b843c749SSergey Zigachev
dce100_add_stream_to_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)775b843c749SSergey Zigachev enum dc_status dce100_add_stream_to_ctx(
776b843c749SSergey Zigachev struct dc *dc,
777b843c749SSergey Zigachev struct dc_state *new_ctx,
778b843c749SSergey Zigachev struct dc_stream_state *dc_stream)
779b843c749SSergey Zigachev {
780b843c749SSergey Zigachev enum dc_status result = DC_ERROR_UNEXPECTED;
781b843c749SSergey Zigachev
782b843c749SSergey Zigachev result = resource_map_pool_resources(dc, new_ctx, dc_stream);
783b843c749SSergey Zigachev
784b843c749SSergey Zigachev if (result == DC_OK)
785b843c749SSergey Zigachev result = resource_map_clock_resources(dc, new_ctx, dc_stream);
786b843c749SSergey Zigachev
787b843c749SSergey Zigachev if (result == DC_OK)
788b843c749SSergey Zigachev result = build_mapped_resource(dc, new_ctx, dc_stream);
789b843c749SSergey Zigachev
790b843c749SSergey Zigachev return result;
791b843c749SSergey Zigachev }
792b843c749SSergey Zigachev
dce100_destroy_resource_pool(struct resource_pool ** pool)793b843c749SSergey Zigachev static void dce100_destroy_resource_pool(struct resource_pool **pool)
794b843c749SSergey Zigachev {
795b843c749SSergey Zigachev struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
796b843c749SSergey Zigachev
797b843c749SSergey Zigachev destruct(dce110_pool);
798b843c749SSergey Zigachev kfree(dce110_pool);
799b843c749SSergey Zigachev *pool = NULL;
800b843c749SSergey Zigachev }
801b843c749SSergey Zigachev
dce100_validate_plane(const struct dc_plane_state * plane_state,struct dc_caps * caps)802b843c749SSergey Zigachev enum dc_status dce100_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
803b843c749SSergey Zigachev {
804b843c749SSergey Zigachev
805b843c749SSergey Zigachev if (plane_state->format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
806b843c749SSergey Zigachev return DC_OK;
807b843c749SSergey Zigachev
808b843c749SSergey Zigachev return DC_FAIL_SURFACE_VALIDATE;
809b843c749SSergey Zigachev }
810b843c749SSergey Zigachev
811b843c749SSergey Zigachev static const struct resource_funcs dce100_res_pool_funcs = {
812b843c749SSergey Zigachev .destroy = dce100_destroy_resource_pool,
813b843c749SSergey Zigachev .link_enc_create = dce100_link_encoder_create,
814b843c749SSergey Zigachev .validate_bandwidth = dce100_validate_bandwidth,
815b843c749SSergey Zigachev .validate_plane = dce100_validate_plane,
816b843c749SSergey Zigachev .add_stream_to_ctx = dce100_add_stream_to_ctx,
817b843c749SSergey Zigachev .validate_global = dce100_validate_global
818b843c749SSergey Zigachev };
819b843c749SSergey Zigachev
construct(uint8_t num_virtual_links,struct dc * dc,struct dce110_resource_pool * pool)820b843c749SSergey Zigachev static bool construct(
821b843c749SSergey Zigachev uint8_t num_virtual_links,
822b843c749SSergey Zigachev struct dc *dc,
823b843c749SSergey Zigachev struct dce110_resource_pool *pool)
824b843c749SSergey Zigachev {
825b843c749SSergey Zigachev unsigned int i;
826b843c749SSergey Zigachev struct dc_context *ctx = dc->ctx;
827b843c749SSergey Zigachev struct dc_firmware_info info;
828b843c749SSergey Zigachev struct dc_bios *bp;
829b843c749SSergey Zigachev struct dm_pp_static_clock_info static_clk_info = {0};
830b843c749SSergey Zigachev
831b843c749SSergey Zigachev ctx->dc_bios->regs = &bios_regs;
832b843c749SSergey Zigachev
833b843c749SSergey Zigachev pool->base.res_cap = &res_cap;
834b843c749SSergey Zigachev pool->base.funcs = &dce100_res_pool_funcs;
835b843c749SSergey Zigachev pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
836b843c749SSergey Zigachev
837b843c749SSergey Zigachev bp = ctx->dc_bios;
838b843c749SSergey Zigachev
839b843c749SSergey Zigachev if ((bp->funcs->get_firmware_info(bp, &info) == BP_RESULT_OK) &&
840b843c749SSergey Zigachev info.external_clock_source_frequency_for_dp != 0) {
841b843c749SSergey Zigachev pool->base.dp_clock_source =
842b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_EXTERNAL, NULL, true);
843b843c749SSergey Zigachev
844b843c749SSergey Zigachev pool->base.clock_sources[0] =
845b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], false);
846b843c749SSergey Zigachev pool->base.clock_sources[1] =
847b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
848b843c749SSergey Zigachev pool->base.clock_sources[2] =
849b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
850b843c749SSergey Zigachev pool->base.clk_src_count = 3;
851b843c749SSergey Zigachev
852b843c749SSergey Zigachev } else {
853b843c749SSergey Zigachev pool->base.dp_clock_source =
854b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL0, &clk_src_regs[0], true);
855b843c749SSergey Zigachev
856b843c749SSergey Zigachev pool->base.clock_sources[0] =
857b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL1, &clk_src_regs[1], false);
858b843c749SSergey Zigachev pool->base.clock_sources[1] =
859b843c749SSergey Zigachev dce100_clock_source_create(ctx, bp, CLOCK_SOURCE_ID_PLL2, &clk_src_regs[2], false);
860b843c749SSergey Zigachev pool->base.clk_src_count = 2;
861b843c749SSergey Zigachev }
862b843c749SSergey Zigachev
863b843c749SSergey Zigachev if (pool->base.dp_clock_source == NULL) {
864b843c749SSergey Zigachev dm_error("DC: failed to create dp clock source!\n");
865b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
866b843c749SSergey Zigachev goto res_create_fail;
867b843c749SSergey Zigachev }
868b843c749SSergey Zigachev
869b843c749SSergey Zigachev for (i = 0; i < pool->base.clk_src_count; i++) {
870b843c749SSergey Zigachev if (pool->base.clock_sources[i] == NULL) {
871b843c749SSergey Zigachev dm_error("DC: failed to create clock sources!\n");
872b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
873b843c749SSergey Zigachev goto res_create_fail;
874b843c749SSergey Zigachev }
875b843c749SSergey Zigachev }
876b843c749SSergey Zigachev
877b843c749SSergey Zigachev pool->base.dccg = dce_dccg_create(ctx,
878b843c749SSergey Zigachev &disp_clk_regs,
879b843c749SSergey Zigachev &disp_clk_shift,
880b843c749SSergey Zigachev &disp_clk_mask);
881b843c749SSergey Zigachev if (pool->base.dccg == NULL) {
882b843c749SSergey Zigachev dm_error("DC: failed to create display clock!\n");
883b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
884b843c749SSergey Zigachev goto res_create_fail;
885b843c749SSergey Zigachev }
886b843c749SSergey Zigachev
887b843c749SSergey Zigachev pool->base.dmcu = dce_dmcu_create(ctx,
888b843c749SSergey Zigachev &dmcu_regs,
889b843c749SSergey Zigachev &dmcu_shift,
890b843c749SSergey Zigachev &dmcu_mask);
891b843c749SSergey Zigachev if (pool->base.dmcu == NULL) {
892b843c749SSergey Zigachev dm_error("DC: failed to create dmcu!\n");
893b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
894b843c749SSergey Zigachev goto res_create_fail;
895b843c749SSergey Zigachev }
896b843c749SSergey Zigachev
897b843c749SSergey Zigachev pool->base.abm = dce_abm_create(ctx,
898b843c749SSergey Zigachev &abm_regs,
899b843c749SSergey Zigachev &abm_shift,
900b843c749SSergey Zigachev &abm_mask);
901b843c749SSergey Zigachev if (pool->base.abm == NULL) {
902b843c749SSergey Zigachev dm_error("DC: failed to create abm!\n");
903b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
904b843c749SSergey Zigachev goto res_create_fail;
905b843c749SSergey Zigachev }
906b843c749SSergey Zigachev
907b843c749SSergey Zigachev /* get static clock information for PPLIB or firmware, save
908b843c749SSergey Zigachev * max_clock_state
909b843c749SSergey Zigachev */
910b843c749SSergey Zigachev if (dm_pp_get_static_clocks(ctx, &static_clk_info))
911b843c749SSergey Zigachev pool->base.dccg->max_clks_state =
912b843c749SSergey Zigachev static_clk_info.max_clocks_state;
913b843c749SSergey Zigachev {
914b843c749SSergey Zigachev struct irq_service_init_data init_data;
915b843c749SSergey Zigachev init_data.ctx = dc->ctx;
916b843c749SSergey Zigachev pool->base.irqs = dal_irq_service_dce110_create(&init_data);
917b843c749SSergey Zigachev if (!pool->base.irqs)
918b843c749SSergey Zigachev goto res_create_fail;
919b843c749SSergey Zigachev }
920b843c749SSergey Zigachev
921b843c749SSergey Zigachev /*************************************************
922b843c749SSergey Zigachev * Resource + asic cap harcoding *
923b843c749SSergey Zigachev *************************************************/
924b843c749SSergey Zigachev pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
925b843c749SSergey Zigachev pool->base.pipe_count = res_cap.num_timing_generator;
926b843c749SSergey Zigachev pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
927b843c749SSergey Zigachev dc->caps.max_downscale_ratio = 200;
928b843c749SSergey Zigachev dc->caps.i2c_speed_in_khz = 40;
929b843c749SSergey Zigachev dc->caps.max_cursor_size = 128;
930b843c749SSergey Zigachev dc->caps.dual_link_dvi = true;
931b843c749SSergey Zigachev dc->caps.disable_dp_clk_share = true;
932b843c749SSergey Zigachev for (i = 0; i < pool->base.pipe_count; i++) {
933b843c749SSergey Zigachev pool->base.timing_generators[i] =
934b843c749SSergey Zigachev dce100_timing_generator_create(
935b843c749SSergey Zigachev ctx,
936b843c749SSergey Zigachev i,
937b843c749SSergey Zigachev &dce100_tg_offsets[i]);
938b843c749SSergey Zigachev if (pool->base.timing_generators[i] == NULL) {
939b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
940b843c749SSergey Zigachev dm_error("DC: failed to create tg!\n");
941b843c749SSergey Zigachev goto res_create_fail;
942b843c749SSergey Zigachev }
943b843c749SSergey Zigachev
944b843c749SSergey Zigachev pool->base.mis[i] = dce100_mem_input_create(ctx, i);
945b843c749SSergey Zigachev if (pool->base.mis[i] == NULL) {
946b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
947b843c749SSergey Zigachev dm_error(
948b843c749SSergey Zigachev "DC: failed to create memory input!\n");
949b843c749SSergey Zigachev goto res_create_fail;
950b843c749SSergey Zigachev }
951b843c749SSergey Zigachev
952b843c749SSergey Zigachev pool->base.ipps[i] = dce100_ipp_create(ctx, i);
953b843c749SSergey Zigachev if (pool->base.ipps[i] == NULL) {
954b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
955b843c749SSergey Zigachev dm_error(
956b843c749SSergey Zigachev "DC: failed to create input pixel processor!\n");
957b843c749SSergey Zigachev goto res_create_fail;
958b843c749SSergey Zigachev }
959b843c749SSergey Zigachev
960b843c749SSergey Zigachev pool->base.transforms[i] = dce100_transform_create(ctx, i);
961b843c749SSergey Zigachev if (pool->base.transforms[i] == NULL) {
962b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
963b843c749SSergey Zigachev dm_error(
964b843c749SSergey Zigachev "DC: failed to create transform!\n");
965b843c749SSergey Zigachev goto res_create_fail;
966b843c749SSergey Zigachev }
967b843c749SSergey Zigachev
968b843c749SSergey Zigachev pool->base.opps[i] = dce100_opp_create(ctx, i);
969b843c749SSergey Zigachev if (pool->base.opps[i] == NULL) {
970b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
971b843c749SSergey Zigachev dm_error(
972b843c749SSergey Zigachev "DC: failed to create output pixel processor!\n");
973b843c749SSergey Zigachev goto res_create_fail;
974b843c749SSergey Zigachev }
975b843c749SSergey Zigachev pool->base.engines[i] = dce100_aux_engine_create(ctx, i);
976b843c749SSergey Zigachev if (pool->base.engines[i] == NULL) {
977b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
978b843c749SSergey Zigachev dm_error(
979b843c749SSergey Zigachev "DC:failed to create aux engine!!\n");
980b843c749SSergey Zigachev goto res_create_fail;
981b843c749SSergey Zigachev }
982b843c749SSergey Zigachev }
983b843c749SSergey Zigachev
984b843c749SSergey Zigachev dc->caps.max_planes = pool->base.pipe_count;
985b843c749SSergey Zigachev
986b843c749SSergey Zigachev if (!resource_construct(num_virtual_links, dc, &pool->base,
987b843c749SSergey Zigachev &res_create_funcs))
988b843c749SSergey Zigachev goto res_create_fail;
989b843c749SSergey Zigachev
990b843c749SSergey Zigachev /* Create hardware sequencer */
991b843c749SSergey Zigachev dce100_hw_sequencer_construct(dc);
992b843c749SSergey Zigachev return true;
993b843c749SSergey Zigachev
994b843c749SSergey Zigachev res_create_fail:
995b843c749SSergey Zigachev destruct(pool);
996b843c749SSergey Zigachev
997b843c749SSergey Zigachev return false;
998b843c749SSergey Zigachev }
999b843c749SSergey Zigachev
dce100_create_resource_pool(uint8_t num_virtual_links,struct dc * dc)1000b843c749SSergey Zigachev struct resource_pool *dce100_create_resource_pool(
1001b843c749SSergey Zigachev uint8_t num_virtual_links,
1002b843c749SSergey Zigachev struct dc *dc)
1003b843c749SSergey Zigachev {
1004b843c749SSergey Zigachev struct dce110_resource_pool *pool =
1005b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1006b843c749SSergey Zigachev
1007b843c749SSergey Zigachev if (!pool)
1008b843c749SSergey Zigachev return NULL;
1009b843c749SSergey Zigachev
1010b843c749SSergey Zigachev if (construct(num_virtual_links, dc, pool))
1011b843c749SSergey Zigachev return &pool->base;
1012b843c749SSergey Zigachev
1013b843c749SSergey Zigachev kfree(pool);
1014b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1015b843c749SSergey Zigachev return NULL;
1016b843c749SSergey Zigachev }
1017b843c749SSergey Zigachev
1018