Loading...
1#ifndef __SOUND_INFO_H
2#define __SOUND_INFO_H
3
4/*
5 * Header file for info interface
6 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <linux/poll.h>
26
27/* buffer for information */
28struct snd_info_buffer {
29 char *buffer; /* pointer to begin of buffer */
30 unsigned int curr; /* current position in buffer */
31 unsigned int size; /* current size */
32 unsigned int len; /* total length of buffer */
33 int stop; /* stop flag */
34 int error; /* error code */
35};
36
37#define SNDRV_INFO_CONTENT_TEXT 0
38#define SNDRV_INFO_CONTENT_DATA 1
39
40struct snd_info_entry;
41
42struct snd_info_entry_text {
43 void (*read)(struct snd_info_entry *entry,
44 struct snd_info_buffer *buffer);
45 void (*write)(struct snd_info_entry *entry,
46 struct snd_info_buffer *buffer);
47};
48
49struct snd_info_entry_ops {
50 int (*open)(struct snd_info_entry *entry,
51 unsigned short mode, void **file_private_data);
52 int (*release)(struct snd_info_entry *entry,
53 unsigned short mode, void *file_private_data);
54 ssize_t (*read)(struct snd_info_entry *entry, void *file_private_data,
55 struct file *file, char __user *buf,
56 size_t count, loff_t pos);
57 ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data,
58 struct file *file, const char __user *buf,
59 size_t count, loff_t pos);
60 loff_t (*llseek)(struct snd_info_entry *entry,
61 void *file_private_data, struct file *file,
62 loff_t offset, int orig);
63 unsigned int (*poll)(struct snd_info_entry *entry,
64 void *file_private_data, struct file *file,
65 poll_table *wait);
66 int (*ioctl)(struct snd_info_entry *entry, void *file_private_data,
67 struct file *file, unsigned int cmd, unsigned long arg);
68 int (*mmap)(struct snd_info_entry *entry, void *file_private_data,
69 struct inode *inode, struct file *file,
70 struct vm_area_struct *vma);
71};
72
73struct snd_info_entry {
74 const char *name;
75 mode_t mode;
76 long size;
77 unsigned short content;
78 union {
79 struct snd_info_entry_text text;
80 struct snd_info_entry_ops *ops;
81 } c;
82 struct snd_info_entry *parent;
83 struct snd_card *card;
84 struct module *module;
85 void *private_data;
86 void (*private_free)(struct snd_info_entry *entry);
87 struct proc_dir_entry *p;
88 struct mutex access;
89 struct list_head children;
90 struct list_head list;
91};
92
93#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS)
94int snd_info_minor_register(void);
95int snd_info_minor_unregister(void);
96#else
97#define snd_info_minor_register() /* NOP */
98#define snd_info_minor_unregister() /* NOP */
99#endif
100
101
102#ifdef CONFIG_PROC_FS
103
104extern struct snd_info_entry *snd_seq_root;
105#ifdef CONFIG_SND_OSSEMUL
106extern struct snd_info_entry *snd_oss_root;
107void snd_card_info_read_oss(struct snd_info_buffer *buffer);
108#else
109#define snd_oss_root NULL
110static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {}
111#endif
112
113int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...) \
114 __attribute__ ((format (printf, 2, 3)));
115int snd_info_init(void);
116int snd_info_done(void);
117
118int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len);
119const char *snd_info_get_str(char *dest, const char *src, int len);
120struct snd_info_entry *snd_info_create_module_entry(struct module *module,
121 const char *name,
122 struct snd_info_entry *parent);
123struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
124 const char *name,
125 struct snd_info_entry *parent);
126void snd_info_free_entry(struct snd_info_entry *entry);
127int snd_info_store_text(struct snd_info_entry *entry);
128int snd_info_restore_text(struct snd_info_entry *entry);
129
130int snd_info_card_create(struct snd_card *card);
131int snd_info_card_register(struct snd_card *card);
132int snd_info_card_free(struct snd_card *card);
133void snd_info_card_disconnect(struct snd_card *card);
134void snd_info_card_id_change(struct snd_card *card);
135int snd_info_register(struct snd_info_entry *entry);
136
137/* for card drivers */
138int snd_card_proc_new(struct snd_card *card, const char *name,
139 struct snd_info_entry **entryp);
140
141static inline void snd_info_set_text_ops(struct snd_info_entry *entry,
142 void *private_data,
143 void (*read)(struct snd_info_entry *, struct snd_info_buffer *))
144{
145 entry->private_data = private_data;
146 entry->c.text.read = read;
147}
148
149int snd_info_check_reserved_words(const char *str);
150
151#else
152
153#define snd_seq_root NULL
154#define snd_oss_root NULL
155
156static inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; }
157static inline int snd_info_init(void) { return 0; }
158static inline int snd_info_done(void) { return 0; }
159
160static inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; }
161static inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; }
162static inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; }
163static inline struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, const char *name, struct snd_info_entry *parent) { return NULL; }
164static inline void snd_info_free_entry(struct snd_info_entry *entry) { ; }
165
166static inline int snd_info_card_create(struct snd_card *card) { return 0; }
167static inline int snd_info_card_register(struct snd_card *card) { return 0; }
168static inline int snd_info_card_free(struct snd_card *card) { return 0; }
169static inline void snd_info_card_disconnect(struct snd_card *card) { }
170static inline void snd_info_card_id_change(struct snd_card *card) { }
171static inline int snd_info_register(struct snd_info_entry *entry) { return 0; }
172
173static inline int snd_card_proc_new(struct snd_card *card, const char *name,
174 struct snd_info_entry **entryp) { return -EINVAL; }
175static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)),
176 void *private_data,
177 void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {}
178
179static inline int snd_info_check_reserved_words(const char *str) { return 1; }
180
181#endif
182
183/*
184 * OSS info part
185 */
186
187#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS)
188
189#define SNDRV_OSS_INFO_DEV_AUDIO 0
190#define SNDRV_OSS_INFO_DEV_SYNTH 1
191#define SNDRV_OSS_INFO_DEV_MIDI 2
192#define SNDRV_OSS_INFO_DEV_TIMERS 4
193#define SNDRV_OSS_INFO_DEV_MIXERS 5
194
195#define SNDRV_OSS_INFO_DEV_COUNT 6
196
197int snd_oss_info_register(int dev, int num, char *string);
198#define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL)
199
200#endif /* CONFIG_SND_OSSEMUL && CONFIG_PROC_FS */
201
202#endif /* __SOUND_INFO_H */
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2#ifndef __SOUND_INFO_H
3#define __SOUND_INFO_H
4
5/*
6 * Header file for info interface
7 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
8 */
9
10#include <linux/poll.h>
11#include <linux/seq_file.h>
12#include <sound/core.h>
13
14/* buffer for information */
15struct snd_info_buffer {
16 char *buffer; /* pointer to begin of buffer */
17 unsigned int curr; /* current position in buffer */
18 unsigned int size; /* current size */
19 unsigned int len; /* total length of buffer */
20 int stop; /* stop flag */
21 int error; /* error code */
22};
23
24#define SNDRV_INFO_CONTENT_TEXT 0
25#define SNDRV_INFO_CONTENT_DATA 1
26
27struct snd_info_entry;
28
29struct snd_info_entry_text {
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);
34};
35
36struct snd_info_entry_ops {
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);
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);
50 __poll_t (*poll)(struct snd_info_entry *entry,
51 void *file_private_data, struct file *file,
52 poll_table *wait);
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);
58};
59
60struct snd_info_entry {
61 const char *name;
62 umode_t mode;
63 long size;
64 unsigned short content;
65 union {
66 struct snd_info_entry_text text;
67 const struct snd_info_entry_ops *ops;
68 } c;
69 struct snd_info_entry *parent;
70 struct module *module;
71 void *private_data;
72 void (*private_free)(struct snd_info_entry *entry);
73 struct proc_dir_entry *p;
74 struct mutex access;
75 struct list_head children;
76 struct list_head list;
77};
78
79#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
80int snd_info_minor_register(void);
81#else
82#define snd_info_minor_register() 0
83#endif
84
85
86#ifdef CONFIG_SND_PROC_FS
87
88extern struct snd_info_entry *snd_seq_root;
89#ifdef CONFIG_SND_OSSEMUL
90extern struct snd_info_entry *snd_oss_root;
91void snd_card_info_read_oss(struct snd_info_buffer *buffer);
92#else
93#define snd_oss_root NULL
94static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {}
95#endif
96
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
109int snd_info_init(void);
110int snd_info_done(void);
111
112int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len);
113const char *snd_info_get_str(char *dest, const char *src, int len);
114struct snd_info_entry *snd_info_create_module_entry(struct module *module,
115 const char *name,
116 struct snd_info_entry *parent);
117struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
118 const char *name,
119 struct snd_info_entry *parent);
120void snd_info_free_entry(struct snd_info_entry *entry);
121int snd_info_store_text(struct snd_info_entry *entry);
122int snd_info_restore_text(struct snd_info_entry *entry);
123
124int snd_info_card_create(struct snd_card *card);
125int snd_info_card_register(struct snd_card *card);
126int snd_info_card_free(struct snd_card *card);
127void snd_info_card_disconnect(struct snd_card *card);
128void snd_info_card_id_change(struct snd_card *card);
129int snd_info_register(struct snd_info_entry *entry);
130
131/* for card drivers */
132static 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}
138
139static inline void snd_info_set_text_ops(struct snd_info_entry *entry,
140 void *private_data,
141 void (*read)(struct snd_info_entry *, struct snd_info_buffer *))
142{
143 entry->private_data = private_data;
144 entry->c.text.read = read;
145}
146
147int 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
154int snd_info_check_reserved_words(const char *str);
155
156#else
157
158#define snd_seq_root NULL
159#define snd_oss_root NULL
160
161static inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; }
162static inline int snd_info_init(void) { return 0; }
163static inline int snd_info_done(void) { return 0; }
164
165static inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; }
166static inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; }
167static inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; }
168static inline struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, const char *name, struct snd_info_entry *parent) { return NULL; }
169static inline void snd_info_free_entry(struct snd_info_entry *entry) { ; }
170
171static inline int snd_info_card_create(struct snd_card *card) { return 0; }
172static inline int snd_info_card_register(struct snd_card *card) { return 0; }
173static inline int snd_info_card_free(struct snd_card *card) { return 0; }
174static inline void snd_info_card_disconnect(struct snd_card *card) { }
175static inline void snd_info_card_id_change(struct snd_card *card) { }
176static inline int snd_info_register(struct snd_info_entry *entry) { return 0; }
177
178static inline int snd_card_proc_new(struct snd_card *card, const char *name,
179 struct snd_info_entry **entryp) { return -EINVAL; }
180static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)),
181 void *private_data,
182 void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {}
183static 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}
192static inline int snd_info_check_reserved_words(const char *str) { return 1; }
193
194#endif
195
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 */
206static inline int
207snd_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
215/*
216 * OSS info part
217 */
218
219#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
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
229int snd_oss_info_register(int dev, int num, char *string);
230#define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL)
231
232#endif /* CONFIG_SND_OSSEMUL && CONFIG_SND_PROC_FS */
233
234#endif /* __SOUND_INFO_H */