Usermode - Renamed VFS syscalls to _Sys* to remove POSIX collisions
[tpg/acess2.git] / Usermode / Applications / lspci_src / main.c
1 /*
2  * Acess2 lspci
3  * - By John Hodge (thePowersGang)
4  *
5  * main.c
6  */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <acess/sys.h>
10
11 #define PCI_BASE        "/Devices/pci"
12 // === PROTOTYPES ===
13  int    main(int argc, char *argv[]);
14 void    show_device(int PFD, const char *File, int bVerbose);
15
16 // === CODE ===
17 int main(int argc, char *argv[])
18 {
19         int fd = _SysOpen(PCI_BASE, OPENFLAG_READ);
20
21         char name[256]; 
22
23         while( _SysReadDir(fd, name) )
24         {
25                 if(name[0] == '.')      continue ;
26                 
27                 show_device(fd, name, 0);
28         }
29
30         _SysClose(fd);
31
32         return 0;
33 }
34
35 void show_device(int PFD, const char *File, int bVerbose)
36 {
37          int    fd;
38          int    rv;
39
40         struct {
41                 uint16_t        vendor;
42                 uint16_t        device;
43                 uint32_t        _unused;
44                 uint32_t        revclass;
45         } pciinfo;
46
47         fd = _SysOpenChild(PFD, File, OPENFLAG_READ);
48         if( fd == -1 ) {
49                 printf("%s - ERR (open failure)\n", File);
50                 return ;
51         }
52         rv = _SysRead(fd, &pciinfo, sizeof(pciinfo));
53         if( rv != sizeof(pciinfo) ) {
54                 printf("%s - ERR (read %i < %i)\n", File, rv, sizeof(pciinfo));
55                 _SysClose(fd);
56                 return ;
57         }
58         uint32_t        class_if = pciinfo.revclass >> 8;
59         uint8_t         revision = pciinfo.revclass & 0xFF;
60         printf("%s - %04x:%04x %06x:%02x\n",
61                 File,
62                 pciinfo.vendor, pciinfo.device,
63                 class_if, revision
64                 );
65
66         if( bVerbose )
67         {
68                 printf("\n");
69         }
70
71         _SysClose(fd);
72 }
73

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