Index: sys/dev/audio.c
===================================================================
RCS file: /home/repos/netbsd-current/src/sys/dev/audio.c,v
retrieving revision 1.243
diff -u -r1.243 audio.c
--- sys/dev/audio.c     10 Jun 2008 22:53:08 -0000      1.243
+++ sys/dev/audio.c     8 Dec 2008 08:15:21 -0000
@@ -88,7 +88,7 @@

#include <machine/endian.h>

-/* #define AUDIO_DEBUG 1 */
+/*#define AUDIO_DEBUG  1*/
#ifdef AUDIO_DEBUG
#define DPRINTF(x)     if (audiodebug) printf x
#define DPRINTFN(n,x)  if (audiodebug>(n)) printf x
@@ -285,16 +285,35 @@
       struct audio_attach_args *sa;
       const struct audio_hw_if *hwp;
       void *hdlp;
-       int error;
-       mixer_devinfo_t mi;
-       int iclass, mclass, oclass, rclass, props;
-       int record_master_found, record_source_found;

       sc = device_private(self);
       sc->dev = self;
+
       sa = aux;
       hwp = sa->hwif;
       hdlp = sa->hdl;
+
+       sc->hw_if = hwp;
+       sc->hw_hdl = hdlp;
+       sc->sc_dev = parent;
+
+       audio_attach(sc);
+}
+
+void
+audio_attach(struct audio_softc *sc)
+{
+       const struct audio_hw_if *hwp;
+       void *hdlp;
+
+       int error;
+       mixer_devinfo_t mi;
+       int iclass, mclass, oclass, rclass, props;
+       int record_master_found, record_source_found;
+
+       hwp = sc->hw_if;
+       hdlp = sc->hw_hdl;
+
#ifdef DIAGNOSTIC
       if (hwp == 0 ||
           hwp->query_encoding == 0 ||
@@ -330,9 +349,6 @@

       aprint_normal("\n");

-       sc->hw_if = hwp;
-       sc->hw_hdl = hdlp;
-       sc->sc_dev = parent;
       sc->sc_opencnt = 0;
       sc->sc_writing = sc->sc_waitcomp = 0;
       sc->sc_lastinfovalid = false;
@@ -495,25 +511,25 @@

#ifdef AUDIO_PM_IDLE
       callout_init(&sc->sc_idle_counter, 0);
-       callout_setfunc(&sc->sc_idle_counter, audio_idle, self);
+       callout_setfunc(&sc->sc_idle_counter, audio_idle, sc->dev);
#endif

-       if (!pmf_device_register(self, audio_suspend, audio_resume))
-               aprint_error_dev(self, "couldn't establish power handler\n");
+       if (!pmf_device_register(sc->dev, audio_suspend, audio_resume))
+               aprint_error_dev(sc->dev, "couldn't establish power handler\n");
#ifdef AUDIO_PM_IDLE
-       if (!device_active_register(self, audio_activity))
-               aprint_error_dev(self, "couldn't register activity handler\n");
+       if (!device_active_register(sc->dev, audio_activity))
+               aprint_error_dev(sc->dev, "couldn't register activity handler\n");
#endif

-       if (!pmf_event_register(self, PMFE_AUDIO_VOLUME_DOWN,
+       if (!pmf_event_register(sc->dev, PMFE_AUDIO_VOLUME_DOWN,
           audio_volume_down, true))
-               aprint_error_dev(self, "couldn't add volume down handler\n");
-       if (!pmf_event_register(self, PMFE_AUDIO_VOLUME_UP,
+               aprint_error_dev(sc->dev, "couldn't add volume down handler\n");
+       if (!pmf_event_register(sc->dev, PMFE_AUDIO_VOLUME_UP,
           audio_volume_up, true))
-               aprint_error_dev(self, "couldn't add volume up handler\n");
-       if (!pmf_event_register(self, PMFE_AUDIO_VOLUME_TOGGLE,
+               aprint_error_dev(sc->dev, "couldn't add volume up handler\n");
+       if (!pmf_event_register(sc->dev, PMFE_AUDIO_VOLUME_TOGGLE,
           audio_volume_toggle, true))
-               aprint_error_dev(self, "couldn't add volume toggle handler\n");
+               aprint_error_dev(sc->dev, "couldn't add volume toggle handler\n");

#ifdef AUDIO_PM_IDLE
       callout_schedule(&sc->sc_idle_counter, audio_idle_timeout * hz);
@@ -3583,6 +3599,10 @@
               s = splaudio();
               init_error = audio_initbufs(sc);
               if (init_error) goto err;
+               if (sc->sc_pustream == NULL ||
+                   sc->sc_rustream == NULL) {
+                       goto err;
+               }
               if (sc->sc_pr.blksize != oldpblksize ||
                   sc->sc_rr.blksize != oldrblksize ||
                   sc->sc_pustream != oldpus ||
Index: sys/dev/audio_if.h
===================================================================
RCS file: /home/repos/netbsd-current/src/sys/dev/audio_if.h,v
retrieving revision 1.65
diff -u -r1.65 audio_if.h
--- sys/dev/audio_if.h  4 Mar 2008 18:23:44 -0000       1.65
+++ sys/dev/audio_if.h  3 Dec 2008 17:42:12 -0000
@@ -254,6 +254,10 @@

/* Attach the MI driver(s) to the MD driver. */
device_t audio_attach_mi(const struct audio_hw_if *, void *, device_t);
+
+/* Generic audio(9) attach routine */
+void audio_attach(struct audio_softc *);
+
int    audioprint(void *, const char *);

/* Device identity flags */
Index: sys/dev/audiovar.h
===================================================================
RCS file: /home/repos/netbsd-current/src/sys/dev/audiovar.h,v
retrieving revision 1.45
diff -u -r1.45 audiovar.h
--- sys/dev/audiovar.h  28 Apr 2008 20:23:46 -0000      1.45
+++ sys/dev/audiovar.h  6 Dec 2008 04:18:41 -0000
@@ -65,6 +65,9 @@
 */
#ifndef _SYS_DEV_AUDIOVAR_H_
#define _SYS_DEV_AUDIOVAR_H_
+
+#include <sys/select.h>
+
#include <dev/audio_if.h>

/*