blob: 83f890a3c31ccff2be87eab70109c82042344d51 [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
81/*
82 * Indirect registers accessor
83 */
84static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
85{
86 unsigned long flags;
87 u32 r;
88
89 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
90 WREG32(mmPCIE_INDEX, reg);
91 (void)RREG32(mmPCIE_INDEX);
92 r = RREG32(mmPCIE_DATA);
93 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
94 return r;
95}
96
97static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
98{
99 unsigned long flags;
100
101 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
102 WREG32(mmPCIE_INDEX, reg);
103 (void)RREG32(mmPCIE_INDEX);
104 WREG32(mmPCIE_DATA, v);
105 (void)RREG32(mmPCIE_DATA);
106 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
107}
108
109static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
110{
111 unsigned long flags;
112 u32 r;
113
114 spin_lock_irqsave(&adev->smc_idx_lock, flags);
115 WREG32(mmSMC_IND_INDEX_0, (reg));
116 r = RREG32(mmSMC_IND_DATA_0);
117 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
118 return r;
119}
120
121static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
122{
123 unsigned long flags;
124
125 spin_lock_irqsave(&adev->smc_idx_lock, flags);
126 WREG32(mmSMC_IND_INDEX_0, (reg));
127 WREG32(mmSMC_IND_DATA_0, (v));
128 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
129}
130
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400131/* smu_8_0_d.h */
132#define mmMP0PUB_IND_INDEX 0x180
133#define mmMP0PUB_IND_DATA 0x181
134
135static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
136{
137 unsigned long flags;
138 u32 r;
139
140 spin_lock_irqsave(&adev->smc_idx_lock, flags);
141 WREG32(mmMP0PUB_IND_INDEX, (reg));
142 r = RREG32(mmMP0PUB_IND_DATA);
143 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
144 return r;
145}
146
147static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
148{
149 unsigned long flags;
150
151 spin_lock_irqsave(&adev->smc_idx_lock, flags);
152 WREG32(mmMP0PUB_IND_INDEX, (reg));
153 WREG32(mmMP0PUB_IND_DATA, (v));
154 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
155}
156
Alex Deucheraaa36a92015-04-20 17:31:14 -0400157static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
158{
159 unsigned long flags;
160 u32 r;
161
162 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
163 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
164 r = RREG32(mmUVD_CTX_DATA);
165 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
166 return r;
167}
168
169static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
170{
171 unsigned long flags;
172
173 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
174 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
175 WREG32(mmUVD_CTX_DATA, (v));
176 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
177}
178
179static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
180{
181 unsigned long flags;
182 u32 r;
183
184 spin_lock_irqsave(&adev->didt_idx_lock, flags);
185 WREG32(mmDIDT_IND_INDEX, (reg));
186 r = RREG32(mmDIDT_IND_DATA);
187 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
188 return r;
189}
190
191static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
192{
193 unsigned long flags;
194
195 spin_lock_irqsave(&adev->didt_idx_lock, flags);
196 WREG32(mmDIDT_IND_INDEX, (reg));
197 WREG32(mmDIDT_IND_DATA, (v));
198 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
199}
200
201static const u32 tonga_mgcg_cgcg_init[] =
202{
203 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
204 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
205 mmPCIE_DATA, 0x000f0000, 0x00000000,
206 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
207 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400208 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
209 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
210};
211
David Zhang48299f92015-07-08 01:05:16 +0800212static const u32 fiji_mgcg_cgcg_init[] =
213{
214 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
215 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
216 mmPCIE_DATA, 0x000f0000, 0x00000000,
217 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
218 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
219 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
220 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
221};
222
Alex Deucheraaa36a92015-04-20 17:31:14 -0400223static const u32 iceland_mgcg_cgcg_init[] =
224{
225 mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
226 mmPCIE_DATA, 0x000f0000, 0x00000000,
227 mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
228 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
229 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
230};
231
232static const u32 cz_mgcg_cgcg_init[] =
233{
234 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
235 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
236 mmPCIE_DATA, 0x000f0000, 0x00000000,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400237 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
238 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
239};
240
Samuel Li39bb0c92015-10-08 16:31:43 -0400241static const u32 stoney_mgcg_cgcg_init[] =
242{
243 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
244 mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
245 mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
246};
247
Alex Deucheraaa36a92015-04-20 17:31:14 -0400248static void vi_init_golden_registers(struct amdgpu_device *adev)
249{
250 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
251 mutex_lock(&adev->grbm_idx_mutex);
252
253 switch (adev->asic_type) {
254 case CHIP_TOPAZ:
255 amdgpu_program_register_sequence(adev,
256 iceland_mgcg_cgcg_init,
257 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
258 break;
David Zhang48299f92015-07-08 01:05:16 +0800259 case CHIP_FIJI:
260 amdgpu_program_register_sequence(adev,
261 fiji_mgcg_cgcg_init,
262 (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
263 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400264 case CHIP_TONGA:
265 amdgpu_program_register_sequence(adev,
266 tonga_mgcg_cgcg_init,
267 (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
268 break;
269 case CHIP_CARRIZO:
270 amdgpu_program_register_sequence(adev,
271 cz_mgcg_cgcg_init,
272 (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
273 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400274 case CHIP_STONEY:
275 amdgpu_program_register_sequence(adev,
276 stoney_mgcg_cgcg_init,
277 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
278 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400279 default:
280 break;
281 }
282 mutex_unlock(&adev->grbm_idx_mutex);
283}
284
285/**
286 * vi_get_xclk - get the xclk
287 *
288 * @adev: amdgpu_device pointer
289 *
290 * Returns the reference clock used by the gfx engine
291 * (VI).
292 */
293static u32 vi_get_xclk(struct amdgpu_device *adev)
294{
295 u32 reference_clock = adev->clock.spll.reference_freq;
296 u32 tmp;
297
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800298 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400299 return reference_clock;
300
301 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
302 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
303 return 1000;
304
305 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
306 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
307 return reference_clock / 4;
308
309 return reference_clock;
310}
311
312/**
313 * vi_srbm_select - select specific register instances
314 *
315 * @adev: amdgpu_device pointer
316 * @me: selected ME (micro engine)
317 * @pipe: pipe
318 * @queue: queue
319 * @vmid: VMID
320 *
321 * Switches the currently active registers instances. Some
322 * registers are instanced per VMID, others are instanced per
323 * me/pipe/queue combination.
324 */
325void vi_srbm_select(struct amdgpu_device *adev,
326 u32 me, u32 pipe, u32 queue, u32 vmid)
327{
328 u32 srbm_gfx_cntl = 0;
329 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
330 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
331 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
332 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
333 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
334}
335
336static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
337{
338 /* todo */
339}
340
341static bool vi_read_disabled_bios(struct amdgpu_device *adev)
342{
343 u32 bus_cntl;
344 u32 d1vga_control = 0;
345 u32 d2vga_control = 0;
346 u32 vga_render_control = 0;
347 u32 rom_cntl;
348 bool r;
349
350 bus_cntl = RREG32(mmBUS_CNTL);
351 if (adev->mode_info.num_crtc) {
352 d1vga_control = RREG32(mmD1VGA_CONTROL);
353 d2vga_control = RREG32(mmD2VGA_CONTROL);
354 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
355 }
356 rom_cntl = RREG32_SMC(ixROM_CNTL);
357
358 /* enable the rom */
359 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
360 if (adev->mode_info.num_crtc) {
361 /* Disable VGA mode */
362 WREG32(mmD1VGA_CONTROL,
363 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
364 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
365 WREG32(mmD2VGA_CONTROL,
366 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
367 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
368 WREG32(mmVGA_RENDER_CONTROL,
369 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
370 }
371 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
372
373 r = amdgpu_read_bios(adev);
374
375 /* restore regs */
376 WREG32(mmBUS_CNTL, bus_cntl);
377 if (adev->mode_info.num_crtc) {
378 WREG32(mmD1VGA_CONTROL, d1vga_control);
379 WREG32(mmD2VGA_CONTROL, d2vga_control);
380 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
381 }
382 WREG32_SMC(ixROM_CNTL, rom_cntl);
383 return r;
384}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500385
386static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
387 u8 *bios, u32 length_bytes)
388{
389 u32 *dw_ptr;
390 unsigned long flags;
391 u32 i, length_dw;
392
393 if (bios == NULL)
394 return false;
395 if (length_bytes == 0)
396 return false;
397 /* APU vbios image is part of sbios image */
398 if (adev->flags & AMD_IS_APU)
399 return false;
400
401 dw_ptr = (u32 *)bios;
402 length_dw = ALIGN(length_bytes, 4) / 4;
403 /* take the smc lock since we are using the smc index */
404 spin_lock_irqsave(&adev->smc_idx_lock, flags);
405 /* set rom index to 0 */
406 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
407 WREG32(mmSMC_IND_DATA_0, 0);
408 /* set index to data for continous read */
409 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
410 for (i = 0; i < length_dw; i++)
411 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
412 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
413
414 return true;
415}
416
Nils Wallméniuseca22402016-03-19 16:12:17 +0100417static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400418 {mmGB_MACROTILE_MODE7, true},
419};
420
Nils Wallméniuseca22402016-03-19 16:12:17 +0100421static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400422 {mmGB_TILE_MODE7, true},
423 {mmGB_TILE_MODE12, true},
424 {mmGB_TILE_MODE17, true},
425 {mmGB_TILE_MODE23, true},
426 {mmGB_MACROTILE_MODE7, true},
427};
428
Nils Wallméniuseca22402016-03-19 16:12:17 +0100429static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400430 {mmGRBM_STATUS, false},
Marek Olšákc7890fe2015-07-11 12:08:46 +0200431 {mmGRBM_STATUS2, false},
432 {mmGRBM_STATUS_SE0, false},
433 {mmGRBM_STATUS_SE1, false},
434 {mmGRBM_STATUS_SE2, false},
435 {mmGRBM_STATUS_SE3, false},
436 {mmSRBM_STATUS, false},
437 {mmSRBM_STATUS2, false},
438 {mmSRBM_STATUS3, false},
439 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
440 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
441 {mmCP_STAT, false},
442 {mmCP_STALLED_STAT1, false},
443 {mmCP_STALLED_STAT2, false},
444 {mmCP_STALLED_STAT3, false},
445 {mmCP_CPF_BUSY_STAT, false},
446 {mmCP_CPF_STALLED_STAT1, false},
447 {mmCP_CPF_STATUS, false},
448 {mmCP_CPC_BUSY_STAT, false},
449 {mmCP_CPC_STALLED_STAT1, false},
450 {mmCP_CPC_STATUS, false},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400451 {mmGB_ADDR_CONFIG, false},
452 {mmMC_ARB_RAMCFG, false},
453 {mmGB_TILE_MODE0, false},
454 {mmGB_TILE_MODE1, false},
455 {mmGB_TILE_MODE2, false},
456 {mmGB_TILE_MODE3, false},
457 {mmGB_TILE_MODE4, false},
458 {mmGB_TILE_MODE5, false},
459 {mmGB_TILE_MODE6, false},
460 {mmGB_TILE_MODE7, false},
461 {mmGB_TILE_MODE8, false},
462 {mmGB_TILE_MODE9, false},
463 {mmGB_TILE_MODE10, false},
464 {mmGB_TILE_MODE11, false},
465 {mmGB_TILE_MODE12, false},
466 {mmGB_TILE_MODE13, false},
467 {mmGB_TILE_MODE14, false},
468 {mmGB_TILE_MODE15, false},
469 {mmGB_TILE_MODE16, false},
470 {mmGB_TILE_MODE17, false},
471 {mmGB_TILE_MODE18, false},
472 {mmGB_TILE_MODE19, false},
473 {mmGB_TILE_MODE20, false},
474 {mmGB_TILE_MODE21, false},
475 {mmGB_TILE_MODE22, false},
476 {mmGB_TILE_MODE23, false},
477 {mmGB_TILE_MODE24, false},
478 {mmGB_TILE_MODE25, false},
479 {mmGB_TILE_MODE26, false},
480 {mmGB_TILE_MODE27, false},
481 {mmGB_TILE_MODE28, false},
482 {mmGB_TILE_MODE29, false},
483 {mmGB_TILE_MODE30, false},
484 {mmGB_TILE_MODE31, false},
485 {mmGB_MACROTILE_MODE0, false},
486 {mmGB_MACROTILE_MODE1, false},
487 {mmGB_MACROTILE_MODE2, false},
488 {mmGB_MACROTILE_MODE3, false},
489 {mmGB_MACROTILE_MODE4, false},
490 {mmGB_MACROTILE_MODE5, false},
491 {mmGB_MACROTILE_MODE6, false},
492 {mmGB_MACROTILE_MODE7, false},
493 {mmGB_MACROTILE_MODE8, false},
494 {mmGB_MACROTILE_MODE9, false},
495 {mmGB_MACROTILE_MODE10, false},
496 {mmGB_MACROTILE_MODE11, false},
497 {mmGB_MACROTILE_MODE12, false},
498 {mmGB_MACROTILE_MODE13, false},
499 {mmGB_MACROTILE_MODE14, false},
500 {mmGB_MACROTILE_MODE15, false},
501 {mmCC_RB_BACKEND_DISABLE, false, true},
502 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
503 {mmGB_BACKEND_MAP, false, false},
504 {mmPA_SC_RASTER_CONFIG, false, true},
505 {mmPA_SC_RASTER_CONFIG_1, false, true},
506};
507
508static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
509 u32 sh_num, u32 reg_offset)
510{
511 uint32_t val;
512
513 mutex_lock(&adev->grbm_idx_mutex);
514 if (se_num != 0xffffffff || sh_num != 0xffffffff)
515 gfx_v8_0_select_se_sh(adev, se_num, sh_num);
516
517 val = RREG32(reg_offset);
518
519 if (se_num != 0xffffffff || sh_num != 0xffffffff)
520 gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
521 mutex_unlock(&adev->grbm_idx_mutex);
522 return val;
523}
524
525static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
526 u32 sh_num, u32 reg_offset, u32 *value)
527{
Nils Wallméniuseca22402016-03-19 16:12:17 +0100528 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
529 const struct amdgpu_allowed_register_entry *asic_register_entry;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400530 uint32_t size, i;
531
532 *value = 0;
533 switch (adev->asic_type) {
534 case CHIP_TOPAZ:
535 asic_register_table = tonga_allowed_read_registers;
536 size = ARRAY_SIZE(tonga_allowed_read_registers);
537 break;
David Zhang48299f92015-07-08 01:05:16 +0800538 case CHIP_FIJI:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400539 case CHIP_TONGA:
540 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -0400541 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400542 asic_register_table = cz_allowed_read_registers;
543 size = ARRAY_SIZE(cz_allowed_read_registers);
544 break;
545 default:
546 return -EINVAL;
547 }
548
549 if (asic_register_table) {
550 for (i = 0; i < size; i++) {
551 asic_register_entry = asic_register_table + i;
552 if (reg_offset != asic_register_entry->reg_offset)
553 continue;
554 if (!asic_register_entry->untouched)
555 *value = asic_register_entry->grbm_indexed ?
556 vi_read_indexed_register(adev, se_num,
557 sh_num, reg_offset) :
558 RREG32(reg_offset);
559 return 0;
560 }
561 }
562
563 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
564 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
565 continue;
566
567 if (!vi_allowed_read_registers[i].untouched)
568 *value = vi_allowed_read_registers[i].grbm_indexed ?
569 vi_read_indexed_register(adev, se_num,
570 sh_num, reg_offset) :
571 RREG32(reg_offset);
572 return 0;
573 }
574 return -EINVAL;
575}
576
Alex Deucheraaa36a92015-04-20 17:31:14 -0400577static void vi_gpu_pci_config_reset(struct amdgpu_device *adev)
578{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400579 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400580
581 dev_info(adev->dev, "GPU pci config reset\n");
582
Alex Deucheraaa36a92015-04-20 17:31:14 -0400583 /* disable BM */
584 pci_clear_master(adev->pdev);
585 /* reset */
586 amdgpu_pci_config_reset(adev);
587
588 udelay(100);
589
590 /* wait for asic to come out of reset */
591 for (i = 0; i < adev->usec_timeout; i++) {
592 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
593 break;
594 udelay(1);
595 }
596
597}
598
599static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
600{
601 u32 tmp = RREG32(mmBIOS_SCRATCH_3);
602
603 if (hung)
604 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
605 else
606 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
607
608 WREG32(mmBIOS_SCRATCH_3, tmp);
609}
610
611/**
612 * vi_asic_reset - soft reset GPU
613 *
614 * @adev: amdgpu_device pointer
615 *
616 * Look up which blocks are hung and attempt
617 * to reset them.
618 * Returns 0 for success.
619 */
620static int vi_asic_reset(struct amdgpu_device *adev)
621{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400622 vi_set_bios_scratch_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400623
Alex Deuchera2c5c692015-10-14 09:39:37 -0400624 vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400625
Alex Deuchera2c5c692015-10-14 09:39:37 -0400626 vi_set_bios_scratch_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400627
628 return 0;
629}
630
631static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
632 u32 cntl_reg, u32 status_reg)
633{
634 int r, i;
635 struct atom_clock_dividers dividers;
636 uint32_t tmp;
637
638 r = amdgpu_atombios_get_clock_dividers(adev,
639 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
640 clock, false, &dividers);
641 if (r)
642 return r;
643
644 tmp = RREG32_SMC(cntl_reg);
645 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
646 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
647 tmp |= dividers.post_divider;
648 WREG32_SMC(cntl_reg, tmp);
649
650 for (i = 0; i < 100; i++) {
651 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
652 break;
653 mdelay(10);
654 }
655 if (i == 100)
656 return -ETIMEDOUT;
657
658 return 0;
659}
660
661static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
662{
663 int r;
664
665 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
666 if (r)
667 return r;
668
669 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
670
671 return 0;
672}
673
674static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
675{
676 /* todo */
677
678 return 0;
679}
680
681static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
682{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400683 if (pci_is_root_bus(adev->pdev->bus))
684 return;
685
Alex Deucheraaa36a92015-04-20 17:31:14 -0400686 if (amdgpu_pcie_gen2 == 0)
687 return;
688
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800689 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400690 return;
691
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500692 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
693 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400694 return;
695
696 /* todo */
697}
698
699static void vi_program_aspm(struct amdgpu_device *adev)
700{
701
702 if (amdgpu_aspm == 0)
703 return;
704
705 /* todo */
706}
707
708static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
709 bool enable)
710{
711 u32 tmp;
712
713 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800714 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400715 return;
716
717 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
718 if (enable)
719 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
720 else
721 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
722
723 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
724}
725
726/* topaz has no DCE, UVD, VCE */
727static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
728{
729 /* ORDER MATTERS! */
730 {
yanyang15fc3aee2015-05-22 14:39:35 -0400731 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400732 .major = 2,
733 .minor = 0,
734 .rev = 0,
735 .funcs = &vi_common_ip_funcs,
736 },
737 {
yanyang15fc3aee2015-05-22 14:39:35 -0400738 .type = AMD_IP_BLOCK_TYPE_GMC,
Ken Wang429c45d2016-02-03 19:16:54 +0800739 .major = 7,
740 .minor = 4,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400741 .rev = 0,
Ken Wang429c45d2016-02-03 19:16:54 +0800742 .funcs = &gmc_v7_0_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400743 },
744 {
yanyang15fc3aee2015-05-22 14:39:35 -0400745 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400746 .major = 2,
747 .minor = 4,
748 .rev = 0,
749 .funcs = &iceland_ih_ip_funcs,
750 },
751 {
yanyang15fc3aee2015-05-22 14:39:35 -0400752 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400753 .major = 7,
754 .minor = 1,
755 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500756 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400757 },
758 {
yanyang15fc3aee2015-05-22 14:39:35 -0400759 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400760 .major = 8,
761 .minor = 0,
762 .rev = 0,
763 .funcs = &gfx_v8_0_ip_funcs,
764 },
765 {
yanyang15fc3aee2015-05-22 14:39:35 -0400766 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400767 .major = 2,
768 .minor = 4,
769 .rev = 0,
770 .funcs = &sdma_v2_4_ip_funcs,
771 },
772};
773
774static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
775{
776 /* ORDER MATTERS! */
777 {
yanyang15fc3aee2015-05-22 14:39:35 -0400778 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400779 .major = 2,
780 .minor = 0,
781 .rev = 0,
782 .funcs = &vi_common_ip_funcs,
783 },
784 {
yanyang15fc3aee2015-05-22 14:39:35 -0400785 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400786 .major = 8,
787 .minor = 0,
788 .rev = 0,
789 .funcs = &gmc_v8_0_ip_funcs,
790 },
791 {
yanyang15fc3aee2015-05-22 14:39:35 -0400792 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400793 .major = 3,
794 .minor = 0,
795 .rev = 0,
796 .funcs = &tonga_ih_ip_funcs,
797 },
798 {
yanyang15fc3aee2015-05-22 14:39:35 -0400799 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400800 .major = 7,
801 .minor = 1,
802 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500803 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400804 },
805 {
yanyang15fc3aee2015-05-22 14:39:35 -0400806 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400807 .major = 10,
808 .minor = 0,
809 .rev = 0,
810 .funcs = &dce_v10_0_ip_funcs,
811 },
812 {
yanyang15fc3aee2015-05-22 14:39:35 -0400813 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400814 .major = 8,
815 .minor = 0,
816 .rev = 0,
817 .funcs = &gfx_v8_0_ip_funcs,
818 },
819 {
yanyang15fc3aee2015-05-22 14:39:35 -0400820 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400821 .major = 3,
822 .minor = 0,
823 .rev = 0,
824 .funcs = &sdma_v3_0_ip_funcs,
825 },
826 {
yanyang15fc3aee2015-05-22 14:39:35 -0400827 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400828 .major = 5,
829 .minor = 0,
830 .rev = 0,
831 .funcs = &uvd_v5_0_ip_funcs,
832 },
833 {
yanyang15fc3aee2015-05-22 14:39:35 -0400834 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400835 .major = 3,
836 .minor = 0,
837 .rev = 0,
838 .funcs = &vce_v3_0_ip_funcs,
839 },
840};
841
David Zhang48299f92015-07-08 01:05:16 +0800842static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
843{
844 /* ORDER MATTERS! */
845 {
846 .type = AMD_IP_BLOCK_TYPE_COMMON,
847 .major = 2,
848 .minor = 0,
849 .rev = 0,
850 .funcs = &vi_common_ip_funcs,
David Zhang127a2622015-07-08 01:11:52 +0800851 },
852 {
853 .type = AMD_IP_BLOCK_TYPE_GMC,
854 .major = 8,
855 .minor = 5,
856 .rev = 0,
857 .funcs = &gmc_v8_0_ip_funcs,
858 },
David Zhangaa8a3b52015-07-08 21:40:31 +0800859 {
860 .type = AMD_IP_BLOCK_TYPE_IH,
861 .major = 3,
862 .minor = 0,
863 .rev = 0,
864 .funcs = &tonga_ih_ip_funcs,
865 },
David Zhang8e711e1a2015-07-08 01:23:25 +0800866 {
867 .type = AMD_IP_BLOCK_TYPE_SMC,
868 .major = 7,
869 .minor = 1,
870 .rev = 0,
Eric Huang899fa4c2015-09-29 14:58:53 -0400871 .funcs = &amdgpu_pp_ip_funcs,
David Zhang8e711e1a2015-07-08 01:23:25 +0800872 },
David Zhang84390862015-07-08 01:28:20 +0800873 {
874 .type = AMD_IP_BLOCK_TYPE_DCE,
875 .major = 10,
876 .minor = 1,
877 .rev = 0,
878 .funcs = &dce_v10_0_ip_funcs,
879 },
David Zhangaf15a2d2015-07-30 19:42:11 -0400880 {
881 .type = AMD_IP_BLOCK_TYPE_GFX,
882 .major = 8,
883 .minor = 0,
884 .rev = 0,
885 .funcs = &gfx_v8_0_ip_funcs,
886 },
David Zhang1a5bbb62015-07-08 17:29:27 +0800887 {
888 .type = AMD_IP_BLOCK_TYPE_SDMA,
889 .major = 3,
890 .minor = 0,
891 .rev = 0,
892 .funcs = &sdma_v3_0_ip_funcs,
893 },
David Zhang974ee3d2015-07-08 17:32:15 +0800894 {
895 .type = AMD_IP_BLOCK_TYPE_UVD,
896 .major = 6,
897 .minor = 0,
898 .rev = 0,
899 .funcs = &uvd_v6_0_ip_funcs,
900 },
Alex Deucher188a9bc2015-07-27 14:24:14 -0400901 {
902 .type = AMD_IP_BLOCK_TYPE_VCE,
903 .major = 3,
904 .minor = 0,
905 .rev = 0,
906 .funcs = &vce_v3_0_ip_funcs,
907 },
David Zhang48299f92015-07-08 01:05:16 +0800908};
909
Alex Deucheraaa36a92015-04-20 17:31:14 -0400910static const struct amdgpu_ip_block_version cz_ip_blocks[] =
911{
912 /* ORDER MATTERS! */
913 {
yanyang15fc3aee2015-05-22 14:39:35 -0400914 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400915 .major = 2,
916 .minor = 0,
917 .rev = 0,
918 .funcs = &vi_common_ip_funcs,
919 },
920 {
yanyang15fc3aee2015-05-22 14:39:35 -0400921 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400922 .major = 8,
923 .minor = 0,
924 .rev = 0,
925 .funcs = &gmc_v8_0_ip_funcs,
926 },
927 {
yanyang15fc3aee2015-05-22 14:39:35 -0400928 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400929 .major = 3,
930 .minor = 0,
931 .rev = 0,
932 .funcs = &cz_ih_ip_funcs,
933 },
934 {
yanyang15fc3aee2015-05-22 14:39:35 -0400935 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400936 .major = 8,
937 .minor = 0,
938 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500939 .funcs = &amdgpu_pp_ip_funcs
Alex Deucheraaa36a92015-04-20 17:31:14 -0400940 },
941 {
yanyang15fc3aee2015-05-22 14:39:35 -0400942 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400943 .major = 11,
944 .minor = 0,
945 .rev = 0,
946 .funcs = &dce_v11_0_ip_funcs,
947 },
948 {
yanyang15fc3aee2015-05-22 14:39:35 -0400949 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400950 .major = 8,
951 .minor = 0,
952 .rev = 0,
953 .funcs = &gfx_v8_0_ip_funcs,
954 },
955 {
yanyang15fc3aee2015-05-22 14:39:35 -0400956 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400957 .major = 3,
958 .minor = 0,
959 .rev = 0,
960 .funcs = &sdma_v3_0_ip_funcs,
961 },
962 {
yanyang15fc3aee2015-05-22 14:39:35 -0400963 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400964 .major = 6,
965 .minor = 0,
966 .rev = 0,
967 .funcs = &uvd_v6_0_ip_funcs,
968 },
969 {
yanyang15fc3aee2015-05-22 14:39:35 -0400970 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400971 .major = 3,
972 .minor = 0,
973 .rev = 0,
974 .funcs = &vce_v3_0_ip_funcs,
975 },
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -0400976#if defined(CONFIG_DRM_AMD_ACP)
977 {
978 .type = AMD_IP_BLOCK_TYPE_ACP,
979 .major = 2,
980 .minor = 2,
981 .rev = 0,
982 .funcs = &acp_ip_funcs,
983 },
984#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -0400985};
986
987int vi_set_ip_blocks(struct amdgpu_device *adev)
988{
989 switch (adev->asic_type) {
990 case CHIP_TOPAZ:
991 adev->ip_blocks = topaz_ip_blocks;
992 adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
993 break;
David Zhang48299f92015-07-08 01:05:16 +0800994 case CHIP_FIJI:
995 adev->ip_blocks = fiji_ip_blocks;
996 adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
997 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400998 case CHIP_TONGA:
999 adev->ip_blocks = tonga_ip_blocks;
1000 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
1001 break;
1002 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -04001003 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001004 adev->ip_blocks = cz_ip_blocks;
1005 adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
1006 break;
1007 default:
1008 /* FIXME: not supported yet */
1009 return -EINVAL;
1010 }
1011
Alex Deucheraaa36a92015-04-20 17:31:14 -04001012 return 0;
1013}
1014
Samuel Li39bb0c92015-10-08 16:31:43 -04001015#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
1016#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
1017#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
1018
Alex Deucheraaa36a92015-04-20 17:31:14 -04001019static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
1020{
Flora Cuiabdfb852015-11-20 11:40:53 +08001021 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -04001022 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
1023 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001024 else
Flora Cuiabdfb852015-11-20 11:40:53 +08001025 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
1026 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001027}
1028
1029static const struct amdgpu_asic_funcs vi_asic_funcs =
1030{
1031 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -05001032 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001033 .read_register = &vi_read_register,
1034 .reset = &vi_asic_reset,
1035 .set_vga_state = &vi_vga_set_state,
1036 .get_xclk = &vi_get_xclk,
1037 .set_uvd_clocks = &vi_set_uvd_clocks,
1038 .set_vce_clocks = &vi_set_vce_clocks,
1039 .get_cu_info = &gfx_v8_0_get_cu_info,
1040 /* these should be moved to their own ip modules */
1041 .get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
1042 .wait_for_mc_idle = &gmc_v8_0_mc_wait_for_idle,
1043};
1044
yanyang15fc3aee2015-05-22 14:39:35 -04001045static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001046{
1047 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -04001048 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001049
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001050 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -04001051 adev->smc_rreg = &cz_smc_rreg;
1052 adev->smc_wreg = &cz_smc_wreg;
1053 } else {
1054 adev->smc_rreg = &vi_smc_rreg;
1055 adev->smc_wreg = &vi_smc_wreg;
1056 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001057 adev->pcie_rreg = &vi_pcie_rreg;
1058 adev->pcie_wreg = &vi_pcie_wreg;
1059 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
1060 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
1061 adev->didt_rreg = &vi_didt_rreg;
1062 adev->didt_wreg = &vi_didt_wreg;
1063
1064 adev->asic_funcs = &vi_asic_funcs;
1065
yanyang15fc3aee2015-05-22 14:39:35 -04001066 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
1067 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -04001068 smc_enabled = true;
1069
1070 adev->rev_id = vi_get_rev_id(adev);
1071 adev->external_rev_id = 0xFF;
1072 switch (adev->asic_type) {
1073 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001074 adev->cg_flags = 0;
1075 adev->pg_flags = 0;
1076 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001077 break;
David Zhang48299f92015-07-08 01:05:16 +08001078 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -04001079 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1080 AMD_CG_SUPPORT_GFX_MGLS |
1081 AMD_CG_SUPPORT_GFX_RLC_LS |
1082 AMD_CG_SUPPORT_GFX_CP_LS |
1083 AMD_CG_SUPPORT_GFX_CGTS |
1084 AMD_CG_SUPPORT_GFX_CGTS_LS |
1085 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -04001086 AMD_CG_SUPPORT_GFX_CGLS |
1087 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -04001088 AMD_CG_SUPPORT_SDMA_LS |
1089 AMD_CG_SUPPORT_BIF_LS |
1090 AMD_CG_SUPPORT_HDP_MGCG |
1091 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -04001092 AMD_CG_SUPPORT_ROM_MGCG |
1093 AMD_CG_SUPPORT_MC_MGCG |
1094 AMD_CG_SUPPORT_MC_LS;
Flora Cuib6bc28f2015-11-02 21:21:34 +08001095 adev->pg_flags = 0;
1096 adev->external_rev_id = adev->rev_id + 0x3c;
1097 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001098 case CHIP_TONGA:
Tom St Denis5f64e772016-03-23 13:16:13 -04001099 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001100 adev->pg_flags = 0;
1101 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001102 break;
1103 case CHIP_CARRIZO:
Alex Deucher70eced92016-04-07 23:01:48 -04001104 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1105 AMD_CG_SUPPORT_GFX_MGLS |
1106 AMD_CG_SUPPORT_GFX_RLC_LS |
1107 AMD_CG_SUPPORT_GFX_CP_LS |
1108 AMD_CG_SUPPORT_GFX_CGTS |
1109 AMD_CG_SUPPORT_GFX_MGLS |
1110 AMD_CG_SUPPORT_GFX_CGTS_LS |
1111 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001112 AMD_CG_SUPPORT_GFX_CGLS |
1113 AMD_CG_SUPPORT_BIF_LS |
1114 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001115 AMD_CG_SUPPORT_HDP_LS |
1116 AMD_CG_SUPPORT_SDMA_MGCG |
1117 AMD_CG_SUPPORT_SDMA_LS;
Alex Deucher0fd4af92016-02-04 23:31:32 -05001118 adev->pg_flags = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001119 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001120 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001121 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001122 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1123 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001124 AMD_CG_SUPPORT_GFX_MGLS |
1125 AMD_CG_SUPPORT_BIF_LS |
1126 AMD_CG_SUPPORT_HDP_MGCG |
1127 AMD_CG_SUPPORT_HDP_LS;
Tom St Deniscde64932016-03-23 13:17:04 -04001128 adev->pg_flags = 0;
1129 adev->external_rev_id = adev->rev_id + 0x1;
1130 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001131 default:
1132 /* FIXME: not supported yet */
1133 return -EINVAL;
1134 }
1135
Flora Cuia3d08fa2015-11-02 21:15:55 +08001136 if (amdgpu_smc_load_fw && smc_enabled)
1137 adev->firmware.smu_load = true;
1138
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001139 amdgpu_get_pcie_info(adev);
1140
Alex Deucheraaa36a92015-04-20 17:31:14 -04001141 return 0;
1142}
1143
yanyang15fc3aee2015-05-22 14:39:35 -04001144static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001145{
1146 return 0;
1147}
1148
yanyang15fc3aee2015-05-22 14:39:35 -04001149static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001150{
1151 return 0;
1152}
1153
yanyang15fc3aee2015-05-22 14:39:35 -04001154static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001155{
yanyang15fc3aee2015-05-22 14:39:35 -04001156 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1157
Alex Deucheraaa36a92015-04-20 17:31:14 -04001158 /* move the golden regs per IP block */
1159 vi_init_golden_registers(adev);
1160 /* enable pcie gen2/3 link */
1161 vi_pcie_gen3_enable(adev);
1162 /* enable aspm */
1163 vi_program_aspm(adev);
1164 /* enable the doorbell aperture */
1165 vi_enable_doorbell_aperture(adev, true);
1166
1167 return 0;
1168}
1169
yanyang15fc3aee2015-05-22 14:39:35 -04001170static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001171{
yanyang15fc3aee2015-05-22 14:39:35 -04001172 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1173
Alex Deucheraaa36a92015-04-20 17:31:14 -04001174 /* enable the doorbell aperture */
1175 vi_enable_doorbell_aperture(adev, false);
1176
1177 return 0;
1178}
1179
yanyang15fc3aee2015-05-22 14:39:35 -04001180static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001181{
yanyang15fc3aee2015-05-22 14:39:35 -04001182 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1183
Alex Deucheraaa36a92015-04-20 17:31:14 -04001184 return vi_common_hw_fini(adev);
1185}
1186
yanyang15fc3aee2015-05-22 14:39:35 -04001187static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001188{
yanyang15fc3aee2015-05-22 14:39:35 -04001189 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1190
Alex Deucheraaa36a92015-04-20 17:31:14 -04001191 return vi_common_hw_init(adev);
1192}
1193
yanyang15fc3aee2015-05-22 14:39:35 -04001194static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001195{
1196 return true;
1197}
1198
yanyang15fc3aee2015-05-22 14:39:35 -04001199static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001200{
1201 return 0;
1202}
1203
yanyang15fc3aee2015-05-22 14:39:35 -04001204static void vi_common_print_status(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001205{
yanyang15fc3aee2015-05-22 14:39:35 -04001206 return;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001207}
1208
yanyang15fc3aee2015-05-22 14:39:35 -04001209static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001210{
1211 return 0;
1212}
1213
Alex Deucher76f10b92016-04-08 01:37:44 -04001214static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1215 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001216{
1217 uint32_t temp, data;
1218
1219 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1220
Alex Deucherc90766c2016-04-08 00:52:58 -04001221 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001222 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1223 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1224 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1225 else
1226 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1227 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1228 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1229
1230 if (temp != data)
1231 WREG32_PCIE(ixPCIE_CNTL2, data);
1232}
1233
Alex Deucher76f10b92016-04-08 01:37:44 -04001234static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1235 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001236{
1237 uint32_t temp, data;
1238
1239 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1240
Alex Deucherc90766c2016-04-08 00:52:58 -04001241 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001242 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1243 else
1244 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1245
1246 if (temp != data)
1247 WREG32(mmHDP_HOST_PATH_CNTL, data);
1248}
1249
Alex Deucher76f10b92016-04-08 01:37:44 -04001250static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1251 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001252{
1253 uint32_t temp, data;
1254
1255 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1256
Alex Deucherc90766c2016-04-08 00:52:58 -04001257 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001258 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1259 else
1260 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1261
1262 if (temp != data)
1263 WREG32(mmHDP_MEM_POWER_LS, data);
1264}
1265
Alex Deucher76f10b92016-04-08 01:37:44 -04001266static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1267 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001268{
1269 uint32_t temp, data;
1270
1271 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1272
Alex Deucherc90766c2016-04-08 00:52:58 -04001273 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001274 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1275 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1276 else
1277 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1278 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1279
1280 if (temp != data)
1281 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1282}
1283
yanyang15fc3aee2015-05-22 14:39:35 -04001284static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001285 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001286{
Eric Huang6cec2652015-11-12 16:59:47 -05001287 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1288
1289 switch (adev->asic_type) {
1290 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001291 vi_update_bif_medium_grain_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001292 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001293 vi_update_hdp_medium_grain_clock_gating(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001294 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001295 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001296 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001297 vi_update_rom_medium_grain_clock_gating(adev,
1298 state == AMD_CG_STATE_GATE ? true : false);
1299 break;
1300 case CHIP_CARRIZO:
1301 case CHIP_STONEY:
1302 vi_update_bif_medium_grain_light_sleep(adev,
1303 state == AMD_CG_STATE_GATE ? true : false);
1304 vi_update_hdp_medium_grain_clock_gating(adev,
1305 state == AMD_CG_STATE_GATE ? true : false);
1306 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001307 state == AMD_CG_STATE_GATE ? true : false);
1308 break;
1309 default:
1310 break;
1311 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001312 return 0;
1313}
1314
yanyang15fc3aee2015-05-22 14:39:35 -04001315static int vi_common_set_powergating_state(void *handle,
1316 enum amd_powergating_state state)
1317{
1318 return 0;
1319}
1320
1321const struct amd_ip_funcs vi_common_ip_funcs = {
Alex Deucheraaa36a92015-04-20 17:31:14 -04001322 .early_init = vi_common_early_init,
1323 .late_init = NULL,
1324 .sw_init = vi_common_sw_init,
1325 .sw_fini = vi_common_sw_fini,
1326 .hw_init = vi_common_hw_init,
1327 .hw_fini = vi_common_hw_fini,
1328 .suspend = vi_common_suspend,
1329 .resume = vi_common_resume,
1330 .is_idle = vi_common_is_idle,
1331 .wait_for_idle = vi_common_wait_for_idle,
1332 .soft_reset = vi_common_soft_reset,
1333 .print_status = vi_common_print_status,
1334 .set_clockgating_state = vi_common_set_clockgating_state,
1335 .set_powergating_state = vi_common_set_powergating_state,
1336};
1337