@@ -371,31 +371,42 @@ struct coresight_device *coresight_get_sink(struct list_head *path)
371371/**
372372 * _coresight_build_path - recursively build a path from a @csdev to a sink.
373373 * @csdev: The device to start from.
374+ * @sink: The name of the sink this path should connect with.
374375 * @path: The list to add devices to.
375376 *
376- * The tree of Coresight device is traversed until an activated sink is
377- * found. From there the sink is added to the list along with all the
378- * devices that led to that point - the end result is a list from source
379- * to sink. In that list the source is the first device and the sink the
380- * last one.
377+ * The tree of Coresight device is traversed until an activated sink or
378+ * the one specified by @ sink is found.
379+ * From there the sink is added to the list along with all the devices that
380+ * led to that point - the end result is a list from source to sink. In that
381+ * list the source is the first device and the sink the last one.
381382 */
382383static int _coresight_build_path (struct coresight_device * csdev ,
383- struct list_head * path )
384+ const char * sink , struct list_head * path )
384385{
385386 int i ;
386387 bool found = false;
387388 struct coresight_node * node ;
388389
389- /* An activated sink has been found. Enqueue the element */
390- if ((csdev -> type == CORESIGHT_DEV_TYPE_SINK ||
391- csdev -> type == CORESIGHT_DEV_TYPE_LINKSINK ) && csdev -> activated )
392- goto out ;
390+ /*
391+ * First see if we are dealing with a sink. If we have one check if
392+ * it was selected via sysFS or the perf cmd line.
393+ */
394+ if (csdev -> type == CORESIGHT_DEV_TYPE_SINK ||
395+ csdev -> type == CORESIGHT_DEV_TYPE_LINKSINK ) {
396+ /* Activated via perf cmd line */
397+ if (sink && !strcmp (dev_name (& csdev -> dev ), sink ))
398+ goto out ;
399+ /* Activatred via sysFS */
400+ if (csdev -> activated )
401+ goto out ;
402+ }
393403
394404 /* Not a sink - recursively explore each port found on this element */
395405 for (i = 0 ; i < csdev -> nr_outport ; i ++ ) {
396406 struct coresight_device * child_dev = csdev -> conns [i ].child_dev ;
397407
398- if (child_dev && _coresight_build_path (child_dev , path ) == 0 ) {
408+ if (child_dev &&
409+ _coresight_build_path (child_dev , sink , path ) == 0 ) {
399410 found = true;
400411 break ;
401412 }
@@ -422,7 +433,8 @@ static int _coresight_build_path(struct coresight_device *csdev,
422433 return 0 ;
423434}
424435
425- struct list_head * coresight_build_path (struct coresight_device * csdev )
436+ struct list_head * coresight_build_path (struct coresight_device * csdev ,
437+ const char * sink )
426438{
427439 struct list_head * path ;
428440 int rc ;
@@ -433,7 +445,7 @@ struct list_head *coresight_build_path(struct coresight_device *csdev)
433445
434446 INIT_LIST_HEAD (path );
435447
436- rc = _coresight_build_path (csdev , path );
448+ rc = _coresight_build_path (csdev , sink , path );
437449 if (rc ) {
438450 kfree (path );
439451 return ERR_PTR (rc );
@@ -508,7 +520,7 @@ int coresight_enable(struct coresight_device *csdev)
508520 if (csdev -> enable )
509521 goto out ;
510522
511- path = coresight_build_path (csdev );
523+ path = coresight_build_path (csdev , NULL );
512524 if (IS_ERR (path )) {
513525 pr_err ("building path(s) failed\n" );
514526 ret = PTR_ERR (path );
0 commit comments