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 <dev/sound/pcm/sound.h> |
28#include <sys/ctype.h> |
29 |
30SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/dsp.c 170161 2007-05-31 18:43:33Z ariff $"); |
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 |
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 |
73static eventhandler_tag dsp_ehtag = NULL; 74static int dsp_umax = -1; 75static int dsp_cmax = -1; |
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{ |
95 return (devclass_get_softc(pcm_devclass, PCMUNIT(dev))); |
96} 97 98static u_int32_t 99dsp_get_flags(struct cdev *dev) 100{ 101 device_t bdev; |
102 |
103 bdev = devclass_get_device(pcm_devclass, PCMUNIT(dev)); |
104 |
105 return ((bdev != NULL) ? pcm_getflags(bdev) : 0xffffffff); |
106} 107 108static void 109dsp_set_flags(struct cdev *dev, u_int32_t flags) 110{ 111 device_t bdev; |
112 |
113 bdev = devclass_get_device(pcm_devclass, PCMUNIT(dev)); |
114 |
115 if (bdev != NULL) 116 pcm_setflags(bdev, flags); |
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 |
131 d = dsp_get_info(dev); |
132 if (d == NULL) 133 return -1; |
134 pcm_inprog(d, 1); 135 pcm_lock(d); |
136 flags = dsp_get_flags(dev); |
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 |
145 *rdch = PCM_RDCH(dev); 146 *wrch = PCM_WRCH(dev); |
147 if ((flags & SD_F_SIMPLEX) && (flags & SD_F_PRIO_SET)) { 148 if (prio) { 149 if (*rdch && flags & SD_F_PRIO_WR) { |
150 PCM_RDCH(dev) = NULL; |
151 *rdch = pcm_getfakechan(d); 152 } else if (*wrch && flags & SD_F_PRIO_RD) { |
153 PCM_WRCH(dev) = NULL; |
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; |
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 |
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; |
254 uint32_t fmt, spd; 255 int i, error, devtype; 256 int wdevunit, rdevunit; |
257 |
258 /* Kind of impossible.. */ |
259 if (i_dev == NULL || td == NULL) 260 return ENODEV; 261 |
262 /* This too.. */ |
263 d = dsp_get_info(i_dev); |
264 if (d == NULL) 265 return EBADF; |
266 |
267 /* Lock snddev so nobody else can monkey with it. */ 268 pcm_lock(d); |
269 |
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 } |
279 |
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; |
289 |
290 if (error != 0) { 291 (void)snd_clone_release(i_dev); 292 pcm_unlock(d); 293 return error; |
294 } 295 |
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); |
301 |
302 devtype = PCMDEV(i_dev); 303 wdevunit = -1; 304 rdevunit = -1; 305 fmt = 0; 306 spd = 0; |
307 |
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; |
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 |
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 */ |
346 if (DSP_F_READ(flags)) { |
347 /* open for read */ 348 pcm_unlock(d); |
349 error = pcm_chnalloc(d, &rdch, PCMDIR_REC, td->td_proc->p_pid, 350 rdevunit); |
351 |
352 if (error == 0 && (chn_reset(rdch, fmt) != 0 || 353 (chn_setspeed(rdch, spd) != 0))) |
354 error = ENODEV; 355 356 if (error != 0) { |
357 if (rdch != NULL) |
358 pcm_chnrelease(rdch); |
359 pcm_lock(d); 360 (void)snd_clone_release(i_dev); 361 PCMDEV_RELEASE(i_dev); 362 pcm_unlock(d); |
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 |
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); |
378 |
379 if (error == 0 && (chn_reset(wrch, fmt) != 0 || 380 (chn_setspeed(wrch, spd) != 0))) 381 error = ENODEV; |
382 |
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; |
400 } 401 |
402 if (flags & O_NONBLOCK) 403 wrch->flags |= CHN_F_NBIO; 404 pcm_chnref(wrch, 1); 405 CHN_UNLOCK(wrch); 406 pcm_lock(d); |
407 } 408 |
409 /* 410 * Increase clone refcount for its automatic garbage collector. 411 */ 412 (void)snd_clone_ref(i_dev); |
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 |
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; |
435 pcm_lock(d); |
436 rdch = PCM_RDCH(i_dev); 437 wrch = PCM_WRCH(i_dev); |
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); |
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) |
487 PCM_RDCH(i_dev) = NULL; |
488 if (wrch) |
489 PCM_WRCH(i_dev) = NULL; |
490 /* 491 * If there are no more references, release the channels. 492 */ |
493 if (refs == 0 && PCM_RDCH(i_dev) == NULL && 494 PCM_WRCH(i_dev) == NULL) { |
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); |
508 } |
509 } 510 |
511 pcm_unlock(d); |
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 |
529 if (rdch == NULL || !(rdch->flags & CHN_F_BUSY)) 530 return EBADF; |
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 |
552 if (wrch == NULL || !(wrch->flags & CHN_F_BUSY)) 553 return EBADF; |
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; |
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; |
643 |
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 |
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 |
1682static void |
1683dsp_clone(void *arg, 1684#if __FreeBSD_version >= 600034 1685 struct ucred *cred, 1686#endif 1687 char *name, int namelen, struct cdev **dev) |
1688{ |
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; |
1694 |
1695 KASSERT(dsp_umax >= 0 && dsp_cmax >= 0, ("Uninitialized unit!")); 1696 |
1697 if (*dev != NULL) 1698 return; |
1699 |
1700 unit = -1; |
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) |
1717 unit = snd_unit; |
1718 else if (dsp_stdclone(name, devname, devsep, 1719 dsp_cdevs[i].use_sep, &unit, &cunit) != 0) { 1720 unit = -1; 1721 cunit = -1; |
1722 } 1723 } |
1724 1725 d = devclass_get_softc(pcm_devclass, unit); 1726 if (d == NULL || d->clones == NULL) |
1727 return; 1728 |
1729 pcm_lock(d); 1730 if (snd_clone_disabled(d->clones)) { 1731 pcm_unlock(d); |
1732 return; |
1733 } |
1734 |
1735 udcmask = snd_u2unit(unit) | snd_d2unit(devtype); |
1736 |
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); |
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; |
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); |
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; |
1823 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000); 1824} 1825 1826static void 1827dsp_sysuninit(void *p) 1828{ |
1829 if (dsp_ehtag == NULL) 1830 return; 1831 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag); 1832 dsp_ehtag = NULL; |
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 |
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{ |
1894 struct pcmchan_caps *caps; 1895 struct pcm_channel *ch; 1896 struct snddev_info *d; |
1897 uint32_t fmts; 1898 int i, nchan, ret, *rates, minch, maxch; |
1899 char *devname, buf[CHN_NAMELEN]; |
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; |
1910 devname = NULL; |
1911 nchan = 0; 1912 ret = 0; |
1913 bzero(buf, sizeof(buf)); 1914 |
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 |
1929 CHN_FOREACH(ch, d, channels.pcm) { |
1930 mtx_assert(ch->lock, MA_NOTOWNED); 1931 CHN_LOCK(ch); 1932 if (ai->dev == -1) { |
1933 if ((ch == PCM_RDCH(i_dev)) || /* record ch */ 1934 (ch == PCM_WRCH(i_dev))) { /* playback ch */ 1935 devname = i_dev->si_name; |
1936 goto dspfound; 1937 } 1938 } else if (ai->dev == nchan) { |
1939 devname = dsp_unit2name(buf, sizeof(buf), 1940 ch->unit); |
1941 goto dspfound; 1942 } 1943 CHN_UNLOCK(ch); |
1944 /* 1945 * XXX I really doubt if this is correct. 1946 */ |
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 */ |
1959 if (devname == NULL) { |
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; |
1996 |
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; |
2059 strlcpy(ai->devnode, devname, sizeof(ai->devnode)); |
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; |
2283 |
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 --- |