From: John Hodge Date: Wed, 8 Aug 2012 03:25:02 +0000 (+0800) Subject: Usermode/lspci - Recreated without the huge database of vendors X-Git-Tag: rel0.15~706^2~54 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=4755a14b58a1c7934eb11a95c8df4d569e023f8a;p=tpg%2Facess2.git Usermode/lspci - Recreated without the huge database of vendors --- diff --git a/Usermode/Applications/lspci_src/Makefile b/Usermode/Applications/lspci_src/Makefile new file mode 100644 index 00000000..b0c5e4fb --- /dev/null +++ b/Usermode/Applications/lspci_src/Makefile @@ -0,0 +1,10 @@ +# Project: PCI Device Listing + +-include ../Makefile.cfg + +LDFLAGS += + +OBJ = main.o +BIN = lspci + +-include ../Makefile.tpl diff --git a/Usermode/Applications/lspci_src/main.c b/Usermode/Applications/lspci_src/main.c new file mode 100644 index 00000000..c24fde9d --- /dev/null +++ b/Usermode/Applications/lspci_src/main.c @@ -0,0 +1,72 @@ +/* + * Acess2 lspci + * - By John Hodge (thePowersGang) + * + * main.c + */ +#include +#include +#include +#include + +#define PCI_BASE "/Devices/pci" +// === PROTOTYPES === + int main(int argc, char *argv[]); +void show_device(int PFD, const char *File, int bVerbose); + +// === CODE === +int main(int argc, char *argv[]) +{ + int fd = open(PCI_BASE, OPENFLAG_READ); + + char name[256]; + + while( SysReadDir(fd, name) ) + { + if(name[0] == '.') continue ; + + show_device(fd, name, 0); + } + + return 0; +} + +void show_device(int PFD, const char *File, int bVerbose) +{ + int fd; + int rv; + + struct { + uint16_t vendor; + uint16_t device; + uint32_t _unused; + uint32_t revclass; + } pciinfo; + + fd = _SysOpenChild(PFD, File, OPENFLAG_READ); + if( fd == -1 ) { + printf("%s - ERR (open failure)\n", File); + return ; + } + rv = read(fd, &pciinfo, sizeof(pciinfo)); + if( rv != sizeof(pciinfo) ) { + printf("%s - ERR (read %i < %i)\n", File, rv, sizeof(pciinfo)); + close(fd); + return ; + } + uint32_t class_if = pciinfo.revclass >> 8; + uint8_t revision = pciinfo.revclass & 0xFF; + printf("%s - %04x:%04x %06x:%02x\n", + File, + pciinfo.vendor, pciinfo.device, + class_if, revision + ); + + if( bVerbose ) + { + printf("\n"); + } + + close(fd); +} +