info.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_INFO_H
  3. #define __SOUND_INFO_H
  4. /*
  5. * Header file for info interface
  6. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  7. */
  8. #include <linux/poll.h>
  9. #include <linux/seq_file.h>
  10. #include <sound/core.h>
  11. /* buffer for information */
  12. struct snd_info_buffer {
  13. char *buffer; /* pointer to begin of buffer */
  14. unsigned int curr; /* current position in buffer */
  15. unsigned int size; /* current size */
  16. unsigned int len; /* total length of buffer */
  17. int stop; /* stop flag */
  18. int error; /* error code */
  19. };
  20. #define SNDRV_INFO_CONTENT_TEXT 0
  21. #define SNDRV_INFO_CONTENT_DATA 1
  22. struct snd_info_entry;
  23. struct snd_info_entry_text {
  24. void (*read)(struct snd_info_entry *entry,
  25. struct snd_info_buffer *buffer);
  26. void (*write)(struct snd_info_entry *entry,
  27. struct snd_info_buffer *buffer);
  28. };
  29. struct snd_info_entry_ops {
  30. int (*open)(struct snd_info_entry *entry,
  31. unsigned short mode, void **file_private_data);
  32. int (*release)(struct snd_info_entry *entry,
  33. unsigned short mode, void *file_private_data);
  34. ssize_t (*read)(struct snd_info_entry *entry, void *file_private_data,
  35. struct file *file, char __user *buf,
  36. size_t count, loff_t pos);
  37. ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data,
  38. struct file *file, const char __user *buf,
  39. size_t count, loff_t pos);
  40. loff_t (*llseek)(struct snd_info_entry *entry,
  41. void *file_private_data, struct file *file,
  42. loff_t offset, int orig);
  43. __poll_t (*poll)(struct snd_info_entry *entry,
  44. void *file_private_data, struct file *file,
  45. poll_table *wait);
  46. int (*ioctl)(struct snd_info_entry *entry, void *file_private_data,
  47. struct file *file, unsigned int cmd, unsigned long arg);
  48. int (*mmap)(struct snd_info_entry *entry, void *file_private_data,
  49. struct inode *inode, struct file *file,
  50. struct vm_area_struct *vma);
  51. };
  52. struct snd_info_entry {
  53. const char *name;
  54. umode_t mode;
  55. long size;
  56. unsigned short content;
  57. union {
  58. struct snd_info_entry_text text;
  59. const struct snd_info_entry_ops *ops;
  60. } c;
  61. struct snd_info_entry *parent;
  62. struct module *module;
  63. void *private_data;
  64. void (*private_free)(struct snd_info_entry *entry);
  65. struct proc_dir_entry *p;
  66. struct mutex access;
  67. struct list_head children;
  68. struct list_head list;
  69. };
  70. #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
  71. int snd_info_minor_register(void);
  72. #else
  73. #define snd_info_minor_register() 0
  74. #endif
  75. #ifdef CONFIG_SND_PROC_FS
  76. extern struct snd_info_entry *snd_seq_root;
  77. #ifdef CONFIG_SND_OSSEMUL
  78. extern struct snd_info_entry *snd_oss_root;
  79. void snd_card_info_read_oss(struct snd_info_buffer *buffer);
  80. #else
  81. #define snd_oss_root NULL
  82. static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {}
  83. #endif
  84. /**
  85. * snd_iprintf - printf on the procfs buffer
  86. * @buf: the procfs buffer
  87. * @fmt: the printf format
  88. *
  89. * Outputs the string on the procfs buffer just like printf().
  90. *
  91. * Return: zero for success, or a negative error code.
  92. */
  93. #define snd_iprintf(buf, fmt, args...) \
  94. seq_printf((struct seq_file *)(buf)->buffer, fmt, ##args)
  95. int snd_info_init(void);
  96. int snd_info_done(void);
  97. int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len);
  98. const char *snd_info_get_str(char *dest, const char *src, int len);
  99. struct snd_info_entry *snd_info_create_module_entry(struct module *module,
  100. const char *name,
  101. struct snd_info_entry *parent);
  102. struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
  103. const char *name,
  104. struct snd_info_entry *parent);
  105. void snd_info_free_entry(struct snd_info_entry *entry);
  106. int snd_info_card_create(struct snd_card *card);
  107. int snd_info_card_register(struct snd_card *card);
  108. int snd_info_card_free(struct snd_card *card);
  109. void snd_info_card_disconnect(struct snd_card *card);
  110. void snd_info_card_id_change(struct snd_card *card);
  111. int snd_info_register(struct snd_info_entry *entry);
  112. /* for card drivers */
  113. static inline int snd_card_proc_new(struct snd_card *card, const char *name,
  114. struct snd_info_entry **entryp)
  115. {
  116. *entryp = snd_info_create_card_entry(card, name, card->proc_root);
  117. return *entryp ? 0 : -ENOMEM;
  118. }
  119. static inline void snd_info_set_text_ops(struct snd_info_entry *entry,
  120. void *private_data,
  121. void (*read)(struct snd_info_entry *, struct snd_info_buffer *))
  122. {
  123. entry->private_data = private_data;
  124. entry->c.text.read = read;
  125. }
  126. int snd_card_rw_proc_new(struct snd_card *card, const char *name,
  127. void *private_data,
  128. void (*read)(struct snd_info_entry *,
  129. struct snd_info_buffer *),
  130. void (*write)(struct snd_info_entry *entry,
  131. struct snd_info_buffer *buffer));
  132. int snd_info_check_reserved_words(const char *str);
  133. #else
  134. #define snd_seq_root NULL
  135. #define snd_oss_root NULL
  136. static inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; }
  137. static inline int snd_info_init(void) { return 0; }
  138. static inline int snd_info_done(void) { return 0; }
  139. static inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; }
  140. static inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; }
  141. static inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; }
  142. static inline struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, const char *name, struct snd_info_entry *parent) { return NULL; }
  143. static inline void snd_info_free_entry(struct snd_info_entry *entry) { ; }
  144. static inline int snd_info_card_create(struct snd_card *card) { return 0; }
  145. static inline int snd_info_card_register(struct snd_card *card) { return 0; }
  146. static inline int snd_info_card_free(struct snd_card *card) { return 0; }
  147. static inline void snd_info_card_disconnect(struct snd_card *card) { }
  148. static inline void snd_info_card_id_change(struct snd_card *card) { }
  149. static inline int snd_info_register(struct snd_info_entry *entry) { return 0; }
  150. static inline int snd_card_proc_new(struct snd_card *card, const char *name,
  151. struct snd_info_entry **entryp) { return -EINVAL; }
  152. static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)),
  153. void *private_data,
  154. void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {}
  155. static inline int snd_card_rw_proc_new(struct snd_card *card, const char *name,
  156. void *private_data,
  157. void (*read)(struct snd_info_entry *,
  158. struct snd_info_buffer *),
  159. void (*write)(struct snd_info_entry *entry,
  160. struct snd_info_buffer *buffer))
  161. {
  162. return 0;
  163. }
  164. static inline int snd_info_check_reserved_words(const char *str) { return 1; }
  165. #endif
  166. /**
  167. * snd_card_ro_proc_new - Create a read-only text proc file entry for the card
  168. * @card: the card instance
  169. * @name: the file name
  170. * @private_data: the arbitrary private data
  171. * @read: the read callback
  172. *
  173. * This proc file entry will be registered via snd_card_register() call, and
  174. * it will be removed automatically at the card removal, too.
  175. */
  176. static inline int
  177. snd_card_ro_proc_new(struct snd_card *card, const char *name,
  178. void *private_data,
  179. void (*read)(struct snd_info_entry *,
  180. struct snd_info_buffer *))
  181. {
  182. return snd_card_rw_proc_new(card, name, private_data, read, NULL);
  183. }
  184. /*
  185. * OSS info part
  186. */
  187. #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
  188. #define SNDRV_OSS_INFO_DEV_AUDIO 0
  189. #define SNDRV_OSS_INFO_DEV_SYNTH 1
  190. #define SNDRV_OSS_INFO_DEV_MIDI 2
  191. #define SNDRV_OSS_INFO_DEV_TIMERS 4
  192. #define SNDRV_OSS_INFO_DEV_MIXERS 5
  193. #define SNDRV_OSS_INFO_DEV_COUNT 6
  194. int snd_oss_info_register(int dev, int num, char *string);
  195. #define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL)
  196. #endif /* CONFIG_SND_OSSEMUL && CONFIG_SND_PROC_FS */
  197. #endif /* __SOUND_INFO_H */