xref: /freebsd/sys/dev/sound/pcm/channel.h (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
1 /*
2  * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
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  *
26  * $FreeBSD$
27  */
28 
29 int chn_reinit(pcm_channel *c);
30 int chn_write(pcm_channel *c, struct uio *buf);
31 int chn_read(pcm_channel *c, struct uio *buf);
32 u_int32_t chn_start(pcm_channel *c, int force);
33 int chn_sync(pcm_channel *c, int threshold);
34 int chn_flush(pcm_channel *c);
35 int chn_poll(pcm_channel *c, int ev, struct proc *p);
36 
37 int chn_init(pcm_channel *c, void *devinfo, int dir);
38 int chn_kill(pcm_channel *c);
39 int chn_setdir(pcm_channel *c, int dir);
40 int chn_reset(pcm_channel *c, u_int32_t fmt);
41 int chn_setvolume(pcm_channel *c, int left, int right);
42 int chn_setspeed(pcm_channel *c, int speed);
43 int chn_setformat(pcm_channel *c, u_int32_t fmt);
44 int chn_setblocksize(pcm_channel *c, int blkcnt, int blksz);
45 int chn_trigger(pcm_channel *c, int go);
46 int chn_getptr(pcm_channel *c);
47 pcmchan_caps *chn_getcaps(pcm_channel *c);
48 u_int32_t chn_getformats(pcm_channel *c);
49 
50 int chn_allocbuf(snd_dbuf *b, bus_dma_tag_t parent_dmat);
51 void chn_freebuf(snd_dbuf *b);
52 void chn_resetbuf(pcm_channel *c);
53 void chn_intr(pcm_channel *c);
54 void chn_checkunderflow(pcm_channel *c);
55 int chn_wrfeed(pcm_channel *c);
56 int chn_rdfeed(pcm_channel *c);
57 int chn_abort(pcm_channel *c);
58 
59 int fmtvalid(u_int32_t fmt, u_int32_t *fmtlist);
60 
61 void buf_isadma(snd_dbuf *b, int go);
62 int buf_isadmaptr(snd_dbuf *b);
63 
64 #define PCMDIR_PLAY 1
65 #define PCMDIR_REC -1
66 
67 #define PCMTRIG_START 1
68 #define PCMTRIG_EMLDMAWR 2
69 #define PCMTRIG_EMLDMARD 3
70 #define PCMTRIG_STOP 0
71 #define PCMTRIG_ABORT -1
72 
73 #define CHN_F_READING           0x00000001  /* have a pending read */
74 #define CHN_F_WRITING           0x00000002  /* have a pending write */
75 #define CHN_F_CLOSING           0x00000004  /* a pending close */
76 #define CHN_F_ABORTING          0x00000008  /* a pending abort */
77 #define	CHN_F_PENDING_IO	(CHN_F_READING | CHN_F_WRITING)
78 #define CHN_F_RUNNING		0x00000010  /* dma is running */
79 #define CHN_F_TRIGGERED		0x00000020
80 #define CHN_F_NOTRIGGER		0x00000040
81 
82 #define CHN_F_BUSY              0x00001000  /* has been opened 	*/
83 #define	CHN_F_HAS_SIZE		0x00002000  /* user set block size */
84 #define CHN_F_NBIO              0x00004000  /* do non-blocking i/o */
85 #define CHN_F_INIT              0x00008000  /* changed parameters. need init */
86 #define CHN_F_MAPPED		0x00010000  /* has been mmap()ed */
87 #define CHN_F_DEAD		0x00020000
88 
89 
90 #define CHN_F_RESET		(CHN_F_BUSY | CHN_F_DEAD)
91 
92 /*
93  * This should be large enough to hold all pcm data between
94  * tsleeps in chn_{read,write} at the highest sample rate.
95  * (which is usually 48kHz * 16bit * stereo = 192000 bytes/sec)
96  */
97 #define CHN_2NDBUFBLKSIZE	(2 * 1024)
98 /* The total number of blocks per secondary buffer. */
99 #define CHN_2NDBUFBLKNUM	(32)
100 /* The size of a whole secondary buffer. */
101 #define CHN_2NDBUFMAXSIZE	(131072)
102