From patchwork Fri Mar 10 16:06:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13169876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3F12C6FA99 for ; Fri, 10 Mar 2023 17:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OWxfraW4T4Ew/v4WeFFf2ZZgZmkPgFc1RIgHMfAaDW0=; b=rwkgjWp7pSrjLl NjltsGxlNbhlg9+bQCmyeSLa/YUzI9Ta/NueRxjmyRVTyxacTUElZlUXdOmqwjTAakmAjVXJEelNg ZYJcLVq8wWMBzzQnflf22CnD9SNRinPEBnuG1iwx8pOkFvg+lp5ajjqrOOcy+yh1inqUMo+ZNIadS ehwAeZOgz5qo+qO2kwfeaWMTzrEFTKkQYAjoAllLjm+TDx7e+HZLuMmB3TElGCih6ZdnXSiq7k63Y x6PnaA4UJKMoJ/72fafJSSL0pmc9mTetKmZ353/nACcewE6lngYj9galswTD1s47lnpN0jJn/hH0k SBsvPWrc2oxLbo/p5X3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pagpD-00FeVW-PJ; Fri, 10 Mar 2023 17:46:39 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pafsI-00FLvF-7e for linux-arm-kernel@bombadil.infradead.org; Fri, 10 Mar 2023 16:45:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=aGRvib40OL8KUlyWl+MfYpfzSTL5N1QxU0edY0dLiXE=; b=ERsgVCWPmS7VJH5uhAvS+R5AEz S5cPQwZ2VPCgEtqG7S1evIneLqABgipyP3LN+iySF/mdlyPNZUMuTktHlUptbjI2NjI5rVx4NDvXZ /S1a4y+4abLLXGa6bq2zsTON0CK+kthtkq1CSwAsE6XE6WMtLLyohbTgqahvytm0+GE3z0tili+gh j8ZRT3Ih5M6D0tVhzR61o8I6VElQkPhvSDOtiICyi//xTUHliS4bxD7zsyBSEuK3gn3Uq1Re1GXj2 jDA/gLq8MkZdiAgRICPdCnV96d2ke5/YUm9yhKThTYES2P0hKi70IwSCcKR475UptjLNSiNxeG+hR TvxMBlCw==; Received: from foss.arm.com ([217.140.110.172]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pafGn-000VjP-2t for linux-arm-kernel@lists.infradead.org; Fri, 10 Mar 2023 16:07:04 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DBBA61762; Fri, 10 Mar 2023 08:07:42 -0800 (PST) Received: from e127643.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0566E3F5A1; Fri, 10 Mar 2023 08:06:57 -0800 (PST) From: James Clark To: coresight@lists.linaro.org Cc: James Clark , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , Alexander Shishkin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/9] coresight: Dynamically add connections Date: Fri, 10 Mar 2023 16:06:04 +0000 Message-Id: <20230310160610.742382-6-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230310160610.742382-1-james.clark@arm.com> References: <20230310160610.742382-1-james.clark@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230310_160702_362038_27F42CC9 X-CRM114-Status: GOOD ( 23.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a function for adding connections dynamically. This also removes the 1:1 mapping between port number and the index into the connections array. The only place this mapping was used was in the warning for duplicate output ports, which has been replaced by a search. Other uses of the port number already use the port member variable. Being able to dynamically add connections will allow other devices like CTI to re-use the connection mechanism despite not having explicit connections described in the DT. Signed-off-by: James Clark --- .../hwtracing/coresight/coresight-platform.c | 77 ++++++++++++++----- include/linux/coresight.h | 7 +- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c index c77238cdf448..16553f7dde12 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c @@ -27,8 +27,9 @@ static int coresight_alloc_conns(struct device *dev, struct coresight_platform_data *pdata) { if (pdata->nr_outconns) { - pdata->out_conns = devm_kcalloc(dev, pdata->nr_outconns, - sizeof(*pdata->out_conns), GFP_KERNEL); + pdata->out_conns = devm_krealloc_array( + dev, pdata->out_conns, pdata->nr_outconns, + sizeof(*pdata->out_conns), GFP_KERNEL | __GFP_ZERO); if (!pdata->out_conns) return -ENOMEM; } @@ -36,6 +37,48 @@ static int coresight_alloc_conns(struct device *dev, return 0; } +/* + * Add a connection in the first free slot, or realloc + * if there is no space. @conn's contents is copied into the new slot. + * + * If the output port is already assigned on this device, return -EINVAL + */ +int coresight_add_conn(struct device *dev, + struct coresight_platform_data *pdata, + const struct coresight_connection *conn) +{ + int ret; + struct coresight_connection *free_conn = NULL; + struct coresight_connection *i; + + /* + * Search for a free slot, and while looking for one, warn + * on any existing duplicate output port. + */ + for (i = pdata->out_conns; i < pdata->out_conns + pdata->nr_outconns; + ++i) { + if (i->remote_fwnode && conn->port != -1 && + i->port == conn->port) { + dev_warn(dev, "Duplicate output port %d\n", i->port); + return -EINVAL; + } + if (!i->remote_fwnode && !free_conn) + free_conn = i; + } + + if (!free_conn) { + pdata->nr_outconns++; + ret = coresight_alloc_conns(dev, pdata); + if (ret) + return ret; + free_conn = &pdata->out_conns[pdata->nr_outconns - 1]; + } + + *free_conn = *conn; + return 0; +} +EXPORT_SYMBOL_GPL(coresight_add_conn); + static struct device * coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) { @@ -224,7 +267,7 @@ static int of_coresight_parse_endpoint(struct device *dev, struct device_node *rep = NULL; struct device *rdev = NULL; struct fwnode_handle *rdev_fwnode; - struct coresight_connection *conn; + struct coresight_connection conn; do { /* Parse the local port details */ @@ -251,14 +294,7 @@ static int of_coresight_parse_endpoint(struct device *dev, break; } - conn = &pdata->out_conns[endpoint.port]; - if (conn->remote_fwnode) { - dev_warn(dev, "Duplicate output port %d\n", - endpoint.port); - ret = -EINVAL; - break; - } - conn->port = endpoint.port; + conn.port = endpoint.port; /* * Hold the refcount to the target device. This could be * released via: @@ -267,8 +303,14 @@ static int of_coresight_parse_endpoint(struct device *dev, * 2) While removing the target device via * coresight_remove_match() */ - conn->remote_fwnode = fwnode_handle_get(rdev_fwnode); - conn->remote_port = rendpoint.port; + conn.remote_fwnode = fwnode_handle_get(rdev_fwnode); + conn.remote_port = rendpoint.port; + + ret = coresight_add_conn(dev, pdata, &conn); + if (ret) { + fwnode_handle_put(conn.remote_fwnode); + return ret; + } /* Connection record updated */ } while (0); @@ -741,13 +783,10 @@ static int acpi_coresight_parse_graph(struct acpi_device *adev, /* Copy the connection information to the final location */ for (i = 0; conns + i < ptr; i++) { - int port = conns[i].port; - - /* Duplicate output port */ - WARN_ON(pdata->out_conns[port].remote_fwnode); - pdata->out_conns[port] = conns[i]; + rc = coresight_add_conn(&adev->dev, pdata, &conns[i]); + if (rc) + return rc; } - devm_kfree(&adev->dev, conns); return 0; } diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 64bb5fc95afa..47fa58d6981d 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -173,7 +173,9 @@ struct coresight_desc { * on the remote device. * @remote_fwnode: remote component's fwnode handle. * @remote_dev: a @coresight_device representation of the component - * connected to @port. + * connected to @port. Will be looked up using + * @remote_fwnode once the remote's coresight_device has + * been created. * @link: Representation of the connection as a sysfs link. */ struct coresight_connection { @@ -614,5 +616,8 @@ static inline void coresight_write64(struct coresight_device *csdev, u64 val, u3 extern int coresight_get_cpu(struct device *dev); struct coresight_platform_data *coresight_get_platform_data(struct device *dev); +int coresight_add_conn(struct device *dev, + struct coresight_platform_data *pdata, + const struct coresight_connection *conn); #endif /* _LINUX_COREISGHT_H */