Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux driver DMA transfer to a PCIe card with PC as master

I am working on a DMA routine to transfer data from PC to a FPGA on a PCIe card. I read DMA-API.txt and LDD3 ch. 15 for details. However, I could not figure out how to do a DMA transfer from PC to a consistent block of iomem on the PCIe card. The dad sample for PCI in LDD3 maps a buffer and then tells the card to do the DMA transfer, but I need the PC to do this.

What I already found out:

  1. Request bus master

    pci_set_master(pdev);
    
  2. Set the DMA mask

    if (dma_set_mask(&(pdev->dev), DMA_BIT_MASK(32))) {
        dev_err(&pdev->dev,"No suitable DMA available.\n");
        goto cleanup;
    }
    
  3. Request a DMA channel

    if (request_dma(dmachannel, DRIVER_NAME)) {
        dev_err(&pdev->dev,"Could not reserve DMA channel %d.\n", dmachannel);
        goto cleanup;
    }
    
  4. Map a buffer for DMA transfer

    dma_handle = pci_map_single(pci_dev, buffer, count, DMA_TO_DEVICE);
    

Question:

What do I have to do in order to let the PC perform the DMA transfer instead of the card?

Thank your for your help!


First of all thank you for your replies. Maybe I should put my questions more precisely:

  1. In my understanding the PC has to have a DMA controller. How do I access this DMA controller to start a transfer to a memory mapped IO region in the PCIe card?
  2. Our specification demands that the PC's DMA controller initiates the transfer. However, I could only find examples where the device would do the DMA job (DMA_mapping.txt, LDD3 ch.15). Is there a reason, why nobody uses the PC's DMA controller (It still has DMA channels though)? Would it be better to request a specification change for our project?

Thanks for your patience.

like image 370
kohpe Avatar asked Apr 19 '13 11:04

kohpe


1 Answers

Look up DMA_mapping.txt. There's a long section in there that tells you how to set the direction ('DMA direction', line 408).

EDIT

Ok, since you edited your question... your specification is wrong. You could set up the system DMA controller, but it would be pointless, because it's too slow, as I said in the comments. Read this thread.

You must change your FPGA to support bus mastering. I do this for a living - contact me off-thread if you want to sub-contract.

like image 136
EML Avatar answered Sep 30 '22 18:09

EML