Module Name: src Committed By: nat Date: Sat Oct 15 07:08:06 UTC 2016
Modified Files: src/sys/dev/pad: pad.c src/tests/dev/audio: h_pad.c Log Message: pad(4) must be open before corresponding audio device is opened. OK christos@ To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/dev/pad/pad.c cvs rdiff -u -r1.1 -r1.2 src/tests/dev/audio/h_pad.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pad/pad.c diff -u src/sys/dev/pad/pad.c:1.25 src/sys/dev/pad/pad.c:1.26 --- src/sys/dev/pad/pad.c:1.25 Thu Jul 7 06:55:41 2016 +++ src/sys/dev/pad/pad.c Sat Oct 15 07:08:06 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pad.c,v 1.25 2016/07/07 06:55:41 msaitoh Exp $ */ +/* $NetBSD: pad.c,v 1.26 2016/10/15 07:08:06 nat Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.25 2016/07/07 06:55:41 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.26 2016/10/15 07:08:06 nat Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -74,6 +74,7 @@ static void pad_attach(device_t, device_ static int pad_detach(device_t, int); static void pad_childdet(device_t, device_t); +static int pad_audio_open(void *, int); static int pad_query_encoding(void *, struct audio_encoding *); static int pad_set_params(void *, int, int, audio_params_t *, audio_params_t *, @@ -99,6 +100,7 @@ static stream_filter_t *pad_swvol_filter static void pad_swvol_dtor(stream_filter_t *); static const struct audio_hw_if pad_hw_if = { + .open = pad_audio_open, .query_encoding = pad_query_encoding, .set_params = pad_set_params, .start_output = pad_start_output, @@ -341,7 +343,7 @@ pad_close(dev_t dev, int flags, int fmt, #define PAD_BYTES_PER_SEC (44100 * sizeof(int16_t) * 2) #define TIMENEXTREAD (20 * 1000) -#define BYTESTOSLEEP (PAD_BYTES_PER_SEC / (1000000 / TIMENEXTREAD)) +#define BYTESTOSLEEP ((PAD_BYTES_PER_SEC / (1000000 / TIMENEXTREAD)) + PAD_BLKSIZE) int pad_read(dev_t dev, struct uio *uio, int flags) @@ -420,6 +422,19 @@ pad_read(dev_t dev, struct uio *uio, int } static int +pad_audio_open(void *opaque, int flags) +{ + pad_softc_t *sc; + sc = opaque; + + if (sc->sc_open == 0) + return EIO; + + getmicrotime(&sc->sc_last); + return 0; +} + +static int pad_query_encoding(void *opaque, struct audio_encoding *ae) { pad_softc_t *sc; @@ -477,6 +492,8 @@ pad_start_output(void *opaque, void *blo sc = (pad_softc_t *)opaque; KASSERT(mutex_owned(&sc->sc_lock)); + if (!sc->sc_open) + return EIO; sc->sc_intr = intr; sc->sc_intrarg = intrarg; Index: src/tests/dev/audio/h_pad.c diff -u src/tests/dev/audio/h_pad.c:1.1 src/tests/dev/audio/h_pad.c:1.2 --- src/tests/dev/audio/h_pad.c:1.1 Wed Aug 4 13:15:15 2010 +++ src/tests/dev/audio/h_pad.c Sat Oct 15 07:08:06 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: h_pad.c,v 1.1 2010/08/04 13:15:15 pooka Exp $ */ +/* $NetBSD: h_pad.c,v 1.2 2016/10/15 07:08:06 nat Exp $ */ /* * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -56,14 +56,14 @@ main(int argc, char *argv[]) ssize_t n; rump_init(); - audiofd = rump_sys_open("/dev/audio0", O_RDWR); - if (audiofd == -1) - err(1, "open audio"); - padfd = rump_sys_open("/dev/pad0", O_RDONLY); if (padfd == -1) err(1, "open pad"); + audiofd = rump_sys_open("/dev/audio0", O_RDWR); + if (audiofd == -1) + err(1, "open audio"); + if ((n = rump_sys_write(audiofd, musa, sizeof(musa))) != sizeof(musa)) err(1, "write");