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 "dm_services.h"
27b843c749SSergey Zigachev
28b843c749SSergey Zigachev #include "link_encoder.h"
29b843c749SSergey Zigachev #include "stream_encoder.h"
30b843c749SSergey Zigachev
31b843c749SSergey Zigachev #include "resource.h"
32b843c749SSergey Zigachev #include "include/irq_service_interface.h"
33b843c749SSergey Zigachev #include "dce110/dce110_resource.h"
34b843c749SSergey Zigachev #include "dce110/dce110_timing_generator.h"
35b843c749SSergey Zigachev
36b843c749SSergey Zigachev #include "irq/dce110/irq_service_dce110.h"
37b843c749SSergey Zigachev
38b843c749SSergey Zigachev #include "dce/dce_mem_input.h"
39b843c749SSergey Zigachev #include "dce/dce_transform.h"
40b843c749SSergey Zigachev #include "dce/dce_link_encoder.h"
41b843c749SSergey Zigachev #include "dce/dce_stream_encoder.h"
42b843c749SSergey Zigachev #include "dce/dce_audio.h"
43b843c749SSergey Zigachev #include "dce/dce_opp.h"
44b843c749SSergey Zigachev #include "dce/dce_ipp.h"
45b843c749SSergey Zigachev #include "dce/dce_clocks.h"
46b843c749SSergey Zigachev #include "dce/dce_clock_source.h"
47b843c749SSergey Zigachev
48b843c749SSergey Zigachev #include "dce/dce_hwseq.h"
49b843c749SSergey Zigachev #include "dce112/dce112_hw_sequencer.h"
50b843c749SSergey Zigachev #include "dce/dce_abm.h"
51b843c749SSergey Zigachev #include "dce/dce_dmcu.h"
52b843c749SSergey Zigachev #include "dce/dce_aux.h"
53b843c749SSergey Zigachev
54b843c749SSergey Zigachev #include "reg_helper.h"
55b843c749SSergey Zigachev
56b843c749SSergey Zigachev #include "dce/dce_11_2_d.h"
57b843c749SSergey Zigachev #include "dce/dce_11_2_sh_mask.h"
58b843c749SSergey Zigachev
59b843c749SSergey Zigachev #include "dce100/dce100_resource.h"
60*78973132SSergey Zigachev
61*78973132SSergey Zigachev #include "dce112_resource.h"
62*78973132SSergey Zigachev
63b843c749SSergey Zigachev #define DC_LOGGER \
64b843c749SSergey Zigachev dc->ctx->logger
65b843c749SSergey Zigachev
66b843c749SSergey Zigachev #ifndef mmDP_DPHY_INTERNAL_CTRL
67b843c749SSergey Zigachev #define mmDP_DPHY_INTERNAL_CTRL 0x4aa7
68b843c749SSergey Zigachev #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x4aa7
69b843c749SSergey Zigachev #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x4ba7
70b843c749SSergey Zigachev #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x4ca7
71b843c749SSergey Zigachev #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x4da7
72b843c749SSergey Zigachev #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x4ea7
73b843c749SSergey Zigachev #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x4fa7
74b843c749SSergey Zigachev #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x54a7
75b843c749SSergey Zigachev #define mmDP7_DP_DPHY_INTERNAL_CTRL 0x56a7
76b843c749SSergey Zigachev #define mmDP8_DP_DPHY_INTERNAL_CTRL 0x57a7
77b843c749SSergey Zigachev #endif
78b843c749SSergey Zigachev
79b843c749SSergey Zigachev #ifndef mmBIOS_SCRATCH_2
80b843c749SSergey Zigachev #define mmBIOS_SCRATCH_2 0x05CB
81b843c749SSergey Zigachev #define mmBIOS_SCRATCH_6 0x05CF
82b843c749SSergey Zigachev #endif
83b843c749SSergey Zigachev
84b843c749SSergey Zigachev #ifndef mmDP_DPHY_BS_SR_SWAP_CNTL
85b843c749SSergey Zigachev #define mmDP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
86b843c749SSergey Zigachev #define mmDP0_DP_DPHY_BS_SR_SWAP_CNTL 0x4ADC
87b843c749SSergey Zigachev #define mmDP1_DP_DPHY_BS_SR_SWAP_CNTL 0x4BDC
88b843c749SSergey Zigachev #define mmDP2_DP_DPHY_BS_SR_SWAP_CNTL 0x4CDC
89b843c749SSergey Zigachev #define mmDP3_DP_DPHY_BS_SR_SWAP_CNTL 0x4DDC
90b843c749SSergey Zigachev #define mmDP4_DP_DPHY_BS_SR_SWAP_CNTL 0x4EDC
91b843c749SSergey Zigachev #define mmDP5_DP_DPHY_BS_SR_SWAP_CNTL 0x4FDC
92b843c749SSergey Zigachev #define mmDP6_DP_DPHY_BS_SR_SWAP_CNTL 0x54DC
93b843c749SSergey Zigachev #endif
94b843c749SSergey Zigachev
95b843c749SSergey Zigachev #ifndef mmDP_DPHY_FAST_TRAINING
96b843c749SSergey Zigachev #define mmDP_DPHY_FAST_TRAINING 0x4ABC
97b843c749SSergey Zigachev #define mmDP0_DP_DPHY_FAST_TRAINING 0x4ABC
98b843c749SSergey Zigachev #define mmDP1_DP_DPHY_FAST_TRAINING 0x4BBC
99b843c749SSergey Zigachev #define mmDP2_DP_DPHY_FAST_TRAINING 0x4CBC
100b843c749SSergey Zigachev #define mmDP3_DP_DPHY_FAST_TRAINING 0x4DBC
101b843c749SSergey Zigachev #define mmDP4_DP_DPHY_FAST_TRAINING 0x4EBC
102b843c749SSergey Zigachev #define mmDP5_DP_DPHY_FAST_TRAINING 0x4FBC
103b843c749SSergey Zigachev #define mmDP6_DP_DPHY_FAST_TRAINING 0x54BC
104b843c749SSergey Zigachev #endif
105b843c749SSergey Zigachev
106b843c749SSergey Zigachev enum dce112_clk_src_array_id {
107b843c749SSergey Zigachev DCE112_CLK_SRC_PLL0,
108b843c749SSergey Zigachev DCE112_CLK_SRC_PLL1,
109b843c749SSergey Zigachev DCE112_CLK_SRC_PLL2,
110b843c749SSergey Zigachev DCE112_CLK_SRC_PLL3,
111b843c749SSergey Zigachev DCE112_CLK_SRC_PLL4,
112b843c749SSergey Zigachev DCE112_CLK_SRC_PLL5,
113b843c749SSergey Zigachev
114b843c749SSergey Zigachev DCE112_CLK_SRC_TOTAL
115b843c749SSergey Zigachev };
116b843c749SSergey Zigachev
117b843c749SSergey Zigachev static const struct dce110_timing_generator_offsets dce112_tg_offsets[] = {
118b843c749SSergey Zigachev {
119b843c749SSergey Zigachev .crtc = (mmCRTC0_CRTC_CONTROL - mmCRTC_CONTROL),
120b843c749SSergey Zigachev .dcp = (mmDCP0_GRPH_CONTROL - mmGRPH_CONTROL),
121b843c749SSergey Zigachev },
122b843c749SSergey Zigachev {
123b843c749SSergey Zigachev .crtc = (mmCRTC1_CRTC_CONTROL - mmCRTC_CONTROL),
124b843c749SSergey Zigachev .dcp = (mmDCP1_GRPH_CONTROL - mmGRPH_CONTROL),
125b843c749SSergey Zigachev },
126b843c749SSergey Zigachev {
127b843c749SSergey Zigachev .crtc = (mmCRTC2_CRTC_CONTROL - mmCRTC_CONTROL),
128b843c749SSergey Zigachev .dcp = (mmDCP2_GRPH_CONTROL - mmGRPH_CONTROL),
129b843c749SSergey Zigachev },
130b843c749SSergey Zigachev {
131b843c749SSergey Zigachev .crtc = (mmCRTC3_CRTC_CONTROL - mmCRTC_CONTROL),
132b843c749SSergey Zigachev .dcp = (mmDCP3_GRPH_CONTROL - mmGRPH_CONTROL),
133b843c749SSergey Zigachev },
134b843c749SSergey Zigachev {
135b843c749SSergey Zigachev .crtc = (mmCRTC4_CRTC_CONTROL - mmCRTC_CONTROL),
136b843c749SSergey Zigachev .dcp = (mmDCP4_GRPH_CONTROL - mmGRPH_CONTROL),
137b843c749SSergey Zigachev },
138b843c749SSergey Zigachev {
139b843c749SSergey Zigachev .crtc = (mmCRTC5_CRTC_CONTROL - mmCRTC_CONTROL),
140b843c749SSergey Zigachev .dcp = (mmDCP5_GRPH_CONTROL - mmGRPH_CONTROL),
141b843c749SSergey Zigachev }
142b843c749SSergey Zigachev };
143b843c749SSergey Zigachev
144b843c749SSergey Zigachev /* set register offset */
145b843c749SSergey Zigachev #define SR(reg_name)\
146b843c749SSergey Zigachev .reg_name = mm ## reg_name
147b843c749SSergey Zigachev
148b843c749SSergey Zigachev /* set register offset with instance */
149b843c749SSergey Zigachev #define SRI(reg_name, block, id)\
150b843c749SSergey Zigachev .reg_name = mm ## block ## id ## _ ## reg_name
151b843c749SSergey Zigachev
152b843c749SSergey Zigachev
153b843c749SSergey Zigachev static const struct dccg_registers disp_clk_regs = {
154b843c749SSergey Zigachev CLK_COMMON_REG_LIST_DCE_BASE()
155b843c749SSergey Zigachev };
156b843c749SSergey Zigachev
157b843c749SSergey Zigachev static const struct dccg_shift disp_clk_shift = {
158b843c749SSergey Zigachev CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
159b843c749SSergey Zigachev };
160b843c749SSergey Zigachev
161b843c749SSergey Zigachev static const struct dccg_mask disp_clk_mask = {
162b843c749SSergey Zigachev CLK_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
163b843c749SSergey Zigachev };
164b843c749SSergey Zigachev
165b843c749SSergey Zigachev static const struct dce_dmcu_registers dmcu_regs = {
166b843c749SSergey Zigachev DMCU_DCE110_COMMON_REG_LIST()
167b843c749SSergey Zigachev };
168b843c749SSergey Zigachev
169b843c749SSergey Zigachev static const struct dce_dmcu_shift dmcu_shift = {
170b843c749SSergey Zigachev DMCU_MASK_SH_LIST_DCE110(__SHIFT)
171b843c749SSergey Zigachev };
172b843c749SSergey Zigachev
173b843c749SSergey Zigachev static const struct dce_dmcu_mask dmcu_mask = {
174b843c749SSergey Zigachev DMCU_MASK_SH_LIST_DCE110(_MASK)
175b843c749SSergey Zigachev };
176b843c749SSergey Zigachev
177b843c749SSergey Zigachev static const struct dce_abm_registers abm_regs = {
178b843c749SSergey Zigachev ABM_DCE110_COMMON_REG_LIST()
179b843c749SSergey Zigachev };
180b843c749SSergey Zigachev
181b843c749SSergey Zigachev static const struct dce_abm_shift abm_shift = {
182b843c749SSergey Zigachev ABM_MASK_SH_LIST_DCE110(__SHIFT)
183b843c749SSergey Zigachev };
184b843c749SSergey Zigachev
185b843c749SSergey Zigachev static const struct dce_abm_mask abm_mask = {
186b843c749SSergey Zigachev ABM_MASK_SH_LIST_DCE110(_MASK)
187b843c749SSergey Zigachev };
188b843c749SSergey Zigachev
189b843c749SSergey Zigachev #define ipp_regs(id)\
190b843c749SSergey Zigachev [id] = {\
191b843c749SSergey Zigachev IPP_DCE110_REG_LIST_DCE_BASE(id)\
192b843c749SSergey Zigachev }
193b843c749SSergey Zigachev
194b843c749SSergey Zigachev static const struct dce_ipp_registers ipp_regs[] = {
195b843c749SSergey Zigachev ipp_regs(0),
196b843c749SSergey Zigachev ipp_regs(1),
197b843c749SSergey Zigachev ipp_regs(2),
198b843c749SSergey Zigachev ipp_regs(3),
199b843c749SSergey Zigachev ipp_regs(4),
200b843c749SSergey Zigachev ipp_regs(5)
201b843c749SSergey Zigachev };
202b843c749SSergey Zigachev
203b843c749SSergey Zigachev static const struct dce_ipp_shift ipp_shift = {
204b843c749SSergey Zigachev IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(__SHIFT)
205b843c749SSergey Zigachev };
206b843c749SSergey Zigachev
207b843c749SSergey Zigachev static const struct dce_ipp_mask ipp_mask = {
208b843c749SSergey Zigachev IPP_DCE100_MASK_SH_LIST_DCE_COMMON_BASE(_MASK)
209b843c749SSergey Zigachev };
210b843c749SSergey Zigachev
211b843c749SSergey Zigachev #define transform_regs(id)\
212b843c749SSergey Zigachev [id] = {\
213b843c749SSergey Zigachev XFM_COMMON_REG_LIST_DCE110(id)\
214b843c749SSergey Zigachev }
215b843c749SSergey Zigachev
216b843c749SSergey Zigachev static const struct dce_transform_registers xfm_regs[] = {
217b843c749SSergey Zigachev transform_regs(0),
218b843c749SSergey Zigachev transform_regs(1),
219b843c749SSergey Zigachev transform_regs(2),
220b843c749SSergey Zigachev transform_regs(3),
221b843c749SSergey Zigachev transform_regs(4),
222b843c749SSergey Zigachev transform_regs(5)
223b843c749SSergey Zigachev };
224b843c749SSergey Zigachev
225b843c749SSergey Zigachev static const struct dce_transform_shift xfm_shift = {
226b843c749SSergey Zigachev XFM_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
227b843c749SSergey Zigachev };
228b843c749SSergey Zigachev
229b843c749SSergey Zigachev static const struct dce_transform_mask xfm_mask = {
230b843c749SSergey Zigachev XFM_COMMON_MASK_SH_LIST_DCE110(_MASK)
231b843c749SSergey Zigachev };
232b843c749SSergey Zigachev
233b843c749SSergey Zigachev #define aux_regs(id)\
234b843c749SSergey Zigachev [id] = {\
235b843c749SSergey Zigachev AUX_REG_LIST(id)\
236b843c749SSergey Zigachev }
237b843c749SSergey Zigachev
238b843c749SSergey Zigachev static const struct dce110_link_enc_aux_registers link_enc_aux_regs[] = {
239b843c749SSergey Zigachev aux_regs(0),
240b843c749SSergey Zigachev aux_regs(1),
241b843c749SSergey Zigachev aux_regs(2),
242b843c749SSergey Zigachev aux_regs(3),
243b843c749SSergey Zigachev aux_regs(4),
244b843c749SSergey Zigachev aux_regs(5)
245b843c749SSergey Zigachev };
246b843c749SSergey Zigachev
247b843c749SSergey Zigachev #define hpd_regs(id)\
248b843c749SSergey Zigachev [id] = {\
249b843c749SSergey Zigachev HPD_REG_LIST(id)\
250b843c749SSergey Zigachev }
251b843c749SSergey Zigachev
252b843c749SSergey Zigachev static const struct dce110_link_enc_hpd_registers link_enc_hpd_regs[] = {
253b843c749SSergey Zigachev hpd_regs(0),
254b843c749SSergey Zigachev hpd_regs(1),
255b843c749SSergey Zigachev hpd_regs(2),
256b843c749SSergey Zigachev hpd_regs(3),
257b843c749SSergey Zigachev hpd_regs(4),
258b843c749SSergey Zigachev hpd_regs(5)
259b843c749SSergey Zigachev };
260b843c749SSergey Zigachev
261b843c749SSergey Zigachev #define link_regs(id)\
262b843c749SSergey Zigachev [id] = {\
263b843c749SSergey Zigachev LE_DCE110_REG_LIST(id)\
264b843c749SSergey Zigachev }
265b843c749SSergey Zigachev
266b843c749SSergey Zigachev static const struct dce110_link_enc_registers link_enc_regs[] = {
267b843c749SSergey Zigachev link_regs(0),
268b843c749SSergey Zigachev link_regs(1),
269b843c749SSergey Zigachev link_regs(2),
270b843c749SSergey Zigachev link_regs(3),
271b843c749SSergey Zigachev link_regs(4),
272b843c749SSergey Zigachev link_regs(5),
273b843c749SSergey Zigachev link_regs(6),
274b843c749SSergey Zigachev };
275b843c749SSergey Zigachev
276b843c749SSergey Zigachev #define stream_enc_regs(id)\
277b843c749SSergey Zigachev [id] = {\
278b843c749SSergey Zigachev SE_COMMON_REG_LIST(id),\
279b843c749SSergey Zigachev .TMDS_CNTL = 0,\
280b843c749SSergey Zigachev }
281b843c749SSergey Zigachev
282b843c749SSergey Zigachev static const struct dce110_stream_enc_registers stream_enc_regs[] = {
283b843c749SSergey Zigachev stream_enc_regs(0),
284b843c749SSergey Zigachev stream_enc_regs(1),
285b843c749SSergey Zigachev stream_enc_regs(2),
286b843c749SSergey Zigachev stream_enc_regs(3),
287b843c749SSergey Zigachev stream_enc_regs(4),
288b843c749SSergey Zigachev stream_enc_regs(5)
289b843c749SSergey Zigachev };
290b843c749SSergey Zigachev
291b843c749SSergey Zigachev static const struct dce_stream_encoder_shift se_shift = {
292b843c749SSergey Zigachev SE_COMMON_MASK_SH_LIST_DCE112(__SHIFT)
293b843c749SSergey Zigachev };
294b843c749SSergey Zigachev
295b843c749SSergey Zigachev static const struct dce_stream_encoder_mask se_mask = {
296b843c749SSergey Zigachev SE_COMMON_MASK_SH_LIST_DCE112(_MASK)
297b843c749SSergey Zigachev };
298b843c749SSergey Zigachev
299b843c749SSergey Zigachev #define opp_regs(id)\
300b843c749SSergey Zigachev [id] = {\
301b843c749SSergey Zigachev OPP_DCE_112_REG_LIST(id),\
302b843c749SSergey Zigachev }
303b843c749SSergey Zigachev
304b843c749SSergey Zigachev static const struct dce_opp_registers opp_regs[] = {
305b843c749SSergey Zigachev opp_regs(0),
306b843c749SSergey Zigachev opp_regs(1),
307b843c749SSergey Zigachev opp_regs(2),
308b843c749SSergey Zigachev opp_regs(3),
309b843c749SSergey Zigachev opp_regs(4),
310b843c749SSergey Zigachev opp_regs(5)
311b843c749SSergey Zigachev };
312b843c749SSergey Zigachev
313b843c749SSergey Zigachev static const struct dce_opp_shift opp_shift = {
314b843c749SSergey Zigachev OPP_COMMON_MASK_SH_LIST_DCE_112(__SHIFT)
315b843c749SSergey Zigachev };
316b843c749SSergey Zigachev
317b843c749SSergey Zigachev static const struct dce_opp_mask opp_mask = {
318b843c749SSergey Zigachev OPP_COMMON_MASK_SH_LIST_DCE_112(_MASK)
319b843c749SSergey Zigachev };
320b843c749SSergey Zigachev
321b843c749SSergey Zigachev #define aux_engine_regs(id)\
322b843c749SSergey Zigachev [id] = {\
323b843c749SSergey Zigachev AUX_COMMON_REG_LIST(id), \
324b843c749SSergey Zigachev .AUX_RESET_MASK = 0 \
325b843c749SSergey Zigachev }
326b843c749SSergey Zigachev
327b843c749SSergey Zigachev static const struct dce110_aux_registers aux_engine_regs[] = {
328b843c749SSergey Zigachev aux_engine_regs(0),
329b843c749SSergey Zigachev aux_engine_regs(1),
330b843c749SSergey Zigachev aux_engine_regs(2),
331b843c749SSergey Zigachev aux_engine_regs(3),
332b843c749SSergey Zigachev aux_engine_regs(4),
333b843c749SSergey Zigachev aux_engine_regs(5)
334b843c749SSergey Zigachev };
335b843c749SSergey Zigachev
336b843c749SSergey Zigachev #define audio_regs(id)\
337b843c749SSergey Zigachev [id] = {\
338b843c749SSergey Zigachev AUD_COMMON_REG_LIST(id)\
339b843c749SSergey Zigachev }
340b843c749SSergey Zigachev
341b843c749SSergey Zigachev static const struct dce_audio_registers audio_regs[] = {
342b843c749SSergey Zigachev audio_regs(0),
343b843c749SSergey Zigachev audio_regs(1),
344b843c749SSergey Zigachev audio_regs(2),
345b843c749SSergey Zigachev audio_regs(3),
346b843c749SSergey Zigachev audio_regs(4),
347b843c749SSergey Zigachev audio_regs(5)
348b843c749SSergey Zigachev };
349b843c749SSergey Zigachev
350b843c749SSergey Zigachev static const struct dce_audio_shift audio_shift = {
351b843c749SSergey Zigachev AUD_COMMON_MASK_SH_LIST(__SHIFT)
352b843c749SSergey Zigachev };
353b843c749SSergey Zigachev
354b843c749SSergey Zigachev static const struct dce_aduio_mask audio_mask = {
355b843c749SSergey Zigachev AUD_COMMON_MASK_SH_LIST(_MASK)
356b843c749SSergey Zigachev };
357b843c749SSergey Zigachev
358b843c749SSergey Zigachev #define clk_src_regs(index, id)\
359b843c749SSergey Zigachev [index] = {\
360b843c749SSergey Zigachev CS_COMMON_REG_LIST_DCE_112(id),\
361b843c749SSergey Zigachev }
362b843c749SSergey Zigachev
363b843c749SSergey Zigachev static const struct dce110_clk_src_regs clk_src_regs[] = {
364b843c749SSergey Zigachev clk_src_regs(0, A),
365b843c749SSergey Zigachev clk_src_regs(1, B),
366b843c749SSergey Zigachev clk_src_regs(2, C),
367b843c749SSergey Zigachev clk_src_regs(3, D),
368b843c749SSergey Zigachev clk_src_regs(4, E),
369b843c749SSergey Zigachev clk_src_regs(5, F)
370b843c749SSergey Zigachev };
371b843c749SSergey Zigachev
372b843c749SSergey Zigachev static const struct dce110_clk_src_shift cs_shift = {
373b843c749SSergey Zigachev CS_COMMON_MASK_SH_LIST_DCE_112(__SHIFT)
374b843c749SSergey Zigachev };
375b843c749SSergey Zigachev
376b843c749SSergey Zigachev static const struct dce110_clk_src_mask cs_mask = {
377b843c749SSergey Zigachev CS_COMMON_MASK_SH_LIST_DCE_112(_MASK)
378b843c749SSergey Zigachev };
379b843c749SSergey Zigachev
380b843c749SSergey Zigachev static const struct bios_registers bios_regs = {
381b843c749SSergey Zigachev .BIOS_SCRATCH_6 = mmBIOS_SCRATCH_6
382b843c749SSergey Zigachev };
383b843c749SSergey Zigachev
384b843c749SSergey Zigachev static const struct resource_caps polaris_10_resource_cap = {
385b843c749SSergey Zigachev .num_timing_generator = 6,
386b843c749SSergey Zigachev .num_audio = 6,
387b843c749SSergey Zigachev .num_stream_encoder = 6,
388b843c749SSergey Zigachev .num_pll = 8, /* why 8? 6 combo PHY PLL + 2 regular PLLs? */
389b843c749SSergey Zigachev };
390b843c749SSergey Zigachev
391b843c749SSergey Zigachev static const struct resource_caps polaris_11_resource_cap = {
392b843c749SSergey Zigachev .num_timing_generator = 5,
393b843c749SSergey Zigachev .num_audio = 5,
394b843c749SSergey Zigachev .num_stream_encoder = 5,
395b843c749SSergey Zigachev .num_pll = 8, /* why 8? 6 combo PHY PLL + 2 regular PLLs? */
396b843c749SSergey Zigachev };
397b843c749SSergey Zigachev
398b843c749SSergey Zigachev #define CTX ctx
399b843c749SSergey Zigachev #define REG(reg) mm ## reg
400b843c749SSergey Zigachev
401b843c749SSergey Zigachev #ifndef mmCC_DC_HDMI_STRAPS
402b843c749SSergey Zigachev #define mmCC_DC_HDMI_STRAPS 0x4819
403b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__HDMI_DISABLE_MASK 0x40
404b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__HDMI_DISABLE__SHIFT 0x6
405b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER_MASK 0x700
406b843c749SSergey Zigachev #define CC_DC_HDMI_STRAPS__AUDIO_STREAM_NUMBER__SHIFT 0x8
407b843c749SSergey Zigachev #endif
408b843c749SSergey Zigachev
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)409b843c749SSergey Zigachev static void read_dce_straps(
410b843c749SSergey Zigachev struct dc_context *ctx,
411b843c749SSergey Zigachev struct resource_straps *straps)
412b843c749SSergey Zigachev {
413b843c749SSergey Zigachev REG_GET_2(CC_DC_HDMI_STRAPS,
414b843c749SSergey Zigachev HDMI_DISABLE, &straps->hdmi_disable,
415b843c749SSergey Zigachev AUDIO_STREAM_NUMBER, &straps->audio_stream_number);
416b843c749SSergey Zigachev
417b843c749SSergey Zigachev REG_GET(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO, &straps->dc_pinstraps_audio);
418b843c749SSergey Zigachev }
419b843c749SSergey Zigachev
create_audio(struct dc_context * ctx,unsigned int inst)420b843c749SSergey Zigachev static struct audio *create_audio(
421b843c749SSergey Zigachev struct dc_context *ctx, unsigned int inst)
422b843c749SSergey Zigachev {
423b843c749SSergey Zigachev return dce_audio_create(ctx, inst,
424b843c749SSergey Zigachev &audio_regs[inst], &audio_shift, &audio_mask);
425b843c749SSergey Zigachev }
426b843c749SSergey Zigachev
427b843c749SSergey Zigachev
dce112_timing_generator_create(struct dc_context * ctx,uint32_t instance,const struct dce110_timing_generator_offsets * offsets)428b843c749SSergey Zigachev static struct timing_generator *dce112_timing_generator_create(
429b843c749SSergey Zigachev struct dc_context *ctx,
430b843c749SSergey Zigachev uint32_t instance,
431b843c749SSergey Zigachev const struct dce110_timing_generator_offsets *offsets)
432b843c749SSergey Zigachev {
433b843c749SSergey Zigachev struct dce110_timing_generator *tg110 =
434b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_timing_generator), GFP_KERNEL);
435b843c749SSergey Zigachev
436b843c749SSergey Zigachev if (!tg110)
437b843c749SSergey Zigachev return NULL;
438b843c749SSergey Zigachev
439b843c749SSergey Zigachev dce110_timing_generator_construct(tg110, ctx, instance, offsets);
440b843c749SSergey Zigachev return &tg110->base;
441b843c749SSergey Zigachev }
442b843c749SSergey Zigachev
dce112_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)443b843c749SSergey Zigachev static struct stream_encoder *dce112_stream_encoder_create(
444b843c749SSergey Zigachev enum engine_id eng_id,
445b843c749SSergey Zigachev struct dc_context *ctx)
446b843c749SSergey Zigachev {
447b843c749SSergey Zigachev struct dce110_stream_encoder *enc110 =
448b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_stream_encoder), GFP_KERNEL);
449b843c749SSergey Zigachev
450b843c749SSergey Zigachev if (!enc110)
451b843c749SSergey Zigachev return NULL;
452b843c749SSergey Zigachev
453b843c749SSergey Zigachev dce110_stream_encoder_construct(enc110, ctx, ctx->dc_bios, eng_id,
454b843c749SSergey Zigachev &stream_enc_regs[eng_id],
455b843c749SSergey Zigachev &se_shift, &se_mask);
456b843c749SSergey Zigachev return &enc110->base;
457b843c749SSergey Zigachev }
458b843c749SSergey Zigachev
459b843c749SSergey Zigachev #define SRII(reg_name, block, id)\
460b843c749SSergey Zigachev .reg_name[id] = mm ## block ## id ## _ ## reg_name
461b843c749SSergey Zigachev
462b843c749SSergey Zigachev static const struct dce_hwseq_registers hwseq_reg = {
463b843c749SSergey Zigachev HWSEQ_DCE112_REG_LIST()
464b843c749SSergey Zigachev };
465b843c749SSergey Zigachev
466b843c749SSergey Zigachev static const struct dce_hwseq_shift hwseq_shift = {
467b843c749SSergey Zigachev HWSEQ_DCE112_MASK_SH_LIST(__SHIFT)
468b843c749SSergey Zigachev };
469b843c749SSergey Zigachev
470b843c749SSergey Zigachev static const struct dce_hwseq_mask hwseq_mask = {
471b843c749SSergey Zigachev HWSEQ_DCE112_MASK_SH_LIST(_MASK)
472b843c749SSergey Zigachev };
473b843c749SSergey Zigachev
dce112_hwseq_create(struct dc_context * ctx)474b843c749SSergey Zigachev static struct dce_hwseq *dce112_hwseq_create(
475b843c749SSergey Zigachev struct dc_context *ctx)
476b843c749SSergey Zigachev {
477b843c749SSergey Zigachev struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
478b843c749SSergey Zigachev
479b843c749SSergey Zigachev if (hws) {
480b843c749SSergey Zigachev hws->ctx = ctx;
481b843c749SSergey Zigachev hws->regs = &hwseq_reg;
482b843c749SSergey Zigachev hws->shifts = &hwseq_shift;
483b843c749SSergey Zigachev hws->masks = &hwseq_mask;
484b843c749SSergey Zigachev }
485b843c749SSergey Zigachev return hws;
486b843c749SSergey Zigachev }
487b843c749SSergey Zigachev
488b843c749SSergey Zigachev static const struct resource_create_funcs res_create_funcs = {
489b843c749SSergey Zigachev .read_dce_straps = read_dce_straps,
490b843c749SSergey Zigachev .create_audio = create_audio,
491b843c749SSergey Zigachev .create_stream_encoder = dce112_stream_encoder_create,
492b843c749SSergey Zigachev .create_hwseq = dce112_hwseq_create,
493b843c749SSergey Zigachev };
494b843c749SSergey Zigachev
495b843c749SSergey Zigachev #define mi_inst_regs(id) { MI_DCE11_2_REG_LIST(id) }
496b843c749SSergey Zigachev static const struct dce_mem_input_registers mi_regs[] = {
497b843c749SSergey Zigachev mi_inst_regs(0),
498b843c749SSergey Zigachev mi_inst_regs(1),
499b843c749SSergey Zigachev mi_inst_regs(2),
500b843c749SSergey Zigachev mi_inst_regs(3),
501b843c749SSergey Zigachev mi_inst_regs(4),
502b843c749SSergey Zigachev mi_inst_regs(5),
503b843c749SSergey Zigachev };
504b843c749SSergey Zigachev
505b843c749SSergey Zigachev static const struct dce_mem_input_shift mi_shifts = {
506b843c749SSergey Zigachev MI_DCE11_2_MASK_SH_LIST(__SHIFT)
507b843c749SSergey Zigachev };
508b843c749SSergey Zigachev
509b843c749SSergey Zigachev static const struct dce_mem_input_mask mi_masks = {
510b843c749SSergey Zigachev MI_DCE11_2_MASK_SH_LIST(_MASK)
511b843c749SSergey Zigachev };
512b843c749SSergey Zigachev
dce112_mem_input_create(struct dc_context * ctx,uint32_t inst)513b843c749SSergey Zigachev static struct mem_input *dce112_mem_input_create(
514b843c749SSergey Zigachev struct dc_context *ctx,
515b843c749SSergey Zigachev uint32_t inst)
516b843c749SSergey Zigachev {
517b843c749SSergey Zigachev struct dce_mem_input *dce_mi = kzalloc(sizeof(struct dce_mem_input),
518b843c749SSergey Zigachev GFP_KERNEL);
519b843c749SSergey Zigachev
520b843c749SSergey Zigachev if (!dce_mi) {
521b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
522b843c749SSergey Zigachev return NULL;
523b843c749SSergey Zigachev }
524b843c749SSergey Zigachev
525b843c749SSergey Zigachev dce112_mem_input_construct(dce_mi, ctx, inst, &mi_regs[inst], &mi_shifts, &mi_masks);
526b843c749SSergey Zigachev return &dce_mi->base;
527b843c749SSergey Zigachev }
528b843c749SSergey Zigachev
dce112_transform_destroy(struct transform ** xfm)529b843c749SSergey Zigachev static void dce112_transform_destroy(struct transform **xfm)
530b843c749SSergey Zigachev {
531b843c749SSergey Zigachev kfree(TO_DCE_TRANSFORM(*xfm));
532b843c749SSergey Zigachev *xfm = NULL;
533b843c749SSergey Zigachev }
534b843c749SSergey Zigachev
dce112_transform_create(struct dc_context * ctx,uint32_t inst)535b843c749SSergey Zigachev static struct transform *dce112_transform_create(
536b843c749SSergey Zigachev struct dc_context *ctx,
537b843c749SSergey Zigachev uint32_t inst)
538b843c749SSergey Zigachev {
539b843c749SSergey Zigachev struct dce_transform *transform =
540b843c749SSergey Zigachev kzalloc(sizeof(struct dce_transform), GFP_KERNEL);
541b843c749SSergey Zigachev
542b843c749SSergey Zigachev if (!transform)
543b843c749SSergey Zigachev return NULL;
544b843c749SSergey Zigachev
545b843c749SSergey Zigachev dce_transform_construct(transform, ctx, inst,
546b843c749SSergey Zigachev &xfm_regs[inst], &xfm_shift, &xfm_mask);
547b843c749SSergey Zigachev transform->lb_memory_size = 0x1404; /*5124*/
548b843c749SSergey Zigachev return &transform->base;
549b843c749SSergey Zigachev }
550b843c749SSergey Zigachev
551b843c749SSergey Zigachev static const struct encoder_feature_support link_enc_feature = {
552b843c749SSergey Zigachev .max_hdmi_deep_color = COLOR_DEPTH_121212,
553b843c749SSergey Zigachev .max_hdmi_pixel_clock = 600000,
554b843c749SSergey Zigachev .ycbcr420_supported = true,
555b843c749SSergey Zigachev .flags.bits.IS_HBR2_CAPABLE = true,
556b843c749SSergey Zigachev .flags.bits.IS_HBR3_CAPABLE = true,
557b843c749SSergey Zigachev .flags.bits.IS_TPS3_CAPABLE = true,
558b843c749SSergey Zigachev .flags.bits.IS_TPS4_CAPABLE = true,
559b843c749SSergey Zigachev .flags.bits.IS_YCBCR_CAPABLE = true
560b843c749SSergey Zigachev };
561b843c749SSergey Zigachev
562*78973132SSergey Zigachev static
dce112_link_encoder_create(const struct encoder_init_data * enc_init_data)563b843c749SSergey Zigachev struct link_encoder *dce112_link_encoder_create(
564b843c749SSergey Zigachev const struct encoder_init_data *enc_init_data)
565b843c749SSergey Zigachev {
566b843c749SSergey Zigachev struct dce110_link_encoder *enc110 =
567b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_link_encoder), GFP_KERNEL);
568b843c749SSergey Zigachev
569b843c749SSergey Zigachev if (!enc110)
570b843c749SSergey Zigachev return NULL;
571b843c749SSergey Zigachev
572b843c749SSergey Zigachev dce110_link_encoder_construct(enc110,
573b843c749SSergey Zigachev enc_init_data,
574b843c749SSergey Zigachev &link_enc_feature,
575b843c749SSergey Zigachev &link_enc_regs[enc_init_data->transmitter],
576b843c749SSergey Zigachev &link_enc_aux_regs[enc_init_data->channel - 1],
577b843c749SSergey Zigachev &link_enc_hpd_regs[enc_init_data->hpd_source]);
578b843c749SSergey Zigachev return &enc110->base;
579b843c749SSergey Zigachev }
580b843c749SSergey Zigachev
dce112_ipp_create(struct dc_context * ctx,uint32_t inst)581b843c749SSergey Zigachev static struct input_pixel_processor *dce112_ipp_create(
582b843c749SSergey Zigachev struct dc_context *ctx, uint32_t inst)
583b843c749SSergey Zigachev {
584b843c749SSergey Zigachev struct dce_ipp *ipp = kzalloc(sizeof(struct dce_ipp), GFP_KERNEL);
585b843c749SSergey Zigachev
586b843c749SSergey Zigachev if (!ipp) {
587b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
588b843c749SSergey Zigachev return NULL;
589b843c749SSergey Zigachev }
590b843c749SSergey Zigachev
591b843c749SSergey Zigachev dce_ipp_construct(ipp, ctx, inst,
592b843c749SSergey Zigachev &ipp_regs[inst], &ipp_shift, &ipp_mask);
593b843c749SSergey Zigachev return &ipp->base;
594b843c749SSergey Zigachev }
595b843c749SSergey Zigachev
596*78973132SSergey Zigachev static
dce112_opp_create(struct dc_context * ctx,uint32_t inst)597b843c749SSergey Zigachev struct output_pixel_processor *dce112_opp_create(
598b843c749SSergey Zigachev struct dc_context *ctx,
599b843c749SSergey Zigachev uint32_t inst)
600b843c749SSergey Zigachev {
601b843c749SSergey Zigachev struct dce110_opp *opp =
602b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_opp), GFP_KERNEL);
603b843c749SSergey Zigachev
604b843c749SSergey Zigachev if (!opp)
605b843c749SSergey Zigachev return NULL;
606b843c749SSergey Zigachev
607b843c749SSergey Zigachev dce110_opp_construct(opp,
608b843c749SSergey Zigachev ctx, inst, &opp_regs[inst], &opp_shift, &opp_mask);
609b843c749SSergey Zigachev return &opp->base;
610b843c749SSergey Zigachev }
611b843c749SSergey Zigachev
612*78973132SSergey Zigachev static
dce112_aux_engine_create(struct dc_context * ctx,uint32_t inst)613b843c749SSergey Zigachev struct aux_engine *dce112_aux_engine_create(
614b843c749SSergey Zigachev struct dc_context *ctx,
615b843c749SSergey Zigachev uint32_t inst)
616b843c749SSergey Zigachev {
617b843c749SSergey Zigachev struct aux_engine_dce110 *aux_engine =
618b843c749SSergey Zigachev kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
619b843c749SSergey Zigachev
620b843c749SSergey Zigachev if (!aux_engine)
621b843c749SSergey Zigachev return NULL;
622b843c749SSergey Zigachev
623b843c749SSergey Zigachev dce110_aux_engine_construct(aux_engine, ctx, inst,
624b843c749SSergey Zigachev SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
625b843c749SSergey Zigachev &aux_engine_regs[inst]);
626b843c749SSergey Zigachev
627b843c749SSergey Zigachev return &aux_engine->base;
628b843c749SSergey Zigachev }
629b843c749SSergey Zigachev
630*78973132SSergey Zigachev static
dce112_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)631b843c749SSergey Zigachev struct clock_source *dce112_clock_source_create(
632b843c749SSergey Zigachev struct dc_context *ctx,
633b843c749SSergey Zigachev struct dc_bios *bios,
634b843c749SSergey Zigachev enum clock_source_id id,
635b843c749SSergey Zigachev const struct dce110_clk_src_regs *regs,
636b843c749SSergey Zigachev bool dp_clk_src)
637b843c749SSergey Zigachev {
638b843c749SSergey Zigachev struct dce110_clk_src *clk_src =
639b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
640b843c749SSergey Zigachev
641b843c749SSergey Zigachev if (!clk_src)
642b843c749SSergey Zigachev return NULL;
643b843c749SSergey Zigachev
644b843c749SSergey Zigachev if (dce110_clk_src_construct(clk_src, ctx, bios, id,
645b843c749SSergey Zigachev regs, &cs_shift, &cs_mask)) {
646b843c749SSergey Zigachev clk_src->base.dp_clk_src = dp_clk_src;
647b843c749SSergey Zigachev return &clk_src->base;
648b843c749SSergey Zigachev }
649b843c749SSergey Zigachev
650b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
651b843c749SSergey Zigachev return NULL;
652b843c749SSergey Zigachev }
653b843c749SSergey Zigachev
654*78973132SSergey Zigachev static
dce112_clock_source_destroy(struct clock_source ** clk_src)655b843c749SSergey Zigachev void dce112_clock_source_destroy(struct clock_source **clk_src)
656b843c749SSergey Zigachev {
657b843c749SSergey Zigachev kfree(TO_DCE110_CLK_SRC(*clk_src));
658b843c749SSergey Zigachev *clk_src = NULL;
659b843c749SSergey Zigachev }
660b843c749SSergey Zigachev
destruct(struct dce110_resource_pool * pool)661b843c749SSergey Zigachev static void destruct(struct dce110_resource_pool *pool)
662b843c749SSergey Zigachev {
663b843c749SSergey Zigachev unsigned int i;
664b843c749SSergey Zigachev
665b843c749SSergey Zigachev for (i = 0; i < pool->base.pipe_count; i++) {
666b843c749SSergey Zigachev if (pool->base.opps[i] != NULL)
667b843c749SSergey Zigachev dce110_opp_destroy(&pool->base.opps[i]);
668b843c749SSergey Zigachev
669b843c749SSergey Zigachev if (pool->base.engines[i] != NULL)
670b843c749SSergey Zigachev dce110_engine_destroy(&pool->base.engines[i]);
671b843c749SSergey Zigachev
672b843c749SSergey Zigachev if (pool->base.transforms[i] != NULL)
673b843c749SSergey Zigachev dce112_transform_destroy(&pool->base.transforms[i]);
674b843c749SSergey Zigachev
675b843c749SSergey Zigachev if (pool->base.ipps[i] != NULL)
676b843c749SSergey Zigachev dce_ipp_destroy(&pool->base.ipps[i]);
677b843c749SSergey Zigachev
678b843c749SSergey Zigachev if (pool->base.mis[i] != NULL) {
679b843c749SSergey Zigachev kfree(TO_DCE_MEM_INPUT(pool->base.mis[i]));
680b843c749SSergey Zigachev pool->base.mis[i] = NULL;
681b843c749SSergey Zigachev }
682b843c749SSergey Zigachev
683b843c749SSergey Zigachev if (pool->base.timing_generators[i] != NULL) {
684b843c749SSergey Zigachev kfree(DCE110TG_FROM_TG(pool->base.timing_generators[i]));
685b843c749SSergey Zigachev pool->base.timing_generators[i] = NULL;
686b843c749SSergey Zigachev }
687b843c749SSergey Zigachev
688b843c749SSergey Zigachev }
689b843c749SSergey Zigachev
690b843c749SSergey Zigachev for (i = 0; i < pool->base.stream_enc_count; i++) {
691b843c749SSergey Zigachev if (pool->base.stream_enc[i] != NULL)
692b843c749SSergey Zigachev kfree(DCE110STRENC_FROM_STRENC(pool->base.stream_enc[i]));
693b843c749SSergey Zigachev }
694b843c749SSergey Zigachev
695b843c749SSergey Zigachev for (i = 0; i < pool->base.clk_src_count; i++) {
696b843c749SSergey Zigachev if (pool->base.clock_sources[i] != NULL) {
697b843c749SSergey Zigachev dce112_clock_source_destroy(&pool->base.clock_sources[i]);
698b843c749SSergey Zigachev }
699b843c749SSergey Zigachev }
700b843c749SSergey Zigachev
701b843c749SSergey Zigachev if (pool->base.dp_clock_source != NULL)
702b843c749SSergey Zigachev dce112_clock_source_destroy(&pool->base.dp_clock_source);
703b843c749SSergey Zigachev
704b843c749SSergey Zigachev for (i = 0; i < pool->base.audio_count; i++) {
705b843c749SSergey Zigachev if (pool->base.audios[i] != NULL) {
706b843c749SSergey Zigachev dce_aud_destroy(&pool->base.audios[i]);
707b843c749SSergey Zigachev }
708b843c749SSergey Zigachev }
709b843c749SSergey Zigachev
710b843c749SSergey Zigachev if (pool->base.abm != NULL)
711b843c749SSergey Zigachev dce_abm_destroy(&pool->base.abm);
712b843c749SSergey Zigachev
713b843c749SSergey Zigachev if (pool->base.dmcu != NULL)
714b843c749SSergey Zigachev dce_dmcu_destroy(&pool->base.dmcu);
715b843c749SSergey Zigachev
716b843c749SSergey Zigachev if (pool->base.dccg != NULL)
717b843c749SSergey Zigachev dce_dccg_destroy(&pool->base.dccg);
718b843c749SSergey Zigachev
719b843c749SSergey Zigachev if (pool->base.irqs != NULL) {
720b843c749SSergey Zigachev dal_irq_service_destroy(&pool->base.irqs);
721b843c749SSergey Zigachev }
722b843c749SSergey Zigachev }
723b843c749SSergey Zigachev
find_matching_pll(struct resource_context * res_ctx,const struct resource_pool * pool,const struct dc_stream_state * const stream)724b843c749SSergey Zigachev static struct clock_source *find_matching_pll(
725b843c749SSergey Zigachev struct resource_context *res_ctx,
726b843c749SSergey Zigachev const struct resource_pool *pool,
727b843c749SSergey Zigachev const struct dc_stream_state *const stream)
728b843c749SSergey Zigachev {
729b843c749SSergey Zigachev switch (stream->sink->link->link_enc->transmitter) {
730b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_A:
731b843c749SSergey Zigachev return pool->clock_sources[DCE112_CLK_SRC_PLL0];
732b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_B:
733b843c749SSergey Zigachev return pool->clock_sources[DCE112_CLK_SRC_PLL1];
734b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_C:
735b843c749SSergey Zigachev return pool->clock_sources[DCE112_CLK_SRC_PLL2];
736b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_D:
737b843c749SSergey Zigachev return pool->clock_sources[DCE112_CLK_SRC_PLL3];
738b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_E:
739b843c749SSergey Zigachev return pool->clock_sources[DCE112_CLK_SRC_PLL4];
740b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_F:
741b843c749SSergey Zigachev return pool->clock_sources[DCE112_CLK_SRC_PLL5];
742b843c749SSergey Zigachev default:
743b843c749SSergey Zigachev return NULL;
744b843c749SSergey Zigachev };
745b843c749SSergey Zigachev
746b843c749SSergey Zigachev return 0;
747b843c749SSergey Zigachev }
748b843c749SSergey Zigachev
build_mapped_resource(const struct dc * dc,struct dc_state * context,struct dc_stream_state * stream)749b843c749SSergey Zigachev static enum dc_status build_mapped_resource(
750b843c749SSergey Zigachev const struct dc *dc,
751b843c749SSergey Zigachev struct dc_state *context,
752b843c749SSergey Zigachev struct dc_stream_state *stream)
753b843c749SSergey Zigachev {
754b843c749SSergey Zigachev struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
755b843c749SSergey Zigachev
756b843c749SSergey Zigachev if (!pipe_ctx)
757b843c749SSergey Zigachev return DC_ERROR_UNEXPECTED;
758b843c749SSergey Zigachev
759b843c749SSergey Zigachev dce110_resource_build_pipe_hw_param(pipe_ctx);
760b843c749SSergey Zigachev
761b843c749SSergey Zigachev resource_build_info_frame(pipe_ctx);
762b843c749SSergey Zigachev
763b843c749SSergey Zigachev return DC_OK;
764b843c749SSergey Zigachev }
765b843c749SSergey Zigachev
dce112_validate_bandwidth(struct dc * dc,struct dc_state * context)766b843c749SSergey Zigachev bool dce112_validate_bandwidth(
767b843c749SSergey Zigachev struct dc *dc,
768b843c749SSergey Zigachev struct dc_state *context)
769b843c749SSergey Zigachev {
770b843c749SSergey Zigachev bool result = false;
771b843c749SSergey Zigachev
772b843c749SSergey Zigachev DC_LOG_BANDWIDTH_CALCS(
773b843c749SSergey Zigachev "%s: start",
774b843c749SSergey Zigachev __func__);
775b843c749SSergey Zigachev
776b843c749SSergey Zigachev if (bw_calcs(
777b843c749SSergey Zigachev dc->ctx,
778b843c749SSergey Zigachev dc->bw_dceip,
779b843c749SSergey Zigachev dc->bw_vbios,
780b843c749SSergey Zigachev context->res_ctx.pipe_ctx,
781b843c749SSergey Zigachev dc->res_pool->pipe_count,
782b843c749SSergey Zigachev &context->bw.dce))
783b843c749SSergey Zigachev result = true;
784b843c749SSergey Zigachev
785b843c749SSergey Zigachev if (!result)
786b843c749SSergey Zigachev DC_LOG_BANDWIDTH_VALIDATION(
787b843c749SSergey Zigachev "%s: Bandwidth validation failed!",
788b843c749SSergey Zigachev __func__);
789b843c749SSergey Zigachev
790b843c749SSergey Zigachev if (memcmp(&dc->current_state->bw.dce,
791b843c749SSergey Zigachev &context->bw.dce, sizeof(context->bw.dce))) {
792b843c749SSergey Zigachev
793b843c749SSergey Zigachev DC_LOG_BANDWIDTH_CALCS(
794b843c749SSergey Zigachev "%s: finish,\n"
795b843c749SSergey Zigachev "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
796b843c749SSergey Zigachev "stutMark_b: %d stutMark_a: %d\n"
797b843c749SSergey Zigachev "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
798b843c749SSergey Zigachev "stutMark_b: %d stutMark_a: %d\n"
799b843c749SSergey Zigachev "nbpMark_b: %d nbpMark_a: %d urgentMark_b: %d urgentMark_a: %d\n"
800b843c749SSergey Zigachev "stutMark_b: %d stutMark_a: %d stutter_mode_enable: %d\n"
801b843c749SSergey Zigachev "cstate: %d pstate: %d nbpstate: %d sync: %d dispclk: %d\n"
802b843c749SSergey Zigachev "sclk: %d sclk_sleep: %d yclk: %d blackout_recovery_time_us: %d\n"
803b843c749SSergey Zigachev ,
804b843c749SSergey Zigachev __func__,
805b843c749SSergey Zigachev context->bw.dce.nbp_state_change_wm_ns[0].b_mark,
806b843c749SSergey Zigachev context->bw.dce.nbp_state_change_wm_ns[0].a_mark,
807b843c749SSergey Zigachev context->bw.dce.urgent_wm_ns[0].b_mark,
808b843c749SSergey Zigachev context->bw.dce.urgent_wm_ns[0].a_mark,
809b843c749SSergey Zigachev context->bw.dce.stutter_exit_wm_ns[0].b_mark,
810b843c749SSergey Zigachev context->bw.dce.stutter_exit_wm_ns[0].a_mark,
811b843c749SSergey Zigachev context->bw.dce.nbp_state_change_wm_ns[1].b_mark,
812b843c749SSergey Zigachev context->bw.dce.nbp_state_change_wm_ns[1].a_mark,
813b843c749SSergey Zigachev context->bw.dce.urgent_wm_ns[1].b_mark,
814b843c749SSergey Zigachev context->bw.dce.urgent_wm_ns[1].a_mark,
815b843c749SSergey Zigachev context->bw.dce.stutter_exit_wm_ns[1].b_mark,
816b843c749SSergey Zigachev context->bw.dce.stutter_exit_wm_ns[1].a_mark,
817b843c749SSergey Zigachev context->bw.dce.nbp_state_change_wm_ns[2].b_mark,
818b843c749SSergey Zigachev context->bw.dce.nbp_state_change_wm_ns[2].a_mark,
819b843c749SSergey Zigachev context->bw.dce.urgent_wm_ns[2].b_mark,
820b843c749SSergey Zigachev context->bw.dce.urgent_wm_ns[2].a_mark,
821b843c749SSergey Zigachev context->bw.dce.stutter_exit_wm_ns[2].b_mark,
822b843c749SSergey Zigachev context->bw.dce.stutter_exit_wm_ns[2].a_mark,
823b843c749SSergey Zigachev context->bw.dce.stutter_mode_enable,
824b843c749SSergey Zigachev context->bw.dce.cpuc_state_change_enable,
825b843c749SSergey Zigachev context->bw.dce.cpup_state_change_enable,
826b843c749SSergey Zigachev context->bw.dce.nbp_state_change_enable,
827b843c749SSergey Zigachev context->bw.dce.all_displays_in_sync,
828b843c749SSergey Zigachev context->bw.dce.dispclk_khz,
829b843c749SSergey Zigachev context->bw.dce.sclk_khz,
830b843c749SSergey Zigachev context->bw.dce.sclk_deep_sleep_khz,
831b843c749SSergey Zigachev context->bw.dce.yclk_khz,
832b843c749SSergey Zigachev context->bw.dce.blackout_recovery_time_us);
833b843c749SSergey Zigachev }
834b843c749SSergey Zigachev return result;
835b843c749SSergey Zigachev }
836b843c749SSergey Zigachev
resource_map_phy_clock_resources(const struct dc * dc,struct dc_state * context,struct dc_stream_state * stream)837b843c749SSergey Zigachev enum dc_status resource_map_phy_clock_resources(
838b843c749SSergey Zigachev const struct dc *dc,
839b843c749SSergey Zigachev struct dc_state *context,
840b843c749SSergey Zigachev struct dc_stream_state *stream)
841b843c749SSergey Zigachev {
842b843c749SSergey Zigachev
843b843c749SSergey Zigachev /* acquire new resources */
844b843c749SSergey Zigachev struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(
845b843c749SSergey Zigachev &context->res_ctx, stream);
846b843c749SSergey Zigachev
847b843c749SSergey Zigachev if (!pipe_ctx)
848b843c749SSergey Zigachev return DC_ERROR_UNEXPECTED;
849b843c749SSergey Zigachev
850b843c749SSergey Zigachev if (dc_is_dp_signal(pipe_ctx->stream->signal)
851b843c749SSergey Zigachev || pipe_ctx->stream->signal == SIGNAL_TYPE_VIRTUAL)
852b843c749SSergey Zigachev pipe_ctx->clock_source =
853b843c749SSergey Zigachev dc->res_pool->dp_clock_source;
854b843c749SSergey Zigachev else
855b843c749SSergey Zigachev pipe_ctx->clock_source = find_matching_pll(
856b843c749SSergey Zigachev &context->res_ctx, dc->res_pool,
857b843c749SSergey Zigachev stream);
858b843c749SSergey Zigachev
859b843c749SSergey Zigachev if (pipe_ctx->clock_source == NULL)
860b843c749SSergey Zigachev return DC_NO_CLOCK_SOURCE_RESOURCE;
861b843c749SSergey Zigachev
862b843c749SSergey Zigachev resource_reference_clock_source(
863b843c749SSergey Zigachev &context->res_ctx,
864b843c749SSergey Zigachev dc->res_pool,
865b843c749SSergey Zigachev pipe_ctx->clock_source);
866b843c749SSergey Zigachev
867b843c749SSergey Zigachev return DC_OK;
868b843c749SSergey Zigachev }
869b843c749SSergey Zigachev
dce112_validate_surface_sets(struct dc_state * context)870b843c749SSergey Zigachev static bool dce112_validate_surface_sets(
871b843c749SSergey Zigachev struct dc_state *context)
872b843c749SSergey Zigachev {
873b843c749SSergey Zigachev int i;
874b843c749SSergey Zigachev
875b843c749SSergey Zigachev for (i = 0; i < context->stream_count; i++) {
876b843c749SSergey Zigachev if (context->stream_status[i].plane_count == 0)
877b843c749SSergey Zigachev continue;
878b843c749SSergey Zigachev
879b843c749SSergey Zigachev if (context->stream_status[i].plane_count > 1)
880b843c749SSergey Zigachev return false;
881b843c749SSergey Zigachev
882b843c749SSergey Zigachev if (context->stream_status[i].plane_states[0]->format
883b843c749SSergey Zigachev >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
884b843c749SSergey Zigachev return false;
885b843c749SSergey Zigachev }
886b843c749SSergey Zigachev
887b843c749SSergey Zigachev return true;
888b843c749SSergey Zigachev }
889b843c749SSergey Zigachev
dce112_add_stream_to_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)890b843c749SSergey Zigachev enum dc_status dce112_add_stream_to_ctx(
891b843c749SSergey Zigachev struct dc *dc,
892b843c749SSergey Zigachev struct dc_state *new_ctx,
893b843c749SSergey Zigachev struct dc_stream_state *dc_stream)
894b843c749SSergey Zigachev {
895b843c749SSergey Zigachev enum dc_status result = DC_ERROR_UNEXPECTED;
896b843c749SSergey Zigachev
897b843c749SSergey Zigachev result = resource_map_pool_resources(dc, new_ctx, dc_stream);
898b843c749SSergey Zigachev
899b843c749SSergey Zigachev if (result == DC_OK)
900b843c749SSergey Zigachev result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
901b843c749SSergey Zigachev
902b843c749SSergey Zigachev
903b843c749SSergey Zigachev if (result == DC_OK)
904b843c749SSergey Zigachev result = build_mapped_resource(dc, new_ctx, dc_stream);
905b843c749SSergey Zigachev
906b843c749SSergey Zigachev return result;
907b843c749SSergey Zigachev }
908b843c749SSergey Zigachev
909*78973132SSergey Zigachev static
dce112_validate_global(struct dc * dc,struct dc_state * context)910b843c749SSergey Zigachev enum dc_status dce112_validate_global(
911b843c749SSergey Zigachev struct dc *dc,
912b843c749SSergey Zigachev struct dc_state *context)
913b843c749SSergey Zigachev {
914b843c749SSergey Zigachev if (!dce112_validate_surface_sets(context))
915b843c749SSergey Zigachev return DC_FAIL_SURFACE_VALIDATE;
916b843c749SSergey Zigachev
917b843c749SSergey Zigachev return DC_OK;
918b843c749SSergey Zigachev }
919b843c749SSergey Zigachev
dce112_destroy_resource_pool(struct resource_pool ** pool)920b843c749SSergey Zigachev static void dce112_destroy_resource_pool(struct resource_pool **pool)
921b843c749SSergey Zigachev {
922b843c749SSergey Zigachev struct dce110_resource_pool *dce110_pool = TO_DCE110_RES_POOL(*pool);
923b843c749SSergey Zigachev
924b843c749SSergey Zigachev destruct(dce110_pool);
925b843c749SSergey Zigachev kfree(dce110_pool);
926b843c749SSergey Zigachev *pool = NULL;
927b843c749SSergey Zigachev }
928b843c749SSergey Zigachev
929b843c749SSergey Zigachev static const struct resource_funcs dce112_res_pool_funcs = {
930b843c749SSergey Zigachev .destroy = dce112_destroy_resource_pool,
931b843c749SSergey Zigachev .link_enc_create = dce112_link_encoder_create,
932b843c749SSergey Zigachev .validate_bandwidth = dce112_validate_bandwidth,
933b843c749SSergey Zigachev .validate_plane = dce100_validate_plane,
934b843c749SSergey Zigachev .add_stream_to_ctx = dce112_add_stream_to_ctx,
935b843c749SSergey Zigachev .validate_global = dce112_validate_global
936b843c749SSergey Zigachev };
937b843c749SSergey Zigachev
bw_calcs_data_update_from_pplib(struct dc * dc)938b843c749SSergey Zigachev static void bw_calcs_data_update_from_pplib(struct dc *dc)
939b843c749SSergey Zigachev {
940b843c749SSergey Zigachev struct dm_pp_clock_levels_with_latency eng_clks = {0};
941b843c749SSergey Zigachev struct dm_pp_clock_levels_with_latency mem_clks = {0};
942b843c749SSergey Zigachev struct dm_pp_wm_sets_with_clock_ranges clk_ranges = {0};
943b843c749SSergey Zigachev struct dm_pp_clock_levels clks = {0};
944b843c749SSergey Zigachev
945b843c749SSergey Zigachev /*do system clock TODO PPLIB: after PPLIB implement,
946b843c749SSergey Zigachev * then remove old way
947b843c749SSergey Zigachev */
948b843c749SSergey Zigachev if (!dm_pp_get_clock_levels_by_type_with_latency(
949b843c749SSergey Zigachev dc->ctx,
950b843c749SSergey Zigachev DM_PP_CLOCK_TYPE_ENGINE_CLK,
951b843c749SSergey Zigachev &eng_clks)) {
952b843c749SSergey Zigachev
953b843c749SSergey Zigachev /* This is only for temporary */
954b843c749SSergey Zigachev dm_pp_get_clock_levels_by_type(
955b843c749SSergey Zigachev dc->ctx,
956b843c749SSergey Zigachev DM_PP_CLOCK_TYPE_ENGINE_CLK,
957b843c749SSergey Zigachev &clks);
958b843c749SSergey Zigachev /* convert all the clock fro kHz to fix point mHz */
959b843c749SSergey Zigachev dc->bw_vbios->high_sclk = bw_frc_to_fixed(
960b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels-1], 1000);
961b843c749SSergey Zigachev dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
962b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels/8], 1000);
963b843c749SSergey Zigachev dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
964b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels*2/8], 1000);
965b843c749SSergey Zigachev dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
966b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels*3/8], 1000);
967b843c749SSergey Zigachev dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
968b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels*4/8], 1000);
969b843c749SSergey Zigachev dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
970b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels*5/8], 1000);
971b843c749SSergey Zigachev dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
972b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels*6/8], 1000);
973b843c749SSergey Zigachev dc->bw_vbios->low_sclk = bw_frc_to_fixed(
974b843c749SSergey Zigachev clks.clocks_in_khz[0], 1000);
975b843c749SSergey Zigachev
976b843c749SSergey Zigachev /*do memory clock*/
977b843c749SSergey Zigachev dm_pp_get_clock_levels_by_type(
978b843c749SSergey Zigachev dc->ctx,
979b843c749SSergey Zigachev DM_PP_CLOCK_TYPE_MEMORY_CLK,
980b843c749SSergey Zigachev &clks);
981b843c749SSergey Zigachev
982b843c749SSergey Zigachev dc->bw_vbios->low_yclk = bw_frc_to_fixed(
983b843c749SSergey Zigachev clks.clocks_in_khz[0] * MEMORY_TYPE_MULTIPLIER, 1000);
984b843c749SSergey Zigachev dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
985b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels>>1] * MEMORY_TYPE_MULTIPLIER,
986b843c749SSergey Zigachev 1000);
987b843c749SSergey Zigachev dc->bw_vbios->high_yclk = bw_frc_to_fixed(
988b843c749SSergey Zigachev clks.clocks_in_khz[clks.num_levels-1] * MEMORY_TYPE_MULTIPLIER,
989b843c749SSergey Zigachev 1000);
990b843c749SSergey Zigachev
991b843c749SSergey Zigachev return;
992b843c749SSergey Zigachev }
993b843c749SSergey Zigachev
994b843c749SSergey Zigachev /* convert all the clock fro kHz to fix point mHz TODO: wloop data */
995b843c749SSergey Zigachev dc->bw_vbios->high_sclk = bw_frc_to_fixed(
996b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels-1].clocks_in_khz, 1000);
997b843c749SSergey Zigachev dc->bw_vbios->mid1_sclk = bw_frc_to_fixed(
998b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels/8].clocks_in_khz, 1000);
999b843c749SSergey Zigachev dc->bw_vbios->mid2_sclk = bw_frc_to_fixed(
1000b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*2/8].clocks_in_khz, 1000);
1001b843c749SSergey Zigachev dc->bw_vbios->mid3_sclk = bw_frc_to_fixed(
1002b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz, 1000);
1003b843c749SSergey Zigachev dc->bw_vbios->mid4_sclk = bw_frc_to_fixed(
1004b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*4/8].clocks_in_khz, 1000);
1005b843c749SSergey Zigachev dc->bw_vbios->mid5_sclk = bw_frc_to_fixed(
1006b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*5/8].clocks_in_khz, 1000);
1007b843c749SSergey Zigachev dc->bw_vbios->mid6_sclk = bw_frc_to_fixed(
1008b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*6/8].clocks_in_khz, 1000);
1009b843c749SSergey Zigachev dc->bw_vbios->low_sclk = bw_frc_to_fixed(
1010b843c749SSergey Zigachev eng_clks.data[0].clocks_in_khz, 1000);
1011b843c749SSergey Zigachev
1012b843c749SSergey Zigachev /*do memory clock*/
1013b843c749SSergey Zigachev dm_pp_get_clock_levels_by_type_with_latency(
1014b843c749SSergey Zigachev dc->ctx,
1015b843c749SSergey Zigachev DM_PP_CLOCK_TYPE_MEMORY_CLK,
1016b843c749SSergey Zigachev &mem_clks);
1017b843c749SSergey Zigachev
1018b843c749SSergey Zigachev /* we don't need to call PPLIB for validation clock since they
1019b843c749SSergey Zigachev * also give us the highest sclk and highest mclk (UMA clock).
1020b843c749SSergey Zigachev * ALSO always convert UMA clock (from PPLIB) to YCLK (HW formula):
1021b843c749SSergey Zigachev * YCLK = UMACLK*m_memoryTypeMultiplier
1022b843c749SSergey Zigachev */
1023b843c749SSergey Zigachev dc->bw_vbios->low_yclk = bw_frc_to_fixed(
1024b843c749SSergey Zigachev mem_clks.data[0].clocks_in_khz * MEMORY_TYPE_MULTIPLIER, 1000);
1025b843c749SSergey Zigachev dc->bw_vbios->mid_yclk = bw_frc_to_fixed(
1026b843c749SSergey Zigachev mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz * MEMORY_TYPE_MULTIPLIER,
1027b843c749SSergey Zigachev 1000);
1028b843c749SSergey Zigachev dc->bw_vbios->high_yclk = bw_frc_to_fixed(
1029b843c749SSergey Zigachev mem_clks.data[mem_clks.num_levels-1].clocks_in_khz * MEMORY_TYPE_MULTIPLIER,
1030b843c749SSergey Zigachev 1000);
1031b843c749SSergey Zigachev
1032b843c749SSergey Zigachev /* Now notify PPLib/SMU about which Watermarks sets they should select
1033b843c749SSergey Zigachev * depending on DPM state they are in. And update BW MGR GFX Engine and
1034b843c749SSergey Zigachev * Memory clock member variables for Watermarks calculations for each
1035b843c749SSergey Zigachev * Watermark Set
1036b843c749SSergey Zigachev */
1037b843c749SSergey Zigachev clk_ranges.num_wm_sets = 4;
1038b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[0].wm_set_id = WM_SET_A;
1039b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[0].wm_min_eng_clk_in_khz =
1040b843c749SSergey Zigachev eng_clks.data[0].clocks_in_khz;
1041b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[0].wm_max_eng_clk_in_khz =
1042b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz - 1;
1043b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[0].wm_min_mem_clk_in_khz =
1044b843c749SSergey Zigachev mem_clks.data[0].clocks_in_khz;
1045b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[0].wm_max_mem_clk_in_khz =
1046b843c749SSergey Zigachev mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz - 1;
1047b843c749SSergey Zigachev
1048b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[1].wm_set_id = WM_SET_B;
1049b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[1].wm_min_eng_clk_in_khz =
1050b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz;
1051b843c749SSergey Zigachev /* 5 GHz instead of data[7].clockInKHz to cover Overdrive */
1052b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[1].wm_max_eng_clk_in_khz = 5000000;
1053b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[1].wm_min_mem_clk_in_khz =
1054b843c749SSergey Zigachev mem_clks.data[0].clocks_in_khz;
1055b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[1].wm_max_mem_clk_in_khz =
1056b843c749SSergey Zigachev mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz - 1;
1057b843c749SSergey Zigachev
1058b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[2].wm_set_id = WM_SET_C;
1059b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[2].wm_min_eng_clk_in_khz =
1060b843c749SSergey Zigachev eng_clks.data[0].clocks_in_khz;
1061b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[2].wm_max_eng_clk_in_khz =
1062b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz - 1;
1063b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[2].wm_min_mem_clk_in_khz =
1064b843c749SSergey Zigachev mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz;
1065b843c749SSergey Zigachev /* 5 GHz instead of data[2].clockInKHz to cover Overdrive */
1066b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[2].wm_max_mem_clk_in_khz = 5000000;
1067b843c749SSergey Zigachev
1068b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[3].wm_set_id = WM_SET_D;
1069b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[3].wm_min_eng_clk_in_khz =
1070b843c749SSergey Zigachev eng_clks.data[eng_clks.num_levels*3/8].clocks_in_khz;
1071b843c749SSergey Zigachev /* 5 GHz instead of data[7].clockInKHz to cover Overdrive */
1072b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[3].wm_max_eng_clk_in_khz = 5000000;
1073b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[3].wm_min_mem_clk_in_khz =
1074b843c749SSergey Zigachev mem_clks.data[mem_clks.num_levels>>1].clocks_in_khz;
1075b843c749SSergey Zigachev /* 5 GHz instead of data[2].clockInKHz to cover Overdrive */
1076b843c749SSergey Zigachev clk_ranges.wm_clk_ranges[3].wm_max_mem_clk_in_khz = 5000000;
1077b843c749SSergey Zigachev
1078b843c749SSergey Zigachev /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
1079b843c749SSergey Zigachev dm_pp_notify_wm_clock_changes(dc->ctx, &clk_ranges);
1080b843c749SSergey Zigachev }
1081b843c749SSergey Zigachev
1082*78973132SSergey Zigachev static
dce112_resource_cap(struct hw_asic_id * asic_id)1083b843c749SSergey Zigachev const struct resource_caps *dce112_resource_cap(
1084b843c749SSergey Zigachev struct hw_asic_id *asic_id)
1085b843c749SSergey Zigachev {
1086b843c749SSergey Zigachev if (ASIC_REV_IS_POLARIS11_M(asic_id->hw_internal_rev) ||
1087b843c749SSergey Zigachev ASIC_REV_IS_POLARIS12_V(asic_id->hw_internal_rev))
1088b843c749SSergey Zigachev return &polaris_11_resource_cap;
1089b843c749SSergey Zigachev else
1090b843c749SSergey Zigachev return &polaris_10_resource_cap;
1091b843c749SSergey Zigachev }
1092b843c749SSergey Zigachev
construct(uint8_t num_virtual_links,struct dc * dc,struct dce110_resource_pool * pool)1093b843c749SSergey Zigachev static bool construct(
1094b843c749SSergey Zigachev uint8_t num_virtual_links,
1095b843c749SSergey Zigachev struct dc *dc,
1096b843c749SSergey Zigachev struct dce110_resource_pool *pool)
1097b843c749SSergey Zigachev {
1098b843c749SSergey Zigachev unsigned int i;
1099b843c749SSergey Zigachev struct dc_context *ctx = dc->ctx;
1100b843c749SSergey Zigachev struct dm_pp_static_clock_info static_clk_info = {0};
1101b843c749SSergey Zigachev
1102b843c749SSergey Zigachev ctx->dc_bios->regs = &bios_regs;
1103b843c749SSergey Zigachev
1104b843c749SSergey Zigachev pool->base.res_cap = dce112_resource_cap(&ctx->asic_id);
1105b843c749SSergey Zigachev pool->base.funcs = &dce112_res_pool_funcs;
1106b843c749SSergey Zigachev
1107b843c749SSergey Zigachev /*************************************************
1108b843c749SSergey Zigachev * Resource + asic cap harcoding *
1109b843c749SSergey Zigachev *************************************************/
1110b843c749SSergey Zigachev pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1111b843c749SSergey Zigachev pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1112b843c749SSergey Zigachev pool->base.timing_generator_count = pool->base.res_cap->num_timing_generator;
1113b843c749SSergey Zigachev dc->caps.max_downscale_ratio = 200;
1114b843c749SSergey Zigachev dc->caps.i2c_speed_in_khz = 100;
1115b843c749SSergey Zigachev dc->caps.max_cursor_size = 128;
1116b843c749SSergey Zigachev dc->caps.dual_link_dvi = true;
1117b843c749SSergey Zigachev
1118b843c749SSergey Zigachev
1119b843c749SSergey Zigachev /*************************************************
1120b843c749SSergey Zigachev * Create resources *
1121b843c749SSergey Zigachev *************************************************/
1122b843c749SSergey Zigachev
1123b843c749SSergey Zigachev pool->base.clock_sources[DCE112_CLK_SRC_PLL0] =
1124b843c749SSergey Zigachev dce112_clock_source_create(
1125b843c749SSergey Zigachev ctx, ctx->dc_bios,
1126b843c749SSergey Zigachev CLOCK_SOURCE_COMBO_PHY_PLL0,
1127b843c749SSergey Zigachev &clk_src_regs[0], false);
1128b843c749SSergey Zigachev pool->base.clock_sources[DCE112_CLK_SRC_PLL1] =
1129b843c749SSergey Zigachev dce112_clock_source_create(
1130b843c749SSergey Zigachev ctx, ctx->dc_bios,
1131b843c749SSergey Zigachev CLOCK_SOURCE_COMBO_PHY_PLL1,
1132b843c749SSergey Zigachev &clk_src_regs[1], false);
1133b843c749SSergey Zigachev pool->base.clock_sources[DCE112_CLK_SRC_PLL2] =
1134b843c749SSergey Zigachev dce112_clock_source_create(
1135b843c749SSergey Zigachev ctx, ctx->dc_bios,
1136b843c749SSergey Zigachev CLOCK_SOURCE_COMBO_PHY_PLL2,
1137b843c749SSergey Zigachev &clk_src_regs[2], false);
1138b843c749SSergey Zigachev pool->base.clock_sources[DCE112_CLK_SRC_PLL3] =
1139b843c749SSergey Zigachev dce112_clock_source_create(
1140b843c749SSergey Zigachev ctx, ctx->dc_bios,
1141b843c749SSergey Zigachev CLOCK_SOURCE_COMBO_PHY_PLL3,
1142b843c749SSergey Zigachev &clk_src_regs[3], false);
1143b843c749SSergey Zigachev pool->base.clock_sources[DCE112_CLK_SRC_PLL4] =
1144b843c749SSergey Zigachev dce112_clock_source_create(
1145b843c749SSergey Zigachev ctx, ctx->dc_bios,
1146b843c749SSergey Zigachev CLOCK_SOURCE_COMBO_PHY_PLL4,
1147b843c749SSergey Zigachev &clk_src_regs[4], false);
1148b843c749SSergey Zigachev pool->base.clock_sources[DCE112_CLK_SRC_PLL5] =
1149b843c749SSergey Zigachev dce112_clock_source_create(
1150b843c749SSergey Zigachev ctx, ctx->dc_bios,
1151b843c749SSergey Zigachev CLOCK_SOURCE_COMBO_PHY_PLL5,
1152b843c749SSergey Zigachev &clk_src_regs[5], false);
1153b843c749SSergey Zigachev pool->base.clk_src_count = DCE112_CLK_SRC_TOTAL;
1154b843c749SSergey Zigachev
1155b843c749SSergey Zigachev pool->base.dp_clock_source = dce112_clock_source_create(
1156b843c749SSergey Zigachev ctx, ctx->dc_bios,
1157b843c749SSergey Zigachev CLOCK_SOURCE_ID_DP_DTO, &clk_src_regs[0], true);
1158b843c749SSergey Zigachev
1159b843c749SSergey Zigachev
1160b843c749SSergey Zigachev for (i = 0; i < pool->base.clk_src_count; i++) {
1161b843c749SSergey Zigachev if (pool->base.clock_sources[i] == NULL) {
1162b843c749SSergey Zigachev dm_error("DC: failed to create clock sources!\n");
1163b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1164b843c749SSergey Zigachev goto res_create_fail;
1165b843c749SSergey Zigachev }
1166b843c749SSergey Zigachev }
1167b843c749SSergey Zigachev
1168b843c749SSergey Zigachev pool->base.dccg = dce112_dccg_create(ctx,
1169b843c749SSergey Zigachev &disp_clk_regs,
1170b843c749SSergey Zigachev &disp_clk_shift,
1171b843c749SSergey Zigachev &disp_clk_mask);
1172b843c749SSergey Zigachev if (pool->base.dccg == NULL) {
1173b843c749SSergey Zigachev dm_error("DC: failed to create display clock!\n");
1174b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1175b843c749SSergey Zigachev goto res_create_fail;
1176b843c749SSergey Zigachev }
1177b843c749SSergey Zigachev
1178b843c749SSergey Zigachev pool->base.dmcu = dce_dmcu_create(ctx,
1179b843c749SSergey Zigachev &dmcu_regs,
1180b843c749SSergey Zigachev &dmcu_shift,
1181b843c749SSergey Zigachev &dmcu_mask);
1182b843c749SSergey Zigachev if (pool->base.dmcu == NULL) {
1183b843c749SSergey Zigachev dm_error("DC: failed to create dmcu!\n");
1184b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1185b843c749SSergey Zigachev goto res_create_fail;
1186b843c749SSergey Zigachev }
1187b843c749SSergey Zigachev
1188b843c749SSergey Zigachev pool->base.abm = dce_abm_create(ctx,
1189b843c749SSergey Zigachev &abm_regs,
1190b843c749SSergey Zigachev &abm_shift,
1191b843c749SSergey Zigachev &abm_mask);
1192b843c749SSergey Zigachev if (pool->base.abm == NULL) {
1193b843c749SSergey Zigachev dm_error("DC: failed to create abm!\n");
1194b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1195b843c749SSergey Zigachev goto res_create_fail;
1196b843c749SSergey Zigachev }
1197b843c749SSergey Zigachev
1198b843c749SSergey Zigachev /* get static clock information for PPLIB or firmware, save
1199b843c749SSergey Zigachev * max_clock_state
1200b843c749SSergey Zigachev */
1201b843c749SSergey Zigachev if (dm_pp_get_static_clocks(ctx, &static_clk_info))
1202b843c749SSergey Zigachev pool->base.dccg->max_clks_state =
1203b843c749SSergey Zigachev static_clk_info.max_clocks_state;
1204b843c749SSergey Zigachev
1205b843c749SSergey Zigachev {
1206b843c749SSergey Zigachev struct irq_service_init_data init_data;
1207b843c749SSergey Zigachev init_data.ctx = dc->ctx;
1208b843c749SSergey Zigachev pool->base.irqs = dal_irq_service_dce110_create(&init_data);
1209b843c749SSergey Zigachev if (!pool->base.irqs)
1210b843c749SSergey Zigachev goto res_create_fail;
1211b843c749SSergey Zigachev }
1212b843c749SSergey Zigachev
1213b843c749SSergey Zigachev for (i = 0; i < pool->base.pipe_count; i++) {
1214b843c749SSergey Zigachev pool->base.timing_generators[i] =
1215b843c749SSergey Zigachev dce112_timing_generator_create(
1216b843c749SSergey Zigachev ctx,
1217b843c749SSergey Zigachev i,
1218b843c749SSergey Zigachev &dce112_tg_offsets[i]);
1219b843c749SSergey Zigachev if (pool->base.timing_generators[i] == NULL) {
1220b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1221b843c749SSergey Zigachev dm_error("DC: failed to create tg!\n");
1222b843c749SSergey Zigachev goto res_create_fail;
1223b843c749SSergey Zigachev }
1224b843c749SSergey Zigachev
1225b843c749SSergey Zigachev pool->base.mis[i] = dce112_mem_input_create(ctx, i);
1226b843c749SSergey Zigachev if (pool->base.mis[i] == NULL) {
1227b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1228b843c749SSergey Zigachev dm_error(
1229b843c749SSergey Zigachev "DC: failed to create memory input!\n");
1230b843c749SSergey Zigachev goto res_create_fail;
1231b843c749SSergey Zigachev }
1232b843c749SSergey Zigachev
1233b843c749SSergey Zigachev pool->base.ipps[i] = dce112_ipp_create(ctx, i);
1234b843c749SSergey Zigachev if (pool->base.ipps[i] == NULL) {
1235b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1236b843c749SSergey Zigachev dm_error(
1237b843c749SSergey Zigachev "DC:failed to create input pixel processor!\n");
1238b843c749SSergey Zigachev goto res_create_fail;
1239b843c749SSergey Zigachev }
1240b843c749SSergey Zigachev
1241b843c749SSergey Zigachev pool->base.transforms[i] = dce112_transform_create(ctx, i);
1242b843c749SSergey Zigachev if (pool->base.transforms[i] == NULL) {
1243b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1244b843c749SSergey Zigachev dm_error(
1245b843c749SSergey Zigachev "DC: failed to create transform!\n");
1246b843c749SSergey Zigachev goto res_create_fail;
1247b843c749SSergey Zigachev }
1248b843c749SSergey Zigachev
1249b843c749SSergey Zigachev pool->base.opps[i] = dce112_opp_create(
1250b843c749SSergey Zigachev ctx,
1251b843c749SSergey Zigachev i);
1252b843c749SSergey Zigachev if (pool->base.opps[i] == NULL) {
1253b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1254b843c749SSergey Zigachev dm_error(
1255b843c749SSergey Zigachev "DC:failed to create output pixel processor!\n");
1256b843c749SSergey Zigachev goto res_create_fail;
1257b843c749SSergey Zigachev }
1258b843c749SSergey Zigachev pool->base.engines[i] = dce112_aux_engine_create(ctx, i);
1259b843c749SSergey Zigachev if (pool->base.engines[i] == NULL) {
1260b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1261b843c749SSergey Zigachev dm_error(
1262b843c749SSergey Zigachev "DC:failed to create aux engine!!\n");
1263b843c749SSergey Zigachev goto res_create_fail;
1264b843c749SSergey Zigachev }
1265b843c749SSergey Zigachev }
1266b843c749SSergey Zigachev
1267b843c749SSergey Zigachev if (!resource_construct(num_virtual_links, dc, &pool->base,
1268b843c749SSergey Zigachev &res_create_funcs))
1269b843c749SSergey Zigachev goto res_create_fail;
1270b843c749SSergey Zigachev
1271b843c749SSergey Zigachev dc->caps.max_planes = pool->base.pipe_count;
1272b843c749SSergey Zigachev
1273b843c749SSergey Zigachev /* Create hardware sequencer */
1274b843c749SSergey Zigachev dce112_hw_sequencer_construct(dc);
1275b843c749SSergey Zigachev
1276b843c749SSergey Zigachev bw_calcs_init(dc->bw_dceip, dc->bw_vbios, dc->ctx->asic_id);
1277b843c749SSergey Zigachev
1278b843c749SSergey Zigachev bw_calcs_data_update_from_pplib(dc);
1279b843c749SSergey Zigachev
1280b843c749SSergey Zigachev return true;
1281b843c749SSergey Zigachev
1282b843c749SSergey Zigachev res_create_fail:
1283b843c749SSergey Zigachev destruct(pool);
1284b843c749SSergey Zigachev return false;
1285b843c749SSergey Zigachev }
1286b843c749SSergey Zigachev
dce112_create_resource_pool(uint8_t num_virtual_links,struct dc * dc)1287b843c749SSergey Zigachev struct resource_pool *dce112_create_resource_pool(
1288b843c749SSergey Zigachev uint8_t num_virtual_links,
1289b843c749SSergey Zigachev struct dc *dc)
1290b843c749SSergey Zigachev {
1291b843c749SSergey Zigachev struct dce110_resource_pool *pool =
1292b843c749SSergey Zigachev kzalloc(sizeof(struct dce110_resource_pool), GFP_KERNEL);
1293b843c749SSergey Zigachev
1294b843c749SSergey Zigachev if (!pool)
1295b843c749SSergey Zigachev return NULL;
1296b843c749SSergey Zigachev
1297b843c749SSergey Zigachev if (construct(num_virtual_links, dc, pool))
1298b843c749SSergey Zigachev return &pool->base;
1299b843c749SSergey Zigachev
1300b843c749SSergey Zigachev kfree(pool);
1301b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1302b843c749SSergey Zigachev return NULL;
1303b843c749SSergey Zigachev }
1304