[ALSA] Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz
[linux-2.6.git] / sound / core / pcm_memory.c
index 9a174fb..a13e38c 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
@@ -46,7 +46,7 @@ static const size_t snd_minimum_buffer = 16384;
  *
  * the minimum size is snd_minimum_buffer.  it should be power of 2.
  */
-static int preallocate_pcm_pages(snd_pcm_substream_t *substream, size_t size)
+static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t size)
 {
        struct snd_dma_buffer *dmab = &substream->dma_buffer;
        int err;
@@ -78,7 +78,7 @@ static int preallocate_pcm_pages(snd_pcm_substream_t *substream, size_t size)
 /*
  * release the preallocated buffer if not yet done.
  */
-static void snd_pcm_lib_preallocate_dma_free(snd_pcm_substream_t *substream)
+static void snd_pcm_lib_preallocate_dma_free(struct snd_pcm_substream *substream)
 {
        if (substream->dma_buffer.area == NULL)
                return;
@@ -97,13 +97,15 @@ static void snd_pcm_lib_preallocate_dma_free(snd_pcm_substream_t *substream)
  *
  * Returns zero if successful, or a negative error code on failure.
  */
-int snd_pcm_lib_preallocate_free(snd_pcm_substream_t *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;
 }
 
@@ -115,9 +117,9 @@ int snd_pcm_lib_preallocate_free(snd_pcm_substream_t *substream)
  *
  * Returns zero if successful, or a negative error code on failure.
  */
-int snd_pcm_lib_preallocate_free_for_all(snd_pcm_t *pcm)
+int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm)
 {
-       snd_pcm_substream_t *substream;
+       struct snd_pcm_substream *substream;
        int stream;
 
        for (stream = 0; stream < 2; stream++)
@@ -126,27 +128,42 @@ int snd_pcm_lib_preallocate_free_for_all(snd_pcm_t *pcm)
        return 0;
 }
 
+EXPORT_SYMBOL(snd_pcm_lib_preallocate_free_for_all);
+
+#ifdef CONFIG_SND_VERBOSE_PROCFS
 /*
  * read callback for prealloc proc file
  *
  * prints the current allocated size in kB.
  */
-static void snd_pcm_lib_preallocate_proc_read(snd_info_entry_t *entry,
-                                             snd_info_buffer_t *buffer)
+static void snd_pcm_lib_preallocate_proc_read(struct snd_info_entry *entry,
+                                             struct snd_info_buffer *buffer)
 {
-       snd_pcm_substream_t *substream = (snd_pcm_substream_t *)entry->private_data;
+       struct snd_pcm_substream *substream = entry->private_data;
        snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_buffer.bytes / 1024);
 }
 
 /*
+ * 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.
  */
-static void snd_pcm_lib_preallocate_proc_write(snd_info_entry_t *entry,
-                                              snd_info_buffer_t *buffer)
+static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry,
+                                              struct snd_info_buffer *buffer)
 {
-       snd_pcm_substream_t *substream = (snd_pcm_substream_t *)entry->private_data;
+       struct snd_pcm_substream *substream = entry->private_data;
        char line[64], str[64];
        size_t size;
        struct snd_dma_buffer new_dmab;
@@ -185,24 +202,12 @@ static void snd_pcm_lib_preallocate_proc_write(snd_info_entry_t *entry,
        }
 }
 
