public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 0/3] coresight: Expose device connections via sysfs
@ 2019-05-30 16:44 Suzuki K Poulose
  2019-05-30 16:44 ` [PATCH 1/3] coresight: Pass coresight_device for coresight_release_platform_data Suzuki K Poulose
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Suzuki K Poulose @ 2019-05-30 16:44 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: coresight, leo.yan, Suzuki K Poulose, mathieu.poirier, mike.leach

Coresight device connections are a bit complicated and is not
exposed currently to the user. One has to look at the platform
descriptions (DT bindings or ACPI bindings) to make an understanding.
Given the new naming scheme, it will be helpful to have this information
to choose the appropriate devices for tracing. This patch exposes
the device connections via links in the sysfs directories.

e.g, for a connection devA[OutputPort_X] -> devB[InputPort_Y]
is represented as two symlinks:

  /sys/bus/coresight/.../devA/out:X -> /sys/bus/coresight/.../devB
  /sys/bus/coresight/.../devB/in:Y  -> /sys/bus/coresight/.../devA

Applies on coresight/next tree.

This is split from the ACPI bindings series. No functional changes.

Suzuki K Poulose (3):
  coresight: Pass coresight_device for coresight_release_platform_data
  coresight: add return value for fixup connections
  coresight: Expose device connections via sysfs

 drivers/hwtracing/coresight/coresight-platform.c |   2 +-
 drivers/hwtracing/coresight/coresight-priv.h     |   3 +-
 drivers/hwtracing/coresight/coresight.c          | 148 +++++++++++++++++++----
 include/linux/coresight.h                        |   4 +
 4 files changed, 132 insertions(+), 25 deletions(-)

-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] coresight: Pass coresight_device for coresight_release_platform_data
  2019-05-30 16:44 [PATCH 0/3] coresight: Expose device connections via sysfs Suzuki K Poulose
@ 2019-05-30 16:44 ` Suzuki K Poulose
  2019-05-30 16:44 ` [PATCH 2/3] coresight: add return value for fixup connections Suzuki K Poulose
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Suzuki K Poulose @ 2019-05-30 16:44 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: coresight, leo.yan, Suzuki K Poulose, mathieu.poirier, mike.leach

As we prepare to expose the links between the devices in
sysfs, pass the coresight_device instance to the
coresight_release_platform_data in order to free up the connections
when the device is removed.

No functional changes as such in this patch.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-platform.c | 2 +-
 drivers/hwtracing/coresight/coresight-priv.h     | 3 ++-
 drivers/hwtracing/coresight/coresight.c          | 7 ++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 6fef873..ea03dc8 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -804,7 +804,7 @@ coresight_get_platform_data(struct device *dev)
 error:
 	if (!IS_ERR_OR_NULL(pdata))
 		/* Cleanup the connection information */
-		coresight_release_platform_data(pdata);
+		coresight_release_platform_data(NULL, pdata);
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(coresight_get_platform_data);
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index 8b07fe5..ae01250 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -200,7 +200,8 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
 	return 0;
 }
 
-void coresight_release_platform_data(struct coresight_platform_data *pdata);
+void coresight_release_platform_data(struct coresight_device *csdev,
+				     struct coresight_platform_data *pdata);
 
 int coresight_device_fwnode_match(struct device *dev, void *fwnode);
 
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 86d1fc2..05a869b 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1175,7 +1175,8 @@ postcore_initcall(coresight_init);
  * coresight_release_platform_data: Release references to the devices connected
  * to the output port of this device.
  */
-void coresight_release_platform_data(struct coresight_platform_data *pdata)
+void coresight_release_platform_data(struct coresight_device *csdev,
+				     struct coresight_platform_data *pdata)
 {
 	int i;
 
@@ -1277,7 +1278,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	kfree(csdev);
 err_out:
 	/* Cleanup the connection information */
-	coresight_release_platform_data(desc->pdata);
+	coresight_release_platform_data(NULL, desc->pdata);
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(coresight_register);
@@ -1287,7 +1288,7 @@ void coresight_unregister(struct coresight_device *csdev)
 	etm_perf_del_symlink_sink(csdev);
 	/* Remove references of that device in the topology */
 	coresight_remove_conns(csdev);
-	coresight_release_platform_data(csdev->pdata);
+	coresight_release_platform_data(csdev, csdev->pdata);
 	device_unregister(&csdev->dev);
 }
 EXPORT_SYMBOL_GPL(coresight_unregister);
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] coresight: add return value for fixup connections
  2019-05-30 16:44 [PATCH 0/3] coresight: Expose device connections via sysfs Suzuki K Poulose
  2019-05-30 16:44 ` [PATCH 1/3] coresight: Pass coresight_device for coresight_release_platform_data Suzuki K Poulose
