Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/io.h>
- #include "pci_compat.h"
- #include <stdio.h>
- int isBridge(unsigned int mainAddress) {
- unsigned int address = mainAddress + 0x0C;
- outl(address, 0xCF8);
- unsigned int result = (char) (inl(0xCFC) >> 16);
- return result != 0;
- }
- void printDeviceAndVendor(unsigned int registerResult) {
- unsigned short int vendorId = registerResult;
- unsigned short int deviceId = registerResult >> 16;
- int vendorFound = 0;
- int deviceFound = 0;
- printf("Vendor code: %04x\nDevice code: %04x\n", vendorId, deviceId);
- for(int i = 0; i < PCI_VENTABLE_LEN && !vendorFound; i++) {
- if(vendorId == PciVenTable[i].VenId) {
- printf("Vendor: %s\n", PciVenTable[i].VenShort);
- vendorFound = 1;
- }
- }
- if(vendorFound) {
- for(int i = 0; i < PCI_DEVTABLE_LEN && !deviceFound; i++) {
- if(deviceId == PciDevTable[i].DevId) {
- printf("Device: %s\n", PciDevTable[i].Chip);
- deviceFound = 1;
- }
- }
- if(!deviceFound) {
- puts("Device not found");
- }
- } else {
- puts("Vendor not found");
- }
- }
- void printMemoryBase(unsigned int mainAddress) {
- if(!isBridge(mainAddress)) {
- unsigned int address = mainAddress + 0x20;
- outl(address, 0xCF8);
- unsigned int result = inl(0xCFC);
- char memoryBase = result >> 8;
- printf("Memory base: %x\n", memoryBase);
- address = mainAddress + 0x24;
- outl(address, 0xCF8);
- result = inl(0xCFC);
- memoryBase = result >> 8;
- printf("Prefetchable memory base: %x\n", memoryBase);
- }
- }
- void printInterruptPin(unsigned int mainAddress) {
- if(!isBridge(mainAddress)) {
- unsigned int address = mainAddress + 0x3C;
- outl(address, 0x0CF8);
- unsigned int result = inl(0xCFC);
- unsigned short int pin = result >> 8;
- printf("Interrupt pin: %02x\n", pin);
- }
- }
- void printClassCode(unsigned int mainAddress) {
- if(isBridge(mainAddress)) {
- unsigned int address = mainAddress + 0x08;
- outl(address, 0x0CF8);
- unsigned int result = inl(0xCFC);
- char interface = result >> 8;
- char subClass = result >> 16;
- char baseClass = result >> 24;
- int interfaceFound = 0;
- printf("Interface : %02x\n", interface);
- printf("Subclass : %02x\n", subClass);
- printf("Baseclass : %02x\n", baseClass);
- for(int i = 0; i < PCI_CLASSCODETABLE_LEN && !interfaceFound; i++) {
- if(interface == PciClassCodeTable[i].ProgIf && subClass == PciClassCodeTable[i].SubClass && baseClass == PciClassCodeTable[i].BaseClass) {
- printf("Description: %s %s %s\n", PciClassCodeTable[i].BaseDesc, PciClassCodeTable[i].SubDesc, PciClassCodeTable[i].ProgDesc);
- interfaceFound = 1;
- }
- }
- }
- }
- int main() {
- if(iopl(3)) {
- puts("Error, try run this program under root user");
- } else {
- unsigned int mainAddress, registerAddress, registerResult;
- for(int busNum = 0; busNum < 256; busNum++) {
- for(int deviceNum = 0; deviceNum < 32; deviceNum++) {
- for(int funcNum = 0; funcNum < 8; funcNum++) {
- mainAddress = (1 << 31) + (busNum << 16) + (deviceNum << 11) + (funcNum << 8);
- registerAddress = mainAddress;
- outl(registerAddress, 0xCF8);
- registerResult = inl(0xCFC);
- if (registerResult >> 16 != 0xFFFF && registerResult != 0) {
- printf("Address: %08x\nBus number: %02x,\nDevice number: %02x,\nFunction number: %01x\n", mainAddress, busNum, deviceNum, funcNum);
- printDeviceAndVendor(registerResult);
- printMemoryBase(mainAddress);
- printClassCode(mainAddress);
- puts("-------------------------------------------------------------");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement