Provide a shim layer for reference counted pages
[akaros.git] / kern / kfs / bin / pci
1 #!/bin/bash
2 # pci [-bv] - dump pci configuration
3 prog=$0
4 verbose() {
5         if [[ ! -f /lib/pci ]]; then
6                 echo $0: no /lib/pci >&2
7         fi
8         awk '
9
10         function lower(s) {
11                 gsub(/A/, "a", s)
12                 gsub(/B/, "b", s)
13                 gsub(/C/, "c", s)
14                 gsub(/D/, "d", s)
15                 gsub(/E/, "e", s)
16                 gsub(/F/, "f", s)
17                 return s
18         }
19         BEGIN{
20                 file="/lib/pci"
21                 FS="\t"
22                 while(getline <file > 0){
23                         if(/^;/) continue
24                         if(/^[0-9a-fA-F]/){
25                                 vid=lower($1)
26                                 vendor[vid] = $2
27                         }
28                         if(/^   [0-9a-fA-F]/){
29                                 did=lower($2)
30                                 id[vid "/" did] = $3
31                         }
32                 }
33                 FS = " "
34         }
35
36         {
37                 print $0
38                 vid = $4
39                 sub(/\/.*/, "", vid)
40                 if(vid in vendor){
41                         s = vendor[vid]
42                         if($4 in id)
43                                 s = s " " id[$4]
44                         print "\t" s
45                 }
46         }
47 '
48 }
49
50 usage() {
51         echo "usage: ${prog} [-bv]" >&2
52         exit 1
53 }
54
55 filter=none
56 bridges=yes
57 while getopts "bv" opt; do
58         case $opt in
59         b) bridges=no;;
60         v) filter=verbose;;
61         *) usage $0 ;;
62         esac
63 done
64 shift $((OPTIND-1))
65 if [[ $# -ne 0 ]]; then
66         usage $0
67 fi
68
69 maybebridges() {
70         if [[ "${bridges}" == "no" ]]; then
71                 sed '/:06/d'
72         else
73                 cat
74         fi
75 }
76
77 maybefilter() {
78         if [[ "${filter}" = "verbose" ]]; then
79                 verbose
80         else
81                 cat
82         fi
83 }
84
85 # DMG 06/02/2016 Make pci(8) recognize virtio devices
86 # source: http://git.qemu.org/?p=qemu.git;a=blob;f=include/hw/pci/pci.h
87 # devices with vendor code 0x1af4 are QEMU own virtio devices.
88 # useful device codes below:
89 # 0x1000: virtio network card
90 # 0x1001: virtio block device
91 # 0x1002: virtio balloon
92 # 0x1003: virtio console
93 # 0x1004: virtio SCSI
94 # 0x1005: virtio RNG (random numbers generator)
95 # 0x1009: virtio 9P transport
96 # based on this information, the translation table below is amended
97 # to show these devices in the pci (8) output.
98
99 grep -a . '#pci'/*ctl | maybebridges | sed '
100         s/^.pci\///
101         s/ctl:/:        /
102         t noop
103 : noop
104         s/:     \(02\..*\ 1af4\/1000\)/:        virtio-net     \1/
105         s/:     \(01\..*\ 1af4\/1001\)/:        virtio-disk    \1/
106         s/:     \(00\..*\ 1af4\/1002\)/:        virtio-balloon \1/
107         s/:     \(07\..*\ 1af4\/1003\)/:        virtio-console \1/
108         s/:     \(01\..*\ 1af4\/1004\)/:        virtio-scsi    \1/
109         s/:     \(00\..*\ 1af4\/1005\)/:        virtio-rng     \1/
110         s/:     \(00\..*\ 1af4\/1009\)/:        virtio-9p      \1/
111         s/:     01/:    disk  01/
112         s/:     02/:    net   02/
113         s/:     03/:    vid   03/
114         s/:     04/:    aud   04/
115         s/:     05/:    mem   05/
116         s/:     06/:    brg   06/
117         s/:     07/:    ser   07/
118         s/:     0c\.03/:        usb   0c.03/
119         s/:     0c\.05/:        smb   0c.05/
120         s/:     0d/:    rad   0d/
121         s/:     10/:    cryp  10/
122         t
123         s/      /       ---  /
124 ' | maybefilter