Call selwakeup() from an MP-protected taskqueue.
[dragonfly.git] / sys / dev / sound / pcm / buffer.h
CommitLineData
558a398b
SS
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
984263bc
MD
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 *
4886ec58 26 * $FreeBSD: src/sys/dev/sound/pcm/buffer.h,v 1.10.2.2 2007/05/13 20:50:31 ariff Exp $
5a5410b8 27 * $DragonFly: src/sys/dev/sound/pcm/buffer.h,v 1.5 2008/01/05 13:34:22 corecode Exp $
984263bc
MD
28 */
29
558a398b 30#define SND_DMA(b) (sndbuf_getflags((b)) & SNDBUF_F_DMA)
984263bc
MD
31#define SNDBUF_LOCKASSERT(b)
32
558a398b 33#define SNDBUF_F_DMA 0x00000001
984263bc
MD
34#define SNDBUF_F_XRUN 0x00000002
35#define SNDBUF_F_RUNNING 0x00000004
4886ec58 36#define SNDBUF_F_MANAGED 0x00000008
984263bc 37
558a398b
SS
38#define SNDBUF_NAMELEN 48
39
40struct snd_dbuf {
41 device_t dev;
42 u_int8_t *buf, *tmpbuf;
43 unsigned int bufsize, maxsize;
44 volatile int dl; /* transfer size */
45 volatile int rp; /* pointers to the ready area */
46 volatile int rl; /* length of ready area */
47 volatile int hp;
48 volatile u_int32_t total, prev_total;
49 int dmachan, dir; /* dma channel */
50 u_int32_t fmt, spd, bps;
51 unsigned int blksz, blkcnt;
52 int xrun;
53 u_int32_t flags;
54 bus_dmamap_t dmamap;
55 bus_dma_tag_t dmatag;
4886ec58 56 bus_addr_t buf_addr;
558a398b 57 struct selinfo sel;
5a5410b8 58 struct task seltask;
558a398b
SS
59 struct pcm_channel *channel;
60 char name[SNDBUF_NAMELEN];
61};
62
63struct snd_dbuf *sndbuf_create(device_t dev, char *drv, char *desc, struct pcm_channel *channel);
984263bc
MD
64void sndbuf_destroy(struct snd_dbuf *b);
65
66void sndbuf_dump(struct snd_dbuf *b, char *s, u_int32_t what);
67
68int sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, unsigned int size);
69int sndbuf_setup(struct snd_dbuf *b, void *buf, unsigned int size);
70void sndbuf_free(struct snd_dbuf *b);
71int sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz);
72int sndbuf_remalloc(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz);
73void sndbuf_reset(struct snd_dbuf *b);
74void sndbuf_clear(struct snd_dbuf *b, unsigned int length);
75void sndbuf_fillsilence(struct snd_dbuf *b);
76
77u_int32_t sndbuf_getfmt(struct snd_dbuf *b);
78int sndbuf_setfmt(struct snd_dbuf *b, u_int32_t fmt);
79unsigned int sndbuf_getspd(struct snd_dbuf *b);
80void sndbuf_setspd(struct snd_dbuf *b, unsigned int spd);
81unsigned int sndbuf_getbps(struct snd_dbuf *b);
82
558a398b
SS
83bus_addr_t sndbuf_getbufaddr(struct snd_dbuf *buf);
84
984263bc
MD
85void *sndbuf_getbuf(struct snd_dbuf *b);
86void *sndbuf_getbufofs(struct snd_dbuf *b, unsigned int ofs);
87unsigned int sndbuf_getsize(struct snd_dbuf *b);
88unsigned int sndbuf_getmaxsize(struct snd_dbuf *b);
89unsigned int sndbuf_getalign(struct snd_dbuf *b);
90unsigned int sndbuf_getblkcnt(struct snd_dbuf *b);
91void sndbuf_setblkcnt(struct snd_dbuf *b, unsigned int blkcnt);
92unsigned int sndbuf_getblksz(struct snd_dbuf *b);
93void sndbuf_setblksz(struct snd_dbuf *b, unsigned int blksz);
94unsigned int sndbuf_runsz(struct snd_dbuf *b);
95void sndbuf_setrun(struct snd_dbuf *b, int go);
96struct selinfo *sndbuf_getsel(struct snd_dbuf *b);
97
98unsigned int sndbuf_getxrun(struct snd_dbuf *b);
99void sndbuf_setxrun(struct snd_dbuf *b, unsigned int cnt);
100unsigned int sndbuf_gethwptr(struct snd_dbuf *b);
101void sndbuf_sethwptr(struct snd_dbuf *b, unsigned int ptr);
102unsigned int sndbuf_getfree(struct snd_dbuf *b);
103unsigned int sndbuf_getfreeptr(struct snd_dbuf *b);
104unsigned int sndbuf_getready(struct snd_dbuf *b);
105unsigned int sndbuf_getreadyptr(struct snd_dbuf *b);
106unsigned int sndbuf_getblocks(struct snd_dbuf *b);
107unsigned int sndbuf_getprevblocks(struct snd_dbuf *b);
108unsigned int sndbuf_gettotal(struct snd_dbuf *b);
109void sndbuf_updateprevtotal(struct snd_dbuf *b);
110
111int sndbuf_acquire(struct snd_dbuf *b, u_int8_t *from, unsigned int count);
112int sndbuf_dispose(struct snd_dbuf *b, u_int8_t *to, unsigned int count);
984263bc
MD
113int sndbuf_feed(struct snd_dbuf *from, struct snd_dbuf *to, struct pcm_channel *channel, struct pcm_feeder *feeder, unsigned int count);
114
115u_int32_t sndbuf_getflags(struct snd_dbuf *b);
116void sndbuf_setflags(struct snd_dbuf *b, u_int32_t flags, int on);
117
558a398b
SS
118int sndbuf_dmasetup(struct snd_dbuf *b, struct resource *drq);
119int sndbuf_dmasetdir(struct snd_dbuf *b, int dir);
120void sndbuf_dma(struct snd_dbuf *b, int go);
121int sndbuf_dmaptr(struct snd_dbuf *b);
122void sndbuf_dmabounce(struct snd_dbuf *b);