]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - sound/core/pcm_memory.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mv-sheeva.git] / sound / core / pcm_memory.c
index caa7796bc2f513e2bb2a73c1c26a8c866856894b..917e4055ee30fdc37d6726e8af2f8d4d07506410 100644 (file)
@@ -22,7 +22,9 @@
 #include <asm/io.h>
 #include <linux/time.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/moduleparam.h>
+#include <linux/vmalloc.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/info.h>
@@ -434,3 +436,57 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
 }
 
 EXPORT_SYMBOL(snd_pcm_lib_free_pages);
+
+int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
+                                     size_t size, gfp_t gfp_flags)
+{
+       struct snd_pcm_runtime *runtime;
+
+       if (PCM_RUNTIME_CHECK(substream))
+               return -EINVAL;
+       runtime = substream->runtime;
+       if (runtime->dma_area) {
+               if (runtime->dma_bytes >= size)
+                       return 0; /* already large enough */
+               vfree(runtime->dma_area);
+       }
+       runtime->dma_area = __vmalloc(size, gfp_flags, PAGE_KERNEL);
+       if (!runtime->dma_area)
+               return -ENOMEM;
+       runtime->dma_bytes = size;
+       return 1;
+}
+EXPORT_SYMBOL(_snd_pcm_lib_alloc_vmalloc_buffer);
+
+/**
+ * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer
+ * @substream: the substream with a buffer allocated by
+ *     snd_pcm_lib_alloc_vmalloc_buffer()
+ */
+int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime;
+
+       if (PCM_RUNTIME_CHECK(substream))
+               return -EINVAL;
+       runtime = substream->runtime;
+       vfree(runtime->dma_area);
+       runtime->dma_area = NULL;
+       return 0;
+}
+EXPORT_SYMBOL(snd_pcm_lib_free_vmalloc_buffer);
+
+/**
+ * snd_pcm_lib_get_vmalloc_page - map vmalloc buffer offset to page struct
+ * @substream: the substream with a buffer allocated by
+ *     snd_pcm_lib_alloc_vmalloc_buffer()
+ * @offset: offset in the buffer
+ *
+ * This function is to be used as the page callback in the PCM ops.
+ */
+struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
+                                         unsigned long offset)
+{
+       return vmalloc_to_page(substream->runtime->dma_area + offset);
+}
+EXPORT_SYMBOL(snd_pcm_lib_get_vmalloc_page);