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