2 * Copyright 2016 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <linux/firmware.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/pci.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"
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 "nbio/nbio_7_0_default.h"
46 #include "nbio/nbio_7_0_offset.h"
47 #include "nbio/nbio_7_0_sh_mask.h"
48 #include "nbio/nbio_7_0_smn.h"
49 #include "mp/mp_9_0_offset.h"
52 #include "soc15_common.h"
55 #include "gfxhub_v1_0.h"
56 #include "mmhub_v1_0.h"
59 #include "nbio_v6_1.h"
60 #include "nbio_v7_0.h"
61 #include "nbio_v7_4.h"
62 #include "vega10_ih.h"
63 #include "navi10_ih.h"
64 #include "sdma_v4_0.h"
69 #include "jpeg_v2_0.h"
71 #include "jpeg_v2_5.h"
72 #include "smuio_v9_0.h"
73 #include "smuio_v11_0.h"
74 #include "dce_virtual.h"
76 #include "amdgpu_smu.h"
77 #include "amdgpu_ras.h"
78 #include "amdgpu_xgmi.h"
79 #include <uapi/linux/kfd_ioctl.h>
81 #define mmMP0_MISC_CGTT_CTRL0 0x01b9
82 #define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
83 #define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
84 #define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
86 /* for Vega20 register name change */
87 #define mmHDP_MEM_POWER_CTRL 0x00d4
88 #define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK 0x00000001L
89 #define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK 0x00000002L
90 #define HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK 0x00010000L
91 #define HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK 0x00020000L
92 #define mmHDP_MEM_POWER_CTRL_BASE_IDX 0
95 * Indirect registers accessor
97 static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
99 unsigned long address, data;
100 address = adev->nbio.funcs->get_pcie_index_offset(adev);
101 data = adev->nbio.funcs->get_pcie_data_offset(adev);
103 return amdgpu_device_indirect_rreg(adev, address, data, reg);
106 static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
108 unsigned long address, data;
110 address = adev->nbio.funcs->get_pcie_index_offset(adev);
111 data = adev->nbio.funcs->get_pcie_data_offset(adev);
113 amdgpu_device_indirect_wreg(adev, address, data, reg, v);
116 static u64 soc15_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
118 unsigned long address, data;
119 address = adev->nbio.funcs->get_pcie_index_offset(adev);
120 data = adev->nbio.funcs->get_pcie_data_offset(adev);
122 return amdgpu_device_indirect_rreg64(adev, address, data, reg);
125 static void soc15_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
127 unsigned long address, data;
129 address = adev->nbio.funcs->get_pcie_index_offset(adev);
130 data = adev->nbio.funcs->get_pcie_data_offset(adev);
132 amdgpu_device_indirect_wreg64(adev, address, data, reg, v);
135 static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
137 unsigned long flags, address, data;
140 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
141 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
143 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
144 WREG32(address, ((reg) & 0x1ff));
146 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
150 static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
152 unsigned long flags, address, data;
154 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
155 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
157 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
158 WREG32(address, ((reg) & 0x1ff));
160 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
163 static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
165 unsigned long flags, address, data;
168 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
169 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
171 spin_lock_irqsave(&adev->didt_idx_lock, flags);
172 WREG32(address, (reg));
174 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
178 static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
180 unsigned long flags, address, data;
182 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
183 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
185 spin_lock_irqsave(&adev->didt_idx_lock, flags);
186 WREG32(address, (reg));
188 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
191 static u32 soc15_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
196 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
197 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
198 r = RREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA);
199 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
203 static void soc15_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
207 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
208 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
209 WREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA, (v));
210 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
213 static u32 soc15_se_cac_rreg(struct amdgpu_device *adev, u32 reg)
218 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
219 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
220 r = RREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA);
221 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
225 static void soc15_se_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
229 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
230 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
231 WREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA, (v));
232 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
235 static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
237 return adev->nbio.funcs->get_memsize(adev);
240 static u32 soc15_get_xclk(struct amdgpu_device *adev)
242 u32 reference_clock = adev->clock.spll.reference_freq;
244 if (adev->asic_type == CHIP_RAVEN)
245 return reference_clock / 4;
247 return reference_clock;
251 void soc15_grbm_select(struct amdgpu_device *adev,
252 u32 me, u32 pipe, u32 queue, u32 vmid)
254 u32 grbm_gfx_cntl = 0;
255 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
256 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
257 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
258 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
260 WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
263 static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
268 static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
274 static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
275 u8 *bios, u32 length_bytes)
279 uint32_t rom_index_offset;
280 uint32_t rom_data_offset;
284 if (length_bytes == 0)
286 /* APU vbios image is part of sbios image */
287 if (adev->flags & AMD_IS_APU)
290 dw_ptr = (u32 *)bios;
291 length_dw = ALIGN(length_bytes, 4) / 4;
294 adev->smuio.funcs->get_rom_index_offset(adev);
296 adev->smuio.funcs->get_rom_data_offset(adev);
298 /* set rom index to 0 */
299 WREG32(rom_index_offset, 0);
300 /* read out the rom data */
301 for (i = 0; i < length_dw; i++)
302 dw_ptr[i] = RREG32(rom_data_offset);
307 static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {
308 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
309 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
310 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
311 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
312 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
313 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
314 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
315 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
316 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
317 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
318 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
319 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
320 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
321 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
322 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
323 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
324 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
325 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
326 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
327 { SOC15_REG_ENTRY(GC, 0, mmDB_DEBUG2)},
330 static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
331 u32 sh_num, u32 reg_offset)
335 mutex_lock(&adev->grbm_idx_mutex);
336 if (se_num != 0xffffffff || sh_num != 0xffffffff)
337 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
339 val = RREG32(reg_offset);
341 if (se_num != 0xffffffff || sh_num != 0xffffffff)
342 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
343 mutex_unlock(&adev->grbm_idx_mutex);
347 static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
348 bool indexed, u32 se_num,
349 u32 sh_num, u32 reg_offset)
352 return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
354 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
355 return adev->gfx.config.gb_addr_config;
356 else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
357 return adev->gfx.config.db_debug2;
358 return RREG32(reg_offset);
362 static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
363 u32 sh_num, u32 reg_offset, u32 *value)
366 struct soc15_allowed_register_entry *en;
369 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
370 en = &soc15_allowed_read_registers[i];
371 if (adev->reg_offset[en->hwip][en->inst] &&
372 reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
376 *value = soc15_get_register_value(adev,
377 soc15_allowed_read_registers[i].grbm_indexed,
378 se_num, sh_num, reg_offset);
386 * soc15_program_register_sequence - program an array of registers.
388 * @adev: amdgpu_device pointer
389 * @regs: pointer to the register array
390 * @array_size: size of the register array
392 * Programs an array or registers with and and or masks.
393 * This is a helper for setting golden registers.
396 void soc15_program_register_sequence(struct amdgpu_device *adev,
397 const struct soc15_reg_golden *regs,
398 const u32 array_size)
400 const struct soc15_reg_golden *entry;
404 for (i = 0; i < array_size; ++i) {
406 reg = adev->reg_offset[entry->hwip][entry->instance][entry->segment] + entry->reg;
408 if (entry->and_mask == 0xffffffff) {
409 tmp = entry->or_mask;
412 tmp &= ~(entry->and_mask);
413 tmp |= (entry->or_mask & entry->and_mask);
416 if (reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_BINNER_EVENT_CNTL_3) ||
417 reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE) ||
418 reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE_1) ||
419 reg == SOC15_REG_OFFSET(GC, 0, mmSH_MEM_CONFIG))
420 WREG32_RLC(reg, tmp);
428 static int soc15_asic_mode1_reset(struct amdgpu_device *adev)
433 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
435 dev_info(adev->dev, "GPU mode1 reset\n");
438 pci_clear_master(adev->pdev);
440 amdgpu_device_cache_pci_state(adev->pdev);
442 ret = psp_gpu_reset(adev);
444 dev_err(adev->dev, "GPU mode1 reset failed\n");
446 amdgpu_device_load_pci_state(adev->pdev);
448 /* wait for asic to come out of reset */
449 for (i = 0; i < adev->usec_timeout; i++) {
450 u32 memsize = adev->nbio.funcs->get_memsize(adev);
452 if (memsize != 0xffffffff)
457 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
462 static int soc15_asic_baco_reset(struct amdgpu_device *adev)
464 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
467 /* avoid NBIF got stuck when do RAS recovery in BACO reset */
468 if (ras && ras->supported)
469 adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
471 ret = amdgpu_dpm_baco_reset(adev);
475 /* re-enable doorbell interrupt after BACO exit */
476 if (ras && ras->supported)
477 adev->nbio.funcs->enable_doorbell_interrupt(adev, true);
482 static enum amd_reset_method
483 soc15_asic_reset_method(struct amdgpu_device *adev)
485 bool baco_reset = false;
486 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
488 if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
489 amdgpu_reset_method == AMD_RESET_METHOD_MODE2 ||
490 amdgpu_reset_method == AMD_RESET_METHOD_BACO)
491 return amdgpu_reset_method;
493 if (amdgpu_reset_method != -1)
494 dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
495 amdgpu_reset_method);
497 switch (adev->asic_type) {
500 return AMD_RESET_METHOD_MODE2;
504 baco_reset = amdgpu_dpm_is_baco_supported(adev);
507 if (adev->psp.sos_fw_version >= 0x80067)
508 baco_reset = amdgpu_dpm_is_baco_supported(adev);
511 * 1. PMFW version > 0x284300: all cases use baco
512 * 2. PMFW version <= 0x284300: only sGPU w/o RAS use baco
514 if ((ras && ras->supported) && adev->pm.fw_version <= 0x283400)
522 return AMD_RESET_METHOD_BACO;
524 return AMD_RESET_METHOD_MODE1;
527 static int soc15_asic_reset(struct amdgpu_device *adev)
529 /* original raven doesn't have full asic reset */
530 if ((adev->apu_flags & AMD_APU_IS_RAVEN) &&
531 !(adev->apu_flags & AMD_APU_IS_RAVEN2))
534 switch (soc15_asic_reset_method(adev)) {
535 case AMD_RESET_METHOD_BACO:
536 dev_info(adev->dev, "BACO reset\n");
537 return soc15_asic_baco_reset(adev);
538 case AMD_RESET_METHOD_MODE2:
539 dev_info(adev->dev, "MODE2 reset\n");
540 return amdgpu_dpm_mode2_reset(adev);
542 dev_info(adev->dev, "MODE1 reset\n");
543 return soc15_asic_mode1_reset(adev);
547 static bool soc15_supports_baco(struct amdgpu_device *adev)
549 switch (adev->asic_type) {
553 return amdgpu_dpm_is_baco_supported(adev);
555 if (adev->psp.sos_fw_version >= 0x80067)
556 return amdgpu_dpm_is_baco_supported(adev);
563 /*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
564 u32 cntl_reg, u32 status_reg)
569 static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
573 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
577 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
582 static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
589 static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
591 if (pci_is_root_bus(adev->pdev->bus))
594 if (amdgpu_pcie_gen2 == 0)
597 if (adev->flags & AMD_IS_APU)
600 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
601 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
607 static void soc15_program_aspm(struct amdgpu_device *adev)
610 if (amdgpu_aspm == 0)
616 static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
619 adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
620 adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
623 static const struct amdgpu_ip_block_version vega10_common_ip_block =
625 .type = AMD_IP_BLOCK_TYPE_COMMON,
629 .funcs = &soc15_common_ip_funcs,
632 static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
634 return adev->nbio.funcs->get_rev_id(adev);
637 static void soc15_reg_base_init(struct amdgpu_device *adev)
641 /* Set IP register base before any HW register access */
642 switch (adev->asic_type) {
646 vega10_reg_base_init(adev);
649 /* It's safe to do ip discovery here for Renior,
650 * it doesn't support SRIOV. */
651 if (amdgpu_discovery) {
652 r = amdgpu_discovery_reg_base_init(adev);
655 DRM_WARN("failed to init reg base from ip discovery table, "
656 "fallback to legacy init method\n");
658 vega10_reg_base_init(adev);
661 vega20_reg_base_init(adev);
664 arct_reg_base_init(adev);
667 DRM_ERROR("Unsupported asic type: %d!\n", adev->asic_type);
672 void soc15_set_virt_ops(struct amdgpu_device *adev)
674 adev->virt.ops = &xgpu_ai_virt_ops;
676 /* init soc15 reg base early enough so we can
677 * request request full access for sriov before
679 soc15_reg_base_init(adev);
682 int soc15_set_ip_blocks(struct amdgpu_device *adev)
684 /* for bare metal case */
685 if (!amdgpu_sriov_vf(adev))
686 soc15_reg_base_init(adev);
688 if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
689 adev->gmc.xgmi.supported = true;
691 if (adev->flags & AMD_IS_APU) {
692 adev->nbio.funcs = &nbio_v7_0_funcs;
693 adev->nbio.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg;
694 } else if (adev->asic_type == CHIP_VEGA20 ||
695 adev->asic_type == CHIP_ARCTURUS) {
696 adev->nbio.funcs = &nbio_v7_4_funcs;
697 adev->nbio.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg;
699 adev->nbio.funcs = &nbio_v6_1_funcs;
700 adev->nbio.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg;
703 if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
704 adev->df.funcs = &df_v3_6_funcs;
706 adev->df.funcs = &df_v1_7_funcs;
708 if (adev->asic_type == CHIP_VEGA20 ||
709 adev->asic_type == CHIP_ARCTURUS)
710 adev->smuio.funcs = &smuio_v11_0_funcs;
712 adev->smuio.funcs = &smuio_v9_0_funcs;
714 adev->rev_id = soc15_get_rev_id(adev);
716 switch (adev->asic_type) {
720 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
721 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
723 /* For Vega10 SR-IOV, PSP need to be initialized before IH */
724 if (amdgpu_sriov_vf(adev)) {
725 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
726 if (adev->asic_type == CHIP_VEGA20)
727 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
729 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
731 if (adev->asic_type == CHIP_VEGA20)
732 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
734 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
736 if (adev->asic_type == CHIP_VEGA20)
737 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
739 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
740 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
741 if (adev->asic_type == CHIP_VEGA20)
742 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
744 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
747 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
748 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
749 if (is_support_sw_smu(adev)) {
750 if (!amdgpu_sriov_vf(adev))
751 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
753 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
755 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
756 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
757 #if defined(CONFIG_DRM_AMD_DC)
758 else if (amdgpu_device_has_dc_support(adev))
759 amdgpu_device_ip_block_add(adev, &dm_ip_block);
761 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) {
762 amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
763 amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
767 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
768 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
769 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
770 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
771 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
772 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
773 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
774 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
775 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
776 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
777 #if defined(CONFIG_DRM_AMD_DC)
778 else if (amdgpu_device_has_dc_support(adev))
779 amdgpu_device_ip_block_add(adev, &dm_ip_block);
781 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
784 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
785 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
787 if (amdgpu_sriov_vf(adev)) {
788 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
789 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
790 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
792 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
793 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
794 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
797 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
798 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
799 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
800 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
801 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
803 if (amdgpu_sriov_vf(adev)) {
804 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
805 amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
807 amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
809 if (!amdgpu_sriov_vf(adev))
810 amdgpu_device_ip_block_add(adev, &jpeg_v2_5_ip_block);
813 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
814 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
815 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
816 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
817 amdgpu_device_ip_block_add(adev, &psp_v12_0_ip_block);
818 amdgpu_device_ip_block_add(adev, &smu_v12_0_ip_block);
819 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
820 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
821 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
822 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
823 #if defined(CONFIG_DRM_AMD_DC)
824 else if (amdgpu_device_has_dc_support(adev))
825 amdgpu_device_ip_block_add(adev, &dm_ip_block);
827 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
828 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
837 static void soc15_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
839 adev->nbio.funcs->hdp_flush(adev, ring);
842 static void soc15_invalidate_hdp(struct amdgpu_device *adev,
843 struct amdgpu_ring *ring)
845 if (!ring || !ring->funcs->emit_wreg)
846 WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
848 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
849 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
852 static bool soc15_need_full_reset(struct amdgpu_device *adev)
854 /* change this when we implement soft reset */
858 static void vega20_reset_hdp_ras_error_count(struct amdgpu_device *adev)
860 if (!amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__HDP))
862 /*read back hdp ras counter to reset it to 0 */
863 RREG32_SOC15(HDP, 0, mmHDP_EDC_CNT);
866 static void soc15_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
869 uint32_t perfctr = 0;
870 uint64_t cnt0_of, cnt1_of;
873 /* This reports 0 on APUs, so return to avoid writing/reading registers
874 * that may or may not be different from their GPU counterparts
876 if (adev->flags & AMD_IS_APU)
879 /* Set the 2 events that we wish to watch, defined above */
880 /* Reg 40 is # received msgs */
881 /* Reg 104 is # of posted requests sent */
882 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40);
883 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104);
885 /* Write to enable desired perf counters */
886 WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK, perfctr);
887 /* Zero out and enable the perf counters
889 * Bit 0 = Start all counters(1)
890 * Bit 2 = Global counter reset enable(1)
892 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
896 /* Load the shadow and disable the perf counters
898 * Bit 0 = Stop counters(0)
899 * Bit 1 = Load the shadow counters(1)
901 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
903 /* Read register values to get any >32bit overflow */
904 tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK);
905 cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER);
906 cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER);
908 /* Get the values and add the overflow */
909 *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32);
910 *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
913 static void vega20_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
916 uint32_t perfctr = 0;
917 uint64_t cnt0_of, cnt1_of;
920 /* This reports 0 on APUs, so return to avoid writing/reading registers
921 * that may or may not be different from their GPU counterparts
923 if (adev->flags & AMD_IS_APU)
926 /* Set the 2 events that we wish to watch, defined above */
927 /* Reg 40 is # received msgs */
928 /* Reg 108 is # of posted requests sent on VG20 */
929 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
931 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
934 /* Write to enable desired perf counters */
935 WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctr);
936 /* Zero out and enable the perf counters
938 * Bit 0 = Start all counters(1)
939 * Bit 2 = Global counter reset enable(1)
941 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
945 /* Load the shadow and disable the perf counters
947 * Bit 0 = Stop counters(0)
948 * Bit 1 = Load the shadow counters(1)
950 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
952 /* Read register values to get any >32bit overflow */
953 tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3);
954 cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER0_UPPER);
955 cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER1_UPPER);
957 /* Get the values and add the overflow */
958 *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) | (cnt0_of << 32);
959 *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK3) | (cnt1_of << 32);
962 static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
966 /* Just return false for soc15 GPUs. Reset does not seem to
969 if (!amdgpu_passthrough(adev))
972 if (adev->flags & AMD_IS_APU)
975 /* Check sOS sign of life register to confirm sys driver and sOS
976 * are already been loaded.
978 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
985 static uint64_t soc15_get_pcie_replay_count(struct amdgpu_device *adev)
987 uint64_t nak_r, nak_g;
989 /* Get the number of NAKs received and generated */
990 nak_r = RREG32_PCIE(smnPCIE_RX_NUM_NAK);
991 nak_g = RREG32_PCIE(smnPCIE_RX_NUM_NAK_GENERATED);
993 /* Add the total number of NAKs, i.e the number of replays */
994 return (nak_r + nak_g);
997 static void soc15_pre_asic_init(struct amdgpu_device *adev)
999 gmc_v9_0_restore_registers(adev);
1002 static const struct amdgpu_asic_funcs soc15_asic_funcs =
1004 .read_disabled_bios = &soc15_read_disabled_bios,
1005 .read_bios_from_rom = &soc15_read_bios_from_rom,
1006 .read_register = &soc15_read_register,
1007 .reset = &soc15_asic_reset,
1008 .reset_method = &soc15_asic_reset_method,
1009 .set_vga_state = &soc15_vga_set_state,
1010 .get_xclk = &soc15_get_xclk,
1011 .set_uvd_clocks = &soc15_set_uvd_clocks,
1012 .set_vce_clocks = &soc15_set_vce_clocks,
1013 .get_config_memsize = &soc15_get_config_memsize,
1014 .flush_hdp = &soc15_flush_hdp,
1015 .invalidate_hdp = &soc15_invalidate_hdp,
1016 .need_full_reset = &soc15_need_full_reset,
1017 .init_doorbell_index = &vega10_doorbell_index_init,
1018 .get_pcie_usage = &soc15_get_pcie_usage,
1019 .need_reset_on_init = &soc15_need_reset_on_init,
1020 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
1021 .supports_baco = &soc15_supports_baco,
1022 .pre_asic_init = &soc15_pre_asic_init,
1025 static const struct amdgpu_asic_funcs vega20_asic_funcs =
1027 .read_disabled_bios = &soc15_read_disabled_bios,
1028 .read_bios_from_rom = &soc15_read_bios_from_rom,
1029 .read_register = &soc15_read_register,
1030 .reset = &soc15_asic_reset,
1031 .reset_method = &soc15_asic_reset_method,
1032 .set_vga_state = &soc15_vga_set_state,
1033 .get_xclk = &soc15_get_xclk,
1034 .set_uvd_clocks = &soc15_set_uvd_clocks,
1035 .set_vce_clocks = &soc15_set_vce_clocks,
1036 .get_config_memsize = &soc15_get_config_memsize,
1037 .flush_hdp = &soc15_flush_hdp,
1038 .invalidate_hdp = &soc15_invalidate_hdp,
1039 .reset_hdp_ras_error_count = &vega20_reset_hdp_ras_error_count,
1040 .need_full_reset = &soc15_need_full_reset,
1041 .init_doorbell_index = &vega20_doorbell_index_init,
1042 .get_pcie_usage = &vega20_get_pcie_usage,
1043 .need_reset_on_init = &soc15_need_reset_on_init,
1044 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
1045 .supports_baco = &soc15_supports_baco,
1046 .pre_asic_init = &soc15_pre_asic_init,
1049 static int soc15_common_early_init(void *handle)
1051 #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
1052 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1054 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
1055 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
1056 adev->smc_rreg = NULL;
1057 adev->smc_wreg = NULL;
1058 adev->pcie_rreg = &soc15_pcie_rreg;
1059 adev->pcie_wreg = &soc15_pcie_wreg;
1060 adev->pcie_rreg64 = &soc15_pcie_rreg64;
1061 adev->pcie_wreg64 = &soc15_pcie_wreg64;
1062 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
1063 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
1064 adev->didt_rreg = &soc15_didt_rreg;
1065 adev->didt_wreg = &soc15_didt_wreg;
1066 adev->gc_cac_rreg = &soc15_gc_cac_rreg;
1067 adev->gc_cac_wreg = &soc15_gc_cac_wreg;
1068 adev->se_cac_rreg = &soc15_se_cac_rreg;
1069 adev->se_cac_wreg = &soc15_se_cac_wreg;
1072 adev->external_rev_id = 0xFF;
1073 switch (adev->asic_type) {
1075 adev->asic_funcs = &soc15_asic_funcs;
1076 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1077 AMD_CG_SUPPORT_GFX_MGLS |
1078 AMD_CG_SUPPORT_GFX_RLC_LS |
1079 AMD_CG_SUPPORT_GFX_CP_LS |
1080 AMD_CG_SUPPORT_GFX_3D_CGCG |
1081 AMD_CG_SUPPORT_GFX_3D_CGLS |
1082 AMD_CG_SUPPORT_GFX_CGCG |
1083 AMD_CG_SUPPORT_GFX_CGLS |
1084 AMD_CG_SUPPORT_BIF_MGCG |
1085 AMD_CG_SUPPORT_BIF_LS |
1086 AMD_CG_SUPPORT_HDP_LS |
1087 AMD_CG_SUPPORT_DRM_MGCG |
1088 AMD_CG_SUPPORT_DRM_LS |
1089 AMD_CG_SUPPORT_ROM_MGCG |
1090 AMD_CG_SUPPORT_DF_MGCG |
1091 AMD_CG_SUPPORT_SDMA_MGCG |
1092 AMD_CG_SUPPORT_SDMA_LS |
1093 AMD_CG_SUPPORT_MC_MGCG |
1094 AMD_CG_SUPPORT_MC_LS;
1096 adev->external_rev_id = 0x1;
1099 adev->asic_funcs = &soc15_asic_funcs;
1100 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1101 AMD_CG_SUPPORT_GFX_MGLS |
1102 AMD_CG_SUPPORT_GFX_CGCG |
1103 AMD_CG_SUPPORT_GFX_CGLS |
1104 AMD_CG_SUPPORT_GFX_3D_CGCG |
1105 AMD_CG_SUPPORT_GFX_3D_CGLS |
1106 AMD_CG_SUPPORT_GFX_CP_LS |
1107 AMD_CG_SUPPORT_MC_LS |
1108 AMD_CG_SUPPORT_MC_MGCG |
1109 AMD_CG_SUPPORT_SDMA_MGCG |
1110 AMD_CG_SUPPORT_SDMA_LS |
1111 AMD_CG_SUPPORT_BIF_MGCG |
1112 AMD_CG_SUPPORT_BIF_LS |
1113 AMD_CG_SUPPORT_HDP_MGCG |
1114 AMD_CG_SUPPORT_HDP_LS |
1115 AMD_CG_SUPPORT_ROM_MGCG |
1116 AMD_CG_SUPPORT_VCE_MGCG |
1117 AMD_CG_SUPPORT_UVD_MGCG;
1119 adev->external_rev_id = adev->rev_id + 0x14;
1122 adev->asic_funcs = &vega20_asic_funcs;
1123 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1124 AMD_CG_SUPPORT_GFX_MGLS |
1125 AMD_CG_SUPPORT_GFX_CGCG |
1126 AMD_CG_SUPPORT_GFX_CGLS |
1127 AMD_CG_SUPPORT_GFX_3D_CGCG |
1128 AMD_CG_SUPPORT_GFX_3D_CGLS |
1129 AMD_CG_SUPPORT_GFX_CP_LS |
1130 AMD_CG_SUPPORT_MC_LS |
1131 AMD_CG_SUPPORT_MC_MGCG |
1132 AMD_CG_SUPPORT_SDMA_MGCG |
1133 AMD_CG_SUPPORT_SDMA_LS |
1134 AMD_CG_SUPPORT_BIF_MGCG |
1135 AMD_CG_SUPPORT_BIF_LS |
1136 AMD_CG_SUPPORT_HDP_MGCG |
1137 AMD_CG_SUPPORT_HDP_LS |
1138 AMD_CG_SUPPORT_ROM_MGCG |
1139 AMD_CG_SUPPORT_VCE_MGCG |
1140 AMD_CG_SUPPORT_UVD_MGCG;
1142 adev->external_rev_id = adev->rev_id + 0x28;
1145 adev->asic_funcs = &soc15_asic_funcs;
1146 if (adev->pdev->device == 0x15dd)
1147 adev->apu_flags |= AMD_APU_IS_RAVEN;
1148 if (adev->pdev->device == 0x15d8)
1149 adev->apu_flags |= AMD_APU_IS_PICASSO;
1150 if (adev->rev_id >= 0x8)
1151 adev->apu_flags |= AMD_APU_IS_RAVEN2;
1153 if (adev->apu_flags & AMD_APU_IS_RAVEN2)
1154 adev->external_rev_id = adev->rev_id + 0x79;
1155 else if (adev->apu_flags & AMD_APU_IS_PICASSO)
1156 adev->external_rev_id = adev->rev_id + 0x41;
1157 else if (adev->rev_id == 1)
1158 adev->external_rev_id = adev->rev_id + 0x20;
1160 adev->external_rev_id = adev->rev_id + 0x01;
1162 if (adev->apu_flags & AMD_APU_IS_RAVEN2) {
1163 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1164 AMD_CG_SUPPORT_GFX_MGLS |
1165 AMD_CG_SUPPORT_GFX_CP_LS |
1166 AMD_CG_SUPPORT_GFX_3D_CGCG |
1167 AMD_CG_SUPPORT_GFX_3D_CGLS |
1168 AMD_CG_SUPPORT_GFX_CGCG |
1169 AMD_CG_SUPPORT_GFX_CGLS |
1170 AMD_CG_SUPPORT_BIF_LS |
1171 AMD_CG_SUPPORT_HDP_LS |
1172 AMD_CG_SUPPORT_MC_MGCG |
1173 AMD_CG_SUPPORT_MC_LS |
1174 AMD_CG_SUPPORT_SDMA_MGCG |
1175 AMD_CG_SUPPORT_SDMA_LS |
1176 AMD_CG_SUPPORT_VCN_MGCG;
1178 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
1179 } else if (adev->apu_flags & AMD_APU_IS_PICASSO) {
1180 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1181 AMD_CG_SUPPORT_GFX_MGLS |
1182 AMD_CG_SUPPORT_GFX_CP_LS |
1183 AMD_CG_SUPPORT_GFX_3D_CGCG |
1184 AMD_CG_SUPPORT_GFX_3D_CGLS |
1185 AMD_CG_SUPPORT_GFX_CGCG |
1186 AMD_CG_SUPPORT_GFX_CGLS |
1187 AMD_CG_SUPPORT_BIF_LS |
1188 AMD_CG_SUPPORT_HDP_LS |
1189 AMD_CG_SUPPORT_MC_MGCG |
1190 AMD_CG_SUPPORT_MC_LS |
1191 AMD_CG_SUPPORT_SDMA_MGCG |
1192 AMD_CG_SUPPORT_SDMA_LS;
1194 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
1195 AMD_PG_SUPPORT_MMHUB |
1198 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1199 AMD_CG_SUPPORT_GFX_MGLS |
1200 AMD_CG_SUPPORT_GFX_RLC_LS |
1201 AMD_CG_SUPPORT_GFX_CP_LS |
1202 AMD_CG_SUPPORT_GFX_3D_CGCG |
1203 AMD_CG_SUPPORT_GFX_3D_CGLS |
1204 AMD_CG_SUPPORT_GFX_CGCG |
1205 AMD_CG_SUPPORT_GFX_CGLS |
1206 AMD_CG_SUPPORT_BIF_MGCG |
1207 AMD_CG_SUPPORT_BIF_LS |
1208 AMD_CG_SUPPORT_HDP_MGCG |
1209 AMD_CG_SUPPORT_HDP_LS |
1210 AMD_CG_SUPPORT_DRM_MGCG |
1211 AMD_CG_SUPPORT_DRM_LS |
1212 AMD_CG_SUPPORT_MC_MGCG |
1213 AMD_CG_SUPPORT_MC_LS |
1214 AMD_CG_SUPPORT_SDMA_MGCG |
1215 AMD_CG_SUPPORT_SDMA_LS |
1216 AMD_CG_SUPPORT_VCN_MGCG;
1218 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
1222 adev->asic_funcs = &vega20_asic_funcs;
1223 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1224 AMD_CG_SUPPORT_GFX_MGLS |
1225 AMD_CG_SUPPORT_GFX_CGCG |
1226 AMD_CG_SUPPORT_GFX_CGLS |
1227 AMD_CG_SUPPORT_GFX_CP_LS |
1228 AMD_CG_SUPPORT_HDP_MGCG |
1229 AMD_CG_SUPPORT_HDP_LS |
1230 AMD_CG_SUPPORT_SDMA_MGCG |
1231 AMD_CG_SUPPORT_SDMA_LS |
1232 AMD_CG_SUPPORT_MC_MGCG |
1233 AMD_CG_SUPPORT_MC_LS |
1234 AMD_CG_SUPPORT_IH_CG |
1235 AMD_CG_SUPPORT_VCN_MGCG |
1236 AMD_CG_SUPPORT_JPEG_MGCG;
1237 adev->pg_flags = AMD_PG_SUPPORT_VCN | AMD_PG_SUPPORT_VCN_DPG;
1238 adev->external_rev_id = adev->rev_id + 0x32;
1241 adev->asic_funcs = &soc15_asic_funcs;
1242 if ((adev->pdev->device == 0x1636) ||
1243 (adev->pdev->device == 0x164c))
1244 adev->apu_flags |= AMD_APU_IS_RENOIR;
1246 adev->apu_flags |= AMD_APU_IS_GREEN_SARDINE;
1248 if (adev->apu_flags & AMD_APU_IS_RENOIR)
1249 adev->external_rev_id = adev->rev_id + 0x91;
1251 adev->external_rev_id = adev->rev_id + 0xa1;
1252 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1253 AMD_CG_SUPPORT_GFX_MGLS |
1254 AMD_CG_SUPPORT_GFX_3D_CGCG |
1255 AMD_CG_SUPPORT_GFX_3D_CGLS |
1256 AMD_CG_SUPPORT_GFX_CGCG |
1257 AMD_CG_SUPPORT_GFX_CGLS |
1258 AMD_CG_SUPPORT_GFX_CP_LS |
1259 AMD_CG_SUPPORT_MC_MGCG |
1260 AMD_CG_SUPPORT_MC_LS |
1261 AMD_CG_SUPPORT_SDMA_MGCG |
1262 AMD_CG_SUPPORT_SDMA_LS |
1263 AMD_CG_SUPPORT_BIF_LS |
1264 AMD_CG_SUPPORT_HDP_LS |
1265 AMD_CG_SUPPORT_VCN_MGCG |
1266 AMD_CG_SUPPORT_JPEG_MGCG |
1267 AMD_CG_SUPPORT_IH_CG |
1268 AMD_CG_SUPPORT_ATHUB_LS |
1269 AMD_CG_SUPPORT_ATHUB_MGCG |
1270 AMD_CG_SUPPORT_DF_MGCG;
1271 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
1272 AMD_PG_SUPPORT_VCN |
1273 AMD_PG_SUPPORT_JPEG |
1274 AMD_PG_SUPPORT_VCN_DPG;
1277 /* FIXME: not supported yet */
1281 if (amdgpu_sriov_vf(adev)) {
1282 amdgpu_virt_init_setting(adev);
1283 xgpu_ai_mailbox_set_irq_funcs(adev);
1289 static int soc15_common_late_init(void *handle)
1291 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1294 if (amdgpu_sriov_vf(adev))
1295 xgpu_ai_mailbox_get_irq(adev);
1297 if (adev->asic_funcs &&
1298 adev->asic_funcs->reset_hdp_ras_error_count)
1299 adev->asic_funcs->reset_hdp_ras_error_count(adev);
1301 if (adev->nbio.funcs->ras_late_init)
1302 r = adev->nbio.funcs->ras_late_init(adev);
1307 static int soc15_common_sw_init(void *handle)
1309 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1311 if (amdgpu_sriov_vf(adev))
1312 xgpu_ai_mailbox_add_irq_id(adev);
1314 adev->df.funcs->sw_init(adev);
1319 static int soc15_common_sw_fini(void *handle)
1321 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1323 amdgpu_nbio_ras_fini(adev);
1324 adev->df.funcs->sw_fini(adev);
1328 static void soc15_doorbell_range_init(struct amdgpu_device *adev)
1331 struct amdgpu_ring *ring;
1333 /* sdma/ih doorbell range are programed by hypervisor */
1334 if (!amdgpu_sriov_vf(adev)) {
1335 for (i = 0; i < adev->sdma.num_instances; i++) {
1336 ring = &adev->sdma.instance[i].ring;
1337 adev->nbio.funcs->sdma_doorbell_range(adev, i,
1338 ring->use_doorbell, ring->doorbell_index,
1339 adev->doorbell_index.sdma_doorbell_range);
1342 adev->nbio.funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
1343 adev->irq.ih.doorbell_index);
1347 static int soc15_common_hw_init(void *handle)
1349 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1351 /* enable pcie gen2/3 link */
1352 soc15_pcie_gen3_enable(adev);
1354 soc15_program_aspm(adev);
1355 /* setup nbio registers */
1356 adev->nbio.funcs->init_registers(adev);
1357 /* remap HDP registers to a hole in mmio space,
1358 * for the purpose of expose those registers
1361 if (adev->nbio.funcs->remap_hdp_registers)
1362 adev->nbio.funcs->remap_hdp_registers(adev);
1364 /* enable the doorbell aperture */
1365 soc15_enable_doorbell_aperture(adev, true);
1366 /* HW doorbell routing policy: doorbell writing not
1367 * in SDMA/IH/MM/ACV range will be routed to CP. So
1368 * we need to init SDMA/IH/MM/ACV doorbell range prior
1369 * to CP ip block init and ring test.
1371 soc15_doorbell_range_init(adev);
1376 static int soc15_common_hw_fini(void *handle)
1378 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1380 /* disable the doorbell aperture */
1381 soc15_enable_doorbell_aperture(adev, false);
1382 if (amdgpu_sriov_vf(adev))
1383 xgpu_ai_mailbox_put_irq(adev);
1385 if (adev->nbio.ras_if &&
1386 amdgpu_ras_is_supported(adev, adev->nbio.ras_if->block)) {
1387 if (adev->nbio.funcs->init_ras_controller_interrupt)
1388 amdgpu_irq_put(adev, &adev->nbio.ras_controller_irq, 0);
1389 if (adev->nbio.funcs->init_ras_err_event_athub_interrupt)
1390 amdgpu_irq_put(adev, &adev->nbio.ras_err_event_athub_irq, 0);
1396 static int soc15_common_suspend(void *handle)
1398 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1400 return soc15_common_hw_fini(adev);
1403 static int soc15_common_resume(void *handle)
1405 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1407 return soc15_common_hw_init(adev);
1410 static bool soc15_common_is_idle(void *handle)
1415 static int soc15_common_wait_for_idle(void *handle)
1420 static int soc15_common_soft_reset(void *handle)
1425 static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
1429 if (adev->asic_type == CHIP_VEGA20 ||
1430 adev->asic_type == CHIP_ARCTURUS ||
1431 adev->asic_type == CHIP_RENOIR) {
1432 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL));
1434 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1435 data |= HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1436 HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1437 HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1438 HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK;
1440 data &= ~(HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1441 HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1442 HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1443 HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK);
1446 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL), data);
1448 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1450 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1451 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1453 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1456 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
1460 static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
1464 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1466 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
1467 data &= ~(0x01000000 |
1476 data |= (0x01000000 |
1486 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
1489 static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
1493 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1495 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1501 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
1504 static int soc15_common_set_clockgating_state(void *handle,
1505 enum amd_clockgating_state state)
1507 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1509 if (amdgpu_sriov_vf(adev))
1512 switch (adev->asic_type) {
1516 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1517 state == AMD_CG_STATE_GATE);
1518 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1519 state == AMD_CG_STATE_GATE);
1520 soc15_update_hdp_light_sleep(adev,
1521 state == AMD_CG_STATE_GATE);
1522 soc15_update_drm_clock_gating(adev,
1523 state == AMD_CG_STATE_GATE);
1524 soc15_update_drm_light_sleep(adev,
1525 state == AMD_CG_STATE_GATE);
1526 adev->smuio.funcs->update_rom_clock_gating(adev,
1527 state == AMD_CG_STATE_GATE);
1528 adev->df.funcs->update_medium_grain_clock_gating(adev,
1529 state == AMD_CG_STATE_GATE);
1533 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1534 state == AMD_CG_STATE_GATE);
1535 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1536 state == AMD_CG_STATE_GATE);
1537 soc15_update_hdp_light_sleep(adev,
1538 state == AMD_CG_STATE_GATE);
1539 soc15_update_drm_clock_gating(adev,
1540 state == AMD_CG_STATE_GATE);
1541 soc15_update_drm_light_sleep(adev,
1542 state == AMD_CG_STATE_GATE);
1545 soc15_update_hdp_light_sleep(adev,
1546 state == AMD_CG_STATE_GATE);
1554 static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
1556 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1559 if (amdgpu_sriov_vf(adev))
1562 adev->nbio.funcs->get_clockgating_state(adev, flags);
1564 /* AMD_CG_SUPPORT_HDP_LS */
1565 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1566 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1567 *flags |= AMD_CG_SUPPORT_HDP_LS;
1569 /* AMD_CG_SUPPORT_DRM_MGCG */
1570 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1571 if (!(data & 0x01000000))
1572 *flags |= AMD_CG_SUPPORT_DRM_MGCG;
1574 /* AMD_CG_SUPPORT_DRM_LS */
1575 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1577 *flags |= AMD_CG_SUPPORT_DRM_LS;
1579 /* AMD_CG_SUPPORT_ROM_MGCG */
1580 adev->smuio.funcs->get_clock_gating_state(adev, flags);
1582 adev->df.funcs->get_clockgating_state(adev, flags);
1585 static int soc15_common_set_powergating_state(void *handle,
1586 enum amd_powergating_state state)
1592 const struct amd_ip_funcs soc15_common_ip_funcs = {
1593 .name = "soc15_common",
1594 .early_init = soc15_common_early_init,
1595 .late_init = soc15_common_late_init,
1596 .sw_init = soc15_common_sw_init,
1597 .sw_fini = soc15_common_sw_fini,
1598 .hw_init = soc15_common_hw_init,
1599 .hw_fini = soc15_common_hw_fini,
1600 .suspend = soc15_common_suspend,
1601 .resume = soc15_common_resume,
1602 .is_idle = soc15_common_is_idle,
1603 .wait_for_idle = soc15_common_wait_for_idle,
1604 .soft_reset = soc15_common_soft_reset,
1605 .set_clockgating_state = soc15_common_set_clockgating_state,
1606 .set_powergating_state = soc15_common_set_powergating_state,
1607 .get_clockgating_state= soc15_common_get_clockgating_state,