1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > linux如何禁止pci设备 怎么让linux重新枚举pci设备

linux如何禁止pci设备 怎么让linux重新枚举pci设备

时间:2020-03-13 22:51:19

相关推荐

linux如何禁止pci设备 怎么让linux重新枚举pci设备

在Linux下,lspci可以枚举所有PCI设备。它是通过读取PCI配置空间(PCI Configuration Space)信息来实现PCI设备的枚举的。这里,我通过两种方式来简单的模拟一下lspci的功能。一种是通过PCI总线的CF8和CFC端口来枚举(参考PCI总线规范);另一种是利用proc filesystem。

方法一:这种方法需要对端口进行操作,在Linux下,普通应用程序没有权限读写I/O 端口,需要通过iopl或ioperm来提升权限,我的代码里面使用iopl。

[cpp] view plaincopyprint?

/*

* Enum all pci device via the PCI config register(CF8 and CFC).

*/

#include

#include

#include

#include

#define PCI_MAX_BUS 255 /* 8 bits (0 ~ 255) */

#define PCI_MAX_DEV 31 /* 5 bits (0 ~ 31) */

#define PCI_MAX_FUN 7 /* 3 bits (0 ~ 7) */

#define CONFIG_ADDRESS 0xCF8

#define CONFIG_DATA 0xCFC

#define PCICFG_REG_VID 0x00 /* Vendor id, 2 bytes */

#define PCICFG_REG_DID 0x02 /* Device id, 2 bytes */

#define PCICFG_REG_CMD 0x04 /* Command register, 2 bytes */

#define PCICFG_REG_STAT 0x06 /* Status register, 2 bytes */

#define PCICFG_REG_RID 0x08 /* Revision id, 1 byte */

void list_pci_devices()

{

unsigned int bus, dev, fun;

unsigned int addr, data;

//printf("BB:DD:FF VID:DID\n");

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 = 0x80000000L | (bus<<16) | (dev<<11) | (fun<<8);

outl(addr, CONFIG_ADDRESS);

data = inl(CONFIG_DATA);

<

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。