--- drivers/platform/x86/amd-pmc.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) Index: linux-pm/drivers/platform/x86/amd-pmc.c =================================================================== --- linux-pm.orig/drivers/platform/x86/amd-pmc.c +++ linux-pm/drivers/platform/x86/amd-pmc.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,7 @@ static struct amd_pmc_dev pmc; static int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg, bool ret); static int amd_pmc_write_stb(struct amd_pmc_dev *dev, u32 data); static int amd_pmc_read_stb(struct amd_pmc_dev *dev, u32 *buf); +static struct pm_qos_request amd_pmc_pm_qos_req; static inline u32 amd_pmc_reg_read(struct amd_pmc_dev *dev, int reg_offset) { @@ -531,6 +533,14 @@ static int __maybe_unused amd_pmc_suspen u8 msg; u32 arg = 1; + /* + * Prevent CPUs from getting into idle states while running the code + * below which is generally safe to run when none of the CPUs are in + * idle states. + */ + cpu_latency_qos_update_request(&amd_pmc_pm_qos_req, 0); + wake_up_all_idle_cpus(); + /* Reset and Start SMU logging - to monitor the s0i3 stats */ amd_pmc_send_cmd(pdev, 0, NULL, SMU_MSG_LOG_RESET, 0); amd_pmc_send_cmd(pdev, 0, NULL, SMU_MSG_LOG_START, 0); @@ -539,7 +549,7 @@ static int __maybe_unused amd_pmc_suspen if (pdev->cpu_id == AMD_CPU_ID_CZN) { rc = amd_pmc_verify_czn_rtc(pdev, &arg); if (rc < 0) - return rc; + goto out; } /* Dump the IdleMask before we send hint to SMU */ @@ -551,10 +561,11 @@ static int __maybe_unused amd_pmc_suspen if (enable_stb) rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_PREDEF); - if (rc) { + if (rc) dev_err(pdev->dev, "error writing to STB\n"); - return rc; - } + +out: + cpu_latency_qos_update_request(&amd_pmc_pm_qos_req, PM_QOS_DEFAULT_VALUE); return rc; } @@ -565,6 +576,14 @@ static int __maybe_unused amd_pmc_resume int rc; u8 msg; + /* + * Prevent CPUs from getting into idle states while running the code + * below which is generally safe to run when none of the CPUs are in + * idle states. + */ + cpu_latency_qos_update_request(&amd_pmc_pm_qos_req, 0); + wake_up_all_idle_cpus(); + msg = amd_pmc_get_os_hint(pdev); rc = amd_pmc_send_cmd(pdev, 0, NULL, msg, 0); if (rc) @@ -579,12 +598,12 @@ static int __maybe_unused amd_pmc_resume /* Write data incremented by 1 to distinguish in stb_read */ if (enable_stb) rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_PREDEF + 1); - if (rc) { + if (rc) dev_err(pdev->dev, "error writing to STB\n"); - return rc; - } - return 0; + cpu_latency_qos_update_request(&amd_pmc_pm_qos_req, PM_QOS_DEFAULT_VALUE); + + return rc; } static const struct dev_pm_ops amd_pmc_pm_ops = { @@ -722,6 +741,7 @@ static int amd_pmc_probe(struct platform amd_pmc_get_smu_version(dev); platform_set_drvdata(pdev, dev); amd_pmc_dbgfs_register(dev); + cpu_latency_qos_add_request(&amd_pmc_pm_qos_req, PM_QOS_DEFAULT_VALUE); return 0; err_pci_dev_put: