[v4,17/30] coresight: Make device to CPU mapping generic
diff mbox series

Message ID 1558521304-27469-18-git-send-email-suzuki.poulose@arm.com
State New, archived
Headers show
Series
  • coresight: Support for ACPI bindings
Related show

Commit Message

Suzuki K Poulose May 22, 2019, 10:34 a.m. UTC
The CoreSight components ETM and CPU-Debug are always associated
with CPUs. Replace the of_coresight_get_cpu() with a platform
agnostic helper, in preparation to add ACPI support.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-cpu-debug.c |  3 +--
 drivers/hwtracing/coresight/coresight-platform.c  | 18 +++++++++++++-----
 include/linux/coresight.h                         |  7 +------
 3 files changed, 15 insertions(+), 13 deletions(-)

Comments

Mike Leach June 3, 2019, 10:07 a.m. UTC | #1
Hi,

On Wed, 22 May 2019 at 11:37, Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> The CoreSight components ETM and CPU-Debug are always associated
> with CPUs. Replace the of_coresight_get_cpu() with a platform
> agnostic helper, in preparation to add ACPI support.
>
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-cpu-debug.c |  3 +--
>  drivers/hwtracing/coresight/coresight-platform.c  | 18 +++++++++++++-----
>  include/linux/coresight.h                         |  7 +------
>  3 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c
> index e8819d7..07a1367 100644
> --- a/drivers/hwtracing/coresight/coresight-cpu-debug.c
> +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c
> @@ -572,14 +572,13 @@ static int debug_probe(struct amba_device *adev, const struct amba_id *id)
>         struct device *dev = &adev->dev;
>         struct debug_drvdata *drvdata;
>         struct resource *res = &adev->res;
> -       struct device_node *np = adev->dev.of_node;
>         int ret;
>
>         drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
>         if (!drvdata)
>                 return -ENOMEM;
>
> -       drvdata->cpu = np ? of_coresight_get_cpu(np) : 0;
> +       drvdata->cpu = coresight_get_cpu(dev);
>         if (per_cpu(debug_drvdata, drvdata->cpu)) {
>                 dev_err(dev, "CPU%d drvdata has already been initialized\n",
>                         drvdata->cpu);
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index 5d78f4f..ba8c146 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -151,12 +151,14 @@ static void of_coresight_get_ports(const struct device_node *node,
>         }
>  }
>
> -int of_coresight_get_cpu(const struct device_node *node)
> +static int of_coresight_get_cpu(struct device *dev)
>  {
>         int cpu;
>         struct device_node *dn;
>
> -       dn = of_parse_phandle(node, "cpu", 0);
> +       if (!dev->of_node)
> +               return 0;
> +       dn = of_parse_phandle(dev->of_node, "cpu", 0);
>         /* Affinity defaults to CPU0 */
>         if (!dn)
>                 return 0;
> @@ -166,7 +168,6 @@ int of_coresight_get_cpu(const struct device_node *node)
>         /* Affinity to CPU0 if no cpu nodes are found */
>         return (cpu < 0) ? 0 : cpu;
>  }
> -EXPORT_SYMBOL_GPL(of_coresight_get_cpu);
>
>  /*
>   * of_coresight_parse_endpoint : Parse the given output endpoint @ep
> @@ -240,8 +241,6 @@ static int of_get_coresight_platform_data(struct device *dev,
>         bool legacy_binding = false;
>         struct device_node *node = dev->of_node;
>
> -       pdata->cpu = of_coresight_get_cpu(node);
> -
>         /* Get the number of input and output port for this component */
>         of_coresight_get_ports(node, &pdata->nr_inport, &pdata->nr_outport);
>
> @@ -300,6 +299,14 @@ of_get_coresight_platform_data(struct device *dev,
>  }
>  #endif
>
> +int coresight_get_cpu(struct device *dev)
> +{
> +       if (is_of_node(dev->fwnode))
> +               return of_coresight_get_cpu(dev);

No of_coresight_get_cpu() will be defined if CONFIG_OF _not_ defined.
This will hit an implicit declaration compile error in this case.

Mike

> +       return 0;
> +}
> +EXPORT_SYMBOL_GPL(coresight_get_cpu);
> +
>  struct coresight_platform_data *
>  coresight_get_platform_data(struct device *dev)
>  {
> @@ -318,6 +325,7 @@ coresight_get_platform_data(struct device *dev)
>
>         /* Use device name as sysfs handle */
>         pdata->name = dev_name(dev);
> +       pdata->cpu = coresight_get_cpu(dev);
>
>         if (is_of_node(fwnode))
>                 ret = of_get_coresight_platform_data(dev, pdata);
> diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> index e2b95e0..98a4440 100644
> --- a/include/linux/coresight.h
> +++ b/include/linux/coresight.h
> @@ -292,12 +292,7 @@ static inline void coresight_disclaim_device_unlocked(void __iomem *base) {}
>
>  #endif
>
> -#ifdef CONFIG_OF
> -extern int of_coresight_get_cpu(const struct device_node *node);
> -#else
> -static inline int of_coresight_get_cpu(const struct device_node *node)
> -{ return 0; }
> -#endif
> +extern int coresight_get_cpu(struct device *dev);
>
>  struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
>
> --
> 2.7.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Suzuki K Poulose June 6, 2019, 12:56 p.m. UTC | #2
On 03/06/2019 11:07, Mike Leach wrote:
> Hi,
> 
> On Wed, 22 May 2019 at 11:37, Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>>
>> The CoreSight components ETM and CPU-Debug are always associated
>> with CPUs. Replace the of_coresight_get_cpu() with a platform
>> agnostic helper, in preparation to add ACPI support.
>>
>> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
>> ---
>>   drivers/hwtracing/coresight/coresight-cpu-debug.c |  3 +--
>>   drivers/hwtracing/coresight/coresight-platform.c  | 18 +++++++++++++-----
>>   include/linux/coresight.h                         |  7 +------
>>   3 files changed, 15 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c
>> index e8819d7..07a1367 100644
>> --- a/drivers/hwtracing/coresight/coresight-cpu-debug.c
>> +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c
>> @@ -572,14 +572,13 @@ static int debug_probe(struct amba_device *adev, const struct amba_id *id)
>>          struct device *dev = &adev->dev;
>>          struct debug_drvdata *drvdata;
>>          struct resource *res = &adev->res;
>> -       struct device_node *np = adev->dev.of_node;
>>          int ret;
>>
>>          drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
>>          if (!drvdata)
>>                  return -ENOMEM;
>>
>> -       drvdata->cpu = np ? of_coresight_get_cpu(np) : 0;
>> +       drvdata->cpu = coresight_get_cpu(dev);
>>          if (per_cpu(debug_drvdata, drvdata->cpu)) {
>>                  dev_err(dev, "CPU%d drvdata has already been initialized\n",
>>                          drvdata->cpu);
>> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
>> index 5d78f4f..ba8c146 100644
>> --- a/drivers/hwtracing/coresight/coresight-platform.c
>> +++ b/drivers/hwtracing/coresight/coresight-platform.c
>> @@ -151,12 +151,14 @@ static void of_coresight_get_ports(const struct device_node *node,
>>          }
>>   }
>>
>> -int of_coresight_get_cpu(const struct device_node *node)
>> +static int of_coresight_get_cpu(struct device *dev)
>>   {
>>          int cpu;
>>          struct device_node *dn;
>>
>> -       dn = of_parse_phandle(node, "cpu", 0);
>> +       if (!dev->of_node)
>> +               return 0;
>> +       dn = of_parse_phandle(dev->of_node, "cpu", 0);
>>          /* Affinity defaults to CPU0 */
>>          if (!dn)
>>                  return 0;
>> @@ -166,7 +168,6 @@ int of_coresight_get_cpu(const struct device_node *node)
>>          /* Affinity to CPU0 if no cpu nodes are found */
>>          return (cpu < 0) ? 0 : cpu;
>>   }
>> -EXPORT_SYMBOL_GPL(of_coresight_get_cpu);
>>
>>   /*
>>    * of_coresight_parse_endpoint : Parse the given output endpoint @ep
>> @@ -240,8 +241,6 @@ static int of_get_coresight_platform_data(struct device *dev,
>>          bool legacy_binding = false;
>>          struct device_node *node = dev->of_node;
>>
>> -       pdata->cpu = of_coresight_get_cpu(node);
>> -
>>          /* Get the number of input and output port for this component */
>>          of_coresight_get_ports(node, &pdata->nr_inport, &pdata->nr_outport);
>>
>> @@ -300,6 +299,14 @@ of_get_coresight_platform_data(struct device *dev,
>>   }
>>   #endif
>>
>> +int coresight_get_cpu(struct device *dev)
>> +{
>> +       if (is_of_node(dev->fwnode))
>> +               return of_coresight_get_cpu(dev);
> 
> No of_coresight_get_cpu() will be defined if CONFIG_OF _not_ defined.
> This will hit an implicit declaration compile error in this case.

Thanks for catching it and you're right. I will fix this.

Cheers
Suzuki

Patch
diff mbox series

diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c
index e8819d7..07a1367 100644
--- a/drivers/hwtracing/coresight/coresight-cpu-debug.c
+++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c
@@ -572,14 +572,13 @@  static int debug_probe(struct amba_device *adev, const struct amba_id *id)
 	struct device *dev = &adev->dev;
 	struct debug_drvdata *drvdata;
 	struct resource *res = &adev->res;
-	struct device_node *np = adev->dev.of_node;
 	int ret;
 
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
 	if (!drvdata)
 		return -ENOMEM;
 
-	drvdata->cpu = np ? of_coresight_get_cpu(np) : 0;
+	drvdata->cpu = coresight_get_cpu(dev);
 	if (per_cpu(debug_drvdata, drvdata->cpu)) {
 		dev_err(dev, "CPU%d drvdata has already been initialized\n",
 			drvdata->cpu);
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 5d78f4f..ba8c146 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -151,12 +151,14 @@  static void of_coresight_get_ports(const struct device_node *node,
 	}
 }
 
-int of_coresight_get_cpu(const struct device_node *node)
+static int of_coresight_get_cpu(struct device *dev)
 {
 	int cpu;
 	struct device_node *dn;
 
-	dn = of_parse_phandle(node, "cpu", 0);
+	if (!dev->of_node)
+		return 0;
+	dn = of_parse_phandle(dev->of_node, "cpu", 0);
 	/* Affinity defaults to CPU0 */
 	if (!dn)
 		return 0;
@@ -166,7 +168,6 @@  int of_coresight_get_cpu(const struct device_node *node)
 	/* Affinity to CPU0 if no cpu nodes are found */
 	return (cpu < 0) ? 0 : cpu;
 }
-EXPORT_SYMBOL_GPL(of_coresight_get_cpu);
 
 /*
  * of_coresight_parse_endpoint : Parse the given output endpoint @ep
@@ -240,8 +241,6 @@  static int of_get_coresight_platform_data(struct device *dev,
 	bool legacy_binding = false;
 	struct device_node *node = dev->of_node;
 
-	pdata->cpu = of_coresight_get_cpu(node);
-
 	/* Get the number of input and output port for this component */
 	of_coresight_get_ports(node, &pdata->nr_inport, &pdata->nr_outport);
 
@@ -300,6 +299,14 @@  of_get_coresight_platform_data(struct device *dev,
 }
 #endif
 
+int coresight_get_cpu(struct device *dev)
+{
+	if (is_of_node(dev->fwnode))
+		return of_coresight_get_cpu(dev);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(coresight_get_cpu);
+
 struct coresight_platform_data *
 coresight_get_platform_data(struct device *dev)
 {
@@ -318,6 +325,7 @@  coresight_get_platform_data(struct device *dev)
 
 	/* Use device name as sysfs handle */
 	pdata->name = dev_name(dev);
+	pdata->cpu = coresight_get_cpu(dev);
 
 	if (is_of_node(fwnode))
 		ret = of_get_coresight_platform_data(dev, pdata);
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index e2b95e0..98a4440 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -292,12 +292,7 @@  static inline void coresight_disclaim_device_unlocked(void __iomem *base) {}
 
 #endif
 
-#ifdef CONFIG_OF
-extern int of_coresight_get_cpu(const struct device_node *node);
-#else
-static inline int of_coresight_get_cpu(const struct device_node *node)
-{ return 0; }
-#endif
+extern int coresight_get_cpu(struct device *dev);
 
 struct coresight_platform_data *coresight_get_platform_data(struct device *dev);