服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - 详解linux dma驱动编写

详解linux dma驱动编写

2022-03-07 16:35feixiaoxing Linux

这篇文章主要介绍了详解linux dma驱动编写,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

linux下面的驱动虽然什么样的情形都有,但是dma驱动却并不少见。dma可以有很多的好处,其中最重要的功能就是能够帮助我们将数据搬来搬去,这个时候cpu就由时间去做别的事情了,提高了设备效率。

1、dma驱动在什么地方

?
1
drivers/dma

2、如何看s3c的dma驱动,先看Kconfig

?
1
2
3
4
5
6
7
8
9
10
11
config S3C24XX_DMAC
  bool "Samsung S3C24XX DMA support"
  depends on ARCH_S3C24XX || COMPILE_TEST
  select DMA_ENGINE
  select DMA_VIRTUAL_CHANNELS
  help
   Support for the Samsung S3C24XX DMA controller driver. The
   DMA controller is having multiple DMA channels which can be
   configured for different peripherals like audio, UART, SPI.
   The DMA controller can transfer data from memory to peripheral,
   periphal to memory, periphal to periphal and memory to memory.

3、发现s3c只依赖于S3C24XX_DMAC,这样可以接着看Makefile

?
1
obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o

4、确认驱动文件为s3c24xx-dma.c,了解基本结构

?
1
2
3
4
5
6
7
8
9
10
static struct platform_driver s3c24xx_dma_driver = {
  .driver   = {
    .name  = "s3c24xx-dma",
  },
  .id_table  = s3c24xx_dma_driver_ids,
  .probe   = s3c24xx_dma_probe,
  .remove   = s3c24xx_dma_remove,
};
 
module_platform_driver(s3c24xx_dma_driver);

5、驱动为基本的platform driver,接着就可以了解probe函数了

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Initialize memcpy engine */
dma_cap_set(DMA_MEMCPY, s3cdma->memcpy.cap_mask);
dma_cap_set(DMA_PRIVATE, s3cdma->memcpy.cap_mask);
s3cdma->memcpy.dev = &pdev->dev;
s3cdma->memcpy.device_free_chan_resources =
        s3c24xx_dma_free_chan_resources;
s3cdma->memcpy.device_prep_dma_memcpy = s3c24xx_dma_prep_memcpy;
s3cdma->memcpy.device_tx_status = s3c24xx_dma_tx_status;
s3cdma->memcpy.device_issue_pending = s3c24xx_dma_issue_pending;
s3cdma->memcpy.device_config = s3c24xx_dma_set_runtime_config;
s3cdma->memcpy.device_terminate_all = s3c24xx_dma_terminate_all;
s3cdma->memcpy.device_synchronize = s3c24xx_dma_synchronize;
 
/* Initialize slave engine for SoC internal dedicated peripherals */
dma_cap_set(DMA_SLAVE, s3cdma->slave.cap_mask);
dma_cap_set(DMA_CYCLIC, s3cdma->slave.cap_mask);
dma_cap_set(DMA_PRIVATE, s3cdma->slave.cap_mask);
s3cdma->slave.dev = &pdev->dev;
s3cdma->slave.device_free_chan_resources =
        s3c24xx_dma_free_chan_resources;
s3cdma->slave.device_tx_status = s3c24xx_dma_tx_status;
s3cdma->slave.device_issue_pending = s3c24xx_dma_issue_pending;
s3cdma->slave.device_prep_slave_sg = s3c24xx_dma_prep_slave_sg;
s3cdma->slave.device_prep_dma_cyclic = s3c24xx_dma_prep_dma_cyclic;
s3cdma->slave.device_config = s3c24xx_dma_set_runtime_config;
s3cdma->slave.device_terminate_all = s3c24xx_dma_terminate_all;
s3cdma->slave.device_synchronize = s3c24xx_dma_synchronize;
s3cdma->slave.filter.map = pdata->slave_map;
s3cdma->slave.filter.mapcnt = pdata->slavecnt;
s3cdma->slave.filter.fn = s3c24xx_dma_filter;

6、通过code获悉,s3cdma有master和slave两个engine,且部分接口共享。

只要完成dma接口的适配,dma就可以正常使用了。当然,前提是,两个engine要进行注册使用。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ret = dma_async_device_register(&s3cdma->memcpy);
if (ret) {
  dev_warn(&pdev->dev,
    "%s failed to register memcpy as an async device - %d\n",
    __func__, ret);
  goto err_memcpy_reg;
}
 
ret = dma_async_device_register(&s3cdma->slave);
if (ret) {
  dev_warn(&pdev->dev,
    "%s failed to register slave as an async device - %d\n",
    __func__, ret);
  goto err_slave_reg;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/feixiaoxing/article/details/79873782

延伸 · 阅读

精彩推荐
  • LinuxLinux 黑话解释:什么是桌面环境?

    Linux 黑话解释:什么是桌面环境?

    在桌面 Linux 世界中,最常用的术语之一就是 桌面环境(Desktop Environment)(DE)。如果你是 Linux 的新手,你应该了解一下这个经常使用的术语。...

    Linux中国5782020-09-07
  • Linuxlinux下如何不解压tar.gz文件查看其中的文件大小

    linux下如何不解压tar.gz文件查看其中的文件大小

    最近有朋友问如何linux系统中不用解压tar.gz文件就可以查看其中的文件大小,这里简单分享下, 方便需要的朋友 ...

    linux教程网9752019-11-10
  • Linux使用dmidecode获取Linux服务器硬件信息的方法详解

    使用dmidecode获取Linux服务器硬件信息的方法详解

    这篇文章主要介绍了使用dmidecode获取Linux服务器硬件信息的方法,特别适用于检查主机商提供的硬件配置,需要的朋友可以参考下...

    老左博客4382019-07-08
  • Linux使用 gdu 进行更快的磁盘使用情况检查

    使用 gdu 进行更快的磁盘使用情况检查

    在 Linux 终端中有两种常用的 检查磁盘使用情况的方法:du 命令和 df 命令。du 命令更多的是用来检查目录的使用空间,df 命令则是提供文件系统级别的磁盘...

    Linux中国9512021-03-26
  • LinuxLinux下定时删除过期文件的方法

    Linux下定时删除过期文件的方法

    在linux的日常管理中,有时需要定时删除超过指定时间的文件,这里简单介绍下,方便需要的朋友 ...

    Linux教程网5712019-11-28
  • LinuxLinux系统下findmnt命令使用全解

    Linux系统下findmnt命令使用全解

    这篇文章主要介绍了Linux系统下findmnt命令使用全解,是Linux入门学习中的基础知识,需要的朋友可以参考下...

    开源中文社区9802019-07-09
  • LinuxLinux 相对路径和绝对路径的使用

    Linux 相对路径和绝对路径的使用

    这篇文章主要介绍了Linux 相对路径和绝对路径的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们...

    沧海一笑-dj2112020-09-24
  • LinuxSELinux基本概念详解

    SELinux基本概念详解

    SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux上最杰出的新安全子系统。今天小编要为大家分享的是SELinux基本概念详...

    脚本之家6602019-06-01