vserver 2.0 rc7
[linux-2.6.git] / sound / oss / sonicvibes.c
index e231cf0..06047e7 100644 (file)
@@ -365,7 +365,7 @@ struct sv_state {
                unsigned char obuf[MIDIOUTBUF];
        } midi;
 
-       struct gameport gameport;
+       struct gameport *gameport;
 };
 
 /* --------------------------------------------------------------------- */
@@ -756,7 +756,7 @@ static int prog_dmabuf(struct sv_state *s, unsigned rec)
                if ((virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1) & ~0xffffff)
                        printk(KERN_DEBUG "sv: DMA buffer beyond 16MB: busaddr 0x%lx  size %ld\n", 
                               virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
-               /* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
+               /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
                pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
                for (page = virt_to_page(db->rawbuf); page <= pend; page++)
                        SetPageReserved(page);
@@ -1149,7 +1149,7 @@ static int mixer_ioctl(struct sv_state *s, unsigned int cmd, unsigned long arg)
                        if (mixtable[i].rec)
                                break;
                }
-               if (!mixtable[i].rec)
+               if (i == SOUND_MIXER_NRDEVICES)
                        return 0;
                spin_lock_irqsave(&s->lock, flags);
                frobindir(s, SV_CIMIX_ADCINL, 0x1f, mixtable[i].rec << 5);
@@ -1252,7 +1252,7 @@ static int sv_open_mixdev(struct inode *inode, struct file *file)
        }
                VALIDATE_STATE(s);
        file->private_data = s;
-       return 0;
+       return nonseekable_open(inode, file);
 }
 
 static int sv_release_mixdev(struct inode *inode, struct file *file)
@@ -1325,8 +1325,6 @@ static ssize_t sv_read(struct file *file, char __user *buffer, size_t count, lof
        int cnt;
 
        VALIDATE_STATE(s);
-       if (ppos != &file->f_pos)
-               return -ESPIPE;
        if (s->dma_adc.mapped)
                return -ENXIO;
        if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
@@ -1410,8 +1408,6 @@ static ssize_t sv_write(struct file *file, const char __user *buffer, size_t cou
        int cnt;
 
        VALIDATE_STATE(s);
-       if (ppos != &file->f_pos)
-               return -ESPIPE;
        if (s->dma_dac.mapped)
                return -ENXIO;
        if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
@@ -1553,7 +1549,9 @@ static int sv_mmap(struct file *file, struct vm_area_struct *vma)
        if (size > (PAGE_SIZE << db->buforder))
                goto out;
        ret = -EAGAIN;
-       if (remap_page_range(vma, vma->vm_start, virt_to_phys(db->rawbuf), size, vma->vm_page_prot))
+       if (remap_pfn_range(vma, vma->vm_start,
+                               virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
+                               size, vma->vm_page_prot))
                goto out;
        db->mapped = 1;
        ret = 0;
@@ -1954,7 +1952,7 @@ static int sv_open(struct inode *inode, struct file *file)
        set_fmt(s, fmtm, fmts);
        s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
        up(&s->open_sem);
-       return 0;
+       return nonseekable_open(inode, file);
 }
 
 static int sv_release(struct inode *inode, struct file *file)
@@ -2005,8 +2003,6 @@ static ssize_t sv_midi_read(struct file *file, char __user *buffer, size_t count
        int cnt;
 
        VALIDATE_STATE(s);
-       if (ppos != &file->f_pos)
-               return -ESPIPE;
        if (!access_ok(VERIFY_WRITE, buffer, count))
                return -EFAULT;
        if (count == 0)
@@ -2068,8 +2064,6 @@ static ssize_t sv_midi_write(struct file *file, const char __user *buffer, size_
        int cnt;
 
        VALIDATE_STATE(s);
-       if (ppos != &file->f_pos)
-               return -ESPIPE;
        if (!access_ok(VERIFY_READ, buffer, count))
                return -EFAULT;
        if (count == 0)
@@ -2212,7 +2206,7 @@ static int sv_midi_open(struct inode *inode, struct file *file)
        spin_unlock_irqrestore(&s->lock, flags);
        s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
        up(&s->open_sem);
-       return 0;
+       return nonseekable_open(inode, file);
 }
 
 static int sv_midi_release(struct inode *inode, struct file *file)
@@ -2414,7 +2408,7 @@ static int sv_dmfm_open(struct inode *inode, struct file *file)
        outb(1, s->iosynth+3);  /* enable OPL3 */
        s->open_mode |= FMODE_DMFM;
        up(&s->open_sem);
-       return 0;
+       return nonseekable_open(inode, file);
 }
 
 static int sv_dmfm_release(struct inode *inode, struct file *file)
@@ -2459,7 +2453,7 @@ static int wavetable[NR_DEVICE];
 
 static unsigned int devindex;
 
-MODULE_PARM(reverb, "1-" __MODULE_STRING(NR_DEVICE) "i");
+module_param_array(reverb, bool, NULL, 0);
 MODULE_PARM_DESC(reverb, "if 1 enables the reverb circuitry. NOTE: your card must have the reverb RAM");
 #if 0
 MODULE_PARM(wavetable, "1-" __MODULE_STRING(NR_DEVICE) "i");
