Commit 5e7263d3 authored by Federico Vaga's avatar Federico Vaga

sysfs: new std attribute 'version' for device, trigger and buffer

The 'version' attribute is a standard attribute. It is placed at
the last position of the standard attribute array. In this way, it is
easier to identify it in an hexdump stream because it is the last
standard attribute. At the moment the last index of standard attributes
array is 15, but in a far away future may change.

The aim of this attribute is to identify the version of an attribute set
of a ZIO object (device, trigger, buffer). During development the set
of attribute exported by a driver may change. This attribute must be
used to notify these changes to user-space programs.
The attribute is optional.

When used in a device, we suggest to place it at device level.
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
Acked-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ab8ad967
......@@ -83,6 +83,11 @@ static int __init zio_init(void)
{
int err;
/* The attribute 'version' must be the last attributes */
BUILD_BUG_ON(_ZIO_DEV_ATTR_STD_NUM != ZIO_ATTR_VERSION + 1);
BUILD_BUG_ON(_ZIO_TRG_ATTR_STD_NUM != ZIO_ATTR_VERSION + 1);
BUILD_BUG_ON(_ZIO_BUF_ATTR_STD_NUM != ZIO_ATTR_VERSION + 1);
/* Some compile-time checks, so developers are free to hack around */
BUILD_BUG_ON(_ZIO_DEV_ATTR_STD_NUM != ARRAY_SIZE(zio_zdev_attr_names));
BUILD_BUG_ON(_ZIO_BUF_ATTR_STD_NUM != ARRAY_SIZE(zio_zbuf_attr_names));
......
......@@ -15,9 +15,16 @@
#include <linux/zio.h>
#include <linux/zio-buffer.h>
#define ZZERO_VERSION ZIO_HEX_VERSION(1, 1, 0)
ZIO_PARAM_TRIGGER(zzero_trigger);
ZIO_PARAM_BUFFER(zzero_buffer);
ZIO_ATTR_DEFINE_STD(ZIO_DEV, zzero_zattr_dev) = {
ZIO_SET_ATTR_VERSION(ZZERO_VERSION),
};
ZIO_ATTR_DEFINE_STD(ZIO_DEV, zzero_zattr_cset8) = {
/* 8 bit -> ssize = 1 */
ZIO_ATTR(zdev, ZIO_ATTR_NBITS, ZIO_RO_PERM, 0, 8),
......@@ -154,6 +161,9 @@ static struct zio_device zzero_tmpl = {
.cset = zzero_cset,
.n_cset = ARRAY_SIZE(zzero_cset),
.s_op = &zzero_sysfs_ops,
.zattr_set = {
.std_zattr = zzero_zattr_dev,
}
};
static struct zio_device *zzero_dev;
......
......@@ -71,24 +71,37 @@ struct zio_attribute_set {
unsigned int n_ext_attr;
};
#define ZIO_ATTR_VERSION (ZIO_MAX_STD_ATTR - 1)
enum zio_dev_std_attr {
ZIO_ATTR_NBITS, /* number of bits per sample */
ZIO_ATTR_GAIN, /* gain for signal, integer in 0.001 steps */
ZIO_ATTR_OFFSET, /* microvolts */
ZIO_ATTR_MAXRATE, /* hertz */
ZIO_ATTR_VREFTYPE, /* source of Vref (0 = default) */
_ZIO_DEV_ATTR_STD_NUM, /* used to size arrays */
/* Specials attributes */
ZIO_ATTR_DEV_VERSION = ZIO_ATTR_VERSION, /* attribute set version */
_ZIO_DEV_ATTR_STD_NUM, /* used to size arrays and check ZIO */
};
enum zio_trg_std_attr {
ZIO_ATTR_TRIG_N_SHOTS = 0,/* trigger programmed shots (0: infinite) */
ZIO_ATTR_TRIG_POST_SAMP, /* samples after trigger fire */
ZIO_ATTR_TRIG_PRE_SAMP, /* samples before trigger fire */
_ZIO_TRG_ATTR_STD_NUM, /* used to size arrays */
/* Specials attributes */
ZIO_ATTR_TRIG_VERSION = ZIO_ATTR_VERSION, /* attribute set version */
_ZIO_TRG_ATTR_STD_NUM, /* used to size arrays and check ZIO */
};
enum zio_buf_std_attr {
ZIO_ATTR_ZBUF_MAXLEN = 0, /* max number of element in buffer */
ZIO_ATTR_ZBUF_MAXKB, /* max number of kB in buffer */
_ZIO_BUF_ATTR_STD_NUM, /* used to size arrays */
/* Specials attributes */
ZIO_ATTR_ZBUF_VERSION = ZIO_ATTR_VERSION, /* attribute set version */
_ZIO_BUF_ATTR_STD_NUM, /* used to size arrays and check ZIO */
};
enum zio_chn_bin_attr {
ZIO_BIN_CTRL = 0, /* current control */
......@@ -107,7 +120,6 @@ extern const char zio_zbuf_attr_names[_ZIO_BUF_ATTR_STD_NUM][ZIO_NAME_LEN];
* @ZIO_ATTR: define a zio attribute
* @ZIO_ATTR_EXT: define a zio extended attribute
* @ZIO_PARAM_EXT: define a zio attribute parameter (not included in ctrl)
*/
#define ZIO_ATTR(zobj, _type, _mode, _add, _val)[_type] = { \
.attr = { \
......@@ -133,5 +145,24 @@ extern const char zio_zbuf_attr_names[_ZIO_BUF_ATTR_STD_NUM][ZIO_NAME_LEN];
.flags = 0, \
}
/*
* This macro defines the standard attribute 'version' for an attribute_set of
* a zio object. In the macro there is an explicit reference to the device
* (zdev) but it does not care because the show function and the sysfs name it
* is the same for every ZIO object.
*
* The ZIO core handles directly this attribute without useing the driver,
* trigger or buffer sysfs operations
*/
#define ZIO_SET_ATTR_VERSION(_hexversion) \
ZIO_ATTR(zdev, ZIO_ATTR_VERSION, ZIO_RO_PERM, 0, _hexversion)
/*
* The attribute set version is in the format (a.b c). Fields 'a' and 'b' are
* the major and minor version number. The field 'c' is free choice of the
* driver developer
*/
#define ZIO_HEX_VERSION(_a, _b, _c) (((_a & 0xFF) << 24) + \
((_b & 0xFF) << 16) + (_c & 0xFFFF))
#endif /* ZIO_SYSFS_H_ */
......@@ -34,6 +34,7 @@ const char zio_zdev_attr_names[_ZIO_DEV_ATTR_STD_NUM][ZIO_NAME_LEN] = {
[ZIO_ATTR_NBITS] = "resolution-bits",
[ZIO_ATTR_MAXRATE] = "max-sample-rate",
[ZIO_ATTR_VREFTYPE] = "vref-src",
[ZIO_ATTR_DEV_VERSION] = "version",
};
EXPORT_SYMBOL(zio_zdev_attr_names);
......@@ -41,12 +42,14 @@ const char zio_trig_attr_names[_ZIO_TRG_ATTR_STD_NUM][ZIO_NAME_LEN] = {
[ZIO_ATTR_TRIG_N_SHOTS] = "nshots",
[ZIO_ATTR_TRIG_PRE_SAMP] = "pre-samples",
[ZIO_ATTR_TRIG_POST_SAMP] = "post-samples",
[ZIO_ATTR_TRIG_VERSION] = "version",
};
EXPORT_SYMBOL(zio_trig_attr_names);
const char zio_zbuf_attr_names[_ZIO_BUF_ATTR_STD_NUM][ZIO_NAME_LEN] = {
[ZIO_ATTR_ZBUF_MAXLEN] = "max-buffer-len",
[ZIO_ATTR_ZBUF_MAXKB] = "max-buffer-kb",
[ZIO_ATTR_ZBUF_VERSION] = "version",
};
EXPORT_SYMBOL(zio_zbuf_attr_names);
......@@ -859,6 +862,24 @@ struct device_type bi_device_type = {
.groups = def_bi_groups_ptr,
};
static ssize_t zio_show_attr_version(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct zio_attribute *zattr = to_zio_zattr(attr);
unsigned int major, minor, flags;
major = (zattr->value & 0xFF000000) >> 24;
minor = (zattr->value & 0x00FF0000) >> 16;
flags = (zattr->value & 0xFFFF);
if (flags)
return sprintf(buf, "%d.%d 0x%04x\n", major, minor, flags);
else
return sprintf(buf, "%d.%d\n", major, minor);
}
int __check_dev_zattr(struct zio_attribute_set *parent,
struct zio_attribute_set *this)
{
......@@ -959,9 +980,13 @@ int zattr_set_create(struct zio_obj_head *head,
case 0:
/* valid attribute */
groups[g]->attrs[a_count++] = attr;
zattr_set->std_zattr[i].attr.show = zattr_show;
zattr_set->std_zattr[i].attr.store = zattr_store;
zattr_set->std_zattr[i].s_op = s_op;
if (i == ZIO_ATTR_VERSION) {
zattr->attr.show = zio_show_attr_version;
} else { /* All other attributes */
zattr_set->std_zattr[i].attr.show = zattr_show;
zattr_set->std_zattr[i].attr.store = zattr_store;
zattr_set->std_zattr[i].s_op = s_op;
}
zattr_set->std_zattr[i].index = i;
break;
case -EINVAL: /* unused std attribute */
......
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