3 * - By John Hodge (thePowersGang)
12 #define PCI_BASE "/Devices/pci"
14 int main(int argc, char *argv[]);
15 int ParseCommandline(int argc, char *argv[]);
16 void show_device(int PFD, const char *File, int bVerbose);
19 int gbEnableVerbose = 0;
20 const char *gsDeviceName;
23 int main(int argc, char *argv[])
27 rv = ParseCommandline(argc, argv);
30 int fd = _SysOpen(PCI_BASE, OPENFLAG_READ);
33 show_device(fd, gsDeviceName, gbEnableVerbose);
38 while( _SysReadDir(fd, name) )
40 if(name[0] == '.') continue ;
42 show_device(fd, name, gbEnableVerbose);
50 void ShowUsage(const char *progname)
52 fprintf(stderr, "Usage: %s [-v|--verbose] [<pcidev>]\n", progname);
55 "-v | --verbose : Enable dump of BARs\n"
60 int ParseCommandline(int argc, char *argv[])
62 for( int i = 1; i < argc; i ++ )
64 const char *arg = argv[i];
66 // Show an individual device
69 else if( arg[1] != '-' ) {
83 if(strcmp(arg, "--verbose") == 0) {
95 const char *get_device_class(uint32_t revclass)
97 uint8_t class = revclass >> 24;
98 uint8_t subclass = revclass >> 16;
104 case 0x01: return "VGA-Compatible";
106 return "Pre Classcodes";
110 case 0x00: return "SCSI Bus Controller";
111 case 0x01: return "IDE Controller";
112 case 0x02: return "Floppy Disk Controller";
114 return "Mass Storage Controller";
115 case 0x02: return "Network Controller";
116 case 0x03: return "Display Controller";
117 case 0x04: return "Multimedia Controller";
118 case 0x05: return "Memory Controller";
119 case 0x06: return "Bridge Device";
120 case 0x07: return "Simple Communications Controller";
121 case 0x08: return "Base System Peripherals";
122 case 0x09: return "Input Device";
123 case 0x0A: return "Docing Station";
124 case 0x0B: return "Processor";
125 case 0x0C: return "Serial Bus Controller";
130 void show_device(int PFD, const char *File, int bVerbose)
145 fd = _SysOpenChild(PFD, File, OPENFLAG_READ);
147 printf("%s - ERR (open failure)\n", File);
150 rv = _SysRead(fd, &pciinfo, sizeof(pciinfo));
151 if( rv != sizeof(pciinfo) ) {
152 printf("%s - ERR (read %i < %i)\n", File, rv, sizeof(pciinfo));
156 uint32_t class_if = pciinfo.revclass >> 8;
157 uint8_t revision = pciinfo.revclass & 0xFF;
158 printf("%s - %04x:%04x %06x:%02x %s\n",
160 pciinfo.vendor, pciinfo.device,
162 get_device_class(pciinfo.revclass)
168 if(pciinfo.command & (1 <<10)) printf("INTx# Disabled, ");
169 if(pciinfo.command & (1 << 2)) printf("Bus Master, ");
170 if(pciinfo.command & (1 << 1)) printf("MMIO Enabled, ");
171 if(pciinfo.command & (1 << 0)) printf("IO Enabled, ");
173 for( int i = 0; i < 6; i ++ )
175 uint32_t bar = pciinfo.bar[i];
178 printf("BAR%i: ", i);
180 printf("IO 0x%02x", bar & ~3);
184 switch( (bar & 6) >> 1 )
187 printf("Mem32 0x%08x", bar & ~15);
190 printf("Mem20 0x%05x", bar & ~15);
193 printf("Mem64 0x%08x%08x", pciinfo.bar[i+1], bar & ~15);
197 printf("UNK %08x", bar & ~15);
200 printf(" %s", (bar & 8 ? "Prefetchable" : ""));