From patchwork Thu Feb 27 15:14:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 11408803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B040014D5 for ; Thu, 27 Feb 2020 15:15:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8A40324688 for ; Thu, 27 Feb 2020 15:15:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="r+iF5g5I"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yUhrzFw2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A40324688 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=gpMZHGjI8JgjVOR25caR5wbowemrKz1GmyNcsh12sZ8=; b=r+iF5g5I36nuR3zzIV1go0itn/ 4gcJsI7vh+5EdTN41BLhxMNKN6FeqX+WY0kXBbUUs2n9D473HzRO5tRDVKHI5Ip2GNW9a0xU6qktz 3UX/8m/+P77/Iq0MZsPFJUnNSCNLuqfV3YZt2Hu7rPIjLaa+3iZBXPQBqrS5bj6NeUcebEKRFM5AV LfiE4+UnTW7dZVF2/4EX17Bb0HlsNm9Xwqh2m4imU7RmxY+Oi1uVQU1RHO3h20rD6JXpHLdsRjPDI j/ZPUFsC/glpBQ722y0HhPAnkCw/i8hoHtU+EwuQGiX00rkcXwWNA+4bNmx4Ywj1p0XWQEKJIVApx vOo2XeyA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Kso-00021b-TO; Thu, 27 Feb 2020 15:15:26 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Kru-0008VT-GN for linux-arm-kernel@lists.infradead.org; Thu, 27 Feb 2020 15:14:32 +0000 Received: by mail-wm1-x344.google.com with SMTP id a5so4009345wmb.0 for ; Thu, 27 Feb 2020 07:14:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aTDBzI1XIx/lCwvz5NfAj4LMnLcoxC6x80PetPnO3r0=; b=yUhrzFw2SPQAAyNL6r+o0pfXf+cP/0hDZG5rLfDyMhYX5BtxfzM1BxRO2mgF2q7/QN Kasf0zMc7pfGMMB/Q7nLq+4S9oav0Wp3dpRF9QjOxAuHIgvNEY1EcT7XVL/ZRSD61qKU gW0C/zxCsylA2t4SuSzO0gGPuUrDg2e7x/6qs9SpxZWA2QejAkogv0VFoydNNKeGV1cn k69/XCc5Al46kb4S4B3UIydwLGYYjmfJ1YOHKf/fzjZh6eFZaaX5bXSk8mhOskLddaya SXjLct5SXgpMg1wdVOLg6gAohDMJvW5qX9YcQZlsajKG2UUKkdN4tvO3z66D1iR0CBYz vU3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aTDBzI1XIx/lCwvz5NfAj4LMnLcoxC6x80PetPnO3r0=; b=t7StI48zHl8/YppqKKw+6SJmZb2N2cYLwS7bU2X7YxzG1R6eYgQMk3+IBjpL2IZomU aoHVeNeSX3H4MhhpZ13tycbSgVnLdE5EHgvFDSdpyP/zM/pxZ/CcDiKrhHMjUHbyNUe7 By4rbbNeGKAPNNmKKmBiy9BGjMK6Ze/63RpXGHxbe8Pjpb7PWs4Ejv9RAiskE0tFsHeA miSeGYrPwgR9QRI+oN0t/hGzWR5OzpkFstqIV5Ikkm6BSUGd/RzzKy867k83jssPzDC7 XFG4Ij12eg9GDTUNUU7jS+h3uWaDFaCOp1moc3KkOOPjcQOX/xF3KBhwUQp4gr1mZFpP 21dQ== X-Gm-Message-State: APjAAAU1JdiDrOzyI75IbNzOdF4uaW3YeGfaT1h0rzkYr/9siLMHtuKm bY/ttOotPCBRGJIjK+a5GZIVnV5QWZI= X-Google-Smtp-Source: APXvYqwif1iRQrupH6jmi5KHHZRUMYrZW46xuTCHun48dnOu77CziodNXre5xSQXbN61jclIulFqZg== X-Received: by 2002:a1c:f71a:: with SMTP id v26mr5858539wmh.85.1582816467932; Thu, 27 Feb 2020 07:14:27 -0800 (PST) Received: from linaro.org ([2a00:23c5:6801:1801:2dc1:e60d:4b1c:70e0]) by smtp.gmail.com with ESMTPSA id q12sm8973079wrg.71.2020.02.27.07.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 07:14:26 -0800 (PST) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-doc@vger.kernel.org Subject: [PATCH v5 3/6] coresight: Add generic sysfs link creation functions Date: Thu, 27 Feb 2020 15:14:13 +0000 Message-Id: <20200227151416.14271-4-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200227151416.14271-1-mike.leach@linaro.org> References: <20200227151416.14271-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_071430_573643_0CA772D6 X-CRM114-Status: GOOD ( 19.46 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:344 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mike Leach , mathieu.poirier@linaro.org, suzuki.poulose@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org To allow the connections between coresight components to be represented in sysfs, generic methods for creating sysfs links between two coresight devices are added. Signed-off-by: Mike Leach Reviewed-by: Suzuki K Poulose Reviewed-by: Mathieu Poirier --- drivers/hwtracing/coresight/Makefile | 3 +- drivers/hwtracing/coresight/coresight-priv.h | 4 + drivers/hwtracing/coresight/coresight-sysfs.c | 124 ++++++++++++++++++ include/linux/coresight.h | 20 +++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 drivers/hwtracing/coresight/coresight-sysfs.c diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 0e3e72f0f510..19497d1d92bf 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -2,7 +2,8 @@ # # Makefile for CoreSight drivers. # -obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o coresight-platform.o +obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \ + coresight-platform.o coresight-sysfs.o obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \ coresight-tmc-etf.o \ coresight-tmc-etr.o diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 1cad642f27aa..a4a658d46045 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -153,6 +153,10 @@ struct coresight_device *coresight_get_sink_by_id(u32 id); struct list_head *coresight_build_path(struct coresight_device *csdev, struct coresight_device *sink); void coresight_release_path(struct list_head *path); +int coresight_add_sysfs_link(struct coresight_sysfs_link *info); +void coresight_remove_sysfs_link(struct coresight_sysfs_link *info); +int coresight_create_conns_sysfs_group(struct coresight_device *csdev); +void coresight_remove_conns_sysfs_group(struct coresight_device *csdev); #ifdef CONFIG_CORESIGHT_SOURCE_ETM3X extern int etm_readl_cp14(u32 off, unsigned int *val); diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c new file mode 100644 index 000000000000..17d565941e5e --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-sysfs.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019, Linaro Limited, All rights reserved. + * Author: Mike Leach + */ + +#include +#include + +#include "coresight-priv.h" + +/* + * Connections group - links attribute. + * Count of created links between coresight components in the group. + */ +static ssize_t nr_links_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct coresight_device *csdev = to_coresight_device(dev); + + return scnprintf(buf, PAGE_SIZE, "%d\n", csdev->nr_links); +} +static DEVICE_ATTR_RO(nr_links); + +static struct attribute *coresight_conns_attrs[] = { + &dev_attr_nr_links.attr, + NULL, +}; + +static struct attribute_group coresight_conns_group = { + .attrs = coresight_conns_attrs, + .name = "connections", +}; + +/* + * Create connections group for CoreSight devices. + * This group will then be used to collate the sysfs links between + * devices. + */ +int coresight_create_conns_sysfs_group(struct coresight_device *csdev) +{ + int ret = 0; + + if (!csdev) + return -EINVAL; + + ret = sysfs_create_group(&csdev->dev.kobj, &coresight_conns_group); + if (ret) + return ret; + + csdev->has_conns_grp = true; + return ret; +} + +void coresight_remove_conns_sysfs_group(struct coresight_device *csdev) +{ + if (!csdev) + return; + + if (csdev->has_conns_grp) { + sysfs_remove_group(&csdev->dev.kobj, &coresight_conns_group); + csdev->has_conns_grp = false; + } +} + +int coresight_add_sysfs_link(struct coresight_sysfs_link *info) +{ + int ret = 0; + + if (!info) + return -EINVAL; + if (!info->orig || !info->target || + !info->orig_name || !info->target_name) + return -EINVAL; + if (!info->orig->has_conns_grp || !info->target->has_conns_grp) + return -EINVAL; + + /* first link orig->target */ + ret = sysfs_add_link_to_group(&info->orig->dev.kobj, + coresight_conns_group.name, + &info->target->dev.kobj, + info->orig_name); + if (ret) + return ret; + + /* second link target->orig */ + ret = sysfs_add_link_to_group(&info->target->dev.kobj, + coresight_conns_group.name, + &info->orig->dev.kobj, + info->target_name); + + /* error in second link - remove first - otherwise inc counts */ + if (ret) { + sysfs_remove_link_from_group(&info->orig->dev.kobj, + coresight_conns_group.name, + info->orig_name); + } else { + info->orig->nr_links++; + info->target->nr_links++; + } + + return ret; +} + +void coresight_remove_sysfs_link(struct coresight_sysfs_link *info) +{ + if (!info) + return; + if (!info->orig || !info->target || + !info->orig_name || !info->target_name) + return; + + sysfs_remove_link_from_group(&info->orig->dev.kobj, + coresight_conns_group.name, + info->orig_name); + + sysfs_remove_link_from_group(&info->target->dev.kobj, + coresight_conns_group.name, + info->target_name); + + info->orig->nr_links--; + info->target->nr_links--; +} diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 193cc9dbf448..a2ec25e02ca9 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -148,6 +148,20 @@ struct coresight_connection { struct coresight_device *child_dev; }; +/** + * struct coresight_sysfs_link - representation of a connection in sysfs. + * @orig: Originating (master) coresight device for the link. + * @orig_name: Name to use for the link orig->target. + * @target: Target (slave) coresight device for the link. + * @target_name: Name to use for the link target->orig. + */ +struct coresight_sysfs_link { + struct coresight_device *orig; + const char *orig_name; + struct coresight_device *target; + const char *target_name; +}; + /** * struct coresight_device - representation of a device as used by the framework * @pdata: Platform data with device connections associated to this device. @@ -165,6 +179,9 @@ struct coresight_connection { * @ea: Device attribute for sink representation under PMU directory. * @ect_dev: Associated cross trigger device. Not part of the trace data * path or connections. + * @nr_links: number of sysfs links created to other components from this + * device. These will appear in the "connections" group. + * @has_conns_grp: Have added a "connections" group for sysfs links. */ struct coresight_device { struct coresight_platform_data *pdata; @@ -180,6 +197,9 @@ struct coresight_device { struct dev_ext_attribute *ea; /* cross trigger handling */ struct coresight_device *ect_dev; + /* sysfs links between components */ + int nr_links; + bool has_conns_grp; }; /*