Skip to content

Commit 296b01f

Browse files
James-A-ClarkSuzuki K Poulose
authored and
Suzuki K Poulose
committed
coresight: Refactor out buffer allocation function for ETR
When CATU is moved to the generic enable/disable path system in the next commit, it will need to call into ETR and get it to pre-allocate its buffer so add a function for it. No functional changes Reviewed-by: Mike Leach <[email protected]> Signed-off-by: James Clark <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ae7f2b5 commit 296b01f

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

drivers/hwtracing/coresight/coresight-tmc-etr.c

+43-7
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ void tmc_etr_disable_hw(struct tmc_drvdata *drvdata)
11691169
drvdata->etr_buf = NULL;
11701170
}
11711171

1172-
static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
1172+
static struct etr_buf *tmc_etr_get_sysfs_buffer(struct coresight_device *csdev)
11731173
{
11741174
int ret = 0;
11751175
unsigned long flags;
@@ -1192,7 +1192,7 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
11921192
/* Allocate memory with the locks released */
11931193
free_buf = new_buf = tmc_etr_setup_sysfs_buf(drvdata);
11941194
if (IS_ERR(new_buf))
1195-
return PTR_ERR(new_buf);
1195+
return new_buf;
11961196

11971197
/* Let's try again */
11981198
spin_lock_irqsave(&drvdata->spinlock, flags);
@@ -1223,24 +1223,60 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
12231223
drvdata->sysfs_buf = new_buf;
12241224
}
12251225

1226-
ret = tmc_etr_enable_hw(drvdata, drvdata->sysfs_buf);
1227-
if (!ret) {
1228-
drvdata->mode = CS_MODE_SYSFS;
1229-
atomic_inc(&csdev->refcnt);
1230-
}
12311226
out:
12321227
spin_unlock_irqrestore(&drvdata->spinlock, flags);
12331228

12341229
/* Free memory outside the spinlock if need be */
12351230
if (free_buf)
12361231
tmc_etr_free_sysfs_buf(free_buf);
1232+
return ret ? ERR_PTR(ret) : drvdata->sysfs_buf;
1233+
}
1234+
1235+
static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
1236+
{
1237+
int ret;
1238+
unsigned long flags;
1239+
struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
1240+
struct etr_buf *sysfs_buf = tmc_etr_get_sysfs_buffer(csdev);
1241+
1242+
if (IS_ERR(sysfs_buf))
1243+
return PTR_ERR(sysfs_buf);
1244+
1245+
spin_lock_irqsave(&drvdata->spinlock, flags);
1246+
ret = tmc_etr_enable_hw(drvdata, sysfs_buf);
1247+
if (!ret) {
1248+
drvdata->mode = CS_MODE_SYSFS;
1249+
atomic_inc(&csdev->refcnt);
1250+
}
1251+
1252+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
12371253

12381254
if (!ret)
12391255
dev_dbg(&csdev->dev, "TMC-ETR enabled\n");
12401256

12411257
return ret;
12421258
}
12431259

1260+
struct etr_buf *tmc_etr_get_buffer(struct coresight_device *csdev,
1261+
enum cs_mode mode, void *data)
1262+
{
1263+
struct perf_output_handle *handle = data;
1264+
struct etr_perf_buffer *etr_perf;
1265+
1266+
switch (mode) {
1267+
case CS_MODE_SYSFS:
1268+
return tmc_etr_get_sysfs_buffer(csdev);
1269+
case CS_MODE_PERF:
1270+
etr_perf = etm_perf_sink_config(handle);
1271+
if (WARN_ON(!etr_perf || !etr_perf->etr_buf))
1272+
return ERR_PTR(-EINVAL);
1273+
return etr_perf->etr_buf;
1274+
default:
1275+
return ERR_PTR(-EINVAL);
1276+
}
1277+
}
1278+
EXPORT_SYMBOL_GPL(tmc_etr_get_buffer);
1279+
12441280
/*
12451281
* alloc_etr_buf: Allocate ETR buffer for use by perf.
12461282
* The size of the hardware buffer is dependent on the size configured

drivers/hwtracing/coresight/coresight-tmc.h

+2
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,7 @@ struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
332332

333333
void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
334334
void tmc_etr_remove_catu_ops(void);
335+
struct etr_buf *tmc_etr_get_buffer(struct coresight_device *csdev,
336+
enum cs_mode mode, void *data);
335337

336338
#endif

0 commit comments

Comments
 (0)