Easiest way to use DMA in Linux
Asked Answered
T

4

12

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

Terse answered 9/12, 2015 at 20:29 Comment(5)
You don't say ow its connected. Is it PCIe? USB? UNIBUS?Crappie
@Crappie None of the above; it's mapped directly in memory. The Zynq is an unusual device. :)Forseti
ok I should have explained better I guess ;) On the ZYNQ arm processor and FPGA are on the same silicon die, they are connected via AXI Busses; AXI is a BUS protocol from ARM holdings, it's version of AMBA 4Terse
The driver of the DMA Engine in kernel already for a long time. You have to understand who is the client of the DMA resources in your case. Looks like you are implementing a specific IP on FPGA, so, you have to write a driver for that IP. If it's user space driver you still have to write something which can provide HW resources to your user space driver.Tymbal
Keep in mind that you need to consider cache coherency, too.Leuco
D
1

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

Demean answered 9/12, 2015 at 23:3 Comment(5)
I'm afraid you didn't read the content of the documentation. There is zero instances of word DMA in the text so little (which have nothing to do with DMA resources) in the UIO framework.Tymbal
@AndyShevchenko the UIO framework is not used for initializing DMA, but rather as simple way to expose memory to user space. Each UIO device can make one or more memory regions available for memory mapping. Each mapping has its own directory in sysfs .... as I don't know Zync I don't know how to access the DMA part, but wrapping that in a UIO module makes it easier for the user space to access it.Demean
Yes, but someone somehow still need to run the hardware, I think UIO helps a little in this case. Most of the stuff will be inside kernel part of the driver anyway. I'm even not sure that some part of image / video filtering makes sense in user space (e.g. the images came from camera through V4L2 interface), I wonder if it would be possible to extend UIO framework to support DMA Engine API.Tymbal
@AndyShevchenko it really depends on the hardware I think. while exposing the DMA configuration is definitely possible this is only half of the work. if you driver needs interrupts working or does require some high performance logic you need to expose that as well. creating a DSL based driver framework is definitely possible (e.g. usb gadget fs does userspace drivers where you configure the driver via file descriptors, linux-usb.org/gadget)Demean
I believe the configfs example is a bad one here. In any case the topic starter must elaborate what they are doing and why in that way.Tymbal
H
0

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:

Hundredpercenter answered 7/1, 2016 at 19:38 Comment(0)
G
0

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

Glaring answered 3/2, 2023 at 16:39 Comment(0)
N
-1

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

Naashom answered 10/12, 2015 at 21:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.