From nobody Mon Dec 1 22:35:06 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 A5FBD32936E for ; Fri, 28 Nov 2025 11:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764330962; cv=none; b=G2HMH0+7zh4pKwaKugYzfLCuTLT+mpsYUCNOSnzPXeUhyzQz2Zx+5CKhdRBWPNXyKFYOEuXY8IXos0QlQVXMBeuv5xf253oq2pRev1yLt3XCcDh+g9GFY/DJMM5iC3uRP8gJ0B5SOELfgHxyux1ydPbiNQLSFeNpWq9o+YU5YSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764330962; c=relaxed/simple; bh=oojn1Q2oz2LQF81+BuEH6IiwZcCbYqPy0W372S4oSK4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kCMzCAYetWTU6c0NQtMUVLkWnWgMd60nTEtaZu8Kt4/O5fIzoqP7TiiH5VwnNFFHr2jl7APf7542tW4xtPH8++MnJ9UN3qjy3QQ1u2vWINRKIvGMqkIi4M9DoOud7kfRSPGBEbx2QCpIFg2wGAZyc1HprlB5FXj/vF20xu4t3ew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=v8tJSr1v; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass 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="v8tJSr1v" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-477563e28a3so12395465e9.1 for ; Fri, 28 Nov 2025 03:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764330958; x=1764935758; 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=f/X8/s0XmEBVcp92RiDvltwq9YKc36aF7AB3/15oKmM=; b=v8tJSr1vdIYJSeGzB797iropr0GbsX31uHkrXrtF8bSfsz6JN7h8PseYGtaq+lw0bP IpKA4Y89jbLkvifhC9fWu6SNK+wRQi1ZqlBuVLW3xuDQcAqZtZ5UrDlptCRCsWlXVSOn iskDuTj58juJ09ZF1LkbgS1JM5DAEM9K36syjUzVLa1lxeEpwRBIEs6paw2i+/pPlcKr tbG8Bo0J7xJfYdNMmzQaOS8fqh3XYurwvcnfQTh/yaO+/M+qjHpgzKOziSdQFX8SIjZ3 ya7VAPmw9Kj9KvjcAnv3Kxfkg30ZQvKeT2axccye621cQ5aQWoLOarTG/bXvlh7Lvz2W DLhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764330958; x=1764935758; 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=f/X8/s0XmEBVcp92RiDvltwq9YKc36aF7AB3/15oKmM=; b=YTlucEf/RAi6X/4s9MvK5edR1gz20oqvRumG+hRmLOnfur9VlvfJcqNboLm1V//9jn m7kGCtdyUYejCfOXZDYqUB4jZo97DFDpQtnxIkUT1xxwhPMV810W0hxzrcnOXF39lkNh dMamAfU1Bd7h93jYmfeYxtxnxLVSF5iEoRoC1BJPK8vAgJZkhfnx8z96+JxkHc0UNpQg ws3NUFoHnfwhhr5nbn0DV/eA+BWglB65MfJuDRs22RZpsJQqe3J0F8GGXA9DLRMibqOo mM1Pv5wfswQ/kyL3oDM+SMO4i5efvKSKQls5HhxwbHCT1IV2RHbYGZb1VOHpJ+IcOhTg MRoQ== X-Forwarded-Encrypted: i=1; AJvYcCWCoGs6Dv12rN9JjXN1dH+C45AAWqh6l89TvSmpab74XtxK6KTux85TF3esnWJg17tob6iAx9AFMnGD5sQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwNSYFgq43KL82C8C7fk1oR1QD4rHG04cGWWBTpmNdGWnYddZ5B EwQDze5cNp6Z/2iWaUCdOy7togEijHBDCVamwKoLj3VbhGsGlKFDMxN8yO9re4pmTJ0= X-Gm-Gg: ASbGncsJB4zEg1a0uac50P8AzyoVXagW1kt4igcUPWoKNa3IfrKigI1FFhlX6ATdDfW QL4TdValrA/++qPz3CjfWEYQEiOz6eSNfqtyts7jfjRdLCvk+cl/CSEsqtpP5wAnA3QpzYJUPTr gv8KhViy6T+2A0cOj+pL0YtlFoCYv5/CgxwImKXZ9XQVXiKnmNSW2wWhCELTQS3aLy+JDJP5W8X FWeUX7rVNBoDKkboEMdznpVW36EB9TjQgc1F9aQYgyp1oPq0XabzqIN+9Lb7/RNzCT09psAGeGZ k/WjudqHCOWM6LH6NZtCgRQHNlBURinb4Nn5N6gf8IM+G405MHf1GT5YrZJpkFCYsEi1QJvhk6g gg5nC+kwWPzLeeizAgcykZIwpUlrW08sWvkNUQur2MMMtF2qtbvpghxGjO//CC0Ya5rNoBZs/Xa TRtKY4OewawV8mhCe6qpYS X-Google-Smtp-Source: AGHT+IGaQRyFBvi4xXG1OSwj8+KoP6rOM24a0UhWoYDoOvAcD4TFnR9g6F/aB9eSqTg5kCu4JYRodQ== X-Received: by 2002:a05:600c:4746:b0:477:a289:d854 with SMTP id 5b1f17b1804b1-477c04cfa31mr284161715e9.5.1764330957915; Fri, 28 Nov 2025 03:55:57 -0800 (PST) Received: from ho-tower-lan.lan ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4790adc8bc7sm158974465e9.1.2025.11.28.03.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Nov 2025 03:55:57 -0800 (PST) From: James Clark Date: Fri, 28 Nov 2025 11:55:21 +0000 Subject: [PATCH v8 09/13] coresight: Interpret ETMv4 config with ATTR_CFG_GET_FLD() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251128-james-cs-syncfreq-v8-9-4d319764cc58@linaro.org> References: <20251128-james-cs-syncfreq-v8-0-4d319764cc58@linaro.org> In-Reply-To: <20251128-james-cs-syncfreq-v8-0-4d319764cc58@linaro.org> To: Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jonathan Corbet , Leo Yan , Randy Dunlap 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 hard coded bitfield extractions and shifts and replace with ATTR_CFG_GET_FLD(). ETM4_CFG_BIT_BB was defined to give the register bit positions to userspace, TRCCONFIGR_BB should be used in the kernel so replace it. Reviewed-by: Leo Yan Reviewed-by: Mike Leach Tested-by: Leo Yan Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 44 ++++++++++--------= ---- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/h= wtracing/coresight/coresight-etm4x-core.c index 2ec2ae1fef58..b457f182efbe 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -780,17 +781,17 @@ static int etm4_parse_event_config(struct coresight_d= evice *csdev, goto out; =20 /* Go from generic option to ETMv4 specifics */ - if (attr->config & BIT(ETM_OPT_CYCACC)) { + if (ATTR_CFG_GET_FLD(attr, cycacc)) { config->cfg |=3D TRCCONFIGR_CCI; /* TRM: Must program this for cycacc to work */ - cc_threshold =3D attr->config3 & ETM_CYC_THRESHOLD_MASK; + cc_threshold =3D ATTR_CFG_GET_FLD(attr, cc_threshold); if (!cc_threshold) cc_threshold =3D ETM_CYC_THRESHOLD_DEFAULT; if (cc_threshold < drvdata->ccitmin) cc_threshold =3D drvdata->ccitmin; config->ccctlr =3D cc_threshold; } - if (attr->config & BIT(ETM_OPT_TS)) { + if (ATTR_CFG_GET_FLD(attr, timestamp)) { /* * Configure timestamps to be emitted at regular intervals in * order to correlate instructions executed on different CPUs @@ -810,17 +811,17 @@ static int etm4_parse_event_config(struct coresight_d= evice *csdev, } =20 /* Only trace contextID when runs in root PID namespace */ - if ((attr->config & BIT(ETM_OPT_CTXTID)) && + if (ATTR_CFG_GET_FLD(attr, contextid1) && task_is_in_init_pid_ns(current)) /* bit[6], Context ID tracing bit */ config->cfg |=3D TRCCONFIGR_CID; =20 /* - * If set bit ETM_OPT_CTXTID2 in perf config, this asks to trace VMID - * for recording CONTEXTIDR_EL2. Do not enable VMID tracing if the - * kernel is not running in EL2. + * If set bit contextid2 in perf config, this asks to trace VMID for + * recording CONTEXTIDR_EL2. Do not enable VMID tracing if the kernel + * is not running in EL2. */ - if (attr->config & BIT(ETM_OPT_CTXTID2)) { + if (ATTR_CFG_GET_FLD(attr, contextid2)) { if (!is_kernel_in_hyp_mode()) { ret =3D -EINVAL; goto out; @@ -831,26 +832,22 @@ static int etm4_parse_event_config(struct coresight_d= evice *csdev, } =20 /* return stack - enable if selected and supported */ - if ((attr->config & BIT(ETM_OPT_RETSTK)) && drvdata->retstack) + if (ATTR_CFG_GET_FLD(attr, retstack) && drvdata->retstack) /* bit[12], Return stack enable bit */ config->cfg |=3D TRCCONFIGR_RS; =20 /* - * Set any selected configuration and preset. - * - * This extracts the values of PMU_FORMAT_ATTR(configid) and PMU_FORMAT_A= TTR(preset) - * in the perf attributes defined in coresight-etm-perf.c. - * configid uses bits 63:32 of attr->config2, preset uses bits 3:0 of att= r->config. - * A zero configid means no configuration active, preset =3D 0 means no p= reset selected. + * Set any selected configuration and preset. A zero configid means no + * configuration active, preset =3D 0 means no preset selected. */ - if (attr->config2 & GENMASK_ULL(63, 32)) { - cfg_hash =3D (u32)(attr->config2 >> 32); - preset =3D attr->config & 0xF; + cfg_hash =3D ATTR_CFG_GET_FLD(attr, configid); + if (cfg_hash) { + preset =3D ATTR_CFG_GET_FLD(attr, preset); ret =3D cscfg_csdev_enable_active_config(csdev, cfg_hash, preset); } =20 /* branch broadcast - enable if selected and supported */ - if (attr->config & BIT(ETM_OPT_BRANCH_BROADCAST)) { + if (ATTR_CFG_GET_FLD(attr, branch_broadcast)) { if (!drvdata->trcbb) { /* * Missing BB support could cause silent decode errors @@ -859,7 +856,7 @@ static int etm4_parse_event_config(struct coresight_dev= ice *csdev, ret =3D -EINVAL; goto out; } else { - config->cfg |=3D BIT(ETM4_CFG_BIT_BB); + config->cfg |=3D TRCCONFIGR_BB; } } =20 @@ -1083,11 +1080,8 @@ static int etm4_disable_perf(struct coresight_device= *csdev, return -EINVAL; =20 etm4_disable_hw(drvdata); - /* - * The config_id occupies bits 63:32 of the config2 perf event attr - * field. If this is non-zero then we will have enabled a config. - */ - if (attr->config2 & GENMASK_ULL(63, 32)) + /* If configid is non-zero then we will have enabled a config. */ + if (ATTR_CFG_GET_FLD(attr, configid)) cscfg_csdev_disable_active_config(csdev); =20 /* --=20 2.34.1