Source-Changes-HG archive

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

[src/netbsd-7]: src/sys Pull up following revision(s) (requested by skrll in ...



details:   https://anonhg.NetBSD.org/src/rev/69156d7e5920
branches:  netbsd-7
changeset: 798450:69156d7e5920
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Oct 19 15:22:00 2014 +0000

description:
Pull up following revision(s) (requested by skrll in ticket #151):
        sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_shim.c: revision 1.5
        sys/arch/arm/broadcom/bcm2835_vcaudio.c: revision 1.4
        sys/arch/arm/broadcom/bcm2835_vcaudio.c: revision 1.5
        sys/arch/arm/broadcom/bcm2835_vcaudio.c: revision 1.6
        sys/arch/arm/broadcom/bcm2835_vcaudio.c: revision 1.7
use a fixed frequency (48kHz) and configure the audio server at attach time, instead of at the beginning of playback
improved playback error handling, and get rid of junk+silence insertion at the beginning of playback
expose vchi_get_peer_version
capture peer version; if less than 2, bail out as bulk mode is not supported. report the peer version with "audioctl version"
Some improvements that make playback mostly reliable for me - the final
piece of the jigaw is probably in vchiq:
- prefill vchiq with a number (currently 2) blocks of audio before
   starting
- use a kthread as workqueue isn't suited to our usage.
- don't drain on stopping as for some reason it leaves data behind.

diffstat:

 sys/arch/arm/broadcom/bcm2835_vcaudio.c                      |  340 ++++++----
 sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_shim.c |    2 +-
 2 files changed, 201 insertions(+), 141 deletions(-)

diffs (truncated from 613 to 300 lines):

diff -r 6c671c901a4b -r 69156d7e5920 sys/arch/arm/broadcom/bcm2835_vcaudio.c
--- a/sys/arch/arm/broadcom/bcm2835_vcaudio.c   Sun Oct 19 10:04:00 2014 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_vcaudio.c   Sun Oct 19 15:22:00 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_vcaudio.c,v 1.3 2014/05/05 08:13:31 skrll Exp $ */
+/* $NetBSD: bcm2835_vcaudio.c,v 1.3.4.1 2014/10/19 15:22:00 martin Exp $ */
 
 /*-
  * Copyright (c) 2013 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_vcaudio.c,v 1.3 2014/05/05 08:13:31 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_vcaudio.c,v 1.3.4.1 2014/10/19 15:22:00 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -40,7 +40,6 @@
 #include <sys/conf.h>
 #include <sys/bus.h>
 #include <sys/kmem.h>
-#include <sys/workqueue.h>
 
 #include <sys/audioio.h>
 #include <dev/audio_if.h>
@@ -68,16 +67,33 @@
        VCAUDIO_DEST_HDMI = 2,
 };
 
-struct vcaudio_work {
-       struct work                     vw_wk;
-};
+
+/*
+ * Standard message size is 4000 bytes and VCHIQ can accept 16 messages.
+ *
+ * 4000 bytes of 16bit 48kHz stereo is approximately 21ms.
+ *
+ * We get complete messages at ~10ms intervals.
+ *
+ * Setting blocksize to 2 x 4000 means that we send approx 42ms of audio. We
+ * prefill by two blocks before starting audio meaning we have 83ms of latency.
+ */
+
+#define VCAUDIO_MSGSIZE                4000
+#define VCAUDIO_NUMMSGS                2
+#define VCAUDIO_BLOCKSIZE      (VCAUDIO_MSGSIZE * VCAUDIO_NUMMSGS)
+#define VCAUDIO_BUFFERSIZE     128000
+#define VCAUDIO_PREFILLCOUNT   2
 
 struct vcaudio_softc {
        device_t                        sc_dev;
        device_t                        sc_audiodev;
 
+       lwp_t                           *sc_lwp;
+
        kmutex_t                        sc_lock;
        kmutex_t                        sc_intr_lock;
+       kcondvar_t                      sc_datacv;
 
        kmutex_t                        sc_msglock;
        kcondvar_t                      sc_msgcv;
@@ -89,7 +105,9 @@
        void                            *sc_pintarg;
        audio_params_t                  sc_pparam;
        bool                            sc_started;
-       int                             sc_pbytes;
+       int                             sc_pblkcnt;     // prefill block count
+       int                             sc_abytes;      // available bytes
+       int                             sc_pbytes;      // played bytes
        off_t                           sc_ppos;
        void                            *sc_pstart;
        void                            *sc_pend;
@@ -102,8 +120,7 @@
        VCHI_CONNECTION_T               sc_connection;
        VCHI_SERVICE_HANDLE_T           sc_service;
 
-       struct workqueue                *sc_wq;
-       struct vcaudio_work             sc_work;
+       short                           sc_peer_version;
 
        int                             sc_volume;
        enum vcaudio_dest               sc_dest;
@@ -116,18 +133,17 @@
 
 static int     vcaudio_init(struct vcaudio_softc *);
 static void    vcaudio_service_callback(void *,
-                                        const VCHI_CALLBACK_REASON_T,
-                                        void *);
-static int     vcaudio_msg_sync(struct vcaudio_softc *, VC_AUDIO_MSG_T *, size_t);
-static void    vcaudio_worker(struct work *, void *);
+    const VCHI_CALLBACK_REASON_T, void *);
+static int     vcaudio_msg_sync(struct vcaudio_softc *, VC_AUDIO_MSG_T *,
+    size_t);
+static void    vcaudio_worker(void *);
 
 static int     vcaudio_open(void *, int);
 static void    vcaudio_close(void *);
 static int     vcaudio_query_encoding(void *, struct audio_encoding *);
 static int     vcaudio_set_params(void *, int, int,
-                                 audio_params_t *, audio_params_t *,
-                                 stream_filter_list_t *,
-                                 stream_filter_list_t *);
+    audio_params_t *, audio_params_t *,
+    stream_filter_list_t *, stream_filter_list_t *);
 static int     vcaudio_halt_output(void *);
 static int     vcaudio_halt_input(void *);
 static int     vcaudio_set_port(void *, mixer_ctrl_t *);
@@ -135,14 +151,16 @@
 static int     vcaudio_query_devinfo(void *, mixer_devinfo_t *);
 static int     vcaudio_getdev(void *, struct audio_device *);
 static int     vcaudio_get_props(void *);
-static int     vcaudio_round_blocksize(void *, int, int, const audio_params_t *);
+
+static int     vcaudio_round_blocksize(void *, int, int,
+    const audio_params_t *);
 static size_t  vcaudio_round_buffersize(void *, int, size_t);
+
 static int     vcaudio_trigger_output(void *, void *, void *, int,
-                                    void (*)(void *), void *,
-                                    const audio_params_t *);
+    void (*)(void *), void *, const audio_params_t *);
 static int     vcaudio_trigger_input(void *, void *, void *, int,
-                                   void (*)(void *), void *,
-                                   const audio_params_t *);
+    void (*)(void *), void *, const audio_params_t *);
+
 static void    vcaudio_get_locks(void *, kmutex_t **, kmutex_t **);
 
 static const struct audio_hw_if vcaudio_hw_if = {
@@ -165,7 +183,8 @@
 };
 
 CFATTACH_DECL2_NEW(vcaudio, sizeof(struct vcaudio_softc),
-    vcaudio_match, vcaudio_attach, NULL, NULL, vcaudio_rescan, vcaudio_childdet);
+    vcaudio_match, vcaudio_attach, NULL, NULL, vcaudio_rescan,
+    vcaudio_childdet);
 
 static int
 vcaudio_match(device_t parent, cfdata_t match, void *aux)
