linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, coresight@lists.linaro.org,
	mathieu.poirier@linaro.org, mike.leach@linaro.org,
	rjw@rjwysocki.net, robert.walker@arm.com,
	Suzuki K Poulose <suzuki.poulose@arm.com>
Subject: [PATCH v2 29/36] coresight: Use fwnode handle instead of device names
Date: Mon, 15 Apr 2019 17:04:12 +0100	[thread overview]
Message-ID: <1555344260-12375-30-git-send-email-suzuki.poulose@arm.com> (raw)
In-Reply-To: <1555344260-12375-1-git-send-email-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.

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

diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 318a6ff..c9a59fb 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -214,9 +214,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 c216421..61d7f9f 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -200,8 +200,6 @@ 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);
 
 #endif
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 82fb411..5169ce1 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -976,6 +976,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);
 }
@@ -1007,13 +1008,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;
-			}
 		}
 	}
 
@@ -1045,9 +1044,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,
+				      device_fwnode_match);
 		if (dev) {
 			conn->child_dev = to_coresight_device(dev);
 			/* and put reference from 'bus_find_device()' */
@@ -1082,9 +1081,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;
 		}
@@ -1164,6 +1169,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 = 0;
+		}
+	}
+}
+
 struct coresight_device *coresight_register(struct coresight_desc *desc)
 {
 	int ret;
@@ -1208,6 +1229,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 8c10def..188e759 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.7.4


  parent reply	other threads:[~2019-04-15 16:07 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15 16:03 [PATCH v2 00/36] coresight: Support for ACPI bindings Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 01/36] coresight: Fix freeing up the coresight connections Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 02/36] coresight: etb10: Cleanup power management Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 03/36] coresight: tpiu: " Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 04/36] coresight: catu: " Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 05/36] coresight: tmc: " Suzuki K Poulose
2019-04-17 20:03   ` Mathieu Poirier
2019-04-23  9:33     ` Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 06/36] coresight: funnel: Clean up device book keeping Suzuki K Poulose
2019-04-17 20:14   ` Mathieu Poirier
2019-04-15 16:03 ` [PATCH v2 07/36] coresight: replicator: Cleanup device tracking Suzuki K Poulose
2019-04-17 20:34   ` Mathieu Poirier
2019-04-15 16:03 ` [PATCH v2 08/36] coresight: tmc: Clean up device specific data Suzuki K Poulose
2019-04-17 21:23   ` Mathieu Poirier
2019-05-03 17:13     ` Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 09/36] coresight: catu: Cleanup " Suzuki K Poulose
2019-04-17 21:40   ` Mathieu Poirier
2019-04-15 16:03 ` [PATCH v2 10/36] coresight: tpiu: Clean up " Suzuki K Poulose
2019-04-17 21:41   ` Mathieu Poirier
2019-04-15 16:03 ` [PATCH v2 11/36] coresight: stm: Cleanup " Suzuki K Poulose
2019-04-18 16:50   ` Mathieu Poirier
2019-04-15 16:03 ` [PATCH v2 12/36] coresight: etm: Clean up " Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 13/36] coresight: etb10: " Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 14/36] coresight: Rename of_coresight to coresight-platform Suzuki K Poulose
2019-04-18 17:22   ` Mathieu Poirier
2019-04-15 16:03 ` [PATCH v2 15/36] coresight: etm3x: Rearrange cp14 access detection Suzuki K Poulose
2019-04-15 16:03 ` [PATCH v2 16/36] coresight: stm: Rearrange probing the stimulus area Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 17/36] coresight: tmc-etr: Rearrange probing default buffer size Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 18/36] coresight: platform: Make memory allocation helper generic Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 19/36] coresight: Introduce generic platform data helper Suzuki K Poulose
2019-04-22 18:09   ` Mathieu Poirier
2019-04-23  9:43     ` Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 20/36] coresight: Make device to CPU mapping generic Suzuki K Poulose
2019-04-18 18:14   ` Mathieu Poirier
2019-04-15 16:04 ` [PATCH v2 21/36] coresight: Remove cpu field from platform data Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 22/36] coresight: Remove name from platform description Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 23/36] coresight: Cleanup coresight_remove_conns Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 24/36] coresight: Reuse platform data structure for connection tracking Suzuki K Poulose
2019-04-22 17:06   ` Mathieu Poirier
2019-04-15 16:04 ` [PATCH v2 25/36] coresight: Rearrange platform data probing Suzuki K Poulose
2019-04-22 17:16   ` Mathieu Poirier
2019-04-25 17:12     ` Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 26/36] coresight: Add support for releasing platform specific data Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 27/36] drivers: Add a generic helper to match device by fwnode handle Suzuki K Poulose
2019-04-16 10:20   ` Rafael J. Wysocki
2019-04-16 10:34     ` Suzuki K Poulose
2019-04-16 10:45       ` Rafael J. Wysocki
2019-04-16 10:39   ` [RESEND][PATCH " Suzuki K Poulose
2019-04-16 10:48     ` Rafael J. Wysocki
2019-04-16 10:56       ` Suzuki K Poulose
2019-04-18 14:39         ` Rafael J. Wysocki
2019-04-18 15:18           ` Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 28/36] coresight: platform: Use fwnode handle for device search Suzuki K Poulose
2019-04-23 16:17   ` Mathieu Poirier
2019-04-15 16:04 ` Suzuki K Poulose [this message]
2019-04-23 16:14   ` [PATCH v2 29/36] coresight: Use fwnode handle instead of device names Mathieu Poirier
2019-04-15 16:04 ` [PATCH v2 30/36] coresight: Use platform agnostic names Suzuki K Poulose
2019-04-23 17:38   ` Mathieu Poirier
2019-04-15 16:04 ` [PATCH v2 31/36] coresight: stm: ACPI support for parsing stimulus base Suzuki K Poulose
2019-04-23 17:59   ` Mathieu Poirier
2019-04-25 16:17     ` Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 32/36] coresight: Support for ACPI bindings Suzuki K Poulose
2019-04-25 16:50   ` Mathieu Poirier
2019-04-25 17:30     ` Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 33/36] coresight: acpi: Support for components Suzuki K Poulose
2019-04-25 17:45   ` Mathieu Poirier
2019-04-29  8:54     ` Suzuki K Poulose
2019-04-15 16:04 ` [PATCH v2 34/36] [RFC] coresight: Pass coresight_device for coresight_release_platform_data Suzuki K Poulose
2019-04-29 17:40   ` Mathieu Poirier
2019-04-15 16:04 ` [PATCH v2 35/36] [RFC] coresight: add return value for fixup connections Suzuki K Poulose
2019-04-29 17:44   ` Mathieu Poirier
2019-04-15 16:04 ` [PATCH v2 36/36] [RFC] coresight: Expose device connections via sysfs Suzuki K Poulose
2019-04-29 20:50   ` Mathieu Poirier
2019-04-15 16:04 ` [TEST PATCH 37/36][EDK2] edk2-platform: juno: Update ACPI CoreSight Bindings Suzuki K Poulose

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=1555344260-12375-30-git-send-email-suzuki.poulose@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=coresight@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=rjw@rjwysocki.net \
    --cc=robert.walker@arm.com \
    /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).