Deleted Added
full compact
dsp.c (167647) dsp.c (170161)
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
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

--- 10 unchanged lines hidden (view full) ---

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
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
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

--- 10 unchanged lines hidden (view full) ---

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
27#include <sys/param.h>
28#include <sys/queue.h>
29
30#include <dev/sound/pcm/sound.h>
27#include <dev/sound/pcm/sound.h>
28#include <sys/ctype.h>
31
29
32SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/dsp.c 167647 2007-03-16 17:17:25Z ariff $");
30SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/dsp.c 170161 2007-05-31 18:43:33Z ariff $");
33
31
32struct dsp_cdevinfo {
33 struct pcm_channel *rdch, *wrch;
34};
35
36#define PCM_RDCH(x) (((struct dsp_cdevinfo *)(x)->si_drv1)->rdch)
37#define PCM_WRCH(x) (((struct dsp_cdevinfo *)(x)->si_drv1)->wrch)
38
39#define PCMDEV_ACQUIRE(x) do { \
40 if ((x)->si_drv1 == NULL) \
41 (x)->si_drv1 = x; \
42} while(0)
43
44#define PCMDEV_RELEASE(x) do { \
45 if ((x)->si_drv1 == x) \
46 (x)->si_drv1 = NULL; \
47} while(0)
48
34#define OLDPCM_IOCTL
35
36static d_open_t dsp_open;
37static d_close_t dsp_close;
38static d_read_t dsp_read;
39static d_write_t dsp_write;
40static d_ioctl_t dsp_ioctl;
41static d_poll_t dsp_poll;

--- 8 unchanged lines hidden (view full) ---

50 .d_write = dsp_write,
51 .d_ioctl = dsp_ioctl,
52 .d_poll = dsp_poll,
53 .d_mmap = dsp_mmap,
54 .d_name = "dsp",
55};
56
57#ifdef USING_DEVFS
49#define OLDPCM_IOCTL
50
51static d_open_t dsp_open;
52static d_close_t dsp_close;
53static d_read_t dsp_read;
54static d_write_t dsp_write;
55static d_ioctl_t dsp_ioctl;
56static d_poll_t dsp_poll;

--- 8 unchanged lines hidden (view full) ---

65 .d_write = dsp_write,
66 .d_ioctl = dsp_ioctl,
67 .d_poll = dsp_poll,
68 .d_mmap = dsp_mmap,
69 .d_name = "dsp",
70};
71
72#ifdef USING_DEVFS
58static eventhandler_tag dsp_ehtag;
73static eventhandler_tag dsp_ehtag = NULL;
74static int dsp_umax = -1;
75static int dsp_cmax = -1;
59#endif
60
61static int dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgroup *group);
62static int dsp_oss_syncstart(int sg_id);
63static int dsp_oss_policy(struct pcm_channel *wrch, struct pcm_channel *rdch, int policy);
64#ifdef OSSV4_EXPERIMENT
65static int dsp_oss_cookedmode(struct pcm_channel *wrch, struct pcm_channel *rdch, int enabled);
66static int dsp_oss_getchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map);
67static int dsp_oss_setchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map);
68static int dsp_oss_getlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label);
69static int dsp_oss_setlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label);
70static int dsp_oss_getsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song);
71static int dsp_oss_setsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song);
72static int dsp_oss_setname(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *name);
73#endif
74
75static struct snddev_info *
76dsp_get_info(struct cdev *dev)
77{
76#endif
77
78static int dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgroup *group);
79static int dsp_oss_syncstart(int sg_id);
80static int dsp_oss_policy(struct pcm_channel *wrch, struct pcm_channel *rdch, int policy);
81#ifdef OSSV4_EXPERIMENT
82static int dsp_oss_cookedmode(struct pcm_channel *wrch, struct pcm_channel *rdch, int enabled);
83static int dsp_oss_getchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map);
84static int dsp_oss_setchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map);
85static int dsp_oss_getlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label);
86static int dsp_oss_setlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label);
87static int dsp_oss_getsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song);
88static int dsp_oss_setsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song);
89static int dsp_oss_setname(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *name);
90#endif
91
92static struct snddev_info *
93dsp_get_info(struct cdev *dev)
94{
78 struct snddev_info *d;
79 int unit;
80
81 unit = PCMUNIT(dev);
82 if (unit >= devclass_get_maxunit(pcm_devclass))
83 return NULL;
84 d = devclass_get_softc(pcm_devclass, unit);
85
86 return d;
95 return (devclass_get_softc(pcm_devclass, PCMUNIT(dev)));
87}
88
89static u_int32_t
90dsp_get_flags(struct cdev *dev)
91{
92 device_t bdev;
96}
97
98static u_int32_t
99dsp_get_flags(struct cdev *dev)
100{
101 device_t bdev;
93 int unit;
94
102
95 unit = PCMUNIT(dev);
96 if (unit >= devclass_get_maxunit(pcm_devclass))
97 return 0xffffffff;
98 bdev = devclass_get_device(pcm_devclass, unit);
103 bdev = devclass_get_device(pcm_devclass, PCMUNIT(dev));
99
104
100 return pcm_getflags(bdev);
105 return ((bdev != NULL) ? pcm_getflags(bdev) : 0xffffffff);
101}
102
103static void
104dsp_set_flags(struct cdev *dev, u_int32_t flags)
105{
106 device_t bdev;
106}
107
108static void
109dsp_set_flags(struct cdev *dev, u_int32_t flags)
110{
111 device_t bdev;
107 int unit;
108
112
109 unit = PCMUNIT(dev);
110 if (unit >= devclass_get_maxunit(pcm_devclass))
111 return;
112 bdev = devclass_get_device(pcm_devclass, unit);
113 bdev = devclass_get_device(pcm_devclass, PCMUNIT(dev));
113
114
114 pcm_setflags(bdev, flags);
115 if (bdev != NULL)
116 pcm_setflags(bdev, flags);
115}
116
117/*
118 * return the channels associated with an open device instance.
119 * set the priority if the device is simplex and one direction (only) is
120 * specified.
121 * lock channels specified.
122 */
123static int
124getchns(struct cdev *dev, struct pcm_channel **rdch, struct pcm_channel **wrch, u_int32_t prio)
125{
126 struct snddev_info *d;
127 u_int32_t flags;
128
117}
118
119/*
120 * return the channels associated with an open device instance.
121 * set the priority if the device is simplex and one direction (only) is
122 * specified.
123 * lock channels specified.
124 */
125static int
126getchns(struct cdev *dev, struct pcm_channel **rdch, struct pcm_channel **wrch, u_int32_t prio)
127{
128 struct snddev_info *d;
129 u_int32_t flags;
130
129 flags = dsp_get_flags(dev);
130 d = dsp_get_info(dev);
131 d = dsp_get_info(dev);
132 if (d == NULL)
133 return -1;
131 pcm_inprog(d, 1);
132 pcm_lock(d);
134 pcm_inprog(d, 1);
135 pcm_lock(d);
136 flags = dsp_get_flags(dev);
133 KASSERT((flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
134 ("getchns: read and write both prioritised"));
135
136 if ((flags & SD_F_PRIO_SET) == 0 && (prio != (SD_F_PRIO_RD | SD_F_PRIO_WR))) {
137 flags |= prio & (SD_F_PRIO_RD | SD_F_PRIO_WR);
138 dsp_set_flags(dev, flags);
139 }
140
137 KASSERT((flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
138 ("getchns: read and write both prioritised"));
139
140 if ((flags & SD_F_PRIO_SET) == 0 && (prio != (SD_F_PRIO_RD | SD_F_PRIO_WR))) {
141 flags |= prio & (SD_F_PRIO_RD | SD_F_PRIO_WR);
142 dsp_set_flags(dev, flags);
143 }
144
141 *rdch = dev->si_drv1;
142 *wrch = dev->si_drv2;
145 *rdch = PCM_RDCH(dev);
146 *wrch = PCM_WRCH(dev);
143 if ((flags & SD_F_SIMPLEX) && (flags & SD_F_PRIO_SET)) {
144 if (prio) {
145 if (*rdch && flags & SD_F_PRIO_WR) {
147 if ((flags & SD_F_SIMPLEX) && (flags & SD_F_PRIO_SET)) {
148 if (prio) {
149 if (*rdch && flags & SD_F_PRIO_WR) {
146 dev->si_drv1 = NULL;
150 PCM_RDCH(dev) = NULL;
147 *rdch = pcm_getfakechan(d);
148 } else if (*wrch && flags & SD_F_PRIO_RD) {
151 *rdch = pcm_getfakechan(d);
152 } else if (*wrch && flags & SD_F_PRIO_RD) {
149 dev->si_drv2 = NULL;
153 PCM_WRCH(dev) = NULL;
150 *wrch = pcm_getfakechan(d);
151 }
152 }
153
154 pcm_getfakechan(d)->flags |= CHN_F_BUSY;
155 }
156 pcm_unlock(d);
157

--- 7 unchanged lines hidden (view full) ---

165
166/* unlock specified channels */
167static void
168relchns(struct cdev *dev, struct pcm_channel *rdch, struct pcm_channel *wrch, u_int32_t prio)
169{
170 struct snddev_info *d;
171
172 d = dsp_get_info(dev);
154 *wrch = pcm_getfakechan(d);
155 }
156 }
157
158 pcm_getfakechan(d)->flags |= CHN_F_BUSY;
159 }
160 pcm_unlock(d);
161

--- 7 unchanged lines hidden (view full) ---

169
170/* unlock specified channels */
171static void
172relchns(struct cdev *dev, struct pcm_channel *rdch, struct pcm_channel *wrch, u_int32_t prio)
173{
174 struct snddev_info *d;
175
176 d = dsp_get_info(dev);
177 if (d == NULL)
178 return;
173 if (wrch && wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
174 CHN_UNLOCK(wrch);
175 if (rdch && rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
176 CHN_UNLOCK(rdch);
177 pcm_inprog(d, -1);
178}
179
179 if (wrch && wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
180 CHN_UNLOCK(wrch);
181 if (rdch && rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
182 CHN_UNLOCK(rdch);
183 pcm_inprog(d, -1);
184}
185
186static void
187dsp_cdevinfo_alloc(struct cdev *dev,
188 struct pcm_channel *rdch, struct pcm_channel *wrch)
189{
190 KASSERT(dev != NULL && dev->si_drv1 == dev && rdch != wrch,
191 ("bogus %s(), what are you trying to accomplish here?", __func__));
192
193 dev->si_drv1 = malloc(sizeof(struct dsp_cdevinfo), M_DEVBUF,
194 M_WAITOK | M_ZERO);
195 PCM_RDCH(dev) = rdch;
196 PCM_WRCH(dev) = wrch;
197}
198
199static void
200dsp_cdevinfo_free(struct cdev *dev)
201{
202 KASSERT(dev != NULL && dev->si_drv1 != NULL &&
203 PCM_RDCH(dev) == NULL && PCM_WRCH(dev) == NULL,
204 ("bogus %s(), what are you trying to accomplish here?", __func__));
205
206 free(dev->si_drv1, M_DEVBUF);
207 dev->si_drv1 = NULL;
208}
209
210/* duplex / simplex cdev type */
211enum {
212 DSP_CDEV_TYPE_RDONLY, /* simplex read-only (record) */
213 DSP_CDEV_TYPE_WRONLY, /* simplex write-only (play) */
214 DSP_CDEV_TYPE_RDWR, /* duplex read, write, or both */
215};
216
217#define DSP_F_VALID(x) ((x) & (FREAD | FWRITE))
218#define DSP_F_DUPLEX(x) (((x) & (FREAD | FWRITE)) == (FREAD | FWRITE))
219#define DSP_F_SIMPLEX(x) (!DSP_F_DUPLEX(x))
220#define DSP_F_READ(x) ((x) & FREAD)
221#define DSP_F_WRITE(x) ((x) & FWRITE)
222
223static const struct {
224 int type;
225 char *name;
226 char *sep;
227 int use_sep;
228 int hw;
229 int max;
230 uint32_t fmt, spd;
231 int query;
232} dsp_cdevs[] = {
233 { SND_DEV_DSP, "dsp", ".", 0, 0, 0,
234 AFMT_U8, DSP_DEFAULT_SPEED, DSP_CDEV_TYPE_RDWR },
235 { SND_DEV_AUDIO, "audio", ".", 0, 0, 0,
236 AFMT_MU_LAW, DSP_DEFAULT_SPEED, DSP_CDEV_TYPE_RDWR },
237 { SND_DEV_DSP16, "dspW", ".", 0, 0, 0,
238 AFMT_S16_LE, DSP_DEFAULT_SPEED, DSP_CDEV_TYPE_RDWR },
239 { SND_DEV_DSPHW_PLAY, "dsp", ".p", 1, 1, SND_MAXHWCHAN,
240 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_WRONLY },
241 { SND_DEV_DSPHW_VPLAY, "dsp", ".vp", 1, 1, SND_MAXVCHANS,
242 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_WRONLY },
243 { SND_DEV_DSPHW_REC, "dsp", ".r", 1, 1, SND_MAXHWCHAN,
244 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_RDONLY },
245 { SND_DEV_DSPHW_VREC, "dsp", ".vr", 1, 1, SND_MAXVCHANS,
246 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_RDONLY },
247};
248
180static int
181dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
182{
183 struct pcm_channel *rdch, *wrch;
184 struct snddev_info *d;
249static int
250dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
251{
252 struct pcm_channel *rdch, *wrch;
253 struct snddev_info *d;
185 u_int32_t fmt;
186 int devtype;
187 int error;
188 int chnum;
254 uint32_t fmt, spd;
255 int i, error, devtype;
256 int wdevunit, rdevunit;
189
257
258 /* Kind of impossible.. */
190 if (i_dev == NULL || td == NULL)
191 return ENODEV;
192
259 if (i_dev == NULL || td == NULL)
260 return ENODEV;
261
193 if ((flags & (FREAD | FWRITE)) == 0)
194 return EINVAL;
195
262 /* This too.. */
196 d = dsp_get_info(i_dev);
263 d = dsp_get_info(i_dev);
197 devtype = PCMDEV(i_dev);
198 chnum = -1;
264 if (d == NULL)
265 return EBADF;
199
266
200 /* decide default format */
201 switch (devtype) {
202 case SND_DEV_DSP16:
203 fmt = AFMT_S16_LE;
204 break;
267 /* Lock snddev so nobody else can monkey with it. */
268 pcm_lock(d);
205
269
206 case SND_DEV_DSP:
207 fmt = AFMT_U8;
208 break;
270 /*
271 * Try to acquire cloned device before someone else pick it.
272 * ENODEV means this is not a cloned droids.
273 */
274 error = snd_clone_acquire(i_dev);
275 if (!(error == 0 || error == ENODEV)) {
276 pcm_unlock(d);
277 return error;
278 }
209
279
210 case SND_DEV_AUDIO:
211 fmt = AFMT_MU_LAW;
212 break;
280 if (!DSP_F_VALID(flags))
281 error = EINVAL;
282 else if (i_dev->si_drv1 != NULL)
283 error = EBUSY;
284 else if (DSP_F_DUPLEX(flags) &&
285 (dsp_get_flags(i_dev) & SD_F_SIMPLEX))
286 error = ENOTSUP;
287 else
288 error = 0;
213
289
214 case SND_DEV_NORESET:
215 fmt = 0;
216 break;
217
218 case SND_DEV_DSPHW:
219 /*
220 * HW *specific* access without channel numbering confusion
221 * caused by "first come first served" by dsp_clone().
222 */
223 fmt = AFMT_U8;
224 chnum = PCMCHAN(i_dev);
225 break;
226
227 default:
228 panic("impossible devtype %d", devtype);
290 if (error != 0) {
291 (void)snd_clone_release(i_dev);
292 pcm_unlock(d);
293 return error;
229 }
230
294 }
295
231 /* lock snddev so nobody else can monkey with it */
232 pcm_lock(d);
296 /*
297 * Fake busy state by pointing si_drv1 to something else since
298 * we have to give up locking somewhere during setup process.
299 */
300 PCMDEV_ACQUIRE(i_dev);
233
301
234 rdch = i_dev->si_drv1;
235 wrch = i_dev->si_drv2;
302 devtype = PCMDEV(i_dev);
303 wdevunit = -1;
304 rdevunit = -1;
305 fmt = 0;
306 spd = 0;
236
307
237 if (rdch || wrch || ((dsp_get_flags(i_dev) & SD_F_SIMPLEX) &&
238 (flags & (FREAD | FWRITE)) == (FREAD | FWRITE))) {
239 /* simplex or not, better safe than sorry. */
240 pcm_unlock(d);
241 return EBUSY;
308 for (i = 0; i < (sizeof(dsp_cdevs) / sizeof(dsp_cdevs[0])); i++) {
309 if (devtype != dsp_cdevs[i].type)
310 continue;
311 if (DSP_F_SIMPLEX(flags) &&
312 ((dsp_cdevs[i].query == DSP_CDEV_TYPE_WRONLY &&
313 DSP_F_READ(flags)) ||
314 (dsp_cdevs[i].query == DSP_CDEV_TYPE_RDONLY &&
315 DSP_F_WRITE(flags)))) {
316 /*
317 * simplex, opposite direction? Please be gone..
318 */
319 (void)snd_clone_release(i_dev);
320 PCMDEV_RELEASE(i_dev);
321 pcm_unlock(d);
322 return ENOTSUP;
323 }
324 if (dsp_cdevs[i].query == DSP_CDEV_TYPE_WRONLY)
325 wdevunit = dev2unit(i_dev);
326 else if (dsp_cdevs[i].query == DSP_CDEV_TYPE_RDONLY)
327 rdevunit = dev2unit(i_dev);
328 fmt = dsp_cdevs[i].fmt;
329 spd = dsp_cdevs[i].spd;
330 break;
242 }
243
331 }
332
333 /* No matching devtype? */
334 if (fmt == 0 || spd == 0)
335 panic("impossible devtype %d", devtype);
336
337 rdch = NULL;
338 wrch = NULL;
339
244 /*
245 * if we get here, the open request is valid- either:
246 * * we were previously not open
247 * * we were open for play xor record and the opener wants
248 * the non-open direction
249 */
340 /*
341 * if we get here, the open request is valid- either:
342 * * we were previously not open
343 * * we were open for play xor record and the opener wants
344 * the non-open direction
345 */
250 if (flags & FREAD) {
346 if (DSP_F_READ(flags)) {
251 /* open for read */
252 pcm_unlock(d);
347 /* open for read */
348 pcm_unlock(d);
253 error = pcm_chnalloc(d, &rdch, PCMDIR_REC, td->td_proc->p_pid, chnum);
254 if (error != 0 && error != EBUSY && chnum != -1 && (flags & FWRITE))
255 error = pcm_chnalloc(d, &rdch, PCMDIR_REC, td->td_proc->p_pid, -1);
349 error = pcm_chnalloc(d, &rdch, PCMDIR_REC, td->td_proc->p_pid,
350 rdevunit);
256
351
257 if (error == 0 && (chn_reset(rdch, fmt) ||
258 (fmt && chn_setspeed(rdch, DSP_DEFAULT_SPEED))))
352 if (error == 0 && (chn_reset(rdch, fmt) != 0 ||
353 (chn_setspeed(rdch, spd) != 0)))
259 error = ENODEV;
260
261 if (error != 0) {
354 error = ENODEV;
355
356 if (error != 0) {
262 if (rdch)
357 if (rdch != NULL)
263 pcm_chnrelease(rdch);
358 pcm_chnrelease(rdch);
359 pcm_lock(d);
360 (void)snd_clone_release(i_dev);
361 PCMDEV_RELEASE(i_dev);
362 pcm_unlock(d);
264 return error;
265 }
266
267 if (flags & O_NONBLOCK)
268 rdch->flags |= CHN_F_NBIO;
269 pcm_chnref(rdch, 1);
270 CHN_UNLOCK(rdch);
271 pcm_lock(d);
272 }
273
363 return error;
364 }
365
366 if (flags & O_NONBLOCK)
367 rdch->flags |= CHN_F_NBIO;
368 pcm_chnref(rdch, 1);
369 CHN_UNLOCK(rdch);
370 pcm_lock(d);
371 }
372
274 if (flags & FWRITE) {
275 /* open for write */
276 pcm_unlock(d);
277 error = pcm_chnalloc(d, &wrch, PCMDIR_PLAY, td->td_proc->p_pid, chnum);
278 if (error != 0 && error != EBUSY && chnum != -1 && (flags & FREAD))
279 error = pcm_chnalloc(d, &wrch, PCMDIR_PLAY, td->td_proc->p_pid, -1);
373 if (DSP_F_WRITE(flags)) {
374 /* open for write */
375 pcm_unlock(d);
376 error = pcm_chnalloc(d, &wrch, PCMDIR_PLAY, td->td_proc->p_pid,
377 wdevunit);
280
378
281 if (error == 0 && (chn_reset(wrch, fmt) ||
282 (fmt && chn_setspeed(wrch, DSP_DEFAULT_SPEED))))
283 error = ENODEV;
379 if (error == 0 && (chn_reset(wrch, fmt) != 0 ||
380 (chn_setspeed(wrch, spd) != 0)))
381 error = ENODEV;
284
382
285 if (error != 0) {
286 if (wrch)
287 pcm_chnrelease(wrch);
288 if (rdch) {
289 /*
290 * Lock, deref and release previously created record channel
291 */
292 CHN_LOCK(rdch);
293 pcm_chnref(rdch, -1);
294 pcm_chnrelease(rdch);
383 if (error != 0) {
384 if (wrch != NULL)
385 pcm_chnrelease(wrch);
386 if (rdch != NULL) {
387 /*
388 * Lock, deref and release previously
389 * created record channel
390 */
391 CHN_LOCK(rdch);
392 pcm_chnref(rdch, -1);
393 pcm_chnrelease(rdch);
394 }
395 pcm_lock(d);
396 (void)snd_clone_release(i_dev);
397 PCMDEV_RELEASE(i_dev);
398 pcm_unlock(d);
399 return error;
295 }
296
400 }
401
297 return error;
298 }
299
300 if (flags & O_NONBLOCK)
301 wrch->flags |= CHN_F_NBIO;
302 pcm_chnref(wrch, 1);
303 CHN_UNLOCK(wrch);
304 pcm_lock(d);
402 if (flags & O_NONBLOCK)
403 wrch->flags |= CHN_F_NBIO;
404 pcm_chnref(wrch, 1);
405 CHN_UNLOCK(wrch);
406 pcm_lock(d);
305 }
306
407 }
408
307 i_dev->si_drv1 = rdch;
308 i_dev->si_drv2 = wrch;
409 /*
410 * Increase clone refcount for its automatic garbage collector.
411 */
412 (void)snd_clone_ref(i_dev);
309
310 pcm_unlock(d);
413
414 pcm_unlock(d);
415
416 /*
417 * We're done. Allocate and point si_drv1 to a real
418 * allocated structure.
419 */
420 dsp_cdevinfo_alloc(i_dev, rdch, wrch);
421
311 return 0;
312}
313
314static int
315dsp_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
316{
317 struct pcm_channel *rdch, *wrch;
318 struct snddev_info *d;
319 int refs, sg_ids[2];
320
321 d = dsp_get_info(i_dev);
422 return 0;
423}
424
425static int
426dsp_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
427{
428 struct pcm_channel *rdch, *wrch;
429 struct snddev_info *d;
430 int refs, sg_ids[2];
431
432 d = dsp_get_info(i_dev);
433 if (d == NULL)
434 return EBADF;
322 pcm_lock(d);
435 pcm_lock(d);
323 rdch = i_dev->si_drv1;
324 wrch = i_dev->si_drv2;
325 pcm_unlock(d);
436 rdch = PCM_RDCH(i_dev);
437 wrch = PCM_WRCH(i_dev);
326
327 /*
328 * Free_unr() may sleep, so store released syncgroup IDs until after
329 * all locks are released.
330 */
331 sg_ids[0] = sg_ids[1] = 0;
332
333 if (rdch || wrch) {
334 refs = 0;
438
439 /*
440 * Free_unr() may sleep, so store released syncgroup IDs until after
441 * all locks are released.
442 */
443 sg_ids[0] = sg_ids[1] = 0;
444
445 if (rdch || wrch) {
446 refs = 0;
447 pcm_unlock(d);
335 if (rdch) {
336 /*
337 * The channel itself need not be locked because:
338 * a) Adding a channel to a syncgroup happens only in dsp_ioctl(),
339 * which cannot run concurrently to dsp_close().
340 * b) The syncmember pointer (sm) is protected by the global
341 * syncgroup list lock.
342 * c) A channel can't just disappear, invalidating pointers,

--- 23 unchanged lines hidden (view full) ---

366 chn_flush(wrch); /* may sleep */
367 wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
368 chn_reset(wrch, 0);
369 pcm_chnrelease(wrch);
370 }
371
372 pcm_lock(d);
373 if (rdch)
448 if (rdch) {
449 /*
450 * The channel itself need not be locked because:
451 * a) Adding a channel to a syncgroup happens only in dsp_ioctl(),
452 * which cannot run concurrently to dsp_close().
453 * b) The syncmember pointer (sm) is protected by the global
454 * syncgroup list lock.
455 * c) A channel can't just disappear, invalidating pointers,

--- 23 unchanged lines hidden (view full) ---

479 chn_flush(wrch); /* may sleep */
480 wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
481 chn_reset(wrch, 0);
482 pcm_chnrelease(wrch);
483 }
484
485 pcm_lock(d);
486 if (rdch)
374 i_dev->si_drv1 = NULL;
487 PCM_RDCH(i_dev) = NULL;
375 if (wrch)
488 if (wrch)
376 i_dev->si_drv2 = NULL;
489 PCM_WRCH(i_dev) = NULL;
377 /*
378 * If there are no more references, release the channels.
379 */
490 /*
491 * If there are no more references, release the channels.
492 */
380 if (refs == 0 && i_dev->si_drv1 == NULL &&
381 i_dev->si_drv2 == NULL) {
493 if (refs == 0 && PCM_RDCH(i_dev) == NULL &&
494 PCM_WRCH(i_dev) == NULL) {
382 if (pcm_getfakechan(d))
383 pcm_getfakechan(d)->flags = 0;
384 /* What is this?!? */
385 dsp_set_flags(i_dev, dsp_get_flags(i_dev) & ~SD_F_TRANSIENT);
495 if (pcm_getfakechan(d))
496 pcm_getfakechan(d)->flags = 0;
497 /* What is this?!? */
498 dsp_set_flags(i_dev, dsp_get_flags(i_dev) & ~SD_F_TRANSIENT);
499 dsp_cdevinfo_free(i_dev);
500 /*
501 * Release clone busy state and unref it
502 * so the automatic garbage collector will
503 * get the hint and do the remaining cleanup
504 * process.
505 */
506 (void)snd_clone_release(i_dev);
507 (void)snd_clone_unref(i_dev);
386 }
508 }
387 pcm_unlock(d);
388 }
389
509 }
510
511 pcm_unlock(d);
390
391 if (sg_ids[0])
392 free_unr(pcmsg_unrhdr, sg_ids[0]);
393 if (sg_ids[1])
394 free_unr(pcmsg_unrhdr, sg_ids[1]);
395
396 return 0;
397}
398
399static int
400dsp_read(struct cdev *i_dev, struct uio *buf, int flag)
401{
402 struct pcm_channel *rdch, *wrch;
403 int ret;
404
405 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD);
406
512
513 if (sg_ids[0])
514 free_unr(pcmsg_unrhdr, sg_ids[0]);
515 if (sg_ids[1])
516 free_unr(pcmsg_unrhdr, sg_ids[1]);
517
518 return 0;
519}
520
521static int
522dsp_read(struct cdev *i_dev, struct uio *buf, int flag)
523{
524 struct pcm_channel *rdch, *wrch;
525 int ret;
526
527 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD);
528
407 KASSERT(rdch, ("dsp_read: nonexistant channel"));
408 KASSERT(rdch->flags & CHN_F_BUSY, ("dsp_read: nonbusy channel"));
529 if (rdch == NULL || !(rdch->flags & CHN_F_BUSY))
530 return EBADF;
409
410 if (rdch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
411 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
412 return EINVAL;
413 }
414 if (!(rdch->flags & CHN_F_RUNNING))
415 rdch->flags |= CHN_F_RUNNING;
416 ret = chn_read(rdch, buf);

--- 5 unchanged lines hidden (view full) ---

422static int
423dsp_write(struct cdev *i_dev, struct uio *buf, int flag)
424{
425 struct pcm_channel *rdch, *wrch;
426 int ret;
427
428 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_WR);
429
531
532 if (rdch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
533 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
534 return EINVAL;
535 }
536 if (!(rdch->flags & CHN_F_RUNNING))
537 rdch->flags |= CHN_F_RUNNING;
538 ret = chn_read(rdch, buf);

--- 5 unchanged lines hidden (view full) ---

544static int
545dsp_write(struct cdev *i_dev, struct uio *buf, int flag)
546{
547 struct pcm_channel *rdch, *wrch;
548 int ret;
549
550 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_WR);
551
430 KASSERT(wrch, ("dsp_write: nonexistant channel"));
431 KASSERT(wrch->flags & CHN_F_BUSY, ("dsp_write: nonbusy channel"));
552 if (wrch == NULL || !(wrch->flags & CHN_F_BUSY))
553 return EBADF;
432
433 if (wrch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
434 relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
435 return EINVAL;
436 }
437 if (!(wrch->flags & CHN_F_RUNNING))
438 wrch->flags |= CHN_F_RUNNING;
439

--- 24 unchanged lines hidden (view full) ---

464 xcmd = 0;
465
466 /*
467 * this is an evil hack to allow broken apps to perform mixer ioctls
468 * on dsp devices.
469 */
470
471 d = dsp_get_info(i_dev);
554
555 if (wrch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
556 relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
557 return EINVAL;
558 }
559 if (!(wrch->flags & CHN_F_RUNNING))
560 wrch->flags |= CHN_F_RUNNING;
561

--- 24 unchanged lines hidden (view full) ---

586 xcmd = 0;
587
588 /*
589 * this is an evil hack to allow broken apps to perform mixer ioctls
590 * on dsp devices.
591 */
592
593 d = dsp_get_info(i_dev);
594 if (d == NULL)
595 return EBADF;
472 if (IOCGROUP(cmd) == 'M') {
473 /*
474 * This is at least, a bug to bug compatible with OSS.
475 */
476 if (d->mixer_dev != NULL)
477 return mixer_ioctl(d->mixer_dev, cmd, arg, -1, td);
478 else
479 return EBADF;

--- 31 unchanged lines hidden (view full) ---

511 if (kill == 3) {
512 relchns(i_dev, rdch, wrch, 0);
513 return EINVAL;
514 }
515 if (kill & 1)
516 wrch = NULL;
517 if (kill & 2)
518 rdch = NULL;
596 if (IOCGROUP(cmd) == 'M') {
597 /*
598 * This is at least, a bug to bug compatible with OSS.
599 */
600 if (d->mixer_dev != NULL)
601 return mixer_ioctl(d->mixer_dev, cmd, arg, -1, td);
602 else
603 return EBADF;

--- 31 unchanged lines hidden (view full) ---

635 if (kill == 3) {
636 relchns(i_dev, rdch, wrch, 0);
637 return EINVAL;
638 }
639 if (kill & 1)
640 wrch = NULL;
641 if (kill & 2)
642 rdch = NULL;
519
643
520 switch(cmd) {
521#ifdef OLDPCM_IOCTL
522 /*
523 * we start with the new ioctl interface.
524 */
525 case AIONWRITE: /* how many bytes can write ? */
526 if (wrch) {
527 CHN_LOCK(wrch);

--- 970 unchanged lines hidden (view full) ---

1498 *paddr = vtophys(sndbuf_getbufofs(c->bufsoft, offset));
1499 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1500
1501 return 0;
1502}
1503
1504#ifdef USING_DEVFS
1505
644 switch(cmd) {
645#ifdef OLDPCM_IOCTL
646 /*
647 * we start with the new ioctl interface.
648 */
649 case AIONWRITE: /* how many bytes can write ? */
650 if (wrch) {
651 CHN_LOCK(wrch);

--- 970 unchanged lines hidden (view full) ---

1622 *paddr = vtophys(sndbuf_getbufofs(c->bufsoft, offset));
1623 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1624
1625 return 0;
1626}
1627
1628#ifdef USING_DEVFS
1629
1506/*
1507 * Clone logic is this:
1508 * x E X = {dsp, dspW, audio}
1509 * x -> x${sysctl("hw.snd.unit")}
1510 * xN->
1511 * for i N = 1 to channels of device N
1512 * if xN.i isn't busy, return its dev_t
1513 */
1630/* So much for dev_stdclone() */
1631static int
1632dsp_stdclone(char *name, char *namep, char *sep, int use_sep, int *u, int *c)
1633{
1634 size_t len;
1635
1636 len = strlen(namep);
1637
1638 if (bcmp(name, namep, len) != 0)
1639 return (ENODEV);
1640
1641 name += len;
1642
1643 if (isdigit(*name) == 0)
1644 return (ENODEV);
1645
1646 len = strlen(sep);
1647
1648 if (*name == '0' && !(name[1] == '\0' || bcmp(name + 1, sep, len) == 0))
1649 return (ENODEV);
1650
1651 for (*u = 0; isdigit(*name) != 0; name++) {
1652 *u *= 10;
1653 *u += *name - '0';
1654 if (*u > dsp_umax)
1655 return (ENODEV);
1656 }
1657
1658 if (*name == '\0')
1659 return ((use_sep == 0) ? 0 : ENODEV);
1660
1661 if (bcmp(name, sep, len) != 0 || isdigit(name[len]) == 0)
1662 return (ENODEV);
1663
1664 name += len;
1665
1666 if (*name == '0' && name[1] != '\0')
1667 return (ENODEV);
1668
1669 for (*c = 0; isdigit(*name) != 0; name++) {
1670 *c *= 10;
1671 *c += *name - '0';
1672 if (*c > dsp_cmax)
1673 return (ENODEV);
1674 }
1675
1676 if (*name != '\0')
1677 return (ENODEV);
1678
1679 return (0);
1680}
1681
1514static void
1682static void
1515dsp_clone(void *arg, struct ucred *cred, char *name, int namelen,
1516 struct cdev **dev)
1683dsp_clone(void *arg,
1684#if __FreeBSD_version >= 600034
1685 struct ucred *cred,
1686#endif
1687 char *name, int namelen, struct cdev **dev)
1517{
1688{
1518 struct cdev *pdev;
1519 struct snddev_info *pcm_dev;
1520 struct snddev_channel *pcm_chan;
1521 int i, unit, devtype;
1522 static int devtypes[3] = {SND_DEV_DSP, SND_DEV_DSP16, SND_DEV_AUDIO};
1523 static char *devnames[3] = {"dsp", "dspW", "audio"};
1689 struct snddev_info *d;
1690 struct snd_clone_entry *ce;
1691 struct pcm_channel *c;
1692 int i, unit, udcmask, cunit, devtype, devhw, devcmax, tumax;
1693 char *devname, *devsep;
1524
1694
1695 KASSERT(dsp_umax >= 0 && dsp_cmax >= 0, ("Uninitialized unit!"));
1696
1525 if (*dev != NULL)
1526 return;
1697 if (*dev != NULL)
1698 return;
1527 if (pcm_devclass == NULL)
1528 return;
1529
1699
1530 devtype = 0;
1531 unit = -1;
1700 unit = -1;
1532 for (i = 0; (i < 3) && (unit == -1); i++) {
1533 devtype = devtypes[i];
1534 if (strcmp(name, devnames[i]) == 0) {
1701 cunit = -1;
1702 devtype = -1;
1703 devhw = 0;
1704 devcmax = -1;
1705 tumax = -1;
1706 devname = NULL;
1707 devsep = NULL;
1708
1709 for (i = 0; i < (sizeof(dsp_cdevs) / sizeof(dsp_cdevs[0])) &&
1710 unit == -1; i++) {
1711 devtype = dsp_cdevs[i].type;
1712 devname = dsp_cdevs[i].name;
1713 devsep = dsp_cdevs[i].sep;
1714 devhw = dsp_cdevs[i].hw;
1715 devcmax = dsp_cdevs[i].max - 1;
1716 if (strcmp(name, devname) == 0)
1535 unit = snd_unit;
1717 unit = snd_unit;
1536 } else {
1537 if (dev_stdclone(name, NULL, devnames[i], &unit) != 1)
1538 unit = -1;
1718 else if (dsp_stdclone(name, devname, devsep,
1719 dsp_cdevs[i].use_sep, &unit, &cunit) != 0) {
1720 unit = -1;
1721 cunit = -1;
1539 }
1540 }
1722 }
1723 }
1541 if (unit == -1 || unit >= devclass_get_maxunit(pcm_devclass))
1724
1725 d = devclass_get_softc(pcm_devclass, unit);
1726 if (d == NULL || d->clones == NULL)
1542 return;
1543
1727 return;
1728
1544 pcm_dev = devclass_get_softc(pcm_devclass, unit);
1545
1546 if (pcm_dev == NULL)
1729 pcm_lock(d);
1730 if (snd_clone_disabled(d->clones)) {
1731 pcm_unlock(d);
1547 return;
1732 return;
1733 }
1548
1734
1549 SLIST_FOREACH(pcm_chan, &pcm_dev->channels, link) {
1735 udcmask = snd_u2unit(unit) | snd_d2unit(devtype);
1550
1736
1551 switch(devtype) {
1552 case SND_DEV_DSP:
1553 pdev = pcm_chan->dsp_devt;
1554 break;
1555 case SND_DEV_DSP16:
1556 pdev = pcm_chan->dspW_devt;
1557 break;
1558 case SND_DEV_AUDIO:
1559 pdev = pcm_chan->audio_devt;
1560 break;
1561 default:
1562 panic("Unknown devtype %d", devtype);
1563 }
1564
1565 if ((pdev != NULL) && (pdev->si_drv1 == NULL) && (pdev->si_drv2 == NULL)) {
1566 *dev = pdev;
1567 dev_ref(*dev);
1737 if (devhw != 0) {
1738 KASSERT(devcmax <= dsp_cmax,
1739 ("overflow: devcmax=%d, dsp_cmax=%d", devcmax, dsp_cmax));
1740 if (cunit > devcmax) {
1741 pcm_unlock(d);
1568 return;
1569 }
1742 return;
1743 }
1744 udcmask |= snd_c2unit(cunit);
1745 CHN_FOREACH(c, d, channels.pcm) {
1746 CHN_LOCK(c);
1747 if (c->unit != udcmask) {
1748 CHN_UNLOCK(c);
1749 continue;
1750 }
1751 CHN_UNLOCK(c);
1752 udcmask &= ~snd_c2unit(cunit);
1753 /*
1754 * Temporarily increase clone maxunit to overcome
1755 * vchan flexibility.
1756 *
1757 * # sysctl dev.pcm.0.play.vchans=256
1758 * dev.pcm.0.play.vchans: 1 -> 256
1759 * # cat /dev/zero > /dev/dsp0.vp255 &
1760 * [1] 17296
1761 * # sysctl dev.pcm.0.play.vchans=0
1762 * dev.pcm.0.play.vchans: 256 -> 1
1763 * # fg
1764 * [1] + running cat /dev/zero > /dev/dsp0.vp255
1765 * ^C
1766 * # cat /dev/zero > /dev/dsp0.vp255
1767 * zsh: operation not supported: /dev/dsp0.vp255
1768 */
1769 tumax = snd_clone_getmaxunit(d->clones);
1770 if (cunit > tumax)
1771 snd_clone_setmaxunit(d->clones, cunit);
1772 else
1773 tumax = -1;
1774 goto dsp_clone_alloc;
1775 }
1776 /*
1777 * Ok, so we're requesting unallocated vchan, but still
1778 * within maximum vchan limit.
1779 */
1780 if (((devtype == SND_DEV_DSPHW_VPLAY && d->pvchancount > 0) ||
1781 (devtype == SND_DEV_DSPHW_VREC && d->rvchancount > 0)) &&
1782 cunit < snd_maxautovchans) {
1783 udcmask &= ~snd_c2unit(cunit);
1784 tumax = snd_clone_getmaxunit(d->clones);
1785 if (cunit > tumax)
1786 snd_clone_setmaxunit(d->clones, cunit);
1787 else
1788 tumax = -1;
1789 goto dsp_clone_alloc;
1790 }
1791 pcm_unlock(d);
1792 return;
1570 }
1793 }
1794
1795dsp_clone_alloc:
1796 ce = snd_clone_alloc(d->clones, dev, &cunit, udcmask);
1797 if (tumax != -1)
1798 snd_clone_setmaxunit(d->clones, tumax);
1799 if (ce != NULL) {
1800 udcmask |= snd_c2unit(cunit);
1801 pcm_unlock(d);
1802 *dev = make_dev(&dsp_cdevsw, unit2minor(udcmask),
1803 UID_ROOT, GID_WHEEL, 0666, "%s%d%s%d",
1804 devname, unit, devsep, cunit);
1805 pcm_lock(d);
1806 snd_clone_register(ce, *dev);
1807 }
1808 pcm_unlock(d);
1809
1810 if (*dev != NULL)
1811 dev_ref(*dev);
1571}
1572
1573static void
1574dsp_sysinit(void *p)
1575{
1812}
1813
1814static void
1815dsp_sysinit(void *p)
1816{
1817 if (dsp_ehtag != NULL)
1818 return;
1819 /* initialize unit numbering */
1820 snd_unit_init();
1821 dsp_umax = PCMMAXUNIT;
1822 dsp_cmax = PCMMAXCHAN;
1576 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000);
1577}
1578
1579static void
1580dsp_sysuninit(void *p)
1581{
1823 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000);
1824}
1825
1826static void
1827dsp_sysuninit(void *p)
1828{
1582 if (dsp_ehtag != NULL)
1583 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag);
1829 if (dsp_ehtag == NULL)
1830 return;
1831 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag);
1832 dsp_ehtag = NULL;
1584}
1585
1586SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
1587SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);
1588#endif
1589
1833}
1834
1835SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
1836SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);
1837#endif
1838
1839char *
1840dsp_unit2name(char *buf, size_t len, int unit)
1841{
1842 int i, dtype;
1843
1844 KASSERT(buf != NULL && len != 0, ("bogus buf=%p len=%u", buf, len));
1845
1846 dtype = snd_unit2d(unit);
1847
1848 for (i = 0; i < (sizeof(dsp_cdevs) / sizeof(dsp_cdevs[0])); i++) {
1849 if (dtype != dsp_cdevs[i].type)
1850 continue;
1851 snprintf(buf, len, "%s%d%s%d", dsp_cdevs[i].name,
1852 snd_unit2u(unit), dsp_cdevs[i].sep, snd_unit2c(unit));
1853 return (buf);
1854 }
1855
1856 return (NULL);
1857}
1858
1590/**
1591 * @brief Handler for SNDCTL_AUDIOINFO.
1592 *
1593 * Gathers information about the audio device specified in ai->dev. If
1594 * ai->dev == -1, then this function gathers information about the current
1595 * device. If the call comes in on a non-audio device and ai->dev == -1,
1596 * return EINVAL.
1597 *

--- 19 unchanged lines hidden (view full) ---

1617 * @retval 0 success
1618 * @retval EINVAL ai->dev specifies an invalid device
1619 *
1620 * @todo Verify correctness of Doxygen tags. ;)
1621 */
1622int
1623dsp_oss_audioinfo(struct cdev *i_dev, oss_audioinfo *ai)
1624{
1859/**
1860 * @brief Handler for SNDCTL_AUDIOINFO.
1861 *
1862 * Gathers information about the audio device specified in ai->dev. If
1863 * ai->dev == -1, then this function gathers information about the current
1864 * device. If the call comes in on a non-audio device and ai->dev == -1,
1865 * return EINVAL.
1866 *

--- 19 unchanged lines hidden (view full) ---

1886 * @retval 0 success
1887 * @retval EINVAL ai->dev specifies an invalid device
1888 *
1889 * @todo Verify correctness of Doxygen tags. ;)
1890 */
1891int
1892dsp_oss_audioinfo(struct cdev *i_dev, oss_audioinfo *ai)
1893{
1625 struct snddev_channel *sce;
1626 struct pcmchan_caps *caps;
1627 struct pcm_channel *ch;
1628 struct snddev_info *d;
1894 struct pcmchan_caps *caps;
1895 struct pcm_channel *ch;
1896 struct snddev_info *d;
1629 struct cdev *t_cdev;
1630 uint32_t fmts;
1631 int i, nchan, ret, *rates, minch, maxch;
1897 uint32_t fmts;
1898 int i, nchan, ret, *rates, minch, maxch;
1899 char *devname, buf[CHN_NAMELEN];
1632
1633 /*
1634 * If probing the device that received the ioctl, make sure it's a
1635 * DSP device. (Users may use this ioctl with /dev/mixer and
1636 * /dev/midi.)
1637 */
1638 if ((ai->dev == -1) && (i_dev->si_devsw != &dsp_cdevsw))
1639 return EINVAL;
1640
1641 ch = NULL;
1900
1901 /*
1902 * If probing the device that received the ioctl, make sure it's a
1903 * DSP device. (Users may use this ioctl with /dev/mixer and
1904 * /dev/midi.)
1905 */
1906 if ((ai->dev == -1) && (i_dev->si_devsw != &dsp_cdevsw))
1907 return EINVAL;
1908
1909 ch = NULL;
1642 t_cdev = NULL;
1910 devname = NULL;
1643 nchan = 0;
1644 ret = 0;
1911 nchan = 0;
1912 ret = 0;
1645
1913 bzero(buf, sizeof(buf));
1914
1646 /*
1647 * Search for the requested audio device (channel). Start by
1648 * iterating over pcm devices.
1649 */
1650 for (i = 0; i < devclass_get_maxunit(pcm_devclass); i++) {
1651 d = devclass_get_softc(pcm_devclass, i);
1652 if (d == NULL)
1653 continue;
1654
1655 /* See the note in function docblock */
1656 mtx_assert(d->lock, MA_NOTOWNED);
1657 pcm_inprog(d, 1);
1658 pcm_lock(d);
1659
1915 /*
1916 * Search for the requested audio device (channel). Start by
1917 * iterating over pcm devices.
1918 */
1919 for (i = 0; i < devclass_get_maxunit(pcm_devclass); i++) {
1920 d = devclass_get_softc(pcm_devclass, i);
1921 if (d == NULL)
1922 continue;
1923
1924 /* See the note in function docblock */
1925 mtx_assert(d->lock, MA_NOTOWNED);
1926 pcm_inprog(d, 1);
1927 pcm_lock(d);
1928
1660 SLIST_FOREACH(sce, &d->channels, link) {
1661 ch = sce->channel;
1929 CHN_FOREACH(ch, d, channels.pcm) {
1662 mtx_assert(ch->lock, MA_NOTOWNED);
1663 CHN_LOCK(ch);
1664 if (ai->dev == -1) {
1930 mtx_assert(ch->lock, MA_NOTOWNED);
1931 CHN_LOCK(ch);
1932 if (ai->dev == -1) {
1665 if ((ch == i_dev->si_drv1) || /* record ch */
1666 (ch == i_dev->si_drv2)) { /* playback ch */
1667 t_cdev = i_dev;
1933 if ((ch == PCM_RDCH(i_dev)) || /* record ch */
1934 (ch == PCM_WRCH(i_dev))) { /* playback ch */
1935 devname = i_dev->si_name;
1668 goto dspfound;
1669 }
1670 } else if (ai->dev == nchan) {
1936 goto dspfound;
1937 }
1938 } else if (ai->dev == nchan) {
1671 t_cdev = sce->dsp_devt;
1939 devname = dsp_unit2name(buf, sizeof(buf),
1940 ch->unit);
1672 goto dspfound;
1673 }
1674 CHN_UNLOCK(ch);
1941 goto dspfound;
1942 }
1943 CHN_UNLOCK(ch);
1944 /*
1945 * XXX I really doubt if this is correct.
1946 */
1675 ++nchan;
1676 }
1677
1678 pcm_unlock(d);
1679 pcm_inprog(d, -1);
1680 }
1681
1682 /* Exhausted the search -- nothing is locked, so return. */
1683 return EINVAL;
1684
1685dspfound:
1686 /* Should've found the device, but something isn't right */
1947 ++nchan;
1948 }
1949
1950 pcm_unlock(d);
1951 pcm_inprog(d, -1);
1952 }
1953
1954 /* Exhausted the search -- nothing is locked, so return. */
1955 return EINVAL;
1956
1957dspfound:
1958 /* Should've found the device, but something isn't right */
1687 if (t_cdev == NULL) {
1959 if (devname == NULL) {
1688 ret = EINVAL;
1689 goto out;
1690 }
1691
1692 /*
1693 * At this point, the following synchronization stuff has happened:
1694 * - a specific PCM device is locked and its "in progress
1695 * operations" counter has been incremented, so be sure to unlock

--- 20 unchanged lines hidden (view full) ---

1716
1717 /**
1718 * @note
1719 * @c cmd - OSSv4 docs: "Only supported under Linux at this moment."
1720 * Cop-out, I know, but I'll save running around in the process
1721 * table for later. Is there a risk of leaking information?
1722 */
1723 ai->pid = ch->pid;
1960 ret = EINVAL;
1961 goto out;
1962 }
1963
1964 /*
1965 * At this point, the following synchronization stuff has happened:
1966 * - a specific PCM device is locked and its "in progress
1967 * operations" counter has been incremented, so be sure to unlock

--- 20 unchanged lines hidden (view full) ---

1988
1989 /**
1990 * @note
1991 * @c cmd - OSSv4 docs: "Only supported under Linux at this moment."
1992 * Cop-out, I know, but I'll save running around in the process
1993 * table for later. Is there a risk of leaking information?
1994 */
1995 ai->pid = ch->pid;
1724
1996
1725 /*
1726 * These flags stolen from SNDCTL_DSP_GETCAPS handler. Note, however,
1727 * that a single channel operates in only one direction, so
1728 * DSP_CAP_DUPLEX is out.
1729 */
1730 /**
1731 * @todo @c SNDCTL_AUDIOINFO::caps - Make drivers keep these in
1732 * pcmchan::caps?

--- 46 unchanged lines hidden (view full) ---

1779 */
1780 ai->port_number = -1;
1781 ai->mixer_dev = (d->mixer_dev != NULL) ? PCMUNIT(d->mixer_dev) : -1;
1782 /**
1783 * @note
1784 * @c real_device - OSSv4 docs: "Obsolete."
1785 */
1786 ai->real_device = -1;
1997 /*
1998 * These flags stolen from SNDCTL_DSP_GETCAPS handler. Note, however,
1999 * that a single channel operates in only one direction, so
2000 * DSP_CAP_DUPLEX is out.
2001 */
2002 /**
2003 * @todo @c SNDCTL_AUDIOINFO::caps - Make drivers keep these in
2004 * pcmchan::caps?

--- 46 unchanged lines hidden (view full) ---

2051 */
2052 ai->port_number = -1;
2053 ai->mixer_dev = (d->mixer_dev != NULL) ? PCMUNIT(d->mixer_dev) : -1;
2054 /**
2055 * @note
2056 * @c real_device - OSSv4 docs: "Obsolete."
2057 */
2058 ai->real_device = -1;
1787 strlcpy(ai->devnode, t_cdev->si_name, sizeof(ai->devnode));
2059 strlcpy(ai->devnode, devname, sizeof(ai->devnode));
1788 ai->enabled = device_is_attached(d->dev) ? 1 : 0;
1789 /**
1790 * @note
1791 * @c flags - OSSv4 docs: "Reserved for future use."
1792 *
1793 * @note
1794 * @c binding - OSSv4 docs: "Reserved for future use."
1795 *

--- 207 unchanged lines hidden (view full) ---

2003 */
2004static int
2005dsp_oss_syncstart(int sg_id)
2006{
2007 struct pcmchan_syncmember *sm, *sm_tmp;
2008 struct pcmchan_syncgroup *sg;
2009 struct pcm_channel *c;
2010 int ret, needlocks;
2060 ai->enabled = device_is_attached(d->dev) ? 1 : 0;
2061 /**
2062 * @note
2063 * @c flags - OSSv4 docs: "Reserved for future use."
2064 *
2065 * @note
2066 * @c binding - OSSv4 docs: "Reserved for future use."
2067 *

--- 207 unchanged lines hidden (view full) ---

2275 */
2276static int
2277dsp_oss_syncstart(int sg_id)
2278{
2279 struct pcmchan_syncmember *sm, *sm_tmp;
2280 struct pcmchan_syncgroup *sg;
2281 struct pcm_channel *c;
2282 int ret, needlocks;
2011
2283
2012 /* Get the synclists lock */
2013 PCM_SG_LOCK();
2014
2015 do {
2016 ret = 0;
2017 needlocks = 0;
2018
2019 /* Search for syncgroup by ID */

--- 341 unchanged lines hidden ---
2284 /* Get the synclists lock */
2285 PCM_SG_LOCK();
2286
2287 do {
2288 ret = 0;
2289 needlocks = 0;
2290
2291 /* Search for syncgroup by ID */

--- 341 unchanged lines hidden ---