Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp487163rwl; Wed, 29 Mar 2023 04:59:20 -0700 (PDT) X-Google-Smtp-Source: AKy350bZ1xloTSBl2wRPXRLN/koqT78oxCYX/PnCNYGksrFN3gH7D3V/VNmEpjuKzAtJQ8Mzuoto X-Received: by 2002:a17:906:18a9:b0:92f:e4c5:5a28 with SMTP id c9-20020a17090618a900b0092fe4c55a28mr21385763ejf.54.1680091160306; Wed, 29 Mar 2023 04:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680091160; cv=none; d=google.com; s=arc-20160816; b=PU1zDU487Ed9+x6eU55hgGzGQra0VZ2gXb69zRByKP6WjhUCHwFA1ev+DuZ8vhncPe VU6WxcyXCL3scBbCVaq+E3HR3LK4xgm4JqxNPI3exdS5yW/KBJT5CYfstcufZSybePE9 sNnE40Gjn+niE+hkU4otl9yVnwM0/Twtl6AvKHbCi6bGkwp9VSojPG6t5cLGfTPtJfea VzS6Lqi6NxD52eMmYvq5ZC1qIasUqAU2DYjQUCrVPGOp3r34zEo2fFtwC10JGocQkX1c jReHBErdmhZN5ZBji6r0E9pHj71RDY3OxZ6S7rYK+lrZXCGmVuWyG+0//n5nxb8DR0ST KvzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=x7hFT1O7Zb0qnn534KR+v1Eg5+EOk4hMPwWwR6CVIGE=; b=Dy8LMhB9ecm72gP8bJN3qiOUSxdeLUlnwqOgUYDbF7dm8tnxfQuRIacGBhv6Vr45E+ 07nMwl/DjKFLz4DWJaiOmt4iRSM/ht6tAZfr5x/vyMUecd0TmBozLmKPO36YX6osWkOE 3ATAhPNDtCeJMwDlVocUnNxywc0mR2SEuREEBkNfi6mcTr7+eFiU5bh1F1iNmw4A0Fgu jacPp7CNlln0XFy4Vo5xr+S2ADRUFei6VeZRXSxDaFuizOJDDDonDL4t2Bq/9+9v2bkq GZfp2+kHloYjq41rgArb/tdMEuZEPM4BJr2OFz8q9Ev3CeK+0VptKvANk4R9lYQz1Q27 emTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a50fb81000000b005021f0d575esi15654006edq.677.2023.03.29.04.58.55; Wed, 29 Mar 2023 04:59:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbjC2Lyv (ORCPT + 99 others); Wed, 29 Mar 2023 07:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbjC2Lyj (ORCPT ); Wed, 29 Mar 2023 07:54:39 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A13674C2C for ; Wed, 29 Mar 2023 04:54:19 -0700 (PDT) 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 B14D8152B; Wed, 29 Mar 2023 04:55:03 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A46BF3F6C4; Wed, 29 Mar 2023 04:54:17 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, quic_jinlmao@quicinc.com, mike.leach@linaro.org, suzuki.poulose@arm.com Cc: James Clark , Mathieu Poirier , Leo Yan , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH v3 07/13] coresight: Store pointers to connections rather than an array of them Date: Wed, 29 Mar 2023 12:53:20 +0100 Message-Id: <20230329115329.2747724-8-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230329115329.2747724-1-james.clark@arm.com> References: <20230329115329.2747724-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This will allow the same connection object to be referenced via the input connection list in a later commit rather than duplicating them. Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-core.c | 45 ++++++++++--------- .../hwtracing/coresight/coresight-platform.c | 8 ++-- drivers/hwtracing/coresight/coresight-priv.h | 1 + .../hwtracing/coresight/coresight-tmc-etr.c | 2 +- include/linux/coresight.h | 2 +- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 12cbb68e8e1c..389f6203c8f0 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -119,7 +119,7 @@ static int coresight_find_link_inport(struct coresight_device *csdev, struct coresight_connection *conn; for (i = 0; i < parent->pdata->nr_outconns; i++) { - conn = &parent->pdata->out_conns[i]; + conn = parent->pdata->out_conns[i]; if (conn->dest_dev == csdev) return conn->dest_port; } @@ -137,7 +137,7 @@ static int coresight_find_link_outport(struct coresight_device *csdev, struct coresight_connection *conn; for (i = 0; i < csdev->pdata->nr_outconns; i++) { - conn = &csdev->pdata->out_conns[i]; + conn = csdev->pdata->out_conns[i]; if (conn->dest_dev == child) return conn->src_port; } @@ -606,7 +606,7 @@ coresight_find_enabled_sink(struct coresight_device *csdev) for (i = 0; i < csdev->pdata->nr_outconns; i++) { struct coresight_device *child_dev; - child_dev = csdev->pdata->out_conns[i].dest_dev; + child_dev = csdev->pdata->out_conns[i]->dest_dev; if (child_dev) sink = coresight_find_enabled_sink(child_dev); if (sink) @@ -722,7 +722,7 @@ static int coresight_grab_device(struct coresight_device *csdev) for (i = 0; i < csdev->pdata->nr_outconns; i++) { struct coresight_device *child; - child = csdev->pdata->out_conns[i].dest_dev; + child = csdev->pdata->out_conns[i]->dest_dev; if (child && child->type == CORESIGHT_DEV_TYPE_HELPER) if (!coresight_get_ref(child)) goto err; @@ -733,7 +733,7 @@ static int coresight_grab_device(struct coresight_device *csdev) for (i--; i >= 0; i--) { struct coresight_device *child; - child = csdev->pdata->out_conns[i].dest_dev; + child = csdev->pdata->out_conns[i]->dest_dev; if (child && child->type == CORESIGHT_DEV_TYPE_HELPER) coresight_put_ref(child); } @@ -752,7 +752,7 @@ static void coresight_drop_device(struct coresight_device *csdev) for (i = 0; i < csdev->pdata->nr_outconns; i++) { struct coresight_device *child; - child = csdev->pdata->out_conns[i].dest_dev; + child = csdev->pdata->out_conns[i]->dest_dev; if (child && child->type == CORESIGHT_DEV_TYPE_HELPER) coresight_put_ref(child); } @@ -794,7 +794,7 @@ static int _coresight_build_path(struct coresight_device *csdev, for (i = 0; i < csdev->pdata->nr_outconns; i++) { struct coresight_device *child_dev; - child_dev = csdev->pdata->out_conns[i].dest_dev; + child_dev = csdev->pdata->out_conns[i]->dest_dev; if (child_dev && _coresight_build_path(child_dev, sink, path) == 0) { found = true; @@ -964,7 +964,7 @@ coresight_find_sink(struct coresight_device *csdev, int *depth) struct coresight_device *child_dev, *sink = NULL; int child_depth = curr_depth; - child_dev = csdev->pdata->out_conns[i].dest_dev; + child_dev = csdev->pdata->out_conns[i]->dest_dev; if (child_dev) sink = coresight_find_sink(child_dev, &child_depth); @@ -1334,7 +1334,7 @@ static int coresight_orphan_match(struct device *dev, void *data) * an orphan connection whose name matches @csdev, link it. */ for (i = 0; i < i_csdev->pdata->nr_outconns; i++) { - conn = &i_csdev->pdata->out_conns[i]; + conn = i_csdev->pdata->out_conns[i]; /* We have found at least one orphan connection */ if (conn->dest_dev == NULL) { @@ -1372,7 +1372,7 @@ static int coresight_fixup_device_conns(struct coresight_device *csdev) int i, ret = 0; for (i = 0; i < csdev->pdata->nr_outconns; i++) { - struct coresight_connection *conn = &csdev->pdata->out_conns[i]; + struct coresight_connection *conn = csdev->pdata->out_conns[i]; conn->dest_dev = coresight_find_csdev_by_fwnode(conn->dest_fwnode); @@ -1406,15 +1406,12 @@ static int coresight_remove_match(struct device *dev, void *data) * a connection whose name matches @csdev, remove it. */ for (i = 0; i < iterator->pdata->nr_outconns; i++) { - conn = &iterator->pdata->out_conns[i]; + conn = iterator->pdata->out_conns[i]; - if (conn->dest_dev == NULL) - continue; - - if (csdev->dev.fwnode == conn->dest_fwnode) { + /* Child_dev being set signifies that the links were made */ + if (csdev->dev.fwnode == conn->dest_fwnode && conn->dest_dev) { iterator->orphan = true; coresight_remove_links(iterator, conn); - conn->dest_dev = NULL; /* No need to continue */ break; @@ -1534,21 +1531,25 @@ void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset) * to the output port of this device. */ void coresight_release_platform_data(struct coresight_device *csdev, + struct device *dev, struct coresight_platform_data *pdata) { int i; - struct coresight_connection *conns = pdata->out_conns; + struct coresight_connection **conns = pdata->out_conns; for (i = 0; i < pdata->nr_outconns; i++) { /* If we have made the links, remove them now */ - if (csdev && conns[i].dest_dev) - coresight_remove_links(csdev, &conns[i]); + if (csdev && conns[i]->dest_dev) + coresight_remove_links(csdev, conns[i]); /* * Drop the refcount and clear the handle as this device * is going away */ - fwnode_handle_put(conns[i].dest_fwnode); + fwnode_handle_put(conns[i]->dest_fwnode); + devm_kfree(dev, conns[i]); } + devm_kfree(dev, pdata->out_conns); + devm_kfree(dev, pdata); if (csdev) coresight_remove_conns_sysfs_group(csdev); } @@ -1665,7 +1666,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) err_out: /* Cleanup the connection information */ - coresight_release_platform_data(NULL, desc->pdata); + coresight_release_platform_data(NULL, desc->dev, desc->pdata); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(coresight_register); @@ -1678,7 +1679,7 @@ void coresight_unregister(struct coresight_device *csdev) cti_assoc_ops->remove(csdev); coresight_remove_conns(csdev); coresight_clear_default_sink(csdev); - coresight_release_platform_data(csdev, csdev->pdata); + coresight_release_platform_data(csdev, csdev->dev.parent, csdev->pdata); device_unregister(&csdev->dev); } EXPORT_SYMBOL_GPL(coresight_unregister); diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c index 80ed2e74620b..bea8f1ba309a 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c @@ -36,7 +36,7 @@ int coresight_add_out_conn(struct device *dev, * Warn on any existing duplicate output port. */ for (i = 0; i < pdata->nr_outconns; ++i) { - conn = &pdata->out_conns[i]; + conn = pdata->out_conns[i]; /* Output == -1 means ignore the port for example for helpers */ if (conn->src_port != -1 && conn->src_port == new_conn->src_port) { @@ -53,7 +53,9 @@ int coresight_add_out_conn(struct device *dev, if (!pdata->out_conns) return -ENOMEM; - pdata->out_conns[pdata->nr_outconns - 1] = *new_conn; + pdata->out_conns[pdata->nr_outconns - 1] = devm_kmalloc( + dev, sizeof(struct coresight_connection), GFP_KERNEL); + *pdata->out_conns[pdata->nr_outconns - 1] = *new_conn; return 0; } EXPORT_SYMBOL_GPL(coresight_add_out_conn); @@ -859,7 +861,7 @@ coresight_get_platform_data(struct device *dev) error: if (!IS_ERR_OR_NULL(pdata)) /* Cleanup the connection information */ - coresight_release_platform_data(NULL, pdata); + coresight_release_platform_data(NULL, dev, 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 788ff19c60f6..65ae6d161c57 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -207,6 +207,7 @@ static inline void *coresight_get_uci_data(const struct amba_id *id) } void coresight_release_platform_data(struct coresight_device *csdev, + struct device *dev, struct coresight_platform_data *pdata); struct coresight_device * coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode); diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 61234cb8052a..1bbe5410a23d 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -782,7 +782,7 @@ tmc_etr_get_catu_device(struct tmc_drvdata *drvdata) return NULL; for (i = 0; i < etr->pdata->nr_outconns; i++) { - tmp = etr->pdata->out_conns[i].dest_dev; + tmp = etr->pdata->out_conns[i]->dest_dev; if (tmp && coresight_is_catu_device(tmp)) return tmp; } diff --git a/include/linux/coresight.h b/include/linux/coresight.h index ccbc5eafcb6b..7197b07deede 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -111,7 +111,7 @@ struct coresight_platform_data { int high_outport; int nr_inconns; int nr_outconns; - struct coresight_connection *out_conns; + struct coresight_connection **out_conns; }; /** -- 2.34.1