linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: gregkh@linuxfoundation.org
Cc: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 13/28] coresight: Use fwnode handle instead of device names
Date: Wed, 19 Jun 2019 13:53:03 -0600	[thread overview]
Message-ID: <20190619195318.19254-14-mathieu.poirier@linaro.org> (raw)
In-Reply-To: <20190619195318.19254-1-mathieu.poirier@linaro.org>

From: Suzuki K Poulose <suzuki.poulose@arm.com>

We rely on the device names to find a CoreSight device on the
coresight bus. The device name however is obtained from the platform,
which is bound to the real platform/amba device. As we are about
to use different naming scheme for the coresight devices, we can't
rely on the platform device name to find the corresponding
coresight device. Instead we use the platform agnostic
"fwnode handle" of the parent device to find the devices.
We also reuse the same fwnode as the parent for the Coresight
device we create.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 .../hwtracing/coresight/coresight-platform.c  | 14 +++++--
 drivers/hwtracing/coresight/coresight-priv.h  |  6 +--
 drivers/hwtracing/coresight/coresight.c       | 42 +++++++++++++++----
 include/linux/coresight.h                     |  4 +-
 4 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 4394095ad224..49112a58478e 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -36,7 +36,7 @@ static int coresight_alloc_conns(struct device *dev,
 	return 0;
 }
 
-static int coresight_device_fwnode_match(struct device *dev, void *fwnode)
+int coresight_device_fwnode_match(struct device *dev, void *fwnode)
 {
 	return dev_fwnode(dev) == fwnode;
 }
@@ -219,9 +219,15 @@ static int of_coresight_parse_endpoint(struct device *dev,
 		}
 
 		conn->outport = endpoint.port;
-		conn->child_name = devm_kstrdup(dev,
-						dev_name(rdev),
-						GFP_KERNEL);
+		/*
+		 * Hold the refcount to the target device. This could be
+		 * released via:
+		 * 1) coresight_release_platform_data() if the probe fails or
+		 *    this device is unregistered.
+		 * 2) While removing the target device via
+		 *    coresight_remove_match()
+		 */
+		conn->child_fwnode = fwnode_handle_get(rdev_fwnode);
 		conn->child_port = rendpoint.port;
 		/* Connection record updated */
 		ret = 1;
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index c21642114fc3..8b07fe55395a 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -200,8 +200,8 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
 	return 0;
 }
 
-static inline void
-coresight_release_platform_data(struct coresight_platform_data *pdata)
-{}
+void coresight_release_platform_data(struct coresight_platform_data *pdata);
+
+int coresight_device_fwnode_match(struct device *dev, void *fwnode);
 
 #endif
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 526141c2f876..1287778c3be5 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -978,6 +978,7 @@ static void coresight_device_release(struct device *dev)
 {
 	struct coresight_device *csdev = to_coresight_device(dev);
 
+	fwnode_handle_put(csdev->dev.fwnode);
 	kfree(csdev->refcnt);
 	kfree(csdev);
 }
@@ -1009,13 +1010,11 @@ 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_name &&
-			    !strcmp(dev_name(&csdev->dev), conn->child_name)) {
+			if (conn->child_fwnode == csdev->dev.fwnode)
 				conn->child_dev = csdev;
-			} else {
+			else
 				/* This component still has an orphan */
 				still_orphan = true;
-			}
 		}
 	}
 
@@ -1047,9 +1046,9 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
 		struct coresight_connection *conn = &csdev->pdata->conns[i];
 		struct device *dev = NULL;
 
-		if (conn->child_name)
-			dev = bus_find_device_by_name(&coresight_bustype, NULL,
-						      conn->child_name);
+		dev = bus_find_device(&coresight_bustype, NULL,
+				      (void *)conn->child_fwnode,
+				      coresight_device_fwnode_match);
 		if (dev) {
 			conn->child_dev = to_coresight_device(dev);
 			/* and put reference from 'bus_find_device()' */
@@ -1084,9 +1083,15 @@ static int coresight_remove_match(struct device *dev, void *data)
 		if (conn->child_dev == NULL)
 			continue;
 
-		if (!strcmp(dev_name(&csdev->dev), conn->child_name)) {
+		if (csdev->dev.fwnode == conn->child_fwnode) {
 			iterator->orphan = true;
 			conn->child_dev = NULL;
+			/*
+			 * Drop the reference to the handle for the remote
+			 * device acquired in parsing the connections from
+			 * platform data.
+			 */
+			fwnode_handle_put(conn->child_fwnode);
 			/* No need to continue */
 			break;
 		}
@@ -1166,6 +1171,22 @@ static int __init coresight_init(void)
 }
 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)
