c24fde9dceb97b1f3c8b27e527b3b15885d69d35
[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 <unistd.h>
10 #include <acess/sys.h>
11
12 #define PCI_BASE        "/Devices/pci"
13 // === PROTOTYPES ===
14  int    main(int argc, char *argv[]);
15 void    show_device(int PFD, const char *File, int bVerbose);
16
17 // === CODE ===
18 int main(int argc, char *argv[])
19 {
20         int fd = open(PCI_BASE, OPENFLAG_READ);
21
22         char name[256]; 
23
24         while( SysReadDir(fd, name) )
25         {
26                 if(name[0] == '.')      continue ;
27                 
28                 show_device(fd, name, 0);
29         }
30
31         return 0;
32 }
33
34 void show_device(int PFD, const char *File, int bVerbose)
35 {
36          int    fd;
37          int    rv;
38
39         struct {
40                 uint16_t        vendor;
41                 uint16_t        device;
42                 uint32_t        _unused;
43                 uint32_t        revclass;
44         } pciinfo;
45
46         fd = _SysOpenChild(PFD, File, OPENFLAG_READ);
47         if( fd == -1 ) {
48                 printf("%s - ERR (open failure)\n", File);
49                 return ;
50         }
51         rv = read(fd, &pciinfo, sizeof(pciinfo));
52         if( rv != sizeof(pciinfo) ) {
53                 printf("%s - ERR (read %i < %i)\n", File, rv, sizeof(pciinfo));
54                 close(fd);
55                 return ;
56         }
57         uint32_t        class_if = pciinfo.revclass >> 8;
58         uint8_t         revision = pciinfo.revclass & 0xFF;
59         printf("%s - %04x:%04x %06x:%02x\n",
60                 File,
61                 pciinfo.vendor, pciinfo.device,
62                 class_if, revision
63                 );
64
65         if( bVerbose )
66         {
67                 printf("\n");
68         }
69
70         close(fd);
71 }
72

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