Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Mathieu Poirier and committed by
Greg Kroah-Hartman
a685d683 8e996a28

+82 -24
+82 -24
drivers/hwtracing/coresight/coresight.c
··· 43 43 * When operating Coresight drivers from the sysFS interface, only a single 44 44 * path can exist from a tracer (associated to a CPU) to a sink. 45 45 */ 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; 47 55 48 56 static int coresight_id_match(struct device *dev, void *data) 49 57 { ··· 440 432 path = NULL; 441 433 } 442 434 435 + /** coresight_validate_source - make sure a source has the right credentials 436 + * @csdev: the device structure for a source. 437 + * @function: the function this was called from. 438 + * 439 + * Assumes the coresight_mutex is held. 440 + */ 441 + static int coresight_validate_source(struct coresight_device *csdev, 442 + const char *function) 443 + { 444 + u32 type, subtype; 445 + 446 + type = csdev->type; 447 + subtype = csdev->subtype.source_subtype; 448 + 449 + if (type != CORESIGHT_DEV_TYPE_SOURCE) { 450 + dev_err(&csdev->dev, "wrong device type in %s\n", function); 451 + return -EINVAL; 452 + } 453 + 454 + if (subtype != CORESIGHT_DEV_SUBTYPE_SOURCE_PROC && 455 + subtype != CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE) { 456 + dev_err(&csdev->dev, "wrong device subtype in %s\n", function); 457 + return -EINVAL; 458 + } 459 + 460 + return 0; 461 + } 462 + 443 463 int coresight_enable(struct coresight_device *csdev) 444 464 { 445 - int ret = 0; 446 - int cpu; 465 + int cpu, ret = 0; 447 466 struct list_head *path; 448 467 449 468 mutex_lock(&coresight_mutex); 450 - if (csdev->type != CORESIGHT_DEV_TYPE_SOURCE) { 451 - ret = -EINVAL; 452 - dev_err(&csdev->dev, "wrong device type in %s\n", __func__); 469 + 470 + ret = coresight_validate_source(csdev, __func__); 471 + if (ret) 453 472 goto out; 454 - } 473 + 455 474 if (csdev->enable) 456 475 goto out; 457 476 ··· 496 461 if (ret) 497 462 goto err_source; 498 463 499 - /* 500 - * When working from sysFS it is important to keep track 501 - * of the paths that were created so that they can be 502 - * undone in 'coresight_disable()'. Since there can only 503 - * be a single session per tracer (when working from sysFS) 504 - * a per-cpu variable will do just fine. 505 - */ 506 - cpu = source_ops(csdev)->cpu_id(csdev); 507 - per_cpu(sysfs_path, cpu) = path; 464 + switch (csdev->subtype.source_subtype) { 465 + case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: 466 + /* 467 + * When working from sysFS it is important to keep track 468 + * of the paths that were created so that they can be 469 + * undone in 'coresight_disable()'. Since there can only 470 + * be a single session per tracer (when working from sysFS) 471 + * a per-cpu variable will do just fine. 472 + */ 473 + cpu = source_ops(csdev)->cpu_id(csdev); 474 + per_cpu(tracer_path, cpu) = path; 475 + break; 476 + case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: 477 + stm_path = path; 478 + break; 479 + default: 480 + /* We can't be here */ 481 + break; 482 + } 508 483 509 484 out: 510 485 mutex_unlock(&coresight_mutex); ··· 531 486 532 487 void coresight_disable(struct coresight_device *csdev) 533 488 { 534 - int cpu; 535 - struct list_head *path; 489 + int cpu, ret; 490 + struct list_head *path = NULL; 536 491 537 492 mutex_lock(&coresight_mutex); 538 - if (csdev->type != CORESIGHT_DEV_TYPE_SOURCE) { 539 - dev_err(&csdev->dev, "wrong device type in %s\n", __func__); 493 + 494 + ret = coresight_validate_source(csdev, __func__); 495 + if (ret) 540 496 goto out; 541 - } 497 + 542 498 if (!csdev->enable) 543 499 goto out; 544 500 545 - cpu = source_ops(csdev)->cpu_id(csdev); 546 - path = per_cpu(sysfs_path, cpu); 501 + switch (csdev->subtype.source_subtype) { 502 + case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: 503 + cpu = source_ops(csdev)->cpu_id(csdev); 504 + path = per_cpu(tracer_path, cpu); 505 + per_cpu(tracer_path, cpu) = NULL; 506 + break; 507 + case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: 508 + path = stm_path; 509 + stm_path = NULL; 510 + break; 511 + default: 512 + /* We can't be here */ 513 + break; 514 + } 515 + 547 516 coresight_disable_source(csdev); 548 517 coresight_disable_path(path); 549 518 coresight_release_path(path); 550 - per_cpu(sysfs_path, cpu) = NULL; 551 519 552 520 out: 553 521 mutex_unlock(&coresight_mutex);