1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2007-2009 Ariff Abdullah <ariff@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _SND_SNDSTAT_H_ 30 #define _SND_SNDSTAT_H_ 31 32 #define SNDSTAT_PREPARE_PCM_ARGS \ 33 struct sbuf *s, device_t dev, int verbose 34 35 #define SNDSTAT_PREPARE_PCM_BEGIN() do { \ 36 struct snddev_info *d; \ 37 struct pcm_channel *c; \ 38 struct pcm_feeder *f; \ 39 \ 40 d = device_get_softc(dev); \ 41 PCM_BUSYASSERT(d); \ 42 \ 43 if (CHN_EMPTY(d, channels.pcm)) { \ 44 sbuf_printf(s, " (mixer only)"); \ 45 return (0); \ 46 } \ 47 \ 48 if (verbose < 1) { \ 49 sbuf_printf(s, " (%s%s%s", \ 50 d->playcount ? "play" : "", \ 51 (d->playcount && d->reccount) ? "/" : "", \ 52 d->reccount ? "rec" : ""); \ 53 } else { \ 54 sbuf_printf(s, " (%dp:%dv/%dr:%dv", \ 55 d->playcount, d->pvchancount, \ 56 d->reccount, d->rvchancount); \ 57 } \ 58 sbuf_printf(s, "%s)%s", \ 59 ((d->playcount != 0 && d->reccount != 0) && \ 60 (d->flags & SD_F_SIMPLEX)) ? " simplex" : "", \ 61 (device_get_unit(dev) == snd_unit) ? " default" : "") 62 63 #define SNDSTAT_PREPARE_PCM_END() \ 64 if (verbose <= 1) \ 65 return (0); \ 66 \ 67 sbuf_printf(s, "\n\t"); \ 68 sbuf_printf(s, "snddev flags=0x%b", d->flags, SD_F_BITS); \ 69 \ 70 CHN_FOREACH(c, d, channels.pcm) { \ 71 \ 72 KASSERT(c->bufhard != NULL && c->bufsoft != NULL, \ 73 ("hosed pcm channel setup")); \ 74 \ 75 sbuf_printf(s, "\n\t"); \ 76 \ 77 sbuf_printf(s, "%s[%s]: ", \ 78 (c->parentchannel != NULL) ? \ 79 c->parentchannel->name : "", c->name); \ 80 sbuf_printf(s, "spd %d", c->speed); \ 81 if (c->speed != sndbuf_getspd(c->bufhard)) \ 82 sbuf_printf(s, "/%d", \ 83 sndbuf_getspd(c->bufhard)); \ 84 sbuf_printf(s, ", fmt 0x%08x", c->format); \ 85 if (c->format != sndbuf_getfmt(c->bufhard)) \ 86 sbuf_printf(s, "/0x%08x", \ 87 sndbuf_getfmt(c->bufhard)); \ 88 sbuf_printf(s, ", flags 0x%08x, 0x%08x", \ 89 c->flags, c->feederflags); \ 90 if (c->pid != -1) \ 91 sbuf_printf(s, ", pid %d (%s)", \ 92 c->pid, c->comm); \ 93 sbuf_printf(s, "\n\t"); \ 94 \ 95 sbuf_printf(s, "interrupts %d, ", c->interrupts); \ 96 \ 97 if (c->direction == PCMDIR_REC) \ 98 sbuf_printf(s, \ 99 "overruns %d, feed %u, hfree %d, " \ 100 "sfree %d [b:%d/%d/%d|bs:%d/%d/%d]", \ 101 c->xruns, c->feedcount, \ 102 sndbuf_getfree(c->bufhard), \ 103 sndbuf_getfree(c->bufsoft), \ 104 sndbuf_getsize(c->bufhard), \ 105 sndbuf_getblksz(c->bufhard), \ 106 sndbuf_getblkcnt(c->bufhard), \ 107 sndbuf_getsize(c->bufsoft), \ 108 sndbuf_getblksz(c->bufsoft), \ 109 sndbuf_getblkcnt(c->bufsoft)); \ 110 else \ 111 sbuf_printf(s, \ 112 "underruns %d, feed %u, ready %d " \ 113 "[b:%d/%d/%d|bs:%d/%d/%d]", \ 114 c->xruns, c->feedcount, \ 115 sndbuf_getready(c->bufsoft), \ 116 sndbuf_getsize(c->bufhard), \ 117 sndbuf_getblksz(c->bufhard), \ 118 sndbuf_getblkcnt(c->bufhard), \ 119 sndbuf_getsize(c->bufsoft), \ 120 sndbuf_getblksz(c->bufsoft), \ 121 sndbuf_getblkcnt(c->bufsoft)); \ 122 sbuf_printf(s, "\n\t"); \ 123 \ 124 sbuf_printf(s, "channel flags=0x%b", c->flags, \ 125 CHN_F_BITS); \ 126 sbuf_printf(s, "\n\t"); \ 127 \ 128 sbuf_printf(s, "{%s}", \ 129 (c->direction == PCMDIR_REC) ? "hardware" : \ 130 "userland"); \ 131 sbuf_printf(s, " -> "); \ 132 f = c->feeder; \ 133 while (f->source != NULL) \ 134 f = f->source; \ 135 while (f != NULL) { \ 136 sbuf_printf(s, "%s", f->class->name); \ 137 if (f->desc->type == FEEDER_FORMAT) \ 138 sbuf_printf(s, "(0x%08x -> 0x%08x)", \ 139 f->desc->in, f->desc->out); \ 140 else if (f->desc->type == FEEDER_MATRIX) \ 141 sbuf_printf(s, "(%d.%d -> %d.%d)", \ 142 AFMT_CHANNEL(f->desc->in) - \ 143 AFMT_EXTCHANNEL(f->desc->in), \ 144 AFMT_EXTCHANNEL(f->desc->in), \ 145 AFMT_CHANNEL(f->desc->out) - \ 146 AFMT_EXTCHANNEL(f->desc->out), \ 147 AFMT_EXTCHANNEL(f->desc->out)); \ 148 else if (f->desc->type == FEEDER_RATE) \ 149 sbuf_printf(s, \ 150 "(0x%08x q:%d %d -> %d)", \ 151 f->desc->out, \ 152 FEEDER_GET(f, FEEDRATE_QUALITY), \ 153 FEEDER_GET(f, FEEDRATE_SRC), \ 154 FEEDER_GET(f, FEEDRATE_DST)); \ 155 else \ 156 sbuf_printf(s, "(0x%08x)", \ 157 f->desc->out); \ 158 sbuf_printf(s, " -> "); \ 159 f = f->parent; \ 160 } \ 161 sbuf_printf(s, "{%s}", \ 162 (c->direction == PCMDIR_REC) ? "userland" : \ 163 "hardware"); \ 164 } \ 165 \ 166 return (0); \ 167 } while (0) 168 169 #endif /* !_SND_SNDSTAT_H_ */ 170