0

I am trying to get memory resource but for any reason, I cannot. My code is the following:

   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");
            }
    }

I always get "Impossible to get memory". So, there are memory but I cannot request it.

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

There are memories there, but I cannot request them. It always fail! But my uboot detect my device.

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

And there is not driver loaded which take these memories:

    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

Any idea what is going on?

BR

manolo tunez
  • 131
  • 1
  • 2
  • 9
  • 1
    Your driver cannot request memory that is already claimed (i.e. if you see the memory region listed in **/proc/iomem**, then that memory is already reserved). Study http://stackoverflow.com/questions/7682422/what-does-request-mem-region-actually-do-and-when-it-is-needed including the part about coding style. – sawdust Jan 20 '16 at 20:50
  • Thanks for your answer. I have read this post, However, there is no driver taking this memory. And I do not know who is taking it. Any idea how to discover it? BR – manolo tunez Jan 21 '16 at 07:25

1 Answers1

0

I have already solved this problem. I have changed the following:

        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");
        }

to

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

When the function return 0, the memory is reserved properly. So, you can find in /proc/iomem the memory with a associated name ("mydriver").

Best regards

manolo tunez
  • 131
  • 1
  • 2
  • 9
  • 1
    Yeah, because PCI bus core requested all resources for you (see the driver for `c20000000-c200fffff : 0001:01:00.0`). – 0andriy Jan 21 '16 at 13:03