info.h 7.9 KB

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