Commit 8205779114e8f612549d191f8e151526a74ab9f2

Authored by Hans J. Koch
Committed by Greg Kroah-Hartman
1 parent 57fee4a58f

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>

Showing 3 changed files with 51 additions and 4 deletions Side-by-side Diff

Documentation/DocBook/uio-howto.tmpl
... ... @@ -42,6 +42,13 @@
42 42  
43 43 <revhistory>
44 44 <revision>
  45 + <revnumber>0.8</revnumber>
  46 + <date>2008-12-24</date>
  47 + <authorinitials>hjk</authorinitials>
  48 + <revremark>Added name attributes in mem and portio sysfs directories.
  49 + </revremark>
  50 + </revision>
  51 + <revision>
45 52 <revnumber>0.7</revnumber>
46 53 <date>2008-12-23</date>
47 54 <authorinitials>hjk</authorinitials>
48 55  
... ... @@ -303,12 +310,19 @@
303 310 appear if the size of the mapping is not 0.
304 311 </para>
305 312 <para>
306   - Each <filename>mapX/</filename> directory contains two read-only files
307   - that show start address and size of the memory:
  313 + Each <filename>mapX/</filename> directory contains four read-only files
  314 + that show attributes of the memory:
308 315 </para>
309 316 <itemizedlist>
310 317 <listitem>
311 318 <para>
  319 + <filename>name</filename>: A string identifier for this mapping. This
  320 + is optional, the string can be empty. Drivers can set this to make it
  321 + easier for userspace to find the correct mapping.
  322 + </para>
  323 +</listitem>
  324 +<listitem>
  325 + <para>
312 326 <filename>addr</filename>: The address of memory that can be mapped.
313 327 </para>
314 328 </listitem>
315 329  
... ... @@ -366,10 +380,17 @@
366 380 <filename>/sys/class/uio/uioX/portio/</filename>.
367 381 </para>
368 382 <para>
369   - Each <filename>portX/</filename> directory contains three read-only
370   - files that show start, size, and type of the port region:
  383 + Each <filename>portX/</filename> directory contains four read-only
  384 + files that show name, start, size, and type of the port region:
371 385 </para>
372 386 <itemizedlist>
  387 +<listitem>
  388 + <para>
  389 + <filename>name</filename>: A string identifier for this port region.
  390 + The string is optional and can be empty. Drivers can set it to make it
  391 + easier for userspace to find a certain port region.
  392 + </para>
  393 +</listitem>
373 394 <listitem>
374 395 <para>
375 396 <filename>start</filename>: The first port of this region.
... ... @@ -61,6 +61,14 @@
61 61 };
62 62 #define to_map(map) container_of(map, struct uio_map, kobj)
63 63  
  64 +static ssize_t map_name_show(struct uio_mem *mem, char *buf)
  65 +{
  66 + if (unlikely(!mem->name))
  67 + mem->name = "";
  68 +
  69 + return sprintf(buf, "%s\n", mem->name);
  70 +}
  71 +
64 72 static ssize_t map_addr_show(struct uio_mem *mem, char *buf)
65 73 {
66 74 return sprintf(buf, "0x%lx\n", mem->addr);
... ... @@ -82,6 +90,8 @@
82 90 ssize_t (*store)(struct uio_mem *, const char *, size_t);
83 91 };
84 92  
  93 +static struct map_sysfs_entry name_attribute =
  94 + __ATTR(name, S_IRUGO, map_name_show, NULL);
85 95 static struct map_sysfs_entry addr_attribute =
86 96 __ATTR(addr, S_IRUGO, map_addr_show, NULL);
87 97 static struct map_sysfs_entry size_attribute =
... ... @@ -90,6 +100,7 @@
90 100 __ATTR(offset, S_IRUGO, map_offset_show, NULL);
91 101  
92 102 static struct attribute *attrs[] = {
  103 + &name_attribute.attr,
93 104 &addr_attribute.attr,
94 105 &size_attribute.attr,
95 106 &offset_attribute.attr,
... ... @@ -133,6 +144,14 @@
133 144 };
134 145 #define to_portio(portio) container_of(portio, struct uio_portio, kobj)
135 146  
  147 +static ssize_t portio_name_show(struct uio_port *port, char *buf)
  148 +{
  149 + if (unlikely(!port->name))
  150 + port->name = "";
  151 +
  152 + return sprintf(buf, "%s\n", port->name);
  153 +}
  154 +
136 155 static ssize_t portio_start_show(struct uio_port *port, char *buf)
137 156 {
138 157 return sprintf(buf, "0x%lx\n", port->start);
... ... @@ -159,6 +178,8 @@
159 178 ssize_t (*store)(struct uio_port *, const char *, size_t);
160 179 };
161 180  
  181 +static struct portio_sysfs_entry portio_name_attribute =
  182 + __ATTR(name, S_IRUGO, portio_name_show, NULL);
162 183 static struct portio_sysfs_entry portio_start_attribute =
163 184 __ATTR(start, S_IRUGO, portio_start_show, NULL);
164 185 static struct portio_sysfs_entry portio_size_attribute =
... ... @@ -167,6 +188,7 @@
167 188 __ATTR(porttype, S_IRUGO, portio_porttype_show, NULL);
168 189  
169 190 static struct attribute *portio_attrs[] = {
  191 + &portio_name_attribute.attr,
170 192 &portio_start_attribute.attr,
171 193 &portio_size_attribute.attr,
172 194 &portio_porttype_attribute.attr,
include/linux/uio_driver.h
... ... @@ -22,6 +22,7 @@
22 22  
23 23 /**
24 24 * struct uio_mem - description of a UIO memory region
  25 + * @name: name of the memory region for identification
25 26 * @addr: address of the device's memory
26 27 * @size: size of IO
27 28 * @memtype: type of memory addr points to
... ... @@ -29,6 +30,7 @@
29 30 * @map: for use by the UIO core only.
30 31 */
31 32 struct uio_mem {
  33 + const char *name;
32 34 unsigned long addr;
33 35 unsigned long size;
34 36 int memtype;
35 37  
... ... @@ -42,12 +44,14 @@
42 44  
43 45 /**
44 46 * struct uio_port - description of a UIO port region
  47 + * @name: name of the port region for identification
45 48 * @start: start of port region
46 49 * @size: size of port region
47 50 * @porttype: type of port (see UIO_PORT_* below)
48 51 * @portio: for use by the UIO core only.
49 52 */
50 53 struct uio_port {
  54 + const char *name;
51 55 unsigned long start;
52 56 unsigned long size;
53 57 int porttype;