Commit fbca79e5 authored by James Clark's avatar James Clark Committed by Mathieu Poirier

coresight: cti-sysfs: Re-use same functions for similar sysfs register accessors

Currently each accessor macro creates an identical function which wastes
space in the text area and pollutes the ftrace function name list.
Change it so that the same function is used, but the register to access
is passed in as parameter rather than baked into each function.

Note that only the single accessor is used here and not
csdev_access_relaxed_read_pair() like in the previous commit, so
so a single unsigned offset value is stored instead.
Signed-off-by: default avatarJames Clark <james.clark@arm.com>
Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
Link: https://lore.kernel.org/r/20220830172614.340962-5-james.clark@arm.comSigned-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
parent 08e9fa5f
...@@ -163,48 +163,82 @@ static struct attribute *coresight_cti_attrs[] = { ...@@ -163,48 +163,82 @@ static struct attribute *coresight_cti_attrs[] = {
/* register based attributes */ /* register based attributes */
/* macro to access RO registers with power check only (no enable check). */ /* Read registers with power check only (no enable check). */
static ssize_t coresight_cti_reg_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
struct cs_off_attribute *cti_attr = container_of(attr, struct cs_off_attribute, attr);
u32 val = 0;
pm_runtime_get_sync(dev->parent);
spin_lock(&drvdata->spinlock);
if (drvdata->config.hw_powered)
val = readl_relaxed(drvdata->base + cti_attr->off);
spin_unlock(&drvdata->spinlock);
pm_runtime_put_sync(dev->parent);
return sysfs_emit(buf, "0x%x\n", val);
}
/* Write registers with power check only (no enable check). */
static ssize_t coresight_cti_reg_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
struct cs_off_attribute *cti_attr = container_of(attr, struct cs_off_attribute, attr);
unsigned long val = 0;
if (kstrtoul(buf, 0, &val))
return -EINVAL;
pm_runtime_get_sync(dev->parent);
spin_lock(&drvdata->spinlock);
if (drvdata->config.hw_powered)
cti_write_single_reg(drvdata, cti_attr->off, val);
spin_unlock(&drvdata->spinlock);
pm_runtime_put_sync(dev->parent);
return size;
}
#define coresight_cti_reg(name, offset) \ #define coresight_cti_reg(name, offset) \
static ssize_t name##_show(struct device *dev, \ (&((struct cs_off_attribute[]) { \
struct device_attribute *attr, char *buf) \ { \
{ \ __ATTR(name, 0444, coresight_cti_reg_show, NULL), \
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent); \ offset \
u32 val = 0; \ } \
pm_runtime_get_sync(dev->parent); \ })[0].attr.attr)
spin_lock(&drvdata->spinlock); \
if (drvdata->config.hw_powered) \
val = readl_relaxed(drvdata->base + offset); \
spin_unlock(&drvdata->spinlock); \
pm_runtime_put_sync(dev->parent); \
return sprintf(buf, "0x%x\n", val); \
} \
static DEVICE_ATTR_RO(name)
/* coresight management registers */ #define coresight_cti_reg_rw(name, offset) \
coresight_cti_reg(devaff0, CTIDEVAFF0); (&((struct cs_off_attribute[]) { \
coresight_cti_reg(devaff1, CTIDEVAFF1); { \
coresight_cti_reg(authstatus, CORESIGHT_AUTHSTATUS); __ATTR(name, 0644, coresight_cti_reg_show, \
coresight_cti_reg(devarch, CORESIGHT_DEVARCH); coresight_cti_reg_store), \
coresight_cti_reg(devid, CORESIGHT_DEVID); offset \
coresight_cti_reg(devtype, CORESIGHT_DEVTYPE); } \
coresight_cti_reg(pidr0, CORESIGHT_PERIPHIDR0); })[0].attr.attr)
coresight_cti_reg(pidr1, CORESIGHT_PERIPHIDR1);
coresight_cti_reg(pidr2, CORESIGHT_PERIPHIDR2); #define coresight_cti_reg_wo(name, offset) \
coresight_cti_reg(pidr3, CORESIGHT_PERIPHIDR3); (&((struct cs_off_attribute[]) { \
coresight_cti_reg(pidr4, CORESIGHT_PERIPHIDR4); { \
__ATTR(name, 0200, NULL, coresight_cti_reg_store), \
offset \
} \
})[0].attr.attr)
/* coresight management registers */
static struct attribute *coresight_cti_mgmt_attrs[] = { static struct attribute *coresight_cti_mgmt_attrs[] = {
&dev_attr_devaff0.attr, coresight_cti_reg(devaff0, CTIDEVAFF0),
&dev_attr_devaff1.attr, coresight_cti_reg(devaff1, CTIDEVAFF1),
&dev_attr_authstatus.attr, coresight_cti_reg(authstatus, CORESIGHT_AUTHSTATUS),
&dev_attr_devarch.attr, coresight_cti_reg(devarch, CORESIGHT_DEVARCH),
&dev_attr_devid.attr, coresight_cti_reg(devid, CORESIGHT_DEVID),
&dev_attr_devtype.attr, coresight_cti_reg(devtype, CORESIGHT_DEVTYPE),
&dev_attr_pidr0.attr, coresight_cti_reg(pidr0, CORESIGHT_PERIPHIDR0),
&dev_attr_pidr1.attr, coresight_cti_reg(pidr1, CORESIGHT_PERIPHIDR1),
&dev_attr_pidr2.attr, coresight_cti_reg(pidr2, CORESIGHT_PERIPHIDR2),
&dev_attr_pidr3.attr, coresight_cti_reg(pidr3, CORESIGHT_PERIPHIDR3),
&dev_attr_pidr4.attr, coresight_cti_reg(pidr4, CORESIGHT_PERIPHIDR4),
NULL, NULL,
}; };
...@@ -454,86 +488,11 @@ static ssize_t apppulse_store(struct device *dev, ...@@ -454,86 +488,11 @@ static ssize_t apppulse_store(struct device *dev,
} }
static DEVICE_ATTR_WO(apppulse); static DEVICE_ATTR_WO(apppulse);
coresight_cti_reg(triginstatus, CTITRIGINSTATUS);
coresight_cti_reg(trigoutstatus, CTITRIGOUTSTATUS);
coresight_cti_reg(chinstatus, CTICHINSTATUS);
coresight_cti_reg(choutstatus, CTICHOUTSTATUS);
/* /*
* Define CONFIG_CORESIGHT_CTI_INTEGRATION_REGS to enable the access to the * Define CONFIG_CORESIGHT_CTI_INTEGRATION_REGS to enable the access to the
* integration control registers. Normally only used to investigate connection * integration control registers. Normally only used to investigate connection
* data. * data.
*/ */
#ifdef CONFIG_CORESIGHT_CTI_INTEGRATION_REGS
/* macro to access RW registers with power check only (no enable check). */
#define coresight_cti_reg_rw(name, offset) \
static ssize_t name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent); \
u32 val = 0; \
pm_runtime_get_sync(dev->parent); \
spin_lock(&drvdata->spinlock); \
if (drvdata->config.hw_powered) \
val = readl_relaxed(drvdata->base + offset); \
spin_unlock(&drvdata->spinlock); \
pm_runtime_put_sync(dev->parent); \
return sprintf(buf, "0x%x\n", val); \
} \
\
static ssize_t name##_store(struct device *dev, \
struct device_attribute *attr, \
const char *buf, size_t size) \
{ \
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent); \
unsigned long val = 0; \
if (kstrtoul(buf, 0, &val)) \
return -EINVAL; \
\
pm_runtime_get_sync(dev->parent); \
spin_lock(&drvdata->spinlock); \
if (drvdata->config.hw_powered) \
cti_write_single_reg(drvdata, offset, val); \
spin_unlock(&drvdata->spinlock); \
pm_runtime_put_sync(dev->parent); \
return size; \
} \
static DEVICE_ATTR_RW(name)
/* macro to access WO registers with power check only (no enable check). */
#define coresight_cti_reg_wo(name, offset) \
static ssize_t name##_store(struct device *dev, \
struct device_attribute *attr, \
const char *buf, size_t size) \
{ \
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent); \
unsigned long val = 0; \
if (kstrtoul(buf, 0, &val)) \
return -EINVAL; \
\
pm_runtime_get_sync(dev->parent); \
spin_lock(&drvdata->spinlock); \
if (drvdata->config.hw_powered) \
cti_write_single_reg(drvdata, offset, val); \
spin_unlock(&drvdata->spinlock); \
pm_runtime_put_sync(dev->parent); \
return size; \
} \
static DEVICE_ATTR_WO(name)
coresight_cti_reg_rw(itchout, ITCHOUT);
coresight_cti_reg_rw(ittrigout, ITTRIGOUT);
coresight_cti_reg_rw(itctrl, CORESIGHT_ITCTRL);
coresight_cti_reg_wo(itchinack, ITCHINACK);
coresight_cti_reg_wo(ittriginack, ITTRIGINACK);
coresight_cti_reg(ittrigin, ITTRIGIN);
coresight_cti_reg(itchin, ITCHIN);
coresight_cti_reg(itchoutack, ITCHOUTACK);
coresight_cti_reg(ittrigoutack, ITTRIGOUTACK);
#endif /* CORESIGHT_CTI_INTEGRATION_REGS */
static struct attribute *coresight_cti_regs_attrs[] = { static struct attribute *coresight_cti_regs_attrs[] = {
&dev_attr_inout_sel.attr, &dev_attr_inout_sel.attr,
&dev_attr_inen.attr, &dev_attr_inen.attr,
...@@ -544,20 +503,20 @@ static struct attribute *coresight_cti_regs_attrs[] = { ...@@ -544,20 +503,20 @@ static struct attribute *coresight_cti_regs_attrs[] = {
&dev_attr_appset.attr, &dev_attr_appset.attr,
&dev_attr_appclear.attr, &dev_attr_appclear.attr,
&dev_attr_apppulse.attr, &dev_attr_apppulse.attr,
&dev_attr_triginstatus.attr, coresight_cti_reg(triginstatus, CTITRIGINSTATUS),
&dev_attr_trigoutstatus.attr, coresight_cti_reg(trigoutstatus, CTITRIGOUTSTATUS),
&dev_attr_chinstatus.attr, coresight_cti_reg(chinstatus, CTICHINSTATUS),
&dev_attr_choutstatus.attr, coresight_cti_reg(choutstatus, CTICHOUTSTATUS),
#ifdef CONFIG_CORESIGHT_CTI_INTEGRATION_REGS #ifdef CONFIG_CORESIGHT_CTI_INTEGRATION_REGS
&dev_attr_itctrl.attr, coresight_cti_reg_rw(itctrl, CORESIGHT_ITCTRL),
&dev_attr_ittrigin.attr, coresight_cti_reg(ittrigin, ITTRIGIN),
&dev_attr_itchin.attr, coresight_cti_reg(itchin, ITCHIN),
&dev_attr_ittrigout.attr, coresight_cti_reg_rw(ittrigout, ITTRIGOUT),
&dev_attr_itchout.attr, coresight_cti_reg_rw(itchout, ITCHOUT),
&dev_attr_itchoutack.attr, coresight_cti_reg(itchoutack, ITCHOUTACK),
&dev_attr_ittrigoutack.attr, coresight_cti_reg(ittrigoutack, ITTRIGOUTACK),
&dev_attr_ittriginack.attr, coresight_cti_reg_wo(ittriginack, ITTRIGINACK),
&dev_attr_itchinack.attr, coresight_cti_reg_wo(itchinack, ITCHINACK),
#endif #endif
NULL, NULL,
}; };
......
...@@ -45,6 +45,11 @@ struct cs_pair_attribute { ...@@ -45,6 +45,11 @@ struct cs_pair_attribute {
s32 hi_off; s32 hi_off;
}; };
struct cs_off_attribute {
struct device_attribute attr;
u32 off;
};
extern ssize_t coresight_simple_show(struct device *_dev, extern ssize_t coresight_simple_show(struct device *_dev,
struct device_attribute *attr, char *buf); struct device_attribute *attr, char *buf);
......
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