vs.c revision 1.47 1 /* $NetBSD: vs.c,v 1.47 2017/09/02 12:52:55 isaki Exp $ */
2
3 /*
4 * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 /*
29 * VS - OKI MSM6258 ADPCM voice synthesizer device driver.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.47 2017/09/02 12:52:55 isaki Exp $");
34
35 #include "audio.h"
36 #include "vs.h"
37 #if NAUDIO > 0 && NVS > 0
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/kmem.h>
43
44 #include <sys/audioio.h>
45 #include <dev/audio_if.h>
46 #include <dev/mulaw.h>
47
48 #include <machine/bus.h>
49 #include <machine/cpu.h>
50
51 #include <dev/ic/msm6258var.h>
52
53 #include <arch/x68k/dev/dmacvar.h>
54 #include <arch/x68k/dev/intiovar.h>
55 #include <arch/x68k/dev/opmvar.h>
56
57 #include <arch/x68k/dev/vsvar.h>
58
59 #ifdef VS_DEBUG
60 #define DPRINTF(y,x) if (vs_debug >= (y)) printf x
61 static int vs_debug;
62 #ifdef AUDIO_DEBUG
63 extern int audiodebug;
64 #endif
65 #else
66 #define DPRINTF(y,x)
67 #endif
68
69 static int vs_match(device_t, cfdata_t, void *);
70 static void vs_attach(device_t, device_t, void *);
71
72 static int vs_dmaintr(void *);
73 static int vs_dmaerrintr(void *);
74
75 /* MI audio layer interface */
76 static int vs_open(void *, int);
77 static void vs_close(void *);
78 static int vs_query_encoding(void *, struct audio_encoding *);
79 static int vs_set_params(void *, int, int, audio_params_t *,
80 audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
81 static int vs_init_output(void *, void *, int);
82 static int vs_init_input(void *, void *, int);
83 static int vs_start_input(void *, void *, int, void (*)(void *), void *);
84 static int vs_start_output(void *, void *, int, void (*)(void *), void *);
85 static int vs_halt_output(void *);
86 static int vs_halt_input(void *);
87 static int vs_allocmem(struct vs_softc *, size_t, size_t, size_t,
88 struct vs_dma *);
89 static void vs_freemem(struct vs_dma *);
90 static int vs_getdev(void *, struct audio_device *);
91 static int vs_set_port(void *, mixer_ctrl_t *);
92 static int vs_get_port(void *, mixer_ctrl_t *);
93 static int vs_query_devinfo(void *, mixer_devinfo_t *);
94 static void *vs_allocm(void *, int, size_t);
95 static void vs_freem(void *, void *, size_t);
96 static size_t vs_round_buffersize(void *, int, size_t);
97 static int vs_get_props(void *);
98 static void vs_get_locks(void *, kmutex_t **, kmutex_t **);
99
100 /* lower functions */
101 static int vs_round_sr(u_long);
102 static void vs_set_sr(struct vs_softc *, int);
103 static inline void vs_set_po(struct vs_softc *, u_long);
104
105 extern struct cfdriver vs_cd;
106
107 CFATTACH_DECL_NEW(vs, sizeof(struct vs_softc),
108 vs_match, vs_attach, NULL, NULL);
109
110 static int vs_attached;
111
112 static const struct audio_hw_if vs_hw_if = {
113 vs_open,
114 vs_close,
115 NULL, /* drain */
116 vs_query_encoding,
117 vs_set_params,
118 NULL, /* round_blocksize */
119 NULL, /* commit_settings */
120 vs_init_output,
121 vs_init_input,
122 vs_start_output,
123 vs_start_input,
124 vs_halt_output,
125 vs_halt_input,
126 NULL, /* speaker_ctl */
127 vs_getdev,
128 NULL, /* setfd */
129 vs_set_port,
130 vs_get_port,
131 vs_query_devinfo,
132 vs_allocm,
133 vs_freem,
134 vs_round_buffersize,
135 NULL, /* mappage */
136 vs_get_props,
137 NULL, /* trigger_output */
138 NULL, /* trigger_input */
139 NULL,
140 vs_get_locks,
141 };
142
143 static struct audio_device vs_device = {
144 "OKI MSM6258",
145 "",
146 "vs"
147 };
148
149 struct {
150 u_long rate;
151 u_char clk;
152 u_char den;
153 } vs_l2r[] = {
154 { VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 },
155 { VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 },
156 { VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024},
157 { VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 },
158 { VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024}
159 };
160
161 #define NUM_RATE (sizeof(vs_l2r)/sizeof(vs_l2r[0]))
162
163 extern stream_filter_factory_t null_filter;
164
165 static int
166 vs_match(device_t parent, cfdata_t cf, void *aux)
167 {
168 struct intio_attach_args *ia;
169
170 ia = aux;
171 if (strcmp(ia->ia_name, "vs") || vs_attached)
172 return 0;
173
174 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
175 ia->ia_addr = VS_ADDR;
176 if (ia->ia_dma == INTIOCF_DMA_DEFAULT)
177 ia->ia_dma = VS_DMA;
178 if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT)
179 ia->ia_dmaintr = VS_DMAINTR;
180
181 /* fixed parameters */
182 if (ia->ia_addr != VS_ADDR)
183 return 0;
184 if (ia->ia_dma != VS_DMA)
185 return 0;
186 if (ia->ia_dmaintr != VS_DMAINTR)
187 return 0;
188
189 #ifdef VS_DEBUG
190 vs_debug = 1;
191 #ifdef AUDIO_DEBUG
192 audiodebug = 2;
193 #endif
194 #endif
195
196 return 1;
197 }
198
199 static void
200 vs_attach(device_t parent, device_t self, void *aux)
201 {
202 struct vs_softc *sc;
203 bus_space_tag_t iot;
204 bus_space_handle_t ioh;
205 struct intio_attach_args *ia;
206
207 sc = device_private(self);
208 sc->sc_dev = self;
209 ia = aux;
210 vs_attached = 1;
211
212 printf("\n");
213
214 /* Re-map the I/O space */
215 iot = ia->ia_bst;
216 bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh);
217
218 /* Initialize sc */
219 sc->sc_iot = iot;
220 sc->sc_ioh = ioh;
221 sc->sc_hw_if = &vs_hw_if;
222 sc->sc_addr = (void *) ia->ia_addr;
223 sc->sc_dmas = NULL;
224 sc->sc_prev_vd = NULL;
225 sc->sc_active = 0;
226 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
227 mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
228
229 /* XXX */
230 bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED,
231 &sc->sc_ppi);
232
233 /* Initialize DMAC */
234 sc->sc_dmat = ia->ia_dmat;
235 sc->sc_dma_ch = dmac_alloc_channel(parent, ia->ia_dma, "vs",
236 ia->ia_dmaintr, vs_dmaintr, sc,
237 ia->ia_dmaintr+1, vs_dmaerrintr, sc,
238 (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC | DMAC_DCR_OPS_8BIT),
239 (DMAC_OCR_SIZE_BYTE | DMAC_OCR_REQG_EXTERNAL));
240
241 aprint_normal_dev(self, "MSM6258V ADPCM voice synthesizer\n");
242
243 audio_attach_mi(&vs_hw_if, sc, sc->sc_dev);
244 }
245
246 /*
247 * vs interrupt handler
248 */
249 static int
250 vs_dmaintr(void *hdl)
251 {
252 struct vs_softc *sc;
253
254 DPRINTF(2, ("vs_dmaintr\n"));
255 sc = hdl;
256
257 mutex_spin_enter(&sc->sc_intr_lock);
258
259 if (sc->sc_pintr) {
260 sc->sc_pintr(sc->sc_parg);
261 } else if (sc->sc_rintr) {
262 sc->sc_rintr(sc->sc_rarg);
263 } else {
264 printf("vs_dmaintr: spurious interrupt\n");
265 }
266
267 mutex_spin_exit(&sc->sc_intr_lock);
268
269 return 1;
270 }
271
272 static int
273 vs_dmaerrintr(void *hdl)
274 {
275 struct vs_softc *sc;
276
277 sc = hdl;
278 DPRINTF(1, ("%s: DMA transfer error.\n", device_xname(sc->sc_dev)));
279 /* XXX */
280 vs_dmaintr(sc);
281
282 return 1;
283 }
284
285
286 /*
287 * audio MD layer interfaces
288 */
289
290 static int
291 vs_open(void *hdl, int flags)
292 {
293 struct vs_softc *sc;
294
295 DPRINTF(1, ("vs_open: flags=%d\n", flags));
296 sc = hdl;
297 sc->sc_pintr = NULL;
298 sc->sc_rintr = NULL;
299 sc->sc_active = 0;
300
301 return 0;
302 }
303
304 static void
305 vs_close(void *hdl)
306 {
307
308 DPRINTF(1, ("vs_close\n"));
309 }
310
311 static int
312 vs_query_encoding(void *hdl, struct audio_encoding *fp)
313 {
314
315 DPRINTF(1, ("vs_query_encoding\n"));
316
317 if (fp->index == 0) {
318 strcpy(fp->name, AudioEslinear);
319 fp->encoding = AUDIO_ENCODING_SLINEAR;
320 fp->precision = 8;
321 fp->flags = 0;
322 return 0;
323 }
324 if (fp->index == 1) {
325 strcpy(fp->name, AudioEslinear_be);
326 fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
327 fp->precision = 16;
328 fp->flags = 0;
329 return 0;
330 }
331 return EINVAL;
332 }
333
334 static int
335 vs_round_sr(u_long rate)
336 {
337 int i;
338 int diff;
339 int nearest;
340
341 diff = rate;
342 nearest = 0;
343 for (i = 0; i < NUM_RATE; i++) {
344 if (rate >= vs_l2r[i].rate) {
345 if (rate - vs_l2r[i].rate < diff) {
346 diff = rate - vs_l2r[i].rate;
347 nearest = i;
348 }
349 } else {
350 if (vs_l2r[i].rate - rate < diff) {
351 diff = vs_l2r[i].rate - rate;
352 nearest = i;
353 }
354 }
355 }
356 if (diff * 100 / rate > 15)
357 return -1;
358 else
359 return nearest;
360 }
361
362 static int
363 vs_set_params(void *hdl, int setmode, int usemode,
364 audio_params_t *play, audio_params_t *rec,
365 stream_filter_list_t *pfil, stream_filter_list_t *rfil)
366 {
367 struct vs_softc *sc;
368 stream_filter_factory_t *pconv;
369 stream_filter_factory_t *rconv;
370 int rate;
371
372 sc = hdl;
373
374 DPRINTF(1, ("vs_set_params: mode=%d enc=%d rate=%d prec=%d ch=%d: ",
375 setmode, play->encoding, play->sample_rate,
376 play->precision, play->channels));
377
378 /* *play and *rec are identical because !AUDIO_PROP_INDEPENDENT */
379
380 if (play->channels != 1) {
381 DPRINTF(1, ("channels not matched\n"));
382 return EINVAL;
383 }
384
385 rate = vs_round_sr(play->sample_rate);
386 if (rate < 0) {
387 DPRINTF(1, ("rate not matched\n"));
388 return EINVAL;
389 }
390
391 if (play->precision == 8 && play->encoding == AUDIO_ENCODING_SLINEAR) {
392 pconv = msm6258_linear8_to_adpcm;
393 rconv = msm6258_adpcm_to_linear8;
394 } else if (play->precision == 16 &&
395 play->encoding == AUDIO_ENCODING_SLINEAR_BE) {
396 pconv = msm6258_slinear16_to_adpcm;
397 rconv = msm6258_adpcm_to_slinear16;
398 } else {
399 DPRINTF(1, ("prec/enc not matched\n"));
400 return EINVAL;
401 }
402
403 sc->sc_current.rate = rate;
404
405 /* pfil and rfil are independent even if !AUDIO_PROP_INDEPENDENT */
406
407 if ((setmode & AUMODE_PLAY) != 0) {
408 pfil->append(pfil, null_filter, play);
409 play->encoding = AUDIO_ENCODING_ADPCM;
410 play->validbits = 4;
411 play->precision = 4;
412 pfil->append(pfil, pconv, play);
413 }
414 if ((setmode & AUMODE_RECORD) != 0) {
415 rfil->append(rfil, null_filter, rec);
416 rec->encoding = AUDIO_ENCODING_ADPCM;
417 rec->validbits = 4;
418 rec->precision = 4;
419 rfil->append(rfil, rconv, rec);
420 }
421
422 DPRINTF(1, ("accepted\n"));
423 return 0;
424 }
425
426 static void
427 vs_set_sr(struct vs_softc *sc, int rate)
428 {
429
430 DPRINTF(1, ("setting sample rate to %d, %d\n",
431 rate, (int)vs_l2r[rate].rate));
432 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
433 (bus_space_read_1 (sc->sc_iot, sc->sc_ppi,
434 PPI_PORTC) & 0xf0)
435 | vs_l2r[rate].den);
436 adpcm_chgclk(vs_l2r[rate].clk);
437 }
438
439 static inline void
440 vs_set_po(struct vs_softc *sc, u_long po)
441 {
442 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
443 (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
444 & 0xfc) | po);
445 }
446
447 static int
448 vs_init_output(void *hdl, void *buffer, int size)
449 {
450 struct vs_softc *sc;
451
452 DPRINTF(1, ("%s\n", __func__));
453 sc = hdl;
454
455 /* Set rate and pan */
456 vs_set_sr(sc, sc->sc_current.rate);
457 vs_set_po(sc, VS_PANOUT_LR);
458
459 return 0;
460 }
461
462 static int
463 vs_init_input(void *hdl, void *buffer, int size)
464 {
465 struct vs_softc *sc;
466
467 DPRINTF(1, ("%s\n", __func__));
468 sc = hdl;
469
470 /* Set rate */
471 vs_set_sr(sc, sc->sc_current.rate);
472
473 return 0;
474 }
475
476 static int
477 vs_start_output(void *hdl, void *block, int blksize, void (*intr)(void *),
478 void *arg)
479 {
480 struct vs_softc *sc;
481 struct vs_dma *vd;
482 struct dmac_channel_stat *chan;
483
484 DPRINTF(2, ("%s: block=%p blksize=%d\n", __func__, block, blksize));
485 sc = hdl;
486
487 sc->sc_pintr = intr;
488 sc->sc_parg = arg;
489
490 /* Find DMA buffer. */
491 for (vd = sc->sc_dmas; vd != NULL; vd = vd->vd_next) {
492 if (KVADDR(vd) <= block && block < KVADDR_END(vd)
493 break;
494 }
495 if (vd == NULL) {
496 printf("%s: start_output: bad addr %p\n",
497 device_xname(sc->sc_dev), block);
498 return EINVAL;
499 }
500
501 chan = sc->sc_dma_ch;
502
503 if (vd != sc->sc_prev_vd) {
504 sc->sc_current.xfer = dmac_prepare_xfer(chan, sc->sc_dmat,
505 vd->vd_map, DMAC_OCR_DIR_MTD,
506 (DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT),
507 sc->sc_addr + MSM6258_DATA * 2 + 1);
508 sc->sc_prev_vd = vd;
509 }
510 dmac_start_xfer_offset(chan->ch_softc, sc->sc_current.xfer,
511 (int)block - (int)KVADDR(vd), blksize);
512
513 if (sc->sc_active == 0) {
514 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 2);
515 sc->sc_active = 1;
516 }
517
518 return 0;
519 }
520
521 static int
522 vs_start_input(void *hdl, void *block, int blksize, void (*intr)(void *),
523 void *arg)
524 {
525 struct vs_softc *sc;
526 struct vs_dma *vd;
527 struct dmac_channel_stat *chan;
528
529 DPRINTF(2, ("%s: block=%p blksize=%d\n", __func__, block, blksize));
530 sc = hdl;
531
532 sc->sc_rintr = intr;
533 sc->sc_rarg = arg;
534
535 /* Find DMA buffer. */
536 for (vd = sc->sc_dmas; vd != NULL; vd = vd->vd_next) {
537 if (KVADDR(vd) <= block && block < KVADDR_END(vd)
538 break;
539 }
540 if (vd == NULL) {
541 printf("%s: start_output: bad addr %p\n",
542 device_xname(sc->sc_dev), block);
543 return EINVAL;
544 }
545
546 chan = sc->sc_dma_ch;
547
548 if (vd != sc->sc_prev_vd) {
549 sc->sc_current.xfer = dmac_prepare_xfer(chan, sc->sc_dmat,
550 vd->vd_map, DMAC_OCR_DIR_DTM,
551 (DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT),
552 sc->sc_addr + MSM6258_DATA * 2 + 1);
553 sc->sc_prev_vd = vd;
554 }
555 dmac_start_xfer_offset(chan->ch_softc, sc->sc_current.xfer,
556 (int)block - (int)KVADDR(vd), blksize);
557
558 if (sc->sc_active == 0) {
559 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 4);
560 sc->sc_active = 1;
561 }
562
563 return 0;
564 }
565
566 static int
567 vs_halt_output(void *hdl)
568 {
569 struct vs_softc *sc;
570
571 DPRINTF(1, ("vs_halt_output\n"));
572 sc = hdl;
573 if (sc->sc_active) {
574 /* stop ADPCM play */
575 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
576 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
577 sc->sc_active = 0;
578 }
579
580 return 0;
581 }
582
583 static int
584 vs_halt_input(void *hdl)
585 {
586 struct vs_softc *sc;
587
588 DPRINTF(1, ("vs_halt_input\n"));
589 sc = hdl;
590 if (sc->sc_active) {
591 /* stop ADPCM recoding */
592 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
593 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
594 sc->sc_active = 0;
595 }
596
597 return 0;
598 }
599
600 static int
601 vs_allocmem(struct vs_softc *sc, size_t size, size_t align, size_t boundary,
602 struct vs_dma *vd)
603 {
604 int error;
605
606 #ifdef DIAGNOSTIC
607 if (size > DMAC_MAXSEGSZ)
608 panic ("vs_allocmem: maximum size exceeded, %d", (int) size);
609 #endif
610
611 vd->vd_size = size;
612
613 error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary,
614 vd->vd_segs,
615 sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]),
616 &vd->vd_nsegs, BUS_DMA_WAITOK);
617 if (error)
618 goto out;
619
620 error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs,
621 vd->vd_size, &vd->vd_addr,
622 BUS_DMA_WAITOK | BUS_DMA_COHERENT);
623 if (error)
624 goto free;
625
626 error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ,
627 0, BUS_DMA_WAITOK, &vd->vd_map);
628 if (error)
629 goto unmap;
630
631 error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr,
632 vd->vd_size, NULL, BUS_DMA_WAITOK);
633 if (error)
634 goto destroy;
635
636 return 0;
637
638 destroy:
639 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
640 unmap:
641 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
642 free:
643 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
644 out:
645 return error;
646 }
647
648 static void
649 vs_freemem(struct vs_dma *vd)
650 {
651
652 bus_dmamap_unload(vd->vd_dmat, vd->vd_map);
653 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
654 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
655 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
656 }
657
658 static int
659 vs_getdev(void *hdl, struct audio_device *retp)
660 {
661
662 DPRINTF(1, ("vs_getdev\n"));
663 *retp = vs_device;
664 return 0;
665 }
666
667 static int
668 vs_set_port(void *hdl, mixer_ctrl_t *cp)
669 {
670
671 DPRINTF(1, ("vs_set_port\n"));
672 return 0;
673 }
674
675 static int
676 vs_get_port(void *hdl, mixer_ctrl_t *cp)
677 {
678
679 DPRINTF(1, ("vs_get_port\n"));
680 return 0;
681 }
682
683 static int
684 vs_query_devinfo(void *hdl, mixer_devinfo_t *mi)
685 {
686
687 DPRINTF(1, ("vs_query_devinfo\n"));
688 switch (mi->index) {
689 default:
690 return EINVAL;
691 }
692 return 0;
693 }
694
695 static void *
696 vs_allocm(void *hdl, int direction, size_t size)
697 {
698 struct vs_softc *sc;
699 struct vs_dma *vd;
700 int error;
701
702 vd = kmem_alloc(sizeof(*vd), KM_SLEEP);
703 sc = hdl;
704 vd->vd_dmat = sc->sc_dmat;
705
706 error = vs_allocmem(sc, size, 32, 0, vd);
707 if (error) {
708 kmem_free(vd, sizeof(*vd));
709 return NULL;
710 }
711 vd->vd_next = sc->sc_dmas;
712 sc->sc_dmas = vd;
713
714 return KVADDR(vd);
715 }
716
717 static void
718 vs_freem(void *hdl, void *addr, size_t size)
719 {
720 struct vs_softc *sc;
721 struct vs_dma *p, **pp;
722
723 sc = hdl;
724 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) {
725 if (KVADDR(p) == addr) {
726 vs_freemem(p);
727 *pp = p->vd_next;
728 kmem_free(p, sizeof(*p));
729 return;
730 }
731 }
732 }
733
734 static size_t
735 vs_round_buffersize(void *hdl, int direction, size_t bufsize)
736 {
737
738 if (bufsize > DMAC_MAXSEGSZ)
739 bufsize = DMAC_MAXSEGSZ;
740 return bufsize;
741 }
742
743 #if 0
744 paddr_t
745 vs_mappage(void *addr, void *mem, off_t off, int prot)
746 {
747 struct vs_softc *sc;
748 struct vs_dma *p;
749
750 if (off < 0)
751 return -1;
752 sc = addr;
753 for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
754 p = p->vd_next)
755 continue;
756 if (p == NULL) {
757 printf("%s: mappage: bad addr %p\n",
758 device_xname(sc->sc_dev), start);
759 return -1;
760 }
761
762 return bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
763 off, prot, BUS_DMA_WAITOK);
764 }
765 #endif
766
767 static int
768 vs_get_props(void *hdl)
769 {
770
771 DPRINTF(1, ("vs_get_props\n"));
772 return 0 /* | dependent | half duplex | no mmap */;
773 }
774
775 static void
776 vs_get_locks(void *hdl, kmutex_t **intr, kmutex_t **thread)
777 {
778 struct vs_softc *sc;
779
780 DPRINTF(1, ("vs_get_locks\n"));
781 sc = hdl;
782 *intr = &sc->sc_intr_lock;
783 *thread = &sc->sc_lock;
784 }
785
786 #endif /* NAUDIO > 0 && NVS > 0*/
787