1 /*- 2 * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org> 3 * Portions Copyright (c) Ryan Beasley <ryan.beasley@gmail.com> - GSoC 2006 4 * Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org> 5 * Copyright (c) 1997 Luigi Rizzo 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifdef HAVE_KERNEL_OPTION_HEADERS 31 #include "opt_snd.h" 32 #endif 33 34 #include <dev/sound/pcm/sound.h> 35 #include <dev/sound/pcm/ac97.h> 36 #include <dev/sound/pcm/vchan.h> 37 #include <dev/sound/pcm/dsp.h> 38 #include <dev/sound/pcm/sndstat.h> 39 #include <dev/sound/version.h> 40 #include <sys/limits.h> 41 #include <sys/sysctl.h> 42 43 #include "feeder_if.h" 44 45 SND_DECLARE_FILE("$FreeBSD$"); 46 47 devclass_t pcm_devclass; 48 49 int pcm_veto_load = 1; 50 51 int snd_unit = -1; 52 TUNABLE_INT("hw.snd.default_unit", &snd_unit); 53 54 static int snd_unit_auto = -1; 55 TUNABLE_INT("hw.snd.default_auto", &snd_unit_auto); 56 SYSCTL_INT(_hw_snd, OID_AUTO, default_auto, CTLFLAG_RW, 57 &snd_unit_auto, 0, "assign default unit to a newly attached device"); 58 59 int snd_maxautovchans = 16; 60 /* XXX: a tunable implies that we may need more than one sound channel before 61 the system can change a sysctl (/etc/sysctl.conf), do we really need 62 this? */ 63 TUNABLE_INT("hw.snd.maxautovchans", &snd_maxautovchans); 64 65 SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD, 0, "Sound driver"); 66 67 /* 68 * XXX I've had enough with people not telling proper version/arch 69 * while reporting problems, not after 387397913213th questions/requests. 70 */ 71 static char snd_driver_version[] = 72 __XSTRING(SND_DRV_VERSION)"/"MACHINE_ARCH; 73 SYSCTL_STRING(_hw_snd, OID_AUTO, version, CTLFLAG_RD, &snd_driver_version, 74 0, "driver version/arch"); 75 76 /** 77 * @brief Unit number allocator for syncgroup IDs 78 */ 79 struct unrhdr *pcmsg_unrhdr = NULL; 80 81 static int 82 sndstat_prepare_pcm(SNDSTAT_PREPARE_PCM_ARGS) 83 { 84 SNDSTAT_PREPARE_PCM_BEGIN(); 85 SNDSTAT_PREPARE_PCM_END(); 86 } 87 88 void * 89 snd_mtxcreate(const char *desc, const char *type) 90 { 91 struct mtx *m; 92 93 m = malloc(sizeof(*m), M_DEVBUF, M_WAITOK | M_ZERO); 94 mtx_init(m, desc, type, MTX_DEF); 95 return m; 96 } 97 98 void 99 snd_mtxfree(void *m) 100 { 101 struct mtx *mtx = m; 102 103 mtx_destroy(mtx); 104 free(mtx, M_DEVBUF); 105 } 106 107 void 108 snd_mtxassert(void *m) 109 { 110 #ifdef INVARIANTS 111 struct mtx *mtx = m; 112 113 mtx_assert(mtx, MA_OWNED); 114 #endif 115 } 116 117 int 118 snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep) 119 { 120 struct snddev_info *d; 121 122 flags &= INTR_MPSAFE; 123 flags |= INTR_TYPE_AV; 124 d = device_get_softc(dev); 125 if (d != NULL && (flags & INTR_MPSAFE)) 126 d->flags |= SD_F_MPSAFE; 127 128 return bus_setup_intr(dev, res, flags, 129 #if __FreeBSD_version >= 700031 130 NULL, 131 #endif 132 hand, param, cookiep); 133 } 134 135 static void 136 pcm_clonereset(struct snddev_info *d) 137 { 138 int cmax; 139 140 PCM_BUSYASSERT(d); 141 142 cmax = d->playcount + d->reccount - 1; 143 if (d->pvchancount > 0) 144 cmax += max(d->pvchancount, snd_maxautovchans) - 1; 145 if (d->rvchancount > 0) 146 cmax += max(d->rvchancount, snd_maxautovchans) - 1; 147 if (cmax > PCMMAXCLONE) 148 cmax = PCMMAXCLONE; 149 (void)snd_clone_gc(d->clones); 150 (void)snd_clone_setmaxunit(d->clones, cmax); 151 } 152 153 int 154 pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num) 155 { 156 struct pcm_channel *c, *ch, *nch; 157 struct pcmchan_caps *caps; 158 int i, err, vcnt; 159 160 PCM_BUSYASSERT(d); 161 162 if ((direction == PCMDIR_PLAY && d->playcount < 1) || 163 (direction == PCMDIR_REC && d->reccount < 1)) 164 return (ENODEV); 165 166 if (!(d->flags & SD_F_AUTOVCHAN)) 167 return (EINVAL); 168 169 if (newcnt < 0 || newcnt > SND_MAXVCHANS) 170 return (E2BIG); 171 172 if (direction == PCMDIR_PLAY) 173 vcnt = d->pvchancount; 174 else if (direction == PCMDIR_REC) 175 vcnt = d->rvchancount; 176 else 177 return (EINVAL); 178 179 if (newcnt > vcnt) { 180 KASSERT(num == -1 || 181 (num >= 0 && num < SND_MAXVCHANS && (newcnt - 1) == vcnt), 182 ("bogus vchan_create() request num=%d newcnt=%d vcnt=%d", 183 num, newcnt, vcnt)); 184 /* add new vchans - find a parent channel first */ 185 ch = NULL; 186 CHN_FOREACH(c, d, channels.pcm) { 187 CHN_LOCK(c); 188 if (c->direction == direction && 189 ((c->flags & CHN_F_HAS_VCHAN) || (vcnt == 0 && 190 c->refcount < 1 && 191 !(c->flags & (CHN_F_BUSY | CHN_F_VIRTUAL))))) { 192 /* 193 * Reuse hw channel with vchans already 194 * created. 195 */ 196 if (c->flags & CHN_F_HAS_VCHAN) { 197 ch = c; 198 break; 199 } 200 /* 201 * No vchans ever created, look for 202 * channels with supported formats. 203 */ 204 caps = chn_getcaps(c); 205 if (caps == NULL) { 206 CHN_UNLOCK(c); 207 continue; 208 } 209 for (i = 0; caps->fmtlist[i] != 0; i++) { 210 if (caps->fmtlist[i] & AFMT_CONVERTIBLE) 211 break; 212 } 213 if (caps->fmtlist[i] != 0) { 214 ch = c; 215 break; 216 } 217 } 218 CHN_UNLOCK(c); 219 } 220 if (ch == NULL) 221 return (EBUSY); 222 ch->flags |= CHN_F_BUSY; 223 err = 0; 224 while (err == 0 && newcnt > vcnt) { 225 err = vchan_create(ch, num); 226 if (err == 0) 227 vcnt++; 228 else if (err == E2BIG && newcnt > vcnt) 229 device_printf(d->dev, 230 "%s: err=%d Maximum channel reached.\n", 231 __func__, err); 232 } 233 if (vcnt == 0) 234 ch->flags &= ~CHN_F_BUSY; 235 CHN_UNLOCK(ch); 236 if (err != 0) 237 return (err); 238 else 239 pcm_clonereset(d); 240 } else if (newcnt < vcnt) { 241 KASSERT(num == -1, 242 ("bogus vchan_destroy() request num=%d", num)); 243 CHN_FOREACH(c, d, channels.pcm) { 244 CHN_LOCK(c); 245 if (c->direction != direction || 246 CHN_EMPTY(c, children) || 247 !(c->flags & CHN_F_HAS_VCHAN)) { 248 CHN_UNLOCK(c); 249 continue; 250 } 251 CHN_FOREACH_SAFE(ch, c, nch, children) { 252 CHN_LOCK(ch); 253 if (vcnt == 1 && c->refcount > 0) { 254 CHN_UNLOCK(ch); 255 break; 256 } 257 if (!(ch->flags & CHN_F_BUSY) && 258 ch->refcount < 1) { 259 err = vchan_destroy(ch); 260 if (err == 0) 261 vcnt--; 262 } else 263 CHN_UNLOCK(ch); 264 if (vcnt == newcnt) 265 break; 266 } 267 CHN_UNLOCK(c); 268 break; 269 } 270 pcm_clonereset(d); 271 } 272 273 return (0); 274 } 275 276 /* return error status and a locked channel */ 277 int 278 pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, 279 pid_t pid, char *comm, int devunit) 280 { 281 struct pcm_channel *c; 282 int err, vchancount, vchan_num; 283 284 KASSERT(d != NULL && ch != NULL && (devunit == -1 || 285 !(devunit & ~(SND_U_MASK | SND_D_MASK | SND_C_MASK))) && 286 (direction == PCMDIR_PLAY || direction == PCMDIR_REC), 287 ("%s(): invalid d=%p ch=%p direction=%d pid=%d devunit=%d", 288 __func__, d, ch, direction, pid, devunit)); 289 PCM_BUSYASSERT(d); 290 291 /* Double check again. */ 292 if (devunit != -1) { 293 switch (snd_unit2d(devunit)) { 294 case SND_DEV_DSPHW_PLAY: 295 case SND_DEV_DSPHW_VPLAY: 296 if (direction != PCMDIR_PLAY) 297 return (ENOTSUP); 298 break; 299 case SND_DEV_DSPHW_REC: 300 case SND_DEV_DSPHW_VREC: 301 if (direction != PCMDIR_REC) 302 return (ENOTSUP); 303 break; 304 default: 305 if (!(direction == PCMDIR_PLAY || 306 direction == PCMDIR_REC)) 307 return (ENOTSUP); 308 break; 309 } 310 } 311 312 *ch = NULL; 313 vchan_num = 0; 314 vchancount = (direction == PCMDIR_PLAY) ? d->pvchancount : 315 d->rvchancount; 316 317 retry_chnalloc: 318 err = ENOTSUP; 319 /* scan for a free channel */ 320 CHN_FOREACH(c, d, channels.pcm) { 321 CHN_LOCK(c); 322 if (devunit == -1 && c->direction == direction && 323 (c->flags & CHN_F_VIRTUAL)) { 324 if (vchancount < snd_maxautovchans && 325 vchan_num < CHN_CHAN(c)) { 326 CHN_UNLOCK(c); 327 goto vchan_alloc; 328 } 329 vchan_num++; 330 } 331 if (c->direction == direction && !(c->flags & CHN_F_BUSY) && 332 (devunit == -1 || devunit == -2 || c->unit == devunit)) { 333 c->flags |= CHN_F_BUSY; 334 c->pid = pid; 335 strlcpy(c->comm, (comm != NULL) ? comm : 336 CHN_COMM_UNKNOWN, sizeof(c->comm)); 337 *ch = c; 338 return (0); 339 } else if (c->unit == devunit) { 340 if (c->direction != direction) 341 err = ENOTSUP; 342 else if (c->flags & CHN_F_BUSY) 343 err = EBUSY; 344 else 345 err = EINVAL; 346 CHN_UNLOCK(c); 347 return (err); 348 } else if ((devunit == -1 || devunit == -2) && 349 c->direction == direction && (c->flags & CHN_F_BUSY)) 350 err = EBUSY; 351 CHN_UNLOCK(c); 352 } 353 354 if (devunit == -2) 355 return (err); 356 357 vchan_alloc: 358 /* no channel available */ 359 if (devunit == -1 || snd_unit2d(devunit) == SND_DEV_DSPHW_VPLAY || 360 snd_unit2d(devunit) == SND_DEV_DSPHW_VREC) { 361 if (!(vchancount > 0 && vchancount < snd_maxautovchans) && 362 (devunit == -1 || snd_unit2c(devunit) < snd_maxautovchans)) 363 return (err); 364 err = pcm_setvchans(d, direction, vchancount + 1, 365 (devunit == -1) ? -1 : snd_unit2c(devunit)); 366 if (err == 0) { 367 if (devunit == -1) 368 devunit = -2; 369 goto retry_chnalloc; 370 } 371 } 372 373 return (err); 374 } 375 376 /* release a locked channel and unlock it */ 377 int 378 pcm_chnrelease(struct pcm_channel *c) 379 { 380 PCM_BUSYASSERT(c->parentsnddev); 381 CHN_LOCKASSERT(c); 382 383 c->flags &= ~CHN_F_BUSY; 384 c->pid = -1; 385 strlcpy(c->comm, CHN_COMM_UNUSED, sizeof(c->comm)); 386 CHN_UNLOCK(c); 387 388 return (0); 389 } 390 391 int 392 pcm_chnref(struct pcm_channel *c, int ref) 393 { 394 PCM_BUSYASSERT(c->parentsnddev); 395 CHN_LOCKASSERT(c); 396 397 c->refcount += ref; 398 399 return (c->refcount); 400 } 401 402 int 403 pcm_inprog(struct snddev_info *d, int delta) 404 { 405 PCM_LOCKASSERT(d); 406 407 d->inprog += delta; 408 409 return (d->inprog); 410 } 411 412 static void 413 pcm_setmaxautovchans(struct snddev_info *d, int num) 414 { 415 PCM_BUSYASSERT(d); 416 417 if (num < 0) 418 return; 419 420 if (num >= 0 && d->pvchancount > num) 421 (void)pcm_setvchans(d, PCMDIR_PLAY, num, -1); 422 else if (num > 0 && d->pvchancount == 0) 423 (void)pcm_setvchans(d, PCMDIR_PLAY, 1, -1); 424 425 if (num >= 0 && d->rvchancount > num) 426 (void)pcm_setvchans(d, PCMDIR_REC, num, -1); 427 else if (num > 0 && d->rvchancount == 0) 428 (void)pcm_setvchans(d, PCMDIR_REC, 1, -1); 429 430 pcm_clonereset(d); 431 } 432 433 static int 434 sysctl_hw_snd_default_unit(SYSCTL_HANDLER_ARGS) 435 { 436 struct snddev_info *d; 437 int error, unit; 438 439 unit = snd_unit; 440 error = sysctl_handle_int(oidp, &unit, 0, req); 441 if (error == 0 && req->newptr != NULL) { 442 d = devclass_get_softc(pcm_devclass, unit); 443 if (!PCM_REGISTERED(d) || CHN_EMPTY(d, channels.pcm)) 444 return EINVAL; 445 snd_unit = unit; 446 snd_unit_auto = 0; 447 } 448 return (error); 449 } 450 /* XXX: do we need a way to let the user change the default unit? */ 451 SYSCTL_PROC(_hw_snd, OID_AUTO, default_unit, 452 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY, 453 0, sizeof(int), sysctl_hw_snd_default_unit, "I", 454 "default sound device"); 455 456 static int 457 sysctl_hw_snd_maxautovchans(SYSCTL_HANDLER_ARGS) 458 { 459 struct snddev_info *d; 460 int i, v, error; 461 462 v = snd_maxautovchans; 463 error = sysctl_handle_int(oidp, &v, 0, req); 464 if (error == 0 && req->newptr != NULL) { 465 if (v < 0) 466 v = 0; 467 if (v > SND_MAXVCHANS) 468 v = SND_MAXVCHANS; 469 snd_maxautovchans = v; 470 for (i = 0; pcm_devclass != NULL && 471 i < devclass_get_maxunit(pcm_devclass); i++) { 472 d = devclass_get_softc(pcm_devclass, i); 473 if (!PCM_REGISTERED(d)) 474 continue; 475 PCM_ACQUIRE_QUICK(d); 476 pcm_setmaxautovchans(d, v); 477 PCM_RELEASE_QUICK(d); 478 } 479 } 480 return (error); 481 } 482 SYSCTL_PROC(_hw_snd, OID_AUTO, maxautovchans, CTLTYPE_INT | CTLFLAG_RW, 483 0, sizeof(int), sysctl_hw_snd_maxautovchans, "I", "maximum virtual channel"); 484 485 struct pcm_channel * 486 pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo) 487 { 488 struct pcm_channel *ch; 489 int direction, err, rpnum, *pnum, max; 490 int udc, device, chan; 491 char *dirs, *devname, buf[CHN_NAMELEN]; 492 493 PCM_BUSYASSERT(d); 494 PCM_LOCKASSERT(d); 495 KASSERT(num >= -1, ("invalid num=%d", num)); 496 497 498 switch (dir) { 499 case PCMDIR_PLAY: 500 dirs = "play"; 501 direction = PCMDIR_PLAY; 502 pnum = &d->playcount; 503 device = SND_DEV_DSPHW_PLAY; 504 max = SND_MAXHWCHAN; 505 break; 506 case PCMDIR_PLAY_VIRTUAL: 507 dirs = "virtual"; 508 direction = PCMDIR_PLAY; 509 pnum = &d->pvchancount; 510 device = SND_DEV_DSPHW_VPLAY; 511 max = SND_MAXVCHANS; 512 break; 513 case PCMDIR_REC: 514 dirs = "record"; 515 direction = PCMDIR_REC; 516 pnum = &d->reccount; 517 device = SND_DEV_DSPHW_REC; 518 max = SND_MAXHWCHAN; 519 break; 520 case PCMDIR_REC_VIRTUAL: 521 dirs = "virtual"; 522 direction = PCMDIR_REC; 523 pnum = &d->rvchancount; 524 device = SND_DEV_DSPHW_VREC; 525 max = SND_MAXVCHANS; 526 break; 527 default: 528 return (NULL); 529 } 530 531 chan = (num == -1) ? 0 : num; 532 533 if (*pnum >= max || chan >= max) 534 return (NULL); 535 536 rpnum = 0; 537 538 CHN_FOREACH(ch, d, channels.pcm) { 539 if (CHN_DEV(ch) != device) 540 continue; 541 if (chan == CHN_CHAN(ch)) { 542 if (num != -1) { 543 device_printf(d->dev, 544 "channel num=%d allocated!\n", chan); 545 return (NULL); 546 } 547 chan++; 548 if (chan >= max) { 549 device_printf(d->dev, 550 "chan=%d > %d\n", chan, max); 551 return (NULL); 552 } 553 } 554 rpnum++; 555 } 556 557 if (*pnum != rpnum) { 558 device_printf(d->dev, 559 "%s(): WARNING: pnum screwed : dirs=%s pnum=%d rpnum=%d\n", 560 __func__, dirs, *pnum, rpnum); 561 return (NULL); 562 } 563 564 udc = snd_mkunit(device_get_unit(d->dev), device, chan); 565 devname = dsp_unit2name(buf, sizeof(buf), udc); 566 567 if (devname == NULL) { 568 device_printf(d->dev, 569 "Failed to query device name udc=0x%08x\n", udc); 570 return (NULL); 571 } 572 573 PCM_UNLOCK(d); 574 ch = malloc(sizeof(*ch), M_DEVBUF, M_WAITOK | M_ZERO); 575 ch->methods = kobj_create(cls, M_DEVBUF, M_WAITOK | M_ZERO); 576 ch->unit = udc; 577 ch->pid = -1; 578 strlcpy(ch->comm, CHN_COMM_UNUSED, sizeof(ch->comm)); 579 ch->parentsnddev = d; 580 ch->parentchannel = parent; 581 ch->dev = d->dev; 582 ch->trigger = PCMTRIG_STOP; 583 snprintf(ch->name, sizeof(ch->name), "%s:%s:%s", 584 device_get_nameunit(ch->dev), dirs, devname); 585 586 err = chn_init(ch, devinfo, dir, direction); 587 PCM_LOCK(d); 588 if (err) { 589 device_printf(d->dev, "chn_init(%s) failed: err = %d\n", 590 ch->name, err); 591 kobj_delete(ch->methods, M_DEVBUF); 592 free(ch, M_DEVBUF); 593 return (NULL); 594 } 595 596 return (ch); 597 } 598 599 int 600 pcm_chn_destroy(struct pcm_channel *ch) 601 { 602 struct snddev_info *d; 603 int err; 604 605 d = ch->parentsnddev; 606 PCM_BUSYASSERT(d); 607 608 err = chn_kill(ch); 609 if (err) { 610 device_printf(ch->dev, "chn_kill(%s) failed, err = %d\n", 611 ch->name, err); 612 return (err); 613 } 614 615 kobj_delete(ch->methods, M_DEVBUF); 616 free(ch, M_DEVBUF); 617 618 return (0); 619 } 620 621 int 622 pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch) 623 { 624 PCM_BUSYASSERT(d); 625 PCM_LOCKASSERT(d); 626 KASSERT(ch != NULL && (ch->direction == PCMDIR_PLAY || 627 ch->direction == PCMDIR_REC), ("Invalid pcm channel")); 628 629 CHN_INSERT_SORT_ASCEND(d, ch, channels.pcm); 630 631 switch (CHN_DEV(ch)) { 632 case SND_DEV_DSPHW_PLAY: 633 d->playcount++; 634 break; 635 case SND_DEV_DSPHW_VPLAY: 636 d->pvchancount++; 637 break; 638 case SND_DEV_DSPHW_REC: 639 d->reccount++; 640 break; 641 case SND_DEV_DSPHW_VREC: 642 d->rvchancount++; 643 break; 644 default: 645 break; 646 } 647 648 d->devcount++; 649 650 return (0); 651 } 652 653 int 654 pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch) 655 { 656 struct pcm_channel *tmp; 657 658 PCM_BUSYASSERT(d); 659 PCM_LOCKASSERT(d); 660 661 tmp = NULL; 662 663 CHN_FOREACH(tmp, d, channels.pcm) { 664 if (tmp == ch) 665 break; 666 } 667 668 if (tmp != ch) 669 return (EINVAL); 670 671 CHN_REMOVE(d, ch, channels.pcm); 672 673 switch (CHN_DEV(ch)) { 674 case SND_DEV_DSPHW_PLAY: 675 d->playcount--; 676 break; 677 case SND_DEV_DSPHW_VPLAY: 678 d->pvchancount--; 679 break; 680 case SND_DEV_DSPHW_REC: 681 d->reccount--; 682 break; 683 case SND_DEV_DSPHW_VREC: 684 d->rvchancount--; 685 break; 686 default: 687 break; 688 } 689 690 d->devcount--; 691 692 return (0); 693 } 694 695 int 696 pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo) 697 { 698 struct snddev_info *d = device_get_softc(dev); 699 struct pcm_channel *ch; 700 int err; 701 702 PCM_BUSYASSERT(d); 703 704 PCM_LOCK(d); 705 ch = pcm_chn_create(d, NULL, cls, dir, -1, devinfo); 706 if (!ch) { 707 device_printf(d->dev, "pcm_chn_create(%s, %d, %p) failed\n", 708 cls->name, dir, devinfo); 709 PCM_UNLOCK(d); 710 return (ENODEV); 711 } 712 713 err = pcm_chn_add(d, ch); 714 PCM_UNLOCK(d); 715 if (err) { 716 device_printf(d->dev, "pcm_chn_add(%s) failed, err=%d\n", 717 ch->name, err); 718 pcm_chn_destroy(ch); 719 } 720 721 return (err); 722 } 723 724 static int 725 pcm_killchan(device_t dev) 726 { 727 struct snddev_info *d = device_get_softc(dev); 728 struct pcm_channel *ch; 729 int error; 730 731 PCM_BUSYASSERT(d); 732 733 ch = CHN_FIRST(d, channels.pcm); 734 735 PCM_LOCK(d); 736 error = pcm_chn_remove(d, ch); 737 PCM_UNLOCK(d); 738 if (error) 739 return (error); 740 return (pcm_chn_destroy(ch)); 741 } 742 743 static int 744 pcm_best_unit(int old) 745 { 746 struct snddev_info *d; 747 int i, best, bestprio, prio; 748 749 best = -1; 750 bestprio = -100; 751 for (i = 0; pcm_devclass != NULL && 752 i < devclass_get_maxunit(pcm_devclass); i++) { 753 d = devclass_get_softc(pcm_devclass, i); 754 if (!PCM_REGISTERED(d)) 755 continue; 756 prio = 0; 757 if (d->playcount == 0) 758 prio -= 10; 759 if (d->reccount == 0) 760 prio -= 2; 761 if (prio > bestprio || (prio == bestprio && i == old)) { 762 best = i; 763 bestprio = prio; 764 } 765 } 766 return (best); 767 } 768 769 int 770 pcm_setstatus(device_t dev, char *str) 771 { 772 struct snddev_info *d = device_get_softc(dev); 773 774 PCM_BUSYASSERT(d); 775 776 if (d->playcount == 0 || d->reccount == 0) 777 d->flags |= SD_F_SIMPLEX; 778 779 if ((d->playcount > 0 || d->reccount > 0) && 780 !(d->flags & SD_F_AUTOVCHAN)) { 781 d->flags |= SD_F_AUTOVCHAN; 782 vchan_initsys(dev); 783 } 784 785 pcm_setmaxautovchans(d, snd_maxautovchans); 786 787 strlcpy(d->status, str, SND_STATUSLEN); 788 789 PCM_LOCK(d); 790 791 /* Last stage, enable cloning. */ 792 if (d->clones != NULL) 793 (void)snd_clone_enable(d->clones); 794 795 /* Done, we're ready.. */ 796 d->flags |= SD_F_REGISTERED; 797 798 PCM_RELEASE(d); 799 800 PCM_UNLOCK(d); 801 802 if (snd_unit_auto < 0) 803 snd_unit_auto = (snd_unit < 0) ? 1 : 0; 804 if (snd_unit < 0 || snd_unit_auto > 1) 805 snd_unit = device_get_unit(dev); 806 else if (snd_unit_auto == 1) 807 snd_unit = pcm_best_unit(snd_unit); 808 809 return (0); 810 } 811 812 uint32_t 813 pcm_getflags(device_t dev) 814 { 815 struct snddev_info *d = device_get_softc(dev); 816 817 return d->flags; 818 } 819 820 void 821 pcm_setflags(device_t dev, uint32_t val) 822 { 823 struct snddev_info *d = device_get_softc(dev); 824 825 d->flags = val; 826 } 827 828 void * 829 pcm_getdevinfo(device_t dev) 830 { 831 struct snddev_info *d = device_get_softc(dev); 832 833 return d->devinfo; 834 } 835 836 unsigned int 837 pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz) 838 { 839 struct snddev_info *d = device_get_softc(dev); 840 int sz, x; 841 842 sz = 0; 843 if (resource_int_value(device_get_name(dev), device_get_unit(dev), "buffersize", &sz) == 0) { 844 x = sz; 845 RANGE(sz, minbufsz, maxbufsz); 846 if (x != sz) 847 device_printf(dev, "'buffersize=%d' hint is out of range (%d-%d), using %d\n", x, minbufsz, maxbufsz, sz); 848 x = minbufsz; 849 while (x < sz) 850 x <<= 1; 851 if (x > sz) 852 x >>= 1; 853 if (x != sz) { 854 device_printf(dev, "'buffersize=%d' hint is not a power of 2, using %d\n", sz, x); 855 sz = x; 856 } 857 } else { 858 sz = deflt; 859 } 860 861 d->bufsz = sz; 862 863 return sz; 864 } 865 866 static int 867 sysctl_dev_pcm_bitperfect(SYSCTL_HANDLER_ARGS) 868 { 869 struct snddev_info *d; 870 int err, val; 871 872 d = oidp->oid_arg1; 873 if (!PCM_REGISTERED(d)) 874 return (ENODEV); 875 876 PCM_LOCK(d); 877 PCM_WAIT(d); 878 val = (d->flags & SD_F_BITPERFECT) ? 1 : 0; 879 PCM_ACQUIRE(d); 880 PCM_UNLOCK(d); 881 882 err = sysctl_handle_int(oidp, &val, 0, req); 883 884 if (err == 0 && req->newptr != NULL) { 885 if (!(val == 0 || val == 1)) { 886 PCM_RELEASE_QUICK(d); 887 return (EINVAL); 888 } 889 890 PCM_LOCK(d); 891 892 d->flags &= ~SD_F_BITPERFECT; 893 d->flags |= (val != 0) ? SD_F_BITPERFECT : 0; 894 895 PCM_RELEASE(d); 896 PCM_UNLOCK(d); 897 } else 898 PCM_RELEASE_QUICK(d); 899 900 return (err); 901 } 902 903 #ifdef SND_DEBUG 904 static int 905 sysctl_dev_pcm_clone_flags(SYSCTL_HANDLER_ARGS) 906 { 907 struct snddev_info *d; 908 uint32_t flags; 909 int err; 910 911 d = oidp->oid_arg1; 912 if (!PCM_REGISTERED(d) || d->clones == NULL) 913 return (ENODEV); 914 915 PCM_ACQUIRE_QUICK(d); 916 917 flags = snd_clone_getflags(d->clones); 918 err = sysctl_handle_int(oidp, &flags, 0, req); 919 920 if (err == 0 && req->newptr != NULL) { 921 if (flags & ~SND_CLONE_MASK) 922 err = EINVAL; 923 else 924 (void)snd_clone_setflags(d->clones, flags); 925 } 926 927 PCM_RELEASE_QUICK(d); 928 929 return (err); 930 } 931 932 static int 933 sysctl_dev_pcm_clone_deadline(SYSCTL_HANDLER_ARGS) 934 { 935 struct snddev_info *d; 936 int err, deadline; 937 938 d = oidp->oid_arg1; 939 if (!PCM_REGISTERED(d) || d->clones == NULL) 940 return (ENODEV); 941 942 PCM_ACQUIRE_QUICK(d); 943 944 deadline = snd_clone_getdeadline(d->clones); 945 err = sysctl_handle_int(oidp, &deadline, 0, req); 946 947 if (err == 0 && req->newptr != NULL) { 948 if (deadline < 0) 949 err = EINVAL; 950 else 951 (void)snd_clone_setdeadline(d->clones, deadline); 952 } 953 954 PCM_RELEASE_QUICK(d); 955 956 return (err); 957 } 958 959 static int 960 sysctl_dev_pcm_clone_gc(SYSCTL_HANDLER_ARGS) 961 { 962 struct snddev_info *d; 963 int err, val; 964 965 d = oidp->oid_arg1; 966 if (!PCM_REGISTERED(d) || d->clones == NULL) 967 return (ENODEV); 968 969 val = 0; 970 err = sysctl_handle_int(oidp, &val, 0, req); 971 972 if (err == 0 && req->newptr != NULL && val != 0) { 973 PCM_ACQUIRE_QUICK(d); 974 val = snd_clone_gc(d->clones); 975 PCM_RELEASE_QUICK(d); 976 if (bootverbose != 0 || snd_verbose > 3) 977 device_printf(d->dev, "clone gc: pruned=%d\n", val); 978 } 979 980 return (err); 981 } 982 983 static int 984 sysctl_hw_snd_clone_gc(SYSCTL_HANDLER_ARGS) 985 { 986 struct snddev_info *d; 987 int i, err, val; 988 989 val = 0; 990 err = sysctl_handle_int(oidp, &val, 0, req); 991 992 if (err == 0 && req->newptr != NULL && val != 0) { 993 for (i = 0; pcm_devclass != NULL && 994 i < devclass_get_maxunit(pcm_devclass); i++) { 995 d = devclass_get_softc(pcm_devclass, i); 996 if (!PCM_REGISTERED(d) || d->clones == NULL) 997 continue; 998 PCM_ACQUIRE_QUICK(d); 999 val = snd_clone_gc(d->clones); 1000 PCM_RELEASE_QUICK(d); 1001 if (bootverbose != 0 || snd_verbose > 3) 1002 device_printf(d->dev, "clone gc: pruned=%d\n", 1003 val); 1004 } 1005 } 1006 1007 return (err); 1008 } 1009 SYSCTL_PROC(_hw_snd, OID_AUTO, clone_gc, CTLTYPE_INT | CTLFLAG_RW, 1010 0, sizeof(int), sysctl_hw_snd_clone_gc, "I", 1011 "global clone garbage collector"); 1012 #endif 1013 1014 int 1015 pcm_register(device_t dev, void *devinfo, int numplay, int numrec) 1016 { 1017 struct snddev_info *d; 1018 int i; 1019 1020 if (pcm_veto_load) { 1021 device_printf(dev, "disabled due to an error while initialising: %d\n", pcm_veto_load); 1022 1023 return EINVAL; 1024 } 1025 1026 if (device_get_unit(dev) > PCMMAXUNIT) { 1027 device_printf(dev, "PCMMAXUNIT reached : unit=%d > %d\n", 1028 device_get_unit(dev), PCMMAXUNIT); 1029 device_printf(dev, 1030 "Use 'hw.snd.maxunit' tunable to raise the limit.\n"); 1031 return ENODEV; 1032 } 1033 1034 d = device_get_softc(dev); 1035 d->dev = dev; 1036 d->lock = snd_mtxcreate(device_get_nameunit(dev), "sound cdev"); 1037 cv_init(&d->cv, device_get_nameunit(dev)); 1038 PCM_ACQUIRE_QUICK(d); 1039 dsp_cdevinfo_init(d); 1040 #if 0 1041 /* 1042 * d->flags should be cleared by the allocator of the softc. 1043 * We cannot clear this field here because several devices set 1044 * this flag before calling pcm_register(). 1045 */ 1046 d->flags = 0; 1047 #endif 1048 i = 0; 1049 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 1050 "vpc", &i) != 0 || i != 0) 1051 d->flags |= SD_F_VPC; 1052 1053 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 1054 "bitperfect", &i) == 0 && i != 0) 1055 d->flags |= SD_F_BITPERFECT; 1056 1057 d->devinfo = devinfo; 1058 d->devcount = 0; 1059 d->reccount = 0; 1060 d->playcount = 0; 1061 d->pvchancount = 0; 1062 d->rvchancount = 0; 1063 d->pvchanrate = 0; 1064 d->pvchanformat = 0; 1065 d->rvchanrate = 0; 1066 d->rvchanformat = 0; 1067 d->inprog = 0; 1068 1069 /* 1070 * Create clone manager, disabled by default. Cloning will be 1071 * enabled during final stage of driver initialization through 1072 * pcm_setstatus(). 1073 */ 1074 d->clones = snd_clone_create(SND_U_MASK | SND_D_MASK, PCMMAXCLONE, 1075 SND_CLONE_DEADLINE_DEFAULT, SND_CLONE_WAITOK | 1076 SND_CLONE_GC_ENABLE | SND_CLONE_GC_UNREF | 1077 SND_CLONE_GC_LASTREF | SND_CLONE_GC_EXPIRED); 1078 1079 CHN_INIT(d, channels.pcm); 1080 CHN_INIT(d, channels.pcm.busy); 1081 CHN_INIT(d, channels.pcm.opened); 1082 1083 /* XXX This is incorrect, but lets play along for now. */ 1084 if ((numplay == 0 || numrec == 0) && numplay != numrec) 1085 d->flags |= SD_F_SIMPLEX; 1086 1087 sysctl_ctx_init(&d->play_sysctl_ctx); 1088 d->play_sysctl_tree = SYSCTL_ADD_NODE(&d->play_sysctl_ctx, 1089 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "play", 1090 CTLFLAG_RD, 0, "playback channels node"); 1091 sysctl_ctx_init(&d->rec_sysctl_ctx); 1092 d->rec_sysctl_tree = SYSCTL_ADD_NODE(&d->rec_sysctl_ctx, 1093 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "rec", 1094 CTLFLAG_RD, 0, "record channels node"); 1095 /* XXX: an user should be able to set this with a control tool, the 1096 sysadmin then needs min+max sysctls for this */ 1097 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1098 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1099 OID_AUTO, "buffersize", CTLFLAG_RD, &d->bufsz, 0, "allocated buffer size"); 1100 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1101 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1102 "bitperfect", CTLTYPE_INT | CTLFLAG_RW, d, sizeof(d), 1103 sysctl_dev_pcm_bitperfect, "I", 1104 "bit-perfect playback/recording (0=disable, 1=enable)"); 1105 #ifdef SND_DEBUG 1106 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1107 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1108 "clone_flags", CTLTYPE_UINT | CTLFLAG_RW, d, sizeof(d), 1109 sysctl_dev_pcm_clone_flags, "IU", 1110 "clone flags"); 1111 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1112 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1113 "clone_deadline", CTLTYPE_INT | CTLFLAG_RW, d, sizeof(d), 1114 sysctl_dev_pcm_clone_deadline, "I", 1115 "clone expiration deadline (ms)"); 1116 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1117 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1118 "clone_gc", CTLTYPE_INT | CTLFLAG_RW, d, sizeof(d), 1119 sysctl_dev_pcm_clone_gc, "I", 1120 "clone garbage collector"); 1121 #endif 1122 1123 if (numplay > 0 || numrec > 0) { 1124 d->flags |= SD_F_AUTOVCHAN; 1125 vchan_initsys(dev); 1126 } 1127 1128 if (d->flags & SD_F_EQ) 1129 feeder_eq_initsys(dev); 1130 1131 sndstat_register(dev, d->status, sndstat_prepare_pcm); 1132 1133 return 0; 1134 } 1135 1136 int 1137 pcm_unregister(device_t dev) 1138 { 1139 struct snddev_info *d; 1140 struct pcm_channel *ch; 1141 struct thread *td; 1142 1143 td = curthread; 1144 d = device_get_softc(dev); 1145 1146 if (!PCM_ALIVE(d)) { 1147 device_printf(dev, "unregister: device not configured\n"); 1148 return (0); 1149 } 1150 1151 if (sndstat_acquire(td) != 0) { 1152 device_printf(dev, "unregister: sndstat busy\n"); 1153 return (EBUSY); 1154 } 1155 1156 PCM_LOCK(d); 1157 PCM_WAIT(d); 1158 1159 if (d->inprog != 0) { 1160 device_printf(dev, "unregister: operation in progress\n"); 1161 PCM_UNLOCK(d); 1162 sndstat_release(td); 1163 return (EBUSY); 1164 } 1165 1166 PCM_ACQUIRE(d); 1167 PCM_UNLOCK(d); 1168 1169 CHN_FOREACH(ch, d, channels.pcm) { 1170 CHN_LOCK(ch); 1171 if (ch->refcount > 0) { 1172 device_printf(dev, 1173 "unregister: channel %s busy (pid %d)\n", 1174 ch->name, ch->pid); 1175 CHN_UNLOCK(ch); 1176 PCM_RELEASE_QUICK(d); 1177 sndstat_release(td); 1178 return (EBUSY); 1179 } 1180 CHN_UNLOCK(ch); 1181 } 1182 1183 if (d->clones != NULL) { 1184 if (snd_clone_busy(d->clones) != 0) { 1185 device_printf(dev, "unregister: clone busy\n"); 1186 PCM_RELEASE_QUICK(d); 1187 sndstat_release(td); 1188 return (EBUSY); 1189 } else { 1190 PCM_LOCK(d); 1191 (void)snd_clone_disable(d->clones); 1192 PCM_UNLOCK(d); 1193 } 1194 } 1195 1196 if (mixer_uninit(dev) == EBUSY) { 1197 device_printf(dev, "unregister: mixer busy\n"); 1198 PCM_LOCK(d); 1199 if (d->clones != NULL) 1200 (void)snd_clone_enable(d->clones); 1201 PCM_RELEASE(d); 1202 PCM_UNLOCK(d); 1203 sndstat_release(td); 1204 return (EBUSY); 1205 } 1206 1207 PCM_LOCK(d); 1208 d->flags |= SD_F_DYING; 1209 d->flags &= ~SD_F_REGISTERED; 1210 PCM_UNLOCK(d); 1211 1212 /* 1213 * No lock being held, so this thing can be flushed without 1214 * stucking into devdrn oblivion. 1215 */ 1216 if (d->clones != NULL) { 1217 snd_clone_destroy(d->clones); 1218 d->clones = NULL; 1219 } 1220 1221 if (d->play_sysctl_tree != NULL) { 1222 sysctl_ctx_free(&d->play_sysctl_ctx); 1223 d->play_sysctl_tree = NULL; 1224 } 1225 if (d->rec_sysctl_tree != NULL) { 1226 sysctl_ctx_free(&d->rec_sysctl_ctx); 1227 d->rec_sysctl_tree = NULL; 1228 } 1229 1230 while (!CHN_EMPTY(d, channels.pcm)) 1231 pcm_killchan(dev); 1232 1233 dsp_cdevinfo_flush(d); 1234 1235 PCM_LOCK(d); 1236 PCM_RELEASE(d); 1237 cv_destroy(&d->cv); 1238 PCM_UNLOCK(d); 1239 snd_mtxfree(d->lock); 1240 sndstat_unregister(dev); 1241 sndstat_release(td); 1242 1243 if (snd_unit == device_get_unit(dev)) { 1244 snd_unit = pcm_best_unit(-1); 1245 if (snd_unit_auto == 0) 1246 snd_unit_auto = 1; 1247 } 1248 1249 return (0); 1250 } 1251 1252 /************************************************************************/ 1253 1254 /** 1255 * @brief Handle OSSv4 SNDCTL_SYSINFO ioctl. 1256 * 1257 * @param si Pointer to oss_sysinfo struct where information about the 1258 * sound subsystem will be written/copied. 1259 * 1260 * This routine returns information about the sound system, such as the 1261 * current OSS version, number of audio, MIDI, and mixer drivers, etc. 1262 * Also includes a bitmask showing which of the above types of devices 1263 * are open (busy). 1264 * 1265 * @note 1266 * Calling threads must not hold any snddev_info or pcm_channel locks. 1267 * 1268 * @author Ryan Beasley <ryanb@FreeBSD.org> 1269 */ 1270 void 1271 sound_oss_sysinfo(oss_sysinfo *si) 1272 { 1273 static char si_product[] = "FreeBSD native OSS ABI"; 1274 static char si_version[] = __XSTRING(__FreeBSD_version); 1275 static char si_license[] = "BSD"; 1276 static int intnbits = sizeof(int) * 8; /* Better suited as macro? 1277 Must pester a C guru. */ 1278 1279 struct snddev_info *d; 1280 struct pcm_channel *c; 1281 int i, j, ncards; 1282 1283 ncards = 0; 1284 1285 strlcpy(si->product, si_product, sizeof(si->product)); 1286 strlcpy(si->version, si_version, sizeof(si->version)); 1287 si->versionnum = SOUND_VERSION; 1288 strlcpy(si->license, si_license, sizeof(si->license)); 1289 1290 /* 1291 * Iterate over PCM devices and their channels, gathering up data 1292 * for the numaudios, ncards, and openedaudio fields. 1293 */ 1294 si->numaudios = 0; 1295 bzero((void *)&si->openedaudio, sizeof(si->openedaudio)); 1296 1297 j = 0; 1298 1299 for (i = 0; pcm_devclass != NULL && 1300 i < devclass_get_maxunit(pcm_devclass); i++) { 1301 d = devclass_get_softc(pcm_devclass, i); 1302 if (!PCM_REGISTERED(d)) 1303 continue; 1304 1305 /* XXX Need Giant magic entry ??? */ 1306 1307 /* See note in function's docblock */ 1308 PCM_UNLOCKASSERT(d); 1309 PCM_LOCK(d); 1310 1311 si->numaudios += d->devcount; 1312 ++ncards; 1313 1314 CHN_FOREACH(c, d, channels.pcm) { 1315 CHN_UNLOCKASSERT(c); 1316 CHN_LOCK(c); 1317 if (c->flags & CHN_F_BUSY) 1318 si->openedaudio[j / intnbits] |= 1319 (1 << (j % intnbits)); 1320 CHN_UNLOCK(c); 1321 j++; 1322 } 1323 1324 PCM_UNLOCK(d); 1325 } 1326 si->numaudioengines = si->numaudios; 1327 1328 si->numsynths = 0; /* OSSv4 docs: this field is obsolete */ 1329 /** 1330 * @todo Collect num{midis,timers}. 1331 * 1332 * Need access to sound/midi/midi.c::midistat_lock in order 1333 * to safely touch midi_devices and get a head count of, well, 1334 * MIDI devices. midistat_lock is a global static (i.e., local to 1335 * midi.c), but midi_devices is a regular global; should the mutex 1336 * be publicized, or is there another way to get this information? 1337 * 1338 * NB: MIDI/sequencer stuff is currently on hold. 1339 */ 1340 si->nummidis = 0; 1341 si->numtimers = 0; 1342 si->nummixers = mixer_count; 1343 si->numcards = ncards; 1344 /* OSSv4 docs: Intended only for test apps; API doesn't 1345 really have much of a concept of cards. Shouldn't be 1346 used by applications. */ 1347 1348 /** 1349 * @todo Fill in "busy devices" fields. 1350 * 1351 * si->openedmidi = " MIDI devices 1352 */ 1353 bzero((void *)&si->openedmidi, sizeof(si->openedmidi)); 1354 1355 /* 1356 * Si->filler is a reserved array, but according to docs each 1357 * element should be set to -1. 1358 */ 1359 for (i = 0; i < sizeof(si->filler)/sizeof(si->filler[0]); i++) 1360 si->filler[i] = -1; 1361 } 1362 1363 int 1364 sound_oss_card_info(oss_card_info *si) 1365 { 1366 struct snddev_info *d; 1367 int i, ncards; 1368 1369 ncards = 0; 1370 1371 for (i = 0; pcm_devclass != NULL && 1372 i < devclass_get_maxunit(pcm_devclass); i++) { 1373 d = devclass_get_softc(pcm_devclass, i); 1374 if (!PCM_REGISTERED(d)) 1375 continue; 1376 1377 if (ncards++ != si->card) 1378 continue; 1379 1380 PCM_UNLOCKASSERT(d); 1381 PCM_LOCK(d); 1382 1383 strlcpy(si->shortname, device_get_nameunit(d->dev), 1384 sizeof(si->shortname)); 1385 strlcpy(si->longname, device_get_desc(d->dev), 1386 sizeof(si->longname)); 1387 strlcpy(si->hw_info, d->status, sizeof(si->hw_info)); 1388 si->intr_count = si->ack_count = 0; 1389 1390 PCM_UNLOCK(d); 1391 1392 return (0); 1393 } 1394 return (ENXIO); 1395 } 1396 1397 /************************************************************************/ 1398 1399 static int 1400 sound_modevent(module_t mod, int type, void *data) 1401 { 1402 int ret; 1403 #if 0 1404 return (midi_modevent(mod, type, data)); 1405 #else 1406 ret = 0; 1407 1408 switch(type) { 1409 case MOD_LOAD: 1410 pcmsg_unrhdr = new_unrhdr(1, INT_MAX, NULL); 1411 break; 1412 case MOD_UNLOAD: 1413 ret = sndstat_acquire(curthread); 1414 if (ret != 0) 1415 break; 1416 if (pcmsg_unrhdr != NULL) { 1417 delete_unrhdr(pcmsg_unrhdr); 1418 pcmsg_unrhdr = NULL; 1419 } 1420 break; 1421 case MOD_SHUTDOWN: 1422 break; 1423 default: 1424 ret = ENOTSUP; 1425 } 1426 1427 return ret; 1428 #endif 1429 } 1430 1431 DEV_MODULE(sound, sound_modevent, NULL); 1432 MODULE_VERSION(sound, SOUND_MODVER); 1433