Page 1 of 1

Detecting memory mapped i/o

Posted: Mon Sep 14, 2009 5:46 am
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

Re: Detecting memory mapped i/o

Posted: Mon Sep 14, 2009 3:49 pm
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

Re: Detecting memory mapped i/o

Posted: Tue Sep 15, 2009 3:38 am
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

Re: Detecting memory mapped i/o

Posted: Tue Sep 15, 2009 7:06 am
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

Re: Detecting memory mapped i/o

Posted: Tue Sep 15, 2009 12:55 pm
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.

Re: Detecting memory mapped i/o

Posted: Tue Sep 15, 2009 4:37 pm
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