]> err.no Git - linux-2.6/blobdiff - sound/core/memalloc.c
[ALSA] semaphore -> mutex (core part)
[linux-2.6] / sound / core / memalloc.c
index 91124ddbdda939322f6bc813fa418578b9ff2280..9f2b88cb5877fc03a962873df41963e9e96fe69c 100644 (file)
@@ -31,7 +31,7 @@
 #include <asm/uaccess.h>
 #include <linux/dma-mapping.h>
 #include <linux/moduleparam.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #include <sound/memalloc.h>
 #ifdef CONFIG_SBUS
 #include <asm/sbus.h>
@@ -43,10 +43,6 @@ MODULE_DESCRIPTION("Memory allocator for ALSA system.");
 MODULE_LICENSE("GPL");
 
 
-#ifndef SNDRV_CARDS
-#define SNDRV_CARDS    8
-#endif
-
 /*
  */
 
@@ -58,7 +54,7 @@ int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);
 /*
  */
 
-static DECLARE_MUTEX(list_mutex);
+static DEFINE_MUTEX(list_mutex);
 static LIST_HEAD(mem_list_head);
 
 /* buffer preservation list */
@@ -106,7 +102,7 @@ struct snd_mem_list {
 
 static void *snd_dma_hack_alloc_coherent(struct device *dev, size_t size,
                                         dma_addr_t *dma_handle,
-                                        unsigned int __nocast flags)
+                                        gfp_t flags)
 {
        void *ret;
        u64 dma_mask, coherent_dma_mask;
@@ -190,13 +186,14 @@ static void unmark_pages(struct page *page, int order)
  *
  * Returns the pointer of the buffer, or NULL if no enoguh memory.
  */
-void *snd_malloc_pages(size_t size, unsigned int gfp_flags)
+void *snd_malloc_pages(size_t size, gfp_t gfp_flags)
 {
        int pg;
        void *res;
 
        snd_assert(size > 0, return NULL);
        snd_assert(gfp_flags != 0, return NULL);
+       gfp_flags |= __GFP_COMP;        /* compound page lets parts be mapped */
        pg = get_order(size);
        if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL) {
                mark_pages(virt_to_page(res), pg);
@@ -235,12 +232,13 @@ static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *d
 {
        int pg;
        void *res;
-       unsigned int gfp_flags;
+       gfp_t gfp_flags;
 
        snd_assert(size > 0, return NULL);
        snd_assert(dma != NULL, return NULL);
        pg = get_order(size);
        gfp_flags = GFP_KERNEL
+               | __GFP_COMP    /* compound page lets parts be mapped */
                | __GFP_NORETRY /* don't trigger OOM-killer */
                | __GFP_NOWARN; /* no stack trace print - this call is non-critical */
        res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
@@ -442,7 +440,7 @@ size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
 
        snd_assert(dmab, return 0);
 
-       down(&list_mutex);
+       mutex_lock(&list_mutex);
        list_for_each(p, &mem_list_head) {
                mem = list_entry(p, struct snd_mem_list, list);
                if (mem->id == id &&
@@ -454,11 +452,11 @@ size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
                        if (dmab->dev.dev == NULL)
                                dmab->dev.dev = dev;
                        kfree(mem);
-                       up(&list_mutex);
+                       mutex_unlock(&list_mutex);
                        return dmab->bytes;
                }
        }
-       up(&list_mutex);
+       mutex_unlock(&list_mutex);
        return 0;
 }
 
@@ -479,11 +477,11 @@ int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id)
        mem = kmalloc(sizeof(*mem), GFP_KERNEL);
        if (! mem)
                return -ENOMEM;
-       down(&list_mutex);
+       mutex_lock(&list_mutex);
        mem->buffer = *dmab;
        mem->id = id;
        list_add_tail(&mem->list, &mem_list_head);
-       up(&list_mutex);
+       mutex_unlock(&list_mutex);
        return 0;
 }
 
@@ -495,7 +493,7 @@ static void free_all_reserved_pages(void)
        struct list_head *p;
        struct snd_mem_list *mem;
 
-       down(&list_mutex);
+       mutex_lock(&list_mutex);
        while (! list_empty(&mem_list_head)) {
                p = mem_list_head.next;
                mem = list_entry(p, struct snd_mem_list, list);
@@ -503,7 +501,7 @@ static void free_all_reserved_pages(void)
                snd_dma_free_pages(&mem->buffer);
                kfree(mem);
        }
-       up(&list_mutex);
+       mutex_unlock(&list_mutex);
 }
 
 
@@ -524,7 +522,7 @@ static int snd_mem_proc_read(char *page, char **start, off_t off,
        int devno;
        static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG", "SBUS" };
 
-       down(&list_mutex);
+       mutex_lock(&list_mutex);
        len += snprintf(page + len, count - len,
                        "pages  : %li bytes (%li pages per %likB)\n",
                        pages * PAGE_SIZE, pages, PAGE_SIZE / 1024);
@@ -539,7 +537,7 @@ static int snd_mem_proc_read(char *page, char **start, off_t off,
                                "  addr = 0x%lx, size = %d bytes\n",
                                (unsigned long)mem->buffer.addr, (int)mem->buffer.bytes);
        }
-       up(&list_mutex);
+       mutex_unlock(&list_mutex);
        return len;
 }