From patchwork Mon Apr 15 16:04:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 162223 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3106968jan; Mon, 15 Apr 2019 09:07:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqylAthaCGbnKVEbeCFi9R127NqpGPhxSoJ7ziZjGcvVt7KhKEeH3zugOXy81gzG1mC8E/7x X-Received: by 2002:a17:902:2bc9:: with SMTP id l67mr59333390plb.237.1555344446788; Mon, 15 Apr 2019 09:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555344446; cv=none; d=google.com; s=arc-20160816; b=Evwa/ldmklQt7gU3+ZLruV/BFWRa+0zVver9mTsAhjQdJEMXUduDjIhK9w26royNk1 qoDO/rxdW3QTiLUmiE+yIlo9ohwWRyoY6VpAA6utACqkTgSk0c2un/WqyHeGXG0x1Q14 p0fTQtrH0Y6FrrUxanZkG/pbdTHOnFj5A4d/4l9Isjrv+9hwVDIPz3TujZWMXJ8jE1iF 2Tz4d/eOdPtC+fQNe8tFig0tadQnZ5zC1c9dD+MIGYyzHCjmJsg6W5UJRKuj6S4pgCvi psaJC7egvpcBEwaLH+9DH4dE+/WSEogxPFFcVEpW0HkTWiSpxT3LKCGnYzZAOBCN9zvZ Sb9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=N7UJ5/U3Qc6TQKdtlYq5UFT0iF+7WgxU86vP7uQ/uSM=; b=rqbHHV8CBcjSEE35Cowr47U0d93eWvPfLJExe12HkelFDZFTZ32WoVZL2VngKUGJKo 2m7K3CBJ862lHav0+yxIecEyUIk9qV9C78ncJVXOlSryStYg/PUoZ2IC6wME+8DVU32Y DusliP/b6tUDJY5EmF38htfuO4lx3K1NmF+tDDKfCW7pMWrrZ261HOUcMFpyWCO/ny9/ frdZrg5L5cvPwaxvmXVuPq4qkKcXQoRh2dEt43Z3gYDnsqkxgC+dXfn76IjhXhf9iM0/ zewB5iaqfJoSw7OAuznIQwKe8S9PCO/3l9VD+nGPFwtih03oxKa4B7oUXPZ33wt2/E6B q9FA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i195si45006724pgd.521.2019.04.15.09.07.26; Mon, 15 Apr 2019 09:07:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728087AbfDOQGi (ORCPT + 30 others); Mon, 15 Apr 2019 12:06:38 -0400 Received: from foss.arm.com ([217.140.101.70]:38036 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728069AbfDOQGg (ORCPT ); Mon, 15 Apr 2019 12:06:36 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F40F41AC1; Mon, 15 Apr 2019 09:06:35 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.196.93]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7A2693F68F; Mon, 15 Apr 2019 09:06:34 -0700 (PDT) From: Suzuki K Poulose 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 Subject: [PATCH v2 29/36] coresight: Use fwnode handle instead of device names Date: Mon, 15 Apr 2019 17:04:12 +0100 Message-Id: <1555344260-12375-30-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555344260-12375-1-git-send-email-suzuki.poulose@arm.com> References: <1555344260-12375-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Suzuki K Poulose --- 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(-) -- 2.7.4 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; };