Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/dev Pull up following revision(s) (requested by isaki...



details:   https://anonhg.NetBSD.org/src/rev/927b3908697d
branches:  netbsd-8
changeset: 434304:927b3908697d
user:      snj <snj%NetBSD.org@localhost>
date:      Sat Sep 23 17:13:10 2017 +0000

description:
Pull up following revision(s) (requested by isaki in ticket #278):
        sys/dev/audiovar.h: revision 1.61-1.62
        sys/dev/audiovar.h: revision 1.63 via patch
        sys/dev/audio.c: revision 1.381, 1.390, 1.391, 1.393
        sys/dev/audio.c: revision 1.394 via patch
Use do .. while (0) for macros.
--
Introduce audio_destroy_pfilters()/audio_destroy_rfilters()
and use it.
--
Remove dead codes. chan will never be NULL in SIMPLEQ_FOREACH.
--
Move defines to the appropriate place.
--
Remove mixer chan from sc_audiochan.
Now sc_audiochan contains opened audio chan (and first special
element) only.
First I splitted sc_audiochan into sc_audiochan which has
audio chan (and first special element) and sc_mixerchan
which has mixer chan only.  However nobody else refers this
sc_mixerchan except additions to list and deletions from
list.  So mixer chan's list is not necessary.
--
Split the first special element from sc_audiochan list.
- This makes sc_audiochan a list of only open audio chan.
- "SIMPLEQ_FIRST(&sc->sc_audiochan)->vc" is now "sc->hwvc".
No functional changes (except one debug message).

diffstat:

 sys/dev/audio.c    |  291 ++++++++++++++++++----------------------------------
 sys/dev/audiovar.h |   18 +-
 2 files changed, 112 insertions(+), 197 deletions(-)

diffs (truncated from 814 to 300 lines):

diff -r 51ad63cfe909 -r 927b3908697d sys/dev/audio.c
--- a/sys/dev/audio.c   Sat Sep 23 17:04:40 2017 +0000
+++ b/sys/dev/audio.c   Sat Sep 23 17:13:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.357.2.7 2017/09/11 05:33:23 snj Exp $      */
+/*     $NetBSD: audio.c,v 1.357.2.8 2017/09/23 17:13:10 snj Exp $      */
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.357.2.7 2017/09/11 05:33:23 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.357.2.8 2017/09/23 17:13:10 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -214,11 +214,15 @@
 int    audio_idle_timeout = 30;
 #endif
 
-#define HW_LOCK(x)     if ((x) == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc) \
-                               mutex_enter(sc->sc_intr_lock);
-
-#define HW_UNLOCK(x)   if ((x) == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc) \
-                               mutex_exit(sc->sc_intr_lock);
+#define HW_LOCK(x)     do { \
+       if ((x) == sc->sc_hwvc) \
+               mutex_enter(sc->sc_intr_lock); \
+} while (0)
+
+#define HW_UNLOCK(x)   do { \
+       if ((x) == sc->sc_hwvc) \
+               mutex_exit(sc->sc_intr_lock); \
+} while (0)
 
 int    audio_blk_ms = AUDIO_BLK_MS;
 
@@ -280,7 +284,7 @@
                              struct audio_ringbuffer *, int);
 int    audio_initbufs(struct audio_softc *, struct virtual_channel *);
 void   audio_calcwater(struct audio_softc *, struct virtual_channel *);
-int    audio_drain(struct audio_softc *, struct audio_chan *);
+int    audio_drain(struct audio_softc *, struct virtual_channel *);
 void   audio_clear(struct audio_softc *, struct virtual_channel *);
 void   audio_clear_intr_unlocked(struct audio_softc *sc,
                                  struct virtual_channel *);
@@ -294,6 +298,8 @@
                              stream_filter_list_t *, struct virtual_channel *);
 static int audio_setup_rfilters(struct audio_softc *, const audio_params_t *,
                              stream_filter_list_t *, struct virtual_channel *);
