From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25E2D23B607 for ; Mon, 11 Aug 2025 09:32:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904768; cv=none; b=EPLPDZs20epYfgOSYBDNff1Q75ut7s2XM8rPNAl2XEO2niMHi4gJ1Y0QBqSfJFExSxV8qfhH30P/20HvbvU1fBlTVMe2wMjgqIYqP7czbtoooAE4n12NA35vLtlDcjxjhgwoM0uCiq5dzlHqYlNXGshZqDSCvYHNA41VdoslYjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904768; c=relaxed/simple; bh=U8TkMqWfDTBWjb8GRi9+VCChj3K0XOJrpYPU0RGTnw8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OvA4hZVkGXo5h1zaIXwdg/IenkhQpOpxbJEp3YFAJV5Fixwbl2FFbcsgYMhniNtjIqd6ww/ZcLQ3MQlctXADfNYPNKc32idiWPAumK5dViFZ3WCsOkVV2v1+UI+VekxDI558ye3Pb5aBBA+ET8E55s9v6yQ4vWY61epmKshRJd8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=fail smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WaPV97H/; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WaPV97H/" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3b782cca9a0so2685503f8f.1 for ; Mon, 11 Aug 2025 02:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1754904764; x=1755509564; darn=vger.kernel.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=UCFJWq6hVWDLLnb3WEoK3x2DCujP3OgS7K9EwJG0Zgk=; b=WaPV97H/1HVJobO0jHweb5V7XspdUpfj+yWdrWKqhrFT7c2jh40RueECwPR6ijJPgi iWlHxaqkpgsPsw1nnbhw4uWt+O5uy+RParOlQU8or98tTgd+qQ/Q6FFO9Aauygz5hdnl vO2iK1X8rH78rhbsbCI1xUPA8yD5aLK8qwek8ukiQAfaEHZei2NkwuQRPpddsgG8fRz4 1nM0Vi3cgpSVRo7IxfqlMieyVsLzsxw+eYskWvgDW90Id3Ql9zNYcUH9I3WeJ87qNQV8 /tePCpy2Az/lvt3laqPj45j3K5xPzUmNHVMZzLcRzECt/4pm6yrAgTraL7bzc1wIqC1D eEog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754904764; x=1755509564; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UCFJWq6hVWDLLnb3WEoK3x2DCujP3OgS7K9EwJG0Zgk=; b=XwaOdc9PXjjdOkLyTt0qAYEcWDRE6y3Wx7xHJSHINQq9oER3W3uSaAZ6IcDedHnkFM d4L3Jl9u7eF77Pc5M52ACOPs20VPS3M2CKGjikGETo7MqlXHm1pBy8D5Hn8Ls7wmrm9b UGyzfYX8+J8SNdc9NY8D5evxbaarNhuYNqBAsLEkTgblCkWQyOWDdICK9cld66IM+SpK oVvZaDkj/vyCexNlO6o+3jZnaDZo7k+4gHUk0nVeX15ZZm7puxlNYQbCLWlM0wVmBwQ+ c6fHHODt65ikgHNIzyOwVRdwp9cZI04AIrrxITzl5J8VxxDDN/aTS74trNdZDGuMTIpi 2C+g== X-Forwarded-Encrypted: i=1; AJvYcCVsknRtXO5CX0Bq+IdR1+F1YaUv4VroUmxSbffY1NsJqlL+rSSzHiYZ+ULBqYvTO3L2ZQR/ZaJX3NQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyVcvhO9xsPfoo91841u4O47EIfgJtEPYj5EQmUJ53FYwmqjhsl WAemM4VMxNPoY3MXxIc4qXj08sRKrxbmmiwZb44sSXJW5kKx2pb8ThabMDCoklcLNgk= X-Gm-Gg: ASbGncv9hep+Urq/5udtfbBb30+qHXwSY9LwlhQ+zg0hmC88DvRe7ftAG2HWUEZUK8P AflS4rHuwKVbS6Vk6SdsgvyFyIjOgMg1D0YGnNRY128MCNakorWMAUmHL/UJ1CyiTXdPma8Q7k6 NLJaX2mdprng3hkkLMbbZSlZ8RoBcuM/gZR6Xjp7f3aFaUwg5B5nvJmZhGHluKgttHGZPje0iXN ateT3PnS0SMmmTHZSl+Ny0J2A/AudKj0Tl487gk48uBdX51f5EO4gx5ITyWrsuBxL8CuZ8aZx3F eIi9/kMWXQt5R6S1lZSnecfNQw1xzKZQWMsirjVUaqWh0iP+MYMk4xsw/I8ayaHVzmaBbPOG1Z3 tNfHNsvcEIdewE00Vn7IUnveDFAtdMLk= X-Google-Smtp-Source: AGHT+IGwXBJru7lzSvqSg6s6aOA3Q/MWqjAM+gI5z5Pyj6soY54J04BAuUaaiohr/CZ2BO2EaR5SGw== X-Received: by 2002:a05:6000:430e:b0:3b8:d12f:67ef with SMTP id ffacd0b85a97d-3b900b5060fmr9681173f8f.31.1754904764235; Mon, 11 Aug 2025 02:32:44 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c45346asm39904799f8f.39.2025.08.11.02.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Aug 2025 02:32:43 -0700 (PDT) From: James Clark Date: Mon, 11 Aug 2025 10:32:09 +0100 Subject: [PATCH 4/6] coresight: Refactor etm4_config_timestamp_event() Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250811-james-cs-syncfreq-v1-4-b001cd6e3404@linaro.org> References: <20250811-james-cs-syncfreq-v1-0-b001cd6e3404@linaro.org> In-Reply-To: <20250811-james-cs-syncfreq-v1-0-b001cd6e3404@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 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. Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 95 ++++++++++++++-------- drivers/hwtracing/coresight/coresight-etm4x.h | 20 +++-- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index cbea200489c8..1a2d02bdcb88 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -608,18 +608,33 @@ static void etm4_enable_hw_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++) @@ -629,15 +644,17 @@ 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'. + * + * 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]) @@ -646,13 +663,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. @@ -660,26 +673,42 @@ 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 = 0, reload on resource 0 (fixed always false resource, never + * reload) + * CNTTYPE = 0, one count input resource + * CNTSEL = 1, count on resource 1 (fixed always true resource, always + * decrement) + */ + config->cntr_ctrl[ctridx] = TRCCNTCTLRn_RLDSELF | + FIELD_PREP(TRCCNTCTLRn_CNTSEL_MASK, 1); - 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 1c67b263b01b..aaa6633b2d67 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -224,6 +224,16 @@ #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) + /* * System instructions to access ETM registers. * See ETMv4.4 spec ARM IHI0064F section 4.3.6 System instructions @@ -823,7 +833,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; @@ -843,11 +853,11 @@ struct etmv4_config { u32 seq_rst; u32 seq_state; - 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 */ - u32 res_ctrl[ETM_MAX_RES_SEL]; + u32 res_ctrl[ETM_MAX_RES_SEL]; /* TRCRSCTLRn */ u32 ss_ctrl[ETM_MAX_SS_CMP]; u32 ss_status[ETM_MAX_SS_CMP]; -- 2.34.1