Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/audio Call get_props() once at attach.



details:   https://anonhg.NetBSD.org/src/rev/a7eab8c9f6c9
branches:  trunk
changeset: 451882:a7eab8c9f6c9
user:      isaki <isaki%NetBSD.org@localhost>
date:      Mon Jun 10 13:12:51 2019 +0000

description:
Call get_props() once at attach.

diffstat:

 sys/dev/audio/audio.c    |  57 ++++++++++++++---------------------------------
 sys/dev/audio/audiovar.h |   8 +++++-
 2 files changed, 24 insertions(+), 41 deletions(-)

diffs (172 lines):

diff -r 2cfb08aebc79 -r a7eab8c9f6c9 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Mon Jun 10 10:28:41 2019 +0000
+++ b/sys/dev/audio/audio.c     Mon Jun 10 13:12:51 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.13 2019/06/08 08:20:10 isaki Exp $ */
+/*     $NetBSD: audio.c,v 1.14 2019/06/10 13:12:51 isaki Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -121,7 +121,7 @@
  *     allocm                  -       - +     (*1)
  *     freem                   -       - +     (*1)
  *     round_buffersize        -       x
- *     get_props               -       x
+ *     get_props               -       x       Called at attach time
  *     trigger_output          x       x +
  *     trigger_input           x       x +
  *     dev_ioctl               -       x
@@ -142,7 +142,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.13 2019/06/08 08:20:10 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.14 2019/06/10 13:12:51 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -550,7 +550,6 @@
        audio_filter_reg_t *, audio_filter_reg_t *);
 static int audiogetinfo(struct audio_softc *, struct audio_info *, int,
        audio_file_t *);
-static int audio_get_props(struct audio_softc *);
 static bool audio_can_playback(struct audio_softc *);
 static bool audio_can_capture(struct audio_softc *);
 static int audio_check_params(audio_format2_t *);
@@ -843,7 +842,6 @@
        bool has_indep;
        bool has_fulldup;
        int mode;
-       int props;
        int error;
 
        sc = device_private(self);
@@ -884,13 +882,16 @@
        cv_init(&sc->sc_exlockcv, "audiolk");
 
        mutex_enter(sc->sc_lock);
-       props = audio_get_props(sc);
+       sc->sc_props = hw_if->get_props(sc->hw_hdl);
        mutex_exit(sc->sc_lock);
 
-       has_playback = (props & AUDIO_PROP_PLAYBACK);
-       has_capture  = (props & AUDIO_PROP_CAPTURE);
-       has_indep    = (props & AUDIO_PROP_INDEPENDENT);
-       has_fulldup  = (props & AUDIO_PROP_FULLDUPLEX);
+       /* MMAP is now supported by upper layer.  */
+       sc->sc_props |= AUDIO_PROP_MMAP;
+
+       has_playback = (sc->sc_props & AUDIO_PROP_PLAYBACK);
+       has_capture  = (sc->sc_props & AUDIO_PROP_CAPTURE);
+       has_indep    = (sc->sc_props & AUDIO_PROP_INDEPENDENT);
+       has_fulldup  = (sc->sc_props & AUDIO_PROP_FULLDUPLEX);
 
        KASSERT(has_playback || has_capture);
        /* Unidirectional device must have neither FULLDUP nor INDEPENDENT. */
@@ -1859,7 +1860,7 @@
                goto bad1;
        }
 
-       fullduplex = (audio_get_props(sc) & AUDIO_PROP_FULLDUPLEX);
+       fullduplex = (sc->sc_props & AUDIO_PROP_FULLDUPLEX);
 
        /*
         * On half duplex hardware,
@@ -2652,16 +2653,14 @@
                 * it is full duplex.  Otherwise half duplex.
                 */
                mutex_enter(sc->sc_lock);
-               fd = (audio_get_props(sc) & AUDIO_PROP_FULLDUPLEX)
+               fd = (sc->sc_props & AUDIO_PROP_FULLDUPLEX)
                    && (sc->sc_pmixer && sc->sc_rmixer);
                mutex_exit(sc->sc_lock);
                *(int *)addr = fd;
                break;
 
        case AUDIO_GETPROPS:
-               mutex_enter(sc->sc_lock);
-               *(int *)addr = audio_get_props(sc);
-               mutex_exit(sc->sc_lock);
+               *(int *)addr = sc->sc_props;
                break;
 
        case AUDIO_QUERYFORMAT:
@@ -6296,7 +6295,6 @@
        audio_filter_reg_t pfil;
        audio_filter_reg_t rfil;
        int mode;
-       int props;
        int error;
 
        KASSERT(mutex_owned(sc->sc_lock));
@@ -6329,8 +6327,7 @@
        }
 
        /* On non-independent devices, use the same format for both. */
-       props = audio_get_props(sc);
-       if ((props & AUDIO_PROP_INDEPENDENT) == 0) {
+       if ((sc->sc_props & AUDIO_PROP_INDEPENDENT) == 0) {
                if (mode == AUMODE_RECORD) {
                        phwfmt = rhwfmt;
                } else {
@@ -6340,9 +6337,9 @@
        }
 
        /* Then, unset the direction not exist on the hardware. */
-       if ((props & AUDIO_PROP_PLAYBACK) == 0)
+       if ((sc->sc_props & AUDIO_PROP_PLAYBACK) == 0)
                mode &= ~AUMODE_PLAY;
-       if ((props & AUDIO_PROP_CAPTURE) == 0)
+       if ((sc->sc_props & AUDIO_PROP_CAPTURE) == 0)
                mode &= ~AUMODE_RECORD;
 
        /* debug */
@@ -7162,26 +7159,6 @@
 }
 
 /*
- * Must be called with sc_lock held.
- */
-static int
-audio_get_props(struct audio_softc *sc)
-{
-       const struct audio_hw_if *hw;
-       int props;
-
-       KASSERT(mutex_owned(sc->sc_lock));
-
-       hw = sc->hw_if;
-       props = hw->get_props(sc->hw_hdl);
-
-       /* MMAP is now supported by upper layer.  */
-       props |= AUDIO_PROP_MMAP;
-
-       return props;
-}
-
-/*
  * Return true if playback is configured.
  * This function can be used after audioattach.
  */
diff -r 2cfb08aebc79 -r a7eab8c9f6c9 sys/dev/audio/audiovar.h
--- a/sys/dev/audio/audiovar.h  Mon Jun 10 10:28:41 2019 +0000
+++ b/sys/dev/audio/audiovar.h  Mon Jun 10 13:12:51 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiovar.h,v 1.2 2019/05/08 13:40:17 isaki Exp $       */
+/*     $NetBSD: audiovar.h,v 1.3 2019/06/10 13:12:51 isaki Exp $       */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -142,6 +142,12 @@
        void            *hw_hdl;
 
        /*
+        * Properties obtained by get_props().
+        * No need any locks to read this variable.
+        */
+       int sc_props;
+
+       /*
         * List of opened descriptors.
         * Must be protected by sc_intr_lock.
         */



Home | Main Index | Thread Index | Old Index