blob: 0bd567d339a3ad14ff75c38c7a36d21f3de66419 [file] [log] [blame]
Alex Deucheraaa36a92015-04-20 17:31:14 -04001/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23#include <linux/firmware.h>
24#include <linux/slab.h>
25#include <linux/module.h>
26#include "drmP.h"
27#include "amdgpu.h"
28#include "amdgpu_atombios.h"
29#include "amdgpu_ih.h"
30#include "amdgpu_uvd.h"
31#include "amdgpu_vce.h"
32#include "amdgpu_ucode.h"
33#include "atom.h"
Alex Deucherd0dd7f02015-11-11 19:45:06 -050034#include "amd_pcie.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040035
36#include "gmc/gmc_8_1_d.h"
37#include "gmc/gmc_8_1_sh_mask.h"
38
39#include "oss/oss_3_0_d.h"
40#include "oss/oss_3_0_sh_mask.h"
41
42#include "bif/bif_5_0_d.h"
43#include "bif/bif_5_0_sh_mask.h"
44
45#include "gca/gfx_8_0_d.h"
46#include "gca/gfx_8_0_sh_mask.h"
47
48#include "smu/smu_7_1_1_d.h"
49#include "smu/smu_7_1_1_sh_mask.h"
50
51#include "uvd/uvd_5_0_d.h"
52#include "uvd/uvd_5_0_sh_mask.h"
53
54#include "vce/vce_3_0_d.h"
55#include "vce/vce_3_0_sh_mask.h"
56
57#include "dce/dce_10_0_d.h"
58#include "dce/dce_10_0_sh_mask.h"
59
60#include "vid.h"
61#include "vi.h"
62#include "vi_dpm.h"
63#include "gmc_v8_0.h"
Ken Wang429c45d2016-02-03 19:16:54 +080064#include "gmc_v7_0.h"
Alex Deucheraaa36a92015-04-20 17:31:14 -040065#include "gfx_v8_0.h"
66#include "sdma_v2_4.h"
67#include "sdma_v3_0.h"
68#include "dce_v10_0.h"
69#include "dce_v11_0.h"
70#include "iceland_ih.h"
71#include "tonga_ih.h"
72#include "cz_ih.h"
73#include "uvd_v5_0.h"
74#include "uvd_v6_0.h"
75#include "vce_v3_0.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050076#include "amdgpu_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040077#if defined(CONFIG_DRM_AMD_ACP)
78#include "amdgpu_acp.h"
79#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -040080
Flora Cuif8951062016-03-18 19:07:55 +080081MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
82MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
83MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
84MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
85
Alex Deucheraaa36a92015-04-20 17:31:14 -040086/*
87 * Indirect registers accessor
88 */
89static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
90{
91 unsigned long flags;
92 u32 r;
93
94 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
95 WREG32(mmPCIE_INDEX, reg);
96 (void)RREG32(mmPCIE_INDEX);
97 r = RREG32(mmPCIE_DATA);
98 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
99 return r;
100}
101
102static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
103{
104 unsigned long flags;
105
106 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
107 WREG32(mmPCIE_INDEX, reg);
108 (void)RREG32(mmPCIE_INDEX);
109 WREG32(mmPCIE_DATA, v);
110 (void)RREG32(mmPCIE_DATA);
111 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
112}
113
114static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
115{
116 unsigned long flags;
117 u32 r;
118
119 spin_lock_irqsave(&adev->smc_idx_lock, flags);
120 WREG32(mmSMC_IND_INDEX_0, (reg));
121 r = RREG32(mmSMC_IND_DATA_0);
122 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
123 return r;
124}
125
126static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
127{
128 unsigned long flags;
129
130 spin_lock_irqsave(&adev->smc_idx_lock, flags);
131 WREG32(mmSMC_IND_INDEX_0, (reg));
132 WREG32(mmSMC_IND_DATA_0, (v));
133 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
134}
135
Alex Deucher7b92cdb2015-07-10 16:21:10 -0400136/* smu_8_0_d.h */
137#define mmMP0PUB_IND_INDEX 0x180
138#define mmMP0PUB_IND_DATA 0x181
139
140static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
141{
142 unsigned long flags;
143 u32 r;
144
145 spin_lock_irqsave(&adev->smc_idx_lock, flags);
146 WREG32(mmMP0PUB_IND_INDEX, (reg));
147 r = RREG32(mmMP0PUB_IND_DATA);
148 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
149 return r;
150}
151
152static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&adev->smc_idx_lock, flags);
157 WREG32(mmMP0PUB_IND_INDEX, (reg));
158 WREG32(mmMP0PUB_IND_DATA, (v));
159 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
160}
161
Alex Deucheraaa36a92015-04-20 17:31:14 -0400162static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
163{
164 unsigned long flags;
165 u32 r;
166
167 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
168 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
169 r = RREG32(mmUVD_CTX_DATA);
170 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
171 return r;
172}
173
174static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
175{
176 unsigned long flags;
177
178 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
179 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
180 WREG32(mmUVD_CTX_DATA, (v));
181 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
182}
183
184static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
185{
186 unsigned long flags;
187 u32 r;
188
189 spin_lock_irqsave(&adev->didt_idx_lock, flags);
190 WREG32(mmDIDT_IND_INDEX, (reg));
191 r = RREG32(mmDIDT_IND_DATA);
192 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
193 return r;
194}
195
196static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
197{
198 unsigned long flags;
199
200 spin_lock_irqsave(&adev->didt_idx_lock, flags);
201 WREG32(mmDIDT_IND_INDEX, (reg));
202 WREG32(mmDIDT_IND_DATA, (v));
203 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
204}
205
206static const u32 tonga_mgcg_cgcg_init[] =
207{
208 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
209 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
210 mmPCIE_DATA, 0x000f0000, 0x00000000,
211 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
212 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400213 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
214 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
215};
216
David Zhang48299f92015-07-08 01:05:16 +0800217static const u32 fiji_mgcg_cgcg_init[] =
218{
219 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
220 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
221 mmPCIE_DATA, 0x000f0000, 0x00000000,
222 mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
223 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
224 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
225 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
226};
227
Alex Deucheraaa36a92015-04-20 17:31:14 -0400228static const u32 iceland_mgcg_cgcg_init[] =
229{
230 mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
231 mmPCIE_DATA, 0x000f0000, 0x00000000,
232 mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
233 mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
234 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
235};
236
237static const u32 cz_mgcg_cgcg_init[] =
238{
239 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
240 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
241 mmPCIE_DATA, 0x000f0000, 0x00000000,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400242 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
243 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
244};
245
Samuel Li39bb0c92015-10-08 16:31:43 -0400246static const u32 stoney_mgcg_cgcg_init[] =
247{
248 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
249 mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
250 mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
251};
252
Alex Deucheraaa36a92015-04-20 17:31:14 -0400253static void vi_init_golden_registers(struct amdgpu_device *adev)
254{
255 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
256 mutex_lock(&adev->grbm_idx_mutex);
257
258 switch (adev->asic_type) {
259 case CHIP_TOPAZ:
260 amdgpu_program_register_sequence(adev,
261 iceland_mgcg_cgcg_init,
262 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
263 break;
David Zhang48299f92015-07-08 01:05:16 +0800264 case CHIP_FIJI:
265 amdgpu_program_register_sequence(adev,
266 fiji_mgcg_cgcg_init,
267 (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
268 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400269 case CHIP_TONGA:
270 amdgpu_program_register_sequence(adev,
271 tonga_mgcg_cgcg_init,
272 (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
273 break;
274 case CHIP_CARRIZO:
275 amdgpu_program_register_sequence(adev,
276 cz_mgcg_cgcg_init,
277 (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
278 break;
Samuel Li39bb0c92015-10-08 16:31:43 -0400279 case CHIP_STONEY:
280 amdgpu_program_register_sequence(adev,
281 stoney_mgcg_cgcg_init,
282 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
283 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400284 case CHIP_POLARIS11:
285 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400286 default:
287 break;
288 }
289 mutex_unlock(&adev->grbm_idx_mutex);
290}
291
292/**
293 * vi_get_xclk - get the xclk
294 *
295 * @adev: amdgpu_device pointer
296 *
297 * Returns the reference clock used by the gfx engine
298 * (VI).
299 */
300static u32 vi_get_xclk(struct amdgpu_device *adev)
301{
302 u32 reference_clock = adev->clock.spll.reference_freq;
303 u32 tmp;
304
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800305 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400306 return reference_clock;
307
308 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
309 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
310 return 1000;
311
312 tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
313 if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
314 return reference_clock / 4;
315
316 return reference_clock;
317}
318
319/**
320 * vi_srbm_select - select specific register instances
321 *
322 * @adev: amdgpu_device pointer
323 * @me: selected ME (micro engine)
324 * @pipe: pipe
325 * @queue: queue
326 * @vmid: VMID
327 *
328 * Switches the currently active registers instances. Some
329 * registers are instanced per VMID, others are instanced per
330 * me/pipe/queue combination.
331 */
332void vi_srbm_select(struct amdgpu_device *adev,
333 u32 me, u32 pipe, u32 queue, u32 vmid)
334{
335 u32 srbm_gfx_cntl = 0;
336 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
337 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
338 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
339 srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
340 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
341}
342
343static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
344{
345 /* todo */
346}
347
348static bool vi_read_disabled_bios(struct amdgpu_device *adev)
349{
350 u32 bus_cntl;
351 u32 d1vga_control = 0;
352 u32 d2vga_control = 0;
353 u32 vga_render_control = 0;
354 u32 rom_cntl;
355 bool r;
356
357 bus_cntl = RREG32(mmBUS_CNTL);
358 if (adev->mode_info.num_crtc) {
359 d1vga_control = RREG32(mmD1VGA_CONTROL);
360 d2vga_control = RREG32(mmD2VGA_CONTROL);
361 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
362 }
363 rom_cntl = RREG32_SMC(ixROM_CNTL);
364
365 /* enable the rom */
366 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
367 if (adev->mode_info.num_crtc) {
368 /* Disable VGA mode */
369 WREG32(mmD1VGA_CONTROL,
370 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
371 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
372 WREG32(mmD2VGA_CONTROL,
373 (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
374 D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
375 WREG32(mmVGA_RENDER_CONTROL,
376 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
377 }
378 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
379
380 r = amdgpu_read_bios(adev);
381
382 /* restore regs */
383 WREG32(mmBUS_CNTL, bus_cntl);
384 if (adev->mode_info.num_crtc) {
385 WREG32(mmD1VGA_CONTROL, d1vga_control);
386 WREG32(mmD2VGA_CONTROL, d2vga_control);
387 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
388 }
389 WREG32_SMC(ixROM_CNTL, rom_cntl);
390 return r;
391}
Alex Deucher95addb2a2015-11-24 10:37:54 -0500392
393static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
394 u8 *bios, u32 length_bytes)
395{
396 u32 *dw_ptr;
397 unsigned long flags;
398 u32 i, length_dw;
399
400 if (bios == NULL)
401 return false;
402 if (length_bytes == 0)
403 return false;
404 /* APU vbios image is part of sbios image */
405 if (adev->flags & AMD_IS_APU)
406 return false;
407
408 dw_ptr = (u32 *)bios;
409 length_dw = ALIGN(length_bytes, 4) / 4;
410 /* take the smc lock since we are using the smc index */
411 spin_lock_irqsave(&adev->smc_idx_lock, flags);
412 /* set rom index to 0 */
413 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
414 WREG32(mmSMC_IND_DATA_0, 0);
415 /* set index to data for continous read */
416 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
417 for (i = 0; i < length_dw; i++)
418 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
419 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
420
421 return true;
422}
423
Nils Wallméniuseca22402016-03-19 16:12:17 +0100424static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400425 {mmGB_MACROTILE_MODE7, true},
426};
427
Nils Wallméniuseca22402016-03-19 16:12:17 +0100428static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400429 {mmGB_TILE_MODE7, true},
430 {mmGB_TILE_MODE12, true},
431 {mmGB_TILE_MODE17, true},
432 {mmGB_TILE_MODE23, true},
433 {mmGB_MACROTILE_MODE7, true},
434};
435
Nils Wallméniuseca22402016-03-19 16:12:17 +0100436static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400437 {mmGRBM_STATUS, false},
Marek Olšákc7890fe2015-07-11 12:08:46 +0200438 {mmGRBM_STATUS2, false},
439 {mmGRBM_STATUS_SE0, false},
440 {mmGRBM_STATUS_SE1, false},
441 {mmGRBM_STATUS_SE2, false},
442 {mmGRBM_STATUS_SE3, false},
443 {mmSRBM_STATUS, false},
444 {mmSRBM_STATUS2, false},
445 {mmSRBM_STATUS3, false},
446 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
447 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
448 {mmCP_STAT, false},
449 {mmCP_STALLED_STAT1, false},
450 {mmCP_STALLED_STAT2, false},
451 {mmCP_STALLED_STAT3, false},
452 {mmCP_CPF_BUSY_STAT, false},
453 {mmCP_CPF_STALLED_STAT1, false},
454 {mmCP_CPF_STATUS, false},
455 {mmCP_CPC_BUSY_STAT, false},
456 {mmCP_CPC_STALLED_STAT1, false},
457 {mmCP_CPC_STATUS, false},
Alex Deucheraaa36a92015-04-20 17:31:14 -0400458 {mmGB_ADDR_CONFIG, false},
459 {mmMC_ARB_RAMCFG, false},
460 {mmGB_TILE_MODE0, false},
461 {mmGB_TILE_MODE1, false},
462 {mmGB_TILE_MODE2, false},
463 {mmGB_TILE_MODE3, false},
464 {mmGB_TILE_MODE4, false},
465 {mmGB_TILE_MODE5, false},
466 {mmGB_TILE_MODE6, false},
467 {mmGB_TILE_MODE7, false},
468 {mmGB_TILE_MODE8, false},
469 {mmGB_TILE_MODE9, false},
470 {mmGB_TILE_MODE10, false},
471 {mmGB_TILE_MODE11, false},
472 {mmGB_TILE_MODE12, false},
473 {mmGB_TILE_MODE13, false},
474 {mmGB_TILE_MODE14, false},
475 {mmGB_TILE_MODE15, false},
476 {mmGB_TILE_MODE16, false},
477 {mmGB_TILE_MODE17, false},
478 {mmGB_TILE_MODE18, false},
479 {mmGB_TILE_MODE19, false},
480 {mmGB_TILE_MODE20, false},
481 {mmGB_TILE_MODE21, false},
482 {mmGB_TILE_MODE22, false},
483 {mmGB_TILE_MODE23, false},
484 {mmGB_TILE_MODE24, false},
485 {mmGB_TILE_MODE25, false},
486 {mmGB_TILE_MODE26, false},
487 {mmGB_TILE_MODE27, false},
488 {mmGB_TILE_MODE28, false},
489 {mmGB_TILE_MODE29, false},
490 {mmGB_TILE_MODE30, false},
491 {mmGB_TILE_MODE31, false},
492 {mmGB_MACROTILE_MODE0, false},
493 {mmGB_MACROTILE_MODE1, false},
494 {mmGB_MACROTILE_MODE2, false},
495 {mmGB_MACROTILE_MODE3, false},
496 {mmGB_MACROTILE_MODE4, false},
497 {mmGB_MACROTILE_MODE5, false},
498 {mmGB_MACROTILE_MODE6, false},
499 {mmGB_MACROTILE_MODE7, false},
500 {mmGB_MACROTILE_MODE8, false},
501 {mmGB_MACROTILE_MODE9, false},
502 {mmGB_MACROTILE_MODE10, false},
503 {mmGB_MACROTILE_MODE11, false},
504 {mmGB_MACROTILE_MODE12, false},
505 {mmGB_MACROTILE_MODE13, false},
506 {mmGB_MACROTILE_MODE14, false},
507 {mmGB_MACROTILE_MODE15, false},
508 {mmCC_RB_BACKEND_DISABLE, false, true},
509 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
510 {mmGB_BACKEND_MAP, false, false},
511 {mmPA_SC_RASTER_CONFIG, false, true},
512 {mmPA_SC_RASTER_CONFIG_1, false, true},
513};
514
515static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
516 u32 sh_num, u32 reg_offset)
517{
518 uint32_t val;
519
520 mutex_lock(&adev->grbm_idx_mutex);
521 if (se_num != 0xffffffff || sh_num != 0xffffffff)
522 gfx_v8_0_select_se_sh(adev, se_num, sh_num);
523
524 val = RREG32(reg_offset);
525
526 if (se_num != 0xffffffff || sh_num != 0xffffffff)
527 gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
528 mutex_unlock(&adev->grbm_idx_mutex);
529 return val;
530}
531
532static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
533 u32 sh_num, u32 reg_offset, u32 *value)
534{
Nils Wallméniuseca22402016-03-19 16:12:17 +0100535 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
536 const struct amdgpu_allowed_register_entry *asic_register_entry;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400537 uint32_t size, i;
538
539 *value = 0;
540 switch (adev->asic_type) {
541 case CHIP_TOPAZ:
542 asic_register_table = tonga_allowed_read_registers;
543 size = ARRAY_SIZE(tonga_allowed_read_registers);
544 break;
David Zhang48299f92015-07-08 01:05:16 +0800545 case CHIP_FIJI:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400546 case CHIP_TONGA:
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400547 case CHIP_POLARIS11:
548 case CHIP_POLARIS10:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400549 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -0400550 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -0400551 asic_register_table = cz_allowed_read_registers;
552 size = ARRAY_SIZE(cz_allowed_read_registers);
553 break;
554 default:
555 return -EINVAL;
556 }
557
558 if (asic_register_table) {
559 for (i = 0; i < size; i++) {
560 asic_register_entry = asic_register_table + i;
561 if (reg_offset != asic_register_entry->reg_offset)
562 continue;
563 if (!asic_register_entry->untouched)
564 *value = asic_register_entry->grbm_indexed ?
565 vi_read_indexed_register(adev, se_num,
566 sh_num, reg_offset) :
567 RREG32(reg_offset);
568 return 0;
569 }
570 }
571
572 for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
573 if (reg_offset != vi_allowed_read_registers[i].reg_offset)
574 continue;
575
576 if (!vi_allowed_read_registers[i].untouched)
577 *value = vi_allowed_read_registers[i].grbm_indexed ?
578 vi_read_indexed_register(adev, se_num,
579 sh_num, reg_offset) :
580 RREG32(reg_offset);
581 return 0;
582 }
583 return -EINVAL;
584}
585
Alex Deucheraaa36a92015-04-20 17:31:14 -0400586static void vi_gpu_pci_config_reset(struct amdgpu_device *adev)
587{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400588 u32 i;
Alex Deucheraaa36a92015-04-20 17:31:14 -0400589
590 dev_info(adev->dev, "GPU pci config reset\n");
591
Alex Deucheraaa36a92015-04-20 17:31:14 -0400592 /* disable BM */
593 pci_clear_master(adev->pdev);
594 /* reset */
595 amdgpu_pci_config_reset(adev);
596
597 udelay(100);
598
599 /* wait for asic to come out of reset */
600 for (i = 0; i < adev->usec_timeout; i++) {
601 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
602 break;
603 udelay(1);
604 }
605
606}
607
608static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
609{
610 u32 tmp = RREG32(mmBIOS_SCRATCH_3);
611
612 if (hung)
613 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
614 else
615 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
616
617 WREG32(mmBIOS_SCRATCH_3, tmp);
618}
619
620/**
621 * vi_asic_reset - soft reset GPU
622 *
623 * @adev: amdgpu_device pointer
624 *
625 * Look up which blocks are hung and attempt
626 * to reset them.
627 * Returns 0 for success.
628 */
629static int vi_asic_reset(struct amdgpu_device *adev)
630{
Alex Deuchera2c5c692015-10-14 09:39:37 -0400631 vi_set_bios_scratch_engine_hung(adev, true);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400632
Alex Deuchera2c5c692015-10-14 09:39:37 -0400633 vi_gpu_pci_config_reset(adev);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400634
Alex Deuchera2c5c692015-10-14 09:39:37 -0400635 vi_set_bios_scratch_engine_hung(adev, false);
Alex Deucheraaa36a92015-04-20 17:31:14 -0400636
637 return 0;
638}
639
640static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
641 u32 cntl_reg, u32 status_reg)
642{
643 int r, i;
644 struct atom_clock_dividers dividers;
645 uint32_t tmp;
646
647 r = amdgpu_atombios_get_clock_dividers(adev,
648 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
649 clock, false, &dividers);
650 if (r)
651 return r;
652
653 tmp = RREG32_SMC(cntl_reg);
654 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
655 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
656 tmp |= dividers.post_divider;
657 WREG32_SMC(cntl_reg, tmp);
658
659 for (i = 0; i < 100; i++) {
660 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
661 break;
662 mdelay(10);
663 }
664 if (i == 100)
665 return -ETIMEDOUT;
666
667 return 0;
668}
669
670static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
671{
672 int r;
673
674 r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
675 if (r)
676 return r;
677
678 r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
679
680 return 0;
681}
682
683static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
684{
685 /* todo */
686
687 return 0;
688}
689
690static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
691{
Alex Deuchere79d5c02015-10-06 09:38:45 -0400692 if (pci_is_root_bus(adev->pdev->bus))
693 return;
694
Alex Deucheraaa36a92015-04-20 17:31:14 -0400695 if (amdgpu_pcie_gen2 == 0)
696 return;
697
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800698 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400699 return;
700
Alex Deucherd0dd7f02015-11-11 19:45:06 -0500701 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
702 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
Alex Deucheraaa36a92015-04-20 17:31:14 -0400703 return;
704
705 /* todo */
706}
707
708static void vi_program_aspm(struct amdgpu_device *adev)
709{
710
711 if (amdgpu_aspm == 0)
712 return;
713
714 /* todo */
715}
716
717static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
718 bool enable)
719{
720 u32 tmp;
721
722 /* not necessary on CZ */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800723 if (adev->flags & AMD_IS_APU)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400724 return;
725
726 tmp = RREG32(mmBIF_DOORBELL_APER_EN);
727 if (enable)
728 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
729 else
730 tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
731
732 WREG32(mmBIF_DOORBELL_APER_EN, tmp);
733}
734
735/* topaz has no DCE, UVD, VCE */
736static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
737{
738 /* ORDER MATTERS! */
739 {
yanyang15fc3aee2015-05-22 14:39:35 -0400740 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400741 .major = 2,
742 .minor = 0,
743 .rev = 0,
744 .funcs = &vi_common_ip_funcs,
745 },
746 {
yanyang15fc3aee2015-05-22 14:39:35 -0400747 .type = AMD_IP_BLOCK_TYPE_GMC,
Ken Wang429c45d2016-02-03 19:16:54 +0800748 .major = 7,
749 .minor = 4,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400750 .rev = 0,
Ken Wang429c45d2016-02-03 19:16:54 +0800751 .funcs = &gmc_v7_0_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400752 },
753 {
yanyang15fc3aee2015-05-22 14:39:35 -0400754 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400755 .major = 2,
756 .minor = 4,
757 .rev = 0,
758 .funcs = &iceland_ih_ip_funcs,
759 },
760 {
yanyang15fc3aee2015-05-22 14:39:35 -0400761 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400762 .major = 7,
763 .minor = 1,
764 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500765 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400766 },
767 {
yanyang15fc3aee2015-05-22 14:39:35 -0400768 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400769 .major = 8,
770 .minor = 0,
771 .rev = 0,
772 .funcs = &gfx_v8_0_ip_funcs,
773 },
774 {
yanyang15fc3aee2015-05-22 14:39:35 -0400775 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400776 .major = 2,
777 .minor = 4,
778 .rev = 0,
779 .funcs = &sdma_v2_4_ip_funcs,
780 },
781};
782
783static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
784{
785 /* ORDER MATTERS! */
786 {
yanyang15fc3aee2015-05-22 14:39:35 -0400787 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400788 .major = 2,
789 .minor = 0,
790 .rev = 0,
791 .funcs = &vi_common_ip_funcs,
792 },
793 {
yanyang15fc3aee2015-05-22 14:39:35 -0400794 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400795 .major = 8,
796 .minor = 0,
797 .rev = 0,
798 .funcs = &gmc_v8_0_ip_funcs,
799 },
800 {
yanyang15fc3aee2015-05-22 14:39:35 -0400801 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400802 .major = 3,
803 .minor = 0,
804 .rev = 0,
805 .funcs = &tonga_ih_ip_funcs,
806 },
807 {
yanyang15fc3aee2015-05-22 14:39:35 -0400808 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400809 .major = 7,
810 .minor = 1,
811 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500812 .funcs = &amdgpu_pp_ip_funcs,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400813 },
814 {
yanyang15fc3aee2015-05-22 14:39:35 -0400815 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400816 .major = 10,
817 .minor = 0,
818 .rev = 0,
819 .funcs = &dce_v10_0_ip_funcs,
820 },
821 {
yanyang15fc3aee2015-05-22 14:39:35 -0400822 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400823 .major = 8,
824 .minor = 0,
825 .rev = 0,
826 .funcs = &gfx_v8_0_ip_funcs,
827 },
828 {
yanyang15fc3aee2015-05-22 14:39:35 -0400829 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400830 .major = 3,
831 .minor = 0,
832 .rev = 0,
833 .funcs = &sdma_v3_0_ip_funcs,
834 },
835 {
yanyang15fc3aee2015-05-22 14:39:35 -0400836 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400837 .major = 5,
838 .minor = 0,
839 .rev = 0,
840 .funcs = &uvd_v5_0_ip_funcs,
841 },
842 {
yanyang15fc3aee2015-05-22 14:39:35 -0400843 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400844 .major = 3,
845 .minor = 0,
846 .rev = 0,
847 .funcs = &vce_v3_0_ip_funcs,
848 },
849};
850
David Zhang48299f92015-07-08 01:05:16 +0800851static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
852{
853 /* ORDER MATTERS! */
854 {
855 .type = AMD_IP_BLOCK_TYPE_COMMON,
856 .major = 2,
857 .minor = 0,
858 .rev = 0,
859 .funcs = &vi_common_ip_funcs,
David Zhang127a2622015-07-08 01:11:52 +0800860 },
861 {
862 .type = AMD_IP_BLOCK_TYPE_GMC,
863 .major = 8,
864 .minor = 5,
865 .rev = 0,
866 .funcs = &gmc_v8_0_ip_funcs,
867 },
David Zhangaa8a3b52015-07-08 21:40:31 +0800868 {
869 .type = AMD_IP_BLOCK_TYPE_IH,
870 .major = 3,
871 .minor = 0,
872 .rev = 0,
873 .funcs = &tonga_ih_ip_funcs,
874 },
David Zhang8e711e1a2015-07-08 01:23:25 +0800875 {
876 .type = AMD_IP_BLOCK_TYPE_SMC,
877 .major = 7,
878 .minor = 1,
879 .rev = 0,
Eric Huang899fa4c2015-09-29 14:58:53 -0400880 .funcs = &amdgpu_pp_ip_funcs,
David Zhang8e711e1a2015-07-08 01:23:25 +0800881 },
David Zhang84390862015-07-08 01:28:20 +0800882 {
883 .type = AMD_IP_BLOCK_TYPE_DCE,
884 .major = 10,
885 .minor = 1,
886 .rev = 0,
887 .funcs = &dce_v10_0_ip_funcs,
888 },
David Zhangaf15a2d2015-07-30 19:42:11 -0400889 {
890 .type = AMD_IP_BLOCK_TYPE_GFX,
891 .major = 8,
892 .minor = 0,
893 .rev = 0,
894 .funcs = &gfx_v8_0_ip_funcs,
895 },
David Zhang1a5bbb62015-07-08 17:29:27 +0800896 {
897 .type = AMD_IP_BLOCK_TYPE_SDMA,
898 .major = 3,
899 .minor = 0,
900 .rev = 0,
901 .funcs = &sdma_v3_0_ip_funcs,
902 },
David Zhang974ee3d2015-07-08 17:32:15 +0800903 {
904 .type = AMD_IP_BLOCK_TYPE_UVD,
905 .major = 6,
906 .minor = 0,
907 .rev = 0,
908 .funcs = &uvd_v6_0_ip_funcs,
909 },
Alex Deucher188a9bc2015-07-27 14:24:14 -0400910 {
911 .type = AMD_IP_BLOCK_TYPE_VCE,
912 .major = 3,
913 .minor = 0,
914 .rev = 0,
915 .funcs = &vce_v3_0_ip_funcs,
916 },
David Zhang48299f92015-07-08 01:05:16 +0800917};
918
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400919static const struct amdgpu_ip_block_version polaris11_ip_blocks[] =
Flora Cuic0c1f572015-12-07 18:33:10 +0800920{
921 /* ORDER MATTERS! */
922 {
923 .type = AMD_IP_BLOCK_TYPE_COMMON,
924 .major = 2,
925 .minor = 0,
926 .rev = 0,
927 .funcs = &vi_common_ip_funcs,
928 },
929 {
930 .type = AMD_IP_BLOCK_TYPE_GMC,
931 .major = 8,
932 .minor = 1,
933 .rev = 0,
934 .funcs = &gmc_v8_0_ip_funcs,
935 },
936 {
937 .type = AMD_IP_BLOCK_TYPE_IH,
938 .major = 3,
939 .minor = 1,
940 .rev = 0,
941 .funcs = &tonga_ih_ip_funcs,
942 },
943 {
944 .type = AMD_IP_BLOCK_TYPE_SMC,
945 .major = 7,
946 .minor = 2,
947 .rev = 0,
948 .funcs = &amdgpu_pp_ip_funcs,
949 },
950 {
951 .type = AMD_IP_BLOCK_TYPE_DCE,
952 .major = 11,
953 .minor = 2,
954 .rev = 0,
955 .funcs = &dce_v11_0_ip_funcs,
956 },
957 {
958 .type = AMD_IP_BLOCK_TYPE_GFX,
959 .major = 8,
960 .minor = 0,
961 .rev = 0,
962 .funcs = &gfx_v8_0_ip_funcs,
963 },
964 {
965 .type = AMD_IP_BLOCK_TYPE_SDMA,
966 .major = 3,
967 .minor = 1,
968 .rev = 0,
969 .funcs = &sdma_v3_0_ip_funcs,
970 },
971 {
972 .type = AMD_IP_BLOCK_TYPE_UVD,
973 .major = 6,
974 .minor = 3,
975 .rev = 0,
976 .funcs = &uvd_v6_0_ip_funcs,
977 },
978 {
979 .type = AMD_IP_BLOCK_TYPE_VCE,
980 .major = 3,
981 .minor = 4,
982 .rev = 0,
983 .funcs = &vce_v3_0_ip_funcs,
984 },
985};
986
Alex Deucheraaa36a92015-04-20 17:31:14 -0400987static const struct amdgpu_ip_block_version cz_ip_blocks[] =
988{
989 /* ORDER MATTERS! */
990 {
yanyang15fc3aee2015-05-22 14:39:35 -0400991 .type = AMD_IP_BLOCK_TYPE_COMMON,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400992 .major = 2,
993 .minor = 0,
994 .rev = 0,
995 .funcs = &vi_common_ip_funcs,
996 },
997 {
yanyang15fc3aee2015-05-22 14:39:35 -0400998 .type = AMD_IP_BLOCK_TYPE_GMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -0400999 .major = 8,
1000 .minor = 0,
1001 .rev = 0,
1002 .funcs = &gmc_v8_0_ip_funcs,
1003 },
1004 {
yanyang15fc3aee2015-05-22 14:39:35 -04001005 .type = AMD_IP_BLOCK_TYPE_IH,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001006 .major = 3,
1007 .minor = 0,
1008 .rev = 0,
1009 .funcs = &cz_ih_ip_funcs,
1010 },
1011 {
yanyang15fc3aee2015-05-22 14:39:35 -04001012 .type = AMD_IP_BLOCK_TYPE_SMC,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001013 .major = 8,
1014 .minor = 0,
1015 .rev = 0,
Alex Deucher1f7371b2015-12-02 17:46:21 -05001016 .funcs = &amdgpu_pp_ip_funcs
Alex Deucheraaa36a92015-04-20 17:31:14 -04001017 },
1018 {
yanyang15fc3aee2015-05-22 14:39:35 -04001019 .type = AMD_IP_BLOCK_TYPE_DCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001020 .major = 11,
1021 .minor = 0,
1022 .rev = 0,
1023 .funcs = &dce_v11_0_ip_funcs,
1024 },
1025 {
yanyang15fc3aee2015-05-22 14:39:35 -04001026 .type = AMD_IP_BLOCK_TYPE_GFX,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001027 .major = 8,
1028 .minor = 0,
1029 .rev = 0,
1030 .funcs = &gfx_v8_0_ip_funcs,
1031 },
1032 {
yanyang15fc3aee2015-05-22 14:39:35 -04001033 .type = AMD_IP_BLOCK_TYPE_SDMA,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001034 .major = 3,
1035 .minor = 0,
1036 .rev = 0,
1037 .funcs = &sdma_v3_0_ip_funcs,
1038 },
1039 {
yanyang15fc3aee2015-05-22 14:39:35 -04001040 .type = AMD_IP_BLOCK_TYPE_UVD,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001041 .major = 6,
1042 .minor = 0,
1043 .rev = 0,
1044 .funcs = &uvd_v6_0_ip_funcs,
1045 },
1046 {
yanyang15fc3aee2015-05-22 14:39:35 -04001047 .type = AMD_IP_BLOCK_TYPE_VCE,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001048 .major = 3,
1049 .minor = 0,
1050 .rev = 0,
1051 .funcs = &vce_v3_0_ip_funcs,
1052 },
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001053#if defined(CONFIG_DRM_AMD_ACP)
1054 {
1055 .type = AMD_IP_BLOCK_TYPE_ACP,
1056 .major = 2,
1057 .minor = 2,
1058 .rev = 0,
1059 .funcs = &acp_ip_funcs,
1060 },
1061#endif
Alex Deucheraaa36a92015-04-20 17:31:14 -04001062};
1063
1064int vi_set_ip_blocks(struct amdgpu_device *adev)
1065{
1066 switch (adev->asic_type) {
1067 case CHIP_TOPAZ:
1068 adev->ip_blocks = topaz_ip_blocks;
1069 adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
1070 break;
David Zhang48299f92015-07-08 01:05:16 +08001071 case CHIP_FIJI:
1072 adev->ip_blocks = fiji_ip_blocks;
1073 adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
1074 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001075 case CHIP_TONGA:
1076 adev->ip_blocks = tonga_ip_blocks;
1077 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
1078 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001079 case CHIP_POLARIS11:
1080 case CHIP_POLARIS10:
1081 adev->ip_blocks = polaris11_ip_blocks;
1082 adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks);
Flora Cuic0c1f572015-12-07 18:33:10 +08001083 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001084 case CHIP_CARRIZO:
Samuel Li39bb0c92015-10-08 16:31:43 -04001085 case CHIP_STONEY:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001086 adev->ip_blocks = cz_ip_blocks;
1087 adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
1088 break;
1089 default:
1090 /* FIXME: not supported yet */
1091 return -EINVAL;
1092 }
1093
Alex Deucheraaa36a92015-04-20 17:31:14 -04001094 return 0;
1095}
1096
Samuel Li39bb0c92015-10-08 16:31:43 -04001097#define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
1098#define ATI_REV_ID_FUSE_MACRO__SHIFT 9
1099#define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
1100
Alex Deucheraaa36a92015-04-20 17:31:14 -04001101static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
1102{
Flora Cuiabdfb852015-11-20 11:40:53 +08001103 if (adev->flags & AMD_IS_APU)
Samuel Li39bb0c92015-10-08 16:31:43 -04001104 return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
1105 >> ATI_REV_ID_FUSE_MACRO__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001106 else
Flora Cuiabdfb852015-11-20 11:40:53 +08001107 return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
1108 >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001109}
1110
1111static const struct amdgpu_asic_funcs vi_asic_funcs =
1112{
1113 .read_disabled_bios = &vi_read_disabled_bios,
Alex Deucher95addb2a2015-11-24 10:37:54 -05001114 .read_bios_from_rom = &vi_read_bios_from_rom,
Alex Deucheraaa36a92015-04-20 17:31:14 -04001115 .read_register = &vi_read_register,
1116 .reset = &vi_asic_reset,
1117 .set_vga_state = &vi_vga_set_state,
1118 .get_xclk = &vi_get_xclk,
1119 .set_uvd_clocks = &vi_set_uvd_clocks,
1120 .set_vce_clocks = &vi_set_vce_clocks,
1121 .get_cu_info = &gfx_v8_0_get_cu_info,
1122 /* these should be moved to their own ip modules */
1123 .get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
1124 .wait_for_mc_idle = &gmc_v8_0_mc_wait_for_idle,
1125};
1126
yanyang15fc3aee2015-05-22 14:39:35 -04001127static int vi_common_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001128{
1129 bool smc_enabled = false;
yanyang15fc3aee2015-05-22 14:39:35 -04001130 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001131
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001132 if (adev->flags & AMD_IS_APU) {
Alex Deucher7b92cdb2015-07-10 16:21:10 -04001133 adev->smc_rreg = &cz_smc_rreg;
1134 adev->smc_wreg = &cz_smc_wreg;
1135 } else {
1136 adev->smc_rreg = &vi_smc_rreg;
1137 adev->smc_wreg = &vi_smc_wreg;
1138 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001139 adev->pcie_rreg = &vi_pcie_rreg;
1140 adev->pcie_wreg = &vi_pcie_wreg;
1141 adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
1142 adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
1143 adev->didt_rreg = &vi_didt_rreg;
1144 adev->didt_wreg = &vi_didt_wreg;
1145
1146 adev->asic_funcs = &vi_asic_funcs;
1147
yanyang15fc3aee2015-05-22 14:39:35 -04001148 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
1149 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
Alex Deucheraaa36a92015-04-20 17:31:14 -04001150 smc_enabled = true;
1151
1152 adev->rev_id = vi_get_rev_id(adev);
1153 adev->external_rev_id = 0xFF;
1154 switch (adev->asic_type) {
1155 case CHIP_TOPAZ:
Alex Deucheraaa36a92015-04-20 17:31:14 -04001156 adev->cg_flags = 0;
1157 adev->pg_flags = 0;
1158 adev->external_rev_id = 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001159 break;
David Zhang48299f92015-07-08 01:05:16 +08001160 case CHIP_FIJI:
Alex Deucher14698b62016-04-07 18:38:00 -04001161 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1162 AMD_CG_SUPPORT_GFX_MGLS |
1163 AMD_CG_SUPPORT_GFX_RLC_LS |
1164 AMD_CG_SUPPORT_GFX_CP_LS |
1165 AMD_CG_SUPPORT_GFX_CGTS |
1166 AMD_CG_SUPPORT_GFX_CGTS_LS |
1167 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deuchere08d53c2016-04-08 00:42:51 -04001168 AMD_CG_SUPPORT_GFX_CGLS |
1169 AMD_CG_SUPPORT_SDMA_MGCG |
Alex Deucherc90766c2016-04-08 00:52:58 -04001170 AMD_CG_SUPPORT_SDMA_LS |
1171 AMD_CG_SUPPORT_BIF_LS |
1172 AMD_CG_SUPPORT_HDP_MGCG |
1173 AMD_CG_SUPPORT_HDP_LS |
Alex Deucher3fde56b2016-04-08 01:01:18 -04001174 AMD_CG_SUPPORT_ROM_MGCG |
1175 AMD_CG_SUPPORT_MC_MGCG |
1176 AMD_CG_SUPPORT_MC_LS;
Flora Cuib6bc28f2015-11-02 21:21:34 +08001177 adev->pg_flags = 0;
1178 adev->external_rev_id = adev->rev_id + 0x3c;
1179 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001180 case CHIP_TONGA:
Tom St Denis5f64e772016-03-23 13:16:13 -04001181 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001182 adev->pg_flags = 0;
1183 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001184 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001185 case CHIP_POLARIS11:
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 + 0x5A;
1189 break;
Flora Cui2cc0c0b2016-03-14 18:33:29 -04001190 case CHIP_POLARIS10:
Flora Cuic0c1f572015-12-07 18:33:10 +08001191 adev->cg_flags = 0;
1192 adev->pg_flags = 0;
1193 adev->external_rev_id = adev->rev_id + 0x50;
1194 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001195 case CHIP_CARRIZO:
Alex Deucher70eced92016-04-07 23:01:48 -04001196 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1197 AMD_CG_SUPPORT_GFX_MGLS |
1198 AMD_CG_SUPPORT_GFX_RLC_LS |
1199 AMD_CG_SUPPORT_GFX_CP_LS |
1200 AMD_CG_SUPPORT_GFX_CGTS |
1201 AMD_CG_SUPPORT_GFX_MGLS |
1202 AMD_CG_SUPPORT_GFX_CGTS_LS |
1203 AMD_CG_SUPPORT_GFX_CGCG |
Alex Deucher03c335d2016-04-08 00:26:46 -04001204 AMD_CG_SUPPORT_GFX_CGLS |
1205 AMD_CG_SUPPORT_BIF_LS |
1206 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher6f17a252016-04-08 00:39:54 -04001207 AMD_CG_SUPPORT_HDP_LS |
1208 AMD_CG_SUPPORT_SDMA_MGCG |
1209 AMD_CG_SUPPORT_SDMA_LS;
Alex Deucher0fd4af92016-02-04 23:31:32 -05001210 adev->pg_flags = 0;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001211 adev->external_rev_id = adev->rev_id + 0x1;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001212 break;
Tom St Deniscde64932016-03-23 13:17:04 -04001213 case CHIP_STONEY:
Alex Deucher64694902016-04-07 23:17:15 -04001214 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1215 AMD_CG_SUPPORT_GFX_MGCG |
Alex Deucherb6711d12016-04-13 12:41:50 -04001216 AMD_CG_SUPPORT_GFX_MGLS |
1217 AMD_CG_SUPPORT_BIF_LS |
1218 AMD_CG_SUPPORT_HDP_MGCG |
Alex Deucher1bf912f2016-04-08 00:40:49 -04001219 AMD_CG_SUPPORT_HDP_LS |
1220 AMD_CG_SUPPORT_SDMA_MGCG |
1221 AMD_CG_SUPPORT_SDMA_LS;
Tom St Deniscde64932016-03-23 13:17:04 -04001222 adev->pg_flags = 0;
1223 adev->external_rev_id = adev->rev_id + 0x1;
1224 break;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001225 default:
1226 /* FIXME: not supported yet */
1227 return -EINVAL;
1228 }
1229
Flora Cuia3d08fa2015-11-02 21:15:55 +08001230 if (amdgpu_smc_load_fw && smc_enabled)
1231 adev->firmware.smu_load = true;
1232
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001233 amdgpu_get_pcie_info(adev);
1234
Alex Deucheraaa36a92015-04-20 17:31:14 -04001235 return 0;
1236}
1237
yanyang15fc3aee2015-05-22 14:39:35 -04001238static int vi_common_sw_init(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_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001244{
1245 return 0;
1246}
1247
yanyang15fc3aee2015-05-22 14:39:35 -04001248static int vi_common_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001249{
yanyang15fc3aee2015-05-22 14:39:35 -04001250 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1251
Alex Deucheraaa36a92015-04-20 17:31:14 -04001252 /* move the golden regs per IP block */
1253 vi_init_golden_registers(adev);
1254 /* enable pcie gen2/3 link */
1255 vi_pcie_gen3_enable(adev);
1256 /* enable aspm */
1257 vi_program_aspm(adev);
1258 /* enable the doorbell aperture */
1259 vi_enable_doorbell_aperture(adev, true);
1260
1261 return 0;
1262}
1263
yanyang15fc3aee2015-05-22 14:39:35 -04001264static int vi_common_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001265{
yanyang15fc3aee2015-05-22 14:39:35 -04001266 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1267
Alex Deucheraaa36a92015-04-20 17:31:14 -04001268 /* enable the doorbell aperture */
1269 vi_enable_doorbell_aperture(adev, false);
1270
1271 return 0;
1272}
1273
yanyang15fc3aee2015-05-22 14:39:35 -04001274static int vi_common_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001275{
yanyang15fc3aee2015-05-22 14:39:35 -04001276 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1277
Alex Deucheraaa36a92015-04-20 17:31:14 -04001278 return vi_common_hw_fini(adev);
1279}
1280
yanyang15fc3aee2015-05-22 14:39:35 -04001281static int vi_common_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001282{
yanyang15fc3aee2015-05-22 14:39:35 -04001283 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1284
Alex Deucheraaa36a92015-04-20 17:31:14 -04001285 return vi_common_hw_init(adev);
1286}
1287
yanyang15fc3aee2015-05-22 14:39:35 -04001288static bool vi_common_is_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001289{
1290 return true;
1291}
1292
yanyang15fc3aee2015-05-22 14:39:35 -04001293static int vi_common_wait_for_idle(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001294{
1295 return 0;
1296}
1297
yanyang15fc3aee2015-05-22 14:39:35 -04001298static void vi_common_print_status(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001299{
yanyang15fc3aee2015-05-22 14:39:35 -04001300 return;
Alex Deucheraaa36a92015-04-20 17:31:14 -04001301}
1302
yanyang15fc3aee2015-05-22 14:39:35 -04001303static int vi_common_soft_reset(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001304{
1305 return 0;
1306}
1307
Alex Deucher76f10b92016-04-08 01:37:44 -04001308static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1309 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001310{
1311 uint32_t temp, data;
1312
1313 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1314
Alex Deucherc90766c2016-04-08 00:52:58 -04001315 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001316 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1317 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1318 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1319 else
1320 data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1321 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1322 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
1323
1324 if (temp != data)
1325 WREG32_PCIE(ixPCIE_CNTL2, data);
1326}
1327
Alex Deucher76f10b92016-04-08 01:37:44 -04001328static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1329 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001330{
1331 uint32_t temp, data;
1332
1333 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1334
Alex Deucherc90766c2016-04-08 00:52:58 -04001335 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001336 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1337 else
1338 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1339
1340 if (temp != data)
1341 WREG32(mmHDP_HOST_PATH_CNTL, data);
1342}
1343
Alex Deucher76f10b92016-04-08 01:37:44 -04001344static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1345 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001346{
1347 uint32_t temp, data;
1348
1349 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1350
Alex Deucherc90766c2016-04-08 00:52:58 -04001351 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
Eric Huang6cec2652015-11-12 16:59:47 -05001352 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1353 else
1354 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1355
1356 if (temp != data)
1357 WREG32(mmHDP_MEM_POWER_LS, data);
1358}
1359
Alex Deucher76f10b92016-04-08 01:37:44 -04001360static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1361 bool enable)
Eric Huang6cec2652015-11-12 16:59:47 -05001362{
1363 uint32_t temp, data;
1364
1365 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1366
Alex Deucherc90766c2016-04-08 00:52:58 -04001367 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
Eric Huang6cec2652015-11-12 16:59:47 -05001368 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1369 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1370 else
1371 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1372 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1373
1374 if (temp != data)
1375 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
1376}
1377
yanyang15fc3aee2015-05-22 14:39:35 -04001378static int vi_common_set_clockgating_state(void *handle,
Alex Deucherc90766c2016-04-08 00:52:58 -04001379 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -04001380{
Eric Huang6cec2652015-11-12 16:59:47 -05001381 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1382
1383 switch (adev->asic_type) {
1384 case CHIP_FIJI:
Alex Deucher76f10b92016-04-08 01:37:44 -04001385 vi_update_bif_medium_grain_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001386 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001387 vi_update_hdp_medium_grain_clock_gating(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001388 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001389 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001390 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucher76f10b92016-04-08 01:37:44 -04001391 vi_update_rom_medium_grain_clock_gating(adev,
1392 state == AMD_CG_STATE_GATE ? true : false);
1393 break;
1394 case CHIP_CARRIZO:
1395 case CHIP_STONEY:
1396 vi_update_bif_medium_grain_light_sleep(adev,
1397 state == AMD_CG_STATE_GATE ? true : false);
1398 vi_update_hdp_medium_grain_clock_gating(adev,
1399 state == AMD_CG_STATE_GATE ? true : false);
1400 vi_update_hdp_light_sleep(adev,
Eric Huang6cec2652015-11-12 16:59:47 -05001401 state == AMD_CG_STATE_GATE ? true : false);
1402 break;
1403 default:
1404 break;
1405 }
Alex Deucheraaa36a92015-04-20 17:31:14 -04001406 return 0;
1407}
1408
yanyang15fc3aee2015-05-22 14:39:35 -04001409static int vi_common_set_powergating_state(void *handle,
1410 enum amd_powergating_state state)
1411{
1412 return 0;
1413}
1414
1415const struct amd_ip_funcs vi_common_ip_funcs = {
Alex Deucheraaa36a92015-04-20 17:31:14 -04001416 .early_init = vi_common_early_init,
1417 .late_init = NULL,
1418 .sw_init = vi_common_sw_init,
1419 .sw_fini = vi_common_sw_fini,
1420 .hw_init = vi_common_hw_init,
1421 .hw_fini = vi_common_hw_fini,
1422 .suspend = vi_common_suspend,
1423 .resume = vi_common_resume,
1424 .is_idle = vi_common_is_idle,
1425 .wait_for_idle = vi_common_wait_for_idle,
1426 .soft_reset = vi_common_soft_reset,
1427 .print_status = vi_common_print_status,
1428 .set_clockgating_state = vi_common_set_clockgating_state,
1429 .set_powergating_state = vi_common_set_powergating_state,
1430};
1431