在linux内核的上下文中什么是DMA映射和DMA引擎?

时间:2022-10-23 23:46:24

What is DMA mapping and DMA engine in context of linux kernel? When DMA mapping API and DMA engine API can be used in Linux Device Driver? Any real Linux Device Driver example as a reference would be great.

在linux内核的上下文中什么是DMA映射和DMA引擎?什么时候可以在Linux设备驱动程序中使用DMA映射API和DMA引擎API?任何真正的Linux设备驱动程序示例作为参考都会很棒。

2 个解决方案

#1


5  

What is DMA mapping and DMA engine in context of linux kernel?

在linux内核的上下文中什么是DMA映射和DMA引擎?

The kernel normally uses virtual address. Functions like kmalloc(), vmalloc() normally return virtual address. It can be stored in void*. Virtual memory system converts these addresses to physical addresses. These physical addresses are not actually useful to drivers. Drivers must use ioremap() to map the space and produce a virtual address.

内核通常使用虚拟地址。像kmalloc(),vmalloc()这样的函数通常返回虚拟地址。它可以存储在void *中。虚拟内存系统将这些地址转换为物理地址。这些物理地址实际上对驱动程序没用。驱动程序必须使用ioremap()映射空间并生成虚拟地址。

               CPU                  CPU                  Bus
             Virtual              Physical             Address
             Address              Address               Space
              Space                Space

            +-------+             +------+             +------+
            |       |             |MMIO  |   Offset    |      |
            |       |  Virtual    |Space |   applied   |      |
          C +-------+ --------> B +------+ ----------> +------+ A
            |       |  mapping    |      |   by host   |      |
  +-----+   |       |             |      |   bridge    |      |   +--------+
  |     |   |       |             +------+             |      |   |        |
  | CPU |   |       |             | RAM  |             |      |   | Device |
  |     |   |       |             |      |             |      |   |        |
  +-----+   +-------+             +------+             +------+   +--------+
            |       |  Virtual    |Buffer|   Mapping   |      |
          X +-------+ --------> Y +------+ <---------- +------+ Z
            |       |  mapping    | RAM  |   by IOMMU
            |       |             |      |
            |       |             |      |
            +-------+             +------+

If device supports DMA , the driver sets up buffer using kmalloc or similar interface which returns virtual address (X). The virtual memory system maps X to a physical address (Y) in system RAM. The driver can use virtual address X to access the buffer, but the device itself cannot because DMA doesn't go through the CPU virtual memory system. In some system only Device can directly do DMA to physical address. In some system IOMMU hardware is used to translate DMA address to physical address.Look at the figure above It translate Z to Y.

如果设备支持DMA,则驱动程序使用kmalloc或类似的接口设置缓冲区,该接口返回虚拟地址(X)。虚拟内存系统将X映射到系统RAM中的物理地址(Y)。驱动程序可以使用虚拟地址X来访问缓冲区,但设备本身不能,因为DMA不通过CPU虚拟内存系统。在某些系统中,只有Device可以直接对物理地址执行DMA。在某些系统中,IOMMU硬件用于将DMA地址转换为物理地址。如上图所示,它将Z转换为Y.

When DMA mapping API can be used in Linux Device Driver?

什么时候可以在Linux设备驱动程序中使用DMA映射API?

Reason to use DMA mapping API is driver can return virtual address X to interface like dma_map_single(), which sets up any required IOMMU mapping and returns the DMA address Z.The driver then tells the device to do DMA to Z, and the IOMMU maps it to the buffer at address Y in system RAM.

使用DMA映射API的原因是驱动程序可以将虚拟地址X返回到dma_map_single()这样的接口,它设置任何所需的IOMMU映射并返回DMA地址Z.然后驱动程序告诉设备执行DMA到Z,以及IOMMU映射它到系统RAM中地址Y的缓冲区。

Reference is taken from this link.

参考来自此链接。

Any real Linux Device Driver example as a reference would be great.

任何真正的Linux设备驱动程序示例作为参考都会很棒。

A simple PCI DMA example

一个简单的PCI DMA示例

Inside linux kernel you can look to drivers/dma for various real drivers.

在Linux内核中,您可以查看drivers / dma中的各种真实驱动程序。

#2


0  

dmaengine is a generic kernel framework for developing a DMA controller drivers.

