From patchwork Mon Apr 15 16:04:19 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: 10901203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F8B11390 for ; Mon, 15 Apr 2019 16:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CF3E2897D for ; Mon, 15 Apr 2019 16:31:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 214BE28980; Mon, 15 Apr 2019 16:31:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 706462897D for ; Mon, 15 Apr 2019 16:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=SWfIhfAWJfbYPuNjB3WBwtSA2+LWjqVTEMh0Ab0huaE=; b=gswMJH6lppE4RzaGwB/kMENjPV 83uNL7Imy+O75kqDcNtW+CmzeQQIKf9XE0v+SoXReWE54FFUMpCODTcxnO85IKtghxNIxgPPbPU62 CxTn3OqrfK0nxvmXxzy6/guf+RntMUL2mCmi9iFYp98xzilEI7rP/ze7HduqGgyDEge+pPitHwrBx NuttZCf49WN3BpoEjD7yHwwmi9dKmiCioLs/iL154O/JrJDsob9uY+uTUkPk74O4VA78qeBwtxX7O xT/t7NY4YRDKMn1fEqmszs0SN4BSF8dRLNF+FNASsBx/NTSstyrNq0nluRFoAzUDMxiyW+nfHCo2h BnBzh7wA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hG4Vq-00049k-E6; Mon, 15 Apr 2019 16:31:18 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hG4Va-0003me-CJ for linux-arm-kernel@bombadil.infradead.org; Mon, 15 Apr 2019 16:31:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7guntLSdYHrxwDXiY7Iwh3IBB++GOO9lgopk8y+dqWY=; b=f+LzSTj/2H1c9JfswTKN3rWII wuwrpVhITA/OArY3fQUDyQiVYYhKB0n/yZWpjAMS1oFDNoOwFE4CCYBAg07R0SgAkfzZZea7PnTJE NrsMLNWfJeTNCfjHoUgupfvaPjWuvpptZMxlxcwzj6LfZXdS2GpNI4a2MmbdcnVuHS9HZeitI9ScV UVb2d2WRRXU0MMO0lP8Dtpr1drcVL39P5mm3A5VA9g7QX8eIl9IahePlnpIBioiokYKY+0n1hfiLU aFl8O6+YwjWX528vMImnc/uppvgx208K6L2S91f8w2EFPpYtqXnTtcLnGxov0nUVaXksREET5trVz BQ5WFysLw==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hG488-0002hu-CG for linux-arm-kernel@lists.infradead.org; Mon, 15 Apr 2019 16:06:49 +0000 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 3D64F80D; Mon, 15 Apr 2019 09:06:48 -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 B54793F68F; Mon, 15 Apr 2019 09:06:46 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 36/36] [RFC] coresight: Expose device connections via sysfs Date: Mon, 15 Apr 2019 17:04:19 +0100 Message-Id: <1555344260-12375-37-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190415_120648_636978_256A622F X-CRM114-Status: GOOD ( 26.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mathieu.poirier@linaro.org, Suzuki K Poulose , coresight@lists.linaro.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, robert.walker@arm.com, mike.leach@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Coresight device connections are a bit complicated and is not exposed currently to the user. One has to look at the platform descriptions (DT bindings or ACPI bindings) to make an understanding. Given the new naming scheme, it will be helpful to have this information to choose the appropriate devices for tracing. This patch exposes the device connections via links in the sysfs directories. e.g, for a connection devA[OutputPort_X] -> devB[InputPort_Y] is represented as two symlinks: /sys/bus/coresight/.../devA/out:X -> /sys/bus/coresight/.../devB /sys/bus/coresight/.../devB/in:Y -> /sys/bus/coresight/.../devA We could have segregated the links to separate directories aka attribute_groups, for input_ports and output_ports. But the sysfs won't let you create empty attribute_groups and thus it becomes complicated to dynamically create the attribute_groups. Cc: Mathieu Poirier Signed-off-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight.c | 120 +++++++++++++++++++++++++++++--- include/linux/coresight.h | 4 ++ 2 files changed, 113 insertions(+), 11 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 4d63063..50a1f29 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -981,9 +981,92 @@ static void coresight_device_release(struct device *dev) kfree(csdev); } + +/* + * coresight_make_links: Make a link for a connection from a @orig + * device to @target, represented by @conn. + * + * e.g, for devOrig[output_X] -> devTarget[input_Y] is represented + * as two symbolic links : + * + * /sys/.../devOrig/out:X -> /sys/.../devTarget/ + * /sys/.../devTarget/in:Y -> /sys/.../devOrig/ + * + * The link names are allocated for a device where it appears. i.e, the + * "out" link on the master and "in" link on the slave device. + * The link names are stored in the connection record for avoiding + * the reconstruction of names for removal. + */ +static int coresight_make_links(struct coresight_device *orig, + struct coresight_connection *conn, + struct coresight_device *target) +{ + int ret = -ENOMEM; + char *outs = NULL, *ins = NULL; + + do { + outs = devm_kasprintf(&orig->dev, GFP_KERNEL, + "out:%d", conn->outport); + if (!outs) + break; + ins = devm_kasprintf(&target->dev, GFP_KERNEL, + "in:%d", conn->child_port); + if (!ins) + break; + ret = sysfs_create_link(&orig->dev.kobj, + &target->dev.kobj, outs); + if (ret) + break; + + ret = sysfs_create_link(&target->dev.kobj, + &orig->dev.kobj, ins); + if (ret) { + sysfs_remove_link(&orig->dev.kobj, outs); + break; + } + + conn->inlink_name = ins; + conn->outlink_name = outs; + /* + * Install the device connection. This also indicates that + * the links are operational on both ends. + */ + conn->child_dev = target; + return 0; + } while (0); + + if (outs) + devm_kfree(&orig->dev, outs); + if (ins) + devm_kfree(&target->dev, ins); + return ret; +} + +/* + * coresight_remove_links: Remove the sysfs links for a given connection @conn, + * from @orig device to @target device. See coresight_make_links() for more + * details. + */ +static void coresight_remove_links(struct coresight_device *orig, + struct coresight_connection *conn) +{ + struct coresight_device *target = conn->child_dev; + + if (!orig || !target) + return; + + sysfs_remove_link(&orig->dev.kobj, conn->outlink_name); + sysfs_remove_link(&target->dev.kobj, conn->inlink_name); + + devm_kfree(&target->dev, conn->inlink_name); + devm_kfree(&orig->dev, conn->outlink_name); + conn->inlink_name = conn->outlink_name = NULL; + conn->child_dev = NULL; +} + static int coresight_orphan_match(struct device *dev, void *data) { - int i; + int i, ret = 0; bool still_orphan = false; struct coresight_device *csdev, *i_csdev; struct coresight_connection *conn; @@ -1008,19 +1091,23 @@ 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_fwnode == csdev->dev.fwnode) - conn->child_dev = csdev; - else + if (conn->child_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; + } } } i_csdev->orphan = still_orphan; /* - * Returning '0' ensures that all known component on the - * bus will be checked. + * Returning '0' in case we didn't encounter any error, + * ensures that all known component on the bus will be checked. */ return 0; } @@ -1038,7 +1125,7 @@ static int coresight_fixup_orphan_conns(struct coresight_device *csdev) static int coresight_fixup_device_conns(struct coresight_device *csdev) { - int i; + int i, ret = 0; for (i = 0; i < csdev->pdata->nr_outport; i++) { struct coresight_connection *conn = &csdev->pdata->conns[i]; @@ -1048,9 +1135,12 @@ static int coresight_fixup_device_conns(struct coresight_device *csdev) (void *)conn->child_fwnode, device_fwnode_match); if (dev) { - conn->child_dev = to_coresight_device(dev); + ret = coresight_make_links(csdev, conn, + to_coresight_device(dev)); /* and put reference from 'bus_find_device()' */ put_device(dev); + if (ret) + break; } else { csdev->orphan = true; conn->child_dev = NULL; @@ -1085,7 +1175,7 @@ static int coresight_remove_match(struct device *dev, void *data) if (csdev->dev.fwnode == conn->child_fwnode) { iterator->orphan = true; - conn->child_dev = NULL; + coresight_remove_links(iterator, conn); /* * Drop the reference to the handle for the remote * device acquired in parsing the connections from @@ -1179,10 +1269,18 @@ void coresight_release_platform_data(struct coresight_device *csdev, struct coresight_platform_data *pdata) { int i; + struct coresight_connection *conns = pdata->conns; for (i = 0; i < pdata->nr_outport; i++) { - if (pdata->conns[i].child_fwnode) { - fwnode_handle_put(pdata->conns[i].child_fwnode); + /* If we have made the links, remove them now */ + if (csdev && conns[i].child_dev) + coresight_remove_links(csdev, &conns[i]); + /* + * Drop the refcount and clear the handle as this device + * is going away + */ + if (conns[i].child_fwnode) { + fwnode_handle_put(conns[i].child_fwnode); pdata->conns[i].child_fwnode = 0; } } diff --git a/include/linux/coresight.h b/include/linux/coresight.h index d6367a0..284d783 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -130,12 +130,16 @@ struct coresight_desc { * @chid_fwnode: remote component's fwnode handle. * @child_dev: a @coresight_device representation of the component connected to @outport. + * @inlink_name: Name for the "input" link + * @outlink_name: Name for the "output" link */ struct coresight_connection { int outport; int child_port; struct fwnode_handle *child_fwnode; struct coresight_device *child_dev; + const char *inlink_name; + const char *outlink_name; }; /**