To allow the connections between coresight components to be represented in sysfs, generic methods for creating sysfs links between two coresight devices are added.
Signed-off-by: Mike Leach mike.leach@linaro.org --- drivers/hwtracing/coresight/coresight-priv.h | 2 + drivers/hwtracing/coresight/coresight.c | 73 ++++++++++++++++++++ include/linux/coresight.h | 18 +++++ 3 files changed, 93 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 4c176498a367..d02e9d6b80ab 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -153,6 +153,8 @@ struct coresight_device *coresight_get_sink_by_id(u32 id); struct list_head *coresight_build_path(struct coresight_device *csdev, struct coresight_device *sink); void coresight_release_path(struct list_head *path); +int coresight_add_sysfs_link(struct coresight_sysfs_link *info); +void coresight_remove_sysfs_link(struct coresight_sysfs_link *info);
#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X extern int etm_readl_cp14(u32 off, unsigned int *val); diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 52b294dd898e..5a07ba9e3a00 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -1032,6 +1032,79 @@ static void coresight_device_release(struct device *dev) kfree(csdev); }
+static int coresight_create_sysfs_link(struct kobject *from, + struct kobject *to, + const char *link_name, + const char *group_name) +{ + if (group_name) + return sysfs_add_link_to_group(from, group_name, + to, link_name); + else + return sysfs_create_link(from, to, link_name); +} + +static void coresight_delete_sysfs_link(struct kobject *kobj, + const char *link_name, + const char *group_name) +{ + if (group_name) + sysfs_remove_link_from_group(kobj, group_name, link_name); + else + sysfs_remove_link(kobj, link_name); +} + +int coresight_add_sysfs_link(struct coresight_sysfs_link *info) +{ + int ret = 0; + + if (!info) + return -EINVAL; + if (!info->orig || !info->target || + !info->orig_name || !info->target_name) + return -EINVAL; + + /* first link orig->target */ + ret = coresight_create_sysfs_link(&info->orig->dev.kobj, + &info->target->dev.kobj, + info->orig_name, + info->orig->sysfs_link_grp); + if (ret) + return ret; + + /* second link target->orig */ + ret = coresight_create_sysfs_link(&info->target->dev.kobj, + &info->orig->dev.kobj, + info->target_name, + info->target->sysfs_link_grp); + + /* error in second link - remove first */ + if (ret) { + coresight_delete_sysfs_link(&info->orig->dev.kobj, + info->orig_name, + info->orig->sysfs_link_grp); + } + + return ret; +} + +void coresight_remove_sysfs_link(struct coresight_sysfs_link *info) +{ + if (!info) + return; + if (!info->orig || !info->target || + !info->orig_name || !info->target_name) + return; + + coresight_delete_sysfs_link(&info->orig->dev.kobj, + info->orig_name, + info->orig->sysfs_link_grp); + + coresight_delete_sysfs_link(&info->target->dev.kobj, + info->target_name, + info->target->sysfs_link_grp); +} + static int coresight_orphan_match(struct device *dev, void *data) { int i; diff --git a/include/linux/coresight.h b/include/linux/coresight.h index ff97e9a7080a..cd0d92611be6 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -148,6 +148,20 @@ struct coresight_connection { struct coresight_device *child_dev; };
+/** + * struct coresight_sysfs_link - representation of a connection in sysfs. + * @orig: Originating (master) coresight device for the link. + * @orig_name: Name to use for the link orig->target. + * @target: Target (slave) coresight device for the link. + * @target_name: Name to use for the link target->orig. + */ +struct coresight_sysfs_link { + struct coresight_device *orig; + const char *orig_name; + struct coresight_device *target; + const char *target_name; +}; + /** * struct coresight_device - representation of a device as used by the framework * @pdata: Platform data with device connections associated to this device. @@ -165,6 +179,9 @@ struct coresight_connection { * @ea: Device attribute for sink representation under PMU directory. * @ect_dev: Associated cross trigger device. Not part of the trace data * path or connections. + * @sysfs_link_grp: Optional name for a group created to add sysfs links into + * on this device. Group must have been created on device + * registration. */ struct coresight_device { struct coresight_platform_data *pdata; @@ -180,6 +197,7 @@ struct coresight_device { struct dev_ext_attribute *ea; /* cross trigger handling */ struct coresight_device *ect_dev; + const char *sysfs_link_grp; };
/*