Subject: busspaceifying
To: Ben Harris , <mark@netbsd.org>
From: Reinoud Zandijk <imago@kabel065011.kabel.utwente.nl>
List: tech-kern
Date: 02/14/2001 18:41:49
Hi folks,

In the arm32 port there are devices like `beep0 at vidc0' (with `vidc0 at
mainbus?' that use DMA but are not using dmamem mappings trough the bus. I
need this structure to be able to claim memory from a second free list for
DMA to support the Kinetic card (added successfully).

I've started to convert this `beep' device first for its pretty simple in
design and only uses one dma mapping.

The diff is now :

Index: vidc/beep.c
===================================================================
RCS file: /pub/NetBSD-CVS/syssrc/sys/arch/arm32/vidc/beep.c,v
retrieving revision 1.19
diff -u -r1.19 beep.c
--- beep.c      2000/06/29 08:53:03     1.19
+++ beep.c      2001/02/14 17:27:16
@@ -72,6 +72,8 @@

 struct beep_softc {
        struct device sc_device;
+       bus_dma_segment_t bus_dmamem_segment;
+       u_int num_bus_dmamem_segments;
        irqhandler_t sc_ih;
        int sc_iobase;
        int sc_open;
@@ -144,9 +146,15 @@
        sc->sc_open = 0;
        sc->sc_count = 0;

-       sc->sc_buffer0 = uvm_km_zalloc(kernel_map, NBPG);
-       if (sc->sc_buffer0 == 0)
-               panic("beep: Cannot allocate buffer memory\n");
+       /* sc->sc_buffer0 = uvm_km_zalloc(kernel_map, NBPG); */
+/* XXX */
+       if (bus_dmamem_alloc(mb, NBPG, 0, 0, &(sc->bus_dmamem_segment), 1,
+               &(sc->num_bus_dmamem_segments), BUS_DMA_NOWAIT) == 0)
+                       panic("beep: Cannot allocate buffer memory\n");
+       if (bus_dmamem_map(mb, &(sc->bus_dmamem_segment),
sc->num_dmamem_segments,
+               NBPG, &sc->sc_buffer0)
+                       panic("beep: Cannot mmap dma buffer");
+
        if ((sc->sc_buffer0 & (NBPG -1)) != 0)
                panic("beep: Cannot allocate page aligned buffer\n");
        sc->sc_sc_buffer1 = sc->sc_buffer0;

but compiling this gives :

ismaelda# make beep.o
cc  -O2 -Werror -Wall -Wcomment -Wpointer-arith -Wno-uninitialized
-Wno-main -I. -I../../../../arch -I../../../.. -nostdinc -DIOMD -DRISCPC
-DMAXUSERS=10 -D_KERNEL -Darm32  -c ../../../../arch/arm32/vidc/beep.c
../../../../arch/arm32/vidc/beep.c: In function `beepattach':
../../../../arch/arm32/vidc/beep.c:151: structure has no member named
`_dmamem_alloc'
../../../../arch/arm32/vidc/beep.c:154: structure has no member named
`_dmamem_map'
../../../../arch/arm32/vidc/beep.c:154: structure has no member named
`num_dmamem_segments'
*** Error code 1

Stop.
ismaelda#

with :
struct beep_softc {
        struct device sc_device;
        bus_dma_segment_t bus_dmamem_segment;
        u_int num_bus_dmamem_segments;
        irqhandler_t sc_ih;
        int sc_iobase;
        int sc_open;
        int sc_count;
        u_int sc_sound_cur0;
        u_int sc_sound_end0;
        u_int sc_sound_cur1;
        u_int sc_sound_end1;
        vm_offset_t sc_buffer0;
        vm_offset_t sc_buffer1;
};

and

void
beepattach(parent, self, aux)
        struct device *parent;
        struct device *self;
        void *aux;
{
        struct beep_softc *sc = (void *)self;
        struct mainbus_attach_args *mb = aux;

        sc->sc_iobase = mb->mb_iobase;
        sc->sc_open = 0;
        sc->sc_count = 0;

        /* sc->sc_buffer0 = uvm_km_zalloc(kernel_map, NBPG); */
/* XXX */
        if (bus_dmamem_alloc(mb, NBPG, 0, 0, &(sc->bus_dmamem_segment), 1,
                &(sc->num_bus_dmamem_segments), BUS_DMA_NOWAIT) == 0)
                        panic("beep: Cannot allocate buffer memory\n");
        if (bus_dmamem_map(mb, &(sc->bus_dmamem_segment),
sc->num_dmamem_segments,
                NBPG, &sc->sc_buffer0, BUS_DMA_NOWAIT) == 0)
                        panic("beep: Cannot mmap dma buffer");

......

So does that mean that the mainbus tag doesnt have the _dmamem_alloc ? and
how can I write them? i.e. can I use the stuff in arm32/bus.h ?

Is there a different way to aproch it ? the `uvm_km_zalloc' was the old
code ....

A bit puzzling still....

Cheers,
Reinoud