Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <sys/io.h>
- #include "pci.h"
- unsigned getValueOfReg(const int pci, const int device, const int function, const int reg)
- {
- int address = (1 << 31) | (pci << 16) | (device << 11) | (function << 8) | (reg << 2);
- outl(address, 0x0CF8);
- int res = inl(0x0CFC);
- return res;
- }
- int main()
- {
- unsigned value, deviceId, vendorId, intPin;
- if(iopl(3))
- {
- printf("I/O Privilege level change error: %s\nTry running under ROOT user\n",(char *)strerror(errno));
- }
- else {
- for (int pci = 0; pci < 256; pci++) {
- for (int device = 0; device < 32; device++) {
- for (int function = 0; function < 8; function++) {
- value = getValueOfReg(pci, device, function, 0);
- deviceId = (value >> 16) & 0xFFFF;
- if (value != -1) {
- vendorId = value & 0xFFFF;
- puts("______________________________________________________");
- printf("Address: %x-%x-%x\n", pci, device, function);
- for (int i = 0; i < PCI_VENTABLE_LEN; ++i) {
- if (PciVenTable[i].VendorId == vendorId) {
- printf("VendorID: %s\n", PciVenTable[i].VendorName);
- }
- }
- for (int i = 0; i < PCI_DEVTABLE_LEN; ++i) {
- if (PciDevTable[i].VendorId == vendorId && PciDevTable[i].DeviceId == deviceId) {
- printf("DeviceID: %s\n", PciDevTable[i].DeviceName);
- }
- }
- if ((getValueOfReg(pci, device, function, 3) >> 16) == 0) {
- for (int i = 0; i < 6; ++i) {
- if (getValueOfReg(pci, device, function, i + 4) & 0x1)
- printf("Base Address Register %x: %x\n", i,
- getValueOfReg(pci, device, function, i + 4));
- }
- }else{
- printf("Primary Bus Number: %02x\n", (getValueOfReg(pci, device, function, 6) >> 0) & 0xFF);
- printf("Secondary Bus Number: %02x\n", (getValueOfReg(pci, device, function, 6) >> 8) & 0xFF);
- printf("Subordinate Bus Number: %02x\n", (getValueOfReg(pci, device, function, 6) >> 16) & 0xFF);
- printf("Memory Base: %02x\n", (getValueOfReg(pci, device, function, 8) >> 0) & 0xFF);
- printf("Memory Limit: %02x\n", (getValueOfReg(pci, device, function, 8) >> 16) & 0xFF);
- }
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement