From patchwork Tue Apr 4 13:53:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 79142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3058723vqo; Tue, 4 Apr 2023 07:08:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YNmvzR79eySU7MCtc3CZuqYJhisypMu/1hhJyO3hz6DuyYeMnl3BHFY8b+T6RQRhYMZMkG X-Received: by 2002:a17:902:cacd:b0:1a2:9d86:c366 with SMTP id y13-20020a170902cacd00b001a29d86c366mr2012950pld.64.1680617307673; Tue, 04 Apr 2023 07:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680617307; cv=none; d=google.com; s=arc-20160816; b=MtHobPtr4K0GNRVY+4wM65rLLB8sZpKCllEZ/b1mokcgUkyDV0X3diBRwSIzS3VJwL B55uud24/hww6Mq/KrV/A6tawTPkVDSl/naeI+Jg2XgZmxOI/cW2o2uvWOtOyMzk3WPF LnOD+5JOpWBTovTVBF0UFWr8VCpxQQSfZolqjLysAa4CkUj8WymGhj4QmNTau83dd6AO RCR3Tc9lD8LSNV/Ne1X98dOqPmYqaQmQ7ua8sMCcGFi16/zCbKweQM450qePKOVoLXxM 8a8IQr4W9szjKZENu40v4YEhFdwm4DYiN5+LAnDU4MTZ2i3TEPM72v3Z1zfYtmKEeXcV Iamw== 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=MlwmPJfS3114dVkyLlEmziwEa+/6cBAe0pPnNqoBX9k=; b=wWUBNigzMnWjV8IAez9lwm8CpMP0Dgq3IEGIgwPEAEpSJLqIPYtGugkfE1CFz6kj8E RQepHym6j/ev32HIDpo4X30UtWLKePKWqGPaWySIza2I8ugI45c6LHH+WkOBJ1/W5vPR UKYHTZgF8lP5rRCoGn+43uh5Kim2CzBmjtOAv1HXkpodXMaeAWCC9wZyNp6h9c0WZy0x cjQcsm4c+NPPUdbB7wCXeKs4EgnFDGS+pu2ngtTqCz3JjghTTCYakQakRYntqswPd7xU XYwtCyusOPFYWZBVXFFiC3HsFCeF9fTYK7FLB2UnFVwfJcmUnX8CHDh5BUZRjL/Jduwu 80Lw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63db58000000b0050bfb509daasi10654718pgi.637.2023.04.04.07.08.10; Tue, 04 Apr 2023 07:08:27 -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 S235532AbjDDN4o (ORCPT + 99 others); Tue, 4 Apr 2023 09:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235514AbjDDN4Q (ORCPT ); Tue, 4 Apr 2023 09:56:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4240799 for ; Tue, 4 Apr 2023 06:55:29 -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 9C1C4D75; Tue, 4 Apr 2023 06:56:13 -0700 (PDT) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7F3923F762; Tue, 4 Apr 2023 06:55:27 -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 , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 08/13] coresight: Simplify connection fixup mechanism Date: Tue, 4 Apr 2023 14:53:54 +0100 Message-Id: <20230404135401.1728919-9-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404135401.1728919-1-james.clark@arm.com> References: <20230404135401.1728919-1-james.clark@arm.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762254974033536735?= X-GMAIL-MSGID: =?utf-8?q?1762254974033536735?= There is some duplication between coresight_fixup_device_conns() and coresight_fixup_orphan_conns(). They both do the same thing except for the fact that coresight_fixup_orphan_conns() can't handle iterating over itself. By making it able to handle fixing up it's own connections the other function can be removed. Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-core.c | 84 ++++++++------------ 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 0b738960973b..8d377a59e0be 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1316,42 +1316,46 @@ static int coresight_orphan_match(struct device *dev, void *data) { int i, ret = 0; bool still_orphan = false; - struct coresight_device *csdev, *i_csdev; + struct coresight_device *dst_csdev = data; + struct coresight_device *src_csdev = to_coresight_device(dev); struct coresight_connection *conn; - - csdev = data; - i_csdev = to_coresight_device(dev); - - /* No need to check oneself */ - if (csdev == i_csdev) - return 0; + bool fixup_self = (src_csdev == dst_csdev); /* Move on to another component if no connection is orphan */ - if (!i_csdev->orphan) + if (!src_csdev->orphan) return 0; /* - * Circle throuch all the connection of that component. If we find - * an orphan connection whose name matches @csdev, link it. + * Circle through all the connections of that component. If we find + * an orphan connection whose name matches @dst_csdev, link it. */ - for (i = 0; i < i_csdev->pdata->nr_outconns; i++) { - conn = i_csdev->pdata->out_conns[i]; - - /* We have found at least one orphan connection */ - if (conn->dest_dev == NULL) { - /* Does it match this newly added device? */ - if (conn->dest_fwnode == csdev->dev.fwnode) { - ret = coresight_make_links(i_csdev, - conn, csdev); - if (ret) - return ret; - } else { - /* This component still has an orphan */ - still_orphan = true; - } + for (i = 0; i < src_csdev->pdata->nr_outconns; i++) { + conn = src_csdev->pdata->out_conns[i]; + + /* Skip the port if it's already connected. */ + if (conn->dest_dev) + continue; + + /* + * If we are at the "new" device, which triggered this search, + * we must find the remote device from the fwnode in the + * connection. + */ + if (fixup_self) + dst_csdev = coresight_find_csdev_by_fwnode( + conn->dest_fwnode); + + /* Does it match this newly added device? */ + if (dst_csdev && conn->dest_fwnode == dst_csdev->dev.fwnode) { + ret = coresight_make_links(src_csdev, conn, dst_csdev); + if (ret) + return ret; + } else { + /* This component still has an orphan */ + still_orphan = true; } } - i_csdev->orphan = still_orphan; + src_csdev->orphan = still_orphan; /* * Returning '0' in case we didn't encounter any error, @@ -1366,28 +1370,6 @@ static int coresight_fixup_orphan_conns(struct coresight_device *csdev) csdev, coresight_orphan_match); } - -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]; - - conn->dest_dev = - coresight_find_csdev_by_fwnode(conn->dest_fwnode); - if (conn->dest_dev && conn->dest_dev->has_conns_grp) { - ret = coresight_make_links(csdev, conn, conn->dest_dev); - if (ret) - break; - } else { - csdev->orphan = true; - } - } - - return ret; -} - static int coresight_remove_match(struct device *dev, void *data) { int i; @@ -1595,7 +1577,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) csdev->subtype = desc->subtype; csdev->ops = desc->ops; csdev->access = desc->access; - csdev->orphan = false; + csdev->orphan = true; csdev->dev.type = &coresight_dev_type[desc->type]; csdev->dev.groups = desc->groups; @@ -1645,8 +1627,6 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) registered = true; ret = coresight_create_conns_sysfs_group(csdev); - if (!ret) - ret = coresight_fixup_device_conns(csdev); if (!ret) ret = coresight_fixup_orphan_conns(csdev);