Skip to content

Commit

Permalink
coresight: Move mode to struct coresight_device
Browse files Browse the repository at this point in the history
Most devices use mode, so move the mode definition out of the individual
devices and up to the Coresight device. This will allow the core code to
also know the mode which will be useful in a later commit.

This also fixes the inconsistency of the documentation of the mode field
on the individual device types. For example ETB10 had "this ETB is being
used".

Two devices didn't require an atomic mode type, so these usages have
been converted to atomic_get() and atomic_set() only to make it compile,
but the documentation of the field in struct coresight_device explains
this type of usage.

In the future, manipulation of the mode could be completely moved out of
the individual devices and into the core code because it's almost all
duplicate code, and this change is a step towards that.

Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20240129154050.569566-5-james.clark@arm.com
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
  • Loading branch information
James-A-Clark authored and Suzuki K Poulose committed Feb 12, 2024
1 parent a11ebe1 commit 9cae77c
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 76 deletions.
18 changes: 8 additions & 10 deletions drivers/hwtracing/coresight/coresight-etb10.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ DEFINE_CORESIGHT_DEVLIST(etb_devs, "etb");
* @pid: Process ID of the process being monitored by the session
* that is using this component.
* @buf: area of memory where ETB buffer content gets sent.
* @mode: this ETB is being used.
* @buffer_depth: size of @buf.
* @trigger_cntr: amount of words to store after a trigger.
*/
Expand All @@ -89,7 +88,6 @@ struct etb_drvdata {
local_t reading;
pid_t pid;
u8 *buf;
u32 mode;
u32 buffer_depth;
u32 trigger_cntr;
};
Expand Down Expand Up @@ -150,17 +148,17 @@ static int etb_enable_sysfs(struct coresight_device *csdev)
spin_lock_irqsave(&drvdata->spinlock, flags);

