Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
1da177e4 LT |
2 | #ifndef __SOUND_INFO_H |
3 | #define __SOUND_INFO_H | |
4 | ||
5 | /* | |
6 | * Header file for info interface | |
c1017a4c | 7 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
1da177e4 LT |
8 | */ |
9 | ||
10 | #include <linux/poll.h> | |
4adb7bcb | 11 | #include <linux/seq_file.h> |
c560a679 | 12 | #include <sound/core.h> |
1da177e4 LT |
13 | |
14 | /* buffer for information */ | |
15 | struct snd_info_buffer { | |
16 | char *buffer; /* pointer to begin of buffer */ | |
7e4eeec8 TI |
17 | unsigned int curr; /* current position in buffer */ |
18 | unsigned int size; /* current size */ | |
19 | unsigned int len; /* total length of buffer */ | |
1da177e4 LT |
20 | int stop; /* stop flag */ |
21 | int error; /* error code */ | |
22 | }; | |
23 | ||
1da177e4 LT |
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 { | |
fd64138c JK |
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); | |
1da177e4 LT |
34 | }; |
35 | ||
36 | struct snd_info_entry_ops { | |
fd64138c JK |
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); | |
24e4a121 TI |
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); | |
a3f8683b | 50 | __poll_t (*poll)(struct snd_info_entry *entry, |
24e4a121 TI |
51 | void *file_private_data, struct file *file, |
52 | poll_table *wait); | |
fd64138c JK |
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); | |
1da177e4 LT |
58 | }; |
59 | ||
60 | struct snd_info_entry { | |
61 | const char *name; | |
d161a13f | 62 | umode_t mode; |
1da177e4 LT |
63 | long size; |
64 | unsigned short content; | |
1da177e4 LT |
65 | union { |
66 | struct snd_info_entry_text text; | |
d25ff268 | 67 | const struct snd_info_entry_ops *ops; |
1da177e4 | 68 | } c; |
24c1f931 | 69 | struct snd_info_entry *parent; |
1da177e4 LT |
70 | struct module *module; |
71 | void *private_data; | |
24c1f931 | 72 | void (*private_free)(struct snd_info_entry *entry); |
1da177e4 | 73 | struct proc_dir_entry *p; |
1a60d4c5 | 74 | struct mutex access; |
746d4a02 TI |
75 | struct list_head children; |
76 | struct list_head list; | |
1da177e4 LT |
77 | }; |
78 | ||
cd6a6503 | 79 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS) |
24c1f931 | 80 | int snd_info_minor_register(void); |
1da177e4 | 81 | #else |
a0dca822 | 82 | #define snd_info_minor_register() 0 |
1da177e4 LT |
83 | #endif |
84 | ||
85 | ||
cd6a6503 | 86 | #ifdef CONFIG_SND_PROC_FS |
1da177e4 | 87 | |
24c1f931 | 88 | extern struct snd_info_entry *snd_seq_root; |
1da177e4 | 89 | #ifdef CONFIG_SND_OSSEMUL |
24c1f931 | 90 | extern struct snd_info_entry *snd_oss_root; |
36b9cdfe | 91 | void snd_card_info_read_oss(struct snd_info_buffer *buffer); |
1da177e4 LT |
92 | #else |
93 | #define snd_oss_root NULL | |
36b9cdfe | 94 | static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {} |
1da177e4 LT |
95 | #endif |
96 | ||
4adb7bcb TI |
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 | ||
1da177e4 LT |
109 | int snd_info_init(void); |
110 | int snd_info_done(void); | |
111 | ||
fd64138c | 112 | int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len); |
4f7454a9 | 113 | const char *snd_info_get_str(char *dest, const char *src, int len); |
fd64138c | 114 | struct snd_info_entry *snd_info_create_module_entry(struct module *module, |
1da177e4 | 115 | const char *name, |
fd64138c JK |
116 | struct snd_info_entry *parent); |
117 | struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, | |
1da177e4 | 118 | const char *name, |
fd64138c JK |
119 | struct snd_info_entry *parent); |
120 | void snd_info_free_entry(struct snd_info_entry *entry); | |
fd64138c JK |
121 | |
122 | int snd_info_card_create(struct snd_card *card); | |
123 | int snd_info_card_register(struct snd_card *card); | |
124 | int snd_info_card_free(struct snd_card *card); | |
125 | void snd_info_card_disconnect(struct snd_card *card); | |
126 | void snd_info_card_id_change(struct snd_card *card); | |
127 | int snd_info_register(struct snd_info_entry *entry); | |
1da177e4 LT |
128 | |
129 | /* for card drivers */ | |
c560a679 TI |
130 | static inline int snd_card_proc_new(struct snd_card *card, const char *name, |
131 | struct snd_info_entry **entryp) | |
132 | { | |
133 | *entryp = snd_info_create_card_entry(card, name, card->proc_root); | |
134 | return *entryp ? 0 : -ENOMEM; | |
135 | } | |
1da177e4 | 136 | |
24c1f931 | 137 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry, |
fd64138c JK |
138 | void *private_data, |
139 | void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) | |
1da177e4 LT |
140 | { |
141 | entry->private_data = private_data; | |
1da177e4 LT |
142 | entry->c.text.read = read; |
143 | } | |
144 | ||
7453e1da TI |
145 | int snd_card_rw_proc_new(struct snd_card *card, const char *name, |
146 | void *private_data, | |
147 | void (*read)(struct snd_info_entry *, | |
148 | struct snd_info_buffer *), | |
149 | void (*write)(struct snd_info_entry *entry, | |
150 | struct snd_info_buffer *buffer)); | |
151 | ||
e28563cc | 152 | int snd_info_check_reserved_words(const char *str); |
1da177e4 LT |
153 | |
154 | #else | |
155 | ||
156 | #define snd_seq_root NULL | |
157 | #define snd_oss_root NULL | |
158 | ||
fd64138c | 159 | static inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; } |
1da177e4 LT |
160 | static inline int snd_info_init(void) { return 0; } |
161 | static inline int snd_info_done(void) { return 0; } | |
162 | ||
fd64138c | 163 | static inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; } |
1da177e4 | 164 | static inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; } |
fd64138c JK |
165 | static inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; } |
166 | 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; } | |
167 | static inline void snd_info_free_entry(struct snd_info_entry *entry) { ; } | |
168 | ||
169 | static inline int snd_info_card_create(struct snd_card *card) { return 0; } | |
170 | static inline int snd_info_card_register(struct snd_card *card) { return 0; } | |
171 | static inline int snd_info_card_free(struct snd_card *card) { return 0; } | |
172 | static inline void snd_info_card_disconnect(struct snd_card *card) { } | |
173 | static inline void snd_info_card_id_change(struct snd_card *card) { } | |
174 | static inline int snd_info_register(struct snd_info_entry *entry) { return 0; } | |
1da177e4 | 175 | |
e28563cc TI |
176 | static inline int snd_card_proc_new(struct snd_card *card, const char *name, |
177 | struct snd_info_entry **entryp) { return -EINVAL; } | |
178 | static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)), | |
179 | void *private_data, | |
e28563cc | 180 | void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {} |
7453e1da TI |
181 | static inline int snd_card_rw_proc_new(struct snd_card *card, const char *name, |
182 | void *private_data, | |
183 | void (*read)(struct snd_info_entry *, | |
184 | struct snd_info_buffer *), | |
185 | void (*write)(struct snd_info_entry *entry, | |
186 | struct snd_info_buffer *buffer)) | |
187 | { | |
188 | return 0; | |
189 | } | |
e28563cc | 190 | static inline int snd_info_check_reserved_words(const char *str) { return 1; } |
1da177e4 LT |
191 | |
192 | #endif | |
193 | ||
7453e1da TI |
194 | /** |
195 | * snd_card_ro_proc_new - Create a read-only text proc file entry for the card | |
196 | * @card: the card instance | |
197 | * @name: the file name | |
198 | * @private_data: the arbitrary private data | |
199 | * @read: the read callback | |
200 | * | |
201 | * This proc file entry will be registered via snd_card_register() call, and | |
202 | * it will be removed automatically at the card removal, too. | |
203 | */ | |
204 | static inline int | |
205 | snd_card_ro_proc_new(struct snd_card *card, const char *name, | |
206 | void *private_data, | |
207 | void (*read)(struct snd_info_entry *, | |
208 | struct snd_info_buffer *)) | |
209 | { | |
210 | return snd_card_rw_proc_new(card, name, private_data, read, NULL); | |
211 | } | |
212 | ||
1da177e4 LT |
213 | /* |
214 | * OSS info part | |
215 | */ | |
216 | ||
cd6a6503 | 217 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS) |
1da177e4 LT |
218 | |
219 | #define SNDRV_OSS_INFO_DEV_AUDIO 0 | |
220 | #define SNDRV_OSS_INFO_DEV_SYNTH 1 | |
221 | #define SNDRV_OSS_INFO_DEV_MIDI 2 | |
222 | #define SNDRV_OSS_INFO_DEV_TIMERS 4 | |
223 | #define SNDRV_OSS_INFO_DEV_MIXERS 5 | |
224 | ||
225 | #define SNDRV_OSS_INFO_DEV_COUNT 6 | |
226 | ||
24c1f931 | 227 | int snd_oss_info_register(int dev, int num, char *string); |
1da177e4 LT |
228 | #define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL) |
229 | ||
cd6a6503 | 230 | #endif /* CONFIG_SND_OSSEMUL && CONFIG_SND_PROC_FS */ |
1da177e4 LT |
231 | |
232 | #endif /* __SOUND_INFO_H */ |