Deleted Added
full compact
sndstat.c (111119) sndstat.c (111815)
1/*
2 * Copyright (c) 2001 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <dev/sound/pcm/sound.h>
28#include <dev/sound/pcm/vchan.h>
29
1/*
2 * Copyright (c) 2001 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <dev/sound/pcm/sound.h>
28#include <dev/sound/pcm/vchan.h>
29
30SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/sndstat.c 111119 2003-02-19 05:47:46Z imp $");
30SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/sndstat.c 111815 2003-03-03 12:15:54Z phk $");
31
32#define SS_TYPE_MODULE 0
33#define SS_TYPE_FIRST 1
34#define SS_TYPE_PCM 1
35#define SS_TYPE_MIDI 2
36#define SS_TYPE_SEQUENCER 3
37#define SS_TYPE_LAST 3
38
39static d_open_t sndstat_open;
40static d_close_t sndstat_close;
41static d_read_t sndstat_read;
42
43static struct cdevsw sndstat_cdevsw = {
31
32#define SS_TYPE_MODULE 0
33#define SS_TYPE_FIRST 1
34#define SS_TYPE_PCM 1
35#define SS_TYPE_MIDI 2
36#define SS_TYPE_SEQUENCER 3
37#define SS_TYPE_LAST 3
38
39static d_open_t sndstat_open;
40static d_close_t sndstat_close;
41static d_read_t sndstat_read;
42
43static struct cdevsw sndstat_cdevsw = {
44 /* open */ sndstat_open,
45 /* close */ sndstat_close,
46 /* read */ sndstat_read,
47 /* write */ nowrite,
48 /* ioctl */ noioctl,
49 /* poll */ nopoll,
50 /* mmap */ nommap,
51 /* strategy */ nostrategy,
52 /* name */ "sndstat",
53 /* maj */ SND_CDEV_MAJOR,
54 /* dump */ nodump,
55 /* psize */ nopsize,
56 /* flags */ 0,
44 .d_open = sndstat_open,
45 .d_close = sndstat_close,
46 .d_read = sndstat_read,
47 .d_name = "sndstat",
48 .d_maj = SND_CDEV_MAJOR,
57};
58
59struct sndstat_entry {
60 SLIST_ENTRY(sndstat_entry) link;
61 device_t dev;
62 char *str;
63 sndstat_handler handler;
64 int type, unit;
65};
66
67#ifdef USING_MUTEX
68static struct mtx sndstat_lock;
69#endif
70static struct sbuf sndstat_sbuf;
71static dev_t sndstat_dev = 0;
72static int sndstat_isopen = 0;
73static int sndstat_bufptr;
74static int sndstat_maxunit = -1;
75static int sndstat_files = 0;
76
77static SLIST_HEAD(, sndstat_entry) sndstat_devlist = SLIST_HEAD_INITIALIZER(none);
78
79static int sndstat_verbose = 1;
80#ifdef USING_MUTEX
81TUNABLE_INT("hw.snd.verbose", &sndstat_verbose);
82#else
83TUNABLE_INT_DECL("hw.snd.verbose", 1, sndstat_verbose);
84#endif
85
86static int sndstat_prepare(struct sbuf *s);
87
88static int
89sysctl_hw_sndverbose(SYSCTL_HANDLER_ARGS)
90{
91 intrmask_t s;
92 int error, verbose;
93
94 verbose = sndstat_verbose;
95 error = sysctl_handle_int(oidp, &verbose, sizeof(verbose), req);
96 if (error == 0 && req->newptr != NULL) {
97 s = spltty();
98 mtx_lock(&sndstat_lock);
99 if (verbose < 0 || verbose > 3)
100 error = EINVAL;
101 else
102 sndstat_verbose = verbose;
103 mtx_unlock(&sndstat_lock);
104 splx(s);
105 }
106 return error;
107}
108SYSCTL_PROC(_hw_snd, OID_AUTO, verbose, CTLTYPE_INT | CTLFLAG_RW,
109 0, sizeof(int), sysctl_hw_sndverbose, "I", "");
110
111static int
112sndstat_open(dev_t i_dev, int flags, int mode, struct thread *td)
113{
114 intrmask_t s;
115 int error;
116
117 s = spltty();
118 mtx_lock(&sndstat_lock);
119 if (sndstat_isopen) {
120 mtx_unlock(&sndstat_lock);
121 splx(s);
122 return EBUSY;
123 }
124 sndstat_isopen = 1;
125 mtx_unlock(&sndstat_lock);
126 splx(s);
127 if (sbuf_new(&sndstat_sbuf, NULL, 4096, 0) == NULL) {
128 error = ENXIO;
129 goto out;
130 }
131 sndstat_bufptr = 0;
132 error = (sndstat_prepare(&sndstat_sbuf) > 0) ? 0 : ENOMEM;
133out:
134 if (error) {
135 s = spltty();
136 mtx_lock(&sndstat_lock);
137 sndstat_isopen = 0;
138 mtx_unlock(&sndstat_lock);
139 splx(s);
140 }
141 return (error);
142}
143
144static int
145sndstat_close(dev_t i_dev, int flags, int mode, struct thread *td)
146{
147 intrmask_t s;
148
149 s = spltty();
150 mtx_lock(&sndstat_lock);
151 if (!sndstat_isopen) {
152 mtx_unlock(&sndstat_lock);
153 splx(s);
154 return EBADF;
155 }
156 sbuf_delete(&sndstat_sbuf);
157 sndstat_isopen = 0;
158
159 mtx_unlock(&sndstat_lock);
160 splx(s);
161 return 0;
162}
163
164static int
165sndstat_read(dev_t i_dev, struct uio *buf, int flag)
166{
167 intrmask_t s;
168 int l, err;
169
170 s = spltty();
171 mtx_lock(&sndstat_lock);
172 if (!sndstat_isopen) {
173 mtx_unlock(&sndstat_lock);
174 splx(s);
175 return EBADF;
176 }
177 l = min(buf->uio_resid, sbuf_len(&sndstat_sbuf) - sndstat_bufptr);
178 err = (l > 0)? uiomove(sbuf_data(&sndstat_sbuf) + sndstat_bufptr, l, buf) : 0;
179 sndstat_bufptr += l;
180
181 mtx_unlock(&sndstat_lock);
182 splx(s);
183 return err;
184}
185
186/************************************************************************/
187
188static struct sndstat_entry *
189sndstat_find(int type, int unit)
190{
191 struct sndstat_entry *ent;
192
193 SLIST_FOREACH(ent, &sndstat_devlist, link) {
194 if (ent->type == type && ent->unit == unit)
195 return ent;
196 }
197
198 return NULL;
199}
200
201int
202sndstat_register(device_t dev, char *str, sndstat_handler handler)
203{
204 intrmask_t s;
205 struct sndstat_entry *ent;
206 const char *devtype;
207 int type, unit;
208
209 if (dev) {
210 unit = device_get_unit(dev);
211 devtype = device_get_name(dev);
212 if (!strcmp(devtype, "pcm"))
213 type = SS_TYPE_PCM;
214 else if (!strcmp(devtype, "midi"))
215 type = SS_TYPE_MIDI;
216 else if (!strcmp(devtype, "sequencer"))
217 type = SS_TYPE_SEQUENCER;
218 else
219 return EINVAL;
220 } else {
221 type = SS_TYPE_MODULE;
222 unit = -1;
223 }
224
225 ent = malloc(sizeof *ent, M_DEVBUF, M_ZERO | M_WAITOK);
226 if (!ent)
227 return ENOSPC;
228
229 ent->dev = dev;
230 ent->str = str;
231 ent->type = type;
232 ent->unit = unit;
233 ent->handler = handler;
234
235 s = spltty();
236 mtx_lock(&sndstat_lock);
237 SLIST_INSERT_HEAD(&sndstat_devlist, ent, link);
238 if (type == SS_TYPE_MODULE)
239 sndstat_files++;
240 sndstat_maxunit = (unit > sndstat_maxunit)? unit : sndstat_maxunit;
241 mtx_unlock(&sndstat_lock);
242 splx(s);
243
244 return 0;
245}
246
247int
248sndstat_registerfile(char *str)
249{
250 return sndstat_register(NULL, str, NULL);
251}
252
253int
254sndstat_unregister(device_t dev)
255{
256 intrmask_t s;
257 struct sndstat_entry *ent;
258
259 s = spltty();
260 mtx_lock(&sndstat_lock);
261 SLIST_FOREACH(ent, &sndstat_devlist, link) {
262 if (ent->dev == dev) {
263 SLIST_REMOVE(&sndstat_devlist, ent, sndstat_entry, link);
264 mtx_unlock(&sndstat_lock);
265 splx(s);
266 free(ent, M_DEVBUF);
267
268 return 0;
269 }
270 }
271 mtx_unlock(&sndstat_lock);
272 splx(s);
273
274 return ENXIO;
275}
276
277int
278sndstat_unregisterfile(char *str)
279{
280 intrmask_t s;
281 struct sndstat_entry *ent;
282
283 s = spltty();
284 mtx_lock(&sndstat_lock);
285 SLIST_FOREACH(ent, &sndstat_devlist, link) {
286 if (ent->dev == NULL && ent->str == str) {
287 SLIST_REMOVE(&sndstat_devlist, ent, sndstat_entry, link);
288 sndstat_files--;
289 mtx_unlock(&sndstat_lock);
290 splx(s);
291 free(ent, M_DEVBUF);
292
293 return 0;
294 }
295 }
296 mtx_unlock(&sndstat_lock);
297 splx(s);
298
299 return ENXIO;
300}
301
302/************************************************************************/
303
304static int
305sndstat_prepare(struct sbuf *s)
306{
307 struct sndstat_entry *ent;
308 int i, j;
309
310 sbuf_printf(s, "FreeBSD Audio Driver (newpcm)\n");
311 if (SLIST_EMPTY(&sndstat_devlist)) {
312 sbuf_printf(s, "No devices installed.\n");
313 sbuf_finish(s);
314 return sbuf_len(s);
315 }
316
317 sbuf_printf(s, "Installed devices:\n");
318
319 for (i = 0; i <= sndstat_maxunit; i++) {
320 for (j = SS_TYPE_FIRST; j <= SS_TYPE_LAST; j++) {
321 ent = sndstat_find(j, i);
322 if (!ent)
323 continue;
324 sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
325 sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
326 sbuf_printf(s, " %s", ent->str);
327 if (ent->handler)
328 ent->handler(s, ent->dev, sndstat_verbose);
329 else
330 sbuf_printf(s, " [no handler]");
331 sbuf_printf(s, "\n");
332 }
333 }
334
335 if (sndstat_verbose >= 3 && sndstat_files > 0) {
336 sbuf_printf(s, "\nFile Versions:\n");
337
338 SLIST_FOREACH(ent, &sndstat_devlist, link) {
339 if (ent->dev == NULL && ent->str != NULL)
340 sbuf_printf(s, "%s\n", ent->str);
341 }
342 }
343
344 sbuf_finish(s);
345 return sbuf_len(s);
346}
347
348static int
349sndstat_init(void)
350{
351 mtx_init(&sndstat_lock, "sndstat", NULL, 0);
352 sndstat_dev = make_dev(&sndstat_cdevsw, SND_DEV_STATUS, UID_ROOT, GID_WHEEL, 0444, "sndstat");
353
354 return (sndstat_dev != 0)? 0 : ENXIO;
355}
356
357static int
358sndstat_uninit(void)
359{
360 intrmask_t s;
361
362 s = spltty();
363 mtx_lock(&sndstat_lock);
364 if (sndstat_isopen) {
365 mtx_unlock(&sndstat_lock);
366 splx(s);
367 return EBUSY;
368 }
369
370 if (sndstat_dev)
371 destroy_dev(sndstat_dev);
372 sndstat_dev = 0;
373
374 splx(s);
375 mtx_destroy(&sndstat_lock);
376 return 0;
377}
378
379int
380sndstat_busy(void)
381{
382 return (sndstat_isopen);
383}
384
385static void
386sndstat_sysinit(void *p)
387{
388 sndstat_init();
389}
390
391static void
392sndstat_sysuninit(void *p)
393{
394 sndstat_uninit();
395}
396
397SYSINIT(sndstat_sysinit, SI_SUB_DRIVERS, SI_ORDER_FIRST, sndstat_sysinit, NULL);
398SYSUNINIT(sndstat_sysuninit, SI_SUB_DRIVERS, SI_ORDER_FIRST, sndstat_sysuninit, NULL);
399
400
49};
50
51struct sndstat_entry {
52 SLIST_ENTRY(sndstat_entry) link;
53 device_t dev;
54 char *str;
55 sndstat_handler handler;
56 int type, unit;
57};
58
59#ifdef USING_MUTEX
60static struct mtx sndstat_lock;
61#endif
62static struct sbuf sndstat_sbuf;
63static dev_t sndstat_dev = 0;
64static int sndstat_isopen = 0;
65static int sndstat_bufptr;
66static int sndstat_maxunit = -1;
67static int sndstat_files = 0;
68
69static SLIST_HEAD(, sndstat_entry) sndstat_devlist = SLIST_HEAD_INITIALIZER(none);
70
71static int sndstat_verbose = 1;
72#ifdef USING_MUTEX
73TUNABLE_INT("hw.snd.verbose", &sndstat_verbose);
74#else
75TUNABLE_INT_DECL("hw.snd.verbose", 1, sndstat_verbose);
76#endif
77
78static int sndstat_prepare(struct sbuf *s);
79
80static int
81sysctl_hw_sndverbose(SYSCTL_HANDLER_ARGS)
82{
83 intrmask_t s;
84 int error, verbose;
85
86 verbose = sndstat_verbose;
87 error = sysctl_handle_int(oidp, &verbose, sizeof(verbose), req);
88 if (error == 0 && req->newptr != NULL) {
89 s = spltty();
90 mtx_lock(&sndstat_lock);
91 if (verbose < 0 || verbose > 3)
92 error = EINVAL;
93 else
94 sndstat_verbose = verbose;
95 mtx_unlock(&sndstat_lock);
96 splx(s);
97 }
98 return error;
99}
100SYSCTL_PROC(_hw_snd, OID_AUTO, verbose, CTLTYPE_INT | CTLFLAG_RW,
101 0, sizeof(int), sysctl_hw_sndverbose, "I", "");
102
103static int
104sndstat_open(dev_t i_dev, int flags, int mode, struct thread *td)
105{
106 intrmask_t s;
107 int error;
108
109 s = spltty();
110 mtx_lock(&sndstat_lock);
111 if (sndstat_isopen) {
112 mtx_unlock(&sndstat_lock);
113 splx(s);
114 return EBUSY;
115 }
116 sndstat_isopen = 1;
117 mtx_unlock(&sndstat_lock);
118 splx(s);
119 if (sbuf_new(&sndstat_sbuf, NULL, 4096, 0) == NULL) {
120 error = ENXIO;
121 goto out;
122 }
123 sndstat_bufptr = 0;
124 error = (sndstat_prepare(&sndstat_sbuf) > 0) ? 0 : ENOMEM;
125out:
126 if (error) {
127 s = spltty();
128 mtx_lock(&sndstat_lock);
129 sndstat_isopen = 0;
130 mtx_unlock(&sndstat_lock);
131 splx(s);
132 }
133 return (error);
134}
135
136static int
137sndstat_close(dev_t i_dev, int flags, int mode, struct thread *td)
138{
139 intrmask_t s;
140
141 s = spltty();
142 mtx_lock(&sndstat_lock);
143 if (!sndstat_isopen) {
144 mtx_unlock(&sndstat_lock);
145 splx(s);
146 return EBADF;
147 }
148 sbuf_delete(&sndstat_sbuf);
149 sndstat_isopen = 0;
150
151 mtx_unlock(&sndstat_lock);
152 splx(s);
153 return 0;
154}
155
156static int
157sndstat_read(dev_t i_dev, struct uio *buf, int flag)
158{
159 intrmask_t s;
160 int l, err;
161
162 s = spltty();
163 mtx_lock(&sndstat_lock);
164 if (!sndstat_isopen) {
165 mtx_unlock(&sndstat_lock);
166 splx(s);
167 return EBADF;
168 }
169 l = min(buf->uio_resid, sbuf_len(&sndstat_sbuf) - sndstat_bufptr);
170 err = (l > 0)? uiomove(sbuf_data(&sndstat_sbuf) + sndstat_bufptr, l, buf) : 0;
171 sndstat_bufptr += l;
172
173 mtx_unlock(&sndstat_lock);
174 splx(s);
175 return err;
176}
177
178/************************************************************************/
179
180static struct sndstat_entry *
181sndstat_find(int type, int unit)
182{
183 struct sndstat_entry *ent;
184
185 SLIST_FOREACH(ent, &sndstat_devlist, link) {
186 if (ent->type == type && ent->unit == unit)
187 return ent;
188 }
189
190 return NULL;
191}
192
193int
194sndstat_register(device_t dev, char *str, sndstat_handler handler)
195{
196 intrmask_t s;
197 struct sndstat_entry *ent;
198 const char *devtype;
199 int type, unit;
200
201 if (dev) {
202 unit = device_get_unit(dev);
203 devtype = device_get_name(dev);
204 if (!strcmp(devtype, "pcm"))
205 type = SS_TYPE_PCM;
206 else if (!strcmp(devtype, "midi"))
207 type = SS_TYPE_MIDI;
208 else if (!strcmp(devtype, "sequencer"))
209 type = SS_TYPE_SEQUENCER;
210 else
211 return EINVAL;
212 } else {
213 type = SS_TYPE_MODULE;
214 unit = -1;
215 }
216
217 ent = malloc(sizeof *ent, M_DEVBUF, M_ZERO | M_WAITOK);
218 if (!ent)
219 return ENOSPC;
220
221 ent->dev = dev;
222 ent->str = str;
223 ent->type = type;
224 ent->unit = unit;
225 ent->handler = handler;
226
227 s = spltty();
228 mtx_lock(&sndstat_lock);
229 SLIST_INSERT_HEAD(&sndstat_devlist, ent, link);
230 if (type == SS_TYPE_MODULE)
231 sndstat_files++;
232 sndstat_maxunit = (unit > sndstat_maxunit)? unit : sndstat_maxunit;
233 mtx_unlock(&sndstat_lock);
234 splx(s);
235
236 return 0;
237}
238
239int
240sndstat_registerfile(char *str)
241{
242 return sndstat_register(NULL, str, NULL);
243}
244
245int
246sndstat_unregister(device_t dev)
247{
248 intrmask_t s;
249 struct sndstat_entry *ent;
250
251 s = spltty();
252 mtx_lock(&sndstat_lock);
253 SLIST_FOREACH(ent, &sndstat_devlist, link) {
254 if (ent->dev == dev) {
255 SLIST_REMOVE(&sndstat_devlist, ent, sndstat_entry, link);
256 mtx_unlock(&sndstat_lock);
257 splx(s);
258 free(ent, M_DEVBUF);
259
260 return 0;
261 }
262 }
263 mtx_unlock(&sndstat_lock);
264 splx(s);
265
266 return ENXIO;
267}
268
269int
270sndstat_unregisterfile(char *str)
271{
272 intrmask_t s;
273 struct sndstat_entry *ent;
274
275 s = spltty();
276 mtx_lock(&sndstat_lock);
277 SLIST_FOREACH(ent, &sndstat_devlist, link) {
278 if (ent->dev == NULL && ent->str == str) {
279 SLIST_REMOVE(&sndstat_devlist, ent, sndstat_entry, link);
280 sndstat_files--;
281 mtx_unlock(&sndstat_lock);
282 splx(s);
283 free(ent, M_DEVBUF);
284
285 return 0;
286 }
287 }
288 mtx_unlock(&sndstat_lock);
289 splx(s);
290
291 return ENXIO;
292}
293
294/************************************************************************/
295
296static int
297sndstat_prepare(struct sbuf *s)
298{
299 struct sndstat_entry *ent;
300 int i, j;
301
302 sbuf_printf(s, "FreeBSD Audio Driver (newpcm)\n");
303 if (SLIST_EMPTY(&sndstat_devlist)) {
304 sbuf_printf(s, "No devices installed.\n");
305 sbuf_finish(s);
306 return sbuf_len(s);
307 }
308
309 sbuf_printf(s, "Installed devices:\n");
310
311 for (i = 0; i <= sndstat_maxunit; i++) {
312 for (j = SS_TYPE_FIRST; j <= SS_TYPE_LAST; j++) {
313 ent = sndstat_find(j, i);
314 if (!ent)
315 continue;
316 sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
317 sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
318 sbuf_printf(s, " %s", ent->str);
319 if (ent->handler)
320 ent->handler(s, ent->dev, sndstat_verbose);
321 else
322 sbuf_printf(s, " [no handler]");
323 sbuf_printf(s, "\n");
324 }
325 }
326
327 if (sndstat_verbose >= 3 && sndstat_files > 0) {
328 sbuf_printf(s, "\nFile Versions:\n");
329
330 SLIST_FOREACH(ent, &sndstat_devlist, link) {
331 if (ent->dev == NULL && ent->str != NULL)
332 sbuf_printf(s, "%s\n", ent->str);
333 }
334 }
335
336 sbuf_finish(s);
337 return sbuf_len(s);
338}
339
340static int
341sndstat_init(void)
342{
343 mtx_init(&sndstat_lock, "sndstat", NULL, 0);
344 sndstat_dev = make_dev(&sndstat_cdevsw, SND_DEV_STATUS, UID_ROOT, GID_WHEEL, 0444, "sndstat");
345
346 return (sndstat_dev != 0)? 0 : ENXIO;
347}
348
349static int
350sndstat_uninit(void)
351{
352 intrmask_t s;
353
354 s = spltty();
355 mtx_lock(&sndstat_lock);
356 if (sndstat_isopen) {
357 mtx_unlock(&sndstat_lock);
358 splx(s);
359 return EBUSY;
360 }
361
362 if (sndstat_dev)
363 destroy_dev(sndstat_dev);
364 sndstat_dev = 0;
365
366 splx(s);
367 mtx_destroy(&sndstat_lock);
368 return 0;
369}
370
371int
372sndstat_busy(void)
373{
374 return (sndstat_isopen);
375}
376
377static void
378sndstat_sysinit(void *p)
379{
380 sndstat_init();
381}
382
383static void
384sndstat_sysuninit(void *p)
385{
386 sndstat_uninit();
387}
388
389SYSINIT(sndstat_sysinit, SI_SUB_DRIVERS, SI_ORDER_FIRST, sndstat_sysinit, NULL);
390SYSUNINIT(sndstat_sysuninit, SI_SUB_DRIVERS, SI_ORDER_FIRST, sndstat_sysuninit, NULL);
391
392