米尔电子
直播中

卿小小_9e6

7年用户 2191经验值
擅长:可编程逻辑
私信 关注
[技术]

【米尔-Xilinx XC7A100T FPGA开发板试用】+02.PCIE接口测试(zmj)

【米尔-Xilinx XC7A100T FPGA开发板试用】+02.PCIE接口测试(zmj)

1. FPGA程序设计

PCI Express (peripheral component interconnect express) 简称 PCIe,是一种高速串行计算机扩展总线标准。是一种全双工总线,使用高速串行传送方式,能够支持更高的频率,连接的设备不再像 PCI 总线那样共享总线带宽。PCIe 目前发布了 多 个版本——PCIe1.0、PCIe2.0、PCIe3.0、PCIe4.0等。

米尔-Xilinx XC7A100T FPGA开发板的PCIe可配置成 X1、 X2 模式,它 的单通道通信速率可高达 5G bit 带宽。本例程中通过利用 XILINX 的 XDMA IP 来实现 PCIE 的发送和接收速度测试。

1.1 参考电路

米尔-Xilinx XC7A100T FPGA开发板的PCIe参考电路:

image-20241111192229927.png

1.2 工程框架

【图】工程框架

image-20241108184328760.png

1.3 编译结果

编译结果时序正常。

【图】编译结果
image-20241108183943291.png

1.4 烧录

Vivado-2022.2不支持mx25l25645g-spi-x1_x2_x4,因此通过JTAG烧录JTAG的模式测试。

//------板卡QSPI-FLASH型号(容量256Bbit/32MByte)
mx25l25645g-spi-x1_x2_x4
//------Vivado识别FLASH异常的错误信息
ERROR: [Labtoolstcl 44-349] Unrecognized config mem part - mx25l25645g-spi-x1_x2_x4. Please run get_cfgmem_parts and select a valid part or use the cfgmem GUI to assist in selecting a valid device.
//------处理方式
烧录bit调试,烧录完成后系统需要不掉电重启Reboot。

【图】FPGA烧录-固化FLASH时报错(错误原因是Vivado-2022.2不支持QSPI-FLASH“mx25l25645g-spi-x1_x2_x4”)

image-20241108185000212.png

2. 驱动

2.1 驱动下载与编译安装

驱动下载与编译安装,分别测试了Ubuntu-22.04.4-LTS和CentOS-7.9,驱动编译正常。

1.驱动编译:在xdma中执行sudo make install命令编译驱动,生成xmda.ko文件。
2.编译工具:在tools中执行make命令编译工程,生成reg_rw、dma_to_device、dma_from_device可执行文件。
3.驱动加载:在tests中执行sudo ./load_driver.sh加载驱动
4.如果需要增加设备ID,需要修改xdma/xdma_mod.c文件,在”pci_device_id“结构体下增加PCI_DEVICE的Vendor ID和Device ID。

