Commit d724f652 authored by James Clark's avatar James Clark Committed by Suzuki K Poulose

coresight: Add helper for atomically taking the device

Now that mode is in struct coresight_device, this pattern can be wrapped
in a helper.
Signed-off-by: default avatarJames Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20240129154050.569566-11-james.clark@arm.comSigned-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
parent 812265e2
...@@ -556,14 +556,12 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event, ...@@ -556,14 +556,12 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
enum cs_mode mode) enum cs_mode mode)
{ {
int ret; int ret;
u32 val;
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
val = local_cmpxchg(&drvdata->csdev->mode, CS_MODE_DISABLED, mode); if (!coresight_take_mode(csdev, mode)) {
/* Someone is already using the tracer */
/* Someone is already using the tracer */
if (val)
return -EBUSY; return -EBUSY;
}
switch (mode) { switch (mode) {
case CS_MODE_SYSFS: case CS_MODE_SYSFS:
......
...@@ -840,13 +840,11 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event, ...@@ -840,13 +840,11 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
enum cs_mode mode) enum cs_mode mode)
{ {
int ret; int ret;
u32 val;
val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode); if (!coresight_take_mode(csdev, mode)) {
/* Someone is already using the tracer */
/* Someone is already using the tracer */
if (val)
return -EBUSY; return -EBUSY;
}
switch (mode) { switch (mode) {
case CS_MODE_SYSFS: case CS_MODE_SYSFS:
......
...@@ -193,17 +193,15 @@ static void stm_enable_hw(struct stm_drvdata *drvdata) ...@@ -193,17 +193,15 @@ static void stm_enable_hw(struct stm_drvdata *drvdata)
static int stm_enable(struct coresight_device *csdev, struct perf_event *event, static int stm_enable(struct coresight_device *csdev, struct perf_event *event,
enum cs_mode mode) enum cs_mode mode)
{ {
u32 val;
struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
if (mode != CS_MODE_SYSFS) if (mode != CS_MODE_SYSFS)
return -EINVAL; return -EINVAL;
val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode); if (!coresight_take_mode(csdev, mode)) {
/* Someone is already using the tracer */
/* Someone is already using the tracer */
if (val)
return -EBUSY; return -EBUSY;
}
pm_runtime_get_sync(csdev->dev.parent); pm_runtime_get_sync(csdev->dev.parent);
......
...@@ -580,6 +580,17 @@ static inline bool coresight_is_percpu_sink(struct coresight_device *csdev) ...@@ -580,6 +580,17 @@ static inline bool coresight_is_percpu_sink(struct coresight_device *csdev)
(csdev->subtype.sink_subtype == CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM); (csdev->subtype.sink_subtype == CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM);
} }
/*
* Atomically try to take the device and set a new mode. Returns true on
* success, false if the device is already taken by someone else.
*/
static inline bool coresight_take_mode(struct coresight_device *csdev,
enum cs_mode new_mode)
{
return local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, new_mode) ==
CS_MODE_DISABLED;
}
extern struct coresight_device * extern struct coresight_device *
coresight_register(struct coresight_desc *desc); coresight_register(struct coresight_desc *desc);
extern void coresight_unregister(struct coresight_device *csdev); extern void coresight_unregister(struct coresight_device *csdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment