Make GET_SAVED_SP lowercase.
[linux-2.6/linux-mips.git] / sound / core / info.c
blobf6106b33eb9749a2b88e1228cb59468d919d3a8f
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/version.h>
24 #include <linux/init.h>
25 #include <linux/vmalloc.h>
26 #include <linux/time.h>
27 #include <linux/smp_lock.h>
28 #include <sound/core.h>
29 #include <sound/minors.h>
30 #include <sound/info.h>
31 #include <sound/version.h>
32 #include <linux/proc_fs.h>
33 #include <linux/devfs_fs_kernel.h>
34 #include <stdarg.h>
40 int snd_info_check_reserved_words(const char *str)
42 static char *reserved[] =
44 "version",
45 "meminfo",
46 "memdebug",
47 "detect",
48 "devices",
49 "oss",
50 "cards",
51 "timers",
52 "synth",
53 "pcm",
54 "seq",
55 NULL
57 char **xstr = reserved;
59 while (*xstr) {
60 if (!strcmp(*xstr, str))
61 return 0;
62 xstr++;
64 if (!strncmp(str, "card", 4))
65 return 0;
66 return 1;
69 #ifdef CONFIG_PROC_FS
71 static DECLARE_MUTEX(info_mutex);
73 typedef struct _snd_info_private_data {
74 snd_info_buffer_t *rbuffer;
75 snd_info_buffer_t *wbuffer;
76 snd_info_entry_t *entry;
77 void *file_private_data;
78 } snd_info_private_data_t;
80 static int snd_info_version_init(void);
81 static int snd_info_version_done(void);
84 /**
85 * snd_iprintf - printf on the procfs buffer
86 * @buffer: the procfs buffer
87 * @fmt: the printf format
89 * Outputs the string on the procfs buffer just like printf().
91 * Returns the size of output string.
93 int snd_iprintf(snd_info_buffer_t * buffer, char *fmt,...)
95 va_list args;
96 int res;
97 char sbuffer[512];
99 if (buffer->stop || buffer->error)
100 return 0;
101 va_start(args, fmt);
102 res = vsnprintf(sbuffer, sizeof(sbuffer), fmt, args);
103 va_end(args);
104 if (buffer->size + res >= buffer->len) {
105 buffer->stop = 1;
106 return 0;
108 strcpy(buffer->curr, sbuffer);
109 buffer->curr += res;
110 buffer->size += res;
111 return res;
118 struct proc_dir_entry *snd_proc_root = NULL;
119 snd_info_entry_t *snd_seq_root = NULL;
120 #ifdef CONFIG_SND_OSSEMUL
121 snd_info_entry_t *snd_oss_root = NULL;
122 #endif
124 static inline void snd_info_entry_prepare(struct proc_dir_entry *de)
126 de->owner = THIS_MODULE;
129 void snd_remove_proc_entry(struct proc_dir_entry *parent,
130 struct proc_dir_entry *de)
132 if (de)
133 remove_proc_entry(de->name, parent);
136 static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
138 snd_info_private_data_t *data;
139 struct snd_info_entry *entry;
140 loff_t ret;
142 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
143 entry = data->entry;
144 lock_kernel();
145 switch (entry->content) {
146 case SNDRV_INFO_CONTENT_TEXT:
147 switch (orig) {
148 case 0: /* SEEK_SET */
149 file->f_pos = offset;
150 ret = file->f_pos;
151 goto out;
152 case 1: /* SEEK_CUR */
153 file->f_pos += offset;
154 ret = file->f_pos;
155 goto out;
156 case 2: /* SEEK_END */
157 default:
158 ret = -EINVAL;
159 goto out;
161 break;
162 case SNDRV_INFO_CONTENT_DATA:
163 if (entry->c.ops->llseek) {
164 ret = entry->c.ops->llseek(entry,
165 data->file_private_data,
166 file, offset, orig);
167 goto out;
169 break;
171 ret = -ENXIO;
172 out:
173 unlock_kernel();
174 return ret;
177 static ssize_t snd_info_entry_read(struct file *file, char *buffer,
178 size_t count, loff_t * offset)
180 snd_info_private_data_t *data;
181 struct snd_info_entry *entry;
182 snd_info_buffer_t *buf;
183 long size = 0, size1;
185 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
186 snd_assert(data != NULL, return -ENXIO);
187 entry = data->entry;
188 switch (entry->content) {
189 case SNDRV_INFO_CONTENT_TEXT:
190 buf = data->rbuffer;
191 if (buf == NULL)
192 return -EIO;
193 if (file->f_pos >= (long)buf->size)
194 return 0;
195 size = buf->size < count ? buf->size : count;
196 size1 = buf->size - file->f_pos;
197 if (size1 < size)
198 size = size1;
199 if (copy_to_user(buffer, buf->buffer + file->f_pos, size))
200 return -EFAULT;
201 file->f_pos += size;
202 break;
203 case SNDRV_INFO_CONTENT_DATA:
204 if (entry->c.ops->read)
205 return entry->c.ops->read(entry,
206 data->file_private_data,
207 file, buffer, count);
208 if (size > 0)
209 file->f_pos += size;
210 break;
212 return size;
215 static ssize_t snd_info_entry_write(struct file *file, const char *buffer,
216 size_t count, loff_t * offset)
218 snd_info_private_data_t *data;
219 struct snd_info_entry *entry;
220 snd_info_buffer_t *buf;
221 long size = 0, size1;
223 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
224 snd_assert(data != NULL, return -ENXIO);
225 entry = data->entry;
226 switch (entry->content) {
227 case SNDRV_INFO_CONTENT_TEXT:
228 buf = data->wbuffer;
229 if (buf == NULL)
230 return -EIO;
231 if (file->f_pos < 0)
232 return -EINVAL;
233 if (file->f_pos >= (long)buf->len)
234 return -ENOMEM;
235 size = buf->len < count ? buf->len : count;
236 size1 = buf->len - file->f_pos;
237 if (size1 < size)
238 size = size1;
239 if (copy_from_user(buf->buffer + file->f_pos, buffer, size))
240 return -EFAULT;
241 if ((long)buf->size < file->f_pos + size)
242 buf->size = file->f_pos + size;
243 file->f_pos += size;
244 break;
245 case SNDRV_INFO_CONTENT_DATA:
246 if (entry->c.ops->write)
247 return entry->c.ops->write(entry,
248 data->file_private_data,
249 file, buffer, count);
250 if (size > 0)
251 file->f_pos += size;
252 break;
254 return size;
257 static int snd_info_entry_open(struct inode *inode, struct file *file)
259 snd_info_entry_t *entry;
260 snd_info_private_data_t *data;
261 snd_info_buffer_t *buffer;
262 struct proc_dir_entry *p;
263 int mode, err;
265 down(&info_mutex);
266 p = PDE(inode);
267 entry = p == NULL ? NULL : (snd_info_entry_t *)p->data;
268 if (entry == NULL || entry->disconnected) {
269 up(&info_mutex);
270 return -ENODEV;
272 if (!try_module_get(entry->module)) {
273 err = -EFAULT;
274 goto __error1;
276 mode = file->f_flags & O_ACCMODE;
277 if (mode == O_RDONLY || mode == O_RDWR) {
278 if ((entry->content == SNDRV_INFO_CONTENT_TEXT &&
279 !entry->c.text.read_size) ||
280 (entry->content == SNDRV_INFO_CONTENT_DATA &&
281 entry->c.ops->read == NULL) ||
282 entry->content == SNDRV_INFO_CONTENT_DEVICE) {
283 err = -ENODEV;
284 goto __error;
287 if (mode == O_WRONLY || mode == O_RDWR) {
288 if ((entry->content == SNDRV_INFO_CONTENT_TEXT &&
289 !entry->c.text.write_size) ||
290 (entry->content == SNDRV_INFO_CONTENT_DATA &&
291 entry->c.ops->write == NULL) ||
292 entry->content == SNDRV_INFO_CONTENT_DEVICE) {
293 err = -ENODEV;
294 goto __error;
297 data = snd_magic_kcalloc(snd_info_private_data_t, 0, GFP_KERNEL);
298 if (data == NULL) {
299 err = -ENOMEM;
300 goto __error;
302 data->entry = entry;
303 switch (entry->content) {
304 case SNDRV_INFO_CONTENT_TEXT:
305 if (mode == O_RDONLY || mode == O_RDWR) {
306 buffer = (snd_info_buffer_t *)
307 snd_kcalloc(sizeof(snd_info_buffer_t), GFP_KERNEL);
308 if (buffer == NULL) {
309 snd_magic_kfree(data);
310 err = -ENOMEM;
311 goto __error;
313 buffer->len = (entry->c.text.read_size +
314 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
315 buffer->buffer = vmalloc(buffer->len);
316 if (buffer->buffer == NULL) {
317 kfree(buffer);
318 snd_magic_kfree(data);
319 err = -ENOMEM;
320 goto __error;
322 buffer->curr = buffer->buffer;
323 data->rbuffer = buffer;
325 if (mode == O_WRONLY || mode == O_RDWR) {
326 buffer = (snd_info_buffer_t *)
327 snd_kcalloc(sizeof(snd_info_buffer_t), GFP_KERNEL);
328 if (buffer == NULL) {
329 if (mode == O_RDWR) {
330 vfree(data->rbuffer->buffer);
331 kfree(data->rbuffer);
333 snd_magic_kfree(data);
334 err = -ENOMEM;
335 goto __error;
337 buffer->len = (entry->c.text.write_size +
338 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
339 buffer->buffer = vmalloc(buffer->len);
340 if (buffer->buffer == NULL) {
341 if (mode == O_RDWR) {
342 vfree(data->rbuffer->buffer);
343 kfree(data->rbuffer);
345 kfree(buffer);
346 snd_magic_kfree(data);
347 err = -ENOMEM;
348 goto __error;
350 buffer->curr = buffer->buffer;
351 data->wbuffer = buffer;
353 break;
354 case SNDRV_INFO_CONTENT_DATA: /* data */
355 if (entry->c.ops->open) {
356 if ((err = entry->c.ops->open(entry, mode,
357 &data->file_private_data)) < 0) {
358 snd_magic_kfree(data);
359 goto __error;
362 break;
364 file->private_data = data;
365 up(&info_mutex);
366 if (entry->content == SNDRV_INFO_CONTENT_TEXT &&
367 (mode == O_RDONLY || mode == O_RDWR)) {
368 if (entry->c.text.read) {
369 down(&entry->access);
370 entry->c.text.read(entry, data->rbuffer);
371 up(&entry->access);
374 return 0;
376 __error:
377 module_put(entry->module);
378 __error1:
379 up(&info_mutex);
380 return err;
383 static int snd_info_entry_release(struct inode *inode, struct file *file)
385 snd_info_entry_t *entry;
386 snd_info_private_data_t *data;
387 int mode;
389 mode = file->f_flags & O_ACCMODE;
390 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
391 entry = data->entry;
392 switch (entry->content) {
393 case SNDRV_INFO_CONTENT_TEXT:
394 if (mode == O_RDONLY || mode == O_RDWR) {
395 vfree(data->rbuffer->buffer);
396 kfree(data->rbuffer);
398 if (mode == O_WRONLY || mode == O_RDWR) {
399 if (entry->c.text.write) {
400 entry->c.text.write(entry, data->wbuffer);
401 if (data->wbuffer->error) {
402 snd_printk(KERN_WARNING "data write error to %s (%i)\n",
403 entry->name,
404 data->wbuffer->error);
407 vfree(data->wbuffer->buffer);
408 kfree(data->wbuffer);
410 break;
411 case SNDRV_INFO_CONTENT_DATA:
412 if (entry->c.ops->release)
413 entry->c.ops->release(entry, mode,
414 data->file_private_data);
415 break;
417 module_put(entry->module);
418 snd_magic_kfree(data);
419 return 0;
422 static unsigned int snd_info_entry_poll(struct file *file, poll_table * wait)
424 snd_info_private_data_t *data;
425 struct snd_info_entry *entry;
426 unsigned int mask;
428 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
429 if (data == NULL)
430 return 0;
431 entry = data->entry;
432 mask = 0;
433 switch (entry->content) {
434 case SNDRV_INFO_CONTENT_DATA:
435 if (entry->c.ops->poll)
436 return entry->c.ops->poll(entry,
437 data->file_private_data,
438 file, wait);
439 if (entry->c.ops->read)
440 mask |= POLLIN | POLLRDNORM;
441 if (entry->c.ops->write)
442 mask |= POLLOUT | POLLWRNORM;
443 break;
445 return mask;
448 static int snd_info_entry_ioctl(struct inode *inode, struct file *file,
449 unsigned int cmd, unsigned long arg)
451 snd_info_private_data_t *data;
452 struct snd_info_entry *entry;
454 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
455 if (data == NULL)
456 return 0;
457 entry = data->entry;
458 switch (entry->content) {
459 case SNDRV_INFO_CONTENT_DATA:
460 if (entry->c.ops->ioctl)
461 return entry->c.ops->ioctl(entry,
462 data->file_private_data,
463 file, cmd, arg);
464 break;
466 return -ENOTTY;
469 static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma)
471 struct inode *inode = file->f_dentry->d_inode;
472 snd_info_private_data_t *data;
473 struct snd_info_entry *entry;
475 data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
476 if (data == NULL)
477 return 0;
478 entry = data->entry;
479 switch (entry->content) {
480 case SNDRV_INFO_CONTENT_DATA:
481 if (entry->c.ops->mmap)
482 return entry->c.ops->mmap(entry,
483 data->file_private_data,
484 inode, file, vma);
485 break;
487 return -ENXIO;
490 static struct file_operations snd_info_entry_operations =
492 .owner = THIS_MODULE,
493 .llseek = snd_info_entry_llseek,
494 .read = snd_info_entry_read,
495 .write = snd_info_entry_write,
496 .poll = snd_info_entry_poll,
497 .ioctl = snd_info_entry_ioctl,
498 .mmap = snd_info_entry_mmap,
499 .open = snd_info_entry_open,
500 .release = snd_info_entry_release,
504 * snd_create_proc_entry - create a procfs entry
505 * @name: the name of the proc file
506 * @mode: the file permission bits, S_Ixxx
507 * @parent: the parent proc-directory entry
509 * Creates a new proc file entry with the given name and permission
510 * on the given directory.
512 * Returns the pointer of new instance or NULL on failure.
514 struct proc_dir_entry *snd_create_proc_entry(const char *name, mode_t mode,
515 struct proc_dir_entry *parent)
517 struct proc_dir_entry *p;
518 p = create_proc_entry(name, mode, parent);
519 if (p)
520 snd_info_entry_prepare(p);
521 return p;
524 int __init snd_info_init(void)
526 struct proc_dir_entry *p;
528 p = snd_create_proc_entry("asound", S_IFDIR | S_IRUGO | S_IXUGO, &proc_root);
529 if (p == NULL)
530 return -ENOMEM;
531 snd_proc_root = p;
532 #ifdef CONFIG_SND_OSSEMUL
534 snd_info_entry_t *entry;
535 if ((entry = snd_info_create_module_entry(THIS_MODULE, "oss", NULL)) == NULL)
536 return -ENOMEM;
537 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
538 if (snd_info_register(entry) < 0) {
539 snd_info_free_entry(entry);
540 return -ENOMEM;
542 snd_oss_root = entry;
544 #endif
545 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
547 snd_info_entry_t *entry;
548 if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL)
549 return -ENOMEM;
550 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
551 if (snd_info_register(entry) < 0) {
552 snd_info_free_entry(entry);
553 return -ENOMEM;
555 snd_seq_root = entry;
557 #endif
558 snd_info_version_init();
559 snd_memory_info_init();
560 snd_minor_info_init();
561 snd_minor_info_oss_init();
562 snd_card_info_init();
563 return 0;
566 int __exit snd_info_done(void)
568 snd_card_info_done();
569 snd_minor_info_oss_done();
570 snd_minor_info_done();
571 snd_memory_info_done();
572 snd_info_version_done();
573 if (snd_proc_root) {
574 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
575 if (snd_seq_root)
576 snd_info_unregister(snd_seq_root);
577 #endif
578 #ifdef CONFIG_SND_OSSEMUL
579 if (snd_oss_root)
580 snd_info_unregister(snd_oss_root);
581 #endif
582 snd_remove_proc_entry(&proc_root, snd_proc_root);
584 return 0;
593 * create a card proc file
594 * called from init.c
596 int snd_info_card_create(snd_card_t * card)
598 char str[8];
599 snd_info_entry_t *entry;
601 snd_assert(card != NULL, return -ENXIO);
603 sprintf(str, "card%i", card->number);
604 if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL)
605 return -ENOMEM;
606 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
607 if (snd_info_register(entry) < 0) {
608 snd_info_free_entry(entry);
609 return -ENOMEM;
611 card->proc_root = entry;
612 return 0;
616 * register the card proc file
617 * called from init.c
619 int snd_info_card_register(snd_card_t * card)
621 struct proc_dir_entry *p;
623 snd_assert(card != NULL, return -ENXIO);
625 if (!strcmp(card->id, card->proc_root->name))
626 return 0;
628 p = proc_symlink(card->id, snd_proc_root, card->proc_root->name);
629 if (p == NULL)
630 return -ENOMEM;
631 card->proc_root_link = p;
632 return 0;
636 * de-register the card proc file
637 * called from init.c
639 int snd_info_card_free(snd_card_t * card)
641 snd_assert(card != NULL, return -ENXIO);
642 if (card->proc_root_link) {
643 snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
644 card->proc_root_link = NULL;
646 if (card->proc_root) {
647 snd_info_unregister(card->proc_root);
648 card->proc_root = NULL;
650 return 0;
655 * snd_info_get_line - read one line from the procfs buffer
656 * @buffer: the procfs buffer
657 * @line: the buffer to store
658 * @len: the max. buffer size - 1
660 * Reads one line from the buffer and stores the string.
662 * Returns zero if successful, or 1 if error or EOF.
664 int snd_info_get_line(snd_info_buffer_t * buffer, char *line, int len)
666 int c = -1;
668 if (len <= 0 || buffer->stop || buffer->error)
669 return 1;
670 while (--len > 0) {
671 c = *buffer->curr++;
672 if (c == '\n') {
673 if ((buffer->curr - buffer->buffer) >= (long)buffer->size) {
674 buffer->stop = 1;
676 break;
678 *line++ = c;
679 if ((buffer->curr - buffer->buffer) >= (long)buffer->size) {
680 buffer->stop = 1;
681 break;
684 while (c != '\n' && !buffer->stop) {
685 c = *buffer->curr++;
686 if ((buffer->curr - buffer->buffer) >= (long)buffer->size) {
687 buffer->stop = 1;
690 *line = '\0';
691 return 0;
695 * snd_info_get_line - parse a string token
696 * @dest: the buffer to store the string token
697 * @src: the original string
698 * @len: the max. length of token - 1
700 * Parses the original string and copy a token to the given
701 * string buffer.
703 * Returns the updated pointer of the original string so that
704 * it can be used for the next call.
706 char *snd_info_get_str(char *dest, char *src, int len)
708 int c;
710 while (*src == ' ' || *src == '\t')
711 src++;
712 if (*src == '"' || *src == '\'') {
713 c = *src++;
714 while (--len > 0 && *src && *src != c) {
715 *dest++ = *src++;
717 if (*src == c)
718 src++;
719 } else {
720 while (--len > 0 && *src && *src != ' ' && *src != '\t') {
721 *dest++ = *src++;
724 *dest = 0;
725 while (*src == ' ' || *src == '\t')
726 src++;
727 return src;
731 * snd_info_create_entry - create an info entry
732 * @name: the proc file name
734 * Creates an info entry with the given file name and initializes as
735 * the default state.
737 * Usually called from other functions such as
738 * snd_info_create_card_entry().
740 * Returns the pointer of the new instance, or NULL on failure.
742 static snd_info_entry_t *snd_info_create_entry(const char *name)
744 snd_info_entry_t *entry;
745 entry = snd_magic_kcalloc(snd_info_entry_t, 0, GFP_KERNEL);
746 if (entry == NULL)
747 return NULL;
748 entry->name = snd_kmalloc_strdup(name, GFP_KERNEL);
749 if (entry->name == NULL) {
750 snd_magic_kfree(entry);
751 return NULL;
753 entry->mode = S_IFREG | S_IRUGO;
754 entry->content = SNDRV_INFO_CONTENT_TEXT;
755 init_MUTEX(&entry->access);
756 return entry;
760 * snd_info_create_module_entry - create an info entry for the given module
761 * @module: the module pointer
762 * @name: the file name
763 * @parent: the parent directory
765 * Creates a new info entry and assigns it to the given module.
767 * Returns the pointer of the new instance, or NULL on failure.
769 snd_info_entry_t *snd_info_create_module_entry(struct module * module,
770 const char *name,
771 snd_info_entry_t *parent)
773 snd_info_entry_t *entry = snd_info_create_entry(name);
774 if (entry) {
775 entry->module = module;
776 entry->parent = parent;
778 return entry;
782 * snd_info_create_card_entry - create an info entry for the given card
783 * @card: the card instance
784 * @name: the file name
785 * @parent: the parent directory
787 * Creates a new info entry and assigns it to the given card.
789 * Returns the pointer of the new instance, or NULL on failure.
791 snd_info_entry_t *snd_info_create_card_entry(snd_card_t * card,
792 const char *name,
793 snd_info_entry_t * parent)
795 snd_info_entry_t *entry = snd_info_create_entry(name);
796 if (entry) {
797 entry->module = card->module;
798 entry->card = card;
799 entry->parent = parent;
801 return entry;
804 static int snd_info_dev_free_entry(snd_device_t *device)
806 snd_info_entry_t *entry = snd_magic_cast(snd_info_entry_t, device->device_data, return -ENXIO);
807 snd_info_free_entry(entry);
808 return 0;
811 static int snd_info_dev_register_entry(snd_device_t *device)
813 snd_info_entry_t *entry = snd_magic_cast(snd_info_entry_t, device->device_data, return -ENXIO);
814 return snd_info_register(entry);
817 static int snd_info_dev_disconnect_entry(snd_device_t *device)
819 snd_info_entry_t *entry = snd_magic_cast(snd_info_entry_t, device->device_data, return -ENXIO);
820 entry->disconnected = 1;
821 return 0;
824 static int snd_info_dev_unregister_entry(snd_device_t *device)
826 snd_info_entry_t *entry = snd_magic_cast(snd_info_entry_t, device->device_data, return -ENXIO);
827 return snd_info_unregister(entry);
831 * snd_card_proc_new - create an info entry for the given card
832 * @card: the card instance
833 * @name: the file name
834 * @entryp: the pointer to store the new info entry
836 * Creates a new info entry and assigns it to the given card.
837 * Unlike snd_info_create_card_entry(), this function registers the
838 * info entry as an ALSA device component, so that it can be
839 * unregistered/released without explicit call.
840 * Also, you don't have to register this entry via snd_info_register(),
841 * since this will be registered by snd_card_register() automatically.
843 * The parent is assumed as card->proc_root.
845 * For releasing this entry, use snd_device_free() instead of
846 * snd_info_free_entry().
848 * Returns zero if successful, or a negative error code on failure.
850 int snd_card_proc_new(snd_card_t *card, const char *name,
851 snd_info_entry_t **entryp)
853 static snd_device_ops_t ops = {
854 .dev_free = snd_info_dev_free_entry,
855 .dev_register = snd_info_dev_register_entry,
856 .dev_disconnect = snd_info_dev_disconnect_entry,
857 .dev_unregister = snd_info_dev_unregister_entry
859 snd_info_entry_t *entry;
860 int err;
862 entry = snd_info_create_card_entry(card, name, card->proc_root);
863 if (! entry)
864 return -ENOMEM;
865 if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) {
866 snd_info_free_entry(entry);
867 return err;
869 if (entryp)
870 *entryp = entry;
871 return 0;
875 * snd_info_free_entry - release the info entry
876 * @entry: the info entry
878 * Releases the info entry. Don't call this after registered.
880 void snd_info_free_entry(snd_info_entry_t * entry)
882 if (entry == NULL)
883 return;
884 if (entry->name)
885 kfree((char *)entry->name);
886 if (entry->private_free)
887 entry->private_free(entry);
888 snd_magic_kfree(entry);
892 * snd_info_register - register the info entry
893 * @entry: the info entry
895 * Registers the proc info entry.
897 * Returns zero if successful, or a negative error code on failure.
899 int snd_info_register(snd_info_entry_t * entry)
901 struct proc_dir_entry *root, *p = NULL;
903 snd_assert(entry != NULL, return -ENXIO);
904 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
905 down(&info_mutex);
906 p = snd_create_proc_entry(entry->name, entry->mode, root);
907 if (!p) {
908 up(&info_mutex);
909 return -ENOMEM;
911 p->owner = entry->module;
912 if (!S_ISDIR(entry->mode))
913 p->proc_fops = &snd_info_entry_operations;
914 p->size = entry->size;
915 p->data = entry;
916 entry->p = p;
917 up(&info_mutex);
918 return 0;
922 * snd_info_unregister - de-register the info entry
923 * @entry: the info entry
925 * De-registers the info entry and releases the instance.
927 * Returns zero if successful, or a negative error code on failure.
929 int snd_info_unregister(snd_info_entry_t * entry)
931 struct proc_dir_entry *root;
933 snd_assert(entry != NULL && entry->p != NULL, return -ENXIO);
934 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
935 snd_assert(root, return -ENXIO);
936 down(&info_mutex);
937 snd_remove_proc_entry(root, entry->p);
938 up(&info_mutex);
939 snd_info_free_entry(entry);
940 return 0;
947 static snd_info_entry_t *snd_info_version_entry = NULL;
949 static void snd_info_version_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
951 static char *kernel_version = UTS_RELEASE;
953 snd_iprintf(buffer,
954 "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"
955 "Compiled on " __DATE__ " for kernel %s"
956 #ifdef CONFIG_SMP
957 " (SMP)"
958 #endif
959 #ifdef MODVERSIONS
960 " with versioned symbols"
961 #endif
962 ".\n", kernel_version);
965 static int __init snd_info_version_init(void)
967 snd_info_entry_t *entry;
969 entry = snd_info_create_module_entry(THIS_MODULE, "version", NULL);
970 if (entry == NULL)
971 return -ENOMEM;
972 entry->c.text.read_size = 256;
973 entry->c.text.read = snd_info_version_read;
974 if (snd_info_register(entry) < 0) {
975 snd_info_free_entry(entry);
976 return -ENOMEM;
978 snd_info_version_entry = entry;
979 return 0;
982 static int __exit snd_info_version_done(void)
984 if (snd_info_version_entry)
985 snd_info_unregister(snd_info_version_entry);
986 return 0;
989 #endif /* CONFIG_PROC_FS */