Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "pci_codes.h"
- #include "hexioctrl.h"
- #include <conio.h>
- #include <iomanip>
- #include <stdlib.h>
- #include <io.h>
- class Id {
- protected:
- unsigned long id;
- public:
- Id() {
- this->id = -1;
- }
- Id(unsigned long id) {
- this->setId(id);
- }
- unsigned long getId() {
- return this->id;
- }
- void setId(unsigned long id) {
- this->id = id;
- }
- };
- class ConfigSpace {
- private:
- unsigned long configAddress;
- unsigned long configData;
- public:
- ConfigSpace() {
- this->configAddress = -1;
- this->configData = -1;
- }
- unsigned long getConfigData() {
- return this->configData;
- }
- unsigned long getConfigAddress() {
- return this->configAddress;
- }
- void calculateConfigAddress(int bus, int device, int function, int reg) {
- unsigned long address = 1;
- address = (address << 15) + bus; // Номер шины, 8 бит
- address = (address << 5) + device; // Номер устройства, 5 бит
- address = (address << 3) + function; // Номер функции, 3 бита
- address = (address << 8) + reg; // Номер регистра, 8 бит
- this->configAddress = address;
- }
- bool calculateConfigData() {
- _outpd(0xCF8, this->configAddress);
- if (configAddress == -1) {
- return false;
- }
- this->configData = _inpd(0xCFC);
- if(this->configData == -1) {
- return false;
- }
- return true;
- }
- };
- class DeviceId : public Id {
- public:
- DeviceId() : Id() {
- }
- DeviceId(unsigned long id) : Id(id){
- }
- unsigned long calculateDeviceId(ConfigSpace configSpace) {
- return configSpace.getConfigData() >> 16;
- }
- };
- class VendorId : public Id {
- public:
- VendorId() : Id() {
- }
- VendorId(unsigned long id) : Id(id){
- }
- unsigned long calculateVendorId(ConfigSpace configSpace, DeviceId deviceID) {
- return configSpace.getConfigData() - (deviceID.getId() << 16);
- }
- };
- const int lenght = 150;
- class Device {
- private:
- DeviceId deviceId;
- VendorId vendorId;
- char chipName[lenght];
- char chipDescName[lenght];
- char producerName[lenght];
- public:
- Device() {
- this->chipName[0] = '\0';
- this->chipDescName[0] = '\0';
- this->producerName[0] = '\0';
- }
- DeviceId getDeviceId() {
- return this->deviceId;
- }
- void setDeviceId(DeviceId deviceId) {
- this->deviceId = deviceId;
- }
- VendorId getVendorId() {
- return this->vendorId;
- }
- void setVendorId(VendorId vendorId){
- this->vendorId = vendorId;
- }
- char* GetChipName() {
- return this->chipName;
- }
- char* GetChipDescName() {
- return this->chipDescName;
- }
- char* GetProducerName() {
- return this->producerName;
- }
- void decodeChipsName() {
- for (int i = 0; i < PCI_DEVTABLE_LEN; i++)
- if (PciDevTable[i].VenId == this->vendorId.getId() && PciDevTable[i].DevId == this->deviceId.getId())
- {
- strcpy(this->chipName, PciDevTable[i].Chip);
- this->chipName[strlen(PciDevTable[i].Chip)] = '\0';
- strcpy(this->chipDescName, PciDevTable[i].ChipDesc);
- this->chipDescName[strlen(PciDevTable[i].ChipDesc)] = '\0';
- break;
- }
- }
- void decodeProducerName() {
- for (int i = 0; i < PCI_VENTABLE_LEN; i++)
- if (PciVenTable[i].VenId == this->vendorId.getId()) {
- strcpy(this->producerName, PciVenTable[i].VenFull);
- break;
- }
- }
- };
- void printBar()
- {
- printf("-----------------------------------------------------------------------------------------------------------------------\n");
- printf("| N | VendorID | DeviceID | Additional information about the device \n");
- printf("-----------------------------------------------------------------------------------------------------------------------\n");
- }
- void printInfo(Device device){
- static int device_count = 0;
- printf("| %2d | %4x | %4x |", ++device_count, device.getDeviceId().getId(), device.getVendorId().getId());
- if(strcmp(device.GetChipName(), ""))
- printf(" %s, %s", device.GetChipName(), device.GetChipDescName());
- printf("\n| | | |");
- if(strcmp(device.GetProducerName(), ""))
- printf(" Producer: %s", device.GetProducerName());
- printf("\n-----------------------------------------------------------------------------------------------------------------------\n");
- }
- int main() {
- ALLOW_IO_OPERATIONS;
- printBar();
- for (int bus = 0; bus < 256; bus++) // 8 бит, 2^8 = 256
- for (int dev = 0; dev < 32; dev++) // 5 бит, 2^5 = 32
- for (int function = 0; function < 8; function++) { // 3 бита, 2^3 = 8
- Device device;
- ConfigSpace configSpace;
- configSpace.calculateConfigAddress(bus, dev, function, 0x00);
- if (!configSpace.calculateConfigData()) {
- break;
- }
- device.setDeviceId(DeviceId(device.getDeviceId().calculateDeviceId(configSpace)));
- device.setVendorId(VendorId(device.getVendorId().calculateVendorId(configSpace, device.getDeviceId())));
- device.decodeChipsName();
- device.decodeProducerName();
- printInfo(device);
- }
- printf("\n\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement