Usermode/lspci - Recreated without the huge database of vendors
authorJohn Hodge <[email protected]>
Wed, 8 Aug 2012 03:25:02 +0000 (11:25 +0800)
committerJohn Hodge <[email protected]>
Wed, 8 Aug 2012 03:25:02 +0000 (11:25 +0800)
Usermode/Applications/lspci_src/Makefile [new file with mode: 0644]
Usermode/Applications/lspci_src/main.c [new file with mode: 0644]

diff --git a/Usermode/Applications/lspci_src/Makefile b/Usermode/Applications/lspci_src/Makefile
new file mode 100644 (file)
index 0000000..b0c5e4f
--- /dev/null
@@ -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 (file)
index 0000000..c24fde9
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Acess2 lspci
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <acess/sys.h>
+
+#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);
+}
+

UCC git Repository :: git.ucc.asn.au