This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Accessing I/O memory address in kernel module

Hi,

Due to real-time requirement, calling gpio_get_value() is too slow for me project. Now I am looking into another alternative -- reading from GPIO register directly to get the input value of a number of GPIO pins in one go. Below is my implementation:

 

 

int j, tmp, val;

void __iomem *base;

if (!request_mem_region (0x49058000, 1024, "gpio-test")) {

printk(KERN_INFO "request_mem_region failed");

result = -1;

goto fail;

}

base = ioremap (0x49058000, 1024); 

if (!base) {

printk(KERN_INFO "ioremap failed");

result = -1;

goto fail;

}

tmp = ioread32(0x49058038);

printk(KERN_INFO "tmp 0x%04x\n", tmp);

 

 

 

However, my kernel module made kernel OOPS:

Unable to handle kernel paging request at virtual address 49058038

pgd = cb50c000

[49058038] *pgd=00000000

Internal error: Oops: 5 [#1]

 

Can someone guide me on this?

 

Many thanks,

Chuakai

  • You need to use the pointer returned by ioremap when accessing the I/O. The function does what its name suggests - it remaps the 0x49058000 region of 1024 bytes to a virtual adress in the kernel memory space and returns this. It doesn't "open a hole" in the memory map to the underlying physical address, as your usage seems to imply.

    Add a printk("Mapped base: %p\n", base); to see the new address and use that (with the suitable offset - 0x38 in your case).

    I don't know if ioread32 is the right function you want to use either - maybe it maps to the same underlying function but this is more common:

     

            __raw_writel(val, base + idx);   (or writeb, writew)

    or __raw_readl(base + idx) in your case for reading.
    See ya,
    /Bjorn W

     

  • OMAP3 GPIOGoing directly a the registers of cause gives you the fastest response :-). Though please take care that the GPIOs in OMAP aren't specifically fast as whey were never designed to do fast flipping. Doing a while loop flipping a GPIO HIGH/LOW with direct register writes will give you something like a 4MHz square wave on the GPIO...

    I hope this will be fast enough for you application. Best regards - Good luck
      Søren