+static void audio_destroy_pfilters(struct virtual_channel *);
+static void audio_destroy_rfilters(struct virtual_channel *);
 static void audio_stream_dtor(audio_stream_t *);
 static int audio_stream_ctor(audio_stream_t *, const audio_params_t *, int);
 static void stream_filter_list_append(stream_filter_list_t *,
@@ -476,7 +482,6 @@
        struct audio_softc *sc;
        struct audio_attach_args *sa;
        struct virtual_channel *vc;
-       struct audio_chan *chan;
        const struct audio_hw_if *hwp;
        const struct sysctlnode *node;
        void *hdlp;
@@ -522,11 +527,10 @@
        sc->sc_trigger_started = false;
        sc->sc_rec_started = false;
        sc->sc_dying = false;
-       chan = kmem_zalloc(sizeof(struct audio_chan), KM_SLEEP);
+       SIMPLEQ_INIT(&sc->sc_audiochan);
+
        vc = kmem_zalloc(sizeof(struct virtual_channel), KM_SLEEP);
-       chan->vc = vc;
-       SIMPLEQ_INIT(&sc->sc_audiochan);
-       SIMPLEQ_INSERT_HEAD(&sc->sc_audiochan, chan, entries);
+       sc->sc_hwvc = vc;
        vc->sc_open = 0;
        vc->sc_mode = 0;
        vc->sc_npfilters = 0;
@@ -869,7 +873,7 @@
 {
        struct audio_softc *sc;
        struct audio_chan *chan;
-       int maj, mn, i, rc;
+       int maj, mn, rc;
 
        sc = device_private(self);
        DPRINTF(("audio_detach: sc=%p flags=%d\n", sc, flags));
@@ -930,38 +934,19 @@
 
        /* free resources */
        SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
-               if (chan == NULL)
-                       break;
-
-               if (chan->chan == MIXER_INUSE)
-                       continue;
                audio_free_ring(sc, &chan->vc->sc_mpr);
                audio_free_ring(sc, &chan->vc->sc_mrr);
        }
+       audio_free_ring(sc, &sc->sc_hwvc->sc_mpr);
+       audio_free_ring(sc, &sc->sc_hwvc->sc_mrr);
        audio_free_ring(sc, &sc->sc_pr);
        audio_free_ring(sc, &sc->sc_rr);
        SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
-               if (chan == NULL)
-                       break;
-
-               if (chan->chan == MIXER_INUSE)
-                       continue;
-               for (i = 0; i < chan->vc->sc_npfilters; i++) {
-                       chan->vc->sc_pfilters[i]->dtor
-                           (chan->vc->sc_pfilters[i]);
-                       chan->vc->sc_pfilters[i] = NULL;
-                       audio_stream_dtor(&chan->vc->sc_pstreams[i]);
-               }
-               chan->vc->sc_npfilters = 0;
-
-               for (i = 0; i < chan->vc->sc_nrfilters; i++) {
-                       chan->vc->sc_rfilters[i]->dtor
-                           (chan->vc->sc_rfilters[i]);
-                       chan->vc->sc_rfilters[i] = NULL;
-                       audio_stream_dtor(&chan->vc->sc_rstreams[i]);
-               }
-               chan->vc->sc_nrfilters = 0;
-       }
+               audio_destroy_pfilters(chan->vc);
+               audio_destroy_rfilters(chan->vc);
+       }
+       audio_destroy_pfilters(sc->sc_hwvc);
+       audio_destroy_rfilters(sc->sc_hwvc);
 
        auconv_delete_encodings(sc->sc_encodings);
 
@@ -974,10 +959,7 @@
                sc->sc_sih_wr = NULL;
        }
 
-       chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
-       kmem_free(chan->vc, sizeof(struct virtual_channel));
-       SIMPLEQ_REMOVE(&sc->sc_audiochan, chan, audio_chan, entries);
-       kmem_free(chan, sizeof(struct audio_chan));
+       kmem_free(sc->sc_hwvc, sizeof(struct virtual_channel));
        kmem_free(sc->sc_mixer_state, sizeof(mixer_ctrl_t) *
            (sc->sc_nmixer_states + 1));
 
@@ -1107,26 +1089,21 @@
 void
 audio_printsc(struct audio_softc *sc)
 {
-       struct audio_chan *chan;
-       
-       chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
-       
-       if (chan == NULL)
-               return;
+       struct virtual_channel *vc;
+
+       vc = sc->sc_hwvc;
 
        printf("hwhandle %p hw_if %p ", sc->hw_hdl, sc->hw_if);
-       printf("open 0x%x mode 0x%x\n", chan->vc->sc_open,
-           chan->vc->sc_mode);
+       printf("open 0x%x mode 0x%x\n", vc->sc_open, vc->sc_mode);
        printf("rchan 0x%x wchan 0x%x ", cv_has_waiters(&sc->sc_rchan),
            cv_has_waiters(&sc->sc_wchan));
        printf("rring used 0x%x pring used=%d\n",
-              audio_stream_get_used(&chan->vc->sc_mrr.s),
-              audio_stream_get_used(&chan->vc->sc_mpr.s));
-       printf("rbus 0x%x pbus 0x%x ", chan->vc->sc_rbus,
-           chan->vc->sc_pbus);
-       printf("blksize %d", chan->vc->sc_mpr.blksize);
-       printf("hiwat %d lowat %d\n", chan->vc->sc_mpr.usedhigh,
-           chan->vc->sc_mpr.usedlow);
+           audio_stream_get_used(&vc->sc_mrr.s),
+           audio_stream_get_used(&vc->sc_mpr.s));
+       printf("rbus 0x%x pbus 0x%x ", vc->sc_rbus, vc->sc_pbus);
+       printf("blksize %d", vc->sc_mpr.blksize);
+       printf("hiwat %d lowat %d\n", vc->sc_mpr.usedhigh,
+           vc->sc_mpr.usedlow);
 }
 
 void
@@ -1190,13 +1167,13 @@
                 int direction, size_t bufsize)
 {
        const struct audio_hw_if *hw;
-       struct audio_chan *chan;
+       struct virtual_channel *vc;
        void *hdl;
        vaddr_t vstart;
        vsize_t vsize;
        int error;
 
-       chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
+       vc = sc->sc_hwvc;
        hw = sc->hw_if;
        hdl = sc->hw_hdl;
        /*
@@ -1208,7 +1185,7 @@
        if (hw->round_buffersize)
                bufsize = hw->round_buffersize(hdl, direction, bufsize);
 
-       if (hw->allocm && (r == &chan->vc->sc_mpr || r == &chan->vc->sc_mrr)) {
+       if (hw->allocm && (r == &vc->sc_mpr || r == &vc->sc_mrr)) {
                /* Hardware ringbuffer.  No dedicated uvm object.*/
                r->uobj = NULL;
                r->s.start = hw->allocm(hdl, direction, bufsize);
@@ -1253,17 +1230,16 @@
 void
 audio_free_ring(struct audio_softc *sc, struct audio_ringbuffer *r)
 {
-       struct audio_chan *chan;
+       struct virtual_channel *vc;
        vaddr_t vstart;
        vsize_t vsize;
 
        if (r->s.start == NULL)
                return;
 
-       chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
-
-       if (sc->hw_if->freem && (r == &chan->vc->sc_mpr ||
-                                       r == &chan->vc->sc_mrr)) {
+       vc = sc->sc_hwvc;
+
+       if (sc->hw_if->freem && (r == &vc->sc_mpr || r == &vc->sc_mrr)) {
                 /* Hardware ringbuffer.  */
                KASSERT(r->uobj == NULL);
                sc->hw_if->freem(sc->hw_hdl, r->s.start, r->s.bufsize);
@@ -1456,6 +1432,32 @@
 }
 
 static void
+audio_destroy_pfilters(struct virtual_channel *vc)
+{
+       int i;
+
+       for (i = 0; i < vc->sc_npfilters; i++) {
+               vc->sc_pfilters[i]->dtor(vc->sc_pfilters[i]);
+               vc->sc_pfilters[i] = NULL;
+               audio_stream_dtor(&vc->sc_pstreams[i]);
+       }
+       vc->sc_npfilters = 0;
+}
+
+static void
+audio_destroy_rfilters(struct virtual_channel *vc)
+{
+       int i;
+
+       for (i = 0; i < vc->sc_nrfilters; i++) {
+               vc->sc_rfilters[i]->dtor(vc->sc_rfilters[i]);
+               vc->sc_rfilters[i] = NULL;
+               audio_stream_dtor(&vc->sc_pstreams[i]);
+       }
+       vc->sc_nrfilters = 0;
+}
+
+static void
 audio_stream_dtor(audio_stream_t *stream)
 {
 
@@ -1585,8 +1587,6 @@
 
        found = false;
        SIMPLEQ_FOREACH(vchan, &sc->sc_audiochan, entries) {
-               if (vchan == SIMPLEQ_FIRST(&sc->sc_audiochan))
-                       continue;
                if (vchan->vc == vc) {
                        found = true;
                        break;
@@ -2023,12 +2023,10 @@
 audio_initbufs(struct audio_softc *sc, struct virtual_channel *vc)
 {
        const struct audio_hw_if *hw;
-       struct audio_chan *chan;
        int error;
 
-       chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
        if (vc == NULL) {
-               vc = chan->vc;
+               vc = sc->sc_hwvc;
                sc->sc_pr.blksize = vc->sc_mrr.blksize;
                sc->sc_rr.blksize = vc->sc_mrr.blksize;
        }
@@ -2036,7 +2034,7 @@
        DPRINTF(("audio_initbufs: mode=0x%x\n", vc->sc_mode));
        hw = sc->hw_if;
        if (audio_can_capture(sc) &&
-               ((vc->sc_open & AUOPEN_READ) || vc == chan->vc)) {
+               ((vc->sc_open & AUOPEN_READ) || vc == sc->sc_hwvc)) {
                audio_init_ringbuffer(sc, &vc->sc_mrr,
                    AUMODE_RECORD);
                if (sc->sc_opens == 0 && hw->init_input &&
@@ -2047,11 +2045,11 @@
                                return error;
                }
        }



Home | Main Index | Thread Index | Old Index