blob: 82175517c73c8c21bd651692645360b56874d798 [file] [log] [blame]
Alex Deucheraaa36a92015-04-20 17:31:14 -04001/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
Alex Deucheraaa36a92015-04-20 17:31:14 -040023#include <linux/slab.h>
Alex Deucheraaa36a92015-04-20 17:31:14 -040024#include "drmP.h"
25#include "amdgpu.h"
26#include "amdgpu_atombios.h"
27#include "amdgpu_ih.h"
28#include "amdgpu_uvd.h"
29#include "amdgpu_vce.h"
30#include "amdgpu_ucode.h"
31#include "atom.h"
Alex Deucherd0dd7f02015-11-11 19:45:06 -050032#include "amd_pcie.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040033
34#include "gmc/gmc_8_1_d.h"
35#include "gmc/gmc_8_1_sh_mask.h"
36
37#include "oss/oss_3_0_d.h"
38#include "oss/oss_3_0_sh_mask.h"
39
40#include "bif/bif_5_0_d.h"
41#include "bif/bif_5_0_sh_mask.h"
42
43#include "gca/gfx_8_0_d.h"
44#include "gca/gfx_8_0_sh_mask.h"
45
46#include "smu/smu_7_1_1_d.h"
47#include "smu/smu_7_1_1_sh_mask.h"
48
49#include "uvd/uvd_5_0_d.h"
50#include "uvd/uvd_5_0_sh_mask.h"
51
52#include "vce/vce_3_0_d.h"
53#include "vce/vce_3_0_sh_mask.h"
54
55#include "dce/dce_10_0_d.h"
56#include "dce/dce_10_0_sh_mask.h"
57
58#include "vid.h"
59#include "vi.h"
60#include "vi_dpm.h"
61#include "gmc_v8_0.h"
Ken Wang429c45d2016-02-03 19:16:54 +080062#include "gmc_v7_0.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040063#include "gfx_v8_0.h"
64#include "sdma_v2_4.h"
65#include "sdma_v3_0.h"
66#include "dce_v10_0.h"
67#include "dce_v11_0.h"
68#include "iceland_ih.h"
69#include "tonga_ih.h"
70#include "cz_ih.h"
71#include "uvd_v5_0.h"
72#include "uvd_v6_0.h"
73#include "vce_v3_0.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050074#include "amdgpu_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040075#if defined(CONFIG_DRM_AMD_ACP)
76#include "amdgpu_acp.h"
77#endif
Emily Denge9ed3a62016-08-08 11:36:45 +080078#include "dce_virtual.h"
Xiangliang Yu99581cc2017-01-12 15:22:18 +080079#include "mxgpu_vi.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040080
81/*
82 * Indirect registers accessor
83 */
84static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
85{
86 unsigned long flags;
87 u32 r;
88
89 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
90 WREG32(mmPCIE_INDEX, reg);
91 (void)RREG32(mmPCIE_INDEX);
92 r = RREG32(mmPCIE_DATA);
93 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
94 return r;
95}
96
97static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
98{
99 unsigned long flags;
100
101 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
102 WREG32(mmPCIE_INDEX, reg);
103 (void)RREG32(mmPCIE_INDEX);
104 WREG32(mmPCIE_DATA, v);
105 (void)RREG32(mmPCIE_DATA);
106 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
107}
108
109static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
110{
111 unsigned long flags;
112 u32 r;
113
114 spin_lock_irqsave(&adev->smc_idx_lock, flags);
Monk Liu4bc10d12016-03-29 11:01:51 +0800115 WREG32(mmSMC_IND_INDEX_11, (reg));
116 r = RREG32(mmSMC_IND_DATA_11);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400117 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
118 return r;
119}
120
121static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
122{
123 unsigned long flags;
124
125 spin_lock_irqsave(&adev->smc_idx_lock, flags);
Monk Liu4bc10d12016-03-29 11:01:51 +0800126 WREG32(mmSMC_IND_INDEX_11, (reg));
127 WREG32(mmSMC_IND_DATA_11, (v));
Alex Deucheraaa36a92015-04-20 17:31:14 -0400128 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
129}
130
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400131/* smu_8_0_d.h */
132#define mmMP0PUB_IND_INDEX 0x180
133#define mmMP0PUB_IND_DATA 0x181
134
135static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
136{
137 unsigned long flags;
138 u32 r;
139
140 spin_lock_irqsave(&adev->smc_idx_lock, flags);
141 WREG32(mmMP0PUB_IND_INDEX, (reg));
142 r = RREG32(mmMP0PUB_IND_DATA);
143 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
144 return r;
145}
146
147static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
148{
149 unsigned long flags;
150
151 spin_lock_irqsave(&adev->smc_idx_lock, flags);
152 WREG32(mmMP0PUB_IND_INDEX, (reg));
153 WREG32(mmMP0PUB_IND_DATA, (v));
154 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
155}
156
Alex Deucheraaa36a92015-04-20 17:31:14 -0400157static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
158{
159 unsigned long flags;
160 u32 r;
161
162 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
163 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
164 r = RREG32(mmUVD_CTX_DATA);
165 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
166 return r;
167}
168
169static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
170{
171 unsigned long flags;
172
173 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
174 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
175 WREG32(mmUVD_CTX_DATA, (v));
176 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
177}
178
179static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
180{
181 unsigned long flags;
182 u32 r;
183
184 spin_lock_irqsave(&adev->didt_idx_lock, flags);
185 WREG32(mmDIDT_IND_INDEX, (reg));
186 r = RREG32(mmDIDT_IND_DATA);
187 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
188 return r;
189}
190
191static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
192{
193 unsigned long flags;
194
195 spin_lock_irqsave(&adev->didt_idx_lock, flags);
196 WREG32(mmDIDT_IND_INDEX, (reg));
197 WREG32(mmDIDT_IND_DATA, (v));
198 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
199}
200
Rex Zhuccdbb202016-06-08 12:47:41 +0800201static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
202{
203 unsigned long flags;
204 u32 r;
205
206 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
207 WREG32(mmGC_CAC_IND_INDEX, (reg));
208 r = RREG32(mmGC_CAC_IND_DATA);
209 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
210 return r;
211}
212
213static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
214{
215 unsigned long flags;
216
217 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
218 WREG32(mmGC_CAC_IND_INDEX, (reg));
219 WREG32(mmGC_CAC_IND_DATA, (v));
220 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
221}
222
223
Alex Deucheraaa36a92015-04-20 17:31:14 -0400224static const u32 tonga_mgcg_cgcg_init[] =
225{
226 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
227 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
228 mmPCIE_DATA, 0x000f0000, 0x00000000,
229 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
230 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400231 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
232 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
233};
234
David Zhang48299f92015-07-08 01:05:16 +0800235static const u32 fiji_mgcg_cgcg_init[] =
236{
237 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
238 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
239 mmPCIE_DATA, 0x000f0000, 0x00000000,
240 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
241 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
242 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
243 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
244};
245
Alex Deucheraaa36a92015-04-20 17:31:14 -0400246static const u32 iceland_mgcg_cgcg_init[] =
247{
248 mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
249 mmPCIE_DATA, 0x000f0000, 0x00000000,
250 mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
251 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
252 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
253};
254
255static const u32 cz_mgcg_cgcg_init[] =
256{
257 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
258 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
259 mmPCIE_DATA, 0x000f0000, 0x00000000,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400260 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
261 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
262};
263
Samuel Li39bb0c92015-10-08 16:31:43 -0400264static const u32 stoney_mgcg_cgcg_init[] =
265{
266 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
267 mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
268 mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
269};
270
Alex Deucheraaa36a92015-04-20 17:31:14 -0400271static void vi_init_golden_registers(struct amdgpu_device *adev)
272{
273 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
274 mutex_lock(&adev->grbm_idx_mutex);
275
Xiangliang Yu99581cc2017-01-12 15:22:18 +0800276 if (amdgpu_sriov_vf(adev)) {
277 xgpu_vi_init_golden_registers(adev);
278 mutex_unlock(&adev->grbm_idx_mutex);
279 return;
280 }
281
Alex Deucheraaa36a92015-04-20 17:31:14 -0400282 switch (adev->asic_type) {
283 case CHIP_TOPAZ:
284 amdgpu_program_register_sequence(adev,
285 iceland_mgcg_cgcg_init,
286 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
287 break;
David Zhang48299f92015-07-08 01:05:16 +0800288 case CHIP_FIJI:
289 amdgpu_program_register_sequence(adev,
290 fiji_mgcg_cgcg_init,
291 (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
292 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400293 case CHIP_TONGA:
294 amdgpu_program_register_sequence(adev,
295 tonga_mgcg_cgcg_init,
296 (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
297 break;
298 case CHIP_CARRIZO:
299 amdgpu_program_register_sequence(adev,
300 cz_mgcg_cgcg_init,
301 (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
302 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400303 case CHIP_STONEY:
304 amdgpu_program_register_sequence(adev,
305 stoney_mgcg_cgcg_init,
306 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
307 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400308 case CHIP_POLARIS11:
309 case CHIP_POLARIS10:
Junwei Zhangc4642a42016-12-14 15:32:28 -0500310 case CHIP_POLARIS12:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400311 default:
312 break;
313 }
314 mutex_unlock(&adev->grbm_idx_mutex);
315}
316
317/**
318 * vi_get_xclk - get the xclk
319 *
320 * @adev: amdgpu_device pointer
321 *
322 * Returns the reference clock used by the gfx engine
323 * (VI).
324 */
325static u32 vi_get_xclk(struct amdgpu_device *adev)
326{
327 u32 reference_clock = adev->clock.spll.reference_freq;
328 u32 tmp;
329
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800330 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400331 return reference_clock;
332
333 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
334 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
335 return 1000;
336
337 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
338 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
339 return reference_clock / 4;
340
341 return reference_clock;
342}
343
344/**
345 * vi_srbm_select - select specific register instances
346 *
347 * @adev: amdgpu_device pointer
348 * @me: selected ME (micro engine)
349 * @pipe: pipe
350 * @queue: queue
351 * @vmid: VMID
352 *
353 * Switches the currently active registers instances. Some
354 * registers are instanced per VMID, others are instanced per
355 * me/pipe/queue combination.
356 */
357void vi_srbm_select(struct amdgpu_device *adev,
358 u32 me, u32 pipe, u32 queue, u32 vmid)
359{
360 u32 srbm_gfx_cntl = 0;
361 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
362 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
363 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
364 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
365 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
366}
367
368static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
369{
370 /* todo */
371}
372
373static bool vi_read_disabled_bios(struct amdgpu_device *adev)
374{
375 u32 bus_cntl;
376 u32 d1vga_control = 0;
377 u32 d2vga_control = 0;
378 u32 vga_render_control = 0;
379 u32 rom_cntl;
380 bool r;
381
382 bus_cntl = RREG32(mmBUS_CNTL);
383 if (adev->mode_info.num_crtc) {
384 d1vga_control = RREG32(mmD1VGA_CONTROL);
385 d2vga_control = RREG32(mmD2VGA_CONTROL);
386 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
387 }
388 rom_cntl = RREG32_SMC(ixROM_CNTL);
389
390 /* enable the rom */
391 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
392 if (adev->mode_info.num_crtc) {
393 /* Disable VGA mode */
394 WREG32(mmD1VGA_CONTROL,
395 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
396 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
397 WREG32(mmD2VGA_CONTROL,
398 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
399 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
400 WREG32(mmVGA_RENDER_CONTROL,
401 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
402 }
403 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
404
405 r = amdgpu_read_bios(adev);
406
407 /* restore regs */
408 WREG32(mmBUS_CNTL, bus_cntl);
409 if (adev->mode_info.num_crtc) {
410 WREG32(mmD1VGA_CONTROL, d1vga_control);
411 WREG32(mmD2VGA_CONTROL, d2vga_control);
412 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
413 }
414 WREG32_SMC(ixROM_CNTL, rom_cntl);
415 return r;
416}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500417
418static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
419 u8 *bios, u32 length_bytes)
420{
421 u32 *dw_ptr;
422 unsigned long flags;
423 u32 i, length_dw;
424
425 if (bios == NULL)
426 return false;
427 if (length_bytes == 0)
428 return false;
429 /* APU vbios image is part of sbios image */
430 if (adev->flags & AMD_IS_APU)
431 return false;
432
433 dw_ptr = (u32 *)bios;
434 length_dw = ALIGN(length_bytes, 4) / 4;
435 /* take the smc lock since we are using the smc index */
436 spin_lock_irqsave(&adev->smc_idx_lock, flags);
437 /* set rom index to 0 */
Monk Liu4bc10d12016-03-29 11:01:51 +0800438 WREG32(mmSMC_IND_INDEX_11, ixROM_INDEX);
439 WREG32(mmSMC_IND_DATA_11, 0);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500440 /* set index to data for continous read */
Monk Liu4bc10d12016-03-29 11:01:51 +0800441 WREG32(mmSMC_IND_INDEX_11, ixROM_DATA);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500442 for (i = 0; i < length_dw; i++)
Monk Liu4bc10d12016-03-29 11:01:51 +0800443 dw_ptr[i] = RREG32(mmSMC_IND_DATA_11);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500444 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
445
446 return true;
447}
448
Monk Liu4e99a442016-03-31 13:26:59 +0800449static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
Andres Rodriguez048765a2016-06-11 02:51:32 -0400450{
Monk Liu4e99a442016-03-31 13:26:59 +0800451 uint32_t reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
452 /* bit0: 0 means pf and 1 means vf */
453 /* bit31: 0 means disable IOV and 1 means enable */
454 if (reg & 1)
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500455 adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF;
Andres Rodriguez048765a2016-06-11 02:51:32 -0400456
Monk Liu4e99a442016-03-31 13:26:59 +0800457 if (reg & 0x80000000)
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500458 adev->virt.caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV;
Andres Rodriguez048765a2016-06-11 02:51:32 -0400459
Monk Liu4e99a442016-03-31 13:26:59 +0800460 if (reg == 0) {
461 if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500462 adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE;
Monk Liu4e99a442016-03-31 13:26:59 +0800463 }
Andres Rodriguez048765a2016-06-11 02:51:32 -0400464}
465
Nils Wallméniuseca22402016-03-19 16:12:17 +0100466static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Christian König97fcc762017-04-12 12:49:54 +0200467 {mmGRBM_STATUS},
468 {mmGRBM_STATUS2},
469 {mmGRBM_STATUS_SE0},
470 {mmGRBM_STATUS_SE1},
471 {mmGRBM_STATUS_SE2},
472 {mmGRBM_STATUS_SE3},
473 {mmSRBM_STATUS},
474 {mmSRBM_STATUS2},
475 {mmSRBM_STATUS3},
476 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET},
477 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET},
478 {mmCP_STAT},
479 {mmCP_STALLED_STAT1},
480 {mmCP_STALLED_STAT2},
481 {mmCP_STALLED_STAT3},
482 {mmCP_CPF_BUSY_STAT},
483 {mmCP_CPF_STALLED_STAT1},
484 {mmCP_CPF_STATUS},
485 {mmCP_CPC_BUSY_STAT},
486 {mmCP_CPC_STALLED_STAT1},
487 {mmCP_CPC_STATUS},
488 {mmGB_ADDR_CONFIG},
489 {mmMC_ARB_RAMCFG},
490 {mmGB_TILE_MODE0},
491 {mmGB_TILE_MODE1},
492 {mmGB_TILE_MODE2},
493 {mmGB_TILE_MODE3},
494 {mmGB_TILE_MODE4},
495 {mmGB_TILE_MODE5},
496 {mmGB_TILE_MODE6},
497 {mmGB_TILE_MODE7},
498 {mmGB_TILE_MODE8},
499 {mmGB_TILE_MODE9},
500 {mmGB_TILE_MODE10},
501 {mmGB_TILE_MODE11},
502 {mmGB_TILE_MODE12},
503 {mmGB_TILE_MODE13},
504 {mmGB_TILE_MODE14},
505 {mmGB_TILE_MODE15},
506 {mmGB_TILE_MODE16},
507 {mmGB_TILE_MODE17},
508 {mmGB_TILE_MODE18},
509 {mmGB_TILE_MODE19},
510 {mmGB_TILE_MODE20},
511 {mmGB_TILE_MODE21},
512 {mmGB_TILE_MODE22},
513 {mmGB_TILE_MODE23},
514 {mmGB_TILE_MODE24},
515 {mmGB_TILE_MODE25},
516 {mmGB_TILE_MODE26},
517 {mmGB_TILE_MODE27},
518 {mmGB_TILE_MODE28},
519 {mmGB_TILE_MODE29},
520 {mmGB_TILE_MODE30},
521 {mmGB_TILE_MODE31},
522 {mmGB_MACROTILE_MODE0},
523 {mmGB_MACROTILE_MODE1},
524 {mmGB_MACROTILE_MODE2},
525 {mmGB_MACROTILE_MODE3},
526 {mmGB_MACROTILE_MODE4},
527 {mmGB_MACROTILE_MODE5},
528 {mmGB_MACROTILE_MODE6},
529 {mmGB_MACROTILE_MODE7},
530 {mmGB_MACROTILE_MODE8},
531 {mmGB_MACROTILE_MODE9},
532 {mmGB_MACROTILE_MODE10},
533 {mmGB_MACROTILE_MODE11},
534 {mmGB_MACROTILE_MODE12},
535 {mmGB_MACROTILE_MODE13},
536 {mmGB_MACROTILE_MODE14},
537 {mmGB_MACROTILE_MODE15},
538 {mmCC_RB_BACKEND_DISABLE, true},
539 {mmGC_USER_RB_BACKEND_DISABLE, true},
540 {mmGB_BACKEND_MAP, false},
541 {mmPA_SC_RASTER_CONFIG, true},
542 {mmPA_SC_RASTER_CONFIG_1, true},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400543};
544
Alex Deucherdb9635c2016-10-10 12:05:32 -0400545static uint32_t vi_get_register_value(struct amdgpu_device *adev,
546 bool indexed, u32 se_num,
547 u32 sh_num, u32 reg_offset)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400548{
Alex Deucherdb9635c2016-10-10 12:05:32 -0400549 if (indexed) {
550 uint32_t val;
551 unsigned se_idx = (se_num == 0xffffffff) ? 0 : se_num;
552 unsigned sh_idx = (sh_num == 0xffffffff) ? 0 : sh_num;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400553
Alex Deucherdb9635c2016-10-10 12:05:32 -0400554 switch (reg_offset) {
555 case mmCC_RB_BACKEND_DISABLE:
556 return adev->gfx.config.rb_config[se_idx][sh_idx].rb_backend_disable;
557 case mmGC_USER_RB_BACKEND_DISABLE:
558 return adev->gfx.config.rb_config[se_idx][sh_idx].user_rb_backend_disable;
559 case mmPA_SC_RASTER_CONFIG:
560 return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config;
561 case mmPA_SC_RASTER_CONFIG_1:
562 return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config_1;
563 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400564
Alex Deucherdb9635c2016-10-10 12:05:32 -0400565 mutex_lock(&adev->grbm_idx_mutex);
566 if (se_num != 0xffffffff || sh_num != 0xffffffff)
567 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400568
Alex Deucherdb9635c2016-10-10 12:05:32 -0400569 val = RREG32(reg_offset);
570
571 if (se_num != 0xffffffff || sh_num != 0xffffffff)
572 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
573 mutex_unlock(&adev->grbm_idx_mutex);
574 return val;
575 } else {
576 unsigned idx;
577
578 switch (reg_offset) {
579 case mmGB_ADDR_CONFIG:
580 return adev->gfx.config.gb_addr_config;
581 case mmMC_ARB_RAMCFG:
582 return adev->gfx.config.mc_arb_ramcfg;
583 case mmGB_TILE_MODE0:
584 case mmGB_TILE_MODE1:
585 case mmGB_TILE_MODE2:
586 case mmGB_TILE_MODE3:
587 case mmGB_TILE_MODE4:
588 case mmGB_TILE_MODE5:
589 case mmGB_TILE_MODE6:
590 case mmGB_TILE_MODE7:
591 case mmGB_TILE_MODE8:
592 case mmGB_TILE_MODE9:
593 case mmGB_TILE_MODE10:
594 case mmGB_TILE_MODE11:
595 case mmGB_TILE_MODE12:
596 case mmGB_TILE_MODE13:
597 case mmGB_TILE_MODE14:
598 case mmGB_TILE_MODE15:
599 case mmGB_TILE_MODE16:
600 case mmGB_TILE_MODE17:
601 case mmGB_TILE_MODE18:
602 case mmGB_TILE_MODE19:
603 case mmGB_TILE_MODE20:
604 case mmGB_TILE_MODE21:
605 case mmGB_TILE_MODE22:
606 case mmGB_TILE_MODE23:
607 case mmGB_TILE_MODE24:
608 case mmGB_TILE_MODE25:
609 case mmGB_TILE_MODE26:
610 case mmGB_TILE_MODE27:
611 case mmGB_TILE_MODE28:
612 case mmGB_TILE_MODE29:
613 case mmGB_TILE_MODE30:
614 case mmGB_TILE_MODE31:
615 idx = (reg_offset - mmGB_TILE_MODE0);
616 return adev->gfx.config.tile_mode_array[idx];
617 case mmGB_MACROTILE_MODE0:
618 case mmGB_MACROTILE_MODE1:
619 case mmGB_MACROTILE_MODE2:
620 case mmGB_MACROTILE_MODE3:
621 case mmGB_MACROTILE_MODE4:
622 case mmGB_MACROTILE_MODE5:
623 case mmGB_MACROTILE_MODE6:
624 case mmGB_MACROTILE_MODE7:
625 case mmGB_MACROTILE_MODE8:
626 case mmGB_MACROTILE_MODE9:
627 case mmGB_MACROTILE_MODE10:
628 case mmGB_MACROTILE_MODE11:
629 case mmGB_MACROTILE_MODE12:
630 case mmGB_MACROTILE_MODE13:
631 case mmGB_MACROTILE_MODE14:
632 case mmGB_MACROTILE_MODE15:
633 idx = (reg_offset - mmGB_MACROTILE_MODE0);
634 return adev->gfx.config.macrotile_mode_array[idx];
635 default:
636 return RREG32(reg_offset);
637 }
638 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400639}
640
641static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
642 u32 sh_num, u32 reg_offset, u32 *value)
643{
Christian König3032f352017-04-12 12:53:18 +0200644 uint32_t i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400645
646 *value = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400647 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
Christian König97fcc762017-04-12 12:49:54 +0200648 bool indexed = vi_allowed_read_registers[i].grbm_indexed;
649
Alex Deucheraaa36a92015-04-20 17:31:14 -0400650 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
651 continue;
652
Christian König97fcc762017-04-12 12:49:54 +0200653 *value = vi_get_register_value(adev, indexed, se_num, sh_num,
654 reg_offset);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400655 return 0;
656 }
657 return -EINVAL;
658}
659
Chunming Zhou89a31822016-06-06 13:06:45 +0800660static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400661{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400662 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400663
664 dev_info(adev->dev, "GPU pci config reset\n");
665
Alex Deucheraaa36a92015-04-20 17:31:14 -0400666 /* disable BM */
667 pci_clear_master(adev->pdev);
668 /* reset */
669 amdgpu_pci_config_reset(adev);
670
671 udelay(100);
672
673 /* wait for asic to come out of reset */
674 for (i = 0; i < adev->usec_timeout; i++) {
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800675 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
676 /* enable BM */
677 pci_set_master(adev->pdev);
Jim Quc836fec2017-02-10 15:59:59 +0800678 adev->has_hw_reset = true;
Chunming Zhou89a31822016-06-06 13:06:45 +0800679 return 0;
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800680 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400681 udelay(1);
682 }
Chunming Zhou89a31822016-06-06 13:06:45 +0800683 return -EINVAL;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400684}
685
Alex Deucheraaa36a92015-04-20 17:31:14 -0400686/**
687 * vi_asic_reset - soft reset GPU
688 *
689 * @adev: amdgpu_device pointer
690 *
691 * Look up which blocks are hung and attempt
692 * to reset them.
693 * Returns 0 for success.
694 */
695static int vi_asic_reset(struct amdgpu_device *adev)
696{
Chunming Zhou89a31822016-06-06 13:06:45 +0800697 int r;
698
Alex Deucher72a57432016-10-21 15:45:22 -0400699 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400700
Chunming Zhou89a31822016-06-06 13:06:45 +0800701 r = vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400702
Alex Deucher72a57432016-10-21 15:45:22 -0400703 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400704
Chunming Zhou89a31822016-06-06 13:06:45 +0800705 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400706}
707
Alex Deucherbbf282d2017-03-03 17:26:10 -0500708static u32 vi_get_config_memsize(struct amdgpu_device *adev)
709{
710 return RREG32(mmCONFIG_MEMSIZE);
711}
712
Alex Deucheraaa36a92015-04-20 17:31:14 -0400713static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
714 u32 cntl_reg, u32 status_reg)
715{
716 int r, i;
717 struct atom_clock_dividers dividers;
718 uint32_t tmp;
719
720 r = amdgpu_atombios_get_clock_dividers(adev,
721 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
722 clock, false, &dividers);
723 if (r)
724 return r;
725
726 tmp = RREG32_SMC(cntl_reg);
727 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
728 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
729 tmp |= dividers.post_divider;
730 WREG32_SMC(cntl_reg, tmp);
731
732 for (i = 0; i < 100; i++) {
733 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
734 break;
735 mdelay(10);
736 }
737 if (i == 100)
738 return -ETIMEDOUT;
739
740 return 0;
741}
742
743static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
744{
745 int r;
746
747 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
748 if (r)
749 return r;
750
751 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
Alex Deucherd319c2b2017-03-15 22:05:20 -0400752 if (r)
753 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400754
755 return 0;
756}
757
758static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
759{
Rex Zhu714b1f52017-01-10 19:54:25 +0800760 int r, i;
761 struct atom_clock_dividers dividers;
762 u32 tmp;
763
764 r = amdgpu_atombios_get_clock_dividers(adev,
765 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
766 ecclk, false, &dividers);
767 if (r)
768 return r;
769
770 for (i = 0; i < 100; i++) {
771 if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
772 break;
773 mdelay(10);
774 }
775 if (i == 100)
776 return -ETIMEDOUT;
777
778 tmp = RREG32_SMC(ixCG_ECLK_CNTL);
779 tmp &= ~(CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK |
780 CG_ECLK_CNTL__ECLK_DIVIDER_MASK);
781 tmp |= dividers.post_divider;
782 WREG32_SMC(ixCG_ECLK_CNTL, tmp);
783
784 for (i = 0; i < 100; i++) {
785 if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
786 break;
787 mdelay(10);
788 }
789 if (i == 100)
790 return -ETIMEDOUT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400791
792 return 0;
793}
794
795static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
796{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400797 if (pci_is_root_bus(adev->pdev->bus))
798 return;
799
Alex Deucheraaa36a92015-04-20 17:31:14 -0400800 if (amdgpu_pcie_gen2 == 0)
801 return;
802
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800803 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400804 return;
805
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500806 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
807 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400808 return;
809
810 /* todo */
811}
812
813static void vi_program_aspm(struct amdgpu_device *adev)
814{
815
816 if (amdgpu_aspm == 0)
817 return;
818
819 /* todo */
820}
821
822static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
823 bool enable)
824{
825 u32 tmp;
826
827 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800828 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400829 return;
830
831 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
832 if (enable)
833 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
834 else
835 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
836
837 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
838}
839
Samuel Li39bb0c92015-10-08 16:31:43 -0400840#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
841#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
842#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
843
Alex Deucheraaa36a92015-04-20 17:31:14 -0400844static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
845{
Flora Cuiabdfb852015-11-20 11:40:53 +0800846 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -0400847 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
848 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400849 else
Flora Cuiabdfb852015-11-20 11:40:53 +0800850 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
851 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400852}
853
854static const struct amdgpu_asic_funcs vi_asic_funcs =
855{
856 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -0500857 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400858 .read_register = &vi_read_register,
859 .reset = &vi_asic_reset,
860 .set_vga_state = &vi_vga_set_state,
861 .get_xclk = &vi_get_xclk,
862 .set_uvd_clocks = &vi_set_uvd_clocks,
863 .set_vce_clocks = &vi_set_vce_clocks,
Alex Deucherbbf282d2017-03-03 17:26:10 -0500864 .get_config_memsize = &vi_get_config_memsize,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400865};
866
Eric Huang170d6e92016-08-12 13:47:08 -0400867#define CZ_REV_BRISTOL(rev) \
868 ((rev >= 0xC8 && rev <= 0xCE) || (rev >= 0xE1 && rev <= 0xE6))
869
yanyang15fc3aee2015-05-22 14:39:35 -0400870static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400871{
872 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -0400873 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400874
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800875 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400876 adev->smc_rreg = &cz_smc_rreg;
877 adev->smc_wreg = &cz_smc_wreg;
878 } else {
879 adev->smc_rreg = &vi_smc_rreg;
880 adev->smc_wreg = &vi_smc_wreg;
881 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400882 adev->pcie_rreg = &vi_pcie_rreg;
883 adev->pcie_wreg = &vi_pcie_wreg;
884 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
885 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
886 adev->didt_rreg = &vi_didt_rreg;
887 adev->didt_wreg = &vi_didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +0800888 adev->gc_cac_rreg = &vi_gc_cac_rreg;
889 adev->gc_cac_wreg = &vi_gc_cac_wreg;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400890
891 adev->asic_funcs = &vi_asic_funcs;
892
yanyang15fc3aee2015-05-22 14:39:35 -0400893 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
894 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400895 smc_enabled = true;
896
897 adev->rev_id = vi_get_rev_id(adev);
898 adev->external_rev_id = 0xFF;
899 switch (adev->asic_type) {
900 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400901 adev->cg_flags = 0;
902 adev->pg_flags = 0;
903 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400904 break;
David Zhang48299f92015-07-08 01:05:16 +0800905 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -0400906 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
907 AMD_CG_SUPPORT_GFX_MGLS |
908 AMD_CG_SUPPORT_GFX_RLC_LS |
909 AMD_CG_SUPPORT_GFX_CP_LS |
910 AMD_CG_SUPPORT_GFX_CGTS |
911 AMD_CG_SUPPORT_GFX_CGTS_LS |
912 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -0400913 AMD_CG_SUPPORT_GFX_CGLS |
914 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -0400915 AMD_CG_SUPPORT_SDMA_LS |
916 AMD_CG_SUPPORT_BIF_LS |
917 AMD_CG_SUPPORT_HDP_MGCG |
918 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -0400919 AMD_CG_SUPPORT_ROM_MGCG |
920 AMD_CG_SUPPORT_MC_MGCG |
Rex Zhu79abf1a2016-11-09 14:30:25 +0800921 AMD_CG_SUPPORT_MC_LS |
922 AMD_CG_SUPPORT_UVD_MGCG;
Flora Cuib6bc28f2015-11-02 21:21:34 +0800923 adev->pg_flags = 0;
924 adev->external_rev_id = adev->rev_id + 0x3c;
925 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400926 case CHIP_TONGA:
Rex Zhuca18b842016-12-07 18:22:38 +0800927 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
928 AMD_CG_SUPPORT_GFX_CGCG |
929 AMD_CG_SUPPORT_GFX_CGLS |
930 AMD_CG_SUPPORT_SDMA_MGCG |
931 AMD_CG_SUPPORT_SDMA_LS |
932 AMD_CG_SUPPORT_BIF_LS |
933 AMD_CG_SUPPORT_HDP_MGCG |
934 AMD_CG_SUPPORT_HDP_LS |
935 AMD_CG_SUPPORT_ROM_MGCG |
936 AMD_CG_SUPPORT_MC_MGCG |
937 AMD_CG_SUPPORT_MC_LS |
938 AMD_CG_SUPPORT_DRM_LS |
939 AMD_CG_SUPPORT_UVD_MGCG;
Rex Zhu54971402016-12-07 16:06:38 +0800940 adev->pg_flags = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400941 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400942 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400943 case CHIP_POLARIS11:
Rex Zhuca18b842016-12-07 18:22:38 +0800944 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
945 AMD_CG_SUPPORT_GFX_RLC_LS |
946 AMD_CG_SUPPORT_GFX_CP_LS |
947 AMD_CG_SUPPORT_GFX_CGCG |
948 AMD_CG_SUPPORT_GFX_CGLS |
949 AMD_CG_SUPPORT_GFX_3D_CGCG |
950 AMD_CG_SUPPORT_GFX_3D_CGLS |
951 AMD_CG_SUPPORT_SDMA_MGCG |
952 AMD_CG_SUPPORT_SDMA_LS |
953 AMD_CG_SUPPORT_BIF_MGCG |
954 AMD_CG_SUPPORT_BIF_LS |
955 AMD_CG_SUPPORT_HDP_MGCG |
956 AMD_CG_SUPPORT_HDP_LS |
957 AMD_CG_SUPPORT_ROM_MGCG |
958 AMD_CG_SUPPORT_MC_MGCG |
959 AMD_CG_SUPPORT_MC_LS |
960 AMD_CG_SUPPORT_DRM_LS |
961 AMD_CG_SUPPORT_UVD_MGCG |
Maruthi Srinivas Bayyavarapuecc2cf72016-11-17 17:29:50 +0530962 AMD_CG_SUPPORT_VCE_MGCG;
Flora Cuic0c1f572015-12-07 18:33:10 +0800963 adev->pg_flags = 0;
964 adev->external_rev_id = adev->rev_id + 0x5A;
965 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400966 case CHIP_POLARIS10:
Rex Zhuca18b842016-12-07 18:22:38 +0800967 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
968 AMD_CG_SUPPORT_GFX_RLC_LS |
969 AMD_CG_SUPPORT_GFX_CP_LS |
970 AMD_CG_SUPPORT_GFX_CGCG |
971 AMD_CG_SUPPORT_GFX_CGLS |
972 AMD_CG_SUPPORT_GFX_3D_CGCG |
973 AMD_CG_SUPPORT_GFX_3D_CGLS |
974 AMD_CG_SUPPORT_SDMA_MGCG |
975 AMD_CG_SUPPORT_SDMA_LS |
976 AMD_CG_SUPPORT_BIF_MGCG |
977 AMD_CG_SUPPORT_BIF_LS |
978 AMD_CG_SUPPORT_HDP_MGCG |
979 AMD_CG_SUPPORT_HDP_LS |
980 AMD_CG_SUPPORT_ROM_MGCG |
981 AMD_CG_SUPPORT_MC_MGCG |
982 AMD_CG_SUPPORT_MC_LS |
983 AMD_CG_SUPPORT_DRM_LS |
984 AMD_CG_SUPPORT_UVD_MGCG |
Maruthi Srinivas Bayyavarapuecc2cf72016-11-17 17:29:50 +0530985 AMD_CG_SUPPORT_VCE_MGCG;
Flora Cuic0c1f572015-12-07 18:33:10 +0800986 adev->pg_flags = 0;
987 adev->external_rev_id = adev->rev_id + 0x50;
988 break;
Junwei Zhangc4642a42016-12-14 15:32:28 -0500989 case CHIP_POLARIS12:
Rex Zhu739e9ff2017-03-17 19:04:55 +0800990 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
991 AMD_CG_SUPPORT_GFX_RLC_LS |
992 AMD_CG_SUPPORT_GFX_CP_LS |
993 AMD_CG_SUPPORT_GFX_CGCG |
994 AMD_CG_SUPPORT_GFX_CGLS |
995 AMD_CG_SUPPORT_GFX_3D_CGCG |
996 AMD_CG_SUPPORT_GFX_3D_CGLS |
997 AMD_CG_SUPPORT_SDMA_MGCG |
998 AMD_CG_SUPPORT_SDMA_LS |
999 AMD_CG_SUPPORT_BIF_MGCG |
1000 AMD_CG_SUPPORT_BIF_LS |
1001 AMD_CG_SUPPORT_HDP_MGCG |
1002 AMD_CG_SUPPORT_HDP_LS |
1003 AMD_CG_SUPPORT_ROM_MGCG |
1004 AMD_CG_SUPPORT_MC_MGCG |
1005 AMD_CG_SUPPORT_MC_LS |
1006 AMD_CG_SUPPORT_DRM_LS |
1007 AMD_CG_SUPPORT_UVD_MGCG |
1008 AMD_CG_SUPPORT_VCE_MGCG;
Junwei Zhangc4642a42016-12-14 15:32:28 -05001009 adev->pg_flags = 0;
1010 adev->external_rev_id = adev->rev_id + 0x64;
1011 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001012 case CHIP_CARRIZO:
Tom St Denisf0f3a8f2016-05-03 10:36:28 -04001013 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1014 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucher70eced92016-04-07 23:01:48 -04001015 AMD_CG_SUPPORT_GFX_MGLS |
1016 AMD_CG_SUPPORT_GFX_RLC_LS |
1017 AMD_CG_SUPPORT_GFX_CP_LS |
1018 AMD_CG_SUPPORT_GFX_CGTS |
Alex Deucher70eced92016-04-07 23:01:48 -04001019 AMD_CG_SUPPORT_GFX_CGTS_LS |
1020 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001021 AMD_CG_SUPPORT_GFX_CGLS |
1022 AMD_CG_SUPPORT_BIF_LS |
1023 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001024 AMD_CG_SUPPORT_HDP_LS |
1025 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis1af69a22016-08-03 10:16:17 -04001026 AMD_CG_SUPPORT_SDMA_LS |
1027 AMD_CG_SUPPORT_VCE_MGCG;
Tom St Denisf6ade302016-07-28 09:33:56 -04001028 /* rev0 hardware requires workarounds to support PG */
Alex Deucher0fd4af92016-02-04 23:31:32 -05001029 adev->pg_flags = 0;
Eric Huang170d6e92016-08-12 13:47:08 -04001030 if (adev->rev_id != 0x00 || CZ_REV_BRISTOL(adev->pdev->revision)) {
Alex Deucher4fdca892017-03-17 15:27:06 -04001031 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
Tom St Denisf6ade302016-07-28 09:33:56 -04001032 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denis65b42622016-07-28 09:35:57 -04001033 AMD_PG_SUPPORT_GFX_PIPELINE |
Rex Zhu98fccc72016-12-07 17:48:48 +08001034 AMD_PG_SUPPORT_CP |
Tom St Denis2ed09362016-07-28 09:36:26 -04001035 AMD_PG_SUPPORT_UVD |
1036 AMD_PG_SUPPORT_VCE;
Tom St Denisf6ade302016-07-28 09:33:56 -04001037 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001038 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001039 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001040 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001041 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1042 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001043 AMD_CG_SUPPORT_GFX_MGLS |
Tom St Denis413cf602016-06-02 08:52:39 -04001044 AMD_CG_SUPPORT_GFX_RLC_LS |
1045 AMD_CG_SUPPORT_GFX_CP_LS |
1046 AMD_CG_SUPPORT_GFX_CGTS |
Tom St Denis413cf602016-06-02 08:52:39 -04001047 AMD_CG_SUPPORT_GFX_CGTS_LS |
1048 AMD_CG_SUPPORT_GFX_CGCG |
1049 AMD_CG_SUPPORT_GFX_CGLS |
Alex Deucherb6711d12016-04-13 12:41:50 -04001050 AMD_CG_SUPPORT_BIF_LS |
1051 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001052 AMD_CG_SUPPORT_HDP_LS |
1053 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis8ef583e2016-08-03 11:34:35 -04001054 AMD_CG_SUPPORT_SDMA_LS |
1055 AMD_CG_SUPPORT_VCE_MGCG;
Alex Deuchere6b2a7d2016-10-19 13:06:14 -04001056 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
Tom St Denis4e86be72016-07-28 09:38:13 -04001057 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denisc2cdb04282016-07-28 09:38:29 -04001058 AMD_PG_SUPPORT_GFX_PIPELINE |
Rex Zhu98fccc72016-12-07 17:48:48 +08001059 AMD_PG_SUPPORT_CP |
Tom St Denis75419c42016-07-28 09:38:45 -04001060 AMD_PG_SUPPORT_UVD |
1061 AMD_PG_SUPPORT_VCE;
Jordan Lazarea47c78d2016-09-01 13:49:33 -04001062 adev->external_rev_id = adev->rev_id + 0x61;
Tom St Deniscde64932016-03-23 13:17:04 -04001063 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001064 default:
1065 /* FIXME: not supported yet */
1066 return -EINVAL;
1067 }
1068
Xiangliang Yuab276632017-04-21 14:06:09 +08001069 if (amdgpu_sriov_vf(adev)) {
1070 amdgpu_virt_init_setting(adev);
1071 xgpu_vi_mailbox_set_irq_funcs(adev);
1072 }
1073
Huang Ruie635ee02016-11-01 15:35:38 +08001074 /* vi use smc load by default */
1075 adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type);
Flora Cuia3d08fa2015-11-02 21:15:55 +08001076
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001077 amdgpu_get_pcie_info(adev);
1078
Alex Deucheraaa36a92015-04-20 17:31:14 -04001079 return 0;
1080}
1081
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001082static int vi_common_late_init(void *handle)
1083{
1084 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1085
1086 if (amdgpu_sriov_vf(adev))
1087 xgpu_vi_mailbox_get_irq(adev);
1088
1089 return 0;
1090}
1091
yanyang15fc3aee2015-05-22 14:39:35 -04001092static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001093{
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001094 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1095
1096 if (amdgpu_sriov_vf(adev))
1097 xgpu_vi_mailbox_add_irq_id(adev);
1098
Alex Deucheraaa36a92015-04-20 17:31:14 -04001099 return 0;
1100}
1101
yanyang15fc3aee2015-05-22 14:39:35 -04001102static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001103{
1104 return 0;
1105}
1106
yanyang15fc3aee2015-05-22 14:39:35 -04001107static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001108{
yanyang15fc3aee2015-05-22 14:39:35 -04001109 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1110
Alex Deucheraaa36a92015-04-20 17:31:14 -04001111 /* move the golden regs per IP block */
1112 vi_init_golden_registers(adev);
1113 /* enable pcie gen2/3 link */
1114 vi_pcie_gen3_enable(adev);
1115 /* enable aspm */
1116 vi_program_aspm(adev);
1117 /* enable the doorbell aperture */
1118 vi_enable_doorbell_aperture(adev, true);
1119
1120 return 0;
1121}
1122
yanyang15fc3aee2015-05-22 14:39:35 -04001123static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001124{
yanyang15fc3aee2015-05-22 14:39:35 -04001125 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1126
Alex Deucheraaa36a92015-04-20 17:31:14 -04001127 /* enable the doorbell aperture */
1128 vi_enable_doorbell_aperture(adev, false);
1129
Xiangliang Yu63d24f82017-01-18 12:50:14 +08001130 if (amdgpu_sriov_vf(adev))
1131 xgpu_vi_mailbox_put_irq(adev);
1132
Alex Deucheraaa36a92015-04-20 17:31:14 -04001133 return 0;
1134}
1135
yanyang15fc3aee2015-05-22 14:39:35 -04001136static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001137{
yanyang15fc3aee2015-05-22 14:39:35 -04001138 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1139
Alex Deucheraaa36a92015-04-20 17:31:14 -04001140 return vi_common_hw_fini(adev);
1141}
1142
yanyang15fc3aee2015-05-22 14:39:35 -04001143static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001144{
yanyang15fc3aee2015-05-22 14:39:35 -04001145 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1146
Alex Deucheraaa36a92015-04-20 17:31:14 -04001147 return vi_common_hw_init(adev);
1148}
1149
yanyang15fc3aee2015-05-22 14:39:35 -04001150static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001151{
1152 return true;
1153}
1154
yanyang15fc3aee2015-05-22 14:39:35 -04001155static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001156{
1157 return 0;
1158}
1159
yanyang15fc3aee2015-05-22 14:39:35 -04001160static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001161{
1162 return 0;
1163}
1164
Alex Deucher76f10b92016-04-08 01:37:44 -04001165static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1166 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001167{
1168 uint32_t temp, data;
1169
1170 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1171
Alex Deucherc90766c2016-04-08 00:52:58 -04001172 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001173 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1174 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1175 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1176 else
1177 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1178 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1179 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1180
1181 if (temp != data)
1182 WREG32_PCIE(ixPCIE_CNTL2, data);
1183}
1184
Alex Deucher76f10b92016-04-08 01:37:44 -04001185static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1186 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001187{
1188 uint32_t temp, data;
1189
1190 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1191
Alex Deucherc90766c2016-04-08 00:52:58 -04001192 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001193 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1194 else
1195 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1196
1197 if (temp != data)
1198 WREG32(mmHDP_HOST_PATH_CNTL, data);
1199}
1200
Alex Deucher76f10b92016-04-08 01:37:44 -04001201static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1202 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001203{
1204 uint32_t temp, data;
1205
1206 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1207
Alex Deucherc90766c2016-04-08 00:52:58 -04001208 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001209 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1210 else
1211 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1212
1213 if (temp != data)
1214 WREG32(mmHDP_MEM_POWER_LS, data);
1215}
1216
Rex Zhuf6f534e2016-12-08 10:58:15 +08001217static void vi_update_drm_light_sleep(struct amdgpu_device *adev,
1218 bool enable)
1219{
1220 uint32_t temp, data;
1221
1222 temp = data = RREG32(0x157a);
1223
1224 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1225 data |= 1;
1226 else
1227 data &= ~1;
1228
1229 if (temp != data)
1230 WREG32(0x157a, data);
1231}
1232
1233
Alex Deucher76f10b92016-04-08 01:37:44 -04001234static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1235 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001236{
1237 uint32_t temp, data;
1238
1239 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1240
Alex Deucherc90766c2016-04-08 00:52:58 -04001241 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001242 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1243 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1244 else
1245 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1246 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1247
1248 if (temp != data)
1249 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1250}
1251
Rex Zhu1bb08f92016-09-18 16:54:00 +08001252static int vi_common_set_clockgating_state_by_smu(void *handle,
1253 enum amd_clockgating_state state)
1254{
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001255 uint32_t msg_id, pp_state = 0;
1256 uint32_t pp_support_state = 0;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001257 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1258 void *pp_handle = adev->powerplay.pp_handle;
1259
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001260 if (adev->cg_flags & (AMD_CG_SUPPORT_MC_LS | AMD_CG_SUPPORT_MC_MGCG)) {
1261 if (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) {
1262 pp_support_state = AMD_CG_SUPPORT_MC_LS;
1263 pp_state = PP_STATE_LS;
1264 }
1265 if (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG) {
1266 pp_support_state |= AMD_CG_SUPPORT_MC_MGCG;
1267 pp_state |= PP_STATE_CG;
1268 }
1269 if (state == AMD_CG_STATE_UNGATE)
1270 pp_state = 0;
1271 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1272 PP_BLOCK_SYS_MC,
1273 pp_support_state,
1274 pp_state);
1275 amd_set_clockgating_by_smu(pp_handle, msg_id);
1276 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001277
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001278 if (adev->cg_flags & (AMD_CG_SUPPORT_SDMA_LS | AMD_CG_SUPPORT_SDMA_MGCG)) {
1279 if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS) {
1280 pp_support_state = AMD_CG_SUPPORT_SDMA_LS;
1281 pp_state = PP_STATE_LS;
1282 }
1283 if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG) {
1284 pp_support_state |= AMD_CG_SUPPORT_SDMA_MGCG;
1285 pp_state |= PP_STATE_CG;
1286 }
1287 if (state == AMD_CG_STATE_UNGATE)
1288 pp_state = 0;
1289 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1290 PP_BLOCK_SYS_SDMA,
1291 pp_support_state,
1292 pp_state);
1293 amd_set_clockgating_by_smu(pp_handle, msg_id);
1294 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001295
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001296 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_MGCG)) {
1297 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1298 pp_support_state = AMD_CG_SUPPORT_HDP_LS;
1299 pp_state = PP_STATE_LS;
1300 }
1301 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG) {
1302 pp_support_state |= AMD_CG_SUPPORT_HDP_MGCG;
1303 pp_state |= PP_STATE_CG;
1304 }
1305 if (state == AMD_CG_STATE_UNGATE)
1306 pp_state = 0;
1307 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1308 PP_BLOCK_SYS_HDP,
1309 pp_support_state,
1310 pp_state);
1311 amd_set_clockgating_by_smu(pp_handle, msg_id);
1312 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001313
Rex Zhu1bb08f92016-09-18 16:54:00 +08001314
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001315 if (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS) {
1316 if (state == AMD_CG_STATE_UNGATE)
1317 pp_state = 0;
1318 else
1319 pp_state = PP_STATE_LS;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001320
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001321 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1322 PP_BLOCK_SYS_BIF,
1323 PP_STATE_SUPPORT_LS,
1324 pp_state);
1325 amd_set_clockgating_by_smu(pp_handle, msg_id);
1326 }
1327 if (adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG) {
1328 if (state == AMD_CG_STATE_UNGATE)
1329 pp_state = 0;
1330 else
1331 pp_state = PP_STATE_CG;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001332
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001333 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1334 PP_BLOCK_SYS_BIF,
1335 PP_STATE_SUPPORT_CG,
1336 pp_state);
1337 amd_set_clockgating_by_smu(pp_handle, msg_id);
1338 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001339
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001340 if (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS) {
Rex Zhu1bb08f92016-09-18 16:54:00 +08001341
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001342 if (state == AMD_CG_STATE_UNGATE)
1343 pp_state = 0;
1344 else
1345 pp_state = PP_STATE_LS;
1346
1347 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1348 PP_BLOCK_SYS_DRM,
1349 PP_STATE_SUPPORT_LS,
1350 pp_state);
1351 amd_set_clockgating_by_smu(pp_handle, msg_id);
1352 }
1353
1354 if (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG) {
1355
1356 if (state == AMD_CG_STATE_UNGATE)
1357 pp_state = 0;
1358 else
1359 pp_state = PP_STATE_CG;
1360
1361 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1362 PP_BLOCK_SYS_ROM,
1363 PP_STATE_SUPPORT_CG,
1364 pp_state);
1365 amd_set_clockgating_by_smu(pp_handle, msg_id);
1366 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001367 return 0;
1368}
1369
yanyang15fc3aee2015-05-22 14:39:35 -04001370static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001371 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001372{
Eric Huang6cec2652015-11-12 16:59:47 -05001373 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1374
Monk Liuce137c02017-01-23 10:49:33 +08001375 if (amdgpu_sriov_vf(adev))
1376 return 0;
1377
Eric Huang6cec2652015-11-12 16:59:47 -05001378 switch (adev->asic_type) {
1379 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001380 vi_update_bif_medium_grain_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001381 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001382 vi_update_hdp_medium_grain_clock_gating(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001383 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001384 vi_update_hdp_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001385 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001386 vi_update_rom_medium_grain_clock_gating(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001387 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001388 break;
1389 case CHIP_CARRIZO:
1390 case CHIP_STONEY:
1391 vi_update_bif_medium_grain_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001392 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001393 vi_update_hdp_medium_grain_clock_gating(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001394 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001395 vi_update_hdp_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001396 state == AMD_CG_STATE_GATE);
Rex Zhuf6f534e2016-12-08 10:58:15 +08001397 vi_update_drm_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001398 state == AMD_CG_STATE_GATE);
Eric Huang6cec2652015-11-12 16:59:47 -05001399 break;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001400 case CHIP_TONGA:
1401 case CHIP_POLARIS10:
1402 case CHIP_POLARIS11:
Junwei Zhangc4642a42016-12-14 15:32:28 -05001403 case CHIP_POLARIS12:
Rex Zhu1bb08f92016-09-18 16:54:00 +08001404 vi_common_set_clockgating_state_by_smu(adev, state);
Eric Huang6cec2652015-11-12 16:59:47 -05001405 default:
1406 break;
1407 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001408 return 0;
1409}
1410
yanyang15fc3aee2015-05-22 14:39:35 -04001411static int vi_common_set_powergating_state(void *handle,
1412 enum amd_powergating_state state)
1413{
1414 return 0;
1415}
1416
Huang Ruiabd2c2f2017-01-05 20:48:06 +08001417static void vi_common_get_clockgating_state(void *handle, u32 *flags)
1418{
1419 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1420 int data;
1421
Monk Liuce137c02017-01-23 10:49:33 +08001422 if (amdgpu_sriov_vf(adev))
1423 *flags = 0;
1424
Huang Ruiabd2c2f2017-01-05 20:48:06 +08001425 /* AMD_CG_SUPPORT_BIF_LS */
1426 data = RREG32_PCIE(ixPCIE_CNTL2);
1427 if (data & PCIE_CNTL2__SLV_MEM_LS_EN_MASK)
1428 *flags |= AMD_CG_SUPPORT_BIF_LS;
1429
1430 /* AMD_CG_SUPPORT_HDP_LS */
1431 data = RREG32(mmHDP_MEM_POWER_LS);
1432 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1433 *flags |= AMD_CG_SUPPORT_HDP_LS;
1434
1435 /* AMD_CG_SUPPORT_HDP_MGCG */
1436 data = RREG32(mmHDP_HOST_PATH_CNTL);
1437 if (!(data & HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK))
1438 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
1439
1440 /* AMD_CG_SUPPORT_ROM_MGCG */
1441 data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1442 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
1443 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
1444}
1445
Alex Deuchera1255102016-10-13 17:41:13 -04001446static const struct amd_ip_funcs vi_common_ip_funcs = {
Tom St Denis88a907d2016-05-04 14:28:35 -04001447 .name = "vi_common",
Alex Deucheraaa36a92015-04-20 17:31:14 -04001448 .early_init = vi_common_early_init,
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001449 .late_init = vi_common_late_init,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001450 .sw_init = vi_common_sw_init,
1451 .sw_fini = vi_common_sw_fini,
1452 .hw_init = vi_common_hw_init,
1453 .hw_fini = vi_common_hw_fini,
1454 .suspend = vi_common_suspend,
1455 .resume = vi_common_resume,
1456 .is_idle = vi_common_is_idle,
1457 .wait_for_idle = vi_common_wait_for_idle,
1458 .soft_reset = vi_common_soft_reset,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001459 .set_clockgating_state = vi_common_set_clockgating_state,
1460 .set_powergating_state = vi_common_set_powergating_state,
Huang Ruiabd2c2f2017-01-05 20:48:06 +08001461 .get_clockgating_state = vi_common_get_clockgating_state,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001462};
1463
Alex Deuchera1255102016-10-13 17:41:13 -04001464static const struct amdgpu_ip_block_version vi_common_ip_block =
1465{
1466 .type = AMD_IP_BLOCK_TYPE_COMMON,
1467 .major = 1,
1468 .minor = 0,
1469 .rev = 0,
1470 .funcs = &vi_common_ip_funcs,
1471};
1472
1473int vi_set_ip_blocks(struct amdgpu_device *adev)
1474{
Xiangliang Yu91caa082017-01-09 11:49:27 +08001475 /* in early init stage, vbios code won't work */
1476 vi_detect_hw_virtualization(adev);
1477
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001478 if (amdgpu_sriov_vf(adev))
1479 adev->virt.ops = &xgpu_vi_virt_ops;
1480
Alex Deuchera1255102016-10-13 17:41:13 -04001481 switch (adev->asic_type) {
1482 case CHIP_TOPAZ:
1483 /* topaz has no DCE, UVD, VCE */
1484 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1485 amdgpu_ip_block_add(adev, &gmc_v7_4_ip_block);
1486 amdgpu_ip_block_add(adev, &iceland_ih_ip_block);
1487 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1488 if (adev->enable_virtual_display)
1489 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1490 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1491 amdgpu_ip_block_add(adev, &sdma_v2_4_ip_block);
1492 break;
1493 case CHIP_FIJI:
1494 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1495 amdgpu_ip_block_add(adev, &gmc_v8_5_ip_block);
1496 amdgpu_ip_block_add(adev, &tonga_ih_ip_block);
1497 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001498 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deuchera1255102016-10-13 17:41:13 -04001499 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1500 else
1501 amdgpu_ip_block_add(adev, &dce_v10_1_ip_block);
1502 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1503 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001504 if (!amdgpu_sriov_vf(adev)) {
1505 amdgpu_ip_block_add(adev, &uvd_v6_0_ip_block);
1506 amdgpu_ip_block_add(adev, &vce_v3_0_ip_block);
1507 }
Alex Deuchera1255102016-10-13 17:41:13 -04001508 break;
1509 case CHIP_TONGA:
1510 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1511 amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block);
1512 amdgpu_ip_block_add(adev, &tonga_ih_ip_block);
1513 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001514 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deuchera1255102016-10-13 17:41:13 -04001515 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1516 else
1517 amdgpu_ip_block_add(adev, &dce_v10_0_ip_block);
1518 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1519 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001520 if (!amdgpu_sriov_vf(adev)) {
1521 amdgpu_ip_block_add(adev, &uvd_v5_0_ip_block);
1522 amdgpu_ip_block_add(adev, &vce_v3_0_ip_block);
1523 }
Alex Deuchera1255102016-10-13 17:41:13 -04001524 break;
1525 case CHIP_POLARIS11:
1526 case CHIP_POLARIS10:
Junwei Zhangc4642a42016-12-14 15:32:28 -05001527 case CHIP_POLARIS12:
Alex Deuchera1255102016-10-13 17:41:13 -04001528 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1529 amdgpu_ip_block_add(adev, &gmc_v8_1_ip_block);
1530 amdgpu_ip_block_add(adev, &tonga_ih_ip_block);
1531 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1532 if (adev->enable_virtual_display)
1533 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1534 else
1535 amdgpu_ip_block_add(adev, &dce_v11_2_ip_block);
1536 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1537 amdgpu_ip_block_add(adev, &sdma_v3_1_ip_block);
1538 amdgpu_ip_block_add(adev, &uvd_v6_3_ip_block);
1539 amdgpu_ip_block_add(adev, &vce_v3_4_ip_block);
1540 break;
1541 case CHIP_CARRIZO:
1542 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1543 amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block);
1544 amdgpu_ip_block_add(adev, &cz_ih_ip_block);
1545 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1546 if (adev->enable_virtual_display)
1547 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1548 else
1549 amdgpu_ip_block_add(adev, &dce_v11_0_ip_block);
1550 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1551 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
1552 amdgpu_ip_block_add(adev, &uvd_v6_0_ip_block);
1553 amdgpu_ip_block_add(adev, &vce_v3_1_ip_block);
1554#if defined(CONFIG_DRM_AMD_ACP)
1555 amdgpu_ip_block_add(adev, &acp_ip_block);
1556#endif
1557 break;
1558 case CHIP_STONEY:
1559 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1560 amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block);
1561 amdgpu_ip_block_add(adev, &cz_ih_ip_block);
1562 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1563 if (adev->enable_virtual_display)
1564 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1565 else
1566 amdgpu_ip_block_add(adev, &dce_v11_0_ip_block);
1567 amdgpu_ip_block_add(adev, &gfx_v8_1_ip_block);
1568 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
1569 amdgpu_ip_block_add(adev, &uvd_v6_2_ip_block);
1570 amdgpu_ip_block_add(adev, &vce_v3_4_ip_block);
1571#if defined(CONFIG_DRM_AMD_ACP)
1572 amdgpu_ip_block_add(adev, &acp_ip_block);
1573#endif
1574 break;
1575 default:
1576 /* FIXME: not supported yet */
1577 return -EINVAL;
1578 }
1579
1580 return 0;
1581}