generic dma layer
Hi,
I'm trying to update my driver such that it uses the generic dma layer. I can't even get past the first step of allocating/mapping memory. I first tried using dma_alloc_coherent but that didn't work. I was unsure whether the struct device member of my pci_dev structure was actually initialized(not sure if pci_get_device() sets the needed struct device value in there) so I then tried pci_alloc_consistent. That still gives me an Oops in dma_alloc_coherent or dma_generic_alloc_coherent.
[ 91.745091] BUG: unable to handle kernel NULL pointer dereference at (null)
[ 91.745096] IP: [<c010797f>] dma_generic_alloc_coherent+0xaf/0xc0
[ 91.745104] *pde = 00000000
I've also seen an oops such that:
[ 91.745104] *pde = 324235 *pte = 0000000
Either way I have no idea why I am getting the "killing" message here.
Are there any dma driver examples to be found? I can't seem to find anything. Any idea what causes this Oops?
The driver currently uses a method that I believe is unsafe and not portable but seems to work:
*ptr = (ulong *)__get_free_pages((GFP_DMA | GFP_ATOMIC), order);
if (ptr == NULL)
return(-1);
for (addr=(ulong)*ptr; addr <= (((ulong)*ptr)+(PAGE_SIZE<<order)); addr+=PAGE_SIZE)
set_bit(PG_reserved, &((virt_to_page(addr))->flags));
I tried to replace this with:
pdx[card_num].virt_rdAddr = pci_alloc_consistent(pdx[card_num].dev, bCount, pdx[card_num].dma_handle);
I also tried:
pdx[card_num].virt_rdAddr = dma_alloc_coherent(&(pdx[card_num].dev->dev), bCount, pdx[card_num].dma_handle, GFP_KERNEL);
Either way I get a NULL pointer dereferencing error and the Oops.
I have no idea what I'm doing wrong or where to find a simple example.
|