From owner-p4-projects@FreeBSD.ORG Thu Jul 10 07:57:38 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 072671065686; Thu, 10 Jul 2008 07:57:38 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE6751065680 for ; Thu, 10 Jul 2008 07:57:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A82C38FC13 for ; Thu, 10 Jul 2008 07:57:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m6A7vbwL060402 for ; Thu, 10 Jul 2008 07:57:37 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6A7vbex060400 for perforce@freebsd.org; Thu, 10 Jul 2008 07:57:37 GMT (envelope-from hselasky@FreeBSD.org) Date: Thu, 10 Jul 2008 07:57:37 GMT Message-Id: <200807100757.m6A7vbex060400@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 144991 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2008 07:57:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=144991 Change 144991 by hselasky@hselasky_laptop001 on 2008/07/10 07:56:37 These patches into the USB sound system are needed to make the Giant-free USB audio driver work seamlessly. Affected files ... .. //depot/projects/usb/src/sys/dev/sound/pcm/mixer.c#10 edit .. //depot/projects/usb/src/sys/dev/sound/pcm/mixer.h#9 edit .. //depot/projects/usb/src/sys/dev/usb2/sound/uaudio2.c#6 edit .. //depot/projects/usb/src/sys/dev/usb2/sound/uaudio2_pcm.c#3 edit Differences ... ==== //depot/projects/usb/src/sys/dev/sound/pcm/mixer.c#10 (text+ko) ==== @@ -589,7 +589,7 @@ KASSERT(m->type == MIXER_TYPE_SECONDARY, ("%s(): illegal mixer type=%d", __func__, m->type)); - snd_mtxlock(m->lock); + /* mixer uninit can sleep --hps */ MIXER_UNINIT(m); @@ -712,6 +712,10 @@ mixer_setrecsrc(m, SOUND_MASK_MIC); + snd_mtxunlock(m->lock); + + /* mixer uninit can sleep --hps */ + MIXER_UNINIT(m); snd_mtxfree(m->lock); @@ -1280,3 +1284,16 @@ return (EINVAL); } + +/* + * Allow the sound driver to use the mixer lock to protect its mixer + * data: + */ +struct mtx * +mixer_get_lock(struct snd_mixer *m) +{ + if (m->lock == NULL) { + return (&Giant); + } + return (m->lock); +} ==== //depot/projects/usb/src/sys/dev/sound/pcm/mixer.h#9 (text+ko) ==== @@ -56,6 +56,7 @@ u_int32_t mix_getparent(struct snd_mixer *m, u_int32_t dev); u_int32_t mix_getchild(struct snd_mixer *m, u_int32_t dev); void *mix_getdevinfo(struct snd_mixer *m); +struct mtx *mixer_get_lock(struct snd_mixer *m); extern int mixer_count; ==== //depot/projects/usb/src/sys/dev/usb2/sound/uaudio2.c#6 (text+ko) ==== @@ -220,7 +220,6 @@ struct usb2_device *sc_udev; struct usb2_xfer *sc_mixer_xfer[1]; - struct mtx *sc_mixer_lock; struct uaudio_mixer_node *sc_mixer_root; struct uaudio_mixer_node *sc_mixer_curr; @@ -3091,12 +3090,11 @@ { DPRINTF(0, "\n"); - sc->sc_mixer_lock = mixer_get_lock(m); - if (usb2_transfer_setup(sc->sc_udev, &(sc->sc_mixer_iface_index), sc->sc_mixer_xfer, uaudio_mixer_config, 1, sc, - sc->sc_mixer_lock)) { - DPRINTF(0, "could not allocate USB transfer for audio mixer!\n"); + mixer_get_lock(m))) { + DPRINTF(-1, "could not allocate USB " + "transfer for audio mixer!\n"); return (ENOMEM); } if (!(sc->sc_mix_info & SOUND_MASK_VOLUME)) { ==== //depot/projects/usb/src/sys/dev/usb2/sound/uaudio2_pcm.c#3 (text+ko) ==== @@ -127,10 +127,18 @@ ua_mixer_set(struct snd_mixer *m, unsigned type, unsigned left, unsigned right) { struct mtx *mtx = mixer_get_lock(m); + uint8_t do_unlock; - snd_mtxlock(mtx); /* XXX */ + if (mtx_owned(mtx)) { + do_unlock = 0; + } else { + do_unlock = 1; + mtx_lock(mtx); + } uaudio_mixer_set(mix_getdevinfo(m), type, left, right); - snd_mtxunlock(mtx); /* XXX */ + if (do_unlock) { + mtx_unlock(mtx); + } return (left | (right << 8)); } @@ -139,10 +147,18 @@ { struct mtx *mtx = mixer_get_lock(m); int retval; + uint8_t do_unlock; - snd_mtxlock(mtx); /* XXX */ + if (mtx_owned(mtx)) { + do_unlock = 0; + } else { + do_unlock = 1; + mtx_lock(mtx); + } retval = uaudio_mixer_setrecsrc(mix_getdevinfo(m), src); - snd_mtxunlock(mtx); /* XXX */ + if (do_unlock) { + mtx_unlock(mtx); + } return (retval); }