ALSA: Kill truncate warning by shortening Sigmatel-specific AC97 control name
[safe/jmp/linux-2.6] / sound / core / pcm_memory.c
index d37bcb7..a6d4280 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Digital Audio (PCM) abstract layer
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This program is free software; you can redistribute it and/or modify
@@ -19,7 +19,6 @@
  *
  */
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/time.h>
 #include <linux/init.h>
@@ -51,8 +50,6 @@ static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t siz
        struct snd_dma_buffer *dmab = &substream->dma_buffer;
        int err;
 
-       snd_assert(size > 0, return -EINVAL);
-
        /* already reserved? */
        if (snd_dma_get_reserved_buf(dmab, substream->dma_buf_id) > 0) {
                if (dmab->bytes >= size)
@@ -100,10 +97,12 @@ static void snd_pcm_lib_preallocate_dma_free(struct snd_pcm_substream *substream
 int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream)
 {
        snd_pcm_lib_preallocate_dma_free(substream);
-       if (substream->proc_prealloc_entry) {
-               snd_info_unregister(substream->proc_prealloc_entry);
-               substream->proc_prealloc_entry = NULL;
-       }
+#ifdef CONFIG_SND_VERBOSE_PROCFS
+       snd_info_free_entry(substream->proc_prealloc_max_entry);
+       substream->proc_prealloc_max_entry = NULL;
+       snd_info_free_entry(substream->proc_prealloc_entry);
+       substream->proc_prealloc_entry = NULL;
+#endif
        return 0;
 }
 
@@ -126,6 +125,9 @@ int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm)
        return 0;
 }
 
+EXPORT_SYMBOL(snd_pcm_lib_preallocate_free_for_all);
+
+#ifdef CONFIG_SND_VERBOSE_PROCFS
 /*
  * read callback for prealloc proc file
  *
@@ -139,6 +141,18 @@ static void snd_pcm_lib_preallocate_proc_read(struct snd_info_entry *entry,
 }
 
 /*
+ * read callback for prealloc_max proc file
+ *
+ * prints the maximum allowed size in kB.
+ */
+static void snd_pcm_lib_preallocate_max_proc_read(struct snd_info_entry *entry,
+                                                 struct snd_info_buffer *buffer)
+{
+       struct snd_pcm_substream *substream = entry->private_data;
+       snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_max / 1024);
+}
+
+/*
  * write callback for prealloc proc file
  *
  * accepts the preallocation size in kB.
@@ -185,24 +199,12 @@ static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry,
        }
 }
 
-/*
- * pre-allocate the buffer and create a proc file for the substream
- */
-static int snd_pcm_lib_preallocate_pages1(struct snd_pcm_substream *substream,
-                                         size_t size, size_t max)
+static inline void preallocate_info_init(struct snd_pcm_substream *substream)
 {
        struct snd_info_entry *entry;
 
-       if (size > 0 && preallocate_dma && substream->number < maximum_substreams)
-               preallocate_pcm_pages(substream, size);
-
-       if (substream->dma_buffer.bytes > 0)
-               substream->buffer_bytes_max = substream->dma_buffer.bytes;
-       substream->dma_max = max;
        if ((entry = snd_info_create_card_entry(substream->pcm->card, "prealloc", substream->proc_root)) != NULL) {
-               entry->c.text.read_size = 64;
                entry->c.text.read = snd_pcm_lib_preallocate_proc_read;
-               entry->c.text.write_size = 64;
                entry->c.text.write = snd_pcm_lib_preallocate_proc_write;
                entry->mode |= S_IWUSR;
                entry->private_data = substream;
@@ -212,6 +214,35 @@ static int snd_pcm_lib_preallocate_pages1(struct snd_pcm_substream *substream,
                }
        }
        substream->proc_prealloc_entry = entry;
+       if ((entry = snd_info_create_card_entry(substream->pcm->card, "prealloc_max", substream->proc_root)) != NULL) {
+               entry->c.text.read = snd_pcm_lib_preallocate_max_proc_read;
+               entry->private_data = substream;
+               if (snd_info_register(entry) < 0) {
+                       snd_info_free_entry(entry);
+                       entry = NULL;
+               }
+       }
+       substream->proc_prealloc_max_entry = entry;
+}
+
+#else /* !CONFIG_SND_VERBOSE_PROCFS */
+#define preallocate_info_init(s)
+#endif /* CONFIG_SND_VERBOSE_PROCFS */
+
+/*
+ * pre-allocate the buffer and create a proc file for the substream
+ */
+static int snd_pcm_lib_preallocate_pages1(struct snd_pcm_substream *substream,
+                                         size_t size, size_t max)
+{
+
+       if (size > 0 && preallocate_dma && substream->number < maximum_substreams)
+               preallocate_pcm_pages(substream, size);
+
+       if (substream->dma_buffer.bytes > 0)
+               substream->buffer_bytes_max = substream->dma_buffer.bytes;
+       substream->dma_max = max;
+       preallocate_info_init(substream);
        return 0;
 }
 
