How does the kernel differentiate between ram and i/o addresses?
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How does the kernel differentiate between ram and i/o addresses?
How does the kernel know that these are addresses on physical ram and these are i/o memory addresses? I want to make some of my physical ram memory addresses to be treated as i/o memory addresses by the kernel. How can I tell the kernel that THIS address belongs to i/o memory not physical ram?
Maybe not what you want but at least you don't need to fiddle with the kernel code. Just use a ramdisk. Part of memory gets mapped onto the filesystem tree
Your question can be interpreted in at least two ways.
If you are talking about the x86 class of processors, then IO space is distinguished from memory space by the processor instruction set and by the hardware buses that control the memory and IO hardware. The kernel accesses IO space using IO instructions, and memory using memory oriented instructions.
If you are talking about kernels in general, and accessing memory-mapped IO, then there is no real distinction between the various address spaces. Hardware, whether memory-mapped IO, or actual system memory will be somehow configured to be addressed at a specific location in the CPU memory space. This can be in the form of hardware jumpers or switches, software configurable addressing ('plug-and-play'), BIOS based configuration, etc.
Typically, when IO is mapped into CPU address spaces, be it either IO space or memory-mapped, a driver is used to access the IO, and the driver is either given some address information at load time, or has default addressing hard-coded.
--- rod.
This does not answer your question directly, but I hope you get useful information.
The beauty of memory mapped I/O lies in the fact that software does not care if it accesses RAM or device. "I/O Port" access was a different story and required special "I/O Instructions." With memory-IO, Software simply does moveByte to addr to accomplish a "write" or "set attribute". It then does a moveByte from addr to accomplish a corresponding "read" or "get attribute." When the hardware decodes the addr the hardware does any magic dance to cause the data to accomplish correct things. This was the case for the PDP-11, VAX, and DEC-10 systems from aeons ago. Software did not care.
Most modern linux implementations have /proc and /sys file systems. Each of these reach into the bowels of things and permit applications and utilities to read and write all sorts of things. They are very similar to a RAM-disk but "on steroids" due to all that they can access. I recommend that you fetch the code for either or both of these file systems to see what happens at the bit level.
Years ago I used a linux distro for the RTOS (real time operating system) in an industrial instrument. We adapted what was /proc back then to implement access to the instrument-specific hardware.
In case this thread is not interested in following the nasty details, the OP may contact me privately. Over the years I've done a lot of successful memory-mapped-IO hacking.
Good luck,
~~~ 0;-Dan
Last edited by SaintDanBert; 10-28-2009 at 12:43 PM.
Reason: clarification and correction
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.