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> |
30#ifdef USING_MUTEX 31#include <sys/sx.h> 32#endif 33 |
34SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/sndstat.c 170815 2007-06-16 03:37:28Z ariff $"); |
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, |
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 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) { |
151 mtx_lock(&sndstat_lock); |
152 SNDSTAT_PID_SET(i_dev, 0); 153 mtx_unlock(&sndstat_lock); |
154 return ENXIO; |
155 } |
156 sndstat_bufptr = 0; 157 return 0; |
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 |
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; |
354 int i, j; 355 |
356 sbuf_printf(s, "FreeBSD Audio Driver (newpcm: %ubit %d/%s)\n", 357 (u_int)sizeof(intpcm_t) << 3, SND_DRV_VERSION, MACHINE_ARCH); |
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); |
376 sbuf_printf(s, "%s:", device_get_nameunit(ent->dev)); 377 sbuf_printf(s, " <%s>", device_get_desc(ent->dev)); |
378 sbuf_printf(s, " %s [%s]", ent->str, 379 (d->flags & SD_F_MPSAFE) ? "MPSAFE" : "GIANT"); |
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); |
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 --- |