[PKT_SCHED]: Remove unused exports.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / core / info.c
blob0b4aab3225e5270a998e77e06e7821973b3e2146
1 /*
2 * Information interface for ALSA driver
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/time.h>
25 #include <linux/smp_lock.h>
26 #include <linux/string.h>
27 #include <sound/core.h>
28 #include <sound/minors.h>
29 #include <sound/info.h>
30 #include <sound/version.h>
31 #include <linux/proc_fs.h>
32 #include <linux/mutex.h>
33 #include <stdarg.h>
39 #ifdef CONFIG_PROC_FS
41 int snd_info_check_reserved_words(const char *str)
43 static char *reserved[] =
45 "version",
46 "meminfo",
47 "memdebug",
48 "detect",
49 "devices",
50 "oss",
51 "cards",
52 "timers",
53 "synth",
54 "pcm",
55 "seq",
56 NULL
58 char **xstr = reserved;
60 while (*xstr) {
61 if (!strcmp(*xstr, str))
62 return 0;
63 xstr++;
65 if (!strncmp(str, "card", 4))
66 return 0;
67 return 1;
70 static DEFINE_MUTEX(info_mutex);
72 struct snd_info_private_data {
73 struct snd_info_buffer *rbuffer;
74 struct snd_info_buffer *wbuffer;
75 struct snd_info_entry *entry;
76 void *file_private_data;
79 static int snd_info_version_init(void);
80 static int snd_info_version_done(void);
81 static void snd_info_disconnect(struct snd_info_entry *entry);
84 /* resize the proc r/w buffer */
85 static int resize_info_buffer(struct snd_info_buffer *buffer,
86 unsigned int nsize)
88 char *nbuf;
90 nsize = PAGE_ALIGN(nsize);
91 nbuf = kmalloc(nsize, GFP_KERNEL);
92 if (! nbuf)
93 return -ENOMEM;
95 memcpy(nbuf, buffer->buffer, buffer->len);
96 kfree(buffer->buffer);
97 buffer->buffer = nbuf;
98 buffer->len = nsize;
99 return 0;
103 * snd_iprintf - printf on the procfs buffer
104 * @buffer: the procfs buffer
105 * @fmt: the printf format
107 * Outputs the string on the procfs buffer just like printf().
109 * Returns the size of output string.
111 int snd_iprintf(struct snd_info_buffer *buffer, char *fmt,...)
113 va_list args;
114 int len, res;
115 int err = 0;
117 might_sleep();
118 if (buffer->stop || buffer->error)
119 return 0;
120 len = buffer->len - buffer->size;
121 va_start(args, fmt);
122 for (;;) {
123 va_list ap;
124 va_copy(ap, args);
125 res = vsnprintf(buffer->buffer + buffer->curr, len, fmt, ap);
126 va_end(ap);
127 if (res < len)
128 break;
129 err = resize_info_buffer(buffer, buffer->len + PAGE_SIZE);
130 if (err < 0)
131 break;
132 len = buffer->len - buffer->size;
134 va_end(args);
136 if (err < 0)
137 return err;
138 buffer->curr += res;
139 buffer->size += res;
140 return res;
143 EXPORT_SYMBOL(snd_iprintf);
149 static struct proc_dir_entry *snd_proc_root;
150 struct snd_info_entry *snd_seq_root;
151 EXPORT_SYMBOL(snd_seq_root);
153 #ifdef CONFIG_SND_OSSEMUL
154 struct snd_info_entry *snd_oss_root;
155 #endif
157 static inline void snd_info_entry_prepare(struct proc_dir_entry *de)
159 de->owner = THIS_MODULE;
162 static void snd_remove_proc_entry(struct proc_dir_entry *parent,
163 struct proc_dir_entry *de)
165 if (de)
166 remove_proc_entry(de->name, parent);
169 static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
171 struct snd_info_private_data *data;
172 struct snd_info_entry *entry;
173 loff_t ret;
175 data = file->private_data;
176 entry = data->entry;
177 lock_kernel();
178 switch (entry->content) {
179 case SNDRV_INFO_CONTENT_TEXT:
180 switch (orig) {
181 case SEEK_SET:
182 file->f_pos = offset;
183 ret = file->f_pos;
184 goto out;
185 case SEEK_CUR:
186 file->f_pos += offset;
187 ret = file->f_pos;
188 goto out;
189 case SEEK_END:
190 default:
191 ret = -EINVAL;
192 goto out;
194 break;
195 case SNDRV_INFO_CONTENT_DATA:
196 if (entry->c.ops->llseek) {
197 ret = entry->c.ops->llseek(entry,
198 data->file_private_data,
199 file, offset, orig);
200 goto out;
202 break;
204 ret = -ENXIO;
205 out:
206 unlock_kernel();
207 return ret;
210 static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
211 size_t count, loff_t * offset)
213 struct snd_info_private_data *data;
214 struct snd_info_entry *entry;
215 struct snd_info_buffer *buf;
216 size_t size = 0;
217 loff_t pos;
219 data = file->private_data;
220 snd_assert(data != NULL, return -ENXIO);
221 pos = *offset;
222 if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
223 return -EIO;
224 if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
225 return -EIO;
226 entry = data->entry;
227 switch (entry->content) {
228 case SNDRV_INFO_CONTENT_TEXT:
229 buf = data->rbuffer;
230 if (buf == NULL)
231 return -EIO;
232 if (pos >= buf->size)
233 return 0;
234 size = buf->size - pos;
235 size = min(count, size);
236 if (copy_to_user(buffer, buf->buffer + pos, size))
237 return -EFAULT;
238 break;
239 case SNDRV_INFO_CONTENT_DATA:
240 if (entry->c.ops->read)
241 size = entry->c.ops->read(entry,
242 data->file_private_data,
243 file, buffer, count, pos);
244 break;
246 if ((ssize_t) size > 0)
247 *offset = pos + size;
248 return size;
251 static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer,
252 size_t count, loff_t * offset)
254 struct snd_info_private_data *data;
255 struct snd_info_entry *entry;
256 struct snd_info_buffer *buf;
257 ssize_t size = 0;
258 loff_t pos;
260 data = file->private_data;
261 snd_assert(data != NULL, return -ENXIO);
262 entry = data->entry;
263 pos = *offset;
264 if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
265 return -EIO;
266 if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
267 return -EIO;
268 switch (entry->content) {
269 case SNDRV_INFO_CONTENT_TEXT:
270 buf = data->wbuffer;
271 if (buf == NULL)
272 return -EIO;
273 mutex_lock(&entry->access);
274 if (pos + count >= buf->len) {
275 if (resize_info_buffer(buf, pos + count)) {
276 mutex_unlock(&entry->access);
277 return -ENOMEM;
280 if (copy_from_user(buf->buffer + pos, buffer, count)) {
281 mutex_unlock(&entry->access);
282 return -EFAULT;
284 buf->size = pos + count;
285 mutex_unlock(&entry->access);
286 size = count;
287 break;
288 case SNDRV_INFO_CONTENT_DATA:
289 if (entry->c.ops->write)
290 size = entry->c.ops->write(entry,
291 data->file_private_data,
292 file, buffer, count, pos);
293 break;
295 if ((ssize_t) size > 0)
296 *offset = pos + size;
297 return size;
300 static int snd_info_entry_open(struct inode *inode, struct file *file)
302 struct snd_info_entry *entry;
303 struct snd_info_private_data *data;
304 struct snd_info_buffer *buffer;
305 struct proc_dir_entry *p;
306 int mode, err;
308 mutex_lock(&info_mutex);
309 p = PDE(inode);
310 entry = p == NULL ? NULL : (struct snd_info_entry *)p->data;
311 if (entry == NULL || ! entry->p) {
312 mutex_unlock(&info_mutex);
313 return -ENODEV;
315 if (!try_module_get(entry->module)) {
316 err = -EFAULT;
317 goto __error1;
319 mode = file->f_flags & O_ACCMODE;
320 if (mode == O_RDONLY || mode == O_RDWR) {
321 if ((entry->content == SNDRV_INFO_CONTENT_DATA &&
322 entry->c.ops->read == NULL)) {
323 err = -ENODEV;
324 goto __error;
327 if (mode == O_WRONLY || mode == O_RDWR) {
328 if ((entry->content == SNDRV_INFO_CONTENT_DATA &&
329 entry->c.ops->write == NULL)) {
330 err = -ENODEV;
331 goto __error;
334 data = kzalloc(sizeof(*data), GFP_KERNEL);
335 if (data == NULL) {
336 err = -ENOMEM;
337 goto __error;
339 data->entry = entry;
340 switch (entry->content) {
341 case SNDRV_INFO_CONTENT_TEXT:
342 if (mode == O_RDONLY || mode == O_RDWR) {
343 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
344 if (buffer == NULL)
345 goto __nomem;
346 data->rbuffer = buffer;
347 buffer->len = PAGE_SIZE;
348 buffer->buffer = kmalloc(buffer->len, GFP_KERNEL);
349 if (buffer->buffer == NULL)
350 goto __nomem;
352 if (mode == O_WRONLY || mode == O_RDWR) {
353 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
354 if (buffer == NULL)
355 goto __nomem;
356 data->wbuffer = buffer;
357 buffer->len = PAGE_SIZE;
358 buffer->buffer = kmalloc(buffer->len, GFP_KERNEL);
359 if (buffer->buffer == NULL)
360 goto __nomem;
362 break;
363 case SNDRV_INFO_CONTENT_DATA: /* data */
364 if (entry->c.ops->open) {
365 if ((err = entry->c.ops->open(entry, mode,
366 &data->file_private_data)) < 0) {
367 kfree(data);
368 goto __error;
371 break;
373 file->private_data = data;
374 mutex_unlock(&info_mutex);
375 if (entry->content == SNDRV_INFO_CONTENT_TEXT &&
376 (mode == O_RDONLY || mode == O_RDWR)) {
377 if (entry->c.text.read) {
378 mutex_lock(&entry->access);
379 entry->c.text.read(entry, data->rbuffer);
380 mutex_unlock(&entry->access);
383 return 0;
385 __nomem:
386 if (data->rbuffer) {
387 kfree(data->rbuffer->buffer);
388 kfree(data->rbuffer);
390 if (data->wbuffer) {
391 kfree(data->wbuffer->buffer);
392 kfree(data->wbuffer);
394 kfree(data);
395 err = -ENOMEM;
396 __error:
397 module_put(entry->module);
398 __error1:
399 mutex_unlock(&info_mutex);
400 return err;
403 static int snd_info_entry_release(struct inode *inode, struct file *file)
405 struct snd_info_entry *entry;
406 struct snd_info_private_data *data;
407 int mode;
409 mode = file->f_flags & O_ACCMODE;
410 data = file->private_data;
411 entry = data->entry;
412 switch (entry->content) {
413 case SNDRV_INFO_CONTENT_TEXT:
414 if (data->rbuffer) {
415 kfree(data->rbuffer->buffer);
416 kfree(data->rbuffer);
418 if (data->wbuffer) {
419 if (entry->c.text.write) {
420 entry->c.text.write(entry, data->wbuffer);
421 if (data->wbuffer->error) {
422 snd_printk(KERN_WARNING "data write error to %s (%i)\n",
423 entry->name,
424 data->wbuffer->error);
427 kfree(data->wbuffer->buffer);
428 kfree(data->wbuffer);
430 break;
431 case SNDRV_INFO_CONTENT_DATA:
432 if (entry->c.ops->release)
433 entry->c.ops->release(entry, mode,
434 data->file_private_data);
435 break;
437 module_put(entry->module);
438 kfree(data);
439 return 0;
442 static unsigned int snd_info_entry_poll(struct file *file, poll_table * wait)
444 struct snd_info_private_data *data;
445 struct snd_info_entry *entry;
446 unsigned int mask;
448 data = file->private_data;
449 if (data == NULL)
450 return 0;
451 entry = data->entry;
452 mask = 0;
453 switch (entry->content) {
454 case SNDRV_INFO_CONTENT_DATA:
455 if (entry->c.ops->poll)
456 return entry->c.ops->poll(entry,
457 data->file_private_data,
458 file, wait);
459 if (entry->c.ops->read)
460 mask |= POLLIN | POLLRDNORM;
461 if (entry->c.ops->write)
462 mask |= POLLOUT | POLLWRNORM;
463 break;
465 return mask;
468 static long snd_info_entry_ioctl(struct file *file, unsigned int cmd,
469 unsigned long arg)
471 struct snd_info_private_data *data;
472 struct snd_info_entry *entry;
474 data = file->private_data;
475 if (data == NULL)
476 return 0;
477 entry = data->entry;
478 switch (entry->content) {
479 case SNDRV_INFO_CONTENT_DATA:
480 if (entry->c.ops->ioctl)
481 return entry->c.ops->ioctl(entry,
482 data->file_private_data,
483 file, cmd, arg);
484 break;
486 return -ENOTTY;
489 static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma)
491 struct inode *inode = file->f_dentry->d_inode;
492 struct snd_info_private_data *data;
493 struct snd_info_entry *entry;
495 data = file->private_data;
496 if (data == NULL)
497 return 0;
498 entry = data->entry;
499 switch (entry->content) {
500 case SNDRV_INFO_CONTENT_DATA:
501 if (entry->c.ops->mmap)
502 return entry->c.ops->mmap(entry,
503 data->file_private_data,
504 inode, file, vma);
505 break;
507 return -ENXIO;
510 static struct file_operations snd_info_entry_operations =
512 .owner = THIS_MODULE,
513 .llseek = snd_info_entry_llseek,
514 .read = snd_info_entry_read,
515 .write = snd_info_entry_write,
516 .poll = snd_info_entry_poll,
517 .unlocked_ioctl = snd_info_entry_ioctl,
518 .mmap = snd_info_entry_mmap,
519 .open = snd_info_entry_open,
520 .release = snd_info_entry_release,
524 * snd_create_proc_entry - create a procfs entry
525 * @name: the name of the proc file
526 * @mode: the file permission bits, S_Ixxx
527 * @parent: the parent proc-directory entry
529 * Creates a new proc file entry with the given name and permission
530 * on the given directory.
532 * Returns the pointer of new instance or NULL on failure.
534 static struct proc_dir_entry *snd_create_proc_entry(const char *name, mode_t mode,
535 struct proc_dir_entry *parent)
537 struct proc_dir_entry *p;
538 p = create_proc_entry(name, mode, parent);
539 if (p)
540 snd_info_entry_prepare(p);
541 return p;
544 int __init snd_info_init(void)
546 struct proc_dir_entry *p;
548 p = snd_create_proc_entry("asound", S_IFDIR | S_IRUGO | S_IXUGO, &proc_root);
549 if (p == NULL)
550 return -ENOMEM;
551 snd_proc_root = p;
552 #ifdef CONFIG_SND_OSSEMUL
554 struct snd_info_entry *entry;
555 if ((entry = snd_info_create_module_entry(THIS_MODULE, "oss", NULL)) == NULL)
556 return -ENOMEM;
557 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
558 if (snd_info_register(entry) < 0) {
559 snd_info_free_entry(entry);
560 return -ENOMEM;
562 snd_oss_root = entry;
564 #endif
565 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
567 struct snd_info_entry *entry;
568 if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL)
569 return -ENOMEM;
570 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
571 if (snd_info_register(entry) < 0) {
572 snd_info_free_entry(entry);
573 return -ENOMEM;
575 snd_seq_root = entry;
577 #endif
578 snd_info_version_init();
579 snd_minor_info_init();
580 snd_minor_info_oss_init();
581 snd_card_info_init();
582 return 0;
585 int __exit snd_info_done(void)
587 snd_card_info_done();
588 snd_minor_info_oss_done();
589 snd_minor_info_done();
590 snd_info_version_done();
591 if (snd_proc_root) {
592 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
593 snd_info_free_entry(snd_seq_root);
594 #endif
595 #ifdef CONFIG_SND_OSSEMUL
596 snd_info_free_entry(snd_oss_root);
597 #endif
598 snd_remove_proc_entry(&proc_root, snd_proc_root);
600 return 0;
609 * create a card proc file
610 * called from init.c
612 int snd_info_card_create(struct snd_card *card)
614 char str[8];
615 struct snd_info_entry *entry;
617 snd_assert(card != NULL, return -ENXIO);
619 sprintf(str, "card%i", card->number);
620 if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL)
621 return -ENOMEM;
622 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
623 if (snd_info_register(entry) < 0) {
624 snd_info_free_entry(entry);
625 return -ENOMEM;
627 card->proc_root = entry;
628 return 0;
632 * register the card proc file
633 * called from init.c
635 int snd_info_card_register(struct snd_card *card)
637 struct proc_dir_entry *p;
639 snd_assert(card != NULL, return -ENXIO);
641 if (!strcmp(card->id, card->proc_root->name))
642 return 0;
644 p = proc_symlink(card->id, snd_proc_root, card->proc_root->name);
645 if (p == NULL)
646 return -ENOMEM;
647 card->proc_root_link = p;
648 return 0;
652 * de-register the card proc file
653 * called from init.c
655 void snd_info_card_disconnect(struct snd_card *card)
657 snd_assert(card != NULL, return);
658 mutex_lock(&info_mutex);
659 if (card->proc_root_link) {
660 snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
661 card->proc_root_link = NULL;
663 if (card->proc_root)
664 snd_info_disconnect(card->proc_root);
665 mutex_unlock(&info_mutex);
669 * release the card proc file resources
670 * called from init.c
672 int snd_info_card_free(struct snd_card *card)
674 snd_assert(card != NULL, return -ENXIO);
675 snd_info_free_entry(card->proc_root);
676 card->proc_root = NULL;
677 return 0;
682 * snd_info_get_line - read one line from the procfs buffer
683 * @buffer: the procfs buffer
684 * @line: the buffer to store
685 * @len: the max. buffer size - 1
687 * Reads one line from the buffer and stores the string.
689 * Returns zero if successful, or 1 if error or EOF.
691 int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
693 int c = -1;
695 if (len <= 0 || buffer->stop || buffer->error)
696 return 1;
697 while (--len > 0) {
698 c = buffer->buffer[buffer->curr++];
699 if (c == '\n') {
700 if (buffer->curr >= buffer->size)
701 buffer->stop = 1;
702 break;
704 *line++ = c;
705 if (buffer->curr >= buffer->size) {
706 buffer->stop = 1;
707 break;
710 while (c != '\n' && !buffer->stop) {
711 c = buffer->buffer[buffer->curr++];
712 if (buffer->curr >= buffer->size)
713 buffer->stop = 1;
715 *line = '\0';
716 return 0;
719 EXPORT_SYMBOL(snd_info_get_line);
722 * snd_info_get_str - parse a string token
723 * @dest: the buffer to store the string token
724 * @src: the original string
725 * @len: the max. length of token - 1
727 * Parses the original string and copy a token to the given
728 * string buffer.
730 * Returns the updated pointer of the original string so that
731 * it can be used for the next call.
733 char *snd_info_get_str(char *dest, char *src, int len)
735 int c;
737 while (*src == ' ' || *src == '\t')
738 src++;
739 if (*src == '"' || *src == '\'') {
740 c = *src++;
741 while (--len > 0 && *src && *src != c) {
742 *dest++ = *src++;
744 if (*src == c)
745 src++;
746 } else {
747 while (--len > 0 && *src && *src != ' ' && *src != '\t') {
748 *dest++ = *src++;
751 *dest = 0;
752 while (*src == ' ' || *src == '\t')
753 src++;
754 return src;
757 EXPORT_SYMBOL(snd_info_get_str);
760 * snd_info_create_entry - create an info entry
761 * @name: the proc file name
763 * Creates an info entry with the given file name and initializes as
764 * the default state.
766 * Usually called from other functions such as
767 * snd_info_create_card_entry().
769 * Returns the pointer of the new instance, or NULL on failure.
771 static struct snd_info_entry *snd_info_create_entry(const char *name)
773 struct snd_info_entry *entry;
774 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
775 if (entry == NULL)
776 return NULL;
777 entry->name = kstrdup(name, GFP_KERNEL);
778 if (entry->name == NULL) {
779 kfree(entry);
780 return NULL;
782 entry->mode = S_IFREG | S_IRUGO;
783 entry->content = SNDRV_INFO_CONTENT_TEXT;
784 mutex_init(&entry->access);
785 INIT_LIST_HEAD(&entry->children);
786 INIT_LIST_HEAD(&entry->list);
787 return entry;
791 * snd_info_create_module_entry - create an info entry for the given module
792 * @module: the module pointer
793 * @name: the file name
794 * @parent: the parent directory
796 * Creates a new info entry and assigns it to the given module.
798 * Returns the pointer of the new instance, or NULL on failure.
800 struct snd_info_entry *snd_info_create_module_entry(struct module * module,
801 const char *name,
802 struct snd_info_entry *parent)
804 struct snd_info_entry *entry = snd_info_create_entry(name);
805 if (entry) {
806 entry->module = module;
807 entry->parent = parent;
809 return entry;
812 EXPORT_SYMBOL(snd_info_create_module_entry);
815 * snd_info_create_card_entry - create an info entry for the given card
816 * @card: the card instance
817 * @name: the file name
818 * @parent: the parent directory
820 * Creates a new info entry and assigns it to the given card.
822 * Returns the pointer of the new instance, or NULL on failure.
824 struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
825 const char *name,
826 struct snd_info_entry * parent)
828 struct snd_info_entry *entry = snd_info_create_entry(name);
829 if (entry) {
830 entry->module = card->module;
831 entry->card = card;
832 entry->parent = parent;
834 return entry;
837 EXPORT_SYMBOL(snd_info_create_card_entry);
839 static void snd_info_disconnect(struct snd_info_entry *entry)
841 struct list_head *p, *n;
842 struct proc_dir_entry *root;
844 list_for_each_safe(p, n, &entry->children) {
845 snd_info_disconnect(list_entry(p, struct snd_info_entry, list));
848 if (! entry->p)
849 return;
850 list_del_init(&entry->list);
851 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
852 snd_assert(root, return);
853 snd_remove_proc_entry(root, entry->p);
854 entry->p = NULL;
857 static int snd_info_dev_free_entry(struct snd_device *device)
859 struct snd_info_entry *entry = device->device_data;
860 snd_info_free_entry(entry);
861 return 0;
864 static int snd_info_dev_register_entry(struct snd_device *device)
866 struct snd_info_entry *entry = device->device_data;
867 return snd_info_register(entry);
871 * snd_card_proc_new - create an info entry for the given card
872 * @card: the card instance
873 * @name: the file name
874 * @entryp: the pointer to store the new info entry
876 * Creates a new info entry and assigns it to the given card.
877 * Unlike snd_info_create_card_entry(), this function registers the
878 * info entry as an ALSA device component, so that it can be
879 * unregistered/released without explicit call.
880 * Also, you don't have to register this entry via snd_info_register(),
881 * since this will be registered by snd_card_register() automatically.
883 * The parent is assumed as card->proc_root.
885 * For releasing this entry, use snd_device_free() instead of
886 * snd_info_free_entry().
888 * Returns zero if successful, or a negative error code on failure.
890 int snd_card_proc_new(struct snd_card *card, const char *name,
891 struct snd_info_entry **entryp)
893 static struct snd_device_ops ops = {
894 .dev_free = snd_info_dev_free_entry,
895 .dev_register = snd_info_dev_register_entry,
896 /* disconnect is done via snd_info_card_disconnect() */
898 struct snd_info_entry *entry;
899 int err;
901 entry = snd_info_create_card_entry(card, name, card->proc_root);
902 if (! entry)
903 return -ENOMEM;
904 if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) {
905 snd_info_free_entry(entry);
906 return err;
908 if (entryp)
909 *entryp = entry;
910 return 0;
913 EXPORT_SYMBOL(snd_card_proc_new);
916 * snd_info_free_entry - release the info entry
917 * @entry: the info entry
919 * Releases the info entry. Don't call this after registered.
921 void snd_info_free_entry(struct snd_info_entry * entry)
923 if (entry == NULL)
924 return;
925 if (entry->p) {
926 mutex_lock(&info_mutex);
927 snd_info_disconnect(entry);
928 mutex_unlock(&info_mutex);
930 kfree(entry->name);
931 if (entry->private_free)
932 entry->private_free(entry);
933 kfree(entry);
936 EXPORT_SYMBOL(snd_info_free_entry);
939 * snd_info_register - register the info entry
940 * @entry: the info entry
942 * Registers the proc info entry.
944 * Returns zero if successful, or a negative error code on failure.
946 int snd_info_register(struct snd_info_entry * entry)
948 struct proc_dir_entry *root, *p = NULL;
950 snd_assert(entry != NULL, return -ENXIO);
951 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
952 mutex_lock(&info_mutex);
953 p = snd_create_proc_entry(entry->name, entry->mode, root);
954 if (!p) {
955 mutex_unlock(&info_mutex);
956 return -ENOMEM;
958 p->owner = entry->module;
959 if (!S_ISDIR(entry->mode))
960 p->proc_fops = &snd_info_entry_operations;
961 p->size = entry->size;
962 p->data = entry;
963 entry->p = p;
964 if (entry->parent)
965 list_add_tail(&entry->list, &entry->parent->children);
966 mutex_unlock(&info_mutex);
967 return 0;
970 EXPORT_SYMBOL(snd_info_register);
976 static struct snd_info_entry *snd_info_version_entry;
978 static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
980 snd_iprintf(buffer,
981 "Advanced Linux Sound Architecture Driver Version "
982 CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"
986 static int __init snd_info_version_init(void)
988 struct snd_info_entry *entry;
990 entry = snd_info_create_module_entry(THIS_MODULE, "version", NULL);
991 if (entry == NULL)
992 return -ENOMEM;
993 entry->c.text.read = snd_info_version_read;
994 if (snd_info_register(entry) < 0) {
995 snd_info_free_entry(entry);
996 return -ENOMEM;
998 snd_info_version_entry = entry;
999 return 0;
1002 static int __exit snd_info_version_done(void)
1004 snd_info_free_entry(snd_info_version_entry);
1005 return 0;
1008 #endif /* CONFIG_PROC_FS */