[PATCH v10 4/8] coresight: etr: refactor the tmc_etr_get_catu_device function

Jie Gan posted 8 patches 2 weeks, 4 days ago
There is a newer version of this series
[PATCH v10 4/8] coresight: etr: refactor the tmc_etr_get_catu_device function
Posted by Jie Gan 2 weeks, 4 days ago
Refactor tmc_etr_get_catu_device to retrieve the helper device connected
to the TMC ETR based on helper_subtype.

Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
 drivers/hwtracing/coresight/coresight-catu.c    |  3 ++-
 drivers/hwtracing/coresight/coresight-tmc-etr.c | 32 ++++++++++++++++---------
 drivers/hwtracing/coresight/coresight-tmc.h     |  3 ++-
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
index 69b36bae97ab..d3972619cc96 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -334,7 +334,8 @@ static int catu_alloc_etr_buf(struct tmc_drvdata *tmc_drvdata,
 	struct tmc_sg_table *catu_table;
 	struct catu_etr_buf *catu_buf;
 
-	csdev = tmc_etr_get_catu_device(tmc_drvdata);
+	csdev = tmc_etr_get_helper_device(tmc_drvdata,
+			CORESIGHT_DEV_SUBTYPE_HELPER_CATU);
 	if (!csdev)
 		return -ENODEV;
 	catu_buf = kzalloc(sizeof(*catu_buf), GFP_KERNEL);
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index cbbb15648fb7..16a4562533d5 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -844,28 +844,37 @@ static const struct etr_buf_operations etr_sg_buf_ops = {
 };
 
 /*
- * TMC ETR could be connected to a CATU device, which can provide address
- * translation service. This is represented by the Output port of the TMC
- * (ETR) connected to the input port of the CATU.
+ * TMC ETR could be connected to the helper device, which can provide address
+ * translation service(CATU) or data filter function(CTCU). This is represented
+ * by the Output port of the TMC (ETR) connected to the input port of the helper.
  *
- * Returns	: coresight_device ptr for the CATU device if a CATU is found.
+ * @drvdata	: drvdata of the TMC device
+ * @subtype	: helper_subtype of the helper device
+ *
+ * Returns	: coresight_device ptr for the helper device if a helper is found.
  *		: NULL otherwise.
  */
 struct coresight_device *
-tmc_etr_get_catu_device(struct tmc_drvdata *drvdata)
+tmc_etr_get_helper_device(struct tmc_drvdata *drvdata,
+			  enum coresight_dev_subtype_helper subtype)
 {
 	struct coresight_device *etr = drvdata->csdev;
-	union coresight_dev_subtype catu_subtype = {
-		.helper_subtype = CORESIGHT_DEV_SUBTYPE_HELPER_CATU
+	union coresight_dev_subtype helper_subtype = {
+		.helper_subtype = subtype
 	};
 
-	if (!IS_ENABLED(CONFIG_CORESIGHT_CATU))
+
+	if (subtype == CORESIGHT_DEV_SUBTYPE_HELPER_CATU &&
+	    !IS_ENABLED(CONFIG_CORESIGHT_CATU))
+		return NULL;
+	else if (subtype == CORESIGHT_DEV_SUBTYPE_HELPER_CTCU &&
+		 !IS_ENABLED(CONFIG_CORESIGHT_CTCU))
 		return NULL;
 
 	return coresight_find_output_type(etr->pdata, CORESIGHT_DEV_TYPE_HELPER,
-					  catu_subtype);
+					  helper_subtype);
 }
-EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device);
+EXPORT_SYMBOL_GPL(tmc_etr_get_helper_device);
 
 static const struct etr_buf_operations *etr_buf_ops[] = {
 	[ETR_MODE_FLAT] = &etr_flat_buf_ops,
@@ -913,7 +922,8 @@ static void get_etr_buf_hw(struct device *dev, struct etr_buf_hw *buf_hw)
 
 	buf_hw->has_iommu = iommu_get_domain_for_dev(dev->parent);
 	buf_hw->has_etr_sg = tmc_etr_has_cap(drvdata, TMC_ETR_SG);
-	buf_hw->has_catu = !!tmc_etr_get_catu_device(drvdata);
+	buf_hw->has_catu = !!tmc_etr_get_helper_device(drvdata,
+			CORESIGHT_DEV_SUBTYPE_HELPER_CATU);
 	buf_hw->has_resrv = tmc_has_reserved_buffer(drvdata);
 }
 
diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
index c9a82ff6cd00..7690a70069da 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -471,7 +471,8 @@ static inline uint32_t find_crash_tracedata_crc(struct tmc_drvdata *drvdata,
 	return crc32_le(0, (void *)drvdata->resrv_buf.vaddr, crc_size);
 }
 
-struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
+struct coresight_device *tmc_etr_get_helper_device(struct tmc_drvdata *drvdata,
+						   enum coresight_dev_subtype_helper subtype);
 
 void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
 void tmc_etr_remove_catu_ops(void);

-- 
2.34.1
Re: [PATCH v10 4/8] coresight: etr: refactor the tmc_etr_get_catu_device function
Posted by Suzuki K Poulose 2 weeks ago
On 22/01/2026 02:08, Jie Gan wrote:
> Refactor tmc_etr_get_catu_device to retrieve the helper device connected
> to the TMC ETR based on helper_subtype.

Please could you leave this as it is and add :

tmc_etr_get_ctcu_device() ?

It doesn't make much sense to refactor something that is a wrapper for
a generic function. Please avoid un-necessary abstraction

Suzuki


> 
> Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
> ---
>   drivers/hwtracing/coresight/coresight-catu.c    |  3 ++-
>   drivers/hwtracing/coresight/coresight-tmc-etr.c | 32 ++++++++++++++++---------
>   drivers/hwtracing/coresight/coresight-tmc.h     |  3 ++-
>   3 files changed, 25 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
> index 69b36bae97ab..d3972619cc96 100644
> --- a/drivers/hwtracing/coresight/coresight-catu.c
> +++ b/drivers/hwtracing/coresight/coresight-catu.c
> @@ -334,7 +334,8 @@ static int catu_alloc_etr_buf(struct tmc_drvdata *tmc_drvdata,
>   	struct tmc_sg_table *catu_table;
>   	struct catu_etr_buf *catu_buf;
>   
> -	csdev = tmc_etr_get_catu_device(tmc_drvdata);
> +	csdev = tmc_etr_get_helper_device(tmc_drvdata,
> +			CORESIGHT_DEV_SUBTYPE_HELPER_CATU);
>   	if (!csdev)
>   		return -ENODEV;
>   	catu_buf = kzalloc(sizeof(*catu_buf), GFP_KERNEL);
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> index cbbb15648fb7..16a4562533d5 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> @@ -844,28 +844,37 @@ static const struct etr_buf_operations etr_sg_buf_ops = {
>   };
>   
>   /*
> - * TMC ETR could be connected to a CATU device, which can provide address
> - * translation service. This is represented by the Output port of the TMC
> - * (ETR) connected to the input port of the CATU.
> + * TMC ETR could be connected to the helper device, which can provide address
> + * translation service(CATU) or data filter function(CTCU). This is represented
> + * by the Output port of the TMC (ETR) connected to the input port of the helper.
>    *
> - * Returns	: coresight_device ptr for the CATU device if a CATU is found.
> + * @drvdata	: drvdata of the TMC device
> + * @subtype	: helper_subtype of the helper device
> + *
> + * Returns	: coresight_device ptr for the helper device if a helper is found.
>    *		: NULL otherwise.
>    */
>   struct coresight_device *
> -tmc_etr_get_catu_device(struct tmc_drvdata *drvdata)
> +tmc_etr_get_helper_device(struct tmc_drvdata *drvdata,
> +			  enum coresight_dev_subtype_helper subtype)
>   {
>   	struct coresight_device *etr = drvdata->csdev;
> -	union coresight_dev_subtype catu_subtype = {
> -		.helper_subtype = CORESIGHT_DEV_SUBTYPE_HELPER_CATU
> +	union coresight_dev_subtype helper_subtype = {
> +		.helper_subtype = subtype
>   	};
>   
> -	if (!IS_ENABLED(CONFIG_CORESIGHT_CATU))
> +
> +	if (subtype == CORESIGHT_DEV_SUBTYPE_HELPER_CATU &&
> +	    !IS_ENABLED(CONFIG_CORESIGHT_CATU))
> +		return NULL;
> +	else if (subtype == CORESIGHT_DEV_SUBTYPE_HELPER_CTCU &&
> +		 !IS_ENABLED(CONFIG_CORESIGHT_CTCU))
>   		return NULL;
>   
>   	return coresight_find_output_type(etr->pdata, CORESIGHT_DEV_TYPE_HELPER,
> -					  catu_subtype);
> +					  helper_subtype);
>   }
> -EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device);
> +EXPORT_SYMBOL_GPL(tmc_etr_get_helper_device);
>   
>   static const struct etr_buf_operations *etr_buf_ops[] = {
>   	[ETR_MODE_FLAT] = &etr_flat_buf_ops,
> @@ -913,7 +922,8 @@ static void get_etr_buf_hw(struct device *dev, struct etr_buf_hw *buf_hw)
>   
>   	buf_hw->has_iommu = iommu_get_domain_for_dev(dev->parent);
>   	buf_hw->has_etr_sg = tmc_etr_has_cap(drvdata, TMC_ETR_SG);
> -	buf_hw->has_catu = !!tmc_etr_get_catu_device(drvdata);
> +	buf_hw->has_catu = !!tmc_etr_get_helper_device(drvdata,
> +			CORESIGHT_DEV_SUBTYPE_HELPER_CATU);
>   	buf_hw->has_resrv = tmc_has_reserved_buffer(drvdata);
>   }
>   
> diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
> index c9a82ff6cd00..7690a70069da 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc.h
> +++ b/drivers/hwtracing/coresight/coresight-tmc.h
> @@ -471,7 +471,8 @@ static inline uint32_t find_crash_tracedata_crc(struct tmc_drvdata *drvdata,
>   	return crc32_le(0, (void *)drvdata->resrv_buf.vaddr, crc_size);
>   }
>   
> -struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
> +struct coresight_device *tmc_etr_get_helper_device(struct tmc_drvdata *drvdata,
> +						   enum coresight_dev_subtype_helper subtype);
>   
>   void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
>   void tmc_etr_remove_catu_ops(void);
>
Re: [PATCH v10 4/8] coresight: etr: refactor the tmc_etr_get_catu_device function
Posted by Jie Gan 1 week, 6 days ago

