Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/8] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks
@ 2026-11-30  7:11 Jie Gan
  2026-11-30  7:11 ` [PATCH v2 1/8] soc: qcom: add QDCP client library Jie Gan
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Jie Gan @ 2026-11-30  7:11 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Suzuki K Poulose,
	Mike Leach, James Clark, Leo Yan, Alexander Shishkin, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Maxime Coquelin,
	Alexandre Torgue, Tingwei Zhang
  Cc: linux-kernel, linux-arm-msm, coresight, linux-arm-kernel,
	devicetree, 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 running its own firmware: 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. Their control registers are protected by hardware access control
and cannot be accessed from the AP (application processor, the cores
running Linux).

Linux asks the QECP firmware to configure, enable and disable these
blocks over the Qualcomm Debug Control Protocol (QDCP), a QMI service
carried over QRTR like other Qualcomm firmware services. What stays with
Linux is what it can access directly: the STM stimulus ports, written
for trace data, and the ETR trace buffer, allocated in system memory and
read through the TMC device node as for any other ETR.

This series adds a QDCP client library, a driver for the QECP-owned STM
and a driver for the QECP-owned TMC, so that a QECP-owned STM -> ETR
session works through the existing CoreSight sysfs interface.

Design
------

Control path (QDCP, QMI over QRTR) and data path (hardware):

  AP (Linux)                                 QECP
  ----------                                 ----

  sysfs / char dev
        |
  +-----v------------+  typed   +-----------+  QMI/QRTR  +-------------+
  | QDCP STM source  |--------->| QDCP      |            |             |
  | QDCP TMC (ETR)   |  API     | client    |<---------->| QECP        |
  +------------------+          | library   |            | 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)

 - QDCP is a client library under drivers/soc/qcom/, next to the other
   Qualcomm QMI helpers, selected by the drivers that use it. Each device
   creates its own QMI client with devm_qdcp_client_get(); the client is
   released after the driver's remove callback, so a driver can still
   stop its block from there. The library is not a CoreSight device and
   has no devicetree node.

 - The library API follows the protocol. Requests shared by every source
   or sink take its type: qdcp_source_set_atid(),
   qdcp_source_{enable,disable}() and qdcp_sink_{enable,disable}().
   Configuration specific to a block type has typed requests:
   qdcp_stm_set_port_mask(), qdcp_stm_get_param(),
   qdcp_tmc_etr_configure(), qdcp_tmc_get_param() and
   qdcp_tmc_{begin,end}_read().

 - The QECP-owned STM has its own driver, coresight-stm.c is untouched.
   It reads STMDEVID and STMSPFEAT2R through the firmware for its number
   of stimulus ports and fundamental data size, and writes trace data to
   the stimulus ports through the generic STM framework.

 - The QECP-owned TMC driver is a separate module, coresight-tmc-qdcp,
   built on a small set of TMC helpers exported for it, the same way
   CATU builds on the TMC driver. The generic TMC code only gains three
   preparation patches with no functional change. The driver reads DEVID
   through the firmware and selects the configuration specific handling
   from its configuration type, as the TMC driver does; only the ETR
   configuration is implemented, other configurations fail to probe.

 - QECP-internal topology is not modelled in DT: there is no node for
   the funnels/replicators between the STM and the ETR, since CoreSight
   only needs a logical source-to-sink path to build a session.

Devicetree and firmware identifiers
-----------------------------------

 - Each device has a SoC specific compatible, qcom,hawi-qecp-stm and
   qcom,hawi-qecp-tmc, Maili using the Hawi compatibles as fallback.
   One TMC compatible covers every TMC configuration, which is read from
   DEVID, as for arm,coresight-tmc.

 - reg describes the real register regions: the STM control registers
   ("stm-base") and stimulus ports ("stm-stimulus-base"), and the TMC
   registers. The firmware identifies each block by the base address of
   its registers, so the STM source ID and the TMC ID are taken from reg
   and no identifier property is needed. The access-controlled regions
   are never mapped; only the stimulus ports are.

 - The QMI service, version and instance used to reach the firmware are
   fixed for a SoC and the same for every QECP-owned block, so they are
   part of the driver match data (service 0x453, version 1, instance 32
   on Hawi). They are only used to look up the server.

 - Because firmware controls the blocks' clocks and power, the bindings
   describe no clocks, clock-names or power-domains, and the drivers do
   no clock handling or runtime PM. The TMC binding keeps the usual ETR
   properties (iommus, arm,buffer-size, arm,scatter-gather).

Register ownership
------------------

                            AP (Linux)          QECP firmware
                            ----------          -------------
  STM stimulus aperture     owned, mapped,
                            written directly
  STM control registers     read over QDCP      owned, access-
  (DEVID, SPFEAT2R)                             controlled from AP
  Funnel/replicator                             owned, private, not
  routing                                       visible to Linux
  TMC-ETR control registers read over QDCP      owned, access-
  (DEVID, AUTHSTATUS, FFCR)                     controlled from AP
  TMC-ETR trace buffer      owned, allocated,
                            read via sysfs
  TMC-ETR RRP/RWP/STS       read over QDCP      owned, returned over
                                                QDCP on request
  Block clocks and power                        owned, controlled by
                                                firmware only

QDCP is the only channel to the firmware-owned state; there is no direct
path and no fallback.

Sequences
---------

Enable, a trace session start (CoreSight enables sink first, then source):

  CoreSight   QDCP TMC     QDCP STM      QDCP          QECP
  core        (patch 8)    (patch 6)     library       firmware
     |            |            |            |             |
     |--enable--->|            |            |             |
     |  sink      | alloc/reuse etr_buf,    |             |
     |            | compute paddr + IOVA    |             |
     |            |--qdcp_tmc_get_param---->|--FFCR, STS->|
     |            |  (no pending flush, no  |<---values---|
     |            |   memory error)         |             |
     |            |--qdcp_tmc_etr_configure>|--SG mode--->|
     |            |            |            |--buffer---->|
     |            |            |            |--FFCR------>|
     |            |--qdcp_sink_enable------>|--start TMC->|
     |            |            |            |<---ok-------|
     |<--ok-------|            |            |             |
     |--enable------------>    |            |             |
     |  source                 |            |             |
     |            |            |--qdcp_source_set_atid()  |
     |            |            |  qdcp_stm_set_port_mask()|
     |            |            |  qdcp_source_enable()    |
     |            |            |            |--set ATID-->|
     |            |            |            |--ports on-->|
     |            |            |            |--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 TMC     QDCP STM      QDCP          QECP
  core        (patch 8)    (patch 6)     library       firmware
     |            |            |            |             |
     |--disable--------------> |            |             |
     |  source                 |            |             |
     |            |            |--qdcp_stm_set_port_mask()|
     |            |            |  qdcp_source_disable()   |
     |            |            |  qdcp_source_set_atid(0) |
     |            |            |            |--ports off->|
     |            |            |            |--stop STM-->|
     |            |            |            |--clear ATID>|
     |--disable-->|            |            |             |
     |  sink      |--qdcp_tmc_begin_read--->|--flush and->|
     |            |            |            |  stop TMC   |
     |            |--qdcp_tmc_get_param(RRP/RWP/STS)----->|
     |            |<--values------------------------------|
     |            | validate, sync etr_buf  |             |
     |            |--qdcp_sink_disable----->|--disable--->|
     |            |            |            |<---ok-------|
     |            | stop confirmed? no -> keep etr_buf pinned and retry
     |            |   on the next enable, open() of /dev/<tmc> or removal
     |            | yes: release etr_buf    |             |
     |            |            |            |             |
  userspace reads trace from etr_buf through /dev/<tmc>, as for any ETR;
  closing it ends the read (qdcp_tmc_end_read) before a running session
  is resumed.

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 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. The ETR is also stopped on shutdown, so that firmware does not
   keep writing into memory after a reboot or kexec.
 - The ETR is not enabled while a flush from the previous session is
   still pending or a memory error is reported, and it is flushed and
   stopped before its pointers are read.
 - The read/write pointers returned by firmware are only used if the
   ETR was enabled with the buffer and they lie inside it; otherwise
   the buffer is reported empty instead of leaving the previous capture
   readable.
 - The STM stimulus ports are only written once firmware has confirmed
   the STM is enabled, since firmware controls its clocks and power.
 - 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 trace ID is then kept allocated on removal, so
   that no other source reuses an ID firmware may still be applying.
 - Unbinding through sysfs is not supported. An enabled trace path and
   an open device node both hold a reference on the driver module, so
   the devices are always idle when a driver is removed.
 - 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.

Sysfs ABI
---------

No new CoreSight-wide sysfs ABI. A QDCP TMC exposes the generic ETR/TMC
attributes for buffer sizing and sysfs mode enable/disable, except
trigger_cntr, as the driver does not program TMC_TRG through the
firmware. The QDCP STM exposes a read-only "traceid" attribute, like
other CoreSight sources. Userspace reads trace data through the same
/dev/<tmc> interface as for every other ETR.

Known limitations and scope
---------------------------

 - 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
   session is disabled and enabled again.
 - The STM stimulus write path checks the firmware enable state without
   a lock, like coresight-stm.c checks the mode, as the packet callback
   is notrace and can run in atomic context.
 - QDCP-owned ETRs have no panic handler: the control registers are not
   accessible from the panic path.
 - Not included, and deferred until a platform needs it: the TMC ETF/ETB
   configurations (the TMC driver is structured for them), perf mode,
   STM hardware events, other QDCP sources such as TPDM and OCLA, and the
   TMC READ firmware data-copy command (the AP reads the ETR buffer
   directly).
 - The enable/disable requests are not modelled as a power domain: they
   start and stop the blocks' trace function rather than changing a
   power state, carry data (trace ID, port mask, buffer addresses, FFCR)
   and read state back, and follow the CoreSight path lifecycle rather
   than runtime PM.

Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
Changes in v2:
 - Dropped RFC prefix.

 - QDCP provider replaced by a client library (Krzysztof): v1 had a
   "qcom,qdcp" platform device with QMI connection child nodes, and
   consumers referenced a connection through a qcom,qdcp phandle. The
   provider has no resources of its own and QDCP is part of each device,
   so the qcom,qdcp binding, the phandle, the provider list and the
   device links are gone. This also removes the race between
   devm_qdcp_get() and provider unbind, and the use after free on an
   open STM device after a forced unbind through the device link
   (sashiko).

 - No firmware identifiers in DT (Krzysztof): qcom,service-id,
   qcom,instance-id, qcom,version, qcom,qdcp-source-id and
   qcom,qdcp-tmc-id are dropped. The QMI connection values are taken
   from the driver match data; the block IDs are the base addresses of
   the register regions described in reg, which the firmware uses as
   identifiers.

 - SoC specific compatibles (Krzysztof): qcom,coresight-stm-qdcp and
   qcom,coresight-tmc-qdcp are replaced with qcom,hawi-qecp-stm and
   qcom,hawi-qecp-tmc, Maili using them as fallback. The $nodename
   pattern and qcom,num-stimulus-ports are dropped.

 - QMI request lengths fixed (sashiko): v1 passed sizeof() of the
   request structure as the encoded length, which is shorter than the
   encoded message as each TLV adds a 3 byte header, so most requests
   would have failed with -ETOOSMALL.

 - TMC patch split (Suzuki): three preparation patches with no
   functional change, then the QDCP TMC driver as a separate module, so
   that the generic TMC code has no QDCP branches and does not depend on
   the Qualcomm QMI stack. The shared helpers are exported in the patch
   that first uses them.

 - csdev_access (Suzuki): both drivers provide csdev_access methods that
   warn and return 0 instead of leaving desc.access zeroed, so no
   generic helper has to be skipped. A firmware backed accessor does not
   fit the current callbacks, which take no device context, cannot
   report a failed request and are called under spinlocks, while a
   firmware request sleeps.

 - ETR: flushed and stopped (TMC BEGIN_READ) before its pointers are
   read, resumed after a read with TMC END_READ, not enabled while a
   flush is pending or a memory error is reported, buffer configured in
   the order buffer mode, buffer, FFCR, and AUTHSTATUS checked at probe.
   The pointers are not used after a failed enable and are checked
   against the buffer, the buffer is reported empty instead of keeping
   stale metadata, freed on removal once the stop is confirmed, and the
   ETR is stopped on shutdown (sashiko).

 - STM: trace ID set before the stimulus ports are enabled and the STM
   started, and cleared last when it is stopped; number of stimulus
   ports and data size read through the firmware; unused hardware event
   support removed. The stimulus ports are only written once the
   firmware confirmed the STM is enabled, a failed enable is followed by
   a stop, removal no longer disables the source behind the CoreSight
   core, and the trace ID is released after the device is unregistered
   (sashiko).

 - The TMC driver is generic over the TMC configuration, with only the
   ETR configuration implemented, so that an ETF can be added later.

- Link to RFC: https://lore.kernel.org/r/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com

---
Jie Gan (8):
      soc: qcom: add QDCP client library
      coresight: tmc: split ETR buffer sync from hardware state readback
      coresight: tmc: factor out common ETR probe initialisation
      coresight: tmc: move trigger_cntr into its own attribute group
      dt-bindings: arm: qcom: add QECP owned CoreSight STM
      coresight: qcom: add QECP owned STM driver
      dt-bindings: arm: qcom: add QECP owned CoreSight TMC
      coresight: tmc: add QECP owned TMC driver

 .../bindings/arm/qcom,coresight-qecp-stm.yaml      |   76 ++
 .../bindings/arm/qcom,coresight-qecp-tmc.yaml      |   83 ++
 drivers/hwtracing/coresight/Kconfig                |   34 +
 drivers/hwtracing/coresight/Makefile               |    3 +
 .../hwtracing/coresight/coresight-qcom-qdcp-stm.c  |  614 +++++++++++
 drivers/hwtracing/coresight/coresight-tmc-core.c   |  118 ++-
 drivers/hwtracing/coresight/coresight-tmc-etr.c    |   78 +-
 drivers/hwtracing/coresight/coresight-tmc-qdcp.c   |  734 +++++++++++++
 drivers/hwtracing/coresight/coresight-tmc.h        |   20 +
 drivers/soc/qcom/Kconfig                           |   10 +
 drivers/soc/qcom/Makefile                          |    1 +
 drivers/soc/qcom/qcom_qdcp.c                       | 1118 ++++++++++++++++++++
 include/linux/soc/qcom/qdcp.h                      |  120 +++
 13 files changed, 2946 insertions(+), 63 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] 11+ messages in thread

end of thread, other threads:[~2026-11-30  7:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  7:11 [PATCH v2 0/8] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-30  7:11 ` [PATCH v2 1/8] soc: qcom: add QDCP client library Jie Gan
2026-11-30  7:11 ` [PATCH v2 2/8] coresight: tmc: split ETR buffer sync from hardware state readback Jie Gan
2026-11-30  7:11 ` [PATCH v2 3/8] coresight: tmc: factor out common ETR probe initialisation Jie Gan
2026-11-30  7:20   ` sashiko-bot
2026-11-30  7:11 ` [PATCH v2 4/8] coresight: tmc: move trigger_cntr into its own attribute group Jie Gan
2026-11-30  7:11 ` [PATCH v2 5/8] dt-bindings: arm: qcom: add QECP owned CoreSight STM Jie Gan
2026-11-30  7:11 ` [PATCH v2 6/8] coresight: qcom: add QECP owned STM driver Jie Gan
2026-11-30  7:11 ` [PATCH v2 7/8] dt-bindings: arm: qcom: add QECP owned CoreSight TMC Jie Gan
2026-11-30  7:11 ` [PATCH v2 8/8] coresight: tmc: add QECP owned TMC driver Jie Gan
2026-11-30  7:33   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox