| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pad.c,v 1.26 2016/10/15 07:08:06 nat Exp $ */ | | 1 | /* $NetBSD: pad.c,v 1.27 2017/01/26 04:10:27 nat Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.26 2016/10/15 07:08:06 nat Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.27 2017/01/26 04:10:27 nat Exp $"); |
31 | | | 31 | |
32 | #include <sys/types.h> | | 32 | #include <sys/types.h> |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/conf.h> | | 34 | #include <sys/conf.h> |
35 | #include <sys/buf.h> | | 35 | #include <sys/buf.h> |
36 | #include <sys/kmem.h> | | 36 | #include <sys/kmem.h> |
37 | #include <sys/kernel.h> | | 37 | #include <sys/kernel.h> |
38 | #include <sys/device.h> | | 38 | #include <sys/device.h> |
39 | #include <sys/proc.h> | | 39 | #include <sys/proc.h> |
40 | #include <sys/condvar.h> | | 40 | #include <sys/condvar.h> |
41 | #include <sys/select.h> | | 41 | #include <sys/select.h> |
42 | #include <sys/audioio.h> | | 42 | #include <sys/audioio.h> |
43 | #include <sys/vnode.h> | | 43 | #include <sys/vnode.h> |
| @@ -352,31 +352,31 @@ pad_read(dev_t dev, struct uio *uio, int | | | @@ -352,31 +352,31 @@ pad_read(dev_t dev, struct uio *uio, int |
352 | uint64_t nowusec, lastusec; | | 352 | uint64_t nowusec, lastusec; |
353 | pad_softc_t *sc; | | 353 | pad_softc_t *sc; |
354 | pad_block_t pb; | | 354 | pad_block_t pb; |
355 | void (*intr)(void *); | | 355 | void (*intr)(void *); |
356 | void *intrarg; | | 356 | void *intrarg; |
357 | int err, wait_ticks; | | 357 | int err, wait_ticks; |
358 | | | 358 | |
359 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); | | 359 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); |
360 | if (sc == NULL) | | 360 | if (sc == NULL) |
361 | return ENXIO; | | 361 | return ENXIO; |
362 | | | 362 | |
363 | err = 0; | | 363 | err = 0; |
364 | | | 364 | |
365 | mutex_enter(&sc->sc_lock); | | | |
366 | intr = sc->sc_intr; | | | |
367 | intrarg = sc->sc_intrarg; | | | |
368 | | | | |
369 | while (uio->uio_resid > 0 && !err) { | | 365 | while (uio->uio_resid > 0 && !err) { |
| | | 366 | mutex_enter(&sc->sc_lock); |
| | | 367 | intr = sc->sc_intr; |
| | | 368 | intrarg = sc->sc_intrarg; |
| | | 369 | |
370 | getmicrotime(&now); | | 370 | getmicrotime(&now); |
371 | nowusec = (now.tv_sec * 1000000) + now.tv_usec; | | 371 | nowusec = (now.tv_sec * 1000000) + now.tv_usec; |
372 | lastusec = (sc->sc_last.tv_sec * 1000000) + | | 372 | lastusec = (sc->sc_last.tv_sec * 1000000) + |
373 | sc->sc_last.tv_usec; | | 373 | sc->sc_last.tv_usec; |
374 | if (lastusec + TIMENEXTREAD > nowusec && | | 374 | if (lastusec + TIMENEXTREAD > nowusec && |
375 | sc->sc_bytes_count >= BYTESTOSLEEP) { | | 375 | sc->sc_bytes_count >= BYTESTOSLEEP) { |
376 | wait_ticks = (hz * ((lastusec + TIMENEXTREAD) - | | 376 | wait_ticks = (hz * ((lastusec + TIMENEXTREAD) - |
377 | nowusec)) / 1000000; | | 377 | nowusec)) / 1000000; |
378 | if (wait_ticks > 0) { | | 378 | if (wait_ticks > 0) { |
379 | kpause("padwait", TRUE, wait_ticks, | | 379 | kpause("padwait", TRUE, wait_ticks, |
380 | &sc->sc_lock); | | 380 | &sc->sc_lock); |
381 | } | | 381 | } |
382 | | | 382 | |
| @@ -384,49 +384,49 @@ pad_read(dev_t dev, struct uio *uio, int | | | @@ -384,49 +384,49 @@ pad_read(dev_t dev, struct uio *uio, int |
384 | getmicrotime(&sc->sc_last); | | 384 | getmicrotime(&sc->sc_last); |
385 | } else if (sc->sc_bytes_count >= BYTESTOSLEEP) { | | 385 | } else if (sc->sc_bytes_count >= BYTESTOSLEEP) { |
386 | sc->sc_bytes_count -= BYTESTOSLEEP; | | 386 | sc->sc_bytes_count -= BYTESTOSLEEP; |
387 | getmicrotime(&sc->sc_last); | | 387 | getmicrotime(&sc->sc_last); |
388 | } else if (lastusec + TIMENEXTREAD <= nowusec) | | 388 | } else if (lastusec + TIMENEXTREAD <= nowusec) |
389 | getmicrotime(&sc->sc_last); | | 389 | getmicrotime(&sc->sc_last); |
390 | | | 390 | |
391 | err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE)); | | 391 | err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE)); |
392 | if (!err) { | | 392 | if (!err) { |
393 | sc->sc_bytes_count += pb.pb_len; | | 393 | sc->sc_bytes_count += pb.pb_len; |
394 | | | 394 | |
395 | mutex_exit(&sc->sc_lock); | | 395 | mutex_exit(&sc->sc_lock); |
396 | err = uiomove(pb.pb_ptr, pb.pb_len, uio); | | 396 | err = uiomove(pb.pb_ptr, pb.pb_len, uio); |
397 | mutex_enter(&sc->sc_lock); | | | |
398 | continue; | | 397 | continue; |
399 | } | | 398 | } |
400 | | | 399 | |
401 | if (intr) { | | 400 | if (intr) { |
402 | mutex_enter(&sc->sc_intr_lock); | | 401 | mutex_enter(&sc->sc_intr_lock); |
403 | kpreempt_disable(); | | 402 | kpreempt_disable(); |
404 | (*intr)(intrarg); | | 403 | (*intr)(intrarg); |
405 | kpreempt_enable(); | | 404 | kpreempt_enable(); |
406 | mutex_exit(&sc->sc_intr_lock); | | 405 | mutex_exit(&sc->sc_intr_lock); |
407 | intr = sc->sc_intr; | | 406 | intr = sc->sc_intr; |
408 | intrarg = sc->sc_intrarg; | | 407 | intrarg = sc->sc_intrarg; |
409 | err = 0; | | 408 | err = 0; |
| | | 409 | mutex_exit(&sc->sc_lock); |
410 | continue; | | 410 | continue; |
411 | } | | 411 | } |
412 | err = cv_wait_sig(&sc->sc_condvar, &sc->sc_lock); | | 412 | err = cv_wait_sig(&sc->sc_condvar, &sc->sc_lock); |
413 | if (err != 0) | | 413 | if (err != 0) { |
| | | 414 | mutex_exit(&sc->sc_lock); |
414 | break; | | 415 | break; |
| | | 416 | } |
415 | | | 417 | |
416 | intr = sc->sc_intr; | | 418 | mutex_exit(&sc->sc_lock); |
417 | intrarg = sc->sc_intrarg; | | | |
418 | } | | 419 | } |
419 | mutex_exit(&sc->sc_lock); | | | |
420 | | | 420 | |
421 | return err; | | 421 | return err; |
422 | } | | 422 | } |
423 | | | 423 | |
424 | static int | | 424 | static int |
425 | pad_audio_open(void *opaque, int flags) | | 425 | pad_audio_open(void *opaque, int flags) |
426 | { | | 426 | { |
427 | pad_softc_t *sc; | | 427 | pad_softc_t *sc; |
428 | sc = opaque; | | 428 | sc = opaque; |
429 | | | 429 | |
430 | if (sc->sc_open == 0) | | 430 | if (sc->sc_open == 0) |
431 | return EIO; | | 431 | return EIO; |
432 | | | 432 | |