X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Foss%2Fymfpci.c;h=bf90c124a7e61315a4eddd9bceb850918aa6e6ff;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=c6183e770ddaeadaceaa265c5c0866b8b44bf784;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/oss/ymfpci.c b/sound/oss/ymfpci.c index c6183e770..bf90c124a 100644 --- a/sound/oss/ymfpci.c +++ b/sound/oss/ymfpci.c @@ -99,7 +99,7 @@ static void ymfpci_disable_dsp(ymfpci_t *unit); static void ymfpci_download_image(ymfpci_t *codec); static void ymf_memload(ymfpci_t *unit); -static spinlock_t ymf_devs_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(ymf_devs_lock); static LIST_HEAD(ymf_devs); /* @@ -107,14 +107,15 @@ static LIST_HEAD(ymf_devs); */ static struct pci_device_id ymf_id_tbl[] = { -#define DEV(v, d, data) \ - { PCI_VENDOR_ID_##v, PCI_DEVICE_ID_##v##_##d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long)data } - DEV (YAMAHA, 724, "YMF724"), - DEV (YAMAHA, 724F, "YMF724F"), - DEV (YAMAHA, 740, "YMF740"), - DEV (YAMAHA, 740C, "YMF740C"), - DEV (YAMAHA, 744, "YMF744"), - DEV (YAMAHA, 754, "YMF754"), +#define DEV(dev, data) \ + { PCI_VENDOR_ID_YAMAHA, dev, PCI_ANY_ID, PCI_ANY_ID, 0, 0, \ + (unsigned long)data } + DEV (PCI_DEVICE_ID_YAMAHA_724, "YMF724"), + DEV (PCI_DEVICE_ID_YAMAHA_724F, "YMF724F"), + DEV (PCI_DEVICE_ID_YAMAHA_740, "YMF740"), + DEV (PCI_DEVICE_ID_YAMAHA_740C, "YMF740C"), + DEV (PCI_DEVICE_ID_YAMAHA_744, "YMF744"), + DEV (PCI_DEVICE_ID_YAMAHA_754, "YMF754"), #undef DEV { } }; @@ -124,11 +125,6 @@ MODULE_DEVICE_TABLE(pci, ymf_id_tbl); * common I/O routines */ -static inline u8 ymfpci_readb(ymfpci_t *codec, u32 offset) -{ - return readb(codec->reg_area_virt + offset); -} - static inline void ymfpci_writeb(ymfpci_t *codec, u32 offset, u8 val) { writeb(val, codec->reg_area_virt + offset); @@ -334,7 +330,7 @@ static int alloc_dmabuf(ymfpci_t *unit, struct ymf_dmabuf *dmabuf) dmabuf->dma_addr = dma_addr; dmabuf->buforder = order; - /* 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 */ mapend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1); for (map = virt_to_page(rawbuf); map <= mapend; map++) set_bit(PG_reserved, &map->flags); @@ -1220,7 +1216,7 @@ out0: * machine and drained by this loop. */ static ssize_t -ymf_read(struct file *file, char *buffer, size_t count, loff_t *ppos) +ymf_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { struct ymf_state *state = (struct ymf_state *)file->private_data; struct ymf_dmabuf *dmabuf = &state->rpcm.dmabuf; @@ -1231,8 +1227,6 @@ ymf_read(struct file *file, char *buffer, size_t count, loff_t *ppos) unsigned int swptr; int cnt; /* This many to go in this revolution */ - if (ppos != &file->f_pos) - return -ESPIPE; if (dmabuf->mapped) return -ENXIO; if (!dmabuf->ready && (ret = prog_dmabuf(state, 1))) @@ -1335,7 +1329,7 @@ ymf_read(struct file *file, char *buffer, size_t count, loff_t *ppos) } static ssize_t -ymf_write(struct file *file, const char *buffer, size_t count, loff_t *ppos) +ymf_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { struct ymf_state *state = (struct ymf_state *)file->private_data; struct ymf_dmabuf *dmabuf = &state->wpcm.dmabuf; @@ -1350,8 +1344,6 @@ ymf_write(struct file *file, const char *buffer, size_t count, loff_t *ppos) YMFDBGW("ymf_write: count %d\n", count); - if (ppos != &file->f_pos) - return -ESPIPE; if (dmabuf->mapped) return -ENXIO; if (!dmabuf->ready && (ret = prog_dmabuf(state, 0))) @@ -1549,7 +1541,8 @@ static int ymf_mmap(struct file *file, struct vm_area_struct *vma) size = vma->vm_end - vma->vm_start; if (size > (PAGE_SIZE << dmabuf->buforder)) return -EINVAL; - if (remap_page_range(vma, vma->vm_start, virt_to_phys(dmabuf->rawbuf), + if (remap_pfn_range(vma, vma->vm_start, + virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT, size, vma->vm_page_prot)) return -EAGAIN; dmabuf->mapped = 1; @@ -1568,11 +1561,13 @@ static int ymf_ioctl(struct inode *inode, struct file *file, count_info cinfo; int redzone; int val; + void __user *argp = (void __user *)arg; + int __user *p = argp; switch (cmd) { case OSS_GETVERSION: YMFDBGX("ymf_ioctl: cmd 0x%x(GETVER) arg 0x%lx\n", cmd, arg); - return put_user(SOUND_VERSION, (int *)arg); + return put_user(SOUND_VERSION, p); case SNDCTL_DSP_RESET: YMFDBGX("ymf_ioctl: cmd 0x%x(RESET)\n", cmd); @@ -1614,7 +1609,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, return 0; case SNDCTL_DSP_SPEED: /* set smaple rate */ - if (get_user(val, (int *)arg)) + if (get_user(val, p)) return -EFAULT; YMFDBGX("ymf_ioctl: cmd 0x%x(SPEED) sp %d\n", cmd, val); if (val >= 8000 && val <= 48000) { @@ -1637,7 +1632,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, spin_unlock_irqrestore(&state->unit->reg_lock, flags); } } - return put_user(state->format.rate, (int *)arg); + return put_user(state->format.rate, p); /* * OSS manual does not mention SNDCTL_DSP_STEREO at all. @@ -1646,7 +1641,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, * However, mpg123 calls it. I wonder, why Michael Hipp used it. */ case SNDCTL_DSP_STEREO: /* set stereo or mono channel */ - if (get_user(val, (int *)arg)) + if (get_user(val, p)) return -EFAULT; YMFDBGX("ymf_ioctl: cmd 0x%x(STEREO) st %d\n", cmd, val); if (file->f_mode & FMODE_WRITE) { @@ -1676,23 +1671,23 @@ static int ymf_ioctl(struct inode *inode, struct file *file, return val; val = state->wpcm.dmabuf.fragsize; YMFDBGX("ymf_ioctl: GETBLK w %d\n", val); - return put_user(val, (int *)arg); + return put_user(val, p); } if (file->f_mode & FMODE_READ) { if ((val = prog_dmabuf(state, 1))) return val; val = state->rpcm.dmabuf.fragsize; YMFDBGX("ymf_ioctl: GETBLK r %d\n", val); - return put_user(val, (int *)arg); + return put_user(val, p); } return -EINVAL; case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/ YMFDBGX("ymf_ioctl: cmd 0x%x(GETFMTS)\n", cmd); - return put_user(AFMT_S16_LE|AFMT_U8, (int *)arg); + return put_user(AFMT_S16_LE|AFMT_U8, p); case SNDCTL_DSP_SETFMT: /* Select sample format */ - if (get_user(val, (int *)arg)) + if (get_user(val, p)) return -EFAULT; YMFDBGX("ymf_ioctl: cmd 0x%x(SETFMT) fmt %d\n", cmd, val); if (val == AFMT_S16_LE || val == AFMT_U8) { @@ -1715,10 +1710,10 @@ static int ymf_ioctl(struct inode *inode, struct file *file, spin_unlock_irqrestore(&state->unit->reg_lock, flags); } } - return put_user(state->format.format, (int *)arg); + return put_user(state->format.format, p); case SNDCTL_DSP_CHANNELS: - if (get_user(val, (int *)arg)) + if (get_user(val, p)) return -EFAULT; YMFDBGX("ymf_ioctl: cmd 0x%x(CHAN) ch %d\n", cmd, val); if (val != 0) { @@ -1745,7 +1740,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, } } } - return put_user(state->format.voices, (int *)arg); + return put_user(state->format.voices, p); case SNDCTL_DSP_POST: YMFDBGX("ymf_ioctl: cmd 0x%x(POST)\n", cmd); @@ -1768,7 +1763,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, return 0; case SNDCTL_DSP_SETFRAGMENT: - if (get_user(val, (int *)arg)) + if (get_user(val, p)) return -EFAULT; YMFDBGX("ymf_ioctl: cmd 0x%x(SETFRAG) fr 0x%04x:%04x(%d:%d)\n", cmd, @@ -1799,7 +1794,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, abinfo.fragstotal = dmabuf->numfrag; abinfo.fragments = abinfo.bytes >> dmabuf->fragshift; spin_unlock_irqrestore(&state->unit->reg_lock, flags); - return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0; + return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0; case SNDCTL_DSP_GETISPACE: YMFDBGX("ymf_ioctl: cmd 0x%x(GETISPACE)\n", cmd); @@ -1814,7 +1809,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, abinfo.fragstotal = dmabuf->numfrag; abinfo.fragments = abinfo.bytes >> dmabuf->fragshift; spin_unlock_irqrestore(&state->unit->reg_lock, flags); - return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0; + return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0; case SNDCTL_DSP_NONBLOCK: YMFDBGX("ymf_ioctl: cmd 0x%x(NONBLOCK)\n", cmd); @@ -1824,8 +1819,8 @@ static int ymf_ioctl(struct inode *inode, struct file *file, case SNDCTL_DSP_GETCAPS: YMFDBGX("ymf_ioctl: cmd 0x%x(GETCAPS)\n", cmd); /* return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP, - (int *)arg); */ - return put_user(0, (int *)arg); + p); */ + return put_user(0, p); case SNDCTL_DSP_GETIPTR: YMFDBGX("ymf_ioctl: cmd 0x%x(GETIPTR)\n", cmd); @@ -1839,7 +1834,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, spin_unlock_irqrestore(&state->unit->reg_lock, flags); YMFDBGX("ymf_ioctl: GETIPTR ptr %d bytes %d\n", cinfo.ptr, cinfo.bytes); - return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0; + return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0; case SNDCTL_DSP_GETOPTR: YMFDBGX("ymf_ioctl: cmd 0x%x(GETOPTR)\n", cmd); @@ -1853,7 +1848,7 @@ static int ymf_ioctl(struct inode *inode, struct file *file, spin_unlock_irqrestore(&state->unit->reg_lock, flags); YMFDBGX("ymf_ioctl: GETOPTR ptr %d bytes %d\n", cinfo.ptr, cinfo.bytes); - return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0; + return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0; case SNDCTL_DSP_SETDUPLEX: YMFDBGX("ymf_ioctl: cmd 0x%x(SETDUPLEX)\n", cmd); @@ -1861,15 +1856,15 @@ static int ymf_ioctl(struct inode *inode, struct file *file, case SOUND_PCM_READ_RATE: YMFDBGX("ymf_ioctl: cmd 0x%x(READ_RATE)\n", cmd); - return put_user(state->format.rate, (int *)arg); + return put_user(state->format.rate, p); case SOUND_PCM_READ_CHANNELS: YMFDBGX("ymf_ioctl: cmd 0x%x(READ_CH)\n", cmd); - return put_user(state->format.voices, (int *)arg); + return put_user(state->format.voices, p); case SOUND_PCM_READ_BITS: YMFDBGX("ymf_ioctl: cmd 0x%x(READ_BITS)\n", cmd); - return put_user(AFMT_S16_LE, (int *)arg); + return put_user(AFMT_S16_LE, p); case SNDCTL_DSP_MAPINBUF: case SNDCTL_DSP_MAPOUTBUF: @@ -1923,10 +1918,10 @@ static int ymf_open(struct inode *inode, struct file *file) if (unit == NULL) return -ENODEV; - down(&unit->open_sem); + mutex_lock(&unit->open_mutex); if ((state = ymf_state_alloc(unit)) == NULL) { - up(&unit->open_sem); + mutex_unlock(&unit->open_mutex); return -ENOMEM; } list_add_tail(&state->chain, &unit->states); @@ -1961,9 +1956,9 @@ static int ymf_open(struct inode *inode, struct file *file) ymfpci_writeb(unit, YDSXGR_TIMERCTRL, (YDSXGR_TIMERCTRL_TEN|YDSXGR_TIMERCTRL_TIEN)); #endif - up(&unit->open_sem); + mutex_unlock(&unit->open_mutex); - return 0; + return nonseekable_open(inode, file); out_nodma: /* @@ -1979,7 +1974,7 @@ out_nodma: list_del(&state->chain); kfree(state); - up(&unit->open_sem); + mutex_unlock(&unit->open_mutex); return err; } @@ -1992,7 +1987,7 @@ static int ymf_release(struct inode *inode, struct file *file) ymfpci_writeb(unit, YDSXGR_TIMERCTRL, 0); #endif - down(&unit->open_sem); + mutex_lock(&unit->open_mutex); /* * XXX Solve the case of O_NONBLOCK close - don't deallocate here. @@ -2009,7 +2004,7 @@ static int ymf_release(struct inode *inode, struct file *file) file->private_data = NULL; /* Can you tell I programmed Solaris */ kfree(state); - up(&unit->open_sem); + mutex_unlock(&unit->open_mutex); return 0; } @@ -2041,7 +2036,7 @@ static int ymf_open_mixdev(struct inode *inode, struct file *file) match: file->private_data = unit->ac97_codec[i]; - return 0; + return nonseekable_open(inode, file); } static int ymf_ioctl_mixdev(struct inode *inode, struct file *file, @@ -2080,7 +2075,7 @@ static /*const*/ struct file_operations ymf_mixer_fops = { /* */ -static int ymf_suspend(struct pci_dev *pcidev, u32 unused) +static int ymf_suspend(struct pci_dev *pcidev, pm_message_t unused) { struct ymf_unit *unit = pci_get_drvdata(pcidev); unsigned long flags; @@ -2363,7 +2358,8 @@ static int ymfpci_memalloc(ymfpci_t *codec) codec->dma_area_ba = pba; codec->dma_area_size = size + 0xff; - if ((off = ((uint) ptr) & 0xff) != 0) { + off = (unsigned long)ptr & 0xff; + if (off) { ptr += 0x100 - off; pba += 0x100 - off; } @@ -2504,8 +2500,8 @@ static int ymf_ac97_init(ymfpci_t *unit, int num_ac97) # ifdef MODULE static int mpu_io; static int synth_io; -MODULE_PARM(mpu_io, "i"); -MODULE_PARM(synth_io, "i"); +module_param(mpu_io, int, 0); +module_param(synth_io, int, 0); # else static int mpu_io = 0x330; static int synth_io = 0x388; @@ -2536,7 +2532,7 @@ static int __devinit ymf_probe_one(struct pci_dev *pcidev, const struct pci_devi spin_lock_init(&codec->reg_lock); spin_lock_init(&codec->voice_lock); spin_lock_init(&codec->ac97_lock); - init_MUTEX(&codec->open_sem); + mutex_init(&codec->open_mutex); INIT_LIST_HEAD(&codec->states); codec->pci = pcidev; @@ -2684,7 +2680,7 @@ static struct pci_driver ymfpci_driver = { static int __init ymf_init_module(void) { - return pci_module_init(&ymfpci_driver); + return pci_register_driver(&ymfpci_driver); } static void __exit ymf_cleanup_module (void)