@ 2019-05-30 16:44 ` Suzuki K Poulose
  2019-05-30 16:44 ` [PATCH 3/3] coresight: Expose device connections via sysfs Suzuki K Poulose
  2019-06-03  8:45 ` [PATCH 0/3] " Leo Yan
  3 siblings, 0 replies; 5+ messages in thread
From: Suzuki K Poulose @ 2019-05-30 16:44 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: coresight, leo.yan, Suzuki K Poulose, mathieu.poirier, mike.leach

Handle failures in fixing up connections for a newly registered
device. This will be useful to handle cases where we fail to expose
the links via sysfs for the connections.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 05a869b..8836acb 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1027,18 +1027,14 @@ static int coresight_orphan_match(struct device *dev, void *data)
 	return 0;
 }
 
-static void coresight_fixup_orphan_conns(struct coresight_device *csdev)
+static int coresight_fixup_orphan_conns(struct coresight_device *csdev)
 {
-	/*
-	 * No need to check for a return value as orphan connection(s)
-	 * are hooked-up with each newly added component.
-	 */
-	bus_for_each_dev(&coresight_bustype, NULL,
+	return bus_for_each_dev(&coresight_bustype, NULL,
 			 csdev, coresight_orphan_match);
 }
 
 
-static void coresight_fixup_device_conns(struct coresight_device *csdev)
+static int coresight_fixup_device_conns(struct coresight_device *csdev)
 {
 	int i;
 
@@ -1058,6 +1054,8 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
 			conn->child_dev = NULL;
 		}
 	}
+
+	return 0;
 }
 
 static int coresight_remove_match(struct device *dev, void *data)
@@ -1267,10 +1265,15 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 
 	mutex_lock(&coresight_mutex);
 
-	coresight_fixup_device_conns(csdev);
-	coresight_fixup_orphan_conns(csdev);
+	ret = coresight_fixup_device_conns(csdev);
+	if (!ret)
+		ret = coresight_fixup_orphan_conns(csdev);
 
 	mutex_unlock(&coresight_mutex);
+	if (ret) {
+		coresight_unregister(csdev);
+		return ERR_PTR(ret);
+	}
 
 	return csdev;
 
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] coresight: Expose device connections via sysfs
  2019-05-30 16:44 [PATCH 0/3] coresight: Expose device connections via sysfs Suzuki K Poulose
  2019-05-30 16:44 ` [PATCH 1/3] coresight: Pass coresight_device for coresight_release_platform_data Suzuki K Poulose
  2019-05-30 16:44 ` [PATCH 2/3] coresight: add return value for fixup connections Suzuki K Poulose
@ 2019-05-30 16:44 ` Suzuki K Poulose
  2019-06-03  8:45 ` [PATCH 0/3] " Leo Yan
  3 siblings, 0 replies; 5+ messages in thread
From: Suzuki K Poulose @ 2019-05-30 16:44 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: coresight, leo.yan, Suzuki K Poulose, mathieu.poirier, mike.leach

Coresight device connections are a bit complicated and is not
exposed currently to the user. One has to look at the platform
descriptions (DT bindings or ACPI bindings) to make an understanding.
Given the new naming scheme, it will be helpful to have this information
to choose the appropriate devices for tracing. This patch exposes
the device connections via links in the sysfs directories.

e.g, for a connection devA[OutputPort_X] -> devB[InputPort_Y]
is represented as two symlinks:

  /sys/bus/coresight/.../devA/out:X -> /sys/bus/coresight/.../devB
  /sys/bus/coresight/.../devB/in:Y  -> /sys/bus/coresight/.../devA

We could have segregated the links to separate directories aka
attribute_groups, for input_ports and output_ports. But the sysfs won't
let you create empty attribute_groups and thus it becomes complicated to
dynamically create the attribute_groups.

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight.c | 120 +++++++++++++++++++++++++++++---
 include/linux/coresight.h               |   4 ++
 2 files changed, 113 insertions(+), 11 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 8836acb..8f062ab 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -983,9 +983,92 @@ static void coresight_device_release(struct device *dev)
 	kfree(csdev);
 }
 
+
+/*
+ * coresight_make_links: Make a link for a connection from a @orig
+ * device to @target, represented by @conn.
+ *
+ *   e.g, for devOrig[output_X] -> devTarget[input_Y] is represented
+ *   as two symbolic links :
+ *
+ *	/sys/.../devOrig/out:X	-> /sys/.../devTarget/
+ *	/sys/.../devTarget/in:Y	-> /sys/.../devOrig/
+ *
+ * The link names are allocated for a device where it appears. i.e, the
+ * "out" link on the master and "in" link on the slave device.
+ * The link names are stored in the connection record for avoiding
+ * the reconstruction of names for removal.
+ */
+static int coresight_make_links(struct coresight_device *orig,
+				struct coresight_connection *conn,
+				struct coresight_device *target)
+{
+	int ret = -ENOMEM;
+	char *outs = NULL, *ins = NULL;
+
+	do {
+		outs = devm_kasprintf(&orig->dev, GFP_KERNEL,
+				      "out:%d", conn->outport);
+		if (!outs)
+			break;
+		ins = devm_kasprintf(&target->dev, GFP_KERNEL,
+				     "in:%d", conn->child_port);
+		if (!ins)
+			break;
+		ret = sysfs_create_link(&orig->dev.kobj,
+					&target->dev.kobj, outs);
+		if (ret)
+			break;
+
+		ret = sysfs_create_link(&target->dev.kobj,
+					&orig->dev.kobj, ins);
+		if (ret) {
+			sysfs_remove_link(&orig->dev.kobj, outs);
+			break;
+		}
+
+		conn->inlink_name = ins;
+		conn->outlink_name = outs;
+		/*
+		 * Install the device connection. This also indicates that
+		 * the links are operational on both ends.
+		 */
+		conn->child_dev = target;
+		return 0;
+	} while (0);
+
+	if (outs)
+		devm_kfree(&orig->dev, outs);
+	if (ins)
+		devm_kfree(&target->dev, ins);
+	return ret;
+}
+
+/*
+ * coresight_remove_links: Remove the sysfs links for a given connection @conn,
+ * from @orig device to @target device. See coresight_make_links() for more
+ * details.
+ */
+static void coresight_remove_links(struct coresight_device *orig,
+				   struct coresight_connection *conn)
+{
+	struct coresight_device *target = conn->child_dev;
+
+	if (!orig || !target)
+		return;
+
+	sysfs_remove_link(&orig->dev.kobj, conn->outlink_name);
+	sysfs_remove_link(&target->dev.kobj, conn->inlink_name);
+
+	devm_kfree(&target->dev, conn->inlink_name);
+	devm_kfree(&orig->dev, conn->outlink_name);
+	conn->inlink_name = conn->outlink_name = NULL;
+	conn->child_dev = NULL;
+}
+
 static int coresight_orphan_match(struct device *dev, void *data)
 {
-	int i;
+	int i, ret = 0;
 	bool still_orphan = false;
 	struct coresight_device *csdev, *i_csdev;
 	struct coresight_connection *conn;
@@ -1010,19 +1093,23 @@ static int coresight_orphan_match(struct device *dev, void *data)
 		/* We have found at least one orphan connection */
 		if (conn->child_dev == NULL) {
 			/* Does it match this newly added device? */
-			if (conn->child_fwnode == csdev->dev.fwnode)
-				conn->child_dev = csdev;
-			else
+			if (conn->child_fwnode == csdev->dev.fwnode) {
+				ret = coresight_make_links(i_csdev,
+							   conn, csdev);
+				if (ret)
+					return ret;
+			} else {
 				/* This component still has an orphan */
 				still_orphan = true;
+			}
 		}
 	}
 
 	i_csdev->orphan = still_orphan;
 
 	/*
-	 * Returning '0' ensures that all known component on the
-	 * bus will be checked.
+	 * Returning '0' in case we didn't encounter any error,
+	 * ensures that all known component on the bus will be checked.
 	 */
 	return 0;
 }
@@ -1036,7 +1123,7 @@ static int coresight_fixup_orphan_conns(struct coresight_device *csdev)
 
 static int coresight_fixup_device_conns(struct coresight_device *csdev)
 {
-	int i;
+	int i, ret = 0;
 
 	for (i = 0; i < csdev->pdata->nr_outport; i++) {
 		struct coresight_connection *conn = &csdev->pdata->conns[i];
@@ -1046,9 +1133,12 @@ static int coresight_fixup_device_conns(struct coresight_device *csdev)
 				      (void *)conn->child_fwnode,
 				      coresight_device_fwnode_match);
 		if (dev) {
-			conn->child_dev = to_coresight_device(dev);
+			ret = coresight_make_links(csdev, conn,
+						   to_coresight_device(dev));
 			/* and put reference from 'bus_find_device()' */
 			put_device(dev);
+			if (ret)
+				break;
 		} else {
 			csdev->orphan = true;
 			conn->child_dev = NULL;
@@ -1083,7 +1173,7 @@ static int coresight_remove_match(struct device *dev, void *data)
 
 		if (csdev->dev.fwnode == conn->child_fwnode) {
 			iterator->orphan = true;
-			conn->child_dev = NULL;
+			coresight_remove_links(iterator, conn);
 			/*
 			 * Drop the reference to the handle for the remote
 			 * device acquired in parsing the connections from
@@ -1177,10 +1267,18 @@ void coresight_release_platform_data(struct coresight_device *csdev,
 				     struct coresight_platform_data *pdata)
 {
 	int i;
+	struct coresight_connection *conns = pdata->conns;
 
 	for (i = 0; i < pdata->nr_outport; i++) {
-		if (pdata->conns[i].child_fwnode) {
-			fwnode_handle_put(pdata->conns[i].child_fwnode);
+		/* If we have made the links, remove them now */
+		if (csdev && conns[i].child_dev)
+			coresight_remove_links(csdev, &conns[i]);
+		/*
+		 * Drop the refcount and clear the handle as this device
+		 * is going away
+		 */
+		if (conns[i].child_fwnode) {
+			fwnode_handle_put(conns[i].child_fwnode);
 			pdata->conns[i].child_fwnode = NULL;
 		}
 	}
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index a2b6882..057c7d8 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -130,12 +130,16 @@ struct coresight_desc {
  * @chid_fwnode: remote component's fwnode handle.
  * @child_dev:	a @coresight_device representation of the component
 		connected to @outport.
+ * @inlink_name: Name for the "input" link
+ * @outlink_name: Name for the "output" link
  */
 struct coresight_connection {
 	int outport;
 	int child_port;
 	struct fwnode_handle *child_fwnode;
 	struct coresight_device *child_dev;
+	const char *inlink_name;
+	const char *outlink_name;
 };
 
 /**
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] coresight: Expose device connections via sysfs
  2019-05-30 16:44 [PATCH 0/3] coresight: Expose device connections via sysfs Suzuki K Poulose
                   ` (2 preceding siblings ...)
  2019-05-30 16:44 ` [PATCH 3/3] coresight: Expose device connections via sysfs Suzuki K Poulose
@ 2019-06-03  8:45 ` Leo Yan
  3 siblings, 0 replies; 5+ messages in thread
