kernel/sound: Add PCMTRIG_COMMON (from FreeBSD).
[dragonfly.git] / sys / dev / sound / pcm / channel.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 *
558a398b 26 * $FreeBSD: src/sys/dev/sound/pcm/channel.h,v 1.31.2.1 2005/12/30 19:55:54 netchild Exp $
cad195a6 27 * $DragonFly: src/sys/dev/sound/pcm/channel.h,v 1.6 2007/06/16 20:07:22 dillon Exp $
984263bc
MD
28 */
29
30struct pcmchan_children {
31 SLIST_ENTRY(pcmchan_children) link;
32 struct pcm_channel *channel;
33};
34
35struct pcmchan_caps {
36 u_int32_t minspeed, maxspeed;
37 u_int32_t *fmtlist;
38 u_int32_t caps;
39};
40
41#define CHN_NAMELEN 32
42struct pcm_channel {
43 kobj_t methods;
44
45 int num;
46 pid_t pid;
47 int refcount;
48 struct pcm_feeder *feeder;
49 u_int32_t align;
50
51 int volume;
52 u_int32_t speed;
53 u_int32_t format;
54 u_int32_t flags;
55 u_int32_t feederflags;
56 u_int32_t blocks;
57
58 int direction;
59 unsigned int interrupts, xruns;
60 struct snd_dbuf *bufhard, *bufsoft;
61 struct snddev_info *parentsnddev;
62 struct pcm_channel *parentchannel;
63 void *devinfo;
64 device_t dev;
65 char name[CHN_NAMELEN];
cad195a6 66 sndlock_t lock;
984263bc
MD
67 SLIST_HEAD(, pcmchan_children) children;
68};
69
70#include "channel_if.h"
71
72int chn_reinit(struct pcm_channel *c);
9ba76b73
MD
73int chn_write(struct pcm_channel *c, struct uio *buf, int ioflags);
74int chn_read(struct pcm_channel *c, struct uio *buf, int ioflags);
984263bc
MD
75u_int32_t chn_start(struct pcm_channel *c, int force);
76int chn_sync(struct pcm_channel *c, int threshold);
77int chn_flush(struct pcm_channel *c);
558a398b 78int chn_poll(struct pcm_channel *c, int ev, struct thread *td);
984263bc 79
558a398b 80int chn_init(struct pcm_channel *c, void *devinfo, int dir, int direction);
984263bc
MD
81int chn_kill(struct pcm_channel *c);
82int chn_setdir(struct pcm_channel *c, int dir);
83int chn_reset(struct pcm_channel *c, u_int32_t fmt);
84int chn_setvolume(struct pcm_channel *c, int left, int right);
85int chn_setspeed(struct pcm_channel *c, int speed);
86int chn_setformat(struct pcm_channel *c, u_int32_t fmt);
87int chn_setblocksize(struct pcm_channel *c, int blkcnt, int blksz);
88int chn_trigger(struct pcm_channel *c, int go);
89int chn_getptr(struct pcm_channel *c);
90struct pcmchan_caps *chn_getcaps(struct pcm_channel *c);
91u_int32_t chn_getformats(struct pcm_channel *c);
92
93void chn_resetbuf(struct pcm_channel *c);
94void chn_intr(struct pcm_channel *c);
95int chn_wrfeed(struct pcm_channel *c);
96int chn_rdfeed(struct pcm_channel *c);
97int chn_abort(struct pcm_channel *c);
98
99void chn_wrupdate(struct pcm_channel *c);
100void chn_rdupdate(struct pcm_channel *c);
101
102int chn_notify(struct pcm_channel *c, u_int32_t flags);
558a398b
SS
103void chn_lock(struct pcm_channel *c);
104void chn_unlock(struct pcm_channel *c);
984263bc
MD
105
106#ifdef USING_MUTEX
cad195a6
MD
107#define CHN_LOCK(c) snd_mtxlock(((c)->lock))
108#define CHN_UNLOCK(c) snd_mtxunlock(((c)->lock))
984263bc
MD
109#define CHN_LOCKASSERT(c)
110#else
111#define CHN_LOCK(c)
112#define CHN_UNLOCK(c)
113#define CHN_LOCKASSERT(c)
114#endif
115
116int fmtvalid(u_int32_t fmt, u_int32_t *fmtlist);
117
118#define PCMDIR_VIRTUAL 2
119#define PCMDIR_PLAY 1
120#define PCMDIR_REC -1
121
122#define PCMTRIG_START 1
123#define PCMTRIG_EMLDMAWR 2
124#define PCMTRIG_EMLDMARD 3
125#define PCMTRIG_STOP 0
126#define PCMTRIG_ABORT -1
127
d3474664
SW
128#define PCMTRIG_COMMON(x) ((x) == PCMTRIG_START || \
129 (x) == PCMTRIG_STOP || \
130 (x) == PCMTRIG_ABORT)
131
984263bc
MD
132#define CHN_F_CLOSING 0x00000004 /* a pending close */
133#define CHN_F_ABORTING 0x00000008 /* a pending abort */
134#define CHN_F_RUNNING 0x00000010 /* dma is running */
135#define CHN_F_TRIGGERED 0x00000020
136#define CHN_F_NOTRIGGER 0x00000040
137
138#define CHN_F_BUSY 0x00001000 /* has been opened */
139#define CHN_F_HAS_SIZE 0x00002000 /* user set block size */
140#define CHN_F_NBIO 0x00004000 /* do non-blocking i/o */
141#define CHN_F_MAPPED 0x00010000 /* has been mmap()ed */
142#define CHN_F_DEAD 0x00020000
143#define CHN_F_BADSETTING 0x00040000
558a398b
SS
144#define CHN_F_SETBLOCKSIZE 0x00080000
145#define CHN_F_HAS_VCHAN 0x00100000
984263bc
MD
146
147#define CHN_F_VIRTUAL 0x10000000 /* not backed by hardware */
148
558a398b
SS
149#define CHN_F_RESET (CHN_F_BUSY | CHN_F_DEAD | \
150 CHN_F_HAS_VCHAN | CHN_F_VIRTUAL)
151
984263bc
MD
152
153#define CHN_N_RATE 0x00000001
154#define CHN_N_FORMAT 0x00000002
155#define CHN_N_VOLUME 0x00000004
156#define CHN_N_BLOCKSIZE 0x00000008
157#define CHN_N_TRIGGER 0x00000010
158
159/*
160 * This should be large enough to hold all pcm data between
161 * tsleeps in chn_{read,write} at the highest sample rate.
162 * (which is usually 48kHz * 16bit * stereo = 192000 bytes/sec)
163 */
164#define CHN_2NDBUFBLKSIZE (2 * 1024)
165/* The total number of blocks per secondary bufhard. */
166#define CHN_2NDBUFBLKNUM (32)
167/* The size of a whole secondary bufhard. */
168#define CHN_2NDBUFMAXSIZE (131072)
169
170#define CHANNEL_DECLARE(name) static DEFINE_CLASS(name, name ## _methods, sizeof(struct kobj))