From 7eff0e4e0f4f6052a2649fb49f86fac46f57cd50 Mon Sep 17 00:00:00 2001 From: kn Date: Fri, 28 Oct 2022 15:09:45 +0000 Subject: [PATCH] Replace audio(9) get_props() with duplex check in open() in non-duplex drivers Make drivers which do *not* adverise AUDIO_PROP_FULLDPLEX return ENXIO in their open() if full-duplex mode was requested. This way, sys/dev/audio.c:audio_open() will fail immediately rather than later through the to-be-removed get_props() check. These are all drivers which simply don't support full-duplex mode. In device-tree based drivers like simpleaudio(4)/rkiis(4) and newer Apple ones like aplaudio(4)/aplmca(4), this adds a new open() stub to the low-level drivers which merely does the duplex check. My Pinebook Pro keeps playing audio and recording silence with this diff just like before (rkiis(4) is currently play-only): simpleaudio0 at mainbus0 simpleaudio1 at mainbus0 audio0 at simpleaudio1 $ aucat -i song69.wav -o rec.wav OK ratchov miod --- sys/arch/arm64/dev/aplaudio.c | 17 +---------------- sys/arch/arm64/dev/aplmca.c | 22 +++++++++++++--------- sys/arch/luna88k/cbus/nec86.c | 3 +-- sys/arch/luna88k/cbus/nec86hw.c | 12 +++++------- sys/arch/luna88k/cbus/nec86hwvar.h | 4 +--- sys/dev/fdt/graphaudio.c | 17 +---------------- sys/dev/fdt/rkiis.c | 22 ++++++++++++---------- sys/dev/fdt/simpleaudio.c | 17 +---------------- sys/dev/ic/arcofi.c | 13 ++++--------- sys/dev/pci/maestro.c | 15 ++++----------- 10 files changed, 43 insertions(+), 99 deletions(-) diff --git a/sys/arch/arm64/dev/aplaudio.c b/sys/arch/arm64/dev/aplaudio.c index 2e06448a882..9f097b752fe 100644 --- a/sys/arch/arm64/dev/aplaudio.c +++ b/sys/arch/arm64/dev/aplaudio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aplaudio.c,v 1.3 2022/09/02 17:54:42 kettenis Exp $ */ +/* $OpenBSD: aplaudio.c,v 1.4 2022/10/28 15:09:45 kn Exp $ */ /* * Copyright (c) 2022 Mark Kettenis * Copyright (c) 2020 Patrick Wildt @@ -55,7 +55,6 @@ void aplaudio_freem(void *, void *, int); int aplaudio_set_port(void *, mixer_ctrl_t *); int aplaudio_get_port(void *, mixer_ctrl_t *); int aplaudio_query_devinfo(void *, mixer_devinfo_t *); -int aplaudio_get_props(void *); int aplaudio_round_blocksize(void *, int); size_t aplaudio_round_buffersize(void *, int, size_t); int aplaudio_trigger_output(void *, void *, void *, int, @@ -74,7 +73,6 @@ const struct audio_hw_if aplaudio_hw_if = { .set_port = aplaudio_set_port, .get_port = aplaudio_get_port, .query_devinfo = aplaudio_query_devinfo, - .get_props = aplaudio_get_props, .round_blocksize = aplaudio_round_blocksize, .round_buffersize = aplaudio_round_buffersize, .trigger_output = aplaudio_trigger_output, @@ -401,19 +399,6 @@ aplaudio_query_devinfo(void *cookie, mixer_devinfo_t *dip) return ENXIO; } -int -aplaudio_get_props(void *cookie) -{ - struct aplaudio_softc *sc = cookie; - struct dai_device *dai = sc->sc_dai_cpu; - const struct audio_hw_if *hwif = dai->dd_hw_if; - - if (hwif->get_props) - return hwif->get_props(dai->dd_cookie); - - return 0; -} - int aplaudio_round_blocksize(void *cookie, int block) { diff --git a/sys/arch/arm64/dev/aplmca.c b/sys/arch/arm64/dev/aplmca.c index 559dd765933..ab7a1ea9a6b 100644 --- a/sys/arch/arm64/dev/aplmca.c +++ b/sys/arch/arm64/dev/aplmca.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aplmca.c,v 1.4 2022/10/19 07:59:26 kn Exp $ */ +/* $OpenBSD: aplmca.c,v 1.5 2022/10/28 15:09:45 kn Exp $ */ /* * Copyright (c) 2022 Mark Kettenis * @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -123,11 +124,11 @@ struct aplmca_softc { int aplmca_set_format(void *, uint32_t, uint32_t, uint32_t); int aplmca_set_sysclk(void *, uint32_t); +int aplmca_open(void *, int); int aplmca_set_params(void *, int, int, struct audio_params *, struct audio_params *); void *aplmca_allocm(void *, int, size_t, int, int); void aplmca_freem(void *, void *, int); -int aplmca_get_props(void *); int aplmca_trigger_output(void *, void *, void *, int, void (*)(void *), void *, struct audio_params *); int aplmca_trigger_input(void *, void *, void *, int, @@ -136,8 +137,8 @@ int aplmca_halt_output(void *); int aplmca_halt_input(void *); const struct audio_hw_if aplmca_hw_if = { + .open = aplmca_open, .set_params = aplmca_set_params, - .get_props = aplmca_get_props, .allocm = aplmca_allocm, .freem = aplmca_freem, .trigger_output = aplmca_trigger_output, @@ -380,6 +381,15 @@ aplmca_set_sysclk(void *cookie, uint32_t rate) return clock_set_frequency_idx(sc->sc_node, ad->ad_cluster, rate); } +int +aplmca_open(void *cookie, int flags) +{ + if ((flags & (FWRITE | FREAD)) == (FWRITE | FREAD)) + return ENXIO; + + return 0; +} + int aplmca_set_params(void *cookie, int setmode, int usemode, struct audio_params *play, struct audio_params *rec) @@ -396,12 +406,6 @@ aplmca_set_params(void *cookie, int setmode, int usemode, return 0; } -int -aplmca_get_props(void *cookie) -{ - return 0; -} - void * aplmca_allocm(void *cookie, int direction, size_t size, int type, int flags) diff --git a/sys/arch/luna88k/cbus/nec86.c b/sys/arch/luna88k/cbus/nec86.c index b745ad85224..49e31c52d46 100644 --- a/sys/arch/luna88k/cbus/nec86.c +++ b/sys/arch/luna88k/cbus/nec86.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nec86.c,v 1.7 2022/10/19 19:14:16 kn Exp $ */ +/* $OpenBSD: nec86.c,v 1.8 2022/10/28 15:09:45 kn Exp $ */ /* $NecBSD: nec86.c,v 1.11 1999/07/23 11:04:39 honda Exp $ */ /* $NetBSD$ */ @@ -83,7 +83,6 @@ const struct audio_hw_if nec86_hw_if = { .set_port = nec86hw_mixer_set_port, .get_port = nec86hw_mixer_get_port, .query_devinfo = nec86hw_mixer_query_devinfo, - .get_props = nec86_get_props, }; /* diff --git a/sys/arch/luna88k/cbus/nec86hw.c b/sys/arch/luna88k/cbus/nec86hw.c index a49987966c8..070c7f57344 100644 --- a/sys/arch/luna88k/cbus/nec86hw.c +++ b/sys/arch/luna88k/cbus/nec86hw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nec86hw.c,v 1.7 2022/10/19 15:34:02 kn Exp $ */ +/* $OpenBSD: nec86hw.c,v 1.8 2022/10/28 15:09:45 kn Exp $ */ /* $NecBSD: nec86hw.c,v 1.13 1998/03/14 07:04:54 kmatsuda Exp $ */ /* $NetBSD$ */ @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -169,6 +170,9 @@ nec86hw_open(void *arg, int flags) struct nec86hw_softc *sc = arg; DPRINTF(("nec86hw_open: sc=%p\n", sc)); + if ((flags & (FWRITE | FREAD)) == (FWRITE | FREAD)) + return ENXIO; + if (sc->sc_open != 0 || nec86hw_reset(sc) != 0) return ENXIO; @@ -1316,9 +1320,3 @@ nec86hw_intr(void *arg) mtx_leave(&audio_lock); return 1; } - -int -nec86_get_props(void *addr) -{ - return 0; -} diff --git a/sys/arch/luna88k/cbus/nec86hwvar.h b/sys/arch/luna88k/cbus/nec86hwvar.h index 45749c74858..e43e3c3c2f9 100644 --- a/sys/arch/luna88k/cbus/nec86hwvar.h +++ b/sys/arch/luna88k/cbus/nec86hwvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nec86hwvar.h,v 1.4 2022/10/19 15:34:02 kn Exp $ */ +/* $OpenBSD: nec86hwvar.h,v 1.5 2022/10/28 15:09:45 kn Exp $ */ /* $NecBSD: nec86hwvar.h,v 1.10 1998/03/14 07:04:55 kmatsuda Exp $ */ /* $NetBSD$ */ @@ -211,7 +211,5 @@ void nec86fifo_padding(struct nec86hw_softc *, int); int nec86hw_intr(void *); -int nec86_get_props(void *); - #endif /* _KERNEL */ #endif /* !_NEC86HWVAR_H_ */ diff --git a/sys/dev/fdt/graphaudio.c b/sys/dev/fdt/graphaudio.c index af6eb4c370a..27d398c308c 100644 --- a/sys/dev/fdt/graphaudio.c +++ b/sys/dev/fdt/graphaudio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: graphaudio.c,v 1.4 2022/04/06 18:59:28 naddy Exp $ */ +/* $OpenBSD: graphaudio.c,v 1.5 2022/10/28 15:09:45 kn Exp $ */ /* * Copyright (c) 2020 Patrick Wildt * Copyright (c) 2021 Mark Kettenis @@ -55,7 +55,6 @@ void graphaudio_freem(void *, void *, int); int graphaudio_set_port(void *, mixer_ctrl_t *); int graphaudio_get_port(void *, mixer_ctrl_t *); int graphaudio_query_devinfo(void *, mixer_devinfo_t *); -int graphaudio_get_props(void *); int graphaudio_round_blocksize(void *, int); size_t graphaudio_round_buffersize(void *, int, size_t); int graphaudio_trigger_output(void *, void *, void *, int, @@ -74,7 +73,6 @@ const struct audio_hw_if graphaudio_hw_if = { .set_port = graphaudio_set_port, .get_port = graphaudio_get_port, .query_devinfo = graphaudio_query_devinfo, - .get_props = graphaudio_get_props, .round_blocksize = graphaudio_round_blocksize, .round_buffersize = graphaudio_round_buffersize, .trigger_output = graphaudio_trigger_output, @@ -367,19 +365,6 @@ graphaudio_query_devinfo(void *cookie, mixer_devinfo_t *dip) return ENXIO; } -int -graphaudio_get_props(void *cookie) -{ - struct graphaudio_softc *sc = cookie; - struct dai_device *dai = sc->sc_dai_cpu; - const struct audio_hw_if *hwif = dai->dd_hw_if; - - if (hwif->get_props) - return hwif->get_props(dai->dd_cookie); - - return 0; -} - int graphaudio_round_blocksize(void *cookie, int block) { diff --git a/sys/dev/fdt/rkiis.c b/sys/dev/fdt/rkiis.c index e294d583b13..45f6ac7a23b 100644 --- a/sys/dev/fdt/rkiis.c +++ b/sys/dev/fdt/rkiis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rkiis.c,v 1.3 2022/04/06 18:59:28 naddy Exp $ */ +/* $OpenBSD: rkiis.c,v 1.4 2022/10/28 15:09:45 kn Exp $ */ /* $NetBSD: rk_i2s.c,v 1.3 2020/02/29 05:51:10 isaki Exp $ */ /*- * Copyright (c) 2019 Jared McNeill @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -144,12 +145,10 @@ int rkiis_set_format(void *, uint32_t, uint32_t, uint32_t); int rkiis_set_sysclk(void *, uint32_t); int rkiis_open(void *, int); -void rkiis_close(void *); int rkiis_set_params(void *, int, int, struct audio_params *, struct audio_params *); void *rkiis_allocm(void *, int, size_t, int, int); void rkiis_freem(void *, void *, int); -int rkiis_get_props(void *); int rkiis_trigger_output(void *, void *, void *, int, void (*)(void *), void *, struct audio_params *); int rkiis_trigger_input(void *, void *, void *, int, @@ -201,8 +200,8 @@ struct rkiis_softc { }; const struct audio_hw_if rkiis_hw_if = { + .open = rkiis_open, .set_params = rkiis_set_params, - .get_props = rkiis_get_props, .allocm = rkiis_allocm, .freem = rkiis_freem, .trigger_output = rkiis_trigger_output, @@ -425,6 +424,15 @@ rkiis_set_sysclk(void *cookie, uint32_t rate) return 0; } +int +rkiis_open(void *cookie, int flags) +{ + if ((flags & (FWRITE | FREAD)) == (FWRITE | FREAD)) + return ENXIO; + + return 0; +} + int rkiis_set_params(void *cookie, int setmode, int usemode, struct audio_params *play, struct audio_params *rec) @@ -502,12 +510,6 @@ rkiis_set_params(void *cookie, int setmode, int usemode, return 0; } -int -rkiis_get_props(void *cookie) -{ - return 0; -} - void * rkiis_allocm(void *cookie, int direction, size_t size, int type, int flags) diff --git a/sys/dev/fdt/simpleaudio.c b/sys/dev/fdt/simpleaudio.c index 2b904c2287b..9883e5c2471 100644 --- a/sys/dev/fdt/simpleaudio.c +++ b/sys/dev/fdt/simpleaudio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: simpleaudio.c,v 1.6 2022/08/01 09:50:02 kettenis Exp $ */ +/* $OpenBSD: simpleaudio.c,v 1.7 2022/10/28 15:09:45 kn Exp $ */ /* * Copyright (c) 2020 Patrick Wildt * @@ -57,7 +57,6 @@ void simpleaudio_freem(void *, void *, int); int simpleaudio_set_port(void *, mixer_ctrl_t *); int simpleaudio_get_port(void *, mixer_ctrl_t *); int simpleaudio_query_devinfo(void *, mixer_devinfo_t *); -int simpleaudio_get_props(void *); int simpleaudio_round_blocksize(void *, int); size_t simpleaudio_round_buffersize(void *, int, size_t); int simpleaudio_trigger_output(void *, void *, void *, int, @@ -76,7 +75,6 @@ const struct audio_hw_if simpleaudio_hw_if = { .set_port = simpleaudio_set_port, .get_port = simpleaudio_get_port, .query_devinfo = simpleaudio_query_devinfo, - .get_props = simpleaudio_get_props, .round_blocksize = simpleaudio_round_blocksize, .round_buffersize = simpleaudio_round_buffersize, .trigger_output = simpleaudio_trigger_output, @@ -407,19 +405,6 @@ simpleaudio_query_devinfo(void *cookie, mixer_devinfo_t *dip) return ENXIO; } -int -simpleaudio_get_props(void *cookie) -{ - struct simpleaudio_softc *sc = cookie; - struct dai_device *dai = sc->sc_dai_cpu; - const struct audio_hw_if *hwif = dai->dd_hw_if; - - if (hwif->get_props) - return hwif->get_props(dai->dd_cookie); - - return 0; -} - int simpleaudio_round_blocksize(void *cookie, int block) { diff --git a/sys/dev/ic/arcofi.c b/sys/dev/ic/arcofi.c index 8b51d1cab9b..3c8bd835a48 100644 --- a/sys/dev/ic/arcofi.c +++ b/sys/dev/ic/arcofi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arcofi.c,v 1.20 2022/06/27 20:14:51 miod Exp $ */ +/* $OpenBSD: arcofi.c,v 1.21 2022/10/28 15:09:45 kn Exp $ */ /* * Copyright (c) 2011 Miodrag Vallat. @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -196,7 +197,6 @@ int arcofi_set_param(struct arcofi_softc *, int, int, int, void arcofi_close(void *); int arcofi_commit_settings(void *); int arcofi_get_port(void *, mixer_ctrl_t *); -int arcofi_get_props(void *); int arcofi_halt_input(void *); int arcofi_halt_output(void *); int arcofi_open(void *, int); @@ -221,7 +221,6 @@ const struct audio_hw_if arcofi_hw_if = { .set_port = arcofi_set_port, .get_port = arcofi_get_port, .query_devinfo = arcofi_query_devinfo, - .get_props = arcofi_get_props, }; /* mixer items */ @@ -272,6 +271,8 @@ arcofi_open(void *v, int flags) { struct arcofi_softc *sc = (struct arcofi_softc *)v; + if ((flags & (FWRITE | FREAD)) == (FWRITE | FREAD)) + return ENXIO; if (sc->sc_open) return EBUSY; sc->sc_open = 1; @@ -889,12 +890,6 @@ mute: return 0; } -int -arcofi_get_props(void *v) -{ - return 0; -} - int arcofi_hwintr(void *v) { diff --git a/sys/dev/pci/maestro.c b/sys/dev/pci/maestro.c index 1de34df1310..bbd0a3b1edf 100644 --- a/sys/dev/pci/maestro.c +++ b/sys/dev/pci/maestro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: maestro.c,v 1.49 2022/10/19 19:14:17 kn Exp $ */ +/* $OpenBSD: maestro.c,v 1.50 2022/10/28 15:09:46 kn Exp $ */ /* $FreeBSD: /c/ncvs/src/sys/dev/sound/pci/maestro.c,v 1.3 2000/11/21 12:22:11 julian Exp $ */ /* * FreeBSD's ESS Agogo/Maestro driver @@ -476,7 +476,6 @@ int maestro_get_port(void *, mixer_ctrl_t *); int maestro_query_devinfo(void *, mixer_devinfo_t *); void *maestro_malloc(void *, int, size_t, int, int); void maestro_free(void *, void *, int); -int maestro_get_props(void *); int maestro_trigger_output(void *, void *, void *, int, void (*)(void *), void *, struct audio_params *); int maestro_trigger_input(void *, void *, void *, int, void (*)(void *), @@ -539,7 +538,6 @@ const struct audio_hw_if maestro_hw_if = { .query_devinfo = maestro_query_devinfo, .allocm = maestro_malloc, .freem = maestro_free, - .get_props = maestro_get_props, .trigger_output = maestro_trigger_output, .trigger_input = maestro_trigger_input, }; @@ -839,14 +837,6 @@ maestro_free(void *self, void *ptr, int pool) salloc_free(sc->dmapool, ptr); } -int -maestro_get_props(void *self) -{ - /* struct maestro_softc *sc = (struct maestro_softc *)self; */ - - return (0); /* XXX */ -} - int maestro_set_port(void *self, mixer_ctrl_t *cp) { @@ -999,6 +989,9 @@ maestro_open(void *hdl, int flags) struct maestro_softc *sc = (struct maestro_softc *)hdl; DPRINTF(("%s: open(%d)\n", sc->dev.dv_xname, flags)); + if ((flags & (FWRITE | FREAD)) == (FWRITE | FREAD)) + return ENXIO; /* XXX */ + /* XXX work around VM brokeness */ #if 0 if ((OFLAGS(flags) & O_ACCMODE) != O_WRONLY) -- 2.20.1