/* Don't messup with perf sessions. */
if (drvdata->mode == CS_MODE_PERF) {
if (local_read(&csdev->mode) == CS_MODE_PERF) {
ret = -EBUSY;
goto out;
}

if (drvdata->mode == CS_MODE_DISABLED) {
if (local_read(&csdev->mode) == CS_MODE_DISABLED) {
ret = etb_enable_hw(drvdata);
if (ret)
goto out;

drvdata->mode = CS_MODE_SYSFS;
local_set(&csdev->mode, CS_MODE_SYSFS);
}

atomic_inc(&csdev->refcnt);
Expand All @@ -181,7 +179,7 @@ static int etb_enable_perf(struct coresight_device *csdev, void *data)
spin_lock_irqsave(&drvdata->spinlock, flags);

/* No need to continue if the component is already in used by sysFS. */
if (drvdata->mode == CS_MODE_SYSFS) {
if (local_read(&drvdata->csdev->mode) == CS_MODE_SYSFS) {
ret = -EBUSY;
goto out;
}
Expand Down Expand Up @@ -216,7 +214,7 @@ static int etb_enable_perf(struct coresight_device *csdev, void *data)
if (!ret) {
/* Associate with monitored process. */
drvdata->pid = pid;
drvdata->mode = CS_MODE_PERF;
local_set(&drvdata->csdev->mode, CS_MODE_PERF);
atomic_inc(&csdev->refcnt);
}

Expand Down Expand Up @@ -362,11 +360,11 @@ static int etb_disable(struct coresight_device *csdev)
}

/* Complain if we (somehow) got out of sync */
WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
WARN_ON_ONCE(local_read(&csdev->mode) == CS_MODE_DISABLED);
etb_disable_hw(drvdata);
/* Dissociate from monitored process. */
drvdata->pid = -1;
drvdata->mode = CS_MODE_DISABLED;
local_set(&csdev->mode, CS_MODE_DISABLED);
spin_unlock_irqrestore(&drvdata->spinlock, flags);

dev_dbg(&csdev->dev, "ETB disabled\n");
Expand Down Expand Up @@ -589,7 +587,7 @@ static void etb_dump(struct etb_drvdata *drvdata)
unsigned long flags;

spin_lock_irqsave(&drvdata->spinlock, flags);
if (drvdata->mode == CS_MODE_SYSFS) {
if (local_read(&drvdata->csdev->mode) == CS_MODE_SYSFS) {
__etb_disable_hw(drvdata);
etb_dump_hw(drvdata);
__etb_enable_hw(drvdata);
Expand Down
2 changes: 0 additions & 2 deletions drivers/hwtracing/coresight/coresight-etm.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ struct etm_config {
* @port_size: port size as reported by ETMCR bit 4-6 and 21.
* @arch: ETM/PTM version number.
* @use_cpu14: true if management registers need to be accessed via CP14.
* @mode: this tracer's mode, i.e sysFS, Perf or disabled.
* @sticky_enable: true if ETM base configuration has been done.
* @boot_enable:true if we should start tracing at boot time.
* @os_unlock: true if access to management registers is allowed.
Expand All @@ -238,7 +237,6 @@ struct etm_drvdata {
int port_size;
u8 arch;
bool use_cp14;
local_t mode;
bool sticky_enable;
bool boot_enable;
bool os_unlock;
Expand Down
13 changes: 6 additions & 7 deletions drivers/hwtracing/coresight/coresight-etm3x-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
u32 val;
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);

val = local_cmpxchg(&drvdata->mode, CS_MODE_DISABLED, mode);
val = local_cmpxchg(&drvdata->csdev->mode, CS_MODE_DISABLED, mode);

/* Someone is already using the tracer */
if (val)
Expand All @@ -578,7 +578,7 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event,

/* The tracer didn't start */
if (ret)
local_set(&drvdata->mode, CS_MODE_DISABLED);
local_set(&drvdata->csdev->mode, CS_MODE_DISABLED);

return ret;
}
Expand Down Expand Up @@ -672,14 +672,13 @@ static void etm_disable(struct coresight_device *csdev,
struct perf_event *event)
{
enum cs_mode mode;
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);

/*
* For as long as the tracer isn't disabled another entity can't
* change its status. As such we can read the status here without
* fearing it will change under us.
*/
mode = local_read(&drvdata->mode);
mode = local_read(&csdev->mode);

switch (mode) {
case CS_MODE_DISABLED:
Expand All @@ -696,7 +695,7 @@ static void etm_disable(struct coresight_device *csdev,
}

if (mode)
local_set(&drvdata->mode, CS_MODE_DISABLED);
local_set(&csdev->mode, CS_MODE_DISABLED);
}

static const struct coresight_ops_source etm_source_ops = {
Expand Down Expand Up @@ -730,7 +729,7 @@ static int etm_starting_cpu(unsigned int cpu)
etmdrvdata[cpu]->os_unlock = true;
}

if (local_read(&etmdrvdata[cpu]->mode))
if (local_read(&etmdrvdata[cpu]->csdev->mode))
etm_enable_hw(etmdrvdata[cpu]);
spin_unlock(&etmdrvdata[cpu]->spinlock);
return 0;
Expand All @@ -742,7 +741,7 @@ static int etm_dying_cpu(unsigned int cpu)
return 0;

spin_lock(&etmdrvdata[cpu]->spinlock);
if (local_read(&etmdrvdata[cpu]->mode))
if (local_read(&etmdrvdata[cpu]->csdev->mode))
etm_disable_hw(etmdrvdata[cpu]);
spin_unlock(&etmdrvdata[cpu]->spinlock);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ static ssize_t cntr_val_show(struct device *dev,
struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
struct etm_config *config = &drvdata->config;

if (!local_read(&drvdata->mode)) {
if (!local_read(&drvdata->csdev->mode)) {
spin_lock(&drvdata->spinlock);
for (i = 0; i < drvdata->nr_cntr; i++)
ret += sprintf(buf, "counter %d: %x\n",
Expand Down Expand Up @@ -941,7 +941,7 @@ static ssize_t seq_curr_state_show(struct device *dev,
struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
struct etm_config *config = &drvdata->config;

if (!local_read(&drvdata->mode)) {
if (!local_read(&drvdata->csdev->mode)) {
val = config->seq_curr_state;
goto out;
}
Expand Down
16 changes: 7 additions & 9 deletions drivers/hwtracing/coresight/coresight-etm4x-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,8 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
{
int ret;
u32 val;
struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);

val = local_cmpxchg(&drvdata->mode, CS_MODE_DISABLED, mode);
val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode);

/* Someone is already using the tracer */
if (val)
Expand All @@ -862,7 +861,7 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,

/* The tracer didn't start */
if (ret)
local_set(&drvdata->mode, CS_MODE_DISABLED);
local_set(&csdev->mode, CS_MODE_DISABLED);

return ret;
}
Expand Down Expand Up @@ -1004,14 +1003,13 @@ static void etm4_disable(struct coresight_device *csdev,
struct perf_event *event)
{
enum cs_mode mode;
struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);

/*
* For as long as the tracer isn't disabled another entity can't
* change its status. As such we can read the status here without
* fearing it will change under us.
*/
mode = local_read(&drvdata->mode);
mode = local_read(&csdev->mode);

switch (mode) {
case CS_MODE_DISABLED:
Expand All @@ -1025,7 +1023,7 @@ static void etm4_disable(struct coresight_device *csdev,
}

if (mode)
local_set(&drvdata->mode, CS_MODE_DISABLED);
local_set(&csdev->mode, CS_MODE_DISABLED);
}

static const struct coresight_ops_source etm4_source_ops = {
Expand Down Expand Up @@ -1663,7 +1661,7 @@ static int etm4_starting_cpu(unsigned int cpu)
if (!etmdrvdata[cpu]->os_unlock)
etm4_os_unlock(etmdrvdata[cpu]);

if (local_read(&etmdrvdata[cpu]->mode))
if (local_read(&etmdrvdata[cpu]->csdev->mode))
etm4_enable_hw(etmdrvdata[cpu]);
spin_unlock(&etmdrvdata[cpu]->spinlock);
return 0;
Expand All @@ -1675,7 +1673,7 @@ static int etm4_dying_cpu(unsigned int cpu)
return 0;

spin_lock(&etmdrvdata[cpu]->spinlock);
if (local_read(&etmdrvdata[cpu]->mode))
if (local_read(&etmdrvdata[cpu]->csdev->mode))
etm4_disable_hw(etmdrvdata[cpu]);
spin_unlock(&etmdrvdata[cpu]->spinlock);
return 0;
Expand Down Expand Up @@ -1833,7 +1831,7 @@ static int etm4_cpu_save(struct etmv4_drvdata *drvdata)
* Save and restore the ETM Trace registers only if
* the ETM is active.
*/
if (local_read(&drvdata->mode) && drvdata->save_state)
if (local_read(&drvdata->csdev->mode) && drvdata->save_state)
ret = __etm4_cpu_save(drvdata);
return ret;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/hwtracing/coresight/coresight-etm4x.h
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ struct etmv4_drvdata {
void __iomem *base;
struct coresight_device *csdev;
spinlock_t spinlock;
local_t mode;
int cpu;
u8 arch;
u8 nr_pe;
Expand Down
20 changes: 9 additions & 11 deletions drivers/hwtracing/coresight/coresight-stm.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ DEFINE_CORESIGHT_DEVLIST(stm_devs, "stm");
* @spinlock: only one at a time pls.
* @chs: the channels accociated to this STM.
* @stm: structure associated to the generic STM interface.
* @mode: this tracer's mode (enum cs_mode), i.e sysFS, or disabled.
* @traceid: value of the current ID for this component.
* @write_bytes: Maximus bytes this STM can write at a time.
* @stmsper: settings for register STMSPER.
Expand All @@ -136,7 +135,6 @@ struct stm_drvdata {
spinlock_t spinlock;
struct channel_space chs;
struct stm_data stm;
local_t mode;
u8 traceid;
u32 write_bytes;
u32 stmsper;
Expand Down Expand Up @@ -201,7 +199,7 @@ static int stm_enable(struct coresight_device *csdev, struct perf_event *event,
if (mode != CS_MODE_SYSFS)
return -EINVAL;

val = local_cmpxchg(&drvdata->mode, CS_MODE_DISABLED, mode);
val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode);

/* Someone is already using the tracer */
if (val)
Expand Down Expand Up @@ -266,7 +264,7 @@ static void stm_disable(struct coresight_device *csdev,
* change its status. As such we can read the status here without
* fearing it will change under us.
*/
if (local_read(&drvdata->mode) == CS_MODE_SYSFS) {
if (local_read(&csdev->mode) == CS_MODE_SYSFS) {
spin_lock(&drvdata->spinlock);
stm_disable_hw(drvdata);
spin_unlock(&drvdata->spinlock);
Expand All @@ -276,7 +274,7 @@ static void stm_disable(struct coresight_device *csdev,

pm_runtime_put(csdev->dev.parent);

local_set(&drvdata->mode, CS_MODE_DISABLED);
local_set(&csdev->mode, CS_MODE_DISABLED);
dev_dbg(&csdev->dev, "STM tracing disabled\n");
}
}
Expand Down Expand Up @@ -373,7 +371,7 @@ static long stm_generic_set_options(struct stm_data *stm_data,
{
struct stm_drvdata *drvdata = container_of(stm_data,
struct stm_drvdata, stm);
if (!(drvdata && local_read(&drvdata->mode)))
if (!(drvdata && local_read(&drvdata->csdev->mode)))
return -EINVAL;

if (channel >= drvdata->numsp)
Expand Down Expand Up @@ -408,7 +406,7 @@ static ssize_t notrace stm_generic_packet(struct stm_data *stm_data,
struct stm_drvdata, stm);
unsigned int stm_flags;

if (!(drvdata && local_read(&drvdata->mode)))
if (!(drvdata && local_read(&drvdata->csdev->mode)))
return -EACCES;

if (channel >= drvdata->numsp)
Expand Down Expand Up @@ -515,7 +513,7 @@ static ssize_t port_select_show(struct device *dev,
struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
unsigned long val;

if (!local_read(&drvdata->mode)) {
if (!local_read(&drvdata->csdev->mode)) {
val = drvdata->stmspscr;
} else {
spin_lock(&drvdata->spinlock);
Expand All @@ -541,7 +539,7 @@ static ssize_t port_select_store(struct device *dev,
spin_lock(&drvdata->spinlock);
drvdata->stmspscr = val;

if (local_read(&drvdata->mode)) {
if (local_read(&drvdata->csdev->mode)) {
CS_UNLOCK(drvdata->base);
/* Process as per ARM's TRM recommendation */
stmsper = readl_relaxed(drvdata->base + STMSPER);
Expand All @@ -562,7 +560,7 @@ static ssize_t port_enable_show(struct device *dev,
struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
unsigned long val;

if (!local_read(&drvdata->mode)) {
if (!local_read(&drvdata->csdev->mode)) {
val = drvdata->stmsper;
} else {
spin_lock(&drvdata->spinlock);
Expand All @@ -588,7 +586,7 @@ static ssize_t port_enable_store(struct device *dev,
spin_lock(&drvdata->spinlock);
drvdata->stmsper = val;

if (local_read(&drvdata->mode)) {
if (local_read(&drvdata->csdev->mode)) {
CS_UNLOCK(drvdata->base);
writel_relaxed(drvdata->stmsper, drvdata->base + STMSPER);
CS_LOCK(drvdata->base);
Expand Down
2 changes: 1 addition & 1 deletion drivers/hwtracing/coresight/coresight-tmc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ static void tmc_shutdown(struct amba_device *adev)

spin_lock_irqsave(&drvdata->spinlock, flags);

if (drvdata->mode == CS_MODE_DISABLED)
if (local_read(&drvdata->csdev->mode) == CS_MODE_DISABLED)
goto out;

if (drvdata->config_type == TMC_CONFIG_TYPE_ETR)
Expand Down
Loading

0 comments on commit 9cae77c

Please sign in to comment.