White Papers
4
The root privileges can be dropped after calling the ioperm function. A setuid() to a non-root user does not disable the access to the
ports 2Eh and 2Fh, whose permissions have been granted in the example source code.
The permission to access the IO port can be dropped at the end of the program by using the source code shown below. This is optional
because the permission is removed with the process as it exits.
ioperm(0x2E, 2, 0);
ACCESS THE SUPER IO CHIP
The Super IO chip supports multiple functions such as monitoring fan speeds and power supply voltage, providing I2C bus interface
and UART ports. GPIO is one the functionalities provided by the chip.
All accesses to the Super IO are made through the IO ports; 2Eh and 2Fh. The read/write operation performed on these ports are
transformed into LPC bus cycles for the host processor to interact with the Super IO.
#define LPC_ADDR_PORT 0x2E
#define LPC_DATA_PORT 0x2F
...
outb(0x87, LPC_ADDR_PORT);
outb(0x87, LPC_ADDR_PORT);
In the above sample source code, the byte 0x87 is written twice in a row to the IO port 0x2E. This allows the Super IO chip to enter its
Extended Function Mode, where data updates to the chip are allowed.
To leave this mode and for safety reasons, write 0xAA to the same port as shown below:
outb(0xAA, LPC_ADDR_PORT);
As the access and exit of the Extended Function Mode are frequently needed in the program, rewrite them into functions for ease of
use:
void enter_extended_function_mode()
{
outb(0x87, LPC_ADDR_PORT);
outb(0x87, LPC_ADDR_PORT);
}
void leave_extended_function_mode()
{
outb(0xAA, LPC_ADDR_PORT);
}