简体   繁体   中英

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

I'm using Yocto to build a basic linux environement that I can use on the processor with Xilinx's custom kernel kernel branch.

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)...

so is there some kind of library/API/anything really that can make DMA transfers from userland? (in particular it would be from memory to a memory mapped peripheral (An AXI4 port between PS and PL on the zynq)

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

I'll report my successes or failures;)

One potential option could be to use the UIO interface (See also this blog article )

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. (See documentation )
  • your userspace program then handles all the IO that you need in order to get it working. (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).

There's surely a dmaengine driver for that specific platform. All you need to do is to create a small kernel module that gives the user space access to dmaengine client's API.

Please read: dmaengine client

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.

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. 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. 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.

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 is available on 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. It requires a kernel driver but the sample one they provide on their github repo is very helpful.

Linux DMA From User Space 2.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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