Sophie

Sophie

distrib > CentOS > 6 > i386 > by-pkgid > 2c51d8eb79f8810ada971ee8c30ce1e5 > files > 4157

kernel-doc-2.6.32-71.14.1.el6.noarch.rpm

<?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>Non-Contiguous Buffers</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Writing an ALSA Driver" /><link rel="up" href="ch11.html" title="Chapter&#160;11.&#160;Buffer and Memory Management" /><link rel="prev" href="ch11s02.html" title="External Hardware Buffers" /><link rel="next" href="ch11s04.html" title="Vmalloc'ed Buffers" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Non-Contiguous Buffers</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch11s02.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="ch11s04.html">Next</a></td></tr></table><hr /></div><div class="section" title="Non-Contiguous Buffers"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="buffer-and-memory-non-contiguous"></a>Non-Contiguous Buffers</h2></div></div></div><p>
        If your hardware supports the page table as in emu10k1 or the
      buffer descriptors as in via82xx, you can use the scatter-gather
      (SG) DMA. ALSA provides an interface for handling SG-buffers.
      The API is provided in <code class="filename">&lt;sound/pcm.h&gt;</code>. 
      </p><p>
        For creating the SG-buffer handler, call
        <code class="function">snd_pcm_lib_preallocate_pages()</code> or
        <code class="function">snd_pcm_lib_preallocate_pages_for_all()</code>
        with <code class="constant">SNDRV_DMA_TYPE_DEV_SG</code>
	in the PCM constructor like other PCI pre-allocator.
        You need to pass <code class="function">snd_dma_pci_data(pci)</code>,
        where pci is the struct <span class="structname">pci_dev</span> pointer
        of the chip as well.
        The <span class="type">struct snd_sg_buf</span> instance is created as
        substream-&gt;dma_private. You can cast
        the pointer like: 

        </p><div class="informalexample"><pre class="programlisting">

  struct snd_sg_buf *sgbuf = (struct snd_sg_buf *)substream-&gt;dma_private;

          </pre></div><p>
      </p><p>
        Then call <code class="function">snd_pcm_lib_malloc_pages()</code>
      in the <em class="structfield"><code>hw_params</code></em> callback
      as well as in the case of normal PCI buffer.
      The SG-buffer handler will allocate the non-contiguous kernel
      pages of the given size and map them onto the virtually contiguous
      memory.  The virtual pointer is addressed in runtime-&gt;dma_area.
      The physical address (runtime-&gt;dma_addr) is set to zero,
      because the buffer is physically non-contigous.
      The physical address table is set up in sgbuf-&gt;table.
      You can get the physical address at a certain offset via
      <code class="function">snd_pcm_sgbuf_get_addr()</code>. 
      </p><p>
        When a SG-handler is used, you need to set
      <code class="function">snd_pcm_sgbuf_ops_page</code> as
      the <em class="structfield"><code>page</code></em> callback.
      (See <a class="link" href="ch05s06.html#pcm-interface-operators-page-callback" title="page callback">
      <em class="citetitle">page callback section</em></a>.)
      </p><p>
        To release the data, call
      <code class="function">snd_pcm_lib_free_pages()</code> in the
      <em class="structfield"><code>hw_free</code></em> callback as usual.
      </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch11s02.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="ch11.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch11s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">External Hardware 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;Vmalloc'ed Buffers</td></tr></table></div></body></html>