C语言-遍历pci设备(2)

Linux系统下就很简单了,直接看代码吧!

#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/io.h> #define PCI_MAX_BUS 255 #define PCI_MAX_DEV 31 #define PCI_MAX_FUN 7 #define PCI_BASE_ADDR 0x80000000L #define CONFIG_ADDR 0xcf8 #define CONFIG_DATA 0xcfc typedef unsigned long DWORD; typedef unsigned int WORD; typedef unsigned long DWORD; int main() { WORD bus,dev,fun; DWORD addr,data; int ret; printf("bus#\tdev#\tfun#\t"); printf("\n"); ret = iopl(3); if(ret < 0) { perror("iopl set error"); return -1; } for(bus = 0; bus <= PCI_MAX_BUS; bus++) for(dev = 0; dev <= PCI_MAX_DEV; dev++) for(fun = 0; fun <= PCI_MAX_FUN; fun++) { addr = PCI_BASE_ADDR|(bus << 16)|(dev << 11)|(fun << 8); outl(addr,CONFIG_ADDR); data = inl(CONFIG_DATA); if((data != 0xffffffff)&&(data != 0)) { printf("%2x\t%2x\t%2x",bus,dev,fun); printf("\n"); } } ret = iopl(0); if(ret < 0){ perror("iopl set error"); return -1; } return 0; } 

更多详情见请继续阅读下一页的精彩内容

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/9290eab22dcd7d93bffe13dc03713ecb.html