From: Andre Eikmeyer <[email protected]> As mentioned previous any access to the GPU when the GMUX has shut off the rails results in a CPU CATTER, skip and report any register access after the GPU was runtime suspended for GMUX power-off.
Tested-by: Sebastian Zygadlo <[email protected]> Tested-by: Yossef Osman <[email protected]> Signed-off-by: Andre Eikmeyer <[email protected]> Signed-off-by: Atharva Tiwari <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 ++++ .../gpu/drm/amd/amdgpu/amdgpu_reg_access.c | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 6fd607587..9938ae48f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -881,6 +881,7 @@ struct amdgpu_device { /* enable runtime pm on the device */ bool in_runpm; bool has_pr3; + bool runpm_active; bool ucode_sysfs_en; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index ac336594b..ed205352f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -947,6 +947,10 @@ bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev) if (adev->no_hw_access) return true; + if (unlikely(!READ_ONCE(adev->runpm_active))) { + WARN_RATELIMIT(1, "%s: register access while powered off\n", dev_name(adev->dev)); + return true; + } #ifdef CONFIG_LOCKDEP /* * This is a bit complicated to understand, so worth a comment. What we assert @@ -2029,6 +2033,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) int i, r; amdgpu_device_enable_virtual_display(adev); + adev->runpm_active = true; if (amdgpu_sriov_vf(adev)) { /* diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 3978ed284..d1b0c6c73 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2935,6 +2935,9 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev) amdgpu_device_baco_enter(adev); } + if (adev->pm.rpm_mode == AMDGPU_RUNPM_GMUX) + WRITE_ONCE(adev->runpm_active, false); + dev_dbg(&pdev->dev, "asic/device is runtime suspended\n"); return 0; @@ -2963,6 +2966,8 @@ static int amdgpu_pmops_runtime_resume(struct device *dev) if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) return -EINVAL; + WRITE_ONCE(adev->runpm_active, true); + /* Avoids registers access if device is physically gone */ if (!pci_device_is_present(adev->pdev)) adev->no_hw_access = true; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_reg_access.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_reg_access.c index 7468855c1..64eba8a97 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_reg_access.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_reg_access.c @@ -594,6 +594,9 @@ u32 amdgpu_device_indirect_rreg(struct amdgpu_device *adev, u32 reg_addr) void __iomem *pcie_data_offset; u32 r; + if (amdgpu_device_skip_hw_access(adev)) + return 0; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); @@ -617,6 +620,9 @@ u32 amdgpu_device_indirect_rreg_ext(struct amdgpu_device *adev, u64 reg_addr) void __iomem *pcie_index_hi_offset; void __iomem *pcie_data_offset; + if (amdgpu_device_skip_hw_access(adev)) + return 0; + if (unlikely(!adev->nbio.funcs)) { pcie_index = AMDGPU_PCIE_INDEX_FALLBACK; pcie_data = AMDGPU_PCIE_DATA_FALLBACK; @@ -677,6 +683,9 @@ u64 amdgpu_device_indirect_rreg64(struct amdgpu_device *adev, u32 reg_addr) void __iomem *pcie_data_offset; u64 r; + if (amdgpu_device_skip_hw_access(adev)) + return 0; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); @@ -706,6 +715,9 @@ u64 amdgpu_device_indirect_rreg64_ext(struct amdgpu_device *adev, u64 reg_addr) void __iomem *pcie_data_offset; u64 r; + if (amdgpu_device_skip_hw_access(adev)) + return 0; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); if ((reg_addr >> 32) && (adev->nbio.funcs->get_pcie_index_hi_offset)) @@ -762,6 +774,9 @@ void amdgpu_device_indirect_wreg(struct amdgpu_device *adev, u32 reg_addr, void __iomem *pcie_index_offset; void __iomem *pcie_data_offset; + if (amdgpu_device_skip_hw_access(adev)) + return; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); @@ -784,6 +799,9 @@ void amdgpu_device_indirect_wreg_ext(struct amdgpu_device *adev, u64 reg_addr, void __iomem *pcie_index_hi_offset; void __iomem *pcie_data_offset; + if (amdgpu_device_skip_hw_access(adev)) + return; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); if ((reg_addr >> 32) && (adev->nbio.funcs->get_pcie_index_hi_offset)) @@ -832,6 +850,9 @@ void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev, u32 reg_addr, void __iomem *pcie_index_offset; void __iomem *pcie_data_offset; + if (amdgpu_device_skip_hw_access(adev)) + return; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); @@ -861,6 +882,9 @@ void amdgpu_device_indirect_wreg64_ext(struct amdgpu_device *adev, u64 reg_addr, void __iomem *pcie_index_hi_offset; void __iomem *pcie_data_offset; + if (amdgpu_device_skip_hw_access(adev)) + return; + pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev); pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev); if ((reg_addr >> 32) && (adev->nbio.funcs->get_pcie_index_hi_offset)) -- 2.55.0
