gpt4 book ai didi

linux - PCI 驱动程序(request_mem_region 失败)

转载 作者:太空宇宙 更新时间:2023-11-04 12:58:34 25 4
gpt4 key购买 nike

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

   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

最佳答案

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

        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”)的内存。

最好的问候

关于linux - PCI 驱动程序(request_mem_region 失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34905353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com