使用mmap进行PCI-e内存空间访问 [英] PCI-e memory space access with mmap

查看:881
本文介绍了使用mmap进行PCI-e内存空间访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在飞思卡尔MPC8308处理器(基于PowerPC架构)上使用PCI-e端口,尝试使用它时遇到一些问题.端点PCI-e设备的内存空间等于256 MB.我可以使用"pciutils"包轻松读取和写入端点设备的配置空间.

I'm using PCI-e port on Freescale MPC8308 processor (which is based on PowerPC architecture) and I have some problems when trying to use it. The endpoint PCI-e device has memory space equal to 256 MB. I can easily read and write configuration space of the endpoint device by using "pciutils" package.

在配置寄存器中写入正确的值并获得访问内存空间的权限后;我试图通过在C语言中使用"mmap()"函数来访问内存空间,并使用位于:

After writing correct values in configuration registers and getting the permission to access the memory space; I tried to access memory space by using "mmap()" function in C and used the file descriptor located at :

"/sys/devices/pci0000:00/0000:00:00.0/resource0"

"/sys/devices/pci0000:00/0000:00:00.0/resource0"

恰好是256 MB(等于端点设备的内存空间),因此看来我在使用正确的文件描述符路径.在这里,您可以使用 https://github.com/billfarrow/pcimem中提到的"mmap()"找到我的代码:

which was exactly 256 MB (equal to memory space of endpoint device) so it seems that I am using correct path for file descriptor. here you can find my code using "mmap()" as mentioned in https://github.com/billfarrow/pcimem:

https://github.com/billfarrow/pcimem/blob/master /pcimem.c

但是不幸的是,当我尝试通过使用"mmap()"函数的返回地址来使用内存空间时;我无法正确读取端点设备的只读寄存器.另外,当我读取大于"0x7FFFFFC"的地址时,MPC8308重新启动. 考虑到上述情况,我是否错过任何初始化PCI-e接口的步骤?我应该更改Linux内核映像或U-Boot代码中的任何内容吗?通过mmap()使用PowerPC PCI-e有什么不同吗?您是否有任何示例代码可以帮助我读取PCI-e内存空间?

But unfortunately when I try to use memory space by using returned address of "mmap()" function; I cannot read the read-only registers of endpoint device correctly. Also, when I read addresses bigger than "0x7FFFFFC", the MPC8308 reboots. Considering above situation, do I miss any steps to initialize the PCI-e interface? Should I change anything in the Linux kernel image or U-Boot codes? Is there anything different for using PowerPC PCI-e with mmap()? Do you have any example code that can help me read PCI-e memory space?

谢谢

推荐答案

mmap()是从用户空间访问PCIe设备的非常有用但随意的方法.

mmap() is a very useful but casual way to access PCIe devices from user space.

我注意到您将0作为第一个参数传递给mmap.在将FPGA卡插入x86计算机的情况下,我打电话给lspci以获取pcie插槽中卡的物理地址.然后,我将该物理地址用作mmap的第一个参数.我知道您是在设备的配置空间中编写BAR的,但也许可以通过lspci进行仔细检查.

I notice that you pass 0 as the first argument to mmap. In my case of an FPGA card plugged into an x86 computer I make a call to lspci to get the physical address of the card in the pcie slot. Then I use that physical address as the first argument to mmap. I know you are writing the BAR's in config space of the device but maybe double check with lspci.

$ sudo lspci -s 02:00 -v
02:00.0 Memory controller: Xilinx Corporation Device 8028
    Subsystem: Xilinx Corporation Device 0007
    Flags: bus master, fast devsel, latency 0, IRQ 11
    Memory at f7e00000 (32-bit, non-prefetchable) [size=1M]
    Capabilities: [80] Power Management version 3
    Capabilities: [90] MSI: Enable- Count=1/1 Maskable- 64bit+
    Capabilities: [c0] Express Endpoint, MSI 00
    Capabilities: [100] Advanced Error Reporting

这篇关于使用mmap进行PCI-e内存空间访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