From nobody Wed Jul 10 16:49:05 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 4WK3jG1WVMz5Qmcq; Wed, 10 Jul 2024 16:49:06 +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 4WK3jF6hBSz4gN1; Wed, 10 Jul 2024 16:49:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720630146; 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=hKu+HmUeqRQNjTJ1M8jLook9l1g7/66TWN34Yf+KXtw=; b=MUgbOIlv0l7WniAYy947MabLDO+s1fKejsB0o5kLnVBubGzGiCaxAyD1ANhlpRBMgjT2JG ycMI28wkM+ezuurxgY/fpSdP3uhKnCnDxKwtld63fzSCL38NORC6Ki5lAbsfC4GTRUT9p6 g3PS2CBCAeLDhhFDcLavisBEocNY5sP/lmifaWwCbBEN/yJr0bBB81q2T3IsuoBZUnCiLP XS2UDfRMk8L6TmShUV98QjtrnNsn67+ZUiiERl/AQWAqHhzF6vjN1ifcyGjVfbUuG00QN/ +fs7xDPMhcn+00ce74LRNQQviP3MyaS163Vfdts9YqLqo+N4MmX2NG/lKAbmiQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720630146; a=rsa-sha256; cv=none; b=wBYnPNerj3NZWa+m5DvVDpbklf/z5DU1v5sj84C9gWSxmvscZrXGJ0AAuihx9E1BAv9bZ3 sVtNx0NcEHTSniSY/g1t42mVLZ71pGluCx6nPluOSRottklWA8KBxrYbtst4EIetoPiLOa v5GkYbk3tSAGKZDOhqMnhi0s1i+eDWfzvgG9DEMUXSrVuUxQuAYTlH3UvTgMcQbzwjKz/9 o0SzLDRu8nitzOuy2X59JkxvuaVSR/d2OCd6Mx1HMdNz1uWnfjzZUiVruaikley+mWRxRV mAhKvOWg7uj+JB4DYDk+lCddsDal/KohMqXk+8QbM9k80Wz95YGZUZoce4zYPw== 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=1720630146; 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=hKu+HmUeqRQNjTJ1M8jLook9l1g7/66TWN34Yf+KXtw=; b=l6u1kBnNUORI9e7R9CsClxfISG2nsI05EwQB/ZGE0+a/nFVSsH2D841nsuTAhNnv2M59YW fnlhjZ8zz6nBtkyJ4YHmSs4liQK2uV+nQ4NKzGPPU6CBJmpbTagyyN5k6VXswRLueMCVdG vnJUJm35I2oaXPyuVVts+KV4ae1MREKvmbMprOhMlJBzeRV6428E6kA0kewjbFAEuMqHks qMZnnuca3m2X0YiuecYNahw1m19Qo3nmME7kT94m7EJjbEE/nomQk0FPZ1rWdmHthlaXc2 RCiGW9+t4Y4Ln07pXBKtdbf2tqhJsMs+NJxh1Ds8Sc/EOHvIoedMHl1qnMBwYQ== 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 4WK3jF6DgVzPWC; Wed, 10 Jul 2024 16:49:05 +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 46AGn57Y034941; Wed, 10 Jul 2024 16:49:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46AGn5DD034938; Wed, 10 Jul 2024 16:49:05 GMT (envelope-from git) Date: Wed, 10 Jul 2024 16:49:05 GMT Message-Id: <202407101649.46AGn5DD034938@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: 6378079427be - stable/14 - sound: Improve simplex handling in dsp_open() 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: 6378079427be35962d36a8e9b587eb63b1159e99 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=6378079427be35962d36a8e9b587eb63b1159e99 commit 6378079427be35962d36a8e9b587eb63b1159e99 Author: Christos Margiolis AuthorDate: 2024-07-06 18:22:45 +0000 Commit: Christos Margiolis CommitDate: 2024-07-10 16:48:13 +0000 sound: Improve simplex handling in dsp_open() If we are in simplex mode, make sure we do not open in both directions (read/write) and also that we do not open in a direction opposite of what is already opened. For example, if the device is already doing playback, we cannot open the device for recording at the same time, and vice-versa. While here, remove dsp_cdevpriv->simplex as it's no longer needed. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45835 (cherry picked from commit be04a9d9387f6b5d4e83fc4976d8d83bb03fe5af) --- sys/dev/sound/pcm/dsp.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index f2cead08783c..26a2919ed1da 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -52,7 +52,6 @@ struct dsp_cdevpriv { struct pcm_channel *rdch; struct pcm_channel *wrch; struct pcm_channel *volch; - int simplex; }; static int dsp_mmap_allow_prot_exec = 0; @@ -301,10 +300,10 @@ static int dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) { struct dsp_cdevpriv *priv; - struct pcm_channel *rdch, *wrch; + struct pcm_channel *rdch, *wrch, *ch; struct snddev_info *d; uint32_t fmt, spd; - int error, rderror, wrerror; + int error, rderror, wrerror, dir; /* Kind of impossible.. */ if (i_dev == NULL || td == NULL) @@ -319,7 +318,6 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) priv->rdch = NULL; priv->wrch = NULL; priv->volch = NULL; - priv->simplex = (pcm_getflags(d->dev) & SD_F_SIMPLEX) ? 1 : 0; error = devfs_set_cdevpriv(priv, dsp_close); if (error != 0) @@ -333,6 +331,36 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) error = 0; DSP_FIXUP_ERROR(); + if (pcm_getflags(d->dev) & SD_F_SIMPLEX) { + if (DSP_F_DUPLEX(flags)) { + /* + * If no channels are opened yet, and we request + * DUPLEX, limit to playback only, otherwise open one + * channel in a direction that already exists. + */ + if (CHN_EMPTY(d, channels.pcm.opened)) { + if (d->playcount > 0) + flags &= ~FREAD; + else if (d->reccount > 0) + flags &= ~FWRITE; + } else { + ch = CHN_FIRST(d, channels.pcm.opened); + if (ch->direction == PCMDIR_PLAY) + flags &= ~FREAD; + else if (ch->direction == PCMDIR_REC) + flags &= ~FWRITE; + } + } else if (!CHN_EMPTY(d, channels.pcm.opened)) { + /* + * If we requested SIMPLEX, make sure we do not open a + * channel in the opposite direction. + */ + ch = CHN_FIRST(d, channels.pcm.opened); + dir = DSP_F_READ(flags) ? PCMDIR_REC : PCMDIR_PLAY; + if (ch->direction != dir) + error = ENOTSUP; + } + } if (error != 0) { PCM_UNLOCK(d); PCM_GIANT_EXIT(d);