Skip to content

Commit 27e5d1a

Browse files
coresight: adding path for STM device
>From a core framework point of view an STM device is a source that is treated the same way as any other tracers. Unlike tracers though STM devices are not associated with a CPU. As such it doesn't make sense to associate the path from an STM device to its sink with a per-cpu variable as it is done for tracers. This patch simply adds another global variable to keep STM paths and the processing in coresight_enable/disable() is updated to deal with STM devices properly. Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit a685d68328f14579b2e68d6a3a2066089cffbf98)
1 parent b1ffdd7 commit 27e5d1a

1 file changed

Lines changed: 82 additions & 24 deletions

File tree

drivers/hwtracing/coresight/coresight.c

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ struct coresight_node {
4343
* When operating Coresight drivers from the sysFS interface, only a single
4444
* path can exist from a tracer (associated to a CPU) to a sink.
4545
*/
46-
static DEFINE_PER_CPU(struct list_head *, sysfs_path);
46+
static DEFINE_PER_CPU(struct list_head *, tracer_path);
47+
48+
/*
49+
* As of this writing only a single STM can be found in CS topologies. Since
50+
* there is no way to know if we'll ever see more and what kind of
51+
* configuration they will enact, for the time being only define a single path
52+
* for STM.
53+
*/
54+
static struct list_head *stm_path;
4755

4856
static int coresight_id_match(struct device *dev, void *data)
4957
{
@@ -432,18 +440,45 @@ void coresight_release_path(struct list_head *path)
432440
path = NULL;
433441
}
434442

443+
/** coresight_validate_source - make sure a source has the right credentials
444+
* @csdev: the device structure for a source.
445+
* @function: the function this was called from.
446+
*
447+
* Assumes the coresight_mutex is held.
448+
*/
449+
static int coresight_validate_source(struct coresight_device *csdev,
450+
const char *function)
451+
{
452+
u32 type, subtype;
453+
454+
type = csdev->type;
455+
subtype = csdev->subtype.source_subtype;
456+
457+
if (type != CORESIGHT_DEV_TYPE_SOURCE) {
458+
dev_err(&csdev->dev, "wrong device type in %s\n", function);
459+
return -EINVAL;
460+
}
461+
462+
if (subtype != CORESIGHT_DEV_SUBTYPE_SOURCE_PROC &&
463+
subtype != CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE) {
464+
dev_err(&csdev->dev, "wrong device subtype in %s\n", function);
465+
return -EINVAL;
466+
}
467+
468+
return 0;
469+
}
470+
435471
int coresight_enable(struct coresight_device *csdev)
436472
{
437-
int ret = 0;
438-
int cpu;
473+
int cpu, ret = 0;
439474
struct list_head *path;
440475

441476
mutex_lock(&coresight_mutex);
442-
if (csdev->type != CORESIGHT_DEV_TYPE_SOURCE) {
443-
ret = -EINVAL;
444-
dev_err(&csdev->dev, "wrong device type in %s\n", __func__);
477+
478+
ret = coresight_validate_source(csdev, __func__);
479+
if (ret)
445480
goto out;
446-
}
481+
447482
if (csdev->enable)
448483
goto out;
449484

@@ -461,15 +496,25 @@ int coresight_enable(struct coresight_device *csdev)
461496
if (ret)
462497
goto err_source;
463498

464-
/*
465-
* When working from sysFS it is important to keep track
466-
* of the paths that were created so that they can be
467-
* undone in 'coresight_disable()'. Since there can only
468-
* be a single session per tracer (when working from sysFS)
469-
* a per-cpu variable will do just fine.
470-
*/
471-
cpu = source_ops(csdev)->cpu_id(csdev);
472-
per_cpu(sysfs_path, cpu) = path;
499+
switch (csdev->subtype.source_subtype) {
500+
case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC:
501+
/*
502+
* When working from sysFS it is important to keep track
503+
* of the paths that were created so that they can be
504+
* undone in 'coresight_disable()'. Since there can only
505+
* be a single session per tracer (when working from sysFS)
506+
* a per-cpu variable will do just fine.
507+
*/
508+
cpu = source_ops(csdev)->cpu_id(csdev);
509+
per_cpu(tracer_path, cpu) = path;
510+
break;
511+
case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE:
512+
stm_path = path;
513+
break;
514+
default:
515+
/* We can't be here */
516+
break;
517+
}
473518

474519
out:
475520
mutex_unlock(&coresight_mutex);
@@ -486,23 +531,36 @@ EXPORT_SYMBOL_GPL(coresight_enable);
486531

487532
void coresight_disable(struct coresight_device *csdev)
488533
{
489-
int cpu;
490-
struct list_head *path;
534+
int cpu, ret;
535+
struct list_head *path = NULL;
491536

492537
mutex_lock(&coresight_mutex);
493-
if (csdev->type != CORESIGHT_DEV_TYPE_SOURCE) {
494-
dev_err(&csdev->dev, "wrong device type in %s\n", __func__);
538+
539+
ret = coresight_validate_source(csdev, __func__);
540+
if (ret)
495541
goto out;
496-
}
542+
497543
if (!csdev->enable)
498544
goto out;
499545

500-
cpu = source_ops(csdev)->cpu_id(csdev);
501-
path = per_cpu(sysfs_path, cpu);
546+
switch (csdev->subtype.source_subtype) {
547+
case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC:
548+
cpu = source_ops(csdev)->cpu_id(csdev);
549+
path = per_cpu(tracer_path, cpu);
550+
per_cpu(tracer_path, cpu) = NULL;
551+
break;
552+
case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE:
553+
path = stm_path;
554+
stm_path = NULL;
555+
break;
556+
default:
557+
/* We can't be here */
558+
break;
559+
}
560+
502561
coresight_disable_source(csdev);
503562
coresight_disable_path(path);
504563
coresight_release_path(path);
505-
per_cpu(sysfs_path, cpu) = NULL;
506564

507565
out:
508566
mutex_unlock(&coresight_mutex);

0 commit comments

Comments
 (0)