Deleted Added
full compact
sndstat.c (170289) sndstat.c (170815)
1/*-
2 * Copyright (c) 2001 Cameron Grant <cg@freebsd.org>
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

--- 12 unchanged lines hidden (view full) ---

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>
1/*-
2 * Copyright (c) 2001 Cameron Grant <cg@freebsd.org>
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

--- 12 unchanged lines hidden (view full) ---

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#include <dev/sound/version.h>
29#ifdef USING_MUTEX
30#include <sys/sx.h>
31#endif
32
30#ifdef USING_MUTEX
31#include <sys/sx.h>
32#endif
33
33SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/sndstat.c 170289 2007-06-04 18:25:08Z dwmalone $");
34SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/sndstat.c 170815 2007-06-16 03:37:28Z ariff $");
34
35#define SS_TYPE_MODULE 0
36#define SS_TYPE_FIRST 1
37#define SS_TYPE_PCM 1
38#define SS_TYPE_MIDI 2
39#define SS_TYPE_SEQUENCER 3
40#define SS_TYPE_LAST 3
41
42static d_open_t sndstat_open;
43static d_close_t sndstat_close;
44static d_read_t sndstat_read;
45
46static struct cdevsw sndstat_cdevsw = {
47 .d_version = D_VERSION,
35
36#define SS_TYPE_MODULE 0
37#define SS_TYPE_FIRST 1
38#define SS_TYPE_PCM 1
39#define SS_TYPE_MIDI 2
40#define SS_TYPE_SEQUENCER 3
41#define SS_TYPE_LAST 3
42
43static d_open_t sndstat_open;
44static d_close_t sndstat_close;
45static d_read_t sndstat_read;
46
47static struct cdevsw sndstat_cdevsw = {
48 .d_version = D_VERSION,
48 .d_flags = D_NEEDGIANT,
49 .d_open = sndstat_open,
50 .d_close = sndstat_close,
51 .d_read = sndstat_read,
52 .d_name = "sndstat",
53};
54
55struct sndstat_entry {
56 SLIST_ENTRY(sndstat_entry) link;

--- 75 unchanged lines hidden (view full) ---

132 return error;
133}
134SYSCTL_PROC(_hw_snd, OID_AUTO, verbose, CTLTYPE_INT | CTLFLAG_RW,
135 0, sizeof(int), sysctl_hw_sndverbose, "I", "verbosity level");
136
137static int
138sndstat_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
139{
49 .d_open = sndstat_open,
50 .d_close = sndstat_close,
51 .d_read = sndstat_read,
52 .d_name = "sndstat",
53};
54
55struct sndstat_entry {
56 SLIST_ENTRY(sndstat_entry) link;

--- 75 unchanged lines hidden (view full) ---

132 return error;
133}
134SYSCTL_PROC(_hw_snd, OID_AUTO, verbose, CTLTYPE_INT | CTLFLAG_RW,
135 0, sizeof(int), sysctl_hw_sndverbose, "I", "verbosity level");
136
137static int
138sndstat_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
139{
140 int error;
141
142 if (sndstat_dev == NULL || i_dev != sndstat_dev)
143 return EBADF;
144
145 mtx_lock(&sndstat_lock);
146 if (SNDSTAT_PID(i_dev) != 0) {
147 mtx_unlock(&sndstat_lock);
148 return EBUSY;
149 }
150 SNDSTAT_PID_SET(i_dev, td->td_proc->p_pid);
151 mtx_unlock(&sndstat_lock);
152 if (sbuf_new(&sndstat_sbuf, NULL, 4096, SBUF_AUTOEXTEND) == NULL) {
140 if (sndstat_dev == NULL || i_dev != sndstat_dev)
141 return EBADF;
142
143 mtx_lock(&sndstat_lock);
144 if (SNDSTAT_PID(i_dev) != 0) {
145 mtx_unlock(&sndstat_lock);
146 return EBUSY;
147 }
148 SNDSTAT_PID_SET(i_dev, td->td_proc->p_pid);
149 mtx_unlock(&sndstat_lock);
150 if (sbuf_new(&sndstat_sbuf, NULL, 4096, SBUF_AUTOEXTEND) == NULL) {
153 error = ENXIO;
154 goto out;
155 }
156 sndstat_bufptr = 0;
157 error = (sndstat_prepare(&sndstat_sbuf) > 0) ? 0 : ENOMEM;
158out:
159 if (error) {
160 mtx_lock(&sndstat_lock);
151 mtx_lock(&sndstat_lock);
161 SNDSTAT_FLUSH();
162 SNDSTAT_PID_SET(i_dev, 0);
163 mtx_unlock(&sndstat_lock);
152 SNDSTAT_PID_SET(i_dev, 0);
153 mtx_unlock(&sndstat_lock);
154 return ENXIO;
164 }
155 }
165 return (error);
156 sndstat_bufptr = 0;
157 return 0;
166}
167
168static int
169sndstat_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
170{
171 if (sndstat_dev == NULL || i_dev != sndstat_dev)
172 return EBADF;
173

--- 22 unchanged lines hidden (view full) ---

196 mtx_lock(&sndstat_lock);
197 if (SNDSTAT_PID(i_dev) != buf->uio_td->td_proc->p_pid ||
198 sndstat_bufptr == -1) {
199 mtx_unlock(&sndstat_lock);
200 return EBADF;
201 }
202 mtx_unlock(&sndstat_lock);
203
158}
159
160static int
161sndstat_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
162{
163 if (sndstat_dev == NULL || i_dev != sndstat_dev)
164 return EBADF;
165

--- 22 unchanged lines hidden (view full) ---

188 mtx_lock(&sndstat_lock);
189 if (SNDSTAT_PID(i_dev) != buf->uio_td->td_proc->p_pid ||
190 sndstat_bufptr == -1) {
191 mtx_unlock(&sndstat_lock);
192 return EBADF;
193 }
194 mtx_unlock(&sndstat_lock);
195
196 if (sndstat_bufptr == 0) {
197 err = (sndstat_prepare(&sndstat_sbuf) > 0) ? 0 : ENOMEM;
198 if (err) {
199 mtx_lock(&sndstat_lock);
200 SNDSTAT_FLUSH();
201 mtx_unlock(&sndstat_lock);
202 return err;
203 }
204 }
205
204 l = min(buf->uio_resid, sbuf_len(&sndstat_sbuf) - sndstat_bufptr);
205 err = (l > 0)? uiomove(sbuf_data(&sndstat_sbuf) + sndstat_bufptr, l, buf) : 0;
206 sndstat_bufptr += l;
207
208 return err;
209}
210
211/************************************************************************/

