xref: /dflybsd-src/sys/dev/drm/amd/amdgpu/vi.c (revision 789731325bde747251c28a37e0a00ed4efb88c46)
1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2014 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  */
23b843c749SSergey Zigachev #include <linux/slab.h>
24b843c749SSergey Zigachev #include <drm/drmP.h>
25b843c749SSergey Zigachev #include "amdgpu.h"
26b843c749SSergey Zigachev #include "amdgpu_atombios.h"
27b843c749SSergey Zigachev #include "amdgpu_ih.h"
28b843c749SSergey Zigachev #include "amdgpu_uvd.h"
29b843c749SSergey Zigachev #include "amdgpu_vce.h"
30b843c749SSergey Zigachev #include "amdgpu_ucode.h"
31b843c749SSergey Zigachev #include "atom.h"
32b843c749SSergey Zigachev #include "amd_pcie.h"
33b843c749SSergey Zigachev 
34b843c749SSergey Zigachev #include "gmc/gmc_8_1_d.h"
35b843c749SSergey Zigachev #include "gmc/gmc_8_1_sh_mask.h"
36b843c749SSergey Zigachev 
37b843c749SSergey Zigachev #include "oss/oss_3_0_d.h"
38b843c749SSergey Zigachev #include "oss/oss_3_0_sh_mask.h"
39b843c749SSergey Zigachev 
40b843c749SSergey Zigachev #include "bif/bif_5_0_d.h"
41b843c749SSergey Zigachev #include "bif/bif_5_0_sh_mask.h"
42b843c749SSergey Zigachev 
43b843c749SSergey Zigachev #include "gca/gfx_8_0_d.h"
44b843c749SSergey Zigachev #include "gca/gfx_8_0_sh_mask.h"
45b843c749SSergey Zigachev 
46b843c749SSergey Zigachev #include "smu/smu_7_1_1_d.h"
47b843c749SSergey Zigachev #include "smu/smu_7_1_1_sh_mask.h"
48b843c749SSergey Zigachev 
49b843c749SSergey Zigachev #include "uvd/uvd_5_0_d.h"
50b843c749SSergey Zigachev #include "uvd/uvd_5_0_sh_mask.h"
51b843c749SSergey Zigachev 
52b843c749SSergey Zigachev #include "vce/vce_3_0_d.h"
53b843c749SSergey Zigachev #include "vce/vce_3_0_sh_mask.h"
54b843c749SSergey Zigachev 
55b843c749SSergey Zigachev #include "dce/dce_10_0_d.h"
56b843c749SSergey Zigachev #include "dce/dce_10_0_sh_mask.h"
57b843c749SSergey Zigachev 
58b843c749SSergey Zigachev #include "vid.h"
59b843c749SSergey Zigachev #include "vi.h"
60b843c749SSergey Zigachev #include "vi_dpm.h"
61b843c749SSergey Zigachev #include "gmc_v8_0.h"
62b843c749SSergey Zigachev #include "gmc_v7_0.h"
63b843c749SSergey Zigachev #include "gfx_v8_0.h"
64b843c749SSergey Zigachev #include "sdma_v2_4.h"
65b843c749SSergey Zigachev #include "sdma_v3_0.h"
66b843c749SSergey Zigachev #include "dce_v10_0.h"
67b843c749SSergey Zigachev #include "dce_v11_0.h"
68b843c749SSergey Zigachev #include "iceland_ih.h"
69b843c749SSergey Zigachev #include "tonga_ih.h"
70b843c749SSergey Zigachev #include "cz_ih.h"
71b843c749SSergey Zigachev #include "uvd_v5_0.h"
72b843c749SSergey Zigachev #include "uvd_v6_0.h"
73b843c749SSergey Zigachev #include "vce_v3_0.h"
74b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_ACP)
75b843c749SSergey Zigachev #include "amdgpu_acp.h"
76b843c749SSergey Zigachev #endif
77b843c749SSergey Zigachev #include "dce_virtual.h"
78b843c749SSergey Zigachev #include "mxgpu_vi.h"
79b843c749SSergey Zigachev #include "amdgpu_dm.h"
80b843c749SSergey Zigachev 
81b843c749SSergey Zigachev /*
82b843c749SSergey Zigachev  * Indirect registers accessor
83b843c749SSergey Zigachev  */
vi_pcie_rreg(struct amdgpu_device * adev,u32 reg)84b843c749SSergey Zigachev static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
85b843c749SSergey Zigachev {
86b843c749SSergey Zigachev 	unsigned long flags;
87b843c749SSergey Zigachev 	u32 r;
88b843c749SSergey Zigachev 
89b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
90b843c749SSergey Zigachev 	WREG32(mmPCIE_INDEX, reg);
91b843c749SSergey Zigachev 	(void)RREG32(mmPCIE_INDEX);
92b843c749SSergey Zigachev 	r = RREG32(mmPCIE_DATA);
93b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
94b843c749SSergey Zigachev 	return r;
95b843c749SSergey Zigachev }
96b843c749SSergey Zigachev 
vi_pcie_wreg(struct amdgpu_device * adev,u32 reg,u32 v)97b843c749SSergey Zigachev static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
98b843c749SSergey Zigachev {
99b843c749SSergey Zigachev 	unsigned long flags;
100b843c749SSergey Zigachev 
101b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
102b843c749SSergey Zigachev 	WREG32(mmPCIE_INDEX, reg);
103b843c749SSergey Zigachev 	(void)RREG32(mmPCIE_INDEX);
104b843c749SSergey Zigachev 	WREG32(mmPCIE_DATA, v);
105b843c749SSergey Zigachev 	(void)RREG32(mmPCIE_DATA);
106b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
107b843c749SSergey Zigachev }
108b843c749SSergey Zigachev 
vi_smc_rreg(struct amdgpu_device * adev,u32 reg)109b843c749SSergey Zigachev static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
110b843c749SSergey Zigachev {
111b843c749SSergey Zigachev 	unsigned long flags;
112b843c749SSergey Zigachev 	u32 r;
113b843c749SSergey Zigachev 
114b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->smc_idx_lock, flags);
115b843c749SSergey Zigachev 	WREG32_NO_KIQ(mmSMC_IND_INDEX_11, (reg));
116b843c749SSergey Zigachev 	r = RREG32_NO_KIQ(mmSMC_IND_DATA_11);
117b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
118b843c749SSergey Zigachev 	return r;
119b843c749SSergey Zigachev }
120b843c749SSergey Zigachev 
vi_smc_wreg(struct amdgpu_device * adev,u32 reg,u32 v)121b843c749SSergey Zigachev static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
122b843c749SSergey Zigachev {
123b843c749SSergey Zigachev 	unsigned long flags;
124b843c749SSergey Zigachev 
125b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->smc_idx_lock, flags);
126b843c749SSergey Zigachev 	WREG32(mmSMC_IND_INDEX_11, (reg));
127b843c749SSergey Zigachev 	WREG32(mmSMC_IND_DATA_11, (v));
128b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
129b843c749SSergey Zigachev }
130b843c749SSergey Zigachev 
131b843c749SSergey Zigachev /* smu_8_0_d.h */
132b843c749SSergey Zigachev #define mmMP0PUB_IND_INDEX                                                      0x180
133b843c749SSergey Zigachev #define mmMP0PUB_IND_DATA                                                       0x181
134b843c749SSergey Zigachev 
cz_smc_rreg(struct amdgpu_device * adev,u32 reg)135b843c749SSergey Zigachev static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
136b843c749SSergey Zigachev {
137b843c749SSergey Zigachev 	unsigned long flags;
138b843c749SSergey Zigachev 	u32 r;
139b843c749SSergey Zigachev 
140b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->smc_idx_lock, flags);
141b843c749SSergey Zigachev 	WREG32(mmMP0PUB_IND_INDEX, (reg));
142b843c749SSergey Zigachev 	r = RREG32(mmMP0PUB_IND_DATA);
143b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
144b843c749SSergey Zigachev 	return r;
145b843c749SSergey Zigachev }
146b843c749SSergey Zigachev 
cz_smc_wreg(struct amdgpu_device * adev,u32 reg,u32 v)147b843c749SSergey Zigachev static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
148b843c749SSergey Zigachev {
149b843c749SSergey Zigachev 	unsigned long flags;
150b843c749SSergey Zigachev 
151b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->smc_idx_lock, flags);
152b843c749SSergey Zigachev 	WREG32(mmMP0PUB_IND_INDEX, (reg));
153b843c749SSergey Zigachev 	WREG32(mmMP0PUB_IND_DATA, (v));
154b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
155b843c749SSergey Zigachev }
156b843c749SSergey Zigachev 
vi_uvd_ctx_rreg(struct amdgpu_device * adev,u32 reg)157b843c749SSergey Zigachev static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
158b843c749SSergey Zigachev {
159b843c749SSergey Zigachev 	unsigned long flags;
160b843c749SSergey Zigachev 	u32 r;
161b843c749SSergey Zigachev 
162b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
163b843c749SSergey Zigachev 	WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
164b843c749SSergey Zigachev 	r = RREG32(mmUVD_CTX_DATA);
165b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
166b843c749SSergey Zigachev 	return r;
167b843c749SSergey Zigachev }
168b843c749SSergey Zigachev 
vi_uvd_ctx_wreg(struct amdgpu_device * adev,u32 reg,u32 v)169b843c749SSergey Zigachev static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
170b843c749SSergey Zigachev {
171b843c749SSergey Zigachev 	unsigned long flags;
172b843c749SSergey Zigachev 
173b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
174b843c749SSergey Zigachev 	WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
175b843c749SSergey Zigachev 	WREG32(mmUVD_CTX_DATA, (v));
176b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
177b843c749SSergey Zigachev }
178b843c749SSergey Zigachev 
vi_didt_rreg(struct amdgpu_device * adev,u32 reg)179b843c749SSergey Zigachev static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
180b843c749SSergey Zigachev {
181b843c749SSergey Zigachev 	unsigned long flags;
182b843c749SSergey Zigachev 	u32 r;
183b843c749SSergey Zigachev 
184b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->didt_idx_lock, flags);
185b843c749SSergey Zigachev 	WREG32(mmDIDT_IND_INDEX, (reg));
186b843c749SSergey Zigachev 	r = RREG32(mmDIDT_IND_DATA);
187b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
188b843c749SSergey Zigachev 	return r;
189b843c749SSergey Zigachev }
190b843c749SSergey Zigachev 
vi_didt_wreg(struct amdgpu_device * adev,u32 reg,u32 v)191b843c749SSergey Zigachev static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
192b843c749SSergey Zigachev {
193b843c749SSergey Zigachev 	unsigned long flags;
194b843c749SSergey Zigachev 
195b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->didt_idx_lock, flags);
196b843c749SSergey Zigachev 	WREG32(mmDIDT_IND_INDEX, (reg));
197b843c749SSergey Zigachev 	WREG32(mmDIDT_IND_DATA, (v));
198b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
199b843c749SSergey Zigachev }
200b843c749SSergey Zigachev 
vi_gc_cac_rreg(struct amdgpu_device * adev,u32 reg)201b843c749SSergey Zigachev static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
202b843c749SSergey Zigachev {
203b843c749SSergey Zigachev 	unsigned long flags;
204b843c749SSergey Zigachev 	u32 r;
205b843c749SSergey Zigachev 
206b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
207b843c749SSergey Zigachev 	WREG32(mmGC_CAC_IND_INDEX, (reg));
208b843c749SSergey Zigachev 	r = RREG32(mmGC_CAC_IND_DATA);
209b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
210b843c749SSergey Zigachev 	return r;
211b843c749SSergey Zigachev }
212b843c749SSergey Zigachev 
vi_gc_cac_wreg(struct amdgpu_device * adev,u32 reg,u32 v)213b843c749SSergey Zigachev static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
214b843c749SSergey Zigachev {
215b843c749SSergey Zigachev 	unsigned long flags;
216b843c749SSergey Zigachev 
217b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
218b843c749SSergey Zigachev 	WREG32(mmGC_CAC_IND_INDEX, (reg));
219b843c749SSergey Zigachev 	WREG32(mmGC_CAC_IND_DATA, (v));
220b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
221b843c749SSergey Zigachev }
222b843c749SSergey Zigachev 
223b843c749SSergey Zigachev 
224b843c749SSergey Zigachev static const u32 tonga_mgcg_cgcg_init[] =
225b843c749SSergey Zigachev {
226b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
227b843c749SSergey Zigachev 	mmPCIE_INDEX, 0xffffffff, 0x0140001c,
228b843c749SSergey Zigachev 	mmPCIE_DATA, 0x000f0000, 0x00000000,
229b843c749SSergey Zigachev 	mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
230b843c749SSergey Zigachev 	mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
231b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
232b843c749SSergey Zigachev 	mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
233b843c749SSergey Zigachev };
234b843c749SSergey Zigachev 
235b843c749SSergey Zigachev static const u32 fiji_mgcg_cgcg_init[] =
236b843c749SSergey Zigachev {
237b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
238b843c749SSergey Zigachev 	mmPCIE_INDEX, 0xffffffff, 0x0140001c,
239b843c749SSergey Zigachev 	mmPCIE_DATA, 0x000f0000, 0x00000000,
240b843c749SSergey Zigachev 	mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
241b843c749SSergey Zigachev 	mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
242b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
243b843c749SSergey Zigachev 	mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
244b843c749SSergey Zigachev };
245b843c749SSergey Zigachev 
246b843c749SSergey Zigachev static const u32 iceland_mgcg_cgcg_init[] =
247b843c749SSergey Zigachev {
248b843c749SSergey Zigachev 	mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
249b843c749SSergey Zigachev 	mmPCIE_DATA, 0x000f0000, 0x00000000,
250b843c749SSergey Zigachev 	mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
251b843c749SSergey Zigachev 	mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
252b843c749SSergey Zigachev 	mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
253b843c749SSergey Zigachev };
254b843c749SSergey Zigachev 
255b843c749SSergey Zigachev static const u32 cz_mgcg_cgcg_init[] =
256b843c749SSergey Zigachev {
257b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
258b843c749SSergey Zigachev 	mmPCIE_INDEX, 0xffffffff, 0x0140001c,
259b843c749SSergey Zigachev 	mmPCIE_DATA, 0x000f0000, 0x00000000,
260b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
261b843c749SSergey Zigachev 	mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
262b843c749SSergey Zigachev };
263b843c749SSergey Zigachev 
264b843c749SSergey Zigachev static const u32 stoney_mgcg_cgcg_init[] =
265b843c749SSergey Zigachev {
266b843c749SSergey Zigachev 	mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
267b843c749SSergey Zigachev 	mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
268b843c749SSergey Zigachev 	mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
269b843c749SSergey Zigachev };
270b843c749SSergey Zigachev 
vi_init_golden_registers(struct amdgpu_device * adev)271b843c749SSergey Zigachev static void vi_init_golden_registers(struct amdgpu_device *adev)
272b843c749SSergey Zigachev {
273b843c749SSergey Zigachev 	/* Some of the registers might be dependent on GRBM_GFX_INDEX */
274b843c749SSergey Zigachev 	mutex_lock(&adev->grbm_idx_mutex);
275b843c749SSergey Zigachev 
276b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev)) {
277b843c749SSergey Zigachev 		xgpu_vi_init_golden_registers(adev);
278b843c749SSergey Zigachev 		mutex_unlock(&adev->grbm_idx_mutex);
279b843c749SSergey Zigachev 		return;
280b843c749SSergey Zigachev 	}
281b843c749SSergey Zigachev 
282b843c749SSergey Zigachev 	switch (adev->asic_type) {
283b843c749SSergey Zigachev 	case CHIP_TOPAZ:
284b843c749SSergey Zigachev 		amdgpu_device_program_register_sequence(adev,
285b843c749SSergey Zigachev 							iceland_mgcg_cgcg_init,
286b843c749SSergey Zigachev 							ARRAY_SIZE(iceland_mgcg_cgcg_init));
287b843c749SSergey Zigachev 		break;
288b843c749SSergey Zigachev 	case CHIP_FIJI:
289b843c749SSergey Zigachev 		amdgpu_device_program_register_sequence(adev,
290b843c749SSergey Zigachev 							fiji_mgcg_cgcg_init,
291b843c749SSergey Zigachev 							ARRAY_SIZE(fiji_mgcg_cgcg_init));
292b843c749SSergey Zigachev 		break;
293b843c749SSergey Zigachev 	case CHIP_TONGA:
294b843c749SSergey Zigachev 		amdgpu_device_program_register_sequence(adev,
295b843c749SSergey Zigachev 							tonga_mgcg_cgcg_init,
296b843c749SSergey Zigachev 							ARRAY_SIZE(tonga_mgcg_cgcg_init));
297b843c749SSergey Zigachev 		break;
298b843c749SSergey Zigachev 	case CHIP_CARRIZO:
299b843c749SSergey Zigachev 		amdgpu_device_program_register_sequence(adev,
300b843c749SSergey Zigachev 							cz_mgcg_cgcg_init,
301b843c749SSergey Zigachev 							ARRAY_SIZE(cz_mgcg_cgcg_init));
302b843c749SSergey Zigachev 		break;
303b843c749SSergey Zigachev 	case CHIP_STONEY:
304b843c749SSergey Zigachev 		amdgpu_device_program_register_sequence(adev,
305b843c749SSergey Zigachev 							stoney_mgcg_cgcg_init,
306b843c749SSergey Zigachev 							ARRAY_SIZE(stoney_mgcg_cgcg_init));
307b843c749SSergey Zigachev 		break;
308b843c749SSergey Zigachev 	case CHIP_POLARIS10:
309b843c749SSergey Zigachev 	case CHIP_POLARIS11:
310b843c749SSergey Zigachev 	case CHIP_POLARIS12:
311b843c749SSergey Zigachev 	case CHIP_VEGAM:
312b843c749SSergey Zigachev 	default:
313b843c749SSergey Zigachev 		break;
314b843c749SSergey Zigachev 	}
315b843c749SSergey Zigachev 	mutex_unlock(&adev->grbm_idx_mutex);
316b843c749SSergey Zigachev }
317b843c749SSergey Zigachev 
318b843c749SSergey Zigachev /**
319b843c749SSergey Zigachev  * vi_get_xclk - get the xclk
320b843c749SSergey Zigachev  *
321b843c749SSergey Zigachev  * @adev: amdgpu_device pointer
322b843c749SSergey Zigachev  *
323b843c749SSergey Zigachev  * Returns the reference clock used by the gfx engine
324b843c749SSergey Zigachev  * (VI).
325b843c749SSergey Zigachev  */
vi_get_xclk(struct amdgpu_device * adev)326b843c749SSergey Zigachev static u32 vi_get_xclk(struct amdgpu_device *adev)
327b843c749SSergey Zigachev {
328b843c749SSergey Zigachev 	u32 reference_clock = adev->clock.spll.reference_freq;
329b843c749SSergey Zigachev 	u32 tmp;
330b843c749SSergey Zigachev 
331b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU)
332b843c749SSergey Zigachev 		return reference_clock;
333b843c749SSergey Zigachev 
334b843c749SSergey Zigachev 	tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
335b843c749SSergey Zigachev 	if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
336b843c749SSergey Zigachev 		return 1000;
337b843c749SSergey Zigachev 
338b843c749SSergey Zigachev 	tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
339b843c749SSergey Zigachev 	if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
340b843c749SSergey Zigachev 		return reference_clock / 4;
341b843c749SSergey Zigachev 
342b843c749SSergey Zigachev 	return reference_clock;
343b843c749SSergey Zigachev }
344b843c749SSergey Zigachev 
345b843c749SSergey Zigachev /**
346b843c749SSergey Zigachev  * vi_srbm_select - select specific register instances
347b843c749SSergey Zigachev  *
348b843c749SSergey Zigachev  * @adev: amdgpu_device pointer
349b843c749SSergey Zigachev  * @me: selected ME (micro engine)
350b843c749SSergey Zigachev  * @pipe: pipe
351b843c749SSergey Zigachev  * @queue: queue
352b843c749SSergey Zigachev  * @vmid: VMID
353b843c749SSergey Zigachev  *
354b843c749SSergey Zigachev  * Switches the currently active registers instances.  Some
355b843c749SSergey Zigachev  * registers are instanced per VMID, others are instanced per
356b843c749SSergey Zigachev  * me/pipe/queue combination.
357b843c749SSergey Zigachev  */
vi_srbm_select(struct amdgpu_device * adev,u32 me,u32 pipe,u32 queue,u32 vmid)358b843c749SSergey Zigachev void vi_srbm_select(struct amdgpu_device *adev,
359b843c749SSergey Zigachev 		     u32 me, u32 pipe, u32 queue, u32 vmid)
360b843c749SSergey Zigachev {
361b843c749SSergey Zigachev 	u32 srbm_gfx_cntl = 0;
362b843c749SSergey Zigachev 	srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
363b843c749SSergey Zigachev 	srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
364b843c749SSergey Zigachev 	srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
365b843c749SSergey Zigachev 	srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
366b843c749SSergey Zigachev 	WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
367b843c749SSergey Zigachev }
368b843c749SSergey Zigachev 
vi_vga_set_state(struct amdgpu_device * adev,bool state)369b843c749SSergey Zigachev static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
370b843c749SSergey Zigachev {
371b843c749SSergey Zigachev 	/* todo */
372b843c749SSergey Zigachev }
373b843c749SSergey Zigachev 
vi_read_disabled_bios(struct amdgpu_device * adev)374b843c749SSergey Zigachev static bool vi_read_disabled_bios(struct amdgpu_device *adev)
375b843c749SSergey Zigachev {
376b843c749SSergey Zigachev 	u32 bus_cntl;
377b843c749SSergey Zigachev 	u32 d1vga_control = 0;
378b843c749SSergey Zigachev 	u32 d2vga_control = 0;
379b843c749SSergey Zigachev 	u32 vga_render_control = 0;
380b843c749SSergey Zigachev 	u32 rom_cntl;
381b843c749SSergey Zigachev 	bool r;
382b843c749SSergey Zigachev 
383b843c749SSergey Zigachev 	bus_cntl = RREG32(mmBUS_CNTL);
384b843c749SSergey Zigachev 	if (adev->mode_info.num_crtc) {
385b843c749SSergey Zigachev 		d1vga_control = RREG32(mmD1VGA_CONTROL);
386b843c749SSergey Zigachev 		d2vga_control = RREG32(mmD2VGA_CONTROL);
387b843c749SSergey Zigachev 		vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
388b843c749SSergey Zigachev 	}
389b843c749SSergey Zigachev 	rom_cntl = RREG32_SMC(ixROM_CNTL);
390b843c749SSergey Zigachev 
391b843c749SSergey Zigachev 	/* enable the rom */
392b843c749SSergey Zigachev 	WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
393b843c749SSergey Zigachev 	if (adev->mode_info.num_crtc) {
394b843c749SSergey Zigachev 		/* Disable VGA mode */
395b843c749SSergey Zigachev 		WREG32(mmD1VGA_CONTROL,
396b843c749SSergey Zigachev 		       (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
397b843c749SSergey Zigachev 					  D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
398b843c749SSergey Zigachev 		WREG32(mmD2VGA_CONTROL,
399b843c749SSergey Zigachev 		       (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
400b843c749SSergey Zigachev 					  D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
401b843c749SSergey Zigachev 		WREG32(mmVGA_RENDER_CONTROL,
402b843c749SSergey Zigachev 		       (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
403b843c749SSergey Zigachev 	}
404b843c749SSergey Zigachev 	WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
405b843c749SSergey Zigachev 
406b843c749SSergey Zigachev 	r = amdgpu_read_bios(adev);
407b843c749SSergey Zigachev 
408b843c749SSergey Zigachev 	/* restore regs */
409b843c749SSergey Zigachev 	WREG32(mmBUS_CNTL, bus_cntl);
410b843c749SSergey Zigachev 	if (adev->mode_info.num_crtc) {
411b843c749SSergey Zigachev 		WREG32(mmD1VGA_CONTROL, d1vga_control);
412b843c749SSergey Zigachev 		WREG32(mmD2VGA_CONTROL, d2vga_control);
413b843c749SSergey Zigachev 		WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
414b843c749SSergey Zigachev 	}
415b843c749SSergey Zigachev 	WREG32_SMC(ixROM_CNTL, rom_cntl);
416b843c749SSergey Zigachev 	return r;
417b843c749SSergey Zigachev }
418b843c749SSergey Zigachev 
vi_read_bios_from_rom(struct amdgpu_device * adev,u8 * bios,u32 length_bytes)419b843c749SSergey Zigachev static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
420b843c749SSergey Zigachev 				  u8 *bios, u32 length_bytes)
421b843c749SSergey Zigachev {
422b843c749SSergey Zigachev 	u32 *dw_ptr;
423b843c749SSergey Zigachev 	unsigned long flags;
424b843c749SSergey Zigachev 	u32 i, length_dw;
425b843c749SSergey Zigachev 
426b843c749SSergey Zigachev 	if (bios == NULL)
427b843c749SSergey Zigachev 		return false;
428b843c749SSergey Zigachev 	if (length_bytes == 0)
429b843c749SSergey Zigachev 		return false;
430b843c749SSergey Zigachev 	/* APU vbios image is part of sbios image */
431b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU)
432b843c749SSergey Zigachev 		return false;
433b843c749SSergey Zigachev 
434b843c749SSergey Zigachev 	dw_ptr = (u32 *)bios;
435b843c749SSergey Zigachev 	length_dw = ALIGN(length_bytes, 4) / 4;
436b843c749SSergey Zigachev 	/* take the smc lock since we are using the smc index */
437b843c749SSergey Zigachev 	spin_lock_irqsave(&adev->smc_idx_lock, flags);
438b843c749SSergey Zigachev 	/* set rom index to 0 */
439b843c749SSergey Zigachev 	WREG32(mmSMC_IND_INDEX_11, ixROM_INDEX);
440b843c749SSergey Zigachev 	WREG32(mmSMC_IND_DATA_11, 0);
441b843c749SSergey Zigachev 	/* set index to data for continous read */
442b843c749SSergey Zigachev 	WREG32(mmSMC_IND_INDEX_11, ixROM_DATA);
443b843c749SSergey Zigachev 	for (i = 0; i < length_dw; i++)
444b843c749SSergey Zigachev 		dw_ptr[i] = RREG32(mmSMC_IND_DATA_11);
445b843c749SSergey Zigachev 	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
446b843c749SSergey Zigachev 
447b843c749SSergey Zigachev 	return true;
448b843c749SSergey Zigachev }
449b843c749SSergey Zigachev 
vi_detect_hw_virtualization(struct amdgpu_device * adev)450b843c749SSergey Zigachev static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
451b843c749SSergey Zigachev {
452b843c749SSergey Zigachev 	uint32_t reg = 0;
453b843c749SSergey Zigachev 
454b843c749SSergey Zigachev 	if (adev->asic_type == CHIP_TONGA ||
455b843c749SSergey Zigachev 	    adev->asic_type == CHIP_FIJI) {
456b843c749SSergey Zigachev 	       reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
457b843c749SSergey Zigachev 	       /* bit0: 0 means pf and 1 means vf */
458b843c749SSergey Zigachev 	       if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER))
459b843c749SSergey Zigachev 		       adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF;
460b843c749SSergey Zigachev 	       /* bit31: 0 means disable IOV and 1 means enable */
461b843c749SSergey Zigachev 	       if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE))
462b843c749SSergey Zigachev 		       adev->virt.caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV;
463b843c749SSergey Zigachev 	}
464b843c749SSergey Zigachev 
465b843c749SSergey Zigachev 	if (reg == 0) {
466b843c749SSergey Zigachev 		if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */
467b843c749SSergey Zigachev 			adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE;
468b843c749SSergey Zigachev 	}
469b843c749SSergey Zigachev }
470b843c749SSergey Zigachev 
471b843c749SSergey Zigachev static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
472b843c749SSergey Zigachev 	{mmGRBM_STATUS},
473b843c749SSergey Zigachev 	{mmGRBM_STATUS2},
474b843c749SSergey Zigachev 	{mmGRBM_STATUS_SE0},
475b843c749SSergey Zigachev 	{mmGRBM_STATUS_SE1},
476b843c749SSergey Zigachev 	{mmGRBM_STATUS_SE2},
477b843c749SSergey Zigachev 	{mmGRBM_STATUS_SE3},
478b843c749SSergey Zigachev 	{mmSRBM_STATUS},
479b843c749SSergey Zigachev 	{mmSRBM_STATUS2},
480b843c749SSergey Zigachev 	{mmSRBM_STATUS3},
481b843c749SSergey Zigachev 	{mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET},
482b843c749SSergey Zigachev 	{mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET},
483b843c749SSergey Zigachev 	{mmCP_STAT},
484b843c749SSergey Zigachev 	{mmCP_STALLED_STAT1},
485b843c749SSergey Zigachev 	{mmCP_STALLED_STAT2},
486b843c749SSergey Zigachev 	{mmCP_STALLED_STAT3},
487b843c749SSergey Zigachev 	{mmCP_CPF_BUSY_STAT},
488b843c749SSergey Zigachev 	{mmCP_CPF_STALLED_STAT1},
489b843c749SSergey Zigachev 	{mmCP_CPF_STATUS},
490b843c749SSergey Zigachev 	{mmCP_CPC_BUSY_STAT},
491b843c749SSergey Zigachev 	{mmCP_CPC_STALLED_STAT1},
492b843c749SSergey Zigachev 	{mmCP_CPC_STATUS},
493b843c749SSergey Zigachev 	{mmGB_ADDR_CONFIG},
494b843c749SSergey Zigachev 	{mmMC_ARB_RAMCFG},
495b843c749SSergey Zigachev 	{mmGB_TILE_MODE0},
496b843c749SSergey Zigachev 	{mmGB_TILE_MODE1},
497b843c749SSergey Zigachev 	{mmGB_TILE_MODE2},
498b843c749SSergey Zigachev 	{mmGB_TILE_MODE3},
499b843c749SSergey Zigachev 	{mmGB_TILE_MODE4},
500b843c749SSergey Zigachev 	{mmGB_TILE_MODE5},
501b843c749SSergey Zigachev 	{mmGB_TILE_MODE6},
502b843c749SSergey Zigachev 	{mmGB_TILE_MODE7},
503b843c749SSergey Zigachev 	{mmGB_TILE_MODE8},
504b843c749SSergey Zigachev 	{mmGB_TILE_MODE9},
505b843c749SSergey Zigachev 	{mmGB_TILE_MODE10},
506b843c749SSergey Zigachev 	{mmGB_TILE_MODE11},
507b843c749SSergey Zigachev 	{mmGB_TILE_MODE12},
508b843c749SSergey Zigachev 	{mmGB_TILE_MODE13},
509b843c749SSergey Zigachev 	{mmGB_TILE_MODE14},
510b843c749SSergey Zigachev 	{mmGB_TILE_MODE15},
511b843c749SSergey Zigachev 	{mmGB_TILE_MODE16},
512b843c749SSergey Zigachev 	{mmGB_TILE_MODE17},
513b843c749SSergey Zigachev 	{mmGB_TILE_MODE18},
514b843c749SSergey Zigachev 	{mmGB_TILE_MODE19},
515b843c749SSergey Zigachev 	{mmGB_TILE_MODE20},
516b843c749SSergey Zigachev 	{mmGB_TILE_MODE21},
517b843c749SSergey Zigachev 	{mmGB_TILE_MODE22},
518b843c749SSergey Zigachev 	{mmGB_TILE_MODE23},
519b843c749SSergey Zigachev 	{mmGB_TILE_MODE24},
520b843c749SSergey Zigachev 	{mmGB_TILE_MODE25},
521b843c749SSergey Zigachev 	{mmGB_TILE_MODE26},
522b843c749SSergey Zigachev 	{mmGB_TILE_MODE27},
523b843c749SSergey Zigachev 	{mmGB_TILE_MODE28},
524b843c749SSergey Zigachev 	{mmGB_TILE_MODE29},
525b843c749SSergey Zigachev 	{mmGB_TILE_MODE30},
526b843c749SSergey Zigachev 	{mmGB_TILE_MODE31},
527b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE0},
528b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE1},
529b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE2},
530b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE3},
531b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE4},
532b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE5},
533b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE6},
534b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE7},
535b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE8},
536b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE9},
537b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE10},
538b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE11},
539b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE12},
540b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE13},
541b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE14},
542b843c749SSergey Zigachev 	{mmGB_MACROTILE_MODE15},
543b843c749SSergey Zigachev 	{mmCC_RB_BACKEND_DISABLE, true},
544b843c749SSergey Zigachev 	{mmGC_USER_RB_BACKEND_DISABLE, true},
545b843c749SSergey Zigachev 	{mmGB_BACKEND_MAP, false},
546b843c749SSergey Zigachev 	{mmPA_SC_RASTER_CONFIG, true},
547b843c749SSergey Zigachev 	{mmPA_SC_RASTER_CONFIG_1, true},
548b843c749SSergey Zigachev };
549b843c749SSergey Zigachev 
vi_get_register_value(struct amdgpu_device * adev,bool indexed,u32 se_num,u32 sh_num,u32 reg_offset)550b843c749SSergey Zigachev static uint32_t vi_get_register_value(struct amdgpu_device *adev,
551b843c749SSergey Zigachev 				      bool indexed, u32 se_num,
552b843c749SSergey Zigachev 				      u32 sh_num, u32 reg_offset)
553b843c749SSergey Zigachev {
554b843c749SSergey Zigachev 	if (indexed) {
555b843c749SSergey Zigachev 		uint32_t val;
556b843c749SSergey Zigachev 		unsigned se_idx = (se_num == 0xffffffff) ? 0 : se_num;
557b843c749SSergey Zigachev 		unsigned sh_idx = (sh_num == 0xffffffff) ? 0 : sh_num;
558b843c749SSergey Zigachev 
559b843c749SSergey Zigachev 		switch (reg_offset) {
560b843c749SSergey Zigachev 		case mmCC_RB_BACKEND_DISABLE:
561b843c749SSergey Zigachev 			return adev->gfx.config.rb_config[se_idx][sh_idx].rb_backend_disable;
562b843c749SSergey Zigachev 		case mmGC_USER_RB_BACKEND_DISABLE:
563b843c749SSergey Zigachev 			return adev->gfx.config.rb_config[se_idx][sh_idx].user_rb_backend_disable;
564b843c749SSergey Zigachev 		case mmPA_SC_RASTER_CONFIG:
565b843c749SSergey Zigachev 			return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config;
566b843c749SSergey Zigachev 		case mmPA_SC_RASTER_CONFIG_1:
567b843c749SSergey Zigachev 			return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config_1;
568b843c749SSergey Zigachev 		}
569b843c749SSergey Zigachev 
570b843c749SSergey Zigachev 		mutex_lock(&adev->grbm_idx_mutex);
571b843c749SSergey Zigachev 		if (se_num != 0xffffffff || sh_num != 0xffffffff)
572b843c749SSergey Zigachev 			amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
573b843c749SSergey Zigachev 
574b843c749SSergey Zigachev 		val = RREG32(reg_offset);
575b843c749SSergey Zigachev 
576b843c749SSergey Zigachev 		if (se_num != 0xffffffff || sh_num != 0xffffffff)
577b843c749SSergey Zigachev 			amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
578b843c749SSergey Zigachev 		mutex_unlock(&adev->grbm_idx_mutex);
579b843c749SSergey Zigachev 		return val;
580b843c749SSergey Zigachev 	} else {
581b843c749SSergey Zigachev 		unsigned idx;
582b843c749SSergey Zigachev 
583b843c749SSergey Zigachev 		switch (reg_offset) {
584b843c749SSergey Zigachev 		case mmGB_ADDR_CONFIG:
585b843c749SSergey Zigachev 			return adev->gfx.config.gb_addr_config;
586b843c749SSergey Zigachev 		case mmMC_ARB_RAMCFG:
587b843c749SSergey Zigachev 			return adev->gfx.config.mc_arb_ramcfg;
588b843c749SSergey Zigachev 		case mmGB_TILE_MODE0:
589b843c749SSergey Zigachev 		case mmGB_TILE_MODE1:
590b843c749SSergey Zigachev 		case mmGB_TILE_MODE2:
591b843c749SSergey Zigachev 		case mmGB_TILE_MODE3:
592b843c749SSergey Zigachev 		case mmGB_TILE_MODE4:
593b843c749SSergey Zigachev 		case mmGB_TILE_MODE5:
594b843c749SSergey Zigachev 		case mmGB_TILE_MODE6:
595b843c749SSergey Zigachev 		case mmGB_TILE_MODE7:
596b843c749SSergey Zigachev 		case mmGB_TILE_MODE8:
597b843c749SSergey Zigachev 		case mmGB_TILE_MODE9:
598b843c749SSergey Zigachev 		case mmGB_TILE_MODE10:
599b843c749SSergey Zigachev 		case mmGB_TILE_MODE11:
600b843c749SSergey Zigachev 		case mmGB_TILE_MODE12:
601b843c749SSergey Zigachev 		case mmGB_TILE_MODE13:
602b843c749SSergey Zigachev 		case mmGB_TILE_MODE14:
603b843c749SSergey Zigachev 		case mmGB_TILE_MODE15:
604b843c749SSergey Zigachev 		case mmGB_TILE_MODE16:
605b843c749SSergey Zigachev 		case mmGB_TILE_MODE17:
606b843c749SSergey Zigachev 		case mmGB_TILE_MODE18:
607b843c749SSergey Zigachev 		case mmGB_TILE_MODE19:
608b843c749SSergey Zigachev 		case mmGB_TILE_MODE20:
609b843c749SSergey Zigachev 		case mmGB_TILE_MODE21:
610b843c749SSergey Zigachev 		case mmGB_TILE_MODE22:
611b843c749SSergey Zigachev 		case mmGB_TILE_MODE23:
612b843c749SSergey Zigachev 		case mmGB_TILE_MODE24:
613b843c749SSergey Zigachev 		case mmGB_TILE_MODE25:
614b843c749SSergey Zigachev 		case mmGB_TILE_MODE26:
615b843c749SSergey Zigachev 		case mmGB_TILE_MODE27:
616b843c749SSergey Zigachev 		case mmGB_TILE_MODE28:
617b843c749SSergey Zigachev 		case mmGB_TILE_MODE29:
618b843c749SSergey Zigachev 		case mmGB_TILE_MODE30:
619b843c749SSergey Zigachev 		case mmGB_TILE_MODE31:
620b843c749SSergey Zigachev 			idx = (reg_offset - mmGB_TILE_MODE0);
621b843c749SSergey Zigachev 			return adev->gfx.config.tile_mode_array[idx];
622b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE0:
623b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE1:
624b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE2:
625b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE3:
626b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE4:
627b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE5:
628b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE6:
629b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE7:
630b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE8:
631b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE9:
632b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE10:
633b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE11:
634b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE12:
635b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE13:
636b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE14:
637b843c749SSergey Zigachev 		case mmGB_MACROTILE_MODE15:
638b843c749SSergey Zigachev 			idx = (reg_offset - mmGB_MACROTILE_MODE0);
639b843c749SSergey Zigachev 			return adev->gfx.config.macrotile_mode_array[idx];
640b843c749SSergey Zigachev 		default:
641b843c749SSergey Zigachev 			return RREG32(reg_offset);
642b843c749SSergey Zigachev 		}
643b843c749SSergey Zigachev 	}
644b843c749SSergey Zigachev }
645b843c749SSergey Zigachev 
vi_read_register(struct amdgpu_device * adev,u32 se_num,u32 sh_num,u32 reg_offset,u32 * value)646b843c749SSergey Zigachev static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
647b843c749SSergey Zigachev 			    u32 sh_num, u32 reg_offset, u32 *value)
648b843c749SSergey Zigachev {
649b843c749SSergey Zigachev 	uint32_t i;
650b843c749SSergey Zigachev 
651b843c749SSergey Zigachev 	*value = 0;
652b843c749SSergey Zigachev 	for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
653b843c749SSergey Zigachev 		bool indexed = vi_allowed_read_registers[i].grbm_indexed;
654b843c749SSergey Zigachev 
655b843c749SSergey Zigachev 		if (reg_offset != vi_allowed_read_registers[i].reg_offset)
656b843c749SSergey Zigachev 			continue;
657b843c749SSergey Zigachev 
658b843c749SSergey Zigachev 		*value = vi_get_register_value(adev, indexed, se_num, sh_num,
659b843c749SSergey Zigachev 					       reg_offset);
660b843c749SSergey Zigachev 		return 0;
661b843c749SSergey Zigachev 	}
662b843c749SSergey Zigachev 	return -EINVAL;
663b843c749SSergey Zigachev }
664b843c749SSergey Zigachev 
vi_gpu_pci_config_reset(struct amdgpu_device * adev)665b843c749SSergey Zigachev static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
666b843c749SSergey Zigachev {
667b843c749SSergey Zigachev 	u32 i;
668b843c749SSergey Zigachev 
669b843c749SSergey Zigachev 	dev_info(adev->dev, "GPU pci config reset\n");
670b843c749SSergey Zigachev 
671b843c749SSergey Zigachev 	/* disable BM */
672b843c749SSergey Zigachev 	pci_clear_master(adev->pdev);
673b843c749SSergey Zigachev 	/* reset */
674b843c749SSergey Zigachev 	amdgpu_device_pci_config_reset(adev);
675b843c749SSergey Zigachev 
676b843c749SSergey Zigachev 	udelay(100);
677b843c749SSergey Zigachev 
678b843c749SSergey Zigachev 	/* wait for asic to come out of reset */
679b843c749SSergey Zigachev 	for (i = 0; i < adev->usec_timeout; i++) {
680b843c749SSergey Zigachev 		if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
681b843c749SSergey Zigachev 			/* enable BM */
682b843c749SSergey Zigachev 			pci_set_master(adev->pdev);
683b843c749SSergey Zigachev 			adev->has_hw_reset = true;
684b843c749SSergey Zigachev 			return 0;
685b843c749SSergey Zigachev 		}
686b843c749SSergey Zigachev 		udelay(1);
687b843c749SSergey Zigachev 	}
688b843c749SSergey Zigachev 	return -EINVAL;
689b843c749SSergey Zigachev }
690b843c749SSergey Zigachev 
691b843c749SSergey Zigachev /**
692b843c749SSergey Zigachev  * vi_asic_reset - soft reset GPU
693b843c749SSergey Zigachev  *
694b843c749SSergey Zigachev  * @adev: amdgpu_device pointer
695b843c749SSergey Zigachev  *
696b843c749SSergey Zigachev  * Look up which blocks are hung and attempt
697b843c749SSergey Zigachev  * to reset them.
698b843c749SSergey Zigachev  * Returns 0 for success.
699b843c749SSergey Zigachev  */
vi_asic_reset(struct amdgpu_device * adev)700b843c749SSergey Zigachev static int vi_asic_reset(struct amdgpu_device *adev)
701b843c749SSergey Zigachev {
702b843c749SSergey Zigachev 	int r;
703b843c749SSergey Zigachev 
704b843c749SSergey Zigachev 	amdgpu_atombios_scratch_regs_engine_hung(adev, true);
705b843c749SSergey Zigachev 
706b843c749SSergey Zigachev 	r = vi_gpu_pci_config_reset(adev);
707b843c749SSergey Zigachev 
708b843c749SSergey Zigachev 	amdgpu_atombios_scratch_regs_engine_hung(adev, false);
709b843c749SSergey Zigachev 
710b843c749SSergey Zigachev 	return r;
711b843c749SSergey Zigachev }
712b843c749SSergey Zigachev 
vi_get_config_memsize(struct amdgpu_device * adev)713b843c749SSergey Zigachev static u32 vi_get_config_memsize(struct amdgpu_device *adev)
714b843c749SSergey Zigachev {
715b843c749SSergey Zigachev 	return RREG32(mmCONFIG_MEMSIZE);
716b843c749SSergey Zigachev }
717b843c749SSergey Zigachev 
vi_set_uvd_clock(struct amdgpu_device * adev,u32 clock,u32 cntl_reg,u32 status_reg)718b843c749SSergey Zigachev static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
719b843c749SSergey Zigachev 			u32 cntl_reg, u32 status_reg)
720b843c749SSergey Zigachev {
721b843c749SSergey Zigachev 	int r, i;
722b843c749SSergey Zigachev 	struct atom_clock_dividers dividers;
723b843c749SSergey Zigachev 	uint32_t tmp;
724b843c749SSergey Zigachev 
725b843c749SSergey Zigachev 	r = amdgpu_atombios_get_clock_dividers(adev,
726b843c749SSergey Zigachev 					       COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
727b843c749SSergey Zigachev 					       clock, false, &dividers);
728b843c749SSergey Zigachev 	if (r)
729b843c749SSergey Zigachev 		return r;
730b843c749SSergey Zigachev 
731b843c749SSergey Zigachev 	tmp = RREG32_SMC(cntl_reg);
732b843c749SSergey Zigachev 
733b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU)
734b843c749SSergey Zigachev 		tmp &= ~CG_DCLK_CNTL__DCLK_DIVIDER_MASK;
735b843c749SSergey Zigachev 	else
736b843c749SSergey Zigachev 		tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
737b843c749SSergey Zigachev 				CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
738b843c749SSergey Zigachev 	tmp |= dividers.post_divider;
739b843c749SSergey Zigachev 	WREG32_SMC(cntl_reg, tmp);
740b843c749SSergey Zigachev 
741b843c749SSergey Zigachev 	for (i = 0; i < 100; i++) {
742b843c749SSergey Zigachev 		tmp = RREG32_SMC(status_reg);
743b843c749SSergey Zigachev 		if (adev->flags & AMD_IS_APU) {
744b843c749SSergey Zigachev 			if (tmp & 0x10000)
745b843c749SSergey Zigachev 				break;
746b843c749SSergey Zigachev 		} else {
747b843c749SSergey Zigachev 			if (tmp & CG_DCLK_STATUS__DCLK_STATUS_MASK)
748b843c749SSergey Zigachev 				break;
749b843c749SSergey Zigachev 		}
750b843c749SSergey Zigachev 		mdelay(10);
751b843c749SSergey Zigachev 	}
752b843c749SSergey Zigachev 	if (i == 100)
753b843c749SSergey Zigachev 		return -ETIMEDOUT;
754b843c749SSergey Zigachev 	return 0;
755b843c749SSergey Zigachev }
756b843c749SSergey Zigachev 
757b843c749SSergey Zigachev #define ixGNB_CLK1_DFS_CNTL 0xD82200F0
758b843c749SSergey Zigachev #define ixGNB_CLK1_STATUS   0xD822010C
759b843c749SSergey Zigachev #define ixGNB_CLK2_DFS_CNTL 0xD8220110
760b843c749SSergey Zigachev #define ixGNB_CLK2_STATUS   0xD822012C
761b843c749SSergey Zigachev #define ixGNB_CLK3_DFS_CNTL 0xD8220130
762b843c749SSergey Zigachev #define ixGNB_CLK3_STATUS   0xD822014C
763b843c749SSergey Zigachev 
vi_set_uvd_clocks(struct amdgpu_device * adev,u32 vclk,u32 dclk)764b843c749SSergey Zigachev static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
765b843c749SSergey Zigachev {
766b843c749SSergey Zigachev 	int r;
767b843c749SSergey Zigachev 
768b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU) {
769b843c749SSergey Zigachev 		r = vi_set_uvd_clock(adev, vclk, ixGNB_CLK2_DFS_CNTL, ixGNB_CLK2_STATUS);
770b843c749SSergey Zigachev 		if (r)
771b843c749SSergey Zigachev 			return r;
772b843c749SSergey Zigachev 
773b843c749SSergey Zigachev 		r = vi_set_uvd_clock(adev, dclk, ixGNB_CLK1_DFS_CNTL, ixGNB_CLK1_STATUS);
774b843c749SSergey Zigachev 		if (r)
775b843c749SSergey Zigachev 			return r;
776b843c749SSergey Zigachev 	} else {
777b843c749SSergey Zigachev 		r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
778b843c749SSergey Zigachev 		if (r)
779b843c749SSergey Zigachev 			return r;
780b843c749SSergey Zigachev 
781b843c749SSergey Zigachev 		r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
782b843c749SSergey Zigachev 		if (r)
783b843c749SSergey Zigachev 			return r;
784b843c749SSergey Zigachev 	}
785b843c749SSergey Zigachev 
786b843c749SSergey Zigachev 	return 0;
787b843c749SSergey Zigachev }
788b843c749SSergey Zigachev 
vi_set_vce_clocks(struct amdgpu_device * adev,u32 evclk,u32 ecclk)789b843c749SSergey Zigachev static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
790b843c749SSergey Zigachev {
791b843c749SSergey Zigachev 	int r, i;
792b843c749SSergey Zigachev 	struct atom_clock_dividers dividers;
793b843c749SSergey Zigachev 	u32 tmp;
794b843c749SSergey Zigachev 	u32 reg_ctrl;
795b843c749SSergey Zigachev 	u32 reg_status;
796b843c749SSergey Zigachev 	u32 status_mask;
797b843c749SSergey Zigachev 	u32 reg_mask;
798b843c749SSergey Zigachev 
799b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU) {
800b843c749SSergey Zigachev 		reg_ctrl = ixGNB_CLK3_DFS_CNTL;
801b843c749SSergey Zigachev 		reg_status = ixGNB_CLK3_STATUS;
802b843c749SSergey Zigachev 		status_mask = 0x00010000;
803b843c749SSergey Zigachev 		reg_mask = CG_ECLK_CNTL__ECLK_DIVIDER_MASK;
804b843c749SSergey Zigachev 	} else {
805b843c749SSergey Zigachev 		reg_ctrl = ixCG_ECLK_CNTL;
806b843c749SSergey Zigachev 		reg_status = ixCG_ECLK_STATUS;
807b843c749SSergey Zigachev 		status_mask = CG_ECLK_STATUS__ECLK_STATUS_MASK;
808b843c749SSergey Zigachev 		reg_mask = CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK | CG_ECLK_CNTL__ECLK_DIVIDER_MASK;
809b843c749SSergey Zigachev 	}
810b843c749SSergey Zigachev 
811b843c749SSergey Zigachev 	r = amdgpu_atombios_get_clock_dividers(adev,
812b843c749SSergey Zigachev 					       COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
813b843c749SSergey Zigachev 					       ecclk, false, &dividers);
814b843c749SSergey Zigachev 	if (r)
815b843c749SSergey Zigachev 		return r;
816b843c749SSergey Zigachev 
817b843c749SSergey Zigachev 	for (i = 0; i < 100; i++) {
818b843c749SSergey Zigachev 		if (RREG32_SMC(reg_status) & status_mask)
819b843c749SSergey Zigachev 			break;
820b843c749SSergey Zigachev 		mdelay(10);
821b843c749SSergey Zigachev 	}
822b843c749SSergey Zigachev 
823b843c749SSergey Zigachev 	if (i == 100)
824b843c749SSergey Zigachev 		return -ETIMEDOUT;
825b843c749SSergey Zigachev 
826b843c749SSergey Zigachev 	tmp = RREG32_SMC(reg_ctrl);
827b843c749SSergey Zigachev 	tmp &= ~reg_mask;
828b843c749SSergey Zigachev 	tmp |= dividers.post_divider;
829b843c749SSergey Zigachev 	WREG32_SMC(reg_ctrl, tmp);
830b843c749SSergey Zigachev 
831b843c749SSergey Zigachev 	for (i = 0; i < 100; i++) {
832b843c749SSergey Zigachev 		if (RREG32_SMC(reg_status) & status_mask)
833b843c749SSergey Zigachev 			break;
834b843c749SSergey Zigachev 		mdelay(10);
835b843c749SSergey Zigachev 	}
836b843c749SSergey Zigachev 
837b843c749SSergey Zigachev 	if (i == 100)
838b843c749SSergey Zigachev 		return -ETIMEDOUT;
839b843c749SSergey Zigachev 
840b843c749SSergey Zigachev 	return 0;
841b843c749SSergey Zigachev }
842b843c749SSergey Zigachev 
vi_pcie_gen3_enable(struct amdgpu_device * adev)843b843c749SSergey Zigachev static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
844b843c749SSergey Zigachev {
845*78973132SSergey Zigachev #if 0
846b843c749SSergey Zigachev 	if (pci_is_root_bus(adev->pdev->bus))
847b843c749SSergey Zigachev 		return;
848*78973132SSergey Zigachev #endif
849b843c749SSergey Zigachev 
850b843c749SSergey Zigachev 	if (amdgpu_pcie_gen2 == 0)
851b843c749SSergey Zigachev 		return;
852b843c749SSergey Zigachev 
853b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU)
854b843c749SSergey Zigachev 		return;
855b843c749SSergey Zigachev 
856b843c749SSergey Zigachev 	if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
857b843c749SSergey Zigachev 					CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
858b843c749SSergey Zigachev 		return;
859b843c749SSergey Zigachev 
860b843c749SSergey Zigachev 	/* todo */
861b843c749SSergey Zigachev }
862b843c749SSergey Zigachev 
vi_program_aspm(struct amdgpu_device * adev)863b843c749SSergey Zigachev static void vi_program_aspm(struct amdgpu_device *adev)
864b843c749SSergey Zigachev {
865b843c749SSergey Zigachev 
866b843c749SSergey Zigachev 	if (amdgpu_aspm == 0)
867b843c749SSergey Zigachev 		return;
868b843c749SSergey Zigachev 
869b843c749SSergey Zigachev 	/* todo */
870b843c749SSergey Zigachev }
871b843c749SSergey Zigachev 
vi_enable_doorbell_aperture(struct amdgpu_device * adev,bool enable)872b843c749SSergey Zigachev static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
873b843c749SSergey Zigachev 					bool enable)
874b843c749SSergey Zigachev {
875b843c749SSergey Zigachev 	u32 tmp;
876b843c749SSergey Zigachev 
877b843c749SSergey Zigachev 	/* not necessary on CZ */
878b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU)
879b843c749SSergey Zigachev 		return;
880b843c749SSergey Zigachev 
881b843c749SSergey Zigachev 	tmp = RREG32(mmBIF_DOORBELL_APER_EN);
882b843c749SSergey Zigachev 	if (enable)
883b843c749SSergey Zigachev 		tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
884b843c749SSergey Zigachev 	else
885b843c749SSergey Zigachev 		tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
886b843c749SSergey Zigachev 
887b843c749SSergey Zigachev 	WREG32(mmBIF_DOORBELL_APER_EN, tmp);
888b843c749SSergey Zigachev }
889b843c749SSergey Zigachev 
890b843c749SSergey Zigachev #define ATI_REV_ID_FUSE_MACRO__ADDRESS      0xC0014044
891b843c749SSergey Zigachev #define ATI_REV_ID_FUSE_MACRO__SHIFT        9
892b843c749SSergey Zigachev #define ATI_REV_ID_FUSE_MACRO__MASK         0x00001E00
893b843c749SSergey Zigachev 
vi_get_rev_id(struct amdgpu_device * adev)894b843c749SSergey Zigachev static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
895b843c749SSergey Zigachev {
896b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU)
897b843c749SSergey Zigachev 		return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
898b843c749SSergey Zigachev 			>> ATI_REV_ID_FUSE_MACRO__SHIFT;
899b843c749SSergey Zigachev 	else
900b843c749SSergey Zigachev 		return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
901b843c749SSergey Zigachev 			>> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
902b843c749SSergey Zigachev }
903b843c749SSergey Zigachev 
vi_flush_hdp(struct amdgpu_device * adev,struct amdgpu_ring * ring)904b843c749SSergey Zigachev static void vi_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
905b843c749SSergey Zigachev {
906b843c749SSergey Zigachev 	if (!ring || !ring->funcs->emit_wreg) {
907b843c749SSergey Zigachev 		WREG32(mmHDP_MEM_COHERENCY_FLUSH_CNTL, 1);
908b843c749SSergey Zigachev 		RREG32(mmHDP_MEM_COHERENCY_FLUSH_CNTL);
909b843c749SSergey Zigachev 	} else {
910b843c749SSergey Zigachev 		amdgpu_ring_emit_wreg(ring, mmHDP_MEM_COHERENCY_FLUSH_CNTL, 1);
911b843c749SSergey Zigachev 	}
912b843c749SSergey Zigachev }
913b843c749SSergey Zigachev 
vi_invalidate_hdp(struct amdgpu_device * adev,struct amdgpu_ring * ring)914b843c749SSergey Zigachev static void vi_invalidate_hdp(struct amdgpu_device *adev,
915b843c749SSergey Zigachev 			      struct amdgpu_ring *ring)
916b843c749SSergey Zigachev {
917b843c749SSergey Zigachev 	if (!ring || !ring->funcs->emit_wreg) {
918b843c749SSergey Zigachev 		WREG32(mmHDP_DEBUG0, 1);
919b843c749SSergey Zigachev 		RREG32(mmHDP_DEBUG0);
920b843c749SSergey Zigachev 	} else {
921b843c749SSergey Zigachev 		amdgpu_ring_emit_wreg(ring, mmHDP_DEBUG0, 1);
922b843c749SSergey Zigachev 	}
923b843c749SSergey Zigachev }
924b843c749SSergey Zigachev 
vi_need_full_reset(struct amdgpu_device * adev)925b843c749SSergey Zigachev static bool vi_need_full_reset(struct amdgpu_device *adev)
926b843c749SSergey Zigachev {
927b843c749SSergey Zigachev 	switch (adev->asic_type) {
928b843c749SSergey Zigachev 	case CHIP_CARRIZO:
929b843c749SSergey Zigachev 	case CHIP_STONEY:
930b843c749SSergey Zigachev 		/* CZ has hang issues with full reset at the moment */
931b843c749SSergey Zigachev 		return false;
932b843c749SSergey Zigachev 	case CHIP_FIJI:
933b843c749SSergey Zigachev 	case CHIP_TONGA:
934b843c749SSergey Zigachev 		/* XXX: soft reset should work on fiji and tonga */
935b843c749SSergey Zigachev 		return true;
936b843c749SSergey Zigachev 	case CHIP_POLARIS10:
937b843c749SSergey Zigachev 	case CHIP_POLARIS11:
938b843c749SSergey Zigachev 	case CHIP_POLARIS12:
939b843c749SSergey Zigachev 	case CHIP_TOPAZ:
940b843c749SSergey Zigachev 	default:
941b843c749SSergey Zigachev 		/* change this when we support soft reset */
942b843c749SSergey Zigachev 		return true;
943b843c749SSergey Zigachev 	}
944b843c749SSergey Zigachev }
945b843c749SSergey Zigachev 
946b843c749SSergey Zigachev static const struct amdgpu_asic_funcs vi_asic_funcs =
947b843c749SSergey Zigachev {
948b843c749SSergey Zigachev 	.read_disabled_bios = &vi_read_disabled_bios,
949b843c749SSergey Zigachev 	.read_bios_from_rom = &vi_read_bios_from_rom,
950b843c749SSergey Zigachev 	.read_register = &vi_read_register,
951b843c749SSergey Zigachev 	.reset = &vi_asic_reset,
952b843c749SSergey Zigachev 	.set_vga_state = &vi_vga_set_state,
953b843c749SSergey Zigachev 	.get_xclk = &vi_get_xclk,
954b843c749SSergey Zigachev 	.set_uvd_clocks = &vi_set_uvd_clocks,
955b843c749SSergey Zigachev 	.set_vce_clocks = &vi_set_vce_clocks,
956b843c749SSergey Zigachev 	.get_config_memsize = &vi_get_config_memsize,
957b843c749SSergey Zigachev 	.flush_hdp = &vi_flush_hdp,
958b843c749SSergey Zigachev 	.invalidate_hdp = &vi_invalidate_hdp,
959b843c749SSergey Zigachev 	.need_full_reset = &vi_need_full_reset,
960b843c749SSergey Zigachev };
961b843c749SSergey Zigachev 
962b843c749SSergey Zigachev #define CZ_REV_BRISTOL(rev)	 \
963b843c749SSergey Zigachev 	((rev >= 0xC8 && rev <= 0xCE) || (rev >= 0xE1 && rev <= 0xE6))
964b843c749SSergey Zigachev 
vi_common_early_init(void * handle)965b843c749SSergey Zigachev static int vi_common_early_init(void *handle)
966b843c749SSergey Zigachev {
967b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
968b843c749SSergey Zigachev 
969b843c749SSergey Zigachev 	if (adev->flags & AMD_IS_APU) {
970b843c749SSergey Zigachev 		adev->smc_rreg = &cz_smc_rreg;
971b843c749SSergey Zigachev 		adev->smc_wreg = &cz_smc_wreg;
972b843c749SSergey Zigachev 	} else {
973b843c749SSergey Zigachev 		adev->smc_rreg = &vi_smc_rreg;
974b843c749SSergey Zigachev 		adev->smc_wreg = &vi_smc_wreg;
975b843c749SSergey Zigachev 	}
976b843c749SSergey Zigachev 	adev->pcie_rreg = &vi_pcie_rreg;
977b843c749SSergey Zigachev 	adev->pcie_wreg = &vi_pcie_wreg;
978b843c749SSergey Zigachev 	adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
979b843c749SSergey Zigachev 	adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
980b843c749SSergey Zigachev 	adev->didt_rreg = &vi_didt_rreg;
981b843c749SSergey Zigachev 	adev->didt_wreg = &vi_didt_wreg;
982b843c749SSergey Zigachev 	adev->gc_cac_rreg = &vi_gc_cac_rreg;
983b843c749SSergey Zigachev 	adev->gc_cac_wreg = &vi_gc_cac_wreg;
984b843c749SSergey Zigachev 
985b843c749SSergey Zigachev 	adev->asic_funcs = &vi_asic_funcs;
986b843c749SSergey Zigachev 
987b843c749SSergey Zigachev 	adev->rev_id = vi_get_rev_id(adev);
988b843c749SSergey Zigachev 	adev->external_rev_id = 0xFF;
989b843c749SSergey Zigachev 	switch (adev->asic_type) {
990b843c749SSergey Zigachev 	case CHIP_TOPAZ:
991b843c749SSergey Zigachev 		adev->cg_flags = 0;
992b843c749SSergey Zigachev 		adev->pg_flags = 0;
993b843c749SSergey Zigachev 		adev->external_rev_id = 0x1;
994b843c749SSergey Zigachev 		break;
995b843c749SSergey Zigachev 	case CHIP_FIJI:
996b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
997b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_MGLS |
998b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
999b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1000b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGTS |
1001b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGTS_LS |
1002b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1003b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1004b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1005b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1006b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1007b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1008b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1009b843c749SSergey Zigachev 			AMD_CG_SUPPORT_ROM_MGCG |
1010b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_MGCG |
1011b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_LS |
1012b843c749SSergey Zigachev 			AMD_CG_SUPPORT_UVD_MGCG;
1013b843c749SSergey Zigachev 		adev->pg_flags = 0;
1014b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x3c;
1015b843c749SSergey Zigachev 		break;
1016b843c749SSergey Zigachev 	case CHIP_TONGA:
1017b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1018b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1019b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1020b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1021b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1022b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1023b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1024b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1025b843c749SSergey Zigachev 			AMD_CG_SUPPORT_ROM_MGCG |
1026b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_MGCG |
1027b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_LS |
1028b843c749SSergey Zigachev 			AMD_CG_SUPPORT_DRM_LS |
1029b843c749SSergey Zigachev 			AMD_CG_SUPPORT_UVD_MGCG;
1030b843c749SSergey Zigachev 		adev->pg_flags = 0;
1031b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x14;
1032b843c749SSergey Zigachev 		break;
1033b843c749SSergey Zigachev 	case CHIP_POLARIS11:
1034b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1035b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
1036b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1037b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1038b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1039b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGCG |
1040b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGLS |
1041b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1042b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1043b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_MGCG |
1044b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1045b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1046b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1047b843c749SSergey Zigachev 			AMD_CG_SUPPORT_ROM_MGCG |
1048b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_MGCG |
1049b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_LS |
1050b843c749SSergey Zigachev 			AMD_CG_SUPPORT_DRM_LS |
1051b843c749SSergey Zigachev 			AMD_CG_SUPPORT_UVD_MGCG |
1052b843c749SSergey Zigachev 			AMD_CG_SUPPORT_VCE_MGCG;
1053b843c749SSergey Zigachev 		adev->pg_flags = 0;
1054b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x5A;
1055b843c749SSergey Zigachev 		break;
1056b843c749SSergey Zigachev 	case CHIP_POLARIS10:
1057b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1058b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
1059b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1060b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1061b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1062b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGCG |
1063b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGLS |
1064b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1065b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1066b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_MGCG |
1067b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1068b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1069b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1070b843c749SSergey Zigachev 			AMD_CG_SUPPORT_ROM_MGCG |
1071b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_MGCG |
1072b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_LS |
1073b843c749SSergey Zigachev 			AMD_CG_SUPPORT_DRM_LS |
1074b843c749SSergey Zigachev 			AMD_CG_SUPPORT_UVD_MGCG |
1075b843c749SSergey Zigachev 			AMD_CG_SUPPORT_VCE_MGCG;
1076b843c749SSergey Zigachev 		adev->pg_flags = 0;
1077b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x50;
1078b843c749SSergey Zigachev 		break;
1079b843c749SSergey Zigachev 	case CHIP_POLARIS12:
1080b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1081b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
1082b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1083b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1084b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1085b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGCG |
1086b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGLS |
1087b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1088b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1089b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_MGCG |
1090b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1091b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1092b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1093b843c749SSergey Zigachev 			AMD_CG_SUPPORT_ROM_MGCG |
1094b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_MGCG |
1095b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_LS |
1096b843c749SSergey Zigachev 			AMD_CG_SUPPORT_DRM_LS |
1097b843c749SSergey Zigachev 			AMD_CG_SUPPORT_UVD_MGCG |
1098b843c749SSergey Zigachev 			AMD_CG_SUPPORT_VCE_MGCG;
1099b843c749SSergey Zigachev 		adev->pg_flags = 0;
1100b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x64;
1101b843c749SSergey Zigachev 		break;
1102b843c749SSergey Zigachev 	case CHIP_VEGAM:
1103b843c749SSergey Zigachev 		adev->cg_flags = 0;
1104b843c749SSergey Zigachev 			/*AMD_CG_SUPPORT_GFX_MGCG |
1105b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
1106b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1107b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1108b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1109b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGCG |
1110b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_3D_CGLS |
1111b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1112b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1113b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_MGCG |
1114b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1115b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1116b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1117b843c749SSergey Zigachev 			AMD_CG_SUPPORT_ROM_MGCG |
1118b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_MGCG |
1119b843c749SSergey Zigachev 			AMD_CG_SUPPORT_MC_LS |
1120b843c749SSergey Zigachev 			AMD_CG_SUPPORT_DRM_LS |
1121b843c749SSergey Zigachev 			AMD_CG_SUPPORT_UVD_MGCG |
1122b843c749SSergey Zigachev 			AMD_CG_SUPPORT_VCE_MGCG;*/
1123b843c749SSergey Zigachev 		adev->pg_flags = 0;
1124b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x6E;
1125b843c749SSergey Zigachev 		break;
1126b843c749SSergey Zigachev 	case CHIP_CARRIZO:
1127b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1128b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_MGCG |
1129b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_MGLS |
1130b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
1131b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1132b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGTS |
1133b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGTS_LS |
1134b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGCG |
1135b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1136b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1137b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1138b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1139b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1140b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1141b843c749SSergey Zigachev 			AMD_CG_SUPPORT_VCE_MGCG;
1142b843c749SSergey Zigachev 		/* rev0 hardware requires workarounds to support PG */
1143b843c749SSergey Zigachev 		adev->pg_flags = 0;
1144b843c749SSergey Zigachev 		if (adev->rev_id != 0x00 || CZ_REV_BRISTOL(adev->pdev->revision)) {
1145b843c749SSergey Zigachev 			adev->pg_flags |= AMD_PG_SUPPORT_GFX_SMG |
1146b843c749SSergey Zigachev 				AMD_PG_SUPPORT_GFX_PIPELINE |
1147b843c749SSergey Zigachev 				AMD_PG_SUPPORT_CP |
1148b843c749SSergey Zigachev 				AMD_PG_SUPPORT_UVD |
1149b843c749SSergey Zigachev 				AMD_PG_SUPPORT_VCE;
1150b843c749SSergey Zigachev 		}
1151b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x1;
1152b843c749SSergey Zigachev 		break;
1153b843c749SSergey Zigachev 	case CHIP_STONEY:
1154b843c749SSergey Zigachev 		adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1155b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_MGCG |
1156b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_MGLS |
1157b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_RLC_LS |
1158b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CP_LS |
1159b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGTS |
1160b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGTS_LS |
1161b843c749SSergey Zigachev 			AMD_CG_SUPPORT_GFX_CGLS |
1162b843c749SSergey Zigachev 			AMD_CG_SUPPORT_BIF_LS |
1163b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_MGCG |
1164b843c749SSergey Zigachev 			AMD_CG_SUPPORT_HDP_LS |
1165b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_MGCG |
1166b843c749SSergey Zigachev 			AMD_CG_SUPPORT_SDMA_LS |
1167b843c749SSergey Zigachev 			AMD_CG_SUPPORT_VCE_MGCG;
1168b843c749SSergey Zigachev 		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
1169b843c749SSergey Zigachev 			AMD_PG_SUPPORT_GFX_SMG |
1170b843c749SSergey Zigachev 			AMD_PG_SUPPORT_GFX_PIPELINE |
1171b843c749SSergey Zigachev 			AMD_PG_SUPPORT_CP |
1172b843c749SSergey Zigachev 			AMD_PG_SUPPORT_UVD |
1173b843c749SSergey Zigachev 			AMD_PG_SUPPORT_VCE;
1174b843c749SSergey Zigachev 		adev->external_rev_id = adev->rev_id + 0x61;
1175b843c749SSergey Zigachev 		break;
1176b843c749SSergey Zigachev 	default:
1177b843c749SSergey Zigachev 		/* FIXME: not supported yet */
1178b843c749SSergey Zigachev 		return -EINVAL;
1179b843c749SSergey Zigachev 	}
1180b843c749SSergey Zigachev 
1181b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev)) {
1182b843c749SSergey Zigachev 		amdgpu_virt_init_setting(adev);
1183b843c749SSergey Zigachev 		xgpu_vi_mailbox_set_irq_funcs(adev);
1184b843c749SSergey Zigachev 	}
1185b843c749SSergey Zigachev 
1186b843c749SSergey Zigachev 	return 0;
1187b843c749SSergey Zigachev }
1188b843c749SSergey Zigachev 
vi_common_late_init(void * handle)1189b843c749SSergey Zigachev static int vi_common_late_init(void *handle)
1190b843c749SSergey Zigachev {
1191b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1192b843c749SSergey Zigachev 
1193b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev))
1194b843c749SSergey Zigachev 		xgpu_vi_mailbox_get_irq(adev);
1195b843c749SSergey Zigachev 
1196b843c749SSergey Zigachev 	return 0;
1197b843c749SSergey Zigachev }
1198b843c749SSergey Zigachev 
vi_common_sw_init(void * handle)1199b843c749SSergey Zigachev static int vi_common_sw_init(void *handle)
1200b843c749SSergey Zigachev {
1201b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1202b843c749SSergey Zigachev 
1203b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev))
1204b843c749SSergey Zigachev 		xgpu_vi_mailbox_add_irq_id(adev);
1205b843c749SSergey Zigachev 
1206b843c749SSergey Zigachev 	return 0;
1207b843c749SSergey Zigachev }
1208b843c749SSergey Zigachev 
vi_common_sw_fini(void * handle)1209b843c749SSergey Zigachev static int vi_common_sw_fini(void *handle)
1210b843c749SSergey Zigachev {
1211b843c749SSergey Zigachev 	return 0;
1212b843c749SSergey Zigachev }
1213b843c749SSergey Zigachev 
vi_common_hw_init(void * handle)1214b843c749SSergey Zigachev static int vi_common_hw_init(void *handle)
1215b843c749SSergey Zigachev {
1216b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1217b843c749SSergey Zigachev 
1218b843c749SSergey Zigachev 	/* move the golden regs per IP block */
1219b843c749SSergey Zigachev 	vi_init_golden_registers(adev);
1220b843c749SSergey Zigachev 	/* enable pcie gen2/3 link */
1221b843c749SSergey Zigachev 	vi_pcie_gen3_enable(adev);
1222b843c749SSergey Zigachev 	/* enable aspm */
1223b843c749SSergey Zigachev 	vi_program_aspm(adev);
1224b843c749SSergey Zigachev 	/* enable the doorbell aperture */
1225b843c749SSergey Zigachev 	vi_enable_doorbell_aperture(adev, true);
1226b843c749SSergey Zigachev 
1227b843c749SSergey Zigachev 	return 0;
1228b843c749SSergey Zigachev }
1229b843c749SSergey Zigachev 
vi_common_hw_fini(void * handle)1230b843c749SSergey Zigachev static int vi_common_hw_fini(void *handle)
1231b843c749SSergey Zigachev {
1232b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1233b843c749SSergey Zigachev 
1234b843c749SSergey Zigachev 	/* enable the doorbell aperture */
1235b843c749SSergey Zigachev 	vi_enable_doorbell_aperture(adev, false);
1236b843c749SSergey Zigachev 
1237b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev))
1238b843c749SSergey Zigachev 		xgpu_vi_mailbox_put_irq(adev);
1239b843c749SSergey Zigachev 
1240b843c749SSergey Zigachev 	return 0;
1241b843c749SSergey Zigachev }
1242b843c749SSergey Zigachev 
vi_common_suspend(void * handle)1243b843c749SSergey Zigachev static int vi_common_suspend(void *handle)
1244b843c749SSergey Zigachev {
1245b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1246b843c749SSergey Zigachev 
1247b843c749SSergey Zigachev 	return vi_common_hw_fini(adev);
1248b843c749SSergey Zigachev }
1249b843c749SSergey Zigachev 
vi_common_resume(void * handle)1250b843c749SSergey Zigachev static int vi_common_resume(void *handle)
1251b843c749SSergey Zigachev {
1252b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1253b843c749SSergey Zigachev 
1254b843c749SSergey Zigachev 	return vi_common_hw_init(adev);
1255b843c749SSergey Zigachev }
1256b843c749SSergey Zigachev 
vi_common_is_idle(void * handle)1257b843c749SSergey Zigachev static bool vi_common_is_idle(void *handle)
1258b843c749SSergey Zigachev {
1259b843c749SSergey Zigachev 	return true;
1260b843c749SSergey Zigachev }
1261b843c749SSergey Zigachev 
vi_common_wait_for_idle(void * handle)1262b843c749SSergey Zigachev static int vi_common_wait_for_idle(void *handle)
1263b843c749SSergey Zigachev {
1264b843c749SSergey Zigachev 	return 0;
1265b843c749SSergey Zigachev }
1266b843c749SSergey Zigachev 
vi_common_soft_reset(void * handle)1267b843c749SSergey Zigachev static int vi_common_soft_reset(void *handle)
1268b843c749SSergey Zigachev {
1269b843c749SSergey Zigachev 	return 0;
1270b843c749SSergey Zigachev }
1271b843c749SSergey Zigachev 
vi_update_bif_medium_grain_light_sleep(struct amdgpu_device * adev,bool enable)1272b843c749SSergey Zigachev static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1273b843c749SSergey Zigachev 						   bool enable)
1274b843c749SSergey Zigachev {
1275b843c749SSergey Zigachev 	uint32_t temp, data;
1276b843c749SSergey Zigachev 
1277b843c749SSergey Zigachev 	temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1278b843c749SSergey Zigachev 
1279b843c749SSergey Zigachev 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
1280b843c749SSergey Zigachev 		data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1281b843c749SSergey Zigachev 				PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1282b843c749SSergey Zigachev 				PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1283b843c749SSergey Zigachev 	else
1284b843c749SSergey Zigachev 		data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1285b843c749SSergey Zigachev 				PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1286b843c749SSergey Zigachev 				PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1287b843c749SSergey Zigachev 
1288b843c749SSergey Zigachev 	if (temp != data)
1289b843c749SSergey Zigachev 		WREG32_PCIE(ixPCIE_CNTL2, data);
1290b843c749SSergey Zigachev }
1291b843c749SSergey Zigachev 
vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device * adev,bool enable)1292b843c749SSergey Zigachev static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1293b843c749SSergey Zigachev 						    bool enable)
1294b843c749SSergey Zigachev {
1295b843c749SSergey Zigachev 	uint32_t temp, data;
1296b843c749SSergey Zigachev 
1297b843c749SSergey Zigachev 	temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1298b843c749SSergey Zigachev 
1299b843c749SSergey Zigachev 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
1300b843c749SSergey Zigachev 		data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1301b843c749SSergey Zigachev 	else
1302b843c749SSergey Zigachev 		data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1303b843c749SSergey Zigachev 
1304b843c749SSergey Zigachev 	if (temp != data)
1305b843c749SSergey Zigachev 		WREG32(mmHDP_HOST_PATH_CNTL, data);
1306b843c749SSergey Zigachev }
1307b843c749SSergey Zigachev 
vi_update_hdp_light_sleep(struct amdgpu_device * adev,bool enable)1308b843c749SSergey Zigachev static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1309b843c749SSergey Zigachev 				      bool enable)
1310b843c749SSergey Zigachev {
1311b843c749SSergey Zigachev 	uint32_t temp, data;
1312b843c749SSergey Zigachev 
1313b843c749SSergey Zigachev 	temp = data = RREG32(mmHDP_MEM_POWER_LS);
1314b843c749SSergey Zigachev 
1315b843c749SSergey Zigachev 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1316b843c749SSergey Zigachev 		data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1317b843c749SSergey Zigachev 	else
1318b843c749SSergey Zigachev 		data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1319b843c749SSergey Zigachev 
1320b843c749SSergey Zigachev 	if (temp != data)
1321b843c749SSergey Zigachev 		WREG32(mmHDP_MEM_POWER_LS, data);
1322b843c749SSergey Zigachev }
1323b843c749SSergey Zigachev 
vi_update_drm_light_sleep(struct amdgpu_device * adev,bool enable)1324b843c749SSergey Zigachev static void vi_update_drm_light_sleep(struct amdgpu_device *adev,
1325b843c749SSergey Zigachev 				      bool enable)
1326b843c749SSergey Zigachev {
1327b843c749SSergey Zigachev 	uint32_t temp, data;
1328b843c749SSergey Zigachev 
1329b843c749SSergey Zigachev 	temp = data = RREG32(0x157a);
1330b843c749SSergey Zigachev 
1331b843c749SSergey Zigachev 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1332b843c749SSergey Zigachev 		data |= 1;
1333b843c749SSergey Zigachev 	else
1334b843c749SSergey Zigachev 		data &= ~1;
1335b843c749SSergey Zigachev 
1336b843c749SSergey Zigachev 	if (temp != data)
1337b843c749SSergey Zigachev 		WREG32(0x157a, data);
1338b843c749SSergey Zigachev }
1339b843c749SSergey Zigachev 
1340b843c749SSergey Zigachev 
vi_update_rom_medium_grain_clock_gating(struct amdgpu_device * adev,bool enable)1341b843c749SSergey Zigachev static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1342b843c749SSergey Zigachev 						    bool enable)
1343b843c749SSergey Zigachev {
1344b843c749SSergey Zigachev 	uint32_t temp, data;
1345b843c749SSergey Zigachev 
1346b843c749SSergey Zigachev 	temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1347b843c749SSergey Zigachev 
1348b843c749SSergey Zigachev 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
1349b843c749SSergey Zigachev 		data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1350b843c749SSergey Zigachev 				CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1351b843c749SSergey Zigachev 	else
1352b843c749SSergey Zigachev 		data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1353b843c749SSergey Zigachev 				CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1354b843c749SSergey Zigachev 
1355b843c749SSergey Zigachev 	if (temp != data)
1356b843c749SSergey Zigachev 		WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1357b843c749SSergey Zigachev }
1358b843c749SSergey Zigachev 
vi_common_set_clockgating_state_by_smu(void * handle,enum amd_clockgating_state state)1359b843c749SSergey Zigachev static int vi_common_set_clockgating_state_by_smu(void *handle,
1360b843c749SSergey Zigachev 					   enum amd_clockgating_state state)
1361b843c749SSergey Zigachev {
1362b843c749SSergey Zigachev 	uint32_t msg_id, pp_state = 0;
1363b843c749SSergey Zigachev 	uint32_t pp_support_state = 0;
1364b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1365b843c749SSergey Zigachev 
1366b843c749SSergey Zigachev 	if (adev->cg_flags & (AMD_CG_SUPPORT_MC_LS | AMD_CG_SUPPORT_MC_MGCG)) {
1367b843c749SSergey Zigachev 		if (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) {
1368b843c749SSergey Zigachev 			pp_support_state = PP_STATE_SUPPORT_LS;
1369b843c749SSergey Zigachev 			pp_state = PP_STATE_LS;
1370b843c749SSergey Zigachev 		}
1371b843c749SSergey Zigachev 		if (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG) {
1372b843c749SSergey Zigachev 			pp_support_state |= PP_STATE_SUPPORT_CG;
1373b843c749SSergey Zigachev 			pp_state |= PP_STATE_CG;
1374b843c749SSergey Zigachev 		}
1375b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1376b843c749SSergey Zigachev 			pp_state = 0;
1377b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1378b843c749SSergey Zigachev 			       PP_BLOCK_SYS_MC,
1379b843c749SSergey Zigachev 			       pp_support_state,
1380b843c749SSergey Zigachev 			       pp_state);
1381b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1382b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1383b843c749SSergey Zigachev 	}
1384b843c749SSergey Zigachev 
1385b843c749SSergey Zigachev 	if (adev->cg_flags & (AMD_CG_SUPPORT_SDMA_LS | AMD_CG_SUPPORT_SDMA_MGCG)) {
1386b843c749SSergey Zigachev 		if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS) {
1387b843c749SSergey Zigachev 			pp_support_state = PP_STATE_SUPPORT_LS;
1388b843c749SSergey Zigachev 			pp_state = PP_STATE_LS;
1389b843c749SSergey Zigachev 		}
1390b843c749SSergey Zigachev 		if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG) {
1391b843c749SSergey Zigachev 			pp_support_state |= PP_STATE_SUPPORT_CG;
1392b843c749SSergey Zigachev 			pp_state |= PP_STATE_CG;
1393b843c749SSergey Zigachev 		}
1394b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1395b843c749SSergey Zigachev 			pp_state = 0;
1396b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1397b843c749SSergey Zigachev 			       PP_BLOCK_SYS_SDMA,
1398b843c749SSergey Zigachev 			       pp_support_state,
1399b843c749SSergey Zigachev 			       pp_state);
1400b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1401b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1402b843c749SSergey Zigachev 	}
1403b843c749SSergey Zigachev 
1404b843c749SSergey Zigachev 	if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_MGCG)) {
1405b843c749SSergey Zigachev 		if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1406b843c749SSergey Zigachev 			pp_support_state = PP_STATE_SUPPORT_LS;
1407b843c749SSergey Zigachev 			pp_state = PP_STATE_LS;
1408b843c749SSergey Zigachev 		}
1409b843c749SSergey Zigachev 		if (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG) {
1410b843c749SSergey Zigachev 			pp_support_state |= PP_STATE_SUPPORT_CG;
1411b843c749SSergey Zigachev 			pp_state |= PP_STATE_CG;
1412b843c749SSergey Zigachev 		}
1413b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1414b843c749SSergey Zigachev 			pp_state = 0;
1415b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1416b843c749SSergey Zigachev 			       PP_BLOCK_SYS_HDP,
1417b843c749SSergey Zigachev 			       pp_support_state,
1418b843c749SSergey Zigachev 			       pp_state);
1419b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1420b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1421b843c749SSergey Zigachev 	}
1422b843c749SSergey Zigachev 
1423b843c749SSergey Zigachev 
1424b843c749SSergey Zigachev 	if (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS) {
1425b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1426b843c749SSergey Zigachev 			pp_state = 0;
1427b843c749SSergey Zigachev 		else
1428b843c749SSergey Zigachev 			pp_state = PP_STATE_LS;
1429b843c749SSergey Zigachev 
1430b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1431b843c749SSergey Zigachev 			       PP_BLOCK_SYS_BIF,
1432b843c749SSergey Zigachev 			       PP_STATE_SUPPORT_LS,
1433b843c749SSergey Zigachev 			        pp_state);
1434b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1435b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1436b843c749SSergey Zigachev 	}
1437b843c749SSergey Zigachev 	if (adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG) {
1438b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1439b843c749SSergey Zigachev 			pp_state = 0;
1440b843c749SSergey Zigachev 		else
1441b843c749SSergey Zigachev 			pp_state = PP_STATE_CG;
1442b843c749SSergey Zigachev 
1443b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1444b843c749SSergey Zigachev 			       PP_BLOCK_SYS_BIF,
1445b843c749SSergey Zigachev 			       PP_STATE_SUPPORT_CG,
1446b843c749SSergey Zigachev 			       pp_state);
1447b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1448b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1449b843c749SSergey Zigachev 	}
1450b843c749SSergey Zigachev 
1451b843c749SSergey Zigachev 	if (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS) {
1452b843c749SSergey Zigachev 
1453b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1454b843c749SSergey Zigachev 			pp_state = 0;
1455b843c749SSergey Zigachev 		else
1456b843c749SSergey Zigachev 			pp_state = PP_STATE_LS;
1457b843c749SSergey Zigachev 
1458b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1459b843c749SSergey Zigachev 			       PP_BLOCK_SYS_DRM,
1460b843c749SSergey Zigachev 			       PP_STATE_SUPPORT_LS,
1461b843c749SSergey Zigachev 			       pp_state);
1462b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1463b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1464b843c749SSergey Zigachev 	}
1465b843c749SSergey Zigachev 
1466b843c749SSergey Zigachev 	if (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG) {
1467b843c749SSergey Zigachev 
1468b843c749SSergey Zigachev 		if (state == AMD_CG_STATE_UNGATE)
1469b843c749SSergey Zigachev 			pp_state = 0;
1470b843c749SSergey Zigachev 		else
1471b843c749SSergey Zigachev 			pp_state = PP_STATE_CG;
1472b843c749SSergey Zigachev 
1473b843c749SSergey Zigachev 		msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1474b843c749SSergey Zigachev 			       PP_BLOCK_SYS_ROM,
1475b843c749SSergey Zigachev 			       PP_STATE_SUPPORT_CG,
1476b843c749SSergey Zigachev 			       pp_state);
1477b843c749SSergey Zigachev 		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1478b843c749SSergey Zigachev 			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
1479b843c749SSergey Zigachev 	}
1480b843c749SSergey Zigachev 	return 0;
1481b843c749SSergey Zigachev }
1482b843c749SSergey Zigachev 
vi_common_set_clockgating_state(void * handle,enum amd_clockgating_state state)1483b843c749SSergey Zigachev static int vi_common_set_clockgating_state(void *handle,
1484b843c749SSergey Zigachev 					   enum amd_clockgating_state state)
1485b843c749SSergey Zigachev {
1486b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1487b843c749SSergey Zigachev 
1488b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev))
1489b843c749SSergey Zigachev 		return 0;
1490b843c749SSergey Zigachev 
1491b843c749SSergey Zigachev 	switch (adev->asic_type) {
1492b843c749SSergey Zigachev 	case CHIP_FIJI:
1493b843c749SSergey Zigachev 		vi_update_bif_medium_grain_light_sleep(adev,
1494b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1495b843c749SSergey Zigachev 		vi_update_hdp_medium_grain_clock_gating(adev,
1496b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1497b843c749SSergey Zigachev 		vi_update_hdp_light_sleep(adev,
1498b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1499b843c749SSergey Zigachev 		vi_update_rom_medium_grain_clock_gating(adev,
1500b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1501b843c749SSergey Zigachev 		break;
1502b843c749SSergey Zigachev 	case CHIP_CARRIZO:
1503b843c749SSergey Zigachev 	case CHIP_STONEY:
1504b843c749SSergey Zigachev 		vi_update_bif_medium_grain_light_sleep(adev,
1505b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1506b843c749SSergey Zigachev 		vi_update_hdp_medium_grain_clock_gating(adev,
1507b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1508b843c749SSergey Zigachev 		vi_update_hdp_light_sleep(adev,
1509b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1510b843c749SSergey Zigachev 		vi_update_drm_light_sleep(adev,
1511b843c749SSergey Zigachev 				state == AMD_CG_STATE_GATE);
1512b843c749SSergey Zigachev 		break;
1513b843c749SSergey Zigachev 	case CHIP_TONGA:
1514b843c749SSergey Zigachev 	case CHIP_POLARIS10:
1515b843c749SSergey Zigachev 	case CHIP_POLARIS11:
1516b843c749SSergey Zigachev 	case CHIP_POLARIS12:
1517b843c749SSergey Zigachev 	case CHIP_VEGAM:
1518b843c749SSergey Zigachev 		vi_common_set_clockgating_state_by_smu(adev, state);
1519b843c749SSergey Zigachev 	default:
1520b843c749SSergey Zigachev 		break;
1521b843c749SSergey Zigachev 	}
1522b843c749SSergey Zigachev 	return 0;
1523b843c749SSergey Zigachev }
1524b843c749SSergey Zigachev 
vi_common_set_powergating_state(void * handle,enum amd_powergating_state state)1525b843c749SSergey Zigachev static int vi_common_set_powergating_state(void *handle,
1526b843c749SSergey Zigachev 					    enum amd_powergating_state state)
1527b843c749SSergey Zigachev {
1528b843c749SSergey Zigachev 	return 0;
1529b843c749SSergey Zigachev }
1530b843c749SSergey Zigachev 
vi_common_get_clockgating_state(void * handle,u32 * flags)1531b843c749SSergey Zigachev static void vi_common_get_clockgating_state(void *handle, u32 *flags)
1532b843c749SSergey Zigachev {
1533b843c749SSergey Zigachev 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1534b843c749SSergey Zigachev 	int data;
1535b843c749SSergey Zigachev 
1536b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev))
1537b843c749SSergey Zigachev 		*flags = 0;
1538b843c749SSergey Zigachev 
1539b843c749SSergey Zigachev 	/* AMD_CG_SUPPORT_BIF_LS */
1540b843c749SSergey Zigachev 	data = RREG32_PCIE(ixPCIE_CNTL2);
1541b843c749SSergey Zigachev 	if (data & PCIE_CNTL2__SLV_MEM_LS_EN_MASK)
1542b843c749SSergey Zigachev 		*flags |= AMD_CG_SUPPORT_BIF_LS;
1543b843c749SSergey Zigachev 
1544b843c749SSergey Zigachev 	/* AMD_CG_SUPPORT_HDP_LS */
1545b843c749SSergey Zigachev 	data = RREG32(mmHDP_MEM_POWER_LS);
1546b843c749SSergey Zigachev 	if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1547b843c749SSergey Zigachev 		*flags |= AMD_CG_SUPPORT_HDP_LS;
1548b843c749SSergey Zigachev 
1549b843c749SSergey Zigachev 	/* AMD_CG_SUPPORT_HDP_MGCG */
1550b843c749SSergey Zigachev 	data = RREG32(mmHDP_HOST_PATH_CNTL);
1551b843c749SSergey Zigachev 	if (!(data & HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK))
1552b843c749SSergey Zigachev 		*flags |= AMD_CG_SUPPORT_HDP_MGCG;
1553b843c749SSergey Zigachev 
1554b843c749SSergey Zigachev 	/* AMD_CG_SUPPORT_ROM_MGCG */
1555b843c749SSergey Zigachev 	data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1556b843c749SSergey Zigachev 	if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
1557b843c749SSergey Zigachev 		*flags |= AMD_CG_SUPPORT_ROM_MGCG;
1558b843c749SSergey Zigachev }
1559b843c749SSergey Zigachev 
1560b843c749SSergey Zigachev static const struct amd_ip_funcs vi_common_ip_funcs = {
1561b843c749SSergey Zigachev 	.name = "vi_common",
1562b843c749SSergey Zigachev 	.early_init = vi_common_early_init,
1563b843c749SSergey Zigachev 	.late_init = vi_common_late_init,
1564b843c749SSergey Zigachev 	.sw_init = vi_common_sw_init,
1565b843c749SSergey Zigachev 	.sw_fini = vi_common_sw_fini,
1566b843c749SSergey Zigachev 	.hw_init = vi_common_hw_init,
1567b843c749SSergey Zigachev 	.hw_fini = vi_common_hw_fini,
1568b843c749SSergey Zigachev 	.suspend = vi_common_suspend,
1569b843c749SSergey Zigachev 	.resume = vi_common_resume,
1570b843c749SSergey Zigachev 	.is_idle = vi_common_is_idle,
1571b843c749SSergey Zigachev 	.wait_for_idle = vi_common_wait_for_idle,
1572b843c749SSergey Zigachev 	.soft_reset = vi_common_soft_reset,
1573b843c749SSergey Zigachev 	.set_clockgating_state = vi_common_set_clockgating_state,
1574b843c749SSergey Zigachev 	.set_powergating_state = vi_common_set_powergating_state,
1575b843c749SSergey Zigachev 	.get_clockgating_state = vi_common_get_clockgating_state,
1576b843c749SSergey Zigachev };
1577b843c749SSergey Zigachev 
1578b843c749SSergey Zigachev static const struct amdgpu_ip_block_version vi_common_ip_block =
1579b843c749SSergey Zigachev {
1580b843c749SSergey Zigachev 	.type = AMD_IP_BLOCK_TYPE_COMMON,
1581b843c749SSergey Zigachev 	.major = 1,
1582b843c749SSergey Zigachev 	.minor = 0,
1583b843c749SSergey Zigachev 	.rev = 0,
1584b843c749SSergey Zigachev 	.funcs = &vi_common_ip_funcs,
1585b843c749SSergey Zigachev };
1586b843c749SSergey Zigachev 
vi_set_ip_blocks(struct amdgpu_device * adev)1587b843c749SSergey Zigachev int vi_set_ip_blocks(struct amdgpu_device *adev)
1588b843c749SSergey Zigachev {
1589b843c749SSergey Zigachev 	/* in early init stage, vbios code won't work */
1590b843c749SSergey Zigachev 	vi_detect_hw_virtualization(adev);
1591b843c749SSergey Zigachev 
1592b843c749SSergey Zigachev 	if (amdgpu_sriov_vf(adev))
1593b843c749SSergey Zigachev 		adev->virt.ops = &xgpu_vi_virt_ops;
1594b843c749SSergey Zigachev 
1595b843c749SSergey Zigachev 	switch (adev->asic_type) {
1596b843c749SSergey Zigachev 	case CHIP_TOPAZ:
1597b843c749SSergey Zigachev 		/* topaz has no DCE, UVD, VCE */
1598b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1599b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gmc_v7_4_ip_block);
1600b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &iceland_ih_ip_block);
1601b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1602b843c749SSergey Zigachev 		if (adev->enable_virtual_display)
1603b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1604b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1605b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &sdma_v2_4_ip_block);
1606b843c749SSergey Zigachev 		break;
1607b843c749SSergey Zigachev 	case CHIP_FIJI:
1608b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1609b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gmc_v8_5_ip_block);
1610b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &tonga_ih_ip_block);
1611b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1612b843c749SSergey Zigachev 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
1613b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1614b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC)
1615b843c749SSergey Zigachev 		else if (amdgpu_device_has_dc_support(adev))
1616b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
1617b843c749SSergey Zigachev #endif
1618b843c749SSergey Zigachev 		else
1619b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_v10_1_ip_block);
1620b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1621b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
1622b843c749SSergey Zigachev 		if (!amdgpu_sriov_vf(adev)) {
1623b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &uvd_v6_0_ip_block);
1624b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &vce_v3_0_ip_block);
1625b843c749SSergey Zigachev 		}
1626b843c749SSergey Zigachev 		break;
1627b843c749SSergey Zigachev 	case CHIP_TONGA:
1628b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1629b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gmc_v8_0_ip_block);
1630b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &tonga_ih_ip_block);
1631b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1632b843c749SSergey Zigachev 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
1633b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1634b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC)
1635b843c749SSergey Zigachev 		else if (amdgpu_device_has_dc_support(adev))
1636b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
1637b843c749SSergey Zigachev #endif
1638b843c749SSergey Zigachev 		else
1639b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_v10_0_ip_block);
1640b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1641b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
1642b843c749SSergey Zigachev 		if (!amdgpu_sriov_vf(adev)) {
1643b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &uvd_v5_0_ip_block);
1644b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &vce_v3_0_ip_block);
1645b843c749SSergey Zigachev 		}
1646b843c749SSergey Zigachev 		break;
1647b843c749SSergey Zigachev 	case CHIP_POLARIS10:
1648b843c749SSergey Zigachev 	case CHIP_POLARIS11:
1649b843c749SSergey Zigachev 	case CHIP_POLARIS12:
1650b843c749SSergey Zigachev 	case CHIP_VEGAM:
1651b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1652b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gmc_v8_1_ip_block);
1653b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &tonga_ih_ip_block);
1654b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1655b843c749SSergey Zigachev 		if (adev->enable_virtual_display)
1656b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1657b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC)
1658b843c749SSergey Zigachev 		else if (amdgpu_device_has_dc_support(adev))
1659b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
1660b843c749SSergey Zigachev #endif
1661b843c749SSergey Zigachev 		else
1662b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_v11_2_ip_block);
1663b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1664b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &sdma_v3_1_ip_block);
1665b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &uvd_v6_3_ip_block);
1666b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vce_v3_4_ip_block);
1667b843c749SSergey Zigachev 		break;
1668b843c749SSergey Zigachev 	case CHIP_CARRIZO:
1669b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1670b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gmc_v8_0_ip_block);
1671b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &cz_ih_ip_block);
1672b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1673b843c749SSergey Zigachev 		if (adev->enable_virtual_display)
1674b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1675b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC)
1676b843c749SSergey Zigachev 		else if (amdgpu_device_has_dc_support(adev))
1677b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
1678b843c749SSergey Zigachev #endif
1679b843c749SSergey Zigachev 		else
1680b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_v11_0_ip_block);
1681b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1682b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
1683b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &uvd_v6_0_ip_block);
1684b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vce_v3_1_ip_block);
1685b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_ACP)
1686b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &acp_ip_block);
1687b843c749SSergey Zigachev #endif
1688b843c749SSergey Zigachev 		break;
1689b843c749SSergey Zigachev 	case CHIP_STONEY:
1690b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1691b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gmc_v8_0_ip_block);
1692b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &cz_ih_ip_block);
1693b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1694b843c749SSergey Zigachev 		if (adev->enable_virtual_display)
1695b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1696b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC)
1697b843c749SSergey Zigachev 		else if (amdgpu_device_has_dc_support(adev))
1698b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
1699b843c749SSergey Zigachev #endif
1700b843c749SSergey Zigachev 		else
1701b843c749SSergey Zigachev 			amdgpu_device_ip_block_add(adev, &dce_v11_0_ip_block);
1702b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &gfx_v8_1_ip_block);
1703b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
1704b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &uvd_v6_2_ip_block);
1705b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &vce_v3_4_ip_block);
1706b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_ACP)
1707b843c749SSergey Zigachev 		amdgpu_device_ip_block_add(adev, &acp_ip_block);
1708b843c749SSergey Zigachev #endif
1709b843c749SSergey Zigachev 		break;
1710b843c749SSergey Zigachev 	default:
1711b843c749SSergey Zigachev 		/* FIXME: not supported yet */
1712b843c749SSergey Zigachev 		return -EINVAL;
1713b843c749SSergey Zigachev 	}
1714b843c749SSergey Zigachev 
1715b843c749SSergey Zigachev 	return 0;
1716b843c749SSergey Zigachev }
1717