Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/3ae90a575b33
branches:  netbsd-9
changeset: 964312:3ae90a575b33
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Feb 28 07:05:14 2021 +0000

description:
Pull up following revision(s) (requested by isaki in ticket #1217):

        sys/dev/audio/audio.c: revision 1.46
        sys/dev/audio/audio.c: revision 1.82
        sys/dev/audio/audio.c: revision 1.85
        sys/dev/audio/audio.c: revision 1.87
        sys/dev/audio/audio.c: revision 1.88

Change two aprint_error_dev() to device_printf() (and improve messages).
This is also called from other than boot.

Add missing newline.

Revise comments.

Change (harmless) zero-length debug messages.
sys/modules is compiled with -Wzero-length-format and this
makes sys/modules compilable even if AUDIO_DEBUG is defined.

Improve error messages.
- prefix MD device name if it's considered to be related to the MD driver.
- revise some messages.

diffstat:

 sys/dev/audio/audio.c |  183 +++++++++++++++++++++++++++----------------------
 1 files changed, 101 insertions(+), 82 deletions(-)

diffs (truncated from 510 to 300 lines):

diff -r 3dead7fc1d5b -r 3ae90a575b33 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Sun Feb 28 07:01:01 2021 +0000
+++ b/sys/dev/audio/audio.c     Sun Feb 28 07:05:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $   */
+/*     $NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $   */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -518,6 +518,8 @@
 static void audio_softintr_rd(void *);
 static void audio_softintr_wr(void *);
 
+static void audio_printf(struct audio_softc *, const char *, ...)
+       __printflike(2, 3);
 static int audio_exlock_mutex_enter(struct audio_softc *);
 static void audio_exlock_mutex_exit(struct audio_softc *);
 static int audio_exlock_enter(struct audio_softc *);
@@ -965,19 +967,20 @@
                perror = audio_hw_probe(sc, &phwfmt, AUMODE_PLAY);
                rerror = audio_hw_probe(sc, &rhwfmt, AUMODE_RECORD);
                if (perror && rerror) {
-                       aprint_error_dev(self, "audio_hw_probe failed, "
-                           "perror = %d, rerror = %d\n", perror, rerror);
+                       aprint_error_dev(self,
+                           "audio_hw_probe failed: perror=%d, rerror=%d\n",
+                           perror, rerror);
                        goto bad;
                }
                if (perror) {
                        mode &= ~AUMODE_PLAY;
-                       aprint_error_dev(self, "audio_hw_probe failed with "
-                           "%d, playback disabled\n", perror);
+                       aprint_error_dev(self, "audio_hw_probe failed: "
+                           "errno=%d, playback disabled\n", perror);
                }
                if (rerror) {
                        mode &= ~AUMODE_RECORD;
-                       aprint_error_dev(self, "audio_hw_probe failed with "
-                           "%d, capture disabled\n", rerror);
+                       aprint_error_dev(self, "audio_hw_probe failed: "
+                           "errno=%d, capture disabled\n", rerror);
                }
        } else {
                /*
@@ -987,8 +990,8 @@
                audio_format2_t *fmt = has_playback ? &phwfmt : &rhwfmt;
                error = audio_hw_probe(sc, fmt, mode);
                if (error) {
-                       aprint_error_dev(self, "audio_hw_probe failed, "
-                           "error = %d\n", error);
+                       aprint_error_dev(self,
+                           "audio_hw_probe failed: errno=%d\n", error);
                        goto bad;
                }
                if (has_playback && has_capture)
@@ -999,8 +1002,8 @@
        /* hw_probe() also validates [pr]hwfmt.  */
        error = audio_hw_set_format(sc, mode, &phwfmt, &rhwfmt, &pfil, &rfil);
        if (error) {
-               aprint_error_dev(self, "audio_hw_set_format failed, "
-                   "error = %d\n", error);
+               aprint_error_dev(self,
+                   "audio_hw_set_format failed: errno=%d\n", error);
                goto bad;
        }
 
@@ -1010,8 +1013,8 @@
         */
        error = audio_mixers_init(sc, mode, &phwfmt, &rhwfmt, &pfil, &rfil);
        if (sc->sc_pmixer == NULL && sc->sc_rmixer == NULL) {
-               aprint_error_dev(self, "audio_mixers_init failed, "
-                   "error = %d\n", error);
+               aprint_error_dev(self,
+                   "audio_mixers_init failed: errno=%d\n", error);
                goto bad;
        }
 
@@ -1429,6 +1432,22 @@
 }
 
 /*
+ * audio_printf() outputs fmt... with the audio device name and MD device
+ * name prefixed.  If the message is considered to be related to the MD
+ * driver, use this one instead of device_printf().
+ */
+static void
+audio_printf(struct audio_softc *sc, const char *fmt, ...)
+{
+       va_list ap;
+
+       printf("%s(%s): ", device_xname(sc->sc_dev), device_xname(sc->hw_dev));
+       va_start(ap, fmt);
+       vprintf(fmt, ap);
+       va_end(ap);
+}
+
+/*
  * Enter critical section and also keep sc_lock.
  * If successful, returns 0 with sc_lock held.  Otherwise returns errno.
  * Must be called without sc_lock held.
@@ -1574,7 +1593,7 @@
        if (error) {
                TRACET(2, track, "cv_timedwait_sig failed %d", error);
                if (error == EWOULDBLOCK)
-                       device_printf(sc->sc_dev, "device timeout\n");
+                       audio_printf(sc, "device timeout\n");
        } else {
                TRACET(3, track, "wakeup");
        }
@@ -2408,7 +2427,8 @@
 
        /*
         * Acquire exlock to protect counters.
-        * Does not use audio_exlock_enter() due to sc_dying.
+        * audio_exlock_enter() cannot be used here because we have to go
+        * forward even if sc_dying is set.
         */
        while (__predict_false(sc->sc_exlock != 0)) {
                error = cv_timedwait_sig(&sc->sc_exlockcv, sc->sc_lock,
@@ -2416,8 +2436,9 @@
                /* XXX what should I do on error? */
                if (error == EWOULDBLOCK) {
                        mutex_exit(sc->sc_lock);
-                       device_printf(sc->sc_dev,
-                           "%s: cv_timedwait_sig failed %d", __func__, error);
+                       audio_printf(sc,
+                           "%s: cv_timedwait_sig failed: errno=%d\n",
+                           __func__, error);
                        return error;
                }
        }
@@ -2440,8 +2461,8 @@
                if (sc->sc_popens == 0 && sc->sc_pbusy) {
                        error = audio_pmixer_halt(sc);
                        if (error) {
-                               device_printf(sc->sc_dev,
-                                   "halt_output failed with %d (ignored)\n",
+                               audio_printf(sc,
+                                   "halt_output failed: errno=%d (ignored)\n",
                                    error);
                        }
                }
@@ -2466,8 +2487,8 @@
                if (sc->sc_ropens == 0 && sc->sc_rbusy) {
                        error = audio_rmixer_halt(sc);
                        if (error) {
-                               device_printf(sc->sc_dev,
-                                   "halt_input failed with %d (ignored)\n",
+                               audio_printf(sc,
+                                   "halt_input failed: errno=%d (ignored)\n",
                                    error);
                        }
                }
@@ -2585,8 +2606,8 @@
                        if (error) {
                                audio_track_lock_exit(track);
                                device_printf(sc->sc_dev,
-                                   "uiomove(len=%d) failed with %d\n",
-                                   len, error);
+                                   "%s: uiomove(%d) failed: errno=%d\n",
+                                   __func__, len, error);
                                goto abort;
                        }
                        auring_take(usrbuf, len);
@@ -2714,8 +2735,8 @@
                        if (error) {
                                audio_track_lock_exit(track);
                                device_printf(sc->sc_dev,
-                                   "uiomove(len=%d) failed with %d\n",
-                                   len, error);
+                                   "%s: uiomove(%d) failed: errno=%d\n",
+                                   __func__, len, error);
                                goto abort;
                        }
                        auring_push(usrbuf, len);
@@ -3131,7 +3152,7 @@
 
        file = kn->kn_hook;
        sc = file->sc;
-       TRACEF(3, file, "");
+       TRACEF(3, file, "called");
 
        mutex_enter(sc->sc_lock);
        SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
@@ -3178,7 +3199,7 @@
 
        file = kn->kn_hook;
        sc = file->sc;
-       TRACEF(3, file, "");
+       TRACEF(3, file, "called");
 
        mutex_enter(sc->sc_lock);
        SLIST_REMOVE(&sc->sc_wsel.sel_klist, kn, knote, kn_selnext);
@@ -3336,7 +3357,7 @@
 
        KASSERT(sc->sc_exlock);
 
-       TRACE(1, "");
+       TRACE(1, "called");
 
        error = fd_allocfile(&fp, &fd);
        if (error)
@@ -3425,7 +3446,7 @@
            UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_NONE,
            UVM_ADV_RANDOM, 0));
        if (error) {
-               device_printf(sc->sc_dev, "uvm_map failed with %d\n", error);
+               device_printf(sc->sc_dev, "uvm_map failed: errno=%d\n", error);
                uao_detach(track->uobj);        /* release reference */
                goto abort;
        }
@@ -3433,7 +3454,7 @@
        error = uvm_map_pageable(kernel_map, vstart, vstart + newvsize,
            false, 0);
        if (error) {
-               device_printf(sc->sc_dev, "uvm_map_pageable failed with %d\n",
+               device_printf(sc->sc_dev, "uvm_map_pageable failed: errno=%d\n",
                    error);
                uvm_unmap(kernel_map, vstart, vstart + newvsize);
                /* uvm_unmap also detach uobj */
@@ -4886,9 +4907,9 @@
                if (rounded != blksize) {
                        if ((rounded * NBBY) % (mixer->hwbuf.fmt.stride *
                            mixer->hwbuf.fmt.channels) != 0) {
-                               device_printf(sc->sc_dev,
-                                   "round_blocksize must return blocksize "
-                                   "divisible by framesize: "
+                               audio_printf(sc,
+                                   "round_blocksize returned blocksize "
+                                   "indivisible by framesize: "
                                    "blksize=%d rounded=%d "
                                    "stride=%ubit channels=%u\n",
                                    blksize, rounded,
@@ -4917,16 +4938,17 @@
                TRACE(1, "round_buffersize %zd -> %zd", bufsize, rounded);
                if (rounded < bufsize) {
                        /* buffersize needs NBLKHW blocks at least. */
-                       device_printf(sc->sc_dev,
-                           "buffersize too small: buffersize=%zd blksize=%d\n",
+                       audio_printf(sc,
+                           "round_buffersize returned too small buffersize: "
+                           "buffersize=%zd blksize=%d\n",
                            rounded, blksize);
                        return EINVAL;
                }
                if (rounded % blksize != 0) {
                        /* buffersize/blksize constraint mismatch? */
-                       device_printf(sc->sc_dev,
-                           "buffersize must be multiple of blksize: "
-                           "buffersize=%zu blksize=%d\n",
+                       audio_printf(sc,
+                           "round_buffersize returned buffersize indivisible "
+                           "by blksize: buffersize=%zu blksize=%d\n",
                            rounded, blksize);
                        return EINVAL;
                }
@@ -4946,8 +4968,7 @@
                /* sc_lock is not necessary for allocm */
                mixer->hwbuf.mem = sc->hw_if->allocm(sc->hw_hdl, mode, bufsize);
                if (mixer->hwbuf.mem == NULL) {
-                       device_printf(sc->sc_dev, "%s: allocm(%zu) failed\n",
-                           __func__, bufsize);
+                       audio_printf(sc, "allocm(%zu) failed\n", bufsize);
                        return ENOMEM;
                }
        } else {
@@ -5014,8 +5035,7 @@
                mixer->codecbuf.mem = audio_realloc(mixer->codecbuf.mem, len);
                if (mixer->codecbuf.mem == NULL) {
                        device_printf(sc->sc_dev,
-                           "%s: malloc codecbuf(%d) failed\n",
-                           __func__, len);
+                           "malloc codecbuf(%d) failed\n", len);
                        error = ENOMEM;
                        goto abort;
                }
@@ -5490,8 +5510,9 @@
                        error = sc->hw_if->trigger_output(sc->hw_hdl,
                            start, end, blksize, audio_pintr, sc, &params);
                        if (error) {
-                               device_printf(sc->sc_dev,
-                                   "trigger_output failed with %d\n", error);
+                               audio_printf(sc,
+                                   "trigger_output failed: errno=%d\n",
+                                   error);
                                return;
                        }
                }
@@ -5502,8 +5523,8 @@
                error = sc->hw_if->start_output(sc->hw_hdl,



Home | Main Index | Thread Index | Old Index