<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><TITLE >Accessing the device</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Bus-Independent Device Accesses" HREF="book1.html"><LINK REL="UP" TITLE="Memory Mapped IO" HREF="c33.html"><LINK REL="PREVIOUS" TITLE="Memory Mapped IO" HREF="c33.html"><LINK REL="NEXT" TITLE="ISA legacy functions" HREF="x65.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Bus-Independent Device Accesses</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="c33.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Memory Mapped IO</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x65.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN44" ></A >Accessing the device</H1 ><P > The part of the interface most used by drivers is reading and writing memory-mapped registers on the device. Linux provides interfaces to read and write 8-bit, 16-bit, 32-bit and 64-bit quantities. Due to a historical accident, these are named byte, word, long and quad accesses. Both read and write accesses are supported; there is no prefetch support at this time. </P ><P > The functions are named <TT CLASS="FUNCTION" >readb</TT >, <TT CLASS="FUNCTION" >readw</TT >, <TT CLASS="FUNCTION" >readl</TT >, <TT CLASS="FUNCTION" >readq</TT >, <TT CLASS="FUNCTION" >writeb</TT >, <TT CLASS="FUNCTION" >writew</TT >, <TT CLASS="FUNCTION" >writel</TT > and <TT CLASS="FUNCTION" >writeq</TT >. </P ><P > Some devices (such as framebuffers) would like to use larger transfers than 8 bytes at a time. For these devices, the <TT CLASS="FUNCTION" >memcpy_toio</TT >, <TT CLASS="FUNCTION" >memcpy_fromio</TT > and <TT CLASS="FUNCTION" >memset_io</TT > functions are provided. Do not use memset or memcpy on IO addresses; they are not guaranteed to copy data in order. </P ><P > The read and write functions are defined to be ordered. That is the compiler is not permitted to reorder the I/O sequence. When the ordering can be compiler optimised, you can use <TT CLASS="FUNCTION" > __readb</TT > and friends to indicate the relaxed ordering. Use this with care. The <TT CLASS="FUNCTION" >rmb</TT > provides a read memory barrier. The <TT CLASS="FUNCTION" >wmb</TT > provides a write memory barrier. </P ><P > While the basic functions are defined to be synchronous with respect to each other and ordered with respect to each other the busses the devices sit on may themselves have asynchronocity. In paticular many authors are burned by the fact that PCI bus writes are posted asynchronously. A driver author must issue a read from the same device to ensure that writes have occurred in the specific cases the author cares. This kind of property cannot be hidden from driver writers in the API. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="c33.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="book1.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x65.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Memory Mapped IO</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c33.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >ISA legacy functions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >