blob: ff78b5a36143e50e7184f264394e88a06a98c473 [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
Emily Denge9ed3a62016-08-08 11:36:45 +080080#include "dce_virtual.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040081
Flora Cuif8951062016-03-18 19:07:55 +080082MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
83MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
84MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
85MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
86
Alex Deucheraaa36a92015-04-20 17:31:14 -040087/*
88 * Indirect registers accessor
89 */
90static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
91{
92 unsigned long flags;
93 u32 r;
94
95 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
96 WREG32(mmPCIE_INDEX, reg);
97 (void)RREG32(mmPCIE_INDEX);
98 r = RREG32(mmPCIE_DATA);
99 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
100 return r;
101}
102
103static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
104{
105 unsigned long flags;
106
107 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
108 WREG32(mmPCIE_INDEX, reg);
109 (void)RREG32(mmPCIE_INDEX);
110 WREG32(mmPCIE_DATA, v);
111 (void)RREG32(mmPCIE_DATA);
112 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
113}
114
115static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
116{
117 unsigned long flags;
118 u32 r;
119
120 spin_lock_irqsave(&adev->smc_idx_lock, flags);
121 WREG32(mmSMC_IND_INDEX_0, (reg));
122 r = RREG32(mmSMC_IND_DATA_0);
123 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
124 return r;
125}
126
127static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
128{
129 unsigned long flags;
130
131 spin_lock_irqsave(&adev->smc_idx_lock, flags);
132 WREG32(mmSMC_IND_INDEX_0, (reg));
133 WREG32(mmSMC_IND_DATA_0, (v));
134 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
135}
136
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400137/* smu_8_0_d.h */
138#define mmMP0PUB_IND_INDEX 0x180
139#define mmMP0PUB_IND_DATA 0x181
140
141static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
142{
143 unsigned long flags;
144 u32 r;
145
146 spin_lock_irqsave(&adev->smc_idx_lock, flags);
147 WREG32(mmMP0PUB_IND_INDEX, (reg));
148 r = RREG32(mmMP0PUB_IND_DATA);
149 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
150 return r;
151}
152
153static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
154{
155 unsigned long flags;
156
157 spin_lock_irqsave(&adev->smc_idx_lock, flags);
158 WREG32(mmMP0PUB_IND_INDEX, (reg));
159 WREG32(mmMP0PUB_IND_DATA, (v));
160 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
161}
162
Alex Deucheraaa36a92015-04-20 17:31:14 -0400163static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
164{
165 unsigned long flags;
166 u32 r;
167
168 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
169 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
170 r = RREG32(mmUVD_CTX_DATA);
171 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
172 return r;
173}
174
175static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
176{
177 unsigned long flags;
178
179 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
180 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
181 WREG32(mmUVD_CTX_DATA, (v));
182 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
183}
184
185static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
186{
187 unsigned long flags;
188 u32 r;
189
190 spin_lock_irqsave(&adev->didt_idx_lock, flags);
191 WREG32(mmDIDT_IND_INDEX, (reg));
192 r = RREG32(mmDIDT_IND_DATA);
193 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
194 return r;
195}
196
197static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
198{
199 unsigned long flags;
200
201 spin_lock_irqsave(&adev->didt_idx_lock, flags);
202 WREG32(mmDIDT_IND_INDEX, (reg));
203 WREG32(mmDIDT_IND_DATA, (v));
204 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
205}
206
Rex Zhuccdbb202016-06-08 12:47:41 +0800207static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
208{
209 unsigned long flags;
210 u32 r;
211
212 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
213 WREG32(mmGC_CAC_IND_INDEX, (reg));
214 r = RREG32(mmGC_CAC_IND_DATA);
215 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
216 return r;
217}
218
219static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
220{
221 unsigned long flags;
222
223 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
224 WREG32(mmGC_CAC_IND_INDEX, (reg));
225 WREG32(mmGC_CAC_IND_DATA, (v));
226 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
227}
228
229
Alex Deucheraaa36a92015-04-20 17:31:14 -0400230static const u32 tonga_mgcg_cgcg_init[] =
231{
232 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
233 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
234 mmPCIE_DATA, 0x000f0000, 0x00000000,
235 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
236 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400237 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
238 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
239};
240
David Zhang48299f92015-07-08 01:05:16 +0800241static const u32 fiji_mgcg_cgcg_init[] =
242{
243 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
244 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
245 mmPCIE_DATA, 0x000f0000, 0x00000000,
246 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
247 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
248 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
249 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
250};
251
Alex Deucheraaa36a92015-04-20 17:31:14 -0400252static const u32 iceland_mgcg_cgcg_init[] =
253{
254 mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
255 mmPCIE_DATA, 0x000f0000, 0x00000000,
256 mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
257 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
258 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
259};
260
261static const u32 cz_mgcg_cgcg_init[] =
262{
263 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
264 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
265 mmPCIE_DATA, 0x000f0000, 0x00000000,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400266 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
267 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
268};
269
Samuel Li39bb0c92015-10-08 16:31:43 -0400270static const u32 stoney_mgcg_cgcg_init[] =
271{
272 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
273 mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
274 mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
275};
276
Alex Deucheraaa36a92015-04-20 17:31:14 -0400277static void vi_init_golden_registers(struct amdgpu_device *adev)
278{
279 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
280 mutex_lock(&adev->grbm_idx_mutex);
281
282 switch (adev->asic_type) {
283 case CHIP_TOPAZ:
284 amdgpu_program_register_sequence(adev,
285 iceland_mgcg_cgcg_init,
286 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
287 break;
David Zhang48299f92015-07-08 01:05:16 +0800288 case CHIP_FIJI:
289 amdgpu_program_register_sequence(adev,
290 fiji_mgcg_cgcg_init,
291 (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
292 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400293 case CHIP_TONGA:
294 amdgpu_program_register_sequence(adev,
295 tonga_mgcg_cgcg_init,
296 (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
297 break;
298 case CHIP_CARRIZO:
299 amdgpu_program_register_sequence(adev,
300 cz_mgcg_cgcg_init,
301 (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
302 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400303 case CHIP_STONEY:
304 amdgpu_program_register_sequence(adev,
305 stoney_mgcg_cgcg_init,
306 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
307 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400308 case CHIP_POLARIS11:
309 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400310 default:
311 break;
312 }
313 mutex_unlock(&adev->grbm_idx_mutex);
314}
315
316/**
317 * vi_get_xclk - get the xclk
318 *
319 * @adev: amdgpu_device pointer
320 *
321 * Returns the reference clock used by the gfx engine
322 * (VI).
323 */
324static u32 vi_get_xclk(struct amdgpu_device *adev)
325{
326 u32 reference_clock = adev->clock.spll.reference_freq;
327 u32 tmp;
328
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800329 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400330 return reference_clock;
331
332 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
333 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
334 return 1000;
335
336 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
337 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
338 return reference_clock / 4;
339
340 return reference_clock;
341}
342
343/**
344 * vi_srbm_select - select specific register instances
345 *
346 * @adev: amdgpu_device pointer
347 * @me: selected ME (micro engine)
348 * @pipe: pipe
349 * @queue: queue
350 * @vmid: VMID
351 *
352 * Switches the currently active registers instances. Some
353 * registers are instanced per VMID, others are instanced per
354 * me/pipe/queue combination.
355 */
356void vi_srbm_select(struct amdgpu_device *adev,
357 u32 me, u32 pipe, u32 queue, u32 vmid)
358{
359 u32 srbm_gfx_cntl = 0;
360 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
361 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
362 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
363 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
364 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
365}
366
367static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
368{
369 /* todo */
370}
371
372static bool vi_read_disabled_bios(struct amdgpu_device *adev)
373{
374 u32 bus_cntl;
375 u32 d1vga_control = 0;
376 u32 d2vga_control = 0;
377 u32 vga_render_control = 0;
378 u32 rom_cntl;
379 bool r;
380
381 bus_cntl = RREG32(mmBUS_CNTL);
382 if (adev->mode_info.num_crtc) {
383 d1vga_control = RREG32(mmD1VGA_CONTROL);
384 d2vga_control = RREG32(mmD2VGA_CONTROL);
385 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
386 }
387 rom_cntl = RREG32_SMC(ixROM_CNTL);
388
389 /* enable the rom */
390 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
391 if (adev->mode_info.num_crtc) {
392 /* Disable VGA mode */
393 WREG32(mmD1VGA_CONTROL,
394 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
395 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
396 WREG32(mmD2VGA_CONTROL,
397 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
398 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
399 WREG32(mmVGA_RENDER_CONTROL,
400 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
401 }
402 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
403
404 r = amdgpu_read_bios(adev);
405
406 /* restore regs */
407 WREG32(mmBUS_CNTL, bus_cntl);
408 if (adev->mode_info.num_crtc) {
409 WREG32(mmD1VGA_CONTROL, d1vga_control);
410 WREG32(mmD2VGA_CONTROL, d2vga_control);
411 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
412 }
413 WREG32_SMC(ixROM_CNTL, rom_cntl);
414 return r;
415}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500416
417static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
418 u8 *bios, u32 length_bytes)
419{
420 u32 *dw_ptr;
421 unsigned long flags;
422 u32 i, length_dw;
423
424 if (bios == NULL)
425 return false;
426 if (length_bytes == 0)
427 return false;
428 /* APU vbios image is part of sbios image */
429 if (adev->flags & AMD_IS_APU)
430 return false;
431
432 dw_ptr = (u32 *)bios;
433 length_dw = ALIGN(length_bytes, 4) / 4;
434 /* take the smc lock since we are using the smc index */
435 spin_lock_irqsave(&adev->smc_idx_lock, flags);
436 /* set rom index to 0 */
437 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
438 WREG32(mmSMC_IND_DATA_0, 0);
439 /* set index to data for continous read */
440 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
441 for (i = 0; i < length_dw; i++)
442 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
443 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
444
445 return true;
446}
447
Andres Rodriguez048765a2016-06-11 02:51:32 -0400448static u32 vi_get_virtual_caps(struct amdgpu_device *adev)
449{
450 u32 caps = 0;
451 u32 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
452
453 if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE))
454 caps |= AMDGPU_VIRT_CAPS_SRIOV_EN;
455
456 if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER))
457 caps |= AMDGPU_VIRT_CAPS_IS_VF;
458
459 return caps;
460}
461
Nils Wallméniuseca22402016-03-19 16:12:17 +0100462static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400463 {mmGB_MACROTILE_MODE7, true},
464};
465
Nils Wallméniuseca22402016-03-19 16:12:17 +0100466static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400467 {mmGB_TILE_MODE7, true},
468 {mmGB_TILE_MODE12, true},
469 {mmGB_TILE_MODE17, true},
470 {mmGB_TILE_MODE23, true},
471 {mmGB_MACROTILE_MODE7, true},
472};
473
Nils Wallméniuseca22402016-03-19 16:12:17 +0100474static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400475 {mmGRBM_STATUS, false},
Marek Olšákc7890fe2015-07-11 12:08:46 +0200476 {mmGRBM_STATUS2, false},
477 {mmGRBM_STATUS_SE0, false},
478 {mmGRBM_STATUS_SE1, false},
479 {mmGRBM_STATUS_SE2, false},
480 {mmGRBM_STATUS_SE3, false},
481 {mmSRBM_STATUS, false},
482 {mmSRBM_STATUS2, false},
483 {mmSRBM_STATUS3, false},
484 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
485 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
486 {mmCP_STAT, false},
487 {mmCP_STALLED_STAT1, false},
488 {mmCP_STALLED_STAT2, false},
489 {mmCP_STALLED_STAT3, false},
490 {mmCP_CPF_BUSY_STAT, false},
491 {mmCP_CPF_STALLED_STAT1, false},
492 {mmCP_CPF_STATUS, false},
493 {mmCP_CPC_BUSY_STAT, false},
494 {mmCP_CPC_STALLED_STAT1, false},
495 {mmCP_CPC_STATUS, false},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400496 {mmGB_ADDR_CONFIG, false},
497 {mmMC_ARB_RAMCFG, false},
498 {mmGB_TILE_MODE0, false},
499 {mmGB_TILE_MODE1, false},
500 {mmGB_TILE_MODE2, false},
501 {mmGB_TILE_MODE3, false},
502 {mmGB_TILE_MODE4, false},
503 {mmGB_TILE_MODE5, false},
504 {mmGB_TILE_MODE6, false},
505 {mmGB_TILE_MODE7, false},
506 {mmGB_TILE_MODE8, false},
507 {mmGB_TILE_MODE9, false},
508 {mmGB_TILE_MODE10, false},
509 {mmGB_TILE_MODE11, false},
510 {mmGB_TILE_MODE12, false},
511 {mmGB_TILE_MODE13, false},
512 {mmGB_TILE_MODE14, false},
513 {mmGB_TILE_MODE15, false},
514 {mmGB_TILE_MODE16, false},
515 {mmGB_TILE_MODE17, false},
516 {mmGB_TILE_MODE18, false},
517 {mmGB_TILE_MODE19, false},
518 {mmGB_TILE_MODE20, false},
519 {mmGB_TILE_MODE21, false},
520 {mmGB_TILE_MODE22, false},
521 {mmGB_TILE_MODE23, false},
522 {mmGB_TILE_MODE24, false},
523 {mmGB_TILE_MODE25, false},
524 {mmGB_TILE_MODE26, false},
525 {mmGB_TILE_MODE27, false},
526 {mmGB_TILE_MODE28, false},
527 {mmGB_TILE_MODE29, false},
528 {mmGB_TILE_MODE30, false},
529 {mmGB_TILE_MODE31, false},
530 {mmGB_MACROTILE_MODE0, false},
531 {mmGB_MACROTILE_MODE1, false},
532 {mmGB_MACROTILE_MODE2, false},
533 {mmGB_MACROTILE_MODE3, false},
534 {mmGB_MACROTILE_MODE4, false},
535 {mmGB_MACROTILE_MODE5, false},
536 {mmGB_MACROTILE_MODE6, false},
537 {mmGB_MACROTILE_MODE7, false},
538 {mmGB_MACROTILE_MODE8, false},
539 {mmGB_MACROTILE_MODE9, false},
540 {mmGB_MACROTILE_MODE10, false},
541 {mmGB_MACROTILE_MODE11, false},
542 {mmGB_MACROTILE_MODE12, false},
543 {mmGB_MACROTILE_MODE13, false},
544 {mmGB_MACROTILE_MODE14, false},
545 {mmGB_MACROTILE_MODE15, false},
546 {mmCC_RB_BACKEND_DISABLE, false, true},
547 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
548 {mmGB_BACKEND_MAP, false, false},
549 {mmPA_SC_RASTER_CONFIG, false, true},
550 {mmPA_SC_RASTER_CONFIG_1, false, true},
551};
552
553static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
554 u32 sh_num, u32 reg_offset)
555{
556 uint32_t val;
557
558 mutex_lock(&adev->grbm_idx_mutex);
559 if (se_num != 0xffffffff || sh_num != 0xffffffff)
Tom St Denis9559ef52016-06-28 10:26:48 -0400560 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400561
562 val = RREG32(reg_offset);
563
564 if (se_num != 0xffffffff || sh_num != 0xffffffff)
Tom St Denis9559ef52016-06-28 10:26:48 -0400565 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400566 mutex_unlock(&adev->grbm_idx_mutex);
567 return val;
568}
569
570static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
571 u32 sh_num, u32 reg_offset, u32 *value)
572{
Nils Wallméniuseca22402016-03-19 16:12:17 +0100573 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
574 const struct amdgpu_allowed_register_entry *asic_register_entry;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400575 uint32_t size, i;
576
577 *value = 0;
578 switch (adev->asic_type) {
579 case CHIP_TOPAZ:
580 asic_register_table = tonga_allowed_read_registers;
581 size = ARRAY_SIZE(tonga_allowed_read_registers);
582 break;
David Zhang48299f92015-07-08 01:05:16 +0800583 case CHIP_FIJI:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400584 case CHIP_TONGA:
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400585 case CHIP_POLARIS11:
586 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400587 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -0400588 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400589 asic_register_table = cz_allowed_read_registers;
590 size = ARRAY_SIZE(cz_allowed_read_registers);
591 break;
592 default:
593 return -EINVAL;
594 }
595
596 if (asic_register_table) {
597 for (i = 0; i < size; i++) {
598 asic_register_entry = asic_register_table + i;
599 if (reg_offset != asic_register_entry->reg_offset)
600 continue;
601 if (!asic_register_entry->untouched)
602 *value = asic_register_entry->grbm_indexed ?
603 vi_read_indexed_register(adev, se_num,
604 sh_num, reg_offset) :
605 RREG32(reg_offset);
606 return 0;
607 }
608 }
609
610 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
611 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
612 continue;
613
614 if (!vi_allowed_read_registers[i].untouched)
615 *value = vi_allowed_read_registers[i].grbm_indexed ?
616 vi_read_indexed_register(adev, se_num,
617 sh_num, reg_offset) :
618 RREG32(reg_offset);
619 return 0;
620 }
621 return -EINVAL;
622}
623
Chunming Zhou89a31822016-06-06 13:06:45 +0800624static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400625{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400626 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400627
628 dev_info(adev->dev, "GPU pci config reset\n");
629
Alex Deucheraaa36a92015-04-20 17:31:14 -0400630 /* disable BM */
631 pci_clear_master(adev->pdev);
632 /* reset */
633 amdgpu_pci_config_reset(adev);
634
635 udelay(100);
636
637 /* wait for asic to come out of reset */
638 for (i = 0; i < adev->usec_timeout; i++) {
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800639 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
640 /* enable BM */
641 pci_set_master(adev->pdev);
Chunming Zhou89a31822016-06-06 13:06:45 +0800642 return 0;
Chunming Zhoub314f9a2016-06-06 13:50:18 +0800643 }
Alex Deucheraaa36a92015-04-20 17:31:14 -0400644 udelay(1);
645 }
Chunming Zhou89a31822016-06-06 13:06:45 +0800646 return -EINVAL;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400647}
648
649static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
650{
651 u32 tmp = RREG32(mmBIOS_SCRATCH_3);
652
653 if (hung)
654 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
655 else
656 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
657
658 WREG32(mmBIOS_SCRATCH_3, tmp);
659}
660
661/**
662 * vi_asic_reset - soft reset GPU
663 *
664 * @adev: amdgpu_device pointer
665 *
666 * Look up which blocks are hung and attempt
667 * to reset them.
668 * Returns 0 for success.
669 */
670static int vi_asic_reset(struct amdgpu_device *adev)
671{
Chunming Zhou89a31822016-06-06 13:06:45 +0800672 int r;
673
Alex Deuchera2c5c692015-10-14 09:39:37 -0400674 vi_set_bios_scratch_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400675
Chunming Zhou89a31822016-06-06 13:06:45 +0800676 r = vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400677
Alex Deuchera2c5c692015-10-14 09:39:37 -0400678 vi_set_bios_scratch_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400679
Chunming Zhou89a31822016-06-06 13:06:45 +0800680 return r;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400681}
682
683static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
684 u32 cntl_reg, u32 status_reg)
685{
686 int r, i;
687 struct atom_clock_dividers dividers;
688 uint32_t tmp;
689
690 r = amdgpu_atombios_get_clock_dividers(adev,
691 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
692 clock, false, &dividers);
693 if (r)
694 return r;
695
696 tmp = RREG32_SMC(cntl_reg);
697 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
698 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
699 tmp |= dividers.post_divider;
700 WREG32_SMC(cntl_reg, tmp);
701
702 for (i = 0; i < 100; i++) {
703 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
704 break;
705 mdelay(10);
706 }
707 if (i == 100)
708 return -ETIMEDOUT;
709
710 return 0;
711}
712
713static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
714{
715 int r;
716
717 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
718 if (r)
719 return r;
720
721 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
722
723 return 0;
724}
725
726static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
727{
728 /* todo */
729
730 return 0;
731}
732
733static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
734{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400735 if (pci_is_root_bus(adev->pdev->bus))
736 return;
737
Alex Deucheraaa36a92015-04-20 17:31:14 -0400738 if (amdgpu_pcie_gen2 == 0)
739 return;
740
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800741 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400742 return;
743
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500744 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
745 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400746 return;
747
748 /* todo */
749}
750
751static void vi_program_aspm(struct amdgpu_device *adev)
752{
753
754 if (amdgpu_aspm == 0)
755 return;
756
757 /* todo */
758}
759
760static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
761 bool enable)
762{
763 u32 tmp;
764
765 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800766 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400767 return;
768
769 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
770 if (enable)
771 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
772 else
773 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
774
775 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
776}
777
778/* topaz has no DCE, UVD, VCE */
779static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
780{
781 /* ORDER MATTERS! */
782 {
yanyang15fc3aee2015-05-22 14:39:35 -0400783 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400784 .major = 2,
785 .minor = 0,
786 .rev = 0,
787 .funcs = &vi_common_ip_funcs,
788 },
789 {
yanyang15fc3aee2015-05-22 14:39:35 -0400790 .type = AMD_IP_BLOCK_TYPE_GMC,
Ken Wang429c45d2016-02-03 19:16:54 +0800791 .major = 7,
792 .minor = 4,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400793 .rev = 0,
Ken Wang429c45d2016-02-03 19:16:54 +0800794 .funcs = &gmc_v7_0_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400795 },
796 {
yanyang15fc3aee2015-05-22 14:39:35 -0400797 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400798 .major = 2,
799 .minor = 4,
800 .rev = 0,
801 .funcs = &iceland_ih_ip_funcs,
802 },
803 {
yanyang15fc3aee2015-05-22 14:39:35 -0400804 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400805 .major = 7,
806 .minor = 1,
807 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500808 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400809 },
810 {
yanyang15fc3aee2015-05-22 14:39:35 -0400811 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400812 .major = 8,
813 .minor = 0,
814 .rev = 0,
815 .funcs = &gfx_v8_0_ip_funcs,
816 },
817 {
yanyang15fc3aee2015-05-22 14:39:35 -0400818 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400819 .major = 2,
820 .minor = 4,
821 .rev = 0,
822 .funcs = &sdma_v2_4_ip_funcs,
823 },
824};
825
826static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
827{
828 /* ORDER MATTERS! */
829 {
yanyang15fc3aee2015-05-22 14:39:35 -0400830 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400831 .major = 2,
832 .minor = 0,
833 .rev = 0,
834 .funcs = &vi_common_ip_funcs,
835 },
836 {
yanyang15fc3aee2015-05-22 14:39:35 -0400837 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400838 .major = 8,
839 .minor = 0,
840 .rev = 0,
841 .funcs = &gmc_v8_0_ip_funcs,
842 },
843 {
yanyang15fc3aee2015-05-22 14:39:35 -0400844 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400845 .major = 3,
846 .minor = 0,
847 .rev = 0,
848 .funcs = &tonga_ih_ip_funcs,
849 },
850 {
yanyang15fc3aee2015-05-22 14:39:35 -0400851 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400852 .major = 7,
853 .minor = 1,
854 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500855 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400856 },
857 {
yanyang15fc3aee2015-05-22 14:39:35 -0400858 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400859 .major = 10,
860 .minor = 0,
861 .rev = 0,
862 .funcs = &dce_v10_0_ip_funcs,
863 },
864 {
yanyang15fc3aee2015-05-22 14:39:35 -0400865 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400866 .major = 8,
867 .minor = 0,
868 .rev = 0,
869 .funcs = &gfx_v8_0_ip_funcs,
870 },
871 {
yanyang15fc3aee2015-05-22 14:39:35 -0400872 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400873 .major = 3,
874 .minor = 0,
875 .rev = 0,
876 .funcs = &sdma_v3_0_ip_funcs,
877 },
878 {
yanyang15fc3aee2015-05-22 14:39:35 -0400879 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400880 .major = 5,
881 .minor = 0,
882 .rev = 0,
883 .funcs = &uvd_v5_0_ip_funcs,
884 },
885 {
yanyang15fc3aee2015-05-22 14:39:35 -0400886 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400887 .major = 3,
888 .minor = 0,
889 .rev = 0,
890 .funcs = &vce_v3_0_ip_funcs,
891 },
892};
893
Emily Denge9ed3a62016-08-08 11:36:45 +0800894static const struct amdgpu_ip_block_version tonga_ip_blocks_vd[] =
895{
896 /* ORDER MATTERS! */
897 {
898 .type = AMD_IP_BLOCK_TYPE_COMMON,
899 .major = 2,
900 .minor = 0,
901 .rev = 0,
902 .funcs = &vi_common_ip_funcs,
903 },
904 {
905 .type = AMD_IP_BLOCK_TYPE_GMC,
906 .major = 8,
907 .minor = 0,
908 .rev = 0,
909 .funcs = &gmc_v8_0_ip_funcs,
910 },
911 {
912 .type = AMD_IP_BLOCK_TYPE_IH,
913 .major = 3,
914 .minor = 0,
915 .rev = 0,
916 .funcs = &tonga_ih_ip_funcs,
917 },
918 {
919 .type = AMD_IP_BLOCK_TYPE_SMC,
920 .major = 7,
921 .minor = 1,
922 .rev = 0,
923 .funcs = &amdgpu_pp_ip_funcs,
924 },
925 {
926 .type = AMD_IP_BLOCK_TYPE_DCE,
927 .major = 10,
928 .minor = 0,
929 .rev = 0,
930 .funcs = &dce_virtual_ip_funcs,
931 },
932 {
933 .type = AMD_IP_BLOCK_TYPE_GFX,
934 .major = 8,
935 .minor = 0,
936 .rev = 0,
937 .funcs = &gfx_v8_0_ip_funcs,
938 },
939 {
940 .type = AMD_IP_BLOCK_TYPE_SDMA,
941 .major = 3,
942 .minor = 0,
943 .rev = 0,
944 .funcs = &sdma_v3_0_ip_funcs,
945 },
946 {
947 .type = AMD_IP_BLOCK_TYPE_UVD,
948 .major = 5,
949 .minor = 0,
950 .rev = 0,
951 .funcs = &uvd_v5_0_ip_funcs,
952 },
953 {
954 .type = AMD_IP_BLOCK_TYPE_VCE,
955 .major = 3,
956 .minor = 0,
957 .rev = 0,
958 .funcs = &vce_v3_0_ip_funcs,
959 },
960};
961
David Zhang48299f92015-07-08 01:05:16 +0800962static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
963{
964 /* ORDER MATTERS! */
965 {
966 .type = AMD_IP_BLOCK_TYPE_COMMON,
967 .major = 2,
968 .minor = 0,
969 .rev = 0,
970 .funcs = &vi_common_ip_funcs,
David Zhang127a2622015-07-08 01:11:52 +0800971 },
972 {
973 .type = AMD_IP_BLOCK_TYPE_GMC,
974 .major = 8,
975 .minor = 5,
976 .rev = 0,
977 .funcs = &gmc_v8_0_ip_funcs,
978 },
David Zhangaa8a3b52015-07-08 21:40:31 +0800979 {
980 .type = AMD_IP_BLOCK_TYPE_IH,
981 .major = 3,
982 .minor = 0,
983 .rev = 0,
984 .funcs = &tonga_ih_ip_funcs,
985 },
David Zhang8e711e1a2015-07-08 01:23:25 +0800986 {
987 .type = AMD_IP_BLOCK_TYPE_SMC,
988 .major = 7,
989 .minor = 1,
990 .rev = 0,
Eric Huang899fa4c2015-09-29 14:58:53 -0400991 .funcs = &amdgpu_pp_ip_funcs,
David Zhang8e711e1a2015-07-08 01:23:25 +0800992 },
David Zhang84390862015-07-08 01:28:20 +0800993 {
994 .type = AMD_IP_BLOCK_TYPE_DCE,
995 .major = 10,
996 .minor = 1,
997 .rev = 0,
998 .funcs = &dce_v10_0_ip_funcs,
999 },
David Zhangaf15a2d2015-07-30 19:42:11 -04001000 {
1001 .type = AMD_IP_BLOCK_TYPE_GFX,
1002 .major = 8,
1003 .minor = 0,
1004 .rev = 0,
1005 .funcs = &gfx_v8_0_ip_funcs,
1006 },
David Zhang1a5bbb62015-07-08 17:29:27 +08001007 {
1008 .type = AMD_IP_BLOCK_TYPE_SDMA,
1009 .major = 3,
1010 .minor = 0,
1011 .rev = 0,
1012 .funcs = &sdma_v3_0_ip_funcs,
1013 },
David Zhang974ee3d2015-07-08 17:32:15 +08001014 {
1015 .type = AMD_IP_BLOCK_TYPE_UVD,
1016 .major = 6,
1017 .minor = 0,
1018 .rev = 0,
1019 .funcs = &uvd_v6_0_ip_funcs,
1020 },
Alex Deucher188a9bc2015-07-27 14:24:14 -04001021 {
1022 .type = AMD_IP_BLOCK_TYPE_VCE,
1023 .major = 3,
1024 .minor = 0,
1025 .rev = 0,
1026 .funcs = &vce_v3_0_ip_funcs,
1027 },
David Zhang48299f92015-07-08 01:05:16 +08001028};
1029
Emily Denge9ed3a62016-08-08 11:36:45 +08001030static const struct amdgpu_ip_block_version fiji_ip_blocks_vd[] =
1031{
1032 /* ORDER MATTERS! */
1033 {
1034 .type = AMD_IP_BLOCK_TYPE_COMMON,
1035 .major = 2,
1036 .minor = 0,
1037 .rev = 0,
1038 .funcs = &vi_common_ip_funcs,
1039 },
1040 {
1041 .type = AMD_IP_BLOCK_TYPE_GMC,
1042 .major = 8,
1043 .minor = 5,
1044 .rev = 0,
1045 .funcs = &gmc_v8_0_ip_funcs,
1046 },
1047 {
1048 .type = AMD_IP_BLOCK_TYPE_IH,
1049 .major = 3,
1050 .minor = 0,
1051 .rev = 0,
1052 .funcs = &tonga_ih_ip_funcs,
1053 },
1054 {
1055 .type = AMD_IP_BLOCK_TYPE_SMC,
1056 .major = 7,
1057 .minor = 1,
1058 .rev = 0,
1059 .funcs = &amdgpu_pp_ip_funcs,
1060 },
1061 {
1062 .type = AMD_IP_BLOCK_TYPE_DCE,
1063 .major = 10,
1064 .minor = 1,
1065 .rev = 0,
1066 .funcs = &dce_virtual_ip_funcs,
1067 },
1068 {
1069 .type = AMD_IP_BLOCK_TYPE_GFX,
1070 .major = 8,
1071 .minor = 0,
1072 .rev = 0,
1073 .funcs = &gfx_v8_0_ip_funcs,
1074 },
1075 {
1076 .type = AMD_IP_BLOCK_TYPE_SDMA,
1077 .major = 3,
1078 .minor = 0,
1079 .rev = 0,
1080 .funcs = &sdma_v3_0_ip_funcs,
1081 },
1082 {
1083 .type = AMD_IP_BLOCK_TYPE_UVD,
1084 .major = 6,
1085 .minor = 0,
1086 .rev = 0,
1087 .funcs = &uvd_v6_0_ip_funcs,
1088 },
1089 {
1090 .type = AMD_IP_BLOCK_TYPE_VCE,
1091 .major = 3,
1092 .minor = 0,
1093 .rev = 0,
1094 .funcs = &vce_v3_0_ip_funcs,
1095 },
1096};
1097
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001098static const struct amdgpu_ip_block_version polaris11_ip_blocks[] =
Flora Cuic0c1f572015-12-07 18:33:10 +08001099{
1100 /* ORDER MATTERS! */
1101 {
1102 .type = AMD_IP_BLOCK_TYPE_COMMON,
1103 .major = 2,
1104 .minor = 0,
1105 .rev = 0,
1106 .funcs = &vi_common_ip_funcs,
1107 },
1108 {
1109 .type = AMD_IP_BLOCK_TYPE_GMC,
1110 .major = 8,
1111 .minor = 1,
1112 .rev = 0,
1113 .funcs = &gmc_v8_0_ip_funcs,
1114 },
1115 {
1116 .type = AMD_IP_BLOCK_TYPE_IH,
1117 .major = 3,
1118 .minor = 1,
1119 .rev = 0,
1120 .funcs = &tonga_ih_ip_funcs,
1121 },
1122 {
1123 .type = AMD_IP_BLOCK_TYPE_SMC,
1124 .major = 7,
1125 .minor = 2,
1126 .rev = 0,
1127 .funcs = &amdgpu_pp_ip_funcs,
1128 },
1129 {
1130 .type = AMD_IP_BLOCK_TYPE_DCE,
1131 .major = 11,
1132 .minor = 2,
1133 .rev = 0,
1134 .funcs = &dce_v11_0_ip_funcs,
1135 },
1136 {
1137 .type = AMD_IP_BLOCK_TYPE_GFX,
1138 .major = 8,
1139 .minor = 0,
1140 .rev = 0,
1141 .funcs = &gfx_v8_0_ip_funcs,
1142 },
1143 {
1144 .type = AMD_IP_BLOCK_TYPE_SDMA,
1145 .major = 3,
1146 .minor = 1,
1147 .rev = 0,
1148 .funcs = &sdma_v3_0_ip_funcs,
1149 },
1150 {
1151 .type = AMD_IP_BLOCK_TYPE_UVD,
1152 .major = 6,
1153 .minor = 3,
1154 .rev = 0,
1155 .funcs = &uvd_v6_0_ip_funcs,
1156 },
1157 {
1158 .type = AMD_IP_BLOCK_TYPE_VCE,
1159 .major = 3,
1160 .minor = 4,
1161 .rev = 0,
1162 .funcs = &vce_v3_0_ip_funcs,
1163 },
1164};
1165
Emily Denge9ed3a62016-08-08 11:36:45 +08001166static const struct amdgpu_ip_block_version polaris11_ip_blocks_vd[] =
1167{
1168 /* ORDER MATTERS! */
1169 {
1170 .type = AMD_IP_BLOCK_TYPE_COMMON,
1171 .major = 2,
1172 .minor = 0,
1173 .rev = 0,
1174 .funcs = &vi_common_ip_funcs,
1175 },
1176 {
1177 .type = AMD_IP_BLOCK_TYPE_GMC,
1178 .major = 8,
1179 .minor = 1,
1180 .rev = 0,
1181 .funcs = &gmc_v8_0_ip_funcs,
1182 },
1183 {
1184 .type = AMD_IP_BLOCK_TYPE_IH,
1185 .major = 3,
1186 .minor = 1,
1187 .rev = 0,
1188 .funcs = &tonga_ih_ip_funcs,
1189 },
1190 {
1191 .type = AMD_IP_BLOCK_TYPE_SMC,
1192 .major = 7,
1193 .minor = 2,
1194 .rev = 0,
1195 .funcs = &amdgpu_pp_ip_funcs,
1196 },
1197 {
1198 .type = AMD_IP_BLOCK_TYPE_DCE,
1199 .major = 11,
1200 .minor = 2,
1201 .rev = 0,
1202 .funcs = &dce_virtual_ip_funcs,
1203 },
1204 {
1205 .type = AMD_IP_BLOCK_TYPE_GFX,
1206 .major = 8,
1207 .minor = 0,
1208 .rev = 0,
1209 .funcs = &gfx_v8_0_ip_funcs,
1210 },
1211 {
1212 .type = AMD_IP_BLOCK_TYPE_SDMA,
1213 .major = 3,
1214 .minor = 1,
1215 .rev = 0,
1216 .funcs = &sdma_v3_0_ip_funcs,
1217 },
1218 {
1219 .type = AMD_IP_BLOCK_TYPE_UVD,
1220 .major = 6,
1221 .minor = 3,
1222 .rev = 0,
1223 .funcs = &uvd_v6_0_ip_funcs,
1224 },
1225 {
1226 .type = AMD_IP_BLOCK_TYPE_VCE,
1227 .major = 3,
1228 .minor = 4,
1229 .rev = 0,
1230 .funcs = &vce_v3_0_ip_funcs,
1231 },
1232};
1233
Alex Deucheraaa36a92015-04-20 17:31:14 -04001234static const struct amdgpu_ip_block_version cz_ip_blocks[] =
1235{
1236 /* ORDER MATTERS! */
1237 {
yanyang15fc3aee2015-05-22 14:39:35 -04001238 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001239 .major = 2,
1240 .minor = 0,
1241 .rev = 0,
1242 .funcs = &vi_common_ip_funcs,
1243 },
1244 {
yanyang15fc3aee2015-05-22 14:39:35 -04001245 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001246 .major = 8,
1247 .minor = 0,
1248 .rev = 0,
1249 .funcs = &gmc_v8_0_ip_funcs,
1250 },
1251 {
yanyang15fc3aee2015-05-22 14:39:35 -04001252 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001253 .major = 3,
1254 .minor = 0,
1255 .rev = 0,
1256 .funcs = &cz_ih_ip_funcs,
1257 },
1258 {
yanyang15fc3aee2015-05-22 14:39:35 -04001259 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001260 .major = 8,
1261 .minor = 0,
1262 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -05001263 .funcs = &amdgpu_pp_ip_funcs
Alex Deucheraaa36a92015-04-20 17:31:14 -04001264 },
1265 {
yanyang15fc3aee2015-05-22 14:39:35 -04001266 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001267 .major = 11,
1268 .minor = 0,
1269 .rev = 0,
1270 .funcs = &dce_v11_0_ip_funcs,
1271 },
1272 {
yanyang15fc3aee2015-05-22 14:39:35 -04001273 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001274 .major = 8,
1275 .minor = 0,
1276 .rev = 0,
1277 .funcs = &gfx_v8_0_ip_funcs,
1278 },
1279 {
yanyang15fc3aee2015-05-22 14:39:35 -04001280 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001281 .major = 3,
1282 .minor = 0,
1283 .rev = 0,
1284 .funcs = &sdma_v3_0_ip_funcs,
1285 },
1286 {
yanyang15fc3aee2015-05-22 14:39:35 -04001287 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001288 .major = 6,
1289 .minor = 0,
1290 .rev = 0,
1291 .funcs = &uvd_v6_0_ip_funcs,
1292 },
1293 {
yanyang15fc3aee2015-05-22 14:39:35 -04001294 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001295 .major = 3,
1296 .minor = 0,
1297 .rev = 0,
1298 .funcs = &vce_v3_0_ip_funcs,
1299 },
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001300#if defined(CONFIG_DRM_AMD_ACP)
1301 {
1302 .type = AMD_IP_BLOCK_TYPE_ACP,
1303 .major = 2,
1304 .minor = 2,
1305 .rev = 0,
1306 .funcs = &acp_ip_funcs,
1307 },
1308#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -04001309};
1310
Emily Denge9ed3a62016-08-08 11:36:45 +08001311static const struct amdgpu_ip_block_version cz_ip_blocks_vd[] =
1312{
1313 /* ORDER MATTERS! */
1314 {
1315 .type = AMD_IP_BLOCK_TYPE_COMMON,
1316 .major = 2,
1317 .minor = 0,
1318 .rev = 0,
1319 .funcs = &vi_common_ip_funcs,
1320 },
1321 {
1322 .type = AMD_IP_BLOCK_TYPE_GMC,
1323 .major = 8,
1324 .minor = 0,
1325 .rev = 0,
1326 .funcs = &gmc_v8_0_ip_funcs,
1327 },
1328 {
1329 .type = AMD_IP_BLOCK_TYPE_IH,
1330 .major = 3,
1331 .minor = 0,
1332 .rev = 0,
1333 .funcs = &cz_ih_ip_funcs,
1334 },
1335 {
1336 .type = AMD_IP_BLOCK_TYPE_SMC,
1337 .major = 8,
1338 .minor = 0,
1339 .rev = 0,
1340 .funcs = &amdgpu_pp_ip_funcs
1341 },
1342 {
1343 .type = AMD_IP_BLOCK_TYPE_DCE,
1344 .major = 11,
1345 .minor = 0,
1346 .rev = 0,
1347 .funcs = &dce_virtual_ip_funcs,
1348 },
1349 {
1350 .type = AMD_IP_BLOCK_TYPE_GFX,
1351 .major = 8,
1352 .minor = 0,
1353 .rev = 0,
1354 .funcs = &gfx_v8_0_ip_funcs,
1355 },
1356 {
1357 .type = AMD_IP_BLOCK_TYPE_SDMA,
1358 .major = 3,
1359 .minor = 0,
1360 .rev = 0,
1361 .funcs = &sdma_v3_0_ip_funcs,
1362 },
1363 {
1364 .type = AMD_IP_BLOCK_TYPE_UVD,
1365 .major = 6,
1366 .minor = 0,
1367 .rev = 0,
1368 .funcs = &uvd_v6_0_ip_funcs,
1369 },
1370 {
1371 .type = AMD_IP_BLOCK_TYPE_VCE,
1372 .major = 3,
1373 .minor = 0,
1374 .rev = 0,
1375 .funcs = &vce_v3_0_ip_funcs,
1376 },
1377#if defined(CONFIG_DRM_AMD_ACP)
1378 {
1379 .type = AMD_IP_BLOCK_TYPE_ACP,
1380 .major = 2,
1381 .minor = 2,
1382 .rev = 0,
1383 .funcs = &acp_ip_funcs,
1384 },
1385#endif
1386};
1387
Alex Deucheraaa36a92015-04-20 17:31:14 -04001388int vi_set_ip_blocks(struct amdgpu_device *adev)
1389{
1390 switch (adev->asic_type) {
1391 case CHIP_TOPAZ:
1392 adev->ip_blocks = topaz_ip_blocks;
1393 adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
1394 break;
David Zhang48299f92015-07-08 01:05:16 +08001395 case CHIP_FIJI:
1396 adev->ip_blocks = fiji_ip_blocks;
1397 adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
1398 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001399 case CHIP_TONGA:
1400 adev->ip_blocks = tonga_ip_blocks;
1401 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
1402 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001403 case CHIP_POLARIS11:
1404 case CHIP_POLARIS10:
1405 adev->ip_blocks = polaris11_ip_blocks;
1406 adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks);
Flora Cuic0c1f572015-12-07 18:33:10 +08001407 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001408 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -04001409 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001410 adev->ip_blocks = cz_ip_blocks;
1411 adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
1412 break;
1413 default:
1414 /* FIXME: not supported yet */
1415 return -EINVAL;
1416 }
1417
Alex Deucheraaa36a92015-04-20 17:31:14 -04001418 return 0;
1419}
1420
Samuel Li39bb0c92015-10-08 16:31:43 -04001421#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
1422#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
1423#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
1424
Alex Deucheraaa36a92015-04-20 17:31:14 -04001425static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
1426{
Flora Cuiabdfb852015-11-20 11:40:53 +08001427 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -04001428 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
1429 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001430 else
Flora Cuiabdfb852015-11-20 11:40:53 +08001431 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
1432 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001433}
1434
1435static const struct amdgpu_asic_funcs vi_asic_funcs =
1436{
1437 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -05001438 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001439 .read_register = &vi_read_register,
1440 .reset = &vi_asic_reset,
1441 .set_vga_state = &vi_vga_set_state,
1442 .get_xclk = &vi_get_xclk,
1443 .set_uvd_clocks = &vi_set_uvd_clocks,
1444 .set_vce_clocks = &vi_set_vce_clocks,
Andres Rodriguez048765a2016-06-11 02:51:32 -04001445 .get_virtual_caps = &vi_get_virtual_caps,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001446};
1447
yanyang15fc3aee2015-05-22 14:39:35 -04001448static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001449{
1450 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -04001451 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001452
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001453 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -04001454 adev->smc_rreg = &cz_smc_rreg;
1455 adev->smc_wreg = &cz_smc_wreg;
1456 } else {
1457 adev->smc_rreg = &vi_smc_rreg;
1458 adev->smc_wreg = &vi_smc_wreg;
1459 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001460 adev->pcie_rreg = &vi_pcie_rreg;
1461 adev->pcie_wreg = &vi_pcie_wreg;
1462 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
1463 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
1464 adev->didt_rreg = &vi_didt_rreg;
1465 adev->didt_wreg = &vi_didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001466 adev->gc_cac_rreg = &vi_gc_cac_rreg;
1467 adev->gc_cac_wreg = &vi_gc_cac_wreg;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001468
1469 adev->asic_funcs = &vi_asic_funcs;
1470
yanyang15fc3aee2015-05-22 14:39:35 -04001471 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
1472 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -04001473 smc_enabled = true;
1474
1475 adev->rev_id = vi_get_rev_id(adev);
1476 adev->external_rev_id = 0xFF;
1477 switch (adev->asic_type) {
1478 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001479 adev->cg_flags = 0;
1480 adev->pg_flags = 0;
1481 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001482 break;
David Zhang48299f92015-07-08 01:05:16 +08001483 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -04001484 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1485 AMD_CG_SUPPORT_GFX_MGLS |
1486 AMD_CG_SUPPORT_GFX_RLC_LS |
1487 AMD_CG_SUPPORT_GFX_CP_LS |
1488 AMD_CG_SUPPORT_GFX_CGTS |
1489 AMD_CG_SUPPORT_GFX_CGTS_LS |
1490 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -04001491 AMD_CG_SUPPORT_GFX_CGLS |
1492 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -04001493 AMD_CG_SUPPORT_SDMA_LS |
1494 AMD_CG_SUPPORT_BIF_LS |
1495 AMD_CG_SUPPORT_HDP_MGCG |
1496 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -04001497 AMD_CG_SUPPORT_ROM_MGCG |
1498 AMD_CG_SUPPORT_MC_MGCG |
1499 AMD_CG_SUPPORT_MC_LS;
Flora Cuib6bc28f2015-11-02 21:21:34 +08001500 adev->pg_flags = 0;
1501 adev->external_rev_id = adev->rev_id + 0x3c;
1502 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001503 case CHIP_TONGA:
Tom St Denis5f64e772016-03-23 13:16:13 -04001504 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001505 adev->pg_flags = 0;
1506 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001507 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001508 case CHIP_POLARIS11:
Flora Cuic0c1f572015-12-07 18:33:10 +08001509 adev->cg_flags = 0;
1510 adev->pg_flags = 0;
1511 adev->external_rev_id = adev->rev_id + 0x5A;
1512 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001513 case CHIP_POLARIS10:
Flora Cuic0c1f572015-12-07 18:33:10 +08001514 adev->cg_flags = 0;
1515 adev->pg_flags = 0;
1516 adev->external_rev_id = adev->rev_id + 0x50;
1517 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001518 case CHIP_CARRIZO:
Tom St Denisf0f3a8f2016-05-03 10:36:28 -04001519 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1520 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucher70eced92016-04-07 23:01:48 -04001521 AMD_CG_SUPPORT_GFX_MGLS |
1522 AMD_CG_SUPPORT_GFX_RLC_LS |
1523 AMD_CG_SUPPORT_GFX_CP_LS |
1524 AMD_CG_SUPPORT_GFX_CGTS |
1525 AMD_CG_SUPPORT_GFX_MGLS |
1526 AMD_CG_SUPPORT_GFX_CGTS_LS |
1527 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001528 AMD_CG_SUPPORT_GFX_CGLS |
1529 AMD_CG_SUPPORT_BIF_LS |
1530 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001531 AMD_CG_SUPPORT_HDP_LS |
1532 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis1af69a22016-08-03 10:16:17 -04001533 AMD_CG_SUPPORT_SDMA_LS |
1534 AMD_CG_SUPPORT_VCE_MGCG;
Tom St Denisf6ade302016-07-28 09:33:56 -04001535 /* rev0 hardware requires workarounds to support PG */
Alex Deucher0fd4af92016-02-04 23:31:32 -05001536 adev->pg_flags = 0;
Tom St Denisf6ade302016-07-28 09:33:56 -04001537 if (adev->rev_id != 0x00) {
1538 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
1539 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denis65b42622016-07-28 09:35:57 -04001540 AMD_PG_SUPPORT_GFX_PIPELINE |
Tom St Denis2ed09362016-07-28 09:36:26 -04001541 AMD_PG_SUPPORT_UVD |
1542 AMD_PG_SUPPORT_VCE;
Tom St Denisf6ade302016-07-28 09:33:56 -04001543 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001544 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001545 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001546 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001547 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1548 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001549 AMD_CG_SUPPORT_GFX_MGLS |
Tom St Denis413cf602016-06-02 08:52:39 -04001550 AMD_CG_SUPPORT_GFX_RLC_LS |
1551 AMD_CG_SUPPORT_GFX_CP_LS |
1552 AMD_CG_SUPPORT_GFX_CGTS |
1553 AMD_CG_SUPPORT_GFX_MGLS |
1554 AMD_CG_SUPPORT_GFX_CGTS_LS |
1555 AMD_CG_SUPPORT_GFX_CGCG |
1556 AMD_CG_SUPPORT_GFX_CGLS |
Alex Deucherb6711d12016-04-13 12:41:50 -04001557 AMD_CG_SUPPORT_BIF_LS |
1558 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001559 AMD_CG_SUPPORT_HDP_LS |
1560 AMD_CG_SUPPORT_SDMA_MGCG |
Tom St Denis8ef583e2016-08-03 11:34:35 -04001561 AMD_CG_SUPPORT_SDMA_LS |
1562 AMD_CG_SUPPORT_VCE_MGCG;
Tom St Denis4e86be72016-07-28 09:38:13 -04001563 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
1564 AMD_PG_SUPPORT_GFX_SMG |
Tom St Denisc2cdb04282016-07-28 09:38:29 -04001565 AMD_PG_SUPPORT_GFX_PIPELINE |
Tom St Denis75419c42016-07-28 09:38:45 -04001566 AMD_PG_SUPPORT_UVD |
1567 AMD_PG_SUPPORT_VCE;
Tom St Deniscde64932016-03-23 13:17:04 -04001568 adev->external_rev_id = adev->rev_id + 0x1;
1569 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001570 default:
1571 /* FIXME: not supported yet */
1572 return -EINVAL;
1573 }
1574
Flora Cuia3d08fa2015-11-02 21:15:55 +08001575 if (amdgpu_smc_load_fw && smc_enabled)
1576 adev->firmware.smu_load = true;
1577
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001578 amdgpu_get_pcie_info(adev);
1579
Alex Deucheraaa36a92015-04-20 17:31:14 -04001580 return 0;
1581}
1582
yanyang15fc3aee2015-05-22 14:39:35 -04001583static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001584{
1585 return 0;
1586}
1587
yanyang15fc3aee2015-05-22 14:39:35 -04001588static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001589{
1590 return 0;
1591}
1592
yanyang15fc3aee2015-05-22 14:39:35 -04001593static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001594{
yanyang15fc3aee2015-05-22 14:39:35 -04001595 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1596
Alex Deucheraaa36a92015-04-20 17:31:14 -04001597 /* move the golden regs per IP block */
1598 vi_init_golden_registers(adev);
1599 /* enable pcie gen2/3 link */
1600 vi_pcie_gen3_enable(adev);
1601 /* enable aspm */
1602 vi_program_aspm(adev);
1603 /* enable the doorbell aperture */
1604 vi_enable_doorbell_aperture(adev, true);
1605
1606 return 0;
1607}
1608
yanyang15fc3aee2015-05-22 14:39:35 -04001609static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001610{
yanyang15fc3aee2015-05-22 14:39:35 -04001611 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1612
Alex Deucheraaa36a92015-04-20 17:31:14 -04001613 /* enable the doorbell aperture */
1614 vi_enable_doorbell_aperture(adev, false);
1615
1616 return 0;
1617}
1618
yanyang15fc3aee2015-05-22 14:39:35 -04001619static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001620{
yanyang15fc3aee2015-05-22 14:39:35 -04001621 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1622
Alex Deucheraaa36a92015-04-20 17:31:14 -04001623 return vi_common_hw_fini(adev);
1624}
1625
yanyang15fc3aee2015-05-22 14:39:35 -04001626static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001627{
yanyang15fc3aee2015-05-22 14:39:35 -04001628 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1629
Alex Deucheraaa36a92015-04-20 17:31:14 -04001630 return vi_common_hw_init(adev);
1631}
1632
yanyang15fc3aee2015-05-22 14:39:35 -04001633static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001634{
1635 return true;
1636}
1637
yanyang15fc3aee2015-05-22 14:39:35 -04001638static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001639{
1640 return 0;
1641}
1642
yanyang15fc3aee2015-05-22 14:39:35 -04001643static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001644{
1645 return 0;
1646}
1647
Alex Deucher76f10b92016-04-08 01:37:44 -04001648static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1649 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001650{
1651 uint32_t temp, data;
1652
1653 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1654
Alex Deucherc90766c2016-04-08 00:52:58 -04001655 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001656 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1657 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1658 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1659 else
1660 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1661 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1662 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1663
1664 if (temp != data)
1665 WREG32_PCIE(ixPCIE_CNTL2, data);
1666}
1667
Alex Deucher76f10b92016-04-08 01:37:44 -04001668static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1669 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001670{
1671 uint32_t temp, data;
1672
1673 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1674
Alex Deucherc90766c2016-04-08 00:52:58 -04001675 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001676 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1677 else
1678 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1679
1680 if (temp != data)
1681 WREG32(mmHDP_HOST_PATH_CNTL, data);
1682}
1683
Alex Deucher76f10b92016-04-08 01:37:44 -04001684static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1685 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001686{
1687 uint32_t temp, data;
1688
1689 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1690
Alex Deucherc90766c2016-04-08 00:52:58 -04001691 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001692 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1693 else
1694 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1695
1696 if (temp != data)
1697 WREG32(mmHDP_MEM_POWER_LS, data);
1698}
1699
Alex Deucher76f10b92016-04-08 01:37:44 -04001700static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1701 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001702{
1703 uint32_t temp, data;
1704
1705 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1706
Alex Deucherc90766c2016-04-08 00:52:58 -04001707 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001708 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1709 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1710 else
1711 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1712 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1713
1714 if (temp != data)
1715 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1716}
1717
yanyang15fc3aee2015-05-22 14:39:35 -04001718static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001719 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001720{
Eric Huang6cec2652015-11-12 16:59:47 -05001721 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1722
1723 switch (adev->asic_type) {
1724 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001725 vi_update_bif_medium_grain_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001726 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001727 vi_update_hdp_medium_grain_clock_gating(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001728 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001729 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001730 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001731 vi_update_rom_medium_grain_clock_gating(adev,
1732 state == AMD_CG_STATE_GATE ? true : false);
1733 break;
1734 case CHIP_CARRIZO:
1735 case CHIP_STONEY:
1736 vi_update_bif_medium_grain_light_sleep(adev,
1737 state == AMD_CG_STATE_GATE ? true : false);
1738 vi_update_hdp_medium_grain_clock_gating(adev,
1739 state == AMD_CG_STATE_GATE ? true : false);
1740 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001741 state == AMD_CG_STATE_GATE ? true : false);
1742 break;
1743 default:
1744 break;
1745 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001746 return 0;
1747}
1748
yanyang15fc3aee2015-05-22 14:39:35 -04001749static int vi_common_set_powergating_state(void *handle,
1750 enum amd_powergating_state state)
1751{
1752 return 0;
1753}
1754
1755const struct amd_ip_funcs vi_common_ip_funcs = {
Tom St Denis88a907d2016-05-04 14:28:35 -04001756 .name = "vi_common",
Alex Deucheraaa36a92015-04-20 17:31:14 -04001757 .early_init = vi_common_early_init,
1758 .late_init = NULL,
1759 .sw_init = vi_common_sw_init,
1760 .sw_fini = vi_common_sw_fini,
1761 .hw_init = vi_common_hw_init,
1762 .hw_fini = vi_common_hw_fini,
1763 .suspend = vi_common_suspend,
1764 .resume = vi_common_resume,
1765 .is_idle = vi_common_is_idle,
1766 .wait_for_idle = vi_common_wait_for_idle,
1767 .soft_reset = vi_common_soft_reset,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001768 .set_clockgating_state = vi_common_set_clockgating_state,
1769 .set_powergating_state = vi_common_set_powergating_state,
1770};
1771