--- 131 unchanged lines hidden (view full) ---

343}
344
345/************************************************************************/
346
347static int
348sndstat_prepare(struct sbuf *s)
349{
350 struct sndstat_entry *ent;
206 l = min(buf->uio_resid, sbuf_len(&sndstat_sbuf) - sndstat_bufptr);
207 err = (l > 0)? uiomove(sbuf_data(&sndstat_sbuf) + sndstat_bufptr, l, buf) : 0;
208 sndstat_bufptr += l;
209
210 return err;
211}
212
213/************************************************************************/

--- 131 unchanged lines hidden (view full) ---

345}
346
347/************************************************************************/
348
349static int
350sndstat_prepare(struct sbuf *s)
351{
352 struct sndstat_entry *ent;
353 struct snddev_info *d;
351 int i, j;
352
354 int i, j;
355
353 sbuf_printf(s, "FreeBSD Audio Driver (newpcm: %ubit)\n",
354 (unsigned int)sizeof(intpcm_t) << 3);
356 sbuf_printf(s, "FreeBSD Audio Driver (newpcm: %ubit %d/%s)\n",
357 (u_int)sizeof(intpcm_t) << 3, SND_DRV_VERSION, MACHINE_ARCH);
355 if (SLIST_EMPTY(&sndstat_devlist)) {
356 sbuf_printf(s, "No devices installed.\n");
357 sbuf_finish(s);
358 return sbuf_len(s);
359 }
360
361 sbuf_printf(s, "Installed devices:\n");
362
363 for (i = 0; i <= sndstat_maxunit; i++) {
364 for (j = SS_TYPE_FIRST; j <= SS_TYPE_LAST; j++) {
365 ent = sndstat_find(j, i);
366 if (!ent)
367 continue;
358 if (SLIST_EMPTY(&sndstat_devlist)) {
359 sbuf_printf(s, "No devices installed.\n");
360 sbuf_finish(s);
361 return sbuf_len(s);
362 }
363
364 sbuf_printf(s, "Installed devices:\n");
365
366 for (i = 0; i <= sndstat_maxunit; i++) {
367 for (j = SS_TYPE_FIRST; j <= SS_TYPE_LAST; j++) {
368 ent = sndstat_find(j, i);
369 if (!ent)
370 continue;
371 d = device_get_softc(ent->dev);
372 if (!PCM_REGISTERED(d))
373 continue;
374 /* XXX Need Giant magic entry ??? */
375 PCM_ACQUIRE_QUICK(d);
368 sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
369 sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
376 sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
377 sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
370 sbuf_printf(s, " %s", ent->str);
378 sbuf_printf(s, " %s [%s]", ent->str,
379 (d->flags & SD_F_MPSAFE) ? "MPSAFE" : "GIANT");
371 if (ent->handler)
372 ent->handler(s, ent->dev, snd_verbose);
373 else
374 sbuf_printf(s, " [no handler]");
375 sbuf_printf(s, "\n");
380 if (ent->handler)
381 ent->handler(s, ent->dev, snd_verbose);
382 else
383 sbuf_printf(s, " [no handler]");
384 sbuf_printf(s, "\n");
385 PCM_RELEASE_QUICK(d);
376 }
377 }
378
379 if (snd_verbose >= 3 && sndstat_files > 0) {
380 sbuf_printf(s, "\nFile Versions:\n");
381
382 SLIST_FOREACH(ent, &sndstat_devlist, link) {
383 if (ent->dev == NULL && ent->str != NULL)

--- 59 unchanged lines hidden ---
386 }
387 }
388
389 if (snd_verbose >= 3 && sndstat_files > 0) {
390 sbuf_printf(s, "\nFile Versions:\n");
391
392 SLIST_FOREACH(ent, &sndstat_devlist, link) {
393 if (ent->dev == NULL && ent->str != NULL)

--- 59 unchanged lines hidden ---