From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3BBAC43460 for ; Wed, 12 May 2021 21:21:17 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 3EAD261264 for ; Wed, 12 May 2021 21:21:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EAD261264 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+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=bLtHyFZ8iP7sHqK7ODDmaeXBNJlv5ee4BRMKebTs1SE=; b=LwFXRlg0BG15hdCRfFOUdH5+47 bDwTyvK0vZaXj2DTIiAhPeixaNhtlP/zB5zzmyvnqeTDEX2h3XpkkiuxfHo/JMNyQRc5n8dwi8Ir9 lsgvBLvB6yXOwu7hEmn1pDHMbbsIirCAn78oQUHPh1YYYDGTvbDeqOJ8oNOSG7UEiRPD83Bb7IMs1 GzOt0t953KeCrX7cCYlfdOJkrZAwaMTXxPzr/oR2Qlt3HcY9lsP03CQ4u1VXoyOqv4NwV771ydLgd nUtLEzWpyuvl/wPESDJ7yYdbv4mDELKHILE1R5ZLq5SYX2wW8nZRMtzycmm7rlHO5okvBFu+9kVuD zwC/427A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgwFi-0040aQ-Sp; Wed, 12 May 2021 21:18:47 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgwF7-0040Si-6g for linux-arm-kernel@desiato.infradead.org; Wed, 12 May 2021 21:18:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=X29LQIy5WVkatfJsupsDpSzEEIeN1D5SXi0DHsURTqA=; b=NjBrOogfFmnSGGMr8N+aIUj8Di s35QOuS514hBeKu7OJ2Ud0Jp5iS3KsD3wWk8soU+yBB6FmZlNvsrgXmaq2Ff5hgSueEBMW+UfuMWQ rPfFJV4vYw1J6Zqe6MtraSPp1EfbjysmSLif4KUdg9EphxWkuA94WYaA/RiigrNvZS3q5rQkHwiQn IHO2FoFe7VqBs5UGqFJs1D0i6BjD9IYc6zZbgQWdplAmc2jHqkiIagsM8TnpkLTI04roSpopG768p 1rVZU4tnZkq5E0aIskYa30JQPSrBBkLDFF+2XxHCwa9iRvJV5tBF5KUM20FOeuoMt3MNLrxuCOY58 H4z8AjUw==; Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgwF3-00ApfA-B6 for linux-arm-kernel@lists.infradead.org; Wed, 12 May 2021 21:18:07 +0000 Received: by mail-wr1-x42e.google.com with SMTP id l14so25020736wrx.5 for ; Wed, 12 May 2021 14:18:04 -0700 (PDT) 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=X29LQIy5WVkatfJsupsDpSzEEIeN1D5SXi0DHsURTqA=; b=ygXBysmUonfhWPMdudSS0nCQgIqNe34r8dZfHo07pCOGqOEvuuXuuYNQS42I0u8Br8 VOkx54KRnDH5rZRMacun9Ukx9VAHNqU6LdvdFjC9wVbZfLl2KpL+/P2o3Os9nQAhFsq0 2o8AuDEjr2mgfB87XmG55ifKlqfTxJbd973BlGUnkANBF2ISGkfa0mlupiC7US64ACLc 6s4dtzyMx4AVpnxFdEGu52A3l0m8hBBy1LgBExZhP319wf+2mAM7iuSKaTcMIwI7No39 7yWd6YJDXuYZjWfsx27wVSlkVnGvHWhxIRlMRvwU6CvdiLNl4tFbr+RLxs6OwqswbupG Sh5Q== 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=X29LQIy5WVkatfJsupsDpSzEEIeN1D5SXi0DHsURTqA=; b=M6EcltP6NJAwPoB+GNTzW9EhjtNDRis60GQT7Eo017pel+Dpxa6gbSc/xs2E7o9HC+ VGqUzjj4Q2lvEua7esnXQcIE5Gs36z9/TexOWnqeVw/9JuJWmCfVIIAvfgNtCTWKJXIh HqGjNy/QJzkh3f/atdbqtU8oUBMo/DcnqNL+/yN1tM7ZLHfmOdLcJeXL8GLHw4A4wisJ UwGJu5248Z7suChgxUYK98gSi1thTt6C3E1HSmXEEAlt4jIJrw6sKdQ3jpW6hJfjvyUo itLsgqPrb63KAgeUlT4a3QlqIzQ+k/F7ooj2/jx/YRQtPDPlv1mcq9FDpCL0gOr6iQTP SnIw== X-Gm-Message-State: AOAM532yKsaZb+698chhkOvIgb89PQwxwVfWC9el5PMP57H6z2RqH/x6 kbOM+6jfqvSqQC49GfCjsD6ksg== X-Google-Smtp-Source: ABdhPJzol2oc0HfubYUNswAILajL/q/e1xwE19I1tDhm92VjhI2ENzV9Kn51ycGOAAShfaEmiu2vLQ== X-Received: by 2002:adf:fa4c:: with SMTP id y12mr47645598wrr.393.1620854283820; Wed, 12 May 2021 14:18:03 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:3d54:dc15:c65b:180c]) by smtp.gmail.com with ESMTPSA id e10sm908745wrw.20.2021.05.12.14.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 14:18:03 -0700 (PDT) From: Mike Leach To: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org, mathieu.poirier@linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, Mike Leach Subject: [RFC PATCH 4/8] coresight: configfs: Allow configfs to activate configuration. Date: Wed, 12 May 2021 22:17:48 +0100 Message-Id: <20210512211752.4103-5-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210512211752.4103-1-mike.leach@linaro.org> References: <20210512211752.4103-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210512_141805_409681_D90D55CD X-CRM114-Status: GOOD ( 32.77 ) 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: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Adds configfs attributes to allow a configuration to be enabled for use when sysfs is used to control CoreSight. perf retains independent enabling of configurations. Signed-off-by: Mike Leach --- .../coresight/coresight-etm4x-core.c | 5 + .../coresight/coresight-syscfg-configfs.c | 67 +++++++++ .../coresight/coresight-syscfg-configfs.h | 2 + .../hwtracing/coresight/coresight-syscfg.c | 129 ++++++++++++++---- .../hwtracing/coresight/coresight-syscfg.h | 7 +- 5 files changed, 182 insertions(+), 28 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index b7a4aeaa2bc7..2637096c4621 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -688,6 +688,11 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) struct etm4_enable_arg arg = { }; int ret; + /* enable any config activated by configfs */ + ret = cscfg_csdev_enable_active_config(csdev, 0, 0); + if (ret) + return ret; + spin_lock(&drvdata->spinlock); /* diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c index 345a62f1b728..ae79ae8b1d7e 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c @@ -6,6 +6,7 @@ #include +#include "coresight-config.h" #include "coresight-syscfg-configfs.h" /* create a default ci_type. */ @@ -87,9 +88,75 @@ static ssize_t cscfg_cfg_values_show(struct config_item *item, char *page) } CONFIGFS_ATTR_RO(cscfg_cfg_, values); +static ssize_t cscfg_cfg_activate_show(struct config_item *item, char *page) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + + return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->active); +} + +static ssize_t cscfg_cfg_activate_store(struct config_item *item, + const char *page, size_t count) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + int err; + bool val; + + err = kstrtobool(page, &val); + if (!err) + err = cscfg_config_sysfs_activation(fs_config->config_desc, val); + if (!err) { + fs_config->active = val; + if (val) + cscfg_config_sysfs_preset(fs_config->preset); + } + return err ? err : count; +} +CONFIGFS_ATTR(cscfg_cfg_, activate); + +static ssize_t cscfg_cfg_active_preset_show(struct config_item *item, char *page) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + + return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->preset); +} + +static ssize_t cscfg_cfg_active_preset_store(struct config_item *item, + const char *page, size_t count) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + int preset, err; + + err = kstrtoint(page, 0, &preset); + if (!err) { + /* + * presets start at 1, and go up to max (15), + * but the config may provide fewer. + */ + if ((preset < 1) || (preset > fs_config->config_desc->nr_presets)) + err = -EINVAL; + } + + if (!err) { + /* set new value */ + fs_config->preset = preset; + /* set on system if active */ + if (fs_config->active) + cscfg_config_sysfs_preset(fs_config->preset); + } + return err ? err : count; +} +CONFIGFS_ATTR(cscfg_cfg_, active_preset); + static struct configfs_attribute *cscfg_config_view_attrs[] = { &cscfg_cfg_attr_description, &cscfg_cfg_attr_feature_refs, + &cscfg_cfg_attr_activate, + &cscfg_cfg_attr_active_preset, NULL, }; diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h index ea1e54d29f7f..373d84d43268 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h @@ -15,6 +15,8 @@ struct cscfg_fs_config { struct cscfg_config_desc *config_desc; struct config_group group; + bool active; + int preset; }; /* container for feature view */ diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 26c1a244c2b1..ab74e33b892b 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -743,32 +743,23 @@ void cscfg_csdev_reset_feats(struct coresight_device *csdev) } EXPORT_SYMBOL_GPL(cscfg_csdev_reset_feats); -/** - * cscfg_activate_config - Mark a configuration descriptor as active. - * - * This will be seen when csdev devices are enabled in the system. - * Only activated configurations can be enabled on individual devices. - * Activation protects the configuration from alteration or removal while - * active. - * - * Selection by hash value - generated from the configuration name when it - * was loaded and added to the cs_etm/configurations file system for selection - * by perf. +/* + * This activate configuration for either perf or sysfs. Perf can have multiple + * active configs, selected per event, sysfs is limited to one. * * Increments the configuration descriptor active count and the global active * count. * * @cfg_hash: Hash value of the selected configuration name. */ -int cscfg_activate_config(unsigned long cfg_hash) +static int _cscfg_activate_config(unsigned long cfg_hash) { struct cscfg_config_desc *config_desc; int err = -EINVAL; - mutex_lock(&cscfg_mutex); - list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { if ((unsigned long)config_desc->event_ea->var == cfg_hash) { + /* must ensure that config cannot be unloaded in use */ err = cscfg_owner_get(config_desc->load_owner); if (err) @@ -790,6 +781,88 @@ int cscfg_activate_config(unsigned long cfg_hash) break; } } + return err; +} + +static void _cscfg_deactivate_config(unsigned long cfg_hash) +{ + struct cscfg_config_desc *config_desc; + + list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { + if ((unsigned long)config_desc->event_ea->var == cfg_hash) { + atomic_dec(&config_desc->active_cnt); + atomic_dec(&cscfg_mgr->sys_active_cnt); + cscfg_owner_put(config_desc->load_owner); + dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); + break; + } + } +} + +/* + * called from configfs to set/clear the active configuration for use when + * using sysfs to control trace. + */ +int cscfg_config_sysfs_activation(struct cscfg_config_desc *config_desc, bool activate) +{ + unsigned long cfg_hash_desc; + int err = 0; + + mutex_lock(&cscfg_mutex); + + cfg_hash_desc = (unsigned long)config_desc->event_ea->var; + + if (activate) { + /* cannot be a current active value to activate this */ + if (cscfg_mgr->sysfs_active_config) { + err = -EBUSY; + goto exit_unlock; + } + err = _cscfg_activate_config(cfg_hash_desc); + if (!err) + cscfg_mgr->sysfs_active_config = cfg_hash_desc; + } else { + /* disable if matching current value */ + if (cscfg_mgr->sysfs_active_config == cfg_hash_desc) { + _cscfg_deactivate_config(cfg_hash_desc); + cscfg_mgr->sysfs_active_config = 0; + } else + err = -EINVAL; + } + +exit_unlock: + mutex_unlock(&cscfg_mutex); + return err; +} + +/* set the sysfs preset value */ +void cscfg_config_sysfs_preset(int preset) +{ + mutex_lock(&cscfg_mutex); + cscfg_mgr->sysfs_active_preset = preset; + mutex_unlock(&cscfg_mutex); +} + +/** + * cscfg_activate_config - Mark a configuration descriptor as active. + * + * This will be seen when csdev devices are enabled in the system. + * Only activated configurations can be enabled on individual devices. + * Activation protects the configuration from alteration or removal while + * active. + * + * Selection by hash value - generated from the configuration name when it + * was loaded and added to the cs_etm/configurations file system for selection + * by perf. + * + * @cfg_hash: Hash value of the selected configuration name. + */ +int cscfg_activate_config(unsigned long cfg_hash) +{ + int err = 0; + + mutex_lock(&cscfg_mutex); + err = _cscfg_activate_config(cfg_hash); mutex_unlock(&cscfg_mutex); return err; @@ -805,19 +878,8 @@ EXPORT_SYMBOL_GPL(cscfg_activate_config); */ void cscfg_deactivate_config(unsigned long cfg_hash) { - struct cscfg_config_desc *config_desc; - mutex_lock(&cscfg_mutex); - - list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { - if ((unsigned long)config_desc->event_ea->var == cfg_hash) { - atomic_dec(&config_desc->active_cnt); - atomic_dec(&cscfg_mgr->sys_active_cnt); - cscfg_owner_put(config_desc->load_owner); - dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); - break; - } - } + _cscfg_deactivate_config(cfg_hash); mutex_unlock(&cscfg_mutex); } EXPORT_SYMBOL_GPL(cscfg_deactivate_config); @@ -826,7 +888,8 @@ EXPORT_SYMBOL_GPL(cscfg_deactivate_config); * cscfg_csdev_enable_active_config - Enable matching active configuration for device. * * Enables the configuration selected by @cfg_hash if the configuration is supported - * on the device and has been activated. + * on the device and has been activated. A @cfg_hash value of 0 is used if the device + * is being programmed from sysfs, to select the current sysfs active config. * * If active and supported the CoreSight device @csdev will be programmed with the * configuration, using @preset parameters. @@ -850,6 +913,16 @@ int cscfg_csdev_enable_active_config(struct coresight_device *csdev, return 0; mutex_lock(&cscfg_csdev_mutex); + + /* sysfs controlled coresight will call with cfg_hash == 0 */ + if (!cfg_hash) { + if (!cscfg_mgr->sysfs_active_config) + goto exit_unlock; + + cfg_hash = cscfg_mgr->sysfs_active_config; + preset = cscfg_mgr->sysfs_active_preset; + } + list_for_each_entry(config_csdev_item, &csdev->config_csdev_list, node) { config_desc = config_csdev_item->config_desc; if ((atomic_read(&config_desc->active_cnt)) && @@ -863,6 +936,8 @@ int cscfg_csdev_enable_active_config(struct coresight_device *csdev, if (!err) csdev->active_cscfg_ctxt = (void *)config_csdev_active; } + +exit_unlock: mutex_unlock(&cscfg_csdev_mutex); return err; } diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h index 1da37874f70f..e07e1b872806 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.h +++ b/drivers/hwtracing/coresight/coresight-syscfg.h @@ -28,6 +28,8 @@ * @load_order_list: Ordered list of owners for dynamically loaded configurations. * @sys_active_cnt: Total number of active config descriptor references. * @cfgfs_subsys: configfs subsystem used to manage configurations. + * @sysfs_active_config:Active config hash used if CoreSight controlled from sysfs. + * @sysfs_active_preset:Active preset index used if CoreSight controlled from sysfs. */ struct cscfg_manager { struct device dev; @@ -37,6 +39,8 @@ struct cscfg_manager { struct list_head load_order_list; atomic_t sys_active_cnt; struct configfs_subsystem cfgfs_subsys; + u32 sysfs_active_config; + int sysfs_active_preset; }; /* get reference to dev in cscfg_manager */ @@ -88,7 +92,8 @@ int cscfg_preload(void *owner_handle); const struct cscfg_feature_desc *cscfg_get_named_feat_desc(const char *name); int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, int param_idx, u64 value); - +int cscfg_config_sysfs_activation(struct cscfg_config_desc *cfg_desc, bool activate); +void cscfg_config_sysfs_preset(int preset); /* syscfg manager external API */ int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel