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.

This is the first round for drivers with logic in their get_props(),
i.e. those that only support full-duplex mode for specific hardware:

        ess(4), gus(4), pas(4) and sb(4)

All of these are i386/GENERIC only and share code through
sys/dev/isa/{ad1848,sbdsp}{.c,var.h} which is not used by any other
architecture/kernel configuration.

i386/GENERIC.MP builds and boots with this diff.
Feedback? Objection? OK?
---
 sys/dev/isa/ad1848.c    | 12 ++++--------
 sys/dev/isa/ad1848var.h |  2 --
 sys/dev/isa/ess.c       | 29 ++++++++++++-----------------
 sys/dev/isa/gus.c       | 19 +++----------------
 sys/dev/isa/gusvar.h    |  2 --
 sys/dev/isa/pas.c       |  1 -
 sys/dev/isa/sb.c        |  1 -
 sys/dev/isa/sbdsp.c     | 10 +++-------
 sys/dev/isa/sbdspvar.h  |  2 --
 9 files changed, 22 insertions(+), 56 deletions(-)

diff --git a/sys/dev/isa/ad1848.c b/sys/dev/isa/ad1848.c
index bb2b95277a1..843af8f3b0d 100644
--- a/sys/dev/isa/ad1848.c
+++ b/sys/dev/isa/ad1848.c
@@ -74,6 +74,7 @@
 #include <sys/syslog.h>
 #include <sys/device.h>
 #include <sys/buf.h>
+#include <sys/fcntl.h>
 
 #include <machine/cpu.h>
 #include <machine/bus.h>
@@ -1040,6 +1041,9 @@ ad1848_open(void *addr, int flags)
 
        DPRINTF(("ad1848_open: sc=%p\n", sc));
 
+       if ((flags & (FWRITE | FREAD)) && sc->mode != 2)
+               return ENXIO;
+
        sc->sc_pintr = sc->sc_parg = NULL;
        sc->sc_rintr = sc->sc_rarg = NULL;
 
@@ -1458,11 +1462,3 @@ ad1848_round(void *addr, int direction, size_t size)
                size = MAX_ISADMA;
        return size;
 }
-
-int
-ad1848_get_props(void *addr)
-{
-       struct ad1848_softc *sc = addr;
-
-       return (sc->mode == 2 ? AUDIO_PROP_FULLDUPLEX : 0);
-}
diff --git a/sys/dev/isa/ad1848var.h b/sys/dev/isa/ad1848var.h
index 49c199f64fc..c8af3f04b4b 100644
--- a/sys/dev/isa/ad1848var.h
+++ b/sys/dev/isa/ad1848var.h
@@ -210,6 +210,4 @@ void   *ad1848_malloc(void *, int, size_t, int, int);
 void   ad1848_free(void *, void *, int);
 size_t ad1848_round(void *, int, size_t);
 
-int    ad1848_get_props(void *);
-
 #endif
diff --git a/sys/dev/isa/ess.c b/sys/dev/isa/ess.c
index 8989dd94b01..51ecd05f12a 100644
--- a/sys/dev/isa/ess.c
+++ b/sys/dev/isa/ess.c
@@ -74,6 +74,7 @@
 #include <sys/device.h>
 #include <sys/kernel.h>
 #include <sys/timeout.h>
+#include <sys/fcntl.h>
 
 #include <machine/cpu.h>
 #include <machine/intr.h>
@@ -115,6 +116,7 @@ struct audio_params ess_audio_default =
 
 int    ess_setup_sc(struct ess_softc *, int);
 
+int    ess_1788_open(void *, int);
 int    ess_open(void *, int);
 void   ess_1788_close(void *);
 void   ess_1888_close(void *);
@@ -148,8 +150,6 @@ size_t      ess_round_buffersize(void *, int, size_t);
 
 
 int    ess_query_devinfo(void *, mixer_devinfo_t *);
