[PATCH v2 20/28] coresight: cti: Properly handle modes in CPU PM notifiers

From: Leo Yan
Date: Tue Jul 01 2025 - 10:58:45 EST


This commit distinguishes CPU PM flows based on the mode.

The CTI driver retains its existing behavior for the CS_MODE_DEBUG mode.

For modes other than DEBUG, a future change will be made to manage CTI
devices by iterating through the CoreSight path in the core layer. To
avoid conflicts, the CTI driver no longer controls CTI hardware in CPU
PM notifiers for non DEBUG modes.

However, the CTI driver continues to update the hw_powered flag for all
modes to reflect the device's power state.

Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
---
drivers/hwtracing/coresight/coresight-cti-core.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti-core.c b/drivers/hwtracing/coresight/coresight-cti-core.c
index ba4635dfc2e30b4e9ae4972f91bdc6647975b719..c91d339d7ccbf71db71cb7156f9a6f2961ae2198 100644
--- a/drivers/hwtracing/coresight/coresight-cti-core.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -141,6 +141,9 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
raw_spin_lock(&drvdata->spinlock);
config->hw_powered = true;

+ if (coresight_get_mode(drvdata->csdev) != CS_MODE_DEBUG)
+ goto cti_hp_not_enabled;
+
/* no need to do anything if no enable request */
if (!drvdata->config.enable_req_count)
goto cti_hp_not_enabled;
@@ -697,21 +700,27 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
case CPU_PM_ENTER:
/* CTI regs all static - we have a copy & nothing to save */
drvdata->config.hw_powered = false;
- if (drvdata->config.hw_enabled)
+ if ((coresight_get_mode(drvdata->csdev) == CS_MODE_DEBUG) &&
+ drvdata->config.hw_enabled)
coresight_disclaim_device(csdev);
break;

case CPU_PM_ENTER_FAILED:
drvdata->config.hw_powered = true;
- if (drvdata->config.hw_enabled) {
+ if ((coresight_get_mode(drvdata->csdev) == CS_MODE_DEBUG) &&
+ drvdata->config.hw_enabled) {
if (coresight_claim_device(csdev))
drvdata->config.hw_enabled = false;
}
break;

case CPU_PM_EXIT:
- /* write hardware registers to re-enable. */
drvdata->config.hw_powered = true;
+
+ if (coresight_get_mode(drvdata->csdev) != CS_MODE_DEBUG)
+ break;
+
+ /* write hardware registers to re-enable. */
drvdata->config.hw_enabled = false;

/* check enable reference count to enable HW */
@@ -760,7 +769,8 @@ static int cti_dying_cpu(unsigned int cpu)

raw_spin_lock(&drvdata->spinlock);
drvdata->config.hw_powered = false;
- if (drvdata->config.hw_enabled)
+ if ((coresight_get_mode(drvdata->csdev) == CS_MODE_DEBUG) &&
+ drvdata->config.hw_enabled)
coresight_disclaim_device(drvdata->csdev);
raw_spin_unlock(&drvdata->spinlock);
return 0;

--
2.34.1