123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- #include <linux/module.h>
- #include <linux/device.h>
- #include <linux/err.h>
- #include <linux/kdev_t.h>
- #include <linux/major.h>
- #include <sound/core.h>
- #ifdef CONFIG_SOUND_OSS_CORE
- static int __init init_oss_soundcore(void);
- static void cleanup_oss_soundcore(void);
- #else
- static inline int init_oss_soundcore(void) { return 0; }
- static inline void cleanup_oss_soundcore(void) { }
- #endif
- struct class *sound_class;
- EXPORT_SYMBOL(sound_class);
- MODULE_DESCRIPTION("Core sound module");
- MODULE_AUTHOR("Alan Cox");
- MODULE_LICENSE("GPL");
- static char *sound_devnode(struct device *dev, umode_t *mode)
- {
- if (MAJOR(dev->devt) == SOUND_MAJOR)
- return NULL;
- return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev));
- }
- static int __init init_soundcore(void)
- {
- int rc;
- rc = init_oss_soundcore();
- if (rc)
- return rc;
- sound_class = class_create(THIS_MODULE, "sound");
- if (IS_ERR(sound_class)) {
- cleanup_oss_soundcore();
- return PTR_ERR(sound_class);
- }
- sound_class->devnode = sound_devnode;
- return 0;
- }
- static void __exit cleanup_soundcore(void)
- {
- cleanup_oss_soundcore();
- class_destroy(sound_class);
- }
- subsys_initcall(init_soundcore);
- module_exit(cleanup_soundcore);
- #ifdef CONFIG_SOUND_OSS_CORE
- #include <linux/init.h>
- #include <linux/slab.h>
- #include <linux/types.h>
- #include <linux/kernel.h>
- #include <linux/sound.h>
- #include <linux/kmod.h>
- #define SOUND_STEP 16
- struct sound_unit
- {
- int unit_minor;
- const struct file_operations *unit_fops;
- struct sound_unit *next;
- char name[32];
- };
- #ifdef CONFIG_SOUND_MSNDCLAS
- extern int msnd_classic_init(void);
- #endif
- #ifdef CONFIG_SOUND_MSNDPIN
- extern int msnd_pinnacle_init(void);
- #endif
- #ifdef CONFIG_SOUND_OSS_CORE_PRECLAIM
- static int preclaim_oss = 1;
- #else
- static int preclaim_oss = 0;
- #endif
- module_param(preclaim_oss, int, 0444);
- static int soundcore_open(struct inode *, struct file *);
- static const struct file_operations soundcore_fops =
- {
-
- .owner = THIS_MODULE,
- .open = soundcore_open,
- .llseek = noop_llseek,
- };
- static int __sound_insert_unit(struct sound_unit * s, struct sound_unit **list, const struct file_operations *fops, int index, int low, int top)
- {
- int n=low;
- if (index < 0) {
- while (*list && (*list)->unit_minor<n)
- list=&((*list)->next);
- while(n<top)
- {
-
- if(*list==NULL || (*list)->unit_minor>n)
- break;
- list=&((*list)->next);
- n+=SOUND_STEP;
- }
- if(n>=top)
- return -ENOENT;
- } else {
- n = low+(index*16);
- while (*list) {
- if ((*list)->unit_minor==n)
- return -EBUSY;
- if ((*list)->unit_minor>n)
- break;
- list=&((*list)->next);
- }
- }
-
-
-
- s->unit_minor=n;
- s->unit_fops=fops;
-
-
-
- s->next=*list;
- *list=s;
-
-
- return n;
- }
-
- static struct sound_unit *__sound_remove_unit(struct sound_unit **list, int unit)
- {
- while(*list)
- {
- struct sound_unit *p=*list;
- if(p->unit_minor==unit)
- {
- *list=p->next;
- return p;
- }
- list=&(p->next);
- }
- printk(KERN_ERR "Sound device %d went missing!\n", unit);
- return NULL;
- }
- static DEFINE_SPINLOCK(sound_loader_lock);
- static int sound_insert_unit(struct sound_unit **list, const struct file_operations *fops, int index, int low, int top, const char *name, umode_t mode, struct device *dev)
- {
- struct sound_unit *s = kmalloc(sizeof(*s), GFP_KERNEL);
- int r;
- if (!s)
- return -ENOMEM;
- spin_lock(&sound_loader_lock);
- retry:
- r = __sound_insert_unit(s, list, fops, index, low, top);
- spin_unlock(&sound_loader_lock);
-
- if (r < 0)
- goto fail;
- else if (r < SOUND_STEP)
- sprintf(s->name, "sound/%s", name);
- else
- sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
- if (!preclaim_oss) {
-
- r = __register_chrdev(SOUND_MAJOR, s->unit_minor, 1, s->name,
- &soundcore_fops);
- if (r < 0) {
- spin_lock(&sound_loader_lock);
- __sound_remove_unit(list, s->unit_minor);
- if (index < 0) {
- low = s->unit_minor + SOUND_STEP;
- goto retry;
- }
- spin_unlock(&sound_loader_lock);
- return -EBUSY;
- }
- }
- device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
- NULL, "%s", s->name+6);
- return s->unit_minor;
- fail:
- kfree(s);
- return r;
- }
-
- static void sound_remove_unit(struct sound_unit **list, int unit)
- {
- struct sound_unit *p;
- spin_lock(&sound_loader_lock);
- p = __sound_remove_unit(list, unit);
- spin_unlock(&sound_loader_lock);
- if (p) {
- if (!preclaim_oss)
- __unregister_chrdev(SOUND_MAJOR, p->unit_minor, 1,
- p->name);
- device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
- kfree(p);
- }
- }
- static struct sound_unit *chains[SOUND_STEP];
-
- int register_sound_special_device(const struct file_operations *fops, int unit,
- struct device *dev)
- {
- const int chain = unit % SOUND_STEP;
- int max_unit = 256;
- const char *name;
- char _name[16];
- switch (chain) {
- case 0:
- name = "mixer";
- break;
- case 1:
- name = "sequencer";
- if (unit >= SOUND_STEP)
- goto __unknown;
- max_unit = unit + 1;
- break;
- case 2:
- name = "midi";
- break;
- case 3:
- name = "dsp";
- break;
- case 4:
- name = "audio";
- break;
- case 5:
- name = "dspW";
- break;
- case 8:
- name = "sequencer2";
- if (unit >= SOUND_STEP)
- goto __unknown;
- max_unit = unit + 1;
- break;
- case 9:
- name = "dmmidi";
- break;
- case 10:
- name = "dmfm";
- break;
- case 12:
- name = "adsp";
- break;
- case 13:
- name = "amidi";
- break;
- case 14:
- name = "admmidi";
- break;
- default:
- {
- __unknown:
- sprintf(_name, "unknown%d", chain);
- if (unit >= SOUND_STEP)
- strcat(_name, "-");
- name = _name;
- }
- break;
- }
- return sound_insert_unit(&chains[chain], fops, -1, unit, max_unit,
- name, S_IRUSR | S_IWUSR, dev);
- }
-
- EXPORT_SYMBOL(register_sound_special_device);
- int register_sound_special(const struct file_operations *fops, int unit)
- {
- return register_sound_special_device(fops, unit, NULL);
- }
- EXPORT_SYMBOL(register_sound_special);
- int register_sound_mixer(const struct file_operations *fops, int dev)
- {
- return sound_insert_unit(&chains[0], fops, dev, 0, 128,
- "mixer", S_IRUSR | S_IWUSR, NULL);
- }
- EXPORT_SYMBOL(register_sound_mixer);
- int register_sound_midi(const struct file_operations *fops, int dev)
- {
- return sound_insert_unit(&chains[2], fops, dev, 2, 130,
- "midi", S_IRUSR | S_IWUSR, NULL);
- }
- EXPORT_SYMBOL(register_sound_midi);
-
- int register_sound_dsp(const struct file_operations *fops, int dev)
- {
- return sound_insert_unit(&chains[3], fops, dev, 3, 131,
- "dsp", S_IWUSR | S_IRUSR, NULL);
- }
- EXPORT_SYMBOL(register_sound_dsp);
- void unregister_sound_special(int unit)
- {
- sound_remove_unit(&chains[unit % SOUND_STEP], unit);
- }
-
- EXPORT_SYMBOL(unregister_sound_special);
- void unregister_sound_mixer(int unit)
- {
- sound_remove_unit(&chains[0], unit);
- }
- EXPORT_SYMBOL(unregister_sound_mixer);
- void unregister_sound_midi(int unit)
- {
- sound_remove_unit(&chains[2], unit);
- }
- EXPORT_SYMBOL(unregister_sound_midi);
- void unregister_sound_dsp(int unit)
- {
- sound_remove_unit(&chains[3], unit);
- }
- EXPORT_SYMBOL(unregister_sound_dsp);
- static struct sound_unit *__look_for_unit(int chain, int unit)
- {
- struct sound_unit *s;
-
- s=chains[chain];
- while(s && s->unit_minor <= unit)
- {
- if(s->unit_minor==unit)
- return s;
- s=s->next;
- }
- return NULL;
- }
- static int soundcore_open(struct inode *inode, struct file *file)
- {
- int chain;
- int unit = iminor(inode);
- struct sound_unit *s;
- const struct file_operations *new_fops = NULL;
- chain=unit&0x0F;
- if(chain==4 || chain==5)
- {
- unit&=0xF0;
- unit|=3;
- chain=3;
- }
-
- spin_lock(&sound_loader_lock);
- s = __look_for_unit(chain, unit);
- if (s)
- new_fops = fops_get(s->unit_fops);
- if (preclaim_oss && !new_fops) {
- spin_unlock(&sound_loader_lock);
-
- request_module("sound-slot-%i", unit>>4);
- request_module("sound-service-%i-%i", unit>>4, chain);
-
- if (request_module("char-major-%d-%d", SOUND_MAJOR, unit) > 0)
- request_module("char-major-%d", SOUND_MAJOR);
- spin_lock(&sound_loader_lock);
- s = __look_for_unit(chain, unit);
- if (s)
- new_fops = fops_get(s->unit_fops);
- }
- spin_unlock(&sound_loader_lock);
- if (new_fops) {
-
- int err = 0;
- replace_fops(file, new_fops);
- if (file->f_op->open)
- err = file->f_op->open(inode,file);
- return err;
- }
- return -ENODEV;
- }
- MODULE_ALIAS_CHARDEV_MAJOR(SOUND_MAJOR);
- static void cleanup_oss_soundcore(void)
- {
-
- unregister_chrdev(SOUND_MAJOR, "sound");
- }
- static int __init init_oss_soundcore(void)
- {
- if (preclaim_oss &&
- register_chrdev(SOUND_MAJOR, "sound", &soundcore_fops) == -1) {
- printk(KERN_ERR "soundcore: sound device already in use.\n");
- return -EBUSY;
- }
- return 0;
- }
- #endif
|