blob: 008817174365936d5ae8060046ac43cf8b816331 [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 */
23#include <linux/firmware.h>
24#include <linux/slab.h>
25#include <linux/module.h>
26#include "drmP.h"
27#include "amdgpu.h"
28#include "amdgpu_atombios.h"
29#include "amdgpu_ih.h"
30#include "amdgpu_uvd.h"
31#include "amdgpu_vce.h"
32#include "amdgpu_ucode.h"
33#include "atom.h"
Alex Deucherd0dd7f02015-11-11 19:45:06 -050034#include "amd_pcie.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040035
36#include "gmc/gmc_8_1_d.h"
37#include "gmc/gmc_8_1_sh_mask.h"
38
39#include "oss/oss_3_0_d.h"
40#include "oss/oss_3_0_sh_mask.h"
41
42#include "bif/bif_5_0_d.h"
43#include "bif/bif_5_0_sh_mask.h"
44
45#include "gca/gfx_8_0_d.h"
46#include "gca/gfx_8_0_sh_mask.h"
47
48#include "smu/smu_7_1_1_d.h"
49#include "smu/smu_7_1_1_sh_mask.h"
50
51#include "uvd/uvd_5_0_d.h"
52#include "uvd/uvd_5_0_sh_mask.h"
53
54#include "vce/vce_3_0_d.h"
55#include "vce/vce_3_0_sh_mask.h"
56
57#include "dce/dce_10_0_d.h"
58#include "dce/dce_10_0_sh_mask.h"
59
60#include "vid.h"
61#include "vi.h"
62#include "vi_dpm.h"
63#include "gmc_v8_0.h"
Ken Wang429c45d2016-02-03 19:16:54 +080064#include "gmc_v7_0.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040065#include "gfx_v8_0.h"
66#include "sdma_v2_4.h"
67#include "sdma_v3_0.h"
68#include "dce_v10_0.h"
69#include "dce_v11_0.h"
70#include "iceland_ih.h"
71#include "tonga_ih.h"
72#include "cz_ih.h"
73#include "uvd_v5_0.h"
74#include "uvd_v6_0.h"
75#include "vce_v3_0.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050076#include "amdgpu_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040077#if defined(CONFIG_DRM_AMD_ACP)
78#include "amdgpu_acp.h"
79#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -040080
Flora Cuif8951062016-03-18 19:07:55 +080081MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
82MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
83MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
84MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
85
Alex Deucheraaa36a92015-04-20 17:31:14 -040086/*
87 * Indirect registers accessor
88 */
89static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
90{
91 unsigned long flags;
92 u32 r;
93
94 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
95 WREG32(mmPCIE_INDEX, reg);
96 (void)RREG32(mmPCIE_INDEX);
97 r = RREG32(mmPCIE_DATA);
98 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
99 return r;
100}
101
102static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
103{
104 unsigned long flags;
105
106 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
107 WREG32(mmPCIE_INDEX, reg);
108 (void)RREG32(mmPCIE_INDEX);
109 WREG32(mmPCIE_DATA, v);
110 (void)RREG32(mmPCIE_DATA);
111 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
112}
113
114static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
115{
116 unsigned long flags;
117 u32 r;
118
119 spin_lock_irqsave(&adev->smc_idx_lock, flags);
120 WREG32(mmSMC_IND_INDEX_0, (reg));
121 r = RREG32(mmSMC_IND_DATA_0);
122 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
123 return r;
124}
125
126static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
127{
128 unsigned long flags;
129
130 spin_lock_irqsave(&adev->smc_idx_lock, flags);
131 WREG32(mmSMC_IND_INDEX_0, (reg));
132 WREG32(mmSMC_IND_DATA_0, (v));
133 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
134}
135
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400136/* smu_8_0_d.h */
137#define mmMP0PUB_IND_INDEX 0x180
138#define mmMP0PUB_IND_DATA 0x181
139
140static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
141{
142 unsigned long flags;
143 u32 r;
144
145 spin_lock_irqsave(&adev->smc_idx_lock, flags);
146 WREG32(mmMP0PUB_IND_INDEX, (reg));
147 r = RREG32(mmMP0PUB_IND_DATA);
148 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
149 return r;
150}
151
152static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&adev->smc_idx_lock, flags);
157 WREG32(mmMP0PUB_IND_INDEX, (reg));
158 WREG32(mmMP0PUB_IND_DATA, (v));
159 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
160}
161
Alex Deucheraaa36a92015-04-20 17:31:14 -0400162static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
163{
164 unsigned long flags;
165 u32 r;
166
167 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
168 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
169 r = RREG32(mmUVD_CTX_DATA);
170 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
171 return r;
172}
173
174static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
175{
176 unsigned long flags;
177
178 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
179 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
180 WREG32(mmUVD_CTX_DATA, (v));
181 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
182}
183
184static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
185{
186 unsigned long flags;
187 u32 r;
188
189 spin_lock_irqsave(&adev->didt_idx_lock, flags);
190 WREG32(mmDIDT_IND_INDEX, (reg));
191 r = RREG32(mmDIDT_IND_DATA);
192 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
193 return r;
194}
195
196static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
197{
198 unsigned long flags;
199
200 spin_lock_irqsave(&adev->didt_idx_lock, flags);
201 WREG32(mmDIDT_IND_INDEX, (reg));
202 WREG32(mmDIDT_IND_DATA, (v));
203 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
204}
205
Rex Zhuccdbb202016-06-08 12:47:41 +0800206static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
207{
208 unsigned long flags;
209 u32 r;
210
211 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
212 WREG32(mmGC_CAC_IND_INDEX, (reg));
213 r = RREG32(mmGC_CAC_IND_DATA);
214 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
215 return r;
216}
217
218static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
219{
220 unsigned long flags;
221
222 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
223 WREG32(mmGC_CAC_IND_INDEX, (reg));
224 WREG32(mmGC_CAC_IND_DATA, (v));
225 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
226}
227
228
Alex Deucheraaa36a92015-04-20 17:31:14 -0400229static const u32 tonga_mgcg_cgcg_init[] =
230{
231 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
232 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
233 mmPCIE_DATA, 0x000f0000, 0x00000000,
234 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
235 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400236 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
237 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
238};
239
David Zhang48299f92015-07-08 01:05:16 +0800240static const u32 fiji_mgcg_cgcg_init[] =
241{
242 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
243 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
244 mmPCIE_DATA, 0x000f0000, 0x00000000,
245 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
246 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
247 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
248 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
249};
250
Alex Deucheraaa36a92015-04-20 17:31:14 -0400251static const u32 iceland_mgcg_cgcg_init[] =
252{
253 mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
254 mmPCIE_DATA, 0x000f0000, 0x00000000,
255 mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
256 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
257 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
258};
259
260static const u32 cz_mgcg_cgcg_init[] =
261{
262 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
263 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
264 mmPCIE_DATA, 0x000f0000, 0x00000000,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400265 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
266 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
267};
268
Samuel Li39bb0c92015-10-08 16:31:43 -0400269static const u32 stoney_mgcg_cgcg_init[] =
270{
271 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
272 mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
273 mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
274};
275
Alex Deucheraaa36a92015-04-20 17:31:14 -0400276static void vi_init_golden_registers(struct amdgpu_device *adev)
277{
278 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
279 mutex_lock(&adev->grbm_idx_mutex);
280
281 switch (adev->asic_type) {
282 case CHIP_TOPAZ:
283 amdgpu_program_register_sequence(adev,
284 iceland_mgcg_cgcg_init,
285 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
286 break;
David Zhang48299f92015-07-08 01:05:16 +0800287 case CHIP_FIJI:
288 amdgpu_program_register_sequence(adev,
289 fiji_mgcg_cgcg_init,
290 (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
291 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400292 case CHIP_TONGA:
293 amdgpu_program_register_sequence(adev,
294 tonga_mgcg_cgcg_init,
295 (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
296 break;
297 case CHIP_CARRIZO:
298 amdgpu_program_register_sequence(adev,
299 cz_mgcg_cgcg_init,
300 (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
301 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400302 case CHIP_STONEY:
303 amdgpu_program_register_sequence(adev,
304 stoney_mgcg_cgcg_init,
305 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
306 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400307 case CHIP_POLARIS11:
308 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400309 default:
310 break;
311 }
312 mutex_unlock(&adev->grbm_idx_mutex);
313}
314
315/**
316 * vi_get_xclk - get the xclk
317 *
318 * @adev: amdgpu_device pointer
319 *
320 * Returns the reference clock used by the gfx engine
321 * (VI).
322 */
323static u32 vi_get_xclk(struct amdgpu_device *adev)
324{
325 u32 reference_clock = adev->clock.spll.reference_freq;
326 u32 tmp;
327
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800328 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400329 return reference_clock;
330
331 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
332 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
333 return 1000;
334
335 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
336 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
337 return reference_clock / 4;
338
339 return reference_clock;
340}
341
342/**
343 * vi_srbm_select - select specific register instances
344 *
345 * @adev: amdgpu_device pointer
346 * @me: selected ME (micro engine)
347 * @pipe: pipe
348 * @queue: queue
349 * @vmid: VMID
350 *
351 * Switches the currently active registers instances. Some
352 * registers are instanced per VMID, others are instanced per
353 * me/pipe/queue combination.
354 */
355void vi_srbm_select(struct amdgpu_device *adev,
356 u32 me, u32 pipe, u32 queue, u32 vmid)
357{
358 u32 srbm_gfx_cntl = 0;
359 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
360 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
361 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
362 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
363 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
364}
365
366static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
367{
368 /* todo */
369}
370
371static bool vi_read_disabled_bios(struct amdgpu_device *adev)
372{
373 u32 bus_cntl;
374 u32 d1vga_control = 0;
375 u32 d2vga_control = 0;
376 u32 vga_render_control = 0;
377 u32 rom_cntl;
378 bool r;
379
380 bus_cntl = RREG32(mmBUS_CNTL);
381 if (adev->mode_info.num_crtc) {
382 d1vga_control = RREG32(mmD1VGA_CONTROL);
383 d2vga_control = RREG32(mmD2VGA_CONTROL);
384 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
385 }
386 rom_cntl = RREG32_SMC(ixROM_CNTL);
387
388 /* enable the rom */
389 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
390 if (adev->mode_info.num_crtc) {
391 /* Disable VGA mode */
392 WREG32(mmD1VGA_CONTROL,
393 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
394 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
395 WREG32(mmD2VGA_CONTROL,
396 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
397 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
398 WREG32(mmVGA_RENDER_CONTROL,
399 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
400 }
401 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
402
403 r = amdgpu_read_bios(adev);
404
405 /* restore regs */
406 WREG32(mmBUS_CNTL, bus_cntl);
407 if (adev->mode_info.num_crtc) {
408 WREG32(mmD1VGA_CONTROL, d1vga_control);
409 WREG32(mmD2VGA_CONTROL, d2vga_control);
410 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
411 }
412 WREG32_SMC(ixROM_CNTL, rom_cntl);
413 return r;
414}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500415
416static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
417 u8 *bios, u32 length_bytes)
418{
419 u32 *dw_ptr;
420 unsigned long flags;
421 u32 i, length_dw;
422
423 if (bios == NULL)
424 return false;
425 if (length_bytes == 0)
426 return false;
427 /* APU vbios image is part of sbios image */
428 if (adev->flags & AMD_IS_APU)
429 return false;
430
431 dw_ptr = (u32 *)bios;
432 length_dw = ALIGN(length_bytes, 4) / 4;
433 /* take the smc lock since we are using the smc index */
434 spin_lock_irqsave(&adev->smc_idx_lock, flags);
435 /* set rom index to 0 */
436 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
437 WREG32(mmSMC_IND_DATA_0, 0);
438 /* set index to data for continous read */
439 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
440 for (i = 0; i < length_dw; i++)
441 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
442 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
443
444 return true;
445}
446
Andres Rodriguez048765a2016-06-11 02:51:32 -0400447static u32 vi_get_virtual_caps(struct amdgpu_device *adev)
448{
449 u32 caps = 0;
450 u32 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
451
452 if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE))
453 caps |= AMDGPU_VIRT_CAPS_SRIOV_EN;
454
455 if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER))
456 caps |= AMDGPU_VIRT_CAPS_IS_VF;
457
458 return caps;
459}
460
Nils Wallméniuseca22402016-03-19 16:12:17 +0100461static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400462 {mmGB_MACROTILE_MODE7, true},
463};
464
Nils Wallméniuseca22402016-03-19 16:12:17 +0100465static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400466 {mmGB_TILE_MODE7, true},
467 {mmGB_TILE_MODE12, true},
468 {mmGB_TILE_MODE17, true},
469 {mmGB_TILE_MODE23, true},
470 {mmGB_MACROTILE_MODE7, true},
471};
472
Nils Wallméniuseca22402016-03-19 16:12:17 +0100473static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400474 {mmGRBM_STATUS, false},
Marek Olšákc7890fe2015-07-11 12:08:46 +0200475 {mmGRBM_STATUS2, false},
476 {mmGRBM_STATUS_SE0, false},
477 {mmGRBM_STATUS_SE1, false},
478 {mmGRBM_STATUS_SE2, false},
479 {mmGRBM_STATUS_SE3, false},
480 {mmSRBM_STATUS, false},
481 {mmSRBM_STATUS2, false},
482 {mmSRBM_STATUS3, false},
483 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
484 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
485 {mmCP_STAT, false},
486 {mmCP_STALLED_STAT1, false},
487 {mmCP_STALLED_STAT2, false},
488 {mmCP_STALLED_STAT3, false},
489 {mmCP_CPF_BUSY_STAT, false},
490 {mmCP_CPF_STALLED_STAT1, false},
491 {mmCP_CPF_STATUS, false},
492 {mmCP_CPC_BUSY_STAT, false},
493 {mmCP_CPC_STALLED_STAT1, false},
494 {mmCP_CPC_STATUS, false},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400495 {mmGB_ADDR_CONFIG, false},
496 {mmMC_ARB_RAMCFG, false},
497 {mmGB_TILE_MODE0, false},
498 {mmGB_TILE_MODE1, false},
499 {mmGB_TILE_MODE2, false},
500 {mmGB_TILE_MODE3, false},
501 {mmGB_TILE_MODE4, false},
502 {mmGB_TILE_MODE5, false},
503 {mmGB_TILE_MODE6, false},
504 {mmGB_TILE_MODE7, false},
505 {mmGB_TILE_MODE8, false},
506 {mmGB_TILE_MODE9, false},
507 {mmGB_TILE_MODE10, false},
508 {mmGB_TILE_MODE11, false},
509 {mmGB_TILE_MODE12, false},
510 {mmGB_TILE_MODE13, false},
511 {mmGB_TILE_MODE14, false},
512 {mmGB_TILE_MODE15, false},
513 {mmGB_TILE_MODE16, false},
514 {mmGB_TILE_MODE17, false},
515 {mmGB_TILE_MODE18, false},
516 {mmGB_TILE_MODE19, false},
517 {mmGB_TILE_MODE20, false},
518 {mmGB_TILE_MODE21, false},
519 {mmGB_TILE_MODE22, false},
520 {mmGB_TILE_MODE23, false},
521 {mmGB_TILE_MODE24, false},
522 {mmGB_TILE_MODE25, false},
523 {mmGB_TILE_MODE26, false},
524 {mmGB_TILE_MODE27, false},
525 {mmGB_TILE_MODE28, false},
526 {mmGB_TILE_MODE29, false},
527 {mmGB_TILE_MODE30, false},
528 {mmGB_TILE_MODE31, false},
529 {mmGB_MACROTILE_MODE0, false},
530 {mmGB_MACROTILE_MODE1, false},
531 {mmGB_MACROTILE_MODE2, false},
532 {mmGB_MACROTILE_MODE3, false},
533 {mmGB_MACROTILE_MODE4, false},
534 {mmGB_MACROTILE_MODE5, false},
535 {mmGB_MACROTILE_MODE6, false},
536 {mmGB_MACROTILE_MODE7, false},
537 {mmGB_MACROTILE_MODE8, false},
538 {mmGB_MACROTILE_MODE9, false},
539 {mmGB_MACROTILE_MODE10, false},
540 {mmGB_MACROTILE_MODE11, false},
541 {mmGB_MACROTILE_MODE12, false},
542 {mmGB_MACROTILE_MODE13, false},
543 {mmGB_MACROTILE_MODE14, false},
544 {mmGB_MACROTILE_MODE15, false},
545 {mmCC_RB_BACKEND_DISABLE, false, true},
546 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
547 {mmGB_BACKEND_MAP, false, false},
548 {mmPA_SC_RASTER_CONFIG, false, true},
549 {mmPA_SC_RASTER_CONFIG_1, false, true},
550};
551
552static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
553 u32 sh_num, u32 reg_offset)
554{
555 uint32_t val;
556
557 mutex_lock(&adev->grbm_idx_mutex);
558 if (se_num != 0xffffffff || sh_num != 0xffffffff)
Tom St Denis9559ef52016-06-28 10:26:48 -0400559 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400560
561 val = RREG32(reg_offset);
562
563 if (se_num != 0xffffffff || sh_num != 0xffffffff)
Tom St Denis9559ef52016-06-28 10:26:48 -0400564 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400565 mutex_unlock(&adev->grbm_idx_mutex);
566 return val;
567}
568
569static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
570 u32 sh_num, u32 reg_offset, u32 *value)
571{
Nils Wallméniuseca22402016-03-19 16:12:17 +0100572 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
573 const struct amdgpu_allowed_register_entry *asic_register_entry;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400574 uint32_t size, i;
575
576 *value = 0;
577 switch (adev->asic_type) {
578 case CHIP_TOPAZ:
579 asic_register_table = tonga_allowed_read_registers;
580 size = ARRAY_SIZE(tonga_allowed_read_registers);
581 break;
David Zhang48299f92015-07-08 01:05:16 +0800582 case CHIP_FIJI:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400583 case CHIP_TONGA:
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400584 case CHIP_POLARIS11:
585 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400586 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -0400587 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400588 asic_register_table = cz_allowed_read_registers;
589 size = ARRAY_SIZE(cz_allowed_read_registers);
590 break;
591 default:
592 return -EINVAL;
593 }
594
595 if (asic_register_table) {
596 for (i = 0; i < size; i++) {
597 asic_register_entry = asic_register_table + i;
598 if (reg_offset != asic_register_entry->reg_offset)
599 continue;
600 if (!asic_register_entry->untouched)
601 *value = asic_register_entry->grbm_indexed ?
602 vi_read_indexed_register(adev, se_num,
603 sh_num, reg_offset) :
604 RREG32(reg_offset);
605 return 0;
606 }
607 }
608
609 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
610 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
611 continue;
612
613 if (!vi_allowed_read_registers[i].untouched)
614 *value = vi_allowed_read_registers[i].grbm_indexed ?
615 vi_read_indexed_register(adev, se_num,
616 sh_num, reg_offset) :
617 RREG32(reg_offset);
618 return 0;
619 }
620 return -EINVAL;
621}
622
Chunming Zhou89a31822016-06-06 13:06:45 +0800623static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400624{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400625 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400626
627 dev_info(adev->dev, "GPU pci config reset\n");
628
Alex Deucheraaa36a92015-04-20 17:31:14 -0400629 /* disable BM */
630 pci_clear_master(adev->pdev);
631 /* reset */
632 amdgpu_pci_config_reset(adev);
633
634 udelay(100);
635
636 /* wait for asic to come out of reset */
637 for (i = 0; i < adev->usec_timeout; i++) {
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800638 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
639 /* enable BM */
640 pci_set_master(adev->pdev);
Chunming Zhou89a31822016-06-06 13:06:45 +0800641 return 0;
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800642 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400643 udelay(1);
644 }
Chunming Zhou89a31822016-06-06 13:06:45 +0800645 return -EINVAL;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400646}
647
648static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
649{
650 u32 tmp = RREG32(mmBIOS_SCRATCH_3);
651
652 if (hung)
653 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
654 else
655 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
656
657 WREG32(mmBIOS_SCRATCH_3, tmp);
658}
659
660/**
661 * vi_asic_reset - soft reset GPU
662 *
663 * @adev: amdgpu_device pointer
664 *
665 * Look up which blocks are hung and attempt
666 * to reset them.
667 * Returns 0 for success.
668 */
669static int vi_asic_reset(struct amdgpu_device *adev)
670{
Chunming Zhou89a31822016-06-06 13:06:45 +0800671 int r;
672
Alex Deuchera2c5c692015-10-14 09:39:37 -0400673 vi_set_bios_scratch_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400674
Chunming Zhou89a31822016-06-06 13:06:45 +0800675 r = vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400676
Alex Deuchera2c5c692015-10-14 09:39:37 -0400677 vi_set_bios_scratch_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400678
Chunming Zhou89a31822016-06-06 13:06:45 +0800679 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400680}
681
682static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
683 u32 cntl_reg, u32 status_reg)
684{
685 int r, i;
686 struct atom_clock_dividers dividers;
687 uint32_t tmp;
688
689 r = amdgpu_atombios_get_clock_dividers(adev,
690 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
691 clock, false, &dividers);
692 if (r)
693 return r;
694
695 tmp = RREG32_SMC(cntl_reg);
696 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
697 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
698 tmp |= dividers.post_divider;
699 WREG32_SMC(cntl_reg, tmp);
700
701 for (i = 0; i < 100; i++) {
702 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
703 break;
704 mdelay(10);
705 }
706 if (i == 100)
707 return -ETIMEDOUT;
708
709 return 0;
710}
711
712static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
713{
714 int r;
715
716 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
717 if (r)
718 return r;
719
720 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
721
722 return 0;
723}
724
725static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
726{
727 /* todo */
728
729 return 0;
730}
731
732static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
733{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400734 if (pci_is_root_bus(adev->pdev->bus))
735 return;
736
Alex Deucheraaa36a92015-04-20 17:31:14 -0400737 if (amdgpu_pcie_gen2 == 0)
738 return;
739
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800740 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400741 return;
742
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500743 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
744 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400745 return;
746
747 /* todo */
748}
749
750static void vi_program_aspm(struct amdgpu_device *adev)
751{
752
753 if (amdgpu_aspm == 0)
754 return;
755
756 /* todo */
757}
758
759static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
760 bool enable)
761{
762 u32 tmp;
763
764 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800765 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400766 return;
767
768 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
769 if (enable)
770 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
771 else
772 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
773
774 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
775}
776
777/* topaz has no DCE, UVD, VCE */
778static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
779{
780 /* ORDER MATTERS! */
781 {
yanyang15fc3aee2015-05-22 14:39:35 -0400782 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400783 .major = 2,
784 .minor = 0,
785 .rev = 0,
786 .funcs = &vi_common_ip_funcs,
787 },
788 {
yanyang15fc3aee2015-05-22 14:39:35 -0400789 .type = AMD_IP_BLOCK_TYPE_GMC,
Ken Wang429c45d2016-02-03 19:16:54 +0800790 .major = 7,
791 .minor = 4,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400792 .rev = 0,
Ken Wang429c45d2016-02-03 19:16:54 +0800793 .funcs = &gmc_v7_0_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400794 },
795 {
yanyang15fc3aee2015-05-22 14:39:35 -0400796 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400797 .major = 2,
798 .minor = 4,
799 .rev = 0,
800 .funcs = &iceland_ih_ip_funcs,
801 },
802 {
yanyang15fc3aee2015-05-22 14:39:35 -0400803 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400804 .major = 7,
805 .minor = 1,
806 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500807 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400808 },
809 {
yanyang15fc3aee2015-05-22 14:39:35 -0400810 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400811 .major = 8,
812 .minor = 0,
813 .rev = 0,
814 .funcs = &gfx_v8_0_ip_funcs,
815 },
816 {
yanyang15fc3aee2015-05-22 14:39:35 -0400817 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400818 .major = 2,
819 .minor = 4,
820 .rev = 0,
821 .funcs = &sdma_v2_4_ip_funcs,
822 },
823};
824
825static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
826{
827 /* ORDER MATTERS! */
828 {
yanyang15fc3aee2015-05-22 14:39:35 -0400829 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400830 .major = 2,
831 .minor = 0,
832 .rev = 0,
833 .funcs = &vi_common_ip_funcs,
834 },
835 {
yanyang15fc3aee2015-05-22 14:39:35 -0400836 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400837 .major = 8,
838 .minor = 0,
839 .rev = 0,
840 .funcs = &gmc_v8_0_ip_funcs,
841 },
842 {
yanyang15fc3aee2015-05-22 14:39:35 -0400843 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400844 .major = 3,
845 .minor = 0,
846 .rev = 0,
847 .funcs = &tonga_ih_ip_funcs,
848 },
849 {
yanyang15fc3aee2015-05-22 14:39:35 -0400850 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400851 .major = 7,
852 .minor = 1,
853 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500854 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400855 },
856 {
yanyang15fc3aee2015-05-22 14:39:35 -0400857 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400858 .major = 10,
859 .minor = 0,
860 .rev = 0,
861 .funcs = &dce_v10_0_ip_funcs,
862 },
863 {
yanyang15fc3aee2015-05-22 14:39:35 -0400864 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400865 .major = 8,
866 .minor = 0,
867 .rev = 0,
868 .funcs = &gfx_v8_0_ip_funcs,
869 },
870 {
yanyang15fc3aee2015-05-22 14:39:35 -0400871 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400872 .major = 3,
873 .minor = 0,
874 .rev = 0,
875 .funcs = &sdma_v3_0_ip_funcs,
876 },
877 {
yanyang15fc3aee2015-05-22 14:39:35 -0400878 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400879 .major = 5,
880 .minor = 0,
881 .rev = 0,
882 .funcs = &uvd_v5_0_ip_funcs,
883 },
884 {
yanyang15fc3aee2015-05-22 14:39:35 -0400885 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400886 .major = 3,
887 .minor = 0,
888 .rev = 0,
889 .funcs = &vce_v3_0_ip_funcs,
890 },
891};
892
David Zhang48299f92015-07-08 01:05:16 +0800893static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
894{
895 /* ORDER MATTERS! */
896 {
897 .type = AMD_IP_BLOCK_TYPE_COMMON,
898 .major = 2,
899 .minor = 0,
900 .rev = 0,
901 .funcs = &vi_common_ip_funcs,
David Zhang127a2622015-07-08 01:11:52 +0800902 },
903 {
904 .type = AMD_IP_BLOCK_TYPE_GMC,
905 .major = 8,
906 .minor = 5,
907 .rev = 0,
908 .funcs = &gmc_v8_0_ip_funcs,
909 },
David Zhangaa8a3b52015-07-08 21:40:31 +0800910 {
911 .type = AMD_IP_BLOCK_TYPE_IH,
912 .major = 3,
913 .minor = 0,
914 .rev = 0,
915 .funcs = &tonga_ih_ip_funcs,
916 },
David Zhang8e711e1a2015-07-08 01:23:25 +0800917 {
918 .type = AMD_IP_BLOCK_TYPE_SMC,
919 .major = 7,
920 .minor = 1,
921 .rev = 0,
Eric Huang899fa4c2015-09-29 14:58:53 -0400922 .funcs = &amdgpu_pp_ip_funcs,
David Zhang8e711e1a2015-07-08 01:23:25 +0800923 },
David Zhang84390862015-07-08 01:28:20 +0800924 {
925 .type = AMD_IP_BLOCK_TYPE_DCE,
926 .major = 10,
927 .minor = 1,
928 .rev = 0,
929 .funcs = &dce_v10_0_ip_funcs,
930 },
David Zhangaf15a2d2015-07-30 19:42:11 -0400931 {
932 .type = AMD_IP_BLOCK_TYPE_GFX,
933 .major = 8,
934 .minor = 0,
935 .rev = 0,
936 .funcs = &gfx_v8_0_ip_funcs,
937 },
David Zhang1a5bbb62015-07-08 17:29:27 +0800938 {
939 .type = AMD_IP_BLOCK_TYPE_SDMA,
940 .major = 3,
941 .minor = 0,
942 .rev = 0,
943 .funcs = &sdma_v3_0_ip_funcs,
944 },
David Zhang974ee3d2015-07-08 17:32:15 +0800945 {
946 .type = AMD_IP_BLOCK_TYPE_UVD,
947 .major = 6,
948 .minor = 0,
949 .rev = 0,
950 .funcs = &uvd_v6_0_ip_funcs,
951 },
Alex Deucher188a9bc2015-07-27 14:24:14 -0400952 {
953 .type = AMD_IP_BLOCK_TYPE_VCE,
954 .major = 3,
955 .minor = 0,
956 .rev = 0,
957 .funcs = &vce_v3_0_ip_funcs,
958 },
David Zhang48299f92015-07-08 01:05:16 +0800959};
960
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400961static const struct amdgpu_ip_block_version polaris11_ip_blocks[] =
Flora Cuic0c1f572015-12-07 18:33:10 +0800962{
963 /* ORDER MATTERS! */
964 {
965 .type = AMD_IP_BLOCK_TYPE_COMMON,
966 .major = 2,
967 .minor = 0,
968 .rev = 0,
969 .funcs = &vi_common_ip_funcs,
970 },
971 {
972 .type = AMD_IP_BLOCK_TYPE_GMC,
973 .major = 8,
974 .minor = 1,
975 .rev = 0,
976 .funcs = &gmc_v8_0_ip_funcs,
977 },
978 {
979 .type = AMD_IP_BLOCK_TYPE_IH,
980 .major = 3,
981 .minor = 1,
982 .rev = 0,
983 .funcs = &tonga_ih_ip_funcs,
984 },
985 {
986 .type = AMD_IP_BLOCK_TYPE_SMC,
987 .major = 7,
988 .minor = 2,
989 .rev = 0,
990 .funcs = &amdgpu_pp_ip_funcs,
991 },
992 {
993 .type = AMD_IP_BLOCK_TYPE_DCE,
994 .major = 11,
995 .minor = 2,
996 .rev = 0,
997 .funcs = &dce_v11_0_ip_funcs,
998 },
999 {
1000 .type = AMD_IP_BLOCK_TYPE_GFX,
1001 .major = 8,
1002 .minor = 0,
1003 .rev = 0,
1004 .funcs = &gfx_v8_0_ip_funcs,
1005 },
1006 {
1007 .type = AMD_IP_BLOCK_TYPE_SDMA,
1008 .major = 3,
1009 .minor = 1,
1010 .rev = 0,
1011 .funcs = &sdma_v3_0_ip_funcs,
1012 },
1013 {
1014 .type = AMD_IP_BLOCK_TYPE_UVD,
1015 .major = 6,
1016 .minor = 3,
1017 .rev = 0,
1018 .funcs = &uvd_v6_0_ip_funcs,
1019 },
1020 {
1021 .type = AMD_IP_BLOCK_TYPE_VCE,
1022 .major = 3,
1023 .minor = 4,
1024 .rev = 0,
1025 .funcs = &vce_v3_0_ip_funcs,
1026 },
1027};
1028
Alex Deucheraaa36a92015-04-20 17:31:14 -04001029static const struct amdgpu_ip_block_version cz_ip_blocks[] =
1030{
1031 /* ORDER MATTERS! */
1032 {
yanyang15fc3aee2015-05-22 14:39:35 -04001033 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001034 .major = 2,
1035 .minor = 0,
1036 .rev = 0,
1037 .funcs = &vi_common_ip_funcs,
1038 },
1039 {
yanyang15fc3aee2015-05-22 14:39:35 -04001040 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001041 .major = 8,
1042 .minor = 0,
1043 .rev = 0,
1044 .funcs = &gmc_v8_0_ip_funcs,
1045 },
1046 {
yanyang15fc3aee2015-05-22 14:39:35 -04001047 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001048 .major = 3,
1049 .minor = 0,
1050 .rev = 0,
1051 .funcs = &cz_ih_ip_funcs,
1052 },
1053 {
yanyang15fc3aee2015-05-22 14:39:35 -04001054 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001055 .major = 8,
1056 .minor = 0,
1057 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -05001058 .funcs = &amdgpu_pp_ip_funcs
Alex Deucheraaa36a92015-04-20 17:31:14 -04001059 },
1060 {
yanyang15fc3aee2015-05-22 14:39:35 -04001061 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001062 .major = 11,
1063 .minor = 0,
1064 .rev = 0,
1065 .funcs = &dce_v11_0_ip_funcs,
1066 },
1067 {
yanyang15fc3aee2015-05-22 14:39:35 -04001068 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001069 .major = 8,
1070 .minor = 0,
1071 .rev = 0,
1072 .funcs = &gfx_v8_0_ip_funcs,
1073 },
1074 {
yanyang15fc3aee2015-05-22 14:39:35 -04001075 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001076 .major = 3,
1077 .minor = 0,
1078 .rev = 0,
1079 .funcs = &sdma_v3_0_ip_funcs,
1080 },
1081 {
yanyang15fc3aee2015-05-22 14:39:35 -04001082 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001083 .major = 6,
1084 .minor = 0,
1085 .rev = 0,
1086 .funcs = &uvd_v6_0_ip_funcs,
1087 },
1088 {
yanyang15fc3aee2015-05-22 14:39:35 -04001089 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001090 .major = 3,
1091 .minor = 0,
1092 .rev = 0,
1093 .funcs = &vce_v3_0_ip_funcs,
1094 },
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001095#if defined(CONFIG_DRM_AMD_ACP)
1096 {
1097 .type = AMD_IP_BLOCK_TYPE_ACP,
1098 .major = 2,
1099 .minor = 2,
1100 .rev = 0,
1101 .funcs = &acp_ip_funcs,
1102 },
1103#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -04001104};
1105
1106int vi_set_ip_blocks(struct amdgpu_device *adev)
1107{
1108 switch (adev->asic_type) {
1109 case CHIP_TOPAZ:
1110 adev->ip_blocks = topaz_ip_blocks;
1111 adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
1112 break;
David Zhang48299f92015-07-08 01:05:16 +08001113 case CHIP_FIJI:
1114 adev->ip_blocks = fiji_ip_blocks;
1115 adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
1116 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001117 case CHIP_TONGA:
1118 adev->ip_blocks = tonga_ip_blocks;
1119 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
1120 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001121 case CHIP_POLARIS11:
1122 case CHIP_POLARIS10:
1123 adev->ip_blocks = polaris11_ip_blocks;
1124 adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks);
Flora Cuic0c1f572015-12-07 18:33:10 +08001125 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001126 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -04001127 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001128 adev->ip_blocks = cz_ip_blocks;
1129 adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
1130 break;
1131 default:
1132 /* FIXME: not supported yet */
1133 return -EINVAL;
1134 }
1135
Alex Deucheraaa36a92015-04-20 17:31:14 -04001136 return 0;
1137}
1138
Samuel Li39bb0c92015-10-08 16:31:43 -04001139#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
1140#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
1141#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
1142
Alex Deucheraaa36a92015-04-20 17:31:14 -04001143static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
1144{
Flora Cuiabdfb852015-11-20 11:40:53 +08001145 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -04001146 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
1147 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001148 else
Flora Cuiabdfb852015-11-20 11:40:53 +08001149 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
1150 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001151}
1152
1153static const struct amdgpu_asic_funcs vi_asic_funcs =
1154{
1155 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -05001156 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001157 .read_register = &vi_read_register,
1158 .reset = &vi_asic_reset,
1159 .set_vga_state = &vi_vga_set_state,
1160 .get_xclk = &vi_get_xclk,
1161 .set_uvd_clocks = &vi_set_uvd_clocks,
1162 .set_vce_clocks = &vi_set_vce_clocks,
Andres Rodriguez048765a2016-06-11 02:51:32 -04001163 .get_virtual_caps = &vi_get_virtual_caps,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001164};
1165
yanyang15fc3aee2015-05-22 14:39:35 -04001166static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001167{
1168 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -04001169 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001170
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001171 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -04001172 adev->smc_rreg = &cz_smc_rreg;
1173 adev->smc_wreg = &cz_smc_wreg;
1174 } else {
1175 adev->smc_rreg = &vi_smc_rreg;
1176 adev->smc_wreg = &vi_smc_wreg;
1177 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001178 adev->pcie_rreg = &vi_pcie_rreg;
1179 adev->pcie_wreg = &vi_pcie_wreg;
1180 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
1181 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
1182 adev->didt_rreg = &vi_didt_rreg;
1183 adev->didt_wreg = &vi_didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001184 adev->gc_cac_rreg = &vi_gc_cac_rreg;
1185 adev->gc_cac_wreg = &vi_gc_cac_wreg;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001186
1187 adev->asic_funcs = &vi_asic_funcs;
1188
yanyang15fc3aee2015-05-22 14:39:35 -04001189 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
1190 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -04001191 smc_enabled = true;
1192
1193 adev->rev_id = vi_get_rev_id(adev);
1194 adev->external_rev_id = 0xFF;
1195 switch (adev->asic_type) {
1196 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001197 adev->cg_flags = 0;
1198 adev->pg_flags = 0;
1199 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001200 break;
David Zhang48299f92015-07-08 01:05:16 +08001201 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -04001202 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1203 AMD_CG_SUPPORT_GFX_MGLS |
1204 AMD_CG_SUPPORT_GFX_RLC_LS |
1205 AMD_CG_SUPPORT_GFX_CP_LS |
1206 AMD_CG_SUPPORT_GFX_CGTS |
1207 AMD_CG_SUPPORT_GFX_CGTS_LS |
1208 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -04001209 AMD_CG_SUPPORT_GFX_CGLS |
1210 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -04001211 AMD_CG_SUPPORT_SDMA_LS |
1212 AMD_CG_SUPPORT_BIF_LS |
1213 AMD_CG_SUPPORT_HDP_MGCG |
1214 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -04001215 AMD_CG_SUPPORT_ROM_MGCG |
1216 AMD_CG_SUPPORT_MC_MGCG |
1217 AMD_CG_SUPPORT_MC_LS;
Flora Cuib6bc28f2015-11-02 21:21:34 +08001218 adev->pg_flags = 0;
1219 adev->external_rev_id = adev->rev_id + 0x3c;
1220 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001221 case CHIP_TONGA:
Tom St Denis5f64e772016-03-23 13:16:13 -04001222 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001223 adev->pg_flags = 0;
1224 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001225 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001226 case CHIP_POLARIS11:
Flora Cuic0c1f572015-12-07 18:33:10 +08001227 adev->cg_flags = 0;
1228 adev->pg_flags = 0;
1229 adev->external_rev_id = adev->rev_id + 0x5A;
1230 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001231 case CHIP_POLARIS10:
Flora Cuic0c1f572015-12-07 18:33:10 +08001232 adev->cg_flags = 0;
1233 adev->pg_flags = 0;
1234 adev->external_rev_id = adev->rev_id + 0x50;
1235 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001236 case CHIP_CARRIZO:
Tom St Denisf0f3a8f2016-05-03 10:36:28 -04001237 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1238 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucher70eced92016-04-07 23:01:48 -04001239 AMD_CG_SUPPORT_GFX_MGLS |
1240 AMD_CG_SUPPORT_GFX_RLC_LS |
1241 AMD_CG_SUPPORT_GFX_CP_LS |
1242 AMD_CG_SUPPORT_GFX_CGTS |
1243 AMD_CG_SUPPORT_GFX_MGLS |
1244 AMD_CG_SUPPORT_GFX_CGTS_LS |
1245 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001246 AMD_CG_SUPPORT_GFX_CGLS |
1247 AMD_CG_SUPPORT_BIF_LS |
1248 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001249 AMD_CG_SUPPORT_HDP_LS |
1250 AMD_CG_SUPPORT_SDMA_MGCG |
1251 AMD_CG_SUPPORT_SDMA_LS;
Tom St Denisf6ade302016-07-28 09:33:56 -04001252 /* rev0 hardware requires workarounds to support PG */
Alex Deucher0fd4af92016-02-04 23:31:32 -05001253 adev->pg_flags = 0;
Tom St Denisf6ade302016-07-28 09:33:56 -04001254 if (adev->rev_id != 0x00) {
1255 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
1256 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denis65b42622016-07-28 09:35:57 -04001257 AMD_PG_SUPPORT_GFX_PIPELINE |
1258 AMD_PG_SUPPORT_UVD;
Tom St Denisf6ade302016-07-28 09:33:56 -04001259 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001260 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001261 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001262 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001263 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1264 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001265 AMD_CG_SUPPORT_GFX_MGLS |
Tom St Denis413cf602016-06-02 08:52:39 -04001266 AMD_CG_SUPPORT_GFX_RLC_LS |
1267 AMD_CG_SUPPORT_GFX_CP_LS |
1268 AMD_CG_SUPPORT_GFX_CGTS |
1269 AMD_CG_SUPPORT_GFX_MGLS |
1270 AMD_CG_SUPPORT_GFX_CGTS_LS |
1271 AMD_CG_SUPPORT_GFX_CGCG |
1272 AMD_CG_SUPPORT_GFX_CGLS |
Alex Deucherb6711d12016-04-13 12:41:50 -04001273 AMD_CG_SUPPORT_BIF_LS |
1274 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001275 AMD_CG_SUPPORT_HDP_LS |
1276 AMD_CG_SUPPORT_SDMA_MGCG |
1277 AMD_CG_SUPPORT_SDMA_LS;
Tom St Deniscde64932016-03-23 13:17:04 -04001278 adev->external_rev_id = adev->rev_id + 0x1;
1279 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001280 default:
1281 /* FIXME: not supported yet */
1282 return -EINVAL;
1283 }
1284
Flora Cuia3d08fa2015-11-02 21:15:55 +08001285 if (amdgpu_smc_load_fw && smc_enabled)
1286 adev->firmware.smu_load = true;
1287
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001288 amdgpu_get_pcie_info(adev);
1289
Alex Deucheraaa36a92015-04-20 17:31:14 -04001290 return 0;
1291}
1292
yanyang15fc3aee2015-05-22 14:39:35 -04001293static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001294{
1295 return 0;
1296}
1297
yanyang15fc3aee2015-05-22 14:39:35 -04001298static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001299{
1300 return 0;
1301}
1302
yanyang15fc3aee2015-05-22 14:39:35 -04001303static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001304{
yanyang15fc3aee2015-05-22 14:39:35 -04001305 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1306
Alex Deucheraaa36a92015-04-20 17:31:14 -04001307 /* move the golden regs per IP block */
1308 vi_init_golden_registers(adev);
1309 /* enable pcie gen2/3 link */
1310 vi_pcie_gen3_enable(adev);
1311 /* enable aspm */
1312 vi_program_aspm(adev);
1313 /* enable the doorbell aperture */
1314 vi_enable_doorbell_aperture(adev, true);
1315
1316 return 0;
1317}
1318
yanyang15fc3aee2015-05-22 14:39:35 -04001319static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001320{
yanyang15fc3aee2015-05-22 14:39:35 -04001321 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1322
Alex Deucheraaa36a92015-04-20 17:31:14 -04001323 /* enable the doorbell aperture */
1324 vi_enable_doorbell_aperture(adev, false);
1325
1326 return 0;
1327}
1328
yanyang15fc3aee2015-05-22 14:39:35 -04001329static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001330{
yanyang15fc3aee2015-05-22 14:39:35 -04001331 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1332
Alex Deucheraaa36a92015-04-20 17:31:14 -04001333 return vi_common_hw_fini(adev);
1334}
1335
yanyang15fc3aee2015-05-22 14:39:35 -04001336static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001337{
yanyang15fc3aee2015-05-22 14:39:35 -04001338 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1339
Alex Deucheraaa36a92015-04-20 17:31:14 -04001340 return vi_common_hw_init(adev);
1341}
1342
yanyang15fc3aee2015-05-22 14:39:35 -04001343static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001344{
1345 return true;
1346}
1347
yanyang15fc3aee2015-05-22 14:39:35 -04001348static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001349{
1350 return 0;
1351}
1352
yanyang15fc3aee2015-05-22 14:39:35 -04001353static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001354{
1355 return 0;
1356}
1357
Alex Deucher76f10b92016-04-08 01:37:44 -04001358static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1359 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001360{
1361 uint32_t temp, data;
1362
1363 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1364
Alex Deucherc90766c2016-04-08 00:52:58 -04001365 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001366 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1367 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1368 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1369 else
1370 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1371 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1372 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1373
1374 if (temp != data)
1375 WREG32_PCIE(ixPCIE_CNTL2, data);
1376}
1377
Alex Deucher76f10b92016-04-08 01:37:44 -04001378static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1379 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001380{
1381 uint32_t temp, data;
1382
1383 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1384
Alex Deucherc90766c2016-04-08 00:52:58 -04001385 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001386 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1387 else
1388 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1389
1390 if (temp != data)
1391 WREG32(mmHDP_HOST_PATH_CNTL, data);
1392}
1393
Alex Deucher76f10b92016-04-08 01:37:44 -04001394static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1395 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001396{
1397 uint32_t temp, data;
1398
1399 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1400
Alex Deucherc90766c2016-04-08 00:52:58 -04001401 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001402 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1403 else
1404 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1405
1406 if (temp != data)
1407 WREG32(mmHDP_MEM_POWER_LS, data);
1408}
1409
Alex Deucher76f10b92016-04-08 01:37:44 -04001410static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1411 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001412{
1413 uint32_t temp, data;
1414
1415 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1416
Alex Deucherc90766c2016-04-08 00:52:58 -04001417 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001418 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1419 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1420 else
1421 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1422 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1423
1424 if (temp != data)
1425 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1426}
1427
yanyang15fc3aee2015-05-22 14:39:35 -04001428static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001429 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001430{
Eric Huang6cec2652015-11-12 16:59:47 -05001431 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1432
1433 switch (adev->asic_type) {
1434 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001435 vi_update_bif_medium_grain_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001436 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001437 vi_update_hdp_medium_grain_clock_gating(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001438 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001439 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001440 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001441 vi_update_rom_medium_grain_clock_gating(adev,
1442 state == AMD_CG_STATE_GATE ? true : false);
1443 break;
1444 case CHIP_CARRIZO:
1445 case CHIP_STONEY:
1446 vi_update_bif_medium_grain_light_sleep(adev,
1447 state == AMD_CG_STATE_GATE ? true : false);
1448 vi_update_hdp_medium_grain_clock_gating(adev,
1449 state == AMD_CG_STATE_GATE ? true : false);
1450 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001451 state == AMD_CG_STATE_GATE ? true : false);
1452 break;
1453 default:
1454 break;
1455 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001456 return 0;
1457}
1458
yanyang15fc3aee2015-05-22 14:39:35 -04001459static int vi_common_set_powergating_state(void *handle,
1460 enum amd_powergating_state state)
1461{
1462 return 0;
1463}
1464
1465const struct amd_ip_funcs vi_common_ip_funcs = {
Tom St Denis88a907d2016-05-04 14:28:35 -04001466 .name = "vi_common",
Alex Deucheraaa36a92015-04-20 17:31:14 -04001467 .early_init = vi_common_early_init,
1468 .late_init = NULL,
1469 .sw_init = vi_common_sw_init,
1470 .sw_fini = vi_common_sw_fini,
1471 .hw_init = vi_common_hw_init,
1472 .hw_fini = vi_common_hw_fini,
1473 .suspend = vi_common_suspend,
1474 .resume = vi_common_resume,
1475 .is_idle = vi_common_is_idle,
1476 .wait_for_idle = vi_common_wait_for_idle,
1477 .soft_reset = vi_common_soft_reset,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001478 .set_clockgating_state = vi_common_set_clockgating_state,
1479 .set_powergating_state = vi_common_set_powergating_state,
1480};
1481