Tue Aug 15 05:11:25 2017 UTC ()
Clean up audio_allocbufs().
As a result of sc_audiochan cleanup, it is easy to access sc_hwvc.


(isaki)
diff -r1.395 -r1.396 src/sys/dev/audio.c

cvs diff -r1.395 -r1.396 src/sys/dev/Attic/audio.c (expand / switch to unified diff)

--- src/sys/dev/Attic/audio.c 2017/08/15 05:05:32 1.395
+++ src/sys/dev/Attic/audio.c 2017/08/15 05:11:25 1.396
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: audio.c,v 1.395 2017/08/15 05:05:32 isaki Exp $ */ 1/* $NetBSD: audio.c,v 1.396 2017/08/15 05:11:25 isaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> 4 * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Copyright (c) 2008 The NetBSD Foundation, Inc. 7 * Copyright (c) 2008 The NetBSD Foundation, Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Andrew Doran. 11 * by Andrew Doran.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -138,27 +138,27 @@ @@ -138,27 +138,27 @@
138 * query_devinfo - x 138 * query_devinfo - x
139 * allocm - - Called at attach time 139 * allocm - - Called at attach time
140 * freem - - Called at attach time 140 * freem - - Called at attach time
141 * round_buffersize - x 141 * round_buffersize - x
142 * mappage - - Mem. unchanged after attach 142 * mappage - - Mem. unchanged after attach
143 * get_props - x 143 * get_props - x
144 * trigger_output x x 144 * trigger_output x x
145 * trigger_input x x 145 * trigger_input x x
146 * dev_ioctl - x 146 * dev_ioctl - x
147 * get_locks - - Called at attach time 147 * get_locks - - Called at attach time
148 */ 148 */
149 149
150#include <sys/cdefs.h> 150#include <sys/cdefs.h>
151__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.395 2017/08/15 05:05:32 isaki Exp $"); 151__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.396 2017/08/15 05:11:25 isaki Exp $");
152 152
153#ifdef _KERNEL_OPT 153#ifdef _KERNEL_OPT
154#include "audio.h" 154#include "audio.h"
155#include "midi.h" 155#include "midi.h"
156#endif 156#endif
157 157
158#if NAUDIO > 0 158#if NAUDIO > 0
159 159
160#include <sys/types.h> 160#include <sys/types.h>
161#include <sys/param.h> 161#include <sys/param.h>
162#include <sys/ioctl.h> 162#include <sys/ioctl.h>
163#include <sys/fcntl.h> 163#include <sys/fcntl.h>
164#include <sys/file.h> 164#include <sys/file.h>
@@ -269,27 +269,27 @@ void audio_play_thread(void *); @@ -269,27 +269,27 @@ void audio_play_thread(void *);
269void audio_rec_thread(void *); 269void audio_rec_thread(void *);
270void recswvol_func(struct audio_softc *, struct audio_ringbuffer *, 270void recswvol_func(struct audio_softc *, struct audio_ringbuffer *,
271 size_t, struct virtual_channel *); 271 size_t, struct virtual_channel *);
272void mix_func(struct audio_softc *, struct audio_ringbuffer *, 272void mix_func(struct audio_softc *, struct audio_ringbuffer *,
273 struct virtual_channel *); 273 struct virtual_channel *);
274int mix_write(void *); 274int mix_write(void *);
275int mix_read(void *); 275int mix_read(void *);
276int audio_check_params(struct audio_params *); 276int audio_check_params(struct audio_params *);
277 277
278void audio_calc_blksize(struct audio_softc *, int, struct virtual_channel *); 278void audio_calc_blksize(struct audio_softc *, int, struct virtual_channel *);
279void audio_fill_silence(const struct audio_params *, uint8_t *, int); 279void audio_fill_silence(const struct audio_params *, uint8_t *, int);
280int audio_silence_copyout(struct audio_softc *, int, struct uio *); 280int audio_silence_copyout(struct audio_softc *, int, struct uio *);
281 281
282static int audio_allocbufs(struct audio_softc *, struct virtual_channel *); 282static int audio_allocbufs(struct audio_softc *);
283void audio_init_ringbuffer(struct audio_softc *, 283void audio_init_ringbuffer(struct audio_softc *,
284 struct audio_ringbuffer *, int); 284 struct audio_ringbuffer *, int);
285int audio_initbufs(struct audio_softc *, struct virtual_channel *); 285int audio_initbufs(struct audio_softc *, struct virtual_channel *);
286void audio_calcwater(struct audio_softc *, struct virtual_channel *); 286void audio_calcwater(struct audio_softc *, struct virtual_channel *);
287int audio_drain(struct audio_softc *, struct virtual_channel *); 287int audio_drain(struct audio_softc *, struct virtual_channel *);
288void audio_clear(struct audio_softc *, struct virtual_channel *); 288void audio_clear(struct audio_softc *, struct virtual_channel *);
289void audio_clear_intr_unlocked(struct audio_softc *sc, 289void audio_clear_intr_unlocked(struct audio_softc *sc,
290 struct virtual_channel *); 290 struct virtual_channel *);
291static inline void 291static inline void
292 audio_pint_silence(struct audio_softc *, struct audio_ringbuffer *, 292 audio_pint_silence(struct audio_softc *, struct audio_ringbuffer *,
293 uint8_t *, int, struct virtual_channel *); 293 uint8_t *, int, struct virtual_channel *);
294int audio_alloc_ring(struct audio_softc *, struct audio_ringbuffer *, int, 294int audio_alloc_ring(struct audio_softc *, struct audio_ringbuffer *, int,
295 size_t); 295 size_t);
@@ -582,27 +582,27 @@ audioattach(device_t parent, device_t se @@ -582,27 +582,27 @@ audioattach(device_t parent, device_t se
582 if (props & AUDIO_PROP_PLAYBACK) 582 if (props & AUDIO_PROP_PLAYBACK)
583 aprint_normal(", playback"); 583 aprint_normal(", playback");
584 if (props & AUDIO_PROP_CAPTURE) 584 if (props & AUDIO_PROP_CAPTURE)
585 aprint_normal(", capture"); 585 aprint_normal(", capture");
586 if (props & AUDIO_PROP_MMAP) 586 if (props & AUDIO_PROP_MMAP)
587 aprint_normal(", mmap"); 587 aprint_normal(", mmap");
588 if (props & AUDIO_PROP_INDEPENDENT) 588 if (props & AUDIO_PROP_INDEPENDENT)
589 aprint_normal(", independent"); 589 aprint_normal(", independent");
590 590
591 aprint_naive("\n"); 591 aprint_naive("\n");
592 aprint_normal("\n"); 592 aprint_normal("\n");
593 593
594 mutex_enter(sc->sc_lock); 594 mutex_enter(sc->sc_lock);
595 if (audio_allocbufs(sc, vc) != 0) { 595 if (audio_allocbufs(sc) != 0) {
596 aprint_error_dev(sc->sc_dev, 596 aprint_error_dev(sc->sc_dev,
597 "could not allocate ring buffer\n"); 597 "could not allocate ring buffer\n");
598 mutex_exit(sc->sc_lock); 598 mutex_exit(sc->sc_lock);
599 return; 599 return;
600 } 600 }
601 mutex_exit(sc->sc_lock); 601 mutex_exit(sc->sc_lock);
602 602
603 sc->sc_lastgain = 128; 603 sc->sc_lastgain = 128;
604 sc->sc_multiuser = false; 604 sc->sc_multiuser = false;
605 605
606 error = vchan_autoconfig(sc); 606 error = vchan_autoconfig(sc);
607 if (error != 0) { 607 if (error != 0) {
608 aprint_error_dev(sc->sc_dev, "%s: audio_set_vchan_defaults() " 608 aprint_error_dev(sc->sc_dev, "%s: audio_set_vchan_defaults() "
@@ -1097,30 +1097,33 @@ audio_printsc(struct audio_softc *sc) @@ -1097,30 +1097,33 @@ audio_printsc(struct audio_softc *sc)
1097 vc->sc_mpr.usedlow); 1097 vc->sc_mpr.usedlow);
1098} 1098}
1099 1099
1100void 1100void
1101audio_print_params(const char *s, struct audio_params *p) 1101audio_print_params(const char *s, struct audio_params *p)
1102{ 1102{
1103 printf("%s enc=%u %uch %u/%ubit %uHz\n", s, p->encoding, p->channels, 1103 printf("%s enc=%u %uch %u/%ubit %uHz\n", s, p->encoding, p->channels,
1104 p->validbits, p->precision, p->sample_rate); 1104 p->validbits, p->precision, p->sample_rate);
1105} 1105}
1106#endif 1106#endif
1107 1107
1108/* Allocate all ring buffers. called from audioattach() */ 1108/* Allocate all ring buffers. called from audioattach() */
1109static int 1109static int
1110audio_allocbufs(struct audio_softc *sc, struct virtual_channel *vc) 1110audio_allocbufs(struct audio_softc *sc)
1111{ 1111{
 1112 struct virtual_channel *vc;
1112 int error; 1113 int error;
1113 1114
 1115 vc = sc->sc_hwvc;
 1116
1114 sc->sc_pr.s.start = NULL; 1117 sc->sc_pr.s.start = NULL;
1115 vc->sc_mpr.s.start = NULL; 1118 vc->sc_mpr.s.start = NULL;
1116 sc->sc_rr.s.start = NULL; 1119 sc->sc_rr.s.start = NULL;
1117 vc->sc_mrr.s.start = NULL; 1120 vc->sc_mrr.s.start = NULL;
1118 1121
1119 if (audio_can_playback(sc)) { 1122 if (audio_can_playback(sc)) {
1120 error = audio_alloc_ring(sc, &sc->sc_pr, 1123 error = audio_alloc_ring(sc, &sc->sc_pr,
1121 AUMODE_PLAY, AU_RING_SIZE); 1124 AUMODE_PLAY, AU_RING_SIZE);
1122 if (error) 1125 if (error)
1123 goto bad_play1; 1126 goto bad_play1;
1124 1127
1125 error = audio_alloc_ring(sc, &vc->sc_mpr, 1128 error = audio_alloc_ring(sc, &vc->sc_mpr,
1126 AUMODE_PLAY, AU_RING_SIZE); 1129 AUMODE_PLAY, AU_RING_SIZE);