将Linux驱动程序DMA传输到以PC为主机的PCIe卡

将Linux驱动程序DMA传输到以PC为主机的PCIe卡

本文介绍了将Linux驱动程序DMA传输到以PC为主机的PCIe卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究DMA例程,以将数据从PC传输到PCIe卡上的FPGA.我阅读了DMA-API.txt和LDD3 ch.详情请参阅15.但是,我不知道如何进行从PC到PCIe卡上一致的iomem的DMA传输. LDD3中用于PCI的父亲示例映射了一个缓冲区,然后告诉卡进行DMA传输,但是我需要PC来执行此操作.

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.

我已经发现的东西:

  1. 请求总线主控器

  1. Request bus master

pci_set_master(pdev);

  • 设置DMA掩码

  • 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;
    }
    

  • 请求DMA通道

  • Request a DMA channel

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

  • 映射用于DMA传输的缓冲区

  • Map a buffer for DMA transfer

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

  • 问题:

    要让 PC 代替卡执行DMA传输,我该怎么办?

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

    感谢您的帮助!

    首先,感谢您的答复.也许我应该更精确地提出我的问题:

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

    1. 据我了解,PC必须具有DMA控制器.如何访问此DMA控制器以开始向PCIe卡中的内存映射IO区域进行传输?
    2. 我们的规范要求PC的DMA控制器启动传输.但是,我只能找到设备可以执行DMA工作的示例(DMA_mapping.txt,LDD3第15章).是否有原因,为什么没人使用PC的DMA控制器(尽管它仍然具有DMA通道)?为我们的项目要求更改规格会更好吗?

    感谢您的耐心等候.

    推荐答案

    查找DMA_mapping.txt.在那里有一长段告诉您如何设置方向("DMA方向",第408行).

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

    编辑

    好的,因为您已经编辑了问题...您的说明是错误的.您可以设置系统DMA控制器,但这将毫无意义,因为它太慢了,正如我在评论中所说.阅读此线程.

    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.

    您必须更改FPGA以支持总线主控.我这样做是为了谋生-如果您想分包合同,请与我联系.

    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.

    这篇关于将Linux驱动程序DMA传输到以PC为主机的PCIe卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-05 07:26