UIO: Add name attributes for mappings and port regions

If a UIO device has several memory mappings, it can be difficult for userspace
to find the right one. The situation becomes even worse if the UIO driver can
handle different versions of a card that have different numbers of mappings.
Benedikt Spranger has such cards and pointed this out to me. Thanks, Bene!

To address this problem, this patch adds "name" sysfs attributes for each
mapping. Userspace can use these to clearly identify each mapping. The name
string is optional. If a driver doesn't set it, an empty string will be
returned, so this patch won't break existing drivers.

The same problem exists for port region information, so a "name" attribute is
added there, too.

Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Hans J. Koch 2009-01-07 00:15:39 +01:00 committed by Greg Kroah-Hartman
parent 57fee4a58f
commit 8205779114
3 changed files with 51 additions and 4 deletions

View file

@ -41,6 +41,13 @@ GPL version 2.
</abstract> </abstract>
<revhistory> <revhistory>
<revision>
<revnumber>0.8</revnumber>
<date>2008-12-24</date>
<authorinitials>hjk</authorinitials>
<revremark>Added name attributes in mem and portio sysfs directories.
</revremark>
</revision>
<revision> <revision>
<revnumber>0.7</revnumber> <revnumber>0.7</revnumber>
<date>2008-12-23</date> <date>2008-12-23</date>
@ -303,10 +310,17 @@ interested in translating it, please email me
appear if the size of the mapping is not 0. appear if the size of the mapping is not 0.
</para> </para>
<para> <para>
Each <filename>mapX/</filename> directory contains two read-only files Each <filename>mapX/</filename> directory contains four read-only files
that show start address and size of the memory: that show attributes of the memory:
</para> </para>
<itemizedlist> <itemizedlist>
<listitem>
<para>
<filename>name</filename>: A string identifier for this mapping. This
is optional, the string can be empty. Drivers can set this to make it
easier for userspace to find the correct mapping.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
<filename>addr</filename>: The address of memory that can be mapped. <filename>addr</filename>: The address of memory that can be mapped.
@ -366,10 +380,17 @@ offset = N * getpagesize();
<filename>/sys/class/uio/uioX/portio/</filename>. <filename>/sys/class/uio/uioX/portio/</filename>.
</para> </para>
<para> <para>
Each <filename>portX/</filename> directory contains three read-only Each <filename>portX/</filename> directory contains four read-only
files that show start, size, and type of the port region: files that show name, start, size, and type of the port region:
</para> </para>
<itemizedlist> <itemizedlist>
<listitem>
<para>
<filename>name</filename>: A string identifier for this port region.
The string is optional and can be empty. Drivers can set it to make it
easier for userspace to find a certain port region.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
<filename>start</filename>: The first port of this region. <filename>start</filename>: The first port of this region.

View file

