1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;4.&#160;Writing a driver in userspace</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The Userspace I/O HOWTO"><link rel="up" href="index.html" title="The Userspace I/O HOWTO"><link rel="prev" href="using-uio_dmem_genirq.html" title="Using uio_dmem_genirq for platform devices"><link rel="next" href="mmap_device_memory.html" title="mmap() device memory"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;4.&#160;Writing a driver in userspace</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="using-uio_dmem_genirq.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="mmap_device_memory.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="userspace_driver"></a>Chapter&#160;4.&#160;Writing a driver in userspace</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="userspace_driver.html#getting_uio_information">Getting information about your UIO device</a></span></dt><dt><span class="sect1"><a href="mmap_device_memory.html">mmap() device memory</a></span></dt><dt><span class="sect1"><a href="wait_for_interrupts.html">Waiting for interrupts</a></span></dt></dl></div><p>
2	Once you have a working kernel module for your hardware, you can
3	write the userspace part of your driver. You don't need any special
4	libraries, your driver can be written in any reasonable language,
5	you can use floating point numbers and so on. In short, you can
6	use all the tools and libraries you'd normally use for writing a
7	userspace application.
8	</p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="getting_uio_information"></a>Getting information about your UIO device</h2></div></div></div><p>
9	Information about all UIO devices is available in sysfs. The
10	first thing you should do in your driver is check
11	<code class="varname">name</code> and <code class="varname">version</code> to
12	make sure your talking to the right device and that its kernel
13	driver has the version you expect.
14	</p><p>
15	You should also make sure that the memory mapping you need
16	exists and has the size you expect.
17	</p><p>
18	There is a tool called <code class="varname">lsuio</code> that lists
19	UIO devices and their attributes. It is available here:
20	</p><p>
21	<a class="ulink" href="http://www.osadl.org/projects/downloads/UIO/user/" target="_top">
22		http://www.osadl.org/projects/downloads/UIO/user/</a>
23	</p><p>
24	With <code class="varname">lsuio</code> you can quickly check if your
25	kernel module is loaded and which attributes it exports.
26	Have a look at the manpage for details.
27	</p><p>
28	The source code of <code class="varname">lsuio</code> can serve as an
29	example for getting information about an UIO device.
30	The file <code class="filename">uio_helper.c</code> contains a lot of
31	functions you could use in your userspace driver code.
32	</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="using-uio_dmem_genirq.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="mmap_device_memory.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Using uio_dmem_genirq for platform devices&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;mmap() device memory</td></tr></table></div></body></html>
33