dmaengine是用于开发DMA控制器驱动程序的通用内核框架。

You can read: dmaengine provider . You can find numerous examples of dmaengine drivers under drivers/dma.

您可以阅读:dmaengine提供商。你可以在drivers / dma下找到许多dmaengine驱动程序的例子。

#1


5  

What is DMA mapping and DMA engine in context of linux kernel?

在linux内核的上下文中什么是DMA映射和DMA引擎?

The kernel normally uses virtual address. Functions like kmalloc(), vmalloc() normally return virtual address. It can be stored in void*. Virtual memory system converts these addresses to physical addresses. These physical addresses are not actually useful to drivers. Drivers must use ioremap() to map the space and produce a virtual address.

内核通常使用虚拟地址。像kmalloc(),vmalloc()这样的函数通常返回虚拟地址。它可以存储在void *中。虚拟内存系统将这些地址转换为物理地址。这些物理地址实际上对驱动程序没用。驱动程序必须使用ioremap()映射空间并生成虚拟地址。

               CPU                  CPU                  Bus
             Virtual              Physical             Address
             Address              Address               Space
              Space                Space

            +-------+             +------+             +------+
            |       |             |MMIO  |   Offset    |      |
            |       |  Virtual    |Space |   applied   |      |
          C +-------+ --------> B +------+ ----------> +------+ A
            |       |  mapping    |      |   by host   |      |
  +-----+   |       |             |      |   bridge    |      |   +--------+
  |     |   |       |             +------+             |      |   |        |
  | CPU |   |       |             | RAM  |             |      |   | Device |
  |     |   |       |             |      |             |      |   |        |
  +-----+   +-------+             +------+             +------+   +--------+
            |       |  Virtual    |Buffer|   Mapping   |      |
          X +-------+ --------> Y +------+ <---------- +------+ Z
            |       |  mapping    | RAM  |   by IOMMU
            |       |             |      |
            |       |             |      |
            +-------+             +------+

If device supports DMA , the driver sets up buffer using kmalloc or similar interface which returns virtual address (X). The virtual memory system maps X to a physical address (Y) in system RAM. The driver can use virtual address X to access the buffer, but the device itself cannot because DMA doesn't go through the CPU virtual memory system. In some system only Device can directly do DMA to physical address. In some system IOMMU hardware is used to translate DMA address to physical address.Look at the figure above It translate Z to Y.

如果设备支持DMA,则驱动程序使用kmalloc或类似的接口设置缓冲区,该接口返回虚拟地址(X)。虚拟内存系统将X映射到系统RAM中的物理地址(Y)。驱动程序可以使用虚拟地址X来访问缓冲区,但设备本身不能,因为DMA不通过CPU虚拟内存系统。在某些系统中,只有Device可以直接对物理地址执行DMA。在某些系统中,IOMMU硬件用于将DMA地址转换为物理地址。如上图所示,它将Z转换为Y.

When DMA mapping API can be used in Linux Device Driver?

什么时候可以在Linux设备驱动程序中使用DMA映射API?

Reason to use DMA mapping API is driver can return virtual address X to interface like dma_map_single(), which sets up any required IOMMU mapping and returns the DMA address Z.The driver then tells the device to do DMA to Z, and the IOMMU maps it to the buffer at address Y in system RAM.

使用DMA映射API的原因是驱动程序可以将虚拟地址X返回到dma_map_single()这样的接口,它设置任何所需的IOMMU映射并返回DMA地址Z.然后驱动程序告诉设备执行DMA到Z,以及IOMMU映射它到系统RAM中地址Y的缓冲区。

Reference is taken from this link.

参考来自此链接。

Any real Linux Device Driver example as a reference would be great.

任何真正的Linux设备驱动程序示例作为参考都会很棒。

A simple PCI DMA example

一个简单的PCI DMA示例

Inside linux kernel you can look to drivers/dma for various real drivers.

在Linux内核中,您可以查看drivers / dma中的各种真实驱动程序。

#2


0  

dmaengine is a generic kernel framework for developing a DMA controller drivers.

dmaengine是用于开发DMA控制器驱动程序的通用内核框架。

You can read: dmaengine provider . You can find numerous examples of dmaengine drivers under drivers/dma.

您可以阅读:dmaengine提供商。你可以在drivers / dma下找到许多dmaengine驱动程序的例子。