#include <linux/spinlock.h>
#include <linux/smp_lock.h>
#include <linux/gameport.h>
-#include <linux/dma-mapping.h>
-#include <linux/mutex.h>
-
#include <asm/io.h>
#include <asm/uaccess.h>
unsigned char fmt, enable;
spinlock_t lock;
- struct mutex open_mutex;
+ struct semaphore open_sem;
mode_t open_mode;
wait_queue_head_t open_wait;
return r;
}
+/*
+ * hweightN: returns the hamming weight (i.e. the number
+ * of bits set) of a N-bit word
+ */
+
+#ifdef hweight32
+#undef hweight32
+#endif
+
+static inline unsigned int hweight32(unsigned int w)
+{
+ unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
+ res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+ res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
+ res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
+ return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
+}
+
/* --------------------------------------------------------------------- */
/*
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
}
if (file->f_mode & FMODE_READ) {
fmtm &= ~((SV_CFMT_STEREO | SV_CFMT_16BIT) << SV_CFMT_CSHIFT);
}
set_fmt(s, fmtm, fmts);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
return nonseekable_open(inode, file);
}
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
dealloc_dmabuf(s, &s->dma_dac);
}
s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
wake_up(&s->open_wait);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
unlock_kernel();
return 0;
}
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
if (file->f_flags & O_NONBLOCK) {
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
}
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
}
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
return nonseekable_open(inode, file);
}
remove_wait_queue(&s->midi.owait, &wait);
set_current_state(TASK_RUNNING);
}
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
}
spin_unlock_irqrestore(&s->lock, flags);
wake_up(&s->open_wait);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
unlock_kernel();
return 0;
}
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
while (s->open_mode & FMODE_DMFM) {
if (file->f_flags & O_NONBLOCK) {
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
}
/* init the stuff */
outb(1, s->iosynth);
outb(5, s->iosynth+2);
outb(1, s->iosynth+3); /* enable OPL3 */
s->open_mode |= FMODE_DMFM;
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
return nonseekable_open(inode, file);
}
VALIDATE_STATE(s);
lock_kernel();
- mutex_lock(&s->open_mutex);
+ down(&s->open_sem);
s->open_mode &= ~FMODE_DMFM;
for (regb = 0xb0; regb < 0xb9; regb++) {
outb(regb, s->iosynth);
outb(0, s->iosynth+3);
}
wake_up(&s->open_wait);
- mutex_unlock(&s->open_mutex);
+ up(&s->open_sem);
unlock_kernel();
return 0;
}
return -ENODEV;
if (pcidev->irq == 0)
return -ENODEV;
- if (pci_set_dma_mask(pcidev, DMA_24BIT_MASK)) {
+ if (pci_set_dma_mask(pcidev, 0x00ffffff)) {
printk(KERN_WARNING "sonicvibes: architecture does not support 24bit PCI busmaster DMA\n");
return -ENODEV;
}
init_waitqueue_head(&s->open_wait);
init_waitqueue_head(&s->midi.iwait);
init_waitqueue_head(&s->midi.owait);
- mutex_init(&s->open_mutex);
+ init_MUTEX(&s->open_sem);
spin_lock_init(&s->lock);
s->magic = SV_MAGIC;
s->dev = pcidev;
wrindir(s, SV_CIPCMSR1, ((8000 * 65536 / FULLRATE) >> 8) & 0xff);
wrindir(s, SV_CIADCOUTPUT, 0);
/* request irq */
- if ((ret=request_irq(s->irq,sv_interrupt,IRQF_SHARED,"S3 SonicVibes",s))) {
+ if ((ret=request_irq(s->irq,sv_interrupt,SA_SHIRQ,"S3 SonicVibes",s))) {
printk(KERN_ERR "sv: irq %u in use\n", s->irq);
goto err_irq;
}