blob: f2c3a49f73a0051b74c602990d6e18ea64928eda [file] [log] [blame]
Ken Wang220ab9b2017-03-06 14:49:53 -05001/*
2 * Copyright 2016 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>
Masahiro Yamada248a1d62017-04-24 13:50:21 +090026#include <drm/drmP.h>
Ken Wang220ab9b2017-03-06 14:49:53 -050027#include "amdgpu.h"
Alex Deucherd05da0e2017-06-30 17:08:45 -040028#include "amdgpu_atombios.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050029#include "amdgpu_ih.h"
30#include "amdgpu_uvd.h"
31#include "amdgpu_vce.h"
32#include "amdgpu_ucode.h"
33#include "amdgpu_psp.h"
34#include "atom.h"
35#include "amd_pcie.h"
36
37#include "vega10/soc15ip.h"
38#include "vega10/UVD/uvd_7_0_offset.h"
39#include "vega10/GC/gc_9_0_offset.h"
40#include "vega10/GC/gc_9_0_sh_mask.h"
41#include "vega10/SDMA0/sdma0_4_0_offset.h"
42#include "vega10/SDMA1/sdma1_4_0_offset.h"
43#include "vega10/HDP/hdp_4_0_offset.h"
44#include "vega10/HDP/hdp_4_0_sh_mask.h"
45#include "vega10/MP/mp_9_0_offset.h"
46#include "vega10/MP/mp_9_0_sh_mask.h"
47#include "vega10/SMUIO/smuio_9_0_offset.h"
48#include "vega10/SMUIO/smuio_9_0_sh_mask.h"
49
50#include "soc15.h"
51#include "soc15_common.h"
52#include "gfx_v9_0.h"
53#include "gmc_v9_0.h"
54#include "gfxhub_v1_0.h"
55#include "mmhub_v1_0.h"
56#include "vega10_ih.h"
57#include "sdma_v4_0.h"
58#include "uvd_v7_0.h"
59#include "vce_v4_0.h"
Leo Liuf2d7e702016-12-28 13:36:00 -050060#include "vcn_v1_0.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050061#include "amdgpu_powerplay.h"
Xiangliang Yu796b6562017-02-28 17:22:03 +080062#include "dce_virtual.h"
Xiangliang Yuf1a34462017-03-08 15:06:47 +080063#include "mxgpu_ai.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050064
Ken Wang220ab9b2017-03-06 14:49:53 -050065#define mmFabricConfigAccessControl 0x0410
66#define mmFabricConfigAccessControl_BASE_IDX 0
67#define mmFabricConfigAccessControl_DEFAULT 0x00000000
68//FabricConfigAccessControl
69#define FabricConfigAccessControl__CfgRegInstAccEn__SHIFT 0x0
70#define FabricConfigAccessControl__CfgRegInstAccRegLock__SHIFT 0x1
71#define FabricConfigAccessControl__CfgRegInstID__SHIFT 0x10
72#define FabricConfigAccessControl__CfgRegInstAccEn_MASK 0x00000001L
73#define FabricConfigAccessControl__CfgRegInstAccRegLock_MASK 0x00000002L
74#define FabricConfigAccessControl__CfgRegInstID_MASK 0x00FF0000L
75
76
77#define mmDF_PIE_AON0_DfGlobalClkGater 0x00fc
78#define mmDF_PIE_AON0_DfGlobalClkGater_BASE_IDX 0
79//DF_PIE_AON0_DfGlobalClkGater
80#define DF_PIE_AON0_DfGlobalClkGater__MGCGMode__SHIFT 0x0
81#define DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK 0x0000000FL
82
83enum {
84 DF_MGCG_DISABLE = 0,
85 DF_MGCG_ENABLE_00_CYCLE_DELAY =1,
86 DF_MGCG_ENABLE_01_CYCLE_DELAY =2,
87 DF_MGCG_ENABLE_15_CYCLE_DELAY =13,
88 DF_MGCG_ENABLE_31_CYCLE_DELAY =14,
89 DF_MGCG_ENABLE_63_CYCLE_DELAY =15
90};
91
92#define mmMP0_MISC_CGTT_CTRL0 0x01b9
93#define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
94#define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
95#define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
96
97/*
98 * Indirect registers accessor
99 */
100static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
101{
102 unsigned long flags, address, data;
103 u32 r;
104 struct nbio_pcie_index_data *nbio_pcie_id;
105
Chunming Zhouaecbe642017-05-04 15:06:25 -0400106 if (adev->flags & AMD_IS_APU)
107 nbio_pcie_id = &nbio_v7_0_pcie_index_data;
Alex Deucher1fdc6392017-04-03 16:56:08 -0400108 else
Chunming Zhouaecbe642017-05-04 15:06:25 -0400109 nbio_pcie_id = &nbio_v6_1_pcie_index_data;
Ken Wang220ab9b2017-03-06 14:49:53 -0500110
111 address = nbio_pcie_id->index_offset;
112 data = nbio_pcie_id->data_offset;
113
114 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
115 WREG32(address, reg);
116 (void)RREG32(address);
117 r = RREG32(data);
118 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
119 return r;
120}
121
122static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
123{
124 unsigned long flags, address, data;
125 struct nbio_pcie_index_data *nbio_pcie_id;
126
Chunming Zhouaecbe642017-05-04 15:06:25 -0400127 if (adev->flags & AMD_IS_APU)
128 nbio_pcie_id = &nbio_v7_0_pcie_index_data;
Alex Deucher1fdc6392017-04-03 16:56:08 -0400129 else
Chunming Zhouaecbe642017-05-04 15:06:25 -0400130 nbio_pcie_id = &nbio_v6_1_pcie_index_data;
Ken Wang220ab9b2017-03-06 14:49:53 -0500131
132 address = nbio_pcie_id->index_offset;
133 data = nbio_pcie_id->data_offset;
134
135 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
136 WREG32(address, reg);
137 (void)RREG32(address);
138 WREG32(data, v);
139 (void)RREG32(data);
140 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
141}
142
143static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
144{
145 unsigned long flags, address, data;
146 u32 r;
147
148 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
149 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
150
151 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
152 WREG32(address, ((reg) & 0x1ff));
153 r = RREG32(data);
154 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
155 return r;
156}
157
158static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
159{
160 unsigned long flags, address, data;
161
162 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
163 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
164
165 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
166 WREG32(address, ((reg) & 0x1ff));
167 WREG32(data, (v));
168 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
169}
170
171static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
172{
173 unsigned long flags, address, data;
174 u32 r;
175
176 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
177 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
178
179 spin_lock_irqsave(&adev->didt_idx_lock, flags);
180 WREG32(address, (reg));
181 r = RREG32(data);
182 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
183 return r;
184}
185
186static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
187{
188 unsigned long flags, address, data;
189
190 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
191 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
192
193 spin_lock_irqsave(&adev->didt_idx_lock, flags);
194 WREG32(address, (reg));
195 WREG32(data, (v));
196 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
197}
198
Evan Quan560460f2017-07-03 22:37:44 +0800199static u32 soc15_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
200{
201 unsigned long flags;
202 u32 r;
203
204 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
205 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
206 r = RREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA);
207 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
208 return r;
209}
210
211static void soc15_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
212{
213 unsigned long flags;
214
215 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
216 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
217 WREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA, (v));
218 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
219}
220
Evan Quan2f11fb02017-07-04 09:23:01 +0800221static u32 soc15_se_cac_rreg(struct amdgpu_device *adev, u32 reg)
222{
223 unsigned long flags;
224 u32 r;
225
226 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
227 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
228 r = RREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA);
229 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
230 return r;
231}
232
233static void soc15_se_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
234{
235 unsigned long flags;
236
237 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
238 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
239 WREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA, (v));
240 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
241}
242
Ken Wang220ab9b2017-03-06 14:49:53 -0500243static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
244{
Chunming Zhouaecbe642017-05-04 15:06:25 -0400245 if (adev->flags & AMD_IS_APU)
246 return nbio_v7_0_get_memsize(adev);
247 else
248 return nbio_v6_1_get_memsize(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500249}
250
251static const u32 vega10_golden_init[] =
252{
253};
254
Chunming Zhoue0ab9572016-12-08 10:16:00 +0800255static const u32 raven_golden_init[] =
256{
257};
258
Ken Wang220ab9b2017-03-06 14:49:53 -0500259static void soc15_init_golden_registers(struct amdgpu_device *adev)
260{
261 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
262 mutex_lock(&adev->grbm_idx_mutex);
263
264 switch (adev->asic_type) {
265 case CHIP_VEGA10:
266 amdgpu_program_register_sequence(adev,
267 vega10_golden_init,
268 (const u32)ARRAY_SIZE(vega10_golden_init));
269 break;
Chunming Zhoue0ab9572016-12-08 10:16:00 +0800270 case CHIP_RAVEN:
271 amdgpu_program_register_sequence(adev,
272 raven_golden_init,
273 (const u32)ARRAY_SIZE(raven_golden_init));
274 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500275 default:
276 break;
277 }
278 mutex_unlock(&adev->grbm_idx_mutex);
279}
280static u32 soc15_get_xclk(struct amdgpu_device *adev)
281{
282 if (adev->asic_type == CHIP_VEGA10)
283 return adev->clock.spll.reference_freq/4;
284 else
285 return adev->clock.spll.reference_freq;
286}
287
288
289void soc15_grbm_select(struct amdgpu_device *adev,
290 u32 me, u32 pipe, u32 queue, u32 vmid)
291{
292 u32 grbm_gfx_cntl = 0;
293 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
294 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
295 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
296 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
297
298 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
299}
300
301static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
302{
303 /* todo */
304}
305
306static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
307{
308 /* todo */
309 return false;
310}
311
312static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
313 u8 *bios, u32 length_bytes)
314{
315 u32 *dw_ptr;
316 u32 i, length_dw;
317
318 if (bios == NULL)
319 return false;
320 if (length_bytes == 0)
321 return false;
322 /* APU vbios image is part of sbios image */
323 if (adev->flags & AMD_IS_APU)
324 return false;
325
326 dw_ptr = (u32 *)bios;
327 length_dw = ALIGN(length_bytes, 4) / 4;
328
329 /* set rom index to 0 */
330 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
331 /* read out the rom data */
332 for (i = 0; i < length_dw; i++)
333 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
334
335 return true;
336}
337
Ken Wang220ab9b2017-03-06 14:49:53 -0500338static struct amdgpu_allowed_register_entry soc15_allowed_read_registers[] = {
Christian König97fcc762017-04-12 12:49:54 +0200339 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS)},
340 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS2)},
341 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE0)},
342 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE1)},
343 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE2)},
344 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE3)},
345 { SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_STATUS_REG)},
346 { SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_STATUS_REG)},
347 { SOC15_REG_OFFSET(GC, 0, mmCP_STAT)},
348 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT1)},
349 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT2)},
350 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT3)},
351 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_BUSY_STAT)},
352 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STALLED_STAT1)},
353 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STATUS)},
354 { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STALLED_STAT1)},
355 { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STATUS)},
356 { SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)},
Ken Wang220ab9b2017-03-06 14:49:53 -0500357};
358
359static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
360 u32 sh_num, u32 reg_offset)
361{
362 uint32_t val;
363
364 mutex_lock(&adev->grbm_idx_mutex);
365 if (se_num != 0xffffffff || sh_num != 0xffffffff)
366 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
367
368 val = RREG32(reg_offset);
369
370 if (se_num != 0xffffffff || sh_num != 0xffffffff)
371 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
372 mutex_unlock(&adev->grbm_idx_mutex);
373 return val;
374}
375
Alex Deucherc013cea2017-03-24 15:05:07 -0400376static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
377 bool indexed, u32 se_num,
378 u32 sh_num, u32 reg_offset)
379{
380 if (indexed) {
381 return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
382 } else {
383 switch (reg_offset) {
384 case SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG):
385 return adev->gfx.config.gb_addr_config;
386 default:
387 return RREG32(reg_offset);
388 }
389 }
390}
391
Ken Wang220ab9b2017-03-06 14:49:53 -0500392static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
393 u32 sh_num, u32 reg_offset, u32 *value)
394{
Christian König3032f352017-04-12 12:53:18 +0200395 uint32_t i;
Ken Wang220ab9b2017-03-06 14:49:53 -0500396
397 *value = 0;
Ken Wang220ab9b2017-03-06 14:49:53 -0500398 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
399 if (reg_offset != soc15_allowed_read_registers[i].reg_offset)
400 continue;
401
Christian König97fcc762017-04-12 12:49:54 +0200402 *value = soc15_get_register_value(adev,
403 soc15_allowed_read_registers[i].grbm_indexed,
404 se_num, sh_num, reg_offset);
Ken Wang220ab9b2017-03-06 14:49:53 -0500405 return 0;
406 }
407 return -EINVAL;
408}
409
410static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev)
411{
412 u32 i;
413
414 dev_info(adev->dev, "GPU pci config reset\n");
415
416 /* disable BM */
417 pci_clear_master(adev->pdev);
418 /* reset */
419 amdgpu_pci_config_reset(adev);
420
421 udelay(100);
422
423 /* wait for asic to come out of reset */
424 for (i = 0; i < adev->usec_timeout; i++) {
Chunming Zhouaecbe642017-05-04 15:06:25 -0400425 u32 memsize = (adev->flags & AMD_IS_APU) ?
426 nbio_v7_0_get_memsize(adev) :
427 nbio_v6_1_get_memsize(adev);
428 if (memsize != 0xffffffff)
Ken Wang220ab9b2017-03-06 14:49:53 -0500429 break;
430 udelay(1);
431 }
432
433}
434
435static int soc15_asic_reset(struct amdgpu_device *adev)
436{
Alex Deucherd05da0e2017-06-30 17:08:45 -0400437 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
Ken Wang220ab9b2017-03-06 14:49:53 -0500438
439 soc15_gpu_pci_config_reset(adev);
440
Alex Deucherd05da0e2017-06-30 17:08:45 -0400441 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
Ken Wang220ab9b2017-03-06 14:49:53 -0500442
443 return 0;
444}
445
446/*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
447 u32 cntl_reg, u32 status_reg)
448{
449 return 0;
450}*/
451
452static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
453{
454 /*int r;
455
456 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
457 if (r)
458 return r;
459
460 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
461 */
462 return 0;
463}
464
465static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
466{
467 /* todo */
468
469 return 0;
470}
471
472static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
473{
474 if (pci_is_root_bus(adev->pdev->bus))
475 return;
476
477 if (amdgpu_pcie_gen2 == 0)
478 return;
479
480 if (adev->flags & AMD_IS_APU)
481 return;
482
483 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
484 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
485 return;
486
487 /* todo */
488}
489
490static void soc15_program_aspm(struct amdgpu_device *adev)
491{
492
493 if (amdgpu_aspm == 0)
494 return;
495
496 /* todo */
497}
498
499static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
500 bool enable)
501{
Chunming Zhouaecbe642017-05-04 15:06:25 -0400502 if (adev->flags & AMD_IS_APU) {
503 nbio_v7_0_enable_doorbell_aperture(adev, enable);
504 } else {
505 nbio_v6_1_enable_doorbell_aperture(adev, enable);
506 nbio_v6_1_enable_doorbell_selfring_aperture(adev, enable);
507 }
Ken Wang220ab9b2017-03-06 14:49:53 -0500508}
509
510static const struct amdgpu_ip_block_version vega10_common_ip_block =
511{
512 .type = AMD_IP_BLOCK_TYPE_COMMON,
513 .major = 2,
514 .minor = 0,
515 .rev = 0,
516 .funcs = &soc15_common_ip_funcs,
517};
518
519int soc15_set_ip_blocks(struct amdgpu_device *adev)
520{
Xiangliang Yu1b922422017-03-08 15:00:48 +0800521 nbio_v6_1_detect_hw_virt(adev);
522
Xiangliang Yuf1a34462017-03-08 15:06:47 +0800523 if (amdgpu_sriov_vf(adev))
524 adev->virt.ops = &xgpu_ai_virt_ops;
525
Ken Wang220ab9b2017-03-06 14:49:53 -0500526 switch (adev->asic_type) {
527 case CHIP_VEGA10:
528 amdgpu_ip_block_add(adev, &vega10_common_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500529 amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block);
530 amdgpu_ip_block_add(adev, &vega10_ih_ip_block);
Monk Liubb5c9ca2017-03-30 18:00:20 +0800531 if (amdgpu_fw_load_type == 2 || amdgpu_fw_load_type == -1)
532 amdgpu_ip_block_add(adev, &psp_v3_1_ip_block);
Xiangliang Yuc6f3e7c2017-03-28 19:16:42 +0800533 if (!amdgpu_sriov_vf(adev))
Xiangliang Yucfd83732017-02-28 17:26:40 +0800534 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Alex Deucherf8445302017-03-22 10:49:25 -0400535 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Xiangliang Yu796b6562017-02-28 17:22:03 +0800536 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500537 amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block);
538 amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block);
Frank Min91faed92017-04-17 11:19:45 +0800539 amdgpu_ip_block_add(adev, &uvd_v7_0_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500540 amdgpu_ip_block_add(adev, &vce_v4_0_ip_block);
541 break;
Chunming Zhou1023b792016-12-08 10:09:13 +0800542 case CHIP_RAVEN:
543 amdgpu_ip_block_add(adev, &vega10_common_ip_block);
Chunming Zhou1023b792016-12-08 10:09:13 +0800544 amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block);
545 amdgpu_ip_block_add(adev, &vega10_ih_ip_block);
Huang Rui9e2837f2017-05-11 16:26:16 -0400546 amdgpu_ip_block_add(adev, &psp_v10_0_ip_block);
Hawking Zhang30db0952017-05-11 16:30:31 -0400547 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Alex Deucherd67fed162017-06-02 14:52:18 -0400548 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
549 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
Chunming Zhou1023b792016-12-08 10:09:13 +0800550 amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block);
551 amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block);
Leo Liuf2d7e702016-12-28 13:36:00 -0500552 amdgpu_ip_block_add(adev, &vcn_v1_0_ip_block);
Chunming Zhou1023b792016-12-08 10:09:13 +0800553 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500554 default:
555 return -EINVAL;
556 }
557
558 return 0;
559}
560
561static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
562{
Chunming Zhouaecbe642017-05-04 15:06:25 -0400563 if (adev->flags & AMD_IS_APU)
564 return nbio_v7_0_get_rev_id(adev);
565 else
566 return nbio_v6_1_get_rev_id(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500567}
568
Ken Wang220ab9b2017-03-06 14:49:53 -0500569static const struct amdgpu_asic_funcs soc15_asic_funcs =
570{
571 .read_disabled_bios = &soc15_read_disabled_bios,
572 .read_bios_from_rom = &soc15_read_bios_from_rom,
573 .read_register = &soc15_read_register,
574 .reset = &soc15_asic_reset,
575 .set_vga_state = &soc15_vga_set_state,
576 .get_xclk = &soc15_get_xclk,
577 .set_uvd_clocks = &soc15_set_uvd_clocks,
578 .set_vce_clocks = &soc15_set_vce_clocks,
579 .get_config_memsize = &soc15_get_config_memsize,
580};
581
582static int soc15_common_early_init(void *handle)
583{
584 bool psp_enabled = false;
585 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
586
587 adev->smc_rreg = NULL;
588 adev->smc_wreg = NULL;
589 adev->pcie_rreg = &soc15_pcie_rreg;
590 adev->pcie_wreg = &soc15_pcie_wreg;
591 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
592 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
593 adev->didt_rreg = &soc15_didt_rreg;
594 adev->didt_wreg = &soc15_didt_wreg;
Evan Quan560460f2017-07-03 22:37:44 +0800595 adev->gc_cac_rreg = &soc15_gc_cac_rreg;
596 adev->gc_cac_wreg = &soc15_gc_cac_wreg;
Evan Quan2f11fb02017-07-04 09:23:01 +0800597 adev->se_cac_rreg = &soc15_se_cac_rreg;
598 adev->se_cac_wreg = &soc15_se_cac_wreg;
Ken Wang220ab9b2017-03-06 14:49:53 -0500599
600 adev->asic_funcs = &soc15_asic_funcs;
601
602 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP) &&
603 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_PSP)))
604 psp_enabled = true;
605
606 /*
607 * nbio need be used for both sdma and gfx9, but only
608 * initializes once
609 */
610 switch(adev->asic_type) {
611 case CHIP_VEGA10:
612 nbio_v6_1_init(adev);
613 break;
Chunming Zhouaecbe642017-05-04 15:06:25 -0400614 case CHIP_RAVEN:
615 nbio_v7_0_init(adev);
616 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500617 default:
618 return -EINVAL;
619 }
620
621 adev->rev_id = soc15_get_rev_id(adev);
622 adev->external_rev_id = 0xFF;
623 switch (adev->asic_type) {
624 case CHIP_VEGA10:
625 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
626 AMD_CG_SUPPORT_GFX_MGLS |
627 AMD_CG_SUPPORT_GFX_RLC_LS |
628 AMD_CG_SUPPORT_GFX_CP_LS |
629 AMD_CG_SUPPORT_GFX_3D_CGCG |
630 AMD_CG_SUPPORT_GFX_3D_CGLS |
631 AMD_CG_SUPPORT_GFX_CGCG |
632 AMD_CG_SUPPORT_GFX_CGLS |
633 AMD_CG_SUPPORT_BIF_MGCG |
634 AMD_CG_SUPPORT_BIF_LS |
635 AMD_CG_SUPPORT_HDP_LS |
636 AMD_CG_SUPPORT_DRM_MGCG |
637 AMD_CG_SUPPORT_DRM_LS |
638 AMD_CG_SUPPORT_ROM_MGCG |
639 AMD_CG_SUPPORT_DF_MGCG |
640 AMD_CG_SUPPORT_SDMA_MGCG |
641 AMD_CG_SUPPORT_SDMA_LS |
642 AMD_CG_SUPPORT_MC_MGCG |
643 AMD_CG_SUPPORT_MC_LS;
644 adev->pg_flags = 0;
645 adev->external_rev_id = 0x1;
646 break;
Hawking Zhang957c6fe2016-12-27 21:02:48 +0800647 case CHIP_RAVEN:
Huang Rui5c5928a2017-01-18 18:14:08 +0800648 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
649 AMD_CG_SUPPORT_GFX_MGLS |
650 AMD_CG_SUPPORT_GFX_RLC_LS |
651 AMD_CG_SUPPORT_GFX_CP_LS |
652 AMD_CG_SUPPORT_GFX_3D_CGCG |
653 AMD_CG_SUPPORT_GFX_3D_CGLS |
654 AMD_CG_SUPPORT_GFX_CGCG |
655 AMD_CG_SUPPORT_GFX_CGLS |
656 AMD_CG_SUPPORT_BIF_MGCG |
657 AMD_CG_SUPPORT_BIF_LS |
658 AMD_CG_SUPPORT_HDP_MGCG |
659 AMD_CG_SUPPORT_HDP_LS |
660 AMD_CG_SUPPORT_DRM_MGCG |
661 AMD_CG_SUPPORT_DRM_LS |
Huang Ruic2cdb0e2017-05-05 14:27:23 -0400662 AMD_CG_SUPPORT_ROM_MGCG |
663 AMD_CG_SUPPORT_MC_MGCG |
Huang Ruife1a3b22017-05-05 14:28:27 -0400664 AMD_CG_SUPPORT_MC_LS |
665 AMD_CG_SUPPORT_SDMA_MGCG |
666 AMD_CG_SUPPORT_SDMA_LS;
Hawking Zhang32622ad2017-06-19 14:40:19 +0800667 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
668 AMD_PG_SUPPORT_MMHUB;
Hawking Zhang957c6fe2016-12-27 21:02:48 +0800669 adev->external_rev_id = 0x1;
670 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500671 default:
672 /* FIXME: not supported yet */
673 return -EINVAL;
674 }
675
Xiangliang Yuab276632017-04-21 14:06:09 +0800676 if (amdgpu_sriov_vf(adev)) {
677 amdgpu_virt_init_setting(adev);
678 xgpu_ai_mailbox_set_irq_funcs(adev);
679 }
680
Ken Wang220ab9b2017-03-06 14:49:53 -0500681 adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type);
682
683 amdgpu_get_pcie_info(adev);
684
685 return 0;
686}
687
Monk Liu81758c52017-04-05 13:04:50 +0800688static int soc15_common_late_init(void *handle)
689{
690 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
691
692 if (amdgpu_sriov_vf(adev))
693 xgpu_ai_mailbox_get_irq(adev);
694
695 return 0;
696}
697
Ken Wang220ab9b2017-03-06 14:49:53 -0500698static int soc15_common_sw_init(void *handle)
699{
Monk Liu81758c52017-04-05 13:04:50 +0800700 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
701
702 if (amdgpu_sriov_vf(adev))
703 xgpu_ai_mailbox_add_irq_id(adev);
704
Ken Wang220ab9b2017-03-06 14:49:53 -0500705 return 0;
706}
707
708static int soc15_common_sw_fini(void *handle)
709{
710 return 0;
711}
712
713static int soc15_common_hw_init(void *handle)
714{
715 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
716
717 /* move the golden regs per IP block */
718 soc15_init_golden_registers(adev);
719 /* enable pcie gen2/3 link */
720 soc15_pcie_gen3_enable(adev);
721 /* enable aspm */
722 soc15_program_aspm(adev);
Alex Deucher833fa072017-07-06 13:43:55 -0400723 /* setup nbio registers */
724 if (!(adev->flags & AMD_IS_APU))
725 nbio_v6_1_init_registers(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500726 /* enable the doorbell aperture */
727 soc15_enable_doorbell_aperture(adev, true);
728
729 return 0;
730}
731
732static int soc15_common_hw_fini(void *handle)
733{
734 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
735
736 /* disable the doorbell aperture */
737 soc15_enable_doorbell_aperture(adev, false);
Monk Liu81758c52017-04-05 13:04:50 +0800738 if (amdgpu_sriov_vf(adev))
739 xgpu_ai_mailbox_put_irq(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500740
741 return 0;
742}
743
744static int soc15_common_suspend(void *handle)
745{
746 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
747
748 return soc15_common_hw_fini(adev);
749}
750
751static int soc15_common_resume(void *handle)
752{
753 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
754
755 return soc15_common_hw_init(adev);
756}
757
758static bool soc15_common_is_idle(void *handle)
759{
760 return true;
761}
762
763static int soc15_common_wait_for_idle(void *handle)
764{
765 return 0;
766}
767
768static int soc15_common_soft_reset(void *handle)
769{
770 return 0;
771}
772
773static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
774{
775 uint32_t def, data;
776
777 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
778
779 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
780 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
781 else
782 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
783
784 if (def != data)
785 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
786}
787
788static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
789{
790 uint32_t def, data;
791
792 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
793
794 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
795 data &= ~(0x01000000 |
796 0x02000000 |
797 0x04000000 |
798 0x08000000 |
799 0x10000000 |
800 0x20000000 |
801 0x40000000 |
802 0x80000000);
803 else
804 data |= (0x01000000 |
805 0x02000000 |
806 0x04000000 |
807 0x08000000 |
808 0x10000000 |
809 0x20000000 |
810 0x40000000 |
811 0x80000000);
812
813 if (def != data)
814 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
815}
816
817static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
818{
819 uint32_t def, data;
820
821 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
822
823 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
824 data |= 1;
825 else
826 data &= ~1;
827
828 if (def != data)
829 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
830}
831
832static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
833 bool enable)
834{
835 uint32_t def, data;
836
837 def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
838
839 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
840 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
841 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
842 else
843 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
844 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
845
846 if (def != data)
847 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
848}
849
850static void soc15_update_df_medium_grain_clock_gating(struct amdgpu_device *adev,
851 bool enable)
852{
853 uint32_t data;
854
855 /* Put DF on broadcast mode */
856 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl));
857 data &= ~FabricConfigAccessControl__CfgRegInstAccEn_MASK;
858 WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl), data);
859
860 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DF_MGCG)) {
861 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
862 data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
863 data |= DF_MGCG_ENABLE_15_CYCLE_DELAY;
864 WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
865 } else {
866 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
867 data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
868 data |= DF_MGCG_DISABLE;
869 WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
870 }
871
872 WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl),
873 mmFabricConfigAccessControl_DEFAULT);
874}
875
876static int soc15_common_set_clockgating_state(void *handle,
877 enum amd_clockgating_state state)
878{
879 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
880
Monk Liu6e9dc862017-03-22 18:02:40 +0800881 if (amdgpu_sriov_vf(adev))
882 return 0;
883
Ken Wang220ab9b2017-03-06 14:49:53 -0500884 switch (adev->asic_type) {
885 case CHIP_VEGA10:
886 nbio_v6_1_update_medium_grain_clock_gating(adev,
887 state == AMD_CG_STATE_GATE ? true : false);
888 nbio_v6_1_update_medium_grain_light_sleep(adev,
889 state == AMD_CG_STATE_GATE ? true : false);
890 soc15_update_hdp_light_sleep(adev,
891 state == AMD_CG_STATE_GATE ? true : false);
892 soc15_update_drm_clock_gating(adev,
893 state == AMD_CG_STATE_GATE ? true : false);
894 soc15_update_drm_light_sleep(adev,
895 state == AMD_CG_STATE_GATE ? true : false);
896 soc15_update_rom_medium_grain_clock_gating(adev,
897 state == AMD_CG_STATE_GATE ? true : false);
898 soc15_update_df_medium_grain_clock_gating(adev,
899 state == AMD_CG_STATE_GATE ? true : false);
900 break;
Huang Rui9e5a9eb2017-01-18 18:12:59 +0800901 case CHIP_RAVEN:
Huang Rui7fda6ec2017-02-27 14:01:55 +0800902 nbio_v7_0_update_medium_grain_clock_gating(adev,
Huang Rui9e5a9eb2017-01-18 18:12:59 +0800903 state == AMD_CG_STATE_GATE ? true : false);
904 nbio_v6_1_update_medium_grain_light_sleep(adev,
905 state == AMD_CG_STATE_GATE ? true : false);
906 soc15_update_hdp_light_sleep(adev,
907 state == AMD_CG_STATE_GATE ? true : false);
908 soc15_update_drm_clock_gating(adev,
909 state == AMD_CG_STATE_GATE ? true : false);
910 soc15_update_drm_light_sleep(adev,
911 state == AMD_CG_STATE_GATE ? true : false);
912 soc15_update_rom_medium_grain_clock_gating(adev,
913 state == AMD_CG_STATE_GATE ? true : false);
914 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500915 default:
916 break;
917 }
918 return 0;
919}
920
Huang Ruif9abe352017-03-24 10:46:16 +0800921static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
922{
923 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
924 int data;
925
926 if (amdgpu_sriov_vf(adev))
927 *flags = 0;
928
929 nbio_v6_1_get_clockgating_state(adev, flags);
930
931 /* AMD_CG_SUPPORT_HDP_LS */
932 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
933 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
934 *flags |= AMD_CG_SUPPORT_HDP_LS;
935
936 /* AMD_CG_SUPPORT_DRM_MGCG */
937 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
938 if (!(data & 0x01000000))
939 *flags |= AMD_CG_SUPPORT_DRM_MGCG;
940
941 /* AMD_CG_SUPPORT_DRM_LS */
942 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
943 if (data & 0x1)
944 *flags |= AMD_CG_SUPPORT_DRM_LS;
945
946 /* AMD_CG_SUPPORT_ROM_MGCG */
947 data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
948 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
949 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
950
951 /* AMD_CG_SUPPORT_DF_MGCG */
952 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
953 if (data & DF_MGCG_ENABLE_15_CYCLE_DELAY)
954 *flags |= AMD_CG_SUPPORT_DF_MGCG;
955}
956
Ken Wang220ab9b2017-03-06 14:49:53 -0500957static int soc15_common_set_powergating_state(void *handle,
958 enum amd_powergating_state state)
959{
960 /* todo */
961 return 0;
962}
963
964const struct amd_ip_funcs soc15_common_ip_funcs = {
965 .name = "soc15_common",
966 .early_init = soc15_common_early_init,
Monk Liu81758c52017-04-05 13:04:50 +0800967 .late_init = soc15_common_late_init,
Ken Wang220ab9b2017-03-06 14:49:53 -0500968 .sw_init = soc15_common_sw_init,
969 .sw_fini = soc15_common_sw_fini,
970 .hw_init = soc15_common_hw_init,
971 .hw_fini = soc15_common_hw_fini,
972 .suspend = soc15_common_suspend,
973 .resume = soc15_common_resume,
974 .is_idle = soc15_common_is_idle,
975 .wait_for_idle = soc15_common_wait_for_idle,
976 .soft_reset = soc15_common_soft_reset,
977 .set_clockgating_state = soc15_common_set_clockgating_state,
978 .set_powergating_state = soc15_common_set_powergating_state,
Huang Ruif9abe352017-03-24 10:46:16 +0800979 .get_clockgating_state= soc15_common_get_clockgating_state,
Ken Wang220ab9b2017-03-06 14:49:53 -0500980};