该芯片看起来相当典型超级输入/输出控制器 https://en.wikipedia.org/wiki/Super_I/O,它基本上是所有“慢”外设都组合到单个芯片组中的集线器。
Coreboot 有一个 wiki 页面讨论如何访问超级I/O https://www.coreboot.org/Developer_Manual/Super_IO.
在PC架构上,Port I/O是使用特殊的CPU指令来完成的,即in
and out
。这些是特权指令,只能从内核模式驱动程序(Ring 0)或已被授予 I/O 特权的用户空间进程使用。
幸运的是,这在 Linux 中很容易。查看手册页outb和朋友 http://man7.org/linux/man-pages/man2/outb.2.html.
您可以使用 ioperm(2) 或 iopl(2) 告诉内核允许用户空间应用程序访问相关 I/O 端口。如果不这样做将导致应用程序收到分段错误。
因此我们可以将您的函数调整为 Linux 环境,如下所示:
/* Untested: Use at your own risk! */
#include <sys/io.h>
#include <stdio.h>
#define ReadByte(port) inb(port)
#define WriteByte(port, val) outb(val, port)
int main(void)
{
if (iopl(3) < 0) {
fprintf(stderr, "Failed to get I/O privileges (are you root?)\n");
return 2;
}
/* Your code using ReadByte / WriteByte here */
}
Warning
使用此方法直接与超级 IO 对话时,您应该非常小心,因为您的操作系统几乎肯定具有以下设备驱动程序:also与芯片对话。
The right实现此目的的方法是编写一个与其他内核代码正确协调的设备驱动程序,以避免并发访问设备。
Linux 内核提供对至少一些超级 I/O 设备的 GPIO 访问;将其中之一移植到您的平台应该很简单。看IT87xx 芯片组的拉取请求 https://lwn.net/Articles/487166/.