@@ -185,32 +204,38 @@
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&sc->sc_msglock, MUTEX_DEFAULT, IPL_NONE);
-       cv_init(&sc->sc_msgcv, "vcaudiocv");
+       cv_init(&sc->sc_msgcv, "msg");
+       cv_init(&sc->sc_datacv, "data");
        sc->sc_success = -1;
-       error = workqueue_create(&sc->sc_wq, "vcaudiowq", vcaudio_worker,
-           sc, PRI_BIO, IPL_SCHED, WQ_MPSAFE);
+
+       error = kthread_create(PRI_BIO, KTHREAD_MPSAFE, NULL, vcaudio_worker,
+           sc, &sc->sc_lwp, "vcaudio");
        if (error) {
-               aprint_error(": couldn't create workqueue (%d)\n", error);
+               aprint_error(": couldn't create thread (%d)\n", error);
                return;
        }
 
        aprint_naive("\n");
-       aprint_normal(": AUDS\n");
+       aprint_normal(": auds\n");
 
-       if (vcaudio_init(sc) != 0) {
+       error = vcaudio_rescan(self, NULL, NULL);
+       if (error)
                aprint_error_dev(self, "not configured\n");
-               return;
-       }
 
-       vcaudio_rescan(self, NULL, NULL);
 }
 
 static int
 vcaudio_rescan(device_t self, const char *ifattr, const int *locs)
 {
        struct vcaudio_softc *sc = device_private(self);
+       int error;
 
        if (ifattr_match(ifattr, "audiobus") && sc->sc_audiodev == NULL) {
+               error = vcaudio_init(sc);
+               if (error) {
+                       return error;
+               }
+
                sc->sc_audiodev = audio_attach_mi(&vcaudio_hw_if,
                    sc, sc->sc_dev);
        }
@@ -242,7 +267,7 @@
        sc->sc_format.channels = 2;
        sc->sc_format.channel_mask = AUFMT_STEREO;
        sc->sc_format.frequency_type = 0;
-       sc->sc_format.frequency[0] = 8000;
+       sc->sc_format.frequency[0] = 48000;
        sc->sc_format.frequency[1] = 48000;
 
        error = auconv_create_encodings(&sc->sc_format, 1, &sc->sc_encodings);
@@ -254,15 +279,15 @@
 
        error = vchi_initialise(&sc->sc_instance);
        if (error) {
-               device_printf(sc->sc_dev, "couldn't init vchi instance (%d)\n",
-                   error);
+               aprint_error_dev(sc->sc_dev,
+                   "couldn't init vchi instance (%d)\n", error);
                return EIO;
        }
 
        error = vchi_connect(NULL, 0, sc->sc_instance);
        if (error) {
-               device_printf(sc->sc_dev, "couldn't connect vchi (%d)\n",
-                   error);
+               aprint_error_dev(sc->sc_dev,
+                   "couldn't connect vchi (%d)\n", error);
                return EIO;
        }
 
@@ -281,20 +306,38 @@
 
        error = vchi_service_open(sc->sc_instance, &setup, &sc->sc_service);
        if (error) {
-               device_printf(sc->sc_dev, "couldn't open service (%d)\n",
+               aprint_error_dev(sc->sc_dev, "couldn't open service (%d)\n",
                    error);
                return EIO;
        }
-       vchi_service_release(sc->sc_service);
+
+       vchi_get_peer_version(sc->sc_service, &sc->sc_peer_version);
 
-       vchi_service_use(sc->sc_service);
+       if (sc->sc_peer_version < 2) {
+               aprint_error_dev(sc->sc_dev,
+                   "peer version (%d) is less than the required version (2)\n",
+                   sc->sc_peer_version);
+               return EINVAL;
+       }
+
        memset(&msg, 0, sizeof(msg));
        msg.type = VC_AUDIO_MSG_TYPE_OPEN;
        error = vchi_msg_queue(sc->sc_service, &msg, sizeof(msg),
            VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
        if (error) {
-               device_printf(sc->sc_dev, "couldn't send OPEN message (%d)\n",
-                   error);
+               aprint_error_dev(sc->sc_dev,
+                   "couldn't send OPEN message (%d)\n", error);
+       }
+
+       memset(&msg, 0, sizeof(msg));
+       msg.type = VC_AUDIO_MSG_TYPE_CONFIG;
+       msg.u.config.channels = 2;
+       msg.u.config.samplerate = 48000;
+       msg.u.config.bps = 16;
+       error = vcaudio_msg_sync(sc, &msg, sizeof(msg));
+       if (error) {
+               aprint_error_dev(sc->sc_dev,
+                   "couldn't send CONFIG message (%d)\n", error);
        }
 
        memset(&msg, 0, sizeof(msg));
@@ -303,8 +346,10 @@
        msg.u.control.dest = VCAUDIO_DEST_AUTO;
        error = vcaudio_msg_sync(sc, &msg, sizeof(msg));
        if (error) {
-               device_printf(sc->sc_dev, "couldn't send CONTROL message (%d)\n", error);
+               aprint_error_dev(sc->sc_dev,
+                   "couldn't send CONTROL message (%d)\n", error);
        }
+
        vchi_service_release(sc->sc_service);
 
        return 0;
@@ -341,22 +386,35 @@
                cv_broadcast(&sc->sc_msgcv);
                mutex_exit(&sc->sc_msglock);
                break;
+
        case VC_AUDIO_MSG_TYPE_COMPLETE:
                intr = msg.u.complete.callback;
                intrarg = msg.u.complete.cookie;
                if (intr && intrarg) {
+                       int count = msg.u.complete.count & 0xffff;
+                       int perr = (msg.u.complete.count & __BIT(30)) != 0;
+                       bool sched = false;
+
                        mutex_enter(&sc->sc_intr_lock);
-                       if (msg.u.complete.count > 0 && msg.u.complete.count <= sc->sc_pblksize) {
-                               sc->sc_pbytes += msg.u.complete.count;
-                       } else {
-                               if (sc->sc_started) {
-                                       device_printf(sc->sc_dev, "WARNING: count = %d\n", msg.u.complete.count);
-                               }
+
+                       if (count > 0) {
+                               sc->sc_pbytes += count;
+                       }
+                       if (perr && sc->sc_started) {
+#ifdef VCAUDIO_DEBUG



Home | Main Index | Thread Index | Old Index