//------操作指令
a.驱动下载
git clone https://github.com/Xilinx/dma_ip_drivers.git
b.进入目录
cd dma_ip_drivers
cd XDMA/linux-kernel
cd ./xdma
c.编译与安装(普通用户注意权限问题)
sudo make install
d.其他
XDMA的驱动编译、安装及测试参考文件:dma_ip_drivers/XDMA/linux-kernel/readme.txt
//------示例Log信息@192.168.28.126(Ubuntu-22.04.4-LTS)
zhaomj@localhost:~/zmj_ws/git_xilinx$ git clone https://github.com/Xilinx/dma_ip_drivers.git
zhaomj@localhost:~/zmj_ws/git_xilinx$ cd dma_ip_drivers/XDMA/linux-kernel/xdma
zhaomj@localhost:~/zmj_ws/git_xilinx$ sudo make install
zhaomj@localhost:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma$ sudo make install
Makefile:17: XVC_FLAGS: .
make -C /lib/modules/3.10.0-1160.119.1.el7.x86_64/build M=/xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-1160.119.1.el7.x86_64'
/xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/Makefile:17: XVC_FLAGS: .
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/libxdma.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma_cdev.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_ctrl.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_events.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_sgdma.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_xvc.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_bypass.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma_mod.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma_thread.o
  LD [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma.o
  Building modules, stage 2.
/xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/Makefile:17: XVC_FLAGS: .
  MODPOST 1 modules
  CC      /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma.mod.o
  LD [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma.ko
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1160.119.1.el7.x86_64'
installing kernel modules to /lib/modules/3.10.0-1160.119.1.el7.x86_64/xdma ...
‘xdma.ko’ -> ‘/lib/modules/3.10.0-1160.119.1.el7.x86_64/xdma/xdma.ko’
zhaomj@localhost:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma$ 

//------示例Log信息@192.168.28.121(CentOS-7.9)
zhaomj@ahag_121:~/zmj_ws$ cd git_xilinx/
zhaomj@ahag_121:~/zmj_ws/git_xilinx$ git clone https://github.com/Xilinx/dma_ip_drivers.git
zhaomj@ahag_121:~/zmj_ws/git_xilinx$ ls
dma_ip_drivers  dma_ip_drivers.tar.gz  readme.txt
zhaomj@ahag_121:~/zmj_ws/git_xilinx$ cd dma_ip_drivers/
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers$ ls
docs  index.html  QDMA  README.md  XDMA  XVSEC
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers$ cd XDMA/linux-kernel/
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel$ ls
COPYING  include  LICENSE  readme.txt  RELEASE  tests  tools  xdma
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel$ cd xdma/
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma$ sudo make install
Makefile:17: XVC_FLAGS: .
make -C /lib/modules/3.10.0-1160.el7.x86_64/build M=/xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-1160.el7.x86_64'
/xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/Makefile:17: XVC_FLAGS: .
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/libxdma.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma_cdev.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_ctrl.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_events.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_sgdma.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_xvc.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/cdev_bypass.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma_mod.o
  CC [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma_thread.o
  LD [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma.o
  Building modules, stage 2.
/xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/Makefile:17: XVC_FLAGS: .
  MODPOST 1 modules
  CC      /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma.mod.o
  LD [M]  /xdsk/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma/xdma.ko
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1160.el7.x86_64'
installing kernel modules to /lib/modules/3.10.0-1160.el7.x86_64/xdma ...
‘xdma.ko’ -> ‘/lib/modules/3.10.0-1160.el7.x86_64/xdma/xdma.ko’
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/xdma$ cd ..
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel$ ls
COPYING  include  LICENSE  readme.txt  RELEASE  tests  tools  xdma
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel$ cd tools/
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ ls
dma_from_device.c  dma_to_device.c  dma_utils.c  Makefile  performance.c  reg_rw.c  test_chrdev.c
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ sudo make
cc -c -std=c99 -o reg_rw.o reg_rw.c -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -o reg_rw reg_rw.o
cc -c -std=c99 -o dma_to_device.o dma_to_device.c -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -lrt -o dma_to_device dma_to_device.o -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -c -std=c99 -o dma_from_device.o dma_from_device.c -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -lrt -o dma_from_device dma_from_device.o -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -c -std=c99 -o performance.o performance.c -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -o performance performance.o -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -c -std=c99 -o test_chrdev.o test_chrdev.c -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGE_FILE_SOURCE
cc -o test_chrdev test_chrdev.o
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ ls
dma_from_device    dma_to_device    dma_utils.c  performance.c  reg_rw.c     test_chrdev.c
dma_from_device.c  dma_to_device.c  Makefile     performance.o  reg_rw.o     test_chrdev.o
dma_from_device.o  dma_to_device.o  performance  reg_rw         test_chrdev
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ sudo modprobe xdma
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ dmesg | tail 
[   10.868269] virbr0: port 1(virbr0-nic) entered listening state
[   10.868301] IPv6: ADDRCONF(NETDEV_UP): virbr0: link is not ready
[   10.888705] virbr0: port 1(virbr0-nic) entered disabled state
[   14.333459] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   14.333461] Bluetooth: BNEP filters: protocol multicast
[   14.333463] Bluetooth: BNEP socket layer initialized
[   14.559749] rfkill: input handler disabled
[   17.463079] TCP: lp registered
[  756.672292] xdma:xdma_mod_init: Xilinx XDMA Reference Driver xdma v2020.2.2
[  756.672294] xdma:xdma_mod_init: desc_blen_max: 0xfffffff/268435455, timeout: h2c 10 c2h 10 sec.
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$

【图】Ubuntu-22.04.4-LTS编译安装驱动
image-20241101145015863.png
【图】CentOS-7.9编译安装驱动
image-20241108111212813.png

2.2 驱动源文件说明

文件说明

序号 文件 说明
1 include 编译依赖文件。
2 tests 测试文件:load_driver负责加载驱动,run_test.sh执行DMA测试,dma_memory_mapped_test是MM测试调用脚本,dma_streaming_test.sh是Stream测试调用脚本,data是测试数据文件夹(包含测试数据)
3 tools 工具文件(测试文件):reg_rw.c是AXI4-Lite和AXI4-Bypass通道读写寄存器工具,dma_to_device.c是AXI4通道写工具,dma_from_device.c是AXI4通道读工具。
4 xdma 驱动源文件,其中xdma_mod.c添加设备的VendorID和DeviceID
5 readme.txt 说明文件(编译及测试流程的简要说明)
6 RELEASE 版本说明
7 COPYING 权限
8 LICENSE 证书

2.3 驱动加载及验证

2.3.1 驱动加载

通过“modprobe”或者“insmod”加载xdma驱动,此处执行驱动加载指令:sudo modprobe xdma

还可以通过执行驱动加载脚本:sudo ./load_driver.sh 加载驱动;执行:sudo rmmod xdma 卸载驱动。

通过观察dmesg日志,可以看到驱动正确加载。

【图】使用“modprobe”加载驱动

image-20241108111800654.png

【图】使用load_driver.sh脚本加载驱动失败(原因是FPGA未加载XDMA固件,因此无法识别PCIE设备导致驱动加载异常)
image-20241108140752797.png

2.3.2 驱动验证

可以通过“lsmod | grep xdma”查看xdma驱动是否成功加载。

驱动加载正常时,会打印和XDMA相关的驱动信息:

//------lspci:
功能:用于显示当前主机的所有PCI总线信息,以及所有已连接的PCI设备信息。
语法: Ispci(选项)
选项
-n:以数字方式显示PCI厂商和设备代码;
-t:以树状结构显示PCI设备的层次关系,包括所有的总线、桥、设备以
及它们之间的联接;
-b:以总线为中心的视图;
-d:仅显示给定厂商和设备的信息;
-s:仅显示指定总线、插槽上的设备和设备上的功能块信息;
-i:指定PCI编号列表文件,而不使用默认的文件;
-m:以机器可读方式显示PCI设备信息。
//---参数说明
BDF(Bus-Function-Module):0000:01:00.0
Vendor-ID:   10ee   表示Xilinx
Device-ID:   7022   表示7Series/PCIe-Gen2.0/2X

BDF(Bus-Function-Module):
             0000:01:00.0
Vendor-ID:   
             10ee   表示Xilinx
Device-ID:   
             7022   表示7Series/PCIe-Gen2.0/2X

【图】驱动加载验证正常

image-20241108143159471.png

2.4 驱动基本解析

从DMA的角度出发去讨论Xilinx的PCIE传输过程。

值得注意的是,在pcie dma传输数据的过程中,驱动程序会申请两次DMA。第一次是在驱动初始化的时候:

engine->desc = dma_alloc_coherent(&xdev->pdev->dev,
                    XDMA_TRANSFER_MAX_DESC *
                        sizeof(struct xdma_desc),
                    &engine->desc_bus, GFP_KERNEL);

申请的是xdma IP规定的dma描述符,其结构体定义如下:

struct xdma_desc {
    u32 control;
    u32 bytes;      /* transfer length in bytes */
    u32 src_addr_lo;    /* source address (low 32-bit) */
    u32 src_addr_hi;    /* source address (high 32-bit) */
    u32 dst_addr_lo;    /* destination address (low 32-bit) */
    u32 dst_addr_hi;    /* destination address (high 32-bit) */
    /*
     * next descriptor in the single-linked list of descriptors;
     * this is the PCIe (bus) address of the next descriptor in the
     * root complex memory
     */
    u32 next_lo;        /* next desc address (low 32-bit) */
    u32 next_hi;        /* next desc address (high 32-bit) */
} __packed;

把engine->desc_bus直接写到XDMA IP的0H2C SGDMA Descriptor Low Address和H2C SGDMA Descriptor High Address寄存器,然后xdma ip就可以获取到内存中该结构体对应的内容。

第二次申请是在应用程序和pcie设备传输数据的时候,也就是H2C或C2H的时候。驱动程序会根据应用程序申请内存空间大小进行流式dma映射,然后把pcie设备能操作的总线地址写到struct xdma_desc的src_addr_lo、src_addr_hi、dst_addr_lo和dst_addr_hi,要传输的大小写到bytes,这样pcie设备就可以通过XDMA IP的0H2C SGDMA Descriptor Low Address和H2C SGDMA Descriptor High Address寄存器的地址去获取dma的传输信息了。

3. 功能测试

3.1 PCIE设备状态

如上述“2.3 驱动加载及验证”,通过“lspci”指令查看PCIE设备状态。

//------指令:
sudo lspci -vv -s 0000:01:00.0
sudo lspci -xxv -s 0000:01:00.0
//------
BAR0寄存器(AXI4-Lite)存储空间:
Memory at 50500000 (32-bit, non-prefetchable) [size=64K]
//------示例Log信息
zhaomj@ahag_121:~/zmj_ws$ sudo lspci -vv -s 0000:01:00.0
01:00.0 Memory controller: Xilinx Corporation Device 7022
        Subsystem: Xilinx Corporation Device 0007
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 0, Cache Line Size: 64 bytes
        Interrupt: pin A routed to IRQ 171
        Region 0: Memory at 50500000 (32-bit, non-prefetchable) [size=64K]
        Capabilities: [40] Power Management version 3
                Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1+,D2+,D3hot+,D3cold-)
                Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
        Capabilities: [48] MSI: Enable+ Count=1/1 Maskable- 64bit+
                Address: 00000000fee002f8  Data: 0000
        Capabilities: [60] Express (v2) Endpoint, MSI 00
                DevCap: MaxPayload 512 bytes, PhantFunc 0, Latency L0s <64ns, L1 unlimited
                        ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset- SlotPowerLimit 75.000W
                DevCtl: Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
                        RlxdOrd+ ExtTag+ PhantFunc- AuxPwr- NoSnoop+
                        MaxPayload 256 bytes, MaxReadReq 512 bytes
                DevSta: CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr- TransPend-
                LnkCap: Port #0, Speed 5GT/s, Width x2, ASPM L0s, Exit Latency L0s unlimited, L1 unlimited
                        ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp-
                LnkCtl: ASPM Disabled; RCB 64 bytes Disabled- CommClk+
                        ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
                LnkSta: Speed 5GT/s, Width x2, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
                DevCap2: Completion Timeout: Range B, TimeoutDis-, LTR-, OBFF Not Supported
                DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, OBFF Disabled
                LnkCtl2: Target Link Speed: 5GT/s, EnterCompliance- SpeedDis-
                         Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
                         Compliance De-emphasis: -6dB
                LnkSta2: Current De-emphasis Level: -6dB, EqualizationComplete-, EqualizationPhase1-
                         EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
        Capabilities: [100 v1] Device Serial Number 00-00-00-00-00-00-00-00
        Kernel driver in use: xdma
        Kernel modules: xdma

zhaomj@ahag_121:~/zmj_ws$ sudo lspci -xxv -s 0000:01:00.0
01:00.0 Memory controller: Xilinx Corporation Device 7022
        Subsystem: Xilinx Corporation Device 0007
        Flags: bus master, fast devsel, latency 0, IRQ 171
        Memory at 50500000 (32-bit, non-prefetchable) [size=64K]
        Capabilities: [40] Power Management version 3
        Capabilities: [48] MSI: Enable+ Count=1/1 Maskable- 64bit+
        Capabilities: [60] Express Endpoint, MSI 00
        Capabilities: [100] Device Serial Number 00-00-00-00-00-00-00-00
        Kernel driver in use: xdma
        Kernel modules: xdma
00: ee 10 22 70 06 00 10 00 00 00 80 05 10 00 00 00
10: 00 00 50 50 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 ee 10 07 00
30: 00 00 00 00 40 00 00 00 00 00 00 00 ff 01 00 00

zhaomj@ahag_121:~/zmj_ws$

【图】PCIE设备状态

image-20241111203314018.png

3.2 寄存器读写

寄存器读写使用reg_rw通过AXI4-Lite通道进行读写操作。

//------写寄存器
写寄存器指令格式:./reg_rw <设备> <地址> <数据长度> <写入数据>
sudo ./reg_rw /dev/xdma0_control 0x1004 w 0x11223344
解析:设备xdma0_control,偏移地址0x1004,操作写,数据0x11223344
//------读寄存器
读寄存器指令格式:./reg_rw <设备> <地址> <数据长度>
sudo ./reg_rw /dev/xdma0_control 0x1004 r
解析:设备xdma0_control,偏移地址0x1004,操作读
//------示例Log信息
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ sudo ./reg_rw /dev/xdma0_control 0x1004 w 0x11223344
device: /dev/xdma0_control, address: 0x1004 (0x1000+0x4), access write.
access width: word (32-bits)
character device /dev/xdma0_control opened.
Memory 0x1000 mapped at address 0x7f194fac1000.
Write 32-bits value 0x11223344 to 0x1004 (0x0x7f194fac1004)
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$ sudo ./reg_rw /dev/xdma0_control 0x1004 r
device: /dev/xdma0_control, address: 0x1004 (0x1000+0x4), access write.
access width: default to word (32-bits)
character device /dev/xdma0_control opened.
Memory 0x1000 mapped at address 0x7fa5823ba000.
Read 32-bit value at address 0x1004 (0x7fa5823ba004): 0x11223344
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tools$

【图】BAR0寄存器读写测试

image-20241111204201231.png

3.3 完整测试

执行tests文件夹下的脚本“run_test.sh”可以完成对XDMA的测试,整个测试流程包括查询使能通道、确定接口方式(MM or ST),根据接口方式调用脚本dma_memory_mapped_test.sh或者dma_streaming_test。dma_memory_mapped_test.sh和dma_streaming_test脚本首先使用dma_to_device命令发送测试数据到BRAM,然后使用dma_from_device命令从BRAM中取出数据,最后对比两个文件的数据是否一致。测试记过如下图所示。

zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tests$ sudo ./run_test.sh
Info: Number of enabled h2c channels = 2
Info: Number of enabled c2h channels = 2
Info: The PCIe DMA core is memory mapped.
Info: Running PCIe DMA memory mapped write read test
        transfer size:  1024, count: 1
Info: Writing to h2c channel 0 at address offset 0.
Info: Writing to h2c channel 1 at address offset 1024.
Info: Wait for current transactions to complete.
/dev/xdma0_h2c_0 ** Average BW = 1024, 22.168821
/dev/xdma0_h2c_1 ** Average BW = 1024, 24.960390
Info: Writing to h2c channel 0 at address offset 2048.
Info: Writing to h2c channel 1 at address offset 3072.
Info: Wait for current transactions to complete.
/dev/xdma0_h2c_0 ** Average BW = 1024, 28.497482
/dev/xdma0_h2c_1 ** Average BW = 1024, 28.234257
Info: Reading from c2h channel 0 at  address offset 0.
Info: Reading from c2h channel 1 at  address offset 1024.
Info: Wait for current transactions to complete.
/dev/xdma0_c2h_0 ** Average BW = 1024, 25.516434
/dev/xdma0_c2h_1 ** Average BW = 1024, 23.529953
Info: Reading from c2h channel 0 at  address offset 2048.
Info: Reading from c2h channel 1 at  address offset 3072.
Info: Wait for current transactions to complete.
/dev/xdma0_c2h_0 ** Average BW = 1024, 20.966421
/dev/xdma0_c2h_1 ** Average BW = 1024, 24.374569
Info: Checking data integrity.
Info: Data check passed for address range  0 - 1024
Info: Data check passed for address range  1024 - 2048
Info: Data check passed for address range  2048 - 3072
Info: Data check passed for address range  3072 - 4096
Info: All PCIe DMA memory mapped tests passed.
Info: All tests in run_tests.sh passed.
zhaomj@ahag_121:~/zmj_ws/git_xilinx/dma_ip_drivers/XDMA/linux-kernel/tests$

【图】运行完整测试

image-20241111204801587.png

//------end

更多回帖

发帖
×
20
完善资料,
赚取积分