1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Vmalloc'ed Buffers</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Writing an ALSA Driver"><link rel="up" href="buffer-and-memory.html" title="Chapter&#160;11.&#160;Buffer and Memory Management"><link rel="prev" href="buffer-and-memory-non-contiguous.html" title="Non-Contiguous Buffers"><link rel="next" href="proc-interface.html" title="Chapter&#160;12.&#160;Proc Interface"></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">Vmalloc'ed Buffers</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="buffer-and-memory-non-contiguous.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;11.&#160;Buffer and Memory Management</th><td width="20%" align="right">&#160;<a accesskey="n" href="proc-interface.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="buffer-and-memory-vmalloced"></a>Vmalloc'ed Buffers</h2></div></div></div><p>
2        It's possible to use a buffer allocated via
3      <code class="function">vmalloc</code>, for example, for an intermediate
4      buffer. Since the allocated pages are not contiguous, you need
5      to set the <em class="structfield"><code>page</code></em> callback to obtain
6      the physical address at every offset. 
7      </p><p>
8        The implementation of <em class="structfield"><code>page</code></em> callback
9        would be like this: 
10
11        </p><div class="informalexample"><pre class="programlisting">
12
13  #include &lt;linux/vmalloc.h&gt;
14
15  /* get the physical page pointer on the given offset */
16  static struct page *mychip_page(struct snd_pcm_substream *substream,
17                                  unsigned long offset)
18  {
19          void *pageptr = substream-&gt;runtime-&gt;dma_area + offset;
20          return vmalloc_to_page(pageptr);
21  }
22
23          </pre></div><p>
24      </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="buffer-and-memory-non-contiguous.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="buffer-and-memory.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="proc-interface.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Non-Contiguous Buffers&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;12.&#160;Proc Interface</td></tr></table></div></body></html>
25