[PATCH v2 3/8] coresight: tmc: factor out common ETR probe initialisation
From: Jie Gan
Date: Mon Nov 30 2026 - 02:12:40 EST
The TMC ETR probe mixes configuration that needs access to the TMC
registers, the AUTHSTATUS check and the PID based unadvertised
capabilities, with configuration derived only from DEVID and the
firmware properties: the buffer and AXI burst sizes, scatter-gather
support, the DMA mask and the perf buffer IDR.
Move the latter into tmc_etr_probe_common() and leave
tmc_etr_setup_caps() with the register based checks only. The buffer
and burst sizes are now set together with the rest of the ETR
configuration, after the reserved region lookup, which does not depend
on them.
This allows an ETR whose registers are not accessible by the kernel to
share the common ETR initialisation.
No functional change intended.
Signed-off-by: Jie Gan <jie.gan@xxxxxxxxxxxxxxxx>
---
drivers/hwtracing/coresight/coresight-tmc-core.c | 101 ++++++++++++++---------
1 file changed, 60 insertions(+), 41 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index 0ef4b817b297..ad2c99eae5ae 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -601,7 +601,7 @@ static bool tmc_etr_can_use_sg(struct device *dev)
return fwnode_property_present(dev->fwnode, "arm,scatter-gather");
} else if (is_acpi_device_node(dev->fwnode)) {
/*
- * TMC_DEVID_NOSCAT test in tmc_etr_setup_caps(), has already ensured
+ * TMC_DEVID_NOSCAT test in tmc_etr_probe_common(), has already ensured
* this property is only checked for Coresight SoC 400 TMC configured
* as ETR.
*/
@@ -676,12 +676,11 @@ 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,
+/* Detect and initialise the unadvertised capabilities of a TMC ETR */
+static int tmc_etr_setup_caps(struct device *parent,
struct csdev_access *access)
{
- int rc;
- u32 tmc_pid, dma_mask = 0;
+ u32 tmc_pid;
struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
void *dev_caps;
@@ -694,34 +693,7 @@ static int tmc_etr_setup_caps(struct device *parent, u32 devid,
/* 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))
- tmc_etr_set_cap(drvdata, TMC_ETR_SG);
-
- /* Check if the AXI address width is available */
- if (devid & TMC_DEVID_AXIAW_VALID)
- dma_mask = ((devid >> TMC_DEVID_AXIAW_SHIFT) &
- TMC_DEVID_AXIAW_MASK);
-
- /*
- * Unless specified in the device configuration, ETR uses a 40-bit
- * AXI master in place of the embedded SRAM of ETB/ETF.
- */
- switch (dma_mask) {
- case 32:
- case 40:
- case 44:
- case 48:
- case 52:
- dev_info(parent, "Detected dma mask %dbits\n", dma_mask);
- break;
- default:
- dma_mask = 40;
- }
-
- rc = dma_set_mask_and_coherent(parent, DMA_BIT_MASK(dma_mask));
- if (rc)
- dev_err(parent, "Failed to setup DMA mask: %d\n", rc);
- return rc;
+ return 0;
}
static u32 tmc_etr_get_default_buffer_size(struct device *dev)
@@ -748,6 +720,56 @@ static u32 tmc_etr_get_max_burst_size(struct device *dev)
return burst_size;
}
+/*
+ * Initialise the TMC ETR configuration derived from @devid and the
+ * firmware properties: buffer and AXI burst sizes, scatter-gather
+ * support and DMA mask. The unadvertised capabilities must already be
+ * set with tmc_etr_init_caps().
+ */
+static int tmc_etr_probe_common(struct device *dev,
+ struct tmc_drvdata *drvdata, u32 devid)
+{
+ int rc;
+ u32 dma_mask = 0;
+
+ drvdata->size = tmc_etr_get_default_buffer_size(dev);
+ drvdata->max_burst_size = tmc_etr_get_max_burst_size(dev);
+
+ 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 */
+ if (devid & TMC_DEVID_AXIAW_VALID)
+ dma_mask = ((devid >> TMC_DEVID_AXIAW_SHIFT) &
+ TMC_DEVID_AXIAW_MASK);
+
+ /*
+ * Unless specified in the device configuration, ETR uses a 40-bit
+ * AXI master in place of the embedded SRAM of ETB/ETF.
+ */
+ switch (dma_mask) {
+ case 32:
+ case 40:
+ case 44:
+ case 48:
+ case 52:
+ dev_info(dev, "Detected dma mask %dbits\n", dma_mask);
+ break;
+ default:
+ dma_mask = 40;
+ }
+
+ rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(dma_mask));
+ if (rc) {
+ dev_err(dev, "Failed to setup DMA mask: %d\n", rc);
+ return rc;
+ }
+
+ idr_init(&drvdata->idr);
+ mutex_init(&drvdata->idr_mutex);
+ return 0;
+}
+
static void register_crash_dev_interface(struct tmc_drvdata *drvdata,
const char *name)
{
@@ -805,12 +827,8 @@ static int __tmc_probe(struct device *dev, struct resource *res)
drvdata->pid = -1;
drvdata->etr_mode = ETR_MODE_AUTO;
- if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
- drvdata->size = tmc_etr_get_default_buffer_size(dev);
- drvdata->max_burst_size = tmc_etr_get_max_burst_size(dev);
- } else {
+ if (drvdata->config_type != TMC_CONFIG_TYPE_ETR)
drvdata->size = readl_relaxed(drvdata->base + TMC_RSZ) * 4;
- }
tmc_get_reserved_region(dev);
@@ -829,11 +847,12 @@ static int __tmc_probe(struct device *dev, struct resource *res)
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);
+ ret = tmc_etr_setup_caps(dev, &desc.access);
+ if (ret)
+ goto out;
+ ret = tmc_etr_probe_common(dev, drvdata, devid);
if (ret)
goto out;
- idr_init(&drvdata->idr);
- mutex_init(&drvdata->idr_mutex);
dev_list = "tmc_etr";
break;
case TMC_CONFIG_TYPE_ETF:
--
2.34.1