简体   繁体   English

在 Linux 中使用 DMA 的最简单方法

[英]Easiest way to use DMA in Linux

I'm a EE and for a project at uni I'm developing hardware assisted image/video filtering on an FPGA (Xilinx ZYNQ), said device also has a dual core ARM A9 processor inside and more importantly there is also an ARM Primecell PL330 DMA controller我是一名 EE,在 uni 的一个项目中,我正在 FPGA (Xilinx ZYNQ) 上开发硬件辅助图像/视频过滤,该设备内部还有一个双核 ARM A9 处理器,更重要的是还有一个 ARM Primecell PL330 DMA controller

I'm using Yocto to build a basic linux environement that I can use on the processor with Xilinx's custom kernel kernel branch.我正在使用 Yocto 构建一个基本的 linux 环境,我可以在处理器上使用 Xilinx 的自定义 kernel kernel 分支。

Now if I'understood correctly I'can't use the kernel DMA API directly, but I would have to write a custom kernel driver, and here lies the problem, since I don't have enough kernel knowledge to be able to do that (and in particular to set up a build environement for the custom module)...现在,如果我理解正确,我不能直接使用 kernel DMA API,但我必须编写一个自定义的 kernel 驱动程序,这就是问题所在,因为我没有足够的 kernel 知识来做到这一点(特别是为自定义模块设置构建环境)...

so is there some kind of library/API/anything really that can make DMA transfers from userland?那么是否有某种库/API/任何东西真的可以从用户空间进行 DMA 传输? (in particular it would be from memory to a memory mapped peripheral (An AXI4 port between PS and PL on the zynq) (特别是从 memory 到 memory 映射外设(zynq 上 PS 和 PL 之间的 AXI4 端口)

UPDATE更新

After some late night experimenting, I got a basic hello world kernel module to load correctly, so I think i'll go the right way and write a small device-driverish shim that takes a chunk of data from user space (part of an image in this case) and pass it to the FPGA part if the IC trough DMA api经过一些深夜实验,我得到了一个基本的 hello world kernel 模块可以正确加载,所以我想我会以正确的方式 go 并编写一个小型设备驱动程序填充程序,从用户空间获取大量数据(图像的一部分)在这种情况下)并将其传递给 FPGA 部分,如果 IC 通过 DMA api

I'll report my successes or failures;)我会报告我的成功或失败;)

One potential option could be to use the UIO interface (See also this blog article )一种可能的选择是使用UIO 接口(另请参阅此博客文章

There is some example code in the link, but the general structure of the code is:链接中有一些示例代码,但代码的一般结构是:

  • you have a little kernel module that handles the IO init and exposes the DMA.您有一个处理 IO init 并公开 DMA 的小内核模块。 (See documentation ) (见文档
  • your userspace program then handles all the IO that you need in order to get it working.然后,您的用户空间程序会处理您需要的所有 IO 以使其正常工作。 (See also example code ) (另见示例代码

Since you didn't specify what you want to do I cannot be more specific.由于您没有指定您想要做什么,我无法更具体。 But you need to figure how to initialize your memory in kernel (See the tag wiki for docs on that LDD3 is great).但是您需要弄清楚如何在内核中初始化您的内存(有关该LDD3 的文档,请参阅标签 wiki 很棒)。

There's surely a dmaengine driver for that specific platform.该特定平台肯定有一个dmaengine驱动程序。 All you need to do is to create a small kernel module that gives the user space access to dmaengine client's API.您需要做的就是创建一个小的内核模块,使用户空间可以访问 dmaengine 客户端的 API。

Please read: dmaengine client请阅读: dmaengine 客户端

I was surprised when I got a Zedboard a few years ago that I needed to write a device driver in order to connect my application to the programmable logic.几年前,当我得到一个 Zedboard 时,我感到很惊讶,因为我需要编写一个设备驱动程序才能将我的应用程序连接到可编程逻辑。

So I started work on the Connectal Framework to solve that problem.所以我开始研究连接框架来解决这个问题。 Connectal provides a generic device driver for Zynq FPGAs and for Xilinx or Altera FPGAs attached via PCI Express. Connectal 为 Zynq FPGA 以及通过 PCI Express 连接的 Xilinx 或 Altera FPGA 提供通用设备驱动程序。 The device driver enables user-mode software to memory-map the control interface of the hardware and to share memory (via DMA) with the hardware.设备驱动程序使用户模式软件能够对硬件的控制接口进行内存映射,并与硬件共享内存(通过 DMA)。 It also provides an MMU for the programmable logic, so that applications and programmable logic can use the same linear offsets into shared memory objects.它还为可编程逻辑提供了一个 MMU,以便应用程序和可编程逻辑可以使用相同的线性偏移量进入共享内存对象。

Connectal uses Bluespec Systems Verilog for its hardware libraries, which might make the framework or its device drivers difficult to use in your application, but it is available and we would be happy to explain and document in more detail the hardware interface. Connectal 使用 Bluespec Systems Verilog 作为其硬件库,这可能会使框架或其设备驱动程序难以在您的应用程序中使用,但它是可用的,我们很乐意更详细地解释和记录硬件接口。

Connectal is available on github: Connectal 在 github 上可用:

The relevant drivers are here:相关驱动程序在这里:

There are a couple of alternatives out there:有几种选择:

Late to this party, but Xilinx has some good documentation now on controlling DMA from userspace.迟到了,但 Xilinx 现在有一些关于从用户空间控制 DMA 的好文档。 It requires a kernel driver but the sample one they provide on their github repo is very helpful.它需要一个 kernel 驱动程序,但他们在其 github 存储库中提供的示例非常有用。

Linux DMA From User Space 2.0 Linux 来自用户空间 2.0 的 DMA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM