From nobody Wed Apr 8 19:13:59 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A13522F3614; Wed, 25 Feb 2026 06:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772000762; cv=none; b=gM4kAV5+FvaW0RQdpz+L32efJ6gIArj8Kx9crQ2htCnZxccpcwAdMaZ5QT1xwXO7HLLjRrKWqg23QRDCM1CKtgyQpPZ0JZohHKm6lkImlsGxwzQJ78hMThwCQ9jSq3HFjTQ7OsABzH/Aki0NnAkwPYZtJ/VRLRNGBfw8anBkg6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772000762; c=relaxed/simple; bh=3lk0eeJEXb0fsUYE5hVJ2k25Rqjt0USGOiHNHCFXizM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Frh61gfyNhHPmXjWswnCJEypFFCKPm4jV94SdbvE8XMWM6oo1EmAPgMH7dOBHNG94Df2el5hk1Iwib5EXm/fn8Cmbg8xXT3Plz1Gx2yiIe2Tqm0xCMQIlxLF1BBW1thYex3TTPjo+dXSibzn9vJAGcKOgj0aKSe1eo9fb9xt8DI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=JjKiaGNy; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="JjKiaGNy" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61ONp0UO134540; Wed, 25 Feb 2026 06:25:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=hxZVxXcr/V6 2gVHq9sxbPJrXaz87OM850jA/r80z02U=; b=JjKiaGNyiisea4BrHloREcHDlqS R0jEQlgzrz94tnoewanmfPd8mmynsktOOJeXlN9S/w8dooKrTF40cbGZ7GQhPgKF mrYmXGTNziOPBFrz6ITh+7rgrHJ1ZsRvlU8peLNC6g//UbCp24WZz0SsvvwePPA/ 3QoUMxttVtdixFxkgSbMFyESvRcR9+PMEotKLJUmOGBWpi0FNaBazxBDfYodqUpb J3SaEK7J7bKkk6TfBF5V5f3rCFHB7iKdIyVJgAhuEIqYL/KLj8rjcV+RgBqnUeFB bYSbeK/5ZAni8ZyrVsy5R34wVmMC17W34F6di17jvaPogJyAV0Qxo0EjLCQ== Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4chp158wv0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Feb 2026 06:24:59 +0000 (GMT) Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTP id 61P6OMbl001167; Wed, 25 Feb 2026 06:24:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 4cf5sm83dw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Feb 2026 06:24:55 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 61P6OsBl001264; Wed, 25 Feb 2026 06:24:54 GMT Received: from hu-devc-blr-u24-a.qualcomm.com (hu-anuppate-blr.qualcomm.com [10.131.36.165]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 61P6OsQv001262 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Feb 2026 06:24:54 +0000 Received: by hu-devc-blr-u24-a.qualcomm.com (Postfix, from userid 486687) id B90A3249BD; Wed, 25 Feb 2026 11:54:53 +0530 (+0530) From: Anup Patel To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Palmer Dabbelt , Paul Walmsley , Greg KH , Alexander Shishkin , Ian Rogers Cc: Alexandre Ghiti , Peter Zijlstra , Ingo Molnar , Namhyung Kim , Mark Rutland , Jiri Olsa , Adrian Hunter , Liang Kan , Mayuresh Chitale , Anup Patel , Atish Patra , Andrew Jones , Sunil V L , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Anup Patel , Mayuresh Chitale Subject: [PATCH v3 03/12] rvtrace: Add functions to create/destroy a trace component path Date: Wed, 25 Feb 2026 11:54:39 +0530 Message-ID: <20260225062448.4027948-4-anup.patel@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260225062448.4027948-1-anup.patel@oss.qualcomm.com> References: <20260225062448.4027948-1-anup.patel@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjI1MDA2MSBTYWx0ZWRfX5dMwES4a5jOL PzkDqE4B5TS7+bBv14TRaOC23/vH3iO8J5J33FV8QkrDIeN0UgsE0wqQnVl65j/BBGI+zkdyQGy ykETFAUG2JuOvtmzFk8S7vObXzxU/bWxH22rCmfNTpnOI6482F1ZZt2Cb5yZHiRNyb7EQmsVpLT cs/S/VYO3cxWDbF7qSVwKI+EmrcKanEQfsYP8gGZRzCFpnLA/A9VaB2DSHfx9RxrrrHnTgKX3QY ROQ7UZrK4A6Ky82caV6+55//z61ojEvqSnn1FyBQBP/YoymYV8JqSYehWwZjoUe/Z7ahVKtbl2H bUXa/pS8S4K+5CmhemaqwmRaQoTo4mBwiT9Ozndmk3wjp+PG6bu1FP1fxWmtHTYXMmwlygDZYyW wdk0KDOxdiKjjAwEWq/+PW2uj53z+1PSpw5OquIE8brrZa3x+xLMysm9vFS+6pUdxASCWi21AHe PxLR3KH+5NcBQ790fkw== X-Proofpoint-GUID: rg5-qdZ-lO1oULxUVaXdVYMxH9_xM5jF X-Proofpoint-ORIG-GUID: rg5-qdZ-lO1oULxUVaXdVYMxH9_xM5jF X-Authority-Analysis: v=2.4 cv=etXSD4pX c=1 sm=1 tr=0 ts=699e95bc cx=c_pps a=Ou0eQOY4+eZoSc0qltEV5Q==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=UaIybRF2xpGp7VXWmyEA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-24_03,2026-02-23_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 phishscore=0 spamscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2602250061 Content-Type: text/plain; charset="utf-8" Trace needs to be configured on a chain of trace components which are connected to each other. These chain of components is also referred to as trace component path. Add functions to create/destroy a trace component path which will be later used by RISC-V trace perf support. Co-developed-by: Mayuresh Chitale Signed-off-by: Mayuresh Chitale Signed-off-by: Anup Patel --- drivers/hwtracing/rvtrace/rvtrace-core.c | 223 +++++++++++++++++++++++ include/linux/rvtrace.h | 43 ++++- 2 files changed, 264 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/rvtrace/rvtrace-core.c b/drivers/hwtracing/r= vtrace/rvtrace-core.c index d69c2236493a..5f40bad215e0 100644 --- a/drivers/hwtracing/rvtrace/rvtrace-core.c +++ b/drivers/hwtracing/rvtrace/rvtrace-core.c @@ -229,6 +229,53 @@ int rvtrace_reset_component(struct rvtrace_platform_da= ta *pdata) } EXPORT_SYMBOL_GPL(rvtrace_reset_component); =20 +static int __rvtrace_walk_output_components(struct rvtrace_component *comp, + bool *stop, void *priv, + int (*fn)(struct rvtrace_component *comp, bool *stop, + struct rvtrace_connection *stop_conn, + void *priv)) +{ + struct rvtrace_connection *conn, *stop_conn =3D NULL; + struct rvtrace_platform_data *pdata =3D comp->pdata; + int i, ret; + + for (i =3D 0; i < pdata->nr_outconns; i++) { + conn =3D pdata->outconns[i]; + ret =3D __rvtrace_walk_output_components(conn->dest_comp, stop, priv, fn= ); + if (ret) + return ret; + if (*stop) { + stop_conn =3D conn; + break; + } + } + + ret =3D fn(comp, stop, stop_conn, priv); + if (ret) + return ret; + + return 0; +} + +int rvtrace_walk_output_components(struct rvtrace_component *comp, void *p= riv, + int (*fn)(struct rvtrace_component *comp, bool *stop, + struct rvtrace_connection *stop_conn, + void *priv)) +{ + bool stop =3D false; + int ret; + + if (!comp || !fn) + return -EINVAL; + + mutex_lock(&rvtrace_mutex); + ret =3D __rvtrace_walk_output_components(comp, &stop, priv, fn); + mutex_unlock(&rvtrace_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(rvtrace_walk_output_components); + struct rvtrace_component *rvtrace_cpu_source(unsigned int cpu) { if (!cpu_present(cpu)) @@ -452,6 +499,182 @@ void rvtrace_unregister_component(struct rvtrace_comp= onent *comp) } EXPORT_SYMBOL_GPL(rvtrace_unregister_component); =20 +struct rvtrace_path_node { + struct list_head head; + struct rvtrace_component *comp; + struct rvtrace_connection *conn; +}; + +struct rvtrace_component *rvtrace_path_source(struct rvtrace_path *path) +{ + struct rvtrace_path_node *node; + + node =3D list_first_entry(&path->comp_list, struct rvtrace_path_node, hea= d); + return node->comp; +} +EXPORT_SYMBOL_GPL(rvtrace_path_source); + +struct rvtrace_component *rvtrace_path_sink(struct rvtrace_path *path) +{ + struct rvtrace_path_node *node; + + node =3D list_last_entry(&path->comp_list, struct rvtrace_path_node, head= ); + return node->comp; +} +EXPORT_SYMBOL_GPL(rvtrace_path_sink); + +static int rvtrace_assign_trace_id(struct rvtrace_path *path) +{ + const struct rvtrace_driver *rtdrv; + struct rvtrace_component *comp; + struct rvtrace_path_node *node; + int trace_id; + + list_for_each_entry(node, &path->comp_list, head) { + comp =3D node->comp; + rtdrv =3D to_rvtrace_driver(comp->dev.driver); + + if (!rtdrv->get_trace_id) + continue; + + trace_id =3D rtdrv->get_trace_id(comp, path->mode); + if (trace_id > 0) { + path->trace_id =3D trace_id; + return 0; + } else if (trace_id < 0) { + return trace_id; + } + } + + return 0; +} + +static void rvtrace_unassign_trace_id(struct rvtrace_path *path) +{ + const struct rvtrace_driver *rtdrv; + struct rvtrace_component *comp; + struct rvtrace_path_node *node; + + list_for_each_entry(node, &path->comp_list, head) { + comp =3D node->comp; + rtdrv =3D to_rvtrace_driver(comp->dev.driver); + + if (!rtdrv->put_trace_id) + continue; + + rtdrv->put_trace_id(comp, path->mode, path->trace_id); + } +} + +static bool rvtrace_path_ready(struct rvtrace_path *path) +{ + struct rvtrace_path_node *node; + + list_for_each_entry(node, &path->comp_list, head) { + if (!node->comp->ready) + return false; + } + + return true; +} + +struct build_path_walk_priv { + struct rvtrace_path *path; + struct rvtrace_component *sink; +}; + +static int build_path_walk_fn(struct rvtrace_component *comp, bool *stop, + struct rvtrace_connection *stop_conn, + void *priv) +{ + struct build_path_walk_priv *ppriv =3D priv; + struct rvtrace_path *path =3D ppriv->path; + struct rvtrace_path_node *node; + + if ((!ppriv->sink && rvtrace_is_sink(comp->pdata)) || + (ppriv->sink && ppriv->sink =3D=3D comp)) + *stop =3D true; + + if (*stop) { + node =3D kzalloc(sizeof(*node), GFP_KERNEL); + if (!path) + return -ENOMEM; + INIT_LIST_HEAD(&node->head); + rvtrace_get_component(comp); + node->comp =3D comp; + node->conn =3D stop_conn; + list_add(&node->head, &path->comp_list); + } + + return 0; +} + +static void rvtrace_release_path_nodes(struct rvtrace_path *path) +{ + struct rvtrace_path_node *node, *node1; + + list_for_each_entry_safe(node, node1, &path->comp_list, head) { + list_del(&node->head); + rvtrace_put_component(node->comp); + kfree(node); + } +} + +struct rvtrace_path *rvtrace_create_path(struct rvtrace_component *source, + struct rvtrace_component *sink, + enum rvtrace_component_mode mode) +{ + struct build_path_walk_priv priv; + struct rvtrace_path *path; + int ret =3D 0; + + if (!source || mode >=3D RVTRACE_COMPONENT_MODE_MAX) { + ret =3D -EINVAL; + goto err_out; + } + + path =3D kzalloc(sizeof(*path), GFP_KERNEL); + if (!path) { + ret =3D -ENOMEM; + goto err_out; + } + INIT_LIST_HEAD(&path->comp_list); + path->mode =3D mode; + path->trace_id =3D RVTRACE_INVALID_TRACE_ID; + + priv.path =3D path; + priv.sink =3D sink; + ret =3D rvtrace_walk_output_components(source, &priv, build_path_walk_fn); + if (ret < 0) + goto err_release_path_nodes; + + if (!rvtrace_path_ready(path)) { + ret =3D -EOPNOTSUPP; + goto err_release_path_nodes; + } + + ret =3D rvtrace_assign_trace_id(path); + if (ret < 0) + goto err_release_path_nodes; + + return path; + +err_release_path_nodes: + rvtrace_release_path_nodes(path); + kfree(path); +err_out: + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(rvtrace_create_path); + +void rvtrace_destroy_path(struct rvtrace_path *path) +{ + rvtrace_unassign_trace_id(path); + rvtrace_release_path_nodes(path); + kfree(path); +} +EXPORT_SYMBOL_GPL(rvtrace_destroy_path); + int __rvtrace_register_driver(struct module *owner, struct rvtrace_driver = *rtdrv) { rtdrv->driver.owner =3D owner; diff --git a/include/linux/rvtrace.h b/include/linux/rvtrace.h index d6be6e3cc10f..00b63fa22da9 100644 --- a/include/linux/rvtrace.h +++ b/include/linux/rvtrace.h @@ -8,6 +8,8 @@ =20 #include #include +#include +#include #include #include #include @@ -72,6 +74,12 @@ enum rvtrace_component_impid { RVTRACE_COMPONENT_IMPID_MAX }; =20 +/* Supported usage modes for RISC-V trace components */ +enum rvtrace_component_mode { + RVTRACE_COMPONENT_MODE_PERF, + RVTRACE_COMPONENT_MODE_MAX +}; + /** * struct rvtrace_connection - Representation of a physical connection bet= ween * two RISC-V trace components. @@ -239,6 +247,10 @@ int rvtrace_enable_component(struct rvtrace_platform_d= ata *pdata); int rvtrace_disable_component(struct rvtrace_platform_data *pdata); int rvtrace_reset_component(struct rvtrace_platform_data *pdata); =20 +int rvtrace_walk_output_components(struct rvtrace_component *comp, void *p= riv, + int (*fn)(struct rvtrace_component *comp, bool *stop, + struct rvtrace_connection *stop_conn, + void *priv)); struct rvtrace_component *rvtrace_cpu_source(unsigned int cpu); =20 struct rvtrace_component *rvtrace_register_component(enum rvtrace_componen= t_type type, @@ -246,17 +258,44 @@ struct rvtrace_component *rvtrace_register_component(= enum rvtrace_component_type struct rvtrace_platform_data *pdata); void rvtrace_unregister_component(struct rvtrace_component *comp); =20 +/** + * struct rvtrace_path - Representation of a RISC-V trace path from source= to sink + * @comp_list: List of RISC-V trace components in the path + * @mode: Usage mode for RISC-V trace components + * @trace_id: ID of the trace source (typically hart id) + */ +struct rvtrace_path { + struct list_head comp_list; + enum rvtrace_component_mode mode; + u32 trace_id; +#define RVTRACE_INVALID_TRACE_ID 0 +}; + +struct rvtrace_component *rvtrace_path_source(struct rvtrace_path *path); +struct rvtrace_component *rvtrace_path_sink(struct rvtrace_path *path); +struct rvtrace_path *rvtrace_create_path(struct rvtrace_component *source, + struct rvtrace_component *sink, + enum rvtrace_component_mode mode); +void rvtrace_destroy_path(struct rvtrace_path *path); + /** * struct rvtrace_driver - Representation of a RISC-V trace driver * id_table: Table to match components handled by the driver - * probe: Driver probe() function - * remove: Driver remove() function + * probe: Driver probe() function + * remove: Driver remove() function + * get_trace_id: Get/allocate a trace ID + * put_trace_id: Put/free a trace ID * driver: Device driver instance */ struct rvtrace_driver { const struct rvtrace_component_id *id_table; int (*probe)(struct rvtrace_component *comp); void (*remove)(struct rvtrace_component *comp); + int (*get_trace_id)(struct rvtrace_component *comp, + enum rvtrace_component_mode mode); + void (*put_trace_id)(struct rvtrace_component *comp, + enum rvtrace_component_mode mode, + u32 trace_id); struct device_driver driver; }; =20 --=20 2.43.0