From 4755a14b58a1c7934eb11a95c8df4d569e023f8a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 8 Aug 2012 11:25:02 +0800 Subject: [PATCH] Usermode/lspci - Recreated without the huge database of vendors --- Usermode/Applications/lspci_src/Makefile | 10 ++++ Usermode/Applications/lspci_src/main.c | 72 ++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Usermode/Applications/lspci_src/Makefile create mode 100644 Usermode/Applications/lspci_src/main.c 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); +} + -- 2.20.1