+{
+	int i;
+
+	for (i = 0; i < pdata->nr_outport; i++) {
+		if (pdata->conns[i].child_fwnode) {
+			fwnode_handle_put(pdata->conns[i].child_fwnode);
+			pdata->conns[i].child_fwnode = NULL;
+		}
+	}
+}
+
 struct coresight_device *coresight_register(struct coresight_desc *desc)
 {
 	int ret;
@@ -1210,6 +1231,11 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	csdev->dev.parent = desc->dev;
 	csdev->dev.release = coresight_device_release;
 	csdev->dev.bus = &coresight_bustype;
+	/*
+	 * Hold the reference to our parent device. This will be
+	 * dropped only in coresight_device_release().
+	 */
+	csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev));
 	dev_set_name(&csdev->dev, "%s", desc->name);
 
 	ret = device_register(&csdev->dev);
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index b67d5074ece0..b40544bc06fe 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -126,15 +126,15 @@ struct coresight_desc {
 /**
  * struct coresight_connection - representation of a single connection
  * @outport:	a connection's output port number.
- * @chid_name:	remote component's name.
  * @child_port:	remote component's port number @output is connected to.
+ * @chid_fwnode: remote component's fwnode handle.
  * @child_dev:	a @coresight_device representation of the component
 		connected to @outport.
  */
 struct coresight_connection {
 	int outport;
-	const char *child_name;
 	int child_port;
+	struct fwnode_handle *child_fwnode;
 	struct coresight_device *child_dev;
 };
 
-- 
2.17.1


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

  parent reply	other threads:[~2019-06-19 19:58 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19 19:52 [PATCH 00/28] coresight: next v5.2-rc5 (V2) Mathieu Poirier
2019-06-19 19:52 ` [PATCH 01/28] coresight: Rename of_coresight to coresight-platform Mathieu Poirier
2019-06-19 19:52 ` [PATCH 02/28] coresight: platform: Make memory allocation helper generic Mathieu Poirier
2019-06-19 19:52 ` [PATCH 03/28] coresight: Make sure device uses DT for obsolete compatible check Mathieu Poirier
2019-06-19 19:52 ` [PATCH 04/28] coresight: Introduce generic platform data helper Mathieu Poirier
2019-06-19 19:52 ` [PATCH 05/28] coresight: Make device to CPU mapping generic Mathieu Poirier
2019-06-19 19:52 ` [PATCH 06/28] coresight: Remove cpu field from platform data Mathieu Poirier
2019-06-19 19:52 ` [PATCH 07/28] coresight: Remove name from platform description Mathieu Poirier
2019-06-19 19:52 ` [PATCH 08/28] coresight: Cleanup coresight_remove_conns Mathieu Poirier
2019-06-19 19:52 ` [PATCH 09/28] coresight: Reuse platform data structure for connection tracking Mathieu Poirier
2019-06-19 19:53 ` [PATCH 10/28] coresight: Rearrange platform data probing Mathieu Poirier
2019-06-19 19:53 ` [PATCH 11/28] coresight: Add support for releasing platform specific data Mathieu Poirier
2019-06-19 19:53 ` [PATCH 12/28] coresight: platform: Use fwnode handle for device search Mathieu Poirier
2019-06-19 19:53 ` Mathieu Poirier [this message]
2019-06-19 19:53 ` [PATCH 14/28] coresight: Use platform agnostic names Mathieu Poirier
2019-06-19 19:53 ` [PATCH 15/28] coresight: stm: ACPI support for parsing stimulus base Mathieu Poirier
2019-06-19 19:53 ` [PATCH 16/28] coresight: Support for ACPI bindings Mathieu Poirier
2019-06-19 19:53 ` [PATCH 17/28] coresight: acpi: Support for AMBA components Mathieu Poirier
2019-06-19 19:53 ` [PATCH 18/28] coresight: acpi: Support for platform devices Mathieu Poirier
2019-06-19 19:53 ` [PATCH 19/28] coresight: Add dummy definition for of_coresight_get_cpu() Mathieu Poirier
2019-06-19 19:53 ` [PATCH 20/28] coresight: tmc-etr: Do not call smp_processor_id() from preemptible Mathieu Poirier
2019-06-20  6:02   ` Greg KH
2019-06-19 19:53 ` [PATCH 21/28] coresight: tmc-etr: alloc_perf_buf: Do not call smp_processor_id " Mathieu Poirier
2019-06-20  6:03   ` Greg KH
2019-06-19 19:53 ` [PATCH 22/28] coresight: tmc-etf: " Mathieu Poirier
2019-06-20  6:03   ` Greg KH
2019-06-19 19:53 ` [PATCH 23/28] coresight: etb10: " Mathieu Poirier
2019-06-20  6:04   ` Greg KH
2019-06-19 19:53 ` [PATCH 24/28] coresight: Potential uninitialized variable in probe() Mathieu Poirier
2019-06-20  6:04   ` Greg KH
2019-06-19 19:53 ` [PATCH 25/28] coresight: etm3x: Smatch: Fix potential NULL pointer dereference Mathieu Poirier
2019-06-20  6:04   ` Greg KH
2019-06-20 21:38     ` Mathieu Poirier
2019-06-21  6:59       ` Greg KH
2019-06-19 19:53 ` [PATCH 26/28] coresight: tmc: " Mathieu Poirier
2019-06-20  6:05   ` Greg KH
2019-06-20 21:42     ` Mathieu Poirier
2019-06-21  6:59       ` Greg KH
2019-06-19 19:53 ` [PATCH 27/28] coresight: platform: add OF/APCI dependency Mathieu Poirier
2019-06-19 19:53 ` [PATCH 28/28] coresight: replicator: Add terminate entry for acpi_device_id tables Mathieu Poirier
2019-06-20  6:08 ` [PATCH 00/28] coresight: next v5.2-rc5 (V2) Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190619195318.19254-14-mathieu.poirier@linaro.org \
    --to=mathieu.poirier@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).