> Date: Thu, 27 Oct 2022 13:27:43 +0000
> From: Klemens Nanni <[email protected]>
> 
> 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 recording.
> 
> 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.
> 
> The rkiis(4) and aplmca(4) stubs don't open anything, but are now
> required for simpleaudio(4) and aplaudio(4) to actually do the low-level
> driver specific 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
> 
> Builds fine on amd64 and arm64.
> Feedback? Objection? OK?

Sorry, but I'm still not sure I understand how this is supposed to
work.  Because...

> ---
>  sys/arch/arm64/dev/aplaudio.c      | 15 ---------------
>  sys/arch/arm64/dev/aplmca.c        | 20 ++++++++++++--------
>  sys/arch/luna88k/cbus/nec86.c      |  1 -
>  sys/arch/luna88k/cbus/nec86hw.c    | 10 ++++------
>  sys/arch/luna88k/cbus/nec86hwvar.h |  2 --
>  sys/dev/fdt/graphaudio.c           | 15 ---------------
>  sys/dev/fdt/rkiis.c                | 20 +++++++++++---------
>  sys/dev/fdt/simpleaudio.c          | 15 ---------------
>  sys/dev/ic/arcofi.c                | 11 +++--------
>  sys/dev/pci/maestro.c              | 13 +++----------
>  10 files changed, 33 insertions(+), 89 deletions(-)
> 
> diff --git a/sys/arch/arm64/dev/aplaudio.c b/sys/arch/arm64/dev/aplaudio.c
> index 2e06448a882..49b0aac2f38 100644
> --- a/sys/arch/arm64/dev/aplaudio.c
> +++ b/sys/arch/arm64/dev/aplaudio.c
> @@ -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..0d323ffc0c6 100644
> --- a/sys/arch/arm64/dev/aplmca.c
> +++ b/sys/arch/arm64/dev/aplmca.c
> @@ -20,6 +20,7 @@
>  #include <sys/audioio.h>
>  #include <sys/device.h>
>  #include <sys/malloc.h>
> +#include <sys/fcntl.h>
>  
>  #include <machine/bus.h>
>  #include <machine/fdt.h>
> @@ -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))
> +             return ENXIO;

Doesn't this mean that you return ENXIO even if only playback is
requested?  Because then flags would still contain FWRITE...

> +
> +     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..30dd23a7131 100644
> --- a/sys/arch/luna88k/cbus/nec86.c
> +++ b/sys/arch/luna88k/cbus/nec86.c
> @@ -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..f108a8a0773 100644
> --- a/sys/arch/luna88k/cbus/nec86hw.c
> +++ b/sys/arch/luna88k/cbus/nec86hw.c
> @@ -52,6 +52,7 @@
>  #include <sys/syslog.h>
>  #include <sys/device.h>
>  #include <sys/proc.h>
> +#include <sys/fcntl.h>
>  
>  #include <machine/bus.h>
>  #include <machine/cpu.h>
> @@ -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))
> +             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..307f2d07514 100644
> --- a/sys/arch/luna88k/cbus/nec86hwvar.h
> +++ b/sys/arch/luna88k/cbus/nec86hwvar.h
> @@ -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..8760faa04d6 100644
> --- a/sys/dev/fdt/graphaudio.c
> +++ b/sys/dev/fdt/graphaudio.c
> @@ -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..588e38c9f5f 100644
> --- a/sys/dev/fdt/rkiis.c
> +++ b/sys/dev/fdt/rkiis.c
> @@ -30,6 +30,7 @@
>  #include <sys/systm.h>
>  #include <sys/device.h>
>  #include <sys/malloc.h>
> +#include <sys/fcntl.h>
>  
>  #include <machine/intr.h>
>  #include <machine/bus.h>
> @@ -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))
> +             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..87ab7a14409 100644
> --- a/sys/dev/fdt/simpleaudio.c
> +++ b/sys/dev/fdt/simpleaudio.c
> @@ -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..f21c935548c 100644
> --- a/sys/dev/ic/arcofi.c
> +++ b/sys/dev/ic/arcofi.c
> @@ -35,6 +35,7 @@
>  #include <sys/kernel.h>
>  #include <sys/proc.h>
>  #include <sys/endian.h>
> +#include <sys/fcntl.h>
>  
>  #include <sys/audioio.h>
>  #include <dev/audio_if.h>
> @@ -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))
> +             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..63375bd0cc0 100644
> --- a/sys/dev/pci/maestro.c
> +++ b/sys/dev/pci/maestro.c
> @@ -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))
> +             return ENXIO;   /* XXX */
> +
>  /* XXX work around VM brokeness */
>  #if 0
>       if ((OFLAGS(flags) & O_ACCMODE) != O_WRONLY)
> -- 
> 2.38.1
> 
> 

Reply via email to