<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Chapter 4. Writing a driver in userspace</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><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="ch03s04.html" title="Using uio_pdrv_genirq for platform devices" /><link rel="next" href="ch04s02.html" title="mmap() device memory" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. Writing a driver in userspace</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s04.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch04s02.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter 4. Writing a driver in userspace"><div class="titlepage"><div><div><h2 class="title"><a id="userspace_driver"></a>Chapter 4. Writing a driver in userspace</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><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="ch04s02.html">mmap() device memory</a></span></dt><dt><span class="sect1"><a href="ch04s03.html">Waiting for interrupts</a></span></dt></dl></div><p> Once you have a working kernel module for your hardware, you can write the userspace part of your driver. You don't need any special libraries, your driver can be written in any reasonable language, you can use floating point numbers and so on. In short, you can use all the tools and libraries you'd normally use for writing a userspace application. </p><div class="sect1" title="Getting information about your UIO device"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="getting_uio_information"></a>Getting information about your UIO device</h2></div></div></div><p> Information about all UIO devices is available in sysfs. The first thing you should do in your driver is check <code class="varname">name</code> and <code class="varname">version</code> to make sure your talking to the right device and that its kernel driver has the version you expect. </p><p> You should also make sure that the memory mapping you need exists and has the size you expect. </p><p> There is a tool called <code class="varname">lsuio</code> that lists UIO devices and their attributes. It is available here: </p><p> <a class="ulink" href="http://www.osadl.org/projects/downloads/UIO/user/" target="_top"> http://www.osadl.org/projects/downloads/UIO/user/</a> </p><p> With <code class="varname">lsuio</code> you can quickly check if your kernel module is loaded and which attributes it exports. Have a look at the manpage for details. </p><p> The source code of <code class="varname">lsuio</code> can serve as an example for getting information about an UIO device. The file <code class="filename">uio_helper.c</code> contains a lot of functions you could use in your userspace driver code. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s04.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch04s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Using uio_pdrv_genirq for platform devices </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> mmap() device memory</td></tr></table></div></body></html>