1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>mmap() device memory</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="userspace_driver.html" title="Chapter 4. Writing a driver in userspace"><link rel="prev" href="userspace_driver.html" title="Chapter 4. Writing a driver in userspace"><link rel="next" href="wait_for_interrupts.html" title="Waiting for interrupts"></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">mmap() device memory</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="userspace_driver.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Writing a driver in userspace</th><td width="20%" align="right"> <a accesskey="n" href="wait_for_interrupts.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="mmap_device_memory"></a>mmap() device memory</h2></div></div></div><p> 2 After you made sure you've got the right device with the 3 memory mappings you need, all you have to do is to call 4 <code class="function">mmap()</code> to map the device's memory 5 to userspace. 6 </p><p> 7 The parameter <code class="varname">offset</code> of the 8 <code class="function">mmap()</code> call has a special meaning 9 for UIO devices: It is used to select which mapping of 10 your device you want to map. To map the memory of 11 mapping N, you have to use N times the page size as 12 your offset: 13 </p><pre class="programlisting"> 14 offset = N * getpagesize(); 15</pre><p> 16 N starts from zero, so if you've got only one memory 17 range to map, set <code class="varname">offset = 0</code>. 18 A drawback of this technique is that memory is always 19 mapped beginning with its start address. 20 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="userspace_driver.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="userspace_driver.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="wait_for_interrupts.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. Writing a driver in userspace </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Waiting for interrupts</td></tr></table></div></body></html> 21