简体   繁体   English

Linux PCIe DMA驱动程序

[英]Linux PCIe DMA driver

I'm currently writing a driver for a PCIe device that should send data to a Linux system using DMA. 我目前正在为PCIe设备编写驱动程序,该设备应使用DMA将数据发送到Linux系统。 As far as I can understand my PCIe device needs a DMA controller (DMA master) and my Linux system too (DMA slave). 据我了解,我的PCIe设备需要DMA控制器(DMA主设备)和Linux系统(DMA从设备)。 Currently the PCIe device has no DMA controller and should not get one. 当前,PCIe设备没有DMA控制器,因此不应获得一个。 That confuses me. 这让我感到困惑。

A. Is the following possible? 答:以下可能吗?

  1. PCIe device sends interrupt PCIe设备发送中断
  2. Wait for interrupt in the Linux driver 等待Linux驱动程序中的中断
  3. Start DMA transfer from memory mapped PCIe registers to Linux system DMA. 开始从内存映射的PCIe寄存器到Linux系统DMA的DMA传输。
  4. Read the data from memory in userspace 从用户空间中的内存中读取数据

I have everything setup for this, the only thing I miss is how to transfer the data from the PCIe registers to the memory. 我为此设置了所有东西,我唯一想念的是如何将数据从PCIe寄存器传输到内存。

B. Which system call (or series of) do I need to call to do a DMA transfer? B.要进行DMA传输,我需要调用哪个(或一系列)系统调用?

C. I probably need to setup the DMA on the Linux system but what I find points to code that assumes there is a slave, eg struct dma_slave_config. C.我可能需要在Linux系统上设置DMA,但是我发现指向假定有从属的代码,例如struct dma_slave_config。

The use case is collecting data from the PCIe device and make it available in memory to userspace. 用例是从PCIe设备收集数据并将其在内存中提供给用户空间。

Any help is much appreciated. 任何帮助深表感谢。 Thanks in advance! 提前致谢!

DMA, by definition, is completely independent of the CPU and any software (ie OS kernel) running on it. 根据定义,DMA完全独立于CPU及其上运行的任何软件(即OS内核)。 DMA is a way for devices to perform memory reads and writes against host memory without the involvement of the host CPU. DMA是设备在不涉及主机CPU的情况下对主机存储器执行存储器读写的一种方式。

The way DMA usually works is something like this: software will allocate a DMA accessible region in memory and share the physical address with the device, say, by performing memory writes against the address space associated with one of the device's BARs. DMA通常的工作方式是这样的:软件将在内存中分配DMA可访问区域并与设备共享物理地址,例如,通过对与设备BAR之一关联的地址空间执行内存写操作。 Then, the device will perform a DMA read or write against that block of memory. 然后,设备将对该内存块执行DMA读取或写入操作。 When that operation is complete, the device will issue an interrupt to the device driver so it can handle the data and/or free the memory. 该操作完成后,设备将向设备驱动程序发出中断,以便它可以处理数据和/或释放内存。

If your device does not have the capability of issuing a DMA read or write against host memory, then you'll have to interact with it with using the CPU only. 如果您的设备不具备对主机存储器发出DMA读或写的能力,那么您将只能使用CPU与它进行交互。 Discrete DMA controllers have not been a thing for a very long time. 离散DMA控制器已经很久没有出现了。

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

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