我需要吗;启用";Linux 3.12驱动程序中的PCIe内存区域?

我需要吗;启用";Linux 3.12驱动程序中的PCIe内存区域?,linux,linux-kernel,driver,linux-device-driver,pci-e,Linux,Linux Kernel,Driver,Linux Device Driver,Pci E,我有代码,从PCIe驱动程序的probe()函数调用(大致基于此): 编辑:根据响应,我将代码更改为使用pci\u iomap(),但我仍有系统挂起的经验 但是内核在调用ioread8()时挂起 我做错什么了吗?或者我需要看硬件吗? root@socfpga:~# cat /proc/iomem 00000000-3fffffff : System RAM 00008000-006fa7d3 : Kernel code 00754000-007d8c23 : Kernel data c

我有代码,从PCIe驱动程序的probe()函数调用(大致基于此):

编辑:根据响应,我将代码更改为使用
pci\u iomap()
,但我仍有系统挂起的经验

但是内核在调用
ioread8()
时挂起

我做错什么了吗?或者我需要看硬件吗?

root@socfpga:~# cat /proc/iomem 
00000000-3fffffff : System RAM
  00008000-006fa7d3 : Kernel code
  00754000-007d8c23 : Kernel data
c0000000-cfffffff : ALTERA PCIE RP MEM
  c0000000-c00fffff : PCI Bus 0000:01
    c0000000-c001ffff : 0000:01:00.0
d0000000-dfffffff : ALTERA PCIE RP PREF MEM
ff200000-ff20000f : csr
ff200010-ff20008f : vector_slave
ff210000-ff21003f : ff210000.chipidbridge0
ff280000-ff283fff : Cra
ff702000-ff703fff : /soc/ethernet@ff702000
ff704000-ff704fff : /soc/dwmmc0@ff704000
ff705000-ff705fff : ff705000.spi
ffa00000-ffa00fff : ff705000.spi
ffb40000-ffb4fffe : /soc/usb@ffb40000
ffc00000-ffc00fff : c_can_platform
ffc02000-ffc0201f : serial
ffc04000-ffc04fff : /soc/i2c@ffc04000
ffd02000-ffd02fff : /soc/wd@ffd02000
ffe01000-ffe01fff : /soc/amba/pdma@ffe01000
fff00000-fff00fff : fff00000.spi
ffff0000-ffffffff : /soc/sram@ffff0000
root@socfpga:~# 
以下是
lspci-v
cat/proc/iomem
系统干净启动时的输出:

root@socfpga:~# lspci -v
00:00.0 PCI bridge: Altera Corporation Device e000 (rev 01) (prog-if 00 [Normal decode])
    Flags: fast devsel
    Bus: primary=00, secondary=01, subordinate=01, sec-latency=0
    I/O behind bridge: 00000000-00000fff
    Memory behind bridge: c0000000-c00fffff
    Prefetchable memory behind bridge: 00000000-000fffff
    Capabilities: [50] MSI: Enable- Count=1/4 Maskable- 64bit+
    Capabilities: [78] Power Management version 3
    Capabilities: [80] Express Root Port (Slot-), MSI 00
    Capabilities: [100] Virtual Channel
    Capabilities: [200] Vendor Specific Information: ID=1172 Rev=0 Len=044 <?>

01:00.0 Multimedia audio controller: Altera Corporation Device e002 (rev 01)
    Subsystem: Altera Corporation Device e002
    Flags: fast devsel, IRQ 75
    Memory at c0000000 (32-bit, non-prefetchable) [disabled] [size=128K]
    Capabilities: [50] MSI: Enable- Count=1/4 Maskable- 64bit+
    Capabilities: [78] Power Management version 3
    Capabilities: [80] Express Endpoint, MSI 00
    Capabilities: [100] Virtual Channel
    Capabilities: [200] Vendor Specific Information: ID=1172 Rev=0 Len=044 <?>
    Kernel modules: test-pci

你一定要启用它。以下是基本步骤:

pci_enable_device(dev);
pci_request_regions(dev, "driver/device name");
bar0 = pci_iomap(dev, 0, 0);
x = ioread(bar0 + offset);  /* there you are */
所有
pci.*
调用都需要进行错误检查。如果设备需要进行DMA,您还需要调用
pci\u set\u master
pci\u set\u DMA\u mask


更详细地说,绕过PCI内核代码并直接映射条可能在很久以前就起作用了。我不确定它在当前代码中是否合法,但它肯定是不可取的。

要启用内存,您可以直接尝试下面的命令

setpci-s命令=0x02
-s:用于设备选择
命令:请求字大小的命令寄存器,0x02用于启用内存

lspci输出:
0000:01:00.0 RAM内存:Xilinx公司默认PCIe端点ID
0001:02:00.0内存控制器:Xilinx公司设备8011

示例:setpci-s 0001:02:00.0 COMMAND=0x02

感谢您解释我的代码的古老性;没有意识到有更新的界面+1对于
pci\u iomap()
:期待对其进行测试。尝试了您的建议,但没有成功。认为可能是硬件。仍然没有尝试
pci\u request\u regions()
接口,电路板挂在城市的另一边。感谢上帝你回答了。我已经在这页前等了4年了。
pci_enable_device(dev);
pci_request_regions(dev, "driver/device name");
bar0 = pci_iomap(dev, 0, 0);
x = ioread(bar0 + offset);  /* there you are */