]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/pci
use /n/other for tmp storage
[plan9front.git] / rc / bin / pci
1 #!/bin/rc
2 # pci [-bv] - dump pci configuration
3 rfork e
4 fn verbose {
5         if (! test -f /lib/pci)
6                 echo $0: no /lib/pci >[1=2]
7         awk '
8
9         function lower(s) {
10                 gsub(/A/, "a", s)
11                 gsub(/B/, "b", s)
12                 gsub(/C/, "c", s)
13                 gsub(/D/, "d", s)
14                 gsub(/E/, "e", s)
15                 gsub(/F/, "f", s)
16                 return s
17         }
18         BEGIN{
19                 file="/lib/pci"
20                 FS="\t"
21                 while(getline <file > 0){
22                         if(/^;/) continue
23                         if(/^[0-9a-fA-F]/){
24                                 vid=lower($1)
25                                 vendor[vid] = $2
26                         }
27                         if(/^   [0-9a-fA-F]/){
28                                 did=lower($2)
29                                 id[vid "/" did] = $3
30                         }
31                 }
32                 FS = " "
33         }
34
35         {
36                 print $0
37                 vid = $4
38                 sub(/\/.*/, "", vid)
39                 if(vid in vendor){
40                         s = vendor[vid]
41                         if($4 in id)
42                                 s = s " " id[$4]
43                         print "\t" s
44                 }
45         }
46 '
47 }
48 fn usage {
49         echo usage: $1 '[-bv]' >[1=2]
50         exit usage
51 }
52
53 filter=cat
54 bridges=yes
55 done=0
56 while (~ $done 0 && ! ~ $#* 0 && ~ $1 -*) {
57         if (~ $1 -*b*)
58                 bridges=no
59         if (~ $1 -*v*)
60                 filter=verbose
61         switch ($1) {
62         case --
63                 done = 1                # no break in rc, alas
64         case -*[~bv]*
65                 usage $0
66         }
67         shift
68 }
69 if (! ~ $#* 0)
70         usage $0
71
72 builtin cd '#$/pci' && grep . *ctl | {
73         if (~ $bridges no)
74                 sed /:06/d
75         if not
76                 cat
77         } |
78         sed '
79         s/ctl:/:        /
80         t noop
81 : noop
82         s/:     01/:    disk 01/
83         s/:     02/:    net  02/
84         s/:     03/:    vid  03/
85         s/:     04/:    aud  04/
86         s/:     05/:    mem  05/
87         s/:     06/:    brg  06/
88         s/:     07/:    ser  07/
89         s/:     0c\.03/:        usb  0c.03/
90         s/:     0c\.05/:        smb  0c.05/
91         s/:     0d/:    rad  0d/
92         s/:     10/:    cryp 10/
93         t
94         s/      /       ---  /
95 ' | $filter