From nobody Wed Jul 10 16:49:04 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 4WK3jF0ZJgz5QmyZ; Wed, 10 Jul 2024 16:49:05 +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 4WK3jD69KDz4gKM; Wed, 10 Jul 2024 16:49:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720630144; 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=5Cmsgcfk3bLD5LtI/0JTficWQiuffrzzTDpLr/b6/e8=; b=cLgmxljuSxLzgRJBnp/zulq8cNgsfzqoKZTDhV+qPZairCEBvz8vITjqJ92EtcW0CF/lCC f6T5QN4nf7Np5GcDepJ11XEJcz3J0EWeZUOj1g/JciB4Csj+u0guehtkGRaQSdHhrjK1/9 oq2cJWS2phbbitYZCJEfEOdmoAaiFA1dCs0LsxRECN1HhMfFacaT6VYfbNXRjUFa0y0ylf N9RuqOpM84KYTRZQyEpdVc9hzCaFZVmlID51DGijDpuzX3o6Pg0Tb9eDJmIY0hi1RdtReh jOzNM3T7KHxGG8JHSp7dsUek1urwqbyx1JXdoN7JXgP1t5Z2etaVxSr32+S5AQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720630144; a=rsa-sha256; cv=none; b=pVtFkimLGUrHRSiboTS1uHpSr8aphxNFB9tlrV7wx8BFltpsxD9I9jWw4ge+2TDg/8p2sh YlU1PDru8T0GBe6OwjM/mxcjSo6jbNeLtJS8cVKKnfmtp7ezyJ2YHzXxXCvKgBwKDVNZ/L MugR74yvZeppvcybTCoNMbXyxTv3Y6KJgbSVSXjmUrCZYLJmlnJNzAcYwpa9q9Scv/ht3C 3EhGOy12ycaBXvz49GE5YcRIswYJ070fCaJkCpx+NyHfn2BTH3jt6BbWDbxEUmepVqpNAh 5uVIIJj5IalapSs153ECL805DSQcO0s8HnCvlFDiClCTuGuGqFhb7umV/x60eA== 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=1720630144; 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=5Cmsgcfk3bLD5LtI/0JTficWQiuffrzzTDpLr/b6/e8=; b=NKK0cDmKvqPFkdWzFdhjlqo8esM6GTqdMS4Wyk8/eyd+66jbi0D/DnQKMqqTr5AImbfWpy h5lb3kqAXtVzwW7jOKbvnZaTDlD7ZTwJ6f3fKi4qxtRt0mV0vYQb/B9kVbfmoKBH0jsBdG K6CVsIgNYSCCsuXdHTw2+0gVjKZ1U4zUcG1gprEktbuOZrpLFV2OcUh0bxVa9I284qkoIf EnemkLbFl3b0rG0/Hed2S4TwMGWPUCZYA7mxWlxB3WGk5FrsB9vNircL7/6F/ZTSNYVqby L8gqiaGeNGyf7hDkPi+QzEXUEnEUt1/bA+4CRuHj0jENptUui3K8sA2ONIzbSg== 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 4WK3jD5l8BzPWB; Wed, 10 Jul 2024 16:49:04 +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 46AGn4XI034896; Wed, 10 Jul 2024 16:49:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46AGn49f034893; Wed, 10 Jul 2024 16:49:04 GMT (envelope-from git) Date: Wed, 10 Jul 2024 16:49:04 GMT Message-Id: <202407101649.46AGn49f034893@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: e687f4e40ddd - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: e687f4e40ddd0cacffd6f7be7a1236fffb1eda52 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=e687f4e40ddd0cacffd6f7be7a1236fffb1eda52 commit e687f4e40ddd0cacffd6f7be7a1236fffb1eda52 Author: Christos Margiolis AuthorDate: 2024-07-06 18:22:40 +0000 Commit: Christos Margiolis CommitDate: 2024-07-10 16:48:12 +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 (cherry picked from commit 46e92a41cb539e327dd059d571fa381d0fbe779c) --- 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);