Port ranges from PCI addresses

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
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Port ranges from PCI addresses

Post by ~ »

Is it possible somehow to "detect" I/O port ranges from a PCI port address, for example, determine which ranges a certain controller actually uses from base address port 0x1F0 and detect from PCI scanning that it uses 0x1F0 to 0x1F7?

How does Windows do it? Does the software driver actually tells this to Windows (which seems the most reasonable or possible)?

Can this be retrieved from the "I/O limit" and/or "Memory limit" fields, reliably, or is there some other ways?
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Port ranges from PCI addresses

Post by Gigasoft »

The BAR registers tell the base address of I/O and memory ranges, and the size is determined by setting them to all ones and reading them back. Some devices (such as VGA adapters) may use other I/O port ranges that are not covered by the BARs. In this case, they are often initially disabled and the driver must enable the ranges. The driver should also report these ranges before enabling them so that two devices won't use the same port ranges.
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: Port ranges from PCI addresses

Post by Combuster »

In practice, you'll have to keep a list of all devices with their quirks to know what ports they do or do not respond to. You can use a heuristic based on the class code - VGA compatible controllers will respond to 3B0-3DF, IDE controllers will respond to their range. Since they are initialized upon boot, you can't prevent them from enabling such decoding. Several devices can't be taken off such ranges without disabling them entirely, and some can't or shouldn't be disabled. (Try to figure out what ports the southbridge silently uses, and how you can (not) disable that behaviour)

Short answer: the only correct method is to keep tabs on each piece of hardware on what they do without telling you. But you can get a long way with guesswork.
"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 ]
Post Reply