阅读:2076回复:4
请问:如何在Windows下枚举所有的Pci设备?
如果我想在Windows的设备驱动程序中枚举系统中所有的Pci设备,并读它们的配置空间,该如何做?
根据Bus(0-255),Device(0-31),function(0-3)来枚举可以吗?怎么做啊? 盼高手回复! |
|
沙发#
发布于:2003-12-17 08:03
如果我想在Windows的设备驱动程序中枚举系统中所有的Pci设备,并读它们的配置空间,该如何做? 一般就是根据Bus,Device,function来枚举。 |
|
|
板凳#
发布于:2003-12-17 10:15
DOS下的,Windows下也类似。
#include <stdio.h> #include <conio.h> typedef unsigned long DWORD ; static DWORD _inpd(int portnum) { static DWORD value ; asm mov dx,portnum ; asm lea bx,value ; #if defined(__BORLANDC__) __emit__(0x66,0x50, // push EAX 0x66,0xED, // in EAX,DX 0x66,0x89,0x07, // mov [BX],EAX 0x66,0x58) ; // pop EAX #else asm push eax asm in eax,dx ; asm mov [bx],eax ; asm pop eax #endif return value ; } static void _outpd(int portnum, DWORD val) { static DWORD value = 0 ; value = val ; asm mov dx,portnum ; asm lea bx,value ; #if defined(__BORLANDC__) __emit__(0x66,0x50, // push EAX 0x66,0x8B,0x07, // mov EAX,[BX] 0x66,0xEF, // out DX,EAX 0x66,0x58) ; // pop EAX #else asm push eax asm mov eax,[bx] ; asm out dx,eax ; asm pop eax #endif return ; } void main(void) { int i, j, k; int bus, device; unsigned long ioa0, iod; unsigned long iobase; int io; clrscr(); for(i=0; i<5; i++) { for(j=0; j<32; j++) { bus = i; device = j; iobase = 0x80000000 + bus * 0x10000+ (device * 8 ) * 0x100; ioa0 = iobase + 0; _outpd(0xcf8, ioa0); iod = _inpd(0xcfc); if (iod != 0xffffffff) { printf(\"\\nBus# = %x\\n\", bus); printf(\"Device # = %x\\n\", device); printf(\"ID# = %lx\\n\", iod); for (io=0; io<=5; io++) { ioa0 = iobase + 0x10 + io*4; _outpd(0xcf8, ioa0); iod = _inpd(0xcfc); printf(\"Base%d = 0x%lx\\n\", io, iod); } ioa0 = iobase + 0x3c; _outpd(0xcf8, ioa0); iod = _inpd(0xcfc); printf(\"IRQ# = 0x%x\\n\", iod & 0xff); getch(); } } } } |
|
|
地板#
发布于:2003-12-25 19:43
是用直接的采用端口读写来枚举设备吗? 有没有什么其他的方法
|
|
地下室#
发布于:2003-12-25 22:11
DOS也可以用bios ina 1a中断
|
|