Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef __SOUND_INFO_H |
| 3 | #define __SOUND_INFO_H |
| 4 | |
| 5 | /* |
| 6 | * Header file for info interface |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 7 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/poll.h> |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
Takashi Iwai | c560a67 | 2015-04-22 18:26:38 +0200 | [diff] [blame] | 12 | #include <sound/core.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | /* buffer for information */ |
| 15 | struct snd_info_buffer { |
| 16 | char *buffer; /* pointer to begin of buffer */ |
Takashi Iwai | 7e4eeec | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 17 | unsigned int curr; /* current position in buffer */ |
| 18 | unsigned int size; /* current size */ |
| 19 | unsigned int len; /* total length of buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | int stop; /* stop flag */ |
| 21 | int error; /* error code */ |
| 22 | }; |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define SNDRV_INFO_CONTENT_TEXT 0 |
| 25 | #define SNDRV_INFO_CONTENT_DATA 1 |
| 26 | |
| 27 | struct snd_info_entry; |
| 28 | |
| 29 | struct snd_info_entry_text { |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 30 | void (*read)(struct snd_info_entry *entry, |
| 31 | struct snd_info_buffer *buffer); |
| 32 | void (*write)(struct snd_info_entry *entry, |
| 33 | struct snd_info_buffer *buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct snd_info_entry_ops { |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 37 | int (*open)(struct snd_info_entry *entry, |
| 38 | unsigned short mode, void **file_private_data); |
| 39 | int (*release)(struct snd_info_entry *entry, |
| 40 | unsigned short mode, void *file_private_data); |
Takashi Iwai | 24e4a12 | 2010-04-13 11:22:01 +0200 | [diff] [blame] | 41 | ssize_t (*read)(struct snd_info_entry *entry, void *file_private_data, |
| 42 | struct file *file, char __user *buf, |
| 43 | size_t count, loff_t pos); |
| 44 | ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data, |
| 45 | struct file *file, const char __user *buf, |
| 46 | size_t count, loff_t pos); |
| 47 | loff_t (*llseek)(struct snd_info_entry *entry, |
| 48 | void *file_private_data, struct file *file, |
| 49 | loff_t offset, int orig); |
Al Viro | a3f8683 | 2017-07-02 22:22:01 -0400 | [diff] [blame] | 50 | __poll_t (*poll)(struct snd_info_entry *entry, |
Takashi Iwai | 24e4a12 | 2010-04-13 11:22:01 +0200 | [diff] [blame] | 51 | void *file_private_data, struct file *file, |
| 52 | poll_table *wait); |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 53 | int (*ioctl)(struct snd_info_entry *entry, void *file_private_data, |
| 54 | struct file *file, unsigned int cmd, unsigned long arg); |
| 55 | int (*mmap)(struct snd_info_entry *entry, void *file_private_data, |
| 56 | struct inode *inode, struct file *file, |
| 57 | struct vm_area_struct *vma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | struct snd_info_entry { |
| 61 | const char *name; |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 62 | umode_t mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | long size; |
| 64 | unsigned short content; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | union { |
| 66 | struct snd_info_entry_text text; |
Takashi Iwai | d25ff26 | 2020-01-03 09:16:44 +0100 | [diff] [blame] | 67 | const struct snd_info_entry_ops *ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } c; |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 69 | struct snd_info_entry *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | struct module *module; |
| 71 | void *private_data; |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 72 | void (*private_free)(struct snd_info_entry *entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | struct proc_dir_entry *p; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 74 | struct mutex access; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 75 | struct list_head children; |
| 76 | struct list_head list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 79 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS) |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 80 | int snd_info_minor_register(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #else |
Takashi Iwai | a0dca82 | 2015-04-23 10:56:21 +0200 | [diff] [blame] | 82 | #define snd_info_minor_register() 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_SND_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 88 | extern struct snd_info_entry *snd_seq_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #ifdef CONFIG_SND_OSSEMUL |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 90 | extern struct snd_info_entry *snd_oss_root; |
Marcin Ślusarz | 36b9cdf | 2007-12-14 12:58:45 +0100 | [diff] [blame] | 91 | void snd_card_info_read_oss(struct snd_info_buffer *buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | #else |
| 93 | #define snd_oss_root NULL |
Marcin Ślusarz | 36b9cdf | 2007-12-14 12:58:45 +0100 | [diff] [blame] | 94 | static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #endif |
| 96 | |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 97 | /** |
| 98 | * snd_iprintf - printf on the procfs buffer |
| 99 | * @buf: the procfs buffer |
| 100 | * @fmt: the printf format |
| 101 | * |
| 102 | * Outputs the string on the procfs buffer just like printf(). |
| 103 | * |
| 104 | * Return: zero for success, or a negative error code. |
| 105 | */ |
| 106 | #define snd_iprintf(buf, fmt, args...) \ |
| 107 | seq_printf((struct seq_file *)(buf)->buffer, fmt, ##args) |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | int snd_info_init(void); |
| 110 | int snd_info_done(void); |
| 111 | |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 112 | int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len); |
Takashi Iwai | 4f7454a | 2009-09-08 14:29:58 +0200 | [diff] [blame] | 113 | const char *snd_info_get_str(char *dest, const char *src, int len); |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 114 | struct snd_info_entry *snd_info_create_module_entry(struct module *module, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | const char *name, |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 116 | struct snd_info_entry *parent); |
| 117 | struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | const char *name, |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 119 | struct snd_info_entry *parent); |
| 120 | void snd_info_free_entry(struct snd_info_entry *entry); |
| 121 | int snd_info_store_text(struct snd_info_entry *entry); |
| 122 | int snd_info_restore_text(struct snd_info_entry *entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 124 | int snd_info_card_create(struct snd_card *card); |
| 125 | int snd_info_card_register(struct snd_card *card); |
| 126 | int snd_info_card_free(struct snd_card *card); |
| 127 | void snd_info_card_disconnect(struct snd_card *card); |
| 128 | void snd_info_card_id_change(struct snd_card *card); |
| 129 | int snd_info_register(struct snd_info_entry *entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* for card drivers */ |
Takashi Iwai | c560a67 | 2015-04-22 18:26:38 +0200 | [diff] [blame] | 132 | static inline int snd_card_proc_new(struct snd_card *card, const char *name, |
| 133 | struct snd_info_entry **entryp) |
| 134 | { |
| 135 | *entryp = snd_info_create_card_entry(card, name, card->proc_root); |
| 136 | return *entryp ? 0 : -ENOMEM; |
| 137 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 139 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry, |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 140 | void *private_data, |
| 141 | void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | entry->private_data = private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | entry->c.text.read = read; |
| 145 | } |
| 146 | |
Takashi Iwai | 7453e1d | 2019-02-04 14:53:04 +0100 | [diff] [blame] | 147 | int snd_card_rw_proc_new(struct snd_card *card, const char *name, |
| 148 | void *private_data, |
| 149 | void (*read)(struct snd_info_entry *, |
| 150 | struct snd_info_buffer *), |
| 151 | void (*write)(struct snd_info_entry *entry, |
| 152 | struct snd_info_buffer *buffer)); |
| 153 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 154 | int snd_info_check_reserved_words(const char *str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | #else |
| 157 | |
| 158 | #define snd_seq_root NULL |
| 159 | #define snd_oss_root NULL |
| 160 | |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 161 | static inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | static inline int snd_info_init(void) { return 0; } |
| 163 | static inline int snd_info_done(void) { return 0; } |
| 164 | |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 165 | static inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | static inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; } |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 167 | static inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; } |
| 168 | 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; } |
| 169 | static inline void snd_info_free_entry(struct snd_info_entry *entry) { ; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Jaroslav Kysela | fd64138 | 2008-11-12 16:53:47 +0100 | [diff] [blame] | 171 | static inline int snd_info_card_create(struct snd_card *card) { return 0; } |
| 172 | static inline int snd_info_card_register(struct snd_card *card) { return 0; } |
| 173 | static inline int snd_info_card_free(struct snd_card *card) { return 0; } |
| 174 | static inline void snd_info_card_disconnect(struct snd_card *card) { } |
| 175 | static inline void snd_info_card_id_change(struct snd_card *card) { } |
| 176 | static inline int snd_info_register(struct snd_info_entry *entry) { return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 178 | static inline int snd_card_proc_new(struct snd_card *card, const char *name, |
| 179 | struct snd_info_entry **entryp) { return -EINVAL; } |
| 180 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)), |
| 181 | void *private_data, |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 182 | void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {} |
Takashi Iwai | 7453e1d | 2019-02-04 14:53:04 +0100 | [diff] [blame] | 183 | static inline int snd_card_rw_proc_new(struct snd_card *card, const char *name, |
| 184 | void *private_data, |
| 185 | void (*read)(struct snd_info_entry *, |
| 186 | struct snd_info_buffer *), |
| 187 | void (*write)(struct snd_info_entry *entry, |
| 188 | struct snd_info_buffer *buffer)) |
| 189 | { |
| 190 | return 0; |
| 191 | } |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 192 | static inline int snd_info_check_reserved_words(const char *str) { return 1; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | #endif |
| 195 | |
Takashi Iwai | 7453e1d | 2019-02-04 14:53:04 +0100 | [diff] [blame] | 196 | /** |
| 197 | * snd_card_ro_proc_new - Create a read-only text proc file entry for the card |
| 198 | * @card: the card instance |
| 199 | * @name: the file name |
| 200 | * @private_data: the arbitrary private data |
| 201 | * @read: the read callback |
| 202 | * |
| 203 | * This proc file entry will be registered via snd_card_register() call, and |
| 204 | * it will be removed automatically at the card removal, too. |
| 205 | */ |
| 206 | static inline int |
| 207 | snd_card_ro_proc_new(struct snd_card *card, const char *name, |
| 208 | void *private_data, |
| 209 | void (*read)(struct snd_info_entry *, |
| 210 | struct snd_info_buffer *)) |
| 211 | { |
| 212 | return snd_card_rw_proc_new(card, name, private_data, read, NULL); |
| 213 | } |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | /* |
| 216 | * OSS info part |
| 217 | */ |
| 218 | |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 219 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | #define SNDRV_OSS_INFO_DEV_AUDIO 0 |
| 222 | #define SNDRV_OSS_INFO_DEV_SYNTH 1 |
| 223 | #define SNDRV_OSS_INFO_DEV_MIDI 2 |
| 224 | #define SNDRV_OSS_INFO_DEV_TIMERS 4 |
| 225 | #define SNDRV_OSS_INFO_DEV_MIXERS 5 |
| 226 | |
| 227 | #define SNDRV_OSS_INFO_DEV_COUNT 6 |
| 228 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 229 | int snd_oss_info_register(int dev, int num, char *string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | #define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL) |
| 231 | |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 232 | #endif /* CONFIG_SND_OSSEMUL && CONFIG_SND_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | #endif /* __SOUND_INFO_H */ |