xref: /titanic_51/usr/src/uts/common/io/audio/impl/audio_client.h (revision 2c30fa4582c5d6c659e059e719c5f6163f7ef1e3)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_AUDIO_CLIENT_H
27 #define	_AUDIO_CLIENT_H
28 
29 /*
30  * Structure implementation in audio_impl.h
31  */
32 #include <sys/audio/audio_common.h>
33 
34 typedef struct audio_client_ops {
35 	const char	*aco_minor_prefix;
36 	void		*(*aco_dev_init)(audio_dev_t *);
37 	void		(*aco_dev_fini)(void *);
38 	int		(*aco_open)(audio_client_t *, int);
39 	void		(*aco_close)(audio_client_t *);
40 	int		(*aco_read)(audio_client_t *, struct uio *, cred_t *);
41 	int		(*aco_write)(audio_client_t *, struct uio *, cred_t *);
42 	int		(*aco_ioctl)(audio_client_t *, int, intptr_t, int,
43 			    cred_t *, int *);
44 	int		(*aco_chpoll)(audio_client_t *, short, int, short *,
45 			    struct pollhead **);
46 	int		(*aco_mmap)(audio_client_t *, ...);
47 	void		(*aco_input)(audio_client_t *);
48 	void		(*aco_output)(audio_client_t *);
49 	void		(*aco_drain)(audio_client_t *);
50 
51 	void		(*aco_wput)(audio_client_t *, mblk_t *);
52 	void		(*aco_wsrv)(audio_client_t *);
53 	void		(*aco_rsrv)(audio_client_t *);
54 } audio_client_ops_t;
55 
56 void *auclnt_get_private(audio_client_t *);
57 void auclnt_set_private(audio_client_t *, void *);
58 
59 int auclnt_drain(audio_client_t *);
60 int auclnt_start_drain(audio_client_t *);
61 
62 int auclnt_set_rate(audio_stream_t *, int);
63 int auclnt_get_rate(audio_stream_t *);
64 
65 int auclnt_set_format(audio_stream_t *, int);
66 int auclnt_get_format(audio_stream_t *);
67 
68 int auclnt_set_channels(audio_stream_t *, int);
69 int auclnt_get_channels(audio_stream_t *);
70 
71 void auclnt_set_gain(audio_stream_t *, uint8_t);
72 uint8_t auclnt_get_gain(audio_stream_t *);
73 
74 void auclnt_set_muted(audio_stream_t *, boolean_t);
75 boolean_t auclnt_get_muted(audio_stream_t *);
76 
77 uint64_t auclnt_get_samples(audio_stream_t *);
78 void auclnt_set_samples(audio_stream_t *, uint64_t);
79 
80 uint64_t auclnt_get_errors(audio_stream_t *);
81 void auclnt_set_errors(audio_stream_t *, uint64_t);
82 
83 uint64_t auclnt_get_eof(audio_stream_t *);
84 void auclnt_set_eof(audio_stream_t *, uint64_t);
85 
86 boolean_t auclnt_is_running(audio_stream_t *);
87 void auclnt_start(audio_stream_t *);
88 void auclnt_stop(audio_stream_t *);
89 
90 void auclnt_set_paused(audio_stream_t *);
91 void auclnt_clear_paused(audio_stream_t *);
92 boolean_t auclnt_is_paused(audio_stream_t *);
93 
94 void auclnt_flush(audio_stream_t *);
95 
96 void auclnt_get_output_qlen(audio_client_t *, uint_t *, uint_t *);
97 
98 uint_t auclnt_get_fragsz(audio_stream_t *);
99 uint_t auclnt_get_framesz(audio_stream_t *);
100 uint_t auclnt_get_nfrags(audio_stream_t *);
101 uint_t auclnt_get_nframes(audio_stream_t *);
102 uint_t auclnt_get_count(audio_stream_t *);
103 uint64_t auclnt_get_head(audio_stream_t *);
104 uint64_t auclnt_get_tail(audio_stream_t *);
105 uint_t auclnt_get_hidx(audio_stream_t *);
106 uint_t auclnt_get_tidx(audio_stream_t *);
107 
108 void auclnt_set_latency(audio_stream_t *, uint_t, uint_t);
109 
110 audio_stream_t *auclnt_input_stream(audio_client_t *);
111 audio_stream_t *auclnt_output_stream(audio_client_t *);
112 
113 int auclnt_get_oflag(audio_client_t *);
114 
115 int auclnt_open(audio_client_t *, int);
116 void auclnt_close(audio_client_t *);
117 
118 void auclnt_register_ops(minor_t, audio_client_ops_t *);
119 
120 minor_t	auclnt_get_minor(audio_client_t *);
121 minor_t auclnt_get_original_minor(audio_client_t *);
122 minor_t auclnt_get_minor_type(audio_client_t *);
123 queue_t *auclnt_get_rq(audio_client_t *);
124 queue_t *auclnt_get_wq(audio_client_t *);
125 
126 uint_t auclnt_produce(audio_stream_t *, uint_t);
127 uint_t auclnt_produce_data(audio_stream_t *, caddr_t, uint_t);
128 uint_t auclnt_consume(audio_stream_t *, uint_t);
129 uint_t auclnt_consume_data(audio_stream_t *, caddr_t, uint_t);
130 int auclnt_read(audio_client_t *, struct uio *);
131 int auclnt_write(audio_client_t *, struct uio *);
132 int auclnt_chpoll(audio_client_t *, short, int, short *, struct pollhead **);
133 void auclnt_pollwakeup(audio_client_t *, short);
134 
135 /*
136  * Return the process id that performed the original open() of the client.
137  */
138 pid_t auclnt_get_pid(audio_client_t *);
139 
140 /*
141  * Return the credentials of the process that opened the client.
142  */
143 cred_t *auclnt_get_cred(audio_client_t *);
144 
145 /*
146  * Get an opaque handle the underlying device for an audio client.
147  */
148 audio_dev_t *auclnt_get_dev(audio_client_t *);
149 audio_dev_t *auclnt_hold_dev_by_index(int);
150 void auclnt_release_dev(audio_dev_t *);
151 int auclnt_get_dev_index(audio_dev_t *);
152 int auclnt_get_dev_number(audio_dev_t *);
153 void auclnt_set_dev_number(audio_dev_t *, int);
154 const char *auclnt_get_dev_name(audio_dev_t *);
155 const char *auclnt_get_dev_driver(audio_dev_t *);
156 dev_info_t *auclnt_get_dev_devinfo(audio_dev_t *);
157 int auclnt_get_dev_instance(audio_dev_t *);
158 const char *auclnt_get_dev_description(audio_dev_t *);
159 const char *auclnt_get_dev_version(audio_dev_t *);
160 const char *auclnt_get_dev_hw_info(audio_dev_t *, void **);
161 uint_t auclnt_get_dev_capab(audio_dev_t *);
162 #define	AUDIO_CLIENT_CAP_PLAY		(1U << 0)
163 #define	AUDIO_CLIENT_CAP_RECORD		(1U << 1)
164 #define	AUDIO_CLIENT_CAP_DUPLEX		(1U << 2)
165 #define	AUDIO_CLIENT_CAP_SNDSTAT	(1U << 3)
166 #define	AUDIO_CLIENT_CAP_OPAQUE		(1U << 4)
167 
168 /*
169  * Walk all the open client structures for a named audio device.
170  * Clients can use this to find "peer" clients accessing the same
171  * audio device.  (This is useful for implementing special linkages,
172  * e.g. between /dev/audio and /dev/audioctl.)
173  */
174 void auclnt_dev_walk_clients(audio_dev_t *,
175     int (*)(audio_client_t *, void *), void *);
176 
177 /*
178  * This is used to check for updates to volume and control status.
179  * Its a polling-based interface because that's what our clients (OSS)
180  * need, and its far lighter weight than forcing an asynchronous
181  * callback on everything.
182  */
183 uint_t auclnt_dev_get_serial(audio_dev_t *);
184 
185 /*
186  * Audio control functions for use by clients.
187  */
188 
189 /*
190  * This will walk all controls registered to my device and callback
191  * to walker for each one with its audio_ctrl_desc_t..
192  *
193  * Note that walk_func may return values to continue (AUDIO_WALK_CONTINUE)
194  * or stop walk (AUDIO_WALK_STOP).
195  *
196  */
197 void auclnt_walk_controls(audio_dev_t *,
198     int (*)(audio_ctrl_t *, void *), void *);
199 
200 /*
201  * This will search all controls attached to a clients
202  * audio device for a control with the desired name.
203  *
204  * On successful return a ctrl handle will be returned. On
205  * failure NULL is returned.
206  */
207 audio_ctrl_t *auclnt_find_control(audio_dev_t *, const char *);
208 
209 /*
210  * Given a known control, get its attributes.
211  *
212  * The caller must supply a audio_ctrl_desc_t structure.  Also the
213  * values in the structure are ignored when making the call and filled
214  * in by this function.
215  *
216  * If an error occurs then a non-zero is returned.
217  */
218 int auclnt_control_describe(audio_ctrl_t *, audio_ctrl_desc_t *);
219 
220 
221 /*
222  * This is used to read the current value of a control.
223  * Note, this will cause a callback into the driver to get the value.
224  *
225  * On return zero is returned on success else errno is returned.
226  */
227 int auclnt_control_read(audio_ctrl_t *, uint64_t *);
228 
229 /*
230  * This is used to write a value to a control.
231  * Note, this will cause a callback into the driver to write the value.
232  *
233  * On return zero is returned on success else errno is returned.
234  *
235  */
236 int auclnt_control_write(audio_ctrl_t *, uint64_t);
237 
238 /*
239  * Walk all the audio devices on the system.  Useful for clients
240  * like sndstat, which may need to inquire about every audio device
241  * on the system.
242  */
243 void auclnt_walk_devs(int (*walker)(audio_dev_t *, void *), void *);
244 void auclnt_walk_devs_by_number(int (*walker)(audio_dev_t *, void *), void *);
245 
246 audio_client_t *auclnt_hold_by_devt(dev_t);
247 void auclnt_release(audio_client_t *);
248 void auclnt_hold(audio_client_t *);
249 int auclnt_serialize(audio_client_t *);
250 void auclnt_unserialize(audio_client_t *);
251 
252 /*
253  * Engine rlated accesses.  Note that normally clients don't need this level
254  * of information.
255  */
256 void auclnt_dev_walk_engines(audio_dev_t *,
257     int (*)(audio_engine_t *, void *), void *);
258 int auclnt_engine_get_format(audio_engine_t *);
259 int auclnt_engine_get_rate(audio_engine_t *);
260 int auclnt_engine_get_channels(audio_engine_t *);
261 uint_t auclnt_engine_get_capab(audio_engine_t *);
262 
263 /*
264  * Retrieve minor-specific data for the instance.  This allows for
265  * personality modules to store persistent state data on a physical
266  * device (e.g. to store persistent settings.)  Synchronization of
267  * stored settings between personality modules is up to the
268  * personality modules themselves.
269  */
270 void *auclnt_get_minor_data(audio_client_t *, minor_t);
271 void *auclnt_get_dev_minor_data(audio_dev_t *, minor_t);
272 
273 /*
274  * Simpler warning message, alternative to cmn_err.
275  */
276 void auclnt_warn(audio_client_t *, const char *fmt, ...);
277 
278 #endif	/* _AUDIO_CLIENT_H */
279