On 1/27/2026 12:10 AM, Suzuki K Poulose wrote:
> On 22/01/2026 02:08, Jie Gan wrote:
>> Refactor tmc_etr_get_catu_device to retrieve the helper device connected
>> to the TMC ETR based on helper_subtype.
> 
> Please could you leave this as it is and add :
> 
> tmc_etr_get_ctcu_device() ?
> 
> It doesn't make much sense to refactor something that is a wrapper for
> a generic function. Please avoid un-necessary abstraction

Well noted. Will fix it in the next version.

Thanks,
Jie

> 
> Suzuki
> 
> 
>>
>> Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
>> ---
>>   drivers/hwtracing/coresight/coresight-catu.c    |  3 ++-
>>   drivers/hwtracing/coresight/coresight-tmc-etr.c | 32 +++++++++++++++ 
>> +---------
>>   drivers/hwtracing/coresight/coresight-tmc.h     |  3 ++-
>>   3 files changed, 25 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/ 
>> hwtracing/coresight/coresight-catu.c
>> index 69b36bae97ab..d3972619cc96 100644
>> --- a/drivers/hwtracing/coresight/coresight-catu.c
>> +++ b/drivers/hwtracing/coresight/coresight-catu.c
>> @@ -334,7 +334,8 @@ static int catu_alloc_etr_buf(struct tmc_drvdata 
>> *tmc_drvdata,
>>       struct tmc_sg_table *catu_table;
>>       struct catu_etr_buf *catu_buf;
>> -    csdev = tmc_etr_get_catu_device(tmc_drvdata);
>> +    csdev = tmc_etr_get_helper_device(tmc_drvdata,
>> +            CORESIGHT_DEV_SUBTYPE_HELPER_CATU);
>>       if (!csdev)
>>           return -ENODEV;
>>       catu_buf = kzalloc(sizeof(*catu_buf), GFP_KERNEL);
>> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/ 
>> drivers/hwtracing/coresight/coresight-tmc-etr.c
>> index cbbb15648fb7..16a4562533d5 100644
>> --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
>> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
>> @@ -844,28 +844,37 @@ static const struct etr_buf_operations 
>> etr_sg_buf_ops = {
>>   };
>>   /*
>> - * TMC ETR could be connected to a CATU device, which can provide 
>> address
>> - * translation service. This is represented by the Output port of the 
>> TMC
>> - * (ETR) connected to the input port of the CATU.
>> + * TMC ETR could be connected to the helper device, which can provide 
>> address
>> + * translation service(CATU) or data filter function(CTCU). This is 
>> represented
>> + * by the Output port of the TMC (ETR) connected to the input port of 
>> the helper.
>>    *
>> - * Returns    : coresight_device ptr for the CATU device if a CATU is 
>> found.
>> + * @drvdata    : drvdata of the TMC device
>> + * @subtype    : helper_subtype of the helper device
>> + *
>> + * Returns    : coresight_device ptr for the helper device if a 
>> helper is found.
>>    *        : NULL otherwise.
>>    */
>>   struct coresight_device *
>> -tmc_etr_get_catu_device(struct tmc_drvdata *drvdata)
>> +tmc_etr_get_helper_device(struct tmc_drvdata *drvdata,
>> +              enum coresight_dev_subtype_helper subtype)
>>   {
>>       struct coresight_device *etr = drvdata->csdev;
>> -    union coresight_dev_subtype catu_subtype = {
>> -        .helper_subtype = CORESIGHT_DEV_SUBTYPE_HELPER_CATU
>> +    union coresight_dev_subtype helper_subtype = {
>> +        .helper_subtype = subtype
>>       };
>> -    if (!IS_ENABLED(CONFIG_CORESIGHT_CATU))
>> +
>> +    if (subtype == CORESIGHT_DEV_SUBTYPE_HELPER_CATU &&
>> +        !IS_ENABLED(CONFIG_CORESIGHT_CATU))
>> +        return NULL;
>> +    else if (subtype == CORESIGHT_DEV_SUBTYPE_HELPER_CTCU &&
>> +         !IS_ENABLED(CONFIG_CORESIGHT_CTCU))
>>           return NULL;
>>       return coresight_find_output_type(etr->pdata, 
>> CORESIGHT_DEV_TYPE_HELPER,
>> -                      catu_subtype);
>> +                      helper_subtype);
>>   }
>> -EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device);
>> +EXPORT_SYMBOL_GPL(tmc_etr_get_helper_device);
>>   static const struct etr_buf_operations *etr_buf_ops[] = {
>>       [ETR_MODE_FLAT] = &etr_flat_buf_ops,
>> @@ -913,7 +922,8 @@ static void get_etr_buf_hw(struct device *dev, 
>> struct etr_buf_hw *buf_hw)
>>       buf_hw->has_iommu = iommu_get_domain_for_dev(dev->parent);
>>       buf_hw->has_etr_sg = tmc_etr_has_cap(drvdata, TMC_ETR_SG);
>> -    buf_hw->has_catu = !!tmc_etr_get_catu_device(drvdata);
>> +    buf_hw->has_catu = !!tmc_etr_get_helper_device(drvdata,
>> +            CORESIGHT_DEV_SUBTYPE_HELPER_CATU);
>>       buf_hw->has_resrv = tmc_has_reserved_buffer(drvdata);
>>   }
>> diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/ 
>> hwtracing/coresight/coresight-tmc.h
>> index c9a82ff6cd00..7690a70069da 100644
>> --- a/drivers/hwtracing/coresight/coresight-tmc.h
>> +++ b/drivers/hwtracing/coresight/coresight-tmc.h
>> @@ -471,7 +471,8 @@ static inline uint32_t 
>> find_crash_tracedata_crc(struct tmc_drvdata *drvdata,
>>       return crc32_le(0, (void *)drvdata->resrv_buf.vaddr, crc_size);
>>   }
>> -struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata 
>> *drvdata);
>> +struct coresight_device *tmc_etr_get_helper_device(struct tmc_drvdata 
>> *drvdata,
>> +                           enum coresight_dev_subtype_helper subtype);
>>   void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
>>   void tmc_etr_remove_catu_ops(void);
>>
>