Commit 5c0016d7 authored by Mao Jinlong's avatar Mao Jinlong Committed by Suzuki K Poulose

coresight: core: Use IDR for non-cpu bound sources' paths.

Except stm, there could be other sources which are not associated
with cpus. Use IDR to store and search these sources' paths.
Reviewed-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
Signed-off-by: default avatarMao Jinlong <quic_jinlmao@quicinc.com>
Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20230117145708.16739-2-quic_jinlmao@quicinc.com
parent fd30b085
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/idr.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -26,6 +27,13 @@ ...@@ -26,6 +27,13 @@
static DEFINE_MUTEX(coresight_mutex); static DEFINE_MUTEX(coresight_mutex);
static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); static DEFINE_PER_CPU(struct coresight_device *, csdev_sink);
/*
* Use IDR to map the hash of the source's device name
* to the pointer of path for the source. The idr is for
* the sources which aren't associated with CPU.
*/
static DEFINE_IDR(path_idr);
/** /**
* struct coresight_node - elements of a path, from source to sink * struct coresight_node - elements of a path, from source to sink
* @csdev: Address of an element. * @csdev: Address of an element.
...@@ -42,14 +50,6 @@ struct coresight_node { ...@@ -42,14 +50,6 @@ struct coresight_node {
*/ */
static DEFINE_PER_CPU(struct list_head *, tracer_path); static DEFINE_PER_CPU(struct list_head *, tracer_path);
/*
* As of this writing only a single STM can be found in CS topologies. Since
* there is no way to know if we'll ever see more and what kind of
* configuration they will enact, for the time being only define a single path
* for STM.
*/
static struct list_head *stm_path;
/* /*
* When losing synchronisation a new barrier packet needs to be inserted at the * When losing synchronisation a new barrier packet needs to be inserted at the
* beginning of the data collected in a buffer. That way the decoder knows that * beginning of the data collected in a buffer. That way the decoder knows that
...@@ -1075,6 +1075,7 @@ int coresight_enable(struct coresight_device *csdev) ...@@ -1075,6 +1075,7 @@ int coresight_enable(struct coresight_device *csdev)
struct coresight_device *sink; struct coresight_device *sink;
struct list_head *path; struct list_head *path;
enum coresight_dev_subtype_source subtype; enum coresight_dev_subtype_source subtype;
u32 hash;
subtype = csdev->subtype.source_subtype; subtype = csdev->subtype.source_subtype;
...@@ -1129,7 +1130,14 @@ int coresight_enable(struct coresight_device *csdev) ...@@ -1129,7 +1130,14 @@ int coresight_enable(struct coresight_device *csdev)
per_cpu(tracer_path, cpu) = path; per_cpu(tracer_path, cpu) = path;
break; break;
case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE:
stm_path = path; /*
* Use the hash of source's device name as ID
* and map the ID to the pointer of the path.
*/
hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev)));
ret = idr_alloc_u32(&path_idr, path, &hash, hash, GFP_KERNEL);
if (ret)
goto err_source;
break; break;
default: default:
/* We can't be here */ /* We can't be here */
...@@ -1153,6 +1161,7 @@ void coresight_disable(struct coresight_device *csdev) ...@@ -1153,6 +1161,7 @@ void coresight_disable(struct coresight_device *csdev)
{ {
int cpu, ret; int cpu, ret;
struct list_head *path = NULL; struct list_head *path = NULL;
u32 hash;
mutex_lock(&coresight_mutex); mutex_lock(&coresight_mutex);
...@@ -1170,14 +1179,20 @@ void coresight_disable(struct coresight_device *csdev) ...@@ -1170,14 +1179,20 @@ void coresight_disable(struct coresight_device *csdev)
per_cpu(tracer_path, cpu) = NULL; per_cpu(tracer_path, cpu) = NULL;
break; break;
case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE:
path = stm_path; hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev)));
stm_path = NULL; /* Find the path by the hash. */
path = idr_find(&path_idr, hash);
if (path == NULL) {
pr_err("Path is not found for %s\n", dev_name(&csdev->dev));
goto out;
}
break; break;
default: default:
/* We can't be here */ /* We can't be here */
break; break;
} }
idr_remove(&path_idr, hash);
coresight_disable_path(path); coresight_disable_path(path);
coresight_release_path(path); coresight_release_path(path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment