Commit 2e9f3416 authored by Federico Vaga's avatar Federico Vaga

sysfs: add channel's binary attribute 'address'

address is a default ZIO binary attribute which return the channel
address structure zio_addr.
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
Acked-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 8ad7f877
......@@ -89,6 +89,11 @@ enum zio_buf_std_attr {
ZIO_ATTR_ZBUF_MAXKB, /* max number of kB in buffer */
_ZIO_BUF_ATTR_STD_NUM, /* used to size arrays */
};
enum zio_chn_bin_attr {
ZIO_BIN_CTRL = 0, /* current control */
ZIO_BIN_ADDR, /* address */
__ZIO_BIN_ATTR_NUM,
};
extern const char zio_zdev_attr_names[_ZIO_DEV_ATTR_STD_NUM][ZIO_NAME_LEN];
extern const char zio_trig_attr_names[_ZIO_TRG_ATTR_STD_NUM][ZIO_NAME_LEN];
......
......@@ -543,7 +543,7 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t)
{
struct zio_control *ctrl;
struct zio_bi *bi;
int err;
int err, i;
pr_debug("%s:%d\n", __func__, __LINE__);
if (!chan)
......@@ -597,17 +597,19 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t)
if (err)
goto out_ctrl_bits;
if (ZIO_HAS_BINARY_CONTROL) {
/* Create the sysfs binary file for the current control */
err = sysfs_create_bin_file(&chan->head.dev.kobj,
&zio_attr_cur_ctrl);
if (err)
goto out_bin_attr;
for (i = 0; i < __ZIO_BIN_ATTR_NUM; ++i) {
/* Create the sysfs binary file for the current control */
err = sysfs_create_bin_file(&chan->head.dev.kobj,
&zio_bin_attr[i]);
if (err)
goto out_bin_attr;
}
}
/* Create buffer */
bi = __bi_create_and_init(chan->cset->zbuf, chan);
if (IS_ERR(bi)) {
err = PTR_ERR(bi);
goto out_buf_create;
goto out_bin_attr;
}
err = __bi_register(chan->cset->zbuf, chan, bi, "buffer");
if (err)
......@@ -625,10 +627,13 @@ out_cdev_create:
__bi_unregister(chan->cset->zbuf, bi);
out_buf_reg:
__bi_destroy(chan->cset->zbuf, bi);
out_buf_create:
if (ZIO_HAS_BINARY_CONTROL)
sysfs_remove_bin_file(&chan->head.dev.kobj, &zio_attr_cur_ctrl);
out_bin_attr:
if (ZIO_HAS_BINARY_CONTROL) {
while (i--)
sysfs_remove_bin_file(&chan->head.dev.kobj,
&zio_bin_attr[i]);
}
device_unregister(&chan->head.dev);
out_ctrl_bits:
zio_free_control(ctrl);
......@@ -643,6 +648,8 @@ out_zattr_copy:
static void chan_unregister(struct zio_channel *chan)
{
int i;
pr_debug("%s:%d\n", __func__, __LINE__);
if (!chan)
return;
......@@ -651,7 +658,9 @@ static void chan_unregister(struct zio_channel *chan)
__bi_unregister(chan->cset->zbuf, chan->bi);
__bi_destroy(chan->cset->zbuf, chan->bi);
if (ZIO_HAS_BINARY_CONTROL)
sysfs_remove_bin_file(&chan->head.dev.kobj, &zio_attr_cur_ctrl);
for (i = 0; i < __ZIO_BIN_ATTR_NUM; ++i)
sysfs_remove_bin_file(&chan->head.dev.kobj,
&zio_bin_attr[i]);
device_unregister(&chan->head.dev);
zio_free_control(chan->current_ctrl);
zattr_set_remove(&chan->head);
......
......@@ -661,11 +661,43 @@ ssize_t zobj_read_cur_ctrl(struct file *file,struct kobject *kobj,
return count;
}
struct bin_attribute zio_attr_cur_ctrl = {
.attr = { .name = "current-control", .mode = 0444, },
.size = __ZIO_CONTROL_SIZE, /* To be changed at runtime for TLV */
.read = zobj_read_cur_ctrl,
static ssize_t zobj_show_address(struct file *file,struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct zio_channel *chan;
if (off >= bin_attr->size)
return 0;
/* This file must be read entirely */
if (off != 0)
return -ESPIPE; /* Illegal seek */
if (count < bin_attr->size)
return -EINVAL;
if (count > bin_attr->size)
count = bin_attr->size;
chan = to_zio_chan(container_of(kobj, struct device, kobj));
memcpy(buf, &chan->current_ctrl->addr, count); /* FIXME: lock */
return count;
}
struct bin_attribute zio_bin_attr[] = {
[ZIO_BIN_CTRL] = {
.attr = { .name = "current-control", .mode = ZIO_RO_PERM, },
.size = __ZIO_CONTROL_SIZE, /* changed at runtime for TLV */
.read = zobj_read_cur_ctrl,
},
[ZIO_BIN_ADDR] = {
.attr = { .name = "address", .mode = ZIO_RO_PERM, },
.size = sizeof(struct zio_addr),
.read = zobj_show_address,
}
};
#endif /* ZIO_HAS_BINARY_CONTROL */
/* This is only for internal use (DAN == default attribute name) */
......
zio-dump
zio-cat-file
test-dtc
\ No newline at end of file
test-dtc
......@@ -16,7 +16,7 @@ extern struct device_type cset_device_type;
extern struct device_type chan_device_type;
extern struct device_type ti_device_type;
extern struct device_type bi_device_type;
extern struct bin_attribute zio_attr_cur_ctrl;
extern struct bin_attribute zio_bin_attr[];
/* This list is used in the core to keep track of registered objects */
struct zio_object_list {
......
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