PciHandle::PciHandle(uint32 bus_, uint32 device_, uint32 function_) : bus(bus_), device(device_), function(function_), pciAddress(PciBusDevFunc(bus_, device_, function_)) { hDriver = CreateFile(L"\\\\.\\RDMSR", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hDriver == INVALID_HANDLE_VALUE && hOpenLibSys == NULL) throw std::exception(); }
DWORD FindPciDeviceByClass( BYTE baseClass, BYTE subClass, BYTE programIf, BYTE index ) { DWORD bus = 0, dev = 0, func = 0; DWORD count = 0; DWORD pciAddress = 0xFFFFFFFF; DWORD conf[3] = {0}; DWORD error = 0; BOOLEAN multiFuncFlag = FALSE; BYTE type = 0; if(gHandle == INVALID_HANDLE_VALUE) { return 0xFFFFFFFF; } count = 0; for(bus = 0; bus <= 255; bus++) { for(dev = 0; dev < 31; dev++) { multiFuncFlag = FALSE; for(func = 0; func < 7; func++) { if(multiFuncFlag == FALSE && func > 0) { break; } pciAddress = PciBusDevFunc(bus, dev, func); if (Wr0ReadPciConfig(pciAddress, 0, (BYTE*)conf, sizeof(conf))) { if(func == 0) // Is Multi Function Device { if (Wr0ReadPciConfig(pciAddress, 0x0E, (BYTE*)&type, sizeof(type))) { if(type & 0x80) { multiFuncFlag = TRUE; } } } if((conf[2] & 0xFFFFFF00) == (((DWORD)baseClass << 24) | ((DWORD)subClass << 16) | ((DWORD)programIf << 8)) ) { if (count == index) { return pciAddress; } count++; continue; } } } } } return 0xFFFFFFFF; }