@ -61,6 +61,14 @@ struct uio_map {
}; };
#define to_map(map) container_of(map, struct uio_map, kobj) #define to_map(map) container_of(map, struct uio_map, kobj)
static ssize_t map_name_show(struct uio_mem *mem, char *buf)
{
if (unlikely(!mem->name))
mem->name = "";
return sprintf(buf, "%s\n", mem->name);
}
static ssize_t map_addr_show(struct uio_mem *mem, char *buf) static ssize_t map_addr_show(struct uio_mem *mem, char *buf)
{ {
return sprintf(buf, "0x%lx\n", mem->addr); return sprintf(buf, "0x%lx\n", mem->addr);
@ -82,6 +90,8 @@ struct map_sysfs_entry {
ssize_t (*store)(struct uio_mem *, const char *, size_t); ssize_t (*store)(struct uio_mem *, const char *, size_t);
}; };
static struct map_sysfs_entry name_attribute =
__ATTR(name, S_IRUGO, map_name_show, NULL);
static struct map_sysfs_entry addr_attribute = static struct map_sysfs_entry addr_attribute =
__ATTR(addr, S_IRUGO, map_addr_show, NULL); __ATTR(addr, S_IRUGO, map_addr_show, NULL);
static struct map_sysfs_entry size_attribute = static struct map_sysfs_entry size_attribute =
@ -90,6 +100,7 @@ static struct map_sysfs_entry offset_attribute =
__ATTR(offset, S_IRUGO, map_offset_show, NULL); __ATTR(offset, S_IRUGO, map_offset_show, NULL);
static struct attribute *attrs[] = { static struct attribute *attrs[] = {
&name_attribute.attr,
&addr_attribute.attr, &addr_attribute.attr,
&size_attribute.attr, &size_attribute.attr,
&offset_attribute.attr, &offset_attribute.attr,
@ -133,6 +144,14 @@ struct uio_portio {
}; };
#define to_portio(portio) container_of(portio, struct uio_portio, kobj) #define to_portio(portio) container_of(portio, struct uio_portio, kobj)
static ssize_t portio_name_show(struct uio_port *port, char *buf)
{
if (unlikely(!port->name))
port->name = "";
return sprintf(buf, "%s\n", port->name);
}
static ssize_t portio_start_show(struct uio_port *port, char *buf) static ssize_t portio_start_show(struct uio_port *port, char *buf)
{ {
return sprintf(buf, "0x%lx\n", port->start); return sprintf(buf, "0x%lx\n", port->start);
@ -159,6 +178,8 @@ struct portio_sysfs_entry {
ssize_t (*store)(struct uio_port *, const char *, size_t); ssize_t (*store)(struct uio_port *, const char *, size_t);
}; };
static struct portio_sysfs_entry portio_name_attribute =
__ATTR(name, S_IRUGO, portio_name_show, NULL);
static struct portio_sysfs_entry portio_start_attribute = static struct portio_sysfs_entry portio_start_attribute =
__ATTR(start, S_IRUGO, portio_start_show, NULL); __ATTR(start, S_IRUGO, portio_start_show, NULL);
static struct portio_sysfs_entry portio_size_attribute = static struct portio_sysfs_entry portio_size_attribute =
@ -167,6 +188,7 @@ static struct portio_sysfs_entry portio_porttype_attribute =
__ATTR(porttype, S_IRUGO, portio_porttype_show, NULL); __ATTR(porttype, S_IRUGO, portio_porttype_show, NULL);
static struct attribute *portio_attrs[] = { static struct attribute *portio_attrs[] = {
&portio_name_attribute.attr,
&portio_start_attribute.attr, &portio_start_attribute.attr,
&portio_size_attribute.attr, &portio_size_attribute.attr,
&portio_porttype_attribute.attr, &portio_porttype_attribute.attr,

View file

@ -22,6 +22,7 @@ struct uio_map;
/** /**
* struct uio_mem - description of a UIO memory region * struct uio_mem - description of a UIO memory region
* @name: name of the memory region for identification
* @addr: address of the device's memory * @addr: address of the device's memory
* @size: size of IO * @size: size of IO
* @memtype: type of memory addr points to * @memtype: type of memory addr points to
@ -29,6 +30,7 @@ struct uio_map;
* @map: for use by the UIO core only. * @map: for use by the UIO core only.
*/ */
struct uio_mem { struct uio_mem {
const char *name;
unsigned long addr; unsigned long addr;
unsigned long size; unsigned long size;
int memtype; int memtype;
@ -42,12 +44,14 @@ struct uio_portio;
/** /**
* struct uio_port - description of a UIO port region * struct uio_port - description of a UIO port region
* @name: name of the port region for identification
* @start: start of port region * @start: start of port region
* @size: size of port region * @size: size of port region
* @porttype: type of port (see UIO_PORT_* below) * @porttype: type of port (see UIO_PORT_* below)
* @portio: for use by the UIO core only. * @portio: for use by the UIO core only.
*/ */
struct uio_port { struct uio_port {
const char *name;
unsigned long start; unsigned long start;
unsigned long size; unsigned long size;
int porttype; int porttype;