@@ -242,6 +273,8 @@ int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
        return snd_pcm_lib_preallocate_pages1(substream, size, max);
 }
 
+EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages);
+
 /**
  * snd_pcm_lib_preallocate_pages_for_all - pre-allocation for continous memory type (all substreams)
  * @pcm: the pcm instance
@@ -269,6 +302,8 @@ int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
        return 0;
 }
 
+EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all);
+
 /**
  * snd_pcm_sgbuf_ops_page - get the page struct at the given offset
  * @substream: the pcm substream instance
@@ -287,6 +322,34 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigne
        return sgbuf->page_table[idx];
 }
 
+EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page);
+
+/*
+ * compute the max chunk size with continuous pages on sg-buffer
+ */
+unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
+                                         unsigned int ofs, unsigned int size)
+{
+       struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
+       unsigned int start, end, pg;
+
+       start = ofs >> PAGE_SHIFT;
+       end = (ofs + size - 1) >> PAGE_SHIFT;
+       /* check page continuity */
+       pg = sg->table[start].addr >> PAGE_SHIFT;
+       for (;;) {
+               start++;
+               if (start > end)
+                       break;
+               pg++;
+               if ((sg->table[start].addr >> PAGE_SHIFT) != pg)
+                       return (start << PAGE_SHIFT) - ofs;
+       }
+       /* ok, all on continuous pages */
+       return size;
+}
+EXPORT_SYMBOL(snd_pcm_sgbuf_get_chunk_size);
+
 /**
  * snd_pcm_lib_malloc_pages - allocate the DMA buffer
  * @substream: the substream to allocate the DMA buffer to
@@ -303,10 +366,12 @@ int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size)
        struct snd_pcm_runtime *runtime;
        struct snd_dma_buffer *dmab = NULL;
 
-       snd_assert(substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_UNKNOWN, return -EINVAL);
-       snd_assert(substream != NULL, return -EINVAL);
+       if (PCM_RUNTIME_CHECK(substream))
+               return -EINVAL;
+       if (snd_BUG_ON(substream->dma_buffer.dev.type ==
+                      SNDRV_DMA_TYPE_UNKNOWN))
+               return -EINVAL;
        runtime = substream->runtime;
-       snd_assert(runtime != NULL, return -EINVAL);
 
        if (runtime->dma_buffer_p) {
                /* perphaps, we might free the large DMA memory region
@@ -338,6 +403,8 @@ int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size)
        return 1;                       /* area was changed */
 }
 
+EXPORT_SYMBOL(snd_pcm_lib_malloc_pages);
+
 /**
  * snd_pcm_lib_free_pages - release the allocated DMA buffer.
  * @substream: the substream to release the DMA buffer
@@ -350,9 +417,9 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
 {
        struct snd_pcm_runtime *runtime;
 
-       snd_assert(substream != NULL, return -EINVAL);
+       if (PCM_RUNTIME_CHECK(substream))
+               return -EINVAL;
        runtime = substream->runtime;
-       snd_assert(runtime != NULL, return -EINVAL);
        if (runtime->dma_area == NULL)
                return 0;
        if (runtime->dma_buffer_p != &substream->dma_buffer) {
@@ -363,3 +430,5 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
        snd_pcm_set_runtime_buffer(substream, NULL);
        return 0;
 }
+
+EXPORT_SYMBOL(snd_pcm_lib_free_pages);