linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / sound / oss / trident.c
index 2813e4c..a21c663 100644 (file)
  *
  *     Lock order (high->low)
  *             lock    -       hardware lock
- *             open_mutex -    guard opens
+ *             open_sem -      guard opens
  *             sem     -       guard dmabuf, write re-entry etc
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
 #include <linux/pm.h>
 #include <linux/gameport.h>
 #include <linux/kernel.h>
-#include <linux/mutex.h>
-
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/dma.h>
@@ -350,7 +349,7 @@ struct trident_state {
        unsigned chans_num;
        unsigned long fmt_flag;
        /* Guard against mmap/write/read races */
-       struct mutex sem;
+       struct semaphore sem;
 
 };
 
@@ -403,7 +402,7 @@ struct trident_card {
        struct trident_card *next;
 
        /* single open lock mechanism, only used for recording */
-       struct mutex open_mutex;
+       struct semaphore open_sem;
 
        /* The trident has a certain amount of cross channel interaction
           so we use a single per card lock */
@@ -1882,7 +1881,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
        if (!access_ok(VERIFY_WRITE, buffer, count))
                return -EFAULT;
 
-       mutex_lock(&state->sem);
+       down(&state->sem);
        if (!dmabuf->ready && (ret = prog_dmabuf_record(state)))
                goto out;
 
@@ -1914,7 +1913,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
                                goto out;
                        }
 
-                       mutex_unlock(&state->sem);
+                       up(&state->sem);
                        /* No matter how much space left in the buffer, */ 
                        /* we have to wait until CSO == ESO/2 or CSO == ESO */ 
                        /* when address engine interrupts */
@@ -1941,7 +1940,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
                                        ret = -ERESTARTSYS;
                                goto out;
                        }
-                       mutex_lock(&state->sem);
+                       down(&state->sem);
                        if (dmabuf->mapped) {
                                if (!ret)
                                        ret = -ENXIO;
@@ -1969,7 +1968,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
                start_adc(state);
        }
 out:
-       mutex_unlock(&state->sem);
+       up(&state->sem);
        return ret;
 }
 
@@ -1997,7 +1996,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
         *      Guard against an mmap or ioctl while writing
         */
 
-       mutex_lock(&state->sem);
+       down(&state->sem);
 
        if (dmabuf->mapped) {
                ret = -ENXIO;
@@ -2046,7 +2045,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
                        tmo = (dmabuf->dmasize * HZ) / (dmabuf->rate * 2);
                        tmo >>= sample_shift[dmabuf->fmt];
                        unlock_set_fmt(state);
-                       mutex_unlock(&state->sem);
+                       up(&state->sem);
 
                        /* There are two situations when sleep_on_timeout */ 
                        /* returns, one is when the interrupt is serviced */ 
@@ -2074,7 +2073,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
                                        ret = -ERESTARTSYS;
                                goto out_nolock;
                        }
-                       mutex_lock(&state->sem);
+                       down(&state->sem);
                        if (dmabuf->mapped) {
                                if (!ret)
                                        ret = -ENXIO;
@@ -2132,7 +2131,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
                start_dac(state);
        }
 out:
-       mutex_unlock(&state->sem);
+       up(&state->sem);
 out_nolock:
        return ret;
 }
@@ -2153,24 +2152,24 @@ trident_poll(struct file *file, struct poll_table_struct *wait)
         *      prog_dmabuf events
         */
 
-       mutex_lock(&state->sem);
+       down(&state->sem);
 
        if (file->f_mode & FMODE_WRITE) {
                if (!dmabuf->ready && prog_dmabuf_playback(state)) {
-                       mutex_unlock(&state->sem);
+                       up(&state->sem);
                        return 0;
                }
                poll_wait(file, &dmabuf->wait, wait);
        }
        if (file->f_mode & FMODE_READ) {
                if (!dmabuf->ready && prog_dmabuf_record(state)) {
-                       mutex_unlock(&state->sem);
+                       up(&state->sem);
                        return 0;
                }
                poll_wait(file, &dmabuf->wait, wait);
        }
 
-       mutex_unlock(&state->sem);
+       up(&state->sem);
 
        spin_lock_irqsave(&state->card->lock, flags);
        trident_update_ptr(state);
@@ -2208,7 +2207,7 @@ trident_mmap(struct file *file, struct vm_area_struct *vma)
         *      a read or write against an mmap.
         */
 
