coresight: etm4x: Hide sysfs attributes for unavailable registers
Some of the management registers in ETMv4.x are not accessible via system register instructions. Thus we must hide the sysfs files exposing them to the userspace, to prevent system crashes. This patch adds an is_visible() routine to control the visibility at runtime for the registers that may not be accessed. Link: https://lore.kernel.org/r/20210110224850.1880240-13-suzuki.poulose@arm.com Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Mike Leach <mike.leach@linaro.org> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Link: https://lore.kernel.org/r/20210201181351.1475223-15-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
03336d0f4d
commit
91b9f01854
@ -2370,6 +2370,56 @@ static ssize_t coresight_etm4x_reg_show(struct device *dev,
|
||||
return scnprintf(buf, PAGE_SIZE, "0x%x\n", val);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
etm4x_register_implemented(struct etmv4_drvdata *drvdata, u32 offset)
|
||||
{
|
||||
switch (offset) {
|
||||
ETM4x_SYSREG_LIST_CASES
|
||||
/*
|
||||
* Registers accessible via system instructions are always
|
||||
* implemented.
|
||||
*/
|
||||
return true;
|
||||
ETM4x_MMAP_LIST_CASES
|
||||
/*
|
||||
* Registers accessible only via memory-mapped registers
|
||||
* must not be accessed via system instructions.
|
||||
* We cannot access the drvdata->csdev here, as this
|
||||
* function is called during the device creation, via
|
||||
* coresight_register() and the csdev is not initialized
|
||||
* until that is done. So rely on the drvdata->base to
|
||||
* detect if we have a memory mapped access.
|
||||
*/
|
||||
return !!drvdata->base;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hide the ETM4x registers that may not be available on the
|
||||
* hardware.
|
||||
* There are certain management registers unavailable via system
|
||||
* instructions. Make those sysfs attributes hidden on such
|
||||
* systems.
|
||||
*/
|
||||
static umode_t
|
||||
coresight_etm4x_attr_reg_implemented(struct kobject *kobj,
|
||||
struct attribute *attr, int unused)
|
||||
{
|
||||
struct device *dev = kobj_to_dev(kobj);
|
||||
struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent);
|
||||
struct device_attribute *d_attr;
|
||||
u32 offset;
|
||||
|
||||
d_attr = container_of(attr, struct device_attribute, attr);
|
||||
offset = coresight_etm4x_attr_to_offset(d_attr);
|
||||
|
||||
if (etm4x_register_implemented(drvdata, offset))
|
||||
return attr->mode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define coresight_etm4x_reg(name, offset) \
|
||||
&((struct dev_ext_attribute[]) { \
|
||||
{ \
|
||||
@ -2417,6 +2467,7 @@ static const struct attribute_group coresight_etmv4_group = {
|
||||
};
|
||||
|
||||
static const struct attribute_group coresight_etmv4_mgmt_group = {
|
||||
.is_visible = coresight_etm4x_attr_reg_implemented,
|
||||
.attrs = coresight_etmv4_mgmt_attrs,
|
||||
.name = "mgmt",
|
||||
};
|
||||
|
@ -157,6 +157,9 @@
|
||||
#define CASE_WRITE(val, x) \
|
||||
case (x): { write_etm4x_sysreg_const_offset((val), (x)); break; }
|
||||
|
||||
#define CASE_NOP(__unused, x) \
|
||||
case (x): /* fall through */
|
||||
|
||||
/* List of registers accessible via System instructions */
|
||||
#define ETM_SYSREG_LIST(op, val) \
|
||||
CASE_##op((val), TRCPRGCTLR) \
|
||||
@ -369,6 +372,9 @@
|
||||
#define ETM4x_READ_SYSREG_CASES(res) ETM_SYSREG_LIST(READ, (res))
|
||||
#define ETM4x_WRITE_SYSREG_CASES(val) ETM_SYSREG_LIST(WRITE, (val))
|
||||
|
||||
#define ETM4x_SYSREG_LIST_CASES ETM_SYSREG_LIST(NOP, __unused)
|
||||
#define ETM4x_MMAP_LIST_CASES ETM_MMAP_LIST(NOP, __unused)
|
||||
|
||||
#define read_etm4x_sysreg_offset(offset, _64bit) \
|
||||
({ \
|
||||
u64 __val; \
|
||||
|
Loading…
Reference in New Issue
Block a user