Subject: RE: DMA troubles
To: None <tech-kern@netbsd.org>
From: Filka Michal <michal.filka@strom.cz>
List: tech-kern
Date: 04/26/2006 11:57:58
> > > > Hi all,
> > > > I have a problem (possibly) with DMA. I can allocate a DMA
memory in
> > my
> > > > driver and work with it without any troubles. However, If I
unload
> > > > driver (it is a LKM) and try to load it again, kernel crashes
during
> > DMA
> > > > memory allocation. I did a DMA deinitialization when unloading
> > driver
> > >
> > > How does it crash ?
> >
> > ... it breaks into kernel debugger (Page fault trap) during the call
of
> > "bus_dmamem_alloc". I made a simple skeleton of my driver which is
only
> > loaded and unloaded and it still fails in second attempt for loading
it.
> > First attempt loads/unloads without any troubles. All this happens
even
> > if I do only "..._alloc" and "..._free" with no other operations on
> > DMAed memory.
> >
> > Any ideas are very welcome.
>=20
> I'm afraid you'll have to show some code to get welcomed ideas...
... I have already put it in initial message. Of course I can copy it
here again.

Code related to DMA:
Initialization:
	if( bus_dmamem_alloc(	munInfo->pciInfo.pa_dmat,
				BUF_BUF_SIZE,
         			PAGE_SIZE,
				0, 	=09
				&munInfo->dmaMem[ 0],
         			1,	 		=09
				&munInfo->dmaSegs,
				BUS_DMA_NOWAIT) !=3D 0 )
		goto error4;
=09
	if( bus_dmamem_map( munInfo->pciInfo.pa_dmat,
			    munInfo->dmaMem,
			    munInfo->dmaSegs,
			    BUF_BUF_SIZE,
			    &munInfo->dmaBuf,
			    BUS_DMA_NOWAIT | BUS_DMA_NOCACHE) !=3D 0)
		goto error3;

	if( bus_dmamap_create(	munInfo->pciInfo.pa_dmat,=20
				BUF_BUF_SIZE,=20
				1,
         			BUF_BUF_SIZE,=20
				0,=20
				BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
         			&munInfo->dmaMap) !=3D 0)
		goto error2;

	if( bus_dmamap_load(	munInfo->pciInfo.pa_dmat, =20
				munInfo->dmaMap,=20
				munInfo->dmaBuf,=20
				BUF_BUF_SIZE,=20
				NULL,
				BUS_DMA_NOWAIT) !=3D 0)
		goto error1;

Deinitialization:
	bus_dmamap_unload(munInfo->pciInfo.pa_dmat, munInfo->dmaMap);
	bus_dmamap_destroy(munInfo->pciInfo.pa_dmat, munInfo->dmaMap);

	bus_dmamem_unmap(munInfo->pciInfo.pa_dmat, munInfo->dmaBuf,
BUF_BUF_SIZE);
	bus_dmamem_free( munInfo->pciInfo.pa_dmat, munInfo->dmaMem,
munInfo->dmaSegs);

Michal Filka