buffer.c revision 125136
170291Scg/*
2119853Scg * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
370291Scg * All rights reserved.
470291Scg *
570291Scg * Redistribution and use in source and binary forms, with or without
670291Scg * modification, are permitted provided that the following conditions
770291Scg * are met:
870291Scg * 1. Redistributions of source code must retain the above copyright
970291Scg *    notice, this list of conditions and the following disclaimer.
1070291Scg * 2. Redistributions in binary form must reproduce the above copyright
1170291Scg *    notice, this list of conditions and the following disclaimer in the
1270291Scg *    documentation and/or other materials provided with the distribution.
1370291Scg *
1470291Scg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1570291Scg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1670291Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1770291Scg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1870291Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1970291Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2070291Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2170291Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2270291Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2370291Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2470291Scg * SUCH DAMAGE.
2570291Scg */
2670291Scg
2770291Scg#include <dev/sound/pcm/sound.h>
2870291Scg
2974763Scg#include "feeder_if.h"
3074763Scg
3182180ScgSND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/buffer.c 125136 2004-01-28 08:02:15Z truckman $");
3282180Scg
3374763Scgstruct snd_dbuf *
34125136Struckmansndbuf_create(device_t dev, char *drv, char *desc, struct pcm_channel *channel)
3574763Scg{
3674763Scg	struct snd_dbuf *b;
3774763Scg
38111119Simp	b = malloc(sizeof(*b), M_DEVBUF, M_WAITOK | M_ZERO);
3974763Scg	snprintf(b->name, SNDBUF_NAMELEN, "%s:%s", drv, desc);
4089834Scg	b->dev = dev;
41125136Struckman	b->channel = channel;
4289834Scg
4374763Scg	return b;
4474763Scg}
4574763Scg
4674763Scgvoid
4774763Scgsndbuf_destroy(struct snd_dbuf *b)
4874763Scg{
4974763Scg	free(b, M_DEVBUF);
5074763Scg}
5174763Scg
52111183Scognetbus_addr_t
53111183Scognetsndbuf_getbufaddr(struct snd_dbuf *buf)
54111183Scognet{
55111183Scognet	return (buf->buf_addr);
56111183Scognet}
57111183Scognet
5870291Scgstatic void
5970291Scgsndbuf_setmap(void *arg, bus_dma_segment_t *segs, int nseg, int error)
6070291Scg{
6174763Scg	struct snd_dbuf *b = (struct snd_dbuf *)arg;
6270291Scg
6370291Scg	if (bootverbose) {
6489834Scg		device_printf(b->dev, "sndbuf_setmap %lx, %lx; ", (unsigned long)segs->ds_addr,
6570291Scg		       (unsigned long)segs->ds_len);
6670291Scg		printf("%p -> %lx\n", b->buf, (unsigned long)vtophys(b->buf));
6770291Scg	}
68111183Scognet	b->buf_addr = segs->ds_addr;
6970291Scg}
7070291Scg
7170291Scg/*
7274763Scg * Allocate memory for DMA buffer. If the device does not use DMA transfers,
7374763Scg * the driver can call malloc(9) and sndbuf_setup() itself.
7470291Scg */
75111183Scognet
7670291Scgint
7774763Scgsndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, unsigned int size)
7870291Scg{
7970291Scg	b->dmatag = dmatag;
8070291Scg	b->maxsize = size;
8170291Scg	b->bufsize = b->maxsize;
8270291Scg	if (bus_dmamem_alloc(b->dmatag, (void **)&b->buf, BUS_DMA_NOWAIT, &b->dmamap))
8370291Scg		return ENOSPC;
8470291Scg	if (bus_dmamap_load(b->dmatag, b->dmamap, b->buf, b->maxsize, sndbuf_setmap, b, 0))
8570291Scg		return ENOSPC;
8670291Scg	return sndbuf_resize(b, 2, b->maxsize / 2);
8770291Scg}
8870291Scg
8970291Scgint
9074763Scgsndbuf_setup(struct snd_dbuf *b, void *buf, unsigned int size)
9170291Scg{
9270291Scg	b->buf = buf;
9370291Scg	b->maxsize = size;
9470291Scg	b->bufsize = b->maxsize;
9570291Scg	return sndbuf_resize(b, 2, b->maxsize / 2);
9670291Scg}
9770291Scg
9870291Scgvoid
9974763Scgsndbuf_free(struct snd_dbuf *b)
10070291Scg{
10174763Scg	if (b->tmpbuf)
10274763Scg		free(b->tmpbuf, M_DEVBUF);
10374763Scg	b->tmpbuf = NULL;
10474763Scg
10574763Scg	if (b->dmamap)
10674797Scg		bus_dmamap_unload(b->dmatag, b->dmamap);
10774763Scg
10874763Scg	if (b->dmamap && b->buf)
10974797Scg		bus_dmamem_free(b->dmatag, b->buf, b->dmamap);
11077265Scg	b->dmamap = NULL;
11177265Scg	b->buf = NULL;
11270291Scg}
11370291Scg
11470291Scgint
11574763Scgsndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
11670291Scg{
117125136Struckman	u_int8_t *tmpbuf, *f2;
118125136Struckman
119125136Struckman	chn_lock(b->channel);
12074763Scg	if (b->maxsize == 0)
121125136Struckman		goto out;
12270291Scg	if (blkcnt == 0)
12370291Scg		blkcnt = b->blkcnt;
12470291Scg	if (blksz == 0)
12570291Scg		blksz = b->blksz;
126125136Struckman	if (blkcnt < 2 || blksz < 16 || (blkcnt * blksz > b->maxsize)) {
127125136Struckman		chn_unlock(b->channel);
12870291Scg		return EINVAL;
129125136Struckman	}
13089834Scg	if (blkcnt == b->blkcnt && blksz == b->blksz)
131125136Struckman		goto out;
132125136Struckman
133125136Struckman	chn_unlock(b->channel);
134125136Struckman	tmpbuf = malloc(blkcnt * blksz, M_DEVBUF, M_WAITOK);
135125136Struckman	if (tmpbuf == NULL)
136125136Struckman		return ENOMEM;
137125136Struckman	chn_lock(b->channel);
13870291Scg	b->blkcnt = blkcnt;
13970291Scg	b->blksz = blksz;
14070291Scg	b->bufsize = blkcnt * blksz;
141125136Struckman	f2 =  b->tmpbuf;
142113752Sorion	b->tmpbuf = tmpbuf;
14370291Scg	sndbuf_reset(b);
144125136Struckman	chn_unlock(b->channel);
145125136Struckman	free(f2, M_DEVBUF);
14670291Scg	return 0;
147125136Struckmanout:
148125136Struckman	chn_unlock(b->channel);
149125136Struckman	return 0;
15070291Scg}
15170291Scg
15274763Scgint
15374763Scgsndbuf_remalloc(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
15474763Scg{
155107237Scg        u_int8_t *buf, *tmpbuf, *f1, *f2;
156107237Scg        unsigned int bufsize;
157125136Struckman	int ret;
158107237Scg
15974763Scg	if (blkcnt < 2 || blksz < 16)
16074763Scg		return EINVAL;
16174763Scg
162107237Scg	bufsize = blksz * blkcnt;
16374763Scg
164125136Struckman	chn_unlock(b->channel);
165125136Struckman	buf = malloc(bufsize, M_DEVBUF, M_WAITOK);
166125136Struckman	if (buf == NULL) {
167125136Struckman		ret = ENOMEM;
168125136Struckman		goto out;
169125136Struckman	}
17074763Scg
171125136Struckman	tmpbuf = malloc(bufsize, M_DEVBUF, M_WAITOK);
172107237Scg   	if (tmpbuf == NULL) {
173107237Scg		free(buf, M_DEVBUF);
174125136Struckman		ret = ENOMEM;
175125136Struckman		goto out;
176107237Scg	}
177125136Struckman	chn_lock(b->channel);
17874763Scg
179107237Scg	b->blkcnt = blkcnt;
180107237Scg	b->blksz = blksz;
181107237Scg	b->bufsize = bufsize;
182107237Scg	b->maxsize = bufsize;
183107237Scg	f1 = b->buf;
184107237Scg	f2 = b->tmpbuf;
185107237Scg	b->buf = buf;
186107237Scg	b->tmpbuf = tmpbuf;
187107237Scg
188125136Struckman	sndbuf_reset(b);
189125136Struckman
190125136Struckman	chn_unlock(b->channel);
191107237Scg      	if (f1)
192107237Scg		free(f1, M_DEVBUF);
193107237Scg      	if (f2)
194107237Scg		free(f2, M_DEVBUF);
195107237Scg
196125136Struckman	ret = 0;
197125136Struckmanout:
198125136Struckman	chn_lock(b->channel);
199125136Struckman	return ret;
20074763Scg}
20174763Scg
20270291Scgvoid
20374763Scgsndbuf_clear(struct snd_dbuf *b, unsigned int length)
20470291Scg{
20570291Scg	int i;
20673768Scg	u_char data, *p;
20770291Scg
20870291Scg	if (length == 0)
20970291Scg		return;
21073768Scg	if (length > b->bufsize)
21173768Scg		length = b->bufsize;
21270291Scg
21370291Scg	if (b->fmt & AFMT_SIGNED)
21470291Scg		data = 0x00;
21570291Scg	else
21670291Scg		data = 0x80;
21770291Scg
21874763Scg	i = sndbuf_getfreeptr(b);
21974763Scg	p = sndbuf_getbuf(b);
22073768Scg	while (length > 0) {
22173768Scg		p[i] = data;
22273768Scg		length--;
22373768Scg		i++;
22473768Scg		if (i >= b->bufsize)
22570291Scg			i = 0;
22670291Scg	}
22770291Scg}
22870291Scg
22970291Scgvoid
23077265Scgsndbuf_fillsilence(struct snd_dbuf *b)
23177265Scg{
23277265Scg	int i;
23377265Scg	u_char data, *p;
23477265Scg
23577265Scg	if (b->fmt & AFMT_SIGNED)
23677265Scg		data = 0x00;
23777265Scg	else
23877265Scg		data = 0x80;
23977265Scg
24077265Scg	i = 0;
24177265Scg	p = sndbuf_getbuf(b);
24277265Scg	while (i < b->bufsize)
24377265Scg		p[i++] = data;
24477265Scg	b->rp = 0;
24577265Scg	b->rl = b->bufsize;
24677265Scg}
24777265Scg
24877265Scgvoid
24974763Scgsndbuf_reset(struct snd_dbuf *b)
25070291Scg{
25174763Scg	b->hp = 0;
25274763Scg	b->rp = 0;
25374763Scg	b->rl = 0;
25474763Scg	b->dl = 0;
25574763Scg	b->prev_total = 0;
25674763Scg	b->total = 0;
25774763Scg	b->xrun = 0;
25870291Scg	if (b->buf && b->bufsize > 0)
25970291Scg		sndbuf_clear(b, b->bufsize);
26070291Scg}
26170291Scg
26274763Scgu_int32_t
26374763Scgsndbuf_getfmt(struct snd_dbuf *b)
26474763Scg{
26574763Scg	return b->fmt;
26674763Scg}
26774763Scg
26870291Scgint
26974763Scgsndbuf_setfmt(struct snd_dbuf *b, u_int32_t fmt)
27070291Scg{
27170291Scg	b->fmt = fmt;
27270291Scg	b->bps = 1;
27370291Scg	b->bps <<= (b->fmt & AFMT_STEREO)? 1 : 0;
27470291Scg	b->bps <<= (b->fmt & AFMT_16BIT)? 1 : 0;
27570291Scg	b->bps <<= (b->fmt & AFMT_32BIT)? 2 : 0;
27670291Scg	return 0;
27770291Scg}
27870291Scg
27974763Scgunsigned int
28074763Scgsndbuf_getspd(struct snd_dbuf *b)
28170291Scg{
28274763Scg	return b->spd;
28374763Scg}
28474763Scg
28574763Scgvoid
28674763Scgsndbuf_setspd(struct snd_dbuf *b, unsigned int spd)
28774763Scg{
28874763Scg	b->spd = spd;
28974763Scg}
29074763Scg
29174763Scgunsigned int
29274763Scgsndbuf_getalign(struct snd_dbuf *b)
29374763Scg{
29474763Scg	static int align[] = {0, 1, 1, 2, 2, 2, 2, 3};
29574763Scg
29674763Scg	return align[b->bps - 1];
29774763Scg}
29874763Scg
29974763Scgunsigned int
30074763Scgsndbuf_getblkcnt(struct snd_dbuf *b)
30174763Scg{
30274763Scg	return b->blkcnt;
30374763Scg}
30474763Scg
30574763Scgvoid
30674763Scgsndbuf_setblkcnt(struct snd_dbuf *b, unsigned int blkcnt)
30774763Scg{
30874763Scg	b->blkcnt = blkcnt;
30974763Scg}
31074763Scg
31174763Scgunsigned int
31274763Scgsndbuf_getblksz(struct snd_dbuf *b)
31374763Scg{
31474763Scg	return b->blksz;
31574763Scg}
31674763Scg
31774763Scgvoid
31874763Scgsndbuf_setblksz(struct snd_dbuf *b, unsigned int blksz)
31974763Scg{
32074763Scg	b->blksz = blksz;
32174763Scg}
32274763Scg
32374763Scgunsigned int
32474763Scgsndbuf_getbps(struct snd_dbuf *b)
32574763Scg{
32670291Scg	return b->bps;
32770291Scg}
32870291Scg
32970291Scgvoid *
33074763Scgsndbuf_getbuf(struct snd_dbuf *b)
33170291Scg{
33270291Scg	return b->buf;
33370291Scg}
33470291Scg
33574763Scgvoid *
33674763Scgsndbuf_getbufofs(struct snd_dbuf *b, unsigned int ofs)
33770291Scg{
33889771Scg	KASSERT(ofs < b->bufsize, ("%s: ofs invalid %d", __func__, ofs));
33974763Scg
34074763Scg	return b->buf + ofs;
34174763Scg}
34274763Scg
34374763Scgunsigned int
34474763Scgsndbuf_getsize(struct snd_dbuf *b)
34574763Scg{
34670291Scg	return b->bufsize;
34770291Scg}
34870291Scg
34974763Scgunsigned int
35074763Scgsndbuf_getmaxsize(struct snd_dbuf *b)
35170291Scg{
35274763Scg	return b->maxsize;
35374763Scg}
35474763Scg
35574763Scgunsigned int
35674763Scgsndbuf_runsz(struct snd_dbuf *b)
35774763Scg{
35870291Scg	return b->dl;
35970291Scg}
36070291Scg
36174763Scgvoid
36274763Scgsndbuf_setrun(struct snd_dbuf *b, int go)
36374763Scg{
36474763Scg	b->dl = go? b->blksz : 0;
36574763Scg}
36674763Scg
36774763Scgstruct selinfo *
36874763Scgsndbuf_getsel(struct snd_dbuf *b)
36974763Scg{
37074763Scg	return &b->sel;
37174763Scg}
37274763Scg
37374763Scg/************************************************************/
37474763Scgunsigned int
37574763Scgsndbuf_getxrun(struct snd_dbuf *b)
37674763Scg{
37774763Scg	SNDBUF_LOCKASSERT(b);
37874763Scg
37974763Scg	return b->xrun;
38074763Scg}
38174763Scg
38274763Scgvoid
38374763Scgsndbuf_setxrun(struct snd_dbuf *b, unsigned int cnt)
38474763Scg{
38574763Scg	SNDBUF_LOCKASSERT(b);
38674763Scg
38774763Scg	b->xrun = cnt;
38874763Scg}
38974763Scg
39074763Scgunsigned int
39174763Scgsndbuf_gethwptr(struct snd_dbuf *b)
39274763Scg{
39374763Scg	SNDBUF_LOCKASSERT(b);
39474763Scg
39574763Scg	return b->hp;
39674763Scg}
39774763Scg
39874763Scgvoid
39974763Scgsndbuf_sethwptr(struct snd_dbuf *b, unsigned int ptr)
40074763Scg{
40174763Scg	SNDBUF_LOCKASSERT(b);
40274763Scg
40374763Scg	b->hp = ptr;
40474763Scg}
40574763Scg
40674763Scgunsigned int
40774763Scgsndbuf_getready(struct snd_dbuf *b)
40874763Scg{
40974763Scg	SNDBUF_LOCKASSERT(b);
41087599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
41174763Scg
41274763Scg	return b->rl;
41374763Scg}
41474763Scg
41574763Scgunsigned int
41674763Scgsndbuf_getreadyptr(struct snd_dbuf *b)
41774763Scg{
41874763Scg	SNDBUF_LOCKASSERT(b);
41987599Sobrien	KASSERT((b->rp >= 0) && (b->rp <= b->bufsize), ("%s: b->rp invalid %d", __func__, b->rp));
42074763Scg
42174763Scg	return b->rp;
42274763Scg}
42374763Scg
42474763Scgunsigned int
42574763Scgsndbuf_getfree(struct snd_dbuf *b)
42674763Scg{
42774763Scg	SNDBUF_LOCKASSERT(b);
42887599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
42974763Scg
43074763Scg	return b->bufsize - b->rl;
43174763Scg}
43274763Scg
43374763Scgunsigned int
43474763Scgsndbuf_getfreeptr(struct snd_dbuf *b)
43574763Scg{
43674763Scg	SNDBUF_LOCKASSERT(b);
43787599Sobrien	KASSERT((b->rp >= 0) && (b->rp <= b->bufsize), ("%s: b->rp invalid %d", __func__, b->rp));
43887599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
43974763Scg
44074763Scg	return (b->rp + b->rl) % b->bufsize;
44174763Scg}
44274763Scg
44374763Scgunsigned int
44474763Scgsndbuf_getblocks(struct snd_dbuf *b)
44574763Scg{
44674763Scg	SNDBUF_LOCKASSERT(b);
44774763Scg
44874763Scg	return b->total / b->blksz;
44974763Scg}
45074763Scg
45174763Scgunsigned int
45274763Scgsndbuf_getprevblocks(struct snd_dbuf *b)
45374763Scg{
45474763Scg	SNDBUF_LOCKASSERT(b);
45574763Scg
45674763Scg	return b->prev_total / b->blksz;
45774763Scg}
45874763Scg
45974763Scgunsigned int
46074763Scgsndbuf_gettotal(struct snd_dbuf *b)
46174763Scg{
46274763Scg	SNDBUF_LOCKASSERT(b);
46374763Scg
46474763Scg	return b->total;
46574763Scg}
46674763Scg
46774763Scgvoid
46874763Scgsndbuf_updateprevtotal(struct snd_dbuf *b)
46974763Scg{
47074763Scg	SNDBUF_LOCKASSERT(b);
47174763Scg
47274763Scg	b->prev_total = b->total;
47374763Scg}
47474763Scg
47574763Scg/************************************************************/
47674763Scg
47770291Scgint
47874763Scgsndbuf_acquire(struct snd_dbuf *b, u_int8_t *from, unsigned int count)
47970291Scg{
48074763Scg	int l;
48174763Scg
48287599Sobrien	KASSERT(count <= sndbuf_getfree(b), ("%s: count %d > free %d", __func__, count, sndbuf_getfree(b)));
48387599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
48474763Scg	b->total += count;
48574763Scg	if (from != NULL) {
48674763Scg		while (count > 0) {
48774763Scg			l = MIN(count, sndbuf_getsize(b) - sndbuf_getfreeptr(b));
48874763Scg			bcopy(from, sndbuf_getbufofs(b, sndbuf_getfreeptr(b)), l);
48974763Scg			from += l;
49074763Scg			b->rl += l;
49174763Scg			count -= l;
49274763Scg		}
49374763Scg	} else
49474763Scg		b->rl += count;
49587599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d, count %d", __func__, b->rl, count));
49674763Scg
49774763Scg	return 0;
49874763Scg}
49974763Scg
50074763Scgint
50174763Scgsndbuf_dispose(struct snd_dbuf *b, u_int8_t *to, unsigned int count)
50274763Scg{
50374763Scg	int l;
50474763Scg
50587599Sobrien	KASSERT(count <= sndbuf_getready(b), ("%s: count %d > ready %d", __func__, count, sndbuf_getready(b)));
50687599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d", __func__, b->rl));
50774763Scg	if (to != NULL) {
50874763Scg		while (count > 0) {
50974763Scg			l = MIN(count, sndbuf_getsize(b) - sndbuf_getreadyptr(b));
51074763Scg			bcopy(sndbuf_getbufofs(b, sndbuf_getreadyptr(b)), to, l);
51174763Scg			to += l;
51274763Scg			b->rl -= l;
51374763Scg			b->rp = (b->rp + l) % b->bufsize;
51474763Scg			count -= l;
51574763Scg		}
51674763Scg	} else {
51774763Scg		b->rl -= count;
51874763Scg		b->rp = (b->rp + count) % b->bufsize;
51974763Scg	}
52087599Sobrien	KASSERT((b->rl >= 0) && (b->rl <= b->bufsize), ("%s: b->rl invalid %d, count %d", __func__, b->rl, count));
52174763Scg
52274763Scg	return 0;
52374763Scg}
52474763Scg
52574763Scg/* count is number of bytes we want added to destination buffer */
52674763Scgint
52774763Scgsndbuf_feed(struct snd_dbuf *from, struct snd_dbuf *to, struct pcm_channel *channel, struct pcm_feeder *feeder, unsigned int count)
52874763Scg{
52977265Scg	KASSERT(count > 0, ("can't feed 0 bytes"));
53077265Scg
53174763Scg	if (sndbuf_getfree(to) < count)
53274763Scg		return EINVAL;
53374763Scg
53474763Scg	count = FEEDER_FEED(feeder, channel, to->tmpbuf, count, from);
53575317Scg	if (count)
53675317Scg		sndbuf_acquire(to, to->tmpbuf, count);
53774763Scg	/* the root feeder has called sndbuf_dispose(from, , bytes fetched) */
53874763Scg
53974763Scg	return 0;
54074763Scg}
54174763Scg
54274763Scg/************************************************************/
54374763Scg
54474763Scgvoid
54574763Scgsndbuf_dump(struct snd_dbuf *b, char *s, u_int32_t what)
54674763Scg{
54774763Scg	printf("%s: [", s);
54874763Scg	if (what & 0x01)
54974763Scg		printf(" bufsize: %d, maxsize: %d", b->bufsize, b->maxsize);
55074763Scg	if (what & 0x02)
55174763Scg		printf(" dl: %d, rp: %d, rl: %d, hp: %d", b->dl, b->rp, b->rl, b->hp);
55274763Scg	if (what & 0x04)
55374763Scg		printf(" total: %d, prev_total: %d, xrun: %d", b->total, b->prev_total, b->xrun);
55474763Scg   	if (what & 0x08)
55574763Scg		printf(" fmt: 0x%x, spd: %d", b->fmt, b->spd);
55674763Scg	if (what & 0x10)
55774763Scg		printf(" blksz: %d, blkcnt: %d, flags: 0x%x", b->blksz, b->blkcnt, b->flags);
55874763Scg	printf(" ]\n");
55974763Scg}
56074763Scg
56174763Scg/************************************************************/
56274763Scgu_int32_t
56374763Scgsndbuf_getflags(struct snd_dbuf *b)
56474763Scg{
56574763Scg	return b->flags;
56674763Scg}
56774763Scg
56874763Scgvoid
56974763Scgsndbuf_setflags(struct snd_dbuf *b, u_int32_t flags, int on)
57074763Scg{
57174763Scg	b->flags &= ~flags;
57274763Scg	if (on)
57374763Scg		b->flags |= flags;
57474763Scg}
57574763Scg
576