This makes sv(4) use the "modern" audio interface.  Basically, this
blindly concatenates the init_xxx() and start_xxx() functions into
a single trigger_xxx() function.

OK?

Index: sv.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/sv.c,v
retrieving revision 1.33
diff -u -p -u -p -r1.33 sv.c
--- sv.c        14 Sep 2016 06:12:19 -0000      1.33
+++ sv.c        16 Sep 2016 17:03:31 -0000
@@ -139,10 +139,10 @@ int       sv_open(void *, int);
 void   sv_close(void *);
 int    sv_set_params(void *, int, int, struct audio_params *, struct 
audio_params *);
 int    sv_round_blocksize(void *, int);
-int    sv_dma_init_output(void *, void *, int);
-int    sv_dma_init_input(void *, void *, int);
-int    sv_dma_output(void *, void *, int, void (*)(void *), void *);
-int    sv_dma_input(void *, void *, int, void (*)(void *), void *);
+int    sv_trigger_output(void *, void *, void *, int,
+    void (*)(void *), void *, struct audio_params *);
+int    sv_trigger_input(void *, void *, void *, int,
+    void (*)(void *), void *, struct audio_params *);
 int    sv_halt_in_dma(void *);
 int    sv_halt_out_dma(void *);
 int    sv_getdev(void *, struct audio_device *);
@@ -161,10 +161,10 @@ struct audio_hw_if sv_hw_if = {
        sv_set_params,
        sv_round_blocksize,
        NULL,
-       sv_dma_init_output,
-       sv_dma_init_input,
-       sv_dma_output,
-       sv_dma_input,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
        sv_halt_out_dma,
        sv_halt_in_dma,
        NULL,
@@ -177,8 +177,8 @@ struct audio_hw_if sv_hw_if = {
        sv_free,
        NULL,
        sv_get_props,
-       NULL,
-       NULL
+       sv_trigger_output,
+       sv_trigger_input
 };
 
 
@@ -687,106 +687,78 @@ sv_round_blocksize(void *addr, int blk)
 }
 
 int
