From 5f0efc2265ee3e9aa16326de0a1d8be2856b9d02 Mon Sep 17 00:00:00 2001 From: Mao Jinlong Date: Tue, 1 Dec 2020 04:49:58 -0800 Subject: [PATCH] coresight: add node to reset all coresight devices Add new reset_source_sink node to be able to disable all active coresight devices. Change-Id: Ic9daeb35d7aacd334911683d41a2f0f278719725 Signed-off-by: Tingwei Zhang Signed-off-by: Mao Jinlong --- drivers/hwtracing/coresight/coresight-core.c | 74 +++++++++++++++++--- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index af9447b170e3..e41c84cffb81 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -122,6 +122,23 @@ static int coresight_source_is_unique(struct coresight_device *csdev) csdev, coresight_id_match); } +static int coresight_reset_sink(struct device *dev, void *data) +{ + struct coresight_device *csdev = to_coresight_device(dev); + + if ((csdev->type == CORESIGHT_DEV_TYPE_SINK || + csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) && + csdev->activated) + csdev->activated = false; + + return 0; +} + +static void coresight_reset_all_sink(void) +{ + bus_for_each_dev(&coresight_bustype, NULL, NULL, coresight_reset_sink); +} + static int coresight_find_link_inport(struct coresight_device *csdev, struct coresight_device *parent) { @@ -1177,7 +1194,7 @@ int coresight_enable(struct coresight_device *csdev) } EXPORT_SYMBOL_GPL(coresight_enable); -void coresight_disable(struct coresight_device *csdev) +static void __coresight_disable(struct coresight_device *csdev) { int ret; struct list_head *path = NULL; @@ -1185,14 +1202,12 @@ void coresight_disable(struct coresight_device *csdev) struct coresight_path *cspath_next = NULL; struct coresight_device *src_csdev = NULL; - mutex_lock(&coresight_mutex); - ret = coresight_validate_source(csdev, __func__); if (ret) - goto out; + return; if (!csdev->enable || !coresight_disable_source(csdev)) - goto out; + return; list_for_each_entry_safe(cspath, cspath_next, &cs_active_paths, link) { src_csdev = coresight_get_source(cspath->path); @@ -1206,12 +1221,17 @@ void coresight_disable(struct coresight_device *csdev) } if (path == NULL) - goto out; + return; coresight_disable_path(path); coresight_release_path(path); -out: +} + +void coresight_disable(struct coresight_device *csdev) +{ + mutex_lock(&coresight_mutex); + __coresight_disable(csdev); mutex_unlock(&coresight_mutex); } EXPORT_SYMBOL_GPL(coresight_disable); @@ -1771,8 +1791,46 @@ char *coresight_alloc_device_name(struct coresight_dev_list *dict, } EXPORT_SYMBOL_GPL(coresight_alloc_device_name); +static ssize_t reset_source_sink_store(struct bus_type *bus, + const char *buf, size_t size) +{ + int ret = 0; + unsigned long val; + struct coresight_path *cspath = NULL; + struct coresight_path *cspath_next = NULL; + struct coresight_device *csdev; + + ret = kstrtoul(buf, 10, &val); + if (ret) + return ret; + + mutex_lock(&coresight_mutex); + + list_for_each_entry_safe(cspath, cspath_next, &cs_active_paths, link) { + csdev = coresight_get_source(cspath->path); + if (!csdev) + continue; + atomic_set(csdev->refcnt, 1); + __coresight_disable(csdev); + } + + /* Reset all activated sinks */ + coresight_reset_all_sink(); + + mutex_unlock(&coresight_mutex); + return size; +} +static BUS_ATTR_WO(reset_source_sink); + +static struct attribute *coresight_reset_source_sink_attrs[] = { + &bus_attr_reset_source_sink.attr, + NULL, +}; +ATTRIBUTE_GROUPS(coresight_reset_source_sink); + struct bus_type coresight_bustype = { - .name = "coresight", + .name = "coresight", + .bus_groups = coresight_reset_source_sink_groups, }; static int __init coresight_init(void)