]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/pci
fstype: make copy of first sector in /env to avoid unaligned reads on the disk (for...
[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=$1 #vid=lower($1)
25                                 vendor[vid] = $2
26                         }
27                         if(/^   [0-9A-Fa-f]/){
28                                 did=$2 #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
49 filter=cat
50 flagfmt=v,b
51 args='[vid/did ...]'
52 if(! ifs=() eval `{aux/getflags $*}){
53         aux/usage
54         exit usage
55 }
56
57 if(! ~ $#* 0){
58         {
59                 for(i in `{echo $* | tr 'A-Z' 'a-z'})
60                         echo '- - -' $i
61         } | verbose | sed 's:^- - - ::'
62         exit ''
63 }
64
65 if(~ $#flagv 1)
66         filter=verbose
67 builtin cd '#$/pci' && grep . `{ls -n | grep ctl} | {
68         if (~ $#flagb 1)
69                 sed /:06/d
70         if not
71                 cat
72         } |
73         sed '
74         s/ctl:/:        /
75         t noop
76 : noop
77         s/:     01/:    disk 01/
78         s/:     02/:    net  02/
79         s/:     03/:    vid  03/
80         s/:     04/:    aud  04/
81         s/:     05/:    mem  05/
82         s/:     06/:    brg  06/
83         s/:     07/:    ser  07/
84         s/:     08/:    base 08/
85         s/:     09/:    inpt 09/
86         s/:     0a/:    dock 0a/
87         s/:     0b/:    proc 0b/
88         s/:     0c\.03/:        usb  0c.03/
89         s/:     0c\.05/:        smb  0c.05/
90         s/:     0c\.07/:        ipmi 0c.07/
91         s/:     0d/:    rad  0d/
92         s/:     0e/:    intl  0e/
93         s/:     0f/:    sat  0f/
94         s/:     10/:    cryp 10/
95         s/:     11/:    sigl 11/
96         s/:     12/:    exl  12/
97         t
98         s/      /       ---  /
99 ' | $filter