blob: 4ac1288ab7dff4fee300e3cdd1b359628173da71 [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>
Masahiro Yamada248a1d62017-04-24 13:50:21 +090024#include <drm/drmP.h>
Alex Deucheraaa36a92015-04-20 17:31:14 -040025#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"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040074#if defined(CONFIG_DRM_AMD_ACP)
75#include "amdgpu_acp.h"
76#endif
Emily Denge9ed3a62016-08-08 11:36:45 +080077#include "dce_virtual.h"
Xiangliang Yu99581cc2017-01-12 15:22:18 +080078#include "mxgpu_vi.h"
Harry Wentland45622362017-09-12 15:58:20 -040079#include "amdgpu_dm.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:
Alex Deucher9c3f2b52017-12-14 16:20:19 -0500284 amdgpu_device_program_register_sequence(adev,
285 iceland_mgcg_cgcg_init,
286 ARRAY_SIZE(iceland_mgcg_cgcg_init));
Alex Deucheraaa36a92015-04-20 17:31:14 -0400287 break;
David Zhang48299f92015-07-08 01:05:16 +0800288 case CHIP_FIJI:
Alex Deucher9c3f2b52017-12-14 16:20:19 -0500289 amdgpu_device_program_register_sequence(adev,
290 fiji_mgcg_cgcg_init,
291 ARRAY_SIZE(fiji_mgcg_cgcg_init));
David Zhang48299f92015-07-08 01:05:16 +0800292 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400293 case CHIP_TONGA:
Alex Deucher9c3f2b52017-12-14 16:20:19 -0500294 amdgpu_device_program_register_sequence(adev,
295 tonga_mgcg_cgcg_init,
296 ARRAY_SIZE(tonga_mgcg_cgcg_init));
Alex Deucheraaa36a92015-04-20 17:31:14 -0400297 break;
298 case CHIP_CARRIZO:
Alex Deucher9c3f2b52017-12-14 16:20:19 -0500299 amdgpu_device_program_register_sequence(adev,
300 cz_mgcg_cgcg_init,
301 ARRAY_SIZE(cz_mgcg_cgcg_init));
Alex Deucheraaa36a92015-04-20 17:31:14 -0400302 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400303 case CHIP_STONEY:
Alex Deucher9c3f2b52017-12-14 16:20:19 -0500304 amdgpu_device_program_register_sequence(adev,
305 stoney_mgcg_cgcg_init,
306 ARRAY_SIZE(stoney_mgcg_cgcg_init));
Samuel Li39bb0c92015-10-08 16:31:43 -0400307 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400308 case CHIP_POLARIS10:
Leo Liub51c5192018-04-11 15:28:28 -0500309 case CHIP_POLARIS11:
Junwei Zhangc4642a42016-12-14 15:32:28 -0500310 case CHIP_POLARIS12:
Leo Liub51c5192018-04-11 15:28:28 -0500311 case CHIP_VEGAM:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400312 default:
313 break;
314 }
315 mutex_unlock(&adev->grbm_idx_mutex);
316}
317
318/**
319 * vi_get_xclk - get the xclk
320 *
321 * @adev: amdgpu_device pointer
322 *
323 * Returns the reference clock used by the gfx engine
324 * (VI).
325 */
326static u32 vi_get_xclk(struct amdgpu_device *adev)
327{
328 u32 reference_clock = adev->clock.spll.reference_freq;
329 u32 tmp;
330
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800331 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400332 return reference_clock;
333
334 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
335 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
336 return 1000;
337
338 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
339 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
340 return reference_clock / 4;
341
342 return reference_clock;
343}
344
345/**
346 * vi_srbm_select - select specific register instances
347 *
348 * @adev: amdgpu_device pointer
349 * @me: selected ME (micro engine)
350 * @pipe: pipe
351 * @queue: queue
352 * @vmid: VMID
353 *
354 * Switches the currently active registers instances. Some
355 * registers are instanced per VMID, others are instanced per
356 * me/pipe/queue combination.
357 */
358void vi_srbm_select(struct amdgpu_device *adev,
359 u32 me, u32 pipe, u32 queue, u32 vmid)
360{
361 u32 srbm_gfx_cntl = 0;
362 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
363 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
364 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
365 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
366 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
367}
368
369static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
370{
371 /* todo */
372}
373
374static bool vi_read_disabled_bios(struct amdgpu_device *adev)
375{
376 u32 bus_cntl;
377 u32 d1vga_control = 0;
378 u32 d2vga_control = 0;
379 u32 vga_render_control = 0;
380 u32 rom_cntl;
381 bool r;
382
383 bus_cntl = RREG32(mmBUS_CNTL);
384 if (adev->mode_info.num_crtc) {
385 d1vga_control = RREG32(mmD1VGA_CONTROL);
386 d2vga_control = RREG32(mmD2VGA_CONTROL);
387 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
388 }
389 rom_cntl = RREG32_SMC(ixROM_CNTL);
390
391 /* enable the rom */
392 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
393 if (adev->mode_info.num_crtc) {
394 /* Disable VGA mode */
395 WREG32(mmD1VGA_CONTROL,
396 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
397 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
398 WREG32(mmD2VGA_CONTROL,
399 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
400 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
401 WREG32(mmVGA_RENDER_CONTROL,
402 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
403 }
404 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
405
406 r = amdgpu_read_bios(adev);
407
408 /* restore regs */
409 WREG32(mmBUS_CNTL, bus_cntl);
410 if (adev->mode_info.num_crtc) {
411 WREG32(mmD1VGA_CONTROL, d1vga_control);
412 WREG32(mmD2VGA_CONTROL, d2vga_control);
413 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
414 }
415 WREG32_SMC(ixROM_CNTL, rom_cntl);
416 return r;
417}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500418
419static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
420 u8 *bios, u32 length_bytes)
421{
422 u32 *dw_ptr;
423 unsigned long flags;
424 u32 i, length_dw;
425
426 if (bios == NULL)
427 return false;
428 if (length_bytes == 0)
429 return false;
430 /* APU vbios image is part of sbios image */
431 if (adev->flags & AMD_IS_APU)
432 return false;
433
434 dw_ptr = (u32 *)bios;
435 length_dw = ALIGN(length_bytes, 4) / 4;
436 /* take the smc lock since we are using the smc index */
437 spin_lock_irqsave(&adev->smc_idx_lock, flags);
438 /* set rom index to 0 */
Monk Liu4bc10d12016-03-29 11:01:51 +0800439 WREG32(mmSMC_IND_INDEX_11, ixROM_INDEX);
440 WREG32(mmSMC_IND_DATA_11, 0);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500441 /* set index to data for continous read */
Monk Liu4bc10d12016-03-29 11:01:51 +0800442 WREG32(mmSMC_IND_INDEX_11, ixROM_DATA);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500443 for (i = 0; i < length_dw; i++)
Monk Liu4bc10d12016-03-29 11:01:51 +0800444 dw_ptr[i] = RREG32(mmSMC_IND_DATA_11);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500445 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
446
447 return true;
448}
449
Monk Liu4e99a442016-03-31 13:26:59 +0800450static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
Andres Rodriguez048765a2016-06-11 02:51:32 -0400451{
Alex Deucher57ad33a2017-12-19 09:52:31 -0500452 uint32_t reg = 0;
Andres Rodriguez048765a2016-06-11 02:51:32 -0400453
Alex Deucher57ad33a2017-12-19 09:52:31 -0500454 if (adev->asic_type == CHIP_TONGA ||
455 adev->asic_type == CHIP_FIJI) {
456 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
457 /* bit0: 0 means pf and 1 means vf */
Alex Deucher04a0d2d2017-12-19 09:57:53 -0500458 if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER))
Alex Deucher57ad33a2017-12-19 09:52:31 -0500459 adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF;
Alex Deucher04a0d2d2017-12-19 09:57:53 -0500460 /* bit31: 0 means disable IOV and 1 means enable */
461 if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE))
Alex Deucher57ad33a2017-12-19 09:52:31 -0500462 adev->virt.caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV;
463 }
Andres Rodriguez048765a2016-06-11 02:51:32 -0400464
Monk Liu4e99a442016-03-31 13:26:59 +0800465 if (reg == 0) {
466 if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500467 adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE;
Monk Liu4e99a442016-03-31 13:26:59 +0800468 }
Andres Rodriguez048765a2016-06-11 02:51:32 -0400469}
470
Nils Wallméniuseca22402016-03-19 16:12:17 +0100471static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Christian König97fcc762017-04-12 12:49:54 +0200472 {mmGRBM_STATUS},
473 {mmGRBM_STATUS2},
474 {mmGRBM_STATUS_SE0},
475 {mmGRBM_STATUS_SE1},
476 {mmGRBM_STATUS_SE2},
477 {mmGRBM_STATUS_SE3},
478 {mmSRBM_STATUS},
479 {mmSRBM_STATUS2},
480 {mmSRBM_STATUS3},
481 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET},
482 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET},
483 {mmCP_STAT},
484 {mmCP_STALLED_STAT1},
485 {mmCP_STALLED_STAT2},
486 {mmCP_STALLED_STAT3},
487 {mmCP_CPF_BUSY_STAT},
488 {mmCP_CPF_STALLED_STAT1},
489 {mmCP_CPF_STATUS},
490 {mmCP_CPC_BUSY_STAT},
491 {mmCP_CPC_STALLED_STAT1},
492 {mmCP_CPC_STATUS},
493 {mmGB_ADDR_CONFIG},
494 {mmMC_ARB_RAMCFG},
495 {mmGB_TILE_MODE0},
496 {mmGB_TILE_MODE1},
497 {mmGB_TILE_MODE2},
498 {mmGB_TILE_MODE3},
499 {mmGB_TILE_MODE4},
500 {mmGB_TILE_MODE5},
501 {mmGB_TILE_MODE6},
502 {mmGB_TILE_MODE7},
503 {mmGB_TILE_MODE8},
504 {mmGB_TILE_MODE9},
505 {mmGB_TILE_MODE10},
506 {mmGB_TILE_MODE11},
507 {mmGB_TILE_MODE12},
508 {mmGB_TILE_MODE13},
509 {mmGB_TILE_MODE14},
510 {mmGB_TILE_MODE15},
511 {mmGB_TILE_MODE16},
512 {mmGB_TILE_MODE17},
513 {mmGB_TILE_MODE18},
514 {mmGB_TILE_MODE19},
515 {mmGB_TILE_MODE20},
516 {mmGB_TILE_MODE21},
517 {mmGB_TILE_MODE22},
518 {mmGB_TILE_MODE23},
519 {mmGB_TILE_MODE24},
520 {mmGB_TILE_MODE25},
521 {mmGB_TILE_MODE26},
522 {mmGB_TILE_MODE27},
523 {mmGB_TILE_MODE28},
524 {mmGB_TILE_MODE29},
525 {mmGB_TILE_MODE30},
526 {mmGB_TILE_MODE31},
527 {mmGB_MACROTILE_MODE0},
528 {mmGB_MACROTILE_MODE1},
529 {mmGB_MACROTILE_MODE2},
530 {mmGB_MACROTILE_MODE3},
531 {mmGB_MACROTILE_MODE4},
532 {mmGB_MACROTILE_MODE5},
533 {mmGB_MACROTILE_MODE6},
534 {mmGB_MACROTILE_MODE7},
535 {mmGB_MACROTILE_MODE8},
536 {mmGB_MACROTILE_MODE9},
537 {mmGB_MACROTILE_MODE10},
538 {mmGB_MACROTILE_MODE11},
539 {mmGB_MACROTILE_MODE12},
540 {mmGB_MACROTILE_MODE13},
541 {mmGB_MACROTILE_MODE14},
542 {mmGB_MACROTILE_MODE15},
543 {mmCC_RB_BACKEND_DISABLE, true},
544 {mmGC_USER_RB_BACKEND_DISABLE, true},
545 {mmGB_BACKEND_MAP, false},
546 {mmPA_SC_RASTER_CONFIG, true},
547 {mmPA_SC_RASTER_CONFIG_1, true},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400548};
549
Alex Deucherdb9635c2016-10-10 12:05:32 -0400550static uint32_t vi_get_register_value(struct amdgpu_device *adev,
551 bool indexed, u32 se_num,
552 u32 sh_num, u32 reg_offset)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400553{
Alex Deucherdb9635c2016-10-10 12:05:32 -0400554 if (indexed) {
555 uint32_t val;
556 unsigned se_idx = (se_num == 0xffffffff) ? 0 : se_num;
557 unsigned sh_idx = (sh_num == 0xffffffff) ? 0 : sh_num;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400558
Alex Deucherdb9635c2016-10-10 12:05:32 -0400559 switch (reg_offset) {
560 case mmCC_RB_BACKEND_DISABLE:
561 return adev->gfx.config.rb_config[se_idx][sh_idx].rb_backend_disable;
562 case mmGC_USER_RB_BACKEND_DISABLE:
563 return adev->gfx.config.rb_config[se_idx][sh_idx].user_rb_backend_disable;
564 case mmPA_SC_RASTER_CONFIG:
565 return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config;
566 case mmPA_SC_RASTER_CONFIG_1:
567 return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config_1;
568 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400569
Alex Deucherdb9635c2016-10-10 12:05:32 -0400570 mutex_lock(&adev->grbm_idx_mutex);
571 if (se_num != 0xffffffff || sh_num != 0xffffffff)
572 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400573
Alex Deucherdb9635c2016-10-10 12:05:32 -0400574 val = RREG32(reg_offset);
575
576 if (se_num != 0xffffffff || sh_num != 0xffffffff)
577 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
578 mutex_unlock(&adev->grbm_idx_mutex);
579 return val;
580 } else {
581 unsigned idx;
582
583 switch (reg_offset) {
584 case mmGB_ADDR_CONFIG:
585 return adev->gfx.config.gb_addr_config;
586 case mmMC_ARB_RAMCFG:
587 return adev->gfx.config.mc_arb_ramcfg;
588 case mmGB_TILE_MODE0:
589 case mmGB_TILE_MODE1:
590 case mmGB_TILE_MODE2:
591 case mmGB_TILE_MODE3:
592 case mmGB_TILE_MODE4:
593 case mmGB_TILE_MODE5:
594 case mmGB_TILE_MODE6:
595 case mmGB_TILE_MODE7:
596 case mmGB_TILE_MODE8:
597 case mmGB_TILE_MODE9:
598 case mmGB_TILE_MODE10:
599 case mmGB_TILE_MODE11:
600 case mmGB_TILE_MODE12:
601 case mmGB_TILE_MODE13:
602 case mmGB_TILE_MODE14:
603 case mmGB_TILE_MODE15:
604 case mmGB_TILE_MODE16:
605 case mmGB_TILE_MODE17:
606 case mmGB_TILE_MODE18:
607 case mmGB_TILE_MODE19:
608 case mmGB_TILE_MODE20:
609 case mmGB_TILE_MODE21:
610 case mmGB_TILE_MODE22:
611 case mmGB_TILE_MODE23:
612 case mmGB_TILE_MODE24:
613 case mmGB_TILE_MODE25:
614 case mmGB_TILE_MODE26:
615 case mmGB_TILE_MODE27:
616 case mmGB_TILE_MODE28:
617 case mmGB_TILE_MODE29:
618 case mmGB_TILE_MODE30:
619 case mmGB_TILE_MODE31:
620 idx = (reg_offset - mmGB_TILE_MODE0);
621 return adev->gfx.config.tile_mode_array[idx];
622 case mmGB_MACROTILE_MODE0:
623 case mmGB_MACROTILE_MODE1:
624 case mmGB_MACROTILE_MODE2:
625 case mmGB_MACROTILE_MODE3:
626 case mmGB_MACROTILE_MODE4:
627 case mmGB_MACROTILE_MODE5:
628 case mmGB_MACROTILE_MODE6:
629 case mmGB_MACROTILE_MODE7:
630 case mmGB_MACROTILE_MODE8:
631 case mmGB_MACROTILE_MODE9:
632 case mmGB_MACROTILE_MODE10:
633 case mmGB_MACROTILE_MODE11:
634 case mmGB_MACROTILE_MODE12:
635 case mmGB_MACROTILE_MODE13:
636 case mmGB_MACROTILE_MODE14:
637 case mmGB_MACROTILE_MODE15:
638 idx = (reg_offset - mmGB_MACROTILE_MODE0);
639 return adev->gfx.config.macrotile_mode_array[idx];
640 default:
641 return RREG32(reg_offset);
642 }
643 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400644}
645
646static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
647 u32 sh_num, u32 reg_offset, u32 *value)
648{
Christian König3032f352017-04-12 12:53:18 +0200649 uint32_t i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400650
651 *value = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400652 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
Christian König97fcc762017-04-12 12:49:54 +0200653 bool indexed = vi_allowed_read_registers[i].grbm_indexed;
654
Alex Deucheraaa36a92015-04-20 17:31:14 -0400655 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
656 continue;
657
Christian König97fcc762017-04-12 12:49:54 +0200658 *value = vi_get_register_value(adev, indexed, se_num, sh_num,
659 reg_offset);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400660 return 0;
661 }
662 return -EINVAL;
663}
664
Chunming Zhou89a31822016-06-06 13:06:45 +0800665static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400666{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400667 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400668
669 dev_info(adev->dev, "GPU pci config reset\n");
670
Alex Deucheraaa36a92015-04-20 17:31:14 -0400671 /* disable BM */
672 pci_clear_master(adev->pdev);
673 /* reset */
Alex Deucher8111c382017-12-14 16:22:53 -0500674 amdgpu_device_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400675
676 udelay(100);
677
678 /* wait for asic to come out of reset */
679 for (i = 0; i < adev->usec_timeout; i++) {
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800680 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
681 /* enable BM */
682 pci_set_master(adev->pdev);
Jim Quc836fec2017-02-10 15:59:59 +0800683 adev->has_hw_reset = true;
Chunming Zhou89a31822016-06-06 13:06:45 +0800684 return 0;
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800685 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400686 udelay(1);
687 }
Chunming Zhou89a31822016-06-06 13:06:45 +0800688 return -EINVAL;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400689}
690
Alex Deucheraaa36a92015-04-20 17:31:14 -0400691/**
692 * vi_asic_reset - soft reset GPU
693 *
694 * @adev: amdgpu_device pointer
695 *
696 * Look up which blocks are hung and attempt
697 * to reset them.
698 * Returns 0 for success.
699 */
700static int vi_asic_reset(struct amdgpu_device *adev)
701{
Chunming Zhou89a31822016-06-06 13:06:45 +0800702 int r;
703
Alex Deucher72a57432016-10-21 15:45:22 -0400704 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400705
Chunming Zhou89a31822016-06-06 13:06:45 +0800706 r = vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400707
Alex Deucher72a57432016-10-21 15:45:22 -0400708 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400709
Chunming Zhou89a31822016-06-06 13:06:45 +0800710 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400711}
712
Alex Deucherbbf282d2017-03-03 17:26:10 -0500713static u32 vi_get_config_memsize(struct amdgpu_device *adev)
714{
715 return RREG32(mmCONFIG_MEMSIZE);
716}
717
Alex Deucheraaa36a92015-04-20 17:31:14 -0400718static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
719 u32 cntl_reg, u32 status_reg)
720{
721 int r, i;
722 struct atom_clock_dividers dividers;
723 uint32_t tmp;
724
725 r = amdgpu_atombios_get_clock_dividers(adev,
726 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
727 clock, false, &dividers);
728 if (r)
729 return r;
730
731 tmp = RREG32_SMC(cntl_reg);
Rex Zhu819a23f2018-04-10 17:17:22 +0800732
733 if (adev->flags & AMD_IS_APU)
734 tmp &= ~CG_DCLK_CNTL__DCLK_DIVIDER_MASK;
735 else
736 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
737 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400738 tmp |= dividers.post_divider;
739 WREG32_SMC(cntl_reg, tmp);
740
741 for (i = 0; i < 100; i++) {
Rex Zhu819a23f2018-04-10 17:17:22 +0800742 tmp = RREG32_SMC(status_reg);
743 if (adev->flags & AMD_IS_APU) {
744 if (tmp & 0x10000)
745 break;
746 } else {
747 if (tmp & CG_DCLK_STATUS__DCLK_STATUS_MASK)
748 break;
749 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400750 mdelay(10);
751 }
752 if (i == 100)
753 return -ETIMEDOUT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400754 return 0;
755}
756
Rex Zhu819a23f2018-04-10 17:17:22 +0800757#define ixGNB_CLK1_DFS_CNTL 0xD82200F0
758#define ixGNB_CLK1_STATUS 0xD822010C
759#define ixGNB_CLK2_DFS_CNTL 0xD8220110
760#define ixGNB_CLK2_STATUS 0xD822012C
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800761#define ixGNB_CLK3_DFS_CNTL 0xD8220130
762#define ixGNB_CLK3_STATUS 0xD822014C
Rex Zhu819a23f2018-04-10 17:17:22 +0800763
Alex Deucheraaa36a92015-04-20 17:31:14 -0400764static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
765{
766 int r;
767
Rex Zhu819a23f2018-04-10 17:17:22 +0800768 if (adev->flags & AMD_IS_APU) {
769 r = vi_set_uvd_clock(adev, vclk, ixGNB_CLK2_DFS_CNTL, ixGNB_CLK2_STATUS);
770 if (r)
771 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400772
Rex Zhu819a23f2018-04-10 17:17:22 +0800773 r = vi_set_uvd_clock(adev, dclk, ixGNB_CLK1_DFS_CNTL, ixGNB_CLK1_STATUS);
774 if (r)
775 return r;
776 } else {
777 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
778 if (r)
779 return r;
780
781 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
782 if (r)
783 return r;
784 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400785
786 return 0;
787}
788
789static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
790{
Rex Zhu714b1f52017-01-10 19:54:25 +0800791 int r, i;
792 struct atom_clock_dividers dividers;
793 u32 tmp;
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800794 u32 reg_ctrl;
795 u32 reg_status;
796 u32 status_mask;
797 u32 reg_mask;
798
799 if (adev->flags & AMD_IS_APU) {
800 reg_ctrl = ixGNB_CLK3_DFS_CNTL;
801 reg_status = ixGNB_CLK3_STATUS;
802 status_mask = 0x00010000;
803 reg_mask = CG_ECLK_CNTL__ECLK_DIVIDER_MASK;
804 } else {
805 reg_ctrl = ixCG_ECLK_CNTL;
806 reg_status = ixCG_ECLK_STATUS;
807 status_mask = CG_ECLK_STATUS__ECLK_STATUS_MASK;
808 reg_mask = CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK | CG_ECLK_CNTL__ECLK_DIVIDER_MASK;
809 }
Rex Zhu714b1f52017-01-10 19:54:25 +0800810
811 r = amdgpu_atombios_get_clock_dividers(adev,
812 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
813 ecclk, false, &dividers);
814 if (r)
815 return r;
816
817 for (i = 0; i < 100; i++) {
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800818 if (RREG32_SMC(reg_status) & status_mask)
Rex Zhu714b1f52017-01-10 19:54:25 +0800819 break;
820 mdelay(10);
821 }
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800822
Rex Zhu714b1f52017-01-10 19:54:25 +0800823 if (i == 100)
824 return -ETIMEDOUT;
825
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800826 tmp = RREG32_SMC(reg_ctrl);
827 tmp &= ~reg_mask;
Rex Zhu714b1f52017-01-10 19:54:25 +0800828 tmp |= dividers.post_divider;
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800829 WREG32_SMC(reg_ctrl, tmp);
Rex Zhu714b1f52017-01-10 19:54:25 +0800830
831 for (i = 0; i < 100; i++) {
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800832 if (RREG32_SMC(reg_status) & status_mask)
Rex Zhu714b1f52017-01-10 19:54:25 +0800833 break;
834 mdelay(10);
835 }
Rex Zhu08ebb6e2018-04-10 17:49:56 +0800836
Rex Zhu714b1f52017-01-10 19:54:25 +0800837 if (i == 100)
838 return -ETIMEDOUT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400839
840 return 0;
841}
842
843static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
844{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400845 if (pci_is_root_bus(adev->pdev->bus))
846 return;
847
Alex Deucheraaa36a92015-04-20 17:31:14 -0400848 if (amdgpu_pcie_gen2 == 0)
849 return;
850
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800851 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400852 return;
853
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500854 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
855 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400856 return;
857
858 /* todo */
859}
860
861static void vi_program_aspm(struct amdgpu_device *adev)
862{
863
864 if (amdgpu_aspm == 0)
865 return;
866
867 /* todo */
868}
869
870static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
871 bool enable)
872{
873 u32 tmp;
874
875 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800876 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400877 return;
878
879 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
880 if (enable)
881 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
882 else
883 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
884
885 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
886}
887
Samuel Li39bb0c92015-10-08 16:31:43 -0400888#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
889#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
890#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
891
Alex Deucheraaa36a92015-04-20 17:31:14 -0400892static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
893{
Flora Cuiabdfb852015-11-20 11:40:53 +0800894 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -0400895 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
896 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400897 else
Flora Cuiabdfb852015-11-20 11:40:53 +0800898 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
899 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400900}
901
Christian König69882562018-01-19 14:17:40 +0100902static void vi_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
Alex Deucherdd8d07f2017-09-06 18:06:24 -0400903{
Christian König69882562018-01-19 14:17:40 +0100904 if (!ring || !ring->funcs->emit_wreg) {
905 WREG32(mmHDP_MEM_COHERENCY_FLUSH_CNTL, 1);
906 RREG32(mmHDP_MEM_COHERENCY_FLUSH_CNTL);
907 } else {
908 amdgpu_ring_emit_wreg(ring, mmHDP_MEM_COHERENCY_FLUSH_CNTL, 1);
909 }
Alex Deucherdd8d07f2017-09-06 18:06:24 -0400910}
911
Christian König69882562018-01-19 14:17:40 +0100912static void vi_invalidate_hdp(struct amdgpu_device *adev,
913 struct amdgpu_ring *ring)
Alex Deucherdd8d07f2017-09-06 18:06:24 -0400914{
Christian König69882562018-01-19 14:17:40 +0100915 if (!ring || !ring->funcs->emit_wreg) {
916 WREG32(mmHDP_DEBUG0, 1);
917 RREG32(mmHDP_DEBUG0);
918 } else {
919 amdgpu_ring_emit_wreg(ring, mmHDP_DEBUG0, 1);
920 }
Alex Deucherdd8d07f2017-09-06 18:06:24 -0400921}
922
Alex Deucher06082d92018-03-29 14:39:28 -0500923static bool vi_need_full_reset(struct amdgpu_device *adev)
924{
925 switch (adev->asic_type) {
926 case CHIP_CARRIZO:
927 case CHIP_STONEY:
928 /* CZ has hang issues with full reset at the moment */
929 return false;
930 case CHIP_FIJI:
931 case CHIP_TONGA:
932 /* XXX: soft reset should work on fiji and tonga */
933 return true;
934 case CHIP_POLARIS10:
935 case CHIP_POLARIS11:
936 case CHIP_POLARIS12:
937 case CHIP_TOPAZ:
938 default:
939 /* change this when we support soft reset */
940 return true;
941 }
942}
943
Alex Deucheraaa36a92015-04-20 17:31:14 -0400944static const struct amdgpu_asic_funcs vi_asic_funcs =
945{
946 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -0500947 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400948 .read_register = &vi_read_register,
949 .reset = &vi_asic_reset,
950 .set_vga_state = &vi_vga_set_state,
951 .get_xclk = &vi_get_xclk,
952 .set_uvd_clocks = &vi_set_uvd_clocks,
953 .set_vce_clocks = &vi_set_vce_clocks,
Alex Deucherbbf282d2017-03-03 17:26:10 -0500954 .get_config_memsize = &vi_get_config_memsize,
Alex Deucherdd8d07f2017-09-06 18:06:24 -0400955 .flush_hdp = &vi_flush_hdp,
956 .invalidate_hdp = &vi_invalidate_hdp,
Alex Deucher06082d92018-03-29 14:39:28 -0500957 .need_full_reset = &vi_need_full_reset,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400958};
959
Eric Huang170d6e92016-08-12 13:47:08 -0400960#define CZ_REV_BRISTOL(rev) \
961 ((rev >= 0xC8 && rev <= 0xCE) || (rev >= 0xE1 && rev <= 0xE6))
962
yanyang15fc3aee2015-05-22 14:39:35 -0400963static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400964{
yanyang15fc3aee2015-05-22 14:39:35 -0400965 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400966
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800967 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400968 adev->smc_rreg = &cz_smc_rreg;
969 adev->smc_wreg = &cz_smc_wreg;
970 } else {
971 adev->smc_rreg = &vi_smc_rreg;
972 adev->smc_wreg = &vi_smc_wreg;
973 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400974 adev->pcie_rreg = &vi_pcie_rreg;
975 adev->pcie_wreg = &vi_pcie_wreg;
976 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
977 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
978 adev->didt_rreg = &vi_didt_rreg;
979 adev->didt_wreg = &vi_didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +0800980 adev->gc_cac_rreg = &vi_gc_cac_rreg;
981 adev->gc_cac_wreg = &vi_gc_cac_wreg;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400982
983 adev->asic_funcs = &vi_asic_funcs;
984
Alex Deucheraaa36a92015-04-20 17:31:14 -0400985 adev->rev_id = vi_get_rev_id(adev);
986 adev->external_rev_id = 0xFF;
987 switch (adev->asic_type) {
988 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400989 adev->cg_flags = 0;
990 adev->pg_flags = 0;
991 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400992 break;
David Zhang48299f92015-07-08 01:05:16 +0800993 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -0400994 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
995 AMD_CG_SUPPORT_GFX_MGLS |
996 AMD_CG_SUPPORT_GFX_RLC_LS |
997 AMD_CG_SUPPORT_GFX_CP_LS |
998 AMD_CG_SUPPORT_GFX_CGTS |
999 AMD_CG_SUPPORT_GFX_CGTS_LS |
1000 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -04001001 AMD_CG_SUPPORT_GFX_CGLS |
1002 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -04001003 AMD_CG_SUPPORT_SDMA_LS |
1004 AMD_CG_SUPPORT_BIF_LS |
1005 AMD_CG_SUPPORT_HDP_MGCG |
1006 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -04001007 AMD_CG_SUPPORT_ROM_MGCG |
1008 AMD_CG_SUPPORT_MC_MGCG |
Rex Zhu79abf1a2016-11-09 14:30:25 +08001009 AMD_CG_SUPPORT_MC_LS |
1010 AMD_CG_SUPPORT_UVD_MGCG;
Flora Cuib6bc28f2015-11-02 21:21:34 +08001011 adev->pg_flags = 0;
1012 adev->external_rev_id = adev->rev_id + 0x3c;
1013 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001014 case CHIP_TONGA:
Rex Zhuca18b842016-12-07 18:22:38 +08001015 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1016 AMD_CG_SUPPORT_GFX_CGCG |
1017 AMD_CG_SUPPORT_GFX_CGLS |
1018 AMD_CG_SUPPORT_SDMA_MGCG |
1019 AMD_CG_SUPPORT_SDMA_LS |
1020 AMD_CG_SUPPORT_BIF_LS |
1021 AMD_CG_SUPPORT_HDP_MGCG |
1022 AMD_CG_SUPPORT_HDP_LS |
1023 AMD_CG_SUPPORT_ROM_MGCG |
1024 AMD_CG_SUPPORT_MC_MGCG |
1025 AMD_CG_SUPPORT_MC_LS |
1026 AMD_CG_SUPPORT_DRM_LS |
1027 AMD_CG_SUPPORT_UVD_MGCG;
Rex Zhu54971402016-12-07 16:06:38 +08001028 adev->pg_flags = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001029 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001030 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001031 case CHIP_POLARIS11:
Rex Zhuca18b842016-12-07 18:22:38 +08001032 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1033 AMD_CG_SUPPORT_GFX_RLC_LS |
1034 AMD_CG_SUPPORT_GFX_CP_LS |
1035 AMD_CG_SUPPORT_GFX_CGCG |
1036 AMD_CG_SUPPORT_GFX_CGLS |
1037 AMD_CG_SUPPORT_GFX_3D_CGCG |
1038 AMD_CG_SUPPORT_GFX_3D_CGLS |
1039 AMD_CG_SUPPORT_SDMA_MGCG |
1040 AMD_CG_SUPPORT_SDMA_LS |
1041 AMD_CG_SUPPORT_BIF_MGCG |
1042 AMD_CG_SUPPORT_BIF_LS |
1043 AMD_CG_SUPPORT_HDP_MGCG |
1044 AMD_CG_SUPPORT_HDP_LS |
1045 AMD_CG_SUPPORT_ROM_MGCG |
1046 AMD_CG_SUPPORT_MC_MGCG |
1047 AMD_CG_SUPPORT_MC_LS |
1048 AMD_CG_SUPPORT_DRM_LS |
1049 AMD_CG_SUPPORT_UVD_MGCG |
Maruthi Srinivas Bayyavarapuecc2cf72016-11-17 17:29:50 +05301050 AMD_CG_SUPPORT_VCE_MGCG;
Flora Cuic0c1f572015-12-07 18:33:10 +08001051 adev->pg_flags = 0;
1052 adev->external_rev_id = adev->rev_id + 0x5A;
1053 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001054 case CHIP_POLARIS10:
Rex Zhuca18b842016-12-07 18:22:38 +08001055 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1056 AMD_CG_SUPPORT_GFX_RLC_LS |
1057 AMD_CG_SUPPORT_GFX_CP_LS |
1058 AMD_CG_SUPPORT_GFX_CGCG |
1059 AMD_CG_SUPPORT_GFX_CGLS |
1060 AMD_CG_SUPPORT_GFX_3D_CGCG |
1061 AMD_CG_SUPPORT_GFX_3D_CGLS |
1062 AMD_CG_SUPPORT_SDMA_MGCG |
1063 AMD_CG_SUPPORT_SDMA_LS |
1064 AMD_CG_SUPPORT_BIF_MGCG |
1065 AMD_CG_SUPPORT_BIF_LS |
1066 AMD_CG_SUPPORT_HDP_MGCG |
1067 AMD_CG_SUPPORT_HDP_LS |
1068 AMD_CG_SUPPORT_ROM_MGCG |
1069 AMD_CG_SUPPORT_MC_MGCG |
1070 AMD_CG_SUPPORT_MC_LS |
1071 AMD_CG_SUPPORT_DRM_LS |
1072 AMD_CG_SUPPORT_UVD_MGCG |
Maruthi Srinivas Bayyavarapuecc2cf72016-11-17 17:29:50 +05301073 AMD_CG_SUPPORT_VCE_MGCG;
Flora Cuic0c1f572015-12-07 18:33:10 +08001074 adev->pg_flags = 0;
1075 adev->external_rev_id = adev->rev_id + 0x50;
1076 break;
Junwei Zhangc4642a42016-12-14 15:32:28 -05001077 case CHIP_POLARIS12:
Rex Zhu739e9ff2017-03-17 19:04:55 +08001078 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1079 AMD_CG_SUPPORT_GFX_RLC_LS |
1080 AMD_CG_SUPPORT_GFX_CP_LS |
1081 AMD_CG_SUPPORT_GFX_CGCG |
1082 AMD_CG_SUPPORT_GFX_CGLS |
1083 AMD_CG_SUPPORT_GFX_3D_CGCG |
1084 AMD_CG_SUPPORT_GFX_3D_CGLS |
1085 AMD_CG_SUPPORT_SDMA_MGCG |
1086 AMD_CG_SUPPORT_SDMA_LS |
1087 AMD_CG_SUPPORT_BIF_MGCG |
1088 AMD_CG_SUPPORT_BIF_LS |
1089 AMD_CG_SUPPORT_HDP_MGCG |
1090 AMD_CG_SUPPORT_HDP_LS |
1091 AMD_CG_SUPPORT_ROM_MGCG |
1092 AMD_CG_SUPPORT_MC_MGCG |
1093 AMD_CG_SUPPORT_MC_LS |
1094 AMD_CG_SUPPORT_DRM_LS |
1095 AMD_CG_SUPPORT_UVD_MGCG |
1096 AMD_CG_SUPPORT_VCE_MGCG;
Junwei Zhangc4642a42016-12-14 15:32:28 -05001097 adev->pg_flags = 0;
1098 adev->external_rev_id = adev->rev_id + 0x64;
1099 break;
Leo Liub51c5192018-04-11 15:28:28 -05001100 case CHIP_VEGAM:
1101 adev->cg_flags = 0;
1102 /*AMD_CG_SUPPORT_GFX_MGCG |
1103 AMD_CG_SUPPORT_GFX_RLC_LS |
1104 AMD_CG_SUPPORT_GFX_CP_LS |
1105 AMD_CG_SUPPORT_GFX_CGCG |
1106 AMD_CG_SUPPORT_GFX_CGLS |
1107 AMD_CG_SUPPORT_GFX_3D_CGCG |
1108 AMD_CG_SUPPORT_GFX_3D_CGLS |
1109 AMD_CG_SUPPORT_SDMA_MGCG |
1110 AMD_CG_SUPPORT_SDMA_LS |
1111 AMD_CG_SUPPORT_BIF_MGCG |
1112 AMD_CG_SUPPORT_BIF_LS |
1113 AMD_CG_SUPPORT_HDP_MGCG |
1114 AMD_CG_SUPPORT_HDP_LS |
1115 AMD_CG_SUPPORT_ROM_MGCG |
1116 AMD_CG_SUPPORT_MC_MGCG |
1117 AMD_CG_SUPPORT_MC_LS |
1118 AMD_CG_SUPPORT_DRM_LS |
1119 AMD_CG_SUPPORT_UVD_MGCG |
1120 AMD_CG_SUPPORT_VCE_MGCG;*/
1121 adev->pg_flags = 0;
1122 adev->external_rev_id = adev->rev_id + 0x6E;
1123 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001124 case CHIP_CARRIZO:
Tom St Denisf0f3a8f2016-05-03 10:36:28 -04001125 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1126 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucher70eced92016-04-07 23:01:48 -04001127 AMD_CG_SUPPORT_GFX_MGLS |
1128 AMD_CG_SUPPORT_GFX_RLC_LS |
1129 AMD_CG_SUPPORT_GFX_CP_LS |
1130 AMD_CG_SUPPORT_GFX_CGTS |
Alex Deucher70eced92016-04-07 23:01:48 -04001131 AMD_CG_SUPPORT_GFX_CGTS_LS |
Shirish Sfb4bbba2018-02-05 09:23:00 +05301132 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001133 AMD_CG_SUPPORT_GFX_CGLS |
1134 AMD_CG_SUPPORT_BIF_LS |
1135 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001136 AMD_CG_SUPPORT_HDP_LS |
1137 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis1af69a22016-08-03 10:16:17 -04001138 AMD_CG_SUPPORT_SDMA_LS |
1139 AMD_CG_SUPPORT_VCE_MGCG;
Tom St Denisf6ade302016-07-28 09:33:56 -04001140 /* rev0 hardware requires workarounds to support PG */
Alex Deucher0fd4af92016-02-04 23:31:32 -05001141 adev->pg_flags = 0;
Eric Huang170d6e92016-08-12 13:47:08 -04001142 if (adev->rev_id != 0x00 || CZ_REV_BRISTOL(adev->pdev->revision)) {
Felix Kuehlingc2cade32017-08-15 23:00:16 -04001143 adev->pg_flags |= AMD_PG_SUPPORT_GFX_SMG |
Tom St Denis65b42622016-07-28 09:35:57 -04001144 AMD_PG_SUPPORT_GFX_PIPELINE |
Rex Zhu98fccc72016-12-07 17:48:48 +08001145 AMD_PG_SUPPORT_CP |
Tom St Denis2ed09362016-07-28 09:36:26 -04001146 AMD_PG_SUPPORT_UVD |
1147 AMD_PG_SUPPORT_VCE;
Tom St Denisf6ade302016-07-28 09:33:56 -04001148 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001149 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001150 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001151 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001152 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1153 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001154 AMD_CG_SUPPORT_GFX_MGLS |
Tom St Denis413cf602016-06-02 08:52:39 -04001155 AMD_CG_SUPPORT_GFX_RLC_LS |
1156 AMD_CG_SUPPORT_GFX_CP_LS |
1157 AMD_CG_SUPPORT_GFX_CGTS |
Tom St Denis413cf602016-06-02 08:52:39 -04001158 AMD_CG_SUPPORT_GFX_CGTS_LS |
Tom St Denis413cf602016-06-02 08:52:39 -04001159 AMD_CG_SUPPORT_GFX_CGLS |
Alex Deucherb6711d12016-04-13 12:41:50 -04001160 AMD_CG_SUPPORT_BIF_LS |
1161 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001162 AMD_CG_SUPPORT_HDP_LS |
1163 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis8ef583e2016-08-03 11:34:35 -04001164 AMD_CG_SUPPORT_SDMA_LS |
1165 AMD_CG_SUPPORT_VCE_MGCG;
Alex Deuchere6b2a7d2016-10-19 13:06:14 -04001166 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
Tom St Denis4e86be72016-07-28 09:38:13 -04001167 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denisc2cdb04282016-07-28 09:38:29 -04001168 AMD_PG_SUPPORT_GFX_PIPELINE |
Rex Zhu98fccc72016-12-07 17:48:48 +08001169 AMD_PG_SUPPORT_CP |
Tom St Denis75419c42016-07-28 09:38:45 -04001170 AMD_PG_SUPPORT_UVD |
1171 AMD_PG_SUPPORT_VCE;
Jordan Lazarea47c78d2016-09-01 13:49:33 -04001172 adev->external_rev_id = adev->rev_id + 0x61;
Tom St Deniscde64932016-03-23 13:17:04 -04001173 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001174 default:
1175 /* FIXME: not supported yet */
1176 return -EINVAL;
1177 }
1178
Xiangliang Yuab276632017-04-21 14:06:09 +08001179 if (amdgpu_sriov_vf(adev)) {
1180 amdgpu_virt_init_setting(adev);
1181 xgpu_vi_mailbox_set_irq_funcs(adev);
1182 }
1183
Alex Deucheraaa36a92015-04-20 17:31:14 -04001184 return 0;
1185}
1186
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001187static int vi_common_late_init(void *handle)
1188{
1189 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1190
1191 if (amdgpu_sriov_vf(adev))
1192 xgpu_vi_mailbox_get_irq(adev);
1193
1194 return 0;
1195}
1196
yanyang15fc3aee2015-05-22 14:39:35 -04001197static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001198{
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001199 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1200
1201 if (amdgpu_sriov_vf(adev))
1202 xgpu_vi_mailbox_add_irq_id(adev);
1203
Alex Deucheraaa36a92015-04-20 17:31:14 -04001204 return 0;
1205}
1206
yanyang15fc3aee2015-05-22 14:39:35 -04001207static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001208{
1209 return 0;
1210}
1211
yanyang15fc3aee2015-05-22 14:39:35 -04001212static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001213{
yanyang15fc3aee2015-05-22 14:39:35 -04001214 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1215
Alex Deucheraaa36a92015-04-20 17:31:14 -04001216 /* move the golden regs per IP block */
1217 vi_init_golden_registers(adev);
1218 /* enable pcie gen2/3 link */
1219 vi_pcie_gen3_enable(adev);
1220 /* enable aspm */
1221 vi_program_aspm(adev);
1222 /* enable the doorbell aperture */
1223 vi_enable_doorbell_aperture(adev, true);
1224
1225 return 0;
1226}
1227
yanyang15fc3aee2015-05-22 14:39:35 -04001228static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001229{
yanyang15fc3aee2015-05-22 14:39:35 -04001230 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1231
Alex Deucheraaa36a92015-04-20 17:31:14 -04001232 /* enable the doorbell aperture */
1233 vi_enable_doorbell_aperture(adev, false);
1234
Xiangliang Yu63d24f82017-01-18 12:50:14 +08001235 if (amdgpu_sriov_vf(adev))
1236 xgpu_vi_mailbox_put_irq(adev);
1237
Alex Deucheraaa36a92015-04-20 17:31:14 -04001238 return 0;
1239}
1240
yanyang15fc3aee2015-05-22 14:39:35 -04001241static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001242{
yanyang15fc3aee2015-05-22 14:39:35 -04001243 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1244
Alex Deucheraaa36a92015-04-20 17:31:14 -04001245 return vi_common_hw_fini(adev);
1246}
1247
yanyang15fc3aee2015-05-22 14:39:35 -04001248static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001249{
yanyang15fc3aee2015-05-22 14:39:35 -04001250 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1251
Alex Deucheraaa36a92015-04-20 17:31:14 -04001252 return vi_common_hw_init(adev);
1253}
1254
yanyang15fc3aee2015-05-22 14:39:35 -04001255static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001256{
1257 return true;
1258}
1259
yanyang15fc3aee2015-05-22 14:39:35 -04001260static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001261{
1262 return 0;
1263}
1264
yanyang15fc3aee2015-05-22 14:39:35 -04001265static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001266{
1267 return 0;
1268}
1269
Alex Deucher76f10b92016-04-08 01:37:44 -04001270static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1271 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001272{
1273 uint32_t temp, data;
1274
1275 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1276
Alex Deucherc90766c2016-04-08 00:52:58 -04001277 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001278 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1279 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1280 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1281 else
1282 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1283 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1284 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1285
1286 if (temp != data)
1287 WREG32_PCIE(ixPCIE_CNTL2, data);
1288}
1289
Alex Deucher76f10b92016-04-08 01:37:44 -04001290static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1291 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001292{
1293 uint32_t temp, data;
1294
1295 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1296
Alex Deucherc90766c2016-04-08 00:52:58 -04001297 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001298 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1299 else
1300 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1301
1302 if (temp != data)
1303 WREG32(mmHDP_HOST_PATH_CNTL, data);
1304}
1305
Alex Deucher76f10b92016-04-08 01:37:44 -04001306static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1307 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001308{
1309 uint32_t temp, data;
1310
1311 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1312
Alex Deucherc90766c2016-04-08 00:52:58 -04001313 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001314 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1315 else
1316 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1317
1318 if (temp != data)
1319 WREG32(mmHDP_MEM_POWER_LS, data);
1320}
1321
Rex Zhuf6f534e2016-12-08 10:58:15 +08001322static void vi_update_drm_light_sleep(struct amdgpu_device *adev,
1323 bool enable)
1324{
1325 uint32_t temp, data;
1326
1327 temp = data = RREG32(0x157a);
1328
1329 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1330 data |= 1;
1331 else
1332 data &= ~1;
1333
1334 if (temp != data)
1335 WREG32(0x157a, data);
1336}
1337
1338
Alex Deucher76f10b92016-04-08 01:37:44 -04001339static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1340 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001341{
1342 uint32_t temp, data;
1343
1344 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1345
Alex Deucherc90766c2016-04-08 00:52:58 -04001346 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001347 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1348 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1349 else
1350 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1351 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1352
1353 if (temp != data)
1354 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1355}
1356
Rex Zhu1bb08f92016-09-18 16:54:00 +08001357static int vi_common_set_clockgating_state_by_smu(void *handle,
1358 enum amd_clockgating_state state)
1359{
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001360 uint32_t msg_id, pp_state = 0;
1361 uint32_t pp_support_state = 0;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001362 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001363
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001364 if (adev->cg_flags & (AMD_CG_SUPPORT_MC_LS | AMD_CG_SUPPORT_MC_MGCG)) {
1365 if (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) {
1366 pp_support_state = AMD_CG_SUPPORT_MC_LS;
1367 pp_state = PP_STATE_LS;
1368 }
1369 if (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG) {
1370 pp_support_state |= AMD_CG_SUPPORT_MC_MGCG;
1371 pp_state |= PP_STATE_CG;
1372 }
1373 if (state == AMD_CG_STATE_UNGATE)
1374 pp_state = 0;
1375 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1376 PP_BLOCK_SYS_MC,
1377 pp_support_state,
1378 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001379 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1380 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001381 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001382
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001383 if (adev->cg_flags & (AMD_CG_SUPPORT_SDMA_LS | AMD_CG_SUPPORT_SDMA_MGCG)) {
1384 if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS) {
1385 pp_support_state = AMD_CG_SUPPORT_SDMA_LS;
1386 pp_state = PP_STATE_LS;
1387 }
1388 if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG) {
1389 pp_support_state |= AMD_CG_SUPPORT_SDMA_MGCG;
1390 pp_state |= PP_STATE_CG;
1391 }
1392 if (state == AMD_CG_STATE_UNGATE)
1393 pp_state = 0;
1394 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1395 PP_BLOCK_SYS_SDMA,
1396 pp_support_state,
1397 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001398 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1399 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001400 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001401
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001402 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_MGCG)) {
1403 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1404 pp_support_state = AMD_CG_SUPPORT_HDP_LS;
1405 pp_state = PP_STATE_LS;
1406 }
1407 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG) {
1408 pp_support_state |= AMD_CG_SUPPORT_HDP_MGCG;
1409 pp_state |= PP_STATE_CG;
1410 }
1411 if (state == AMD_CG_STATE_UNGATE)
1412 pp_state = 0;
1413 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1414 PP_BLOCK_SYS_HDP,
1415 pp_support_state,
1416 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001417 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1418 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001419 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001420
Rex Zhu1bb08f92016-09-18 16:54:00 +08001421
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001422 if (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS) {
1423 if (state == AMD_CG_STATE_UNGATE)
1424 pp_state = 0;
1425 else
1426 pp_state = PP_STATE_LS;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001427
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001428 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1429 PP_BLOCK_SYS_BIF,
1430 PP_STATE_SUPPORT_LS,
1431 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001432 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1433 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001434 }
1435 if (adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG) {
1436 if (state == AMD_CG_STATE_UNGATE)
1437 pp_state = 0;
1438 else
1439 pp_state = PP_STATE_CG;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001440
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001441 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1442 PP_BLOCK_SYS_BIF,
1443 PP_STATE_SUPPORT_CG,
1444 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001445 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1446 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001447 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001448
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001449 if (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS) {
Rex Zhu1bb08f92016-09-18 16:54:00 +08001450
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001451 if (state == AMD_CG_STATE_UNGATE)
1452 pp_state = 0;
1453 else
1454 pp_state = PP_STATE_LS;
1455
1456 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1457 PP_BLOCK_SYS_DRM,
1458 PP_STATE_SUPPORT_LS,
1459 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001460 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1461 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001462 }
1463
1464 if (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG) {
1465
1466 if (state == AMD_CG_STATE_UNGATE)
1467 pp_state = 0;
1468 else
1469 pp_state = PP_STATE_CG;
1470
1471 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1472 PP_BLOCK_SYS_ROM,
1473 PP_STATE_SUPPORT_CG,
1474 pp_state);
Rex Zhu3811f8f2017-09-26 13:39:38 +08001475 if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
1476 amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001477 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001478 return 0;
1479}
1480
yanyang15fc3aee2015-05-22 14:39:35 -04001481static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001482 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001483{
Eric Huang6cec2652015-11-12 16:59:47 -05001484 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1485
Monk Liuce137c02017-01-23 10:49:33 +08001486 if (amdgpu_sriov_vf(adev))
1487 return 0;
1488
Eric Huang6cec2652015-11-12 16:59:47 -05001489 switch (adev->asic_type) {
1490 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001491 vi_update_bif_medium_grain_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001492 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001493 vi_update_hdp_medium_grain_clock_gating(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001494 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001495 vi_update_hdp_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001496 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001497 vi_update_rom_medium_grain_clock_gating(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001498 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001499 break;
1500 case CHIP_CARRIZO:
1501 case CHIP_STONEY:
1502 vi_update_bif_medium_grain_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001503 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001504 vi_update_hdp_medium_grain_clock_gating(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001505 state == AMD_CG_STATE_GATE);
Alex Deucher76f10b92016-04-08 01:37:44 -04001506 vi_update_hdp_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001507 state == AMD_CG_STATE_GATE);
Rex Zhuf6f534e2016-12-08 10:58:15 +08001508 vi_update_drm_light_sleep(adev,
Andrew F. Davis7e913662017-03-15 11:20:23 -05001509 state == AMD_CG_STATE_GATE);
Eric Huang6cec2652015-11-12 16:59:47 -05001510 break;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001511 case CHIP_TONGA:
1512 case CHIP_POLARIS10:
1513 case CHIP_POLARIS11:
Junwei Zhangc4642a42016-12-14 15:32:28 -05001514 case CHIP_POLARIS12:
Leo Liub51c5192018-04-11 15:28:28 -05001515 case CHIP_VEGAM:
Rex Zhu1bb08f92016-09-18 16:54:00 +08001516 vi_common_set_clockgating_state_by_smu(adev, state);
Eric Huang6cec2652015-11-12 16:59:47 -05001517 default:
1518 break;
1519 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001520 return 0;
1521}
1522
yanyang15fc3aee2015-05-22 14:39:35 -04001523static int vi_common_set_powergating_state(void *handle,
1524 enum amd_powergating_state state)
1525{
1526 return 0;
1527}
1528
Huang Ruiabd2c2f2017-01-05 20:48:06 +08001529static void vi_common_get_clockgating_state(void *handle, u32 *flags)
1530{
1531 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1532 int data;
1533
Monk Liuce137c02017-01-23 10:49:33 +08001534 if (amdgpu_sriov_vf(adev))
1535 *flags = 0;
1536
Huang Ruiabd2c2f2017-01-05 20:48:06 +08001537 /* AMD_CG_SUPPORT_BIF_LS */
1538 data = RREG32_PCIE(ixPCIE_CNTL2);
1539 if (data & PCIE_CNTL2__SLV_MEM_LS_EN_MASK)
1540 *flags |= AMD_CG_SUPPORT_BIF_LS;
1541
1542 /* AMD_CG_SUPPORT_HDP_LS */
1543 data = RREG32(mmHDP_MEM_POWER_LS);
1544 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1545 *flags |= AMD_CG_SUPPORT_HDP_LS;
1546
1547 /* AMD_CG_SUPPORT_HDP_MGCG */
1548 data = RREG32(mmHDP_HOST_PATH_CNTL);
1549 if (!(data & HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK))
1550 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
1551
1552 /* AMD_CG_SUPPORT_ROM_MGCG */
1553 data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1554 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
1555 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
1556}
1557
Alex Deuchera1255102016-10-13 17:41:13 -04001558static const struct amd_ip_funcs vi_common_ip_funcs = {
Tom St Denis88a907d2016-05-04 14:28:35 -04001559 .name = "vi_common",
Alex Deucheraaa36a92015-04-20 17:31:14 -04001560 .early_init = vi_common_early_init,
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001561 .late_init = vi_common_late_init,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001562 .sw_init = vi_common_sw_init,
1563 .sw_fini = vi_common_sw_fini,
1564 .hw_init = vi_common_hw_init,
1565 .hw_fini = vi_common_hw_fini,
1566 .suspend = vi_common_suspend,
1567 .resume = vi_common_resume,
1568 .is_idle = vi_common_is_idle,
1569 .wait_for_idle = vi_common_wait_for_idle,
1570 .soft_reset = vi_common_soft_reset,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001571 .set_clockgating_state = vi_common_set_clockgating_state,
1572 .set_powergating_state = vi_common_set_powergating_state,
Huang Ruiabd2c2f2017-01-05 20:48:06 +08001573 .get_clockgating_state = vi_common_get_clockgating_state,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001574};
1575
Alex Deuchera1255102016-10-13 17:41:13 -04001576static const struct amdgpu_ip_block_version vi_common_ip_block =
1577{
1578 .type = AMD_IP_BLOCK_TYPE_COMMON,
1579 .major = 1,
1580 .minor = 0,
1581 .rev = 0,
1582 .funcs = &vi_common_ip_funcs,
1583};
1584
1585int vi_set_ip_blocks(struct amdgpu_device *adev)
1586{
Xiangliang Yu91caa082017-01-09 11:49:27 +08001587 /* in early init stage, vbios code won't work */
1588 vi_detect_hw_virtualization(adev);
1589
Xiangliang Yu99581cc2017-01-12 15:22:18 +08001590 if (amdgpu_sriov_vf(adev))
1591 adev->virt.ops = &xgpu_vi_virt_ops;
1592
Alex Deuchera1255102016-10-13 17:41:13 -04001593 switch (adev->asic_type) {
1594 case CHIP_TOPAZ:
1595 /* topaz has no DCE, UVD, VCE */
Alex Deucher2990a1f2017-12-15 16:18:00 -05001596 amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1597 amdgpu_device_ip_block_add(adev, &gmc_v7_4_ip_block);
1598 amdgpu_device_ip_block_add(adev, &iceland_ih_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +08001599 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001600 if (adev->enable_virtual_display)
Alex Deucher2990a1f2017-12-15 16:18:00 -05001601 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
1602 amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1603 amdgpu_device_ip_block_add(adev, &sdma_v2_4_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001604 break;
1605 case CHIP_FIJI:
Alex Deucher2990a1f2017-12-15 16:18:00 -05001606 amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1607 amdgpu_device_ip_block_add(adev, &gmc_v8_5_ip_block);
1608 amdgpu_device_ip_block_add(adev, &tonga_ih_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +08001609 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001610 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001611 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001612#if defined(CONFIG_DRM_AMD_DC)
1613 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001614 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001615#endif
Alex Deuchera1255102016-10-13 17:41:13 -04001616 else
Alex Deucher2990a1f2017-12-15 16:18:00 -05001617 amdgpu_device_ip_block_add(adev, &dce_v10_1_ip_block);
1618 amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1619 amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001620 if (!amdgpu_sriov_vf(adev)) {
Alex Deucher2990a1f2017-12-15 16:18:00 -05001621 amdgpu_device_ip_block_add(adev, &uvd_v6_0_ip_block);
1622 amdgpu_device_ip_block_add(adev, &vce_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001623 }
Alex Deuchera1255102016-10-13 17:41:13 -04001624 break;
1625 case CHIP_TONGA:
Alex Deucher2990a1f2017-12-15 16:18:00 -05001626 amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1627 amdgpu_device_ip_block_add(adev, &gmc_v8_0_ip_block);
1628 amdgpu_device_ip_block_add(adev, &tonga_ih_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +08001629 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001630 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001631 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001632#if defined(CONFIG_DRM_AMD_DC)
1633 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001634 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001635#endif
Alex Deuchera1255102016-10-13 17:41:13 -04001636 else
Alex Deucher2990a1f2017-12-15 16:18:00 -05001637 amdgpu_device_ip_block_add(adev, &dce_v10_0_ip_block);
1638 amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1639 amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001640 if (!amdgpu_sriov_vf(adev)) {
Alex Deucher2990a1f2017-12-15 16:18:00 -05001641 amdgpu_device_ip_block_add(adev, &uvd_v5_0_ip_block);
1642 amdgpu_device_ip_block_add(adev, &vce_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001643 }
Alex Deuchera1255102016-10-13 17:41:13 -04001644 break;
Alex Deuchera1255102016-10-13 17:41:13 -04001645 case CHIP_POLARIS10:
Leo Liub51c5192018-04-11 15:28:28 -05001646 case CHIP_POLARIS11:
Junwei Zhangc4642a42016-12-14 15:32:28 -05001647 case CHIP_POLARIS12:
Leo Liub51c5192018-04-11 15:28:28 -05001648 case CHIP_VEGAM:
Alex Deucher2990a1f2017-12-15 16:18:00 -05001649 amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1650 amdgpu_device_ip_block_add(adev, &gmc_v8_1_ip_block);
1651 amdgpu_device_ip_block_add(adev, &tonga_ih_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +08001652 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001653 if (adev->enable_virtual_display)
Alex Deucher2990a1f2017-12-15 16:18:00 -05001654 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001655#if defined(CONFIG_DRM_AMD_DC)
1656 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001657 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001658#endif
Alex Deuchera1255102016-10-13 17:41:13 -04001659 else
Alex Deucher2990a1f2017-12-15 16:18:00 -05001660 amdgpu_device_ip_block_add(adev, &dce_v11_2_ip_block);
1661 amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1662 amdgpu_device_ip_block_add(adev, &sdma_v3_1_ip_block);
1663 amdgpu_device_ip_block_add(adev, &uvd_v6_3_ip_block);
1664 amdgpu_device_ip_block_add(adev, &vce_v3_4_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001665 break;
1666 case CHIP_CARRIZO:
Alex Deucher2990a1f2017-12-15 16:18:00 -05001667 amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1668 amdgpu_device_ip_block_add(adev, &gmc_v8_0_ip_block);
1669 amdgpu_device_ip_block_add(adev, &cz_ih_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +08001670 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001671 if (adev->enable_virtual_display)
Alex Deucher2990a1f2017-12-15 16:18:00 -05001672 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001673#if defined(CONFIG_DRM_AMD_DC)
1674 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001675 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001676#endif
Alex Deuchera1255102016-10-13 17:41:13 -04001677 else
Alex Deucher2990a1f2017-12-15 16:18:00 -05001678 amdgpu_device_ip_block_add(adev, &dce_v11_0_ip_block);
1679 amdgpu_device_ip_block_add(adev, &gfx_v8_0_ip_block);
1680 amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
1681 amdgpu_device_ip_block_add(adev, &uvd_v6_0_ip_block);
1682 amdgpu_device_ip_block_add(adev, &vce_v3_1_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001683#if defined(CONFIG_DRM_AMD_ACP)
Alex Deucher2990a1f2017-12-15 16:18:00 -05001684 amdgpu_device_ip_block_add(adev, &acp_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001685#endif
1686 break;
1687 case CHIP_STONEY:
Alex Deucher2990a1f2017-12-15 16:18:00 -05001688 amdgpu_device_ip_block_add(adev, &vi_common_ip_block);
1689 amdgpu_device_ip_block_add(adev, &gmc_v8_0_ip_block);
1690 amdgpu_device_ip_block_add(adev, &cz_ih_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +08001691 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001692 if (adev->enable_virtual_display)
Alex Deucher2990a1f2017-12-15 16:18:00 -05001693 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001694#if defined(CONFIG_DRM_AMD_DC)
1695 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -05001696 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Harry Wentland45622362017-09-12 15:58:20 -04001697#endif
Alex Deuchera1255102016-10-13 17:41:13 -04001698 else
Alex Deucher2990a1f2017-12-15 16:18:00 -05001699 amdgpu_device_ip_block_add(adev, &dce_v11_0_ip_block);
1700 amdgpu_device_ip_block_add(adev, &gfx_v8_1_ip_block);
1701 amdgpu_device_ip_block_add(adev, &sdma_v3_0_ip_block);
1702 amdgpu_device_ip_block_add(adev, &uvd_v6_2_ip_block);
1703 amdgpu_device_ip_block_add(adev, &vce_v3_4_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001704#if defined(CONFIG_DRM_AMD_ACP)
Alex Deucher2990a1f2017-12-15 16:18:00 -05001705 amdgpu_device_ip_block_add(adev, &acp_ip_block);
Alex Deuchera1255102016-10-13 17:41:13 -04001706#endif
1707 break;
1708 default:
1709 /* FIXME: not supported yet */
1710 return -EINVAL;
1711 }
1712
1713 return 0;
1714}