blob: 333edbf564df373ec80f6c6bf287491bb9f0fe25 [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"
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 "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 Yuf1a34462017-03-08 15:06:47 +080061#include "mxgpu_ai.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050062
63MODULE_FIRMWARE("amdgpu/vega10_smc.bin");
64
65#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
106 if (adev->asic_type == CHIP_VEGA10)
107 nbio_pcie_id = &nbio_v6_1_pcie_index_data;
108
109 address = nbio_pcie_id->index_offset;
110 data = nbio_pcie_id->data_offset;
111
112 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
113 WREG32(address, reg);
114 (void)RREG32(address);
115 r = RREG32(data);
116 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
117 return r;
118}
119
120static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
121{
122 unsigned long flags, address, data;
123 struct nbio_pcie_index_data *nbio_pcie_id;
124
125 if (adev->asic_type == CHIP_VEGA10)
126 nbio_pcie_id = &nbio_v6_1_pcie_index_data;
127
128 address = nbio_pcie_id->index_offset;
129 data = nbio_pcie_id->data_offset;
130
131 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
132 WREG32(address, reg);
133 (void)RREG32(address);
134 WREG32(data, v);
135 (void)RREG32(data);
136 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
137}
138
139static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
140{
141 unsigned long flags, address, data;
142 u32 r;
143
144 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
145 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
146
147 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
148 WREG32(address, ((reg) & 0x1ff));
149 r = RREG32(data);
150 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
151 return r;
152}
153
154static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
155{
156 unsigned long flags, address, data;
157
158 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
159 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
160
161 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
162 WREG32(address, ((reg) & 0x1ff));
163 WREG32(data, (v));
164 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
165}
166
167static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
168{
169 unsigned long flags, address, data;
170 u32 r;
171
172 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
173 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
174
175 spin_lock_irqsave(&adev->didt_idx_lock, flags);
176 WREG32(address, (reg));
177 r = RREG32(data);
178 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
179 return r;
180}
181
182static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
183{
184 unsigned long flags, address, data;
185
186 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
187 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
188
189 spin_lock_irqsave(&adev->didt_idx_lock, flags);
190 WREG32(address, (reg));
191 WREG32(data, (v));
192 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
193}
194
195static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
196{
197 return nbio_v6_1_get_memsize(adev);
198}
199
200static const u32 vega10_golden_init[] =
201{
202};
203
204static void soc15_init_golden_registers(struct amdgpu_device *adev)
205{
206 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
207 mutex_lock(&adev->grbm_idx_mutex);
208
209 switch (adev->asic_type) {
210 case CHIP_VEGA10:
211 amdgpu_program_register_sequence(adev,
212 vega10_golden_init,
213 (const u32)ARRAY_SIZE(vega10_golden_init));
214 break;
215 default:
216 break;
217 }
218 mutex_unlock(&adev->grbm_idx_mutex);
219}
220static u32 soc15_get_xclk(struct amdgpu_device *adev)
221{
222 if (adev->asic_type == CHIP_VEGA10)
223 return adev->clock.spll.reference_freq/4;
224 else
225 return adev->clock.spll.reference_freq;
226}
227
228
229void soc15_grbm_select(struct amdgpu_device *adev,
230 u32 me, u32 pipe, u32 queue, u32 vmid)
231{
232 u32 grbm_gfx_cntl = 0;
233 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
234 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
235 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
236 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
237
238 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
239}
240
241static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
242{
243 /* todo */
244}
245
246static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
247{
248 /* todo */
249 return false;
250}
251
252static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
253 u8 *bios, u32 length_bytes)
254{
255 u32 *dw_ptr;
256 u32 i, length_dw;
257
258 if (bios == NULL)
259 return false;
260 if (length_bytes == 0)
261 return false;
262 /* APU vbios image is part of sbios image */
263 if (adev->flags & AMD_IS_APU)
264 return false;
265
266 dw_ptr = (u32 *)bios;
267 length_dw = ALIGN(length_bytes, 4) / 4;
268
269 /* set rom index to 0 */
270 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
271 /* read out the rom data */
272 for (i = 0; i < length_dw; i++)
273 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
274
275 return true;
276}
277
278static struct amdgpu_allowed_register_entry vega10_allowed_read_registers[] = {
279 /* todo */
280};
281
282static struct amdgpu_allowed_register_entry soc15_allowed_read_registers[] = {
283 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS), false},
284 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS2), false},
285 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE0), false},
286 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE1), false},
287 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE2), false},
288 { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE3), false},
289 { SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_STATUS_REG), false},
290 { SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_STATUS_REG), false},
291 { SOC15_REG_OFFSET(GC, 0, mmCP_STAT), false},
292 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT1), false},
293 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT2), false},
294 { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT3), false},
295 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_BUSY_STAT), false},
296 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STALLED_STAT1), false},
297 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STATUS), false},
298 { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_BUSY_STAT), false},
299 { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STALLED_STAT1), false},
300 { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STATUS), false},
301 { SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG), false},
302 { SOC15_REG_OFFSET(GC, 0, mmCC_RB_BACKEND_DISABLE), false, true},
303 { SOC15_REG_OFFSET(GC, 0, mmGC_USER_RB_BACKEND_DISABLE), false, true},
304 { SOC15_REG_OFFSET(GC, 0, mmGB_BACKEND_MAP), false, false},
305};
306
307static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
308 u32 sh_num, u32 reg_offset)
309{
310 uint32_t val;
311
312 mutex_lock(&adev->grbm_idx_mutex);
313 if (se_num != 0xffffffff || sh_num != 0xffffffff)
314 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
315
316 val = RREG32(reg_offset);
317
318 if (se_num != 0xffffffff || sh_num != 0xffffffff)
319 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
320 mutex_unlock(&adev->grbm_idx_mutex);
321 return val;
322}
323
324static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
325 u32 sh_num, u32 reg_offset, u32 *value)
326{
327 struct amdgpu_allowed_register_entry *asic_register_table = NULL;
328 struct amdgpu_allowed_register_entry *asic_register_entry;
329 uint32_t size, i;
330
331 *value = 0;
332 switch (adev->asic_type) {
333 case CHIP_VEGA10:
334 asic_register_table = vega10_allowed_read_registers;
335 size = ARRAY_SIZE(vega10_allowed_read_registers);
336 break;
337 default:
338 return -EINVAL;
339 }
340
341 if (asic_register_table) {
342 for (i = 0; i < size; i++) {
343 asic_register_entry = asic_register_table + i;
344 if (reg_offset != asic_register_entry->reg_offset)
345 continue;
346 if (!asic_register_entry->untouched)
347 *value = asic_register_entry->grbm_indexed ?
348 soc15_read_indexed_register(adev, se_num,
349 sh_num, reg_offset) :
350 RREG32(reg_offset);
351 return 0;
352 }
353 }
354
355 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
356 if (reg_offset != soc15_allowed_read_registers[i].reg_offset)
357 continue;
358
359 if (!soc15_allowed_read_registers[i].untouched)
360 *value = soc15_allowed_read_registers[i].grbm_indexed ?
361 soc15_read_indexed_register(adev, se_num,
362 sh_num, reg_offset) :
363 RREG32(reg_offset);
364 return 0;
365 }
366 return -EINVAL;
367}
368
369static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev)
370{
371 u32 i;
372
373 dev_info(adev->dev, "GPU pci config reset\n");
374
375 /* disable BM */
376 pci_clear_master(adev->pdev);
377 /* reset */
378 amdgpu_pci_config_reset(adev);
379
380 udelay(100);
381
382 /* wait for asic to come out of reset */
383 for (i = 0; i < adev->usec_timeout; i++) {
384 if (nbio_v6_1_get_memsize(adev) != 0xffffffff)
385 break;
386 udelay(1);
387 }
388
389}
390
391static int soc15_asic_reset(struct amdgpu_device *adev)
392{
393 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
394
395 soc15_gpu_pci_config_reset(adev);
396
397 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
398
399 return 0;
400}
401
402/*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
403 u32 cntl_reg, u32 status_reg)
404{
405 return 0;
406}*/
407
408static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
409{
410 /*int r;
411
412 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
413 if (r)
414 return r;
415
416 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
417 */
418 return 0;
419}
420
421static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
422{
423 /* todo */
424
425 return 0;
426}
427
428static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
429{
430 if (pci_is_root_bus(adev->pdev->bus))
431 return;
432
433 if (amdgpu_pcie_gen2 == 0)
434 return;
435
436 if (adev->flags & AMD_IS_APU)
437 return;
438
439 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
440 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
441 return;
442
443 /* todo */
444}
445
446static void soc15_program_aspm(struct amdgpu_device *adev)
447{
448
449 if (amdgpu_aspm == 0)
450 return;
451
452 /* todo */
453}
454
455static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
456 bool enable)
457{
458 nbio_v6_1_enable_doorbell_aperture(adev, enable);
459 nbio_v6_1_enable_doorbell_selfring_aperture(adev, enable);
460}
461
462static const struct amdgpu_ip_block_version vega10_common_ip_block =
463{
464 .type = AMD_IP_BLOCK_TYPE_COMMON,
465 .major = 2,
466 .minor = 0,
467 .rev = 0,
468 .funcs = &soc15_common_ip_funcs,
469};
470
471int soc15_set_ip_blocks(struct amdgpu_device *adev)
472{
Xiangliang Yu1b922422017-03-08 15:00:48 +0800473 nbio_v6_1_detect_hw_virt(adev);
474
Xiangliang Yuf1a34462017-03-08 15:06:47 +0800475 if (amdgpu_sriov_vf(adev))
476 adev->virt.ops = &xgpu_ai_virt_ops;
477
Ken Wang220ab9b2017-03-06 14:49:53 -0500478 switch (adev->asic_type) {
479 case CHIP_VEGA10:
480 amdgpu_ip_block_add(adev, &vega10_common_ip_block);
481 amdgpu_ip_block_add(adev, &gfxhub_v1_0_ip_block);
482 amdgpu_ip_block_add(adev, &mmhub_v1_0_ip_block);
483 amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block);
484 amdgpu_ip_block_add(adev, &vega10_ih_ip_block);
Xiangliang Yu86d37982017-02-28 16:59:28 +0800485 if (!amdgpu_sriov_vf(adev))
486 amdgpu_ip_block_add(adev, &psp_v3_1_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500487 amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
488 amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block);
489 amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block);
490 amdgpu_ip_block_add(adev, &uvd_v7_0_ip_block);
491 amdgpu_ip_block_add(adev, &vce_v4_0_ip_block);
492 break;
493 default:
494 return -EINVAL;
495 }
496
497 return 0;
498}
499
500static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
501{
502 return nbio_v6_1_get_rev_id(adev);
503}
504
505
506int gmc_v9_0_mc_wait_for_idle(struct amdgpu_device *adev)
507{
508 /* to be implemented in MC IP*/
509 return 0;
510}
511
512static const struct amdgpu_asic_funcs soc15_asic_funcs =
513{
514 .read_disabled_bios = &soc15_read_disabled_bios,
515 .read_bios_from_rom = &soc15_read_bios_from_rom,
516 .read_register = &soc15_read_register,
517 .reset = &soc15_asic_reset,
518 .set_vga_state = &soc15_vga_set_state,
519 .get_xclk = &soc15_get_xclk,
520 .set_uvd_clocks = &soc15_set_uvd_clocks,
521 .set_vce_clocks = &soc15_set_vce_clocks,
522 .get_config_memsize = &soc15_get_config_memsize,
523};
524
525static int soc15_common_early_init(void *handle)
526{
527 bool psp_enabled = false;
528 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
529
530 adev->smc_rreg = NULL;
531 adev->smc_wreg = NULL;
532 adev->pcie_rreg = &soc15_pcie_rreg;
533 adev->pcie_wreg = &soc15_pcie_wreg;
534 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
535 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
536 adev->didt_rreg = &soc15_didt_rreg;
537 adev->didt_wreg = &soc15_didt_wreg;
538
539 adev->asic_funcs = &soc15_asic_funcs;
540
541 if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP) &&
542 (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_PSP)))
543 psp_enabled = true;
544
545 /*
546 * nbio need be used for both sdma and gfx9, but only
547 * initializes once
548 */
549 switch(adev->asic_type) {
550 case CHIP_VEGA10:
551 nbio_v6_1_init(adev);
552 break;
553 default:
554 return -EINVAL;
555 }
556
557 adev->rev_id = soc15_get_rev_id(adev);
558 adev->external_rev_id = 0xFF;
559 switch (adev->asic_type) {
560 case CHIP_VEGA10:
561 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
562 AMD_CG_SUPPORT_GFX_MGLS |
563 AMD_CG_SUPPORT_GFX_RLC_LS |
564 AMD_CG_SUPPORT_GFX_CP_LS |
565 AMD_CG_SUPPORT_GFX_3D_CGCG |
566 AMD_CG_SUPPORT_GFX_3D_CGLS |
567 AMD_CG_SUPPORT_GFX_CGCG |
568 AMD_CG_SUPPORT_GFX_CGLS |
569 AMD_CG_SUPPORT_BIF_MGCG |
570 AMD_CG_SUPPORT_BIF_LS |
571 AMD_CG_SUPPORT_HDP_LS |
572 AMD_CG_SUPPORT_DRM_MGCG |
573 AMD_CG_SUPPORT_DRM_LS |
574 AMD_CG_SUPPORT_ROM_MGCG |
575 AMD_CG_SUPPORT_DF_MGCG |
576 AMD_CG_SUPPORT_SDMA_MGCG |
577 AMD_CG_SUPPORT_SDMA_LS |
578 AMD_CG_SUPPORT_MC_MGCG |
579 AMD_CG_SUPPORT_MC_LS;
580 adev->pg_flags = 0;
581 adev->external_rev_id = 0x1;
582 break;
583 default:
584 /* FIXME: not supported yet */
585 return -EINVAL;
586 }
587
588 adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type);
589
590 amdgpu_get_pcie_info(adev);
591
592 return 0;
593}
594
595static int soc15_common_sw_init(void *handle)
596{
597 return 0;
598}
599
600static int soc15_common_sw_fini(void *handle)
601{
602 return 0;
603}
604
605static int soc15_common_hw_init(void *handle)
606{
607 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
608
609 /* move the golden regs per IP block */
610 soc15_init_golden_registers(adev);
611 /* enable pcie gen2/3 link */
612 soc15_pcie_gen3_enable(adev);
613 /* enable aspm */
614 soc15_program_aspm(adev);
615 /* enable the doorbell aperture */
616 soc15_enable_doorbell_aperture(adev, true);
617
618 return 0;
619}
620
621static int soc15_common_hw_fini(void *handle)
622{
623 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
624
625 /* disable the doorbell aperture */
626 soc15_enable_doorbell_aperture(adev, false);
627
628 return 0;
629}
630
631static int soc15_common_suspend(void *handle)
632{
633 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
634
635 return soc15_common_hw_fini(adev);
636}
637
638static int soc15_common_resume(void *handle)
639{
640 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
641
642 return soc15_common_hw_init(adev);
643}
644
645static bool soc15_common_is_idle(void *handle)
646{
647 return true;
648}
649
650static int soc15_common_wait_for_idle(void *handle)
651{
652 return 0;
653}
654
655static int soc15_common_soft_reset(void *handle)
656{
657 return 0;
658}
659
660static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
661{
662 uint32_t def, data;
663
664 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
665
666 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
667 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
668 else
669 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
670
671 if (def != data)
672 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
673}
674
675static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
676{
677 uint32_t def, data;
678
679 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
680
681 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
682 data &= ~(0x01000000 |
683 0x02000000 |
684 0x04000000 |
685 0x08000000 |
686 0x10000000 |
687 0x20000000 |
688 0x40000000 |
689 0x80000000);
690 else
691 data |= (0x01000000 |
692 0x02000000 |
693 0x04000000 |
694 0x08000000 |
695 0x10000000 |
696 0x20000000 |
697 0x40000000 |
698 0x80000000);
699
700 if (def != data)
701 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
702}
703
704static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
705{
706 uint32_t def, data;
707
708 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
709
710 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
711 data |= 1;
712 else
713 data &= ~1;
714
715 if (def != data)
716 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
717}
718
719static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
720 bool enable)
721{
722 uint32_t def, data;
723
724 def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
725
726 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
727 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
728 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
729 else
730 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
731 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
732
733 if (def != data)
734 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
735}
736
737static void soc15_update_df_medium_grain_clock_gating(struct amdgpu_device *adev,
738 bool enable)
739{
740 uint32_t data;
741
742 /* Put DF on broadcast mode */
743 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl));
744 data &= ~FabricConfigAccessControl__CfgRegInstAccEn_MASK;
745 WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl), data);
746
747 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DF_MGCG)) {
748 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
749 data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
750 data |= DF_MGCG_ENABLE_15_CYCLE_DELAY;
751 WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
752 } else {
753 data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
754 data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
755 data |= DF_MGCG_DISABLE;
756 WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
757 }
758
759 WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl),
760 mmFabricConfigAccessControl_DEFAULT);
761}
762
763static int soc15_common_set_clockgating_state(void *handle,
764 enum amd_clockgating_state state)
765{
766 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
767
768 switch (adev->asic_type) {
769 case CHIP_VEGA10:
770 nbio_v6_1_update_medium_grain_clock_gating(adev,
771 state == AMD_CG_STATE_GATE ? true : false);
772 nbio_v6_1_update_medium_grain_light_sleep(adev,
773 state == AMD_CG_STATE_GATE ? true : false);
774 soc15_update_hdp_light_sleep(adev,
775 state == AMD_CG_STATE_GATE ? true : false);
776 soc15_update_drm_clock_gating(adev,
777 state == AMD_CG_STATE_GATE ? true : false);
778 soc15_update_drm_light_sleep(adev,
779 state == AMD_CG_STATE_GATE ? true : false);
780 soc15_update_rom_medium_grain_clock_gating(adev,
781 state == AMD_CG_STATE_GATE ? true : false);
782 soc15_update_df_medium_grain_clock_gating(adev,
783 state == AMD_CG_STATE_GATE ? true : false);
784 break;
785 default:
786 break;
787 }
788 return 0;
789}
790
791static int soc15_common_set_powergating_state(void *handle,
792 enum amd_powergating_state state)
793{
794 /* todo */
795 return 0;
796}
797
798const struct amd_ip_funcs soc15_common_ip_funcs = {
799 .name = "soc15_common",
800 .early_init = soc15_common_early_init,
801 .late_init = NULL,
802 .sw_init = soc15_common_sw_init,
803 .sw_fini = soc15_common_sw_fini,
804 .hw_init = soc15_common_hw_init,
805 .hw_fini = soc15_common_hw_fini,
806 .suspend = soc15_common_suspend,
807 .resume = soc15_common_resume,
808 .is_idle = soc15_common_is_idle,
809 .wait_for_idle = soc15_common_wait_for_idle,
810 .soft_reset = soc15_common_soft_reset,
811 .set_clockgating_state = soc15_common_set_clockgating_state,
812 .set_powergating_state = soc15_common_set_powergating_state,
813};