LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ioremap failure (https://www.linuxquestions.org/questions/programming-9/ioremap-failure-4175721185/)

Cranegsh 01-21-2023 07:47 PM

ioremap failure
 
Hello,

I am writing a kernel driver under Raspberry Pi.

I try to access to GPIO registers by mapping the physically address first. The physical address should be correct as it is from the MCU manual and confirmed by /proc/iomem. But when I use the ioremap(), it fails to acquire the virtual memory address.

What are the potential causes for this error?

Here is trace information. I would like to know how to interpret these information.

[324495.393321] Welcome to my driver!
[324495.393347] Trying to map GPIO registers at 0x7E200000 with page size 64:
[324495.393377] ------------[ cut here ]------------
[324495.393384] WARNING: CPU: 3 PID: 48777 at arch/arm64/mm/ioremap.c:46 __ioremap_caller+0xd4/0xf8
[324495.393420] Modules linked in: driver_gpio(O+) rfcomm cmac algif_hash aes_arm64 aes_generic algif_skcipher af_alg bnep hci_uart btbcm bluetooth ecdh_generic ecc libaes 8021q garp stp llc brcmfmac vc4 brcmutil snd_soc_hdmi_codec cfg80211 cec drm_kms_helper rfkill snd_soc_core bcm2835_codec(C) snd_compress snd_bcm2835(C) rpivid_hevc(C) snd_pcm_dmaengine v3d bcm2835_isp(C) snd_pcm bcm2835_v4l2(C) v4l2_mem2mem bcm2835_mmal_vchiq(C) gpu_sched videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops snd_timer raspberrypi_hwmon snd videobuf2_v4l2 videobuf2_common syscopyarea i2c_brcmstb sysfillrect videodev vc_sm_cma(C) sysimgblt mc fb_sys_fops uio_pdrv_genirq uio nvmem_rmem drm i2c_dev fuse drm_panel_orientation_quirks backlight ip_tables x_tables ipv6 [last unloaded: driver_gpio]
[324495.393752] CPU: 3 PID: 48777 Comm: insmod Tainted: G WC O 5.15.84-v8+ #1613
[324495.393766] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
[324495.393775] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[324495.393788] pc : __ioremap_caller+0xd4/0xf8
[324495.393803] lr : __ioremap_caller+0x5c/0xf8
[324495.393817] sp : ffffffc00a78bab0
[324495.393823] x29: ffffffc00a78bab0 x28: ffffff804302e800 x27: ffffff8081125a00
[324495.393846] x26: 0000000000000003 x25: ffffffd60da83040 x24: ffffff8081125ad0
[324495.393868] x23: 0068000000000f13 x22: ffffffd60da7206c x21: 0000000000000000
[324495.393891] x20: 000000007e200000 x19: 0000000000001000 x18: 0000000000000001
[324495.393917] x17: 0000000000000000 x16: ffffffd66c4351e0 x15: ffffffffffffffff
[324495.393937] x14: 0000000000000001 x13: 3a343620657a6973 x12: ffffffd66d7b6660
[324495.393957] x11: 0000000000000003 x10: ffffffd66d79e620 x9 : ffffffd66c4349f8
[324495.393977] x8 : 00000000bc000000 x7 : 0000000000000018 x6 : ffffffd66d9573f0
[324495.393997] x5 : ffffffd66d9573d8 x4 : 0000000000000002 x3 : 0000000000000002
[324495.394016] x2 : 00000000fc000000 x1 : 0000000000000001 x0 : 0000000000000001
[324495.394036] Call trace:
[324495.394043] __ioremap_caller+0xd4/0xf8
[324495.394058] __ioremap+0x30/0x60
[324495.394071] driver_gpio_init+0x6c/0x1000 [driver_gpio]
[324495.394093] do_one_initcall+0x54/0x2a0
[324495.394105] do_init_module+0x50/0x228
[324495.394120] load_module+0x214c/0x27a8
[324495.394133] __do_sys_finit_module+0xbc/0xf8
[324495.394147] __arm64_sys_finit_module+0x28/0x38
[324495.394160] invoke_syscall+0x4c/0x110
[324495.394174] el0_svc_common.constprop.3+0xfc/0x120
[324495.394188] do_el0_svc+0x2c/0x90
[324495.394200] el0_svc+0x24/0x60
[324495.394212] el0t_64_sync_handler+0x90/0xb8
[324495.394223] el0t_64_sync+0x1a0/0x1a4
[324495.394233] ---[ end trace e0fb6fca75899295 ]---
[324495.394242] Failed to map GPIO memory to driver

Thanks!

Crane

NevemTeve 01-22-2023 02:07 AM

You might want to check this line in the source: arch/arm64/mm/ioremap.c:46

Cranegsh 01-22-2023 10:22 PM

Quote:

Originally Posted by NevemTeve (Post 6406177)
You might want to check this line in the source: arch/arm64/mm/ioremap.c:46

Thanks NevemTeve for your reply.

I try to find ioremap.c and couldn't find it in /lib/modules/build/arch/arm64/mm/ where there is only a Makefile. I found it in the Linux source folder, but couldn't find the function ioremap() , only __ioremap().
Is this normal that this file is not there and this function doesn't exist in this source file? And how can I track further where the problem comes from?

Thanks
Crane

NevemTeve 01-23-2023 01:30 AM

You have to install the kernel-source -- it depends on your distribution, search for name `linux-source` or `kernel-source`. When you have installed it, it will be (probably) in directory /usr/src.

For example, I tried with Ubuntu, it was a bit more complicated:
Code:

# apt-get install linux-source
# cd /usr/src
# tar xjf linux-source*/*.bz2
# ls -l linux*/arch/arm64/mm/ioremap.c
-rw-r--r-- 1 root root 2980 Jan 28  2018 linux-source-4.15.0/arch/arm64/mm/ioremap.c
# cat -n linux*/arch/arm64/mm/ioremap.c | less -S
...
    41          /*
    42          * Page align the mapping address and size, taking account of any
    43          * offset.
    44          */
    45          phys_addr &= PAGE_MASK;
    46          size = PAGE_ALIGN(size + offset);
...

Mind you, my source is most likely different to yours (older version), so it doesn't help you.
[/code]

Cranegsh 01-23-2023 11:06 PM

Quote:

Originally Posted by NevemTeve (Post 6406375)
You have to install the kernel-source -- it depends on your distribution, search for name `linux-source` or `kernel-source`. When you have installed it, it will be (probably) in directory /usr/src.

[/code]

Thank you NevemTeve!
I can find it from the Linux source folder. But not in the /lib/module/[Version]/build folder. But the latter one is the folder that will be used when building the kernel module.

Anyway, eventually I found the cause. The physically address needs to be mapped from 0x7E200000 to 0xFE200000.


All times are GMT -5. The time now is 10:21 PM.