Linux - EmbeddedThis forum is for the discussion of Linux and embedded devices.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm a bit new to embedded linux. I'm trying to figure out the best way to directly write to two physical registers in my system. Writing a kernel driver for this is not really an option right now.
What's the best way to map the physical addresses into my user space, if this is even possible?
I'm confused whether you're talking about memory or cpu as you mentioned registers.. if you really mean registers then use inline asm (assuming your language supports it). Access to physical memory is not really an option under any modern OS as the virtual memory system will control what processes see.
It is possible to read physical memory but I don't think you'll be able to map which process is in which location, you'd need to take into account paging as well.
Sorry I should have said physical addresses instead of physical memory. It looks like using mmap with /dev/mem to map the registers into virtual user space may be my best option. Does this sound right?
Sorry, I'm still confused by your terminology, its a little difficult to follow when you switch between "physical addresses", "physical memory" and "registers" - you want to be able to read physical memory from user space, correct? ...
I apologize for the confusing terminology, as I said I'm new to embedded linux. My background is with embedded software on devices running lower level RTOS where virtual addressing is not a consideration. I've solved my problem (I believe) but I'll try to clarify a bit for the sake of anyone else looking for the same answer.
First, forget I ever said "Physical memory." What I am trying to do is gain read/write access to a hardware register (not a processor register) from my user-mode application. Initially I was confused how to access physical addresses when my process is only using virtual addresses. Using mmap with /dev/mem I was able to map the section of physical address space that addresses the registers into virtual addresses in my process address space. From there reading and writing was trivial.
Rather than start a new thread I'll just follow up here. I have a memory mapped IO address that I'm unable to write to from user space. I can read to it. And I can read/write it from a kernel module or from uboot. I'm just unable to write to it from my user process.
What would cause such behavior? Is there some global write protections that's set up at startup?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.