-int    ess_1788_get_props(void *);
-int    ess_1888_get_props(void *);
 
 void   ess_speaker_on(struct ess_softc *);
 void   ess_speaker_off(struct ess_softc *);
@@ -198,7 +198,7 @@ static const char *essmodel[] = {
  */
 
 const struct audio_hw_if ess_1788_hw_if = {
-       .open = ess_open,
+       .open = ess_1788_open,
        .close = ess_1788_close,
        .set_params = ess_set_params,
        .round_blocksize = ess_round_blocksize,
@@ -211,7 +211,6 @@ const struct audio_hw_if ess_1788_hw_if = {
        .allocm = ess_malloc,
        .freem = ess_free,
        .round_buffersize = ess_round_buffersize,
-       .get_props = ess_1788_get_props,
        .trigger_output = ess_audio1_trigger_output,
        .trigger_input = ess_audio1_trigger_input,
 };
@@ -230,7 +229,6 @@ const struct audio_hw_if ess_1888_hw_if = {
        .allocm = ess_malloc,
        .freem = ess_free,
        .round_buffersize = ess_round_buffersize,
-       .get_props = ess_1888_get_props,
        .trigger_output = ess_audio2_trigger_output,
        .trigger_input = ess_audio1_trigger_input,
 };
@@ -982,6 +980,15 @@ essattach(struct ess_softc *sc)
  * Various routines to interface to higher level audio driver
  */
 
+int
+ess_1788_open(void *addr, int flags)
+{
+       if (flags & (FWRITE | FREAD))
+               return ENXIO;
+
+       return ess_open(addr, flags);
+}
+
 int
 ess_open(void *addr, int flags)
 {
@@ -2059,18 +2066,6 @@ ess_round_buffersize(void *addr, int direction, size_t 
size)
        return (size);
 }
 
-int
-ess_1788_get_props(void *addr)
-{
-       return (0);
-}
-
-int
-ess_1888_get_props(void *addr)
-{
-       return (AUDIO_PROP_FULLDUPLEX);
-}
-
 /* ============================================
  * Generic functions for ess, not used by audio h/w i/f
  * =============================================
diff --git a/sys/dev/isa/gus.c b/sys/dev/isa/gus.c
index 45fe009fc61..8be5d5abe74 100644
--- a/sys/dev/isa/gus.c
+++ b/sys/dev/isa/gus.c
@@ -277,7 +277,6 @@ const struct audio_hw_if gus_hw_if = {
        .allocm = gus_malloc,
        .freem = gus_free,
        .round_buffersize = gus_round,
-       .get_props = gus_get_props,
 };
 
 static const struct audio_hw_if gusmax_hw_if = {
@@ -297,7 +296,6 @@ static const struct audio_hw_if gusmax_hw_if = {
        .allocm = ad1848_malloc,
        .freem = ad1848_free,
        .round_buffersize = ad1848_round,
-       .get_props = gusmax_get_props,
 };
 
 int
@@ -307,6 +305,9 @@ gusopen(void *addr, int flags)
 
        DPRINTF(("gusopen() called\n"));
 
+       if ((flags & (FWRITE | FREAD)) && sc->sc_recdrq == sc->sc_drq)
+               return ENXIO;
+
        if (sc->sc_flags & GUS_OPEN)
                return EBUSY;
 
@@ -2671,20 +2672,6 @@ gus_mixer_set_port(void *addr, mixer_ctrl_t *cp)
        return error;
 }
 
-int
-gus_get_props(void *addr)
-{
-       struct gus_softc *sc = addr;
-       return (sc->sc_recdrq == sc->sc_drq ? 0 : AUDIO_PROP_FULLDUPLEX);
-}
-
-int
-gusmax_get_props(void *addr)
-{
-       struct ad1848_softc *ac = addr;
-       return gus_get_props(ac->parent);
-}
-
 int
 gusmax_mixer_query_devinfo(void *addr, mixer_devinfo_t *dip)
 {
diff --git a/sys/dev/isa/gusvar.h b/sys/dev/isa/gusvar.h
index e979f53c6ac..6ce0b851ca2 100644
--- a/sys/dev/isa/gusvar.h
+++ b/sys/dev/isa/gusvar.h
@@ -371,8 +371,6 @@ int gusmax_mixer_query_devinfo(void *, mixer_devinfo_t *);
 void   *gus_malloc(void *, int, size_t, int, int);
 void   gus_free(void *, void *, int);
 size_t gus_round(void *, int, size_t);
-int    gus_get_props(void *);
-int    gusmax_get_props(void *);
 
 void   gusics_master_mute(struct ics2101_softc *, int);
 void   gusics_dac_mute(struct ics2101_softc *, int);
diff --git a/sys/dev/isa/pas.c b/sys/dev/isa/pas.c
index 2204b1be495..42c2183d12d 100644
--- a/sys/dev/isa/pas.c
+++ b/sys/dev/isa/pas.c
@@ -122,7 +122,6 @@ const struct audio_hw_if pas_hw_if = {
        .allocm = sb_malloc,
        .freem = sb_free,
        .round_buffersize = sb_round,
-       .get_props = sbdsp_get_props,
        .trigger_output = sbdsp_trigger_output,
        .trigger_input = sbdsp_trigger_input,
 };
diff --git a/sys/dev/isa/sb.c b/sys/dev/isa/sb.c
index bf2bb45c5fa..4c0b17c0214 100644
--- a/sys/dev/isa/sb.c
+++ b/sys/dev/isa/sb.c
@@ -107,7 +107,6 @@ const struct audio_hw_if sb_hw_if = {
        .allocm = sb_malloc,
        .freem = sb_free,
        .round_buffersize = sb_round,
-       .get_props = sbdsp_get_props,
        .trigger_output = sbdsp_trigger_output,
        .trigger_input = sbdsp_trigger_input,
 };
diff --git a/sys/dev/isa/sbdsp.c b/sys/dev/isa/sbdsp.c
index 4ca26c110ef..e12a361cb9a 100644
--- a/sys/dev/isa/sbdsp.c
+++ b/sys/dev/isa/sbdsp.c
@@ -53,6 +53,7 @@
 #include <sys/syslog.h>
 #include <sys/device.h>
 #include <sys/buf.h>
+#include <sys/fcntl.h>
 
 #include <machine/cpu.h>
 #include <machine/intr.h>
@@ -2112,13 +2113,6 @@ sb_round(void *addr, int direction, size_t size)
        return size;
 }
 
-int
-sbdsp_get_props(void *addr)
-{
-       struct sbdsp_softc *sc = addr;
-       return (sc->sc_fullduplex ? AUDIO_PROP_FULLDUPLEX : 0);
-}
-
 #if NMIDI > 0
 /*
  * MIDI related routines.
@@ -2132,6 +2126,8 @@ sbdsp_midi_open(void *addr, int flags, void (*iintr)(void 
*, int),
 
         DPRINTF(("sbdsp_midi_open: sc=%p\n", sc));
 
+       if ((flags & (FWRITE | FREAD)) && !sc->sc_fullduplex)
+               return ENXIO;
        if (sc->sc_open != SB_CLOSED)
                return EBUSY;
        if (sbdsp_reset(sc) != 0)
diff --git a/sys/dev/isa/sbdspvar.h b/sys/dev/isa/sbdspvar.h
index 188cdf205b2..f862799d102 100644
--- a/sys/dev/isa/sbdspvar.h
+++ b/sys/dev/isa/sbdspvar.h
@@ -243,8 +243,6 @@ void        *sb_malloc(void *, int, size_t, int, int);
 void   sb_free(void *, void *, int);
 size_t sb_round(void *, int, size_t);
 
-int    sbdsp_get_props(void *);
-
 
 int    sbdsp_midi_open(void *, int,
                             void (*iintr)(void *, int),
-- 
2.38.1

Reply via email to