-sv_dma_init_input(void *addr, void *buf, int cc)
+sv_trigger_output(void *addr, void *start, void *end, int blksize,
+    void (*intr)(void *), void *arg, struct audio_params *param)
 {
        struct sv_softc *sc = addr;
        struct sv_dma *p;
-       int dma_count;
+       int mode, dma_count;
 
-       DPRINTF(("sv_dma_init_input: dma start loop input addr=%p cc=%d\n", 
-                buf, cc));
-        for (p = sc->sc_dmas; p && KERNADDR(p) != buf; p = p->next)
+        for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
                ;
        if (!p) {
-               printf("sv_dma_init_input: bad addr %p\n", buf);
+               printf("sv_trigger_output: bad addr %p\n", start);
                return (EINVAL);
        }
 
-       dma_count = (cc >> 1) - 1;
-
-       bus_space_write_4(sc->sc_iot, sc->sc_dmac_ioh, SV_DMA_ADDR0,
+       dma_count = (char *)end - (char *)start - 1;
+       bus_space_write_4(sc->sc_iot, sc->sc_dmaa_ioh, SV_DMA_ADDR0,
                          DMAADDR(p));
-       bus_space_write_4(sc->sc_iot, sc->sc_dmac_ioh, SV_DMA_COUNT0,
+       bus_space_write_4(sc->sc_iot, sc->sc_dmaa_ioh, SV_DMA_COUNT0,
                          dma_count);
-       bus_space_write_1(sc->sc_iot, sc->sc_dmac_ioh, SV_DMA_MODE,
-                         DMA37MD_WRITE | DMA37MD_LOOP);
+       bus_space_write_1(sc->sc_iot, sc->sc_dmaa_ioh, SV_DMA_MODE,
+                         DMA37MD_READ | DMA37MD_LOOP);
 
-       return (0);
+       sc->sc_pintr = intr;
+       sc->sc_parg = arg;
+
+       dma_count = blksize - 1;
+       sv_write_indirect(sc, SV_DMAA_COUNT1, dma_count >> 8);
+       sv_write_indirect(sc, SV_DMAA_COUNT0, (dma_count & 0xFF));
+
+       mode = sv_read_indirect(sc, SV_PLAY_RECORD_ENABLE);
+       mode |= SV_PLAY_ENABLE;
+       sv_write_indirect(sc, SV_PLAY_RECORD_ENABLE, mode);
+       sc->sc_enable |= SV_PLAY_ENABLE;
+        return (0);
 }
 
+
 int
-sv_dma_init_output(void *addr, void *buf, int cc)
+sv_trigger_input(void *handle, void *start, void *end, int blksize,
+    void (*intr)(void *), void *arg, struct audio_params *param)
 {
        struct sv_softc *sc = addr;
        struct sv_dma *p;
-       int dma_count;
+       int mode, dma_count;
 
-       DPRINTF(("sv: dma start loop output buf=%p cc=%d\n", buf, cc));
-        for (p = sc->sc_dmas; p && KERNADDR(p) != buf; p = p->next)
+        for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
                ;
        if (!p) {
-               printf("sv_dma_init_output: bad addr %p\n", buf);
+               printf("sv_trigger_input: bad addr %p\n", start);
                return (EINVAL);
        }
 
-       dma_count = cc - 1;
-
-       bus_space_write_4(sc->sc_iot, sc->sc_dmaa_ioh, SV_DMA_ADDR0,
+       dma_count = (((char *)end - (char *)start) >> 1) - 1;
+       bus_space_write_4(sc->sc_iot, sc->sc_dmac_ioh, SV_DMA_ADDR0,
                          DMAADDR(p));
-       bus_space_write_4(sc->sc_iot, sc->sc_dmaa_ioh, SV_DMA_COUNT0,
+       bus_space_write_4(sc->sc_iot, sc->sc_dmac_ioh, SV_DMA_COUNT0,
                          dma_count);
-       bus_space_write_1(sc->sc_iot, sc->sc_dmaa_ioh, SV_DMA_MODE,
-                         DMA37MD_READ | DMA37MD_LOOP);
-
-       return (0);
-}
-
-int
-sv_dma_output(void *addr, void *p, int cc, void (*intr)(void *), void *arg)
-{
-       struct sv_softc *sc = addr;
-       u_int8_t mode;
-
-       DPRINTFN(1, 
-                 ("sv_dma_output: sc=%p buf=%p cc=%d intr=%p(%p)\n", 
-                  addr, p, cc, intr, arg));
-       sc->sc_pintr = intr;
-       sc->sc_parg = arg;
-       if (!(sc->sc_enable & SV_PLAY_ENABLE)) {
-               int dma_count = cc - 1;
-
-               sv_write_indirect(sc, SV_DMAA_COUNT1, dma_count >> 8);
-               sv_write_indirect(sc, SV_DMAA_COUNT0, (dma_count & 0xFF));
-
-               mode = sv_read_indirect(sc, SV_PLAY_RECORD_ENABLE);
-               mode |= SV_PLAY_ENABLE;
-               sv_write_indirect(sc, SV_PLAY_RECORD_ENABLE, mode);
-               sc->sc_enable |= SV_PLAY_ENABLE;
-       }
-        return (0);
-}
-
-int
-sv_dma_input(void *addr, void *p, int cc, void (*intr)(void *), void *arg)
-{
-       struct sv_softc *sc = addr;
-       u_int8_t mode;
+       bus_space_write_1(sc->sc_iot, sc->sc_dmac_ioh, SV_DMA_MODE,
+                         DMA37MD_WRITE | DMA37MD_LOOP);
 
-       DPRINTFN(1, ("sv_dma_input: sc=%p buf=%p cc=%d intr=%p(%p)\n", 
-                    addr, p, cc, intr, arg));
        sc->sc_rintr = intr;
        sc->sc_rarg = arg;
-       if (!(sc->sc_enable & SV_RECORD_ENABLE)) {
-               int dma_count = (cc >> 1) - 1;
 
-               sv_write_indirect(sc, SV_DMAC_COUNT1, dma_count >> 8);
-               sv_write_indirect(sc, SV_DMAC_COUNT0, (dma_count & 0xFF));
+       dma_count = (blksize >> 1) - 1;
+       sv_write_indirect(sc, SV_DMAC_COUNT1, dma_count >> 8);
+       sv_write_indirect(sc, SV_DMAC_COUNT0, (dma_count & 0xFF));
+
+       mode = sv_read_indirect(sc, SV_PLAY_RECORD_ENABLE);
+       mode |= SV_RECORD_ENABLE;
+       sv_write_indirect(sc, SV_PLAY_RECORD_ENABLE, mode);
 
-               mode = sv_read_indirect(sc, SV_PLAY_RECORD_ENABLE);
-               mode |= SV_RECORD_ENABLE;
-               sv_write_indirect(sc, SV_PLAY_RECORD_ENABLE, mode);
-               sc->sc_enable |= SV_RECORD_ENABLE;
-       }
+       sc->sc_enable |= SV_RECORD_ENABLE;
         return (0);
 }
 

Reply via email to