blob: 2c228d6c672e3e0a72d1067deed135f87ec92657 [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;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400279 case CHIP_POLARIS11:
280 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400281 default:
282 break;
283 }
284 mutex_unlock(&adev->grbm_idx_mutex);
285}
286
287/**
288 * vi_get_xclk - get the xclk
289 *
290 * @adev: amdgpu_device pointer
291 *
292 * Returns the reference clock used by the gfx engine
293 * (VI).
294 */
295static u32 vi_get_xclk(struct amdgpu_device *adev)
296{
297 u32 reference_clock = adev->clock.spll.reference_freq;
298 u32 tmp;
299
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800300 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400301 return reference_clock;
302
303 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
304 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
305 return 1000;
306
307 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
308 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
309 return reference_clock / 4;
310
311 return reference_clock;
312}
313
314/**
315 * vi_srbm_select - select specific register instances
316 *
317 * @adev: amdgpu_device pointer
318 * @me: selected ME (micro engine)
319 * @pipe: pipe
320 * @queue: queue
321 * @vmid: VMID
322 *
323 * Switches the currently active registers instances. Some
324 * registers are instanced per VMID, others are instanced per
325 * me/pipe/queue combination.
326 */
327void vi_srbm_select(struct amdgpu_device *adev,
328 u32 me, u32 pipe, u32 queue, u32 vmid)
329{
330 u32 srbm_gfx_cntl = 0;
331 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
332 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
333 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
334 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
335 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
336}
337
338static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
339{
340 /* todo */
341}
342
343static bool vi_read_disabled_bios(struct amdgpu_device *adev)
344{
345 u32 bus_cntl;
346 u32 d1vga_control = 0;
347 u32 d2vga_control = 0;
348 u32 vga_render_control = 0;
349 u32 rom_cntl;
350 bool r;
351
352 bus_cntl = RREG32(mmBUS_CNTL);
353 if (adev->mode_info.num_crtc) {
354 d1vga_control = RREG32(mmD1VGA_CONTROL);
355 d2vga_control = RREG32(mmD2VGA_CONTROL);
356 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
357 }
358 rom_cntl = RREG32_SMC(ixROM_CNTL);
359
360 /* enable the rom */
361 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
362 if (adev->mode_info.num_crtc) {
363 /* Disable VGA mode */
364 WREG32(mmD1VGA_CONTROL,
365 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
366 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
367 WREG32(mmD2VGA_CONTROL,
368 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
369 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
370 WREG32(mmVGA_RENDER_CONTROL,
371 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
372 }
373 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
374
375 r = amdgpu_read_bios(adev);
376
377 /* restore regs */
378 WREG32(mmBUS_CNTL, bus_cntl);
379 if (adev->mode_info.num_crtc) {
380 WREG32(mmD1VGA_CONTROL, d1vga_control);
381 WREG32(mmD2VGA_CONTROL, d2vga_control);
382 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
383 }
384 WREG32_SMC(ixROM_CNTL, rom_cntl);
385 return r;
386}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500387
388static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
389 u8 *bios, u32 length_bytes)
390{
391 u32 *dw_ptr;
392 unsigned long flags;
393 u32 i, length_dw;
394
395 if (bios == NULL)
396 return false;
397 if (length_bytes == 0)
398 return false;
399 /* APU vbios image is part of sbios image */
400 if (adev->flags & AMD_IS_APU)
401 return false;
402
403 dw_ptr = (u32 *)bios;
404 length_dw = ALIGN(length_bytes, 4) / 4;
405 /* take the smc lock since we are using the smc index */
406 spin_lock_irqsave(&adev->smc_idx_lock, flags);
407 /* set rom index to 0 */
408 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
409 WREG32(mmSMC_IND_DATA_0, 0);
410 /* set index to data for continous read */
411 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
412 for (i = 0; i < length_dw; i++)
413 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
414 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
415
416 return true;
417}
418
Nils Wallméniuseca22402016-03-19 16:12:17 +0100419static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400420 {mmGB_MACROTILE_MODE7, true},
421};
422
Nils Wallméniuseca22402016-03-19 16:12:17 +0100423static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400424 {mmGB_TILE_MODE7, true},
425 {mmGB_TILE_MODE12, true},
426 {mmGB_TILE_MODE17, true},
427 {mmGB_TILE_MODE23, true},
428 {mmGB_MACROTILE_MODE7, true},
429};
430
Nils Wallméniuseca22402016-03-19 16:12:17 +0100431static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400432 {mmGRBM_STATUS, false},
Marek Olšákc7890fe2015-07-11 12:08:46 +0200433 {mmGRBM_STATUS2, false},
434 {mmGRBM_STATUS_SE0, false},
435 {mmGRBM_STATUS_SE1, false},
436 {mmGRBM_STATUS_SE2, false},
437 {mmGRBM_STATUS_SE3, false},
438 {mmSRBM_STATUS, false},
439 {mmSRBM_STATUS2, false},
440 {mmSRBM_STATUS3, false},
441 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
442 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
443 {mmCP_STAT, false},
444 {mmCP_STALLED_STAT1, false},
445 {mmCP_STALLED_STAT2, false},
446 {mmCP_STALLED_STAT3, false},
447 {mmCP_CPF_BUSY_STAT, false},
448 {mmCP_CPF_STALLED_STAT1, false},
449 {mmCP_CPF_STATUS, false},
450 {mmCP_CPC_BUSY_STAT, false},
451 {mmCP_CPC_STALLED_STAT1, false},
452 {mmCP_CPC_STATUS, false},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400453 {mmGB_ADDR_CONFIG, false},
454 {mmMC_ARB_RAMCFG, false},
455 {mmGB_TILE_MODE0, false},
456 {mmGB_TILE_MODE1, false},
457 {mmGB_TILE_MODE2, false},
458 {mmGB_TILE_MODE3, false},
459 {mmGB_TILE_MODE4, false},
460 {mmGB_TILE_MODE5, false},
461 {mmGB_TILE_MODE6, false},
462 {mmGB_TILE_MODE7, false},
463 {mmGB_TILE_MODE8, false},
464 {mmGB_TILE_MODE9, false},
465 {mmGB_TILE_MODE10, false},
466 {mmGB_TILE_MODE11, false},
467 {mmGB_TILE_MODE12, false},
468 {mmGB_TILE_MODE13, false},
469 {mmGB_TILE_MODE14, false},
470 {mmGB_TILE_MODE15, false},
471 {mmGB_TILE_MODE16, false},
472 {mmGB_TILE_MODE17, false},
473 {mmGB_TILE_MODE18, false},
474 {mmGB_TILE_MODE19, false},
475 {mmGB_TILE_MODE20, false},
476 {mmGB_TILE_MODE21, false},
477 {mmGB_TILE_MODE22, false},
478 {mmGB_TILE_MODE23, false},
479 {mmGB_TILE_MODE24, false},
480 {mmGB_TILE_MODE25, false},
481 {mmGB_TILE_MODE26, false},
482 {mmGB_TILE_MODE27, false},
483 {mmGB_TILE_MODE28, false},
484 {mmGB_TILE_MODE29, false},
485 {mmGB_TILE_MODE30, false},
486 {mmGB_TILE_MODE31, false},
487 {mmGB_MACROTILE_MODE0, false},
488 {mmGB_MACROTILE_MODE1, false},
489 {mmGB_MACROTILE_MODE2, false},
490 {mmGB_MACROTILE_MODE3, false},
491 {mmGB_MACROTILE_MODE4, false},
492 {mmGB_MACROTILE_MODE5, false},
493 {mmGB_MACROTILE_MODE6, false},
494 {mmGB_MACROTILE_MODE7, false},
495 {mmGB_MACROTILE_MODE8, false},
496 {mmGB_MACROTILE_MODE9, false},
497 {mmGB_MACROTILE_MODE10, false},
498 {mmGB_MACROTILE_MODE11, false},
499 {mmGB_MACROTILE_MODE12, false},
500 {mmGB_MACROTILE_MODE13, false},
501 {mmGB_MACROTILE_MODE14, false},
502 {mmGB_MACROTILE_MODE15, false},
503 {mmCC_RB_BACKEND_DISABLE, false, true},
504 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
505 {mmGB_BACKEND_MAP, false, false},
506 {mmPA_SC_RASTER_CONFIG, false, true},
507 {mmPA_SC_RASTER_CONFIG_1, false, true},
508};
509
510static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
511 u32 sh_num, u32 reg_offset)
512{
513 uint32_t val;
514
515 mutex_lock(&adev->grbm_idx_mutex);
516 if (se_num != 0xffffffff || sh_num != 0xffffffff)
517 gfx_v8_0_select_se_sh(adev, se_num, sh_num);
518
519 val = RREG32(reg_offset);
520
521 if (se_num != 0xffffffff || sh_num != 0xffffffff)
522 gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
523 mutex_unlock(&adev->grbm_idx_mutex);
524 return val;
525}
526
527static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
528 u32 sh_num, u32 reg_offset, u32 *value)
529{
Nils Wallméniuseca22402016-03-19 16:12:17 +0100530 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
531 const struct amdgpu_allowed_register_entry *asic_register_entry;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400532 uint32_t size, i;
533
534 *value = 0;
535 switch (adev->asic_type) {
536 case CHIP_TOPAZ:
537 asic_register_table = tonga_allowed_read_registers;
538 size = ARRAY_SIZE(tonga_allowed_read_registers);
539 break;
David Zhang48299f92015-07-08 01:05:16 +0800540 case CHIP_FIJI:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400541 case CHIP_TONGA:
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400542 case CHIP_POLARIS11:
543 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400544 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -0400545 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400546 asic_register_table = cz_allowed_read_registers;
547 size = ARRAY_SIZE(cz_allowed_read_registers);
548 break;
549 default:
550 return -EINVAL;
551 }
552
553 if (asic_register_table) {
554 for (i = 0; i < size; i++) {
555 asic_register_entry = asic_register_table + i;
556 if (reg_offset != asic_register_entry->reg_offset)
557 continue;
558 if (!asic_register_entry->untouched)
559 *value = asic_register_entry->grbm_indexed ?
560 vi_read_indexed_register(adev, se_num,
561 sh_num, reg_offset) :
562 RREG32(reg_offset);
563 return 0;
564 }
565 }
566
567 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
568 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
569 continue;
570
571 if (!vi_allowed_read_registers[i].untouched)
572 *value = vi_allowed_read_registers[i].grbm_indexed ?
573 vi_read_indexed_register(adev, se_num,
574 sh_num, reg_offset) :
575 RREG32(reg_offset);
576 return 0;
577 }
578 return -EINVAL;
579}
580
Alex Deucheraaa36a92015-04-20 17:31:14 -0400581static void vi_gpu_pci_config_reset(struct amdgpu_device *adev)
582{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400583 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400584
585 dev_info(adev->dev, "GPU pci config reset\n");
586
Alex Deucheraaa36a92015-04-20 17:31:14 -0400587 /* disable BM */
588 pci_clear_master(adev->pdev);
589 /* reset */
590 amdgpu_pci_config_reset(adev);
591
592 udelay(100);
593
594 /* wait for asic to come out of reset */
595 for (i = 0; i < adev->usec_timeout; i++) {
596 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
597 break;
598 udelay(1);
599 }
600
601}
602
603static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
604{
605 u32 tmp = RREG32(mmBIOS_SCRATCH_3);
606
607 if (hung)
608 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
609 else
610 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
611
612 WREG32(mmBIOS_SCRATCH_3, tmp);
613}
614
615/**
616 * vi_asic_reset - soft reset GPU
617 *
618 * @adev: amdgpu_device pointer
619 *
620 * Look up which blocks are hung and attempt
621 * to reset them.
622 * Returns 0 for success.
623 */
624static int vi_asic_reset(struct amdgpu_device *adev)
625{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400626 vi_set_bios_scratch_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400627
Alex Deuchera2c5c692015-10-14 09:39:37 -0400628 vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400629
Alex Deuchera2c5c692015-10-14 09:39:37 -0400630 vi_set_bios_scratch_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400631
632 return 0;
633}
634
635static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
636 u32 cntl_reg, u32 status_reg)
637{
638 int r, i;
639 struct atom_clock_dividers dividers;
640 uint32_t tmp;
641
642 r = amdgpu_atombios_get_clock_dividers(adev,
643 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
644 clock, false, &dividers);
645 if (r)
646 return r;
647
648 tmp = RREG32_SMC(cntl_reg);
649 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
650 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
651 tmp |= dividers.post_divider;
652 WREG32_SMC(cntl_reg, tmp);
653
654 for (i = 0; i < 100; i++) {
655 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
656 break;
657 mdelay(10);
658 }
659 if (i == 100)
660 return -ETIMEDOUT;
661
662 return 0;
663}
664
665static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
666{
667 int r;
668
669 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
670 if (r)
671 return r;
672
673 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
674
675 return 0;
676}
677
678static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
679{
680 /* todo */
681
682 return 0;
683}
684
685static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
686{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400687 if (pci_is_root_bus(adev->pdev->bus))
688 return;
689
Alex Deucheraaa36a92015-04-20 17:31:14 -0400690 if (amdgpu_pcie_gen2 == 0)
691 return;
692
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800693 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400694 return;
695
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500696 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
697 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400698 return;
699
700 /* todo */
701}
702
703static void vi_program_aspm(struct amdgpu_device *adev)
704{
705
706 if (amdgpu_aspm == 0)
707 return;
708
709 /* todo */
710}
711
712static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
713 bool enable)
714{
715 u32 tmp;
716
717 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800718 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400719 return;
720
721 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
722 if (enable)
723 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
724 else
725 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
726
727 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
728}
729
730/* topaz has no DCE, UVD, VCE */
731static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
732{
733 /* ORDER MATTERS! */
734 {
yanyang15fc3aee2015-05-22 14:39:35 -0400735 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400736 .major = 2,
737 .minor = 0,
738 .rev = 0,
739 .funcs = &vi_common_ip_funcs,
740 },
741 {
yanyang15fc3aee2015-05-22 14:39:35 -0400742 .type = AMD_IP_BLOCK_TYPE_GMC,
Ken Wang429c45d2016-02-03 19:16:54 +0800743 .major = 7,
744 .minor = 4,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400745 .rev = 0,
Ken Wang429c45d2016-02-03 19:16:54 +0800746 .funcs = &gmc_v7_0_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400747 },
748 {
yanyang15fc3aee2015-05-22 14:39:35 -0400749 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400750 .major = 2,
751 .minor = 4,
752 .rev = 0,
753 .funcs = &iceland_ih_ip_funcs,
754 },
755 {
yanyang15fc3aee2015-05-22 14:39:35 -0400756 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400757 .major = 7,
758 .minor = 1,
759 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500760 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400761 },
762 {
yanyang15fc3aee2015-05-22 14:39:35 -0400763 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400764 .major = 8,
765 .minor = 0,
766 .rev = 0,
767 .funcs = &gfx_v8_0_ip_funcs,
768 },
769 {
yanyang15fc3aee2015-05-22 14:39:35 -0400770 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400771 .major = 2,
772 .minor = 4,
773 .rev = 0,
774 .funcs = &sdma_v2_4_ip_funcs,
775 },
776};
777
778static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
779{
780 /* ORDER MATTERS! */
781 {
yanyang15fc3aee2015-05-22 14:39:35 -0400782 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400783 .major = 2,
784 .minor = 0,
785 .rev = 0,
786 .funcs = &vi_common_ip_funcs,
787 },
788 {
yanyang15fc3aee2015-05-22 14:39:35 -0400789 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400790 .major = 8,
791 .minor = 0,
792 .rev = 0,
793 .funcs = &gmc_v8_0_ip_funcs,
794 },
795 {
yanyang15fc3aee2015-05-22 14:39:35 -0400796 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400797 .major = 3,
798 .minor = 0,
799 .rev = 0,
800 .funcs = &tonga_ih_ip_funcs,
801 },
802 {
yanyang15fc3aee2015-05-22 14:39:35 -0400803 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400804 .major = 7,
805 .minor = 1,
806 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500807 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400808 },
809 {
yanyang15fc3aee2015-05-22 14:39:35 -0400810 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400811 .major = 10,
812 .minor = 0,
813 .rev = 0,
814 .funcs = &dce_v10_0_ip_funcs,
815 },
816 {
yanyang15fc3aee2015-05-22 14:39:35 -0400817 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400818 .major = 8,
819 .minor = 0,
820 .rev = 0,
821 .funcs = &gfx_v8_0_ip_funcs,
822 },
823 {
yanyang15fc3aee2015-05-22 14:39:35 -0400824 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400825 .major = 3,
826 .minor = 0,
827 .rev = 0,
828 .funcs = &sdma_v3_0_ip_funcs,
829 },
830 {
yanyang15fc3aee2015-05-22 14:39:35 -0400831 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400832 .major = 5,
833 .minor = 0,
834 .rev = 0,
835 .funcs = &uvd_v5_0_ip_funcs,
836 },
837 {
yanyang15fc3aee2015-05-22 14:39:35 -0400838 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400839 .major = 3,
840 .minor = 0,
841 .rev = 0,
842 .funcs = &vce_v3_0_ip_funcs,
843 },
844};
845
David Zhang48299f92015-07-08 01:05:16 +0800846static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
847{
848 /* ORDER MATTERS! */
849 {
850 .type = AMD_IP_BLOCK_TYPE_COMMON,
851 .major = 2,
852 .minor = 0,
853 .rev = 0,
854 .funcs = &vi_common_ip_funcs,
David Zhang127a2622015-07-08 01:11:52 +0800855 },
856 {
857 .type = AMD_IP_BLOCK_TYPE_GMC,
858 .major = 8,
859 .minor = 5,
860 .rev = 0,
861 .funcs = &gmc_v8_0_ip_funcs,
862 },
David Zhangaa8a3b52015-07-08 21:40:31 +0800863 {
864 .type = AMD_IP_BLOCK_TYPE_IH,
865 .major = 3,
866 .minor = 0,
867 .rev = 0,
868 .funcs = &tonga_ih_ip_funcs,
869 },
David Zhang8e711e1a2015-07-08 01:23:25 +0800870 {
871 .type = AMD_IP_BLOCK_TYPE_SMC,
872 .major = 7,
873 .minor = 1,
874 .rev = 0,
Eric Huang899fa4c2015-09-29 14:58:53 -0400875 .funcs = &amdgpu_pp_ip_funcs,
David Zhang8e711e1a2015-07-08 01:23:25 +0800876 },
David Zhang84390862015-07-08 01:28:20 +0800877 {
878 .type = AMD_IP_BLOCK_TYPE_DCE,
879 .major = 10,
880 .minor = 1,
881 .rev = 0,
882 .funcs = &dce_v10_0_ip_funcs,
883 },
David Zhangaf15a2d2015-07-30 19:42:11 -0400884 {
885 .type = AMD_IP_BLOCK_TYPE_GFX,
886 .major = 8,
887 .minor = 0,
888 .rev = 0,
889 .funcs = &gfx_v8_0_ip_funcs,
890 },
David Zhang1a5bbb62015-07-08 17:29:27 +0800891 {
892 .type = AMD_IP_BLOCK_TYPE_SDMA,
893 .major = 3,
894 .minor = 0,
895 .rev = 0,
896 .funcs = &sdma_v3_0_ip_funcs,
897 },
David Zhang974ee3d2015-07-08 17:32:15 +0800898 {
899 .type = AMD_IP_BLOCK_TYPE_UVD,
900 .major = 6,
901 .minor = 0,
902 .rev = 0,
903 .funcs = &uvd_v6_0_ip_funcs,
904 },
Alex Deucher188a9bc2015-07-27 14:24:14 -0400905 {
906 .type = AMD_IP_BLOCK_TYPE_VCE,
907 .major = 3,
908 .minor = 0,
909 .rev = 0,
910 .funcs = &vce_v3_0_ip_funcs,
911 },
David Zhang48299f92015-07-08 01:05:16 +0800912};
913
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400914static const struct amdgpu_ip_block_version polaris11_ip_blocks[] =
Flora Cuic0c1f572015-12-07 18:33:10 +0800915{
916 /* ORDER MATTERS! */
917 {
918 .type = AMD_IP_BLOCK_TYPE_COMMON,
919 .major = 2,
920 .minor = 0,
921 .rev = 0,
922 .funcs = &vi_common_ip_funcs,
923 },
924 {
925 .type = AMD_IP_BLOCK_TYPE_GMC,
926 .major = 8,
927 .minor = 1,
928 .rev = 0,
929 .funcs = &gmc_v8_0_ip_funcs,
930 },
931 {
932 .type = AMD_IP_BLOCK_TYPE_IH,
933 .major = 3,
934 .minor = 1,
935 .rev = 0,
936 .funcs = &tonga_ih_ip_funcs,
937 },
938 {
939 .type = AMD_IP_BLOCK_TYPE_SMC,
940 .major = 7,
941 .minor = 2,
942 .rev = 0,
943 .funcs = &amdgpu_pp_ip_funcs,
944 },
945 {
946 .type = AMD_IP_BLOCK_TYPE_DCE,
947 .major = 11,
948 .minor = 2,
949 .rev = 0,
950 .funcs = &dce_v11_0_ip_funcs,
951 },
952 {
953 .type = AMD_IP_BLOCK_TYPE_GFX,
954 .major = 8,
955 .minor = 0,
956 .rev = 0,
957 .funcs = &gfx_v8_0_ip_funcs,
958 },
959 {
960 .type = AMD_IP_BLOCK_TYPE_SDMA,
961 .major = 3,
962 .minor = 1,
963 .rev = 0,
964 .funcs = &sdma_v3_0_ip_funcs,
965 },
966 {
967 .type = AMD_IP_BLOCK_TYPE_UVD,
968 .major = 6,
969 .minor = 3,
970 .rev = 0,
971 .funcs = &uvd_v6_0_ip_funcs,
972 },
973 {
974 .type = AMD_IP_BLOCK_TYPE_VCE,
975 .major = 3,
976 .minor = 4,
977 .rev = 0,
978 .funcs = &vce_v3_0_ip_funcs,
979 },
980};
981
Alex Deucheraaa36a92015-04-20 17:31:14 -0400982static const struct amdgpu_ip_block_version cz_ip_blocks[] =
983{
984 /* ORDER MATTERS! */
985 {
yanyang15fc3aee2015-05-22 14:39:35 -0400986 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400987 .major = 2,
988 .minor = 0,
989 .rev = 0,
990 .funcs = &vi_common_ip_funcs,
991 },
992 {
yanyang15fc3aee2015-05-22 14:39:35 -0400993 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400994 .major = 8,
995 .minor = 0,
996 .rev = 0,
997 .funcs = &gmc_v8_0_ip_funcs,
998 },
999 {
yanyang15fc3aee2015-05-22 14:39:35 -04001000 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001001 .major = 3,
1002 .minor = 0,
1003 .rev = 0,
1004 .funcs = &cz_ih_ip_funcs,
1005 },
1006 {
yanyang15fc3aee2015-05-22 14:39:35 -04001007 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001008 .major = 8,
1009 .minor = 0,
1010 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -05001011 .funcs = &amdgpu_pp_ip_funcs
Alex Deucheraaa36a92015-04-20 17:31:14 -04001012 },
1013 {
yanyang15fc3aee2015-05-22 14:39:35 -04001014 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001015 .major = 11,
1016 .minor = 0,
1017 .rev = 0,
1018 .funcs = &dce_v11_0_ip_funcs,
1019 },
1020 {
yanyang15fc3aee2015-05-22 14:39:35 -04001021 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001022 .major = 8,
1023 .minor = 0,
1024 .rev = 0,
1025 .funcs = &gfx_v8_0_ip_funcs,
1026 },
1027 {
yanyang15fc3aee2015-05-22 14:39:35 -04001028 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001029 .major = 3,
1030 .minor = 0,
1031 .rev = 0,
1032 .funcs = &sdma_v3_0_ip_funcs,
1033 },
1034 {
yanyang15fc3aee2015-05-22 14:39:35 -04001035 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001036 .major = 6,
1037 .minor = 0,
1038 .rev = 0,
1039 .funcs = &uvd_v6_0_ip_funcs,
1040 },
1041 {
yanyang15fc3aee2015-05-22 14:39:35 -04001042 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001043 .major = 3,
1044 .minor = 0,
1045 .rev = 0,
1046 .funcs = &vce_v3_0_ip_funcs,
1047 },
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001048#if defined(CONFIG_DRM_AMD_ACP)
1049 {
1050 .type = AMD_IP_BLOCK_TYPE_ACP,
1051 .major = 2,
1052 .minor = 2,
1053 .rev = 0,
1054 .funcs = &acp_ip_funcs,
1055 },
1056#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -04001057};
1058
1059int vi_set_ip_blocks(struct amdgpu_device *adev)
1060{
1061 switch (adev->asic_type) {
1062 case CHIP_TOPAZ:
1063 adev->ip_blocks = topaz_ip_blocks;
1064 adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
1065 break;
David Zhang48299f92015-07-08 01:05:16 +08001066 case CHIP_FIJI:
1067 adev->ip_blocks = fiji_ip_blocks;
1068 adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
1069 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001070 case CHIP_TONGA:
1071 adev->ip_blocks = tonga_ip_blocks;
1072 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
1073 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001074 case CHIP_POLARIS11:
1075 case CHIP_POLARIS10:
1076 adev->ip_blocks = polaris11_ip_blocks;
1077 adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks);
Flora Cuic0c1f572015-12-07 18:33:10 +08001078 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001079 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -04001080 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001081 adev->ip_blocks = cz_ip_blocks;
1082 adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
1083 break;
1084 default:
1085 /* FIXME: not supported yet */
1086 return -EINVAL;
1087 }
1088
Alex Deucheraaa36a92015-04-20 17:31:14 -04001089 return 0;
1090}
1091
Samuel Li39bb0c92015-10-08 16:31:43 -04001092#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
1093#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
1094#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
1095
Alex Deucheraaa36a92015-04-20 17:31:14 -04001096static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
1097{
Flora Cuiabdfb852015-11-20 11:40:53 +08001098 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -04001099 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
1100 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001101 else
Flora Cuiabdfb852015-11-20 11:40:53 +08001102 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
1103 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001104}
1105
1106static const struct amdgpu_asic_funcs vi_asic_funcs =
1107{
1108 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -05001109 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001110 .read_register = &vi_read_register,
1111 .reset = &vi_asic_reset,
1112 .set_vga_state = &vi_vga_set_state,
1113 .get_xclk = &vi_get_xclk,
1114 .set_uvd_clocks = &vi_set_uvd_clocks,
1115 .set_vce_clocks = &vi_set_vce_clocks,
1116 .get_cu_info = &gfx_v8_0_get_cu_info,
1117 /* these should be moved to their own ip modules */
1118 .get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
1119 .wait_for_mc_idle = &gmc_v8_0_mc_wait_for_idle,
1120};
1121
yanyang15fc3aee2015-05-22 14:39:35 -04001122static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001123{
1124 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -04001125 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001126
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001127 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -04001128 adev->smc_rreg = &cz_smc_rreg;
1129 adev->smc_wreg = &cz_smc_wreg;
1130 } else {
1131 adev->smc_rreg = &vi_smc_rreg;
1132 adev->smc_wreg = &vi_smc_wreg;
1133 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001134 adev->pcie_rreg = &vi_pcie_rreg;
1135 adev->pcie_wreg = &vi_pcie_wreg;
1136 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
1137 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
1138 adev->didt_rreg = &vi_didt_rreg;
1139 adev->didt_wreg = &vi_didt_wreg;
1140
1141 adev->asic_funcs = &vi_asic_funcs;
1142
yanyang15fc3aee2015-05-22 14:39:35 -04001143 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
1144 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -04001145 smc_enabled = true;
1146
1147 adev->rev_id = vi_get_rev_id(adev);
1148 adev->external_rev_id = 0xFF;
1149 switch (adev->asic_type) {
1150 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001151 adev->cg_flags = 0;
1152 adev->pg_flags = 0;
1153 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001154 break;
David Zhang48299f92015-07-08 01:05:16 +08001155 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -04001156 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1157 AMD_CG_SUPPORT_GFX_MGLS |
1158 AMD_CG_SUPPORT_GFX_RLC_LS |
1159 AMD_CG_SUPPORT_GFX_CP_LS |
1160 AMD_CG_SUPPORT_GFX_CGTS |
1161 AMD_CG_SUPPORT_GFX_CGTS_LS |
1162 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -04001163 AMD_CG_SUPPORT_GFX_CGLS |
1164 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -04001165 AMD_CG_SUPPORT_SDMA_LS |
1166 AMD_CG_SUPPORT_BIF_LS |
1167 AMD_CG_SUPPORT_HDP_MGCG |
1168 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -04001169 AMD_CG_SUPPORT_ROM_MGCG |
1170 AMD_CG_SUPPORT_MC_MGCG |
1171 AMD_CG_SUPPORT_MC_LS;
Flora Cuib6bc28f2015-11-02 21:21:34 +08001172 adev->pg_flags = 0;
1173 adev->external_rev_id = adev->rev_id + 0x3c;
1174 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001175 case CHIP_TONGA:
Tom St Denis5f64e772016-03-23 13:16:13 -04001176 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001177 adev->pg_flags = 0;
1178 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001179 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001180 case CHIP_POLARIS11:
Flora Cuic0c1f572015-12-07 18:33:10 +08001181 adev->cg_flags = 0;
1182 adev->pg_flags = 0;
1183 adev->external_rev_id = adev->rev_id + 0x5A;
1184 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001185 case CHIP_POLARIS10:
Flora Cuic0c1f572015-12-07 18:33:10 +08001186 adev->cg_flags = 0;
1187 adev->pg_flags = 0;
1188 adev->external_rev_id = adev->rev_id + 0x50;
1189 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001190 case CHIP_CARRIZO:
Alex Deucher70eced92016-04-07 23:01:48 -04001191 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1192 AMD_CG_SUPPORT_GFX_MGLS |
1193 AMD_CG_SUPPORT_GFX_RLC_LS |
1194 AMD_CG_SUPPORT_GFX_CP_LS |
1195 AMD_CG_SUPPORT_GFX_CGTS |
1196 AMD_CG_SUPPORT_GFX_MGLS |
1197 AMD_CG_SUPPORT_GFX_CGTS_LS |
1198 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001199 AMD_CG_SUPPORT_GFX_CGLS |
1200 AMD_CG_SUPPORT_BIF_LS |
1201 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001202 AMD_CG_SUPPORT_HDP_LS |
1203 AMD_CG_SUPPORT_SDMA_MGCG |
1204 AMD_CG_SUPPORT_SDMA_LS;
Alex Deucher0fd4af92016-02-04 23:31:32 -05001205 adev->pg_flags = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001206 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001207 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001208 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001209 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1210 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001211 AMD_CG_SUPPORT_GFX_MGLS |
1212 AMD_CG_SUPPORT_BIF_LS |
1213 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001214 AMD_CG_SUPPORT_HDP_LS |
1215 AMD_CG_SUPPORT_SDMA_MGCG |
1216 AMD_CG_SUPPORT_SDMA_LS;
Tom St Deniscde64932016-03-23 13:17:04 -04001217 adev->pg_flags = 0;
1218 adev->external_rev_id = adev->rev_id + 0x1;
1219 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001220 default:
1221 /* FIXME: not supported yet */
1222 return -EINVAL;
1223 }
1224
Flora Cuia3d08fa2015-11-02 21:15:55 +08001225 if (amdgpu_smc_load_fw && smc_enabled)
1226 adev->firmware.smu_load = true;
1227
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001228 amdgpu_get_pcie_info(adev);
1229
Alex Deucheraaa36a92015-04-20 17:31:14 -04001230 return 0;
1231}
1232
yanyang15fc3aee2015-05-22 14:39:35 -04001233static int vi_common_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001234{
1235 return 0;
1236}
1237
yanyang15fc3aee2015-05-22 14:39:35 -04001238static int vi_common_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001239{
1240 return 0;
1241}
1242
yanyang15fc3aee2015-05-22 14:39:35 -04001243static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001244{
yanyang15fc3aee2015-05-22 14:39:35 -04001245 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1246
Alex Deucheraaa36a92015-04-20 17:31:14 -04001247 /* move the golden regs per IP block */
1248 vi_init_golden_registers(adev);
1249 /* enable pcie gen2/3 link */
1250 vi_pcie_gen3_enable(adev);
1251 /* enable aspm */
1252 vi_program_aspm(adev);
1253 /* enable the doorbell aperture */
1254 vi_enable_doorbell_aperture(adev, true);
1255
1256 return 0;
1257}
1258
yanyang15fc3aee2015-05-22 14:39:35 -04001259static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001260{
yanyang15fc3aee2015-05-22 14:39:35 -04001261 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1262
Alex Deucheraaa36a92015-04-20 17:31:14 -04001263 /* enable the doorbell aperture */
1264 vi_enable_doorbell_aperture(adev, false);
1265
1266 return 0;
1267}
1268
yanyang15fc3aee2015-05-22 14:39:35 -04001269static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001270{
yanyang15fc3aee2015-05-22 14:39:35 -04001271 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1272
Alex Deucheraaa36a92015-04-20 17:31:14 -04001273 return vi_common_hw_fini(adev);
1274}
1275
yanyang15fc3aee2015-05-22 14:39:35 -04001276static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001277{
yanyang15fc3aee2015-05-22 14:39:35 -04001278 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1279
Alex Deucheraaa36a92015-04-20 17:31:14 -04001280 return vi_common_hw_init(adev);
1281}
1282
yanyang15fc3aee2015-05-22 14:39:35 -04001283static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001284{
1285 return true;
1286}
1287
yanyang15fc3aee2015-05-22 14:39:35 -04001288static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001289{
1290 return 0;
1291}
1292
yanyang15fc3aee2015-05-22 14:39:35 -04001293static void vi_common_print_status(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001294{
yanyang15fc3aee2015-05-22 14:39:35 -04001295 return;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001296}
1297
yanyang15fc3aee2015-05-22 14:39:35 -04001298static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001299{
1300 return 0;
1301}
1302
Alex Deucher76f10b92016-04-08 01:37:44 -04001303static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1304 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001305{
1306 uint32_t temp, data;
1307
1308 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1309
Alex Deucherc90766c2016-04-08 00:52:58 -04001310 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001311 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1312 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1313 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1314 else
1315 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1316 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1317 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1318
1319 if (temp != data)
1320 WREG32_PCIE(ixPCIE_CNTL2, data);
1321}
1322
Alex Deucher76f10b92016-04-08 01:37:44 -04001323static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1324 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001325{
1326 uint32_t temp, data;
1327
1328 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1329
Alex Deucherc90766c2016-04-08 00:52:58 -04001330 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001331 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1332 else
1333 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1334
1335 if (temp != data)
1336 WREG32(mmHDP_HOST_PATH_CNTL, data);
1337}
1338
Alex Deucher76f10b92016-04-08 01:37:44 -04001339static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1340 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001341{
1342 uint32_t temp, data;
1343
1344 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1345
Alex Deucherc90766c2016-04-08 00:52:58 -04001346 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001347 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1348 else
1349 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1350
1351 if (temp != data)
1352 WREG32(mmHDP_MEM_POWER_LS, data);
1353}
1354
Alex Deucher76f10b92016-04-08 01:37:44 -04001355static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1356 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001357{
1358 uint32_t temp, data;
1359
1360 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1361
Alex Deucherc90766c2016-04-08 00:52:58 -04001362 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001363 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1364 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1365 else
1366 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1367 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1368
1369 if (temp != data)
1370 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1371}
1372
yanyang15fc3aee2015-05-22 14:39:35 -04001373static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001374 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001375{
Eric Huang6cec2652015-11-12 16:59:47 -05001376 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1377
1378 switch (adev->asic_type) {
1379 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001380 vi_update_bif_medium_grain_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001381 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001382 vi_update_hdp_medium_grain_clock_gating(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001383 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001384 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001385 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001386 vi_update_rom_medium_grain_clock_gating(adev,
1387 state == AMD_CG_STATE_GATE ? true : false);
1388 break;
1389 case CHIP_CARRIZO:
1390 case CHIP_STONEY:
1391 vi_update_bif_medium_grain_light_sleep(adev,
1392 state == AMD_CG_STATE_GATE ? true : false);
1393 vi_update_hdp_medium_grain_clock_gating(adev,
1394 state == AMD_CG_STATE_GATE ? true : false);
1395 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001396 state == AMD_CG_STATE_GATE ? true : false);
1397 break;
1398 default:
1399 break;
1400 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001401 return 0;
1402}
1403
yanyang15fc3aee2015-05-22 14:39:35 -04001404static int vi_common_set_powergating_state(void *handle,
1405 enum amd_powergating_state state)
1406{
1407 return 0;
1408}
1409
1410const struct amd_ip_funcs vi_common_ip_funcs = {
Alex Deucheraaa36a92015-04-20 17:31:14 -04001411 .early_init = vi_common_early_init,
1412 .late_init = NULL,
1413 .sw_init = vi_common_sw_init,
1414 .sw_fini = vi_common_sw_fini,
1415 .hw_init = vi_common_hw_init,
1416 .hw_fini = vi_common_hw_fini,
1417 .suspend = vi_common_suspend,
1418 .resume = vi_common_resume,
1419 .is_idle = vi_common_is_idle,
1420 .wait_for_idle = vi_common_wait_for_idle,
1421 .soft_reset = vi_common_soft_reset,
1422 .print_status = vi_common_print_status,
1423 .set_clockgating_state = vi_common_set_clockgating_state,
1424 .set_powergating_state = vi_common_set_powergating_state,
1425};
1426