@@ -2476,7 +2470,7 @@ MODULE_LICENSE("GPL");
 static struct initvol {
        int mixch;
        int vol;
-} initvol[] __initdata = {
+} initvol[] __devinitdata = {
        { SOUND_MIXER_WRITE_RECLEV, 0x4040 },
        { SOUND_MIXER_WRITE_LINE1, 0x4040 },
        { SOUND_MIXER_WRITE_CD, 0x4040 },
@@ -2491,12 +2485,39 @@ static struct initvol {
 #define RSRCISIOREGION(dev,num) (pci_resource_start((dev), (num)) != 0 && \
                                 (pci_resource_flags((dev), (num)) & IORESOURCE_IO))
 
+static int __devinit sv_register_gameport(struct sv_state *s, int io_port)
+{
+       struct gameport *gp;
+
+       if (!request_region(io_port, SV_EXTENT_GAME, "S3 SonicVibes Gameport")) {
+               printk(KERN_ERR "sv: gameport io ports are in use\n");
+               return -EBUSY;
+       }
+
+       s->gameport = gp = gameport_allocate_port();
+       if (!gp) {
+               printk(KERN_ERR "sv: can not allocate memory for gameport\n");
+               release_region(io_port, SV_EXTENT_GAME);
+               return -ENOMEM;
+       }
+
+       gameport_set_name(gp, "S3 SonicVibes Gameport");
+       gameport_set_phys(gp, "isa%04x/gameport0", io_port);
+       gp->dev.parent = &s->dev->dev;
+       gp->io = io_port;
+
+       gameport_register_port(gp);
+
+       return 0;
+}
+
 static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
 {
-       static char __initdata sv_ddma_name[] = "S3 Inc. SonicVibes DDMA Controller";
+       static char __devinitdata sv_ddma_name[] = "S3 Inc. SonicVibes DDMA Controller";
                struct sv_state *s;
        mm_segment_t fs;
        int i, val, ret;
+       int gpio;
        char *ddmaname;
        unsigned ddmanamelen;
 
@@ -2552,11 +2573,11 @@ static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id
        s->iomidi = pci_resource_start(pcidev, RESOURCE_MIDI);
        s->iodmaa = pci_resource_start(pcidev, RESOURCE_DDMA);
        s->iodmac = pci_resource_start(pcidev, RESOURCE_DDMA) + SV_EXTENT_DMA;
-       s->gameport.io = pci_resource_start(pcidev, RESOURCE_GAME);
+       gpio = pci_resource_start(pcidev, RESOURCE_GAME);
        pci_write_config_dword(pcidev, 0x40, s->iodmaa | 9);  /* enable and use extended mode */
        pci_write_config_dword(pcidev, 0x48, s->iodmac | 9);  /* enable */
        printk(KERN_DEBUG "sv: io ports: %#lx %#lx %#lx %#lx %#x %#x %#x\n",
-              s->iosb, s->ioenh, s->iosynth, s->iomidi, s->gameport.io, s->iodmaa, s->iodmac);
+              s->iosb, s->ioenh, s->iosynth, s->iomidi, gpio, s->iodmaa, s->iodmac);
        s->irq = pcidev->irq;
        
        /* hack */
@@ -2583,10 +2604,7 @@ static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id
                printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->iosynth, s->iosynth+SV_EXTENT_SYNTH-1);
                goto err_region1;
        }
-       if (s->gameport.io && !request_region(s->gameport.io, SV_EXTENT_GAME, "ESS Solo1")) {
-               printk(KERN_ERR "sv: gameport io ports in use\n");
-               s->gameport.io = 0;
-       }
+
        /* initialize codec registers */
        outb(0x80, s->ioenh + SV_CODEC_CONTROL); /* assert reset */
        udelay(50);
@@ -2645,7 +2663,7 @@ static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id
        }
        set_fs(fs);
        /* register gameport */
-       gameport_register_port(&s->gameport);
+       sv_register_gameport(s, gpio);
        /* store it in the driver field */
        pci_set_drvdata(pcidev, s);
        /* put it into driver list */
@@ -2665,8 +2683,6 @@ static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id
        printk(KERN_ERR "sv: cannot register misc device\n");
        free_irq(s->irq, s);
  err_irq:
-       if (s->gameport.io)
-               release_region(s->gameport.io, SV_EXTENT_GAME);
        release_region(s->iosynth, SV_EXTENT_SYNTH);
  err_region1:
        release_region(s->iomidi, SV_EXTENT_MIDI);
@@ -2695,9 +2711,10 @@ static void __devexit sv_remove(struct pci_dev *dev)
        /*outb(0, s->iodmaa + SV_DMA_RESET);*/
        /*outb(0, s->iodmac + SV_DMA_RESET);*/
        free_irq(s->irq, s);
-       if (s->gameport.io) {
-               gameport_unregister_port(&s->gameport);
-               release_region(s->gameport.io, SV_EXTENT_GAME);
+       if (s->gameport) {
+               int gpio = s->gameport->io;
+               gameport_unregister_port(s->gameport);
+               release_region(gpio, SV_EXTENT_GAME);
        }
        release_region(s->iodmac, SV_EXTENT_DMA);
        release_region(s->iodmaa, SV_EXTENT_DMA);