PCI驱动程序(request_mem_region失败)

时间:2016-01-20 16:28:06

标签: linux driver linux-device-driver embedded-linux pci

我正在尝试获取内存资源,但出于任何原因,我不能。我的代码如下:

   mmio_base0 = pci_resource_start (dev,0);
   mmio_length0 =pci_resource_len(dev,0);

    if(!mmio_base0 || ((pci_resource_flags (dev,0) & IORESOURCE_MEM)== 0))
    {
            dev_err(&(dev->dev), "no mem resource at PCI #0\n");
    }
    else
    {

            printk(KERN_ALERT "There is memory at BAR0\n");
            if(request_mem_region(mmio_base0,mmio_length0,"driver")==0){
                    printk(KERN_ALERT "Impossible to get memory\n");
            }
    }

我总是得到"无法获得记忆"。所以,有记忆,但我不能要求它。

cat /proc/iomem
c20000000-c2fffffff : /pcie@ffe250000
 c20000000-c2fffffff : PCI Bus 0001:01
  c20000000-c200fffff : 0001:01:00.0 //these two memories I want to request
  c20100000-c201fffff : 0001:01:00.0
 c40000000-c4fffffff : /pcie@ffe270000
 c40000000-c4fffffff : PCI Bus 0002:01

那里有记忆,但我不能要求它们。它总是失败!但我的uboot会检测到我的设备。

    PCIe2: Root Complex, x2 gen2, regs @ 0xfe250000
    02:00.0     - 1957:0808 - Processor

没有驱动程序加载这些记忆:

    0001:01:00.0 Power PC: Freescale Semiconductor Inc Device 0808 (rev 10) (prog-if 01)
    Flags: bus master, fast devsel, latency 0, IRQ 41
    Memory at c20000000 (32-bit, non-prefetchable) [size=1M]
    Memory at c20100000 (32-bit, prefetchable) [size=1M]
    Capabilities: [44] Power Management version 3
    Capabilities: [4c] Express Endpoint, MSI 00
    Capabilities: [88] MSI: Enable- Count=1/16 Maskable- 64bit+
    Capabilities: [100] Advanced Error Reporting

知道发生了什么事吗?

BR

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。我改变了以下内容:

        printk(KERN_ALERT "There is memory at BAR0\n");
        if(request_mem_region(mmio_base0,mmio_length0,"driver")==0){
                printk(KERN_ALERT "Impossible to get memory\n");
        }

 printk(KERN_ALERT "There is memory at BAR0\n");
        if(pci_request_region(dev,0,"mydriver")==0){
                printk(KERN_ALERT "Memory reserved properly\n");
        }

当函数返回0时,内存保留正确。因此,您可以在/ proc / iomem中找到具有关联名称的内存(" mydriver")。

祝你好运