-/*
- * pre-allocate the buffer and create a proc file for the substream
- */
-static int snd_pcm_lib_preallocate_pages1(snd_pcm_substream_t *substream,
-                                         size_t size, size_t max)
+static inline void preallocate_info_init(struct snd_pcm_substream *substream)
 {
-       snd_info_entry_t *entry;
+       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 +217,35 @@ static int snd_pcm_lib_preallocate_pages1(snd_pcm_substream_t *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;
 }
 
@@ -233,7 +267,7 @@ static int snd_pcm_lib_preallocate_pages1(snd_pcm_substream_t *substream,
  *
  * Returns zero if successful, or a negative error code on failure.
  */
-int snd_pcm_lib_preallocate_pages(snd_pcm_substream_t *substream,
+int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
                                  int type, struct device *data,
                                  size_t size, size_t max)
 {
@@ -242,9 +276,11 @@ int snd_pcm_lib_preallocate_pages(snd_pcm_substream_t *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)
- * @substream: the pcm substream instance
+ * @pcm: the pcm instance
  * @type: DMA type (SNDRV_DMA_TYPE_*)
  * @data: DMA type dependant data
  * @size: the requested pre-allocation size in bytes
@@ -255,11 +291,11 @@ int snd_pcm_lib_preallocate_pages(snd_pcm_substream_t *substream,
  *
  * Returns zero if successful, or a negative error code on failure.
  */
-int snd_pcm_lib_preallocate_pages_for_all(snd_pcm_t *pcm,
+int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
                                          int type, void *data,
                                          size_t size, size_t max)
 {
-       snd_pcm_substream_t *substream;
+       struct snd_pcm_substream *substream;
        int stream, err;
 
        for (stream = 0; stream < 2; stream++)
@@ -269,6 +305,8 @@ int snd_pcm_lib_preallocate_pages_for_all(snd_pcm_t *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
@@ -277,7 +315,7 @@ int snd_pcm_lib_preallocate_pages_for_all(snd_pcm_t *pcm,
  * Returns the page struct at the given buffer offset.
  * Used as the page callback of PCM ops.
  */
-struct page *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned long offset)
+struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset)
 {
        struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
 
@@ -287,6 +325,8 @@ struct page *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned lon
        return sgbuf->page_table[idx];
 }
 
+EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page);
+
 /**
  * snd_pcm_lib_malloc_pages - allocate the DMA buffer
  * @substream: the substream to allocate the DMA buffer to
@@ -298,9 +338,9 @@ struct page *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned lon
  * Returns 1 if the buffer is changed, 0 if not changed, or a negative
  * code on failure.
  */
-int snd_pcm_lib_malloc_pages(snd_pcm_substream_t *substream, size_t size)
+int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size)
 {
-       snd_pcm_runtime_t *runtime;
+       struct snd_pcm_runtime *runtime;
        struct snd_dma_buffer *dmab = NULL;
 
        snd_assert(substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_UNKNOWN, return -EINVAL);
@@ -318,10 +358,11 @@ int snd_pcm_lib_malloc_pages(snd_pcm_substream_t *substream, size_t size)
                }
                snd_pcm_lib_free_pages(substream);
        }
-       if (substream->dma_buffer.area != NULL && substream->dma_buffer.bytes >= size) {
+       if (substream->dma_buffer.area != NULL &&
+           substream->dma_buffer.bytes >= size) {
                dmab = &substream->dma_buffer; /* use the pre-allocated buffer */
        } else {
-               dmab = kcalloc(1, sizeof(*dmab), GFP_KERNEL);
+               dmab = kzalloc(sizeof(*dmab), GFP_KERNEL);
                if (! dmab)
                        return -ENOMEM;
                dmab->dev = substream->dma_buffer.dev;
@@ -337,6 +378,8 @@ int snd_pcm_lib_malloc_pages(snd_pcm_substream_t *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
@@ -345,9 +388,9 @@ int snd_pcm_lib_malloc_pages(snd_pcm_substream_t *substream, size_t size)
  *
  * Returns zero if successful, or a negative error code on failure.
  */
-int snd_pcm_lib_free_pages(snd_pcm_substream_t *substream)
+int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime;
+       struct snd_pcm_runtime *runtime;
 
        snd_assert(substream != NULL, return -EINVAL);
        runtime = substream->runtime;
@@ -362,3 +405,5 @@ int snd_pcm_lib_free_pages(snd_pcm_substream_t *substream)
        snd_pcm_set_runtime_buffer(substream, NULL);
        return 0;
 }
+
+EXPORT_SYMBOL(snd_pcm_lib_free_pages);