From nobody Sat Jul 06 18:24:11 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WGf0q2cR5z5PMRc; Sat, 06 Jul 2024 18:24:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WGf0q1PNTz542N; Sat, 6 Jul 2024 18:24:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720290251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BYFt2LXLpTqyoxy2vPivAozE1eTNQKGSVJCnuTXd7/Q=; b=UqcGCKEACi7W1hreZpL7pW5ChtrAM9v2edoR0Uv2OodD42l44eZPV1UerOT84MPdsW8MK+ PjVaoFdd+mOaYAaOpJDWtw20pJNw5lpeqBojny2MJoigmw3lGxb2tpAusxn9cDwtdm75AP LizUGtvyKH5WnChfRqOURN1pAh15ZhVPvctHsIZOkmt8T8aiA4xpmnGkRQn2crLWESDThJ R6tzHwEQWUnWs5gHvptv3fdkdeJgwBsZUAcxBRyK7htcNgF+K6FWL0bujYHsD2iaD46cjE zAEPpcJa6T5FLrnmSc6Ds5ss0wWUXCLFq6IpP0NiWUppu/aceKZfegHCW3bU0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720290251; a=rsa-sha256; cv=none; b=s1npDRCM0BuXGIVtr35nSjmosORKGYgWSNEfQa4gjuhor9NfyHHX/H2yMzrvupwfW5Vdfk UcMJdl2tpUqa+TfnALj1VsEnfmT7RHpQgub/fNZzA9am2YHPgTP4kldWH4yCDzzUckWNeB KkdnjsJY3By+6TovagQHdJjyNnf6+O8Z74r+0agn0xgT4pAYkvzHuL4ZZATKG+7NG+TJxO FrK6cqZIfIxxOJafsg1ibf9JcKam0XJx+sYVrwAOWXH7EQTizVcaG7Dhz256XrEbkzYG7G Z3Vy03LpxoRApFBZoLgLIUjgeqY5Pc7qIPbAKRBgb4gMrLUTlAuF7Sb6lBWceg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720290251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BYFt2LXLpTqyoxy2vPivAozE1eTNQKGSVJCnuTXd7/Q=; b=npQlLkXYeBquLMkxkvZavMxtzFCyNNgiyKxmQh4duJGn8QmIx25sp6heYvz3xzi0+1E1WS h3G0bHHHkV18rvGd7wBrkxWEyRIdY5GnDeFll8A6aS8v+XCiarFiAjna6oURuKxLnTK3yR fRMRm2PkUC82QPEWorxKqeM+/t0/NvZZZb+wc0KjM/ADLzUmeqAUZ6uE245OU+mSNt5hDh icWpPv+Im1bI0G9VBvb8m3KLaaAH9itoHw4vzlTGsSRyaESbvGktfNvkoIYP8ntus2XXYl YZTzwmNXS8jIfcuHFDhUFrpuJMMA+pgv7h82dgiAFeiaoFq4k9oeowwQ5OcR2A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WGf0q0fDvzqpx; Sat, 6 Jul 2024 18:24:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 466IOBdP090752; Sat, 6 Jul 2024 18:24:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 466IOBsk090749; Sat, 6 Jul 2024 18:24:11 GMT (envelope-from git) Date: Sat, 6 Jul 2024 18:24:11 GMT Message-Id: <202407061824.466IOBsk090749@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 46e92a41cb53 - main - sound: Simplify getchns() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 46e92a41cb539e327dd059d571fa381d0fbe779c Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=46e92a41cb539e327dd059d571fa381d0fbe779c commit 46e92a41cb539e327dd059d571fa381d0fbe779c Author: Christos Margiolis AuthorDate: 2024-07-06 18:22:40 +0000 Commit: Christos Margiolis CommitDate: 2024-07-06 18:22:40 +0000 sound: Simplify getchns() Remove all special handling for SIMPLEX, since we can just fetch the channel directly. While here: - Get rid of a no-op getchns() call in dsp_ioctl(). - Rename getchns() to dsp_lock_chans(), and relchns() to dsp_unlock_chans(). - Simplify DSP_FIXUP_ERROR(), as we do not longer assign SD_F_PRIO* flags to the softc. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45775 --- sys/dev/sound/pcm/dsp.c | 74 ++++++++----------------------------------------- 1 file changed, 12 insertions(+), 62 deletions(-) diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index 6ac85635b080..f2cead08783c 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -142,52 +142,8 @@ dsp_destroy_dev(device_t dev) } static void -getchns(struct dsp_cdevpriv *priv, uint32_t prio) +dsp_lock_chans(struct dsp_cdevpriv *priv, uint32_t prio) { - struct snddev_info *d; - struct pcm_channel *ch; - uint32_t flags; - - if (priv->simplex) { - d = priv->sc; - if (!PCM_REGISTERED(d)) - return; - PCM_LOCK(d); - PCM_WAIT(d); - PCM_ACQUIRE(d); - /* - * Note: order is important - - * pcm flags -> prio query flags -> wild guess - */ - ch = NULL; - flags = pcm_getflags(d->dev); - if (flags & SD_F_PRIO_WR) { - ch = priv->rdch; - } else if (flags & SD_F_PRIO_RD) { - ch = priv->wrch; - } else if (prio & SD_F_PRIO_WR) { - ch = priv->rdch; - flags |= SD_F_PRIO_WR; - } else if (prio & SD_F_PRIO_RD) { - ch = priv->wrch; - flags |= SD_F_PRIO_RD; - } else if (priv->wrch != NULL) { - ch = priv->rdch; - flags |= SD_F_PRIO_WR; - } else if (priv->rdch != NULL) { - ch = priv->wrch; - flags |= SD_F_PRIO_RD; - } - pcm_setflags(d->dev, flags); - if (ch != NULL) { - CHN_LOCK(ch); - chn_ref(ch, -1); - chn_release(ch); - } - PCM_RELEASE(d); - PCM_UNLOCK(d); - } - if (priv->rdch != NULL && (prio & SD_F_PRIO_RD)) CHN_LOCK(priv->rdch); if (priv->wrch != NULL && (prio & SD_F_PRIO_WR)) @@ -195,7 +151,7 @@ getchns(struct dsp_cdevpriv *priv, uint32_t prio) } static void -relchns(struct dsp_cdevpriv *priv, uint32_t prio) +dsp_unlock_chans(struct dsp_cdevpriv *priv, uint32_t prio) { if (priv->rdch != NULL && (prio & SD_F_PRIO_RD)) CHN_UNLOCK(priv->rdch); @@ -333,17 +289,12 @@ skip: } #define DSP_FIXUP_ERROR() do { \ - prio = pcm_getflags(d->dev); \ if (!DSP_F_VALID(flags)) \ error = EINVAL; \ if (!DSP_F_DUPLEX(flags) && \ ((DSP_F_READ(flags) && d->reccount == 0) || \ (DSP_F_WRITE(flags) && d->playcount == 0))) \ error = ENOTSUP; \ - else if (!DSP_F_DUPLEX(flags) && (prio & SD_F_SIMPLEX) && \ - ((DSP_F_READ(flags) && (prio & SD_F_PRIO_WR)) || \ - (DSP_F_WRITE(flags) && (prio & SD_F_PRIO_RD)))) \ - error = EBUSY; \ } while (0) static int @@ -352,7 +303,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) struct dsp_cdevpriv *priv; struct pcm_channel *rdch, *wrch; struct snddev_info *d; - uint32_t fmt, spd, prio; + uint32_t fmt, spd; int error, rderror, wrerror; /* Kind of impossible.. */ @@ -533,18 +484,18 @@ dsp_io_ops(struct dsp_cdevpriv *priv, struct uio *buf) runpid = buf->uio_td->td_proc->p_pid; - getchns(priv, prio); + dsp_lock_chans(priv, prio); if (*ch == NULL || !((*ch)->flags & CHN_F_BUSY)) { if (priv->rdch != NULL || priv->wrch != NULL) - relchns(priv, prio); + dsp_unlock_chans(priv, prio); PCM_GIANT_EXIT(d); return (EBADF); } if (((*ch)->flags & (CHN_F_MMAP | CHN_F_DEAD)) || (((*ch)->flags & CHN_F_RUNNING) && (*ch)->pid != runpid)) { - relchns(priv, prio); + dsp_unlock_chans(priv, prio); PCM_GIANT_EXIT(d); return (EINVAL); } else if (!((*ch)->flags & CHN_F_RUNNING)) { @@ -563,7 +514,7 @@ dsp_io_ops(struct dsp_cdevpriv *priv, struct uio *buf) CHN_BROADCAST(&(*ch)->cv); - relchns(priv, prio); + dsp_unlock_chans(priv, prio); PCM_GIANT_LEAVE(d); @@ -799,7 +750,6 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, return (ret); } - getchns(priv, 0); rdch = priv->rdch; wrch = priv->wrch; @@ -1858,7 +1808,7 @@ dsp_poll(struct cdev *i_dev, int events, struct thread *td) ret = 0; - getchns(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); + dsp_lock_chans(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); wrch = priv->wrch; rdch = priv->rdch; @@ -1874,7 +1824,7 @@ dsp_poll(struct cdev *i_dev, int events, struct thread *td) ret |= chn_poll(rdch, e, td); } - relchns(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); + dsp_unlock_chans(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); PCM_GIANT_LEAVE(d); @@ -1936,7 +1886,7 @@ dsp_mmap_single(struct cdev *i_dev, vm_ooffset_t *offset, PCM_GIANT_ENTER(d); - getchns(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); + dsp_lock_chans(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); wrch = priv->wrch; rdch = priv->rdch; @@ -1945,7 +1895,7 @@ dsp_mmap_single(struct cdev *i_dev, vm_ooffset_t *offset, (*offset + size) > sndbuf_getallocsize(c->bufsoft) || (wrch != NULL && (wrch->flags & CHN_F_MMAP_INVALID)) || (rdch != NULL && (rdch->flags & CHN_F_MMAP_INVALID))) { - relchns(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); + dsp_unlock_chans(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); PCM_GIANT_EXIT(d); return (EINVAL); } @@ -1956,7 +1906,7 @@ dsp_mmap_single(struct cdev *i_dev, vm_ooffset_t *offset, rdch->flags |= CHN_F_MMAP; *offset = (uintptr_t)sndbuf_getbufofs(c->bufsoft, *offset); - relchns(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); + dsp_unlock_chans(priv, SD_F_PRIO_RD | SD_F_PRIO_WR); *object = vm_pager_allocate(OBJT_DEVICE, i_dev, size, nprot, *offset, curthread->td_ucred);