Reputation: 735
Before using IN or OUT instruction to access I/O ports in boot loader code, I'd like to make sure that the port matches to the device that I expect. For example, in case of Intel Z370 chipset, I/O port addresses 0x0CF8, 0x0CFC are PCI Configuration Space. Another example, I/O port address 0x0060 is typically Keyboard Controller.
Is there a method to verify or check the port address belongs to which before use?
Upvotes: 2
Views: 1594
Reputation: 44066
No, there isn't.
Some device can be probed by, e.g., reading a register with the vendor id.
However this is not 100% safe as the sequence of writes/reads used to probe may be interpretable as a command by another device on the same ports.
In general you must make assumptions.
Of course, if a port address is read from the PCI config space or from an ACPI table then you have the right to assume it is correct.
The ports used by the legacy devices are not reused to avoid these kind of conflicts.
Buggy implementations that violates the rule of thumbs of above are known to exists and are not rare, the approach taken is to assume the implementation is correct and patch on a case by case basis.
If you fix the platform (e.g. a specific computer model), there is always a way for the software to known what's behind a port.
This involves the datasheet and, sometimes, the schematics.
Not all of this may be public, though.
Upvotes: 4