📄 soundcard.c
字号:
return get_mixer_levels(p); if (cmd == SOUND_MIXER_SETLEVELS) return set_mixer_levels(p); return sound_mixer_ioctl(dev >> 4, cmd, p); case SND_DEV_SEQ: case SND_DEV_SEQ2: return sequencer_ioctl(dev, file, cmd, p); case SND_DEV_DSP: case SND_DEV_DSP16: case SND_DEV_AUDIO: return audio_ioctl(dev, file, cmd, p); break; case SND_DEV_MIDIN: return MIDIbuf_ioctl(dev, file, cmd, p); break; } return -EINVAL;}static unsigned int sound_poll(struct file *file, poll_table * wait){ struct inode *inode = file->f_path.dentry->d_inode; int dev = iminor(inode); DEB(printk("sound_poll(dev=%d)\n", dev)); switch (dev & 0x0f) { case SND_DEV_SEQ: case SND_DEV_SEQ2: return sequencer_poll(dev, file, wait); case SND_DEV_MIDIN: return MIDIbuf_poll(dev, file, wait); case SND_DEV_DSP: case SND_DEV_DSP16: case SND_DEV_AUDIO: return DMAbuf_poll(file, dev >> 4, wait); } return 0;}static int sound_mmap(struct file *file, struct vm_area_struct *vma){ int dev_class; unsigned long size; struct dma_buffparms *dmap = NULL; int dev = iminor(file->f_path.dentry->d_inode); dev_class = dev & 0x0f; dev >>= 4; if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) { printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n"); return -EINVAL; } lock_kernel(); if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */ dmap = audio_devs[dev]->dmap_out; else if (vma->vm_flags & VM_READ) dmap = audio_devs[dev]->dmap_in; else { printk(KERN_ERR "Sound: Undefined mmap() access\n"); unlock_kernel(); return -EINVAL; } if (dmap == NULL) { printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n"); unlock_kernel(); return -EIO; } if (dmap->raw_buf == NULL) { printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n"); unlock_kernel(); return -EIO; } if (dmap->mapping_flags) { printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n"); unlock_kernel(); return -EIO; } if (vma->vm_pgoff != 0) { printk(KERN_ERR "Sound: mmap() offset must be 0.\n"); unlock_kernel(); return -EINVAL; } size = vma->vm_end - vma->vm_start; if (size != dmap->bytes_in_use) { printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use); } if (remap_pfn_range(vma, vma->vm_start, virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT, vma->vm_end - vma->vm_start, vma->vm_page_prot)) { unlock_kernel(); return -EAGAIN; } dmap->mapping_flags |= DMA_MAP_MAPPED; if( audio_devs[dev]->d->mmap) audio_devs[dev]->d->mmap(dev); memset(dmap->raw_buf, dmap->neutral_byte, dmap->bytes_in_use); unlock_kernel(); return 0;}const struct file_operations oss_sound_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .read = sound_read, .write = sound_write, .poll = sound_poll, .ioctl = sound_ioctl, .mmap = sound_mmap, .open = sound_open, .release = sound_release,};/* * Create the required special subdevices */ static int create_special_devices(void){ int seq1,seq2; seq1=register_sound_special(&oss_sound_fops, 1); if(seq1==-1) goto bad; seq2=register_sound_special(&oss_sound_fops, 8); if(seq2!=-1) return 0; unregister_sound_special(1);bad: return -1;}/* These device names follow the official Linux device list, * Documentation/devices.txt. Let us know if there are other * common names we should support for compatibility. * Only those devices not created by the generic code in sound_core.c are * registered here. */static const struct { unsigned short minor; char *name; umode_t mode; int *num;} dev_list[] = { /* list of minor devices *//* seems to be some confusion here -- this device is not in the device list */ {SND_DEV_DSP16, "dspW", S_IWUGO | S_IRUSR | S_IRGRP, &num_audiodevs}, {SND_DEV_AUDIO, "audio", S_IWUGO | S_IRUSR | S_IRGRP, &num_audiodevs},};static int dmabuf;static int dmabug;module_param(dmabuf, int, 0444);module_param(dmabug, int, 0444);static int __init oss_init(void){ int err; int i, j; #ifdef CONFIG_PCI if(dmabug) isa_dma_bridge_buggy = dmabug;#endif err = create_special_devices(); if (err) { printk(KERN_ERR "sound: driver already loaded/included in kernel\n"); return err; } /* Protecting the innocent */ sound_dmap_flag = (dmabuf > 0 ? 1 : 0); for (i = 0; i < ARRAY_SIZE(dev_list); i++) { device_create(sound_class, NULL, MKDEV(SOUND_MAJOR, dev_list[i].minor), "%s", dev_list[i].name); if (!dev_list[i].num) continue; for (j = 1; j < *dev_list[i].num; j++) device_create(sound_class, NULL, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)), "%s%d", dev_list[i].name, j); } if (sound_nblocks >= 1024) printk(KERN_ERR "Sound warning: Deallocation table was too small.\n"); return 0;}static void __exit oss_cleanup(void){ int i, j; for (i = 0; i < ARRAY_SIZE(dev_list); i++) { device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor)); if (!dev_list[i].num) continue; for (j = 1; j < *dev_list[i].num; j++) device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10))); } unregister_sound_special(1); unregister_sound_special(8); sound_stop_timer(); sequencer_unload(); for (i = 0; i < MAX_DMA_CHANNELS; i++) if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) { printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i); sound_free_dma(i); } for (i = 0; i < sound_nblocks; i++) vfree(sound_mem_blocks[i]);}module_init(oss_init);module_exit(oss_cleanup);MODULE_LICENSE("GPL");MODULE_DESCRIPTION("OSS Sound subsystem");MODULE_AUTHOR("Hannu Savolainen, et al.");int sound_alloc_dma(int chn, char *deviceID){ int err; if ((err = request_dma(chn, deviceID)) != 0) return err; dma_alloc_map[chn] = DMA_MAP_FREE; return 0;}EXPORT_SYMBOL(sound_alloc_dma);int sound_open_dma(int chn, char *deviceID){ if (!valid_dma(chn)) { printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn); return 1; } if (dma_alloc_map[chn] != DMA_MAP_FREE) { printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]); return 1; } dma_alloc_map[chn] = DMA_MAP_BUSY; return 0;}EXPORT_SYMBOL(sound_open_dma);void sound_free_dma(int chn){ if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) { /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */ return; } free_dma(chn); dma_alloc_map[chn] = DMA_MAP_UNAVAIL;}EXPORT_SYMBOL(sound_free_dma);void sound_close_dma(int chn){ if (dma_alloc_map[chn] != DMA_MAP_BUSY) { printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn); return; } dma_alloc_map[chn] = DMA_MAP_FREE;}EXPORT_SYMBOL(sound_close_dma);static void do_sequencer_timer(unsigned long dummy){ sequencer_timer(0);}static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0);void request_sound_timer(int count){ extern unsigned long seq_time; if (count < 0) { seq_timer.expires = (-count) + jiffies; add_timer(&seq_timer); return; } count += seq_time; count -= jiffies; if (count < 1) count = 1; seq_timer.expires = (count) + jiffies; add_timer(&seq_timer);}void sound_stop_timer(void){ del_timer(&seq_timer);}void conf_printf(char *name, struct address_info *hw_config){#ifndef CONFIG_SOUND_TRACEINIT return;#else printk("<%s> at 0x%03x", name, hw_config->io_base); if (hw_config->irq) printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq); if (hw_config->dma != -1 || hw_config->dma2 != -1) { printk(" dma %d", hw_config->dma); if (hw_config->dma2 != -1) printk(",%d", hw_config->dma2); } printk("\n");#endif}EXPORT_SYMBOL(conf_printf);void conf_printf2(char *name, int base, int irq, int dma, int dma2){#ifndef CONFIG_SOUND_TRACEINIT return;#else printk("<%s> at 0x%03x", name, base); if (irq) printk(" irq %d", (irq > 0) ? irq : -irq); if (dma != -1 || dma2 != -1) { printk(" dma %d", dma); if (dma2 != -1) printk(",%d", dma2); } printk("\n");#endif}EXPORT_SYMBOL(conf_printf2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -