* [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks
@ 2026-11-19 9:01 Jie Gan
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
` (5 more replies)
0 siblings, 6 replies; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
On Qualcomm Hawi/Maili SoCs, part of the CoreSight trace hardware is
owned by the Qualcomm Embedded Co-Processor (QECP), a separate on-die
processor that runs its own firmware and has its own view of the trace
topology. The owned blocks are an STM (System Trace Macrocell) source,
a TMC (Trace Memory Controller) configured as an ETR (Embedded Trace
Router) sink, and the internal funnels/replicators that connect them.
This hardware ships today; it is not a future design.
The Qualcomm Debug Control Protocol (QDCP) is the firmware interface
Linux uses to ask QECP to do what the AP (application processor, the
cores running Linux) cannot do itself. It is a QMI (Qualcomm MSM
Interface) service carried over QRTR (Qualcomm IPC Router), like other
Qualcomm firmware services. QECP is the co-processor that owns the
hardware; QDCP is the wire protocol Linux uses to talk to its firmware.
This series adds a QDCP provider plus an STM source driver and an ETR
sink path that use it, so a QECP-owned STM -> ETR session works through
the existing CoreSight sysfs interface.
Register ownership
------------------
The QECP-owned MMIO control/status registers are protected by hardware
access control. AP reads and writes to those ranges are blocked or
trapped, so Linux cannot touch them and there is no race to describe.
The AP does keep two things outright, with no access control involved:
- the STM stimulus write aperture, a separate MMIO region used only
for data writes, not for block control;
- the ETR trace buffer, ordinary system memory (DDR) that Linux
allocates, maps and owns exactly as for a local-MMIO ETR.
AP (Linux) QECP firmware
---------- -------------
STM stimulus aperture owned, mapped,
written directly
STM control registers owned, access-
controlled from AP
Funnel/replicator owned, private, not
routing visible to Linux
TMC-ETR control registers owned, access-
controlled from AP
TMC-ETR trace buffer owned, allocated,
read via sysfs
TMC-ETR RRP/RWP/STS read over QDCP owned, returned over
(read/write pointers, QDCP on request
status)
Block clocks and power owned, controlled by
firmware only
Linux owns what it can observe or allocate directly: the stimulus
aperture, the trace buffer and its sysfs lifecycle. QECP owns what
needs access to live hardware state: control registers, internal
routing, pointer/status registers, and the clocks and power of the
blocks. QDCP is the only channel between the two; there is no direct
path and no fallback.
Because firmware controls the blocks' clocks and power, the bindings
describe no clocks, clock-names or power-domains for these devices, and
the QDCP code adds no clock handling or runtime PM.
System overview
---------------
Control path (QDCP, QMI over QRTR) and data path (hardware):
AP (Linux) QECP
---------- ----
sysfs / char dev
|
+-----v------------+ typed +-----------+ QMI/QRTR +-------------+
| QDCP STM source |--------->| | | |
| QDCP TMC-ETR sink| API | QDCP |<---------->| QECP |
+------------------+ | provider | | firmware |
| (soc/qcom)| | |
+-----------+ +------+------+
|
programs STM/TMC ctl regs,
ATID filter, internal routing
|
Data path v
---------
STM stimulus +-----+ (QECP-private funnels/ +---------------+
aperture ----->| STM |----- replicators, no DT ---->| TMC (ETR) |
(AP writes) +-----+ node, not visible) +-------+-------+
| DMA
+-------v-------+
| etr_buf |
| (Linux memory)|
+-------+-------+
|
AP reads via /dev/<tmc> (sysfs)
Enable, a trace session start (CoreSight enables sink first, then source):
CoreSight QDCP ETR QDCP STM QDCP QECP
core (patch 6) (patch 4) provider firmware
| | | | |
|--enable--->| | | |
| sink | alloc/reuse etr_buf, | |
| | compute paddr + IOVA | |
| |--qdcp_tmc_etr_enable()->| |
| | | |--SG mode--->|
| | | |--FFCR------>|
| | | |--buffer---->|
| | | |--start TMC->|
| | | |<---ok-------|
|<--ok-------| | | |
|--enable------------> | | |
| source | | |
| | |--qdcp_stm_source_enable()|
| | | (src id, trace ID, |
| | | port mask) |
| | | |--set ATID-->|
| | | |--start STM->|
| | | |<---ok-------|
|<--ok------------------- | | |
| | | | |
| trace flows STM -> (QECP-private routing) -> ETR -> etr_buf
(SG: scatter-gather, FFCR: formatter and flush control register,
IOVA: I/O virtual address, ATID: ATB trace ID.)
Disable and readback (source first, then sink):
CoreSight QDCP ETR QDCP STM QDCP QECP
core (patch 6) (patch 4) provider firmware
| | | | |
|--disable-------------->| | |
| source |--qdcp_stm_source_disable()|
| | | |--clear ATID>|
| | | |--stop STM-->|
|--disable-->| | | |
| sink |--qdcp_tmc_etr_disable()>| |
| | | |--stop TMC-->|
| | | |<---ok-------|
| | stop confirmed? no -> keep etr_buf pinned and retry
| | on the next enable, open() of /dev/<tmc> or removal
| | yes: | |
| |--qdcp_tmc_get_param(RRP/RWP/STS)---->|
| |<--values----------------------------|
| | sync etr_buf, release |
| | | | |
userspace reads trace from etr_buf through /dev/<tmc>, as for any ETR
Sysfs ABI
---------
This series adds no new CoreSight-wide sysfs ABI. A QDCP ETR exposes
the existing generic ETR/TMC attributes for buffer sizing and sysfs
mode enable/disable, with one omission: trigger_cntr is not exposed,
because the QDCP enable RPC does not convey it to firmware and writes
would be silently ignored. The only new attribute is a read-only
"traceid" on the QDCP STM source, like attributes other CoreSight
source drivers already expose. Userspace reads trace data from the
Linux-owned etr_buf through the same /dev/<tmc> interface as every
other ETR; there is nothing QDCP-specific for it to learn.
Why do qcom,service-id, qcom,instance-id and qcom,version come from DT?
------------------------------------------------------------------------
QDCP is a QMI client over QRTR. The only lookup primitive QMI offers a
client is qmi_add_lookup(service, version, instance): "tell me when a
server matching this tuple appears". There is no API to enumerate all
registered services and pick one, so a client must know what it is
looking for before it can look. Firmware does not advertise a list of
services for Linux to negotiate against. The (service, version,
instance) tuple is fixed by the platform firmware build, which is the
kind of static platform fact DT (devicetree) exists to describe.
qcom,service-id and qcom,instance-id are required; qcom,version is
optional and defaults to 1.
DT dependencies
---------------
The DT surface is deliberately small:
- the provider node has one connection-N child per QMI connection,
carrying the tuple above;
- each consumer has a qcom,qdcp phandle to a connection-N child and an
ID that names its block to firmware (qcom,qdcp-source-id for the
STM, qcom,qdcp-tmc-id for the ETR);
- the STM has its stimulus aperture in reg, and both consumers have
the usual CoreSight graph port towards the logical path.
There are no clocks, power domains or nodes for QECP-internal topology,
so the consumers depend on nothing else in DT.
Design
------
CoreSight is a mature subsystem shared by every Arm CoreSight
implementation. This series is built so that QDCP support:
- does not turn generic CoreSight drivers (coresight-stm.c, the shared
parts of coresight-tmc-core.c and coresight-tmc-etr.c) into
vendor-specific code;
- does not invent fake CoreSight DT nodes for hardware Linux cannot
observe or control;
- does not need a broad refactor of TMC/ETR internals.
QDCP is therefore a firmware *provider*, not a CoreSight *device*. It
lives under drivers/soc/qcom/ next to other Qualcomm QMI services, and
consumers find it through a DT phandle, as for clocks or regulators. It
never appears in the CoreSight topology graph and has no coresight_desc.
The phandle must reference a connection-N child of the provider node,
not the top-level provider node itself.
Only Qualcomm-specific consumer drivers know about QDCP. coresight-stm.c
is untouched, and TMC/ETR gains a parallel, isolated code path chosen
once at probe time by the qcom,qdcp property, leaving the local-MMIO
ETR path unchanged in behaviour. QECP-internal topology is not modeled
in DT: there is no node for the funnels/replicators between the QDCP
STM and the QDCP ETR, since CoreSight only needs a logical
source-to-sink path to build a session.
Probe-time resolution. The QDCP ETR reads DEVID (the TMC device
configuration register) through qdcp_tmc_get_param() instead of MMIO,
rejects any config type other than ETR, and selects its coresight_ops
table and its RRP/RWP/STS readback function once, mirroring how
CoreSight resolves desc.access for MMIO vs. system-register ETMs. The
two paths never coexist on one device instance, so there is nothing to
re-check at runtime.
Lifecycle and safety rules
--------------------------
- Firmware DMA into etr_buf is the main hazard. etr_buf is the buffer
firmware may be writing into, and Linux clears it only after
firmware has confirmed the TMC stop. If a stop is not confirmed,
including a failed or timed-out enable request that firmware may
still have executed, the buffer stays pinned: it is not synced,
freed or replaced, and the stop is retried on the next enable, the
next open of /dev/<tmc>, or device removal. If firmware never
confirms, the buffer is left allocated at removal rather than freed
under possible DMA.
- A failed read of the RRP/RWP/STS state invalidates the buffer
contents instead of leaving the previous capture readable.
- The provider-consumer link is core-managed, so unbinding the
provider first unbinds its consumers. A consumer that probes while
the provider is already unbinding defers its probe.
- If firmware does not confirm an STM stop, Linux still marks the
source disabled (the CoreSight source disable op cannot fail) and
logs a warning. The driver remembers the failed stop, so on removal
the trace ID is kept allocated whether the stop failed during
removal or earlier, and no other source can reuse an ID firmware may
still be applying.
- No lock is held across a QMI transaction wait.
- A QMI reply that omits its result TLV, or the value TLV of a
parameter read, is treated as a failure.
Known limitations
-----------------
- If QECP firmware resets while a session is active, Linux is not
notified and does not reprogram the STM or ETR. Trace stops until
the user disables and re-enables the session, and the disable logs
the firmware error. A provider reset notification is left
for a follow-up once the firmware reset behaviour is defined.
- The STM stimulus write path checks the CoreSight mode without a lock,
exactly like coresight-stm.c. It cannot take one, because the packet
callback is notrace and can run in atomic context, so a write can
race with a concurrent disable.
- QDCP-owned ETRs have no panic handler: the control registers are
firmware-owned and not accessible from the panic path, so trace data
is not preserved on panic.
Scope
-----
This series implements one complete path:
QDCP STM source --(logical CoreSight path)--> QDCP ETR sink
Not included, and deferred until a platform needs it: QDCP ETF (embedded
trace FIFO)/link sinks, perf-mode (AUX) support for STM or ETR (sysfs
mode only here), other QDCP source types such as TPDM (trace, profiling
and diagnostics monitor) and OCLA (on-chip logic analyzer), a
path-helper device for no-MMIO static sources, and the TMC
BEGIN_READ/READ/END_READ firmware data-copy commands (the AP is assumed
able to read the ETR buffer directly).
Why not the power-domain framework?
-----------------------------------
The exported enable/disable calls could be modelled as a power-domain
provider's .power_on/.power_off instead of a new API. This series does
not do that, for three reasons.
1. QDCP does not power anything on or off. The QECP-owned blocks are
controlled entirely by firmware, and HLOS (the high-level OS, here
Linux) has no way to request a power transition for them. When
firmware receives a QDCP request it decides for itself what the
block needs, including any power or clock handling, and performs
it. The on/off value in the SET_STATE requests starts or stops the
block's trace function, it is not a power-state request. A
power-domain provider, whose whole purpose is to control power
state, would describe something HLOS does not do.
2. The calls carry data a power domain has no way to pass. The STM
enable sends the CoreSight-allocated trace ID and a port-enable mask
that firmware turns into its ATID filter. The ETR enable sends the
buffer physical and IOVA address, size, scatter-gather mode and
FFCR, in several requests. qdcp_tmc_get_param() also reads DEVID
and RRP/RWP/STS back from firmware, which the ETR needs to
synchronise etr_buf after a stop, and a power domain has no read
operation.
3. The trigger is different. A power domain follows runtime PM, which
reacts to device usage. QDCP enable/disable must follow the
CoreSight path lifecycle: sink first, then source, started and
stopped by the user's sysfs enable. CoreSight already drives that
through its source/sink ops, so the QDCP calls hang off those ops
directly.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
Jie Gan (6):
dt-bindings: soc: qcom: add QDCP provider
soc: qcom: add QDCP firmware provider
dt-bindings: arm: qcom: add QDCP STM source
coresight: qcom: add QDCP STM source
dt-bindings: arm: qcom: add QDCP TMC ETR sink
coresight: tmc: add QDCP ETR sysfs support
.../bindings/arm/qcom,coresight-stm-qdcp.yaml | 111 +++
.../bindings/arm/qcom,coresight-tmc-qdcp.yaml | 102 +++
.../devicetree/bindings/soc/qcom/qcom,qdcp.yaml | 81 ++
drivers/hwtracing/coresight/Kconfig | 11 +
drivers/hwtracing/coresight/Makefile | 4 +-
.../hwtracing/coresight/coresight-qcom-qdcp-stm.c | 550 ++++++++++++
drivers/hwtracing/coresight/coresight-tmc-core.c | 145 ++-
.../hwtracing/coresight/coresight-tmc-etr-qdcp.c | 379 ++++++++
drivers/hwtracing/coresight/coresight-tmc-etr.c | 46 +-
drivers/hwtracing/coresight/coresight-tmc.h | 46 +
drivers/soc/qcom/Kconfig | 12 +
drivers/soc/qcom/Makefile | 1 +
drivers/soc/qcom/qcom_qdcp.c | 985 +++++++++++++++++++++
include/linux/soc/qcom/qdcp.h | 128 +++
14 files changed, 2553 insertions(+), 48 deletions(-)
---
base-commit: e8017d29067fd1310a65c3494ce1a1b492adbac6
change-id: 20261119-introduce-qcom-qecp-feature-f59c05a21179
Best regards,
--
Jie Gan <jie.gan@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
@ 2026-11-19 9:01 ` Jie Gan
2026-11-19 9:12 ` sashiko-bot
2026-11-19 14:00 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider Jie Gan
` (4 subsequent siblings)
5 siblings, 2 replies; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
Document the Qualcomm Debug Control Protocol (QDCP) firmware provider
node used by CoreSight debug and trace blocks that are owned by the
Qualcomm Embedded Co-Processor (QECP), a separate on-die processor that
runs its own firmware. QDCP is the QMI (Qualcomm MSM Interface) service,
carried over QRTR (Qualcomm IPC Router), that Linux uses to ask QECP
firmware to control those blocks.
The provider is a Qualcomm platform/QMI service node, not a CoreSight
graph device. It exposes the qcom,qdcp compatible along with
per-connection QMI service/instance identifiers; the QMI service
version is the only optional identifier, defaulting to 1.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
.../devicetree/bindings/soc/qcom/qcom,qdcp.yaml | 81 ++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml b/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml
new file mode 100644
index 000000000000..ee0a66b12dde
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/qcom/qcom,qdcp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Debug Control Protocol (QDCP) provider
+
+maintainers:
+ - Jie Gan <jie.gan@oss.qualcomm.com>
+
+description: |
+ QDCP is a QMI-based firmware provider used to control CoreSight trace
+ blocks that are owned by the Qualcomm Embedded Co-Processor (QECP) rather
+ than the application processor (AP). CoreSight-facing consumers look up
+ the provider through a "qcom,qdcp" phandle, naming a specific
+ "connection-N" child node rather than the top-level provider node, and
+ issue typed firmware requests instead of programming registers directly.
+
+ This node does not represent a CoreSight graph device. It is a platform
+ driver that establishes the QMI connections used by consumer drivers such
+ as the Qualcomm QDCP STM source and QDCP-backed TMC/ETR sink.
+
+ QECP exposes more than one independent QMI service (for example, a
+ separate service used by remote ETM/diag sources). Each QMI connection is
+ described as a child node of the "qcom,qdcp" node rather than as a
+ property of the node itself, so a single provider device can establish
+ more than one connection. A node without any "connection-N" child is valid
+ but provides nothing for consumers to reference.
+
+properties:
+ compatible:
+ const: qcom,qdcp
+
+patternProperties:
+ "^connection-[0-9]+$":
+ type: object
+ description:
+ A single QMI connection established by the QDCP provider. Consumers
+ reference this child node directly via their "qcom,qdcp" phandle, not
+ the top-level provider node.
+
+ properties:
+ qcom,service-id:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ QMI service identifier for this connection.
+
+ qcom,version:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ default: 1
+ description:
+ QMI service version for this connection.
+
+ qcom,instance-id:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ QMI instance identifier for this connection.
+
+ required:
+ - qcom,service-id
+ - qcom,instance-id
+
+ additionalProperties: false
+
+required:
+ - compatible
+
+additionalProperties: false
+
+examples:
+ - |
+ qdcp: qdcp {
+ compatible = "qcom,qdcp";
+
+ qdcp_coresight: connection-0 {
+ qcom,service-id = <0x453>;
+ qcom,instance-id = <32>;
+ };
+ };
+...
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
@ 2026-11-19 9:01 ` Jie Gan
2026-11-19 9:18 ` sashiko-bot
2026-11-19 9:01 ` [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source Jie Gan
` (3 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
Add a provider for the Qualcomm Debug Control Protocol (QDCP), the QMI
(Qualcomm MSM Interface) service over QRTR (Qualcomm IPC Router) that
Linux uses to control debug and trace blocks owned by the Qualcomm
Embedded Co-Processor (QECP) firmware. The application processor (AP)
cannot access the registers of those blocks, so consumers ask firmware
to enable, disable and query them through typed provider APIs.
The provider is a Qualcomm platform/QMI service driver rather than a
CoreSight graph device. Consumers look it up through the qcom,qdcp
phandle, which must reference a connection-N child of the provider
node. The lookup takes a core-managed device link, so unbinding the
provider first unbinds its consumers, and a consumer that probes while
the provider is already unbinding defers its probe.
Use the SoC-provider compatible qcom,qdcp and keep the public consumer
API under include/linux/soc/qcom/. QCOM_QDCP selects QCOM_QMI_HELPERS
because that symbol has no prompt and can only be enabled by a select.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
drivers/soc/qcom/Kconfig | 12 +
drivers/soc/qcom/Makefile | 1 +
drivers/soc/qcom/qcom_qdcp.c | 985 ++++++++++++++++++++++++++++++++++++++++++
include/linux/soc/qcom/qdcp.h | 128 ++++++
4 files changed, 1126 insertions(+)
diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index 535c8619197b..5a7ad571cc58 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -330,6 +330,18 @@ config QCOM_QMI_TMD
TMD messaging and handles QMI communication with remote processors
to exchange mitigation state and apply thermal mitigation requests.
+config QCOM_QDCP
+ tristate "Qualcomm Debug Control Protocol driver"
+ depends on ARCH_QCOM || COMPILE_TEST
+ depends on OF
+ depends on NET && QRTR
+ select QCOM_QMI_HELPERS
+ help
+ This driver provides the Qualcomm Debug Control Protocol provider
+ used by QECP-owned debug and trace blocks. It is not registered as
+ a CoreSight device; subsystem drivers call its typed APIs when block
+ registers are owned by QECP firmware.
+
config QCOM_UBWC_CONFIG
tristate
depends on QCOM_SMEM
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index bddd6f0a5836..5c2b4e1c67dc 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -17,6 +17,7 @@ CFLAGS_pmic_pdcharger_ulog.o := -I$(src)
obj-$(CONFIG_QCOM_QMI_TMD) += qmi_tmd.o
obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o
qmi_helpers-y += qmi_encdec.o qmi_interface.o
+obj-$(CONFIG_QCOM_QDCP) += qcom_qdcp.o
obj-$(CONFIG_QCOM_RAMP_CTRL) += ramp_controller.o
obj-$(CONFIG_QCOM_RMTFS_MEM) += rmtfs_mem.o
obj-$(CONFIG_QCOM_RPM_MASTER_STATS) += rpm_master_stats.o
diff --git a/drivers/soc/qcom/qcom_qdcp.c b/drivers/soc/qcom/qcom_qdcp.c
new file mode 100644
index 000000000000..295138b29881
--- /dev/null
+++ b/drivers/soc/qcom/qcom_qdcp.c
@@ -0,0 +1,985 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#include <linux/device.h>
+#include <linux/jiffies.h>
+#include <linux/kref.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/soc/qcom/qmi.h>
+
+#define QCOM_QDCP_PROVIDER
+#include <linux/soc/qcom/qdcp.h>
+
+#define QDCP_TIMEOUT_MS 10000
+#define QDCP_MAX_MSG_LEN 256
+#define QDCP_MAX_ATIDS 8
+
+#define QDCP_STM_SET_STATE 0x0003
+#define QDCP_STM_HWE_SET_STATE 0x0005
+#define QDCP_STM_SET_PARAM 0x0007
+#define QDCP_TMC_SET_STATE 0x002b
+#define QDCP_TMC_ASSIGN_BUFFER 0x002d
+#define QDCP_TMC_SET_PARAM 0x0033
+#define QDCP_TMC_GET_PARAM 0x0034
+#define QDCP_ATID_SET 0x0036
+
+#define QDCP_STM_PARAM_PORT_ENABLE 0x1002
+
+/* Firmware trace-source type used in QDCP_ATID_SET requests. */
+enum qdcp_trace_source {
+ QDCP_TRACE_SOURCE_STM = 0,
+};
+
+struct qdcp_trace_source_v01 {
+ s32 type;
+ u64 id;
+};
+
+/*
+ * Every QDCP response starts with the mandatory QMI result TLV;
+ * qdcp_send_resp() relies on that to check the result without being told
+ * where it lives.
+ */
+struct qdcp_resp_v01 {
+ struct qmi_response_type_v01 resp;
+};
+
+struct qdcp_state_req_v01 {
+ u64 id;
+ s32 state;
+};
+
+struct qdcp_stm_set_param_req_v01 {
+ u64 stm_id;
+ u32 param;
+ u32 value;
+};
+
+struct qdcp_atid_set_req_v01 {
+ struct qdcp_trace_source_v01 trace_source;
+ u8 atids[QDCP_MAX_ATIDS];
+ u8 num_atids;
+};
+
+struct qdcp_tmc_buffer_v01 {
+ u64 paddr;
+ u64 iaddr;
+ u64 size;
+};
+
+struct qdcp_tmc_assign_buffer_req_v01 {
+ u64 tmc_id;
+ struct qdcp_tmc_buffer_v01 buffer;
+};
+
+struct qdcp_tmc_set_param_req_v01 {
+ u64 tmc_id;
+ u32 param;
+ u64 value;
+};
+
+struct qdcp_tmc_get_param_req_v01 {
+ u64 tmc_id;
+ u32 param;
+};
+
+struct qdcp_tmc_get_param_resp_v01 {
+ struct qmi_response_type_v01 resp;
+ u8 value_valid;
+ u64 value;
+};
+
+static_assert(offsetof(struct qdcp_resp_v01, resp) == 0);
+static_assert(offsetof(struct qdcp_tmc_get_param_resp_v01, resp) == 0);
+
+/**
+ * struct qdcp_data - QDCP connection state.
+ * @ref: lifetime reference for connection consumers.
+ * @dev: parent provider device.
+ * @of_node: connection device tree node.
+ * @qmi: QMI service handle.
+ * @sq: QRTR server address.
+ * @lock: serializes QMI connection state and transactions.
+ * @node: entry in the global provider lookup list.
+ * @service_id: QDCP QMI service identifier.
+ * @version: QDCP QMI service version.
+ * @instance_id: QDCP QMI instance identifier.
+ * @connected: true when the QDCP service is available.
+ * @dying: true when provider removal has started.
+ */
+struct qdcp_data {
+ struct kref ref;
+ struct device *dev;
+ struct device_node *of_node;
+ struct qmi_handle qmi;
+ struct sockaddr_qrtr sq;
+ /* Serializes QMI connection state and transactions. */
+ struct mutex lock;
+ struct list_head node;
+ u32 service_id;
+ u32 version;
+ u32 instance_id;
+ bool connected;
+ bool dying;
+};
+
+static LIST_HEAD(qdcp_providers);
+static DEFINE_MUTEX(qdcp_providers_lock);
+
+static void qdcp_release(struct kref *ref)
+{
+ struct qdcp_data *qdcp = container_of(ref, struct qdcp_data,
+ ref);
+
+ of_node_put(qdcp->of_node);
+ put_device(qdcp->dev);
+ kfree(qdcp);
+}
+
+static const struct qmi_elem_info qdcp_resp_ei[] = {
+ {
+ .data_type = QMI_STRUCT,
+ .elem_len = 1,
+ .elem_size = sizeof(struct qmi_response_type_v01),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_resp_v01, resp),
+ .ei_array = qmi_response_type_v01_ei,
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_state_req_ei[] = {
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x01,
+ .offset = offsetof(struct qdcp_state_req_v01, id),
+ },
+ {
+ .data_type = QMI_SIGNED_4_BYTE_ENUM,
+ .elem_len = 1,
+ .elem_size = sizeof(s32),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_state_req_v01, state),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_stm_set_param_req_ei[] = {
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x01,
+ .offset = offsetof(struct qdcp_stm_set_param_req_v01, stm_id),
+ },
+ {
+ .data_type = QMI_UNSIGNED_4_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u32),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_stm_set_param_req_v01, param),
+ },
+ {
+ .data_type = QMI_UNSIGNED_4_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u32),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x03,
+ .offset = offsetof(struct qdcp_stm_set_param_req_v01, value),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_trace_source_ei[] = {
+ {
+ .data_type = QMI_SIGNED_4_BYTE_ENUM,
+ .elem_len = 1,
+ .elem_size = sizeof(s32),
+ .array_type = NO_ARRAY,
+ .tlv_type = QMI_COMMON_TLV_TYPE,
+ .offset = offsetof(struct qdcp_trace_source_v01, type),
+ },
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = QMI_COMMON_TLV_TYPE,
+ .offset = offsetof(struct qdcp_trace_source_v01, id),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_atid_set_req_ei[] = {
+ {
+ .data_type = QMI_STRUCT,
+ .elem_len = 1,
+ .elem_size = sizeof(struct qdcp_trace_source_v01),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x01,
+ .offset = offsetof(struct qdcp_atid_set_req_v01, trace_source),
+ .ei_array = qdcp_trace_source_ei,
+ },
+ {
+ .data_type = QMI_UNSIGNED_1_BYTE,
+ .elem_len = QDCP_MAX_ATIDS,
+ .elem_size = sizeof(u8),
+ .array_type = STATIC_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_atid_set_req_v01, atids),
+ },
+ {
+ .data_type = QMI_UNSIGNED_1_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u8),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x03,
+ .offset = offsetof(struct qdcp_atid_set_req_v01, num_atids),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_tmc_buffer_ei[] = {
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = QMI_COMMON_TLV_TYPE,
+ .offset = offsetof(struct qdcp_tmc_buffer_v01, paddr),
+ },
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = QMI_COMMON_TLV_TYPE,
+ .offset = offsetof(struct qdcp_tmc_buffer_v01, iaddr),
+ },
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = QMI_COMMON_TLV_TYPE,
+ .offset = offsetof(struct qdcp_tmc_buffer_v01, size),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_tmc_assign_buffer_req_ei[] = {
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x01,
+ .offset = offsetof(struct qdcp_tmc_assign_buffer_req_v01, tmc_id),
+ },
+ {
+ .data_type = QMI_STRUCT,
+ .elem_len = 1,
+ .elem_size = sizeof(struct qdcp_tmc_buffer_v01),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_tmc_assign_buffer_req_v01, buffer),
+ .ei_array = qdcp_tmc_buffer_ei,
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_tmc_get_param_resp_ei[] = {
+ {
+ .data_type = QMI_STRUCT,
+ .elem_len = 1,
+ .elem_size = sizeof(struct qmi_response_type_v01),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_tmc_get_param_resp_v01, resp),
+ .ei_array = qmi_response_type_v01_ei,
+ },
+ {
+ /* Decode sets value_valid only if the value TLV is present. */
+ .data_type = QMI_OPT_FLAG,
+ .elem_len = 1,
+ .elem_size = sizeof(u8),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x03,
+ .offset = offsetof(struct qdcp_tmc_get_param_resp_v01,
+ value_valid),
+ },
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x03,
+ .offset = offsetof(struct qdcp_tmc_get_param_resp_v01, value),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_tmc_set_param_req_ei[] = {
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x01,
+ .offset = offsetof(struct qdcp_tmc_set_param_req_v01, tmc_id),
+ },
+ {
+ .data_type = QMI_UNSIGNED_4_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u32),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_tmc_set_param_req_v01, param),
+ },
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x03,
+ .offset = offsetof(struct qdcp_tmc_set_param_req_v01, value),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static const struct qmi_elem_info qdcp_tmc_get_param_req_ei[] = {
+ {
+ .data_type = QMI_UNSIGNED_8_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u64),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x01,
+ .offset = offsetof(struct qdcp_tmc_get_param_req_v01, tmc_id),
+ },
+ {
+ .data_type = QMI_UNSIGNED_4_BYTE,
+ .elem_len = 1,
+ .elem_size = sizeof(u32),
+ .array_type = NO_ARRAY,
+ .tlv_type = 0x02,
+ .offset = offsetof(struct qdcp_tmc_get_param_req_v01, param),
+ },
+ {
+ .data_type = QMI_EOTI,
+ },
+};
+
+static int qdcp_check_resp(struct qdcp_data *qdcp,
+ const struct qmi_response_type_v01 *resp)
+{
+ if (resp->result == QMI_RESULT_SUCCESS_V01)
+ return 0;
+
+ dev_err(qdcp->dev, "QMI request failed: result=%u error=%u\n",
+ resp->result, resp->error);
+ return -EIO;
+}
+
+static int qdcp_send_resp(struct qdcp_data *qdcp, unsigned int msg_id,
+ const struct qmi_elem_info *req_ei, const void *req,
+ size_t req_len, const struct qmi_elem_info *resp_ei,
+ void *resp, size_t resp_len)
+{
+ /* @resp starts with the QMI result TLV, see struct qdcp_resp_v01. */
+ struct qmi_response_type_v01 *qmi_resp = resp;
+ struct sockaddr_qrtr sq;
+ struct qmi_txn txn;
+ bool connected, dying;
+ int ret;
+
+ /*
+ * Only snapshot connection state under qdcp->lock; do not hold it
+ * across qmi_txn_wait(). qdcp_del_server()/qdcp_net_reset() also take
+ * qdcp->lock and run on qdcp->qmi's ordered workqueue, the same
+ * workqueue that must process the response completing this
+ * transaction. Holding the lock across the wait can deadlock: the
+ * workqueue thread blocks on qdcp->lock while this waiter blocks on
+ * a completion only that (now-blocked) workqueue thread can deliver.
+ */
+ mutex_lock(&qdcp->lock);
+ dying = qdcp->dying;
+ connected = qdcp->connected;
+ sq = qdcp->sq;
+ mutex_unlock(&qdcp->lock);
+
+ if (dying)
+ /* Provider is being removed: this is a permanent failure. */
+ return -ENODEV;
+
+ if (!connected)
+ /*
+ * The QDCP QMI service has not registered yet (or dropped
+ * off transiently). Report -EAGAIN rather than -ENODEV so
+ * callers can distinguish "retry later" from "never coming
+ * back", and defer probe instead of failing outright.
+ */
+ return -EAGAIN;
+
+ memset(resp, 0, resp_len);
+ /*
+ * QMI_RESULT_SUCCESS_V01 is 0, the same value memset() above just
+ * wrote into qmi_resp->result. A firmware reply that omits the
+ * mandatory response TLV (qmi_decode_message() does not treat a
+ * missing TLV as an error, it just decodes however many bytes are
+ * actually present) would otherwise leave that zero in place and
+ * read back as an implicit success. Poison it to a failure value
+ * first so decode must positively overwrite it with
+ * QMI_RESULT_SUCCESS_V01 for qdcp_check_resp() to accept the reply.
+ */
+ qmi_resp->result = QMI_RESULT_FAILURE_V01;
+ qmi_resp->error = QMI_ERR_MALFORMED_MSG_V01;
+
+ ret = qmi_txn_init(&qdcp->qmi, &txn, resp_ei, resp);
+ if (ret < 0)
+ return ret;
+
+ ret = qmi_send_request(&qdcp->qmi, &sq, &txn, msg_id, req_len, req_ei,
+ req);
+ if (ret < 0) {
+ qmi_txn_cancel(&txn);
+ return ret;
+ }
+
+ ret = qmi_txn_wait(&txn, msecs_to_jiffies(QDCP_TIMEOUT_MS));
+ if (ret < 0)
+ return ret;
+
+ return qdcp_check_resp(qdcp, qmi_resp);
+}
+
+static int qdcp_send(struct qdcp_data *qdcp, unsigned int msg_id,
+ const struct qmi_elem_info *req_ei, const void *req,
+ size_t req_len, struct qdcp_resp_v01 *resp)
+{
+ return qdcp_send_resp(qdcp, msg_id, req_ei, req, req_len, qdcp_resp_ei,
+ resp, sizeof(*resp));
+}
+
+static int qdcp_set_state(struct qdcp_data *qdcp, unsigned int msg_id,
+ u64 id, bool enable)
+{
+ struct qdcp_state_req_v01 req = {
+ .id = id,
+ .state = enable,
+ };
+ struct qdcp_resp_v01 resp;
+
+ return qdcp_send(qdcp, msg_id, qdcp_state_req_ei, &req, sizeof(req),
+ &resp);
+}
+
+struct qdcp_devres {
+ struct qdcp_data *qdcp;
+};
+
+static void qdcp_release_provider(void *data)
+{
+ struct qdcp_devres *devres = data;
+
+ put_device(devres->qdcp->dev);
+ kref_put(&devres->qdcp->ref, qdcp_release);
+}
+
+struct qdcp_data *devm_qdcp_get(struct device *dev, const char *phandle_name)
+{
+ struct qdcp_devres *devres;
+ struct device_link *link;
+ struct qdcp_data *qdcp;
+ struct device_node *np;
+ int ret;
+
+ if (!dev->of_node)
+ return ERR_PTR(-ENOENT);
+
+ np = of_parse_phandle(dev->of_node, phandle_name, 0);
+ if (!np)
+ return ERR_PTR(-ENOENT);
+
+ mutex_lock(&qdcp_providers_lock);
+ list_for_each_entry(qdcp, &qdcp_providers, node) {
+ if (qdcp->of_node != np || qdcp->dying)
+ continue;
+
+ if (!kref_get_unless_zero(&qdcp->ref))
+ continue;
+
+ get_device(qdcp->dev);
+ mutex_unlock(&qdcp_providers_lock);
+ of_node_put(np);
+
+ /*
+ * A managed link with DL_FLAG_AUTOREMOVE_CONSUMER (i.e. no
+ * DL_FLAG_STATELESS) is required so that the driver core's
+ * device_links_busy()/device_links_unbind_consumers()
+ * machinery forces this consumer to unbind before
+ * qdcp_remove() can proceed on the supplier, and so the link
+ * itself is dropped automatically by the core when this
+ * consumer unbinds or fails to probe. A stateless link
+ * carries neither guarantee: qdcp_remove() could release the
+ * QMI handle while a consumer still has outstanding or
+ * in-flight QDCP RPCs, and device_link_del() refuses to drop
+ * a non-stateless link while the consumer is still
+ * registered, which is always the case from inside a devm
+ * release callback.
+ */
+ link = device_link_add(dev, qdcp->dev,
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (!link) {
+ put_device(qdcp->dev);
+ kref_put(&qdcp->ref, qdcp_release);
+ return ERR_PTR(-EINVAL);
+ }
+
+ /*
+ * The core still creates a link to a supplier that is already
+ * unbinding, and will not unbind this consumer for it. Defer
+ * rather than bind to a provider that is going away.
+ */
+ if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND) {
+ put_device(qdcp->dev);
+ kref_put(&qdcp->ref, qdcp_release);
+ return ERR_PTR(-EPROBE_DEFER);
+ }
+
+ devres = devm_kzalloc(dev, sizeof(*devres), GFP_KERNEL);
+ if (!devres) {
+ put_device(qdcp->dev);
+ kref_put(&qdcp->ref, qdcp_release);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ devres->qdcp = qdcp;
+ ret = devm_add_action_or_reset(dev, qdcp_release_provider, devres);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return qdcp;
+ }
+ mutex_unlock(&qdcp_providers_lock);
+ of_node_put(np);
+
+ return ERR_PTR(-EPROBE_DEFER);
+}
+EXPORT_SYMBOL_GPL(devm_qdcp_get);
+
+static int qdcp_set_atid(struct qdcp_data *qdcp,
+ enum qdcp_trace_source source, u64 source_id,
+ u8 atid)
+{
+ struct qdcp_atid_set_req_v01 req = {
+ .trace_source = {
+ .type = source,
+ .id = source_id,
+ },
+ };
+ struct qdcp_resp_v01 resp;
+
+ if (atid) {
+ req.atids[0] = atid;
+ req.num_atids = 1;
+ }
+
+ return qdcp_send(qdcp, QDCP_ATID_SET, qdcp_atid_set_req_ei, &req,
+ sizeof(req), &resp);
+}
+
+int qdcp_stm_source_enable(struct qdcp_data *qdcp, u64 stm_id,
+ u8 atid, u32 port_mask, bool hwevent)
+{
+ struct qdcp_stm_set_param_req_v01 port_req = {
+ .stm_id = stm_id,
+ .param = QDCP_STM_PARAM_PORT_ENABLE,
+ .value = port_mask,
+ };
+ struct qdcp_resp_v01 resp;
+ int ret;
+
+ ret = qdcp_set_atid(qdcp, QDCP_TRACE_SOURCE_STM, stm_id, atid);
+ if (ret)
+ return ret;
+
+ if (hwevent) {
+ ret = qdcp_set_state(qdcp, QDCP_STM_HWE_SET_STATE, stm_id, true);
+ if (ret)
+ goto clear_atid;
+ }
+
+ ret = qdcp_send(qdcp, QDCP_STM_SET_PARAM, qdcp_stm_set_param_req_ei,
+ &port_req, sizeof(port_req), &resp);
+ if (ret)
+ goto disable_hwevent;
+
+ ret = qdcp_set_state(qdcp, QDCP_STM_SET_STATE, stm_id, true);
+ if (ret)
+ goto disable_hwevent;
+
+ return 0;
+
+disable_hwevent:
+ if (hwevent)
+ qdcp_set_state(qdcp, QDCP_STM_HWE_SET_STATE, stm_id, false);
+clear_atid:
+ qdcp_set_atid(qdcp, QDCP_TRACE_SOURCE_STM, stm_id, 0);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(qdcp_stm_source_enable);
+
+int qdcp_stm_source_disable(struct qdcp_data *qdcp, u64 stm_id,
+ u8 atid, bool hwevent)
+{
+ int ret, err;
+
+ /* Best effort: run every step and report the first failure. */
+ ret = qdcp_set_state(qdcp, QDCP_STM_SET_STATE, stm_id, false);
+ if (hwevent) {
+ err = qdcp_set_state(qdcp, QDCP_STM_HWE_SET_STATE, stm_id,
+ false);
+ ret = ret ?: err;
+ }
+ err = qdcp_set_atid(qdcp, QDCP_TRACE_SOURCE_STM, stm_id, 0);
+
+ return ret ?: err;
+}
+EXPORT_SYMBOL_GPL(qdcp_stm_source_disable);
+
+static int qdcp_tmc_set_param(struct qdcp_data *qdcp, u64 tmc_id,
+ enum qdcp_tmc_param param, u64 value)
+{
+ struct qdcp_tmc_set_param_req_v01 req = {
+ .tmc_id = tmc_id,
+ .param = param,
+ .value = value,
+ };
+ struct qdcp_resp_v01 resp;
+
+ return qdcp_send(qdcp, QDCP_TMC_SET_PARAM, qdcp_tmc_set_param_req_ei,
+ &req, sizeof(req), &resp);
+}
+
+int qdcp_tmc_get_param(struct qdcp_data *qdcp, u64 tmc_id,
+ enum qdcp_tmc_param param, u64 *value)
+{
+ struct qdcp_tmc_get_param_req_v01 req = {
+ .tmc_id = tmc_id,
+ .param = param,
+ };
+ struct qdcp_tmc_get_param_resp_v01 resp;
+ int ret;
+
+ ret = qdcp_send_resp(qdcp, QDCP_TMC_GET_PARAM,
+ qdcp_tmc_get_param_req_ei, &req, sizeof(req),
+ qdcp_tmc_get_param_resp_ei, &resp, sizeof(resp));
+ if (ret)
+ return ret;
+
+ if (!resp.value_valid)
+ return -EPROTO;
+
+ *value = resp.value;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(qdcp_tmc_get_param);
+
+static int qdcp_tmc_enable(struct qdcp_data *qdcp, u64 tmc_id)
+{
+ return qdcp_set_state(qdcp, QDCP_TMC_SET_STATE, tmc_id, true);
+}
+
+static int qdcp_tmc_disable(struct qdcp_data *qdcp, u64 tmc_id)
+{
+ return qdcp_set_state(qdcp, QDCP_TMC_SET_STATE, tmc_id, false);
+}
+
+static int qdcp_tmc_assign_buffer(struct qdcp_data *qdcp, u64 tmc_id,
+ phys_addr_t paddr, dma_addr_t iaddr,
+ size_t size)
+{
+ struct qdcp_tmc_assign_buffer_req_v01 req = {
+ .tmc_id = tmc_id,
+ .buffer = {
+ .paddr = paddr,
+ .iaddr = iaddr,
+ .size = size,
+ },
+ };
+ struct qdcp_resp_v01 resp;
+
+ return qdcp_send(qdcp, QDCP_TMC_ASSIGN_BUFFER,
+ qdcp_tmc_assign_buffer_req_ei, &req, sizeof(req), &resp);
+}
+
+int qdcp_tmc_etr_enable(struct qdcp_data *qdcp, const struct qdcp_tmc_cfg *cfg)
+{
+ int ret;
+
+ ret = qdcp_tmc_set_param(qdcp, cfg->tmc_id,
+ QDCP_TMC_PARAM_SG_MODE,
+ cfg->sg_mode ? 1 : 0);
+ if (ret)
+ return ret;
+
+ if (cfg->ffcr) {
+ ret = qdcp_tmc_set_param(qdcp, cfg->tmc_id,
+ QDCP_TMC_PARAM_FFCR,
+ cfg->ffcr);
+ if (ret)
+ return ret;
+ }
+
+ ret = qdcp_tmc_assign_buffer(qdcp, cfg->tmc_id, cfg->paddr, cfg->iaddr,
+ cfg->size);
+ if (ret)
+ return ret;
+
+ return qdcp_tmc_enable(qdcp, cfg->tmc_id);
+}
+EXPORT_SYMBOL_GPL(qdcp_tmc_etr_enable);
+
+int qdcp_tmc_etr_disable(struct qdcp_data *qdcp, u64 tmc_id)
+{
+ return qdcp_tmc_disable(qdcp, tmc_id);
+}
+EXPORT_SYMBOL_GPL(qdcp_tmc_etr_disable);
+
+static int qdcp_new_server(struct qmi_handle *qmi, struct qmi_service *svc)
+{
+ struct qdcp_data *qdcp = container_of(qmi, struct qdcp_data,
+ qmi);
+
+ if (svc->version != qdcp->version || svc->instance != qdcp->instance_id)
+ return -EINVAL;
+
+ mutex_lock(&qdcp->lock);
+ qdcp->sq.sq_family = AF_QIPCRTR;
+ qdcp->sq.sq_node = svc->node;
+ qdcp->sq.sq_port = svc->port;
+ qdcp->connected = true;
+ svc->priv = qdcp;
+ mutex_unlock(&qdcp->lock);
+
+ dev_info(qdcp->dev, "connected to QECP QDCP service %u instance %u\n",
+ qdcp->service_id, qdcp->instance_id);
+ return 0;
+}
+
+static void qdcp_del_server(struct qmi_handle *qmi, struct qmi_service *svc)
+{
+ struct qdcp_data *qdcp = svc->priv;
+
+ if (!qdcp)
+ return;
+
+ mutex_lock(&qdcp->lock);
+ /*
+ * svc->priv only proves this svc was once matched by
+ * qdcp_new_server(); it doesn't prove svc is the currently active
+ * server. A firmware restart can register a new server (updating
+ * qdcp->sq) before the old server's DEL_SERVER arrives here, so
+ * only clear the connection if this del_server is for the node/port
+ * qdcp is actually connected to.
+ */
+ if (qdcp->connected && qdcp->sq.sq_node == svc->node &&
+ qdcp->sq.sq_port == svc->port) {
+ qdcp->connected = false;
+ memset(&qdcp->sq, 0, sizeof(qdcp->sq));
+ dev_info(qdcp->dev, "disconnected from QECP QDCP service\n");
+ }
+ mutex_unlock(&qdcp->lock);
+}
+
+static void qdcp_net_reset(struct qmi_handle *qmi)
+{
+ struct qdcp_data *qdcp = container_of(qmi, struct qdcp_data,
+ qmi);
+
+ mutex_lock(&qdcp->lock);
+ qdcp->connected = false;
+ memset(&qdcp->sq, 0, sizeof(qdcp->sq));
+ mutex_unlock(&qdcp->lock);
+}
+
+static const struct qmi_ops qdcp_qmi_ops = {
+ .new_server = qdcp_new_server,
+ .del_server = qdcp_del_server,
+ .net_reset = qdcp_net_reset,
+};
+
+static void qdcp_connection_free(struct qdcp_data *qdcp)
+{
+ qmi_handle_release(&qdcp->qmi);
+ kref_put(&qdcp->ref, qdcp_release);
+}
+
+static struct qdcp_data *qdcp_connection_create(struct device *dev,
+ struct device_node *np)
+{
+ struct qdcp_data *qdcp;
+ int ret;
+
+ qdcp = kzalloc_obj(*qdcp);
+ if (!qdcp)
+ return ERR_PTR(-ENOMEM);
+
+ kref_init(&qdcp->ref);
+ qdcp->dev = get_device(dev);
+ qdcp->of_node = of_node_get(np);
+ mutex_init(&qdcp->lock);
+ INIT_LIST_HEAD(&qdcp->node);
+
+ ret = of_property_read_u32(np, "qcom,service-id", &qdcp->service_id);
+ if (ret) {
+ dev_err(dev, "%pOFn: missing qcom,service-id: %d\n", np, ret);
+ goto err_release;
+ }
+
+ ret = of_property_read_u32(np, "qcom,instance-id", &qdcp->instance_id);
+ if (ret) {
+ dev_err(dev, "%pOFn: missing qcom,instance-id: %d\n", np, ret);
+ goto err_release;
+ }
+
+ /* qcom,version is optional; default to version 1 when absent. */
+ if (of_property_read_u32(np, "qcom,version", &qdcp->version))
+ qdcp->version = 1;
+
+ ret = qmi_handle_init(&qdcp->qmi, QDCP_MAX_MSG_LEN, &qdcp_qmi_ops, NULL);
+ if (ret) {
+ dev_err(dev, "%pOFn: failed to initialize QMI handle: %d\n",
+ np, ret);
+ goto err_release;
+ }
+
+ ret = qmi_add_lookup(&qdcp->qmi, qdcp->service_id, qdcp->version,
+ qdcp->instance_id);
+ if (ret) {
+ dev_err(dev, "%pOFn: failed to add QMI lookup: %d\n", np, ret);
+ qmi_handle_release(&qdcp->qmi);
+ goto err_release;
+ }
+
+ dev_info(dev, "%pOFn: registered QDCP connection service=%u version=%u instance=%u\n",
+ np, qdcp->service_id, qdcp->version, qdcp->instance_id);
+ return qdcp;
+
+err_release:
+ kref_put(&qdcp->ref, qdcp_release);
+ return ERR_PTR(ret);
+}
+
+static int qdcp_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct qdcp_data *qdcp, *tmp;
+ LIST_HEAD(conn_list);
+ int ret;
+
+ for_each_available_child_of_node_scoped(dev->of_node, np) {
+ qdcp = qdcp_connection_create(dev, np);
+ if (IS_ERR(qdcp)) {
+ ret = PTR_ERR(qdcp);
+ goto err_unwind;
+ }
+ list_add_tail(&qdcp->node, &conn_list);
+ }
+
+ /*
+ * A provider with no connection-N children is valid, since the binding
+ * cannot require one; it simply has nothing for consumers to reference.
+ */
+ if (list_empty(&conn_list))
+ dev_warn(dev, "no QDCP connection child nodes found\n");
+
+ mutex_lock(&qdcp_providers_lock);
+ list_splice_tail(&conn_list, &qdcp_providers);
+ mutex_unlock(&qdcp_providers_lock);
+
+ return 0;
+
+err_unwind:
+ list_for_each_entry_safe(qdcp, tmp, &conn_list, node) {
+ list_del(&qdcp->node);
+ qdcp_connection_free(qdcp);
+ }
+ return ret;
+}
+
+static void qdcp_remove(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct qdcp_data *qdcp, *tmp;
+ LIST_HEAD(removed);
+
+ mutex_lock(&qdcp_providers_lock);
+ list_for_each_entry_safe(qdcp, tmp, &qdcp_providers, node) {
+ if (qdcp->dev != dev)
+ continue;
+ list_move_tail(&qdcp->node, &removed);
+ }
+ mutex_unlock(&qdcp_providers_lock);
+
+ list_for_each_entry_safe(qdcp, tmp, &removed, node) {
+ mutex_lock(&qdcp->lock);
+ qdcp->dying = true;
+ qdcp->connected = false;
+ mutex_unlock(&qdcp->lock);
+
+ list_del(&qdcp->node);
+ qdcp_connection_free(qdcp);
+ }
+}
+
+static const struct of_device_id qdcp_match[] = {
+ { .compatible = "qcom,qdcp" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, qdcp_match);
+
+static struct platform_driver qdcp_driver = {
+ .probe = qdcp_probe,
+ .remove = qdcp_remove,
+ .driver = {
+ .name = "qcom-qdcp",
+ .of_match_table = qdcp_match,
+ },
+};
+module_platform_driver(qdcp_driver);
+
+MODULE_DESCRIPTION("Qualcomm Debug Control Protocol provider");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/qcom/qdcp.h b/include/linux/soc/qcom/qdcp.h
new file mode 100644
index 000000000000..cff50bae3c15
--- /dev/null
+++ b/include/linux/soc/qcom/qdcp.h
@@ -0,0 +1,128 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef _LINUX_SOC_QCOM_QDCP_H
+#define _LINUX_SOC_QCOM_QDCP_H
+
+#include <linux/err.h>
+#include <linux/kconfig.h>
+#include <linux/errno.h>
+#include <linux/mutex.h>
+#include <linux/types.h>
+
+struct device;
+struct qdcp_data;
+
+/**
+ * struct qdcp_consumer - per-consumer QDCP connection state.
+ * @provider: QDCP QMI connection this consumer was resolved against.
+ * @id: firmware identifier for this consumer within @provider (STM source
+ * id or TMC id, depending on which consumer embeds this struct).
+ * @lock: serializes this consumer's QDCP firmware calls together with
+ * whatever consumer-local state (mode, refcount, buffers, ...) must
+ * stay atomic with them. Needed because QDCP enable/disable makes a
+ * sleeping firmware RPC and therefore cannot be guarded by a spinlock.
+ *
+ * Embedded by Qualcomm CoreSight consumer drivers (QDCP STM source, QDCP
+ * TMC/ETR sink) that talk to a firmware-owned trace block through QDCP.
+ */
+struct qdcp_consumer {
+ struct qdcp_data *provider;
+ u64 id;
+ /* Serializes this consumer's QDCP firmware calls; see field comment. */
+ struct mutex lock;
+};
+
+/*
+ * QDCP TMC parameter identifiers used in QDCP_TMC_GET_PARAM/SET_PARAM
+ * requests. These are firmware-defined parameter IDs, not a mirror of the
+ * TMC MMIO register map: STS, FFCR, and DEVID happen to share their values
+ * with the corresponding TMC_STS/TMC_FFCR/CORESIGHT_DEVID register offsets
+ * because firmware proxies those specific parameters as literal register
+ * reads, but SG_MODE, RRP, and RWP are firmware-only parameter IDs with no
+ * corresponding MMIO offset. Do not "align" RRP/RWP to TMC_RRP/TMC_RWP —
+ * that would send the wrong parameter ID to firmware.
+ */
+enum qdcp_tmc_param {
+ QDCP_TMC_PARAM_STS = 0x00c,
+ QDCP_TMC_PARAM_FFCR = 0x304,
+ QDCP_TMC_PARAM_SG_MODE = 0x1002,
+ QDCP_TMC_PARAM_RRP = 0x1003,
+ QDCP_TMC_PARAM_RWP = 0x1004,
+ QDCP_TMC_PARAM_DEVID = 0xfc8,
+};
+
+struct qdcp_tmc_cfg {
+ u64 tmc_id;
+ phys_addr_t paddr;
+ dma_addr_t iaddr;
+ size_t size;
+ bool sg_mode;
+ u32 ffcr;
+};
+
+#if IS_REACHABLE(CONFIG_QCOM_QDCP) || defined(QCOM_QDCP_PROVIDER)
+/**
+ * devm_qdcp_get() - look up a QDCP connection by phandle
+ * @dev: consumer device whose DT node holds @phandle_name
+ * @phandle_name: name of the phandle property, e.g. "qcom,qdcp"
+ *
+ * @phandle_name must reference a "connection-N" child node of a
+ * "qcom,qdcp" provider (see
+ * Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml), not the
+ * top-level provider node itself. A phandle to the provider node will
+ * never match and the lookup will keep returning -EPROBE_DEFER.
+ *
+ * Return: connection handle, or an error pointer on failure.
+ */
+struct qdcp_data *devm_qdcp_get(struct device *dev, const char *phandle_name);
+int qdcp_stm_source_enable(struct qdcp_data *qdcp, u64 stm_id, u8 atid,
+ u32 port_mask, bool hwevent);
+int qdcp_stm_source_disable(struct qdcp_data *qdcp, u64 stm_id, u8 atid,
+ bool hwevent);
+int qdcp_tmc_get_param(struct qdcp_data *qdcp, u64 tmc_id,
+ enum qdcp_tmc_param param, u64 *value);
+int qdcp_tmc_etr_enable(struct qdcp_data *qdcp,
+ const struct qdcp_tmc_cfg *cfg);
+int qdcp_tmc_etr_disable(struct qdcp_data *qdcp, u64 tmc_id);
+#else
+static inline struct qdcp_data *
+devm_qdcp_get(struct device *dev, const char *phandle_name)
+{
+ return ERR_PTR(-EOPNOTSUPP);
+}
+
+static inline int qdcp_stm_source_enable(struct qdcp_data *qdcp, u64 stm_id,
+ u8 atid, u32 port_mask, bool hwevent)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int qdcp_stm_source_disable(struct qdcp_data *qdcp,
+ u64 stm_id, u8 atid, bool hwevent)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int
+qdcp_tmc_get_param(struct qdcp_data *qdcp, u64 tmc_id,
+ enum qdcp_tmc_param param, u64 *value)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int
+qdcp_tmc_etr_enable(struct qdcp_data *qdcp, const struct qdcp_tmc_cfg *cfg)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int qdcp_tmc_etr_disable(struct qdcp_data *qdcp, u64 tmc_id)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
+#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
2026-11-19 9:01 ` [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider Jie Gan
@ 2026-11-19 9:01 ` Jie Gan
2026-11-19 14:02 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 4/6] coresight: " Jie Gan
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
Document the Qualcomm QDCP-backed CoreSight STM (System Trace Macrocell)
source, for platforms where the STM control registers are owned by
Qualcomm Embedded Co-Processor (QECP) firmware instead of the
application processor (AP).
The node describes only the STM stimulus aperture, the MMIO region the
AP writes trace data to. Firmware controls the STM through the Qualcomm
Debug Control Protocol (QDCP) provider referenced by the qcom,qdcp
phandle. Firmware also controls the block's clocks and power, so the
binding has no clocks or power-domains properties.
The output port must have an endpoint so the source can be connected to
a trace sink.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
.../bindings/arm/qcom,coresight-stm-qdcp.yaml | 111 +++++++++++++++++++++
1 file changed, 111 insertions(+)
diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight-stm-qdcp.yaml b/Documentation/devicetree/bindings/arm/qcom,coresight-stm-qdcp.yaml
new file mode 100644
index 000000000000..f365ce2450ad
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/qcom,coresight-stm-qdcp.yaml
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/qcom,coresight-stm-qdcp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm QDCP-backed CoreSight STM source
+
+maintainers:
+ - Jie Gan <jie.gan@oss.qualcomm.com>
+
+description: |
+ The System Trace Macrocell (STM) is a CoreSight trace source designed for
+ high-bandwidth trace of software instrumentation, made up of memory-mapped
+ writes to the STM stimulus aperture.
+
+ On Qualcomm platforms where the STM control registers are owned by QECP
+ firmware, this binding describes an STM whose stimulus aperture is mapped by
+ the application processor for data writes, while enabling and disabling the
+ trace path is delegated to firmware over the Qualcomm Debug Control Protocol
+ (QDCP). It references a QDCP provider through the "qcom,qdcp" phandle rather
+ than exposing the STM programming registers directly.
+
+select:
+ properties:
+ compatible:
+ contains:
+ const: qcom,coresight-stm-qdcp
+ required:
+ - compatible
+
+properties:
+ $nodename:
+ pattern: "^stm(@[0-9a-f]+)$"
+
+ compatible:
+ const: qcom,coresight-stm-qdcp
+
+ reg:
+ maxItems: 1
+
+ reg-names:
+ items:
+ - const: stm-stimulus-base
+
+ qcom,qdcp:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the specific "connection-N" child node of the QDCP
+ provider (see qcom,qdcp.yaml) that owns this STM's control registers
+ and services the firmware enable/disable transactions. This must
+ reference the connection child node directly, not the top-level
+ QDCP provider node itself.
+
+ qcom,qdcp-source-id:
+ $ref: /schemas/types.yaml#/definitions/uint64
+ description:
+ QECP firmware source identifier for this STM, used to address it in QDCP
+ transactions.
+
+ qcom,num-stimulus-ports:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ Number of stimulus ports (channels) exposed by this STM. If absent, the
+ number of ports is derived from the size of the stimulus aperture.
+ minimum: 1
+
+ out-ports:
+ $ref: /schemas/graph.yaml#/properties/ports
+ additionalProperties: false
+
+ properties:
+ port:
+ description: Output connection to the CoreSight Trace bus.
+ $ref: /schemas/graph.yaml#/properties/port
+ required:
+ - endpoint
+
+ required:
+ - port
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - qcom,qdcp
+ - qcom,qdcp-source-id
+ - out-ports
+
+additionalProperties: false
+
+examples:
+ - |
+ stm@a06000 {
+ compatible = "qcom,coresight-stm-qdcp";
+ reg = <0x00a06000 0x180000>;
+ reg-names = "stm-stimulus-base";
+
+ qcom,qdcp = <&qdcp_coresight>;
+ qcom,qdcp-source-id = /bits/ 64 <0>;
+ qcom,num-stimulus-ports = <128>;
+
+ out-ports {
+ port {
+ stm_out_funnel_in0: endpoint {
+ remote-endpoint = <&funnel_in0_in_stm>;
+ };
+ };
+ };
+ };
+...
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFC 4/6] coresight: qcom: add QDCP STM source
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
` (2 preceding siblings ...)
2026-11-19 9:01 ` [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source Jie Gan
@ 2026-11-19 9:01 ` Jie Gan
2026-11-19 9:28 ` sashiko-bot
2026-11-19 9:01 ` [PATCH RFC 5/6] dt-bindings: arm: qcom: add QDCP TMC ETR sink Jie Gan
2026-11-19 9:01 ` [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support Jie Gan
5 siblings, 1 reply; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
Add a Qualcomm-specific CoreSight STM (System Trace Macrocell) source
for platforms where the Qualcomm Embedded Co-Processor (QECP) firmware
owns the STM control registers.
The driver maps only the AP-visible STM stimulus aperture. Enable and
disable operations go through the Qualcomm Debug Control Protocol
(QDCP) provider referenced by qcom,qdcp, keeping the generic CoreSight
STM driver untouched. Firmware controls the block's clocks and power,
so the driver does no clock handling or runtime PM.
The CoreSight source disable operation cannot fail. If firmware does
not confirm a stop, the source is still marked disabled and a warning
is logged, and the failure is remembered. On removal the trace ID then
stays allocated, so no other source can reuse an ID that firmware may
still be applying. On removal the STM device is unregistered before the
CoreSight device, so its unlink callback never runs on a freed
CoreSight device.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
drivers/hwtracing/coresight/Kconfig | 11 +
drivers/hwtracing/coresight/Makefile | 2 +
.../hwtracing/coresight/coresight-qcom-qdcp-stm.c | 550 +++++++++++++++++++++
3 files changed, 563 insertions(+)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 6a4239ebb582..f6ad698344fe 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -119,6 +119,17 @@ config ETM4X_IMPDEF_FEATURE
ETM 4.x tracer module that can't reduce commit rate automatically.
This avoids overflow between the ETM tracer module and the cpu core.
+config CORESIGHT_QCOM_QDCP_STM
+ tristate "Qualcomm QDCP CoreSight STM source driver"
+ depends on QCOM_QDCP
+ select CORESIGHT_LINKS_AND_SINKS
+ select STM
+ help
+ This driver provides a Qualcomm QDCP-backed CoreSight STM source.
+ It maps the AP-visible STM stimulus aperture but asks QECP firmware
+ to enable and disable STM tracing through QDCP instead of touching
+ STM control registers directly.
+
config CORESIGHT_STM
tristate "CoreSight System Trace Macrocell driver"
depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index ab16d06783a5..d97e334fe1fc 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -23,6 +23,7 @@ condflags := \
subdir-ccflags-y += $(condflags)
CFLAGS_coresight-stm.o := -D__DISABLE_TRACE_MMIO__
+CFLAGS_coresight-qcom-qdcp-stm.o := -D__DISABLE_TRACE_MMIO__
obj-$(CONFIG_CORESIGHT) += coresight.o
coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.o \
@@ -43,6 +44,7 @@ coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o \
coresight-etm4x-cfg.o
+obj-$(CONFIG_CORESIGHT_QCOM_QDCP_STM) += coresight-qcom-qdcp-stm.o
obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
diff --git a/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c b/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c
new file mode 100644
index 000000000000..39c6a2798a0f
--- /dev/null
+++ b/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c
@@ -0,0 +1,550 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * Qualcomm QDCP-backed CoreSight STM source driver.
+ */
+
+#include <linux/bitmap.h>
+#include <linux/coresight.h>
+#include <linux/coresight-stm.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/log2.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/perf_event.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/stm.h>
+#include <linux/string.h>
+
+#include "coresight-priv.h"
+#include <linux/soc/qcom/qdcp.h>
+#include "coresight-trace-id.h"
+
+#define QDCP_STM_BYTES_PER_CHANNEL 256
+#define QDCP_STM_PKT_TYPE_DATA 0x98
+#define QDCP_STM_PKT_TYPE_FLAG 0xe8
+
+#define qdcp_stm_channel_addr(drvdata, channel) \
+ ((drvdata)->stimulus_base + \
+ ((channel) * QDCP_STM_BYTES_PER_CHANNEL))
+#define qdcp_stm_channel_off(type, options) ((type) & ~(options))
+
+/**
+ * struct qcom_qdcp_stm_drvdata - QDCP STM source data.
+ * @stm: generic STM interface handle.
+ * @csdev: CoreSight source device.
+ * @stimulus_base: mapped AP-visible STM stimulus aperture.
+ * @stimulus_phys: physical base of the STM stimulus aperture.
+ * @guaranteed: per-channel guaranteed/invariant delivery bitmap.
+ * @qdcp: QDCP connection state; @qdcp.id is the QECP firmware source
+ * identifier, @qdcp.lock serializes sleeping QDCP operations.
+ * @traceid: CoreSight ATID assigned to this source.
+ * @fw_stop_failed: the last firmware stop was not confirmed, so firmware may
+ * still be tagging trace with @traceid. Updated under @qdcp.lock; read
+ * without it only on removal, when nothing else can use the source.
+ * @numsp: number of stimulus ports.
+ * @write_bytes: maximum naturally aligned stimulus write size.
+ * @port_mask: stimulus port enable mask sent to firmware. Like the STMSPER
+ * register it mirrors, this is a 32-bit mask applied per 32-port group,
+ * so enabling every bit covers all ports regardless of @numsp.
+ */
+struct qcom_qdcp_stm_drvdata {
+ struct stm_data stm;
+ struct coresight_device *csdev;
+ void __iomem *stimulus_base;
+ phys_addr_t stimulus_phys;
+ unsigned long *guaranteed;
+ struct qdcp_consumer qdcp;
+ u8 traceid;
+ bool fw_stop_failed;
+ u32 numsp;
+ u32 write_bytes;
+ u32 port_mask;
+};
+
+static bool qdcp_stm_addr_unaligned(const void *addr, u8 write_bytes)
+{
+ return (unsigned long)addr & (write_bytes - 1);
+}
+
+static void qdcp_stm_send(void __iomem *addr, const void *data,
+ u32 size, u8 write_bytes)
+{
+ u8 payload[8];
+
+ if (qdcp_stm_addr_unaligned(data, write_bytes)) {
+ memcpy(payload, data, size);
+ data = payload;
+ }
+
+ switch (size) {
+#ifdef CONFIG_64BIT
+ case 8:
+ writeq_relaxed(*(u64 *)data, addr);
+ break;
+#endif
+ case 4:
+ writel_relaxed(*(u32 *)data, addr);
+ break;
+ case 2:
+ writew_relaxed(*(u16 *)data, addr);
+ break;
+ case 1:
+ writeb_relaxed(*(u8 *)data, addr);
+ break;
+ default:
+ break;
+ }
+}
+
+static ssize_t notrace qdcp_stm_packet(struct stm_data *stm_data,
+ unsigned int master, unsigned int channel,
+ unsigned int packet, unsigned int flags,
+ unsigned int size,
+ const unsigned char *payload)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+ void __iomem *channel_addr;
+ unsigned int stm_flags;
+
+ drvdata = container_of(stm_data, struct qcom_qdcp_stm_drvdata, stm);
+ if (!coresight_get_mode(drvdata->csdev))
+ return -EACCES;
+
+ if (channel >= drvdata->numsp)
+ return -EINVAL;
+
+ channel_addr = qdcp_stm_channel_addr(drvdata, channel);
+ stm_flags = flags & STP_PACKET_TIMESTAMPED ? STM_FLAG_TIMESTAMPED : 0;
+ stm_flags |= test_bit(channel, drvdata->guaranteed) ?
+ STM_FLAG_GUARANTEED : 0;
+
+ switch (packet) {
+ case STP_PACKET_FLAG:
+ channel_addr += qdcp_stm_channel_off(QDCP_STM_PKT_TYPE_FLAG,
+ stm_flags);
+ qdcp_stm_send(channel_addr, payload, 1, drvdata->write_bytes);
+ return 1;
+ case STP_PACKET_DATA:
+ if (!size)
+ return 0;
+ if (size > drvdata->write_bytes)
+ size = drvdata->write_bytes;
+ else
+ size = rounddown_pow_of_two(size);
+
+ stm_flags |= flags & STP_PACKET_MARKED ? STM_FLAG_MARKED : 0;
+ channel_addr += qdcp_stm_channel_off(QDCP_STM_PKT_TYPE_DATA,
+ stm_flags);
+ qdcp_stm_send(channel_addr, payload, size, drvdata->write_bytes);
+ return size;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static phys_addr_t qdcp_stm_mmio_addr(struct stm_data *stm_data,
+ unsigned int master, unsigned int channel,
+ unsigned int nr_chans)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+ phys_addr_t addr;
+
+ drvdata = container_of(stm_data, struct qcom_qdcp_stm_drvdata, stm);
+ addr = drvdata->stimulus_phys +
+ channel * QDCP_STM_BYTES_PER_CHANNEL;
+
+ if (offset_in_page(addr) ||
+ offset_in_page(nr_chans * QDCP_STM_BYTES_PER_CHANNEL))
+ return 0;
+
+ return addr;
+}
+
+static int qdcp_stm_link(struct stm_data *stm_data, unsigned int master,
+ unsigned int channel)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+
+ drvdata = container_of(stm_data, struct qcom_qdcp_stm_drvdata, stm);
+ if (!drvdata->csdev)
+ return -EINVAL;
+
+ return coresight_enable_sysfs(drvdata->csdev);
+}
+
+static void qdcp_stm_unlink(struct stm_data *stm_data, unsigned int master,
+ unsigned int channel)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+
+ drvdata = container_of(stm_data, struct qcom_qdcp_stm_drvdata, stm);
+ if (drvdata->csdev)
+ coresight_disable_sysfs(drvdata->csdev);
+}
+
+static long qdcp_stm_set_options(struct stm_data *stm_data,
+ unsigned int master, unsigned int channel,
+ unsigned int nr_chans, unsigned long options)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+
+ drvdata = container_of(stm_data, struct qcom_qdcp_stm_drvdata, stm);
+ if (!coresight_get_mode(drvdata->csdev))
+ return -EINVAL;
+
+ if (channel >= drvdata->numsp)
+ return -EINVAL;
+
+ switch (options) {
+ case STM_OPTION_GUARANTEED:
+ set_bit(channel, drvdata->guaranteed);
+ break;
+ case STM_OPTION_INVARIANT:
+ clear_bit(channel, drvdata->guaranteed);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int qdcp_stm_enable(struct coresight_device *csdev,
+ struct perf_event *event, enum cs_mode mode,
+ struct coresight_path *path)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+ int ret;
+
+ if (mode != CS_MODE_SYSFS)
+ return -EINVAL;
+
+ if (!coresight_take_mode(csdev, mode))
+ return -EBUSY;
+
+ drvdata = dev_get_drvdata(csdev->dev.parent);
+
+ mutex_lock(&drvdata->qdcp.lock);
+ ret = qdcp_stm_source_enable(drvdata->qdcp.provider, drvdata->qdcp.id,
+ drvdata->traceid, drvdata->port_mask,
+ false);
+ if (!ret)
+ drvdata->fw_stop_failed = false;
+ mutex_unlock(&drvdata->qdcp.lock);
+ if (ret) {
+ coresight_set_mode(csdev, CS_MODE_DISABLED);
+ return ret;
+ }
+
+ dev_dbg(&csdev->dev, "QDCP STM tracing enabled\n");
+ return 0;
+}
+
+/*
+ * The CoreSight source disable op returns void and the user has already torn
+ * the path down, so the source always ends up disabled from Linux's point of
+ * view. Return the firmware result so the caller can at least report it.
+ */
+static int qdcp_stm_disable_source(struct coresight_device *csdev)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+ struct qdcp_data *qdcp;
+ u64 source_id;
+ u8 traceid;
+ int ret;
+
+ if (coresight_get_mode(csdev) != CS_MODE_SYSFS)
+ return 0;
+
+ drvdata = dev_get_drvdata(csdev->dev.parent);
+ qdcp = drvdata->qdcp.provider;
+ source_id = drvdata->qdcp.id;
+ traceid = drvdata->traceid;
+
+ mutex_lock(&drvdata->qdcp.lock);
+ ret = qdcp_stm_source_disable(qdcp, source_id, traceid, false);
+ drvdata->fw_stop_failed = !!ret;
+ mutex_unlock(&drvdata->qdcp.lock);
+
+ coresight_set_mode(csdev, CS_MODE_DISABLED);
+ dev_dbg(&csdev->dev, "QDCP STM tracing disabled\n");
+ return ret;
+}
+
+static void qdcp_stm_disable(struct coresight_device *csdev,
+ struct perf_event *event)
+{
+ int ret = qdcp_stm_disable_source(csdev);
+
+ if (ret)
+ dev_warn(&csdev->dev,
+ "firmware did not confirm QDCP STM disable: %d\n",
+ ret);
+}
+
+static int qdcp_stm_trace_id(struct coresight_device *csdev,
+ enum cs_mode mode, struct coresight_device *sink)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+
+ drvdata = dev_get_drvdata(csdev->dev.parent);
+ return drvdata->traceid;
+}
+
+static const struct coresight_ops_source qdcp_stm_source_ops = {
+ .enable = qdcp_stm_enable,
+ .disable = qdcp_stm_disable,
+};
+
+static const struct coresight_ops qdcp_stm_cs_ops = {
+ .trace_id = qdcp_stm_trace_id,
+ .source_ops = &qdcp_stm_source_ops,
+};
+
+static ssize_t traceid_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
+
+ return sysfs_emit(buf, "%#x\n", drvdata->traceid);
+}
+static DEVICE_ATTR_RO(traceid);
+
+static struct attribute *qdcp_stm_attrs[] = {
+ &dev_attr_traceid.attr,
+ NULL,
+};
+
+static const struct attribute_group qdcp_stm_group = {
+ .attrs = qdcp_stm_attrs,
+};
+
+static const struct attribute_group *qdcp_stm_groups[] = {
+ &qdcp_stm_group,
+ NULL,
+};
+
+static int qdcp_stm_get_stimulus_area(struct platform_device *pdev,
+ struct resource **res)
+{
+ /*
+ * The binding requires reg-names = "stm-stimulus-base"; there is no
+ * documented unnamed-resource form, so don't silently accept one.
+ */
+ *res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+ "stm-stimulus-base");
+ return *res ? 0 : -EINVAL;
+}
+
+static void qdcp_stm_init_stm_data(struct qcom_qdcp_stm_drvdata *drvdata,
+ const char *name)
+{
+ struct stm_data *stm = &drvdata->stm;
+
+ stm->name = name;
+ stm->sw_start = 1;
+ stm->sw_end = 1;
+ stm->hw_override = true;
+ stm->sw_nchannels = drvdata->numsp;
+ stm->sw_mmiosz = QDCP_STM_BYTES_PER_CHANNEL;
+ stm->packet = qdcp_stm_packet;
+ stm->mmio_addr = qdcp_stm_mmio_addr;
+ stm->link = qdcp_stm_link;
+ stm->unlink = qdcp_stm_unlink;
+ stm->set_options = qdcp_stm_set_options;
+}
+
+static int qdcp_stm_probe(struct platform_device *pdev)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata;
+ struct coresight_platform_data *pdata;
+ struct coresight_desc desc = { 0 };
+ struct device *dev = &pdev->dev;
+ struct resource *res;
+ const char *name;
+ u32 numsp;
+ int trace_id;
+ int ret;
+
+ drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
+ if (!drvdata)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, drvdata);
+
+ drvdata->qdcp.provider = devm_qdcp_get(dev, "qcom,qdcp");
+ if (IS_ERR(drvdata->qdcp.provider)) {
+ dev_err(dev, "failed to get QDCP provider: %pe\n",
+ drvdata->qdcp.provider);
+ return PTR_ERR(drvdata->qdcp.provider);
+ }
+
+ ret = fwnode_property_read_u64(dev->fwnode, "qcom,qdcp-source-id",
+ &drvdata->qdcp.id);
+ if (ret) {
+ dev_err(dev, "missing QDCP STM source id: %d\n", ret);
+ return ret;
+ }
+
+ ret = qdcp_stm_get_stimulus_area(pdev, &res);
+ if (ret) {
+ dev_err(dev, "missing STM stimulus aperture: %d\n", ret);
+ return ret;
+ }
+
+ drvdata->stimulus_phys = res->start;
+ drvdata->stimulus_base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(drvdata->stimulus_base))
+ return PTR_ERR(drvdata->stimulus_base);
+
+ ret = fwnode_property_read_u32(dev->fwnode, "qcom,num-stimulus-ports",
+ &numsp);
+ if (ret) {
+ numsp = resource_size(res) / QDCP_STM_BYTES_PER_CHANNEL;
+ if (!numsp) {
+ dev_err(dev, "stimulus aperture of %llu bytes holds no channels\n",
+ (u64)resource_size(res));
+ return -EINVAL;
+ }
+ } else if (!numsp ||
+ (u64)numsp * QDCP_STM_BYTES_PER_CHANNEL > resource_size(res)) {
+ /*
+ * A DT-provided port count that doesn't fit the mapped
+ * stimulus aperture would let channel addressing in
+ * qdcp_stm_packet()/qdcp_stm_mmio_addr() compute offsets past
+ * the end of what devm_ioremap_resource() actually mapped.
+ */
+ dev_err(dev, "qcom,num-stimulus-ports %u exceeds stimulus aperture of %llu bytes\n",
+ numsp, (u64)resource_size(res));
+ return -EINVAL;
+ }
+
+ drvdata->numsp = numsp;
+ drvdata->write_bytes = IS_ENABLED(CONFIG_64BIT) ? 8 : 4;
+ /*
+ * STMSPER-style mask: enable all ports in every 32-port group. The
+ * firmware applies it to whichever group is active, so this covers
+ * all ports irrespective of numsp.
+ */
+ drvdata->port_mask = U32_MAX;
+ drvdata->guaranteed = devm_bitmap_zalloc(dev, numsp, GFP_KERNEL);
+ if (!drvdata->guaranteed)
+ return -ENOMEM;
+
+ mutex_init(&drvdata->qdcp.lock);
+
+ name = coresight_alloc_device_name("qdcp_stm", dev);
+ if (!name)
+ return -ENOMEM;
+
+ trace_id = coresight_trace_id_get_system_id();
+ if (trace_id < 0)
+ return trace_id;
+ drvdata->traceid = trace_id;
+
+ pdata = coresight_get_platform_data(dev);
+ if (IS_ERR(pdata)) {
+ ret = PTR_ERR(pdata);
+ goto err_trace_id_put;
+ }
+ dev->platform_data = pdata;
+
+ desc.name = name;
+ desc.type = CORESIGHT_DEV_TYPE_SOURCE;
+ desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE;
+ desc.ops = &qdcp_stm_cs_ops;
+ desc.pdata = pdata;
+ desc.dev = dev;
+ desc.groups = qdcp_stm_groups;
+ /*
+ * The STM control registers are owned by QECP firmware and are not
+ * AP-accessible; only the stimulus aperture is mapped (for data
+ * writes, not CoreSight management access). Leave desc.access unset
+ * so the core never tries to touch programming registers directly.
+ */
+ drvdata->csdev = coresight_register(&desc);
+ if (IS_ERR(drvdata->csdev)) {
+ ret = PTR_ERR(drvdata->csdev);
+ goto err_trace_id_put;
+ }
+
+ /*
+ * csdev and traceid must both be valid before the STM char device
+ * is live, since stm_register_device() makes drvdata->stm's
+ * callbacks (packet(), set_options(), ...) reachable immediately via
+ * /dev/<name> ioctls and writes, and those callbacks dereference
+ * drvdata->csdev and drvdata->traceid.
+ */
+ qdcp_stm_init_stm_data(drvdata, name);
+ ret = stm_register_device(dev, &drvdata->stm, THIS_MODULE);
+ if (ret) {
+ dev_err(dev, "failed to register STM: %d\n", ret);
+ goto err_coresight_unregister;
+ }
+
+ dev_info(&drvdata->csdev->dev, "QDCP STM initialized\n");
+ return 0;
+
+err_coresight_unregister:
+ coresight_unregister(drvdata->csdev);
+err_trace_id_put:
+ coresight_trace_id_put_system_id(drvdata->traceid);
+ return ret;
+}
+
+static void qdcp_stm_remove(struct platform_device *pdev)
+{
+ struct qcom_qdcp_stm_drvdata *drvdata = platform_get_drvdata(pdev);
+
+ /*
+ * Unregister the STM first: its unlink callback disables the source
+ * through drvdata->csdev, which must still be live.
+ */
+ stm_unregister_device(&drvdata->stm);
+
+ /*
+ * No-op unless the source is still in CS_MODE_SYSFS. Without it,
+ * removing an enabled source would leave firmware STM enabled.
+ */
+ qdcp_stm_disable_source(drvdata->csdev);
+
+ /*
+ * A stop that failed here or earlier (fw_stop_failed) means firmware
+ * may still be tagging trace with this ID. Keep it allocated rather
+ * than let another source reuse it.
+ */
+ if (drvdata->fw_stop_failed)
+ dev_warn(&pdev->dev,
+ "QDCP STM not confirmed stopped, leaking trace ID %u\n",
+ drvdata->traceid);
+ else
+ coresight_trace_id_put_system_id(drvdata->traceid);
+
+ coresight_unregister(drvdata->csdev);
+}
+
+static const struct of_device_id qdcp_stm_match[] = {
+ { .compatible = "qcom,coresight-stm-qdcp" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, qdcp_stm_match);
+
+static struct platform_driver qdcp_stm_driver = {
+ .probe = qdcp_stm_probe,
+ .remove = qdcp_stm_remove,
+ .driver = {
+ .name = "coresight-qcom-qdcp-stm",
+ .of_match_table = qdcp_stm_match,
+ .suppress_bind_attrs = true,
+ },
+};
+module_platform_driver(qdcp_stm_driver);
+
+MODULE_DESCRIPTION("Qualcomm QDCP CoreSight STM source driver");
+MODULE_AUTHOR("Jie Gan <jie.gan@oss.qualcomm.com>");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFC 5/6] dt-bindings: arm: qcom: add QDCP TMC ETR sink
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
` (3 preceding siblings ...)
2026-11-19 9:01 ` [PATCH RFC 4/6] coresight: " Jie Gan
@ 2026-11-19 9:01 ` Jie Gan
2026-11-19 9:01 ` [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support Jie Gan
5 siblings, 0 replies; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
Document the Qualcomm QDCP-backed CoreSight TMC-ETR sink, a Trace
Memory Controller (TMC) configured as an Embedded Trace Router (ETR).
Linux owns the ETR trace buffer allocation and sysfs lifetime as usual;
only the TMC control registers are owned by Qualcomm Embedded
Co-Processor (QECP) firmware. The qcom,qdcp phandle identifies the
Qualcomm Debug Control Protocol (QDCP) firmware provider used for
buffer handoff and TMC enable/disable, and qcom,qdcp-tmc-id identifies
this TMC instance in QDCP transactions.
Firmware also controls the block's clocks and power, so the binding has
no clocks or power-domains properties. The input port must have an
endpoint so the sink can be connected to a trace source.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
.../bindings/arm/qcom,coresight-tmc-qdcp.yaml | 102 +++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight-tmc-qdcp.yaml b/Documentation/devicetree/bindings/arm/qcom,coresight-tmc-qdcp.yaml
new file mode 100644
index 000000000000..03a9dc18f13b
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/qcom,coresight-tmc-qdcp.yaml
@@ -0,0 +1,102 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/qcom,coresight-tmc-qdcp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm QDCP-backed CoreSight TMC-ETR sink
+
+maintainers:
+ - Jie Gan <jie.gan@oss.qualcomm.com>
+
+description: |
+ On Qualcomm platforms where a Trace Memory Controller configured as an
+ Embedded Trace Router (TMC-ETR) is owned by QECP firmware, the AP cannot
+ map or program the TMC control registers directly. This binding describes
+ such a firmware-owned TMC-ETR sink.
+
+ Linux still allocates and owns the ETR trace buffer using the normal
+ CoreSight sysfs buffer lifetime. The allocated buffer address and size are
+ handed off to QECP firmware over the Qualcomm Debug Control Protocol
+ (QDCP), referenced through the "qcom,qdcp" phandle, which enables and
+ disables the firmware-owned TMC and synchronizes read/write pointers.
+
+select:
+ properties:
+ compatible:
+ contains:
+ const: qcom,coresight-tmc-qdcp
+ required:
+ - compatible
+
+properties:
+ compatible:
+ const: qcom,coresight-tmc-qdcp
+
+ qcom,qdcp:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the specific "connection-N" child node of the QDCP
+ provider (see qcom,qdcp.yaml) that owns this TMC-ETR's control
+ registers and services the firmware buffer handoff and enable/disable
+ transactions. This must reference the connection child node
+ directly, not the top-level QDCP provider node itself.
+
+ qcom,qdcp-tmc-id:
+ $ref: /schemas/types.yaml#/definitions/uint64
+ description:
+ QECP firmware identifier for this TMC-ETR, used to address it in QDCP
+ transactions.
+
+ arm,scatter-gather:
+ type: boolean
+ description:
+ Indicates that the TMC-ETR can safely use the SG mode on this system.
+
+ arm,max-burst-size:
+ description:
+ The maximum burst size initiated by TMC on the AXI master interface.
+ The burst size can be in the range [0..15], the setting supports one
+ data transfer per burst up to a maximum of 16 data transfers per burst.
+ $ref: /schemas/types.yaml#/definitions/uint32
+ maximum: 15
+
+ in-ports:
+ $ref: /schemas/graph.yaml#/properties/ports
+ additionalProperties: false
+
+ properties:
+ port:
+ description: Input connection from the CoreSight Trace bus.
+ $ref: /schemas/graph.yaml#/properties/port
+ required:
+ - endpoint
+
+ required:
+ - port
+
+required:
+ - compatible
+ - qcom,qdcp
+ - qcom,qdcp-tmc-id
+ - in-ports
+
+additionalProperties: false
+
+examples:
+ - |
+ etr_qdcp: etr-qdcp {
+ compatible = "qcom,coresight-tmc-qdcp";
+
+ qcom,qdcp = <&qdcp_coresight>;
+ qcom,qdcp-tmc-id = /bits/ 64 <0>;
+
+ in-ports {
+ port {
+ etr_qdcp_in_stm: endpoint {
+ remote-endpoint = <&stm_out_etr_qdcp>;
+ };
+ };
+ };
+ };
+...
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
` (4 preceding siblings ...)
2026-11-19 9:01 ` [PATCH RFC 5/6] dt-bindings: arm: qcom: add QDCP TMC ETR sink Jie Gan
@ 2026-11-19 9:01 ` Jie Gan
2026-11-19 9:25 ` sashiko-bot
5 siblings, 1 reply; 13+ messages in thread
From: Jie Gan @ 2026-11-19 9:01 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32, Jie Gan
Add support for TMC (Trace Memory Controller) instances configured as
an ETR (Embedded Trace Router) whose control registers are owned by the
Qualcomm Embedded Co-Processor (QECP) instead of the application
processor (AP). Since the AP has no MMIO access to these registers,
probing, sysfs sink enable/disable, and RRP/RWP/STS (RAM read pointer,
RAM write pointer and status) synchronization are carried out over the
Qualcomm Debug Control Protocol (QDCP), a firmware RPC interface,
instead of direct register access. Linux still allocates and owns the
ETR trace buffer as usual.
QDCP-owned ETR probe, buffer handoff, sysfs enable/disable, and read
prepare/unprepare are implemented in a new coresight-tmc-etr-qdcp.c.
coresight-tmc-core.c and coresight-tmc-etr.c gain the probe-time checks
needed to detect a QECP-owned ETR and dispatch into it.
Firmware may write into the trace buffer until it confirms a stop, so
drvdata->etr_buf is cleared only after a confirmed stop. If a stop is
not confirmed, including after an enable request that failed or timed
out and may still have been executed, the buffer is not synced, freed
or replaced. The stop is retried on the next enable, the next open of
the device node, or removal. A failed RRP/RWP/STS read invalidates the
buffer contents instead of leaving the previous capture readable.
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
drivers/hwtracing/coresight/Makefile | 2 +-
drivers/hwtracing/coresight/coresight-tmc-core.c | 145 ++++++--
.../hwtracing/coresight/coresight-tmc-etr-qdcp.c | 379 +++++++++++++++++++++
drivers/hwtracing/coresight/coresight-tmc-etr.c | 46 ++-
drivers/hwtracing/coresight/coresight-tmc.h | 46 +++
5 files changed, 570 insertions(+), 48 deletions(-)
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index d97e334fe1fc..4a5ed093d226 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -32,7 +32,7 @@ coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.o \
coresight-syscfg-configfs.o coresight-trace-id.o
obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
- coresight-tmc-etr.o
+ coresight-tmc-etr.o coresight-tmc-etr-qdcp.o
obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index 0ef4b817b297..9b6871c51057 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -565,10 +565,27 @@ static struct attribute *coresight_tmc_attrs[] = {
NULL,
};
-static const struct attribute_group coresight_tmc_group = {
+const struct attribute_group coresight_tmc_group = {
.attrs = coresight_tmc_attrs,
};
+/*
+ * trigger_cntr has no QDCP equivalent: the local-MMIO path writes it
+ * straight to the TMC_TRG register in __tmc_etr_enable_hw(), but
+ * qdcp_tmc_cfg has no field for it and no QDCP_TMC_SET_PARAM
+ * parameter ID conveys it to firmware. Omit it here instead of exposing a
+ * sysfs knob that silently does nothing for a QDCP-owned ETR.
+ */
+static struct attribute *coresight_qdcp_tmc_attrs[] = {
+ &dev_attr_buffer_size.attr,
+ &dev_attr_stop_on_flush.attr,
+ NULL,
+};
+
+const struct attribute_group coresight_qdcp_tmc_group = {
+ .attrs = coresight_qdcp_tmc_attrs,
+};
+
static const struct attribute_group coresight_tmc_mgmt_group = {
.attrs = coresight_tmc_mgmt_attrs,
.name = "mgmt",
@@ -676,25 +693,18 @@ static void tmc_get_reserved_region(struct device *parent)
drvdata->crash_mdata.size = resource_size(&res);
}
-/* Detect and initialise the capabilities of a TMC ETR */
-static int tmc_etr_setup_caps(struct device *parent, u32 devid,
- struct csdev_access *access)
+/*
+ * Detect ETR scatter-gather support from devid and configure the DMA mask.
+ * Shared by the local-MMIO and QDCP firmware-owned ETR probe paths, which
+ * differ only in how they obtain devid and the unadvertised capabilities.
+ */
+int tmc_etr_setup_sg_and_dma_mask(struct device *dev,
+ struct tmc_drvdata *drvdata, u32 devid)
{
int rc;
- u32 tmc_pid, dma_mask = 0;
- struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
- void *dev_caps;
+ u32 dma_mask = 0;
- if (!tmc_etr_has_non_secure_access(drvdata))
- return -EACCES;
-
- tmc_pid = coresight_get_pid(access);
- dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid);
-
- /* Set the unadvertised capabilities */
- tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps);
-
- if (!(devid & TMC_DEVID_NOSCAT) && tmc_etr_can_use_sg(parent))
+ if (!(devid & TMC_DEVID_NOSCAT) && tmc_etr_can_use_sg(dev))
tmc_etr_set_cap(drvdata, TMC_ETR_SG);
/* Check if the AXI address width is available */
@@ -712,18 +722,38 @@ static int tmc_etr_setup_caps(struct device *parent, u32 devid,
case 44:
case 48:
case 52:
- dev_info(parent, "Detected dma mask %dbits\n", dma_mask);
+ dev_info(dev, "Detected dma mask %dbits\n", dma_mask);
break;
default:
dma_mask = 40;
}
- rc = dma_set_mask_and_coherent(parent, DMA_BIT_MASK(dma_mask));
+ rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(dma_mask));
if (rc)
- dev_err(parent, "Failed to setup DMA mask: %d\n", rc);
+ dev_err(dev, "Failed to setup DMA mask: %d\n", rc);
return rc;
}
+/* Detect and initialise the capabilities of a TMC ETR */
+static int tmc_etr_setup_caps(struct device *parent, u32 devid,
+ struct csdev_access *access)
+{
+ u32 tmc_pid;
+ struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
+ void *dev_caps;
+
+ if (!tmc_etr_has_non_secure_access(drvdata))
+ return -EACCES;
+
+ tmc_pid = coresight_get_pid(access);
+ dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid);
+
+ /* Set the unadvertised capabilities */
+ tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps);
+
+ return tmc_etr_setup_sg_and_dma_mask(parent, drvdata, devid);
+}
+
static u32 tmc_etr_get_default_buffer_size(struct device *dev)
{
u32 size;
@@ -786,20 +816,30 @@ static int __tmc_probe(struct device *dev, struct resource *res)
ret = -ENOMEM;
- /* Validity for the resource is already checked by the AMBA core */
- base = devm_ioremap_resource(dev, res);
- if (IS_ERR(base)) {
- ret = PTR_ERR(base);
- goto out;
+ if (device_property_present(dev, "qcom,qdcp")) {
+ ret = tmc_qdcp_etr_probe_setup(dev, drvdata, &devid);
+ if (ret)
+ goto out;
+ } else {
+ /* Validity for the resource is already checked by the AMBA core */
+ base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(base)) {
+ ret = PTR_ERR(base);
+ goto out;
+ }
+
+ drvdata->base = base;
+ desc.access = CSDEV_ACCESS_IOMEM(base);
+ devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
}
- drvdata->base = base;
- desc.access = CSDEV_ACCESS_IOMEM(base);
-
raw_spin_lock_init(&drvdata->spinlock);
-
- devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
+ mutex_init(&drvdata->qdcp.lock);
drvdata->config_type = BMVAL(devid, 6, 7);
+ if (tmc_has_qdcp(drvdata) && drvdata->config_type != TMC_CONFIG_TYPE_ETR) {
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
drvdata->memwidth = tmc_get_memwidth(devid);
/* This device is not associated with a session */
drvdata->pid = -1;
@@ -812,7 +852,8 @@ static int __tmc_probe(struct device *dev, struct resource *res)
drvdata->size = readl_relaxed(drvdata->base + TMC_RSZ) * 4;
}
- tmc_get_reserved_region(dev);
+ if (!tmc_has_qdcp(drvdata))
+ tmc_get_reserved_region(dev);
desc.dev = dev;
@@ -825,11 +866,25 @@ static int __tmc_probe(struct device *dev, struct resource *res)
dev_list = "tmc_etb";
break;
case TMC_CONFIG_TYPE_ETR:
- desc.groups = coresight_etr_groups;
+ if (tmc_has_qdcp(drvdata)) {
+ ret = tmc_qdcp_etr_sink_setup(dev, drvdata, devid, &desc);
+ /*
+ * The TMC control registers are firmware-owned and
+ * are not accessible from the panic handler, so
+ * QDCP-owned ETRs have no panic_ops and trace data
+ * captured by QECP firmware is not preserved on
+ * panic.
+ */
+ dev_notice(dev,
+ "QDCP TMC-ETR: trace data not preserved on panic\n");
+ } else {
+ desc.groups = coresight_etr_groups;
+ desc.ops = &tmc_etr_cs_ops;
+ drvdata->etr_get_state = tmc_etr_mmio_get_state;
+ ret = tmc_etr_setup_caps(dev, devid, &desc.access);
+ }
desc.type = CORESIGHT_DEV_TYPE_SINK;
desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM;
- desc.ops = &tmc_etr_cs_ops;
- ret = tmc_etr_setup_caps(dev, devid, &desc.access);
if (ret)
goto out;
idr_init(&drvdata->idr);
@@ -864,7 +919,8 @@ static int __tmc_probe(struct device *dev, struct resource *res)
dev->platform_data = pdata;
desc.pdata = pdata;
- coresight_clear_self_claim_tag(&desc.access);
+ if (!tmc_has_qdcp(drvdata))
+ coresight_clear_self_claim_tag(&desc.access);
drvdata->csdev = coresight_register(&desc);
if (IS_ERR(drvdata->csdev)) {
ret = PTR_ERR(drvdata->csdev);
@@ -881,7 +937,7 @@ static int __tmc_probe(struct device *dev, struct resource *res)
}
out:
- if (is_tmc_crashdata_valid(drvdata) &&
+ if (!tmc_has_qdcp(drvdata) && is_tmc_crashdata_valid(drvdata) &&
!tmc_prepare_crashdata(drvdata))
register_crash_dev_interface(drvdata, desc.name);
return ret;
@@ -932,6 +988,16 @@ static void __tmc_remove(struct device *dev)
misc_deregister(&drvdata->miscdev);
if (drvdata->crashdev.fops)
misc_deregister(&drvdata->crashdev);
+
+ /*
+ * coresight_unregister() does not invoke sink_ops->disable(). An
+ * active QDCP-owned ETR must be stopped and have its firmware-DMA
+ * target quiesced explicitly, or QECP firmware can keep writing into
+ * the trace buffer after it is freed below.
+ */
+ if (tmc_has_qdcp(drvdata))
+ tmc_qdcp_etr_shutdown(drvdata);
+
coresight_unregister(drvdata->csdev);
}
@@ -1041,12 +1107,19 @@ static const struct acpi_device_id tmc_acpi_ids[] = {
MODULE_DEVICE_TABLE(acpi, tmc_acpi_ids);
#endif
+static const struct of_device_id tmc_platform_match[] = {
+ { .compatible = "qcom,coresight-tmc-qdcp" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, tmc_platform_match);
+
static struct platform_driver tmc_platform_driver = {
.probe = tmc_platform_probe,
.remove = tmc_platform_remove,
.driver = {
.name = "coresight-tmc-platform",
.acpi_match_table = ACPI_PTR(tmc_acpi_ids),
+ .of_match_table = tmc_platform_match,
.suppress_bind_attrs = true,
.pm = &tmc_dev_pm_ops,
},
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr-qdcp.c b/drivers/hwtracing/coresight/coresight-tmc-etr-qdcp.c
new file mode 100644
index 000000000000..db94bce76f15
--- /dev/null
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr-qdcp.c
@@ -0,0 +1,379 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * Support for QDCP firmware-owned TMC-ETR instances. The TMC control
+ * registers are owned by QECP firmware and are not accessible from the AP;
+ * Linux still allocates and owns the ETR trace buffer using the normal
+ * CoreSight sysfs buffer lifetime, handing the buffer address/size off to
+ * firmware over the Qualcomm Debug Control Protocol (QDCP).
+ */
+
+#include <linux/coresight.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/iommu.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/soc/qcom/qdcp.h>
+#include <linux/types.h>
+
+#include "coresight-priv.h"
+#include "coresight-tmc.h"
+
+static const struct attribute_group *coresight_qdcp_etr_groups[] = {
+ &coresight_etr_group,
+ &coresight_qdcp_tmc_group,
+ NULL,
+};
+
+static int tmc_qdcp_get_param(struct tmc_drvdata *drvdata,
+ enum qdcp_tmc_param param, u64 *value)
+{
+ return qdcp_tmc_get_param(drvdata->qdcp.provider,
+ drvdata->qdcp.id, param, value);
+}
+
+int tmc_qdcp_etr_probe_setup(struct device *dev, struct tmc_drvdata *drvdata,
+ u32 *devid)
+{
+ struct qdcp_data *qdcp;
+ u64 value;
+ int ret;
+
+ qdcp = devm_qdcp_get(dev, "qcom,qdcp");
+ if (IS_ERR(qdcp)) {
+ if (PTR_ERR(qdcp) == -EOPNOTSUPP)
+ dev_err(dev, "QDCP provider unavailable, is QCOM_QDCP a module while TMC is built in?\n");
+ else
+ dev_err(dev, "failed to get QDCP provider: %pe\n", qdcp);
+ return PTR_ERR(qdcp);
+ }
+
+ ret = fwnode_property_read_u64(dev->fwnode, "qcom,qdcp-tmc-id",
+ &drvdata->qdcp.id);
+ if (ret) {
+ dev_err(dev, "missing QDCP TMC id: %d\n", ret);
+ return ret;
+ }
+
+ drvdata->qdcp.provider = qdcp;
+ ret = tmc_qdcp_get_param(drvdata, QDCP_TMC_PARAM_DEVID,
+ &value);
+ if (ret) {
+ /*
+ * -EAGAIN means the QDCP QMI service has not registered yet;
+ * retry via probe deferral. Any other error, including
+ * -ENODEV from a dying provider, is a permanent failure.
+ */
+ if (ret == -EAGAIN)
+ ret = -EPROBE_DEFER;
+ else
+ dev_err(dev, "failed to read QDCP TMC DEVID: %d\n", ret);
+ return ret;
+ }
+
+ *devid = value;
+ return 0;
+}
+
+static int tmc_etr_qdcp_get_state(struct tmc_drvdata *drvdata, u64 *rrp,
+ u64 *rwp, u32 *status)
+{
+ u64 value;
+ int ret;
+
+ ret = tmc_qdcp_get_param(drvdata, QDCP_TMC_PARAM_RRP,
+ rrp);
+ if (ret)
+ goto err;
+
+ ret = tmc_qdcp_get_param(drvdata, QDCP_TMC_PARAM_RWP,
+ rwp);
+ if (ret)
+ goto err;
+
+ ret = tmc_qdcp_get_param(drvdata, QDCP_TMC_PARAM_STS,
+ &value);
+ if (ret)
+ goto err;
+
+ *status = value;
+ return 0;
+
+err:
+ /*
+ * tmc_sync_etr_buf() returns without syncing on error. Invalidate the
+ * buffer so a reused one doesn't present the previous capture as new.
+ */
+ dev_err(&drvdata->csdev->dev, "failed to read QDCP ETR state: %d\n", ret);
+ if (drvdata->etr_buf) {
+ drvdata->etr_buf->len = 0;
+ drvdata->etr_buf->full = false;
+ }
+ return ret;
+}
+
+static void tmc_etr_qdcp_get_buffer_addr(struct tmc_drvdata *drvdata,
+ struct etr_buf *etr_buf,
+ phys_addr_t *paddr, dma_addr_t *iaddr)
+{
+ struct device *real_dev = drvdata->csdev->dev.parent;
+ struct iommu_domain *domain = iommu_get_domain_for_dev(real_dev);
+
+ *iaddr = etr_buf->hwaddr;
+
+ /*
+ * etr_buf->hwaddr is the DMA address handed to the ETR/QECP AXI
+ * master. When an IOMMU sits on that path it is an IOVA rather than
+ * the CPU physical address, and QECP firmware needs the real
+ * physical address separately for its own bus/master view of memory.
+ * Without an IOMMU domain, the DMA address already is the physical
+ * address.
+ */
+ if (domain)
+ *paddr = iommu_iova_to_phys(domain, etr_buf->hwaddr);
+ else
+ *paddr = etr_buf->hwaddr;
+}
+
+static int tmc_etr_qdcp_enable_hw(struct tmc_drvdata *drvdata,
+ struct etr_buf *etr_buf)
+{
+ struct qdcp_tmc_cfg cfg = { 0 };
+ int ret;
+
+ if (WARN_ON(!etr_buf))
+ return -EINVAL;
+
+ if (etr_buf->mode == ETR_MODE_ETR_SG &&
+ WARN_ON(!tmc_etr_has_cap(drvdata, TMC_ETR_SG)))
+ return -EINVAL;
+
+ if (WARN_ON(drvdata->etr_buf))
+ return -EBUSY;
+
+ cfg.tmc_id = drvdata->qdcp.id;
+ tmc_etr_qdcp_get_buffer_addr(drvdata, etr_buf, &cfg.paddr, &cfg.iaddr);
+ cfg.size = etr_buf->size;
+ cfg.sg_mode = etr_buf->mode == ETR_MODE_ETR_SG;
+ cfg.ffcr = tmc_etr_default_ffcr(drvdata);
+
+ drvdata->etr_buf = etr_buf;
+ ret = qdcp_tmc_etr_enable(drvdata->qdcp.provider, &cfg);
+ /*
+ * A failed or timed-out request may still have been executed, so
+ * firmware may be writing into the buffer. Only release it once a
+ * stop is confirmed, else keep it pinned for a later retry.
+ */
+ if (ret && !qdcp_tmc_etr_disable(drvdata->qdcp.provider, drvdata->qdcp.id))
+ drvdata->etr_buf = NULL;
+ return ret;
+}
+
+/*
+ * drvdata->etr_buf is the buffer firmware may be writing into. It is only
+ * cleared once firmware has confirmed the stop, so a non-NULL etr_buf with the
+ * sink disabled means a stop is still pending and the buffer must not be freed
+ * or replaced.
+ */
+static int tmc_etr_qdcp_disable_hw(struct tmc_drvdata *drvdata)
+{
+ int ret;
+
+ if (!drvdata->etr_buf)
+ return 0;
+
+ ret = qdcp_tmc_etr_disable(drvdata->qdcp.provider, drvdata->qdcp.id);
+ if (ret) {
+ dev_err(&drvdata->csdev->dev,
+ "failed to stop QDCP ETR: %d\n", ret);
+ return ret;
+ }
+
+ tmc_etr_sync_sysfs_buf(drvdata);
+ drvdata->etr_buf = NULL;
+ return 0;
+}
+
+static int tmc_enable_etr_sink_sysfs_qdcp(struct coresight_device *csdev)
+{
+ struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
+ struct etr_buf *sysfs_buf;
+ int ret = 0;
+
+ /*
+ * tmc_etr_get_sysfs_buffer() takes drvdata->spinlock internally to
+ * read/install drvdata->sysfs_buf, but every other QDCP path
+ * (read_prepare/read_unprepare/disable) serializes that same field
+ * through drvdata->qdcp.lock instead. Call it with qdcp.lock already
+ * held so qdcp.lock is the single lock protocol for sysfs_buf/
+ * etr_buf/reading from the QDCP driver's point of view; spinlock
+ * nests safely inside the mutex.
+ */
+ mutex_lock(&drvdata->qdcp.lock);
+
+ /* Retry an unconfirmed stop before the buffer can be replaced. */
+ if (drvdata->etr_buf && coresight_get_mode(csdev) == CS_MODE_DISABLED) {
+ ret = tmc_etr_qdcp_disable_hw(drvdata);
+ if (ret) {
+ mutex_unlock(&drvdata->qdcp.lock);
+ return ret;
+ }
+ }
+
+ sysfs_buf = tmc_etr_get_sysfs_buffer(csdev);
+ if (IS_ERR(sysfs_buf)) {
+ mutex_unlock(&drvdata->qdcp.lock);
+ return PTR_ERR(sysfs_buf);
+ }
+
+ if (coresight_get_mode(csdev) == CS_MODE_SYSFS) {
+ csdev->refcnt++;
+ goto out;
+ }
+
+ if (coresight_get_mode(csdev) != CS_MODE_DISABLED) {
+ drvdata->sysfs_buf = NULL;
+ mutex_unlock(&drvdata->qdcp.lock);
+ tmc_etr_free_sysfs_buf(sysfs_buf);
+ return -EBUSY;
+ }
+
+ ret = tmc_etr_qdcp_enable_hw(drvdata, sysfs_buf);
+ if (!ret) {
+ coresight_set_mode(csdev, CS_MODE_SYSFS);
+ csdev->refcnt++;
+ }
+
+out:
+ mutex_unlock(&drvdata->qdcp.lock);
+ if (!ret)
+ dev_dbg(&csdev->dev, "TMC-ETR enabled\n");
+ return ret;
+}
+
+static int tmc_disable_etr_sink_qdcp(struct coresight_device *csdev)
+{
+ struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
+ int ret;
+
+ mutex_lock(&drvdata->qdcp.lock);
+ if (drvdata->reading) {
+ mutex_unlock(&drvdata->qdcp.lock);
+ return -EBUSY;
+ }
+
+ csdev->refcnt--;
+ if (csdev->refcnt) {
+ mutex_unlock(&drvdata->qdcp.lock);
+ return -EBUSY;
+ }
+
+ /*
+ * The core drops the path whatever is returned here, so nobody is left
+ * to retry. If the stop is not confirmed the buffer stays pinned and
+ * the next enable, read or removal retries it.
+ */
+ ret = tmc_etr_qdcp_disable_hw(drvdata);
+ drvdata->pid = -1;
+ coresight_set_mode(csdev, CS_MODE_DISABLED);
+ mutex_unlock(&drvdata->qdcp.lock);
+
+ if (!ret)
+ dev_dbg(&csdev->dev, "TMC-ETR disabled\n");
+ return ret;
+}
+
+void tmc_qdcp_etr_shutdown(struct tmc_drvdata *drvdata)
+{
+ mutex_lock(&drvdata->qdcp.lock);
+ if (tmc_etr_qdcp_disable_hw(drvdata))
+ dev_warn(&drvdata->csdev->dev,
+ "QDCP ETR did not stop, leaving trace buffer allocated\n");
+ coresight_set_mode(drvdata->csdev, CS_MODE_DISABLED);
+ mutex_unlock(&drvdata->qdcp.lock);
+}
+
+static int tmc_enable_qdcp_etr_sink(struct coresight_device *csdev,
+ enum cs_mode mode,
+ struct coresight_path *path)
+{
+ switch (mode) {
+ case CS_MODE_SYSFS:
+ return tmc_enable_etr_sink_sysfs_qdcp(csdev);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static const struct coresight_ops_sink tmc_qdcp_etr_sink_ops = {
+ .enable = tmc_enable_qdcp_etr_sink,
+ .disable = tmc_disable_etr_sink_qdcp,
+};
+
+static const struct coresight_ops tmc_qdcp_etr_cs_ops = {
+ .sink_ops = &tmc_qdcp_etr_sink_ops,
+};
+
+int tmc_qdcp_etr_sink_setup(struct device *dev, struct tmc_drvdata *drvdata,
+ u32 devid, struct coresight_desc *desc)
+{
+ desc->groups = coresight_qdcp_etr_groups;
+ desc->ops = &tmc_qdcp_etr_cs_ops;
+ drvdata->etr_get_state = tmc_etr_qdcp_get_state;
+
+ tmc_etr_init_caps(drvdata, 0);
+
+ return tmc_etr_setup_sg_and_dma_mask(dev, drvdata, devid);
+}
+
+int tmc_qdcp_etr_read_prepare(struct tmc_drvdata *drvdata)
+{
+ int ret = 0;
+
+ mutex_lock(&drvdata->qdcp.lock);
+ if (drvdata->reading) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ if (!drvdata->sysfs_buf) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ ret = tmc_etr_qdcp_disable_hw(drvdata);
+ if (ret)
+ goto out;
+
+ drvdata->reading = true;
+out:
+ mutex_unlock(&drvdata->qdcp.lock);
+ return ret;
+}
+
+int tmc_qdcp_etr_read_unprepare(struct tmc_drvdata *drvdata)
+{
+ struct etr_buf *sysfs_buf = NULL;
+ int ret = 0;
+
+ mutex_lock(&drvdata->qdcp.lock);
+ if (coresight_get_mode(drvdata->csdev) == CS_MODE_SYSFS) {
+ /*
+ * If firmware does not resume, stay in SYSFS mode: the core
+ * still holds its sink reference, and the final disable()
+ * drops it.
+ */
+ ret = tmc_etr_qdcp_enable_hw(drvdata, drvdata->sysfs_buf);
+ } else {
+ sysfs_buf = drvdata->sysfs_buf;
+ drvdata->sysfs_buf = NULL;
+ }
+ drvdata->reading = false;
+ mutex_unlock(&drvdata->qdcp.lock);
+
+ if (sysfs_buf)
+ tmc_etr_free_sysfs_buf(sysfs_buf);
+ return ret;
+}
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index 361a433e6f0c..c53a1ee8b1fd 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -911,7 +911,8 @@ static void get_etr_buf_hw(struct device *dev, struct etr_buf_hw *buf_hw)
buf_hw->has_iommu = iommu_get_domain_for_dev(dev->parent);
buf_hw->has_etr_sg = tmc_etr_has_cap(drvdata, TMC_ETR_SG);
- buf_hw->has_catu = !!tmc_etr_get_catu_device(drvdata);
+ buf_hw->has_catu = !tmc_has_qdcp(drvdata) &&
+ !!tmc_etr_get_catu_device(drvdata);
buf_hw->has_resrv = tmc_has_reserved_buffer(drvdata);
}
@@ -1019,6 +1020,15 @@ tmc_etr_buf_insert_barrier_packet(struct etr_buf *etr_buf, u64 offset)
return offset + CORESIGHT_BARRIER_PKT_SIZE;
}
+int tmc_etr_mmio_get_state(struct tmc_drvdata *drvdata, u64 *rrp,
+ u64 *rwp, u32 *status)
+{
+ *rrp = tmc_read_rrp(drvdata);
+ *rwp = tmc_read_rwp(drvdata);
+ *status = readl_relaxed(drvdata->base + TMC_STS);
+ return 0;
+}
+
/*
* tmc_sync_etr_buf: Sync the trace buffer availability with drvdata.
* Makes sure the trace data is synced to the memory for consumption.
@@ -1030,10 +1040,11 @@ static void tmc_sync_etr_buf(struct tmc_drvdata *drvdata)
struct etr_buf *etr_buf = drvdata->etr_buf;
u64 rrp, rwp;
u32 status;
+ int ret;
- rrp = tmc_read_rrp(drvdata);
- rwp = tmc_read_rwp(drvdata);
- status = readl_relaxed(drvdata->base + TMC_STS);
+ ret = drvdata->etr_get_state(drvdata, &rrp, &rwp, &status);
+ if (ret)
+ return;
/*
* If there were memory errors in the session, truncate the
@@ -1054,6 +1065,16 @@ static void tmc_sync_etr_buf(struct tmc_drvdata *drvdata)
etr_buf->ops->sync(etr_buf, rrp, rwp);
}
+u32 tmc_etr_default_ffcr(struct tmc_drvdata *drvdata)
+{
+ u32 ffcr = TMC_FFCR_EN_FMT | TMC_FFCR_EN_TI | TMC_FFCR_FON_FLIN |
+ TMC_FFCR_FON_TRIG_EVT | TMC_FFCR_TRIGON_TRIGIN;
+
+ if (drvdata->stop_on_flush)
+ ffcr |= TMC_FFCR_STOP_ON_FLUSH;
+ return ffcr;
+}
+
static int __tmc_etr_enable_hw(struct tmc_drvdata *drvdata)
{
u32 axictl, sts, ffcr;
@@ -1102,10 +1123,7 @@ static int __tmc_etr_enable_hw(struct tmc_drvdata *drvdata)
writel_relaxed(sts, drvdata->base + TMC_STS);
}
- ffcr = TMC_FFCR_EN_FMT | TMC_FFCR_EN_TI | TMC_FFCR_FON_FLIN |
- TMC_FFCR_FON_TRIG_EVT | TMC_FFCR_TRIGON_TRIGIN;
- if (drvdata->stop_on_flush)
- ffcr |= TMC_FFCR_STOP_ON_FLUSH;
+ ffcr = tmc_etr_default_ffcr(drvdata);
writel_relaxed(ffcr, drvdata->base + TMC_FFCR);
writel_relaxed(drvdata->trigger_cntr, drvdata->base + TMC_TRG);
@@ -1180,14 +1198,14 @@ tmc_etr_setup_sysfs_buf(struct tmc_drvdata *drvdata)
0, cpu_to_node(0), NULL);
}
-static void
+void
tmc_etr_free_sysfs_buf(struct etr_buf *buf)
{
if (buf)
tmc_free_etr_buf(buf);
}
-static void tmc_etr_sync_sysfs_buf(struct tmc_drvdata *drvdata)
+void tmc_etr_sync_sysfs_buf(struct tmc_drvdata *drvdata)
{
struct etr_buf *etr_buf = drvdata->etr_buf;
@@ -1232,7 +1250,7 @@ void tmc_etr_disable_hw(struct tmc_drvdata *drvdata)
drvdata->etr_buf = NULL;
}
-static struct etr_buf *tmc_etr_get_sysfs_buffer(struct coresight_device *csdev)
+struct etr_buf *tmc_etr_get_sysfs_buffer(struct coresight_device *csdev)
{
int ret = 0;
unsigned long flags;
@@ -1927,6 +1945,9 @@ int tmc_read_prepare_etr(struct tmc_drvdata *drvdata)
if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETR))
return -EINVAL;
+ if (tmc_has_qdcp(drvdata))
+ return tmc_qdcp_etr_read_prepare(drvdata);
+
raw_spin_lock_irqsave(&drvdata->spinlock, flags);
if (drvdata->reading) {
ret = -EBUSY;
@@ -1963,6 +1984,9 @@ int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata)
if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETR))
return -EINVAL;
+ if (tmc_has_qdcp(drvdata))
+ return tmc_qdcp_etr_read_unprepare(drvdata);
+
raw_spin_lock_irqsave(&drvdata->spinlock, flags);
/* RE-enable the TMC if need be */
diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
index 319a354ede9f..bb30957af1e3 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -13,6 +13,7 @@
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <linux/crc32.h>
+#include <linux/soc/qcom/qdcp.h>
#define TMC_RSZ 0x004
#define TMC_STS 0x00c
@@ -166,6 +167,18 @@ enum etr_mode {
};
struct etr_buf_operations;
+struct tmc_drvdata;
+
+/*
+ * tmc_etr_get_state_fn - read back {rrp, rwp, status} for an ETR sink.
+ * Resolved once at probe time to either the local-MMIO or QDCP firmware
+ * implementation, so tmc_sync_etr_buf() does not need to branch on
+ * tmc_has_qdcp() on every buffer sync. Returns 0 on success; the local-MMIO
+ * implementation always succeeds, the QDCP implementation may fail if the
+ * firmware transaction fails.
+ */
+typedef int (*tmc_etr_get_state_fn)(struct tmc_drvdata *drvdata, u64 *rrp,
+ u64 *rwp, u32 *status);
/**
* struct etr_buf - Details of the buffer used by ETR
@@ -245,6 +258,14 @@ struct tmc_resrv_buf {
* (after crash) by default.
* @crash_mdata: Reserved memory for storing tmc crash metadata.
* Used by ETR/ETF.
+ * @qdcp: QDCP connection state for firmware-owned ETR instances.
+ * @qdcp.id is the QDCP TMC identifier. @qdcp.lock does more than
+ * its name in struct qdcp_consumer suggests: QDCP enable/
+ * disable makes a sleeping firmware RPC, so it cannot share
+ * @spinlock, and instead serialises those calls together with
+ * the csdev->refcnt/mode transitions they guard.
+ * @etr_get_state: resolved at probe time to the local-MMIO or QDCP ETR
+ * {rrp, rwp, status} readback implementation.
*/
struct tmc_drvdata {
struct clk *atclk;
@@ -275,8 +296,15 @@ struct tmc_drvdata {
struct etr_buf *perf_buf;
struct tmc_resrv_buf resrv_buf;
struct tmc_resrv_buf crash_mdata;
+ struct qdcp_consumer qdcp;
+ tmc_etr_get_state_fn etr_get_state;
};
+static inline bool tmc_has_qdcp(struct tmc_drvdata *drvdata)
+{
+ return !!drvdata->qdcp.provider;
+}
+
struct etr_buf_operations {
int (*alloc)(struct tmc_drvdata *drvdata, struct etr_buf *etr_buf,
int node, void **pages);
@@ -339,9 +367,27 @@ int tmc_read_prepare_etr(struct tmc_drvdata *drvdata);
int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata);
void tmc_etr_disable_hw(struct tmc_drvdata *drvdata);
extern const struct coresight_ops tmc_etr_cs_ops;
+int tmc_etr_mmio_get_state(struct tmc_drvdata *drvdata, u64 *rrp, u64 *rwp,
+ u32 *status);
ssize_t tmc_etr_get_sysfs_trace(struct tmc_drvdata *drvdata,
loff_t pos, size_t len, char **bufpp);
+struct etr_buf *tmc_etr_get_sysfs_buffer(struct coresight_device *csdev);
+void tmc_etr_free_sysfs_buf(struct etr_buf *buf);
+void tmc_etr_sync_sysfs_buf(struct tmc_drvdata *drvdata);
+u32 tmc_etr_default_ffcr(struct tmc_drvdata *drvdata);
+int tmc_etr_setup_sg_and_dma_mask(struct device *dev,
+ struct tmc_drvdata *drvdata, u32 devid);
+extern const struct attribute_group coresight_tmc_group;
+extern const struct attribute_group coresight_qdcp_tmc_group;
+/* QDCP-owned ETR functions, see coresight-tmc-etr-qdcp.c */
+int tmc_qdcp_etr_probe_setup(struct device *dev, struct tmc_drvdata *drvdata,
+ u32 *devid);
+int tmc_qdcp_etr_sink_setup(struct device *dev, struct tmc_drvdata *drvdata,
+ u32 devid, struct coresight_desc *desc);
+int tmc_qdcp_etr_read_prepare(struct tmc_drvdata *drvdata);
+int tmc_qdcp_etr_read_unprepare(struct tmc_drvdata *drvdata);
+void tmc_qdcp_etr_shutdown(struct tmc_drvdata *drvdata);
#define TMC_REG_PAIR(name, lo_off, hi_off) \
static inline u64 \
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
@ 2026-11-19 9:12 ` sashiko-bot
2026-11-19 14:00 ` Krzysztof Kozlowski
1 sibling, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-19 9:12 UTC (permalink / raw)
To: Jie Gan; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] dt-bindings: soc: qcom: qcom,qdcp models virtual QMI driver
and lookup IDs
- [Low] dt-bindings: soc: qcom: unused labels in qcom,qdcp example fail
style check
--
commit 975ed970c6f545b1a481d1850cc2e7de01d28cd7
Author: Jie Gan <jie.gan@oss.qualcomm.com>
dt-bindings: soc: qcom: add QDCP provider
This commit adds a Devicetree binding schema for the Qualcomm Debug Control
Protocol (QDCP) firmware provider node and its QMI connection child nodes.
> diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml b/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml
> new file mode 100644
> index 0000000000000..ee0a66b12dde7
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml
> @@ -0,0 +1,81 @@
[ ... ]
> + This node does not represent a CoreSight graph device. It is a platform
> + driver that establishes the QMI connections used by consumer drivers such
> + as the Qualcomm QDCP STM source and QDCP-backed TMC/ETR sink.
> +
> + QECP exposes more than one independent QMI service (for example, a
> + separate service used by remote ETM/diag sources). Each QMI connection is
> + described as a child node of the "qcom,qdcp" node rather than as a
> + property of the node itself, so a single provider device can establish
> + more than one connection. A node without any "connection-N" child is valid
> + but provides nothing for consumers to reference.
> +
> +properties:
> + compatible:
> + const: qcom,qdcp
> +
> +patternProperties:
> + "^connection-[0-9]+$":
> + type: object
> + description:
> + A single QMI connection established by the QDCP provider. Consumers
> + reference this child node directly via their "qcom,qdcp" phandle, not
> + the top-level provider node.
> +
> + properties:
> + qcom,service-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + QMI service identifier for this connection.
> +
> + qcom,version:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + default: 1
> + description:
> + QMI service version for this connection.
> +
> + qcom,instance-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + QMI instance identifier for this connection.
[Severity: Medium]
Does this binding model a virtual Linux platform driver and its QMI lookup
parameters rather than hardware?
The top-level qcom,qdcp node has no hardware resources or SoC-specific
compatible string, and its resource-less connection-N child nodes exist only
to pass qcom,service-id, qcom,version and qcom,instance-id into the driver's
qmi_add_lookup() call, encoding driver implementation details in the
Devicetree ABI instead of keeping QMI service constants in driver match data
or passing provider arguments via phandle cells.
[ ... ]
> +examples:
> + - |
> + qdcp: qdcp {
> + compatible = "qcom,qdcp";
> +
> + qdcp_coresight: connection-0 {
> + qcom,service-id = <0x453>;
> + qcom,instance-id = <32>;
> + };
> + };
[Severity: Low]
Should the unreferenced qdcp and qdcp_coresight labels be dropped from the
example? Neither label is referenced in the example, which causes
scripts/dtc/dt-check-style --mode=strict to report unused-labels warnings.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider
2026-11-19 9:01 ` [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider Jie Gan
@ 2026-11-19 9:18 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-19 9:18 UTC (permalink / raw)
To: Jie Gan; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] soc: qcom: qdcp_send_resp() callers pass struct size as QMI
wire length
- [Medium] soc: qcom: devm_qdcp_get() races with provider unbind after
unlock
--
commit 0767c9931547d43da1782dd32902fb9f2ad363f7
Author: Jie Gan <jie.gan@oss.qualcomm.com>
soc: qcom: add QDCP firmware provider
This commit adds a QMI service provider driver for the Qualcomm Debug
Control Protocol (QDCP) so consumer drivers can enable, disable, and
query QECP firmware-owned debug and trace blocks.
> diff --git a/drivers/soc/qcom/qcom_qdcp.c b/drivers/soc/qcom/qcom_qdcp.c
> new file mode 100644
> index 0000000000000..295138b298819
> --- /dev/null
> +++ b/drivers/soc/qcom/qcom_qdcp.c
> @@ -0,0 +1,985 @@
[ ... ]
> +static int qdcp_send_resp(struct qdcp_data *qdcp, unsigned int msg_id,
> + const struct qmi_elem_info *req_ei, const void *req,
> + size_t req_len, const struct qmi_elem_info *resp_ei,
> + void *resp, size_t resp_len)
> +{
[ ... ]
> + ret = qmi_send_request(&qdcp->qmi, &sq, &txn, msg_id, req_len, req_ei,
> + req);
> + if (ret < 0) {
> + qmi_txn_cancel(&txn);
> + return ret;
> + }
> +
> + ret = qmi_txn_wait(&txn, msecs_to_jiffies(QDCP_TIMEOUT_MS));
> + if (ret < 0)
> + return ret;
> +
> + return qdcp_check_resp(qdcp, qmi_resp);
> +}
> +
> +static int qdcp_send(struct qdcp_data *qdcp, unsigned int msg_id,
> + const struct qmi_elem_info *req_ei, const void *req,
> + size_t req_len, struct qdcp_resp_v01 *resp)
> +{
> + return qdcp_send_resp(qdcp, msg_id, req_ei, req, req_len, qdcp_resp_ei,
> + resp, sizeof(*resp));
> +}
> +
> +static int qdcp_set_state(struct qdcp_data *qdcp, unsigned int msg_id,
> + u64 id, bool enable)
> +{
> + struct qdcp_state_req_v01 req = {
> + .id = id,
> + .state = enable,
> + };
> + struct qdcp_resp_v01 resp;
> +
> + return qdcp_send(qdcp, msg_id, qdcp_state_req_ei, &req, sizeof(req),
> + &resp);
> +}
[Severity: High]
Does passing sizeof(req) as req_len cause qmi_send_request() to fail with
-ETOOSMALL across all QDCP requests?
qmi_send_request() passes req_len to qmi_encode_message() as the maximum
encoded wire payload length, and each top-level TLV adds a 3-byte TLV
header (1-byte type + 2-byte length) to the field payload. For example,
struct qdcp_state_req_v01 is 16 bytes, whereas qdcp_state_req_ei encodes
two top-level TLVs totaling (3 + 8) + (3 + 4) = 18 bytes. Because
qdcp_set_state(), qdcp_stm_source_enable(), qdcp_tmc_set_param(),
qdcp_tmc_get_param(), and qdcp_tmc_assign_buffer() all pass sizeof(req),
every exported QDCP operation fails in qmi_encode() with -ETOOSMALL.
> +struct qdcp_devres {
> + struct qdcp_data *qdcp;
> +};
> +
> +static void qdcp_release_provider(void *data)
> +{
> + struct qdcp_devres *devres = data;
> +
> + put_device(devres->qdcp->dev);
> + kref_put(&devres->qdcp->ref, qdcp_release);
> +}
> +
> +struct qdcp_data *devm_qdcp_get(struct device *dev, const char *phandle_name)
> +{
> + struct qdcp_devres *devres;
> + struct device_link *link;
> + struct qdcp_data *qdcp;
> + struct device_node *np;
> + int ret;
> +
> + if (!dev->of_node)
> + return ERR_PTR(-ENOENT);
> +
> + np = of_parse_phandle(dev->of_node, phandle_name, 0);
> + if (!np)
> + return ERR_PTR(-ENOENT);
> +
> + mutex_lock(&qdcp_providers_lock);
> + list_for_each_entry(qdcp, &qdcp_providers, node) {
> + if (qdcp->of_node != np || qdcp->dying)
> + continue;
> +
> + if (!kref_get_unless_zero(&qdcp->ref))
> + continue;
> +
> + get_device(qdcp->dev);
> + mutex_unlock(&qdcp_providers_lock);
> + of_node_put(np);
> +
> + /*
> + * A managed link with DL_FLAG_AUTOREMOVE_CONSUMER (i.e. no
> + * DL_FLAG_STATELESS) is required so that the driver core's
> + * device_links_busy()/device_links_unbind_consumers()
> + * machinery forces this consumer to unbind before
> + * qdcp_remove() can proceed on the supplier, and so the link
> + * itself is dropped automatically by the core when this
> + * consumer unbinds or fails to probe. A stateless link
> + * carries neither guarantee: qdcp_remove() could release the
> + * QMI handle while a consumer still has outstanding or
> + * in-flight QDCP RPCs, and device_link_del() refuses to drop
> + * a non-stateless link while the consumer is still
> + * registered, which is always the case from inside a devm
> + * release callback.
> + */
> + link = device_link_add(dev, qdcp->dev,
> + DL_FLAG_AUTOREMOVE_CONSUMER);
> + if (!link) {
> + put_device(qdcp->dev);
> + kref_put(&qdcp->ref, qdcp_release);
> + return ERR_PTR(-EINVAL);
> + }
> +
> + /*
> + * The core still creates a link to a supplier that is already
> + * unbinding, and will not unbind this consumer for it. Defer
> + * rather than bind to a provider that is going away.
> + */
> + if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND) {
> + put_device(qdcp->dev);
> + kref_put(&qdcp->ref, qdcp_release);
> + return ERR_PTR(-EPROBE_DEFER);
> + }
[Severity: Medium]
Can devm_qdcp_get() still race with provider unbind after dropping
qdcp_providers_lock?
CPU0 CPU1
devm_qdcp_get()
mutex_lock(&qdcp_providers_lock)
/* finds qdcp, !qdcp->dying */
mutex_unlock(&qdcp_providers_lock)
__device_release_driver(qdcp->dev)
qdcp_remove()
qdcp->dying = true
qmi_handle_release(&qdcp->qmi)
device_links_driver_cleanup()
supplier->links.status =
DL_DEV_NO_DRIVER
device_link_add(dev, qdcp->dev,
DL_FLAG_AUTOREMOVE_CONSUMER)
/* link->status = DL_STATE_DORMANT */
if (link->status ==
DL_STATE_SUPPLIER_UNBIND)
/* false, returns dead qdcp */
...
device_links_driver_bound()
WARN_ON(link->status !=
DL_STATE_CONSUMER_PROBE) <-- warning & bound to dead provider
If the supplier finishes unbinding in the window between dropping
qdcp_providers_lock and calling device_link_add(), supplier->links.status
is already DL_DEV_NO_DRIVER, so device_link_init_status() initializes
link->status to DL_STATE_DORMANT rather than DL_STATE_SUPPLIER_UNBIND.
devm_qdcp_get() then succeeds on a provider whose QMI handle was released
and triggers WARN_ON(link->status != DL_STATE_CONSUMER_PROBE) in
device_links_driver_bound().
Even when device_link_add() runs while the supplier is still in
DL_DEV_UNBINDING (setting link->status to DL_STATE_SUPPLIER_UNBIND), the
new DL_FLAG_AUTOREMOVE_CONSUMER link stays on supplier->links.consumers
until the consumer's probe failure path runs device_links_no_driver(), so
device_links_driver_cleanup() on the supplier can win the race and hit
WARN_ON(device_link_test(link, DL_FLAG_AUTOREMOVE_CONSUMER)).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support
2026-11-19 9:01 ` [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support Jie Gan
@ 2026-11-19 9:25 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-19 9:25 UTC (permalink / raw)
To: Jie Gan; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] coresight: tmc: refcnt leak and stray DMA resume in
tmc_disable_etr_sink_qdcp()
- [High] coresight: tmc: bogus sync and OOB offset in
tmc_etr_qdcp_disable_hw()
- [Medium] coresight: tmc: leak of sysfs_buf in tmc_qdcp_etr_shutdown()
on removal
- [Medium] coresight: tmc: stale buffer metadata left by
tmc_etr_qdcp_enable_hw()
--
commit 4c2126e70bf6a901c5097e6430bf243717b9f97e
Author: Jie Gan <jie.gan@oss.qualcomm.com>
coresight: tmc: add QDCP ETR sysfs support
This commit adds sysfs sink support for CoreSight TMC-ETR instances whose
control registers are managed by the Qualcomm Embedded Co-Processor
(QECP) over the Qualcomm Debug Control Protocol (QDCP).
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr-qdcp.c b/drivers/hwtracing/coresight/coresight-tmc-etr-qdcp.c
> new file mode 100644
> index 0000000000000..db94bce76f15c
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr-qdcp.c
[ ... ]
> +static int tmc_etr_qdcp_enable_hw(struct tmc_drvdata *drvdata,
> + struct etr_buf *etr_buf)
> +{
> + struct qdcp_tmc_cfg cfg = { 0 };
> + int ret;
> +
> + if (WARN_ON(!etr_buf))
> + return -EINVAL;
> +
> + if (etr_buf->mode == ETR_MODE_ETR_SG &&
> + WARN_ON(!tmc_etr_has_cap(drvdata, TMC_ETR_SG)))
> + return -EINVAL;
> +
> + if (WARN_ON(drvdata->etr_buf))
> + return -EBUSY;
> +
> + cfg.tmc_id = drvdata->qdcp.id;
> + tmc_etr_qdcp_get_buffer_addr(drvdata, etr_buf, &cfg.paddr, &cfg.iaddr);
> + cfg.size = etr_buf->size;
> + cfg.sg_mode = etr_buf->mode == ETR_MODE_ETR_SG;
> + cfg.ffcr = tmc_etr_default_ffcr(drvdata);
> +
> + drvdata->etr_buf = etr_buf;
> + ret = qdcp_tmc_etr_enable(drvdata->qdcp.provider, &cfg);
> + /*
> + * A failed or timed-out request may still have been executed, so
> + * firmware may be writing into the buffer. Only release it once a
> + * stop is confirmed, else keep it pinned for a later retry.
> + */
> + if (ret && !qdcp_tmc_etr_disable(drvdata->qdcp.provider, drvdata->qdcp.id))
> + drvdata->etr_buf = NULL;
> + return ret;
> +}
[Severity: Medium]
If qdcp_tmc_etr_enable() fails on a reused drvdata->sysfs_buf (for
instance when tmc_qdcp_etr_read_unprepare() resumes an active session)
and the recovery qdcp_tmc_etr_disable() succeeds, does clearing
drvdata->etr_buf leave stale etr_buf->len and etr_buf->full values from
the previous capture?
With drvdata->etr_buf set to NULL, a subsequent tmc_etr_qdcp_disable_hw()
returns 0 immediately without syncing or invalidating the buffer, so the
next read exposes the old len and offset over a failed or partially
overwritten buffer.
> +
> +/*
> + * drvdata->etr_buf is the buffer firmware may be writing into. It is only
> + * cleared once firmware has confirmed the stop, so a non-NULL etr_buf with the
> + * sink disabled means a stop is still pending and the buffer must not be freed
> + * or replaced.
> + */
> +static int tmc_etr_qdcp_disable_hw(struct tmc_drvdata *drvdata)
> +{
> + int ret;
> +
> + if (!drvdata->etr_buf)
> + return 0;
> +
> + ret = qdcp_tmc_etr_disable(drvdata->qdcp.provider, drvdata->qdcp.id);
> + if (ret) {
> + dev_err(&drvdata->csdev->dev,
> + "failed to stop QDCP ETR: %d\n", ret);
> + return ret;
> + }
> +
> + tmc_etr_sync_sysfs_buf(drvdata);
> + drvdata->etr_buf = NULL;
> + return 0;
> +}
[Severity: High]
Can tmc_etr_sync_sysfs_buf() compute an out-of-bounds etr_buf->offset
when tmc_etr_qdcp_disable_hw() retries a stop after a failed enable?
If qdcp_tmc_etr_enable() failed before assigning the buffer to firmware
and the immediate recovery disable also failed, drvdata->etr_buf stays
set while csdev remains in CS_MODE_DISABLED. When a later
tmc_etr_qdcp_disable_hw() succeeds, it still calls
tmc_etr_sync_sysfs_buf() (unlike __tmc_etr_disable_hw(), which only syncs
when mode == CS_MODE_SYSFS), reading RRP and RWP values from firmware
that are 0 or from an earlier buffer.
Neither tmc_etr_qdcp_get_state() nor tmc_etr_sync_flat_buf() checks that
rrp and rwp lie within [etr_buf->hwaddr, etr_buf->hwaddr + etr_buf->size):
drivers/hwtracing/coresight/coresight-tmc-etr.c:tmc_etr_sync_flat_buf() {
etr_buf->offset = rrp - etr_buf->hwaddr;
if (etr_buf->full)
etr_buf->len = etr_buf->size;
else
etr_buf->len = rwp - rrp;
...
}
An out-of-bounds offset underflows etr_buf->size - offset in
tmc_etr_buf_get_data(), causing tmc_etr_buf_insert_barrier_packet() or
tmc_read() to write or read past flat_buf->vaddr.
[ ... ]
> +static int tmc_disable_etr_sink_qdcp(struct coresight_device *csdev)
> +{
> + struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
> + int ret;
> +
> + mutex_lock(&drvdata->qdcp.lock);
> + if (drvdata->reading) {
> + mutex_unlock(&drvdata->qdcp.lock);
> + return -EBUSY;
> + }
> +
> + csdev->refcnt--;
> + if (csdev->refcnt) {
> + mutex_unlock(&drvdata->qdcp.lock);
> + return -EBUSY;
> + }
> +
> + /*
> + * The core drops the path whatever is returned here, so nobody is left
> + * to retry. If the stop is not confirmed the buffer stays pinned and
> + * the next enable, read or removal retries it.
> + */
> + ret = tmc_etr_qdcp_disable_hw(drvdata);
> + drvdata->pid = -1;
> + coresight_set_mode(csdev, CS_MODE_DISABLED);
> + mutex_unlock(&drvdata->qdcp.lock);
> +
> + if (!ret)
> + dev_dbg(&csdev->dev, "TMC-ETR disabled\n");
> + return ret;
> +}
[Severity: High]
What happens if a sysfs trace source is disabled while /dev/tmc_etrX is
open for reading (drvdata->reading is true)?
coresight_disable_sink() ignores the return value of sink_ops->disable()
and coresight_disable_sysfs() proceeds to tear down the path. Returning
-EBUSY early here leaves csdev->refcnt elevated and csdev->mode set to
CS_MODE_SYSFS, so when the reader closes /dev/tmc_etrX,
tmc_qdcp_etr_read_unprepare() sees CS_MODE_SYSFS and calls
tmc_etr_qdcp_enable_hw() to restart firmware DMA with no active trace
path instead of freeing drvdata->sysfs_buf.
> +
> +void tmc_qdcp_etr_shutdown(struct tmc_drvdata *drvdata)
> +{
> + mutex_lock(&drvdata->qdcp.lock);
> + if (tmc_etr_qdcp_disable_hw(drvdata))
> + dev_warn(&drvdata->csdev->dev,
> + "QDCP ETR did not stop, leaving trace buffer allocated\n");
> + coresight_set_mode(drvdata->csdev, CS_MODE_DISABLED);
> + mutex_unlock(&drvdata->qdcp.lock);
> +}
[Severity: Medium]
Does tmc_qdcp_etr_shutdown() leak drvdata->sysfs_buf when
tmc_etr_qdcp_disable_hw() succeeds?
tmc_etr_qdcp_disable_hw() only syncs the buffer and clears
drvdata->etr_buf. Because __tmc_remove() has already deregistered
drvdata->miscdev, nothing else will free drvdata->sysfs_buf after
tmc_qdcp_etr_shutdown() returns.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com?part=6
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFC 4/6] coresight: qcom: add QDCP STM source
2026-11-19 9:01 ` [PATCH RFC 4/6] coresight: " Jie Gan
@ 2026-11-19 9:28 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-19 9:28 UTC (permalink / raw)
To: Jie Gan; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] coresight: qcom: path and refcount leak in qdcp_stm_remove()
- [Medium] coresight: qcom: sysfs enable_source race in
qdcp_stm_remove()
- [Medium] coresight: qcom: premature CS_MODE_SYSFS transition in
qdcp_stm_enable()
- [Medium] coresight: qcom-qdcp-stm: UAF of drvdata and csdev after
qdcp_stm_remove()
--
commit 70d23454ea311ef6b9bc809416627572cf195a8d
Author: Jie Gan <jie.gan@oss.qualcomm.com>
coresight: qcom: add QDCP STM source
This commit adds a Qualcomm CoreSight STM source driver that maps the
AP-visible stimulus aperture and delegates STM enable and disable
operations to QECP firmware via QDCP.
> diff --git a/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c b/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c
> new file mode 100644
> index 0000000000000..39c6a2798a0f9
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c
> @@ -0,0 +1,550 @@
[ ... ]
> +static int qdcp_stm_enable(struct coresight_device *csdev,
> + struct perf_event *event, enum cs_mode mode,
> + struct coresight_path *path)
> +{
> + struct qcom_qdcp_stm_drvdata *drvdata;
> + int ret;
> +
> + if (mode != CS_MODE_SYSFS)
> + return -EINVAL;
> +
> + if (!coresight_take_mode(csdev, mode))
> + return -EBUSY;
> +
> + drvdata = dev_get_drvdata(csdev->dev.parent);
> +
> + mutex_lock(&drvdata->qdcp.lock);
> + ret = qdcp_stm_source_enable(drvdata->qdcp.provider, drvdata->qdcp.id,
> + drvdata->traceid, drvdata->port_mask,
> + false);
> + if (!ret)
> + drvdata->fw_stop_failed = false;
> + mutex_unlock(&drvdata->qdcp.lock);
> + if (ret) {
> + coresight_set_mode(csdev, CS_MODE_DISABLED);
> + return ret;
> + }
> +
> + dev_dbg(&csdev->dev, "QDCP STM tracing enabled\n");
> + return 0;
> +}
> +
> +/*
> + * The CoreSight source disable op returns void and the user has already torn
> + * the path down, so the source always ends up disabled from Linux's point of
> + * view. Return the firmware result so the caller can at least report it.
> + */
> +static int qdcp_stm_disable_source(struct coresight_device *csdev)
> +{
> + struct qcom_qdcp_stm_drvdata *drvdata;
> + struct qdcp_data *qdcp;
> + u64 source_id;
> + u8 traceid;
> + int ret;
> +
> + if (coresight_get_mode(csdev) != CS_MODE_SYSFS)
> + return 0;
> +
> + drvdata = dev_get_drvdata(csdev->dev.parent);
> + qdcp = drvdata->qdcp.provider;
> + source_id = drvdata->qdcp.id;
> + traceid = drvdata->traceid;
> +
> + mutex_lock(&drvdata->qdcp.lock);
> + ret = qdcp_stm_source_disable(qdcp, source_id, traceid, false);
> + drvdata->fw_stop_failed = !!ret;
> + mutex_unlock(&drvdata->qdcp.lock);
> +
> + coresight_set_mode(csdev, CS_MODE_DISABLED);
> + dev_dbg(&csdev->dev, "QDCP STM tracing disabled\n");
> + return ret;
> +}
[Severity: Medium]
Can qdcp_stm_packet() write to drvdata->stimulus_base while the STM block
is still unclocked or disabled by firmware?
qdcp_stm_packet() is lockless and checks only coresight_get_mode(csdev)
before performing MMIO writes to drvdata->stimulus_base. Unlike
coresight-stm, QECP firmware controls the block's clocks and power over
sleeping QMI calls:
CPU0 CPU1
qdcp_stm_enable()
coresight_take_mode(...,
CS_MODE_SYSFS)
qdcp_stm_source_enable()
/* sleeping QMI RPC */
qdcp_stm_packet()
coresight_get_mode() == CS_MODE_SYSFS
qdcp_stm_send(channel_addr, ...)
<-- MMIO write before firmware
enables STM clocks/power
The same window exists in qdcp_stm_disable_source(), where csdev->mode
remains CS_MODE_SYSFS until after qdcp_stm_source_disable() completes.
On Qualcomm SoCs, MMIO accesses to an unclocked CoreSight aperture can
cause a synchronous external abort or bus hang.
[ ... ]
> +static void qdcp_stm_remove(struct platform_device *pdev)
> +{
> + struct qcom_qdcp_stm_drvdata *drvdata = platform_get_drvdata(pdev);
> +
> + /*
> + * Unregister the STM first: its unlink callback disables the source
> + * through drvdata->csdev, which must still be live.
> + */
> + stm_unregister_device(&drvdata->stm);
[Severity: Medium]
Can closing an open /dev/qdcp_stmN file descriptor after qdcp_stm_remove()
cause a use-after-free on drvdata and drvdata->csdev?
Unbinding the qcom-qdcp supplier triggers qdcp_stm_remove() via the
DL_FLAG_AUTOREMOVE_CONSUMER device link created by devm_qdcp_get().
stm_unregister_device() only unlinks in-kernel stm_source devices on
stm->link_list; any open userspace struct stm_file still holds stmf->stm
with stm->data pointing to &drvdata->stm:
drivers/hwtracing/stm/core.c:stm_char_release() {
struct stm_file *stmf = file->private_data;
struct stm_device *stm = stmf->stm;
if (stm->data->unlink)
stm->data->unlink(stm->data, stmf->output.master,
stmf->output.channel);
...
}
After qdcp_stm_remove() unregisters drvdata->csdev and devres frees
drvdata, closing the open file descriptor calls qdcp_stm_unlink() ->
coresight_disable_sysfs(drvdata->csdev) on freed memory.
> +
> + /*
> + * No-op unless the source is still in CS_MODE_SYSFS. Without it,
> + * removing an enabled source would leave firmware STM enabled.
> + */
> + qdcp_stm_disable_source(drvdata->csdev);
[Severity: Medium]
Does calling qdcp_stm_disable_source() here instead of
coresight_disable_sysfs() leak csdev->path and leave downstream CoreSight
components enabled?
When the source is enabled in CS_MODE_SYSFS (for example via the sysfs
enable_source attribute), coresight_enable_sysfs() builds csdev->path,
enables the sink and links, and takes device, module, and runtime PM
references on every component in the path via coresight_grab_device().
Calling qdcp_stm_disable_source() directly only disables the source in
firmware and sets csdev->mode to CS_MODE_DISABLED without calling
coresight_disable_path() or coresight_release_path_locked(), leaking the
path and the get_device(&csdev->dev) reference on drvdata->csdev itself.
> +
> + /*
> + * A stop that failed here or earlier (fw_stop_failed) means firmware
> + * may still be tagging trace with this ID. Keep it allocated rather
> + * than let another source reuse it.
> + */
> + if (drvdata->fw_stop_failed)
> + dev_warn(&pdev->dev,
> + "QDCP STM not confirmed stopped, leaking trace ID %u\n",
> + drvdata->traceid);
> + else
> + coresight_trace_id_put_system_id(drvdata->traceid);
> +
> + coresight_unregister(drvdata->csdev);
> +}
[Severity: Medium]
What prevents sysfs enable_source_store() from racing with
qdcp_stm_remove() before coresight_unregister() removes the sysfs
attribute?
Because coresight_unregister() runs last and qdcp_stm_remove() does not
hold coresight_mutex, enable_source Remains accessible while
qdcp_stm_remove() disables the source and releases drvdata->traceid:
CPU0 CPU1
qdcp_stm_remove()
qdcp_stm_disable_source()
enable_source_store()
coresight_enable_sysfs()
qdcp_stm_enable()
qdcp_stm_source_enable(...,
drvdata->traceid, ...)
drvdata->fw_stop_failed = false
if (drvdata->fw_stop_failed)
else
coresight_trace_id_put_system_id(
drvdata->traceid)
<-- trace ID freed while
firmware is enabled
coresight_unregister(csdev)
Unregistering drvdata->csdev before releasing drvdata->traceid (or
tearing down the sysfs session under coresight_mutex during
unregister) would close this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
2026-11-19 9:12 ` sashiko-bot
@ 2026-11-19 14:00 ` Krzysztof Kozlowski
1 sibling, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-19 14:00 UTC (permalink / raw)
To: Jie Gan, Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32
On 19/11/2026 10:01, Jie Gan wrote:
> Document the Qualcomm Debug Control Protocol (QDCP) firmware provider
> node used by CoreSight debug and trace blocks that are owned by the
> Qualcomm Embedded Co-Processor (QECP), a separate on-die processor that
> runs its own firmware. QDCP is the QMI (Qualcomm MSM Interface) service,
> carried over QRTR (Qualcomm IPC Router), that Linux uses to ask QECP
> firmware to control those blocks.
>
> The provider is a Qualcomm platform/QMI service node, not a CoreSight
> graph device. It exposes the qcom,qdcp compatible along with
> per-connection QMI service/instance identifiers; the QMI service
> version is the only optional identifier, defaulting to 1.
>
> Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
> ---
> .../devicetree/bindings/soc/qcom/qcom,qdcp.yaml | 81 ++++++++++++++++++++++
> 1 file changed, 81 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml b/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml
> new file mode 100644
> index 000000000000..ee0a66b12dde
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/qcom/qcom,qdcp.yaml
> @@ -0,0 +1,81 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/soc/qcom/qcom,qdcp.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Qualcomm Debug Control Protocol (QDCP) provider
> +
> +maintainers:
> + - Jie Gan <jie.gan@oss.qualcomm.com>
> +
> +description: |
> + QDCP is a QMI-based firmware provider used to control CoreSight trace
> + blocks that are owned by the Qualcomm Embedded Co-Processor (QECP) rather
> + than the application processor (AP). CoreSight-facing consumers look up
> + the provider through a "qcom,qdcp" phandle, naming a specific
> + "connection-N" child node rather than the top-level provider node, and
> + issue typed firmware requests instead of programming registers directly.
> +
> + This node does not represent a CoreSight graph device. It is a platform
> + driver that establishes the QMI connections used by consumer drivers such
> + as the Qualcomm QDCP STM source and QDCP-backed TMC/ETR sink.
> +
> + QECP exposes more than one independent QMI service (for example, a
> + separate service used by remote ETM/diag sources). Each QMI connection is
> + described as a child node of the "qcom,qdcp" node rather than as a
> + property of the node itself, so a single provider device can establish
> + more than one connection. A node without any "connection-N" child is valid
> + but provides nothing for consumers to reference.
> +
> +properties:
> + compatible:
> + const: qcom,qdcp
Standard comment - compatibles are not supposed to be generic. That's
why you have entire commit msg to explain any oddities or deviations
from common rules.
No resources here, so this does not look like separate device.
> +
> +patternProperties:
> + "^connection-[0-9]+$":
> + type: object
> + description:
> + A single QMI connection established by the QDCP provider. Consumers
> + reference this child node directly via their "qcom,qdcp" phandle, not
> + the top-level provider node.
> +
> + properties:
> + qcom,service-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + QMI service identifier for this connection.
> +
> + qcom,version:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + default: 1
> + description:
> + QMI service version for this connection.
> +
> + qcom,instance-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + QMI instance identifier for this connection.
> +
Please don't describe firmware contents as random integers in DT.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source
2026-11-19 9:01 ` [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source Jie Gan
@ 2026-11-19 14:02 ` Krzysztof Kozlowski
0 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-19 14:02 UTC (permalink / raw)
To: Jie Gan, Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Suzuki K Poulose, Mike Leach,
James Clark, Leo Yan, Tingwei Zhang, Maxime Coquelin,
Alexandre Torgue, Alexander Shishkin
Cc: linux-arm-msm, devicetree, linux-kernel, coresight,
linux-arm-kernel, linux-stm32
On 19/11/2026 10:01, Jie Gan wrote:
> Document the Qualcomm QDCP-backed CoreSight STM (System Trace Macrocell)
> source, for platforms where the STM control registers are owned by
> Qualcomm Embedded Co-Processor (QECP) firmware instead of the
> application processor (AP).
>
> The node describes only the STM stimulus aperture, the MMIO region the
> AP writes trace data to. Firmware controls the STM through the Qualcomm
> Debug Control Protocol (QDCP) provider referenced by the qcom,qdcp
> phandle. Firmware also controls the block's clocks and power, so the
> binding has no clocks or power-domains properties.
>
> The output port must have an endpoint so the source can be connected to
> a trace sink.
>
> Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
> ---
> .../bindings/arm/qcom,coresight-stm-qdcp.yaml | 111 +++++++++++++++++++++
> 1 file changed, 111 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight-stm-qdcp.yaml b/Documentation/devicetree/bindings/arm/qcom,coresight-stm-qdcp.yaml
> new file mode 100644
> index 000000000000..f365ce2450ad
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/qcom,coresight-stm-qdcp.yaml
> @@ -0,0 +1,111 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/arm/qcom,coresight-stm-qdcp.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Qualcomm QDCP-backed CoreSight STM source
> +
> +maintainers:
> + - Jie Gan <jie.gan@oss.qualcomm.com>
> +
> +description: |
> + The System Trace Macrocell (STM) is a CoreSight trace source designed for
> + high-bandwidth trace of software instrumentation, made up of memory-mapped
> + writes to the STM stimulus aperture.
> +
> + On Qualcomm platforms where the STM control registers are owned by QECP
> + firmware, this binding describes an STM whose stimulus aperture is mapped by
> + the application processor for data writes, while enabling and disabling the
> + trace path is delegated to firmware over the Qualcomm Debug Control Protocol
> + (QDCP). It references a QDCP provider through the "qcom,qdcp" phandle rather
> + than exposing the STM programming registers directly.
> +
> +select:
> + properties:
> + compatible:
> + contains:
> + const: qcom,coresight-stm-qdcp
> + required:
> + - compatible
> +
> +properties:
> + $nodename:
> + pattern: "^stm(@[0-9a-f]+)$"
That's RFC, so maybe you do not expect review. Explain in cover letter
as the most important part what do you expect from us.
Anyway, drop, I do not see how is this conforming to DT spec.
> +
> + compatible:
> + const: qcom,coresight-stm-qdcp
> +
> + reg:
> + maxItems: 1
> +
> + reg-names:
> + items:
> + - const: stm-stimulus-base
> +
> + qcom,qdcp:
> + $ref: /schemas/types.yaml#/definitions/phandle
> + description:
> + Phandle to the specific "connection-N" child node of the QDCP
> + provider (see qcom,qdcp.yaml) that owns this STM's control registers
> + and services the firmware enable/disable transactions. This must
> + reference the connection child node directly, not the top-level
> + QDCP provider node itself.
No, the QDCP is just part of this device.
> +
> + qcom,qdcp-source-id:
> + $ref: /schemas/types.yaml#/definitions/uint64
> + description:
> + QECP firmware source identifier for this STM, used to address it in QDCP
> + transactions.
Drop, we don't allow instance IDs.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-19 14:02 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
2026-11-19 9:12 ` sashiko-bot
2026-11-19 14:00 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider Jie Gan
2026-11-19 9:18 ` sashiko-bot
2026-11-19 9:01 ` [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source Jie Gan
2026-11-19 14:02 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 4/6] coresight: " Jie Gan
2026-11-19 9:28 ` sashiko-bot
2026-11-19 9:01 ` [PATCH RFC 5/6] dt-bindings: arm: qcom: add QDCP TMC ETR sink Jie Gan
2026-11-19 9:01 ` [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support Jie Gan
2026-11-19 9:25 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox