From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 8B2F93FB071; Wed, 29 Apr 2026 12:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777467142; cv=none; b=Pj91LC3T+Bv4zp2unF4ooUq3S6VnfgfYEOAXU7F/j/rP4ZRF9Au3V0C3Yx/GSLRyqCIF1s9Z4T3r/z/nZORCQQM6KHO8eZ7nGPyP3cp6/37fF39O0ggbEPVpsat+aOII9TIBVGdR94a6EwIMSB7OdSZ+BZzkhUkCGBfUHL1npmw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777467142; c=relaxed/simple; bh=cYR1n+zirgG0zH8tcvTp+EPdhOZ9Ul9RSaJkma0s8SE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DIyLwvos2jnHNGKlA5buZQIJU8XQHHQNf1uXYH56hHS/1Z/7jr2ehknb4aT9G08mRInT4XUQDrx8+9R7ihEgmHV1k+ODY5hr9VlS/1EcREorHkt22+XxyDG5V+nxnMhZBHXGIaPDbkrAwpHISlxRC3luUwzDI6E94Ez+C3FJ2j4= 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=N6w3AYil; arc=none smtp.client-ip=205.220.168.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="N6w3AYil" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63TCefnc317335; Wed, 29 Apr 2026 12:51:41 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=/YKoPwdEO8W YEpMs9vHeAEAiqtm6RK9Cw3ZK+rSJyqE=; b=N6w3AYilJcasjSwSunbUi/9QvmA l6uDs/P3BKYmcbTCCh4hkDSkSF/XaARLPNa4ZRbEbOzKBojjrWMCak5UiRfS4sYU h00l5nJWlYvoFPMDCkqZRBRJAC8IU1W0N/grsTmohyYEh9Jcerj8huxbF0wImrOY 1SSyIP2VkxQHLz1CQKFpDgW6SUpUSUDhm6ICZCRUEcm2sG4pIOptR9cDcXUoJPsH hpoCxRXVSOzbRjCLOJWMQ0xldtlvS4krrVj/mQtBrxkoJG4rBkdodLvfF0Lw5Aa1 lzuFUgmOhtB6qShocHYW3+ixuKn0hB5x8zQAj3UtN/+b1Gg28NFw0qQoNow== Received: from apblrppmta02.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4duj6t813x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 Apr 2026 12:51:40 +0000 (GMT) Received: from pps.filterd (APBLRPPMTA02.qualcomm.com [127.0.0.1]) by APBLRPPMTA02.qualcomm.com (8.18.1.7/8.18.1.7) with ESMTP id 63TCpbOU010778; Wed, 29 Apr 2026 12:51:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA02.qualcomm.com (PPS) with ESMTPS id 4ds65fvr0u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 Apr 2026 12:51:37 +0000 (GMT) Received: from APBLRPPMTA02.qualcomm.com (APBLRPPMTA02.qualcomm.com [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.1.12) with ESMTP id 63TCpb99010750; Wed, 29 Apr 2026 12:51:37 GMT Received: from hu-devc-blr-u24-a.qualcomm.com (hu-anuppate-blr.qualcomm.com [10.131.36.165]) by APBLRPPMTA02.qualcomm.com (PPS) with ESMTPS id 63TCpbfo010744 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 Apr 2026 12:51:37 +0000 (GMT) Received: by hu-devc-blr-u24-a.qualcomm.com (Postfix, from userid 486687) id B875021CCF; Wed, 29 Apr 2026 18:21:36 +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 , 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 v4 03/12] rvtrace: Add functions to create/destroy a trace component path Date: Wed, 29 Apr 2026 18:21:26 +0530 Message-ID: <20260429125135.1983498-4-anup.patel@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429125135.1983498-1-anup.patel@oss.qualcomm.com> References: <20260429125135.1983498-1-anup.patel@oss.qualcomm.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-GUID: nICYyS_84c7fsqcSUXORReGBfPy-v7wb X-Authority-Analysis: v=2.4 cv=KcHidwYD c=1 sm=1 tr=0 ts=69f1fedd cx=c_pps a=Ou0eQOY4+eZoSc0qltEV5Q==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=UaIybRF2xpGp7VXWmyEA:9 X-Proofpoint-ORIG-GUID: nICYyS_84c7fsqcSUXORReGBfPy-v7wb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI5MDEzMCBTYWx0ZWRfXzkgU9sqDtl3N FKNKxNydqbTVVSQPkOzThZGlMcAe1ghhOBj0Or4cbRUkjg78u4aBNINlOFocD7ZxnN6v/IIJh50 ZY5THXXLSz6C3vOWAyjYNNh8SSx0/z/Zf60oKJXHzkg+A+BBQUJzIYQ2mozyoHHgG6JVw+8Bg0R 76LLm7irNWuMWe81Ufdl1Xn0euymN5xlICUchAFlYwJqKA9462YWb7gyTo/r6dOIyHCwl8ZkoE6 n/PekMlewG4Y4IjDJRLHIlV66tuQmkRDxTtTRhfT1xXRQnLvQ1vlprx77NqjKCsmNCHXrOacXL4 admjCeSWq3PSZo0OW1RC8jK6SDSJlwVKaU4haZZqGrk3vY5CY6VIdk0CDp510IgC0KJQKjsWtEi X3qheULkv+728uYdxqkpWToV8EhuIWzXM9jNQLymR5jXq4bLzoRxzk9zIotjLuAfcCPmnG3Adht 2jvK6Yrpf2nmZ7W7Q/Q== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-28_05,2026-04-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1011 adultscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604290130 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/rvtrace/rvtrace-core.c index d69c2236493a..f78e3ba9a0e5 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_data *pdata) } EXPORT_SYMBOL_GPL(rvtrace_reset_component); +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 = NULL; + struct rvtrace_platform_data *pdata = comp->pdata; + int i, ret; + + for (i = 0; i < pdata->nr_outconns; i++) { + conn = pdata->outconns[i]; + ret = __rvtrace_walk_output_components(conn->dest_comp, stop, priv, fn); + if (ret) + return ret; + if (*stop) { + stop_conn = conn; + break; + } + } + + ret = fn(comp, stop, stop_conn, priv); + if (ret) + return ret; + + return 0; +} + +int rvtrace_walk_output_components(struct rvtrace_component *comp, void *priv, + int (*fn)(struct rvtrace_component *comp, bool *stop, + struct rvtrace_connection *stop_conn, + void *priv)) +{ + bool stop = false; + int ret; + + if (!comp || !fn) + return -EINVAL; + + mutex_lock(&rvtrace_mutex); + ret = __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_component *comp) } EXPORT_SYMBOL_GPL(rvtrace_unregister_component); +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 = list_first_entry(&path->comp_list, struct rvtrace_path_node, head); + 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 = 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 = node->comp; + rtdrv = to_rvtrace_driver(comp->dev.driver); + + if (!rtdrv->get_trace_id) + continue; + + trace_id = rtdrv->get_trace_id(comp, path->mode); + if (trace_id > 0) { + path->trace_id = 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 = node->comp; + rtdrv = 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 = priv; + struct rvtrace_path *path = ppriv->path; + struct rvtrace_path_node *node; + + if ((!ppriv->sink && rvtrace_is_sink(comp->pdata)) || + (ppriv->sink && ppriv->sink == comp)) + *stop = true; + + if (*stop) { + node = kzalloc_obj(*node); + if (!path) + return -ENOMEM; + INIT_LIST_HEAD(&node->head); + rvtrace_get_component(comp); + node->comp = comp; + node->conn = 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 = 0; + + if (!source || mode >= RVTRACE_COMPONENT_MODE_MAX) { + ret = -EINVAL; + goto err_out; + } + + path = kzalloc_obj(*path); + if (!path) { + ret = -ENOMEM; + goto err_out; + } + INIT_LIST_HEAD(&path->comp_list); + path->mode = mode; + path->trace_id = RVTRACE_INVALID_TRACE_ID; + + priv.path = path; + priv.sink = sink; + ret = rvtrace_walk_output_components(source, &priv, build_path_walk_fn); + if (ret < 0) + goto err_release_path_nodes; + + if (!rvtrace_path_ready(path)) { + ret = -EOPNOTSUPP; + goto err_release_path_nodes; + } + + ret = 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 = 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 @@ #include #include +#include +#include #include #include #include @@ -72,6 +74,12 @@ enum rvtrace_component_impid { RVTRACE_COMPONENT_IMPID_MAX }; +/* 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 between * two RISC-V trace components. @@ -239,6 +247,10 @@ int rvtrace_enable_component(struct rvtrace_platform_data *pdata); int rvtrace_disable_component(struct rvtrace_platform_data *pdata); int rvtrace_reset_component(struct rvtrace_platform_data *pdata); +int rvtrace_walk_output_components(struct rvtrace_component *comp, void *priv, + int (*fn)(struct rvtrace_component *comp, bool *stop, + struct rvtrace_connection *stop_conn, + void *priv)); struct rvtrace_component *rvtrace_cpu_source(unsigned int cpu); struct rvtrace_component *rvtrace_register_component(enum rvtrace_component_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); +/** + * 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; }; -- 2.43.0