Subject: Re: troubles with DMA
To: Filka Michal <michal.filka@strom.cz>
From: Quentin Garnier <cube@cubidou.net>
List: tech-kern
Date: 03/14/2006 13:51:41
--jl4Fp3UZkJvcEKYn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Mar 14, 2006 at 01:07:26PM +0100, Filka Michal wrote:
> Hi all,
> 	I have troubles with DMA in driver for proprietary device
> (developed by company I work for). I got things as far as I could
> according to man pages and J.Thorpe's paper, but it's still not working
> and I have no more ideas.
>=20
> The device uses DMA for subscribing interrupt vector(s) on particular
> interrupt type (of course it generates one interrupt on PIC but there is
> an additional info in one of device's register which). Problem is that
> when I try to read it in my interrupt handler I have no data in assigned
> memory (it is zero-filled).
>=20
> Any ideas are very welcome.
>=20
> DMA initialization (reduced) as done in attach callback:
> bus_dmamem_alloc(	munInfo->pciInfo.pa_dmat, BUF_BUF_SIZE,
> PAGE_SIZE,&munInfo->dmaMem[ 0], 1, &munInfo->dmaSegs, 0)
> =09
> bus_dmamem_map( munInfo->pciInfo.pa_dmat, munInfo->dmaMem,
> munInfo->dmaSegs, BUF_BUF_SIZE,=20
>        &munInfo->dmaBuf, BUS_DMA_NOWAIT | BUS_DMA_NOCACHE )
>=20
> bus_dmamap_create(
> munInfo->pciInfo.pa_dmat,BUF_BUF_SIZE,1,BUF_BUF_SIZE,0,=20
> 				0, &munInfo->dmaMap)
>=20
> bus_dmamap_load(	munInfo->pciInfo.pa_dmat,  munInfo->dmaMap,
> munInfo->dmaBuf, BUF_BUF_SIZE, NULL, 0)
>=20
> Next thing I do is that I configure device's DMA related registers.
> E.g for the first interrupt queue: pulIntQueue[0]=3DmunInfo->dmaBuf + 0
>       For the second interrupt queue: pulIntQueue[1]=3DmunInfo->dmaBuf +
> INT_QUEUE_SIZE
> And so on ... and write those pulIntQueue[ i] into device ...

dmaBuf is the virtual address at which the aera is mapped.  You need to
tell the device about the physical address(es) which you get in the
bus_dma_segment_t table, otherwise it will write in rather random places
of the memory...

In your case, you need at least one segment per whatever your structure
is, you don't necessarily need to put all of them into one.  Then you
assign the registers to the values you get from the segments.

--=20
Quentin Garnier - cube@cubidou.net - cube@NetBSD.org
"When I find the controls, I'll go where I like, I'll know where I want
to be, but maybe for now I'll stay right here on a silent sea."
KT Tunstall, Silent Sea, Eye to the Telescope, 2004.

--jl4Fp3UZkJvcEKYn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBRBa8XdgoQloHrPnoAQJjTwf/aysiLWvLFMawBDPOCMj4PZifVvMEIUvs
Ihrm16vKU5bRQVdtBRzU2S4wBu8kC7GbbSI8laPYPAZRod83rkCb+OBzLpg8DxsY
1icZ94NbVbsD6SrFvKE7rXraOW1w969ReS63rt6/E5PG+roJrTSFKS0+fsoL6XqY
FMhKLJ3guX6uDdey73X0D020tDt9BhETtebg/SdnS/Vn8cLpWwTjfCs/cCtefpIC
xdTzP/531GAMsyVBqGx3diyf2AJDiSncBsHy4D+7S0LBNqYdbrkX6BP9DymxWPlU
L27/18jlDKIBT6G6P3DweWFSd9NnW5nRwL47Onu90TlzDF5zAxdfIg==
=+kzl
-----END PGP SIGNATURE-----

--jl4Fp3UZkJvcEKYn--