From: Leo Yan @ 2019-06-03  8:45 UTC (permalink / raw)
  To: Suzuki K Poulose; +Cc: coresight, mathieu.poirier, linux-arm-kernel, mike.leach

Hi Suzuki,

On Thu, May 30, 2019 at 05:44:54PM +0100, Suzuki K Poulose wrote:
> Coresight device connections are a bit complicated and is not
> exposed currently to the user. One has to look at the platform
> descriptions (DT bindings or ACPI bindings) to make an understanding.
> Given the new naming scheme, it will be helpful to have this information
> to choose the appropriate devices for tracing. This patch exposes
> the device connections via links in the sysfs directories.
> 
> e.g, for a connection devA[OutputPort_X] -> devB[InputPort_Y]
> is represented as two symlinks:
> 
>   /sys/bus/coresight/.../devA/out:X -> /sys/bus/coresight/.../devB
>   /sys/bus/coresight/.../devB/in:Y  -> /sys/bus/coresight/.../devA
> 
> Applies on coresight/next tree.
> 
> This is split from the ACPI bindings series. No functional changes.

I tested this patch set and it works well as expected on my Juno board.

FWIW:

Tested-by: Leo Yan <leo.yan@linaro.org>


> Suzuki K Poulose (3):
>   coresight: Pass coresight_device for coresight_release_platform_data
>   coresight: add return value for fixup connections
>   coresight: Expose device connections via sysfs
> 
>  drivers/hwtracing/coresight/coresight-platform.c |   2 +-
>  drivers/hwtracing/coresight/coresight-priv.h     |   3 +-
>  drivers/hwtracing/coresight/coresight.c          | 148 +++++++++++++++++++----
>  include/linux/coresight.h                        |   4 +
>  4 files changed, 132 insertions(+), 25 deletions(-)
> 
> -- 
> 2.7.4
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-03  8:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-30 16:44 [PATCH 0/3] coresight: Expose device connections via sysfs Suzuki K Poulose
2019-05-30 16:44 ` [PATCH 1/3] coresight: Pass coresight_device for coresight_release_platform_data Suzuki K Poulose
2019-05-30 16:44 ` [PATCH 2/3] coresight: add return value for fixup connections Suzuki K Poulose
2019-05-30 16:44 ` [PATCH 3/3] coresight: Expose device connections via sysfs Suzuki K Poulose
2019-06-03  8:45 ` [PATCH 0/3] " Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox