LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2023, 07:47 PM   #1
Cranegsh
Member
 
Registered: Jan 2023
Posts: 42

Rep: Reputation: 0
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
 
Old 01-22-2023, 02:07 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,924
Blog Entries: 1

Rep: Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886
You might want to check this line in the source: arch/arm64/mm/ioremap.c:46
 
Old 01-22-2023, 10:22 PM   #3
Cranegsh
Member
 
Registered: Jan 2023
Posts: 42

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by NevemTeve View Post
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
 
Old 01-23-2023, 01:30 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,924
Blog Entries: 1

Rep: Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886Reputation: 1886
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]
 
Old 01-23-2023, 11:06 PM   #5
Cranegsh
Member
 
Registered: Jan 2023
Posts: 42

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by NevemTeve View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference to ioremap Changho Chung Linux - Software 3 05-27-2013 12:23 AM
Is it safe to use copy_to_user on a __iomem pointer returned by ioremap? orback Linux - Kernel 12 03-01-2010 10:32 AM
regarding ioremap() for accessing hardware ksrinivas Debian 0 03-29-2007 10:42 PM
ioremap and remap_page_range mspies Linux - Software 1 08-20-2005 10:41 PM
ioremap() and readl() not compiling CyberEE Linux - Software 0 01-19-2004 10:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration