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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1CA26CD13CF for ; Wed, 12 Nov 2025 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2uusonc4IVmEmKIwyNSABzF5dmeq8W3J1RDTb9RhE1k=; b=qwKz1UOZlbE/M/qw3fQXbOL1qe lq1r+OxP03ETUuzCgEOEGtoXwvaJt+cKq4XnXh6hVMIY/YRA8opU91XR7gPhxJg/7fpUWDMu+Aipl hczR71tnnf65hlDszL/DNaBUFGG2jxEICcJMxM5gMX4Xk9iS3zXgzNUDlcM607F/A/svRnIgnMvPU qPAzteZiXp5Kc51UhstRf4TSOON0ZdrH0uRSGu4t2eQ+iLD+iuSLsemHa+oLl5iLNuJGUX7bkOkHQ cx9tJJ/5yhkwLmNasJkYkXynjj9dVj2qS/8Msx4bx2ZEOpXkgDkVEYl2xwyMqCChifhr8HG1Ei36c CsfXbkKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vJCg9-000000092JM-0U9V; Wed, 12 Nov 2025 15:22:37 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vJCg5-000000092GD-2pD5 for linux-arm-kernel@lists.infradead.org; Wed, 12 Nov 2025 15:22:34 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4775895d69cso5398955e9.0 for ; Wed, 12 Nov 2025 07:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1762960952; x=1763565752; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2uusonc4IVmEmKIwyNSABzF5dmeq8W3J1RDTb9RhE1k=; b=R5GfqDPRApYHzhMIak6LkH6xYhYfCDJV/O+Ngx0veAy6YbU5cgYVpXYzN/28kFxb7r oNHop2YUQMJ1A1Dy9R3eMjsQM8aK5iXffupKr3WwlYSUH2MB44/tNJ0BBfQRgD/wm29h t/IOKDq54vOLwtfs+TKNLzLTh9Kbn/9DvYlRztq5c3DA8A6wMBVhWdXpsh4LJ/+oEpRm NTBWgo100cgrzGqb1GcBYF1qZh1qycNzfJm0dbI4YpX8oIsTkqj2BulaaVZsYmVStJdH wyGx5M1sT3t1e+HxOT4GIvqS5trQyKKBonZNAzJQxKx/M1C2eqKLY8x1UAcN7yEBPbaM zq8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762960952; x=1763565752; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2uusonc4IVmEmKIwyNSABzF5dmeq8W3J1RDTb9RhE1k=; b=lDL1nxitbcsjOGItJf1CgOb8R9UY+d3IAzwXV426JHAhRT6806frWknsKV22LQeIlj jmYwzwUm1m8ST5ZAVUIyVsFtdFDYFAbFnqJeWxDGtNPE5PLJnSbFArTOLg3QmGTHfQL7 6eQ134Lo5mx74vEftLQlVHZi37MvscrZ/YModtO4yAt95pZZGCGokS3JJT5g9JE+9f7a khLIZi7MGuVnVyqfmQhn59upZviNPYtiTj1rZjdUlShAeLWcfwWeZDO7ciD/KwehT7qC v9S2EDBkwME9VlgxVruiUY2mObXlkUTcIO8kwSTrRYKHhnLyyZeSH1E9mwNHfz33ikEC 0ubA== X-Forwarded-Encrypted: i=1; AJvYcCV3qxLHubBYHJS/whnQ7ZZuKogEbtnBxozpGSGBubpY5I3VWJgOy5d64t8Aqg0aqAI00iHyfCIL5RrPFfm7H0w0@lists.infradead.org X-Gm-Message-State: AOJu0Yw7u8gKkWqe+JMDMSvA5HRV0dTAT4AkvaWyaXbqmpo8c8cDoYJM ynh4OAVlFggRD7SZX87gURvPirgxFgBdBMYF2KGAkFuNDadFQaLLPKjSD80g4Bnu6Ck= X-Gm-Gg: ASbGnctcke/Z97UxgC9QeR5AkozRJPfXh8xmRtWcsS9i9EyN873oEOio5l+ugFmHS0T M5uZJkFMjU8wvIxKj8tM6ryGdUbTtGXp4Rfp1TkRhWzsloWl6GopDO0ZEXOcJoRw92cq6luy1xB lpWDEi2pbkS5WhTuqGSZPhJATvA/n2EQ+TxUjX8H8ZL/3YQQykrW+bHHCU+hAlN649ffz15SYpp Ms4u+vaOKrBV4YYo8C3XppSzavuqPRve5pJcMQWMPfXm7bzSM6GURd8NZTZL6NkogTGNuRES5G4 cCn+mHvLoxpb93OafNCrgPIIjh5B36FiR40mJUcJFlPGzWxEgqXZWWBX0KChZmi8GZFvFpFJHHA LjedeyhrHmS3rCdZI9kfM7LwZJswGX9VgExGq6NYZG+LLE5Md7K3NzPpe3uj759Ev1f3u6l9Z5Q uNpE+EqZuv6w== X-Google-Smtp-Source: AGHT+IE9sB9s/FnD51s9bvHKIuSCDAZDLn+Lwu16yVjVYz52tbr9N0U5pqNtEoKseunsJWxOI0/4tA== X-Received: by 2002:a05:600c:a43:b0:477:73cc:82c2 with SMTP id 5b1f17b1804b1-4778707ba5bmr33877885e9.9.1762960951695; Wed, 12 Nov 2025 07:22:31 -0800 (PST) Received: from ho-tower-lan.lan ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42ac677ab75sm33573485f8f.35.2025.11.12.07.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 07:22:31 -0800 (PST) From: James Clark Date: Wed, 12 Nov 2025 15:22:09 +0000 Subject: [PATCH v4 03/13] coresight: Refactor etm4_config_timestamp_event() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251112-james-cs-syncfreq-v4-3-165ba21401dc@linaro.org> References: <20251112-james-cs-syncfreq-v4-0-165ba21401dc@linaro.org> In-Reply-To: <20251112-james-cs-syncfreq-v4-0-165ba21401dc@linaro.org> To: Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jonathan Corbet , Leo Yan Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251112_072233_761742_9FE0396A X-CRM114-Status: GOOD ( 23.86 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Remove some of the magic numbers and try to clarify some of the documentation so it's clearer how this sets up the timestamp interval. Return errors directly instead of jumping to out and returning ret, nothing needs to be cleaned up at the end and it only obscures the flow and return value. Reviewed-by: Leo Yan Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 96 ++++++++++++++-------- drivers/hwtracing/coresight/coresight-etm4x.h | 23 ++++-- 2 files changed, 81 insertions(+), 38 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 1c17d5472920..380a7840adb8 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -651,18 +651,33 @@ static void etm4_enable_sysfs_smp_call(void *info) * TRCRSCTLR1 (always true) used to get the counter to decrement. From * there a resource selector is configured with the counter and the * timestamp control register to use the resource selector to trigger the - * event that will insert a timestamp packet in the stream. + * event that will insert a timestamp packet in the stream: + * + * +--------------+ + * | Resource 1 | fixed "always-true" resource + * +--------------+ + * | + * +------v-------+ + * | Counter x | (reload to 1 on underflow) + * +--------------+ + * | + * +------v--------------+ + * | Resource Selector y | (trigger on counter x == 0) + * +---------------------+ + * | + * +------v---------------+ + * | Timestamp Generator | (timestamp on resource y) + * +----------------------+ */ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) { - int ctridx, ret = -EINVAL; - int counter, rselector; - u32 val = 0; + int ctridx; + int rselector; struct etmv4_config *config = &drvdata->config; /* No point in trying if we don't have at least one counter */ if (!drvdata->nr_cntr) - goto out; + return -EINVAL; /* Find a counter that hasn't been initialised */ for (ctridx = 0; ctridx < drvdata->nr_cntr; ctridx++) @@ -672,15 +687,19 @@ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) /* All the counters have been configured already, bail out */ if (ctridx == drvdata->nr_cntr) { pr_debug("%s: no available counter found\n", __func__); - ret = -ENOSPC; - goto out; + return -ENOSPC; } /* - * Searching for an available resource selector to use, starting at - * '2' since every implementation has at least 2 resource selector. - * ETMIDR4 gives the number of resource selector _pairs_, - * hence multiply by 2. + * Searching for an available resource selector to use, starting at '2' + * since resource 0 is the fixed 'always returns false' resource and 1 + * is the fixed 'always returns true' resource. See IHI0064H_b '7.3.64 + * TRCRSCTLRn, Resource Selection Control Registers, n=2-31'. If there + * are no resources, there would also be no counters so wouldn't get + * here. + * + * ETMIDR4 gives the number of resource selector _pairs_, hence multiply + * by 2. */ for (rselector = 2; rselector < drvdata->nr_resource * 2; rselector++) if (!config->res_ctrl[rselector]) @@ -689,13 +708,9 @@ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) if (rselector == drvdata->nr_resource * 2) { pr_debug("%s: no available resource selector found\n", __func__); - ret = -ENOSPC; - goto out; + return -ENOSPC; } - /* Remember what counter we used */ - counter = 1 << ctridx; - /* * Initialise original and reload counter value to the smallest * possible value in order to get as much precision as we can. @@ -703,26 +718,41 @@ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) config->cntr_val[ctridx] = 1; config->cntrldvr[ctridx] = 1; - /* Set the trace counter control register */ - val = 0x1 << 16 | /* Bit 16, reload counter automatically */ - 0x0 << 7 | /* Select single resource selector */ - 0x1; /* Resource selector 1, i.e always true */ - - config->cntr_ctrl[ctridx] = val; - - val = 0x2 << 16 | /* Group 0b0010 - Counter and sequencers */ - counter << 0; /* Counter to use */ - - config->res_ctrl[rselector] = val; + /* + * Trace Counter Control Register TRCCNTCTLRn + * + * CNTCHAIN = 0, don't reload on the previous counter + * RLDSELF = true, reload counter automatically on underflow + * RLDTYPE = 0, one reload input resource + * RLDSEL = RES_SEL_FALSE (0), reload on false resource (never reload) + * CNTTYPE = 0, one count input resource + * CNTSEL = RES_SEL_TRUE (1), count fixed 'always true' resource (always decrement) + */ + config->cntr_ctrl[ctridx] = TRCCNTCTLRn_RLDSELF | + FIELD_PREP(TRCCNTCTLRn_RLDSEL_MASK, ETM_RES_SEL_FALSE) | + FIELD_PREP(TRCCNTCTLRn_CNTSEL_MASK, ETM_RES_SEL_TRUE); - val = 0x0 << 7 | /* Select single resource selector */ - rselector; /* Resource selector */ + /* + * Resource Selection Control Register TRCRSCTLRn + * + * PAIRINV = 0, INV = 0, don't invert + * GROUP = 2, SELECT = ctridx, trigger when counter 'ctridx' reaches 0 + * + * Multiple counters can be selected, and each bit signifies a counter, + * so set bit 'ctridx' to select our counter. + */ + config->res_ctrl[rselector] = FIELD_PREP(TRCRSCTLRn_GROUP_MASK, 2) | + FIELD_PREP(TRCRSCTLRn_SELECT_MASK, 1 << ctridx); - config->ts_ctrl = val; + /* + * Global Timestamp Control Register TRCTSCTLR + * + * TYPE = 0, one input resource + * SEL = rselector, generate timestamp on resource 'rselector' + */ + config->ts_ctrl = FIELD_PREP(TRCTSCTLR_SEL_MASK, rselector); - ret = 0; -out: - return ret; + return 0; } static int etm4_parse_event_config(struct coresight_device *csdev, diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtracing/coresight/coresight-etm4x.h index 8f546764908c..0f83a29320e6 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -225,6 +225,19 @@ #define TRCRSCTLRn_GROUP_MASK GENMASK(19, 16) #define TRCRSCTLRn_SELECT_MASK GENMASK(15, 0) +#define TRCCNTCTLRn_CNTCHAIN BIT(17) +#define TRCCNTCTLRn_RLDSELF BIT(16) +#define TRCCNTCTLRn_RLDTYPE BIT(15) +#define TRCCNTCTLRn_RLDSEL_MASK GENMASK(12, 8) +#define TRCCNTCTLRn_CNTTYPE_MASK BIT(7) +#define TRCCNTCTLRn_CNTSEL_MASK GENMASK(4, 0) + +#define TRCTSCTLR_TYPE BIT(7) +#define TRCTSCTLR_SEL_MASK GENMASK(4, 0) + +#define ETM_RES_SEL_FALSE 0 /* Fixed function 'always false' resource selector */ +#define ETM_RES_SEL_TRUE 1 /* Fixed function 'always true' resource selector */ + /* * System instructions to access ETM registers. * See ETMv4.4 spec ARM IHI0064F section 4.3.6 System instructions @@ -825,7 +838,7 @@ struct etmv4_config { u32 eventctrl0; u32 eventctrl1; u32 stall_ctrl; - u32 ts_ctrl; + u32 ts_ctrl; /* TRCTSCTLR */ u32 ccctlr; u32 bb_ctrl; u32 vinst_ctrl; @@ -838,11 +851,11 @@ struct etmv4_config { u32 seq_rst; u32 seq_state; u8 cntr_idx; - u32 cntrldvr[ETMv4_MAX_CNTR]; - u32 cntr_ctrl[ETMv4_MAX_CNTR]; - u32 cntr_val[ETMv4_MAX_CNTR]; + u32 cntrldvr[ETMv4_MAX_CNTR]; /* TRCCNTRLDVRn */ + u32 cntr_ctrl[ETMv4_MAX_CNTR]; /* TRCCNTCTLRn */ + u32 cntr_val[ETMv4_MAX_CNTR]; /* TRCCNTVRn */ u8 res_idx; - u32 res_ctrl[ETM_MAX_RES_SEL]; + u32 res_ctrl[ETM_MAX_RES_SEL]; /* TRCRSCTLRn */ u8 ss_idx; u32 ss_ctrl[ETM_MAX_SS_CMP]; u32 ss_status[ETM_MAX_SS_CMP]; -- 2.34.1