blob: b368496ed6858bbbfc0417dc7d1051ac4403ddb8 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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 <linux/pci.h>
27
28#include "amdgpu.h"
29#include "amdgpu_atombios.h"
30#include "amdgpu_ih.h"
31#include "amdgpu_uvd.h"
32#include "amdgpu_vce.h"
33#include "amdgpu_ucode.h"
34#include "amdgpu_psp.h"
35#include "atom.h"
36#include "amd_pcie.h"
37
38#include "uvd/uvd_7_0_offset.h"
39#include "gc/gc_9_0_offset.h"
40#include "gc/gc_9_0_sh_mask.h"
41#include "sdma0/sdma0_4_0_offset.h"
42#include "sdma1/sdma1_4_0_offset.h"
43#include "hdp/hdp_4_0_offset.h"
44#include "hdp/hdp_4_0_sh_mask.h"
45#include "smuio/smuio_9_0_offset.h"
46#include "smuio/smuio_9_0_sh_mask.h"
47#include "nbio/nbio_7_0_default.h"
48#include "nbio/nbio_7_0_offset.h"
49#include "nbio/nbio_7_0_sh_mask.h"
50#include "nbio/nbio_7_0_smn.h"
51#include "mp/mp_9_0_offset.h"
52
53#include "soc15.h"
54#include "soc15_common.h"
55#include "gfx_v9_0.h"
56#include "gmc_v9_0.h"
57#include "gfxhub_v1_0.h"
58#include "mmhub_v1_0.h"
59#include "df_v1_7.h"
60#include "df_v3_6.h"
61#include "vega10_ih.h"
62#include "sdma_v4_0.h"
63#include "uvd_v7_0.h"
64#include "vce_v4_0.h"
65#include "vcn_v1_0.h"
66#include "vcn_v2_0.h"
67#include "vcn_v2_5.h"
68#include "dce_virtual.h"
69#include "mxgpu_ai.h"
70#include "amdgpu_smu.h"
71#include "amdgpu_ras.h"
72#include "amdgpu_xgmi.h"
73#include <uapi/linux/kfd_ioctl.h>
74
75#define mmMP0_MISC_CGTT_CTRL0 0x01b9
76#define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
77#define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
78#define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
79
80/* for Vega20 register name change */
81#define mmHDP_MEM_POWER_CTRL 0x00d4
82#define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK 0x00000001L
83#define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK 0x00000002L
84#define HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK 0x00010000L
85#define HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK 0x00020000L
86#define mmHDP_MEM_POWER_CTRL_BASE_IDX 0
87
88/* for Vega20/arcturus regiter offset change */
89#define mmROM_INDEX_VG20 0x00e4
90#define mmROM_INDEX_VG20_BASE_IDX 0
91#define mmROM_DATA_VG20 0x00e5
92#define mmROM_DATA_VG20_BASE_IDX 0
93
94/*
95 * Indirect registers accessor
96 */
97static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
98{
99 unsigned long flags, address, data;
100 u32 r;
101 address = adev->nbio_funcs->get_pcie_index_offset(adev);
102 data = adev->nbio_funcs->get_pcie_data_offset(adev);
103
104 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
105 WREG32(address, reg);
106 (void)RREG32(address);
107 r = RREG32(data);
108 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
109 return r;
110}
111
112static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
113{
114 unsigned long flags, address, data;
115
116 address = adev->nbio_funcs->get_pcie_index_offset(adev);
117 data = adev->nbio_funcs->get_pcie_data_offset(adev);
118
119 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
120 WREG32(address, reg);
121 (void)RREG32(address);
122 WREG32(data, v);
123 (void)RREG32(data);
124 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
125}
126
127static u64 soc15_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
128{
129 unsigned long flags, address, data;
130 u64 r;
131 address = adev->nbio_funcs->get_pcie_index_offset(adev);
132 data = adev->nbio_funcs->get_pcie_data_offset(adev);
133
134 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
135 /* read low 32 bit */
136 WREG32(address, reg);
137 (void)RREG32(address);
138 r = RREG32(data);
139
140 /* read high 32 bit*/
141 WREG32(address, reg + 4);
142 (void)RREG32(address);
143 r |= ((u64)RREG32(data) << 32);
144 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
145 return r;
146}
147
148static void soc15_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
149{
150 unsigned long flags, address, data;
151
152 address = adev->nbio_funcs->get_pcie_index_offset(adev);
153 data = adev->nbio_funcs->get_pcie_data_offset(adev);
154
155 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
156 /* write low 32 bit */
157 WREG32(address, reg);
158 (void)RREG32(address);
159 WREG32(data, (u32)(v & 0xffffffffULL));
160 (void)RREG32(data);
161
162 /* write high 32 bit */
163 WREG32(address, reg + 4);
164 (void)RREG32(address);
165 WREG32(data, (u32)(v >> 32));
166 (void)RREG32(data);
167 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
168}
169
170static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
171{
172 unsigned long flags, address, data;
173 u32 r;
174
175 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
176 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
177
178 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
179 WREG32(address, ((reg) & 0x1ff));
180 r = RREG32(data);
181 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
182 return r;
183}
184
185static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
186{
187 unsigned long flags, address, data;
188
189 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
190 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
191
192 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
193 WREG32(address, ((reg) & 0x1ff));
194 WREG32(data, (v));
195 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
196}
197
198static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
199{
200 unsigned long flags, address, data;
201 u32 r;
202
203 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
204 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
205
206 spin_lock_irqsave(&adev->didt_idx_lock, flags);
207 WREG32(address, (reg));
208 r = RREG32(data);
209 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
210 return r;
211}
212
213static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
214{
215 unsigned long flags, address, data;
216
217 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
218 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
219
220 spin_lock_irqsave(&adev->didt_idx_lock, flags);
221 WREG32(address, (reg));
222 WREG32(data, (v));
223 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
224}
225
226static u32 soc15_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
227{
228 unsigned long flags;
229 u32 r;
230
231 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
232 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
233 r = RREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA);
234 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
235 return r;
236}
237
238static void soc15_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
239{
240 unsigned long flags;
241
242 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
243 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
244 WREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA, (v));
245 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
246}
247
248static u32 soc15_se_cac_rreg(struct amdgpu_device *adev, u32 reg)
249{
250 unsigned long flags;
251 u32 r;
252
253 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
254 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
255 r = RREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA);
256 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
257 return r;
258}
259
260static void soc15_se_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
261{
262 unsigned long flags;
263
264 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
265 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
266 WREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA, (v));
267 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
268}
269
270static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
271{
272 return adev->nbio_funcs->get_memsize(adev);
273}
274
275static u32 soc15_get_xclk(struct amdgpu_device *adev)
276{
277 u32 reference_clock = adev->clock.spll.reference_freq;
278
279 if (adev->asic_type == CHIP_RENOIR)
280 return 10000;
281 if (adev->asic_type == CHIP_RAVEN)
282 return reference_clock / 4;
283
284 return reference_clock;
285}
286
287
288void soc15_grbm_select(struct amdgpu_device *adev,
289 u32 me, u32 pipe, u32 queue, u32 vmid)
290{
291 u32 grbm_gfx_cntl = 0;
292 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
293 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
294 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
295 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
296
297 WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
298}
299
300static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
301{
302 /* todo */
303}
304
305static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
306{
307 /* todo */
308 return false;
309}
310
311static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
312 u8 *bios, u32 length_bytes)
313{
314 u32 *dw_ptr;
315 u32 i, length_dw;
316 uint32_t rom_index_offset;
317 uint32_t rom_data_offset;
318
319 if (bios == NULL)
320 return false;
321 if (length_bytes == 0)
322 return false;
323 /* APU vbios image is part of sbios image */
324 if (adev->flags & AMD_IS_APU)
325 return false;
326
327 dw_ptr = (u32 *)bios;
328 length_dw = ALIGN(length_bytes, 4) / 4;
329
330 switch (adev->asic_type) {
331 case CHIP_VEGA20:
332 case CHIP_ARCTURUS:
333 rom_index_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX_VG20);
334 rom_data_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA_VG20);
335 break;
336 default:
337 rom_index_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX);
338 rom_data_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA);
339 break;
340 }
341
342 /* set rom index to 0 */
343 WREG32(rom_index_offset, 0);
344 /* read out the rom data */
345 for (i = 0; i < length_dw; i++)
346 dw_ptr[i] = RREG32(rom_data_offset);
347
348 return true;
349}
350
351static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {
352 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
353 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
354 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
355 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
356 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
357 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
358 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
359 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
360 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
361 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
362 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
363 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
364 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
365 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
366 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
367 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
368 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
369 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
370 { SOC15_REG_ENTRY(GC, 0, mmDB_DEBUG2)},
371};
372
373static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
374 u32 sh_num, u32 reg_offset)
375{
376 uint32_t val;
377
378 mutex_lock(&adev->grbm_idx_mutex);
379 if (se_num != 0xffffffff || sh_num != 0xffffffff)
380 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
381
382 val = RREG32(reg_offset);
383
384 if (se_num != 0xffffffff || sh_num != 0xffffffff)
385 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
386 mutex_unlock(&adev->grbm_idx_mutex);
387 return val;
388}
389
390static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
391 bool indexed, u32 se_num,
392 u32 sh_num, u32 reg_offset)
393{
394 if (indexed) {
395 return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
396 } else {
397 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
398 return adev->gfx.config.gb_addr_config;
399 else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
400 return adev->gfx.config.db_debug2;
401 return RREG32(reg_offset);
402 }
403}
404
405static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
406 u32 sh_num, u32 reg_offset, u32 *value)
407{
408 uint32_t i;
409 struct soc15_allowed_register_entry *en;
410
411 *value = 0;
412 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
413 en = &soc15_allowed_read_registers[i];
414 if (reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
415 + en->reg_offset))
416 continue;
417
418 *value = soc15_get_register_value(adev,
419 soc15_allowed_read_registers[i].grbm_indexed,
420 se_num, sh_num, reg_offset);
421 return 0;
422 }
423 return -EINVAL;
424}
425
426
427/**
428 * soc15_program_register_sequence - program an array of registers.
429 *
430 * @adev: amdgpu_device pointer
431 * @regs: pointer to the register array
432 * @array_size: size of the register array
433 *
434 * Programs an array or registers with and and or masks.
435 * This is a helper for setting golden registers.
436 */
437
438void soc15_program_register_sequence(struct amdgpu_device *adev,
439 const struct soc15_reg_golden *regs,
440 const u32 array_size)
441{
442 const struct soc15_reg_golden *entry;
443 u32 tmp, reg;
444 int i;
445
446 for (i = 0; i < array_size; ++i) {
447 entry = &regs[i];
448 reg = adev->reg_offset[entry->hwip][entry->instance][entry->segment] + entry->reg;
449
450 if (entry->and_mask == 0xffffffff) {
451 tmp = entry->or_mask;
452 } else {
453 tmp = RREG32(reg);
454 tmp &= ~(entry->and_mask);
455 tmp |= (entry->or_mask & entry->and_mask);
456 }
457
458 if (reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_BINNER_EVENT_CNTL_3) ||
459 reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE) ||
460 reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE_1) ||
461 reg == SOC15_REG_OFFSET(GC, 0, mmSH_MEM_CONFIG))
462 WREG32_RLC(reg, tmp);
463 else
464 WREG32(reg, tmp);
465
466 }
467
468}
469
470static int soc15_asic_mode1_reset(struct amdgpu_device *adev)
471{
472 u32 i;
473 int ret = 0;
474
475 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
476
477 dev_info(adev->dev, "GPU mode1 reset\n");
478
479 /* disable BM */
480 pci_clear_master(adev->pdev);
481
482 pci_save_state(adev->pdev);
483
484 ret = psp_gpu_reset(adev);
485 if (ret)
486 dev_err(adev->dev, "GPU mode1 reset failed\n");
487
488 pci_restore_state(adev->pdev);
489
490 /* wait for asic to come out of reset */
491 for (i = 0; i < adev->usec_timeout; i++) {
492 u32 memsize = adev->nbio_funcs->get_memsize(adev);
493
494 if (memsize != 0xffffffff)
495 break;
496 udelay(1);
497 }
498
499 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
500
501 return ret;
502}
503
504static int soc15_asic_get_baco_capability(struct amdgpu_device *adev, bool *cap)
505{
506 void *pp_handle = adev->powerplay.pp_handle;
507 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
508
509 if (!pp_funcs || !pp_funcs->get_asic_baco_capability) {
510 *cap = false;
511 return -ENOENT;
512 }
513
514 return pp_funcs->get_asic_baco_capability(pp_handle, cap);
515}
516
517static int soc15_asic_baco_reset(struct amdgpu_device *adev)
518{
519 void *pp_handle = adev->powerplay.pp_handle;
520 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
521
522 if (!pp_funcs ||!pp_funcs->get_asic_baco_state ||!pp_funcs->set_asic_baco_state)
523 return -ENOENT;
524
525 /* enter BACO state */
526 if (pp_funcs->set_asic_baco_state(pp_handle, 1))
527 return -EIO;
528
529 /* exit BACO state */
530 if (pp_funcs->set_asic_baco_state(pp_handle, 0))
531 return -EIO;
532
533 dev_info(adev->dev, "GPU BACO reset\n");
534
535 adev->in_baco_reset = 1;
536
537 return 0;
538}
539
540static int soc15_mode2_reset(struct amdgpu_device *adev)
541{
542 if (!adev->powerplay.pp_funcs ||
543 !adev->powerplay.pp_funcs->asic_reset_mode_2)
544 return -ENOENT;
545
546 return adev->powerplay.pp_funcs->asic_reset_mode_2(adev->powerplay.pp_handle);
547}
548
549static enum amd_reset_method
550soc15_asic_reset_method(struct amdgpu_device *adev)
551{
552 bool baco_reset;
553
554 switch (adev->asic_type) {
555 case CHIP_RAVEN:
556 return AMD_RESET_METHOD_MODE2;
557 case CHIP_VEGA10:
558 case CHIP_VEGA12:
559 soc15_asic_get_baco_capability(adev, &baco_reset);
560 break;
561 case CHIP_VEGA20:
562 if (adev->psp.sos_fw_version >= 0x80067)
563 soc15_asic_get_baco_capability(adev, &baco_reset);
564 else
565 baco_reset = false;
566 if (baco_reset) {
567 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0);
568 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
569
570 if (hive || (ras && ras->supported))
571 baco_reset = false;
572 }
573 break;
574 default:
575 baco_reset = false;
576 break;
577 }
578
579 if (baco_reset)
580 return AMD_RESET_METHOD_BACO;
581 else
582 return AMD_RESET_METHOD_MODE1;
583}
584
585static int soc15_asic_reset(struct amdgpu_device *adev)
586{
587 switch (soc15_asic_reset_method(adev)) {
588 case AMD_RESET_METHOD_BACO:
589 if (!adev->in_suspend)
590 amdgpu_inc_vram_lost(adev);
591 return soc15_asic_baco_reset(adev);
592 case AMD_RESET_METHOD_MODE2:
593 return soc15_mode2_reset(adev);
594 default:
595 if (!adev->in_suspend)
596 amdgpu_inc_vram_lost(adev);
597 return soc15_asic_mode1_reset(adev);
598 }
599}
600
601/*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
602 u32 cntl_reg, u32 status_reg)
603{
604 return 0;
605}*/
606
607static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
608{
609 /*int r;
610
611 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
612 if (r)
613 return r;
614
615 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
616 */
617 return 0;
618}
619
620static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
621{
622 /* todo */
623
624 return 0;
625}
626
627static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
628{
629 if (pci_is_root_bus(adev->pdev->bus))
630 return;
631
632 if (amdgpu_pcie_gen2 == 0)
633 return;
634
635 if (adev->flags & AMD_IS_APU)
636 return;
637
638 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
639 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
640 return;
641
642 /* todo */
643}
644
645static void soc15_program_aspm(struct amdgpu_device *adev)
646{
647
648 if (amdgpu_aspm == 0)
649 return;
650
651 /* todo */
652}
653
654static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
655 bool enable)
656{
657 adev->nbio_funcs->enable_doorbell_aperture(adev, enable);
658 adev->nbio_funcs->enable_doorbell_selfring_aperture(adev, enable);
659}
660
661static const struct amdgpu_ip_block_version vega10_common_ip_block =
662{
663 .type = AMD_IP_BLOCK_TYPE_COMMON,
664 .major = 2,
665 .minor = 0,
666 .rev = 0,
667 .funcs = &soc15_common_ip_funcs,
668};
669
670static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
671{
672 return adev->nbio_funcs->get_rev_id(adev);
673}
674
675int soc15_set_ip_blocks(struct amdgpu_device *adev)
676{
677 /* Set IP register base before any HW register access */
678 switch (adev->asic_type) {
679 case CHIP_VEGA10:
680 case CHIP_VEGA12:
681 case CHIP_RAVEN:
682 case CHIP_RENOIR:
683 vega10_reg_base_init(adev);
684 break;
685 case CHIP_VEGA20:
686 vega20_reg_base_init(adev);
687 break;
688 case CHIP_ARCTURUS:
689 arct_reg_base_init(adev);
690 break;
691 default:
692 return -EINVAL;
693 }
694
695 if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
696 adev->gmc.xgmi.supported = true;
697
698 if (adev->flags & AMD_IS_APU)
699 adev->nbio_funcs = &nbio_v7_0_funcs;
700 else if (adev->asic_type == CHIP_VEGA20 ||
701 adev->asic_type == CHIP_ARCTURUS)
702 adev->nbio_funcs = &nbio_v7_4_funcs;
703 else
704 adev->nbio_funcs = &nbio_v6_1_funcs;
705
706 if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
707 adev->df_funcs = &df_v3_6_funcs;
708 else
709 adev->df_funcs = &df_v1_7_funcs;
710
711 adev->rev_id = soc15_get_rev_id(adev);
712 adev->nbio_funcs->detect_hw_virt(adev);
713
714 if (amdgpu_sriov_vf(adev))
715 adev->virt.ops = &xgpu_ai_virt_ops;
716
717 switch (adev->asic_type) {
718 case CHIP_VEGA10:
719 case CHIP_VEGA12:
720 case CHIP_VEGA20:
721 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
722 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
723
724 /* For Vega10 SR-IOV, PSP need to be initialized before IH */
725 if (amdgpu_sriov_vf(adev)) {
726 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
727 if (adev->asic_type == CHIP_VEGA20)
728 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
729 else
730 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
731 }
732 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
733 } else {
734 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
735 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
736 if (adev->asic_type == CHIP_VEGA20)
737 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
738 else
739 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
740 }
741 }
742 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
743 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
744 if (!amdgpu_sriov_vf(adev)) {
745 if (is_support_sw_smu(adev))
746 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
747 else
748 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
749 }
750 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
751 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
752#if defined(CONFIG_DRM_AMD_DC)
753 else if (amdgpu_device_has_dc_support(adev))
754 amdgpu_device_ip_block_add(adev, &dm_ip_block);
755#endif
756 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) {
757 amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
758 amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
759 }
760 break;
761 case CHIP_RAVEN:
762 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
763 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
764 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
765 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
766 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
767 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
768 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
769 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
770 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
771 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
772#if defined(CONFIG_DRM_AMD_DC)
773 else if (amdgpu_device_has_dc_support(adev))
774 amdgpu_device_ip_block_add(adev, &dm_ip_block);
775#endif
776 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
777 break;
778 case CHIP_ARCTURUS:
779 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
780 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
781 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
782 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
783 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
784 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
785 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
786 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
787 amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
788 break;
789 case CHIP_RENOIR:
790 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
791 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
792 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
793 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
794 amdgpu_device_ip_block_add(adev, &psp_v12_0_ip_block);
795 if (is_support_sw_smu(adev))
796 amdgpu_device_ip_block_add(adev, &smu_v12_0_ip_block);
797 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
798 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
799 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
800 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
801#if defined(CONFIG_DRM_AMD_DC)
802 else if (amdgpu_device_has_dc_support(adev))
803 amdgpu_device_ip_block_add(adev, &dm_ip_block);
804#endif
805 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
806 break;
807 default:
808 return -EINVAL;
809 }
810
811 return 0;
812}
813
814static void soc15_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
815{
816 adev->nbio_funcs->hdp_flush(adev, ring);
817}
818
819static void soc15_invalidate_hdp(struct amdgpu_device *adev,
820 struct amdgpu_ring *ring)
821{
822 if (!ring || !ring->funcs->emit_wreg)
823 WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
824 else
825 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
826 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
827}
828
829static bool soc15_need_full_reset(struct amdgpu_device *adev)
830{
831 /* change this when we implement soft reset */
832 return true;
833}
834static void soc15_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
835 uint64_t *count1)
836{
837 uint32_t perfctr = 0;
838 uint64_t cnt0_of, cnt1_of;
839 int tmp;
840
841 /* This reports 0 on APUs, so return to avoid writing/reading registers
842 * that may or may not be different from their GPU counterparts
843 */
844 if (adev->flags & AMD_IS_APU)
845 return;
846
847 /* Set the 2 events that we wish to watch, defined above */
848 /* Reg 40 is # received msgs */
849 /* Reg 104 is # of posted requests sent */
850 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40);
851 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104);
852
853 /* Write to enable desired perf counters */
854 WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK, perfctr);
855 /* Zero out and enable the perf counters
856 * Write 0x5:
857 * Bit 0 = Start all counters(1)
858 * Bit 2 = Global counter reset enable(1)
859 */
860 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
861
862 msleep(1000);
863
864 /* Load the shadow and disable the perf counters
865 * Write 0x2:
866 * Bit 0 = Stop counters(0)
867 * Bit 1 = Load the shadow counters(1)
868 */
869 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
870
871 /* Read register values to get any >32bit overflow */
872 tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK);
873 cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER);
874 cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER);
875
876 /* Get the values and add the overflow */
877 *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32);
878 *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
879}
880
881static void vega20_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
882 uint64_t *count1)
883{
884 uint32_t perfctr = 0;
885 uint64_t cnt0_of, cnt1_of;
886 int tmp;
887
888 /* This reports 0 on APUs, so return to avoid writing/reading registers
889 * that may or may not be different from their GPU counterparts
890 */
891 if (adev->flags & AMD_IS_APU)
892 return;
893
894 /* Set the 2 events that we wish to watch, defined above */
895 /* Reg 40 is # received msgs */
896 /* Reg 108 is # of posted requests sent on VG20 */
897 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
898 EVENT0_SEL, 40);
899 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
900 EVENT1_SEL, 108);
901
902 /* Write to enable desired perf counters */
903 WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctr);
904 /* Zero out and enable the perf counters
905 * Write 0x5:
906 * Bit 0 = Start all counters(1)
907 * Bit 2 = Global counter reset enable(1)
908 */
909 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
910
911 msleep(1000);
912
913 /* Load the shadow and disable the perf counters
914 * Write 0x2:
915 * Bit 0 = Stop counters(0)
916 * Bit 1 = Load the shadow counters(1)
917 */
918 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
919
920 /* Read register values to get any >32bit overflow */
921 tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3);
922 cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER0_UPPER);
923 cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER1_UPPER);
924
925 /* Get the values and add the overflow */
926 *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) | (cnt0_of << 32);
927 *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK3) | (cnt1_of << 32);
928}
929
930static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
931{
932 u32 sol_reg;
933
934 /* Just return false for soc15 GPUs. Reset does not seem to
935 * be necessary.
936 */
937 if (!amdgpu_passthrough(adev))
938 return false;
939
940 if (adev->flags & AMD_IS_APU)
941 return false;
942
943 /* Check sOS sign of life register to confirm sys driver and sOS
944 * are already been loaded.
945 */
946 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
947 if (sol_reg)
948 return true;
949
950 return false;
951}
952
953static uint64_t soc15_get_pcie_replay_count(struct amdgpu_device *adev)
954{
955 uint64_t nak_r, nak_g;
956
957 /* Get the number of NAKs received and generated */
958 nak_r = RREG32_PCIE(smnPCIE_RX_NUM_NAK);
959 nak_g = RREG32_PCIE(smnPCIE_RX_NUM_NAK_GENERATED);
960
961 /* Add the total number of NAKs, i.e the number of replays */
962 return (nak_r + nak_g);
963}
964
965static const struct amdgpu_asic_funcs soc15_asic_funcs =
966{
967 .read_disabled_bios = &soc15_read_disabled_bios,
968 .read_bios_from_rom = &soc15_read_bios_from_rom,
969 .read_register = &soc15_read_register,
970 .reset = &soc15_asic_reset,
971 .reset_method = &soc15_asic_reset_method,
972 .set_vga_state = &soc15_vga_set_state,
973 .get_xclk = &soc15_get_xclk,
974 .set_uvd_clocks = &soc15_set_uvd_clocks,
975 .set_vce_clocks = &soc15_set_vce_clocks,
976 .get_config_memsize = &soc15_get_config_memsize,
977 .flush_hdp = &soc15_flush_hdp,
978 .invalidate_hdp = &soc15_invalidate_hdp,
979 .need_full_reset = &soc15_need_full_reset,
980 .init_doorbell_index = &vega10_doorbell_index_init,
981 .get_pcie_usage = &soc15_get_pcie_usage,
982 .need_reset_on_init = &soc15_need_reset_on_init,
983 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
984};
985
986static const struct amdgpu_asic_funcs vega20_asic_funcs =
987{
988 .read_disabled_bios = &soc15_read_disabled_bios,
989 .read_bios_from_rom = &soc15_read_bios_from_rom,
990 .read_register = &soc15_read_register,
991 .reset = &soc15_asic_reset,
992 .set_vga_state = &soc15_vga_set_state,
993 .get_xclk = &soc15_get_xclk,
994 .set_uvd_clocks = &soc15_set_uvd_clocks,
995 .set_vce_clocks = &soc15_set_vce_clocks,
996 .get_config_memsize = &soc15_get_config_memsize,
997 .flush_hdp = &soc15_flush_hdp,
998 .invalidate_hdp = &soc15_invalidate_hdp,
999 .need_full_reset = &soc15_need_full_reset,
1000 .init_doorbell_index = &vega20_doorbell_index_init,
1001 .get_pcie_usage = &vega20_get_pcie_usage,
1002 .need_reset_on_init = &soc15_need_reset_on_init,
1003 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
1004 .reset_method = &soc15_asic_reset_method
1005};
1006
1007static int soc15_common_early_init(void *handle)
1008{
1009#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
1010 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1011
1012 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
1013 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
1014 adev->smc_rreg = NULL;
1015 adev->smc_wreg = NULL;
1016 adev->pcie_rreg = &soc15_pcie_rreg;
1017 adev->pcie_wreg = &soc15_pcie_wreg;
1018 adev->pcie_rreg64 = &soc15_pcie_rreg64;
1019 adev->pcie_wreg64 = &soc15_pcie_wreg64;
1020 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
1021 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
1022 adev->didt_rreg = &soc15_didt_rreg;
1023 adev->didt_wreg = &soc15_didt_wreg;
1024 adev->gc_cac_rreg = &soc15_gc_cac_rreg;
1025 adev->gc_cac_wreg = &soc15_gc_cac_wreg;
1026 adev->se_cac_rreg = &soc15_se_cac_rreg;
1027 adev->se_cac_wreg = &soc15_se_cac_wreg;
1028
1029
1030 adev->external_rev_id = 0xFF;
1031 switch (adev->asic_type) {
1032 case CHIP_VEGA10:
1033 adev->asic_funcs = &soc15_asic_funcs;
1034 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1035 AMD_CG_SUPPORT_GFX_MGLS |
1036 AMD_CG_SUPPORT_GFX_RLC_LS |
1037 AMD_CG_SUPPORT_GFX_CP_LS |
1038 AMD_CG_SUPPORT_GFX_3D_CGCG |
1039 AMD_CG_SUPPORT_GFX_3D_CGLS |
1040 AMD_CG_SUPPORT_GFX_CGCG |
1041 AMD_CG_SUPPORT_GFX_CGLS |
1042 AMD_CG_SUPPORT_BIF_MGCG |
1043 AMD_CG_SUPPORT_BIF_LS |
1044 AMD_CG_SUPPORT_HDP_LS |
1045 AMD_CG_SUPPORT_DRM_MGCG |
1046 AMD_CG_SUPPORT_DRM_LS |
1047 AMD_CG_SUPPORT_ROM_MGCG |
1048 AMD_CG_SUPPORT_DF_MGCG |
1049 AMD_CG_SUPPORT_SDMA_MGCG |
1050 AMD_CG_SUPPORT_SDMA_LS |
1051 AMD_CG_SUPPORT_MC_MGCG |
1052 AMD_CG_SUPPORT_MC_LS;
1053 adev->pg_flags = 0;
1054 adev->external_rev_id = 0x1;
1055 break;
1056 case CHIP_VEGA12:
1057 adev->asic_funcs = &soc15_asic_funcs;
1058 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1059 AMD_CG_SUPPORT_GFX_MGLS |
1060 AMD_CG_SUPPORT_GFX_CGCG |
1061 AMD_CG_SUPPORT_GFX_CGLS |
1062 AMD_CG_SUPPORT_GFX_3D_CGCG |
1063 AMD_CG_SUPPORT_GFX_3D_CGLS |
1064 AMD_CG_SUPPORT_GFX_CP_LS |
1065 AMD_CG_SUPPORT_MC_LS |
1066 AMD_CG_SUPPORT_MC_MGCG |
1067 AMD_CG_SUPPORT_SDMA_MGCG |
1068 AMD_CG_SUPPORT_SDMA_LS |
1069 AMD_CG_SUPPORT_BIF_MGCG |
1070 AMD_CG_SUPPORT_BIF_LS |
1071 AMD_CG_SUPPORT_HDP_MGCG |
1072 AMD_CG_SUPPORT_HDP_LS |
1073 AMD_CG_SUPPORT_ROM_MGCG |
1074 AMD_CG_SUPPORT_VCE_MGCG |
1075 AMD_CG_SUPPORT_UVD_MGCG;
1076 adev->pg_flags = 0;
1077 adev->external_rev_id = adev->rev_id + 0x14;
1078 break;
1079 case CHIP_VEGA20:
1080 adev->asic_funcs = &vega20_asic_funcs;
1081 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1082 AMD_CG_SUPPORT_GFX_MGLS |
1083 AMD_CG_SUPPORT_GFX_CGCG |
1084 AMD_CG_SUPPORT_GFX_CGLS |
1085 AMD_CG_SUPPORT_GFX_3D_CGCG |
1086 AMD_CG_SUPPORT_GFX_3D_CGLS |
1087 AMD_CG_SUPPORT_GFX_CP_LS |
1088 AMD_CG_SUPPORT_MC_LS |
1089 AMD_CG_SUPPORT_MC_MGCG |
1090 AMD_CG_SUPPORT_SDMA_MGCG |
1091 AMD_CG_SUPPORT_SDMA_LS |
1092 AMD_CG_SUPPORT_BIF_MGCG |
1093 AMD_CG_SUPPORT_BIF_LS |
1094 AMD_CG_SUPPORT_HDP_MGCG |
1095 AMD_CG_SUPPORT_HDP_LS |
1096 AMD_CG_SUPPORT_ROM_MGCG |
1097 AMD_CG_SUPPORT_VCE_MGCG |
1098 AMD_CG_SUPPORT_UVD_MGCG;
1099 adev->pg_flags = 0;
1100 adev->external_rev_id = adev->rev_id + 0x28;
1101 break;
1102 case CHIP_RAVEN:
1103 adev->asic_funcs = &soc15_asic_funcs;
1104 if (adev->rev_id >= 0x8)
1105 adev->external_rev_id = adev->rev_id + 0x79;
1106 else if (adev->pdev->device == 0x15d8)
1107 adev->external_rev_id = adev->rev_id + 0x41;
1108 else if (adev->rev_id == 1)
1109 adev->external_rev_id = adev->rev_id + 0x20;
1110 else
1111 adev->external_rev_id = adev->rev_id + 0x01;
1112
1113 if (adev->rev_id >= 0x8) {
1114 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1115 AMD_CG_SUPPORT_GFX_MGLS |
1116 AMD_CG_SUPPORT_GFX_CP_LS |
1117 AMD_CG_SUPPORT_GFX_3D_CGCG |
1118 AMD_CG_SUPPORT_GFX_3D_CGLS |
1119 AMD_CG_SUPPORT_GFX_CGCG |
1120 AMD_CG_SUPPORT_GFX_CGLS |
1121 AMD_CG_SUPPORT_BIF_LS |
1122 AMD_CG_SUPPORT_HDP_LS |
1123 AMD_CG_SUPPORT_ROM_MGCG |
1124 AMD_CG_SUPPORT_MC_MGCG |
1125 AMD_CG_SUPPORT_MC_LS |
1126 AMD_CG_SUPPORT_SDMA_MGCG |
1127 AMD_CG_SUPPORT_SDMA_LS |
1128 AMD_CG_SUPPORT_VCN_MGCG;
1129
1130 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
1131 } else if (adev->pdev->device == 0x15d8) {
1132 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1133 AMD_CG_SUPPORT_GFX_MGLS |
1134 AMD_CG_SUPPORT_GFX_CP_LS |
1135 AMD_CG_SUPPORT_GFX_3D_CGLS |
1136 AMD_CG_SUPPORT_GFX_CGCG |
1137 AMD_CG_SUPPORT_GFX_CGLS |
1138 AMD_CG_SUPPORT_BIF_LS |
1139 AMD_CG_SUPPORT_HDP_LS |
1140 AMD_CG_SUPPORT_ROM_MGCG |
1141 AMD_CG_SUPPORT_MC_MGCG |
1142 AMD_CG_SUPPORT_MC_LS |
1143 AMD_CG_SUPPORT_SDMA_MGCG |
1144 AMD_CG_SUPPORT_SDMA_LS;
1145
1146 /*
1147 * MMHUB PG needs to be disabled for Picasso for
1148 * stability reasons.
1149 */
1150 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
1151 AMD_PG_SUPPORT_VCN;
1152 } else {
1153 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1154 AMD_CG_SUPPORT_GFX_MGLS |
1155 AMD_CG_SUPPORT_GFX_RLC_LS |
1156 AMD_CG_SUPPORT_GFX_CP_LS |
1157 AMD_CG_SUPPORT_GFX_3D_CGLS |
1158 AMD_CG_SUPPORT_GFX_CGCG |
1159 AMD_CG_SUPPORT_GFX_CGLS |
1160 AMD_CG_SUPPORT_BIF_MGCG |
1161 AMD_CG_SUPPORT_BIF_LS |
1162 AMD_CG_SUPPORT_HDP_MGCG |
1163 AMD_CG_SUPPORT_HDP_LS |
1164 AMD_CG_SUPPORT_DRM_MGCG |
1165 AMD_CG_SUPPORT_DRM_LS |
1166 AMD_CG_SUPPORT_ROM_MGCG |
1167 AMD_CG_SUPPORT_MC_MGCG |
1168 AMD_CG_SUPPORT_MC_LS |
1169 AMD_CG_SUPPORT_SDMA_MGCG |
1170 AMD_CG_SUPPORT_SDMA_LS |
1171 AMD_CG_SUPPORT_VCN_MGCG;
1172
1173 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
1174 }
1175 break;
1176 case CHIP_ARCTURUS:
1177 adev->asic_funcs = &vega20_asic_funcs;
1178 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1179 AMD_CG_SUPPORT_GFX_MGLS |
1180 AMD_CG_SUPPORT_GFX_CGCG |
1181 AMD_CG_SUPPORT_GFX_CGLS |
1182 AMD_CG_SUPPORT_GFX_CP_LS |
1183 AMD_CG_SUPPORT_HDP_MGCG |
1184 AMD_CG_SUPPORT_HDP_LS |
1185 AMD_CG_SUPPORT_SDMA_MGCG |
1186 AMD_CG_SUPPORT_SDMA_LS |
1187 AMD_CG_SUPPORT_MC_MGCG |
1188 AMD_CG_SUPPORT_MC_LS;
1189 adev->pg_flags = 0;
1190 adev->external_rev_id = adev->rev_id + 0x32;
1191 break;
1192 case CHIP_RENOIR:
1193 adev->asic_funcs = &soc15_asic_funcs;
1194 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1195 AMD_CG_SUPPORT_GFX_MGLS |
1196 AMD_CG_SUPPORT_GFX_3D_CGCG |
1197 AMD_CG_SUPPORT_GFX_3D_CGLS |
1198 AMD_CG_SUPPORT_GFX_CGCG |
1199 AMD_CG_SUPPORT_GFX_CGLS |
1200 AMD_CG_SUPPORT_GFX_CP_LS |
1201 AMD_CG_SUPPORT_MC_MGCG |
1202 AMD_CG_SUPPORT_MC_LS |
1203 AMD_CG_SUPPORT_SDMA_MGCG |
1204 AMD_CG_SUPPORT_SDMA_LS |
1205 AMD_CG_SUPPORT_BIF_LS |
1206 AMD_CG_SUPPORT_HDP_LS |
1207 AMD_CG_SUPPORT_ROM_MGCG |
1208 AMD_CG_SUPPORT_VCN_MGCG |
1209 AMD_CG_SUPPORT_IH_CG |
1210 AMD_CG_SUPPORT_ATHUB_LS |
1211 AMD_CG_SUPPORT_ATHUB_MGCG |
1212 AMD_CG_SUPPORT_DF_MGCG;
1213 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
1214 AMD_PG_SUPPORT_VCN |
1215 AMD_PG_SUPPORT_VCN_DPG;
1216 adev->external_rev_id = adev->rev_id + 0x91;
1217 break;
1218 default:
1219 /* FIXME: not supported yet */
1220 return -EINVAL;
1221 }
1222
1223 if (amdgpu_sriov_vf(adev)) {
1224 amdgpu_virt_init_setting(adev);
1225 xgpu_ai_mailbox_set_irq_funcs(adev);
1226 }
1227
1228 return 0;
1229}
1230
1231static int soc15_common_late_init(void *handle)
1232{
1233 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1234
1235 if (amdgpu_sriov_vf(adev))
1236 xgpu_ai_mailbox_get_irq(adev);
1237
1238 return 0;
1239}
1240
1241static int soc15_common_sw_init(void *handle)
1242{
1243 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1244
1245 if (amdgpu_sriov_vf(adev))
1246 xgpu_ai_mailbox_add_irq_id(adev);
1247
1248 adev->df_funcs->sw_init(adev);
1249
1250 return 0;
1251}
1252
1253static int soc15_common_sw_fini(void *handle)
1254{
1255 return 0;
1256}
1257
1258static void soc15_doorbell_range_init(struct amdgpu_device *adev)
1259{
1260 int i;
1261 struct amdgpu_ring *ring;
1262
1263 /* sdma/ih doorbell range are programed by hypervisor */
1264 if (!amdgpu_sriov_vf(adev)) {
1265 for (i = 0; i < adev->sdma.num_instances; i++) {
1266 ring = &adev->sdma.instance[i].ring;
1267 adev->nbio_funcs->sdma_doorbell_range(adev, i,
1268 ring->use_doorbell, ring->doorbell_index,
1269 adev->doorbell_index.sdma_doorbell_range);
1270 }
1271
1272 adev->nbio_funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
1273 adev->irq.ih.doorbell_index);
1274 }
1275}
1276
1277static int soc15_common_hw_init(void *handle)
1278{
1279 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1280
1281 /* enable pcie gen2/3 link */
1282 soc15_pcie_gen3_enable(adev);
1283 /* enable aspm */
1284 soc15_program_aspm(adev);
1285 /* setup nbio registers */
1286 adev->nbio_funcs->init_registers(adev);
1287 /* remap HDP registers to a hole in mmio space,
1288 * for the purpose of expose those registers
1289 * to process space
1290 */
1291 if (adev->nbio_funcs->remap_hdp_registers)
1292 adev->nbio_funcs->remap_hdp_registers(adev);
1293
1294 /* enable the doorbell aperture */
1295 soc15_enable_doorbell_aperture(adev, true);
1296 /* HW doorbell routing policy: doorbell writing not
1297 * in SDMA/IH/MM/ACV range will be routed to CP. So
1298 * we need to init SDMA/IH/MM/ACV doorbell range prior
1299 * to CP ip block init and ring test.
1300 */
1301 soc15_doorbell_range_init(adev);
1302
1303 return 0;
1304}
1305
1306static int soc15_common_hw_fini(void *handle)
1307{
1308 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1309
1310 /* disable the doorbell aperture */
1311 soc15_enable_doorbell_aperture(adev, false);
1312 if (amdgpu_sriov_vf(adev))
1313 xgpu_ai_mailbox_put_irq(adev);
1314
1315 return 0;
1316}
1317
1318static int soc15_common_suspend(void *handle)
1319{
1320 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1321
1322 return soc15_common_hw_fini(adev);
1323}
1324
1325static int soc15_common_resume(void *handle)
1326{
1327 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1328
1329 return soc15_common_hw_init(adev);
1330}
1331
1332static bool soc15_common_is_idle(void *handle)
1333{
1334 return true;
1335}
1336
1337static int soc15_common_wait_for_idle(void *handle)
1338{
1339 return 0;
1340}
1341
1342static int soc15_common_soft_reset(void *handle)
1343{
1344 return 0;
1345}
1346
1347static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
1348{
1349 uint32_t def, data;
1350
1351 if (adev->asic_type == CHIP_VEGA20 ||
1352 adev->asic_type == CHIP_ARCTURUS) {
1353 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL));
1354
1355 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1356 data |= HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1357 HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1358 HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1359 HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK;
1360 else
1361 data &= ~(HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1362 HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1363 HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1364 HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK);
1365
1366 if (def != data)
1367 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL), data);
1368 } else {
1369 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1370
1371 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1372 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1373 else
1374 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1375
1376 if (def != data)
1377 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
1378 }
1379}
1380
1381static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
1382{
1383 uint32_t def, data;
1384
1385 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1386
1387 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
1388 data &= ~(0x01000000 |
1389 0x02000000 |
1390 0x04000000 |
1391 0x08000000 |
1392 0x10000000 |
1393 0x20000000 |
1394 0x40000000 |
1395 0x80000000);
1396 else
1397 data |= (0x01000000 |
1398 0x02000000 |
1399 0x04000000 |
1400 0x08000000 |
1401 0x10000000 |
1402 0x20000000 |
1403 0x40000000 |
1404 0x80000000);
1405
1406 if (def != data)
1407 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
1408}
1409
1410static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
1411{
1412 uint32_t def, data;
1413
1414 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1415
1416 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1417 data |= 1;
1418 else
1419 data &= ~1;
1420
1421 if (def != data)
1422 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
1423}
1424
1425static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1426 bool enable)
1427{
1428 uint32_t def, data;
1429
1430 def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
1431
1432 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
1433 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1434 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1435 else
1436 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1437 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1438
1439 if (def != data)
1440 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
1441}
1442
1443static int soc15_common_set_clockgating_state(void *handle,
1444 enum amd_clockgating_state state)
1445{
1446 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1447
1448 if (amdgpu_sriov_vf(adev))
1449 return 0;
1450
1451 switch (adev->asic_type) {
1452 case CHIP_VEGA10:
1453 case CHIP_VEGA12:
1454 case CHIP_VEGA20:
1455 adev->nbio_funcs->update_medium_grain_clock_gating(adev,
1456 state == AMD_CG_STATE_GATE ? true : false);
1457 adev->nbio_funcs->update_medium_grain_light_sleep(adev,
1458 state == AMD_CG_STATE_GATE ? true : false);
1459 soc15_update_hdp_light_sleep(adev,
1460 state == AMD_CG_STATE_GATE ? true : false);
1461 soc15_update_drm_clock_gating(adev,
1462 state == AMD_CG_STATE_GATE ? true : false);
1463 soc15_update_drm_light_sleep(adev,
1464 state == AMD_CG_STATE_GATE ? true : false);
1465 soc15_update_rom_medium_grain_clock_gating(adev,
1466 state == AMD_CG_STATE_GATE ? true : false);
1467 adev->df_funcs->update_medium_grain_clock_gating(adev,
1468 state == AMD_CG_STATE_GATE ? true : false);
1469 break;
1470 case CHIP_RAVEN:
1471 case CHIP_RENOIR:
1472 adev->nbio_funcs->update_medium_grain_clock_gating(adev,
1473 state == AMD_CG_STATE_GATE ? true : false);
1474 adev->nbio_funcs->update_medium_grain_light_sleep(adev,
1475 state == AMD_CG_STATE_GATE ? true : false);
1476 soc15_update_hdp_light_sleep(adev,
1477 state == AMD_CG_STATE_GATE ? true : false);
1478 soc15_update_drm_clock_gating(adev,
1479 state == AMD_CG_STATE_GATE ? true : false);
1480 soc15_update_drm_light_sleep(adev,
1481 state == AMD_CG_STATE_GATE ? true : false);
1482 soc15_update_rom_medium_grain_clock_gating(adev,
1483 state == AMD_CG_STATE_GATE ? true : false);
1484 break;
1485 case CHIP_ARCTURUS:
1486 soc15_update_hdp_light_sleep(adev,
1487 state == AMD_CG_STATE_GATE ? true : false);
1488 break;
1489 default:
1490 break;
1491 }
1492 return 0;
1493}
1494
1495static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
1496{
1497 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1498 int data;
1499
1500 if (amdgpu_sriov_vf(adev))
1501 *flags = 0;
1502
1503 adev->nbio_funcs->get_clockgating_state(adev, flags);
1504
1505 /* AMD_CG_SUPPORT_HDP_LS */
1506 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1507 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1508 *flags |= AMD_CG_SUPPORT_HDP_LS;
1509
1510 /* AMD_CG_SUPPORT_DRM_MGCG */
1511 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1512 if (!(data & 0x01000000))
1513 *flags |= AMD_CG_SUPPORT_DRM_MGCG;
1514
1515 /* AMD_CG_SUPPORT_DRM_LS */
1516 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1517 if (data & 0x1)
1518 *flags |= AMD_CG_SUPPORT_DRM_LS;
1519
1520 /* AMD_CG_SUPPORT_ROM_MGCG */
1521 data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
1522 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
1523 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
1524
1525 adev->df_funcs->get_clockgating_state(adev, flags);
1526}
1527
1528static int soc15_common_set_powergating_state(void *handle,
1529 enum amd_powergating_state state)
1530{
1531 /* todo */
1532 return 0;
1533}
1534
1535const struct amd_ip_funcs soc15_common_ip_funcs = {
1536 .name = "soc15_common",
1537 .early_init = soc15_common_early_init,
1538 .late_init = soc15_common_late_init,
1539 .sw_init = soc15_common_sw_init,
1540 .sw_fini = soc15_common_sw_fini,
1541 .hw_init = soc15_common_hw_init,
1542 .hw_fini = soc15_common_hw_fini,
1543 .suspend = soc15_common_suspend,
1544 .resume = soc15_common_resume,
1545 .is_idle = soc15_common_is_idle,
1546 .wait_for_idle = soc15_common_wait_for_idle,
1547 .soft_reset = soc15_common_soft_reset,
1548 .set_clockgating_state = soc15_common_set_clockgating_state,
1549 .set_powergating_state = soc15_common_set_powergating_state,
1550 .get_clockgating_state= soc15_common_get_clockgating_state,
1551};