blob: 0e1b2fd5cf38e221487b0c7fb2930e06f33129ca [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"
Alex Deucheraaa36a92015-04-20 17:31:14 -040079
80/*
81 * Indirect registers accessor
82 */
83static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
84{
85 unsigned long flags;
86 u32 r;
87
88 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
89 WREG32(mmPCIE_INDEX, reg);
90 (void)RREG32(mmPCIE_INDEX);
91 r = RREG32(mmPCIE_DATA);
92 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
93 return r;
94}
95
96static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
97{
98 unsigned long flags;
99
100 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
101 WREG32(mmPCIE_INDEX, reg);
102 (void)RREG32(mmPCIE_INDEX);
103 WREG32(mmPCIE_DATA, v);
104 (void)RREG32(mmPCIE_DATA);
105 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
106}
107
108static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
109{
110 unsigned long flags;
111 u32 r;
112
113 spin_lock_irqsave(&adev->smc_idx_lock, flags);
Monk Liu4bc10d12016-03-29 11:01:51 +0800114 WREG32(mmSMC_IND_INDEX_11, (reg));
115 r = RREG32(mmSMC_IND_DATA_11);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400116 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
117 return r;
118}
119
120static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
121{
122 unsigned long flags;
123
124 spin_lock_irqsave(&adev->smc_idx_lock, flags);
Monk Liu4bc10d12016-03-29 11:01:51 +0800125 WREG32(mmSMC_IND_INDEX_11, (reg));
126 WREG32(mmSMC_IND_DATA_11, (v));
Alex Deucheraaa36a92015-04-20 17:31:14 -0400127 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
128}
129
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400130/* smu_8_0_d.h */
131#define mmMP0PUB_IND_INDEX 0x180
132#define mmMP0PUB_IND_DATA 0x181
133
134static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
135{
136 unsigned long flags;
137 u32 r;
138
139 spin_lock_irqsave(&adev->smc_idx_lock, flags);
140 WREG32(mmMP0PUB_IND_INDEX, (reg));
141 r = RREG32(mmMP0PUB_IND_DATA);
142 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
143 return r;
144}
145
146static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
147{
148 unsigned long flags;
149
150 spin_lock_irqsave(&adev->smc_idx_lock, flags);
151 WREG32(mmMP0PUB_IND_INDEX, (reg));
152 WREG32(mmMP0PUB_IND_DATA, (v));
153 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
154}
155
Alex Deucheraaa36a92015-04-20 17:31:14 -0400156static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
157{
158 unsigned long flags;
159 u32 r;
160
161 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
162 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
163 r = RREG32(mmUVD_CTX_DATA);
164 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
165 return r;
166}
167
168static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
169{
170 unsigned long flags;
171
172 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
173 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
174 WREG32(mmUVD_CTX_DATA, (v));
175 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
176}
177
178static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
179{
180 unsigned long flags;
181 u32 r;
182
183 spin_lock_irqsave(&adev->didt_idx_lock, flags);
184 WREG32(mmDIDT_IND_INDEX, (reg));
185 r = RREG32(mmDIDT_IND_DATA);
186 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
187 return r;
188}
189
190static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
191{
192 unsigned long flags;
193
194 spin_lock_irqsave(&adev->didt_idx_lock, flags);
195 WREG32(mmDIDT_IND_INDEX, (reg));
196 WREG32(mmDIDT_IND_DATA, (v));
197 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
198}
199
Rex Zhuccdbb202016-06-08 12:47:41 +0800200static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
201{
202 unsigned long flags;
203 u32 r;
204
205 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
206 WREG32(mmGC_CAC_IND_INDEX, (reg));
207 r = RREG32(mmGC_CAC_IND_DATA);
208 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
209 return r;
210}
211
212static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
213{
214 unsigned long flags;
215
216 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
217 WREG32(mmGC_CAC_IND_INDEX, (reg));
218 WREG32(mmGC_CAC_IND_DATA, (v));
219 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
220}
221
222
Alex Deucheraaa36a92015-04-20 17:31:14 -0400223static const u32 tonga_mgcg_cgcg_init[] =
224{
225 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
226 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
227 mmPCIE_DATA, 0x000f0000, 0x00000000,
228 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
229 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400230 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
231 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
232};
233
David Zhang48299f92015-07-08 01:05:16 +0800234static const u32 fiji_mgcg_cgcg_init[] =
235{
236 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
237 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
238 mmPCIE_DATA, 0x000f0000, 0x00000000,
239 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
240 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
241 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
242 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
243};
244
Alex Deucheraaa36a92015-04-20 17:31:14 -0400245static const u32 iceland_mgcg_cgcg_init[] =
246{
247 mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
248 mmPCIE_DATA, 0x000f0000, 0x00000000,
249 mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
250 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
251 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
252};
253
254static const u32 cz_mgcg_cgcg_init[] =
255{
256 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
257 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
258 mmPCIE_DATA, 0x000f0000, 0x00000000,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400259 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
260 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
261};
262
Samuel Li39bb0c92015-10-08 16:31:43 -0400263static const u32 stoney_mgcg_cgcg_init[] =
264{
265 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
266 mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
267 mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
268};
269
Alex Deucheraaa36a92015-04-20 17:31:14 -0400270static void vi_init_golden_registers(struct amdgpu_device *adev)
271{
272 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
273 mutex_lock(&adev->grbm_idx_mutex);
274
275 switch (adev->asic_type) {
276 case CHIP_TOPAZ:
277 amdgpu_program_register_sequence(adev,
278 iceland_mgcg_cgcg_init,
279 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
280 break;
David Zhang48299f92015-07-08 01:05:16 +0800281 case CHIP_FIJI:
282 amdgpu_program_register_sequence(adev,
283 fiji_mgcg_cgcg_init,
284 (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
285 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400286 case CHIP_TONGA:
287 amdgpu_program_register_sequence(adev,
288 tonga_mgcg_cgcg_init,
289 (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
290 break;
291 case CHIP_CARRIZO:
292 amdgpu_program_register_sequence(adev,
293 cz_mgcg_cgcg_init,
294 (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
295 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400296 case CHIP_STONEY:
297 amdgpu_program_register_sequence(adev,
298 stoney_mgcg_cgcg_init,
299 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
300 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400301 case CHIP_POLARIS11:
302 case CHIP_POLARIS10:
Junwei Zhangc4642a42016-12-14 15:32:28 -0500303 case CHIP_POLARIS12:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400304 default:
305 break;
306 }
307 mutex_unlock(&adev->grbm_idx_mutex);
308}
309
310/**
311 * vi_get_xclk - get the xclk
312 *
313 * @adev: amdgpu_device pointer
314 *
315 * Returns the reference clock used by the gfx engine
316 * (VI).
317 */
318static u32 vi_get_xclk(struct amdgpu_device *adev)
319{
320 u32 reference_clock = adev->clock.spll.reference_freq;
321 u32 tmp;
322
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800323 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400324 return reference_clock;
325
326 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
327 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
328 return 1000;
329
330 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
331 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
332 return reference_clock / 4;
333
334 return reference_clock;
335}
336
337/**
338 * vi_srbm_select - select specific register instances
339 *
340 * @adev: amdgpu_device pointer
341 * @me: selected ME (micro engine)
342 * @pipe: pipe
343 * @queue: queue
344 * @vmid: VMID
345 *
346 * Switches the currently active registers instances. Some
347 * registers are instanced per VMID, others are instanced per
348 * me/pipe/queue combination.
349 */
350void vi_srbm_select(struct amdgpu_device *adev,
351 u32 me, u32 pipe, u32 queue, u32 vmid)
352{
353 u32 srbm_gfx_cntl = 0;
354 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
355 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
356 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
357 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
358 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
359}
360
361static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
362{
363 /* todo */
364}
365
366static bool vi_read_disabled_bios(struct amdgpu_device *adev)
367{
368 u32 bus_cntl;
369 u32 d1vga_control = 0;
370 u32 d2vga_control = 0;
371 u32 vga_render_control = 0;
372 u32 rom_cntl;
373 bool r;
374
375 bus_cntl = RREG32(mmBUS_CNTL);
376 if (adev->mode_info.num_crtc) {
377 d1vga_control = RREG32(mmD1VGA_CONTROL);
378 d2vga_control = RREG32(mmD2VGA_CONTROL);
379 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
380 }
381 rom_cntl = RREG32_SMC(ixROM_CNTL);
382
383 /* enable the rom */
384 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
385 if (adev->mode_info.num_crtc) {
386 /* Disable VGA mode */
387 WREG32(mmD1VGA_CONTROL,
388 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
389 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
390 WREG32(mmD2VGA_CONTROL,
391 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
392 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
393 WREG32(mmVGA_RENDER_CONTROL,
394 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
395 }
396 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
397
398 r = amdgpu_read_bios(adev);
399
400 /* restore regs */
401 WREG32(mmBUS_CNTL, bus_cntl);
402 if (adev->mode_info.num_crtc) {
403 WREG32(mmD1VGA_CONTROL, d1vga_control);
404 WREG32(mmD2VGA_CONTROL, d2vga_control);
405 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
406 }
407 WREG32_SMC(ixROM_CNTL, rom_cntl);
408 return r;
409}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500410
411static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
412 u8 *bios, u32 length_bytes)
413{
414 u32 *dw_ptr;
415 unsigned long flags;
416 u32 i, length_dw;
417
418 if (bios == NULL)
419 return false;
420 if (length_bytes == 0)
421 return false;
422 /* APU vbios image is part of sbios image */
423 if (adev->flags & AMD_IS_APU)
424 return false;
425
426 dw_ptr = (u32 *)bios;
427 length_dw = ALIGN(length_bytes, 4) / 4;
428 /* take the smc lock since we are using the smc index */
429 spin_lock_irqsave(&adev->smc_idx_lock, flags);
430 /* set rom index to 0 */
Monk Liu4bc10d12016-03-29 11:01:51 +0800431 WREG32(mmSMC_IND_INDEX_11, ixROM_INDEX);
432 WREG32(mmSMC_IND_DATA_11, 0);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500433 /* set index to data for continous read */
Monk Liu4bc10d12016-03-29 11:01:51 +0800434 WREG32(mmSMC_IND_INDEX_11, ixROM_DATA);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500435 for (i = 0; i < length_dw; i++)
Monk Liu4bc10d12016-03-29 11:01:51 +0800436 dw_ptr[i] = RREG32(mmSMC_IND_DATA_11);
Alex Deucher95addb2a2015-11-24 10:37:54 -0500437 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
438
439 return true;
440}
441
Monk Liu4e99a442016-03-31 13:26:59 +0800442static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
Andres Rodriguez048765a2016-06-11 02:51:32 -0400443{
Monk Liu4e99a442016-03-31 13:26:59 +0800444 uint32_t reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
445 /* bit0: 0 means pf and 1 means vf */
446 /* bit31: 0 means disable IOV and 1 means enable */
447 if (reg & 1)
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500448 adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF;
Andres Rodriguez048765a2016-06-11 02:51:32 -0400449
Monk Liu4e99a442016-03-31 13:26:59 +0800450 if (reg & 0x80000000)
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500451 adev->virt.caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV;
Andres Rodriguez048765a2016-06-11 02:51:32 -0400452
Monk Liu4e99a442016-03-31 13:26:59 +0800453 if (reg == 0) {
454 if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */
Xiangliang Yu5a5099c2017-01-09 18:06:57 -0500455 adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE;
Monk Liu4e99a442016-03-31 13:26:59 +0800456 }
Andres Rodriguez048765a2016-06-11 02:51:32 -0400457}
458
Nils Wallméniuseca22402016-03-19 16:12:17 +0100459static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400460 {mmGB_MACROTILE_MODE7, true},
461};
462
Nils Wallméniuseca22402016-03-19 16:12:17 +0100463static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400464 {mmGB_TILE_MODE7, true},
465 {mmGB_TILE_MODE12, true},
466 {mmGB_TILE_MODE17, true},
467 {mmGB_TILE_MODE23, true},
468 {mmGB_MACROTILE_MODE7, true},
469};
470
Nils Wallméniuseca22402016-03-19 16:12:17 +0100471static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400472 {mmGRBM_STATUS, false},
Marek Olšákc7890fe2015-07-11 12:08:46 +0200473 {mmGRBM_STATUS2, false},
474 {mmGRBM_STATUS_SE0, false},
475 {mmGRBM_STATUS_SE1, false},
476 {mmGRBM_STATUS_SE2, false},
477 {mmGRBM_STATUS_SE3, false},
478 {mmSRBM_STATUS, false},
479 {mmSRBM_STATUS2, false},
480 {mmSRBM_STATUS3, false},
481 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
482 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
483 {mmCP_STAT, false},
484 {mmCP_STALLED_STAT1, false},
485 {mmCP_STALLED_STAT2, false},
486 {mmCP_STALLED_STAT3, false},
487 {mmCP_CPF_BUSY_STAT, false},
488 {mmCP_CPF_STALLED_STAT1, false},
489 {mmCP_CPF_STATUS, false},
490 {mmCP_CPC_BUSY_STAT, false},
491 {mmCP_CPC_STALLED_STAT1, false},
492 {mmCP_CPC_STATUS, false},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400493 {mmGB_ADDR_CONFIG, false},
494 {mmMC_ARB_RAMCFG, false},
495 {mmGB_TILE_MODE0, false},
496 {mmGB_TILE_MODE1, false},
497 {mmGB_TILE_MODE2, false},
498 {mmGB_TILE_MODE3, false},
499 {mmGB_TILE_MODE4, false},
500 {mmGB_TILE_MODE5, false},
501 {mmGB_TILE_MODE6, false},
502 {mmGB_TILE_MODE7, false},
503 {mmGB_TILE_MODE8, false},
504 {mmGB_TILE_MODE9, false},
505 {mmGB_TILE_MODE10, false},
506 {mmGB_TILE_MODE11, false},
507 {mmGB_TILE_MODE12, false},
508 {mmGB_TILE_MODE13, false},
509 {mmGB_TILE_MODE14, false},
510 {mmGB_TILE_MODE15, false},
511 {mmGB_TILE_MODE16, false},
512 {mmGB_TILE_MODE17, false},
513 {mmGB_TILE_MODE18, false},
514 {mmGB_TILE_MODE19, false},
515 {mmGB_TILE_MODE20, false},
516 {mmGB_TILE_MODE21, false},
517 {mmGB_TILE_MODE22, false},
518 {mmGB_TILE_MODE23, false},
519 {mmGB_TILE_MODE24, false},
520 {mmGB_TILE_MODE25, false},
521 {mmGB_TILE_MODE26, false},
522 {mmGB_TILE_MODE27, false},
523 {mmGB_TILE_MODE28, false},
524 {mmGB_TILE_MODE29, false},
525 {mmGB_TILE_MODE30, false},
526 {mmGB_TILE_MODE31, false},
527 {mmGB_MACROTILE_MODE0, false},
528 {mmGB_MACROTILE_MODE1, false},
529 {mmGB_MACROTILE_MODE2, false},
530 {mmGB_MACROTILE_MODE3, false},
531 {mmGB_MACROTILE_MODE4, false},
532 {mmGB_MACROTILE_MODE5, false},
533 {mmGB_MACROTILE_MODE6, false},
534 {mmGB_MACROTILE_MODE7, false},
535 {mmGB_MACROTILE_MODE8, false},
536 {mmGB_MACROTILE_MODE9, false},
537 {mmGB_MACROTILE_MODE10, false},
538 {mmGB_MACROTILE_MODE11, false},
539 {mmGB_MACROTILE_MODE12, false},
540 {mmGB_MACROTILE_MODE13, false},
541 {mmGB_MACROTILE_MODE14, false},
542 {mmGB_MACROTILE_MODE15, false},
543 {mmCC_RB_BACKEND_DISABLE, false, true},
544 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
545 {mmGB_BACKEND_MAP, false, false},
546 {mmPA_SC_RASTER_CONFIG, false, true},
547 {mmPA_SC_RASTER_CONFIG_1, false, true},
548};
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{
Nils Wallméniuseca22402016-03-19 16:12:17 +0100649 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
650 const struct amdgpu_allowed_register_entry *asic_register_entry;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400651 uint32_t size, i;
652
653 *value = 0;
654 switch (adev->asic_type) {
655 case CHIP_TOPAZ:
656 asic_register_table = tonga_allowed_read_registers;
657 size = ARRAY_SIZE(tonga_allowed_read_registers);
658 break;
David Zhang48299f92015-07-08 01:05:16 +0800659 case CHIP_FIJI:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400660 case CHIP_TONGA:
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400661 case CHIP_POLARIS11:
662 case CHIP_POLARIS10:
Junwei Zhangc4642a42016-12-14 15:32:28 -0500663 case CHIP_POLARIS12:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400664 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -0400665 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400666 asic_register_table = cz_allowed_read_registers;
667 size = ARRAY_SIZE(cz_allowed_read_registers);
668 break;
669 default:
670 return -EINVAL;
671 }
672
673 if (asic_register_table) {
674 for (i = 0; i < size; i++) {
675 asic_register_entry = asic_register_table + i;
676 if (reg_offset != asic_register_entry->reg_offset)
677 continue;
678 if (!asic_register_entry->untouched)
Alex Deucherdb9635c2016-10-10 12:05:32 -0400679 *value = vi_get_register_value(adev,
680 asic_register_entry->grbm_indexed,
681 se_num, sh_num, reg_offset);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400682 return 0;
683 }
684 }
685
686 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
687 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
688 continue;
689
690 if (!vi_allowed_read_registers[i].untouched)
Alex Deucherdb9635c2016-10-10 12:05:32 -0400691 *value = vi_get_register_value(adev,
692 vi_allowed_read_registers[i].grbm_indexed,
693 se_num, sh_num, reg_offset);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400694 return 0;
695 }
696 return -EINVAL;
697}
698
Chunming Zhou89a31822016-06-06 13:06:45 +0800699static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400700{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400701 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400702
703 dev_info(adev->dev, "GPU pci config reset\n");
704
Alex Deucheraaa36a92015-04-20 17:31:14 -0400705 /* disable BM */
706 pci_clear_master(adev->pdev);
707 /* reset */
708 amdgpu_pci_config_reset(adev);
709
710 udelay(100);
711
712 /* wait for asic to come out of reset */
713 for (i = 0; i < adev->usec_timeout; i++) {
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800714 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
715 /* enable BM */
716 pci_set_master(adev->pdev);
Chunming Zhou89a31822016-06-06 13:06:45 +0800717 return 0;
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800718 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400719 udelay(1);
720 }
Chunming Zhou89a31822016-06-06 13:06:45 +0800721 return -EINVAL;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400722}
723
Alex Deucheraaa36a92015-04-20 17:31:14 -0400724/**
725 * vi_asic_reset - soft reset GPU
726 *
727 * @adev: amdgpu_device pointer
728 *
729 * Look up which blocks are hung and attempt
730 * to reset them.
731 * Returns 0 for success.
732 */
733static int vi_asic_reset(struct amdgpu_device *adev)
734{
Chunming Zhou89a31822016-06-06 13:06:45 +0800735 int r;
736
Alex Deucher72a57432016-10-21 15:45:22 -0400737 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400738
Chunming Zhou89a31822016-06-06 13:06:45 +0800739 r = vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400740
Alex Deucher72a57432016-10-21 15:45:22 -0400741 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400742
Chunming Zhou89a31822016-06-06 13:06:45 +0800743 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400744}
745
746static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
747 u32 cntl_reg, u32 status_reg)
748{
749 int r, i;
750 struct atom_clock_dividers dividers;
751 uint32_t tmp;
752
753 r = amdgpu_atombios_get_clock_dividers(adev,
754 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
755 clock, false, &dividers);
756 if (r)
757 return r;
758
759 tmp = RREG32_SMC(cntl_reg);
760 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
761 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
762 tmp |= dividers.post_divider;
763 WREG32_SMC(cntl_reg, tmp);
764
765 for (i = 0; i < 100; i++) {
766 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
767 break;
768 mdelay(10);
769 }
770 if (i == 100)
771 return -ETIMEDOUT;
772
773 return 0;
774}
775
776static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
777{
778 int r;
779
780 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
781 if (r)
782 return r;
783
784 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
785
786 return 0;
787}
788
789static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
790{
791 /* todo */
792
793 return 0;
794}
795
796static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
797{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400798 if (pci_is_root_bus(adev->pdev->bus))
799 return;
800
Alex Deucheraaa36a92015-04-20 17:31:14 -0400801 if (amdgpu_pcie_gen2 == 0)
802 return;
803
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800804 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400805 return;
806
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500807 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
808 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400809 return;
810
811 /* todo */
812}
813
814static void vi_program_aspm(struct amdgpu_device *adev)
815{
816
817 if (amdgpu_aspm == 0)
818 return;
819
820 /* todo */
821}
822
823static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
824 bool enable)
825{
826 u32 tmp;
827
828 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800829 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400830 return;
831
832 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
833 if (enable)
834 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
835 else
836 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
837
838 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
839}
840
Samuel Li39bb0c92015-10-08 16:31:43 -0400841#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
842#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
843#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
844
Alex Deucheraaa36a92015-04-20 17:31:14 -0400845static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
846{
Flora Cuiabdfb852015-11-20 11:40:53 +0800847 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -0400848 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
849 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400850 else
Flora Cuiabdfb852015-11-20 11:40:53 +0800851 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
852 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400853}
854
855static const struct amdgpu_asic_funcs vi_asic_funcs =
856{
857 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -0500858 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400859 .read_register = &vi_read_register,
860 .reset = &vi_asic_reset,
861 .set_vga_state = &vi_vga_set_state,
862 .get_xclk = &vi_get_xclk,
863 .set_uvd_clocks = &vi_set_uvd_clocks,
864 .set_vce_clocks = &vi_set_vce_clocks,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400865};
866
yanyang15fc3aee2015-05-22 14:39:35 -0400867static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400868{
869 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -0400870 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400871
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800872 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400873 adev->smc_rreg = &cz_smc_rreg;
874 adev->smc_wreg = &cz_smc_wreg;
875 } else {
876 adev->smc_rreg = &vi_smc_rreg;
877 adev->smc_wreg = &vi_smc_wreg;
878 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400879 adev->pcie_rreg = &vi_pcie_rreg;
880 adev->pcie_wreg = &vi_pcie_wreg;
881 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
882 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
883 adev->didt_rreg = &vi_didt_rreg;
884 adev->didt_wreg = &vi_didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +0800885 adev->gc_cac_rreg = &vi_gc_cac_rreg;
886 adev->gc_cac_wreg = &vi_gc_cac_wreg;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400887
888 adev->asic_funcs = &vi_asic_funcs;
889
yanyang15fc3aee2015-05-22 14:39:35 -0400890 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
891 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400892 smc_enabled = true;
893
894 adev->rev_id = vi_get_rev_id(adev);
895 adev->external_rev_id = 0xFF;
896 switch (adev->asic_type) {
897 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400898 adev->cg_flags = 0;
899 adev->pg_flags = 0;
900 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400901 break;
David Zhang48299f92015-07-08 01:05:16 +0800902 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -0400903 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
904 AMD_CG_SUPPORT_GFX_MGLS |
905 AMD_CG_SUPPORT_GFX_RLC_LS |
906 AMD_CG_SUPPORT_GFX_CP_LS |
907 AMD_CG_SUPPORT_GFX_CGTS |
908 AMD_CG_SUPPORT_GFX_CGTS_LS |
909 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -0400910 AMD_CG_SUPPORT_GFX_CGLS |
911 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -0400912 AMD_CG_SUPPORT_SDMA_LS |
913 AMD_CG_SUPPORT_BIF_LS |
914 AMD_CG_SUPPORT_HDP_MGCG |
915 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -0400916 AMD_CG_SUPPORT_ROM_MGCG |
917 AMD_CG_SUPPORT_MC_MGCG |
Rex Zhu79abf1a2016-11-09 14:30:25 +0800918 AMD_CG_SUPPORT_MC_LS |
919 AMD_CG_SUPPORT_UVD_MGCG;
Flora Cuib6bc28f2015-11-02 21:21:34 +0800920 adev->pg_flags = 0;
921 adev->external_rev_id = adev->rev_id + 0x3c;
922 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400923 case CHIP_TONGA:
Rex Zhuca18b842016-12-07 18:22:38 +0800924 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
925 AMD_CG_SUPPORT_GFX_CGCG |
926 AMD_CG_SUPPORT_GFX_CGLS |
927 AMD_CG_SUPPORT_SDMA_MGCG |
928 AMD_CG_SUPPORT_SDMA_LS |
929 AMD_CG_SUPPORT_BIF_LS |
930 AMD_CG_SUPPORT_HDP_MGCG |
931 AMD_CG_SUPPORT_HDP_LS |
932 AMD_CG_SUPPORT_ROM_MGCG |
933 AMD_CG_SUPPORT_MC_MGCG |
934 AMD_CG_SUPPORT_MC_LS |
935 AMD_CG_SUPPORT_DRM_LS |
936 AMD_CG_SUPPORT_UVD_MGCG;
Rex Zhu54971402016-12-07 16:06:38 +0800937 adev->pg_flags = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400938 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400939 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400940 case CHIP_POLARIS11:
Rex Zhuca18b842016-12-07 18:22:38 +0800941 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
942 AMD_CG_SUPPORT_GFX_RLC_LS |
943 AMD_CG_SUPPORT_GFX_CP_LS |
944 AMD_CG_SUPPORT_GFX_CGCG |
945 AMD_CG_SUPPORT_GFX_CGLS |
946 AMD_CG_SUPPORT_GFX_3D_CGCG |
947 AMD_CG_SUPPORT_GFX_3D_CGLS |
948 AMD_CG_SUPPORT_SDMA_MGCG |
949 AMD_CG_SUPPORT_SDMA_LS |
950 AMD_CG_SUPPORT_BIF_MGCG |
951 AMD_CG_SUPPORT_BIF_LS |
952 AMD_CG_SUPPORT_HDP_MGCG |
953 AMD_CG_SUPPORT_HDP_LS |
954 AMD_CG_SUPPORT_ROM_MGCG |
955 AMD_CG_SUPPORT_MC_MGCG |
956 AMD_CG_SUPPORT_MC_LS |
957 AMD_CG_SUPPORT_DRM_LS |
958 AMD_CG_SUPPORT_UVD_MGCG |
Maruthi Srinivas Bayyavarapuecc2cf72016-11-17 17:29:50 +0530959 AMD_CG_SUPPORT_VCE_MGCG;
Flora Cuic0c1f572015-12-07 18:33:10 +0800960 adev->pg_flags = 0;
961 adev->external_rev_id = adev->rev_id + 0x5A;
962 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400963 case CHIP_POLARIS10:
Rex Zhuca18b842016-12-07 18:22:38 +0800964 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
965 AMD_CG_SUPPORT_GFX_RLC_LS |
966 AMD_CG_SUPPORT_GFX_CP_LS |
967 AMD_CG_SUPPORT_GFX_CGCG |
968 AMD_CG_SUPPORT_GFX_CGLS |
969 AMD_CG_SUPPORT_GFX_3D_CGCG |
970 AMD_CG_SUPPORT_GFX_3D_CGLS |
971 AMD_CG_SUPPORT_SDMA_MGCG |
972 AMD_CG_SUPPORT_SDMA_LS |
973 AMD_CG_SUPPORT_BIF_MGCG |
974 AMD_CG_SUPPORT_BIF_LS |
975 AMD_CG_SUPPORT_HDP_MGCG |
976 AMD_CG_SUPPORT_HDP_LS |
977 AMD_CG_SUPPORT_ROM_MGCG |
978 AMD_CG_SUPPORT_MC_MGCG |
979 AMD_CG_SUPPORT_MC_LS |
980 AMD_CG_SUPPORT_DRM_LS |
981 AMD_CG_SUPPORT_UVD_MGCG |
Maruthi Srinivas Bayyavarapuecc2cf72016-11-17 17:29:50 +0530982 AMD_CG_SUPPORT_VCE_MGCG;
Flora Cuic0c1f572015-12-07 18:33:10 +0800983 adev->pg_flags = 0;
984 adev->external_rev_id = adev->rev_id + 0x50;
985 break;
Junwei Zhangc4642a42016-12-14 15:32:28 -0500986 case CHIP_POLARIS12:
987 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
988 adev->pg_flags = 0;
989 adev->external_rev_id = adev->rev_id + 0x64;
990 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400991 case CHIP_CARRIZO:
Tom St Denisf0f3a8f2016-05-03 10:36:28 -0400992 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
993 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucher70eced92016-04-07 23:01:48 -0400994 AMD_CG_SUPPORT_GFX_MGLS |
995 AMD_CG_SUPPORT_GFX_RLC_LS |
996 AMD_CG_SUPPORT_GFX_CP_LS |
997 AMD_CG_SUPPORT_GFX_CGTS |
998 AMD_CG_SUPPORT_GFX_MGLS |
999 AMD_CG_SUPPORT_GFX_CGTS_LS |
1000 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001001 AMD_CG_SUPPORT_GFX_CGLS |
1002 AMD_CG_SUPPORT_BIF_LS |
1003 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001004 AMD_CG_SUPPORT_HDP_LS |
1005 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis1af69a22016-08-03 10:16:17 -04001006 AMD_CG_SUPPORT_SDMA_LS |
1007 AMD_CG_SUPPORT_VCE_MGCG;
Tom St Denisf6ade302016-07-28 09:33:56 -04001008 /* rev0 hardware requires workarounds to support PG */
Alex Deucher0fd4af92016-02-04 23:31:32 -05001009 adev->pg_flags = 0;
Tom St Denisf6ade302016-07-28 09:33:56 -04001010 if (adev->rev_id != 0x00) {
1011 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
1012 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denis65b42622016-07-28 09:35:57 -04001013 AMD_PG_SUPPORT_GFX_PIPELINE |
Rex Zhu98fccc72016-12-07 17:48:48 +08001014 AMD_PG_SUPPORT_CP |
Tom St Denis2ed09362016-07-28 09:36:26 -04001015 AMD_PG_SUPPORT_UVD |
1016 AMD_PG_SUPPORT_VCE;
Tom St Denisf6ade302016-07-28 09:33:56 -04001017 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001018 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001019 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001020 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001021 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1022 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001023 AMD_CG_SUPPORT_GFX_MGLS |
Tom St Denis413cf602016-06-02 08:52:39 -04001024 AMD_CG_SUPPORT_GFX_RLC_LS |
1025 AMD_CG_SUPPORT_GFX_CP_LS |
1026 AMD_CG_SUPPORT_GFX_CGTS |
1027 AMD_CG_SUPPORT_GFX_MGLS |
1028 AMD_CG_SUPPORT_GFX_CGTS_LS |
1029 AMD_CG_SUPPORT_GFX_CGCG |
1030 AMD_CG_SUPPORT_GFX_CGLS |
Alex Deucherb6711d12016-04-13 12:41:50 -04001031 AMD_CG_SUPPORT_BIF_LS |
1032 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001033 AMD_CG_SUPPORT_HDP_LS |
1034 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis8ef583e2016-08-03 11:34:35 -04001035 AMD_CG_SUPPORT_SDMA_LS |
1036 AMD_CG_SUPPORT_VCE_MGCG;
Alex Deuchere6b2a7d2016-10-19 13:06:14 -04001037 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
Tom St Denis4e86be72016-07-28 09:38:13 -04001038 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denisc2cdb04282016-07-28 09:38:29 -04001039 AMD_PG_SUPPORT_GFX_PIPELINE |
Rex Zhu98fccc72016-12-07 17:48:48 +08001040 AMD_PG_SUPPORT_CP |
Tom St Denis75419c42016-07-28 09:38:45 -04001041 AMD_PG_SUPPORT_UVD |
1042 AMD_PG_SUPPORT_VCE;
Jordan Lazarea47c78d2016-09-01 13:49:33 -04001043 adev->external_rev_id = adev->rev_id + 0x61;
Tom St Deniscde64932016-03-23 13:17:04 -04001044 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001045 default:
1046 /* FIXME: not supported yet */
1047 return -EINVAL;
1048 }
1049
Flora Cuia3d08fa2015-11-02 21:15:55 +08001050 if (amdgpu_smc_load_fw && smc_enabled)
1051 adev->firmware.smu_load = true;
1052
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001053 amdgpu_get_pcie_info(adev);
1054
Alex Deucheraaa36a92015-04-20 17:31:14 -04001055 return 0;
1056}
1057
yanyang15fc3aee2015-05-22 14:39:35 -04001058static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001059{
1060 return 0;
1061}
1062
yanyang15fc3aee2015-05-22 14:39:35 -04001063static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001064{
1065 return 0;
1066}
1067
yanyang15fc3aee2015-05-22 14:39:35 -04001068static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001069{
yanyang15fc3aee2015-05-22 14:39:35 -04001070 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1071
Alex Deucheraaa36a92015-04-20 17:31:14 -04001072 /* move the golden regs per IP block */
1073 vi_init_golden_registers(adev);
1074 /* enable pcie gen2/3 link */
1075 vi_pcie_gen3_enable(adev);
1076 /* enable aspm */
1077 vi_program_aspm(adev);
1078 /* enable the doorbell aperture */
1079 vi_enable_doorbell_aperture(adev, true);
1080
1081 return 0;
1082}
1083
yanyang15fc3aee2015-05-22 14:39:35 -04001084static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001085{
yanyang15fc3aee2015-05-22 14:39:35 -04001086 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1087
Alex Deucheraaa36a92015-04-20 17:31:14 -04001088 /* enable the doorbell aperture */
1089 vi_enable_doorbell_aperture(adev, false);
1090
1091 return 0;
1092}
1093
yanyang15fc3aee2015-05-22 14:39:35 -04001094static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001095{
yanyang15fc3aee2015-05-22 14:39:35 -04001096 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1097
Alex Deucheraaa36a92015-04-20 17:31:14 -04001098 return vi_common_hw_fini(adev);
1099}
1100
yanyang15fc3aee2015-05-22 14:39:35 -04001101static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001102{
yanyang15fc3aee2015-05-22 14:39:35 -04001103 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1104
Alex Deucheraaa36a92015-04-20 17:31:14 -04001105 return vi_common_hw_init(adev);
1106}
1107
yanyang15fc3aee2015-05-22 14:39:35 -04001108static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001109{
1110 return true;
1111}
1112
yanyang15fc3aee2015-05-22 14:39:35 -04001113static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001114{
1115 return 0;
1116}
1117
yanyang15fc3aee2015-05-22 14:39:35 -04001118static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001119{
1120 return 0;
1121}
1122
Alex Deucher76f10b92016-04-08 01:37:44 -04001123static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1124 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001125{
1126 uint32_t temp, data;
1127
1128 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1129
Alex Deucherc90766c2016-04-08 00:52:58 -04001130 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001131 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1132 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1133 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1134 else
1135 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1136 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1137 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1138
1139 if (temp != data)
1140 WREG32_PCIE(ixPCIE_CNTL2, data);
1141}
1142
Alex Deucher76f10b92016-04-08 01:37:44 -04001143static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1144 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001145{
1146 uint32_t temp, data;
1147
1148 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1149
Alex Deucherc90766c2016-04-08 00:52:58 -04001150 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001151 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1152 else
1153 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1154
1155 if (temp != data)
1156 WREG32(mmHDP_HOST_PATH_CNTL, data);
1157}
1158
Alex Deucher76f10b92016-04-08 01:37:44 -04001159static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1160 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001161{
1162 uint32_t temp, data;
1163
1164 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1165
Alex Deucherc90766c2016-04-08 00:52:58 -04001166 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001167 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1168 else
1169 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1170
1171 if (temp != data)
1172 WREG32(mmHDP_MEM_POWER_LS, data);
1173}
1174
Rex Zhuf6f534e2016-12-08 10:58:15 +08001175static void vi_update_drm_light_sleep(struct amdgpu_device *adev,
1176 bool enable)
1177{
1178 uint32_t temp, data;
1179
1180 temp = data = RREG32(0x157a);
1181
1182 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1183 data |= 1;
1184 else
1185 data &= ~1;
1186
1187 if (temp != data)
1188 WREG32(0x157a, data);
1189}
1190
1191
Alex Deucher76f10b92016-04-08 01:37:44 -04001192static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1193 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001194{
1195 uint32_t temp, data;
1196
1197 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1198
Alex Deucherc90766c2016-04-08 00:52:58 -04001199 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001200 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1201 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1202 else
1203 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1204 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1205
1206 if (temp != data)
1207 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1208}
1209
Rex Zhu1bb08f92016-09-18 16:54:00 +08001210static int vi_common_set_clockgating_state_by_smu(void *handle,
1211 enum amd_clockgating_state state)
1212{
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001213 uint32_t msg_id, pp_state = 0;
1214 uint32_t pp_support_state = 0;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001215 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1216 void *pp_handle = adev->powerplay.pp_handle;
1217
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001218 if (adev->cg_flags & (AMD_CG_SUPPORT_MC_LS | AMD_CG_SUPPORT_MC_MGCG)) {
1219 if (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) {
1220 pp_support_state = AMD_CG_SUPPORT_MC_LS;
1221 pp_state = PP_STATE_LS;
1222 }
1223 if (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG) {
1224 pp_support_state |= AMD_CG_SUPPORT_MC_MGCG;
1225 pp_state |= PP_STATE_CG;
1226 }
1227 if (state == AMD_CG_STATE_UNGATE)
1228 pp_state = 0;
1229 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1230 PP_BLOCK_SYS_MC,
1231 pp_support_state,
1232 pp_state);
1233 amd_set_clockgating_by_smu(pp_handle, msg_id);
1234 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001235
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001236 if (adev->cg_flags & (AMD_CG_SUPPORT_SDMA_LS | AMD_CG_SUPPORT_SDMA_MGCG)) {
1237 if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS) {
1238 pp_support_state = AMD_CG_SUPPORT_SDMA_LS;
1239 pp_state = PP_STATE_LS;
1240 }
1241 if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG) {
1242 pp_support_state |= AMD_CG_SUPPORT_SDMA_MGCG;
1243 pp_state |= PP_STATE_CG;
1244 }
1245 if (state == AMD_CG_STATE_UNGATE)
1246 pp_state = 0;
1247 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1248 PP_BLOCK_SYS_SDMA,
1249 pp_support_state,
1250 pp_state);
1251 amd_set_clockgating_by_smu(pp_handle, msg_id);
1252 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001253
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001254 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_MGCG)) {
1255 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1256 pp_support_state = AMD_CG_SUPPORT_HDP_LS;
1257 pp_state = PP_STATE_LS;
1258 }
1259 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG) {
1260 pp_support_state |= AMD_CG_SUPPORT_HDP_MGCG;
1261 pp_state |= PP_STATE_CG;
1262 }
1263 if (state == AMD_CG_STATE_UNGATE)
1264 pp_state = 0;
1265 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1266 PP_BLOCK_SYS_HDP,
1267 pp_support_state,
1268 pp_state);
1269 amd_set_clockgating_by_smu(pp_handle, msg_id);
1270 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001271
Rex Zhu1bb08f92016-09-18 16:54:00 +08001272
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001273 if (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS) {
1274 if (state == AMD_CG_STATE_UNGATE)
1275 pp_state = 0;
1276 else
1277 pp_state = PP_STATE_LS;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001278
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001279 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1280 PP_BLOCK_SYS_BIF,
1281 PP_STATE_SUPPORT_LS,
1282 pp_state);
1283 amd_set_clockgating_by_smu(pp_handle, msg_id);
1284 }
1285 if (adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG) {
1286 if (state == AMD_CG_STATE_UNGATE)
1287 pp_state = 0;
1288 else
1289 pp_state = PP_STATE_CG;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001290
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001291 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1292 PP_BLOCK_SYS_BIF,
1293 PP_STATE_SUPPORT_CG,
1294 pp_state);
1295 amd_set_clockgating_by_smu(pp_handle, msg_id);
1296 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001297
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001298 if (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS) {
Rex Zhu1bb08f92016-09-18 16:54:00 +08001299
Rex Zhu8a19e7f2016-12-07 19:11:49 +08001300 if (state == AMD_CG_STATE_UNGATE)
1301 pp_state = 0;
1302 else
1303 pp_state = PP_STATE_LS;
1304
1305 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1306 PP_BLOCK_SYS_DRM,
1307 PP_STATE_SUPPORT_LS,
1308 pp_state);
1309 amd_set_clockgating_by_smu(pp_handle, msg_id);
1310 }
1311
1312 if (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG) {
1313
1314 if (state == AMD_CG_STATE_UNGATE)
1315 pp_state = 0;
1316 else
1317 pp_state = PP_STATE_CG;
1318
1319 msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1320 PP_BLOCK_SYS_ROM,
1321 PP_STATE_SUPPORT_CG,
1322 pp_state);
1323 amd_set_clockgating_by_smu(pp_handle, msg_id);
1324 }
Rex Zhu1bb08f92016-09-18 16:54:00 +08001325 return 0;
1326}
1327
yanyang15fc3aee2015-05-22 14:39:35 -04001328static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001329 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001330{
Eric Huang6cec2652015-11-12 16:59:47 -05001331 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1332
1333 switch (adev->asic_type) {
1334 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001335 vi_update_bif_medium_grain_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001336 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001337 vi_update_hdp_medium_grain_clock_gating(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001338 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001339 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001340 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001341 vi_update_rom_medium_grain_clock_gating(adev,
1342 state == AMD_CG_STATE_GATE ? true : false);
1343 break;
1344 case CHIP_CARRIZO:
1345 case CHIP_STONEY:
1346 vi_update_bif_medium_grain_light_sleep(adev,
1347 state == AMD_CG_STATE_GATE ? true : false);
1348 vi_update_hdp_medium_grain_clock_gating(adev,
1349 state == AMD_CG_STATE_GATE ? true : false);
1350 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001351 state == AMD_CG_STATE_GATE ? true : false);
Rex Zhuf6f534e2016-12-08 10:58:15 +08001352 vi_update_drm_light_sleep(adev,
1353 state == AMD_CG_STATE_GATE ? true : false);
Eric Huang6cec2652015-11-12 16:59:47 -05001354 break;
Rex Zhu1bb08f92016-09-18 16:54:00 +08001355 case CHIP_TONGA:
1356 case CHIP_POLARIS10:
1357 case CHIP_POLARIS11:
Junwei Zhangc4642a42016-12-14 15:32:28 -05001358 case CHIP_POLARIS12:
Rex Zhu1bb08f92016-09-18 16:54:00 +08001359 vi_common_set_clockgating_state_by_smu(adev, state);
Eric Huang6cec2652015-11-12 16:59:47 -05001360 default:
1361 break;
1362 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001363 return 0;
1364}
1365
yanyang15fc3aee2015-05-22 14:39:35 -04001366static int vi_common_set_powergating_state(void *handle,
1367 enum amd_powergating_state state)
1368{
1369 return 0;
1370}
1371
Alex Deuchera1255102016-10-13 17:41:13 -04001372static const struct amd_ip_funcs vi_common_ip_funcs = {
Tom St Denis88a907d2016-05-04 14:28:35 -04001373 .name = "vi_common",
Alex Deucheraaa36a92015-04-20 17:31:14 -04001374 .early_init = vi_common_early_init,
1375 .late_init = NULL,
1376 .sw_init = vi_common_sw_init,
1377 .sw_fini = vi_common_sw_fini,
1378 .hw_init = vi_common_hw_init,
1379 .hw_fini = vi_common_hw_fini,
1380 .suspend = vi_common_suspend,
1381 .resume = vi_common_resume,
1382 .is_idle = vi_common_is_idle,
1383 .wait_for_idle = vi_common_wait_for_idle,
1384 .soft_reset = vi_common_soft_reset,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001385 .set_clockgating_state = vi_common_set_clockgating_state,
1386 .set_powergating_state = vi_common_set_powergating_state,
1387};
1388
Alex Deuchera1255102016-10-13 17:41:13 -04001389static const struct amdgpu_ip_block_version vi_common_ip_block =
1390{
1391 .type = AMD_IP_BLOCK_TYPE_COMMON,
1392 .major = 1,
1393 .minor = 0,
1394 .rev = 0,
1395 .funcs = &vi_common_ip_funcs,
1396};
1397
1398int vi_set_ip_blocks(struct amdgpu_device *adev)
1399{
Xiangliang Yu91caa082017-01-09 11:49:27 +08001400 /* in early init stage, vbios code won't work */
1401 vi_detect_hw_virtualization(adev);
1402
Alex Deuchera1255102016-10-13 17:41:13 -04001403 switch (adev->asic_type) {
1404 case CHIP_TOPAZ:
1405 /* topaz has no DCE, UVD, VCE */
1406 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1407 amdgpu_ip_block_add(adev, &gmc_v7_4_ip_block);
1408 amdgpu_ip_block_add(adev, &iceland_ih_ip_block);
1409 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1410 if (adev->enable_virtual_display)
1411 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1412 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1413 amdgpu_ip_block_add(adev, &sdma_v2_4_ip_block);
1414 break;
1415 case CHIP_FIJI:
1416 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1417 amdgpu_ip_block_add(adev, &gmc_v8_5_ip_block);
1418 amdgpu_ip_block_add(adev, &tonga_ih_ip_block);
1419 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001420 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deuchera1255102016-10-13 17:41:13 -04001421 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1422 else
1423 amdgpu_ip_block_add(adev, &dce_v10_1_ip_block);
1424 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1425 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001426 if (!amdgpu_sriov_vf(adev)) {
1427 amdgpu_ip_block_add(adev, &uvd_v6_0_ip_block);
1428 amdgpu_ip_block_add(adev, &vce_v3_0_ip_block);
1429 }
Alex Deuchera1255102016-10-13 17:41:13 -04001430 break;
1431 case CHIP_TONGA:
1432 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1433 amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block);
1434 amdgpu_ip_block_add(adev, &tonga_ih_ip_block);
1435 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001436 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deuchera1255102016-10-13 17:41:13 -04001437 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1438 else
1439 amdgpu_ip_block_add(adev, &dce_v10_0_ip_block);
1440 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1441 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
Xiangliang Yu91caa082017-01-09 11:49:27 +08001442 if (!amdgpu_sriov_vf(adev)) {
1443 amdgpu_ip_block_add(adev, &uvd_v5_0_ip_block);
1444 amdgpu_ip_block_add(adev, &vce_v3_0_ip_block);
1445 }
Alex Deuchera1255102016-10-13 17:41:13 -04001446 break;
1447 case CHIP_POLARIS11:
1448 case CHIP_POLARIS10:
Junwei Zhangc4642a42016-12-14 15:32:28 -05001449 case CHIP_POLARIS12:
Alex Deuchera1255102016-10-13 17:41:13 -04001450 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1451 amdgpu_ip_block_add(adev, &gmc_v8_1_ip_block);
1452 amdgpu_ip_block_add(adev, &tonga_ih_ip_block);
1453 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1454 if (adev->enable_virtual_display)
1455 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1456 else
1457 amdgpu_ip_block_add(adev, &dce_v11_2_ip_block);
1458 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1459 amdgpu_ip_block_add(adev, &sdma_v3_1_ip_block);
1460 amdgpu_ip_block_add(adev, &uvd_v6_3_ip_block);
1461 amdgpu_ip_block_add(adev, &vce_v3_4_ip_block);
1462 break;
1463 case CHIP_CARRIZO:
1464 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1465 amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block);
1466 amdgpu_ip_block_add(adev, &cz_ih_ip_block);
1467 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1468 if (adev->enable_virtual_display)
1469 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1470 else
1471 amdgpu_ip_block_add(adev, &dce_v11_0_ip_block);
1472 amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block);
1473 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
1474 amdgpu_ip_block_add(adev, &uvd_v6_0_ip_block);
1475 amdgpu_ip_block_add(adev, &vce_v3_1_ip_block);
1476#if defined(CONFIG_DRM_AMD_ACP)
1477 amdgpu_ip_block_add(adev, &acp_ip_block);
1478#endif
1479 break;
1480 case CHIP_STONEY:
1481 amdgpu_ip_block_add(adev, &vi_common_ip_block);
1482 amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block);
1483 amdgpu_ip_block_add(adev, &cz_ih_ip_block);
1484 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
1485 if (adev->enable_virtual_display)
1486 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
1487 else
1488 amdgpu_ip_block_add(adev, &dce_v11_0_ip_block);
1489 amdgpu_ip_block_add(adev, &gfx_v8_1_ip_block);
1490 amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block);
1491 amdgpu_ip_block_add(adev, &uvd_v6_2_ip_block);
1492 amdgpu_ip_block_add(adev, &vce_v3_4_ip_block);
1493#if defined(CONFIG_DRM_AMD_ACP)
1494 amdgpu_ip_block_add(adev, &acp_ip_block);
1495#endif
1496 break;
1497 default:
1498 /* FIXME: not supported yet */
1499 return -EINVAL;
1500 }
1501
1502 return 0;
1503}