blob: 68ce1e8e9b64a8f96e85026b036324cead3913fe [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>
26#include "drmP.h"
27#include "amdgpu.h"
Alex Deucherbfc181a2017-05-05 10:26:12 -040028#include "amdgpu_atomfirmware.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"
60#include "amdgpu_powerplay.h"
Xiangliang Yu796b6562017-02-28 17:22:03 +080061#include "dce_virtual.h"
Xiangliang Yuf1a34462017-03-08 15:06:47 +080062#include "mxgpu_ai.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050063
64MODULE_FIRMWARE("amdgpu/vega10_smc.bin");
65
66#define mmFabricConfigAccessControl 0x0410
67#define mmFabricConfigAccessControl_BASE_IDX 0
68#define mmFabricConfigAccessControl_DEFAULT 0x00000000
69//FabricConfigAccessControl
70#define FabricConfigAccessControl__CfgRegInstAccEn__SHIFT 0x0
71#define FabricConfigAccessControl__CfgRegInstAccRegLock__SHIFT 0x1
72#define FabricConfigAccessControl__CfgRegInstID__SHIFT 0x10
73#define FabricConfigAccessControl__CfgRegInstAccEn_MASK 0x00000001L
74#define FabricConfigAccessControl__CfgRegInstAccRegLock_MASK 0x00000002L
75#define FabricConfigAccessControl__CfgRegInstID_MASK 0x00FF0000L
76
77
78#define mmDF_PIE_AON0_DfGlobalClkGater 0x00fc
79#define mmDF_PIE_AON0_DfGlobalClkGater_BASE_IDX 0
80//DF_PIE_AON0_DfGlobalClkGater
81#define DF_PIE_AON0_DfGlobalClkGater__MGCGMode__SHIFT 0x0
82#define DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK 0x0000000FL
83
84enum {
85 DF_MGCG_DISABLE = 0,
86 DF_MGCG_ENABLE_00_CYCLE_DELAY =1,
87 DF_MGCG_ENABLE_01_CYCLE_DELAY =2,
88 DF_MGCG_ENABLE_15_CYCLE_DELAY =13,
89 DF_MGCG_ENABLE_31_CYCLE_DELAY =14,
90 DF_MGCG_ENABLE_63_CYCLE_DELAY =15
91};
92
93#define mmMP0_MISC_CGTT_CTRL0 0x01b9
94#define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
95#define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
96#define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
97
98/*
99 * Indirect registers accessor
100 */
101static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
102{
103 unsigned long flags, address, data;
104 u32 r;
105 struct nbio_pcie_index_data *nbio_pcie_id;
106
107 if (adev->asic_type == CHIP_VEGA10)
108 nbio_pcie_id = &nbio_v6_1_pcie_index_data;
Alex Deucher1fdc6392017-04-03 16:56:08 -0400109 else
110 BUG();
Ken Wang220ab9b2017-03-06 14:49:53 -0500111
112 address = nbio_pcie_id->index_offset;
113 data = nbio_pcie_id->data_offset;
114
115 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
116 WREG32(address, reg);
117 (void)RREG32(address);
118 r = RREG32(data);
119 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
120 return r;
121}
122
123static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
124{
125 unsigned long flags, address, data;
126 struct nbio_pcie_index_data *nbio_pcie_id;
127
128 if (adev->asic_type == CHIP_VEGA10)
129 nbio_pcie_id = &nbio_v6_1_pcie_index_data;
Alex Deucher1fdc6392017-04-03 16:56:08 -0400130 else
131 BUG();
Ken Wang220ab9b2017-03-06 14:49:53 -0500132
133 address = nbio_pcie_id->index_offset;
134 data = nbio_pcie_id->data_offset;
135
136 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
137 WREG32(address, reg);
138 (void)RREG32(address);
139 WREG32(data, v);
140 (void)RREG32(data);
141 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
142}
143
144static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
145{
146 unsigned long flags, address, data;
147 u32 r;
148
149 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
150 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
151
152 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
153 WREG32(address, ((reg) & 0x1ff));
154 r = RREG32(data);
155 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
156 return r;
157}
158
159static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
160{
161 unsigned long flags, address, data;
162
163 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
164 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
165
166 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
167 WREG32(address, ((reg) & 0x1ff));
168 WREG32(data, (v));
169 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
170}
171
172static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
173{
174 unsigned long flags, address, data;
175 u32 r;
176
177 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
178 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
179
180 spin_lock_irqsave(&adev->didt_idx_lock, flags);
181 WREG32(address, (reg));
182 r = RREG32(data);
183 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
184 return r;
185}
186
187static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
188{
189 unsigned long flags, address, data;
190
191 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
192 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
193
194 spin_lock_irqsave(&adev->didt_idx_lock, flags);
195 WREG32(address, (reg));
196 WREG32(data, (v));
197 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
198}
199
200static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
201{
202 return nbio_v6_1_get_memsize(adev);
203}
204
205static const u32 vega10_golden_init[] =
206{
207};
208
209static void soc15_init_golden_registers(struct amdgpu_device *adev)
210{
211 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
212 mutex_lock(&adev->grbm_idx_mutex);
213
214 switch (adev->asic_type) {
215 case CHIP_VEGA10:
216 amdgpu_program_register_sequence(adev,
217 vega10_golden_init,
218 (const u32)ARRAY_SIZE(vega10_golden_init));
219 break;
220 default:
221 break;
222 }
223 mutex_unlock(&adev->grbm_idx_mutex);
224}
225static u32 soc15_get_xclk(struct amdgpu_device *adev)
226{
227 if (adev->asic_type == CHIP_VEGA10)
228 return adev->clock.spll.reference_freq/4;
229 else
230 return adev->clock.spll.reference_freq;
231}
232
233
234void soc15_grbm_select(struct amdgpu_device *adev,
235 u32 me, u32 pipe, u32 queue, u32 vmid)
236{
237 u32 grbm_gfx_cntl = 0;
238 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
239 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
240 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
241 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
242
243 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
244}
245
246static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
247{
248 /* todo */
249}
250
251static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
252{
253 /* todo */
254 return false;
255}
256
257static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
258 u8 *bios, u32 length_bytes)
259{
260 u32 *dw_ptr;
261 u32 i, length_dw;
262
263 if (bios == NULL)
264 return false;
265 if (length_bytes == 0)
266 return false;
267 /* APU vbios image is part of sbios image */
268 if (adev->flags & AMD_IS_APU)
269 return false;
270
271 dw_ptr = (u32 *)bios;
272 length_dw = ALIGN(length_bytes, 4) / 4;
273
274 /* set rom index to 0 */
275 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
276 /* read out the rom data */
277 for (i = 0; i < length_dw; i++)
278 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
279
280 return true;
281}
282
283static struct amdgpu_allowed_register_entry vega10_allowed_read_registers[] = {
284 /* todo */
285};
286
287static struct amdgpu_allowed_register_entry soc15_allowed_read_registers[] = {
Christian König97fcc762017-04-12 12:49:54 +0200288 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS)},
289 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS2)},
290 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE0)},
291 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE1)},
292 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE2)},
293 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE3)},
294 { SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_STATUS_REG)},
295 { SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_STATUS_REG)},
296 { SOC15_REG_OFFSET(GC, 0, mmCP_STAT)},
297 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT1)},
298 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT2)},
299 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT3)},
300 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_BUSY_STAT)},
301 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STALLED_STAT1)},
302 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STATUS)},
303 { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STALLED_STAT1)},
304 { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STATUS)},
305 { SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)},
Ken Wang220ab9b2017-03-06 14:49:53 -0500306};
307
308static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
309 u32 sh_num, u32 reg_offset)
310{
311 uint32_t val;
312
313 mutex_lock(&adev->grbm_idx_mutex);
314 if (se_num != 0xffffffff || sh_num != 0xffffffff)
315 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
316
317 val = RREG32(reg_offset);
318
319 if (se_num != 0xffffffff || sh_num != 0xffffffff)
320 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
321 mutex_unlock(&adev->grbm_idx_mutex);
322 return val;
323}
324
Alex Deucherc013cea2017-03-24 15:05:07 -0400325static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
326 bool indexed, u32 se_num,
327 u32 sh_num, u32 reg_offset)
328{
329 if (indexed) {
330 return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
331 } else {
332 switch (reg_offset) {
333 case SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG):
334 return adev->gfx.config.gb_addr_config;
335 default:
336 return RREG32(reg_offset);
337 }
338 }
339}
340
Ken Wang220ab9b2017-03-06 14:49:53 -0500341static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
342 u32 sh_num, u32 reg_offset, u32 *value)
343{
344 struct amdgpu_allowed_register_entry *asic_register_table = NULL;
345 struct amdgpu_allowed_register_entry *asic_register_entry;
346 uint32_t size, i;
347
348 *value = 0;
349 switch (adev->asic_type) {
350 case CHIP_VEGA10:
351 asic_register_table = vega10_allowed_read_registers;
352 size = ARRAY_SIZE(vega10_allowed_read_registers);
353 break;
354 default:
355 return -EINVAL;
356 }
357
358 if (asic_register_table) {
359 for (i = 0; i < size; i++) {
360 asic_register_entry = asic_register_table + i;
361 if (reg_offset != asic_register_entry->reg_offset)
362 continue;
Christian König97fcc762017-04-12 12:49:54 +0200363 *value = soc15_get_register_value(adev,
364 asic_register_entry->grbm_indexed,
365 se_num, sh_num, reg_offset);
Ken Wang220ab9b2017-03-06 14:49:53 -0500366 return 0;
367 }
368 }
369
370 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
371 if (reg_offset != soc15_allowed_read_registers[i].reg_offset)
372 continue;
373
Christian König97fcc762017-04-12 12:49:54 +0200374 *value = soc15_get_register_value(adev,
375 soc15_allowed_read_registers[i].grbm_indexed,
376 se_num, sh_num, reg_offset);
Ken Wang220ab9b2017-03-06 14:49:53 -0500377 return 0;
378 }
379 return -EINVAL;
380}
381
382static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev)
383{
384 u32 i;
385
386 dev_info(adev->dev, "GPU pci config reset\n");
387
388 /* disable BM */
389 pci_clear_master(adev->pdev);
390 /* reset */
391 amdgpu_pci_config_reset(adev);
392
393 udelay(100);
394
395 /* wait for asic to come out of reset */
396 for (i = 0; i < adev->usec_timeout; i++) {
397 if (nbio_v6_1_get_memsize(adev) != 0xffffffff)
398 break;
399 udelay(1);
400 }
401
402}
403
404static int soc15_asic_reset(struct amdgpu_device *adev)
405{
Alex Deucherbfc181a2017-05-05 10:26:12 -0400406 amdgpu_atomfirmware_scratch_regs_engine_hung(adev, true);
Ken Wang220ab9b2017-03-06 14:49:53 -0500407
408 soc15_gpu_pci_config_reset(adev);
409
Alex Deucherbfc181a2017-05-05 10:26:12 -0400410 amdgpu_atomfirmware_scratch_regs_engine_hung(adev, false);
Ken Wang220ab9b2017-03-06 14:49:53 -0500411
412 return 0;
413}
414
415/*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
416 u32 cntl_reg, u32 status_reg)
417{
418 return 0;
419}*/
420
421static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
422{
423 /*int r;
424
425 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
426 if (r)
427 return r;
428
429 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
430 */
431 return 0;
432}
433
434static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
435{
436 /* todo */
437
438 return 0;
439}
440
441static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
442{
443 if (pci_is_root_bus(adev->pdev->bus))
444 return;
445
446 if (amdgpu_pcie_gen2 == 0)
447 return;
448
449 if (adev->flags & AMD_IS_APU)
450 return;
451
452 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
453 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
454 return;
455
456 /* todo */
457}
458
459static void soc15_program_aspm(struct amdgpu_device *adev)
460{
461
462 if (amdgpu_aspm == 0)
463 return;
464
465 /* todo */
466}
467
468static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
469 bool enable)
470{
471 nbio_v6_1_enable_doorbell_aperture(adev, enable);
472 nbio_v6_1_enable_doorbell_selfring_aperture(adev, enable);
473}
474
475static const struct amdgpu_ip_block_version vega10_common_ip_block =
476{
477 .type = AMD_IP_BLOCK_TYPE_COMMON,
478 .major = 2,
479 .minor = 0,
480 .rev = 0,
481 .funcs = &soc15_common_ip_funcs,
482};
483
484int soc15_set_ip_blocks(struct amdgpu_device *adev)
485{
Xiangliang Yu1b922422017-03-08 15:00:48 +0800486 nbio_v6_1_detect_hw_virt(adev);
487
Xiangliang Yuf1a34462017-03-08 15:06:47 +0800488 if (amdgpu_sriov_vf(adev))
489 adev->virt.ops = &xgpu_ai_virt_ops;
490
Ken Wang220ab9b2017-03-06 14:49:53 -0500491 switch (adev->asic_type) {
492 case CHIP_VEGA10:
493 amdgpu_ip_block_add(adev, &vega10_common_ip_block);
494 amdgpu_ip_block_add(adev, &gfxhub_v1_0_ip_block);
495 amdgpu_ip_block_add(adev, &mmhub_v1_0_ip_block);
496 amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block);
497 amdgpu_ip_block_add(adev, &vega10_ih_ip_block);
Monk Liubb5c9ca2017-03-30 18:00:20 +0800498 if (amdgpu_fw_load_type == 2 || amdgpu_fw_load_type == -1)
499 amdgpu_ip_block_add(adev, &psp_v3_1_ip_block);
Xiangliang Yuc6f3e7c2017-03-28 19:16:42 +0800500 if (!amdgpu_sriov_vf(adev))
Xiangliang Yucfd83732017-02-28 17:26:40 +0800501 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
Alex Deucherf8445302017-03-22 10:49:25 -0400502 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Xiangliang Yu796b6562017-02-28 17:22:03 +0800503 amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500504 amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block);
505 amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block);
Frank Min91faed92017-04-17 11:19:45 +0800506 amdgpu_ip_block_add(adev, &uvd_v7_0_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500507 amdgpu_ip_block_add(adev, &vce_v4_0_ip_block);
508 break;
509 default:
510 return -EINVAL;
511 }
512
513 return 0;
514}
515
516static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
517{
518 return nbio_v6_1_get_rev_id(adev);
519}
520
521
522int gmc_v9_0_mc_wait_for_idle(struct amdgpu_device *adev)
523{
524 /* to be implemented in MC IP*/
525 return 0;
526}
527
528static const struct amdgpu_asic_funcs soc15_asic_funcs =
529{
530 .read_disabled_bios = &soc15_read_disabled_bios,
531 .read_bios_from_rom = &soc15_read_bios_from_rom,
532 .read_register = &soc15_read_register,
533 .reset = &soc15_asic_reset,
534 .set_vga_state = &soc15_vga_set_state,
535 .get_xclk = &soc15_get_xclk,
536 .set_uvd_clocks = &soc15_set_uvd_clocks,
537 .set_vce_clocks = &soc15_set_vce_clocks,
538 .get_config_memsize = &soc15_get_config_memsize,
539};
540
541static int soc15_common_early_init(void *handle)
542{
543 bool psp_enabled = false;
544 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
545
546 adev->smc_rreg = NULL;
547 adev->smc_wreg = NULL;
548 adev->pcie_rreg = &soc15_pcie_rreg;
549 adev->pcie_wreg = &soc15_pcie_wreg;
550 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
551 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
552 adev->didt_rreg = &soc15_didt_rreg;
553 adev->didt_wreg = &soc15_didt_wreg;
554
555 adev->asic_funcs = &soc15_asic_funcs;
556
557 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP) &&
558 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_PSP)))
559 psp_enabled = true;
560
Monk Liub4d61262017-03-21 16:41:01 +0800561 if (amdgpu_sriov_vf(adev)) {
562 amdgpu_virt_init_setting(adev);
Monk Liu81758c52017-04-05 13:04:50 +0800563 xgpu_ai_mailbox_set_irq_funcs(adev);
Monk Liub4d61262017-03-21 16:41:01 +0800564 }
565
Ken Wang220ab9b2017-03-06 14:49:53 -0500566 /*
567 * nbio need be used for both sdma and gfx9, but only
568 * initializes once
569 */
570 switch(adev->asic_type) {
571 case CHIP_VEGA10:
572 nbio_v6_1_init(adev);
573 break;
574 default:
575 return -EINVAL;
576 }
577
578 adev->rev_id = soc15_get_rev_id(adev);
579 adev->external_rev_id = 0xFF;
580 switch (adev->asic_type) {
581 case CHIP_VEGA10:
582 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
583 AMD_CG_SUPPORT_GFX_MGLS |
584 AMD_CG_SUPPORT_GFX_RLC_LS |
585 AMD_CG_SUPPORT_GFX_CP_LS |
586 AMD_CG_SUPPORT_GFX_3D_CGCG |
587 AMD_CG_SUPPORT_GFX_3D_CGLS |
588 AMD_CG_SUPPORT_GFX_CGCG |
589 AMD_CG_SUPPORT_GFX_CGLS |
590 AMD_CG_SUPPORT_BIF_MGCG |
591 AMD_CG_SUPPORT_BIF_LS |
592 AMD_CG_SUPPORT_HDP_LS |
593 AMD_CG_SUPPORT_DRM_MGCG |
594 AMD_CG_SUPPORT_DRM_LS |
595 AMD_CG_SUPPORT_ROM_MGCG |
596 AMD_CG_SUPPORT_DF_MGCG |
597 AMD_CG_SUPPORT_SDMA_MGCG |
598 AMD_CG_SUPPORT_SDMA_LS |
599 AMD_CG_SUPPORT_MC_MGCG |
600 AMD_CG_SUPPORT_MC_LS;
601 adev->pg_flags = 0;
602 adev->external_rev_id = 0x1;
603 break;
604 default:
605 /* FIXME: not supported yet */
606 return -EINVAL;
607 }
608
609 adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type);
610
611 amdgpu_get_pcie_info(adev);
612
613 return 0;
614}
615
Monk Liu81758c52017-04-05 13:04:50 +0800616static int soc15_common_late_init(void *handle)
617{
618 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
619
620 if (amdgpu_sriov_vf(adev))
621 xgpu_ai_mailbox_get_irq(adev);
622
623 return 0;
624}
625
Ken Wang220ab9b2017-03-06 14:49:53 -0500626static int soc15_common_sw_init(void *handle)
627{
Monk Liu81758c52017-04-05 13:04:50 +0800628 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
629
630 if (amdgpu_sriov_vf(adev))
631 xgpu_ai_mailbox_add_irq_id(adev);
632
Ken Wang220ab9b2017-03-06 14:49:53 -0500633 return 0;
634}
635
636static int soc15_common_sw_fini(void *handle)
637{
638 return 0;
639}
640
641static int soc15_common_hw_init(void *handle)
642{
643 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
644
645 /* move the golden regs per IP block */
646 soc15_init_golden_registers(adev);
647 /* enable pcie gen2/3 link */
648 soc15_pcie_gen3_enable(adev);
649 /* enable aspm */
650 soc15_program_aspm(adev);
651 /* enable the doorbell aperture */
652 soc15_enable_doorbell_aperture(adev, true);
653
654 return 0;
655}
656
657static int soc15_common_hw_fini(void *handle)
658{
659 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
660
661 /* disable the doorbell aperture */
662 soc15_enable_doorbell_aperture(adev, false);
Monk Liu81758c52017-04-05 13:04:50 +0800663 if (amdgpu_sriov_vf(adev))
664 xgpu_ai_mailbox_put_irq(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500665
666 return 0;
667}
668
669static int soc15_common_suspend(void *handle)
670{
671 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
672
673 return soc15_common_hw_fini(adev);
674}
675
676static int soc15_common_resume(void *handle)
677{
678 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
679
680 return soc15_common_hw_init(adev);
681}
682
683static bool soc15_common_is_idle(void *handle)
684{
685 return true;
686}
687
688static int soc15_common_wait_for_idle(void *handle)
689{
690 return 0;
691}
692
693static int soc15_common_soft_reset(void *handle)
694{
695 return 0;
696}
697
698static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
699{
700 uint32_t def, data;
701
702 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
703
704 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
705 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
706 else
707 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
708
709 if (def != data)
710 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
711}
712
713static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
714{
715 uint32_t def, data;
716
717 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
718
719 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
720 data &= ~(0x01000000 |
721 0x02000000 |
722 0x04000000 |
723 0x08000000 |
724 0x10000000 |
725 0x20000000 |
726 0x40000000 |
727 0x80000000);
728 else
729 data |= (0x01000000 |
730 0x02000000 |
731 0x04000000 |
732 0x08000000 |
733 0x10000000 |
734 0x20000000 |
735 0x40000000 |
736 0x80000000);
737
738 if (def != data)
739 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
740}
741
742static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
743{
744 uint32_t def, data;
745
746 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
747
748 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
749 data |= 1;
750 else
751 data &= ~1;
752
753 if (def != data)
754 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
755}
756
757static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
758 bool enable)
759{
760 uint32_t def, data;
761
762 def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
763
764 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
765 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
766 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
767 else
768 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
769 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
770
771 if (def != data)
772 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
773}
774
775static void soc15_update_df_medium_grain_clock_gating(struct amdgpu_device *adev,
776 bool enable)
777{
778 uint32_t data;
779
780 /* Put DF on broadcast mode */
781 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl));
782 data &= ~FabricConfigAccessControl__CfgRegInstAccEn_MASK;
783 WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl), data);
784
785 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DF_MGCG)) {
786 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
787 data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
788 data |= DF_MGCG_ENABLE_15_CYCLE_DELAY;
789 WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
790 } else {
791 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
792 data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
793 data |= DF_MGCG_DISABLE;
794 WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
795 }
796
797 WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl),
798 mmFabricConfigAccessControl_DEFAULT);
799}
800
801static int soc15_common_set_clockgating_state(void *handle,
802 enum amd_clockgating_state state)
803{
804 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
805
Monk Liu6e9dc862017-03-22 18:02:40 +0800806 if (amdgpu_sriov_vf(adev))
807 return 0;
808
Ken Wang220ab9b2017-03-06 14:49:53 -0500809 switch (adev->asic_type) {
810 case CHIP_VEGA10:
811 nbio_v6_1_update_medium_grain_clock_gating(adev,
812 state == AMD_CG_STATE_GATE ? true : false);
813 nbio_v6_1_update_medium_grain_light_sleep(adev,
814 state == AMD_CG_STATE_GATE ? true : false);
815 soc15_update_hdp_light_sleep(adev,
816 state == AMD_CG_STATE_GATE ? true : false);
817 soc15_update_drm_clock_gating(adev,
818 state == AMD_CG_STATE_GATE ? true : false);
819 soc15_update_drm_light_sleep(adev,
820 state == AMD_CG_STATE_GATE ? true : false);
821 soc15_update_rom_medium_grain_clock_gating(adev,
822 state == AMD_CG_STATE_GATE ? true : false);
823 soc15_update_df_medium_grain_clock_gating(adev,
824 state == AMD_CG_STATE_GATE ? true : false);
825 break;
826 default:
827 break;
828 }
829 return 0;
830}
831
Huang Ruif9abe352017-03-24 10:46:16 +0800832static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
833{
834 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
835 int data;
836
837 if (amdgpu_sriov_vf(adev))
838 *flags = 0;
839
840 nbio_v6_1_get_clockgating_state(adev, flags);
841
842 /* AMD_CG_SUPPORT_HDP_LS */
843 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
844 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
845 *flags |= AMD_CG_SUPPORT_HDP_LS;
846
847 /* AMD_CG_SUPPORT_DRM_MGCG */
848 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
849 if (!(data & 0x01000000))
850 *flags |= AMD_CG_SUPPORT_DRM_MGCG;
851
852 /* AMD_CG_SUPPORT_DRM_LS */
853 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
854 if (data & 0x1)
855 *flags |= AMD_CG_SUPPORT_DRM_LS;
856
857 /* AMD_CG_SUPPORT_ROM_MGCG */
858 data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
859 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
860 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
861
862 /* AMD_CG_SUPPORT_DF_MGCG */
863 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
864 if (data & DF_MGCG_ENABLE_15_CYCLE_DELAY)
865 *flags |= AMD_CG_SUPPORT_DF_MGCG;
866}
867
Ken Wang220ab9b2017-03-06 14:49:53 -0500868static int soc15_common_set_powergating_state(void *handle,
869 enum amd_powergating_state state)
870{
871 /* todo */
872 return 0;
873}
874
875const struct amd_ip_funcs soc15_common_ip_funcs = {
876 .name = "soc15_common",
877 .early_init = soc15_common_early_init,
Monk Liu81758c52017-04-05 13:04:50 +0800878 .late_init = soc15_common_late_init,
Ken Wang220ab9b2017-03-06 14:49:53 -0500879 .sw_init = soc15_common_sw_init,
880 .sw_fini = soc15_common_sw_fini,
881 .hw_init = soc15_common_hw_init,
882 .hw_fini = soc15_common_hw_fini,
883 .suspend = soc15_common_suspend,
884 .resume = soc15_common_resume,
885 .is_idle = soc15_common_is_idle,
886 .wait_for_idle = soc15_common_wait_for_idle,
887 .soft_reset = soc15_common_soft_reset,
888 .set_clockgating_state = soc15_common_set_clockgating_state,
889 .set_powergating_state = soc15_common_set_powergating_state,
Huang Ruif9abe352017-03-24 10:46:16 +0800890 .get_clockgating_state= soc15_common_get_clockgating_state,
Ken Wang220ab9b2017-03-06 14:49:53 -0500891};