-       mutex_lock(&state->sem);
+       down(&state->sem);
 
        if (vma->vm_flags & VM_WRITE) {
                if ((ret = prog_dmabuf_playback(state)) != 0)
@@ -2233,7 +2232,7 @@ trident_mmap(struct file *file, struct vm_area_struct *vma)
        dmabuf->mapped = 1;
        ret = 0;
 out:
-       mutex_unlock(&state->sem);
+       up(&state->sem);
        return ret;
 }
 
@@ -2430,15 +2429,15 @@ trident_ioctl(struct inode *inode, struct file *file,
                                                        unlock_set_fmt(state);
                                                        break;
                                                }
-                                               mutex_lock(&state->card->open_mutex);
+                                               down(&state->card->open_sem);
                                                ret = ali_allocate_other_states_resources(state, 6);
                                                if (ret < 0) {
-                                                       mutex_unlock(&state->card->open_mutex);
+                                                       up(&state->card->open_sem);
                                                        unlock_set_fmt(state);
                                                        break;
                                                }
                                                state->card->multi_channel_use_count++;
-                                               mutex_unlock(&state->card->open_mutex);
+                                               up(&state->card->open_sem);
                                        } else
                                                val = 2;        /*yield to 2-channels */
                                } else
@@ -2728,11 +2727,11 @@ trident_open(struct inode *inode, struct file *file)
 
        /* find an available virtual channel (instance of /dev/dsp) */
        while (card != NULL) {
-               mutex_lock(&card->open_mutex);
+               down(&card->open_sem);
                if (file->f_mode & FMODE_READ) {
                        /* Skip opens on cards that are in 6 channel mode */
                        if (card->multi_channel_use_count > 0) {
-                               mutex_unlock(&card->open_mutex);
+                               up(&card->open_sem);
                                card = card->next;
                                continue;
                        }
@@ -2741,16 +2740,16 @@ trident_open(struct inode *inode, struct file *file)
                        if (card->states[i] == NULL) {
                                state = card->states[i] = kmalloc(sizeof(*state), GFP_KERNEL);
                                if (state == NULL) {
-                                       mutex_unlock(&card->open_mutex);
+                                       up(&card->open_sem);
                                        return -ENOMEM;
                                }
                                memset(state, 0, sizeof(*state));
-                               mutex_init(&state->sem);
+                               init_MUTEX(&state->sem);
                                dmabuf = &state->dmabuf;
                                goto found_virt;
                        }
                }
-               mutex_unlock(&card->open_mutex);
+               up(&card->open_sem);
                card = card->next;
        }
        /* no more virtual channel avaiable */
@@ -2817,7 +2816,7 @@ trident_open(struct inode *inode, struct file *file)
        }
 
        state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
-       mutex_unlock(&card->open_mutex);
+       up(&card->open_sem);
 
        pr_debug("trident: open virtual channel %d, hard channel %d\n",
                 state->virt, dmabuf->channel->num);
@@ -2846,7 +2845,7 @@ trident_release(struct inode *inode, struct file *file)
                 state->virt, dmabuf->channel->num);
 
        /* stop DMA state machine and free DMA buffers/channels */
-       mutex_lock(&card->open_mutex);
+       down(&card->open_sem);
 
        if (file->f_mode & FMODE_WRITE) {
                stop_dac(state);
@@ -2879,8 +2878,8 @@ trident_release(struct inode *inode, struct file *file)
        card->states[state->virt] = NULL;
        kfree(state);
 
-       /* we're covered by the open_mutex */
-       mutex_unlock(&card->open_mutex);
+       /* we're covered by the open_sem */
+       up(&card->open_sem);
 
        return 0;
 }
@@ -4406,7 +4405,7 @@ trident_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
        card->banks[BANK_B].addresses = &bank_b_addrs;
        card->banks[BANK_B].bitmap = 0UL;
 
-       mutex_init(&card->open_mutex);
+       init_MUTEX(&card->open_sem);
        spin_lock_init(&card->lock);
        init_timer(&card->timer);
 
@@ -4472,7 +4471,7 @@ trident_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
 
        /* claim our irq */
        rc = -ENODEV;
-       if (request_irq(card->irq, &trident_interrupt, IRQF_SHARED,
+       if (request_irq(card->irq, &trident_interrupt, SA_SHIRQ, 
                        card_names[pci_id->driver_data], card)) {
                printk(KERN_ERR "trident: unable to allocate irq %d\n", 
                       card->irq);