访问pcie总线地址内容

调用代码如下:

    uint32_t value;
    void * addr;
    printk("------1--------\n");

    addr=0x2730000;
    struct resource *res;
    char const *name = dev_name(&pdev->dev);
    printk("dev_name=%s\n", name);
    res = request_mem_region(addr, 16, "name1");
    if(res == NULL){
        printk("request_mem_region failed\n");
        return -ENOMEM;
    }

    void * ioaddr;
    ioaddr = ioremap(res->start, resource_size(res));
    value = readl(ioaddr);
    printk("-----addr=0x%x  value=0x%x\n",ioaddr, value);
    iounmap(ioaddr);
    release_region(addr, 16);

使用 cat/proc/iomem:
访问pcie总线地址内容_第1张图片

这个是干什么的呢,其实就是当你:

   //addr=0x2002730000;
    addr=0x100000000;
    struct resource *res;
    res = request_region(addr, 8, "name1");

的时候,会在这里记录一下使用了这些内存,别人就不要用了
访问pcie总线地址内容_第2张图片
我们可以通过lspci查看pci总线信息:
访问pcie总线地址内容_第3张图片

root@synopsys-VirtualBox:~# lspci -d 1e36: -v
01:00.0 FireWire (IEEE 1394): Shanghai Enflame Technology Co. Ltd Device 8031 (rev 01) (prog-if 00 [Generic])
Flags: fast devsel, IRQ 5
Memory at e2900000 (32-bit, non-prefetchable) [size=16K]
Memory at e3000000 (32-bit, non-prefetchable) [size=8M]
Memory at 1400000000 (64-bit, prefetchable) [size=16G]
Memory at 1800000000 (64-bit, prefetchable) [size=256M]
Expansion ROM at e2904000 [virtual] [disabled] [size=2K]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable- Count=1/16 Maskable- 64bit+
Capabilities: [70] Express Endpoint, MSI 00
Capabilities: [b0] MSI-X: Enable- Count=8 Masked-

地址不是这样子计算的,你看寄存器bar的物理地址在e3000000,你从这个地址map 8M出来,然后访问offset2730000地方

你可能感兴趣的:(笔记,开发语言)