8

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.

4

2 回答 2

5

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.

于 2013-04-19T21:25:18.583 回答
1

What you are talking about is not really a DMA. The DMA is when your device is accessing memory and the CPU itself is not involved (with an exception of PC's memory controller, which is usually embedded into the PC's CPU these days). Not all devices can do it, and if you are using FPGA, then you surely need some sort of DMA controller in your design (i.e. Expresso DMA Core or alike). In your case, you just have to write to the mapped memory region (i.e. one that you obtain with ioremap_nocache) using iowrite calls (i.e. iowrite32) followed by write memory barriers wmb(). What I/O bar and address you have to write to entirely depends on your device.

Hope it helps. Good Luck!

于 2013-04-19T12:48:44.113 回答