Detecting memory mapped i/o

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
brickhead20
Member
Member
Posts: 38
Joined: Mon Mar 24, 2008 4:17 pm

Detecting memory mapped i/o

Post by brickhead20 »

Hello all,

I am currently designing my memory management, and as such will need to know which memory is used for memory mapped devices. From the wiki, if I have understood correctly, I can use GRUB to give me a pretty good memory map, but it notes there that the reported free memory may contain memory mapped devices. GRUB gives ACPI information, and I know where the video buffer is, but is there some sort of generic way of detecting memory mapped devices? Or is there a bounded list of devices that may be memory mapped and could be polled for information (i.e. a fixed limited number of possibilities)?

To be precise, I need to know which pages are required for drivers, and which are free for user space software.

I've spent a few days searching the wiki and forums; I did find evidence of an old post referring to this topic, and the user who posted it, but searching that user's posts did not seem to reveal it. I hope I haven't missed anything obvious, and I apologise if I have.

Regards,
Richard
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Detecting memory mapped i/o

Post by pcmattman »

Hi,

One of the easiest ways to find device addresses is to read the BARs of that device on the PCI bus. The BARs will give you the I/O space as well as memory mapped I/O addresses for those devices that have them. This also means you don't have to guess at the addresses based on GRUB's memory map, or use an alternative interface to find these addresses.

Have a read of our PCI article. It should make things a little clearer.

Cheers,
Matt
brickhead20
Member
Member
Posts: 38
Joined: Mon Mar 24, 2008 4:17 pm

Re: Detecting memory mapped i/o

Post by brickhead20 »

Hi,

thanks for the reply. I'd scanned over the information on the article before, and its useful so thanks for emphasizing it. Is it a safe assumption to make though, that all devices with memory mapped I/O use the PCI interface? Or is it just that other devices are dealt with in the memory map passed, for instance, by GRUB (e.g. ACPI)? I can't think of any other examples at the minute, but neither can I determine that there aren't any.

Again, many thanks,
Richard
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Detecting memory mapped i/o

Post by jal »

brickhead20 wrote:thanks for the reply. I'd scanned over the information on the article before, and its useful so thanks for emphasizing it. Is it a safe assumption to make though, that all devices with memory mapped I/O use the PCI interface?
Almost. In the days before PCI there was ISA (I'm not counting VLB and the like, or EISA, as no machine uses them today), and allmost all ISA devices use registers, except for the video memory of an ISA video card, and perhaps (though I'm not certain) ISA NICs. There was, iirc, an ISA PnP standard, but I can't recall whether that allowed for easy reading of BAR-like information. You should probably Google to find out, although it is of little use for modern machines, since although they still use ISA for backwards compatability support, all those devices do not use memory mapped I/O (PIC, PIT, DMAC, COM and the like).


JAL
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Detecting memory mapped i/o

Post by Combuster »

brickhead20 wrote:Is it a safe assumption to make though, that all devices with memory mapped I/O use the PCI interface?
No. Try the APIC (which is built into every modern processor) and friends.
Or is it just that other devices are dealt with in the memory map passed, for instance, by GRUB (e.g. ACPI)?
A memory map contains available memory. What's not memory might be a hole, or it might be MMIO'd, but there's no safe way to tell.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
brickhead20
Member
Member
Posts: 38
Joined: Mon Mar 24, 2008 4:17 pm

Re: Detecting memory mapped i/o

Post by brickhead20 »

OK, thanks everybody, thats probably enough for me to do the research myself now (edit: though if you have more information, please post!). The APIC at least will have to be dealt with at some point (at least for a reasonably modern OS), I was just concerned some obscure device might end up using some memory that would be unintentionally passed to an oblivious user program. I guess it would be documented in the wiki if it did however.

I had thought of implementing a system call that would essentially seize memory mapped I/O pages should they be required by a driver, and missed (i.e. not PCI or APIC etc), but that seemed like such a horrid solution. In fact the ill feeling that was encouraged by this was more than enough to put me off...

Many thanks for the help,
Richard
Post Reply