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 "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"
54 #include "soc15_common.h"
57 #include "gfxhub_v1_0.h"
58 #include "mmhub_v1_0.h"
61 #include "vega10_ih.h"
62 #include "sdma_v4_0.h"
66 #include "dce_virtual.h"
68 #include "amdgpu_smu.h"
69 #include "amdgpu_ras.h"
70 #include "amdgpu_xgmi.h"
71 #include <uapi/linux/kfd_ioctl.h>
73 #define mmMP0_MISC_CGTT_CTRL0 0x01b9
74 #define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
75 #define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
76 #define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
78 /* for Vega20 register name change */
79 #define mmHDP_MEM_POWER_CTRL 0x00d4
80 #define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK 0x00000001L
81 #define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK 0x00000002L
82 #define HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK 0x00010000L
83 #define HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK 0x00020000L
84 #define mmHDP_MEM_POWER_CTRL_BASE_IDX 0
86 * Indirect registers accessor
88 static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
90 unsigned long flags, address, data;
92 address = adev->nbio_funcs->get_pcie_index_offset(adev);
93 data = adev->nbio_funcs->get_pcie_data_offset(adev);
95 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
97 (void)RREG32(address);
99 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
103 static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
105 unsigned long flags, address, data;
107 address = adev->nbio_funcs->get_pcie_index_offset(adev);
108 data = adev->nbio_funcs->get_pcie_data_offset(adev);
110 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
111 WREG32(address, reg);
112 (void)RREG32(address);
115 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
118 static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
120 unsigned long flags, address, data;
123 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
124 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
126 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
127 WREG32(address, ((reg) & 0x1ff));
129 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
133 static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
135 unsigned long flags, address, data;
137 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
138 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
140 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
141 WREG32(address, ((reg) & 0x1ff));
143 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
146 static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
148 unsigned long flags, address, data;
151 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
152 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
154 spin_lock_irqsave(&adev->didt_idx_lock, flags);
155 WREG32(address, (reg));
157 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
161 static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
163 unsigned long flags, address, data;
165 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
166 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
168 spin_lock_irqsave(&adev->didt_idx_lock, flags);
169 WREG32(address, (reg));
171 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
174 static u32 soc15_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
179 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
180 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
181 r = RREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA);
182 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
186 static void soc15_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
190 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
191 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
192 WREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA, (v));
193 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
196 static u32 soc15_se_cac_rreg(struct amdgpu_device *adev, u32 reg)
201 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
202 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
203 r = RREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA);
204 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
208 static void soc15_se_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
212 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
213 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
214 WREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA, (v));
215 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
218 static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
220 return adev->nbio_funcs->get_memsize(adev);
223 static u32 soc15_get_xclk(struct amdgpu_device *adev)
225 return adev->clock.spll.reference_freq;
229 void soc15_grbm_select(struct amdgpu_device *adev,
230 u32 me, u32 pipe, u32 queue, u32 vmid)
232 u32 grbm_gfx_cntl = 0;
233 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
234 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
235 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
236 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
238 WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
241 static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
246 static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
252 static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
253 u8 *bios, u32 length_bytes)
260 if (length_bytes == 0)
262 /* APU vbios image is part of sbios image */
263 if (adev->flags & AMD_IS_APU)
266 dw_ptr = (u32 *)bios;
267 length_dw = ALIGN(length_bytes, 4) / 4;
269 /* set rom index to 0 */
270 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
271 /* read out the rom data */
272 for (i = 0; i < length_dw; i++)
273 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
278 static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {
279 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
280 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
281 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
282 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
283 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
284 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
285 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
286 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
287 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
288 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
289 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
290 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
291 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
292 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
293 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
294 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
295 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
296 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
297 { SOC15_REG_ENTRY(GC, 0, mmDB_DEBUG2)},
300 static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
301 u32 sh_num, u32 reg_offset)
305 mutex_lock(&adev->grbm_idx_mutex);
306 if (se_num != 0xffffffff || sh_num != 0xffffffff)
307 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
309 val = RREG32(reg_offset);
311 if (se_num != 0xffffffff || sh_num != 0xffffffff)
312 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
313 mutex_unlock(&adev->grbm_idx_mutex);
317 static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
318 bool indexed, u32 se_num,
319 u32 sh_num, u32 reg_offset)
322 return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
324 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
325 return adev->gfx.config.gb_addr_config;
326 else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
327 return adev->gfx.config.db_debug2;
328 return RREG32(reg_offset);
332 static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
333 u32 sh_num, u32 reg_offset, u32 *value)
336 struct soc15_allowed_register_entry *en;
339 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
340 en = &soc15_allowed_read_registers[i];
341 if (reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
345 *value = soc15_get_register_value(adev,
346 soc15_allowed_read_registers[i].grbm_indexed,
347 se_num, sh_num, reg_offset);
355 * soc15_program_register_sequence - program an array of registers.
357 * @adev: amdgpu_device pointer
358 * @regs: pointer to the register array
359 * @array_size: size of the register array
361 * Programs an array or registers with and and or masks.
362 * This is a helper for setting golden registers.
365 void soc15_program_register_sequence(struct amdgpu_device *adev,
366 const struct soc15_reg_golden *regs,
367 const u32 array_size)
369 const struct soc15_reg_golden *entry;
373 for (i = 0; i < array_size; ++i) {
375 reg = adev->reg_offset[entry->hwip][entry->instance][entry->segment] + entry->reg;
377 if (entry->and_mask == 0xffffffff) {
378 tmp = entry->or_mask;
381 tmp &= ~(entry->and_mask);
382 tmp |= (entry->or_mask & entry->and_mask);
385 if (reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_BINNER_EVENT_CNTL_3) ||
386 reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE) ||
387 reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE_1) ||
388 reg == SOC15_REG_OFFSET(GC, 0, mmSH_MEM_CONFIG))
389 WREG32_RLC(reg, tmp);
397 static int soc15_asic_mode1_reset(struct amdgpu_device *adev)
402 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
404 dev_info(adev->dev, "GPU mode1 reset\n");
407 pci_clear_master(adev->pdev);
409 pci_save_state(adev->pdev);
411 ret = psp_gpu_reset(adev);
413 dev_err(adev->dev, "GPU mode1 reset failed\n");
415 pci_restore_state(adev->pdev);
417 /* wait for asic to come out of reset */
418 for (i = 0; i < adev->usec_timeout; i++) {
419 u32 memsize = adev->nbio_funcs->get_memsize(adev);
421 if (memsize != 0xffffffff)
426 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
431 static int soc15_asic_get_baco_capability(struct amdgpu_device *adev, bool *cap)
433 void *pp_handle = adev->powerplay.pp_handle;
434 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
436 if (!pp_funcs || !pp_funcs->get_asic_baco_capability) {
441 return pp_funcs->get_asic_baco_capability(pp_handle, cap);
444 static int soc15_asic_baco_reset(struct amdgpu_device *adev)
446 void *pp_handle = adev->powerplay.pp_handle;
447 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
449 if (!pp_funcs ||!pp_funcs->get_asic_baco_state ||!pp_funcs->set_asic_baco_state)
452 /* enter BACO state */
453 if (pp_funcs->set_asic_baco_state(pp_handle, 1))
456 /* exit BACO state */
457 if (pp_funcs->set_asic_baco_state(pp_handle, 0))
460 dev_info(adev->dev, "GPU BACO reset\n");
462 adev->in_baco_reset = 1;
467 static int soc15_asic_reset(struct amdgpu_device *adev)
472 switch (adev->asic_type) {
475 soc15_asic_get_baco_capability(adev, &baco_reset);
478 if (adev->psp.sos_fw_version >= 0x80067)
479 soc15_asic_get_baco_capability(adev, &baco_reset);
483 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0);
484 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
486 if (hive || (ras && ras->supported))
496 ret = soc15_asic_baco_reset(adev);
498 ret = soc15_asic_mode1_reset(adev);
503 /*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
504 u32 cntl_reg, u32 status_reg)
509 static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
513 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
517 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
522 static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
529 static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
531 if (pci_is_root_bus(adev->pdev->bus))
534 if (amdgpu_pcie_gen2 == 0)
537 if (adev->flags & AMD_IS_APU)
540 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
541 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
547 static void soc15_program_aspm(struct amdgpu_device *adev)
550 if (amdgpu_aspm == 0)
556 static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
559 adev->nbio_funcs->enable_doorbell_aperture(adev, enable);
560 adev->nbio_funcs->enable_doorbell_selfring_aperture(adev, enable);
563 static const struct amdgpu_ip_block_version vega10_common_ip_block =
565 .type = AMD_IP_BLOCK_TYPE_COMMON,
569 .funcs = &soc15_common_ip_funcs,
572 static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
574 return adev->nbio_funcs->get_rev_id(adev);
577 int soc15_set_ip_blocks(struct amdgpu_device *adev)
579 /* Set IP register base before any HW register access */
580 switch (adev->asic_type) {
584 vega10_reg_base_init(adev);
587 vega20_reg_base_init(adev);
593 if (adev->asic_type == CHIP_VEGA20)
594 adev->gmc.xgmi.supported = true;
596 if (adev->flags & AMD_IS_APU)
597 adev->nbio_funcs = &nbio_v7_0_funcs;
598 else if (adev->asic_type == CHIP_VEGA20)
599 adev->nbio_funcs = &nbio_v7_4_funcs;
601 adev->nbio_funcs = &nbio_v6_1_funcs;
603 if (adev->asic_type == CHIP_VEGA20)
604 adev->df_funcs = &df_v3_6_funcs;
606 adev->df_funcs = &df_v1_7_funcs;
608 adev->rev_id = soc15_get_rev_id(adev);
609 adev->nbio_funcs->detect_hw_virt(adev);
611 if (amdgpu_sriov_vf(adev))
612 adev->virt.ops = &xgpu_ai_virt_ops;
614 switch (adev->asic_type) {
618 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
619 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
621 /* For Vega10 SR-IOV, PSP need to be initialized before IH */
622 if (amdgpu_sriov_vf(adev)) {
623 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
624 if (adev->asic_type == CHIP_VEGA20)
625 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
627 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
629 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
631 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
632 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
633 if (adev->asic_type == CHIP_VEGA20)
634 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
636 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
639 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
640 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
641 if (!amdgpu_sriov_vf(adev)) {
642 if (is_support_sw_smu(adev))
643 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
645 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
647 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
648 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
649 #if defined(CONFIG_DRM_AMD_DC)
650 else if (amdgpu_device_has_dc_support(adev))
651 amdgpu_device_ip_block_add(adev, &dm_ip_block);
653 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) {
654 amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
655 amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
659 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
660 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
661 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
662 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
663 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
664 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
665 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
666 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
667 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
668 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
669 #if defined(CONFIG_DRM_AMD_DC)
670 else if (amdgpu_device_has_dc_support(adev))
671 amdgpu_device_ip_block_add(adev, &dm_ip_block);
673 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
682 static void soc15_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
684 adev->nbio_funcs->hdp_flush(adev, ring);
687 static void soc15_invalidate_hdp(struct amdgpu_device *adev,
688 struct amdgpu_ring *ring)
690 if (!ring || !ring->funcs->emit_wreg)
691 WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
693 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
694 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
697 static bool soc15_need_full_reset(struct amdgpu_device *adev)
699 /* change this when we implement soft reset */
702 static void soc15_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
705 uint32_t perfctr = 0;
706 uint64_t cnt0_of, cnt1_of;
709 /* This reports 0 on APUs, so return to avoid writing/reading registers
710 * that may or may not be different from their GPU counterparts
712 if (adev->flags & AMD_IS_APU)
715 /* Set the 2 events that we wish to watch, defined above */
716 /* Reg 40 is # received msgs */
717 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40);
718 /* Pre-VG20, Reg 104 is # of posted requests sent. On VG20 it's 108 */
719 if (adev->asic_type == CHIP_VEGA20)
720 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,
723 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,
726 /* Write to enable desired perf counters */
727 WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK, perfctr);
728 /* Zero out and enable the perf counters
730 * Bit 0 = Start all counters(1)
731 * Bit 2 = Global counter reset enable(1)
733 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
737 /* Load the shadow and disable the perf counters
739 * Bit 0 = Stop counters(0)
740 * Bit 1 = Load the shadow counters(1)
742 WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
744 /* Read register values to get any >32bit overflow */
745 tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK);
746 cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER);
747 cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER);
749 /* Get the values and add the overflow */
750 *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32);
751 *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
754 static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
758 /* Just return false for soc15 GPUs. Reset does not seem to
761 if (!amdgpu_passthrough(adev))
764 if (adev->flags & AMD_IS_APU)
767 /* Check sOS sign of life register to confirm sys driver and sOS
768 * are already been loaded.
770 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
777 static uint64_t soc15_get_pcie_replay_count(struct amdgpu_device *adev)
779 uint64_t nak_r, nak_g;
781 /* Get the number of NAKs received and generated */
782 nak_r = RREG32_PCIE(smnPCIE_RX_NUM_NAK);
783 nak_g = RREG32_PCIE(smnPCIE_RX_NUM_NAK_GENERATED);
785 /* Add the total number of NAKs, i.e the number of replays */
786 return (nak_r + nak_g);
789 static const struct amdgpu_asic_funcs soc15_asic_funcs =
791 .read_disabled_bios = &soc15_read_disabled_bios,
792 .read_bios_from_rom = &soc15_read_bios_from_rom,
793 .read_register = &soc15_read_register,
794 .reset = &soc15_asic_reset,
795 .set_vga_state = &soc15_vga_set_state,
796 .get_xclk = &soc15_get_xclk,
797 .set_uvd_clocks = &soc15_set_uvd_clocks,
798 .set_vce_clocks = &soc15_set_vce_clocks,
799 .get_config_memsize = &soc15_get_config_memsize,
800 .flush_hdp = &soc15_flush_hdp,
801 .invalidate_hdp = &soc15_invalidate_hdp,
802 .need_full_reset = &soc15_need_full_reset,
803 .init_doorbell_index = &vega10_doorbell_index_init,
804 .get_pcie_usage = &soc15_get_pcie_usage,
805 .need_reset_on_init = &soc15_need_reset_on_init,
806 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
809 static const struct amdgpu_asic_funcs vega20_asic_funcs =
811 .read_disabled_bios = &soc15_read_disabled_bios,
812 .read_bios_from_rom = &soc15_read_bios_from_rom,
813 .read_register = &soc15_read_register,
814 .reset = &soc15_asic_reset,
815 .set_vga_state = &soc15_vga_set_state,
816 .get_xclk = &soc15_get_xclk,
817 .set_uvd_clocks = &soc15_set_uvd_clocks,
818 .set_vce_clocks = &soc15_set_vce_clocks,
819 .get_config_memsize = &soc15_get_config_memsize,
820 .flush_hdp = &soc15_flush_hdp,
821 .invalidate_hdp = &soc15_invalidate_hdp,
822 .need_full_reset = &soc15_need_full_reset,
823 .init_doorbell_index = &vega20_doorbell_index_init,
824 .get_pcie_usage = &soc15_get_pcie_usage,
825 .need_reset_on_init = &soc15_need_reset_on_init,
826 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
829 static int soc15_common_early_init(void *handle)
831 #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
832 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
834 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
835 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
836 adev->smc_rreg = NULL;
837 adev->smc_wreg = NULL;
838 adev->pcie_rreg = &soc15_pcie_rreg;
839 adev->pcie_wreg = &soc15_pcie_wreg;
840 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
841 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
842 adev->didt_rreg = &soc15_didt_rreg;
843 adev->didt_wreg = &soc15_didt_wreg;
844 adev->gc_cac_rreg = &soc15_gc_cac_rreg;
845 adev->gc_cac_wreg = &soc15_gc_cac_wreg;
846 adev->se_cac_rreg = &soc15_se_cac_rreg;
847 adev->se_cac_wreg = &soc15_se_cac_wreg;
850 adev->external_rev_id = 0xFF;
851 switch (adev->asic_type) {
853 adev->asic_funcs = &soc15_asic_funcs;
854 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
855 AMD_CG_SUPPORT_GFX_MGLS |
856 AMD_CG_SUPPORT_GFX_RLC_LS |
857 AMD_CG_SUPPORT_GFX_CP_LS |
858 AMD_CG_SUPPORT_GFX_3D_CGCG |
859 AMD_CG_SUPPORT_GFX_3D_CGLS |
860 AMD_CG_SUPPORT_GFX_CGCG |
861 AMD_CG_SUPPORT_GFX_CGLS |
862 AMD_CG_SUPPORT_BIF_MGCG |
863 AMD_CG_SUPPORT_BIF_LS |
864 AMD_CG_SUPPORT_HDP_LS |
865 AMD_CG_SUPPORT_DRM_MGCG |
866 AMD_CG_SUPPORT_DRM_LS |
867 AMD_CG_SUPPORT_ROM_MGCG |
868 AMD_CG_SUPPORT_DF_MGCG |
869 AMD_CG_SUPPORT_SDMA_MGCG |
870 AMD_CG_SUPPORT_SDMA_LS |
871 AMD_CG_SUPPORT_MC_MGCG |
872 AMD_CG_SUPPORT_MC_LS;
874 adev->external_rev_id = 0x1;
877 adev->asic_funcs = &soc15_asic_funcs;
878 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
879 AMD_CG_SUPPORT_GFX_MGLS |
880 AMD_CG_SUPPORT_GFX_CGCG |
881 AMD_CG_SUPPORT_GFX_CGLS |
882 AMD_CG_SUPPORT_GFX_3D_CGCG |
883 AMD_CG_SUPPORT_GFX_3D_CGLS |
884 AMD_CG_SUPPORT_GFX_CP_LS |
885 AMD_CG_SUPPORT_MC_LS |
886 AMD_CG_SUPPORT_MC_MGCG |
887 AMD_CG_SUPPORT_SDMA_MGCG |
888 AMD_CG_SUPPORT_SDMA_LS |
889 AMD_CG_SUPPORT_BIF_MGCG |
890 AMD_CG_SUPPORT_BIF_LS |
891 AMD_CG_SUPPORT_HDP_MGCG |
892 AMD_CG_SUPPORT_HDP_LS |
893 AMD_CG_SUPPORT_ROM_MGCG |
894 AMD_CG_SUPPORT_VCE_MGCG |
895 AMD_CG_SUPPORT_UVD_MGCG;
897 adev->external_rev_id = adev->rev_id + 0x14;
900 adev->asic_funcs = &vega20_asic_funcs;
901 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
902 AMD_CG_SUPPORT_GFX_MGLS |
903 AMD_CG_SUPPORT_GFX_CGCG |
904 AMD_CG_SUPPORT_GFX_CGLS |
905 AMD_CG_SUPPORT_GFX_3D_CGCG |
906 AMD_CG_SUPPORT_GFX_3D_CGLS |
907 AMD_CG_SUPPORT_GFX_CP_LS |
908 AMD_CG_SUPPORT_MC_LS |
909 AMD_CG_SUPPORT_MC_MGCG |
910 AMD_CG_SUPPORT_SDMA_MGCG |
911 AMD_CG_SUPPORT_SDMA_LS |
912 AMD_CG_SUPPORT_BIF_MGCG |
913 AMD_CG_SUPPORT_BIF_LS |
914 AMD_CG_SUPPORT_HDP_MGCG |
915 AMD_CG_SUPPORT_HDP_LS |
916 AMD_CG_SUPPORT_ROM_MGCG |
917 AMD_CG_SUPPORT_VCE_MGCG |
918 AMD_CG_SUPPORT_UVD_MGCG;
920 adev->external_rev_id = adev->rev_id + 0x28;
923 adev->asic_funcs = &soc15_asic_funcs;
924 if (adev->rev_id >= 0x8)
925 adev->external_rev_id = adev->rev_id + 0x79;
926 else if (adev->pdev->device == 0x15d8)
927 adev->external_rev_id = adev->rev_id + 0x41;
928 else if (adev->rev_id == 1)
929 adev->external_rev_id = adev->rev_id + 0x20;
931 adev->external_rev_id = adev->rev_id + 0x01;
933 if (adev->rev_id >= 0x8) {
934 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
935 AMD_CG_SUPPORT_GFX_MGLS |
936 AMD_CG_SUPPORT_GFX_CP_LS |
937 AMD_CG_SUPPORT_GFX_3D_CGCG |
938 AMD_CG_SUPPORT_GFX_3D_CGLS |
939 AMD_CG_SUPPORT_GFX_CGCG |
940 AMD_CG_SUPPORT_GFX_CGLS |
941 AMD_CG_SUPPORT_BIF_LS |
942 AMD_CG_SUPPORT_HDP_LS |
943 AMD_CG_SUPPORT_ROM_MGCG |
944 AMD_CG_SUPPORT_MC_MGCG |
945 AMD_CG_SUPPORT_MC_LS |
946 AMD_CG_SUPPORT_SDMA_MGCG |
947 AMD_CG_SUPPORT_SDMA_LS |
948 AMD_CG_SUPPORT_VCN_MGCG;
950 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
951 } else if (adev->pdev->device == 0x15d8) {
952 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
953 AMD_CG_SUPPORT_GFX_MGLS |
954 AMD_CG_SUPPORT_GFX_CP_LS |
955 AMD_CG_SUPPORT_GFX_3D_CGCG |
956 AMD_CG_SUPPORT_GFX_3D_CGLS |
957 AMD_CG_SUPPORT_GFX_CGCG |
958 AMD_CG_SUPPORT_GFX_CGLS |
959 AMD_CG_SUPPORT_BIF_LS |
960 AMD_CG_SUPPORT_HDP_LS |
961 AMD_CG_SUPPORT_ROM_MGCG |
962 AMD_CG_SUPPORT_MC_MGCG |
963 AMD_CG_SUPPORT_MC_LS |
964 AMD_CG_SUPPORT_SDMA_MGCG |
965 AMD_CG_SUPPORT_SDMA_LS;
967 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
968 AMD_PG_SUPPORT_MMHUB |
970 AMD_PG_SUPPORT_VCN_DPG;
972 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
973 AMD_CG_SUPPORT_GFX_MGLS |
974 AMD_CG_SUPPORT_GFX_RLC_LS |
975 AMD_CG_SUPPORT_GFX_CP_LS |
976 AMD_CG_SUPPORT_GFX_3D_CGCG |
977 AMD_CG_SUPPORT_GFX_3D_CGLS |
978 AMD_CG_SUPPORT_GFX_CGCG |
979 AMD_CG_SUPPORT_GFX_CGLS |
980 AMD_CG_SUPPORT_BIF_MGCG |
981 AMD_CG_SUPPORT_BIF_LS |
982 AMD_CG_SUPPORT_HDP_MGCG |
983 AMD_CG_SUPPORT_HDP_LS |
984 AMD_CG_SUPPORT_DRM_MGCG |
985 AMD_CG_SUPPORT_DRM_LS |
986 AMD_CG_SUPPORT_ROM_MGCG |
987 AMD_CG_SUPPORT_MC_MGCG |
988 AMD_CG_SUPPORT_MC_LS |
989 AMD_CG_SUPPORT_SDMA_MGCG |
990 AMD_CG_SUPPORT_SDMA_LS |
991 AMD_CG_SUPPORT_VCN_MGCG;
993 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
996 if (adev->pm.pp_feature & PP_GFXOFF_MASK)
997 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
999 AMD_PG_SUPPORT_RLC_SMU_HS;
1002 /* FIXME: not supported yet */
1006 if (amdgpu_sriov_vf(adev)) {
1007 amdgpu_virt_init_setting(adev);
1008 xgpu_ai_mailbox_set_irq_funcs(adev);
1014 static int soc15_common_late_init(void *handle)
1016 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1018 if (amdgpu_sriov_vf(adev))
1019 xgpu_ai_mailbox_get_irq(adev);
1024 static int soc15_common_sw_init(void *handle)
1026 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1028 if (amdgpu_sriov_vf(adev))
1029 xgpu_ai_mailbox_add_irq_id(adev);
1031 adev->df_funcs->sw_init(adev);
1036 static int soc15_common_sw_fini(void *handle)
1041 static void soc15_doorbell_range_init(struct amdgpu_device *adev)
1044 struct amdgpu_ring *ring;
1046 /* Two reasons to skip
1047 * 1, Host driver already programmed them
1048 * 2, To avoid registers program violations in SR-IOV
1050 if (!amdgpu_virt_support_skip_setting(adev)) {
1051 for (i = 0; i < adev->sdma.num_instances; i++) {
1052 ring = &adev->sdma.instance[i].ring;
1053 adev->nbio_funcs->sdma_doorbell_range(adev, i,
1054 ring->use_doorbell, ring->doorbell_index,
1055 adev->doorbell_index.sdma_doorbell_range);
1059 adev->nbio_funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
1060 adev->irq.ih.doorbell_index);
1063 static int soc15_common_hw_init(void *handle)
1065 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1067 /* enable pcie gen2/3 link */
1068 soc15_pcie_gen3_enable(adev);
1070 soc15_program_aspm(adev);
1071 /* setup nbio registers */
1072 adev->nbio_funcs->init_registers(adev);
1073 /* remap HDP registers to a hole in mmio space,
1074 * for the purpose of expose those registers
1077 if (adev->nbio_funcs->remap_hdp_registers)
1078 adev->nbio_funcs->remap_hdp_registers(adev);
1080 /* enable the doorbell aperture */
1081 soc15_enable_doorbell_aperture(adev, true);
1082 /* HW doorbell routing policy: doorbell writing not
1083 * in SDMA/IH/MM/ACV range will be routed to CP. So
1084 * we need to init SDMA/IH/MM/ACV doorbell range prior
1085 * to CP ip block init and ring test.
1087 soc15_doorbell_range_init(adev);
1092 static int soc15_common_hw_fini(void *handle)
1094 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1096 /* disable the doorbell aperture */
1097 soc15_enable_doorbell_aperture(adev, false);
1098 if (amdgpu_sriov_vf(adev))
1099 xgpu_ai_mailbox_put_irq(adev);
1104 static int soc15_common_suspend(void *handle)
1106 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1108 return soc15_common_hw_fini(adev);
1111 static int soc15_common_resume(void *handle)
1113 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1115 return soc15_common_hw_init(adev);
1118 static bool soc15_common_is_idle(void *handle)
1123 static int soc15_common_wait_for_idle(void *handle)
1128 static int soc15_common_soft_reset(void *handle)
1133 static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
1137 if (adev->asic_type == CHIP_VEGA20) {
1138 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL));
1140 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1141 data |= HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1142 HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1143 HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1144 HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK;
1146 data &= ~(HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1147 HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1148 HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1149 HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK);
1152 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL), data);
1154 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1156 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1157 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1159 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1162 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
1166 static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
1170 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1172 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
1173 data &= ~(0x01000000 |
1182 data |= (0x01000000 |
1192 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
1195 static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
1199 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1201 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
1207 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
1210 static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1215 def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
1217 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
1218 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1219 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1221 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1222 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
1225 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
1228 static int soc15_common_set_clockgating_state(void *handle,
1229 enum amd_clockgating_state state)
1231 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1233 if (amdgpu_sriov_vf(adev))
1236 switch (adev->asic_type) {
1240 adev->nbio_funcs->update_medium_grain_clock_gating(adev,
1241 state == AMD_CG_STATE_GATE ? true : false);
1242 adev->nbio_funcs->update_medium_grain_light_sleep(adev,
1243 state == AMD_CG_STATE_GATE ? true : false);
1244 soc15_update_hdp_light_sleep(adev,
1245 state == AMD_CG_STATE_GATE ? true : false);
1246 soc15_update_drm_clock_gating(adev,
1247 state == AMD_CG_STATE_GATE ? true : false);
1248 soc15_update_drm_light_sleep(adev,
1249 state == AMD_CG_STATE_GATE ? true : false);
1250 soc15_update_rom_medium_grain_clock_gating(adev,
1251 state == AMD_CG_STATE_GATE ? true : false);
1252 adev->df_funcs->update_medium_grain_clock_gating(adev,
1253 state == AMD_CG_STATE_GATE ? true : false);
1256 adev->nbio_funcs->update_medium_grain_clock_gating(adev,
1257 state == AMD_CG_STATE_GATE ? true : false);
1258 adev->nbio_funcs->update_medium_grain_light_sleep(adev,
1259 state == AMD_CG_STATE_GATE ? true : false);
1260 soc15_update_hdp_light_sleep(adev,
1261 state == AMD_CG_STATE_GATE ? true : false);
1262 soc15_update_drm_clock_gating(adev,
1263 state == AMD_CG_STATE_GATE ? true : false);
1264 soc15_update_drm_light_sleep(adev,
1265 state == AMD_CG_STATE_GATE ? true : false);
1266 soc15_update_rom_medium_grain_clock_gating(adev,
1267 state == AMD_CG_STATE_GATE ? true : false);
1275 static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
1277 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1280 if (amdgpu_sriov_vf(adev))
1283 adev->nbio_funcs->get_clockgating_state(adev, flags);
1285 /* AMD_CG_SUPPORT_HDP_LS */
1286 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1287 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1288 *flags |= AMD_CG_SUPPORT_HDP_LS;
1290 /* AMD_CG_SUPPORT_DRM_MGCG */
1291 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1292 if (!(data & 0x01000000))
1293 *flags |= AMD_CG_SUPPORT_DRM_MGCG;
1295 /* AMD_CG_SUPPORT_DRM_LS */
1296 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1298 *flags |= AMD_CG_SUPPORT_DRM_LS;
1300 /* AMD_CG_SUPPORT_ROM_MGCG */
1301 data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
1302 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
1303 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
1305 adev->df_funcs->get_clockgating_state(adev, flags);
1308 static int soc15_common_set_powergating_state(void *handle,
1309 enum amd_powergating_state state)
1315 const struct amd_ip_funcs soc15_common_ip_funcs = {
1316 .name = "soc15_common",
1317 .early_init = soc15_common_early_init,
1318 .late_init = soc15_common_late_init,
1319 .sw_init = soc15_common_sw_init,
1320 .sw_fini = soc15_common_sw_fini,
1321 .hw_init = soc15_common_hw_init,
1322 .hw_fini = soc15_common_hw_fini,
1323 .suspend = soc15_common_suspend,
1324 .resume = soc15_common_resume,
1325 .is_idle = soc15_common_is_idle,
1326 .wait_for_idle = soc15_common_wait_for_idle,
1327 .soft_reset = soc15_common_soft_reset,
1328 .set_clockgating_state = soc15_common_set_clockgating_state,
1329 .set_powergating_state = soc15_common_set_powergating_state,
1330 .get_clockgating_state= soc15_common_get_clockgating_state,