怎么样获得PCI槽上的硬件信息?

cpp_pro 2003-04-12 11:39:21
~
...全文
132 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
honix 2003-04-13
  • 打赏
  • 举报
回复
要得到pci配置空间的信息可通过写0xCF8然后读0xCFC端口实现,把我的一个程序给你看看吧!

/*
* Read the PCI Configuration Register
*
* Author: houaq <houaq@163.com>
*/
#include <sys/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>

#define PCI_CONFIG_ADDR(bus, dev, fn, reg) \
(0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3))

void usage()
{
printf("Usage: readpci [-bdfrth]\n\
-b bus : specify PCI bus number(default 0)\n\
-d dev : device number(default 0)\n\
-f fn : function number(default 0)\n\
-r reg : register address(must be multiple of 4, default 0)\n\
-t type: byte length of result(may be 1, 2, 4, default 4)\n\
-h : print this help text\n");
exit(-1);
}

int main(int argc, char **argv)
{
unsigned long val = 0;
char options[] = "b:d:f:r:t:h";
int bus = 0, dev = 0, fn = 0, reg = 0, type = 4;
int opt;

while((opt = getopt(argc, argv, options)) != -1) {
switch(opt) {
case 'b':
bus = atoi(optarg);
break;
case 'd':
dev = atoi(optarg);
break;
case 'f':
fn = atoi(optarg);
break;
case 'r':
reg = atoi(optarg);
break;
case 't':
type = atoi(optarg);
break;
case 'h':
default:
usage();
break;
}
}

iopl(3);

outl(PCI_CONFIG_ADDR(bus, dev, fn, reg), 0xCF8);

switch(type) {
case 1:
val = inb(0xCFC);
break;
case 2:
val = inw(0xCFC);
break;
case 4:
val = inl(0xCFC);
break;
default:
break;
}

printf("PCI: Bus %d, DEV %d, FUNC %d, REG %d, Value is %lX\n", bus, dev, fn, reg, val);

return 0;
}
cpp_pro 2003-04-13
  • 打赏
  • 举报
回复
我是说编程实现
honix 2003-04-13
  • 打赏
  • 举报
回复
# lspci

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